hi all i am doing sdcard(spi) and usb in stm32 using fatfs .I did both separately and both are working properly.How do integrate both the functionality using same fatfs?
please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-12 10:17 PM
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-13 1:13 AM
There are the disk_read(), disk_write() etc functions that your projects provide, and fatfs calls these to handle the actual I/O requests. They each take a drive number as the first parameter, which is probably ignored in your projects.
Merge these functions to call the respective disk i/o functions according to the disk number parameter. E.g. you can rename disk_read() from one project to disk_read_sd, and the other one to disk_read_usb(), then write
DRESULT disk_read(BYTE pdrv,BYTE* buff,LBA_t sector,UINT count) {
switch(pdrv) {
case 0:
return disk_read_sd(pdrv,buff,sector,count);
case 1:
return disk_read_usb(pdrv,buff,sector,count);
}
// handle wrong drive number error here
}
Now you can use filenames starting with the drive number and a colon, e.g.
f_open(FIL *f1, "0:file1.txt", FA_READ); // opens a file on the SD card
f_open(FIL *f2, "1:file2.txt", FA_READ); // opens a file on the USB drive
and disk accesses will be directed to the appropriate i/o functions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-13 1:13 AM
There are the disk_read(), disk_write() etc functions that your projects provide, and fatfs calls these to handle the actual I/O requests. They each take a drive number as the first parameter, which is probably ignored in your projects.
Merge these functions to call the respective disk i/o functions according to the disk number parameter. E.g. you can rename disk_read() from one project to disk_read_sd, and the other one to disk_read_usb(), then write
DRESULT disk_read(BYTE pdrv,BYTE* buff,LBA_t sector,UINT count) {
switch(pdrv) {
case 0:
return disk_read_sd(pdrv,buff,sector,count);
case 1:
return disk_read_usb(pdrv,buff,sector,count);
}
// handle wrong drive number error here
}
Now you can use filenames starting with the drive number and a colon, e.g.
f_open(FIL *f1, "0:file1.txt", FA_READ); // opens a file on the SD card
f_open(FIL *f2, "1:file2.txt", FA_READ); // opens a file on the USB drive
and disk accesses will be directed to the appropriate i/o functions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-18 2:43 AM
you want to make your project to work as usbmsd ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-19 8:15 PM
yes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-19 10:58 PM
which controller you are using ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-19 11:01 PM
stm32 f107vc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-19 11:14 PM
Follow below steps
1)just configure sd card as you configure normally
2)select usb device as mass stroage class
3)regenerate code
after that you have to make some changes in one file "usbd_storage_if.c"
you have to make sd card configuration in above file also
Best of luck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-23 7:46 AM
Hi ,thanks for your advice..i did as you said..i am able to mount both drives and open ,read,write files in both drives...now i need to copy folders from pendrive to sd card..is it possible? .fatfs don't have copydirectory function..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-01-23 2:11 PM
Sometimes you have to write a few lines of code yourself...
Watch out for stack overflow while recursively copying deep directory structures.
