Env setup:
nrf52840 on PCA10056, SDK 16.0.0, S140, FreeRTOS, secure bootloader
Description:
I'm trying BLE background DFU in the application.
Had reference iot/background dfu code. But the final impl is porting dfu/ and ble_dfu/ under sdk/components/libraries/bootloader/ to my application.
The code works with nRF Connect and nRF Toolbox, to transfer dfu payload to flash bank1.
My application was based on ble_app_hrs_freertos/
During the porting, I need to enable the app scheduler for nrf_dfu_req_handler.c, to handler incoming payload written to flash asynchronously.
Disable the dfu timer, since the other BLE connection (e.g. heart rate) is still working
FreeRTOS tasks:
1. invoke nrf_sdh_freertos_init to create softdevice task
2. create a dfu task for consuming app scheduler
void dfu_thread(void * arg) {
UNUSED_PARAMETER(arg);
while (1) {
app_sched_execute();
osDelay(10);
}
}
3. modify the log task, (disable the freertos idle task, not using the task suspend, wake up way), lower priority
while(1) {
if (NRF_LOG_PROCESS()) {
osDelay(1);
} else {
nrfx_gpiote_out_toggle(15); - debug led
osDelay(50);
}
}
4. a log task to report alive
while(1) {
NRF_LOG_DEBUG("alive");
osDelay(1000);
}
Problem:
- sometimes running the background dfu, after transfer complete, the system keeps normal running state, with "alive" message
- sometimes running the background dfu, after transfer complete, the "alive" message won't show periodically.
- in this situation, the debug led still blinking
- press a button to print other log(in in_pin_handler), still working
- sometimes running the background dfu, the transfer stuck,
- in this situation, debug led stopped
- press a button to print other log, not working
- don't run background dfu, just BLE connect / read HRM / disconnect, repeat, the system keeps normal state
I suspect there's something wrong when running freertos with the app scheduler.
Wondering if anyone has similar setup, could share your experience and maybe some debug direction?