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

Catch advertising timeout in main

Hi,

I would like to catch in main.c the nobody connect after advertising event via ADV_SET_TERMINATED. 

I can see with breakpoint program jump into  ble_advertising_on_ble_evt inble_advertising.c but once traeted, it doesn't call the same function in main.c.


I have added the case case BLE_GAP_EVT_ADV_SET_TERMINATED in ble_evt_handler in mains.c. But this timeout event doesn' reach the ble_evt_handler function of may main.c.

I saw another topics where Joakim Jakobsen proposed a good solution, that should solve the problem, but it dosn't work for me. My code is based on ble_app_buttonless_dfu_pca10100.

devzone.nordicsemi.com/.../142407

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code = NRF_SUCCESS;

    switch (p_ble_evt->header.evt_id)
    {
    
            case BLE_GAP_EVT_ADV_SET_TERMINATED:
               // AdvertisingTimeout, nobody connect after 1 minutes
               etat = EVENT_TIMEOUT;
            break;

Thanks a lot !

Parents
  • Hi,

    The buttonless dfu example attempts to enter System OFF (deep sleep) on adv. timeout if you've kept the default implementation. In that case, see if it works if you comment the call to sleep_mode_enter(); being made from on_adv_evt()::BLE_ADV_EVT_IDLE.

  • Great that's works i can reach the event in main.c now. I had also this feeling before to read your answer that program was stopped lol.

    Now i have a second issue: after advertising timeout, i set ma state machine to enter low power with the call 2time to function idle_state_handle();:

     case LOW_POWER:
    
                        NRF_LOG_INFO("State Machine : LOW POWER");
                
                        bma400_goto_mode_power(MODE_LOW_POWER);    // attention si echec recommencer 
    
                        idle_state_handle();
                        idle_state_handle();    //why two times ? but it works...
    

    From a power on sequence this go into low power mode works. But after timeout advertising, it jump over the two function wihtout going into low power mode.

    Is there a link with the fact that we were in timeout advertising event previously may be ?

    Thank you Vidar !

  • The event register is internal and not exposed to the CPU. To clear it you must call __WFE/sd_app_evt_wait(). This is the reason why sd_app_evt_wait() has to be called twice after servicing an application interrupt.

    Olfox said:
    imagine for any reason even after calling two times this function product doesn t enter into low power mode ... 

     This is why I suggested that you placed the "wait for event" call in a spinlock loop earlier.  You want to be sure the correct interrupt/event was triggered before you transition to the next state.

  • Hi Vidar,

    Yes I see now I have implemented it, i try to run my software but i'm stuck with some configuration issue, i guess with settings page. I'm using softdevice s113, secure_bootloader_s113 to perform dfu that worked in the past ( ota worked, but i couldn't flash by jlink cable anymore lol ).

    I try to solve this and i come back to you to tell you if spinlock is working :) . Again, thanks Vidar for your support ! 

  • Ok, it is working fine !

    Is it possible to disable check of CRC in secure bootloader during debug ? Else, i always have to build a new setting page with new hex built.

  • Excellent! Regarding the CRC check, if you are on SDK 15.3.0 or later, you can disable it by specifying --app-boot-validation NO_VALIDATION when you generate the settings page.

    nrfutil settings generate help menu:

  • Ha could be great but it generate en error.

    I tried to move the argument in each place but same result. I also tried to remove application version argument etc but i always have this error:

    fw_no_signed>nrfutil settings generate app-boot-validation NO_VALIDATION --family NRF52 --application ble_app_buttonless_dfu_pca10100_s113.hex --application-version 6 --bootloader-version 1 --bl-settings-version 2 settings.hex
    
    
    Usage: nrfutil settings generate [OPTIONS] HEX_FILE
    Try 'nrfutil settings generate --help' for help.
    
    
    Error: Got unexpected extra arguments (NO_VALIDATION settings.hex)

Reply
  • Ha could be great but it generate en error.

    I tried to move the argument in each place but same result. I also tried to remove application version argument etc but i always have this error:

    fw_no_signed>nrfutil settings generate app-boot-validation NO_VALIDATION --family NRF52 --application ble_app_buttonless_dfu_pca10100_s113.hex --application-version 6 --bootloader-version 1 --bl-settings-version 2 settings.hex
    
    
    Usage: nrfutil settings generate [OPTIONS] HEX_FILE
    Try 'nrfutil settings generate --help' for help.
    
    
    Error: Got unexpected extra arguments (NO_VALIDATION settings.hex)

Children
  • It looks like you are missing the two hyphens ('--') in front of "app-boot-validation"

  • ... Sorry Vidar ... you are right it was the problem ... I was so focused on it that i didn't see this obvious mistake !

    Now next let's go to the next feature to implement: wake up the system each two days with a timer to measure a sensor , log into ram ( that is always on because of my power management mode), and go back to sleep. So i should be able to wake my system on gpio OR eache two days with a timer.

  • No worries. For wakeup I would suggest you set up a repeated app timer instance like most of our BLE examples do.

  • Yes tha's exactly what i did and it works fine. After handler function is finished, does the systeme goes automatically to sleep ? I also have a proble with my jlink connexion now , i don't know why, I have tried several boards always the same issue. I can connect with jlink commander but impossible with nordic tool like nrf Connect or SES. What is strange is taht i didn't get error in the past.

    C:\Users\flo>nrfjprog --version
    nrfjprog version: 10.8.0
    JLinkARM.dll version: 6.82c

    J-Link>connect
    Please specify device / core. <Default>: CORTEX-M4
    Type '?' for selection dialog
    Device>?
    Please specify target interface:
      J) JTAG (Default)
      S) SWD
      T) cJTAG
    TIF>S
    Specify target interface speed [kHz]. <Default>: 4000 kHz
    Speed>
    Device "NRF52833_XXAA" selected.
    
    
    Connecting to target via SWD
    InitTarget() start
    InitTarget() end
    Found SW-DP with ID 0x2BA01477
    SWD speed too high. Reduced from 4000 kHz to 853 kHz for stability
    Failed to power up DAP
    InitTarget() start
    InitTarget() end
    InitTarget() start
    InitTarget() end
    InitTarget() start
    InitTarget() end
    Cannot connect to target.
    J-Link>

  • Olfox said:
    does the systeme goes automatically to sleep ?

     You still have to call idle_state_handle() again after when the program execution returns back to your main loop.

    Olfox said:
    . I can connect with jlink commander

    Jlink commander is too failing to connect to the target based on the log you posted. Can you describe the programming setup you use (connections, voltage, etc)?

Related