Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists