2017-07-25 07:28 AM
Stm32L476 Fatfs using DMA mode
https://community.st.com/tags♯/?tags=stm32l476
https://community.st.com/tags♯/?tags=sdmmc%20dma%20stm32l4
https://community.st.com/tags♯/?tags=dma
https://community.st.com/tags♯/?tags=sdmmc
https://community.st.com/tags♯/?tags=micro%20sd%20card
Hi
We checked the stm32 examples for l476 from the
STM32Cube_FW_
L4_V1.8.0\Projects\STM32L476G_
EVAL\Applications\FatFs\FatFs_
uSD\ archive.
We would like to change Fatfs read/write mode from polling to DMA. Is there any online solution or example that we can use?
#dma #sdmmc-dma-stm32l4 #sdmmc #micro-sd-card #stm32l4762017-08-08 07:42 AM
The FatFS doesn't guarantee word-aligned access to intermediate buffers natively and the DMA requires them because SDMMC uses word access, thus the two are incompatible.
The FatFS would need to align the buffers to allow it.
2017-08-16 05:41 AM
Posted on August 16, 2017 at 14:41
Hello EDISON!
Are you mean that I need keep read and write buffers as described below:
externuint8_tretSD; /* Return value for SD */
externcharSD_Path[]; /* SD logical drive path */
FATFSfs __attribute__((aligned(4)));
FILfp__attribute__((aligned(4)));
charname[] = 'test.txt';
//#define BUFFER_SIZE 0x40000
[DEFINE] BUFFER_SIZE 0x40000
charbuffer[BUFFER_SIZE] __attribute__((aligned(4)));
It doesn't help with sample from
STM32Cube_FW_
L4_V1.8.0\Projects\STM32L476G_
EVAL\Applications\FatFs\FatFs_
uSD\ archive.
I receive the same problems as without aligning. Are you mean that we need change code of FATFS also?
Do you have any really working project with SD WRITE and SD READ by DMA chanel for STM32L476 processor.
The short status of my project is:
I tried produce very simple project for uSD card communication by CubeMx.
The project was generated in the POLLING Mode SD communication and write and read functions working properly.
I tried to change POLLING to DMA write read mode. Now it is impossible to open file , because I received error.
The cause of error is : Impossible to find FAT on the SD card.
I compared this project to base sample from
STM32Cube_FW_L4_V1.5.0/Projects/STM32L476G_EVAL/Applications/FatFs/FatFs_uSD/.
It is mostly the same. The CubeMx produce this code slightly optimized.
I return to sample from
STM32Cube_FW_L4_V1.5.0/Projects/STM32L476G_EVAL/Applications/FatFs/FatFs_uSD/.
I produced a lot of changes in this code and tried to work in the DMA mode. I produced TX and RX across different DMA chanels somethings like described in the SDIO+DMA+FatFS+CubeMX.pdf document for STM32F7 processor.
Now I have DMA_read working quite well. It is mean that I can read 2G file by chanks of 8kBytes without great problems. The DMA_write process working properly till writings block has less 1024 bytes long. If more or equal 1024 bytes then write error occure quickly. As usial it is CRC error. I can't understand what is reason that i can't write blocks more then 1023 bytes.
I need DMA write and read communication, because my main application can't wait for POLLING mode.
I can send to you my partially working project for analyze also.
2017-08-29 10:16 AM
Hi Edison,
you wrote:
>The FatFS doesn't guarantee word-aligned access to intermediate buffers natively and the DMA requires them because >SDMMC uses word access, thus the two are incompatible.
You mean 'SDMMC in STM32L4 is not compatible with FatFs'?
Because in F4 it works excellent!
2017-08-31 12:29 AM
Posted on August 31, 2017 at 07:29
Hello ALEX!
STM32l4 compatible to FatFs!
I was startinf my project with write data to SD card in the polling mode.
It is working without problem.
I added interrupt from timer. Timer working background and produce it's
interrupt during SD writing process.
I received a first problem:
The write to SD card function return with SD write error.
Ok. I decided to try write to CD in the DMA mode. I find STM32Cube_FW_
L4_V1.8.0\Projects\STM32L476
<https://community.st.com/0D70X000006SvS1SAK
G_EVAL\Applications\FatFs\FatFs_uSD\ archive sample and starts working with
it.
I produced changing in this project for DMA using, then I changed one DMA
for receive and transmit to verious DMA for transmit and receive.
The results was:
1. It is possible to read any blocks of information in the DMA mode.
2. It is possible to write any numbers of blocks with size less than 1024
bytes. If block's equal or more 1024 bytes after some blocks writing
received SD_WRITE error.
I tried produce the same project with DMA using by CubeMx application.
Write and read in the polling mode working properly but read or write
produce SD_WRITE error immediately.
I feel that SD card block of STM32L4 has problems with DMA using. I can't
receive clear explanation from ST support.
You are absolutely right. STM32F4 and STM32F7 processors working properly
with SD card in DMA mode.
2017-08-31 01:08 AM
�?¢�?°�?¼ ALEX.001.�?¢ - Ñ�Ñ‚�?¾ Ñ�
Regards,
Alex.
On Thu, Aug 31, 2017 at 8:30 AM, vladimir boretsky <
2017-09-04 11:04 AM
The FILE structure has issues with alignment, not only FS buffers. Thus you won't get it solved easily.
I'd suggest intermediate buffer in the SD card driver and memcpy between thelocations.
Never tried, though, just an idea.