FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [October 2013 Threads]
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 ?
Yes, I'm doing this unmount/mount based on card insert/removal.
See
http://mcuoneclipse.com/2012/07/30/fatfs-with-kinetis/
http://mcuoneclipse.com/2012/11/18/arduino-data-logger-shield-with-the-frdm-kl25z-board/
Nowhere on the links is there any description on how this would be achieved
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 PLHASSD_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)CLS1CMDHELP, CLS1_GetStdio(), CmdParserTable);
if PLHASSD_CARD
FAT1_Init();
endif
for(;;) {
if PLHASSD_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 FAT1CheckCardPresence(bool *cardMounted, byte drive, FATFS *fileSystemObject, const CLS1StdIOType io)
{
if (!(cardMounted) && FAT1isDiskPresent()) {
/* card inserted */
if (FAT1MountFileSystem(fileSystemObject, drive, io)==ERROK) {
*cardMounted = TRUE;
if (io!=NULL) {
CLS1SendStr((unsigned char)"File System mountedrn", io->stdOut);
}
} else {
return ERR_FAILED;
}
} else if (cardMounted && !FAT1isDiskPresent()) {
/* card removed */
if (FAT1UnMountFileSystem(drive, io)==ERROK) {
*cardMounted = FALSE;
if (io!=NULL) {
CLS1SendStr((unsigned char*)"File System unmountedrn", io->stdOut);
}
} else {
return ERRFAILED;
}
}
return ERROK;
}
Everything else is on GitHub:
https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/FRDM-KL25Z/Freedom_FatFS
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
FAT1MountFileSystem
FAT1UnMountFileSystem
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.
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 ?
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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.