Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Enable SoftDevice s140 without enabling BLE

Hi DevZone,

I am working on an application using:

  • nRF52840
  • FreeRTOS v10.0.0.0
  • nRF SDK v17.1.0
  • S140 v7.2.0

My question is if it is possible to enable the S140 without enabling any BLE functionality. BLE will be enabled later in project development, but for now I have to make sure that the RF-antenna is inactive.

I still need access to microcontroller temperature and non-volatile memory controller (nrf_fstorage.h) which are accessed through s140 when the stack is present on the microcontroller, hence it cannot be completely disabled.

Br. Casper

  • Hi Casper

    Yes, enabling the SoftDevice without configuring or running the Bluetooth stack is OK. 

    Just make sure to avoid accessing peripherals that are protected by the SoftDevice, such as the radio, TIMER0 or RTC0. 

    Best regards
    Torbjørn

  • Hi Torbjørn,

    Thank you for getting back to me.

    I have some more questions:

    • Does a complete list of peripherals that are protected by the SoftDevice exist, perhaps even with more examples of what not to access?

    • Is it true that even though the SoftDevice is enabled with nrf_sdh_enable_request() that I cannot access any of the protected peripherals as long as the BLE part of the SoftDevice is disabled?

    • Does an example exist of how to configure the SoftDevice without configuring the Bluetooth stack?

    I am currently having an unstable build after disabling my Bluetooth stack. Symptoms of instability that I am seeing is a sudden fail of all writes to my SD-card which is connected to SPIM3. As soon as the BLE stack is enabled with nrf_sdh_ble_default_cfg_set() and nrf_sdh_ble_enable(), it works. I am suspecting that I am either accessing a resource that is SoftDevice protected, or that I am "initializing the SoftDevice without BLE stack" incorrectly.

    Br. Casper

    Edit: Clarification.

  • Hi Casper

    Casper Kronborg Pedersen said:
    Does a complete list of peripherals that are protected by the SoftDevice exist, perhaps even with more examples of what not to access?

    Yes, this is a part of the S140 SoftDevice Specification document, in the Hardware peripherals chapter. 

    Go here for the S140 v7.2.0 version. 

    Casper Kronborg Pedersen said:
    Is it true that even though the SoftDevice is enabled with nrf_sdh_enable_request() that I cannot access any of the protected peripherals as long as the BLE part of the SoftDevice is disabled?

    The peripheral protection mechanism is not tied in any way to the Bluetooth functionality, it will be enabled as soon as the SoftDevice is enabled. 

    The peripherals listed as "Restricted" in the SoftDevice specification can still be accessed indirectly, but using the corresponding SD API (such as the TEMP and RNG peripherals). 

    The only way to access blocked peripherals when the SoftDevice is enabled is to request a timeslot. In timeslots you can do more or less whatever you like, as long as you make sure to end the timeslot in time. 

    Casper Kronborg Pedersen said:
    Does an example exist of how to configure the SoftDevice without configuring the Bluetooth stack?

    I don't think we have an example specifically for this, but you could just take any BLE example and remove the BLE related init functions, such as the GAP initialization and the service initialization. 

    All you want to remain is the stack init function, which is typically one of the first setup functions in the examples. 

    Casper Kronborg Pedersen said:
    As soon as the BLE stack is enabled with nrf_sdh_ble_default_cfg_set() and nrf_sdh_ble_enable(), it works.

    You mean to say that just enabling the SoftDevice is enough, or you need to enable BLE as well? 

    When you build a project with a SoftDevice then some drivers might switch to using SoftDevice API's to access certain hardware resources, since they are then managed by the SoftDevice, but I am not sure why the SD card driver would have to do this. I am currently out of office, but can take a look at the driver when I am back. 

    Best regards
    Torbjørn

  • Hi Torbjørn,

    The peripheral protection mechanism is not tied in any way to the Bluetooth functionality, it will be enabled as soon as the SoftDevice is enabled. 

    Thank you for clearing that up. Then it seems what I am trying to achieve is definitely possible.

    The only way to access blocked peripherals when the SoftDevice is enabled is to request a timeslot. In timeslots you can do more or less whatever you like, as long as you make sure to end the timeslot in time. 

    I checked out the list of restricted and blocked peripherals, and I don't see any conflicts with what I am doing. I am also making sure to use the SD API when accessing any functionality from restricted peripherals (TEMP, NVMC, CLOCK and POWER in my case).

    I don't think we have an example specifically for this, but you could just take any BLE example and remove the BLE related init functions, such as the GAP initialization and the service initialization. 

    All you want to remain is the stack init function, which is typically one of the first setup functions in the examples. 

    Just to be clear, the "stack init function" you are mentioning here is the code below like in the usbd_ble_uart_freertos_pca10056_s140 example?:

    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Enable BLE stack.
        err_code = nrf_sdh_ble_enable(&ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Register a handler for BLE events.
        NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
    }

    It looks like the nrf_sdh_ble_default_cfg_set() function of the code above is setting configurations for the BLE stack as well as the nrf_sdh_ble_enable() function actually enabling the BLE stack. It is when I remove these two function calls from my own project, but keep the nrf_sdh_enable_request() call, that I experience issues.

    I think I also need to call nrf_sdh_freertos_init(advertising_start, NULL) to handle any events from the SoftDevice when running FreeRTOS?
    But this is also starting advertising on BLE which I need to avoid at the moment. This makes me wonder if what I am trying to do is possible while running FreeRTOS?

    I am not sure why the SD card driver would have to do this. I am currently out of office, but can take a look at the driver when I am back. 

    That sounds good, thank you!

    Br. Casper

  • Hi Casper

    Casper Kronborg Pedersen said:
    Just to be clear, the "stack init function" you are mentioning here is the code below like in the usbd_ble_uart_freertos_pca10056_s140 example?:

    That's the one, yes. 

    Casper Kronborg Pedersen said:
    It looks like the nrf_sdh_ble_default_cfg_set() function of the code above is setting configurations for the BLE stack as well as the nrf_sdh_ble_enable() function actually enabling the BLE stack. It is when I remove these two function calls from my own project, but keep the nrf_sdh_enable_request() call, that I experience issues.

    Thanks for the clarification. Do you also have nrf_sdh_freertos_init() in place in this case? If so it makes sense that it wouldn't work. 

    I would expect you to be able to enable the SoftDevice without configuring the BLE parameters as long as you don't try to use any BLE functions later on (such as starting advertising). 

    Casper Kronborg Pedersen said:
    I think I also need to call nrf_sdh_freertos_init(advertising_start, NULL) to handle any events from the SoftDevice when running FreeRTOS?

    I don't have a lot of experience with FreeRTOS, but looking at the implementation of this function I agree with your assessment. 

    In normal applications SoftDevice events will be polled by a dedicated software interrupt, but when using FreeRTOS this will be handled by a task instead. It makes sense that you would get issues if you don't run this function, at least if the SoftDevice is doing something that would end up generating events. 

    Casper Kronborg Pedersen said:
    But this is also starting advertising on BLE which I need to avoid at the moment. This makes me wonder if what I am trying to do is possible while running FreeRTOS?

    You should be able to provide NULL in the call to nrf_sdh_freertos_init(..) rather than a pointer to the advertising_start function, then this argument will be ignored:

    nrf_sdh_freertos_init(NULL, &erase_bonds);

    As for the SD-card libraries I could not find any dependence on the SoftDevice in any of them. I assume you use app_sdcard.c, diskio_blkdev.c and the standard SPI drivers?

    Best regards
    Torbjørn

Related