STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings •...
Transcript of STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings •...
![Page 1: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/1.jpg)
STM32CubeMaking STM32 development easier
![Page 2: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/2.jpg)
STM32CubeMX application
• 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 ;-)
2
![Page 3: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/3.jpg)
3
Pinout Wizard Clock Tree Wizard Peripherals & Middleware
Wizard
Power Consumption
Wizard
STM32CubeMX
Generates Initialization C Code
based on user choices !
What it is STM32CubeMX ?
![Page 4: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/4.jpg)
STM32Cube: STM32CubeMX 4
Step by step:
• MCU selector
• Pinout configuration
• Clock tree initialization
• Peripherals and
middleware parameters
• Code generation
• Power consumption
calculator
![Page 5: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/5.jpg)
New Project 5
MCU Selector
Easy Optional filtering:
• Series
• Line
• Package
• Peripherals
![Page 6: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/6.jpg)
New Project 6
Board Selector
Easy Optional filtering:
• Type of board
• MCU Series
• Peripherals
• Optional init
![Page 7: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/7.jpg)
STM32CubeMX: Pinout configuration 7
• Pinout from:
• Peripheral tree
• Manually
• Automatic signal
remapping
• Management of
dependencies
between
peripherals and/or
middleware
(FatFS, LWIP, …)
![Page 8: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/8.jpg)
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
![Page 9: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/9.jpg)
Pinout 9
• Export to other tools
• Generate CSV pinout text file
• Design view
• Rotate (Top/Bottom view for BGA)
![Page 10: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/10.jpg)
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
![Page 11: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/11.jpg)
Exercise 11
• Select NUCLEO-F446RE board
• Configure signals
• LED = PA5 (Already done)
• UART = USART2 (TBD)
• BP = PC13 (Already done)
Pinout creation
![Page 12: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/12.jpg)
STM32CubeMX: Clock tree 12
Clock tree automatically computed
• Immediate
display of all
clock values
• Management
of all clock
constraints
• Highlight of
errors
![Page 13: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/13.jpg)
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
![Page 14: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/14.jpg)
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
![Page 15: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/15.jpg)
STM32CubeMX: Peripheral and
middleware configuration 15
• Parameters with
management of
dependencies and
constraints
• Interruptions
• GPIO
• DMA
![Page 16: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/16.jpg)
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
![Page 17: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/17.jpg)
NVIC Panel 17
• Manage all
interruptions
• Manage priorities
and sort by
priorities
• Search for a
specific interrupt in
the list
![Page 18: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/18.jpg)
DMA Panel 18
• Manage All DMA
requests including
Memory to
Memory
• Set Direction and
priority
• Set specific
parameters
![Page 19: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/19.jpg)
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
![Page 20: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/20.jpg)
Exercise 20
• BP external interrupt
• Do NOT forget to validate NVIC !
• Usart
• Communication parameters 9600Bits/s
• Data flow configuration
• IT
Peripherals configuration
![Page 21: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/21.jpg)
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)
![Page 22: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/22.jpg)
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
![Page 23: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/23.jpg)
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
![Page 24: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/24.jpg)
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 settingsYou 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)
![Page 25: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/25.jpg)
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
![Page 26: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/26.jpg)
Exercise 26
• 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)
Application code
![Page 27: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/27.jpg)
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
![Page 28: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/28.jpg)
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.
![Page 30: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/30.jpg)
30
• Add C code between
• /* USER CODE BEGIN XXXXX */ and /* USER CODE END XXXXX */
• Private variables
• Synchonous processing = Blink LED
Exercice solution (1/2)
![Page 31: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/31.jpg)
31
• asynchronous processing = Interrupt
Exercice solution (2/2)
![Page 32: STM32Cube - Université Grenoble Alpes...STM32CubeMX: Project settings 23 •Project -> Settings • Set project name and location • A full folder will be created named with the](https://reader030.fdocuments.us/reader030/viewer/2022040901/5e72124af8be661c930e6a93/html5/thumbnails/32.jpg)
32
• STM32CubeMX
• http://www.st.com/en/development-tools/stm32cubemx.html
• SW4STM32
• http://www.st.com/en/development-tools/sw4stm32.html
Tools