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


Cant get a simple SPI mutex to work..

Posted by Jon Newcomb on April 27, 2010
I'm having one of those days where I'm missing the blinding obvious..
Using FreeRTOS V5.3.0, IAR 5.41.2, JLink, AT91SAM7S256

We have lots of comms on a singe SPI port. I thought it sensible to convert my (old and working I hope) binary
semaphore to a (new and improved) mutex.
I have a global declaration..
static xSemaphoreHandle semaphore_spi_guard;

Simple.. change the line where it is initialised..

vSemaphoreCreateBinary (semaphore_spi_guard

semaphore_spi_guard = xSemaphoreCreateMutex(

As described in

It compiles..
#define configUSE_MUTEXES 1  in FreeRTOSConfig.h
is all present and correct.

The help says..
"Mutexes created using this macro can be accessed using the xSemaphoreTake() and xSemaphoreGive() macros"
Great.. I need not alter any of my code because this is the way I give and take my (old) binary SPI semaphore.

Reality was different..
I was disappointed to find every give or take of the mutex fails.. time to start investigating..
I put breakpoints in a few different locations..
This is when started to really scratch my head and get confused..


xQueueHandle xQueueCreateMutex( void

The following values are end up as follows:
pxNewQueue->pcWriteTo = NULL;
pxNewQueue->pcReadFrom = NULL;

.. OK, so unlike a queue, we don’t set these to the 'head' of a queue.. So far so good.

Then every time we come to give or take the mutex I arrive at xQueueGenericSend or xQueueGenericReceive.
The very first few lines perform a check that always fails - and I cant work out why it does the check and how it can pass..

This check is..

if (!pxQueue || !pxQueue->pcHead) // extended check for valid Queue
return errQUEUE_UNDEF;

Well of course it fails with
I get back to my give / take mutex having don’t nothing and returning a fail..
Please help.. I’m very confused!

Jon Newcomb

RE: Cant get a simple SPI mutex to work..

Posted by Richard on April 27, 2010
I don't think there has ever been an error code errQUEUE_UNDEF, so can only assume that you are not using an official version of FreeRTOS, or that somebody at your end has added this code. Try comparing your queue.c to one from the official release - although your version is not up to date you can still download all the previous versions from SourceForge.


RE: Cant get a simple SPI mutex to work..

Posted by Jon Newcomb on April 28, 2010
That is indeed correct, and as I suspected, obvious. Thankyou.

[ 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