Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Freertos / Fatfs with hot card detection

Posted by tabulous2011 on 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 ?


Freertos / Fatfs with hot card detection

Posted by xz8987f on October 16, 2013

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/


Freertos / Fatfs with hot card detection

Posted by tabulous2011 on October 16, 2013

Nowhere on the links is there any description on how this would be achieved


Freertos / Fatfs with hot card detection

Posted by xz8987f on 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 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


Freertos / Fatfs with hot card detection

Posted by tabulous2011 on 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

FAT1MountFileSystem FAT1UnMountFileSystem


Freertos / Fatfs with hot card detection

Posted by xz8987f on 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.


Freertos / Fatfs with hot card detection

Posted by tabulous2011 on 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 ?


Freertos / Fatfs with hot card detection

Posted by xz8987f on 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.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS