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
..
..
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 driveand disk accesses will be directed to the appropriate i/o functions.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.