The blinky project is a basic example that shows how to get a FreeRTOS project using the MCC Melody library. The MCC Melody generated project offers a seamless integration of the FreeRTOS kernel files and port files, by providing a basic project structure that can be used as a starting point for an RTOS application.
As a minimum, the blinky project will demonstrate how to use a FreeRTOS queue to pass a value between two tasks and toggling an LED each time the value is received.
The project is contained in a single source file (freertos_interface.c) as following:
- The main application loop creates one queue and two tasks, then starts the RTOS scheduler.
- The Queue Send Task is implemented by prvQueueSendTask(). It sends a fixed value (100) to the queue every 200 milliseconds.
- The Queue Receive Task is implemented by prvQueueReceiveTask(). It blocks on queue reads, unblocking and toggling an LED each time the message from the queue send task is received. The queue send task sends to the queue every 200 milliseconds, so the queue receive task leaves the Blocked state and toggles the LED every 200 milliseconds.
More details and code examples on the AVR128DA48 can be found at the following links:
- FreeRTOS™ pages
- FreeRTOS Demo for the Microchip AVR Dx Port
- AVR128DA48 Product Page
- AVR128DA48 Code Examples on GitHub
- MPLAB X IDE 6.20 or newer
- MPLAB XC8 2.46 or a newer compiler
- MPLAB Code Configurator (MCC) 5.7.1 or newer
- AVR-Dx 2.6.303 or newer Device Pack
- AVR Devices package 4.11.0 or newer
- FreeRTOS Library v2.0.1
- AVR128DA48 Curiosity Nano Evaluation Kit
The AVR128DA48 Curiosity Nano Evaluation Kit is used as test platform:
The following configurations must be made for this project:
- Add FreeRTOS library to the project.
- Configure the FreeRTOS application:
2.1 Select timer instance used as Tick Timer (TCB0 in this example).
2.2 Configure the desired Tick Rate.
2.3 Update the FreeRTOS configuration using the UI.
2.4 Enable GPIO pins used by the FreeRTOS application (GPIO0).
2.5 Select the corresponding pin used as GPIO0 by the FreeRTOS application (PC6, Curiosity NANO on-board LED0).
- Select the on-board LED (PC6) as GPIO0 pin that is used by the FreeRTOS library.
-
Generate the code using MCC Melody.
-
Add the demo application code in the
freertos_interface.c
file. -
For information about the programming the device, see the Operation section in this document.
Pin | Configuration |
---|---|
PC6 | Digital Output (LED0) |
In order to configure the toggling period for the on-board LED, the macro below can be modified. In the default case, this period is configured to 200 ms:
To program the Curiosity Nano board with this MPLAB X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.
The application toggles the on-board LED every 200 ms:
The result can be seen also by watching the signal with the logic analyzer:
This example shows how to use the FreeRTOS library to create a basic demo application that toggles the on-board LED (PC6) with a configurable period.
This chapter demonstrates how to use the MPLAB X IDE to program a AVR® device with an Example_Project.X. This is applicable to other projects.
-
Connect the board to the PC.
-
Open the
Example_Project.X
project in MPLAB X IDE. -
Set the
Example_Project.X
project as main project.
Right click the project in the Projects tab and click Set as Main Project. -
Clean and build the
Example_Project.X
project.
Right click theExample_Project.X
project and select Clean and Build. -
Select PICxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
Right click the project and click Properties.
Click the arrow under the Connected Hardware Tool.
Select AVRxxxxx Curiosity Nano (click the SN), click Apply and then click OK: -
Program the project to the board.
Right click the project and click Make and Program Device.