Atmel SAMD20 ARM Cortex-M0+ Demo
FreeRTOS and FreeRTOS+CLI Built Using Atmel Studio and GCC
[RTOS Ports]


Atmel SAMD20 ARM Cortex-M0+ MCU
SAMD20 Xplained PRO

Introduction

This page describes a demo project that uses FreeRTOS and FreeRTOS+CLI on the SAMD20 Cortex-M0+ microcontroller from Atmel.

Commercial licenses for FreeRTOS+CLI are provided free to Atmel SAM users!

The project uses the FreeRTOS ARM Cortex-M0 GCC port, builds with the free Atmel Studio IDE (which uses the Visual Studio framework and includes a kernel aware FreeRTOS plug-in), and targets the very low cost SAMD20 Xplained Pro evaluation board.

The command line interface character input and output uses drivers provided by Atmel in their Atmel Software Framework (ASF).

A #define is used to switch the build between a simple blinky style application, and a comprehensive test and demo application that incorporates the FreeRTOS+CLI component.



The Atmel Studio IDE with Kernel Aware FreeRTOS Plug-in



IMPORTANT! Notes on using the SAMD20 ARM Cortex-M0+ Demo

Please read all the following points before using this RTOS port.

  1. Source Code Organisation
  2. The Demo Application
  3. RTOS Configuration and Usage Details
See also the FAQ My application does not run, what could be wrong?



Source Code Organisation

The FreeRTOS download contains the source code for all the FreeRTOS ports, so contains many more files than are needed by the SAMD20 demo. See the Source Code Organization section for a description of the directory structure.

The Atmel Studio solution file is called RTOSDemo.atsln, and is located in the FreeRTOS/Demo/CORTEX_M0+_Atmel_SAMD20_Xplained directory.



Building and Running the ARM Cortex-M0+ RTOS Application

  1. Open FreeRTOS/Demo/CORTEX_M0+_Atmel_SAMD20_Xplained/RTOSDemo.atsln in the Atmel Studio IDE.

  2. Locate the mainCREATE_SIMPLE_BLINKY_DEMO_ONLY definition at the top of main.c. Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to 1 to create the simple blinky demo, or 0 to create the comprehensive demo that also includes the command line interpreter.

  3. Select "Rebuild RTOSDemo" from the Atmel Studio "Build" menu (or press F7) to build the demo project.

  4. Connect a USB cable between the USB port on the SAMD20 Xplained Pro board and the host computer.

  5. Select "Start Debugging and Break" from the Atmel Studio "Debug" menu to program the microcontroller flash memory and start a debug session.


Demo Application Functionality

Functionality with mainCREATE_SIMPLE_BLINKY_DEMO_ONLY set to 1

Building with mainCREATE_SIMPLE_BLINKY_DEMO_ONLY set to 1 results in main() calling main_blinky(). The main_blinky() demo is described below.


Functionality with mainCREATE_SIMPLE_BLINKY_DEMO_ONLY set to 0

Building with mainCREATE_SIMPLE_BLINKY_DEMO_ONLY set to 0 results in main() calling main_full(). The main_full() demo is described below.



RTOS Configuration and Usage Details


Interrupt service routines

Interrupt service routines that cause a context switch have no special requirements. The macro portEND_SWITCHING_ISR() can be used to request a context switch from within an ISR.

Note that portEND_SWITCHING_ISR() will leave interrupts enabled.

A dummy interrupt handler called Dummy_IRQHandler() is provided at the end of main.c as a reference implementation. Dummy_IRQHandler() is also replicated below.

void Dummy_IRQHandler(void)
{
long lHigherPriorityTaskWoken = pdFALSE;

    /* Clear the interrupt if necessary. */
    Dummy_ClearITPendingBit();

    /* This interrupt does nothing more than demonstrate how to synchronise a
    task with an interrupt.  A semaphore is used for this purpose.  Note
    lHigherPriorityTaskWoken is initialised to zero. Only FreeRTOS API functions
    that end in "FromISR" can be called from an ISR! */
    xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken );

    /* If there was a task that was blocked on the semaphore, and giving the
    semaphore caused the task to unblock, and the unblocked task has a priority
    higher than the current Running state task (the task that this interrupt
    interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE
    internally within xSemaphoreGiveFromISR().  Passing pdTRUE into the
    portEND_SWITCHING_ISR() macro will result in a context switch being pended to
    ensure this interrupt returns directly to the unblocked, higher priority,
    task.  Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */
    portEND_SWITCHING_ISR( lHigherPriorityTaskWoken );
}

Note that the following lines are included in FreeRTOSConfig.h to map the FreeRTOS interrupt handler function names onto the CMSIS interrupt handler function names. This allows the linker scripts provided by the compiler tool vendors to be used without modification.

	#define vPortSVCHandler      SVC_Handler
	#define xPortPendSVHandler   PendSV_Handler
	#define xPortSysTickHandler  SysTick_Handler


RTOS port specific configuration

Configuration items specific to these demos are contained in FreeRTOS/Demo/CORTEX_M0+_Atmel_SAMD20_Xplained/RTOSDemo/src/config/FreeRTOSConfig.h. The constants defined in FreeRTOSConfig.h can be edited to meet the needs of your application. In particular -

Each port #defines 'BaseType_t' to equal the most efficient data type for that processor. All ARM Cortex-M0+ ports define BaseType_t to be of type long.

Note that vPortEndScheduler() has not been implemented.


Memory allocation

Source/Portable/MemMang/heap_4.c is included in the ARM Cortex-M0+ demo application project to provide the memory allocation required by the RTOS kernel. Please refer to the Memory Management section of the API documentation for full information.