I trying to connect SD-card in 1bit mode to Stm32l4 via FatFS+SDIO interface. Code automaticaly generated by CubeMX 5.0. DMA enabled and configured in Cube. When i call FatFS func like f_mount() or f_open(), i get FR_DISK_ERR return statement. Low level read returns by DMA_Timeout. Please, help me.
1 Answers
So to start with, you should probably look at the documentation from ST on how to exactly get the process tree moving with the SD card. I know with USB, you have to call the host process and wait for the state of the host to be active before any FATFS calls can be made. Make sure you are covering your ground waiting for the hardware interrupts to trigger a presence.
Something similar to the effect of, just make sure to have a timeout parameter for if the case of the SD not mounting.
// stateOfHost will change depending on the cube generated code, but it should be somewhere in the SD Card code
extern ApplicationTypeDef stateOfHost;
// Set the default state to idle
ApplicationTypeDef stateOfHost = APPLICATION_IDLE;
while(1)
{
// Start USB Host Process
MX_USB_HOST_PROCESS();
if(stateOfHost == HOST_USER_CLASS_ACTIVE)
{
// FATFS Can now be called
}
}
If all else fails after that, this may sound a bit bizarre, but try increasing the default stack size. The DMA timeout is appearing, because the callback for the disk is not being called. There was no data to be filled. Trying to debug through this implementation of the FATFS is a nightmare.
The USB OTG and the SD card FATFS third party middleware have issues if the stack size is not increased past the default setting which is at 0x400.
Inside of the file startup_stm32l4(xx)xx.s (The two x's in parenthesis are for your variant of the L4), change the stack size to something suitable. To start with, try 0x1000.
I have had similar issues and needed to increase the stack size to 0x3000 in order to get my USB to work.
If the SD is recognized, make sure to make variables to keep track of all your FATFS calls to make sure the whole way it is successful.
In order to read via the FATFS you must: 1. Mount a workspace (f_Mount) 2. Open a file (f_open) 3. Read the file open (f_read)
Writing is done the exact same, just swapped with the read call.
Hopefully this helps.