Quality RTOS & Embedded Software

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


Accessing SD Card via usb (MSC) under FreeRTOS+FAT

Posted by sof-diceytech on June 8, 2017


I am currently using freeRTOS and freeRTOS+FAT on a Hitex eval board (LPC4350).

I was trying to develop an application that exposes an SD Card via usb as a mass storage class. I am using lpcopen library and the MSC interface requires read and write functions. My current implementation uses the read and write function of the IOManager as follow:

~~~ usbtranslaterd(...) { /* Process the parameters */


} ~~~

With usbtranslaterd being the read callback function for the usb msc interface.

Now as part of the read process the application goes into the following function defined in ff_sddisk.c::

~~~ /* Sets up the SD event driven wakeup */ static void prvSDMMCSetupWakeup( void *pvInfo ) { uint32t *ulWaitStatus = ( uint32t * ) pvInfo;

/* Wait for IRQ - for an RTOS, you would pend on an event here with a IRQ
based wakeup. */
/*_RB_ Don't understand why this is spinning on a block time of 0.  Is it
really meant to be != pdFALSE? */
while( xSemaphoreTake( xSDCardSemaphore, 0 ) != pdFALSE )

NVIC_ClearPendingIRQ( SDIO_IRQn );
lSDIOWaitExit = 0;
Chip_SDIF_SetIntMask( LPC_SDMMC, *ulWaitStatus );

} ~~~

The xSemaphoreTake macro fails an assertion in when in goes into taskENTER_CRITICAL() in xQueueGenericReceive.

~~~ void vPortEnterCritical( void ) { portDISABLE_INTERRUPTS(); uxCriticalNesting++;

/* This is not the interrupt safe version of the enter critical function so
assert() if it is being called from an interrupt context.  Only API
functions that end in "FromISR" can be used in an interrupt.  Only assert if
the critical nesting count is 1 to protect against recursive calls if the
assert function also uses a critical section. */
if( uxCriticalNesting == 1 )
	configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );

} ~~~

configASSERT( ( portNVICINTCTRLREG & portVECTACTIVEMASK ) == 0 ); -> Fails

My first assumption is that I would need to handle the usb read/write callbacks as interrupts and therefore I would need to either defer the read to say a task (sending it the data via a queue for example) or have a FF_BlockReadfromISR.

  1. Is my assumption correct?
  2. I was wondering if there was a "preferred" way of implementing this from a freeRTOS point of view.

Cheers, Sof

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

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

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

FreeRTOS kernel V10.0.1 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