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

Softdevice is not advertising after switching from DM (device manager) to PM (peer manager)

Hi,

SDK: nRF5_SDK_00.11.00 ; S132 SoftDevice v2.0.0

I am working now to migrate my application from DM to PM (in order to better handle pairing&bonding).

Sometimes the application will not start advertising, I start to advertise using: 

static uint32_t augu_ble_start_advertising(void)
{
	uint32_t err_code;

	err_code = advertising_enable_disable_(1);
	if (NRF_SUCCESS != err_code)
	{
		AUGU_LOG_PRINTF_ERR("ERROR: advertising_enable_disable_(1) ; error code: %d\n", err_code);
	}

	err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
	if (NRF_SUCCESS != err_code)
	{
		AUGU_LOG_PRINTF_ERR("ERROR: ble_advertising_start(BLE_ADV_MODE_FAST) ; error code: %d\n", err_code);
	}			

	return err_code;
}

but in the cases that adv is not starting, I am not getting ANY advertisement event (none of the below printouts are showing)
void augu_on_adv_evt(ble_adv_evt_t ble_adv_evt) 
{
	switch (ble_adv_evt) {
       	case BLE_ADV_EVT_IDLE:
			AUGU_LOG_PRINTF_WRN("ADV EVENT: BLE_ADV_EVT_IDLE (%d)\n", ble_adv_evt);
    	   	augu_ble_main_fsm(AUGU_BLE_FSM_EVENT_ADV_IDLE);
	   	   	break;

       	case BLE_ADV_EVT_SLOW:
			AUGU_LOG_PRINTF_WRN("ADV EVENT: BLE_ADV_EVT_SLOW (%d)\n", ble_adv_evt);
    	   	break;

       	case BLE_ADV_EVT_FAST:
			AUGU_LOG_PRINTF_WRN("ADV EVENT: BLE_ADV_EVT_FAST (%d)\n", ble_adv_evt);
    	   	break;

	   	default:
	   		AUGU_LOG_PRINTF_ERR("ADV EVENT: received unhandled ADV event (%d)\n", ble_adv_evt);
           	break;
   }
}

This happens most often after flashing the application - it will not start advertising (only after 2-4 reset cycles)

I am looking for the root cause of that because I am not sure it will happen only after flashing, and I surely don't want to solve it with a patch.

BTW,

I tried to start to advertise in a loop (some kind of while until I get the 1st event) but after 8 retires still adv didn't start (only resetting the device 2-4 times solved this)

Best regards,

Erez.

 

Parents
  • Hello Erez,

    Can you please provide more debugging information? Have a look at this introduction on error handling. Also, see the documentation on error module and debug logger.

    Kind regards,
    Øyvind

  • Hi Øyvin

    As you can see at my augu_ble_start_advertising function,

    I check for error codes and print them, this function also returns the err_code, that I check after the function returns.

    There are no errors return in the cases were the adv. is not happening, the only indication I can see besides the actual lack of adv. is the lack of adv. events as I explained in my original message.

    BR,

    Erez

    err_code = augu_ble_start_advertising();
    APP_ERROR_CHECK(err_code);

  • As these functions (e.g. AUGU_LOG_PRINTF_WRN) are not Nordic, have you verified that they work?

    What do you mean with 2-4 resets? Do you mean manually pressing reset 2-4 times? What kind of board are you running? 

    Have you tried debugging your code using any type of IDE, i.e. step through code to see where it hangs? Try using break-points to see if it reaches correct functions.

    Did you read this blog post on migration to peer manager?

  • Hi Øyvin

    AUGU_LOG_PRINTF_WRN is verified, and so as the other envelop functions.

    Regarding the scenario, I will explain some more:

    1. App+Softdevice is flashed to the board

    2. The app starts to run, after a few seconds, it's time for the application to start advertising.

    3. I call augu_ble_start_advertising  to start the advertisement

    4. Nothing happens (no advertising, no error and no adv. events)

    5. I reset the board using nrfjprog --reset -f nrf52 and follow up again until advertising actually happens, this usually requires 2-4 resets cycles

    6. From this point on, the board successfully advertise further on.

    I have noticed another thread: link to the thread but there it happened because of the freertos.

    Regarding the debugging, Yes I have tried to debug and follow up the code and i couldn't see any abnormal behavior, the application actually doesn't hang (it's just not performing the adv. request)

    My feeling is that it's related to the PM & softdevice somehow.

    I would like to continue and investigate to reach to a proper solution and I will be happy to share more explanation/code if that will be required.

    BR

    Erez.

  • The reset issue you are describing could indicate an issue with Fstorage. You will need to call:

    // Forward Softdevice events to the fstorage module
    fs_sys_event_handler(sys_evt);
    

    Have a look at the ble_app_gls example and the following function:

    void ble_advertising_on_sys_evt(uint32_t sys_evt)
    {
        uint32_t err_code = NRF_SUCCESS;
        switch (sys_evt)
        {
    
            case NRF_EVT_FLASH_OPERATION_SUCCESS:
            // Fall through.
    
     
    
            //When a flash operation finishes, advertising no longer needs to be pending.
            case NRF_EVT_FLASH_OPERATION_ERROR:
                if (m_advertising_start_pending)
                {
                    m_advertising_start_pending = false;
                    err_code = ble_advertising_start(m_adv_mode_current);
                    if ((err_code != NRF_SUCCESS) && (m_error_handler != NULL))
                    {
                        m_error_handler(err_code);
                    }
                }
                break;
    
     
    
            default:
                // No implementation needed.
                break;
        }
    }

    If you have this in your project, please check that the m_advertising_start_pending flag is cleared. This can be the cause of why your code is hanging in an advertisement. 

    My best advice is to upgrade your SDK, as v11.0 is very outdated. 

    Another thing to check, not related to your issue, since you have an old version is ERRATA 108.

  • Hi Øyvin

    As you nicely caught, I was missing a call in the sys_evt_dispatch to the fs_sys_event_handler

    it seemed to be solved the issue.

    I will run further tests to be sure.

    Thank you very much Øyvin

    BR

    Erez Shaul

  • Hi Erez, 

    Very glad to hear! Let me know if you meet any further issues Slight smile

    Kind regards,
    Øyvind

Reply Children
No Data
Related