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


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