stm32f0 Hands On PDF
stm32f0 Hands On PDF
stm32f0 Hands On PDF
Objectives
Introduction to the ARM Cortex-M microcontroller
Learn how to build, program, and debug an
embedded system
Free STM32F0 Discovery Kit for each participant
Agenda
Presentation
Installation
Overview of the STM32 Portfolio
Introducing the STM32 F0 Series
The STM32 F0 Part 1: Cortex-M0
Hands-on Training Part I
The STM32 F0 Part 2: System and Peripherals
Hands-on Training Part II
STM32 Firmware and Development Tools
Questions and Answers
Speaker
Microcontroller Group
Americas Region
Tool Installation
Systems Check
Everyone should have
A Windows Laptop (XP, Vista or Windows 7)
USB Flash Drive
The following will be provided after software installation:
USB Cable
STM32F0DISCOVERY kit
Ready to begin?
Note: Please do not attempt to plug in the STM32 F0 Discovery Kit into your laptop until
instructed to do so.
10
STM32 applications
Industrial
Medical
PLC
Glucose meters
Inverters
Printers, scanners
VPAP, CPAP
Industrial networking
Patient monitoring
Solar inverters
Appliances
Alarm systems
Access control
Application control
HVAC
User interfaces
Power meters
Induction cooking
Consumer
Home audio
Gaming
PC peripherals
Digital cameras, GPS
11
13
Advanced timers
32-bit and 16-bit PWM timers with 17
capture/compare input/outputs mapped
on up to 28 pins
Motor control
Permanent magnet synchronous motors
(PMSM)
14
Maximum integration
Meets industry safety
specifications
Class B-ready for appliances
Hardware RAM parity check
Clock security system (CSS) to
switch to internal backup RC in case
of external clock failure
2x watchdogs capable of real-time
code execution monitoring and
ensuring the application integrity
independently from system clock
Cyclic redundancy check (CRC)
with DMA support for embedded
Flash-memory content-integrity
checking
15
STM32 F0 portfolio
now
16
18
3.6 V
CEC
1.8 V
APPLICATION
PROCESSOR
19
Microarchitecture
3-stage pipeline
1x AHB-Lite Bus Interfaces
21
22
Cortex-M3
Cortex-M4
V6M
v7M
v7ME
Thumb + Thumb-2
Thumb + Thumb-2,
DSP, SIMD, FP
0.9
1.25
1.25
Yes
Yes
Yes
1-32 + NMI
1-240 + NMI
1-240 + NMI
8-256
8-256
4/2/0, 2/1/0
8/4/0, 2/1/0
8/4/0, 2/1/0
No
Yes (Option)
Yes (Option)
No
Yes (Option)
Yes (Option)
No
Yes (Option)
No
Yes (Option)
Yes
Yes
No
Yes
Yes
Yes (Option)
Yes
Yes
No
Yes
Yes
No
No
Yes
No
No
Yes (Option)
AHB Lite
Yes
Yes
Yes
Bus protocol
CMSIS Support
23
24
STM32F0-DISCOVERY
STM32F051R8T6
48 MHz Cortex-M0
64-pin LQFP
64 Kbytes Flash/8 Kbytes RAM
26
Embedded ST-Link
ST-Link programming and
debugging tool integrated onboard the kit (STM32F103C8T6)
Can be used two different ways
Program and debug the MCU on the
board
Program an MCU on another
application board
Features
USB Connector
ST-LINK MCU
5V to 3V Voltage regulator
CN2 MCU Program Jumper
CN3 Application SWD connector
27
LEDs/Push-Buttons/Extension
Connector
LEDS
28
P1
P2
LD1
LD2
Push-Buttons
B1: User/Wake-up (PA0)
B2: Reset (NRST)
Extension Connector
B2
B1
P1 and P2
LD4
All GPIOs are available for prototype LD3
Documentation
UM1523 STM32F0DISCOVERY Kit
Firmware Library
Contains STM32F0 Standard
Firmware Library
Contains example code
AN4062 peripheral firmware
examples
JP2
29
30
31
Step #4
ST-Link Driver Trouble Shooting
1. Open Device Manager
2. Right-click on the STM32 ST-Link Driver icon
3. Select Update Driver Software
32
Step #4
ST-Link Driver Trouble Shooting
4. Select Browse my computer for
driver software
33
Step #4
ST-Link Driver Trouble Shooting
The STMicroelectronics ST-Link dongle should be listed
7. Click Next
34
Step #4
ST-Link Driver Trouble Shooting
A warning message may appear
8. Select Install this driver software anyway
35
Step #4
ST-Link Driver Trouble Shooting
You should receive a message:
Windows has successfully updated
your driver software
36
STM32 F0 Tools
Documentation overview
Documentation resources
Discovery Kit related documentation can be found @
www.st.com/stm32f0discovery under the Design support tab
In the directory:
C:\STM32F0-Discovery_Kit\Documentation\
38
Documentation resources
Main website page for the STM32 F0 Series
www.st.com/stm32f0
39
Support resources
Technically trained distributors
Distributors listed on CONTACTS page, www.st.com/contactus
ST Public Forums:
Located on main
www.st.com page under
Support tab ST e2e
Communities
Submit technical
questions to ST Online
Support:
Located on main
www.st.com page under the
Support tab Online
Support
40
42
Step #5
Open FW demo project with Keil uVision
Using explorer, go to the directory:
C:\STM32F0-Discovery_Kit\STM32F0-Discovery_FW_V1.0.0\
Project\Demonstration\MDK-ARM
43
Debug Button
Build Button
Files Window
Project Window
44
Step #6 - Compile
Click on the Build button or Menu::Project::Build Target
Build Button
45
Step #7 - Debug
Click on the Start/Stop Debug Session button or Menu:
Start/Stop Debug Session
Debug Button
46
Step #7
The MDK-ARM IDE Debugger
Disassembly Window
Files Window
Register Window
Command Window
Memory Windows
47
Step #8 - Run
Click on the Run button to start the program
Run Button
48
Step #8 - Run
Mission Accomplished
Please click on the Stop
button.
You code will stop
anywhere within the
program flow
Stop Button
49
50
Project Files
User files
main.c (program entry point)
system_stm32f0xx.c (initial system configuration)
stm32f0xx_it.c (ISRs)
stm32f0-discovery.c
Board specific functions
STM32F0xx_StdPeriph_Driver
Contains peripheral library functions
startup_stm32f0xx.s
System initialization, vector table, reset and branch to
main()
52
startup_stm32f0xx.s
Main Characteristics
Initializes stack pointer
53
system_stm32f0xx.c
SystemInit()
This function is called at startup just after reset and before branch to main
program. This call is made inside the "startup_stm32f0xx.s" file.
Setups the system clock (System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings)
Define PLL source
SystemInit()
.
.
.
Call SetSysClock()
54
main.c
Example main()
Standard C main() function entry
Start of application program
55
stm32f0xx_it.c
Contains Cortex-M0 Processor Exception Handlers (ISRs)
void NMI_Handler(void);
void HardFault_Handler(void);
void SVC_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
56
stm32f0-discovery.c
Contains board specific function and definition
Defines Push-button and LED GPIO definitions
Contains board specific funcitons
void STM_EVAL_LEDInit(Led_TypeDef Led);
void STM_EVAL_LEDOn(Led_TypeDef Led);
void STM_EVAL_LEDOff(Led_TypeDef Led);
void STM_EVAL_LEDToggle(Led_TypeDef Led);
void STM_EVAL_PBInit(Button_TypeDef Button, ButtonMode_TypeDef
Button_Mode);
uint32_t STM_EVAL_PBGetState(Button_TypeDef Button);
57
STM32F0xx_StdPeriph_Driver
Each file contains library functions that can be
used for each peripheral
Abstracts register manipulation and gives a
standard API for access to peripheral
functions
Example:
58
FLASH: up 64 Kbytes
SRAM: up 8 Kbytes
CRC calculation unit
5 DMA Channels
Power Supply with software configurable
internal regulator and low power modes.
Low Power Modes with Auto Wake-up
Low power calendar RTC with 20 bytes of
backup registers
Up to 48 MHz frequency managed &
monitored by the Clock Control w/ Clock
Security System
Rich set of peripherals & IOs
60
System Architecture
ARM 32-bit Cortex-M0 CPU
Nested Vector Interrupt
Controller (NVIC)
SWD
Bus Matrix
5 DMA Channels
61
System architecture/DMA
62
Cortex-M0 and DMA share the AHB bus matrix to allow parallel access
Multiple possibilities of bus access to SRAM, Flash, Peripheral, DMA
Von Neumann + Bus Matrix allows Flash execution in parallel with DMA transfer
Buses are not overloaded with data movement tasks
AHB
BusMatrix
DMA
Flash I/F
Slave 3
SRAM
Slave 1
AHB
AHB2GPIO
GP-DMA
Master 2
GPIO A, B ,C, D, F
Slave 4 Bridge
AHB
APB
AHB2APB
Arbiter
Slave 2 Bridges
62
Cortex-M NVIC
(Nested Vector Interrupt Controller)
Interrupts are Fast AND Deterministic
IRQ1
Cortex-M
Interrupt handling in HW
PUSH
POP
ISR 1
12
12
IRQ2
Cortex-M
Tail-Chaining back-to-back
interrupts
Tail-chaining
PUSH
12
ISR 1
ISR 2
6
6 CYCLES
POP
12
63
Exception Type
Priority
Type of
Priority
Reset
-3 (Highest)
fixed
Reset
NMI
-2
fixed
Non-Maskable Interrupt
Hard Fault
-1
fixed
4-10
Reserved
N.A.
N.A.
11
SVCall
Programmable
settable
12-13
Reserved
N.A.
N.A.
14
PendSV
Programmable
settable
15
SYSTICK
Programmable
settable
16
Interrupt #0
Programmable
settable
External Interrupt #0
..
..
settable
47
Interrupt#31
Programmable
settable
Descriptions
..
External Interrupt #31
The NVIC supports up to 32 dynamically re-prioritizable interrupts each with 4 levels of priority
64
Memories:
Flash, SRAM, Back-up Data Registers
Embedded Memories:
FLASH: up 64 Kbytes
SRAM: up 8 Kbytes
20 bytes of backup
registers
65
System
66
67
Feature
STM32F05x typ
IDD/IDDA (*)
22 / 0.260 (mA)
14 / 0.340 (mA)
68
On-chip oscillators
Up to 48 MHz frequency managed & monitored by the
Clock Control w/ Clock Security System
External Oscillators 32kHz (RTC) and 4-32MHz (System Clock)
Internal RC Oscillators 40kHz (IWDG) and 8MHz
PLL
69
Connectivity
7 communications Interfaces
70
Analog
1 12-bit DAC with output
buffer
1x12-bits 1Msps ADC w/ up to
16 external channels +
Temperature sensor/ voltage
reference/VBAT measurement
2 low power comparators
(Window mode and wakeup)
71
Hands-on #2 NVIC_WFI_Mode
NVIC_WFI_Mode Example
NVIC (Nested Vector Interrupt Controller) using EXTI
interrupt event
WFI (Wait For Interrupt) places CPU to sleep (reduces
power)
Action Steps
Exit Debugger
Close Keil uVision
73
74
Run Example
Action Steps
Compile
Debug
Run
Validate!
75
main.c
1. Configure board specific functionality
Init LED
Init pushbutton
76
77
Configure EXTI
Configure NVIC
78
79
main.c: WFI
The main control loop
EXTI interrupt controls the state variable LowPowerMode
Either flash LED or
Turn LED off and sleep using the Cortex M command Wait For Interrupt (WFI)
80
NVIC Linkage
1. PB triggers Event
2. EXTI Generates Interrupt
3. NVIC pushes 8 regs to
stack
Interrupt
Interrupt
Interrupt
PB Event
Presentation Title
15/10/2012
81
83
STM32 tools
Starter and promotion kits
numerous boards
Evaluation boards:
STM320518-EVAL, STM3240G-EVAL
STM32W-SK
EvoPrimer
STM32-ComStick
4 Discovery kits
and STM32L152D-EVAL
84
85
Motor control
Cryptographic algorithms
RTOS/Kernel
Customer application
Bluetooth stack
-FTP
-
Ethernet
USB
Specific
Graphical protocols SD/SDIO classes
-TCP/IP
protocol - Mass storage
protocols library
-HTTP
Ethernet SD/SDIO
Touch
sensing
library
-Audio
-
USB
DSP library
86
Pinout configuration
Peripherals configuration
Conflicts resolution
www.st.com/microxplorer
87
88
89
Thank you
www.st.com/stm32f0discovery