You are on page 1of 32

STM32Cube

Making STM32 development easier


STM32CubeMX application 2

• STM32CubeMx do allow to configure peripherals using GUI, generate


project framework and peripheral initialization code.

• STM32CubeMx do not allow to create algorithms using GUI and


generate algorithms code yet – there is still some space for
programmers left ;-)
3

What it is STM32CubeMX ?

Pinout Wizard Clock Tree Wizard Peripherals & Middleware Power Consumption
Wizard Wizard

STM32CubeMX

Generates Initialization C Code


based on user choices !
STM32Cube: STM32CubeMX 4

Step by step:

• MCU selector

• Pinout configuration

• Clock tree initialization

• Peripherals and
middleware parameters

• Code generation

• Power consumption
calculator
New Project 5

MCU Selector
Easy Optional filtering:

• Series

• Line

• Package

• Peripherals
New Project 6

Board Selector
Easy Optional filtering:

• Type of board

• MCU Series

• Peripherals

• Optional init
STM32CubeMX: Pinout configuration 7

• Pinout from:
• Peripheral tree
• Manually

• Automatic signal
remapping

• Management of
dependencies
between
peripherals and/or
middleware
(FatFS, LWIP, …)
STM32CubeMX: Pinout configuration 8

• Different possible states for a peripheral modes


• Dimmed: the mode is not available because it requires another mode to be set (just
put the mouse on top of the dimmed mode to see why)
• Red: Signals required for this mode can’t be mapped on the pinout (see tooltip to
see conflicts)

• Keep User Placement renamed to Keep Current Signal Placement


and is unchecked by default

• Signals can be set/moved directly from the pinout view


• Click on the pin to see the list of possible signals and select one
• To see alternate pins for a signal Ctrl+Click on the signal, you can then drag and
drop the signal to the new pin (keep pressing the Ctrl key)

• Signal can be used from several peripherals


• Pin Stacking
Pinout 9

• Export to other tools


• Generate CSV pinout text file

• Design view
• Rotate (Top/Bottom view for BGA)
MCU Replacement 10

• Compatible MCUs
• Select compatible MCU

• Automatically replaced

• Or save project and import


• Save created project
• Click File>Import Project … and import previous project
Exercise 11

Pinout creation
• Select NUCLEO-F446RE board

• Configure signals
• LED = PA5 (Already done)
• UART = USART2 (TBD)
• BP = PC13 (Already done)
STM32CubeMX: Clock tree 12

Clock tree automatically computed

• Immediate
display of all
clock values

• Management
of all clock
constraints

• Highlight of
errors
STM32CubeMX: Clock tree 13

• First choose in the pinout view the desired external clock (RCC)

• Enter the values in the light blue areas

• Wrong values are highlighted in red and a tooltip describes the


reason

• If you have an unused peripheral or input in the clock tree the


corresponding area will be dimmed
STM32CubeMX: Peripheral and
middleware configuration 14

• Global view of used


peripherals and
middleware

• Highlight of
configuration errors
+ Not configured
ⱱ OK
x Error

• Read only tree view


on the left with
access to Ips /
Middleware having
no impact on the
pinout
STM32CubeMX: Peripheral and
middleware configuration 15

• Parameters with
management of
dependencies and
constraints

• Interruptions

• GPIO

• DMA
STM32CubeMX: Peripheral and
middleware configuration 16

• Manage Interruptions
• priorities can only be set in the
NVIC global view

• Manage GPIO parameters

• Manage DMA
• Configure all the parameters of the
DMA request
• Runtime parameters (start
address, …) are not managed
NVIC Panel 17

• Manage all
interruptions

• Manage priorities
and sort by
priorities

• Search for a
specific interrupt in
the list
DMA Panel 18

• Manage All DMA


requests including
Memory to
Memory

• Set Direction and


priority

• Set specific
parameters
GPIO Panel 19

• Most of the GPIO


parameters are set
by default to the
correct value

• You may want to


change the
maximum output
speed

• You can select


multiple pin at a
time to set the
same parameter
Exercise 20

Peripherals configuration
• BP external interrupt
• Do NOT forget to validate NVIC !

• Usart
• Communication parameters 9600Bits/s
• Data flow configuration
• IT
STM32CubeMX: Code generation 21

• Generation of all the C


initialization code

• Automatic integration with


partners toolchains

• User code can be added in


dedicated sections and will be
kept upon regeneration

• Required library code is


automatically copied or
referenced in the project
(updater)
STM32CubeMX: Updater 22

• Help->Updater settings
• Choose location of STM32CubeFx firmware libraries repository
• Choose manual or automatic check
• Set Connection proxy
• Inside ST use lps5.sgp.st.com port 8080 with your windows login name and password

• Help->Install new libraries : Manage the content of the library


repository
• Click on the check button to see what is available
• Select the library you want to install and click install now
• The libraries will be automatically downloaded and unzipped
STM32CubeMX: Project settings 23

• Project -> Settings


• Set project name and location
• A full folder will be created named with the project name.
• Inside this folder you’ll find the saved configuration and all the generated code
• Select toolchain (Keil, IAR, Atollic, SW4STM32)
• You can choose to use the latest version of the firmware library or a specific one
STM32CubeMX: Code Generator settings 24

• Code generator options


• Either copy the full library or only the
necessary files or just reference the
files from the common repository
• Generate all peripherals initialization
in the stm32fYxx_hal_msp.c file or
one file per peripheral
• Keep user code or overwrite it (code
between User code comment
sections)
• Delete or keep files that are not
useful anymore

• GPIO settings
You can choose to set all the remaining pins to analog to optimize power
consumption  don’t forget to reserve debug pins before, this option is set by
default in the 4.0 (unset by default in future versions)
STM32CubeMX: Generated code 25

• By default:
• main.c:
• GPIO configuration
• Clock configuration
• The main() function calling all the initialization code
• stm32f4xx_hal_msp.c:
• Initialization code for all Ips
• Middlewares are in separated files
• stm32f4xx_it.c:
• Management of the interrupts

• User code can be put inside:


/* USER CODE BEGIN 1 */

/* USER CODE END 1 */


The code will be kept upon generation
Exercise 26

Application code
• Synchonous
• Toggle LED (PA5) every 500ms

• Asynchonous
• Send message to PC using USART every time BP is pressed (External Interrupt)

• HAL functions used


• Synchonous :
• void HAL_Delay(__IO uint32_t Delay) (st32f4xx_hal.c)
• void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
(st32f4xx_hal_gpio.c)
• Asynchronous
• void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) (st32f4xx_hal_gpio.c)
• HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t
*pData, uint16_t Size) (st32f4xx_hal_uart.c)
• void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) (st32f4xx_hal_uart.c)
STM32CubeMX: Power consumption
calculator 27

• Power step
definitions

• Battery selection

• Creation of
consumption
graph

• Display of
• Average
consumption
• Average DMIPS
• Battery lifetime

• Supported for L1
and F4
STM32CubeMX: Power consumption
calculator 28

• First Select the Vdd power supply

• Optionally select your battery

• Add steps defining:


• Power Mode
• activated Peripherals list
• Power Consumption Range
• Memory Fetch Type
• Clock Configuration
• Clock Source Frequency
• CPU Frequency (fHCLK)
• User Consumption
• Duration

• See immediately the calculated consumption curve, battery life and


more.
Thank you 29

www.st.com/stm32cube
Exercice solution (1/2) 30

• Add C code between


• /* USER CODE BEGIN XXXXX */ and /* USER CODE END XXXXX */

• Private variables

• Synchonous processing = Blink LED


Exercice solution (2/2) 31

• asynchronous processing = Interrupt


Tools 32

• STM32CubeMX
• http://www.st.com/en/development-tools/stm32cubemx.html

• SW4STM32
• http://www.st.com/en/development-tools/sw4stm32.html

You might also like