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

f_write/f_close cause BLE disconnect

Hardware: nrf52832

SDK: 16.0.0 with FreeRtos, 

Softdevice: S132 7.0

I set configMAX_PRIORITIES to 5 and modified nrf_sdh_freertos_init to set BLE task priority to 4.

My sd card maintain task priority is set to 2.

For BLE NUS service:

#define MIN_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS) /**< Minimum acceptable connection interval (20 ms), Connection interval uses 1.25 ms units. */
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS) /**< Maximum acceptable connection interval (75 ms), Connection interval uses 1.25 ms units. */
#define SLAVE_LATENCY 0 /**< Slave latency. */
#define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) /**< Connection supervisory time-out (4 seconds). */

The NUS service and SD card function works fine when test them separately. But if Operate SD card during NUS connection, I got disconnect with reason:0x8

I have tried to enlarge INTERVAL to 120ms/175ms, also tried to change SLAVE_LATENCY to 4. Problem still exist.

I searched internet and NRF Dev Zone, found some similar question, but none of them can resolve my problem. So I have to raise a new question here. 

 

  • Hi

    Yes, you're right. I mixed up the priorities. I'm really sorry about that, but it's been some time since I have looked at FreeRTOS. And I guess that rules out that the radio is interrupted by the SD card tasks due to priorities. One thing that's worth mentioning. The default SPI settings use standard drive for the SCK and MOSI pins, so it might be worth checking if these need to be set to high drive. Something like the configuration below should do the trick:

        nrf_gpio_cfg(SCK_PIN,
                     NRF_GPIO_PIN_DIR_OUTPUT,
                     NRF_GPIO_PIN_INPUT_DISCONNECT,
                     NRF_GPIO_PIN_NOPULL,
                     NRF_GPIO_PIN_H0H1,       // Require High Drive low/high level
                     NRF_GPIO_PIN_NOSENSE);

    Best regards,

    Simon

  • Dear Simonr:

         Thank you very much for mention about SPI pin setting. I will check it. And does this pin setting can affect BLE connection?

    And I guess that rules out that the radio is interrupted by the SD card tasks due to priorities

     And for "SD card task" , do you mean my own task (which conduct sd card operation) or there is another system level tasks to handle SD card? For my own task, I have already checked. It's priority is lower than BLE task. 

    Is there any demo code for using SD card with BLE connection together successfully?

  • Hi

    Please get back to me with the results of the SPI pin setting test.

    As for "SD card task", I was referring to your own task, as I initially thought you had given the SD card task higher priority than the BLE and MAX_PRIORITIES tasks, but that's my bad.

    You can check out this case, where my colleague has combined the ble_app_uart and fatfs example to write all strings received over BLE to an SD card. I was unable to find a BLE + SD card example that also uses FreeRTOS, so if you want/need to use FreeRTOS you can use Jørgen's example as a template or reference.

    Best regards,

    Simon

  • Dear Simonr:

      1, As you mentioned, SPI Pin setting in my code is S0S1

      2, I modified the setting to H0H1 and the SPI operation still cause BLE disconnect

      3, Thank you very much for provide the reference link. I think the demo code should be very helpful. I will try it ASAP

  • Dear Simonr:

        The demo code need SDK14. My current version is 16. So I need download corresponding environment. Since the network speed is very slow. I am afraid I can not test the demo today. I will report result later.

Related