Quality RTOS & Embedded Software

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


Task Critical blocks USB

Posted by Royston Dsouza on October 10, 2011
I am using free RTOS on STM32 hardware which I have designed. There is an STM32F103RG MCU connected to an accelerometer (MMA8415Q), gyroscope(L3G2400D) and USB. The accelerometer is ineterfaced on I2C and Gyroscope on SPI. For the accelerometer and gyroscope routines I use taskENTER_CRITICAL and taskEXIT_CRITICAL during the I2C and SPI access. At the beginning of the program I just read the accelerometer and Gyroscope device ID registers. After this I go ahead and init the USB section for using VCOM.

If I read the accelerometer and Gyrocope registers, the USB is not enumerated by Windows and says Windows cannot recognise device.
If i comment out the taskENTER_CRITICAL and taskEXIT_CRITICAL from the accelerometer and Gyroscope routines then the Windows enumerated USB properly.

Can anyone advise on the above problem.



RE: Task Critical blocks USB

Posted by Dave on October 10, 2011
You are asking about application design, not really FreeRTOS, but if the critical section is preventing interrupts that are needed to enumerate the USB then the critical section must be very very long, which is never good. If there is only one device on I2C and one device on SPI, then I doubt a critical section is needed around the whole access, and suspect it will only be needed around the access of any registers that are shared by the two serial buses. You might have better luck using scheduler locking, which will leave interrupts enabled, or making the USB interrupt above configMAX_SYSCALL_INTERRUPT_PRIORITY if it does not make any FreeRTOS API calls.

RE: Task Critical blocks USB

Posted by Royston Dsouza on October 10, 2011
Thank you davedoors for your reply.

I have configured the USB priority to be above the SYSCALL priority. Please find code snippet as below.

void USB_Interrupts_Config(void)
NVIC_InitTypeDef NVIC_InitStructure;

NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 14;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

And my FreeRTOS SYSCALL priority is as follows:

/* This is the raw value as per the Cortex-M3 NVIC. Values can be 255 (lowest) to 0 (1?) (highest). */

#define configMAX_SYSCALL_INTERRUPT_PRIORITY 191 /* equivalent to 0xa0, or priority 5. */

/* This is the value being used as per the ST library which permits 16 priority values, 0 to 15. This must correspond to the
configKERNEL_INTERRUPT_PRIORITY setting. Here 15 corresponds to the lowest NVIC value of 255. */


I am a bit confused with the priority setting here. Does the FreeRTOS scheduler use priority 15 or does it use priority 5 as stated above.

Thanks in advance


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

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

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

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

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


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

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

Xilinx Microblaze and Zynq partner