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 !

  • __WFE will execute as a __NOP instruction after servicing an interrupt because the Event register will be set. Please take a look at the ARM documentation here for a more detailed explanation as to how this works: https://developer.arm.com/documentation/ka001269/1-0/?search=5eec6e71e24a5e02d07b259a

  • Hi Vidar,

    Thanks for the link.

    I have found the problem. As my software is based on sdk example, bsp function managing leds and button were called with timer. When i connected scope on debug sleep pin ,i have seen the uC going into sleep for around 0.3sec. Then I thought to someting linked to timer and i have found the leds stuff. So i have set LEDS_NUMBER to 0 and now i'm not waken by this anymore and product is sleeping as i want. 

    I should clean all the function linked to bsp button and leds to be sure it will not happen anymore.

    I'm still not sure whitch register to look at to mastered the enable source of wake up, and i still don't know why i have to call two times idle_state_handle function. I'm really afraid to put a mass production product without be sure of this. imagine for any reason even after calling two times this function product doesn t enter into low power mode ... 

  • 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.

Reply Children
Related