uVision5 provides two routes for users to configure their RTE. The first option, called Classic (used for all the recipes in Chapters 2-8), configures the STM's Hardware Abstraction Layer (HAL) using the RTE_Device.h
header file. This option allows users to quickly configure the RTE for most CMSIS-enabled devices. The second option uses STM's graphical configuration tool, STM32Cube MX, to perform low-level configuration of the HAL directly. Example projects using both approaches are shipped with recent versions of Device Family Packs (for example, DFP 2.6.0). This recipe (named ARM_STM32CubeMX_Blinky_c9v0
) shows you how to build a Blinky project using STM's tool.
STM32CubeMX_Blinky
. Choose the STM32F407IGHx device.main.c
(found in folder STM32CubeMX:Common Sources
), navigate to the main()
function definition, and add this statement in the section identified by the /* USER CODE BEGIN 2 */
comment:LED_Initialize ( );
/* Infinite loop */
comment:LED_On(0); for (i=0; i<1000000; i++) ; LED_Off(0); for (i=0; i<1000000; i++) ;
i
and #include "Board_LED.h"
.We've used STM32CubeMX to generate a very basic runtime environment. We're still using the Board Support API to provide functions to configure GPIO and drive LEDs. STM32CubeMX is much more powerful, and we've only illustrated a very basic configuration. More details and further tutorials can be found at www.st.com.
We can also use STM32CubeMX to configure the GPIO pins that are used to drive the LEDs. We illustrate this in the ARM_STM32CubeMX_Blinky_c9v1
:
STMCubeMX
, as we did before, to generate the code. When we open the main.c
file, we should now find that STM32CubeMX
has added code to configure the GPIO pins in the MX_GPIO_Init()
function, as follows:void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __GPIOI_CLK_ENABLE(); __GPIOH_CLK_ENABLE(); __GPIOG_CLK_ENABLE(); /*Configure GPIO pin : LED_3_Pin */ GPIO_InitStruct.Pin = LED_3_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(LED_3_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pins : LED_7_Pin LED_0_Pin LED_1_Pin LED_2_Pin */ GPIO_InitStruct.Pin = LED_7_Pin|LED_0_Pin|LED_1_Pin|LED_2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOH, &GPIO_InitStruct); /*Configure GPIO pins : LED_6_Pin LED_5_Pin LED_4_Pin */ GPIO_InitStruct.Pin = LED_6_Pin|LED_5_Pin|LED_4_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); }
MX_GPIO_Init()
function that was generated by STM32CubeMX is almost identical to that of LED_Initialize()
. As such, there is no need to call LED_Initialize ()
before calling LED_On()
and LED_Off()
.18.191.54.245