cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX Multi-Drive Support with FatFS

Karan 123
Senior
Posted on May 16, 2018 at 10:46

Hello,

I have STM32F7 discovery kit (Discovery kit with STM32F746NG MCU) . I have successfully tested microSDCard with

Keil + STM32Cube able to Create/read/Write txt files.

I have also through UM1721 'Developing Applications on STM32Cube with FatFs'

STM32F746NG MCU has one only SDMMC interface .

So I have selected STM32F722VET6 (LQFP-100 Pins) with two SDMMC Interfaces.

My requirement is How I can access two microSDCard Simultaneously .

I want to copy the data from one SDCard to another SDCard ( or SPI Flash Memory or USB MSD).

1) How do I configure and access Multi-Drive Support with FatFS ( Different  volume name or numbers)  with STM32CubeMX ?

2) Can I configure and access FATFS with SPI Interface on  any STM32 MCU with STM32Cube ?

Thanks in advance

Karan
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on May 18, 2018 at 15:59

Hi

Singh.Gurpreet

,

1) How do I configure and access Multi-Drive Support with FatFS (Differentvolume name or numbers)with STM32CubeMX?

Within CubeMX, toaccess to your two microSD Card simultaneously,you should first enable SDMMC1, SDMMC2 and FatFS. Then, on the generated code, you can handle both SD cards by indicatingthe drive numberin the path name. Here is an example hoping it helps you:

FIL f_src, f_dst;

f_open(&f_src, '0:srcfile.txt', FA_CREATE_ALWAYS |FA_READ);

f_open(&f_dst, '1:dstfile.txt', FA_CREATE_ALWAYS | FA_WRITE);

2) Can I configure and access FATFS with SPI Interface onany STM32 MCU with STM32Cube?

You can access to your SD card using SPI interface and enabling FatFs (user-defined within CubeMX). Unfortunately, most examples, that serve communication with SD card, use SDIO rather than SPI because of communication speed problem.

For more details about SPI & FATFS configuration to connect your SD card, Please refer to the following discussion

:

https://community.st.com/thread/44247-cubemx-support-for-sdfatfsspi#comment-184565

It would be more efficient and functional to connect your SD card using SDIO, when it is allowed. You can refer to many examples in the firmware thathelp you:

\STM32Cube\Repository\STM32Cube_FW_F7_V1.0\Projects\STM32F722ZE-Nucleo\Applications\FatFS\FatFs_uSD

3) How function like(

/external-link.jspa?url=http%3A%2F%2Felm-chan.org%2Ffsw%2Fff%2Fdoc%2Fchdir.html

) is used to access Volume Name/No. ?

The f_chdir function is used tochange the current working directoryof the current drive.

f_chdir('1:/dir1/dir2');

You can refer to this link to get more explication and details about this function

http://elm-chan.org/fsw/ff/doc/chdir.html

Best Regards,

Mohamed.

View solution in original post

7 REPLIES 7
Posted on May 16, 2018 at 13:40

It might exceed the complexity of what CubeMX can achieve, you might need to construct the code manually by using the existing SDMMC examples and creating a second instance of the pin/peripheral configuration.

FatFs would need additional settings/options to create support for multiple drives/volumes, and you would need code to enumerate directories and copy between systems.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Karan 123
Senior
Posted on May 16, 2018 at 19:22

Hello Clive One,

Thanks for update..

I am go through below thread .

https://community.st.com/0D50X00009XkXEPSA3

My current code for one SDMMC Mode is

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_SDMMC1_SD_Init();

MX_FATFS_Init();

FATFS myFATFS;

FIL myFILE ;

UINT testByte ;

if(f_mount(&myFATFS,SD_Path, 0) == FR_OK)

{

char mypath[] = {'abc.txt\0'} ;

f_open(&myFILE,mypath , FA_WRITE | FA_CREATE_ALWAYS) ;

char mydata[] = {'Hello\0'} ;

f_write(&myFILE, mydata , sizeof(mydata),&testByte ) ;

f_close(&myFILE) ;

}

But how and where I can drive number. ?

'You can pass the drive number in the path name or change the default drive with f_chdrive.'

--

Karan

Posted on May 17, 2018 at 07:11

http://elm-chan.org/fsw/ff/doc/filename.html

 

'0:/driveone.txt'

'1:/drivetwo.txt'

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Karan 123
Senior
Posted on May 18, 2018 at 06:56

Thanks for Update Clive One..

Like below example ..

'0:/driveone.txt'

'1:/drivetwo.txt'

I have go thorough link provided by you ..

1) How function  like((

http://elm-chan.org/fsw/ff/doc/chdir.html

)  is used to access Volume Name/No. ?

2) How Cube Generated code which understand  to Read/Write from Volume Name/No.

Thanks..

Karan

Posted on May 18, 2018 at 15:59

Hi

Singh.Gurpreet

,

1) How do I configure and access Multi-Drive Support with FatFS (Differentvolume name or numbers)with STM32CubeMX?

Within CubeMX, toaccess to your two microSD Card simultaneously,you should first enable SDMMC1, SDMMC2 and FatFS. Then, on the generated code, you can handle both SD cards by indicatingthe drive numberin the path name. Here is an example hoping it helps you:

FIL f_src, f_dst;

f_open(&f_src, '0:srcfile.txt', FA_CREATE_ALWAYS |FA_READ);

f_open(&f_dst, '1:dstfile.txt', FA_CREATE_ALWAYS | FA_WRITE);

2) Can I configure and access FATFS with SPI Interface onany STM32 MCU with STM32Cube?

You can access to your SD card using SPI interface and enabling FatFs (user-defined within CubeMX). Unfortunately, most examples, that serve communication with SD card, use SDIO rather than SPI because of communication speed problem.

For more details about SPI & FATFS configuration to connect your SD card, Please refer to the following discussion

:

https://community.st.com/thread/44247-cubemx-support-for-sdfatfsspi#comment-184565

It would be more efficient and functional to connect your SD card using SDIO, when it is allowed. You can refer to many examples in the firmware thathelp you:

\STM32Cube\Repository\STM32Cube_FW_F7_V1.0\Projects\STM32F722ZE-Nucleo\Applications\FatFS\FatFs_uSD

3) How function like(

/external-link.jspa?url=http%3A%2F%2Felm-chan.org%2Ffsw%2Fff%2Fdoc%2Fchdir.html

) is used to access Volume Name/No. ?

The f_chdir function is used tochange the current working directoryof the current drive.

f_chdir('1:/dir1/dir2');

You can refer to this link to get more explication and details about this function

http://elm-chan.org/fsw/ff/doc/chdir.html

Best Regards,

Mohamed.

Karan 123
Senior
Posted on May 20, 2018 at 15:09

Hello,

Many of Thanks for update ...

I have ordered  

http://www.st.com/en/evaluation-tools/nucleo-f722ze.html

 . I will check you suggestion then update 

with in few days.

One more question If there direct function() in FATFS to

copy the files( 

txt, bmp more then 4MB)

from one SDCard to another SDCard.

http://irtos.sourceforge.net/FAT32_ChaN/doc/en/open.html

 

Thanks again ..

--

Karan

Posted on May 20, 2018 at 15:16

No, you'd need to enumerate through the directories, and copy the file data manually. This is more application level functionality, not file system level.

Basically using f_opendir(), f_readdir(), and then a copy function using f_open(), f_size(), f_read/write(), f_close(). You should probably allocate a large copy buffer to maximize transfer speed. Say 32KB, and then read/write buffer until all file content is processed. If you want attributes and time/date stamps to follow you'll need to manage that also.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..