system
(system)
October 16, 2013, 4:54pm
1
tabulous2011 wrote on Wednesday, October 16, 2013 :
I’ve got Fatfs running nicely with Freertos, but i would like to have the ability to have hot card detection, thus if the card is removed and new one added the file system is remounted.
Hi has anyone tried doing this ? If so did you do all the card management in a task of its own ?
xz8987f wrote on Wednesday, October 16, 2013 :
Yes, I’m doing this unmount/mount based on card insert/removal.
See
system
(system)
October 16, 2013, 7:11pm
3
tabulous2011 wrote on Wednesday, October 16, 2013 :
Nowhere on the links is there any description on how this would be achieved
xz8987f wrote on Wednesday, October 16, 2013 :
You would have to check the sources on GitHub
anyway, for your convenience, here is the important code:
FAT1_CheckCardPresence() does the magic:
static portTASK_FUNCTION(ShellTask, pvParameters) {
#if PL_HAS_SD_CARD
bool cardMounted = FALSE;
static FAT1_FATFS fileSystemObject;
#endif
unsigned char buf[48];
(void)pvParameters; /* not used /
buf[0] = ‘\0’;
(void)CLS1_ParseWithCommandTable((unsigned char )CLS1_CMD_HELP, CLS1_GetStdio(), CmdParserTable);
#if PL_HAS_SD_CARD
FAT1_Init();
#endif
for(; {
#if PL_HAS_SD_CARD
(void)FAT1_CheckCardPresence(&cardMounted,
0 /* volume */, &fileSystemObject, CLS1_GetStdio());
#endif
(void)CLS1_ReadAndParseWithCommandTable(buf, sizeof(buf), CLS1_GetStdio(), CmdParserTable);
FRTOS1_vTaskDelay(50/portTICK_RATE_MS);
LEDG_Neg();
}
}
Which is implemented as:
byte FAT1_CheckCardPresence(bool *cardMounted, byte drive, FATFS *fileSystemObject, const CLS1_StdIOType *io)
{
if (!(cardMounted) && FAT1_isDiskPresent()) {
/ card inserted */
if (FAT1_MountFileSystem(fileSystemObject, drive, io)==ERR_OK) {
cardMounted = TRUE;
if (io!=NULL) {
CLS1_SendStr((unsigned char )“File System mounted\r\n”, io->stdOut);
}
} else {
return ERR_FAILED;
}
} else if (cardMounted && !FAT1_isDiskPresent()) {
/ card removed */
if (FAT1_UnMountFileSystem(drive, io)==ERR_OK) {
cardMounted = FALSE;
if (io!=NULL) {
CLS1_SendStr((unsigned char )“File System unmounted\r\n”, io->stdOut);
}
} else {
return ERR_FAILED;
}
}
return ERR_OK;
}
Everything else is on GitHub:
https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/FRDM-KL25Z/Freedom_FatFS
system
(system)
October 17, 2013, 12:18pm
5
tabulous2011 wrote on Thursday, October 17, 2013 :
on Github there is very little source code, there is alot of *.src ??? i believe this is all PEX modules.
where can i find what these functions are doing, i.e what interaction with FatFS
FAT1_MountFileSystem
FAT1_UnMountFileSystem
xz8987f wrote on Thursday, October 17, 2013 :
These are simple wrappers the FatFS mount() and unmount().
The PEx module code for this module is here:
https://github.com/ErichStyger/mcuoneclipse/blob/master/Drivers/sw/FAT_FileSystem.drv
Search for MountFileSystem there.
I hope this helps.
system
(system)
October 17, 2013, 5:08pm
7
tabulous2011 wrote on Thursday, October 17, 2013 :
Erich thanks for that, all working nicely
i do have one other question, to ensure FatFs can be accessed from multiple tasks did you do anything else other than the mutex protection that is in syscall.c ?
xz8987f wrote on Thursday, October 17, 2013 :
That mutex protection is what I used.
But if you have other tasks acessing the bus (SPI) or pins to the SD card, then of course you need to add another layer of mutual exclusion.