STM32CubeIDE is an advanced C/C++ development platform with peripheral configuration, code generation, code compilation, linking, and debug features. It is based on the Eclipse®/CDT framework and GCC toolchain for
the development, and GDB for the debugging. It allows the integration of the hundreds of existing plugins that complete the features of the Eclipse® IDE.
STM32CubeIDE integrates ST MCUFinder (ST-MCU-FINDER-PC) and STM32CubeMX functionalities to offer all-in-one tool experience. It makes it easy to create new STM32 MCU or board projects and build them using the included GCC toolchain.
STM32CubeIDE includes a build analyzer and a static stack analyzer that provide the user with useful information about project status and memory requirements.
STM32CubeIDE also includes standard and advanced debugging features including views of CPU core registers, memories, and peripheral registers, as well as live variable watch, and serial wire viewer interface. A fault analyzer displays error information if an error is triggered by the STM32 processor during a debug session.
Today we are going to discuss how to create freeRTOS based project using cube ide, for this demonstration we will use STM32F429IDISCOVERY BAORD.
Creating a new STM32 executable project
- The easiest way to create a new STM32 C/C++ project is to use the STM32 project wizard. It is selected through the menu [File]>[New STM32 Project].
- The MCU/MPU selector and Board Selector tabs can be selected at the top of the window. Use the first tab to create project for a specific device and the second if a project for a specific board is needed.
3. Select SMT32F429 in board select tab
4. According to the settings in Figure 3, the project is meant to be stored in the default location with the following
options set:
• C project
• Executable binary type
• STM32CubeIDE targeted project type
Press [Next] to open the Firmware Library Package Setup page.
5. In this page, it is possible to select the STM32Cube firmware package to use when creating the project. In this case, the default settings are used. Press [Finish] to create the project. (Fig 4)
6. As a result, the following dialog is displayed.
7. wait for project creation process
8. Initial view of STM32CUBE ide after project generation
9. System clock setting at 180MHz
10. Go to System Core section -> SYS and change Timebase source (for HAL) from SysTick to other timer i.e. TIM6
11. Pinout & Configuration Middleware -> FREERTOS -> check Select CMSIS Version
12. Go to FREERTOS Configuration > Config parameters setting
• Kernel settings
• RTOS components settings
• Memory setup
13. Configuration options are declared in file FreeRTOSConfig.h, Important configuration options are ,
Sr No | Config Options | Description |
1 | configUSE_PREEMPTION | Set to 1 to use the preemptive RTOS scheduler, or 0 to use the cooperative RTOS scheduler. |
2 | configUSE_TICKLESS_IDLE | Set configUSE_TICKLESS_IDLE to 1 to use the low power tickless mode, or 0 to keep the tick interrupt running at all times. |
3 | configUSE_IDLE_HOOK | Set to 1 if you wish to use an idle hook, or 0 to omit an idle hook |
4 | configUSE_TICK_HOOK | Set to 1 if you wish to use an tick hook, or 0 to omit an tick hook. |
5 | configCPU_CLOCK_HZ | Enter the frequency in Hz at which the internal clock that drives the peripheral used to generate the tick interrupt will be executing – this is normally the same clock that drives the internal CPU clock. |
6 | configTICK_RATE_HZ | The frequency of the RTOS tick interrupt. |
7 | configMAX_PRIORITIES | The number of priorities available to the application tasks. |
8 | configMINIMAL_STACK_SIZE | The size of the stack used by the idle task. |
9 | configIDLE_SHOULD_YIELD | This parameter controls the behaviour of tasks at the idle priority |
10 | configUSE_TASK_NOTIFICATIONS | Setting configUSE_TASK_NOTIFICATIONS to 1 will include direct to task notification functionality and its associated API in the build. |
11 | configUSE_MUTEXES | Set to 1 to include mutex functionality in the build, or 0 to omit mutex functionality from the build. |
12 | configUSE_RECURSIVE_MUTEXES | Set to 1 to include recursive mutex functionality in the build, or 0 to omit recursive mutex functionality from the build. |
13 | configUSE_COUNTING_SEMAPHORES | Set to 1 to include the ‘alternative’ queue functions in the build, or 0 to omit the ‘alternative’ queue functions from the build. |
‘config’ Parameters
configUSE_PREEMPTION : Set to 1 to use the preemptive RTOS scheduler, or 0 to use the cooperative RTOS scheduler.
Pre-emptive scheduling algorithms will immediately ‘pre-empt’ the Running state task if a task that has a priority higher than the Running state task enters the Ready state. Being pre-empted means being involuntarily (without explicitly yielding or blocking) moved out of the Running state and into the Ready state to allow a different task to enter the Running state
Execution pattern highlighting task prioritization and pre-emption in a hypothetical application in which each task has been assigned a unique priority, given below
Execution pattern demonstrating the behavior of the co-operative scheduler
14) Idle Hook & Tick Hook Code Generation : if user enabled USE_IDEL_HOOK , USE_TICK_HOOK parameters as per below image , respected code for both will be generated by CubeIDE
Idle hook Code:
void vApplicationIdleHook( void ) {/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set<br>to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle<br>task. It is essential that code added to this hook function never attempts<br>to block in any way (for example, call xQueueReceive() with a block time<br>specified, or call vTaskDelay()). If the application makes use of the<br>vTaskDelete() API function (as this demo application does) then it is also<br>important that vApplicationIdleHook() is permitted to return to its calling<br>function, because it is the responsibility of the idle task to clean up<br>memory allocated by the kernel to any task that has since been deleted. */ }
Tick Hook Code:
void vApplicationTickHook( void ) {/* This function will be called by each tick interrupt if<br>configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be<br>added here, but the tick hook is called from an interrupt context, so<br>code must not attempt to block, and only the interrupt safe FreeRTOS API<br>functions can be used (those that end in FromISR()). */ }
References:
Software Tools:
- STM32CubeIDE
- STM32CubeMx
- Teraterm
Hardware Setup:
- STM32F429IDISCOVERY board
- Mini USB Cable
- Jumper wire
Conclusion:
Successfully demonstrated FreeRTOS code generation using STM32CubeMx
If you enjoyed this article, share your feedback.