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

Cortex-M3 allocating memory before scheduler start locks interrupts

Posted by smith84 on December 5, 2013

I am running FreeRTOS 7.4.0 on a Cortex-M3 processor (no MPU).

My initialisation code creates a timer before the OS start, and after the call to xTimerCreate() the BASEPRI is set to block interrupts - this causes other problems in my startup routines.

I have managed to trace the code as follows (showing what I think are the relevant parts only!):

  • xTimerCreate()
    • pvPortMalloc()
    • vTaskSuspendAll()
      • xTaskResumeAll()
      • taskENTER_CRITICAL(): this increments the uxCriticalNesting counter which was at the init value of 0xaaaaaaaa to 0xaaaaaaab
        • portDISABLE_INTERRUPTS(): sets BASEPRI to block interrupts
      • taskEXIT_CRITICAL(): this decrements uxCriticalNesting back to 0xaaaaaaaa which is greater than 0 so it does not call portENABLE_INTERRUPTS()

This mess with uxCriticalNesting is all fixed up when the scheduler is started and uxCriticalNesting is set to 0.

My understanding is that I should be able to create timers and tasks etc before the scheduler is started. However, with this call tree it seems that any call for these types of operations will block the interrupts below the OS masking level.

Any suggestions as to what I can try to resolve this problem? I could simply modify the initialisation value of uxCriticalNesting but that doesn't seem to be the right thing to do.


Cortex-M3 allocating memory before scheduler start locks interrupts

Posted by rtel on December 5, 2013

This behaviour is completely intentional and the reason why the critical nesting count is never initialised to 0. It is done like this to prevent interrupts attempting to use RTOS API functions before the RTOS has been started - if an interrupt attempted a context switch when the kernel is not running the system would crash. If the crash is caused by an interrupt the user may not understand what has happened.

If you can guarantee this is not going to happen in your system then you can initialise the critical nesting variable to 0 instead of whichever non-zero value is used.

Regards.


Cortex-M3 allocating memory before scheduler start locks interrupts

Posted by smith84 on December 5, 2013

Thanks for the quick reply. With that information I know that I can work around the problem by using busy-wait loops until the scheduler is started.


[ 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