STM32L4 Seminars Fall 2015 - Rev13

STM32L4 Seminars Fall 2015 - Rev13
STM32L4 MCU series
Excellence in ultra-low-power with performance
Agenda
Presentation
Time
8:00 – 9:00
9:00 – 12:00
12:00 – 1:00
1:00 – 3:00
• System check for pre-installed tools. Tools handout
•
•
•
•
•
•
•
•
STM32L4 Family & Tools Overview
Hands On Session: Out-of-the-box demos
Cortex-M4 core
Hands On Lab#1: Getting Started with CubeMX and STM32L4
STM32L4 Overview: Architecture, Memory, Clocks, Power
Hands On Lab#2: printf() debugging via onboard ST-LINK
STM32L4 Low Power details
Hands On Lab#3: STM32CubeMX Power Consumption Calculator
• Lunch
•
•
•
•
STM32L4 Peripherals Details 1/2
Hands-On Lab#4: 3-axis MEMS Gyro communications
STM32L4 Peripherals Details 2/2
Hands-On Lab#5: Autonomous peripherals: ADC/TIM/DMA app
Systems Check
• Everyone should have:
• A Laptop running Windows OS (XP, Vista, Win7, Win8 or Win10)
• USB Cable
• USB Flash Drive
• STM32L476G-DISCO Discovery kit
• The following software tools installed:
• STM32CubeMX, v4.10.0 + CubeL4 HAL Library, v1.0.0
• ST-LINK Utility, v3.7.0
• IAR Embedded Workbench for ARM, v7.40.5.9739
• Teraterm (or equiv) terminal emulator
STM32L4
Family & Tools overview
Broadest 32-bit MCU product portfolio
CoreMark
75
93
273
106
177
245
398
608
1000
Broad Range of Development Tools
STM32
Nucleo
Discovery
kits
Evaluation
boards
3rd parties
Flexible
prototyping
Key feature
prototyping
Full feature
evaluation
From full evaluation to
open hardware
www.st.com/stm32nucleo
www.st.com/stm32discovery
STM32 Nucleo expansion boards
Specialized
functionality
add-on
www.st.com/x-nucleo
Connectivity, Sensors…
NEW
STM32 Nucleo features
Flexible board power supply
Through USB or external source
Integrated ST-Link/V2.1
Mass storage device flash programming
Virtual COM port for communications
2 push buttons, 2 color LEDs
Arduino™ extension connectors
Easy access for add-ons
One STM32 MCU flavor with 64 pins
Morpho extension headers
direct access to all MCU I/Os
Comprehensive choice of IDEs
STM32CubeMX
Partners IDEs
STMStudio
Generate Code
Compile & Debug
Monitor
Free
IDE
STM32Cube
Supporting all STM32 MCUs
• Generate your configuration code with the STM32Cube and you can
focus on your added-value software !
• 4 configuration wizards: pinout, clock, peripherals & middleware, power consumption
• Portable Hardware Abstraction layer, from series to others
• Middleware with RTOS, USB, TCP/IP, File System, Graphics , Touch sensing…
www.st.com/stm32cube
Comprehensive choice of STM32 free IDEs
tools
System
Workbench
CoIDE
MDK-ARM
COMING
COMING
Free licenses for all STM32
microcontrollers
Free licenses for
STM32F0
& STM32L0
Free access to
all STM32Nucleo
users
New ST MCU Finder Application
• Quickly find the right
ST MCU
• Easy access to
technical materials
• Latest news from ST
MCU world
www.st.com/stmcufinder
Birth of the STM32 L4
High-performance
ARM Cortex-M4 FPU, DSP
Advanced analog,
New digital peripheral set
Ultra-low-power
• STM32L4 is a perfect fit in terms of ultra-low power, performances,
memory size, and peripherals at a cost effective price.
• Convergence between High performance and Ultra-low power series
Key messages of STM32 L4 series
1
ULP leader and performance booster ST has built a new architecture delivering
best-in-class, ultra-low-power (ULP) figures thanks to its high flexibility. In addition
the performance of the STM32L4 far exceeds the competition in the
ultra-low-power world. It delivers 100 DMIPS based on its ARM Cortex-M4 core
with FPU and ST ART Accelerator™ at 80 MHz.
2
Innovation Covering a large range of applications the STM32L4 features many
architectural innovations and new smart embedded peripherals.
3
Integration and safety 1 MB of Flash and 128 KB of SRAM with safety and
security features, smart and numerous peripherals, advanced and low power
analog circuits in packages as small as 3.8 x 4.4 mm.
4
Great Investment This new STM32 member benefits from the pin-to-pin
compatibility of the STM32 family and the STM32 Ecosystem.
Ultra-Low-Power and Flexibility
FlexPowerControl
STM32L4 is based on a new platform optimized to reduce power
consumption and increase flexibility
Down to 30 nA for I/O wake-up
with additional Shutdown mode
External level shifter no longer needed
Separate VDD supplies
(down to 1.08 V)
Down to 360 nA keeping
32 Kbytes of SRAM active
in Standby mode
4 nA VBAT mode with charging
capability
Automatic switch to maintain power
for RTC and backup registers
STM32L4
Wake up MCU with any peripheral
(Communication I/Fs,
analog circuits, timers…)
I/O level kept in low power modes
Optimization of system consumption
RTC available for all power modes
(from Active down to VBAT)
USB capable with 32 kHz crystal
oscillator
(Dedicated crystal oscillator is no
longer needed for USB function)
Internal oscillator from 100 kHz to 48 MHz
(+/-0.25% int. 1
clock accuracy over voltage/temperature with LSE)
1
ULP leader and performance booster
Ultra-low-power modes
Best power consumption numbers with full flexibility
Wake-up time
VBAT
4 nA / 300 nA*
250 µs
SHUTDOWN
14 µs
STANDBY
14 µs
STANDBY + 32 KB RAM
Wake-up sources: reset pin, 5 I/Os,
RTC
30 nA / 330 nA*
5 µs
STOP 2 (full retention)
4 µs
STOP 1 (full retention)
6 cycles
Tamper: 3 I/Os, RTC
SLEEP
130 nA / 430 nA*
Wake-up sources: + BOR,
IWDG
360 nA / 660 nA*
Wake-up sources: + all I/Os, PVD,
LCD, COMPs, I²C, LPUART, LPTIM
1.1 µA / 1.4 µA*
7.3 µA / 7.6 µA*
35 µA / MHz
RUN at 24 MHz
Wake-up sources: + all I²C, UART
Wake-up sources: any interrupt
or event
100 µA / MHz
RUN at 80 MHz
112 µA / MHz
1
Note : * without RTC / with RTC
1
ULP leader and performance booster
STM32L4
This ULPBench® winner takes off like a rocket
Dhrystone
MIPS
And shatters performance limits
in ULP world
100
153
273
The higher the better!
www.st.com/stm32l4
From 0 to 48 MHz in less than 5 µs
From 0 to 80 MHz in less than 20 µs
Run
48 MHz
< 5 µs!
STOP
mode
Run
80 MHz
On competition devices: discontinuity due to lack of DC/DC
functionality when voltage decreases
No external coil and capacitor required for STM32L4
Providing more performance
Do not compromise on performance with STM32L4
CoreMark
score
Execution performance
from Flash
273
• Up to 80 MHz/ 100 DMIPS with
ART Accelerator™
Linear performance thanks
to ST ART AcceleratorTM
• Up to 273 CoreMark Result
• ARM Cortex-M4 with DSP instructions and
floating-point unit (FPU)
• Optimized DMA (14 channels)
Competitors: impact of wait states
• SPI up to 40 Mbit/s, USART 10 Mbit/s
CPU frequency
80 MHz
1
ULP leader and performance booster
High integration
High integration with high memory size in small packages
Parallel Interface
Connectivity
Display
Cortex-M4
80 MHz
FPU
MPU
ETM
LCD driver 8 x 40
DMA
Timers
ART
Accelerator™
FSMC 8-/16-bit
(TFT-LCD, SRAM, NOR,
NAND)
17 timers including:
2 x 16-bit advanced motor
control timers
2 x ULP timers
7 x 16-bit-timers
2 x 32-bit timers
Up to
1-Mbyte Flash
with ECC
Dual Bank
I/Os
128-Kbyte RAM
Up to 114 I/Os
Touch-sensing controller
USB OTG,
1x SD/SDIO/MMC, 3 x SPI,
3 x I²C, 1x CAN,
1 x Quad SPI,
5 x USART + 1 x ULP
UART,
1Digital
x SWP
Package size down
to 4.4 x 3.8 mm
AES (256-bit), TRNG, 2 x
SAI, DFSDM (8 channels)
Analog
3 x 16-bit ADC, 2 x DAC,
2 x comparators,
2 x op amps
1 x temperature sensor
3
Integration
and safety
Safety and security
Integrated safety and security features
ULP with
performance
SECURITY
SAFETY
•
•
•
•
•
•
•
Brown-out Reset
Clock Security System
SRAM parity check
Backup byte registers
Supply monitoring
Flash with ECC
Dual watchdog
•
•
•
•
•
•
•
•
Anti-tamper detection
Memory Protection Unit
Read and Write Protection
Unique ID
AES-256 Encryption
JTAG fuse
Random Number Generator
Software IP Protection
3
Integration and safety
STM32L4: continuity in STM32 portfolio
9 product series / 32 product lines
STM32L4 benefits from pin-to-pin compatibility across the family
2
High-performance
398 CoreMark
120 MHz
150 DMIPS
106 CoreMark
48 MHz
38 DMIPS
Ultra-low-power
93 CoreMark
32 MHz
33 DMIPS
Cortex-M0
Cortex-M0+
Cortex-M3
1 000 CoreMark
200 MHz
428 DMIPS
6
(*) from CCM-SRAM
1
3
75 CoreMark
32 MHz
26 DMIPS
1
245 CoreMark*
72 MHz
90 DMIPS
177 CoreMark
72 MHz
61 DMIPS
3
608 CoreMark
180 MHz
225 DMIPS
5
4
Mainstream
7
273 CoreMark
80 MHz
100 DMIPS
Cortex-M4
Cortex-M7
number of lines
4
Great investment
STM32L Ultra-Low-Power offering
STM32L4 completes the ultra-low-power family
Cost-smart
ULP Champion
Broad Range
Foundation
ULP with
performance
Cortex-M0+ @ 32 MHz
Operating range:
1.65 to 3.6V
8/16-bit applications
Numerous pin counts
Cortex-M3 @ 32 MHz
Operating range:
1.65 to 3.6V
Wide choice of
memory sizes
Cortex-M4 w/ FPU @ 80 MHz
Operating range:
1.71 to 3.6V
Advanced Peripheral
Performance
3 product lines,
Cost-effective,
Smaller packages
USB, LCD, Analog
16 to 192 Kbytes of Flash
Up to 20 Kbytes of SRAM
3 product lines,
USB, LCD, AES,
Rich Analog
True EEPROM,
Dual bank Flash (RWW)
32 to 512 Kbytes of Flash
Up to 80 Kbytes of SRAM
3 product lines,
ADC 5 Msps, PGA, Compar.,
DAC, op amp, USB OTG,
LCD, AES
256 Kbytes to 1 Mbyte of
Flash
Up to 128 Kbytes of SRAM
4
Great investment
STM32L, a complete offering
STM32L4 completes the ultra-low-power family
100 DMIPS
273 CoreMark
Performance
More
performance
More memory and pin counts
More packages
Flash size
(bytes)
WLCSP
1M
QFN
512 K
33 DMIPS
93
CoreMark
26 DMIPS
75 CoreMark
384 K
256 K
192 K
128 K
BGA
64 K
32 K
16 K
8K
MHz
32
32
80
20
28
36
32
48
49
63 100 132 144
64
4
Pins
LQFP
Great investment
Cortex®-M4 (DSP + FPU) – 80 MHz
STM32L4 series
•
•
•
•
•
•
•
8-ch /
ART Accelerator™
2
x
4x
16- bit
Segment
USART, SPI, I²C
Product
Flash RAM Memory
2x
USB2.0
AES
Op
Sigma
ADC
LCD
Quad SPI
line
(KB) (KB)
I/F
Comp
OTG FS
128/256-bit
amps
Delta
(5 Msps)
Driver
16 and 32-bit timers
Interface
SAI + audio PLL
SWP
512
STM32L471
SDIO
1x CAN
to
128
3
Access
FSMC
1024
•
•
2x 12-bit DAC
Temperature sensor STM32L475
USB OTG
•
Low voltage 1.71
to 3.6 V
VBAT Mode
Unique ID
Capacitive Touch
sensing
•
•
•
Legend:
256
to
1024
128
SDIO
FSMC
3
STM32L476 256
USB OTG &
to
LCD
1024
128
SDIO
FSMC
3
Up to
8x40
STM32L486
USB OTG & 1024
LCD & AES
128
SDIO
FSMC
3
Up to
8x40
Available in Q4/2015
4
Great investment
STM32L4 portfolio
Flash memory / RAM size (bytes)
STM32L486RG
1 M / 128 K
STM32L486JG
5
STM32L486VG
STM32L486QG
STM32L486ZG
5
STM32L476RG
STM32L476JG
STM32L476MG
STM32L476VG
STM32L476QG
STM32L476ZG
512 K / 128 K
STM32L476RE
STM32L476JE
STM32L476ME
STM32L476VE
STM32L476QE
STM32L476ZE
256 K / 128 K
STM32L476RC
STM32L476VC
Pin count
LQFP64
WLCSP72
WLCSP81
LQFP100
(10x10x1.4 mm) (4.4x3.8x0.585 mm) (4.4x3.8x0.585 mm) (14x14x1.4 mm)
Legend:
With 128/256-bit AES hardware encryption
UFBGA132
(7x7x0.6 mm)
LQFP144
(20x20x1.4 mm)
Without encryption
4
Great investment
STM32L4 ecosystem
HARDWARE TOOLS
STM32 Nucleo
SOFTWARE TOOLS
Evaluation board
Discovery kit
5
Flexible prototyping
Key feature
prototyping
Full feature
evaluation
STM32CubeMX featuring code generation and power
consumption calculation
4
Great investment
STM32 ODE
Nucleo and X-Nucleo
The building blocks
Your need
Our answer
Accelerometer, gyroscope
Inertial modules, magnetometer
Pressure, temperature, humidity, UV
Sense
DATA COLLECT
Proximity, microphone
Bluetooth LE, Sub-GHz radio
NFC, Wi-Fi, GNSS
Connect
DATA TRANSMIT
Audio amplifier
Touch controller
Translate
DATA ACCESS
Operation Amplifier
Stepper motor driver
DC & BLDC motor driver
Energy management & battery
General purpose microcontrollers
Secure microcontrollers
Move / actuate
Power
Process
Software
DATA CREATE
DATA POWER
DATA PROCESS
STM32 Nucleo
Nucleo Expansion Boards
Hands-On Session:
Out-of-the-box demos
STM32L476 Discovery – HMI
Integrated ST-Link/V2-1 (for
programming and debugging)
LCD 96 segments
Motion Mems (9-axis)
push buttons and joystick,
2 color LEDs
Quad SPI NOR Flash
16 MB
USB OTG connector
28
STM32L476 Discovery - Audio and connector
NFC / ACP connector
MFX to auto-measure power
consumption
Direct access to all MCU I/Os
Audio Codec and 3.5 mm
connector
Microphone Mems
29
STM32L476 Discovery - back side
Flexible board power supply
CR2032 battery or USB
Out-of-the-Box Demos
• Plug the USB cable into the top Mini-B connector of the Discovery Board
• Use the blue joystick to scroll through the application menu:
• IDD Measurement app
• VDD Measurement app
• Record / Playback app
• Compass app
• Sound Meter app
• Guitar Tuner app
• Options
• The project is in the CubeL4 library, Discovery Demonstrations folder:
• C:\Users\xxxx\STM32Cube\Repository\STM32Cube_FW_L4_V1.0.0\Projects\STM32L476GDiscovery\Demonstrations\EWARM
IDD / VDD Measurement apps
Mode
Description
Run
Run 24Mhz, voltage range 2, PLL off, RTC/LSE off, Flash ART on
Sleep
Sleep 24Mhz, voltage range 2, PLL off, RTC/LSE off, Flash ART on
Low-power run
Low Power Run 2Mhz, PLL off, RTC/LSE off, Flash ART on
Low-power
sleep
Low Power Sleep 2Mhz, PLL off, RTC/LSE off, Flash ART on
Stop 2
RTC/LSE off, Flash ART off
Standby
RTC/LSE off, Flash ART off, RAM retention off
Shutdown
RTC/LSE off, Flash ART off
The “IDD Measure” app uses the “MFX” onboard STM32L151 as a nonintrusive auto-ranging current measurement probe.
The target L4 will enter a low power state, the MFX will measure the current,
wake the L4 up and report the measurement back over I2C.
Audio demonstrations
• RECORD application
• Uses MP34DT01 MEMS microphone (LED5 toggling during record)
• 16-bit audio samples @ 48 kHz stored in N25Q128A13 QuadSPI Flash
• LEFT key to exit
• PLAYER application
• Uses CS43L22 audio DAC and 3.5mm jack output
• Audio playback either from internal or QuadSPI Flash after a RECORD. Sub-menus :
• “FLASH” : Audio playback of any WAV binary file loaded @ 0x08020000
• “QSPI” : Audio playback from QuadSPI Flash
• Options :
• SEL key to pause/resume playback
• UP/DOWN keys to control volume
• Audio is played back in loops until LEFT key is pressed
Compass and sound meter demonstrations
• COMPASS application
• Uses LSM303C eCompass MEMS device
•
3D accelerometer and 3D magnetometer
• Sub-Menu
•
•
“CALIB”: rotate board (360° on all axis's) after scrolling message invitation
“RUN”: displays angle in degrees
• LEFT key to exit
• SOUND meter application
• Uses MP34DT01 audio sensor to measure ambient noise
• Displays measurement value in dB on LCD screen
• LEFT key to exit
Guitar tuner demonstration
• Select guitar string
•
•
•
•
•
•
“STR1”: “E” (low E, thickest string, closest to the ceiling)
“STR2”: “A
“STR3”: “D”
“STR4”: “G”
“STR5”: “B”
“STR6”: “e” (high E, thinnest string, closest to the floor)
• RIGHT/SEL to start recording
• Output:
•
•
•
•
•
“ ++ “ when string needs to be tightened
“ + “ when string needs to be slightly tightened (close to correct tune)
“ OK “ when string is correctly tuned
“ - “ when string needs to be slightly loosened (close to correct tune)
“ -- ” when string needs to be loosened
• LEFT key to exit
Option app
• Select whether to enter STOP2 mode after few seconds of inactivity
• Display Firmware version #
1
1
ULP leader and performance booster
References
• Refer to www.st.com/stm32l4-discovery
• Ordering information
• Getting Started Manual, User’s Manual and Application notes
• Board Schematics
• Application development environments support
• Demonstration firmware sources
• Video available on YouTube and st.com
• “Getting started with STM32L476 discovery kit for ultra-low-power & performance
applications”
• https://www.youtube.com/watch?v=UkTFORUS29Q
Cortex-M4 Core
Cortex-M processors
• Forget traditional 8/16/32-bit classifications
• Seamless architecture across all applications
• Every product optimised for ultra low power and ease of use
Cortex-M0
Cortex-M3
“8/16-bit” applications
“16/32-bit” applications
Cortex-M4
“32-bit/DSC” apps
Binary and tool compatible
Cortex-M7
Hi-Performance apps
Cortex-M processors binary compatible
ARM Cortex M4 Core
FPU
Single precision
Ease of use
Better code efficiency
Faster time to market
Eliminate scaling and saturation
Easier support for meta-language tools
What is Cortex-M4?
MCU
Ease of use of C
programming
Interrupt handling
Ultra-low power
DSP
Cortex-M4
Harvard architecture
Single-cycle MAC
Barrel shifter
Cortex-M4 processor microarchitecure
• ARMv7ME Architecture
•
•
•
•
•
•
Thumb-2 Technology
DSP and SIMD extensions
Single cycle MAC (Up to 32 x 32 + 64 -> 64)
Optional single precision FPU
Integrated configurable NVIC
Compatible with Cortex-M3
• Microarchitecture
• 3-stage pipeline with branch speculation
• 3x AHB-Lite Bus Interfaces
• Configurable for ultra low power
• Deep Sleep Mode, Wakeup Interrupt Controller
• Power down features for Floating Point Unit
• Flexible configurations for wider applicability
• Configurable Interrupt Controller (1-240 Interrupts and Priorities)
• Optional Memory Protection Unit
• Optional Debug & Trace
Cortex-M4 extended single cycle MAC
OPERATION
CM3
CM4
SMULBB, SMULBT, SMULTB, SMULTT
SMLABB, SMLABT, SMLATB, SMLATT
SMLALBB, SMLALBT, SMLALTB, SMLALTT
SMULWB, SMULWT
SMLAWB, SMLAWT
SMUAD, SMUADX, SMUSD, SMUSDX
n/a
n/a
n/a
n/a
n/a
n/a
1
1
1
1
1
1
(16 x 16) ± (16 x 16) + 32 = 32
(16 x 16) ± (16 x 16) + 64 = 64
SMLAD, SMLADX, SMLSD, SMLSDX
SMLALD, SMLALDX, SMLSLD, SMLSLDX
n/a
n/a
1
1
32 x 32 =
32 ± (32
32 x 32 =
(32 x 32)
(32 x 32)
MUL
MLA, MLS
SMULL, UMULL
SMLAL, UMLAL
UMAAL
1
2
5-7
5-7
n/a
1
1
1
1
1
SMMLA, SMMLAR, SMMLS, SMMLSR
SMMUL, SMMULR
n/a
n/a
1
1
16 x 16 =
16 x 16 +
16 x 16 +
16 x 32 =
(16 x 32)
(16 x 16)
32
32 = 32
64 = 64
32
+ 32 = 32
± (16 x 16) = 32
32
x 32) = 32
64
+ 64 = 64
+ 32 + 32 = 64
32 ± (32 x 32) = 32 (upper)
(32 x 32) = 32 (upper)
INSTRUCTIONS
All the above operations are single cycle on the Cortex-M4 processor
Cortex-M4 DSP instructions compared
Cycle counts
CLASS
Arithmetic
Multiplication
Division
INSTRUCTION
ALU operation (not PC)
ALU operation to PC
CLZ
QADD, QDADD, QSUB, QDSUB
QADD8, QADD16, QSUB8, QSUB16
QDADD, QDSUB
QASX, QSAX, SASX, SSAX
SHASX, SHSAX, UHASX, UHSAX
SADD8, SADD16, SSUB8, SSUB16
SHADD8, SHADD16, SHSUB8, SHSUB16
UQADD8, UQADD16, UQSUB8, UQSUB16
UHADD8, UHADD16, UHSUB8, UHSUB16
UADD8, UADD16, USUB8, USUB16
UQASX, UQSAX, USAX, UASX
UXTAB, UXTAB16, UXTAH
USAD8, USADA8
MUL, MLA
MULS, MLAS
SMULL, UMULL, SMLAL, UMLAL
SMULBB, SMULBT, SMULTB, SMULTT
SMLABB, SMLBT, SMLATB, SMLATT
SMULWB, SMULWT, SMLAWB, SMLAWT
SMLALBB, SMLALBT, SMLALTB, SMLALTT
SMLAD, SMLADX, SMLALD, SMLALDX
SMLSD, SMLSDX
SMLSLD, SMLSLD
SMMLA, SMMLAR, SMMLS, SMMLSR
SMMUL, SMMULR
SMUAD, SMUADX, SMUSD, SMUSDX
UMAAL
SDIV, UDIV
CORTEX-M3 Cortex-M4
1
1
3
3
1
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
1 - 2
1
1 - 2
1
5 - 7
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
2 - 12
2 – 12
Single
cycle
MAC
FPU arithmetic instructions
Operation
Absolute value
Description
Assembler
Cycle
of float
VABS.F32
1
Addition
float
and multiply float
floating point
VNEG.F32
VNMUL.F32
VADD.F32
1
1
1
Subtract
float
VSUB.F32
1
float
then accumulate float
then subtract float
then accumulate then negate float
the subtract the negate float
then accumulate float
then subtract float
then accumulate then negate float
then subtract then negate float
VMUL.F32
VMLA.F32
VMLS.F32
VNMLA.F32
VNMLS.F32
VFMA.F32
VFMS.F32
VFNMA.F32
VFNMS.F32
1
3
3
3
3
3
3
3
3
float
VDIV.F32
14
of float
VSQRT.F32
14
Negate
Multiply
Multiply
(fused)
Divide
Square-root
DSP lib provided for free by ARM
• The benefits of software libraries for Cortex-M4
• Enables end user to develop applications faster
• Keeps end user abstracted from low level programming
• Benchmarking vehicle during system development
• Clear competitive positioning against incumbent DSP/DSC offerings
• Accelerate third party software development
• Keeping it easy to access for end user
• Minimal entry barrier - very easy to access and use
• One standard library – no duplicated efforts
• ARM channels effort/resources with software partner
• Value add through another level of software – eg: filter config tools
DSP lib function list snapshot
• Basic math – vector mathematics
• Fast math – sin, cos, sqrt etc
• Interpolation – linear, bilinear
• Complex math
• Statistics – max, min,RMS etc
• Filtering – IIR, FIR, LMS etc
• Transforms – FFT(real and complex) , Cosine transform etc
• Matrix functions
• PID Controller
• Support functions – copy/fill arrays, data type conversions etc
47
Memory map overview
4GB linear memory space
No paging/banking
0xFFFFFFFF
System region
System components
and debug
Device region
Off chip peripherals
RAM region
Off chip memory
Peripheral region
Peripherals
SRAM region
SRAM
CODE region
Program flash
0xE0000000
0xA0000000
All locations always accessible by
the SW
Supports 8/16/32-bit data
0x60000000
0x40000000
0x20000000
0x00000000
Standard across all Cortex-M implementations
Core Registers
• All registers are 32-bit wide
• Instructions exist to efficiently support
packed 8/16/32-bit data in memory
• 13 general purpose registers
• Registers r0 – r7 (Low registers)
• Registers r8 – r12 (High registers)
• Only 3 special registers (MRS, MSR)
• Stack Pointer (SP) – r13
• Link Register (LR) – r14
• Program Counter (PC) – r15
• Program Status Register
(Application / Interrupt / Execution)
r0
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
r11
r12
r13 (SP)
r14 (LR)
r15 (PC)
PSR
Register Usage Convention
Arguments
to a callee
Scratch registers
MOV R0,#4
BL FUNC
ADD R0,R0,#1
r0
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
r11
r12
Return value
Local
variables
Non-Scratch
registers
MOV R4,#4
BL FUNC
ADD R4,R4,#1
r13 (SP)
r14 (LR)
r15 (PC)
PSR
• ARM Architecture Procedure Call Standard (AAPCS)
Stack Pointer and Stacks
Only in Thread Mode !
31
2
1
CONTROL register
Active stack
pointer
Main Stack Pointer
Process Stack Pointer
0
1
0
r0
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
r11
r12
r13 (SP)
r14 (LR)
r15 (PC)
PSR
RTOS
Processor modes
Process Stack
/
Main Stack
RESET
STATE
(default)
THUMB STATE
Thread Mode
Normal code execution
Exception
return
Debug
operations
Exception
request
Handler Mode
Exception handler
execution
LOCKUP
STATE
Exception
request
Main Stack
DEBUG
STATE
Exception Model – Types and Priorities
No.
Exception Type
Priority
Type of
Priority
Descriptions
1
Reset
-3 (Highest)
fixed
Reset
2
NMI
-2
fixed
Non-Maskable Interrupt
3
Hard Fault
-1
fixed
Default fault if other hander not
implemented
Reserved
N.A.
N.A.
SVCall
Programmable
settable
12-13
Reserved
N.A.
N.A.
14
PendSV
Programmable
settable
Request for System-Level Service
15
SYSTICK
Programmable
settable
System Tick Timer
16
Interrupt #0
Programmable
settable
External Interrupt #0
………………..
settable
Programmable
settable
4-10
11
……
97
…………………..
Interrupt#81
Supervisor call (SVC)
…………………..
External Interrupt #31
4 priority levels
Interrupt Entry and Return
• Interrupt handling is micro-coded
→ No instruction overhead
• Entry (“Stacking”)
• Processor state automatically saved to the stack over the bus
• {PC, xPSR, R0-R3, R12, LR}
• What about the other registers?
• Then, ISR ready to start executing as soon as stack PUSH complete
• Exit (“Unstacking”)
• Processor state is automatically restored from the stack
• Then interrupted instruction is executed upon completion of stack POP
Preemption
• “Interruption of the exception handler”
• Depending on the priority
• If higher priority exception request comes while another
lower priority exception handler is executing
→ the higher priority exception can preempt the
lower priority exception handler
• Such exceptions are called nested exceptions
Exception Response
• Standard exception latency is 12-cycles
• The latency from processor clock cycle time when the exception is
asserted to the first instruction of the exception handler execution
• 0 memory wait states
• Can be reduced by the following two mechanisms:
• Tail Chaining
If exception request exists or occurs just as another exception handler returns
→ Stacking process can be skipped
• Late arriving (Late arrival)
If higher priority exception request occurs during lower prority exception stacking
process
→ Higher priority exception handler is called right after the stacking finishes
Interrupt Response – Tail-Chaining
Highest
IRQ1
IRQ2
42 CYCLES
ARM7
PUSH
Interrupt handling in
assembler code
ISR 1
POP
PUSH
16
26
ISR 2
26
Tail-chaining
PUSH
Cortex-M
Interrupt handling in HW
ISR 1
12
ARM7
• 26 cycles from IRQ1 to ISR1 entered
• Up to 42 cycles if LSM
• 42 cycles from ISR1 exit to ISR2 entry
• 16 cycles to return from ISR2
ISR 2
6
POP
12
Cortex-M
• 12 cycles from IRQ1 to ISR1 entered
• 6 cycles from ISR1 exit to ISR2 entry
• 12 cycles to return from ISR2
POP
16
Interrupt Response – Late Arriving
IRQ1
Highest
IRQ2
ARM7
PUSH
PUSH
26
Cortex-M0
PUSH
ISR 1
26
ARM7
• 26 cycles to ISR2 entered
• Immediately pre-empted by IRQ1 and
takes a further 26 cycles to enter ISR 1.
• ISR 1 completes and then takes 16
cycles to return to ISR 2.
ISR 2
16
ISR 2
ISR 1
12
POP
POP
6
TailChaining
12
Cortex-M
• Stack push to ISR 2 is interrupted
• Stacking continues but new vector address
is fetched in parallel
• Late-arrival to ISR1 entry will depend
of the PUSH status, then 4 cycles
will be necessary to read the vector table.
• Tail-chain into ISR 2
POP
16
STM32CubeTM Introduction
• STM32CubeTM includes:
• A configuration tool, STM32CubeMX generating initialization code from user choices
• Firmware offering, delivered per series (like STM32CubeF4) with:
• An STM32 Abstraction Layer embedded software: STM32Cube HAL
• A consistent set of Middleware: RTOS, USB, TCP/IP, Graphics, …
STM32CubeMX
STM32CubeL0
STM32CubeF4
STM32CubeL1
STM32CubeF2
STM32CubeF0
STM32CubeF3
STM32CubeL4
STM32CubeF1
STM32CubeMX
Pinout Wizard
Peripherals & Middleware
Wizard
Power Consumption
Wizard
Clock Tree wizard
Power consumption calculator
• Power step
definitions
• Battery selection
• Creation of
consumption
graph
• Display of
• Average
consumption
• Average DMIPS
• Battery lifetime
STM32Cube Firmware Components
Evaluation boards
Discovery boards
Nucleo boards
Board Demonstrations
Middleware level Applications
Networking
LwIP TCP/IP
& Polar SSL
Utilities
USB
Host & Device
Graphics
STemWin
File system
FATFS
RTOS
FreeRTOS
Middleware
HAL level Examples
HAL
Hardware Abstraction Layer API
CMSIS
Boards Support Packages
Drivers
STM32L471
Fx/Lx Family
STM32L475
STM32L476
STM32L486
Hands-On Lab #1:
Getting Started with CubeMX
LED Blinky in Five Easy Steps!
Run STM32CubeMX
Step 1: Create New Project
• Create New Project
• Select STM32L476VGTx
• LQFP100, 1024KB Flash
• Click “OK”
Step 2: Pin Configuration
• In this example we are going to use the LED’s present on the
STM32L476 Discovery board.
• Left-click PB2 & PE8 and set to GPIO_Output mode
Step 3: Generate Source Code
• Open Project > Settings (Alt + P)
• Set the project name (Lab1) and the
project location
(C:\STM32L4Seminar\Labs)
• Set the IDE Toolchain to EWARM
• Click OK
• Generate Code (Ctrl + Shift + G)
• Click Open Project
Step 4: Toggle The LED
• The IAR EWARM IDE should now be open.
• Expand the file tree and open the main.c file
• Add the following code inside the while(1) loop
• Line 85 in “main.c”
• Add within “USER CODE BEGIN WHILE” / “USER CODE END
WHILE” section (this will preserve your code after regeneration)
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_2);
HAL_Delay(100);
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_8);
HAL_Delay(100);
Step 5: Build the Project
• Click “F7” or the “Make” button or use menu Project > Make.
• Click the “Download and Debug” Green
Arrow button (CTRL + D)
• Click the “Go” button (F5)
• Enjoy the flashing LED’s!
STM32L4 Overview
Architecture, Memory, Clocks, Power
STM32L476 block diagram
STM32L4 Bus matrix
DMA1
DMA2
Accel.
S-bus
D-bus
I-bus
Cortex M4
with FPU
Flash
1 MB
SRAM1 96 KB
SRAM2 32 KB
AHB1
Periph.
AHB2
Periph.
QUADSPI
FMC
Note: QuadSPI, FMC and SRAM1 I-bus & D-bus interfaces when remapped to 0x0000 0000 only
APB1 Periph.
APB2 Periph.
Memory Mapping
0xFFFF FFFF
•
Reserved
0xE010 0000
FLASH : up to 1 Mbytes, dual bank
•
Cortex-M4 internal
peripherals
FB_MODE = 0 in SYSCFG_MEMRMP:
Bank 1 @ 0x0800 0000
0xE000 0000
Bank 2 @ 0x0808 0000
0x1FFF FFFF
•
Reserved
Option Bytes
0xB000 0000
FMC & QUADSPI
registers
0xA000 0000
QUADSPI bank
Bank 2 @ 0x0800 0000
0x1FFF C000
Bank 1 @ 0x0808 0000
System Memory 0x1FFF 0000
Reserved
SRAM2
0x1000 8000
•
SRAM: Up to 128 Kbytes SRAM split in 2 parts :
•
•
0x1000 0000
0x9000 0000
FMC banks
FB_MODE = 1 in SYSCFG_MEMRMP
0x1FFF C008
Reserved
Reserved
0x0810 0000
SRAM1 : 96 KBytes @2000 0000
SRAM2 : 32 KBytes @1000 0000 :
Access through D-code and I-code
0x6000 0000
Peripherals
Flash
0x0800 0000
0x4000 0000
SRAM1
•
Reserved
0x0010 0000
0x2000 0000
CODE
0x0000 0000
Memory type
depending on
boot
configuration
0x0000 0000
Physical remap at 0x0000 0000 selected by
MEM_MODE in SYSCFG_MEMRMP:
• Flash Bank 1 or Bank 2 (see FB_MODE)
• System flash (bootloader)
• FMC bank 1
• SRAM1
• QUADSPI
Boot modes
Boot mode selection
BOOT1
BOOT0
(opposite of nBOOT1
option bit)
(pin)
x
Boot mode
Aliasing
0
User Flash
Main Flash memory is
selected as boot space
1
1
System
memory
System memory is
selected as boot space
0
1
SRAM1
Embedded SRAM1 is
selected as boot space
• Flash Bank1 boot: Option Bit BFB2 = 0
• Flash Bank2 boot: Option Bit BFB2 = 1
• Bootloader supports: USART1/2/3, I2C1/2/3, SPI1/2/3, USB DFU, CAN
32KB SRAM2 features
• Access through D-code and I-code:
Code execution max performance without remap
• HW parity check : 4 bit per word
• Enabled with SRAM2_PE user option bit
• NMI / Timer Break on parity check error
• Optional retention in Standby mode
• Write protection with 1 Kbyte granularity
• Read protection with RDP :
Erased when RDP changed from Level 1 to Level 0
• Software reset and optional Hardware reset when system reset
• Erased when setting SRAM2ER in SYSCFG_SCSR SRAM2 control and status register
• Erased with system reset via SRAM2_RST user option bit
15/10/2015
Flash organization
• Two 512KB User Flash banks:
• Each bank is 256 pages of 2KB
• Information block:
• System memory boot loader
• 1 KB (128 double word) OTP for user data
• Option bytes for user configuration
Flash area
Bank 1
Flash memory address
0x0800 0000 – 0x0800 07FF
Size
2K
…
Main memory
Bank 2
Page 0
…
0x0807 F800 – 0x0807 FFFF
2K
Page 255
0x0808 0000 – 0x0808 07FF
2K
Page 256
…
Information
block
Name
…
0x080F F800 – 0x080F FFFF
2K
Page 511
Bank 1
0x1FFF 0000 – 0x1FFF 6FFF
28K
Bank 2
0x1FFF 8000 – 0x1FFF EFFF
28K
System
memory
Bank 1
0x1FFF 7000 – 0x1FFF 73FF
1K
OTP area
Bank 1
0x1FFF 7800 – 0x1FFF 780F
16
Option bytes
Bank 2
0x1FFF F800 – 0x1FFF F80F
16
Program / Erase
• ECC (Error Code Correction) : 8-bit for 64-bit word
• Single error correction:
• Failure address and bank saved in FLASH_ECCR register, optional interrupt
• Double error detection : NMI!
• Programming granularity is 64-bit
• Page granularity for erase is 2 Kbytes
Parameter
Typ
64-bit programming time
82 µs
Page (2 KB) erase time
22 ms
One row (32 double-word) programming time
Normal : 2.6 ms
Fast : 1.9 ms
One page (2 KB) programming time
Normal : 20.9 ms
Fast : 15.3 ms
One bank (512 KB) programming time
Normal : 5.35 s
Fast : 3.9 s
Mass erase time (1 or 2 banks)
22 ms
Performances
Mode
STM32L15x
STM32L4x
CortexM3
CortexM4 + FPU
Flash I/F
Prefetch
ART
Frequency
32MHz
80MHz
~35 DMIPS
~100 DMIPS (no loss)
CPU
Performance
DMIPS
STM32L4
STM32L15x
MHz
ART overview
• Instruction cache = 32 lines of 4x64 bits (1KB)
• Data cache = 8 lines of 4x64 bits (256 B)
• Best tradeoff between cache size, Power and Dhrystone/CM
performances
64
64
64
64
ART
I Cache
8x128
32x4x64
CM4
core
I Current buffer (64)
AHB 32
I Prefetch buffer (64)
FLASH
FLASH
Memory
Memory
128kx64
128kx64
Flash protections
Flexible Protections configurable with option bytes :
• Readout protection (RDP)
• Forbids access to Flash/SRAM2/Backup registers by:
• Debug interface (JTAG/SWD)
• Boot from SRAM1
• Bootloader
• Proprietary Code Protection (PCROP) with 64-bit granularity
• Used to protect specific code area from any read or write access
• The code can only be executed.
• Write Protection (WRP) with 2-KByte granularity
• Used to protect specific code area from unwanted write/erase
Readout Protections
• Readout protection Level 0 : No read protection
•
All operations are possible in all boot configurations.
• Readout protection Level 1
•
User mode: Code executing in user mode can access main Flash memory, option bytes,
RTC backup registers and SRAM2 with all operations.
•
Debug, boot RAM and boot loader modes: The main Flash memory, backup registers and
SRAM2 are totally inaccessible in these modes, a simple read access generates a bus error
and a Hard Fault interrupt.
• Un-protection, Level 1 to Level 0:
•
Flash memory is mass-erased, RTC backup registers and SRAM2 are cleared
•
If Option bit PCROP_RDP is set, the PCROP-protected area is not erased
• Readout protection Level 2 (No debug)
•
•
•
•
All protections provided by Level 1 are active.
RAM boot, System memory boot and all debug features are disabled
Option bytes can no longer be changed in user mode.
Un-protection is not possible. It is an irreversible operation
Proprietary Code (PCROP) / Write Protections
• When enabled, PCROP area is protected against all D-code bus accesses
• The PCROP regions are execute-only
• 1 area per bank, 64-bit granularity.
•
PCROP area can be increased but never decreased
•
Only way to deactivate PCROP is to change RDP from Level 1 to Level 0
• Option bit PCROP_RDP
• When DISABLED: PCROP content is erased when RDP is changed from Level 1 to Level 0.
PCROP_RDP is locked in this state.
• When ENABLED: PCROP content is preserved when RDP is changed from Level 1 to Level 0.
• Flash Write Protection:
• Write-protected area is protected against erasing and programming.
• 2 areas per bank, 2-KByte granularity.
STM32 Firewall (FW)
• The FIREWALL is made to protect parts of code/data (volatile and non volatile) from
access from the rest of the code executed outside of the protected area.
Code Segment (NVM Code)
31
24 23
8 7
1
8 7
1
Start Address
31
22 21
FW_CSSA
Length
Cortex-M4
GP-DMA
FW_CSL
Protection : Code fetch
Bus Matrix
Non-Volatile Data Segment (NVM Data)
31
8 7
24 23
1
Start Address
SRAM1
AHB/APB
31
FLASH
FW_NVDSSA
8 7
22 21
1
Length
Protection : Data
NVM code
NVM data
Volatile Data
FW_NVDSL
FIREWALL
Volatile Data Segment (SRAM1 Data)
Reset event
31
17 16
8 7
1
8 7
1
Start Address
31
3 Segments may be protected
by the Firewall
22 21
Length
FW_VDSSA
FW_VDSL
Protection: - Code fetch if SRAM1 is executable (not shared)
- Data
1
31
VDE
VDS
FPA
FW_CR
FPA : Pre-alarm bit to control the exit point of the protected code
VDS : SRAM1 protected segment is sharable with non protected code
VDE : SRAM1 is executable into the protected volatile data segment
Clock Tree
Clocks: MSI (Multi-Speed Internal)
• MSI = clock at startup from Reset, Standby or Shutdown modes.
• 12 Programmable frequency ranges:
100 kHz, 200 kHz, 400 kHz, 800 kHz, 1 MHz, 2 MHz, 4 MHz (reset value), 8
MHz, 16 MHz, 24 MHz, 32 MHz, 48 MHz.
• After Standby: Frequency selected from 1, 2, 4 or 8 MHz with
MSISRANGE in RCC_CSR register.
• Normal mode and PLL-mode (=auto-calibration with LSE)
PLL-mode : allows USB FS device functionality (0.25% accuracy)
• Factory and user trimmed
Clocks: HSI(High-Speed Internal)
• HSI 16MHz, factory and user trimmed
• Selectable as wakeup clock from STOP1 / STOP2
• Can be automatically woken up when exiting Stop modes
• Can be used as I2C/USART/LPUART source upon wakeup
HSI vs. MSI (design spec)
MSI
Normal mode
HSI
PLL-mode
Over temperature: ±6%
Accuracy (max)
Over voltage:
From 100 to 800 kHz : ±1%
From 1 to 8 MHz : ±2%
From 16 to 48 MHz : ±4%
Better than
0.25%
0.3% after trim
100 kHz : 0.5 µA
800 kHz : 2µA
Consumption (typ)
1 MHz : 5µA
130 µA
8 MHz : 20 µA
16 MHz : 60 µA
48 MHz : 160 µA
Startup time (typ)
100 kHz : 10 µs
48 MHz : 2.5 µs
1.25 ms for
5% of final
freq.
0.9 µs
Clocks: HSE(High-Speed External)
• HSE 4-48MHz
• External source (Bypass mode) up to 40 MHz
• External Crystal/Ceramic resonator (4-48MHz)
• Clock Security System (CSS)
• Automatic detection of HSE failure with
• NMI generation
• Break input to TIM1/TIM8/TIM15/TIM16/TIM17
• Backup clock can be HSI or MSI
Clocks: PLL
• 3 PLL’s
• Each with 3 independent outputs
• PLL input freq = 4-16 MHz
• PLL input can be MSI/HSI or HSE
5,6,7,8
f(VCO clock) =
(f(PLL clock input)/PLLM) × PLLN
f(PLL_P) = f(VCO clock) / PLLP
f(PLL_Q) = f(VCO clock) / PLLQ
f(PLL_R) = f(VCO clock) / PLLR
PLLM from 1 to 8
PLLN from 8 to 86
PLLP = 7 or 17
PLLQ = 2, 4, 6, 8
PLLR = 2, 4, 6, 8
PLLP from 2 to 31 in derivatives
Clocks: LSE (Low-Speed External)
• LSE: programmable amplifier driving capability (4 modes)
Mode
Crystal (max)
Consumption (typ)
Ultra low power
50kOhm/6pF
200 nA
Medium low driving
80kOhm/6pF
260 nA
Medium high driving
50kOhm/12.5pF
410 nA
High driving
80kOhm/12.5pF
540 nA
• Available in all low-power modes + VBAT
Clocks: LSI (Low-Speed Internal)
• LSI 32kHz
Parameters
STM32L15x
STM32L4x
Accuracy over parts
26..56KHz
~8%
Accuracy over temperature
-10% / +4%
(0..85°C)
Consumption (typ)
400nA
2%
(-40 125°C)
110nA
• Available in all low-power modes except Shutdown and VBAT
Power schemes (1/3)
2 OPAMP
2 COMP
3 ADC
2 DAC
VREF buffer
VDDA
VREF+
VLCD
LCD
USB transceivers
CPU
SRAM1
SRAM2
Digital
peripherals
LCD booster
Flash
Reset block
Temp. sensor
3 PLL, HSI, MSI
VDD
VDDIO1
I/O ring
VDDIO2
VDDIO2
I/O ring
VDDUSB
VCORE
Voltage Regulator
Standby circuitry
(wakeup, IWDG)
Backup domain
LSE, RTC, backup registers
VBAT
Peripheral Voltage Monitor
• By default independent powers are electrically isolated and the features
powered by them are not available
• The power isolation must be removed by SW
• Peripheral Voltage Monitor for VDDA, VDDUSB, VDDIO2:
PVM
Power
supply
PVM threshold
EXTI line
PVM1
VDDUSB
VPVM1 = 1.2 V
35
PVM2
VDDIO2
VPVM2 = 0,9 V
36
PVM3
VDDA
VPVM3 = 1.65 V
37
PVM4
VDDA
VPVM4 = 1.82 V
38
Power supply Supervisor
BOR complies with all VDD rise/fall time = no constraint on power supply shape
VDD
VBORx
VBORx (rising edge)
hysteresis
VBORx (falling edge)
tRSTTEMPO
nReset
VCORE Voltage Regulator
• Dynamic Voltage Scaling optimizes performance vs power
• VCORE Voltage Range 1 = 1.2V (Up to 80MHz)
• VCORE Voltage Range 2 = 1.0V (Up to 26MHz)
• VCORE powered by main regulator (MR) or low-power regulator (LPR)
• MVR for Run and Sleep modes.
• LPR for LP run, LP sleep and STOP1/STOP2 modes.
• Regulators OFF in Standby and Shutdown mode.
• However LPR remains ON to preserve SRAM2 content in Shutdown mode, if required.
95
Dynamic voltage scaling in Run mode
SYSCLK(MHz)
127µA/MHz @80MHz
80
4WS
64
3WS
48
2WS
32
1WS
1WS
111µA/MHz @26MHz
26
3WS
1WS
18
16
2WS
12
1WS
6
2
VCORE
VDD
136µA/MHz @26MHz
0WS
0WS
Low-power run
VCORE = 1.1V
Range 2
VCORE = 1.0V
0WS
V
Range 1
VCORE = 1.2V
1.71V .. 3.6V
96
Hands-On Lab #2:
printf() debugging
Hands-On Lab #2 – printf() debugging
Adding to the existing CubeMX project, we will add USART2
debug via the ST-LINK Virtual-COM port
Set up additional GPIO / Clocks:
PD5 – USART2, “VirtualCOM-TX” – Alt. Fn. Push/Pull
PD6 – USART2, “VirtualCOM-RX” – Alt. Fn. Push/Pull
PA0 – GPIO_EXTI0: External Interrupt on Rising Edge Input
USART2 Clock = PCLK1 (80MHz)
USART2 settings:
Asynchronous Mode - 9600 N/8/1, No HW Flow control
Tx/Rx, 16-sample oversampling
No advanced features
User Code HAL function calls required:
See lab2_printf_debug.c in Lab2_Printf directory
Also Need Terminal emulator (Hyperterm, etc)
USART2 is routed to the ST-LINK’s
USART, and brought via the USB
Virtual-COM port class
(SB13/16 have been soldered)
98
GPIO Configuration additions
• Expand the USART2 dialog, and select Asynchronous mode:
• Use PD5 & PD6 for Tx / Rx pins:
• These are the alternate mapping pins (PA2/3 are default)
• Use PA0 in External Interrupt Mode, Rising edge trigger:
Clock Configuration
• We will run the STM32L4 at 80MHz for this lab
• Click on the Clock Configuration tab
• Set the PLL Source Mux to MSI (MSI RC = 4000 KHz)
• Set the System Clock Mux to PLLCLK
• Use PLLM=/1, *N = x40, /R=/2
• AHB Prescaler = /1
• HCLK should equal 80MHz
80MHz
USART2 Configuration
• Click on the Configuration tab, and select USART2:
• Parameter Settings tab:
• 9600Bits/s
• 8-bit word length
• No parity bit
• 1 Stop bit
• Rx & Tx data
• 16-clock oversampling
• No advanced feature settings needed
• No NVIC or DMA settings used
NVIC Configuration
• Click on the Configuration tab, and select NVIC:
• Enable EXTI line0
• Set Preemption Priority to 2
• Click ‘OK’
Regenerate Source Code for Lab1
• Generate Code (Ctrl + Shift + G)
• Open Project
• Copy/Paste needed code bits for Hands-On Lab #2 into main.c:
• C:\STM32L4Seminar\Labs\lab2_printf_debug.c
•
•
•
•
Add
Add
Add
Add
code bits between:
code bits between:
code bits between:
code bits between:
/* USER CODE BEGIN PV */
/* USER CODE BEGIN 2 */
/* USER CODE BEGIN WHILE */
/* USER CODE BEGIN 4 */
/* USER CODE END PV */
/* USER CODE END 2 */
/* USER CODE END WHILE */
/* USER CODE END 4 */
• Open a terminal emulator, using USART2 settings, Virtual COM port xx
• Rebuild, Program/Debug, Run!
STM32L4
Low Power details
Available
Peripheral
GPIO
DMA
FSMC
QUADSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
STM32L4 Power Mode
Run mode
Run Mode Range 1
Ex: execution from Flash
Cortex M4
Main regulator (MR)
Range 1 (up to 80MHZ)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Range 2 (up to 26MHZ)
Low Power
regulator (LPR)
Range 1
131uA/MHz at 80 MHz
(10.2mA)
Range 2
112uA/MHz at 26 MHz
(2.9 mA)
up to 2MHz
Available
Clock
HSI
HSE
LSI
LSE
MSI
Active cell
Frozen cell
Cell in
power-down
Available
Periph and clock
Available
Peripheral
GPIO
DMA
DMA
FSMC
FSMC
QUADSPI
QUADSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
STM32L4 Power Mode
Low-power run mode
Low-power run mode
Ex: execution from Flash
Cortex M4
Main regulator (MR)
Range 1 (up to 80MHZ)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Range 2 (up to 26MHZ)
Low Power
regulator (LPR)
from Flash
135 µA/MHz at 2 MHz
(269 µA)
From SRAM1
112 µA/MHz at 2 MHz
(225 µA)
up to 2MHz
Available
Clock
HSI
HSE
LSI
LSE
MSI
Active cell
Frozen cell
Cell in
power-down
Available
Periph and clock
Available
Peripheral
GPIO
DMA
DMA
FSMC
FSMC
QUADSPI
QUADSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
STM32L4 Power Mode
Sleep mode
Sleep Mode Range 1
Ex: Flash ON, SRAMs ON (default)
Zzz
Cortex M4
Main regulator (MR)
Range 1 (up to 80MHZ)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Range 2 (up to 26MHZ)
Low Power
regulator (LPR)
Range 1
37 µA/MHz at 80 MHz
(2.96 mA)
Range 2
35 µA/MHz at 26 MHz
(0.92 mA)
up to 2MHz
Available
Clock
HSI
HSE
LSI
LSE
MSI
Active cell
Frozen cell
Cell in
power-down
Available
Periph and clock
Available
Peripheral
GPIO
DMA
DMA
FSMC
FSMC
QUADSPI
QUADSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
STM32L4 Power Mode
Low-power sleep mode
Low-power sleep mode
Ex: Flash OFF, SRAM1 OFF
Zzz
Cortex M4
Main regulator (MR)
Range 1 (up to 80MHZ)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Range 2 (up to 26MHZ)
Low Power
regulator (LPR)
Flash ON, SRAMs OFF
48 µA/MHz at 2 MHz
(96 µA)
Flash OFF, SRAMs OFF
40,5 µA/MHz at 2 MHz
(81 µA)
up to 2MHz
Available
Clock
HSI
HSE
LSI
LSE
MSI
Active cell
Frozen cell
Cell in
power-down
Available
Periph and clock
Available
Peripheral
GPIO
DMA
FSMC
QSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
I/Os kept, and configurable
STM32L4 Power Mode
Stop 1 Mode
Stop 1 w/ RTC
on LSE quartz
7.1 µA @3.0V
6.9 µA @1.8V
Wake-up
event
Zzz
Cortex M4
Main regulator (MR)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Available
Clock
HSI
HSE
LSI
LSE
MSI
Low Power
regulator (LPR)
Backup domain
Backup Register
(32x32-bits)
RTC
NRST
BOR
PVD
PVM
RTC + Tamper
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SWPMI
COMP
LPTIM 1
LPTIM 2
IWDG
GPIOs
6us wake-up from Flash
4us wake-up from RAM
Available
Peripheral
GPIO
DMA
FSMC
QSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
I/Os kept, and configurable
STM32L4 Power Mode
Stop 2 Mode
1.67 µA @3.0V
1.43 µA @1.8V
Stop 2 w/ RTC
on LSE quartz
Wake-up
event
Zzz
Cortex M4
Main regulator (MR)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Low Power
regulator (LPR)
NRST
BOR
PVD
PVM
RTC + Tamper
LCD
LP UART
I2C 3
Available
Clock
HSI
HSE
LSI
LSE
MSI
Backup domain
Backup Register
(32x32-bits)
RTC
COMP
LPTIM 1
IWDG
GPIOs
7us wake-up from Flash
5us wake-up from RAM
Available
Peripheral
GPIO
DMA
FSMC
QSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
I/Os can be configured
w/ or w/o pull-up
w/ or w/o pull-down
STM32L4 Power Mode
Standby Mode
Standby
w/ SRAM2
w/o RTC
Zzz
Cortex M4
405 nA @ 3.0V
363 nA @1.8V
Main regulator (MR)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Available
Clock
HSI
HSE
LSI
LSE
MSI
Low Power
regulator (LPR)
Backup domain
Wake-up
event
NRST
BOR
RTC + Tamper
IWDG
5 WKUP pins
Backup Register
(32x32-bits)
RTC
14 us wake-up
Available
Peripheral
GPIO
DMA
FSMC
QSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
I/Os can be configured
w/ or w/o pull-up
w/ or w/o pull-down
STM32L4 Power Mode
Standby Mode
650 nA @ 3.0V
433 [email protected] 1.8V
Standby w/ RTC
on LSE quartz
Zzz
Cortex M4
Main regulator (MR)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Available
Clock
HSI
HSE
LSI
LSE
MSI
Low Power
regulator (LPR)
Backup domain
Wake-up
event
NRST
BOR
RTC + Tamper
IWDG
5 WKUP pins
Backup Register
(32x32-bits)
RTC
14 us wake-up
Available
Peripheral
GPIO
DMA
FSMC
QSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
I/Os can be configured
w/ or w/o pull-up
w/ or w/o pull-down
STM32L4 Power Mode
Standby Mode
150 nA @ 3.0V
114 nA @ 1.8V
Standby
Zzz
Cortex M4
Main regulator (MR)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Available
Clock
HSI
HSE
LSI
LSE
MSI
Low Power
regulator (LPR)
Backup domain
Wake-up
event
NRST
BOR
RTC + Tamper
IWDG
5 WKUP pins
Backup Register
(32x32-bits)
RTC
14 us wake-up
Available
Peripheral
GPIO
DMA
FSMC
QSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
STM32L4 Power Mode
I/Os can be configured
w/ or w/o pull-up
w/ or w/o pull-down
But floating when exit from Shutdown
Shutdown Mode
Shutdown w/ RTC
on LSE quartz
550 nA @ 3.0V
329 nA @ 1.8V
Zzz
Cortex M4
Main regulator (MR)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Low Power
regulator (LPR)
Wake-up
event
NRST
RTC + Tamper
Available
Clock
HSI
HSE
LSI
LSE
MSI
Backup domain
5 WKUP pins
Backup Register
(32x32-bits)
RTC
250 us wake-up
Available
Peripheral
GPIO
DMA
FSMC
QSPI
BOR
PVD, PVM
LCD
USB OTG
USART
LP UART
I2C 1 / I2C 2
I2C 3
SPI
CAN
SDMMC
SWPMI
SAI
DFSDM
ADC
DAC
OPAMP
COMP
Temp Sensor
Timers
LPTIM 1
LPTIM 2
IWDG
WWDG
Systick Timer
Touch Sens
RNG
AES
CRC
STM32L4 Power Mode
I/Os can be configured
w/ or w/o pull-up
w/ or w/o pull-down
But floating when exit from Shutdown
Shutdown Mode
64 nA @ 3.0V
30 nA @ 1.8V
Shutdown
Zzz
Cortex M4
Main regulator (MR)
SRAM 1
(96KB)
Flash
(1MB)
SRAM 2
(32KB)
Low Power
regulator (LPR)
Wake-up
event
NRST
RTC + Tamper
Available
Clock
HSI
HSE
LSI
LSE
MSI
Backup domain
5 WKUP pins
Backup Register
(32x32-bits)
RTC
256 us wake-up
Low-power modes summary
Mode
Regulator
CPU
Flash
SRAM
Clocks
R1
Run
Yes
ON(1)
ON
Any
R2
LPRun
LPR
Peripherals
In Bold : wakeup source
Consumption
@ 1.8V
All
131 µA/MHz
All except
OTG, SDMMC, RNG
112 µA/MHz
135 µA/MHz
Yes
ON(1)
ON
Any
except PLL
All except
OTG, SDMMC, RNG
No
ON(1)
ON(2)
Any
All
Any IT or event
R1
Sleep
R2
LPSleep
LPR
No
ON(1)
ON(2)
6.6µA w/o RTC
6.9 µA w/RTC
4 µs RAM
6 µs Flash
1.2 µA w/o RTC
1.4 µA w/RTC
5 µs RAM
7 µs Flash
OFF
ON
LSE/LSI
Stop 2
LPR
No
OFF
ON
LSE/LSI
Reset pin, all I/Os
BOR,PVD,PVM,RTC,LCD,IWDG,
COMPx,LPUART,I2C3,LPTIM1
LSE/LSI
Reset pin, 5 WKUPx pins
BOR, RTC, IWDG
LSE
Reset pin, 5 WKUPx pins
RTC
SRAM2 ON
OFF
Shutdown
OFF
+ 235 nA
DOWN
DOWN
OFF
DOWN
6 cycles
35 µA/MHz
6 cycles
No
DOWN
37 µA/MHz
40 µA/MHz
LPR
OFF
TBD
All except
OTG, SDMMC, RNG
Any IT or event
Stop 1
Standby
N/A
Any
except PLL
Reset pin, all I/Os
BOR,PVD,PVM,RTC,LCD,IWDG,
COMPx,DACx,OPAMPx,USARTx,
LPUART,I2Cx,LPTIMx,OTG_FS,
SWPMI
LPR
Wakeup
time
1. Can be put in power-down and clock can be gated off
2. SRAM1 and SRAM2 can be gated off independently
128 nA w/o RTC
433 nA w/RTC
30 nA w/o RTC
329 nA w/RTC
14 µs
256 µs
Low-power modes transitions
LPSleep
Sleep
LPRun
Shutdown
Stop1
Run
Standby
Stop2
Hands-On Lab #3:
Power Consumption Calculator
Power Consumption Calculator Lab
• Click on the Power Consumption Calculator tab in CubeMX
• Select two AAA Alkaline batteries (in series) as our power source:
Power Consumption Calculator Lab
• Add a step to our power sequence: Click: Step.. Add
• Configure a 10ms step:
• 4.0MHz Range2 RUN mode
• GPIOB, GPIOE and USART2 peripherals enabled
• Click “Add”
• Resulting step consumption should be 762.8uA
Power Consumption Calculator Lab
• Add three more additional power steps:
• STOP2 mode, Battery power source, ALL Clocks OFF, 100ms duration
• LPRUN mode, FLASH fetch type, Battery power source, 2.0MHz freq, 5ms
duration, GPIOB, GPIOE active
• Duplicate Step #2 (STOP2 mode) using the DUPLICATE button
• Check the result:
VBAT backup domain
• VBAT charging : allows charging a super-cap on VBAT through internal
resistor when VDD is present
• Battery charging is enabled by setting VBE bit in the PWR_CR4 register.
• VBRS bit value in the PWR_CR4 register selects the resistor value
Backup domain
VDD
VBAT
1.5 kΩ
VDD domain
VBE
VBRS
5 kΩ
Battery charging
STM32L4
Peripheral details 1/2
Digital Filter for Sigma
Delta Modulators
8 x parallel inputs
with up to 24-bit data
output resolution
Smart peripherals
∆ Metering
LCD Display
VBAT with RTC
for battery backup
240 nA in VBAT mode
for RTC and
32x 32-bit backup registers
88×40 or 4×44
with step-up converter
STM32L4
Anti Tamper pin
3 x tamper pins
for battery domain
TRNG & AES
for Security
128-/256-bit AES
key encryption hardware
accelerator
Electricity/Gas
/Water
Smart Meter
SPI / UART/ SDIO for Wireless
3x SPIs (4x SPIs with the Quad SPI)
6x USARTs (ISO 7816, LIN, IrDA, modem)
1 x SDIO
FSMC
External memory interface
for static memories supporting SRAM,
PSRAM, NOR and NAND
I/Os Up to 114 fast I/Os for buttons & relays
2
Innovation
Smart Peripherals
Industrial Sensors
Motor Control :
2x 16-bit advanced
motor-control timers
3x 12-bit ADCs: 5 MSPS,
with up to 16-bit with hardware
oversampling, 200 µA/MSPS
LCD Display
8×40 or 4×44
with step-up converter
STM32L4
CAN Bus
High temperature
(2.0B Active)
from -40°C
up to + 125°C
TRNG & AES
SPI / UART
for Security
128/256-bit AES
key encryption hardware accelerator
3x SPIs (4x SPIs with the
Quad SPI)
6x USARTs (ISO 7816, LIN,
IrDA, modem)
FSMC
I²C
External memory interface
for static memories supporting
SRAM, PSRAM, NOR and NAND
3x I²C FM+(1 Mbit/s), SMBus/PMBus
I/Os
Up to 114 GPIOs
2
Innovation
Smart peripherals
Fitness tracker application
Digital Filter for Sigma
Delta Modulators
with PDM microphone input support
TFT Display
STM32L4
Sensors
FSMC
Parallel interface to TFT
SPI
Up to 40 MHz speed
I²C
3x I²C FM+
Batch Acquisition Mode (BAM)
USB
USB OTG 2.0
full-speed,
LPM and BCD
SPI / UART
3x SPIs
Quad SPI
6x USARTs
OPAMP
2x with built-in PGA
DAC
SAI
2x serial audio interfaces
Low-power sample and hold
SWP
Single wire protocol
master interface (SWPMI)
ADC
3× 12-bit ADC 5 MSPS,
2 Innovation
DFSDM Introduction
• External Σ∆ modulators on market:
• This is external standalone device: ADC converter on sigma delta principle
• Analog input (usually differential) and digital output
• Precision: ~16-bit resolution
• Provides digital output as fast 1-bit data stream => serial interface
• Up to 20MHz speed of serial data
• Wide range of suppliers (ST and others)
• STM32 interface: DFSDM = Digital Filter for Sigma Delta
Modulators
Implements complete post-processing from external Σ∆ modulators outputs:
• Receiving of data streams from Σ∆ modulators (in various serial data formats)
• Digital filtering of data stream (final 24-bit result)
• Security/emergency functions
Memory buffer data (DMA/CPU transfer)
not in L4
Block
diagram
External Σ∆
modulator(s)
Analog signal
Decode, Filter, Average, Process
• Up to 8 Serial transceivers:
• Receive and decode raw serial bitstreams, providing data/clock to filter stage
• 1-wire Manchester coded mode or SPI clock/data
• Sincx filter performs input stream digital filtering:
• Sinc1, Sinc2, Sinc3, Sinc4, Sinc5, FastSinc, No filter
• Programmable Sincx oversampling ratio (1 to 1024 filter samples)
• Output filter resolution is 31-bit max
• Integrator stage performs data averaging from digital filter, 1-256 samples
• Post processing:
• Offset compensation
• Programmable right bit shifting for data formatting
• Additional functions
• Min/Max extremes detection
• Analog watchdog (to watch for final data boundaries overflow)
• Break signal generation
MEMS microphone support (PDM)
• Function
• MEMS microphone provides pulse density modulated (PDM) data signal –
like the Σ∆ modulator.
• PDM microphone has stereo support (if two connected in parallel):
• Rising clock = Left audio data, Falling clock = Right audio data
• Implementation into DFSDM transceivers
• Channels data (left vs. right) are separated inside:
• Each DFSDM channel transceiver inputs can be redirected to next channel inputs
• Configuration of those 2 channels differs only in active sampling edge
• Clock signal provided by DFSDM_CKOUT – PDM microphones are slaves
MEMS microphone application - schematic
DFSDM peripheral
Channel 7
.
.
.
DFSDM_DATIN3
DFSDM_DATIN2
MEMS
microphone
Right
L data
DFSDM_DATIN1
clock
DFSDM_DATIN0
R data
clock
DFSDM_CKOUT
Filter 2
Channel 3
Filter 1
R
Filter 0
L
Channel 2
Channel 1
-
direct input
falling edge sampling (R data)
Channel 0
-
redirected from next channel
rising edge sampling (L data)
internal clock
Stereo microphone
MEMS
microphone
Left
Filter 3
Voice recognition Demonstration
• STM32L4 with voice recognition algorithm controls an Android remote
device thanks to Bluetooth Low Energy communication
+
Microphone Shield
With Digitals MEMS
(MP34DT01)
+
Nucleo STM32L4
+
ST BlueNRG BLE RF
Arduino Shield
CR2032
Voice recognition function blocks
Always on
acquisition
(PDM to PCM & signal
conditioning)
Always on BLE
connection
Voice
activity
detector
Voice
trigger
detection
Low power audio DSP replacement
Voice recognition example
Always on
acquisition
(PDM to PCM & signal
conditioning)
< 410 µA
Voice
activity
detector
Voice
trigger
detection
< 2.2 mA
Sub-microwatt acquisition thanks to
PDM to PCM HW processing with DFSDM
and low power Batch Acquisition Mode (BAM)
Hardware/Software blocks
PDM
Input
(1MHz)
Digitals MEMS
(MP34DT01)
PDM
LP Filter and
Decimation
Decimation by 64
Signal
Conditioning
Gain control
HP filtering
Filtering / Decimation / Gain control
done by HW
PCM
Output
Voice Activity
Detector
Voice Trigger
Detection
@ 16MHz
PCM
Output
(16kHz)
@ 2MHz
Indicator
BAM explained
Voice recognition use case
STM32L476
DMA
DFSDM
DFSDM
0111010100101001010101111
128 KB
RAM
Filtering /
Decimation /
Gain control
done by HW
with DFSDM
ART
1024 KB
FLASH
Cortex-M4
Flash fetch
Cortex-M4
RAM fetch
Cortex-M4
RAM fetch
Current
consumption
0111011000010
0011010
Cortex-M4
BAM
No Voice
BAM
Voice
Detected
Algorithm
Processing
Voice trigger
detection
Smart peripherals - DFSDM
∆ Metering
STM32L4
Electricity Meter
Smart peripherals – Serial Audio Interface
Fitness tracker application
Serial Audio Interface supports a wide set of audio
protocols thanks to its flexible architecture:
STM32L4
• I2S Philips standards, (Inter-IC Sound)
• I2S LSB or MSB-justified, (I2S variant)
• SPDIF Output, (Sony/Philips Digital InterFace)
• PCM, (Pulse Code Modulation)
• TDM, (Time Division Multiplexing)
• AC’97, (Audio Codec ’97 from Intel)
SAI
2x serial audio interfaces
2 Innovation
SAI Features
• Two independent audio sub-blocks:
• Transmitter and/or receiver, Master or Slave
• Synchronous or asynchronous modes between the audio sub-blocks
• Clock generator for each audio sub-block to target independent audio frequencies
• 8-word integrated FIFOs for each sub-block, up to 16 slots available
• Mute mode, Stereo/Mono and companding mode supporting µ-Law and A-Law.
IO Line
Management
SYNC
IN
IO Line
Management
SYNC
IN
CMP
SYNC
OUT
CMP
CMP
SYNC
OUT
• Configurable LSB/MSB, data/slot sizes, sampling edges, # of bits, frame shape, etc..
Smart peripherals
SAI: Discovery Board Implementation:
STM32L4
SAI in I2S
Philips mode
2 Innovation
Smart peripherals – I2C
Fitness tracker application
STM32L4
Sensors
I²C
• All known I2C limitations are corrected!
• Flag management improvements (L0/F3-like) for easy use
• Programmable filter on input pins (analog & digital filters)
•Wake-up on address matches – STOP1 (I2C1/2/3), STOP2 (I2C3)
•Fast mode Plus (up to 1Mbits/s) + 20mA
•Dual clock domain allows high baudrates and low CPU clocks to save power
2 Innovation
Smart peripherals – USART/LPUART
Fitness tracker application
STM32L4
LPUART
• Dual clock domain:
• UART functionality and wake up from Stop mode (Stop 1 and Stop 2)
• Baudrate programming independent of PCLK
• Four clock sources: LSE (32.768KHz), HSI, PCLK, System Clock
• Supports up to 9600 baud via 32.768KHz LSE!
• To wakeup from STOP mode, clock source must be LSE or HSI
• 3 Wakeup events:
Address match, START bit detection or RXNE (receive buffer not empty)
• KEY message: LPUART adds STOP2 wakeup, but is a subset of USART, however it is much lower power
2 Innovation
STM32L4 USART Implementation
• 3x USART’s, 2x UART’s and LPUART:
USART features
USART1/2/3
UART4/5
LPUART
Hardware Flow Control
YES
YES
YES
Continous communication using DMA
YES
YES
YES
Multiprocessor communication
YES
YES
YES
Synchronous mode
YES
NO
NO
Smartcard mode
YES
NO
NO
Single wire half duplex mode
YES
YES
YES
IrDA
YES
YES
NO
LIN
YES
YES
NO
Dual clock / wake up from STOP1
YES
YES
YES
Dual clock / wake up from STOP2
NO
NO
YES!!
Receiver timeout
YES
YES
NO
Modbus Communication
YES
YES
NO
Autobaudrate detection
YES
YES
NO
RS-485 Driver enable
YES
YES
YES
Smart peripherals - SPI
STM32L4
SPI
• Programmable frame from 4 to 16bit (bit granularity)
• 32-bit FIFO to optimize bus bandwidth (performance & power consumption)
• BUSY status bit IP fix
• Up to 40 Mbits/s in master mode
•I2S functionality no longer supported in SPI. Now in SAI peripheral
2 Innovation
Smart peripherals
Sensor Hub scenario
Sensors
I²C
STM32L4
I²C
Wakeup from STOP
Host
App.
Processor
SPI / UART
3x SPI
6x USART
Batch Acquisition Mode (BAM)
Optimized mode for transferring data while the system is in low power mode
Only the needed communication peripheral + 1 DMA + 1 SRAM (SRAM1 or SRAM2)
are configured with clock enable in Sleep mode
Flash is in power-down mode
Enter either Sleep or Low-power sleep mode
I2C clock can be at 16 MHz, allowing FM+ support
2 Innovation
Hands-On Lab #4:
SPI communications to MEMS Gyro
Hands-On Lab #4 – SPI communications to 3-axis Gyro
Adding to the existing CubeMX project, we will add SPI
communications to the L3GD20 MEMS gyroscope:
Set up additional GPIO / Clocks:
PD1 – SPI2 SCK – Alt. Fn. Push/Pull
PD3 – SPI2 MISO – Alt. Fn. Push/Pull
PD4 – SPI2 MOSI – Alt. Fn. Push/Pull
PD7 – nCS – GPIO Output, Push/Pull mode
SPI2 settings:
Full-Duplex Master
Motorola, 8-bit MSB-first
Prescaler /16
CPOL = Low, CPHA = 1-Edge
No CRC
Software NSS
User Code HAL function calls required to be added to main.c:
C:\STM32L4Seminar\Labs\lab4_spi_gyro.c
Gyro (under LCD) data is routed to SPI2
147
Regenerate Source Code for Lab1
• Needed code bits from C:\STM32L4Seminar\Labs\lab4_spi_gyro.c into main.c:
•
•
•
•
•
Add
Add
Add
Add
Add
code bits between:
code bits between:
code bits between:
code bits between:
code bits between:
/* USER CODE BEGIN PV */
/* USER CODE BEGIN PFP */
/* USER CODE BEGIN 2 */
/* USER CODE BEGIN WHILE */
/* USER CODE BEGIN 4 */
/* USER CODE END PV */
/* USER CODE END PFP */
/* USER CODE END 2 */
/* USER CODE END WHILE */
/* USER CODE END 4 */
• Open a terminal emulator, using USART2 settings, Virtual COM port xx
• Rebuild, Program/Debug, Run!
STM32L4
Peripherals details 2/2
Smart peripherals - QuadSPI
STM32L4
QuadSPI
• Communication interface for single/dual/quad SPI flash memories
2 Innovation
QuadSPI Overview
• Three operating modes
• Indirect : All operations are performed through registers (classical SPI)
• Status polling: Hardware polling of status registers (interrrupt generation)
• Memory mapped: External flash seen as internal for read operations – 256MB limit
• SDR and DDR support
• DMA, Interrupts & Integrated FIFO for reception, transmission and error handling
• 8, 16, and 32-bit data accesses
QUADSPI
Registers /
Control
Clock
Management
QSPI Flash
CLK
AHB
BK1_IO0/SO
BK1_IO1/SI
FIFO
Shift Register
BK1_IO2
BK1_IO3
BK1_nCS
CLK
Q0/SI
Q1/SO
Q2/nWP
Q3/nHOLD
nCS
QuadSPI Frame format
• Each of the 5 phases is fully configurable
• Enabled or not
• Length
• Number of lanes
• Example of Read configuration
• Instruction on 1 lane
• Address, Alternate & Data on 4 lanes
• 2 dummy cycles
Instruction
Address
Alt
Dummy
Data
nCS
SCLK
IO0
4
0
4
0
4
0
4
0
4
0
4
0
IO1
5
1
5
1
5
1
5
1
5
1
5
1
IO2
6
2
6
2
6
2
6
2
6
2
6
2
IO3
7
3
7
3
7
3
7
3
7
3
7
3
7
6
5
4
3
2
1
0
A23-16
A15-8
A7-0
M7-0
IO switch from
output to input
Byte 1
Byte 2
Smart peripherals – USB OTG FS 2.0
• USB 2.0 / OTG 2.0 compliant
• VDDUSB: Dedicated 3.3V supply input
• 6 bidirectional endpoints
STM32L4
• MSI in PLL mode (auto-trimmed with LSE) to reach
48MHz & < 0.25% accuracy
• HSE not needed
•Link power management (LPM) support
• New power-save state, L1 (Sleep), with fast entry/exit
compared to traditional L2 state (Suspend): 50uS vs 10mS
•Battery charging detection (BCD) support
• Detect and identify the port type (standard or charging)
•Attach Detection Protocol (ADP) support
USB
USB OTG 2.0
full-speed,
LPM and BCD
• Determines attachment status in the absence of bus power
•Suspend/resume support
• Wakeup from STOP
2 Innovation
Analog Peripherals
Smart peripherals
• OPAMP’s:
•
•
•
•
Rail-to-rail inputs, 1mV offset after calibration
Outputs: 500µA (sink/source), 100µA (low-power mode)
1MHz GBW (normal mode), 500kHz (low-power mode)
0.7V/µs slew rate (normal), 0.3V/µs (low-power Mode)
STM32L4
• Comparators:
• 2 Comparators
• Window mode
• Available in low-power modes
• DAC’s:
•
•
•
•
•
8/12-bit mode
Lots of conversion triggers
Programmable output buffer to drive more current
Supply: VDDA = 1.8 V to 3.6 V
NEW! Sample and hold low-power mode
OPAMP
•ADC’s:
•
•
•
•
•
•
•
ADC1/ADC2 are tightly coupled, ADC3 is standalone
Consumption linear vs. conversion rate : 200 µA / MSPS
Dual-clock architecture
Up to 5.3Ms/s with 12-bit resolution in single mode
Single-ended or differential inputs
Internal channels: Temp sensor, VREF, VBAT/3, DAC
NEW! Hardware Oversampling
2x with built-in PGA
COMP
2x Low-power
DAC
2x Low-power sample and hold
ADC
3× 12-bit ADC 5 MSPS
2 Innovation
DAC1 / DAC2 block diagram
DAC Control Register
TIM7_TRGO
DMAENx
TIM8_TRGO
TENx
MAMPx[3:0]
SWTRIGx
TIM6_TRGO
WAVEx[1:0]
TSELx[2:0]
TIM2_TRGO
TIM4_TRGO
TIM5_TRGO
Control Logic x
Ext_IT_9
DMA Request x
12 bits
Noise/triangle
DHRx
BOFF
12 bits
DORx
12 bits
VREF+
VDDA
VSSA
Digital to Analog Converter x
DAC_OUTx
NEW!
Sample & Hold feature
• Maintains DAC output voltage when the MCU is in a low power mode,
such as STOP1 mode
• In Sample & Hold mode the DAC is able to hold its’ output voltage
while all related analog and digital blocks are shut off
• Up to 15x power savings in some configurations!
Vout
How it works?
• Sampling phase: During this phase, the “sample & hold” element is charged into
the desired voltage.
• Holding phase: During which the DAC’s output is tri-stated (High-Z) to maintain the
“Sample & Hold” element’s stored electrical charge.
• Refresh phase: Due to leakage coming from several sources, a refresh phase is
essential to keep the output voltage at the desired value (+/- LSB)
DAC
(Sample & Hold
mode)
Cload
Vout
Vout
ADC Block Diagram
VREF+
VDDA
ADEN/ADDIS
VOPAMPx
VTS
VINN [18:0]
VREF-
SAR ADC
Sample
and hold
12bits
12bits
Start
AUTDLY
oversampler
VINP [18:0]
Address/data bus
ANALOG MUX
ADC_IN[15:1]
DMA Request
ADCAL
VREFINT
VBAT
Injected data register
(4x16bits)
Regular data register
(16bits)
Start & Stop
3 Analog watchdog
ADSTP
Control
S/W
trigger
AREADY EOSMP
EXTI0
EOS
EOC
OVR JEOS JQOVF AWDx
EXTI1
. . . . .
Analog Watchdog
H/W
trigger
AREADYIE EOSMPIE
EXTI15
EOCIE
EOSIE OVRIE JEOSIE JQOVFIE AWDxIE
High Threshold register
(12bits)
EXTSEL[3:0] bits
Low Threshold register
(12bits)
J S/W
trigger
JEXTI0
JEXTSEL[3:0] bits
AWD3_OUT
JEXTI15
AWD2_OUT
. . . . .
AWD1_OUT
JEXTI1
ADC interrupt to NVIC
TIMERs
ADC Clocks
ADC1, ADC2 & ADC3
HCLK
Reset & Clock
controller
ADC123_CK
AHB interface
/1 , /2 or /4
Analog ADC1
(master)
/1 … /256
Analog ADC2
(slave)
CKMODE[0:1]
Analog ADC3
(single)
ADC Sequencer
• Up to 16 regular and 4 injected conversions with programmable order
and programmable sampling time,
Example: - Conversion of channels: 0, 2, 8, 4, 7, 3 and 11
- Different sampling time.
Ch.0
2,5 cycles
Ch.2
6,5 cycles
Ch.8
Ch.4
Ch.7
2,5 cycles
Ch.3
Ch.11
47,5
cycles
24,5 cycles
92,5
cycles
247,5 cycles
ADC Sampling Time (TSampling)
• Three bits programmable sampling time channel by channel
programmable:
ADC
2.5 cycles
6.5 cycles
12.5 cycles
ADCCLK
24.5 cycles
47.5 cycles
Selection
2.5 cycles
6.5 cycles
12.5 cycles
24.5 cycles
47.5 cycles
92.5 cycles
247.5 cycles
640.5 cycles
Sample Time
•
•
•
•
•
•
•
•
92.5 cycles
247.5 cycles
640.5 cycles
SMPx[2:0]
Note: The sampling time value depends on the type of channel (fast or slow), the
resolution and output impedance of the external signal source to be converted
Total Conversion Time
• Total conversion Time = TSampling + TConversion
Resolution
Resolution
TConversion
12 bits
12.5 Cycles
10 bits
10.5 Cycles
8 bits
8.5 Cycles
6 bits
6.5 Cycles
Total conversion Time (When FADC = 80MHz)
12 bits
12.5 + 2.5 = 15cycles
18.75 us
5.33 Msps
10 bits
10,5 + 2.5 = 13 cycles
16.25 us
6.15 Msps
8 bits
8.5 + 2.5 = 11 cycles
13.75 us
7.27 Msps
6 bits
6.5 + 2.5 = 9 cycles
11.25 us
8.89 Msps
Oversampler
• Oversampler performs data pre-processing to offload the CPU.
Handles up to 256 conversions and averages them
• For : Averaging, Data rate reduction, SNR improvement, Basic filtering
12bit data
ADC
20 bit register
0 to 8 bit right shift
DATA
SHIFTER,
TRUNCATER
Accumulation
data register
+
16 bit register
ADCx_DR
• Programmable oversampling ratio
• x2, x4, x8, x16, x32, x64, x128, x256
• Programmable data shifting / truncating
• Right shift 0 to 8 bits
Example: Oversampling ratio x2
CH1(0)
CH1(1)
CH1(0)
CH1(1)
Sampling
Conversion
Trigger for
oversampling channel
EOC
Trigger
End of conversion for
oversampling channel
ADC Analog Watchdogs
• ADC Analog Watchdog 1
• 12-bit programmable analog watchdog low and high thresholds
• Enabled on one or all converted channels
• Interrupt generation on low or high thresholds detection
• ADC Analog Watchdog 2&3
NEW!
• Enabled on some selected channels by programming bits in AWDCHx[18:0],
• Resolution Limited to 8 bits and only the 8 MSBs of the thresholds can be programmed
ADC_IN0
ADC_IN1
.
.
.
.
.
.
ADC_IN18
AWD
Analog Watchdog
Low Threshold
High Threshold
Status Register
COMPARATORS
• 2 ultra-low power comparators: COMP1 / COMP2
• Wake-up from low-power modes thru EXTI (Sleep / STOP1 / STOP2)
• Multiplexed inputs (GPIO, DAC’s, VREFINT)
• Programmable hysteresis and speed-vs-consumption
• Redirection of output to IO or timer inputs (e.g. TIM Break event)
• Outputs with blanking source
• Comparators can be combined in the window comparator
COMP low power features
Power consumption -vs- propagation delay can be adjusted:
PWRMODE
Max propagation delay
Consumption (Typ)
00
80 ns
70 µA
01 or 10
1 µs
5 µA
11
12 µs
350 nA
LP mode
Feature / limitation
Run, LPRun
no limitation, state polling or interrupt thru EXTI
Sleep, LPSleep
wakeup capability thru EXTI
Stop 1, Stop 2
wakeup capability thru EXTI
Standby
not available
Shutdown
not available
Smart peripherals
NOR
NOR Signals
TFT Display
IRQ
STM32L4
Config
NAND
AHB
Shared
Signals
FMC
Parallel interface to TFT
SPI
Up to 40 MHz speed
• NOR Flash/PSRAM and NAND controllers
• Differences from FSMC:
• Continuous FMC clock generation for synchronous and asynchronous modes.
• Performance enhancement
• Removal of PCCard controller on new products.
2 Innovation
FMC Bank memory mapping
• For the FMC, the external memory is divided into 4 fixed size banks of 4x64 MB each:
• Bank 1 can be used to address NOR Flash, OneNAND or PSRAM memory devices.
• Banks 3 is used to address NAND Flash devices.
• Bank 2 & 3 reserved
Supported Memory Type
0x6000 0000
0x6FFF FFFF
0x7000 0000
0x7FFF FFFF
0x8000 0000
0x8FFF FFFF
0x9000 0000
0x9FFF FFFF
Bank 1
4x64 MB
NOR/PSRAM/SRAM/CRAM/OneNAND
Bank 2
Reserved
Bank 3
256 MB
Bank4
Reserved
NAND Flash
168
LPTIM Features Summary
• Asynchronous running capability
• Ultra low power-consumption
• Timeout function for wakeup from
Stop 1 mode (LPTIM1 & LPTIM2) and
Stop 2 mode (LPTIM1 only)
LPTIM Features
• Up to 5 clock sources to achieve lowest power consumption
• APB clock, LSE, LSI, HSI, External clock
• Internal / External hardware triggers, with digital glitch filter:
• Rising / Falling or Both edges
• GPIO, RTC events, COMP1/2
• Up to 2 operation modes
• Continuous mode: free running mode; many counter overruns are possible
• One Shot mode: Counter stops counting when the overrun value is reached
• Encoder mode (LPTIM1 only)
• 6 interrupt sources
LPTIM Features
• Up to 3 configurable waveforms with configurable polarity
• PWM waveform
• One Pulse waveform
• Set Once waveform
LPTIMx_ARR
LPTIMx_CMP
PWM
OnePulse
SetOnce
POL = 0
Hands-On Lab #5:
Autonomous peripherals: ADC/TIM/DMA
Hands-On Lab #5: ADC-TIM-DMA functionality
PA7
TIM4CH4
1KHz PWM
PD15
ADC1
Oversample
x16
ADC1 Data Reg
Rising Edge trigger
DMA1CH1 trigger
on Conv Complete
DMA Destination (incrementing)
ADC_Buffer[0]
ADC_Buffer[1]
ADC_Buffer[2]
ADC_Buffer[3]
ADC_Buffer[4]
ADC_Buffer[5]
ADC_Buffer[6]
ADC_Buffer[7]
ADC_Buffer[8]
ADC_Buffer[9]
DMA Source (fixed)
DMA1CH1
Interrupt trigger
after 10 transfers
Interrupt Handler:
Calculate ADC Avg
173
ADC1 GPIO / Clock setup:
Set up ADC GPIO / Clocks:
PA7 – ADC1_IN12 – Analog Input, Single-Ended
ADC Clock Source = SYSCLK (80MHz)
ADC1 Settings:
Changes from default settings:
Synchronous clock mode divided by 4
DMA Requests Enabled, End of Single conversion
Enable Regular Oversampling
4-bit shift
Oversampling ratio 16x
External Trigger Conversion Edge: Rising Edge
External Trigger Conversion Source: TIM4 CapCom 4
ADC1 DMA and DMA interrupt:
Select DMA Settings tab in ADC1 Configuration:
Click “Add” button
Select ADC1
Use Word Data Width for Peripheral and Memory
Increment Memory Address
Select NVIC Settings tab:
Make sure DMA1 channel1 global interrupt is Enabled
Click “OK”
Set up GPIO:
PD15 – TIM4CH4 Alt Fn output – PWM Generation CH4
TIM4 settings for 1KHz, 20% duty-cycle PWM output:
Prescaler = 79 (79+1=80, 80MHz / 80 = 1MHz timer tick)
Counter Mode = UP
Counter Period = 1000 (1MHz / 1000 = 1KHz)
No Internal Clock Division
PWM Mode 1
Pulse = 200
Fast Mode: Enabled
CH Polarity: High
User Code HAL function calls required:
C:\STM32L4Seminar\Labs\lab5_adc_tim_dma.c
TIM4 CH4 setup:
Hands-On Lab #5: ADC-TIM-DMA functionality
Set up additional GPIO / Clocks:
PA7 – ADC1_IN12 – Analog Input, Single-Ended
ADC Clock = SYSCLK/4 (20MHz)
PD15 – TIM4CH4 Alt Fn output – PWM Generation CH4
ADC1 settings:
Clock Prescaler = Synch /4
12-bit, Right aligned, No Scan, Scan/Continuous modes disabled
x16 oversampling, 4-bit shift, continued mode
Trigger on TIM4CC4, Rising edge
Enable DMA, 1 conversion
Channel 12: Rank1, 2.5 cycle sampling, no offset
DMA settings:
DMA1CH1, Circular mode, Increment memory address, Word data width
DMA1CH1 interrupt enabled, preempt priority = 3
TIM4 settings:
Counting UP, Prescaler=79, Counter Period = 1000, No CKD
PWM Mode 1, Pulse = 200, Fast Mode enabled, Polarity High
User Code HAL function calls required:
C:\STM32L4Seminar\Labs\lab5_adc_tim_dma.c
Internal L4 ADC / TIM / DMA peripherals
178
Lab#5: Autonomous Peripherals
• Needed code bits from C:\STM32L4Seminar\Labs\lab5_adc_tim_dma.c into main.c:
•
•
•
•
Add
Add
Add
Add
code bits between:
code bits between:
code bits between:
code bits between:
/* USER CODE BEGIN PV */
/* USER CODE BEGIN 2 */
/* USER CODE BEGIN WHILE */
/* USER CODE BEGIN 4 */
/* USER CODE END PV */
/* USER CODE END 2 */
/* USER CODE END WHILE */
/* USER CODE END 4 */
• Open a terminal emulator, using USART2 settings, Virtual COM port xx
• Rebuild, Program/Debug, Run!
•
On the rising edge of each TIM4 PWM cycle, the ADC is triggered.
•
The ADC input is oversampled 16 times
•
The summed result is shifted right 4 places, performing a hardware averaging
•
A DMA transfer moves this result into a data array and the array pointer is incremented
•
10 data elements are transferred and then the cycle repeats
• Add the array ADC_Result to the Live Watch debug window to see updates!
SUMMARY 4 Keys of STM32 L4 series
1
ULP leader and performance booster
2
Innovation
3
Integration and safety
4
Great Investment
STM32 apps & social media
• Find more about STM32 products and solutions:
ST MCU Finder mobile application
Social media
ST Forums on microcontrollers
facebook.com/stm32
youtube.com/STonlineMedia
twitter.com/@ST_World
Mbed.org
www.st.com/stmcufinder
STM32 @ ARM connected community
Thank you
/STM32
@ST_World
www.st.com/stm32l4
st.com/e2e
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement