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

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