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

BLE stack re-initialize problem with FreeRTOS

How to correctly reinitialize the BLE stack when using FreeRTOS?


I can not find in the libraries where the task for the work of the stack under FreeRTOS is created.


Stopping the stack is successful, but here's a new initialization leads to a hardfall,

since FreeRTOS is running and the stack task most likely is not deleted when the stack is stopped.

For deinitialization I use the function - nrf_sdh_disable_request();

Problems with reinitialization have already been discussed in this thread - https://devzone.nordicsemi.com/support/214553

Parents
  • try this.

    remove heap_1.c and add heap_2.c file in your project. Since heap_1,c does not support deletion of heap memory needed to delete the task.

    add the below function in nrf_sdh_freertos.c

    void nrf_sdh_freertos_deinit()
    {
         // Use the handle to delete the task.
         if( m_softdevice_task != NULL )
         {
             vTaskDelete( m_softdevice_task );
         }
    }
    

    when you disable the softdevice delete the task along with disable

    nrf_sdh_disable_request();
    nrf_sdh_freertos_deinit();
    

    When you want to reenable the softdevice, then do the below

        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
        
        nrf_sdh_freertos_init(advertising_start, &erase_bonds);

    Should work fine .

  • It also depends on the context on when you are disabling the softdevice and when you want to enable it back.

    Small test on my side shows that this works fine, but i have tested it crudely in the idle handler like this

    void vApplicationIdleHook( void )
    {
        ret_code_t err_code;
      static uint32_t count = 0;
    #if NRF_LOG_ENABLED
         vTaskResume(m_logger_thread);
    #endif
      
      if (count++ == 0)
      {
            application_timers_stop();
        nrf_sdh_disable_request();
        nrf_sdh_freertos_deinit();
    
    
        ble_stack_init();
        
        application_timers_start();
        nrf_sdh_freertos_init(advertising_start, &erase_bonds);
      }
    
    }

  • Hello Susheel,

      Could you provide all the project file?

      I also try to enable and disable softdevice with  freeRTOS running.

      But, It doesn't work. I want to see what you changed.

      Thanks,

        Chongchun Moon

Reply Children
No Data
Related