Week5 STM32 Nucleo
Week5 STM32 Nucleo
Introduction
Development toolchains
• IAR Systems® - IAR Embedded Workbench®
• Keil® - MDK-ARM
• STMicroelectronics - STM32CubeIDE
The first two are Windows only. We will use STM32CubeIDE.
• PA10 means
• GPIO Port A (GPIOA)
• GPIO_PIN_10
• So, to write HIGH to PA10, call this
function:
• HAL_GPIO_WritePin(GPIOA,
GPIO_PIN_10, GPIO_PIN_SET);
• More on the functions later
Spare jumpers
• The STM32 Nucleo board and its shield can consume a maximum of 300 mA current, not more.
• The USART2 interface available on PA2 and PA3 of the STM32 microcontroller can be connected to ST-
LINK MCU, ST morpho connector, or to ARDUINO® connector. The choice can be changed by setting the
related solder bridges. By default, the USART2 communication between the target STM32 and ST-LINK
MCU is enabled, in order to support virtual COM port for Mbed™ (SB13 and SB14 ON, SB62 and SB63
OFF).
• If the communication between the target STM32 PA2 (D1) or PA3 (D0) and shield or extension board is
required, SB62 and SB63 must be ON, while SB13 and SB14 must be OFF.
Save, Build Project, then download the HelloWorld.bin file to the board. The green led should blink (toggle
on/off every 500 ms). If the program does not run automatically, press the Reset button on the board.
Winter 2022 IE5995: IoT & Edge AI Programming 22
Definitions
• Some shorthand names are defined in
main.h
• For example:
• LD2_Pin is alias for GPIO_PIN_5
• But where is GPIO_PIN_5 define?
• It is defined in the stm34f4xx_hal_gpio.h
This means
GPIO_PIN_RESET is alias for 0 (Low)
GPIO_PIN_SET is alias for 1 (High)
+ - 330 ohm
PA_10 (D2)
GND
Tactile switch
Time
HAL_TIM_Base_Start() Timer update event Timer update event
(trigger interrupt) (trigger interrupt)
https://www.st.com/resource/en/user_manual/dm00105879-
description-of-stm32f4-hal-and-ll-drivers-stmicroelectronics.pdf
Winter 2022 IE5995: IoT & Edge AI Programming 48
Code to blink LED using Timer triggered Interrupt
Compared to the Polling method, the interrupt method does not block the process,
especially when the message (msg) size is large.
• Sampling frequency is
determined by clock and
prescaler
• Useful for audio sampling
https://learn.sparkfun.com/tutorials/pulse-width-modulation/all
Winter 2022 IE5995: IoT & Edge AI Programming 61
Update the duty cycle in the program
• The Pulse value is stored in the register
• TIM2->CCR1
• Timer 2 Channel 1’s Capture Compare Register
• This register value can be updated in user code
Experiment: Vary the CCR1 value
in the while(1) loop
Result: the green led will gradually
light up and dim down.
https://www.st.com/resource/en/application_note/cd00259245-audio-and-
waveform-generation-using-the-dac-in-stm32-products-stmicroelectronics.pdf
• Video clip