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


Tasks are blocking on xSemaphoreTake

Posted by Roland Rabien on February 25, 2013

I'm new to FreeRTOS and I'm trying to get what I think is a fairly simple project going, and I'm having problems with tasks blocking indefinitely on xSemaphoreTake. I'm using a Atmel Sam3u4e with Atmel Studio 6 SP2 and FreeRTOS 7.3.0 that ships with the Atmel Software Framework 3.5.1.

I have reduced my program to the minimal parts to reproduce the problem. I have two tasks, loggertask and systask. loggertask is woken by one of three data ready interrupts, and then uses spi to read from either a accelerometer, gyro or magnetometer. systask does nothing but wait on a semaphore that is never given.

I create loggertask from systask like this:

#define LOGGERTASK_STACK_SIZE((4 * 1024)/sizeof(portSTACK_TYPE))

if (xTaskCreate(loggertask_entry_point, name, LOGGERTASK_STACK_SIZE, loggertask, LOGGERTASK_PRIORITY, &loggertask->task) == pdPASS)
return loggertask;

The main loop looks like this:

static void loggertask_entry_point(void* pvParameters)
LoggerTask* loggertask = (LoggerTask*)pvParameters;

xSemaphoreTake(loggertask->sync, 0);
while (true)
if (xSemaphoreTake(loggertask->sync, 100) == pdTRUE)
if (loggertask->magReady)

if (loggertask->accelReady || ioport_get_pin_level(PIN_MEMS_INT_ACCEL) == IOPORT_PIN_LEVEL_HIGH)

if (loggertask->gyroReady || ioport_get_pin_level(PIN_MEMS_INT_ACCEL) == IOPORT_PIN_LEVEL_HIGH)

if (!loggertask->record)

And my interrupts look like:

void loggertask_accel_int(uint32_t a, uint32_t b)
g_loggertask->accelReady = true;
loggertask_wake(g_loggertask, true);

void loggertask_gyro_int(uint32_t a, uint32_t b)
g_loggertask->gyroReady = true;
loggertask_wake(g_loggertask, true);

void loggertask_mag_int(uint32_t a, uint32_t b)
g_loggertask->magReady = true;
loggertask_wake(g_loggertask, true);

void loggertask_wake(LoggerTask* loggertask, bool fromISR)
if (fromISR)
portBASE_TYPE taskWoken = pdFALSE;
xSemaphoreGiveFromISR(loggertask->sync, &taskWoken);

As for my systask, it is very simple, I create it like this:

#define SYSTASK_STACK_SIZE((4 * 1024)/sizeof(portSTACK_TYPE))

if (xTaskCreate(systask_entry_point, name, SYSTASK_STACK_SIZE, systask, SYSTASK_PRIORITY, NULL) == pdPASS)
return systask;

And it's loop looks like this:

static void systask_entry_point(void* pvParameters)
SysTask* systask = (SysTask*)pvParameters;



while (true)
xSemaphoreTake(systask->sync, 250);


The systask_service_logger function creates the loggertask 1 second after the system starts and does nothing else. Future plans are for the systask will take data from the loggertask and write it to an sdcard.

After approximation 10 minutes of runtime, the loggertask hangs on xSemaphoreTake(). The interrupts are still firing, but the call to xSemaphoreGiveFromISR() fails with a errQUEUE_FULL. systask is still running. No breakpoints I set in loggertask ever get hit. FreeRTOS Viewer lists the logger task as Ready with a top of stack 0x2007eea0 and start of stack 0x2007df38. IDLE is running and sys and Tmr Svc are blocked. Removing the calls to read the accelerometer, gyro, magnetometer does not solve the problem, so I loggertask must be getting stuck in xSemaphoreTake().

Is there any way to force a context switch to loggertask so I can examine it's callstack? Where do I look to see if loggertask->sync is corrupted.

My program is very simple, so I must be doing something fairly basic incorrectly. Can anybody see what it is?


RE: Tasks are blocking on xSemaphoreTake

Posted by Roland Rabien on February 26, 2013
And it turns out I should read the FAQ more carefully. There is a whole document on interrupt priorities. Anyway, I wasted a lot of time, but at least I'm moving forward again.

RE: Tasks are blocking on xSemaphoreTake

Posted by Richard on February 26, 2013
Self solving support requests are the best kind ;o)


[ 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