Quality RTOS & Embedded Software

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


FreeRTOS and Atmel SAM4S SPI with several CS's

Posted by goldie13 on December 16, 2013


I am using the freertos SPI API from ASF. In the freertos spiwrite/spiread packets, the API uses the DMA and also gives the ability to pass a semaphore to be notified on transfer completion. So, if using several tasks and each task can communicate via the same SPI but on different CS, I need to modify the freertos spiread/spiwrite functions so it will first acquire the semaphores, then change the CS with “spisetperipheralchipselect_value”, and then configuring the PDC… right? This is because it is not one atom operation, and I don’t want that one task will change the CS and before it will transmit, it will switch to another task that will, again chge to a different CS, then it will switch back to the first task that will start transmitting, but now to the wrong CS… Is this correct?

Thank you, Assaf

FreeRTOS and Atmel SAM4S SPI with several CS's

Posted by rtel on December 16, 2013

I just looked at the demos that come with the driver and they appear to be setting the CS lines manually. The driver has two semaphores/mutexes, one to obtain access to the port and one to be notified of when the operation on the port is complete - is that the case? If so then it is only the semaphore used to get access to the port that prevents you from using the driver unmodified I think, and I would try to avoid modifying the driver.

You could provide your own access mutex so the operation would be as follows.

  1. Create an access mutex in your application.
  2. Open the SPI port using the driver but don't configure it to use an RX mutex, as you already have one in your application.
  3. When a task wants access to the SPI have it first obtain the access mutex within your application, rather than in the driver.
  4. Once access is obtained, set the CS as you require, then use the driver again. You can provide a notification mutex if you wish - just make sure that when the transfer is complete your application gives back the access mutex.


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

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

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

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

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


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





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