Quality RTOS & Embedded Software

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


Loading

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

Posted by sof-diceytech on June 8, 2017

Hi,

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 */

FF_BlockRead(xSDCard->pxIOManager,...);

} ~~~

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 );
NVIC_EnableIRQ( SDIO_IRQn );

} ~~~

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 ]    [ Privacy ]    [ Sitemap ]    [ ]


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner