Clock configuration fail in application with secure bootloader (uart mbr)

I am using nrf52832 with a custom board with no external crystal oscillator. As bootloader I use "secure_bootloader_uart_mbr" so I don't have softdevice. SDK is 17.1.0_ddde560

I have modified sdk_config.h of my application to use RC as LF clock source,
however I haven't added anything to sdk_config.h of the bootloader as it appears that the source is LF RC also there were no config lines related to the source of clock module in place already.


After bootloader starts my application I initialize the clock module, however my application crushes and causes the device to reset.

However when running application aloe without the bootloader everything works fine.

ret_code_t ret= nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    nrf_drv_clock_lfclk_request(NULL);

I assume the problem is some kind of interrupt because in the function nrfx_clock_lfclk_start() called by nrf_drv_clock_lfclk_request,  commenting the nrf_clock_int_enable(NRF_CLOCK_INT_LF_STARTED_MASK) line lets the app to continue running. To be clear when uncommented the application fails 

when  CRITICAL_REGION_EXIT() is called in nrf_drv_clock_lfclk_request function.

The timer in bootloader seems to work, because it resets when in dfu mode for too long (around 2 min) 

void nrfx_clock_lfclk_start(void)
{
    NRFX_ASSERT(m_clock_cb.module_initialized);
    nrf_clock_event_clear(NRF_CLOCK_EVENT_LFCLKSTARTED);
    nrf_clock_int_enable(NRF_CLOCK_INT_LF_STARTED_MASK);

#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB)
    nrfx_clock_anomaly_132();
#endif

    nrf_clock_task_trigger(NRF_CLOCK_TASK_LFCLKSTART);
}
 

void nrf_drv_clock_lfclk_request(nrf_drv_clock_handler_item_t * p_handler_item)
{
    ASSERT(m_clock_cb.module_initialized);

    if (m_clock_cb.lfclk_on)
    {
        if (p_handler_item)
        {
            p_handler_item->event_handler(NRF_DRV_CLOCK_EVT_LFCLK_STARTED);
        }
        CRITICAL_REGION_ENTER();
        ++(m_clock_cb.lfclk_requests);
        CRITICAL_REGION_EXIT();
    }
    else
    {
        CRITICAL_REGION_ENTER();
        if (p_handler_item)
        {
            item_enqueue((nrf_drv_clock_handler_item_t **)&m_clock_cb.p_lf_head,
                p_handler_item);
        }
        if (m_clock_cb.lfclk_requests == 0)
        {
            nrfx_clock_lfclk_start();
        }
        ++(m_clock_cb.lfclk_requests);
        CRITICAL_REGION_EXIT();//this call results in crush
    }

    ASSERT(m_clock_cb.lfclk_requests > 0);
}

I haven't made any changes to the bootloader source code except for public_key.c file, board definition and method of entering dfu mode.

Also I use a timer instance in libuarte if it is relevant.

NRF_LIBUARTE_ASYNC_DEFINE(libuarte,0,1,0,NRF_LIBUARTE_PERIPHERAL_NOT_USED,255,3);

I would appreciate any idea as what may cause this. 

Parents
  • Hi,

    After bootloader starts my application I initialize the clock module, however my application crushes and causes the device to reset.

    Could you test with the debug variant of the bootloader project(pca10040_uart_debug), and see if you get any errors or warnings printed in the log(Segger RTT logger backend)?

  • I ran the debug variant of the bootloader project(pca10040_uart_debug), and here is the log of the bootloader.

    00> <info> app: Inside main
    00>
    00> <debug> app: In nrf_bootloader_init
    00>
    00> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    00>
    00> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    00>
    00> <debug> nrf_dfu_settings: Using settings page.
    00>
    00> <debug> nrf_dfu_settings: Copying forbidden parts from backup page.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <debug> app: Enter nrf_bootloader_fw_activate
    00>
    00> <info> app: No firmware to activate.
    00>
    00> <debug> nrf_dfu_validation: CRC check of app failed. Return 1
    00>
    00> <debug> app: App is valid
    00>
    00> <warning> nrf_dfu_settings: No additional data erased
    00>
    00> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <debug> app: Running nrf_bootloader_app_start with address: 0x00001000
    00>
    00> <debug> app: Disabling interrupts. NVIC->ICER[0]: 0x0
    00>

     

Reply
  • I ran the debug variant of the bootloader project(pca10040_uart_debug), and here is the log of the bootloader.

    00> <info> app: Inside main
    00>
    00> <debug> app: In nrf_bootloader_init
    00>
    00> <debug> nrf_dfu_settings: Calling nrf_dfu_settings_init()...
    00>
    00> <debug> nrf_dfu_flash: Initializing nrf_fstorage_nvmc backend.
    00>
    00> <debug> nrf_dfu_settings: Using settings page.
    00>
    00> <debug> nrf_dfu_settings: Copying forbidden parts from backup page.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <debug> app: Enter nrf_bootloader_fw_activate
    00>
    00> <info> app: No firmware to activate.
    00>
    00> <debug> nrf_dfu_validation: CRC check of app failed. Return 1
    00>
    00> <debug> app: App is valid
    00>
    00> <warning> nrf_dfu_settings: No additional data erased
    00>
    00> <info> nrf_dfu_settings: Backing up settings page to address 0x7E000.
    00>
    00> <debug> nrf_dfu_settings: Destination settings are identical to source, write not needed. Skipping.
    00>
    00> <debug> app: Running nrf_bootloader_app_start with address: 0x00001000
    00>
    00> <debug> app: Disabling interrupts. NVIC->ICER[0]: 0x0
    00>

     

Children
Related