multiple resets occur when calling NVIC_SystemReset()

I am working on a project using the following components:

Board: nRF52833

PCA 10100

SDK: 16.0.0

SoftDevice: s140 7.0.1

When NVIC_SystemReset is called the device appears to go through multiple resets. This is apparent from logging output. There is no consistent point in the code where the reset occurs and no error handling function is triggered, as far as I can tell in the debugger (SES). After anywhere from 2 to 10 resets the device enters its normal operating mode and everything appears to work correctly.

Just prior to reset we call these functions:

sd_ble_gap_scan_stop();

sd_ble_gap_adv_stop(p_adv->adv_handle);

nrf_sdh_disable_request();

NVIC_SystemReset();

I have tried commenting out the setup code and slowly adding back parts until I see the problem again. The problem did not appear until I added back our setup code for ble and the softdevice.

I have found that if I add a 10 second nrf delay call right at the beginning of the main function the problem does not occur. Working further into the setup code I've found that there is a specific point in the code where I can add an 8 second delay call and the problem does occur. If I place the call just before that point the problem does not occur. I've commented on the places in the code where I tested the delay call. 

Here is the function:

void clip_ble_stack_init(void)
{
    ret_code_t err_code;

    //nrf_delay_ms(8000); // Never had multiple resets in 10 tests.
    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);
    //nrf_delay_ms(8000); // Never had multiple resets in 10+ tests.

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);
    //nrf_delay_ms(8000); // Had occasional multiple resets when delay called here.

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);
    //nrf_delay_ms(8000); // Had occasional multiple resets when delay called here.

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, clip_ble_evt_handler, NULL);
    //nrf_delay_ms(8000); // Had occasional multiple resets when delay called here.
}

So the problem seems to occur when I wasn't waiting before nrf_sdh_ble_default_cfg_set() which is the first ble related function we call in setup.

This makes me think there is a problem with our ble configuration or perhaps something is not being shutdown correctly before the system reset call.

I hope there are enough clues here.

I specifically want to know how I can prevent multiple resets from occurring as it makes the restart process take longer.

Thanks!

Parents
  • Hi,

    NVIC_SystemReset() itself only trigger a single reset, but apparently something happens on your device during boot that often causes resets. Your clip_ble_stack_init() looks sensible to me though, and I do not immediately see why a delay here help.

    I would suggest that you start with checking the RESETREAS register to know what type of reset occurred, and with that knowledge, we will know more of where to look.

    Is the issue caused by a soft reset (like  NVIC_SystemReset())? If so, perhaps an error handler detects a non-zero return code and that causes a reset? If so (or in any case, really), I would double check that your error handler does not cause a reset for debug builds, and ensure that you are testing a reset build. The default SDK error handler will not reset if the project is compiled with DEBUG defined for the project.

    Or, if all bits in RESETREAS are cleared that indicate a power-on reset or brown-out reset, and in that case you should take a look at your HW. Could it be that during startup the current consumption is causing the supply voltage to drop too low?

    Einar

  • Thanks Einar,

    The RESETREAS register shows 4 indicating a software reset. I was careful to clear the RESETREAS register after each read. Each time the device reset the reason was the same even when the multiple resets occurred. I tried modifying the error handler so that it would not reset the device, but the result was the same even on the release build.

    I have spent quite a bit of time trying to figure out where a soft reset might be coming from, but have not been able to pin down anything yet. Is there any other way a soft reset might be generated other than writing to the AIRCR in the SCB? I have gone so far as to comment out all but one call to NVIC_SystemReset(). 

    Austin

    EDIT: Well, shucks. That really forces a conclusion, doesn't it? Let me run some more tests. I may have figured this one out.

  • Hi Austin,

    That is interesting. Please let me know what you find.

    Einar

Reply Children
Related