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


Use of vTaskSuspendAll on hardware access?

Posted by Benjamin Meier on February 9, 2012
Hi all,

I am running FreeRTOS successfully on a STM32F103CBT6 using Keil uVision.

I use the SPI from two different tasks. To ensure only one task is accessing the SPI at a time i use a Mutex.
So far so good.

From the flash.c-file of the demonstration i got the following function.

void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
unsigned portSHORT usBit;

if( uxLED < partstMAX_OUTPUT_LED )
usBit = partstFIRST_LED << uxLED;

if( usOutputValue & usBit )
usOutputValue &= ~usBit;
usOutputValue |= usBit;

GPIO_Write( GPIOC, usOutputValue );

I am wondering about the use of the SuspendAll / ResumeAll calls. What exactly are they for in this application? I see two possible explanations.

1) To ensure no other task is currently accessing the usOutputValue-variable.
2) To ensure no other task is currently calling the GPIO_Write-function.

I think the GPIO_Write-function shouldn't be the reason, there is no read modify-write operation in the function.

void GPIO_Write(GPIO_TypeDef* GPIOx, u16 PortVal)
GPIOx->ODR = PortVal;

When exactly do I need to use such a "critical section" ?

Thanks for clearing my confusion.


RE: Use of vTaskSuspendAll on hardware access?

Posted by Richard on February 11, 2012
usOutputValue is a file scope variable, so you are correct in your assumption that it protects against multiple access of the usOutputValue variable.


[ 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