Quality RTOS & Embedded Software

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


PIC32 Bug - vTaskEnterCritical()?

Posted by Mark Samarin on December 7, 2012
When the scheduler is not running, vTaskEnterCritical() sets the system priority to 4.
But vTaskExitCritical() does not restore the priority to the previous state when the scheduler is off.

So if these functions are called with the scheduler off, you end up with a different priority and possibly many missing hairs from your head!!! Since the uChip USB functions set the ISR IPL to 4 (in code, not just the ISR header) this effectively disables the USB interrupt.

RE: PIC32 Bug - vTaskEnterCritical()?

Posted by MEdwards on December 7, 2012
This is a deliberate ploy for all the ports, not just PIC32. Once you start calling FreeRTOS functions interrupts are left disabled to ensure an interrupt that tries a context switch cannot happen. Interrupts are reenabled automatically when the scheduler starts.

RE: PIC32 Bug - vTaskEnterCritical()?

Posted by Mark Samarin on December 16, 2012
This confuses me a bit. Isnt the whole idea of the EnterCritical()/ExitCritical functions to provide control when a context switch can occur? If the scheduler has not started yet, what type of context switch would be harmful? To leave the CPU in a different state when finishing the call set seems wrong IMO.

I modified the ExitCritical function to restore the priority because I have some things that must run before and during the scheduler running. Are you suggesting that this is unsafe?

RE: PIC32 Bug - vTaskEnterCritical()?

Posted by Dave on December 16, 2012
It is only unsafe if:

1) You install and enable an interrupt.
2) The interrupt handling function executes and uses a FreeRTOS API function that modifies the state of the FreeRTOS kernel (which has not yet been initialized) or attempts a context switch (when the kernel has not been initialized).

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

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.


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


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