nRF5 SDK  v14.0.0
Choose documentation:
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Blinky RTC FreeRTOS Example

The Blinky RTC FreeRTOS example shows how to properly use hardware interrupts with FreeRTOS.

When the application starts, two GPIO pins are configured using the BSP module as outputs to drive the LEDs. Then, a new thread is started.

From the created thread, RTC is configured to generate an interrupt. Task negates the LED 1 state and starts waiting for the semaphore that will be set from an RTC interrupt.

The example presents the correct interrupt runtime construction that should be used with FreeRTOS:

  • Inside the RTC interrupt, a semaphore is given using the function with the FromISR postfix.
  • This kind of function takes a pointer to the value that shows if a higher priority task has woken.
  • This variable must be initialized to pdFALSE.
  • Just before ISR processing finishes, portYIELD_FROM_ISR must be called.

Because of the Cortex-M functionality of PendSV, this function can be also called in the event handler that is not the real last instruction in the current ISR. It can be also called multiple times - the task scheduler will be processed only once, when all the interrupts have been processed.

Setup

You can find the source code and the project file of the example in the following folder: <InstallFolder>\examples\peripheral\blinky_rtc_freertos

LED assignments:

  • LED 1 - Blinking from the task.
  • LED 2 - Blinking form the RTC ISR.

Testing

Test the Blinky RTC FreeRTOS Example application by performing the following steps:

  1. Compile and program the application.
  2. LED 1 and LED 2 blink alternately.
Note
See FreeRTOS support for more information about FreeRTOS.