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

NRF51822 Secure Bootloader with app_timer

Hello everybody,

i want to add a timer to my secure bootloader example, so it waits some time and then, if no DFU is in progress, starts the beacon apllication automatic if there is one available.

I tried this by using the app_timer module, but it seems to crash the bootloader and i cant connect to it anymore.

These are some code snippets:

nrf_dfu.c

APP_TIMER_DEF(m_start_timer_id);

nrf_dfu.c in nrf_dfu_init()

    app_timer_create(&m_start_timer_id,
                                        APP_TIMER_MODE_SINGLE_SHOT,
                                        start_timer_handler);

app_timer_start(m_start_timer_id, 0x000FFF, start_timer_handler)

dfu_req_handling.c in nrf_dfu_req_handler_on_req()

app_timer_stop(m_start_timer_id);

I was reading the thread about using a Watchdog timer, but i think i cant use that, because it resets the device and starts the booloader again and again because i modified it to be buttonless.

I am using SDK12.3 and an NRF51822 XXAC chip

Thanks for your help!

Parents
  • I haven't tested this, but something like this may work.

    Don't do nrf_dfu_enter_check(), but set enter_bootloader_mode = 1;

    Then you change BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED to whatever advertising timeout you want (max 180 s).

    When you get the BLE_GAP_EVT_TIMEOUT event with src == BLE_GAP_TIMEOUT_SRC_ADVERTISING you call ble_dfu_transport_close()

  • Hey, thank you guys for the answers, i am pretty new to C-coding, so i didn´t know to not directly call it from the event handler, but finally solved this problem using gpregret:

    		case BLE_GAP_EVT_TIMEOUT:
    			 if (p_ble_evt->evt.gatts_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING )
    			 {
    					if (!nrf_dfu_app_is_valid())
    					{
    						sd_nvic_SystemReset();   
    					}else
    					{
    						sd_power_gpregret_set(0x01);
    						ble_conn_params_stop();
    						sd_nvic_SystemReset();  
        }
    	     }
    			 break;
    

    in nrf_dfu_enter_check i check for the gpregret value instead of the Button and it works all fine!

Reply
  • Hey, thank you guys for the answers, i am pretty new to C-coding, so i didn´t know to not directly call it from the event handler, but finally solved this problem using gpregret:

    		case BLE_GAP_EVT_TIMEOUT:
    			 if (p_ble_evt->evt.gatts_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_ADVERTISING )
    			 {
    					if (!nrf_dfu_app_is_valid())
    					{
    						sd_nvic_SystemReset();   
    					}else
    					{
    						sd_power_gpregret_set(0x01);
    						ble_conn_params_stop();
    						sd_nvic_SystemReset();  
        }
    	     }
    			 break;
    

    in nrf_dfu_enter_check i check for the gpregret value instead of the Button and it works all fine!

Children
No Data
Related