Chapter 2 : STM32 MCU:
harware features and
software programming
Hanene Ben Fradj
ING 2 -ISI
Mise à jour : october 2023
La carte STM32F4-Discovery
DISC1
2
STM32F4-Discovery Board in zoom (1)
3
STM32F4-Discovery Board (2)
4
Ordering Information Scheme
5
Developement toolchains supported
⚫ IAR EWARM
⚫ CubeIDE
⚫ KEIL MDK-ARM
⚫ GCC-based IDEs including free SW4STM32 from AC6
⚫ ARM mbed Enabled™ online
6
STM32F4xx Value Line necessary docs
⚫ RM0090 (Reference Manual): Peripherals description…
⚫ Datasheet STM32F407xx : Electrical parameters…
⚫ UM1725 : Description of STM32F4 HAL and low-layer drivers
⚫ UM1472 (DISCOERY KIT with STM32F407VG MCU value line Discovery):
STM32 discovery board description, electrical schematics…
All docs are available from www.st.com
7
The CMSIS programming standard
• Definition:
The Cortex-M™ Microcontroller Software Interface Standard (CMSIS) is defined in close
cooperation with various silicon and software vendors and provides a common approach
to interface to peripherals, real-time operating systems and middleware components. For
more details, please refer to www.onarm.com.
• CMSIS layer structure
Hal peripherals Driver
8
HAL overview
HAL inclusion in user application
stm32f4xx_hal_ppp.c et .h n’est pas uniquement utilisé
pour désigner un seul fichier mais elle s’étend à un certain
nombre de fichiers.
Chaque fichier étant relatif à l’un des périphériques du
microcontrôleur (ppp étant remplacée par l’abréviation du
périphérique: UART,GPIO, DMA,….). 9
HAL overwiew
HAL file components
10
Using HAL Library 11
⚫ the PPP peripheral is initialized and can be enabled by making a call to
PPP_Cmd(..) function: HAL_PPP_Cmd(PPPx, ENABLE);
⚫ Note: This function is used only for communication peripherals like UART,
SPI, …
⚫ To access the functionality of the PPP peripheral, the user can use a set of
dedicated functions. These functions are specific to the peripheral and for
more details refer to STM32F4xx Firmware Library User Manual.
Example of GPIO Functions are defined in stm32f4xx_hal_gpio.h
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init);
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin);
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
Basic Configuration Steps
In user application main.c #include "stm32f4xx_hal.h"
Enable bus peripheral clock using macros
__HAL_RCC_GPIOA_CLK_ENABLE() in stm32f4xx_hal_rcc.h
__HAL_RCC_GPIOD_CLK_ENABLE(); in stm32f4xx_hal_rcc_ex.h
Pheripheral configuration by data structure declaration
PPPx_InitTypeDef PPP_InitStucture; in stm32f4xx_hal_PPP.h
Pheripheral configuration : Data structure members defined in
stm32f4xx_hal_PPP.h
⚫ PPP_InitStucture.memberX = valX;
⚫ PPP_InitStructure.memberY = valY;
⚫ ………
Use Read or Write functions implemented in stm32f4xx_hal_PPP.c
Example : HAL_PPP_Init(PPPx, &PPP_InitStructure); 12
GPIOC Configuration example
Example : GPIOC port of the STM32 configuration:
AHB2 AHBx = AHB1
Cortex M4 1. GPIO_InitTypeDef GPIO_InitStructure;
2. __HAL_RCC_GPIOC_CLK_ENABLE();// activer l’horloge
AHB1
3. Configurer le périphérique GPIOC
Bridge GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pin =PIO_PIN_3;
APB GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIOA
GPIO_InitStructure.Alternate =
GPIOB GPIO_InitStructure.Speed =
GPIOC ADC
GPIOD UART 4 . Utilisation des pilotes :
GPIOF TIM - Initialisation : HAL_GPIO_Init (GPIOC, &GPIO_InitStructure)
GPIOE DAC -Write: HAL_GPIO_WritePin(GPIOC,GPIO_PIN_3, GPIO_PIN_SET)
GPIOH I2C - Read : GPIO_PinState HAL_GPIO_ReadPin(GPIOC, GPIO_Pin_3)
-…
13
🡪these informations are available in stm32f4xx_hal_gpio.h and stm32f4xx_hal_gpio.c
Environnement Cube IDE
14