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


STM32F4xx __disable_interrupt issue when using SafeRTOS

Posted by franchise98bjn on June 12, 2014

I have an issue when I call the taskENTERCRITICAL() function to prevent RTOS preemption after I have called the STM32F4xx intrinsic function __disableinterrupt().

The processor goes to the HardFaultHandler() function after it processes the taskENTERCRITICAL() function. The function call sequence is shown below. It is executed from the RTOS IDLE task.

static void prvIdleHook( void ) { vTaskSuspendScheduler(); // Suspend scheduler

__disable_interrupt();  // Disable all interrupts on the ARM

taskENTER_CRITICAL(); // Goes to the HardFault_Handler() after this call

(Task critical code here)



xTaskResumeScheduler(); // Resume scheduler


STM32F4xx __disable_interrupt issue when using SafeRTOS

Posted by heinbali01 on June 12, 2014


I'm not sure why it gives a fault, but when calling taskENTERCRITICAL(), it isn't necessary to also call __disableinterrupt().

The function of taskENTER_CRITICAL() is to disable interrupts and it keeps a count (uxCriticalNesting) of how many times a critical section was entered.

taskEXITCRITICAL() decreases that count and when it reaches zero, interrupts will be switched on again. So you can just leave out "__disableinterrupt()"


STM32F4xx __disable_interrupt issue when using SafeRTOS

Posted by rtel on June 13, 2014

As Hein has already mentioned, if you have a double critical section, which means much of your code is obsolete (doesn't do anything useful) anyway, but further to that:

1) It is not recommended to manipulate the interrupt settings in the core other than through the use of the FreeRTOS API. The enter/exit critical macros manage nesting of critical sections, whereas your calls to _disable/enableinterrupt() don't.

2) _disable/enableinterrupt() will globally disable interrupts, which in many applications is a bad thing. The enter/exit critical macros will only mask interrupts up the the user set configMAXSYSCALLINTERRUPT_PRIORITY priority, leaving higher priority interrupt completely unaffected by running FreeRTOS.

3) As a general rule, FreeRTOS API functions should not be called when the scheduler has been suspended. This rule can be relaxed if you are an expert user only (that is, if you understand what the API functions are doing and how not being able to perform a context switch during their execution will have).


STM32F4xx __disable_interrupt issue when using SafeRTOS

Posted by rtel on June 15, 2014

I've just noticed your question is in relation to SafeRTOS, not FreeRTOS - in which case you can discount my last answer.

This forum does not provide support for SafeRTOS.


[ 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