This is a new article in my series about using Microsoft Visual Studio Code: After installation, project setup, building, debugging, setting up a kit and IntelliSense. This one is about setting up and using FreeRTOS:
FreeRTOS is probably the most used and common RTOS for the embedded microcontroller world. It is is very easy to learn, efficient and because it is widely used, there is tools support for it.
In this article I show how you can use FreeRTOS and debug it with Visual Studio Code, including having thread awareness. I assume you have read my previous tutorial articles (see links at the end of this article).
You can find the shared projects on GitHub: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/VisualStudioCode. I’m using the FRDM-K22F_Blinky in this article.
First, have the McuLib with FreeRTOS in your project which includes FreeRTOS:
In your CMakeLists.txt add the FreeRTOS source files:
McuLib/src/McuRTOS.c McuLib/FreeRTOS/FreeRTOShooks.c McuLib/FreeRTOS/Source/croutine.c McuLib/FreeRTOS/Source/event_groups.c McuLib/FreeRTOS/Source/list.c McuLib/FreeRTOS/Source/queue.c McuLib/FreeRTOS/Source/stream_buffer.c McuLib/FreeRTOS/Source/tasks.c McuLib/FreeRTOS/Source/timers.c McuLib/FreeRTOS/Source/portable/MemMang/heap_1.c McuLib/FreeRTOS/Source/portable/MemMang/heap_2.c McuLib/FreeRTOS/Source/portable/MemMang/heap_3.c McuLib/FreeRTOS/Source/portable/MemMang/heap_4.c McuLib/FreeRTOS/Source/portable/MemMang/heap_5.c McuLib/FreeRTOS/Source/portable/MemMang/heap_useNewlib.c McuLib/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c McuLib/FreeRTOS/Source/portable/GCC/ARM_CM4F/portasm.s
List the RTOS include directories:
Update the configuration to include FreeRTOS:
/* ------------------- RTOS ---------------------------*/ #define McuLib_CONFIG_SDK_USE_FREERTOS (1) #define configTOTAL_HEAP_SIZE (24*1024) #define configUSE_HEAP_SECTION_NAME (1) #define configHEAP_SECTION_NAME_STRING ".bss.$SRAM_LOWER.FreeRTOS" #define configQUEUE_REGISTRY_SIZE (10)
With this, build the application and add tasks as needed.
Debugging with FreeRTOS Thread Awareness
I’m using SEGGER J-Link for debugging. It has an option to turn on FreeRTOS thread awareness. Add the following to the launch.json file:
With this, I can debug with all the FreeRTOS threads listed:
There is basic support for FreeRTOS in Visual Studio code including thread awareness. For sure it is not up-to-par with FreeRTOS debugging support you get in free Eclipse based IDEs like the NXP MCUXpresso IDE, but it is suffient to debug FreeRTOS applications on any ARM Cortex.
Happy FreeRTOSing 🙂
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 1 – Installation
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 2 – Project
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 3 – Build
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 4 – Debug
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 5 – ToolKit
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 6 – IntelliSense
- Visual Studio Code for C/C++ with ARM Cortex-M: Part 7 – FreeRTOS
- Visual Studio Code website: https://code.visualstudio.com/
- IntelliSense: https://code.visualstudio.com/docs/editor/intellisense
- Intellisense for Cross Development: https://code.visualstudio.com/docs/cpp/configure-intellisense-crosscompilation
- Examples on GitHub: https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/VisualStudioCode