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

SDK 12.1 S332 Bootloader Not Starting Application

After getting SDK 12.1 and the S332 v2.0.1 softdevice working, I started working on updating the bootloader from the S132 bootloader we've been using to supporting the S332. It seems to be on the verge of working, but I seem to be missing or overlooking something. If I load a combined .hex with the softdevice, application and bootloader (with the bootloader settings merged in) onto the NRF52, nothing seems to happen, the application isn't advertising and the bootloader isn't advertising, it just doesn't seem to do anything. However, if I debug the application (with the softdevice and bootloader on) then it works and the application advertises. If I only load the softdevice and bootloader, no application, then I see it advertise in DFU mode. I thought for sure it was something wrong in the bootloader settings page, but when I read it off of the device, it seems to be the expected values, and if the CRC wasn't passing it should advertise in DFU mode correct? Another observation is that if I build an OTA update package and use that after flashing the softdevice and the bootloader, then the application immediately boots and advertises after the OTA finishes. However, if I then cycle power, it no longer advertises.

I've made the changes to the bootloader that are mentioned in this post: https://devzone.nordicsemi.com/f/nordic-q-a/23454/sdk-13-1-dfu-bootloader_secure_ble

Am I missing something?

  • Hi,

    Please try to run nrfjprog --readregs when the program is 'stuck', check the program counter, then use addr2line or .map file to find out where the program stopped. Also, the last byte of xPSR will also hold the current ISR number ('0' if none), you may want to check this to see if it has entered the hard fault handler (x03) etc.

    I think I've seen similar behavior when I was using the clock driver on with clock source set to LFXO (crystal) on a board without ext. LF crystal. That is, program hangs in infinite loop waiting for the crystal to start when not in debug mode. Does your board have LF crystal?

    Best regards,

    Vidar 

  • Alright, I checked the nrfjprog --readregs when the program is stuck and it didn't provide a lot of useful information. At one point I read the program counter multiple times and the address mapped to the app_error.c. When I debug though, it never gets there, so that was not a super useful result in the program counter. The other address I saw the program counter at was very, very low, something like 0x12F0 or so.

    I looked into the LF crystal, and sure enough, we don't have one on our boards, however, our bootloader for the s132 and our other applications all startup correctly on the same boards. I tried loading the s332 2.0.1, bootloader and application on an nrf52 dev kit 1.2.1, and it worked, everytime, but it still doesn't work on our boards. Looking through the schematics, the only immediate difference seemed to be the LF crystal being on the dev kit, but the bootloader and application should both be configured to use the internal RC. The only other difference is that the softdevice is different, so is there an extra step or a different step in configuring the bootloader when using the S332? Is there an ANT+ version of SOFTDEVICE_HANDLER_APPSH_INIT or something along those lines that I'm missing?

  • Ok, sounds like it may be difficult to replicate this on a development kit. Can you try the attached .hex files and see if you experience the same behavior. I used GCC 4.9.3, s332 v.2.0.1 and SDK 12.3.

    ble_ant_hrm.hex

    bootloader.hex

    settings.hex

    nrfjprog commands:

    nrfjprog --program bootloader.hex --chiperase
    nrfjprog --program ANT_s332_nrf52_2.0.1.hex
    nrfjprog --program ble_ant_hrm.hex
    nrfjprog --program settings.hex --sectorerase -r

    Code changes (disabled LEDs and buttons so it should run on your board)

    diff --git a/components/boards/pca10040.h b/components/boards/pca10040.h
    index 32fb4c6..2938b29 100644
    --- a/components/boards/pca10040.h
    +++ b/components/boards/pca10040.h
    @@ -170,9 +170,9 @@ extern "C" {
     #define ARDUINO_A5_PIN              31    // Analog channel 5
     
     // Low frequency clock source to be used by the SoftDevice
    -#define NRF_CLOCK_LFCLKSRC      {.source        = NRF_CLOCK_LF_SRC_XTAL,            \
    -                                 .rc_ctiv       = 0,                                \
    -                                 .rc_temp_ctiv  = 0,                                \
    +#define NRF_CLOCK_LFCLKSRC      {.source        = NRF_CLOCK_LF_SRC_RC,            \
    +                                 .rc_ctiv       = 16,                                \
    +                                 .rc_temp_ctiv  = 2,                                \
                                      .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_20_PPM}
     
     #ifdef __cplusplus
    diff --git a/components/libraries/bootloader/ble_dfu/nrf_ble_dfu.c b/components/libraries/bootloader/ble_dfu/nrf_ble_dfu.c
    index 9c1003c..6ca90fd 100644
    --- a/components/libraries/bootloader/ble_dfu/nrf_ble_dfu.c
    +++ b/components/libraries/bootloader/ble_dfu/nrf_ble_dfu.c
    @@ -220,8 +220,8 @@ static uint32_t advertising_start(void)
         err_code = sd_ble_gap_adv_start(&adv_params);
         VERIFY_SUCCESS(err_code);
     
    -    nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
    -    nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);
    +/*    nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
    +    nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);*/
     
         m_flags |= DFU_BLE_FLAG_IS_ADVERTISING;
         return NRF_SUCCESS;
    @@ -616,8 +616,8 @@ static void on_ble_evt(ble_evt_t * p_ble_evt)
         switch (p_ble_evt->header.evt_id)
         {
             case BLE_GAP_EVT_CONNECTED:
    -            nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO);
    -            nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);
    +           /* nrf_gpio_pin_clear(CONNECTED_LED_PIN_NO);
    +            nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);*/
     
                 m_conn_handle    = p_ble_evt->evt.gap_evt.conn_handle;
                 m_flags &= ~DFU_BLE_FLAG_IS_ADVERTISING;
    @@ -724,13 +724,13 @@ static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
      *
      * @details     Initializes all LEDs used by this application.
      */
    -static void leds_init(void)
    +/*static void leds_init(void)
     {
         nrf_gpio_cfg_output(ADVERTISING_LED_PIN_NO);
         nrf_gpio_cfg_output(CONNECTED_LED_PIN_NO);
         nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);
         nrf_gpio_pin_set(CONNECTED_LED_PIN_NO);
    -}
    +}*/
     
     
     static uint32_t gap_address_change(void)
    @@ -962,7 +962,7 @@ uint32_t ble_dfu_transport_init(void)
     
         m_flags &= ~DFU_BLE_FLAG_NONE;
     
    -    leds_init();
    +    //leds_init();
     
         err_code = ble_stack_init(true);
         VERIFY_SUCCESS(err_code);
    diff --git a/components/libraries/bootloader/dfu/nrf_dfu.c b/components/libraries/bootloader/dfu/nrf_dfu.c
    index 1de9ebc..27a972a 100644
    --- a/components/libraries/bootloader/dfu/nrf_dfu.c
    +++ b/components/libraries/bootloader/dfu/nrf_dfu.c
    @@ -67,10 +67,10 @@
      */
     __WEAK bool nrf_dfu_enter_check(void)
     {
    -    if (nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0)
    +/*    if (nrf_gpio_pin_read(BOOTLOADER_BUTTON) == 0)
         {
             return true;
    -    }
    +    }*/
     
         if (s_dfu_settings.enter_buttonless_dfu == 1)
         {
    diff --git a/components/softdevice/s332/headers/nrf_sdm.h b/components/softdevice/s332/headers/nrf_sdm.h
    index 58b1b92..c4b6b78 100644
    --- a/components/softdevice/s332/headers/nrf_sdm.h
    +++ b/components/softdevice/s332/headers/nrf_sdm.h
    @@ -158,7 +158,7 @@ the start of the softdevice (without MBR)*/
         You MUST obtain a valid commercial license key BEFORE releasing a product to market that uses the ANT SoftDevices. For
         more information about licensing please visit the website below:
         https://www.thisisant.com/developer/ant/licensing */
    -//#define ANT_LICENSE_KEY "3831-521d-7df9-24d8-eff3-467b-225f-a00e" // This is an EVALUATION license key - DO NOT USE FOR COMMERCIAL PURPOSES
    +#define ANT_LICENSE_KEY "3831-521d-7df9-24d8-eff3-467b-225f-a00e" // This is an EVALUATION license key - DO NOT USE FOR COMMERCIAL PURPOSES
     #ifndef ANT_LICENSE_KEY
        #error "You must obtain a valid license key to use ANT. You may use the evaluation key for non commercial use only by uncommenting it above this error. Commercial use license keys are available from ANT Wireless."
     #endif
    diff --git a/examples/dfu/bootloader_secure/main.c b/examples/dfu/bootloader_secure/main.c
    index 3170389..c309258 100644
    --- a/examples/dfu/bootloader_secure/main.c
    +++ b/examples/dfu/bootloader_secure/main.c
    @@ -75,6 +75,7 @@ void app_error_handler_bare(uint32_t error_code)
     
     /**@brief Function for initialization of LEDs.
      */
    +#if 0 
     static void leds_init(void)
     {
         bsp_board_leds_init();
    @@ -90,7 +91,7 @@ static void buttons_init(void)
                                  BUTTON_PULL,
                                  NRF_GPIO_PIN_SENSE_LOW);
     }
    -
    +#endif
     
     /**@brief Function for application main entry.
      */
    @@ -102,8 +103,8 @@ int main(void)
     
         NRF_LOG_INFO("Inside main\r\n");
     
    -    leds_init();
    -    buttons_init();
    +   /* leds_init();
    +    buttons_init();*/
     
         ret_val = nrf_bootloader_init();
         APP_ERROR_CHECK(ret_val);
    diff --git a/examples/multiprotocol/ble_ant_app_hrm/main.c b/examples/multiprotocol/ble_ant_app_hrm/main.c
    index df7d5a2..6b4934c 100644
    --- a/examples/multiprotocol/ble_ant_app_hrm/main.c
    +++ b/examples/multiprotocol/ble_ant_app_hrm/main.c
    @@ -832,8 +832,8 @@ int main(void)
         // Initialize S332 SoftDevice
         ble_ant_stack_init();
     
    -    err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    -    APP_ERROR_CHECK(err_code);
    +    /*err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    +    APP_ERROR_CHECK(err_code);*/
         // err_code = bsp_buttons_enable((1 << WAKEUP_BUTTON_ID) | (1 << BOND_DELETE_ALL_BUTTON_ID));
         // APP_ERROR_CHECK(err_code);
     
    

  • That was really useful. I was able to compare configurations and replaced the bootloader.hex you provided and replaced it with the s332 bootloader I had configured, and it worked. This caused me to continue digging since the bootloader did actually work and eventually talked to the hardware guys here who designed the module and we found the problem, the inductors for DCC weren't stuffed on this particular board and we needed them. Works like a charm now. Thanks for the help!

  • Thank you for the update, glad you found the problem! I did not think of this. Guess LDO mode is forced when the chip is in debug interface mode.    

Related