Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

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..
from

vSemaphoreCreateBinary (semaphore_spi_guard
);
to

semaphore_spi_guard = xSemaphoreCreateMutex(
);

As described in
http://www.freertos.org/a00121.html
http://www.freertos.org/CreateMutex.html

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..

in

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
errQUEUE_UNDEF
.
I get back to my give / take mutex having don’t nothing and returning a fail..
Please help.. I’m very confused!

Thanks,
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.

Regards.

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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner