cancel
Showing results for 
Search instead for 
Did you mean: 

How does the event flag work on STM32? Part 2

B.Montanari
ST Employee

How does the event flag work on STM32? Part2

This is the part 2 of the article to explain How the Event Flag work on STM32 with a working example. Welcome back!
1. MATERIALS:
To develop this article’s demo, the following materials were necessary:
- STM32CubeIDE version 1.10.0 or higher
- X-CUBE-AZRTOS-G4 1.0.0 or higher
- STM32G474 Discovery Kit (B-G474E-DPOW1)
208.png
2. DEVELOPMENT:
Let us start creating a new STM32 Project on STM32CubeIDE for the STM32G474RET microcontroller.
210.pngGive your project name, just remember to avoid space and special characters – the name given by this article is “EV_FLAG_G474”.
To import the Azure RTOS to the project, click on “Software Packs”, and then “Select Components”.
212.png
In “Software Packs Component Selector” menu, locate STMicroelectronics.X-CUBE-AZRTOS-G4 → RTOS ThreadX → ThreadX, check “Core” box and click OK.
213.png
 Add the Azure RTOS ThreadX checking the box inside Software Packs → STMicroelectronics.X-CUBE-AZRTOS-G4. As this demo is just meant to create small timers and GPIOs managements according to the Event Flags, the default settings are fine. 
215.png
 By default, the HAL driver uses the Systick as its primary time base, but this timer should be left to the AzureRTOS only. If the HAL library does not have a separate time source, the compilation and code execution might fail because both libraries want to use the SysTick_Handler interrupt. To prevent this, we can simply select a different time base for the HAL by clicking in the System Core → SYS and selecting the time base Source as TIM6: 
217.png
Go to clock configurations and adjust the settings as shown in the image to achieve the HLCK at 170MHz.
219.png
Configure the following pins as table shown:
 
ComponentPinConfigurationLabel
Joystick SelectPC13GPIO External Interrupt mode with Falling Edge trigger detection and pull-upJOYSTICK_SELECT
Joystick UpPB10JOYSTICK_UP
Joystick RightPB2JOYSTICK_RIGHT
Joystick DownPC5JOYSTICK_DOWN
Joystick LeftPC4JOYSTICK_LEFT
RGB led RedPC6TIM3_CH1PWM_RED
RGB led GREENPC8TIM3_CH3PWM_GREEN
RGB led BLUEPA8TIM1_CH1PWM_BLUE

221.png
Enable the GPIO External interrupts on NVIC tab and give them a 14 Preemption Priority (this priority will be 1 level lower than thread priorities).
223.png
Set timer 1 and 3 configurations as the following settings:
- TIM1_CHANNEL1: PWM Generation CH1.
- TIM3_CHANNEL1: PWM Generation CH1.
- TIM3_CHANNEL3: PWM Generation CH3.
- Prescaler: 169, that sets the timer frequency to 1MHz = 170Mhz/(169 + 1).
- Counter Period: 99, which sets the PWM frequency to 100KHz = 1MHz/(99 + 1) and a resolution of 1%.
- Auto-reload preload: Enable.

The other settings are default values.
224.png
The last step before the code generation is to enable the “Generate peripheral initialization as a pair of ‘.c/.h’ files per peripheral” in Project Manager → Code Generator. This should be helpful to HAL functions and resources management.
225.png
All set, we can press Alt+K to generate the code or click on the following button.
226.png
In part 3 we will cover the step by step of the code implementation using the STM32CubeIDE.
 
Version history
Last update:
‎2022-09-06 12:47 AM
Updated by: