STM32-Cube IDE-FreeRTOS Code Generation using CubeMx

STM32-Cube IDE-FreeRTOS Code Generation using CubeMx

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

  1. 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].
  2. 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.
Figure 1

3. Select SMT32F429 in board select tab

Figure 2

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.

Figure 3

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)

Figure 4

6. As a result, the following dialog is displayed.

Figure 5

7. wait for project creation process

Figure 6

8. Initial view of STM32CUBE ide after project generation

Figure 7

9. System clock setting at 180MHz

Figure 8

10. Go to System Core section -> SYS and change Timebase source (for HAL) from SysTick to other timer i.e. TIM6

Figure 9 : Time Base Setting Using CubeIDE

11. Pinout & Configuration Middleware -> FREERTOS -> check  Select CMSIS Version

Figure 10

12. Go to FREERTOS Configuration > Config parameters setting

• Kernel settings

• RTOS components settings

• Memory setup

Figure 11 : FreeRTOS Config Parameters Setting

13. Configuration options are declared in file FreeRTOSConfig.h, Important configuration options are ,

Sr NoConfig OptionsDescription
1configUSE_PREEMPTIONSet to 1 to use the preemptive RTOS scheduler, or 0 to use the cooperative RTOS scheduler.
2configUSE_TICKLESS_IDLESet configUSE_TICKLESS_IDLE to 1 to use the low power tickless mode, or 0 to keep the tick interrupt running at all times.
3configUSE_IDLE_HOOKSet to 1 if you wish to use an idle hook, or 0 to omit an idle hook
4configUSE_TICK_HOOKSet to 1 if you wish to use an tick hook, or 0 to omit an tick hook.
5configCPU_CLOCK_HZEnter 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.
6configTICK_RATE_HZThe frequency of the RTOS tick interrupt.
7configMAX_PRIORITIESThe number of priorities available to the application tasks.
8configMINIMAL_STACK_SIZEThe size of the stack used by the idle task.
9configIDLE_SHOULD_YIELDThis parameter controls the behaviour of tasks at the idle priority
10configUSE_TASK_NOTIFICATIONSSetting configUSE_TASK_NOTIFICATIONS to 1 will include direct to task notification functionality and its associated API in the build.
11configUSE_MUTEXESSet to 1 to include mutex functionality in the build, or 0 to omit mutex functionality from the build.
12configUSE_RECURSIVE_MUTEXESSet to 1 to include recursive mutex functionality in the build, or 0 to omit recursive mutex functionality from the build.
13configUSE_COUNTING_SEMAPHORESSet 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

Figure 12

Execution pattern demonstrating the behavior of the co-operative scheduler

Figure 13

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

Figure 14 : FREERTOS Parameters Setting For Idle Hook & Tick Hook

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:

https://www.st.com/content/st_com/en/support/learning/stm32-education/stm32-moocs/FreeRTOS_on_STM32_MOOC.html

https://www.freertos.org/fr-content-src/uploads/2018/07/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf

Software Tools:
  1. STM32CubeIDE
  2. STM32CubeMx
  3. Teraterm
Hardware Setup:
  1. STM32F429IDISCOVERY board
  2. Mini USB Cable
  3. Jumper wire
Conclusion:

Successfully demonstrated FreeRTOS code generation using STM32CubeMx

If you enjoyed this article, share your feedback.

Similar topics:
  1. STM32 Peripherals: ADC using Polling Mode
  2. STM32 Peripherals: UART Interrupt Mode
  3. STM32-Peripheral’s-SPI: Polling Mode
  4. STM32 Peripherals : Base timer in interrupt mode

Leave a Reply

Your email address will not be published. Required fields are marked *