Hackathone session: bugfixes and documentation update (#869)
* ReadMe: update flashing scripts section * Furi: add record exists method to record store. * FuriHal: early OS init and i2c timeouts based on os ticks. * Storage: replace malloc with furi_alloc, fix errors found by pvs. * iButton: properly handle shutdown in cli search command * SubGhz: proper argument type in sscanf and incorrect position of logging in switch.
This commit is contained in:
@@ -405,7 +405,7 @@ BSP_SD_ReadBlocks(uint32_t* pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint
|
||||
goto error;
|
||||
}
|
||||
|
||||
ptr = malloc(sizeof(uint8_t) * BlockSize);
|
||||
ptr = furi_alloc(sizeof(uint8_t) * BlockSize);
|
||||
if(ptr == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@@ -483,7 +483,7 @@ BSP_SD_WriteBlocks(uint32_t* pData, uint32_t WriteAddr, uint32_t NumOfBlocks, ui
|
||||
goto error;
|
||||
}
|
||||
|
||||
ptr = malloc(sizeof(uint8_t) * BlockSize);
|
||||
ptr = furi_alloc(sizeof(uint8_t) * BlockSize);
|
||||
if(ptr == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
@@ -46,38 +46,48 @@ bool furi_hal_i2c_tx(
|
||||
const uint8_t* data,
|
||||
uint8_t size,
|
||||
uint32_t timeout) {
|
||||
|
||||
furi_check(handle->bus->current_handle == handle);
|
||||
uint32_t time_left = timeout;
|
||||
furi_assert(timeout > 0);
|
||||
|
||||
bool ret = true;
|
||||
uint32_t timeout_tick = osKernelGetTickCount() + timeout;
|
||||
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c))
|
||||
;
|
||||
|
||||
LL_I2C_HandleTransfer(
|
||||
handle->bus->i2c,
|
||||
address,
|
||||
LL_I2C_ADDRSLAVE_7BIT,
|
||||
size,
|
||||
LL_I2C_MODE_AUTOEND,
|
||||
LL_I2C_GENERATE_START_WRITE);
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) {
|
||||
if(LL_I2C_IsActiveFlag_TXIS(handle->bus->i2c)) {
|
||||
LL_I2C_TransmitData8(handle->bus->i2c, (*data));
|
||||
data++;
|
||||
size--;
|
||||
time_left = timeout;
|
||||
}
|
||||
|
||||
if(LL_SYSTICK_IsActiveCounterFlag()) {
|
||||
if(--time_left == 0) {
|
||||
do {
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
|
||||
if(osKernelGetTickCount() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LL_I2C_ClearFlag_STOP(handle->bus->i2c);
|
||||
if(!ret) {
|
||||
break;
|
||||
}
|
||||
|
||||
LL_I2C_HandleTransfer(
|
||||
handle->bus->i2c,
|
||||
address,
|
||||
LL_I2C_ADDRSLAVE_7BIT,
|
||||
size,
|
||||
LL_I2C_MODE_AUTOEND,
|
||||
LL_I2C_GENERATE_START_WRITE);
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) {
|
||||
if(LL_I2C_IsActiveFlag_TXIS(handle->bus->i2c)) {
|
||||
LL_I2C_TransmitData8(handle->bus->i2c, (*data));
|
||||
data++;
|
||||
size--;
|
||||
}
|
||||
|
||||
if(osKernelGetTickCount() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LL_I2C_ClearFlag_STOP(handle->bus->i2c);
|
||||
} while(0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -88,38 +98,48 @@ bool furi_hal_i2c_rx(
|
||||
uint8_t* data,
|
||||
uint8_t size,
|
||||
uint32_t timeout) {
|
||||
|
||||
furi_check(handle->bus->current_handle == handle);
|
||||
uint32_t time_left = timeout;
|
||||
furi_assert(timeout > 0);
|
||||
|
||||
bool ret = true;
|
||||
uint32_t timeout_tick = osKernelGetTickCount() + timeout;
|
||||
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c))
|
||||
;
|
||||
|
||||
LL_I2C_HandleTransfer(
|
||||
handle->bus->i2c,
|
||||
address,
|
||||
LL_I2C_ADDRSLAVE_7BIT,
|
||||
size,
|
||||
LL_I2C_MODE_AUTOEND,
|
||||
LL_I2C_GENERATE_START_READ);
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) {
|
||||
if(LL_I2C_IsActiveFlag_RXNE(handle->bus->i2c)) {
|
||||
*data = LL_I2C_ReceiveData8(handle->bus->i2c);
|
||||
data++;
|
||||
size--;
|
||||
time_left = timeout;
|
||||
}
|
||||
|
||||
if(LL_SYSTICK_IsActiveCounterFlag()) {
|
||||
if(--time_left == 0) {
|
||||
do {
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
|
||||
if(osKernelGetTickCount() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LL_I2C_ClearFlag_STOP(handle->bus->i2c);
|
||||
if(!ret) {
|
||||
break;
|
||||
}
|
||||
|
||||
LL_I2C_HandleTransfer(
|
||||
handle->bus->i2c,
|
||||
address,
|
||||
LL_I2C_ADDRSLAVE_7BIT,
|
||||
size,
|
||||
LL_I2C_MODE_AUTOEND,
|
||||
LL_I2C_GENERATE_START_READ);
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) {
|
||||
if(LL_I2C_IsActiveFlag_RXNE(handle->bus->i2c)) {
|
||||
*data = LL_I2C_ReceiveData8(handle->bus->i2c);
|
||||
data++;
|
||||
size--;
|
||||
}
|
||||
|
||||
if(osKernelGetTickCount() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LL_I2C_ClearFlag_STOP(handle->bus->i2c);
|
||||
} while(0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -132,6 +152,7 @@ bool furi_hal_i2c_trx(
|
||||
uint8_t* rx_data,
|
||||
uint8_t rx_size,
|
||||
uint32_t timeout) {
|
||||
|
||||
if(furi_hal_i2c_tx(handle, address, tx_data, tx_size, timeout) &&
|
||||
furi_hal_i2c_rx(handle, address, rx_data, rx_size, timeout)) {
|
||||
return true;
|
||||
|
@@ -17,6 +17,9 @@ void furi_hal_init() {
|
||||
furi_hal_interrupt_init();
|
||||
furi_hal_delay_init();
|
||||
|
||||
// FreeRTOS glue
|
||||
furi_hal_os_init();
|
||||
|
||||
MX_GPIO_Init();
|
||||
FURI_LOG_I(TAG, "GPIO OK");
|
||||
|
||||
@@ -56,9 +59,6 @@ void furi_hal_init() {
|
||||
furi_hal_bt_init();
|
||||
furi_hal_compress_icon_init();
|
||||
|
||||
// FreeRTOS glue
|
||||
furi_hal_os_init();
|
||||
|
||||
// FatFS driver initialization
|
||||
MX_FATFS_Init();
|
||||
FURI_LOG_I(TAG, "FATFS OK");
|
||||
|
@@ -405,7 +405,7 @@ BSP_SD_ReadBlocks(uint32_t* pData, uint32_t ReadAddr, uint32_t NumOfBlocks, uint
|
||||
goto error;
|
||||
}
|
||||
|
||||
ptr = malloc(sizeof(uint8_t) * BlockSize);
|
||||
ptr = furi_alloc(sizeof(uint8_t) * BlockSize);
|
||||
if(ptr == NULL) {
|
||||
goto error;
|
||||
}
|
||||
@@ -483,7 +483,7 @@ BSP_SD_WriteBlocks(uint32_t* pData, uint32_t WriteAddr, uint32_t NumOfBlocks, ui
|
||||
goto error;
|
||||
}
|
||||
|
||||
ptr = malloc(sizeof(uint8_t) * BlockSize);
|
||||
ptr = furi_alloc(sizeof(uint8_t) * BlockSize);
|
||||
if(ptr == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
@@ -46,38 +46,48 @@ bool furi_hal_i2c_tx(
|
||||
const uint8_t* data,
|
||||
uint8_t size,
|
||||
uint32_t timeout) {
|
||||
|
||||
furi_check(handle->bus->current_handle == handle);
|
||||
uint32_t time_left = timeout;
|
||||
furi_assert(timeout > 0);
|
||||
|
||||
bool ret = true;
|
||||
uint32_t timeout_tick = osKernelGetTickCount() + timeout;
|
||||
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c))
|
||||
;
|
||||
|
||||
LL_I2C_HandleTransfer(
|
||||
handle->bus->i2c,
|
||||
address,
|
||||
LL_I2C_ADDRSLAVE_7BIT,
|
||||
size,
|
||||
LL_I2C_MODE_AUTOEND,
|
||||
LL_I2C_GENERATE_START_WRITE);
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) {
|
||||
if(LL_I2C_IsActiveFlag_TXIS(handle->bus->i2c)) {
|
||||
LL_I2C_TransmitData8(handle->bus->i2c, (*data));
|
||||
data++;
|
||||
size--;
|
||||
time_left = timeout;
|
||||
}
|
||||
|
||||
if(LL_SYSTICK_IsActiveCounterFlag()) {
|
||||
if(--time_left == 0) {
|
||||
do {
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
|
||||
if(osKernelGetTickCount() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LL_I2C_ClearFlag_STOP(handle->bus->i2c);
|
||||
if(!ret) {
|
||||
break;
|
||||
}
|
||||
|
||||
LL_I2C_HandleTransfer(
|
||||
handle->bus->i2c,
|
||||
address,
|
||||
LL_I2C_ADDRSLAVE_7BIT,
|
||||
size,
|
||||
LL_I2C_MODE_AUTOEND,
|
||||
LL_I2C_GENERATE_START_WRITE);
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) {
|
||||
if(LL_I2C_IsActiveFlag_TXIS(handle->bus->i2c)) {
|
||||
LL_I2C_TransmitData8(handle->bus->i2c, (*data));
|
||||
data++;
|
||||
size--;
|
||||
}
|
||||
|
||||
if(osKernelGetTickCount() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LL_I2C_ClearFlag_STOP(handle->bus->i2c);
|
||||
} while(0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -88,38 +98,48 @@ bool furi_hal_i2c_rx(
|
||||
uint8_t* data,
|
||||
uint8_t size,
|
||||
uint32_t timeout) {
|
||||
|
||||
furi_check(handle->bus->current_handle == handle);
|
||||
uint32_t time_left = timeout;
|
||||
furi_assert(timeout > 0);
|
||||
|
||||
bool ret = true;
|
||||
uint32_t timeout_tick = osKernelGetTickCount() + timeout;
|
||||
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c))
|
||||
;
|
||||
|
||||
LL_I2C_HandleTransfer(
|
||||
handle->bus->i2c,
|
||||
address,
|
||||
LL_I2C_ADDRSLAVE_7BIT,
|
||||
size,
|
||||
LL_I2C_MODE_AUTOEND,
|
||||
LL_I2C_GENERATE_START_READ);
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) {
|
||||
if(LL_I2C_IsActiveFlag_RXNE(handle->bus->i2c)) {
|
||||
*data = LL_I2C_ReceiveData8(handle->bus->i2c);
|
||||
data++;
|
||||
size--;
|
||||
time_left = timeout;
|
||||
}
|
||||
|
||||
if(LL_SYSTICK_IsActiveCounterFlag()) {
|
||||
if(--time_left == 0) {
|
||||
do {
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
|
||||
if(osKernelGetTickCount() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LL_I2C_ClearFlag_STOP(handle->bus->i2c);
|
||||
if(!ret) {
|
||||
break;
|
||||
}
|
||||
|
||||
LL_I2C_HandleTransfer(
|
||||
handle->bus->i2c,
|
||||
address,
|
||||
LL_I2C_ADDRSLAVE_7BIT,
|
||||
size,
|
||||
LL_I2C_MODE_AUTOEND,
|
||||
LL_I2C_GENERATE_START_READ);
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c) || size > 0) {
|
||||
if(LL_I2C_IsActiveFlag_RXNE(handle->bus->i2c)) {
|
||||
*data = LL_I2C_ReceiveData8(handle->bus->i2c);
|
||||
data++;
|
||||
size--;
|
||||
}
|
||||
|
||||
if(osKernelGetTickCount() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
LL_I2C_ClearFlag_STOP(handle->bus->i2c);
|
||||
} while(0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -132,6 +152,7 @@ bool furi_hal_i2c_trx(
|
||||
uint8_t* rx_data,
|
||||
uint8_t rx_size,
|
||||
uint32_t timeout) {
|
||||
|
||||
if(furi_hal_i2c_tx(handle, address, tx_data, tx_size, timeout) &&
|
||||
furi_hal_i2c_rx(handle, address, rx_data, rx_size, timeout)) {
|
||||
return true;
|
||||
|
@@ -17,6 +17,9 @@ void furi_hal_init() {
|
||||
furi_hal_interrupt_init();
|
||||
furi_hal_delay_init();
|
||||
|
||||
// FreeRTOS glue
|
||||
furi_hal_os_init();
|
||||
|
||||
MX_GPIO_Init();
|
||||
FURI_LOG_I(TAG, "GPIO OK");
|
||||
|
||||
@@ -56,9 +59,6 @@ void furi_hal_init() {
|
||||
furi_hal_bt_init();
|
||||
furi_hal_compress_icon_init();
|
||||
|
||||
// FreeRTOS glue
|
||||
furi_hal_os_init();
|
||||
|
||||
// FatFS driver initialization
|
||||
MX_FATFS_Init();
|
||||
FURI_LOG_I(TAG, "FATFS OK");
|
||||
|
Reference in New Issue
Block a user