Quality RTOS & Embedded Software

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


Silicon Labs EFM32 Low Power RTOS Demo
Using Simplicity Studio (GCC), and Targeting Giant and Pearl Gecko Starter Kits
[RTOS Ports]

EFM Pearl Gecko ARM Cortex-M4 Starter Kit
EFM32 Pearl Gecko Starter Kit SLSTK3401A

EFM Giant Gecko ARM Cortex-M4 Starter Kit
EFM32 Giant Gecko Starter Kit STK3700


Introduction

The demo applications documented on this page target EFM32 ARM Cortex-M3 and ARM Cortex-M4F microcontrollers from Silicon Labs.

Two Simplicity Studio (GCC) projects are provided, one that is preconfigured to target the EFM32 Giant Gecko Starter Kit (STK3700), and one that is preconfigured to target the EFM32 Pearl Gecko Starter Kit (SLSTK3401A).

Both projects can be used to build either a comprehensive test and demo application, or a low power demo application that makes use of the FreeRTOS tick suppression capability (tickless idling). Three EFM32 specific tickless idle implementations are provided: an implementation that uses the RTC peripheral on the Giant Gecko, an implementation that uses the BURTC peripheral also on the Giant Gecko, and an implementation that uses the RTCC peripheral on the Pearl Gecko.



IMPORTANT! Notes on using the EFM32 RTOS demo

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

  1. Source Code Organisation
  2. The RTOS 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 official FreeRTOS zip file download contains the source files for all the RTOS ports, and all the demo applications, only a few of which are needed by the EFM32 Gecko projects. See the Source Code Organization section for a description of the downloaded files and information on creating a new project.

The Simplicity Studio project for the Silicon Labs EFM32 Giant Gecko STK3700 demo application is located in the FreeRTOS/Demo/CORTEX_EFM32_Giant_Gecko_Simplicity_Studio directory.

The Simplicity Studio project for the Silicon Labs EFM32 Pearl Gecko SLSTK3401A demo application is located in the FreeRTOS/Demo/CORTEX_EFM32_Pearl_Gecko_Simplicity_Studio directory.

These are the directories that should be selected when importing the projects into a Simplicity Studio Eclipse workspace.



The EFM32 Gecko RTOS Demo Applications

Hardware set up

The demo uses the LED built onto the EFM32 Gecko Starter Kit Boards, so no hardware setup is required.


Functionality

The RTOS demo projects can be configured to build either a simple lower power tickless project, or a comprehensive test and demo project. The constant configCREATE_LOW_POWER_DEMO, which is defined at the top of FreeRTOSConfig.h, is used to switch between the two. The following table describes the project that will be built for all valid configCREATE_LOW_POWER_DEMO values for both the Pearl and Giant Gecko projects.


EFM32 Giant Gecko Demo
Setting Project Built
0 The comprehensive test and demo application will be built.

1 The simple low power tickless demo will be built with the following parameters:
  • The tick is generated by the BURTC peripheral.
  • Energy mode 3 (EM3) is entered.
  • The ULFRCO clock is used.

The tickless idle implementation that uses the BURTC peripheral is contained in the low_power_tick_management_BURTC.c source file.

Note that using the ULFRCO clock has the benefit of very low power operation at the expense of accurate timing.

2 The simple low power tickless demo will be built with the following parameters:
  • The tick is generated by the RTC peripheral.
  • Energy mode 2 (EM2) is entered.
  • The LXFO clock is used.

The tickless idle implementation that uses the RTC peripheral is contained in the low_power_tick_management_RTC.c source file.

EFM32 Pearl Gecko Demo
Setting Project Built
0 The comprehensive test and demo application will be built.

1 The simple low power tickless demo will be built with the following parameters:
  • The tick is generated by the RTCC peripheral.
  • Energy mode 2 (EM2) is entered.
  • The LXFO clock is used.

The tickless idle implementation that uses the RTCC peripheral is contained in the low_power_tick_management_RTCC.c source file.


Functionality when ( configCREATE_LOW_POWER_DEMO == 0 )

If configCREATE_LOW_POWER_DEMO is set to 0 then main() will call main_full(). main_full() is implemented in the main_full.c C source file.

main_full() creates a comprehensive test and demo application that demonstrates:

Most of the tasks created by the comprehensive demo are from the set of standard demo tasks. Standard demo tasks are used by all RTOS port demo applications. They have no specific functionality, and are created just to demonstrate how to use the FreeRTOS API, and test the RTOS port.

In addition to the standard demo tasks the comprehensive demo creates "RegTest" tasks, and a 'Check' task:

  • The RegTest tasks

    The two RegTest tasks fill all the CPU registers with unique values, then check that the values do not change throughout the lifetime of the task. A register containing an unexpected value is indicative of an error in the context switch mechanism (or a user error if the demo has been modified).

  • The Check task.

    The check task is responsible for checking the RegTest and standard demo tasks are executing as expected, and indicating the system status by toggling an LED.

    If the LED is toggling every 3 seconds, then the check task has not discovered any problems. If the LED is toggling every 200 milliseconds, then the check task has discovered a potential problem in at least one task.


Functionality when ( configCREATE_LOW_POWER_DEMO != 0 )

If configCREATE_LOW_POWER_DEMO is set to 1 or 2 then main() will call main_low_power(). main_low_power() is implemented in the main_low_power.c C source file. See the table above for valid configCREATE_LOW_POWER_DEMO settings for both the EFM32 Giant and Pearl Gecko demos respectively.

main_low_power() creates a queue, a "queue send" task, and a "queue receive" task. It then starts the scheduler.

  • The Queue Send task

    The queue send task sends the value 100 to the queue every second.

  • The Queue Receive task

    The queue receive task blocks on the queue, blipping (quickly turn on then off again) the LED each time it received the value 100 from the queue send task. The queue send task writes to the queue every second, so the LED will blip once a second.

The two tasks spend most of their time in the Blocked state, during which the RTOS tick is turned off, and either energy mode 2 (EM2) or energy mode 3 (EM3) is entered, depending on the configuration.


Building and executing the demo application

Note: The Simplicity Studio Eclipse project uses virtual and linked paths to reference files from outside of the project directory, and might not build if the directory structure has been changed.
  1. Ensure you have Giant and/or Pearl Gecko starter kit support included in your Simplicity Studio installation, otherwise the project will fail to build. Support for additional EFM32 devices and starter kits can be installed using the Simplicity Studio menus.

  2. Start Simplicity Studio and either select an existing or create a new workspace when prompted.

  3. Select "Import" from the Simplicity Studio IDE's "File" menu. The dialogue box shown below will appear. Select "Existing Projects into Workspace".

    Importing the low power Cortex-M4 RTOS demo into simplicity studio


  4. In the next dialogue box, select /FreeRTOS/Demo/CORTEX_EFM32_[part]_Gecko_Simplicity_Studio as the root directory, where [part] is either "Giant" or "Pearl". Then, make sure the RTOSDemo project is checked in the "Projects" area, and that the Copy Projects Into Workspace box is not checked, before clicking the Finish button (see the image below for the correct check box states, the finish button is not visible in the image).

    Importing the low power tickless RTOS demo into Eclipse


    The project source files will appear in the Eclipse project explorer window.

  5. Open FreeRTOSConfig.h, and set configCREATE_LOW_POWER_DEMO to generate either the tickless low power demo, or the full test and demo application, as required. Refer to the table above for valid settings.

  6. Ensure the target hardware is connected to the host computer using a suitable USB cable.

  7. Select "Build All" from the Simplicity Studio "Project" menu to build the application.

  8. After the build completes, select "Debug" from the Simplicity Studio "Run" menu to program the microcontroller flash and start a debug session.



RTOS Configuration and Usage Details

ARM Cortex-M3 and M4F FreeRTOS port specific configuration

Configuration items specific to this demo are contained in FreeRTOS/Demo/CORTEX_EFM32_[part]_Gecko_Simplicity_Studio/FreeRTOSConfig.h. The constants defined in this file can be edited to suit your application. In particular -
  • configTICK_RATE_HZ

    This sets the frequency of the RTOS tick interrupt. The setting used by this demo depends on the configCREATE_LOW_POWER_DEMO setting.

  • configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY

    See the RTOS kernel configuration documentation for full information on these configuration constants.

  • configLIBRARY_LOWEST_INTERRUPT_PRIORITY and configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY

    Whereas configKERNEL_INTERRUPT_PRIORITY and configMAX_SYSCALL_INTERRUPT_PRIORITY are full eight bit shifted values, defined to be used as raw numbers directly in the ARM Cortex-M NVIC registers, configLIBRARY_LOWEST_INTERRUPT_PRIORITY and configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY are equivalents that are defined using just the 3 priority bits implemented in the EFM32 NVIC. These values are provided because the CMSIS library function NVIC_SetPriority() requires the un-shifted 3 bit format.

Attention please!: See the page dedicated to setting interrupt priorities on ARM Cortex-M devices. Remember that ARM Cortex-M cores use numerically low priority numbers to represent HIGH priority interrupts. This can seem counter-intuitive and is easy to forget! If you wish to assign an interrupt a low priority do NOT assign it a priority of 0 (or other low numeric value) as this will result in the interrupt actually having the highest priority in the system - and therefore potentially make your system crash if this priority is above configMAX_SYSCALL_INTERRUPT_PRIORITY. Also, do not leave interrupt priorities unassigned, as by default they will have a priority of 0 and therefore the highest priority possible.

The lowest priority on a ARM Cortex-M core is in fact 255 - however different ARM Cortex-M microcontroller manufacturers implement a different number of priority bits and supply library functions that expect priorities to be specified in different ways. For example, on Silicon Labs ARM Cortex-M microcontrollers, the lowest priority you can specify is in fact 7 - this is defined by the constant configLIBRARY_LOWEST_INTERRUPT_PRIORITY in FreeRTOSConfig.h. The highest priority that can be assigned is always zero.

Each port #defines 'BaseType_t' to equal the most efficient data type for that processor. This port defines BaseType_t to be of type long.


Interrupt service routines

Unlike many FreeRTOS ports, interrupt service routines that cause a context switch have no special requirements, and can be written as per the compiler documentation. The macro portYIELD_FROM_ISR() can be used to request a context switch from within an interrupt service routine.

Note that portYIELD_FROM_ISR() will leave interrupts enabled.

The following source code snippet is provided as an example. The interrupt uses a direct to task notification to synchronise with a task (not shown), and calls portYIELD_FROM_ISR() to ensure the interrupt returns directly to the task if the task has an equal or higher priority than the interrupted task.

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 direct to task notification is used for this purpose.
    Note lHigherPriorityTaskWoken is initialised to zero. */
    vTaskNotifyGiveFromISR( xTaskHandle, &lHigherPriorityTaskWoken );

    /* If the task referenced by the xTaskHandle handle was in the Blocked state
    waiting for a notification then calling vTaskNotifyGiveFromISR() will have
    moved the task into the Ready state.  If the task was moved into the Ready
    state, and the task's priority is higher than the priority of the currently
    executing task (the task this interrupt interrupted), then
    lHigherPriorityTaskWoken will have been set to pdTRUE internally within
    vTaskNotifyFromISR().  Passing pdTRUE into the portYIELD_FROM_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
    portYIELD_FROM_ISR() has no effect. */
    portYIELD_FROM_ISR( lHigherPriorityTaskWoken );
}

Only FreeRTOS API functions that end in "FromISR" can be called from an interrupt service routine - and then only if the priority of the interrupt is less than or equal to that set by the configMAX_SYSCALL_INTERRUPT_PRIORITY configuration constant (or configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY).


Resources used by FreeRTOS

When configCREATE_LOW_POWER_DEMO is set to 0 the standard FreeRTOS Cortex-M port is used, which requires exclusive use of the SysTick and PendSV interrupts. SVC number #0 is also used.

When configCREATE_LOW_POWER_DEMO is set to 1 exclusive access to the RTC, RTCC or BURTC peripheral is required - depending on the configuration.


Memory allocation

Source/Portable/MemMang/heap_4.c is included in the ARM Cortex-M demo application project to provide the memory allocation required by the RTOS kernel. The comprehensive demo also demonstrates RTOS objects being created using statically allocated, rather than dynamically allocated, memory. Please refer to the Memory Management section of the API documentation for full information.


Miscellaneous

Note that vPortEndScheduler() has not been implemented.





[ 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