2024-10-03 05:57 AM
Current working device
For a client we developed a device using stm32F469 that writes sensor data to an sd-card periodically. Later the data are read out from sd-card by connecting it via USB to a computer, using USBD_MSC_CLASS. The system uses FreeRTOS, FatFS, ST USB driver. This works well (using blocking write and read commands to SDIO). The two paths to access the sd-card (from the MCU software using FatFS and the access from Windows using USB driver from ST) is separated by the MCU software, using init and de-init functions of the modules.
New approach
Now I wanted to transfer it to Azure RTOS using ThreadX, FileX, UsbX. The access to SDIO shall be done with DMA (fx_stm32_sd_write_blocks() calls BSP_SD_WriteBlocks_DMA()). The interrupt callbacks from SDIO (transfer completed) are rerouted with callback functions, depending on who (FileX or UsbX) accesses the sd-card.
However this does not work with the following issues:
sd_write_data(..){
[..]
status = fx_stm32_sd_write_blocks(FX_STM32_SD_INSTANCE, (UINT *)media_ptr->fx_media_driver_buffer, (UINT)start_sector, num_sectors);
if (status == error){..}
FX_STM32_SD_WRITE_CPLT_NOTIFY(); /* --> This calls tx_semaphore_put(&transfer_semaphore); */
tx_thread_sleep(10); /* --> delay added as workaround */
[..]
}
fx_stm32_sd_write_blocks(..){
[..]
if (BSP_SD_WriteBlocks((uint32_t *)buffer, start_block, total_blocks, 2000) != MSD_OK) { ret = 1; }
FX_SD_WriteCpltCallback(); /* --> this function is (should be) called by ISR when using DMA.
It executes: tx_semaphore_put(&transfer_semaphore);
return ret;
}
==> So looks like having issues with synchronization and threads...
Questions that possibly help:
Thanks for any support!
2024-10-08 03:05 AM
Hello @Led,
Could you please share your project files so we can analyze and assist you more effectively?
2024-10-08 08:52 AM
Unfortunately it is a client project and I cant share it. What I can provide is parts of the code, without the sensitive parts. Still I dont want to publish it. I'll send you a post with the access data.
2024-11-26 12:11 AM
Unfortunately I still waste a huge amount of time to find a fix.
Let me ask a simplified question:
What are reasons for SDIO_FLAG_CTIMEOUT in SDMMC_GetCmdResp1?
Especially with the focus using SDIO with DMA, FileX and USBX together.
As my implementation sometimes (seldom) works, I assume synchronization and priority issues.
2024-11-26 01:01 AM
Hello @Led
The flag SDIO_FLAG_CTIMEOUT is set when a command response is not received within the expected time frame.
The Command TimeOut period has a fixed value of 64 SDIO_CK clock periods. Please refer to the reference manual for more details.
2024-11-26 01:35 AM
Hi @Saket_Om
Thanks for your reply. The questions remains what are the reasons for it?
With debugger I see
- In SDMMC_CmdReadSingleBlock() a command is sent to SDIO
- Then SDMMC_GetCmdResp1() is blocking-waiting for an answer.
Why should the answer not come? Knowing that writing via USB works, but writing via FileX does mostly not work.