This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

EV board reset after implemented buttonless DFU feature to hrs_freertos example

Hi,

I added the feature of the 'buttonless dfu' to the 'hrs freertos' using the SDK v15.3.0.

After programmed the built image to the EV board PCA10040, it could run normally.

However, when I started the DFU process using 'nRF Connect' APP, the EV board reset itself.

The attached zip file is my changes made.

Thanks!

ble_app_hrs_freertos_dfu_evboard.zip

  • What is EVB? I know it probably is short for Evaluation Board, but what type of board is it? Is it the nRF52DK?

  • Hello,

    Good news. I continued the debugging, and I tried with nRF Connect for iOS (initially I used nRF Connect for Desktop). I received the same hardfault as you had (I believe). As Susheel said, I set a breakpoint in HardFault_Handler() in hardfault_handler_gcc.c. After the execution stopped on 0x00000A60, I hit "continue", and it stopped in HardFault_Handler():

    So step one is done.

    The hardfault handler will call NVIC_SystemReset() in HardFault_c_handler() -> HardFault_process(), but as you can see, if you look at the implementation, it will try to print a lot more before that, but it doesn't have time to do so before the reset. So I changed:

    /*lint -save -e14 */
    __WEAK void HardFault_process(HardFault_stack_t * p_stack)
    {
        // Restart the system by default
        NVIC_SystemReset();
    }
    
    TO:
    
    /*lint -save -e14 */
    __WEAK void HardFault_process(HardFault_stack_t * p_stack)
    {
        // Restart the system by default
        //NVIC_SystemReset();
        for(;;)
        {
          NRF_LOG_PROCESS();
        }
    }

    Then this was printed in the log:

    <info> app: HRS FreeRTOS example started.
    <info> app: Fast advertising.
    <info> app: Connected
    <info> app: Received indication state 1
    <error> hardfault: HARD FAULT at 0x00000000
    <error> hardfault:   R0:  0x20007D8C  R1:  0x20007D84  R2:  0x00000008  R3:  0x00000000
    <error> hardfault:   R12: 0x20007D90  LR:  0x0003B049  PSR: 0x60000000
    <error> hardfault: Cause: The processor has attempted to execute an instruction that makes illegal use of the EPSR.
    <info> app: nrf_sdh_ble_enable() err:0 ram_start:0x20002220
    <info> app: HRS FreeRTOS example started.
    <info> app: Fast advertising.
    <info> app: Connected
    <info> app: Received indication state 1

    What we are looking for here is the link register: LR: 0x0003B049. NB: These numbers may differ when you compile, so check your own files.

    I checked the ble_app_hrs_freertos_pca10040_s132.map file that is generated when you compile. I found the line:

     .text.nrf_dfu_set_adv_name
                    0x000000000003b038       0x24 Output/ble_app_hrs_freertos_pca10040_s132 Release/Obj/ble_dfu_unbonded.o

    So the hardfault occured in the function nrf_dfu_set_adv_name.

    You can use the addr2line tool, which I did, if you want to find even more details:

    C:\Nordic_Semiconductor\SDKs\SDK\15.3.0\examples\test\251837\pca10040\s132\ses\Output\Release\Exe>arm-none-eabi-addr2line -e ble_app_hrs_freertos_pca10040_s132.elf 0x03B049
    C:\Nordic_Semiconductor\SDKs\SDK\15.3.0\components\ble\ble_services\ble_dfu/ble_dfu_unbonded.c:61

    So the issue is located in 

    ble_dfu_unbonded.c line 61.

    I tried to set a breakpoint right before the call to nrf_dfu_set_adv_name() this was hit, this was hit when I tried to perform the DFU, and then I tried to set a breakpoint on the line after, line 152 which was never hit. So the issue was the call to nrf_dfu_set_adv_name().

    Now, this is an SVCI call (similar to softdevice calls), because this name is set by the application, but is used by the bootloader after the next reset. I happen to know that iOS uses the name to identify the device after reset, because the iOS doesn't allow the applications to see the advertising addresses, while Android and nRF Connect for Desktop gives the addresses. This is why I didn't see it in nRF Connect for Desktop, and you wouldn't notice this issue with Android. 

    What you are missing is the lines close to the beginning of main() in ble_app_buttonless_dfu:

        ret_code_t err_code = ble_dfu_buttonless_async_svci_init();
        APP_ERROR_CHECK(err_code);

    I added these lines right below log_init() in your main() function, and then it worked as expected. This function will set the asynchronous SVCI calls, such as nrf_dfu_set_adv_name().

    Add these lines, and your hardfault should disappear.

    BR,

    Edvin

Related