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

Issue reading SD card from within a Gatt connection

Hi,

I am using a NRF58240-dk pca10056 S140. 

I have an external SD card device connected which, I am writing live sensor data to then advertising that data over a ble advertisement packet. I also have the code functionality to have a GATT connection. When I connect to the nordic board the "live data advertisement" stops and the GATT connection is made. I then have a custom service which I can write and receive data from using the NRF connect app. I can see the data received from this connection and handle it via a statemachine within the on_write function within my custom code.

The issue I have is when I try to call the command to read the sd card the code locks up and does not run. It goes to the reading state and starts to read the SD card however, it is unable open to file but, this is due to the fact to code is in the default wait function within diskio_bledev.c. 

static void default_wait_func(void)
{
__WFE();
}//Stops here

How do I stop this? 

Within the fatfs example I have the exact same code to read the data and it works but, the main loop has __WFE(); looped within it. So within my code I added the __WFE(); in the idle state handle routine and tried just running __WFE();. I also tried using sd_app_evt_wait(); Neither of which got out of the default wait function. I tried sd_app_evt_wait due to a forum post about issues with __WFE() and the soft device. My code is based off of the ble_app_template example. I can also read the SD card if I call the function before my main loop then run __WFE(). So I think its something to do with priorities / GATT connection.

Please help.

Also below is my code for reading some data of the CSV file

void SD_CARD_Read_Line()
{
    UINT bytesRead;//From sd card driver library
    static FATFS fs;
    static DIR dir;
    static FILINFO fno;
    static FIL file;

    uint32_t bytes_written;
    FRESULT ff_result;
    DSTATUS disk_state = STA_NOINIT;
    
    NRF_LOG_INFO("Reading SD CARD data");
    char data[100]={0}; /* Line buffer */
    unsigned int ByteRead = 0;

    ff_result = f_open(&file, FILE_NAME, FA_READ);
    if (ff_result != FR_OK)
    {
        NRF_LOG_INFO("Unable to open or create file: " FILE_NAME ".\r\n");
        return;
    }

    uint16_t size = f_size(&file) ;
    NRF_LOG_INFO("size of the file in bytes = %d\r\n",size);

    ff_result = f_read(&file,data,100, &ByteRead);

    if (ff_result != FR_OK)
    {
        NRF_LOG_INFO("Unable to read or create file: " FILE_NAME ".\r\n");
        return;
    }
    else if(ff_result == FR_OK)
    {
      NRF_LOG_INFO("%d bytes read\r\n",ByteRead);
      NRF_LOG_INFO("Data is : %s\r\n", (uint32_t) data);
    }
    else
    {
      NRF_LOG_INFO("Error operation\r\n");
    }
    (void) f_close(&file);
}

Related