DISK READ FAILURE

Hi,

I am working on a project where MP3 files from SD card are fetched and played when play button is pressed.

I am configuring buttons as interrupt mode and when the button is pressed the play flag is set in the interrupt handler.

Also, a timer is running for every 1 second and in the timer handler the play flag, pause flag etc, are monitored and play_mp3() function is called inside the handler.

The mp3 file in sd card is opened by f_open() function to read the file. when it is trying to read disk the busy flag is not setting to false

DRESULT disk_read(BYTE drv, BYTE *buff, DWORD sector, UINT count)
{
ASSERT(m_drives);

if ((drv >= m_drives_count) || (!count))
{
return RES_PARERR; // Invalid parameter(s).
}

if ((m_drives[drv].config.p_block_device == NULL)
|| (m_drives[drv].state & STA_NOINIT))
{
return RES_NOTRDY; // Disk not initialized.
}

const nrf_block_req_t req = {
.p_buff = buff,
.blk_id = sector,
.blk_count = count
};

m_drives[drv].busy = true;
ret_code_t err_code = nrf_blk_dev_read_req(m_drives[drv].config.p_block_device, &req);

if (err_code == NRF_SUCCESS)
{
while (m_drives[drv].busy)
{
m_drives[drv].config.wait_func();
}

if (m_drives[drv].last_result == NRF_BLOCK_DEV_RESULT_SUCCESS)
{
return RES_OK;
}
}
return RES_ERROR;
}

The function then sets the busy flag of the drive to true, indicating that the read operation is in progress. It then calls nrf_blk_dev_read_req(), a function provided by the Nordic SDK, to initiate the read operation.

If the read request is successfully initiated, the function enters a while loop that checks the busy flag of the drive. The wait_func() function, provided by the FatFs library, is called to wait for the read operation to complete.

But the busy flag is not setting false.

Thanks 

  • Hi Ajmal,

    Thank you for contacting DevZone at NordicSemi.

    I can see that in the disk_read() function you are explicitly setting the busy flag as true, and then calling nrf_blk_dev_read_req() function.

    This function is used for block read request. In synchronous mode this function will execute the read operation and wait for its completion.

    However, in an asynchronous mode the function will only request the operation and return immediately.

    Then, the NRF_BLOCK_DEV_EVT_BLK_READ_DONE event will signal that operation has been completed and the specified buffer contains valid data.

    You should be checking this event and then resetting the flag.

    Regards,

    Naeem

  • Thanks for your reply, 

    I can see that in the disk_read() function you are explicitly setting the busy flag as true, and then calling nrf_blk_dev_read_req() function.

    I am not setting it by my side rather it is already given in the code in fatfs example.

  • I think we are not on the same page somehow.

    Here in the fat_fs sample source code, I do not see any function call to disk_read().

    Neither I find this function in the header / include files.

    Can you explain more please or let me know how to produce the error/problem you are facing.

    Regards,

    Naeem

Related