Professional Documents
Culture Documents
Microcontrollers Division
2012 - Week 16 , Tunis
Block Diagrams
Memory and System architecture
Flash
Power Control (PWR) + Hands-on
Direct memory access controller
General Purpose I/Os
Extended interrupts and events controller
STM32F30x Motor Control kit - Complete development platform with all the
hardware and software required to get STM32-based motor control applications
started quickly + STM32F30x new features/peripherals easing motor control
Day 1
Cortex M4 presentation with Focus on FPU and DSP + Hands-on
STM32F3 common parts
Block Diagrams
Memory and System architecture
Flash
Power Control (PWR - with mentioning the differences in both products Power Supply
Schemes )
Direct memory access controller (DMA- with mentioning the differences in the DMA
requests mapping in both products.)
General Purpose I/Os
Extended interrupts and events controller (EXTI - with mentioning the differences in the
EXTI internal lines connections )
Cortex-M processors
9
Cortex-M0
Cortex-M3
8/16-bit applications
16/32-bit applications
Cortex-M4
32-bit/DSC applications
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
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
12
Cortex-M3
Cortex-M4
V6M
v7M
v7ME
Thumb, Thumb-2
System Instructions
Thumb + Thumb-2
Thumb + Thumb-2,
DSP, SIMD, FP
0.9
1.25
1.25
Yes
Yes
Yes
Number interrupts
1-32 + NMI
1-240 + NMI
1-240 + NMI
Interrupt priorities
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
Hardware Divide
No
Yes
Yes
WIC Support
Yes
Yes
Yes
No
Yes
Yes
No
No
Yes
No
No
Yes
AHB Lite
Yes
Yes
Yes
Breakpoints, Watchpoints
Bus protocol
CMSIS Support
13
Cortex-M4 overview
Main Cortex-M4 processor features
ARMv7-ME architecture revision
Fully compatible with Cortex-M3 instruction set
16
17
CM3
CM4
n/a
n/a
n/a
n/a
n/a
n/a
1
1
1
1
1
1
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
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
INSTRUCTIONS
All the above operations are single cycle on the Cortex-M4 processor
18
Saturated arithmetic
Intrinsically prevents overflow of variable by clipping to min/max
boundaries and remove CPU burden due to software range checks
Benefits
Audio applications
1.5
Without
saturation
1.5
1
0.5
0
-0.5
-1
0.5
-1.5
1.5
-0.5
0.5
-1
With
saturation
-1.5
0
-0.5
-1
-1.5
Control applications
The PID controllers integral term is continuously accumulated over time. The saturation
automatically limits its value and saves several CPU cycles per regulators
19
Benefits
Parallelizes operations (2x to 4x speed gain)
Minimizes the number of Load/Store instruction for exchanges between memory
and register file (2 or 4 data transferred at once), if 32-bit is not necessary
Maximizes register file use (1 register holds 2 or 4 values)
20
32-bit
64-bit
32-bit
64-bit
21
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
22
CLASS
Load/Store
Branch
Special
Manipulation
INSTRUCTION
Load single byte to R0-R14
Load single halfword to R0-R14
Load single word to R0-R14
Load to PC
Load double-word
Store single word
Store double word
Load-multiple registers (not PC)
Load-multiple registers plus PC
Store-multiple registers
Load/store exclusive
SWP
B, BL, BX, BLX
CBZ, CBNZ
TBB, TBH
IT
MRS
MSR
CPS
BFI, BFC
RBIT, REV, REV16, REVSH
SBFX, UBFX
UXTH, UXTB, SXTH, SXTB
SSAT, USAT
SEL
SXTAB, SXTAB16, SXTAH
UXTB16, SXTB16
SSAT16, USAT16
PKHTB, PKHBT
CORTEX-M3 Cortex-M4
1 - 3
1 - 3
1 - 3
1 - 3
1 - 3
1 - 3
5
5
3
3
1 - 2
1 - 2
3
3
N+1
N+1
N+5
N+5
N+1
N+1
2
2
n/a
n/a
2 - 3
2 - 3
3
3
5
5
0 - 1
0 - 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
n/a
1
n/a
1
n/a
1
n/a
1
n/a
1
23
B
Extract
00......00
00......00
B
Pack
24
LDR
LDRSH
R0,[SP, #+20]
SXTH
LR,R8
MUL
R8,LR,R0
LDR
R1,[R4, #+44]
SDIV
R0,R1,R7
LDRSH
R2,[R4, #+24]
LDRSH
R3,[R4, #+26]
LDRSH
R10,[R4, #+22]
SXTH
LDR
R2,[R4, #+22]
R6,R6
MLS
R5,R6,R10,R5
MLA
R5,R9,R12,R5
ASR
R6,R8,#+15
MLA
R5,R6,R3,R5
SXTH
R10,[R4, #+12]
R0,R0
MLS
R5,R0,R2,R5
STR
R5,[SP, #+12]
25
27
28
Tools
Matlab / Simulink
Embedded coder for code generation
Mathworks
Demo being developed (availability end of year)
Aimagin (Rapidstm32)
29
Data communications
Echo cancellation (adaptive versions)
Smoothing data
Infinite impulse response (IIR) filters
Audio equalization
Motor control
Fast Fourier transforms (FFT)
Audio compression
Spread spectrum communication
Noise removal
30
Assembly or C ?
Assembly ?
Pros
Can result in highest performance
Cons
Difficult learning curve, longer development cycles
Code reuse difficult not portable
C?
Pros
Easy to write and maintain code, faster development cycles
Code reuse possible, using third party software is easier
Cons
Highest performance might not be possible
Get to know your compiler !
31
Mathematical details
y[n] = h[k ]x[n k ]
N 1
FIR Filter
k =0
Y [k1 ] = X [k1 ] + X [k 2 ]
Y [k 2 ] = ( X [k1 ] X [k 2 ])e j
32
Computing Coefficients
Variables in a DSP algorithm can be
classified as coefficients or state
Coefficients parameters that determine the
response of the filter (e.g., lowpass,
highpass, bandpass, etc.)
State intermediate variables that update
based on the input signal
33
Cortex-M3 Cortex-M4
cycle count cycle count
xN = *x++;
yN = xN * b0;
yN += xNm1 * b1;
yN += xNm2 * b2;
yN -= yNm1 * a1;
yN -= yNm2 * a2;
*y++ = yN;
xNm2 = xNm1;
xNm1 = xN;
yNm2 = yNm1;
yNm1 = yN;
Decrement loop counter
Branch
2
3-7
3-7
3-7
3-7
3-7
2
1
1
1
1
1
2
2
1
1
1
1
1
2
1
1
1
1
1
2
Loop unrolling
35
FIR Filter
36
k =0
x[n]
z 1
z 1
z 1
z 1
h[0]
h[1]
h[2]
h[3]
x[n-1]
x[n-2]
x[n-3]
h[4]
x[n-4]
y[n]
Circular Addressing
37
h[N 2]
h[1]
h[0]
x[n ]
x[n ( N 1)]
coeffPtr
x[n 2]
x[n 1]
statePtr
38
FIRLoop:
Multiply and
accumulate previous
39
Fetch coeffs[k]
Fetch state[stateIndex]
MAC
stateIndex-Circular wrap
Loop overhead
Total
2 cycles
1 cycle
1 cycle
1 cycle
4 cycles
3 cycles
-----------12 cycles
40
per block
Example. N = 6, blockSize = 4. Size of state buffer = 9.
x[0]
x[1]
x[2]
x[3]
x[4]
x[5]
h[4]
h[3]
h[2]
h[1]
h[0]
Block 1 Block 2
h[5]
x[6]
x[7]
x[8]
42
per block
Example. N = 6, blockSize = 4. Size of state buffer = 9.
x[0]
x[1]
x[2]
x[3]
x[4]
x[5]
h[3]
h[2]
h[1]
h[0]
Block 2 Block 3
h[5]
h[4]
x[6]
x[7]
x[8]
per block
Example. N = 6, blockSize = 4. Size of state buffer = 9.
x[0]
x[1]
x[2]
x[3]
x[4]
x[5]
h[2]
h[1]
h[0]
Block 3 Block 4
h[5]
h[4]
h[3]
x[6]
x[7]
x[8]
Fetch coeffs[k]
Fetch state[stateIndex]
MAC
stateIndex++
Loop overhead
Total
2 cycles
1 cycle
1 cycle
1 cycle
3 cycles
----------8 cycles
Improvement in performance
DSP assembly code = 1 cycle
45
Loop unrolling
46
There is overhead inherent in every loop for checking the loop counter
and incrementing it for every iteration (3 cycles on the Cortex-M.)
Fetch state[stateIndex]
MAC
stateIndex++
Loop overhead
Total
2x4
1x4
1x4
1x4
3x1
= 8 cycles
= 4 cycles
= 4 cycles
= 4 cycles
= 3 cycles
-----------23 cycles for 4 taps
= 5.75 cycles per tap
47
Improvement in performance
DSP assembly code = 1 cycle
48
Apply SIMD
Many image, video processing, and communications applications use
8- or 16-bit data types.
SIMD speeds these up
16-bit data yields a 2x speed
improvement over 32-bit
8-bit data yields a 4x speed
improvement
32-bit register
H
32-bit register
H
16-bit
L
16-bit
16-bit
16-bit
32-bit
Sum
64-bit
32-bit
64-bit
64-bit
49
CMSIS Files
50
x[0]
x[1]
x[2]
x[3]
x[4]
x[5]
h[5]
h[4]
h[3]
h[2]
h[1]
h[0]
x[6]
x[7]
x[8]
51
//
//
//
//
//
//
//
//
//
//
//
//
//
2
1
1
2
1
1
2
1
1
2
1
1
3
cycles
cycle
cycle
cycles
cycle
cycle
cycles
cycle
cycle
cycles
cycle
cycle
cycles
52
Improvement in performance
DSP assembly code = 1 cycle
Cortex-M4 standard C code takes 12 cycles
Using circular addressing alternative = 8 cycles
After loop unrolling < 6 cycles
After using SIMD instructions < 2.5 cycles
Thats much better!
But is there anything more?
One more idea left
53
MAC takes
3-7 cycles on Cortex-M3, 1 cycle on Cortex-M4
54
x[0]
x[2]
x[1]
x[4]
x[3]
x0
x[7]
x[6]
x[5]
x[8]
x0
x1
x1
x2
x2
x3
3
coeffsPtr++
x3
3
Increment by 32-bits
h[5]
h[4]
c0
h[3]
h[2]
c0
h[1]
h[0]
56
57
Summary of optimizations
Basic Cortex-M4 C code quite reasonable performance for simple
algorithms
58
Quick introduction to
fixed point data format
Fixed point format can be integer, fractional or a mix of integer and
fractional.
Fixed point use Qx.y notation
X : number of integer bits
Y: number of fractional bits
Q2.13 denotes fixed point data type with 2 bits for integer and 13 bits
for fractional part.
Fixed point format used in CMSIS DSP library is Q0.7 (Q7), Q0.15
(Q15) and Q0.31 (Q31)
Only fractional bits to represent numbers between -1.0 and 1.0.
Value = b(15-i) * 2(-1*i) : with i = 1..15
Example: 0.25 is represented as 0x2000 in Q15 format.
59
Cortex-M4F benefits
Cortex-M4F benefits Vs. Cortex-M3
Improvement in code size (A)
Improvement in performance (B)
1.8x
improvement
2034
Cortex-M3
2.23x
improvement
Cortex-M4F
(A)
3300
Cortex-M3
Cortex-M4F
(B)
60
61
DMA1
DAC2
SRAM
Lockup table
Input signal
TIM6
Processed data
LCD
TIM2
Potentiometer
Signal Sampling
Signal Generation
Signal Output
Signal Processing
Buffer2
Buffer1
ADC1
DAC2
DMA (circular
mode)
SRAM
Update Frequency
New scaling
FFT
Processing
DMA
Sampled data
ADC1
50Hz<F<Fs/2
ADC3
LCD
CPU (DSP
Processing)
Buffer2
DAC stop
Buffer1
Buffer2
DAC start
Stopped if key
or joystick used
62
DMA1
Sampled data
DMA1
Processed data
ADC1
DAC2
SRAM
TIM2
CPU (DSP
Processing)
SRAM
DAC1
Input signal
Lockup table
50Hz<F<Fs/2
TIM6
ADC3
TIM2
Update Frequency
New scaling
Signal Sampling
Signal Processing
Signal Output
Potentiometer
Signal Generation
Oscilloscope
Start display input signal to the oscilloscope
DAC1
Convert to good
input format
FIR
Processing
DMA
Buffer1 Processing
Buffer1
Buffer2
Buffer1
ADC1
DAC2
DMA (circular
mode)
Buffer2
DAC stop
Buffer1
Buffer2
DAC start
Stopped if key
or joystick used
63
Sampling frequency
8KHz
64
10000
250000
8000
200000
6000
150000
4000
100000
2000
50000
0
0
Q15
F2 (30 MHz, 0 WS)
Q15
Q31
F3 (24 MHz, 0 WS)
FFT
(64points) Q31
Q15
FFT
(1024points) Q31
Gain
(F2 vs F3)
x2.23
Q31
F3 (24 MHz, 0 WS)
8022
6522
x1.23
6410
6522
190028
80608
x2.36
80252
80608
215505
158022
x1.36
166406
158022
65
3000.000
120.000
2500.000
100.000
2000.000
80.000
1500.000
60.000
1000.000
40.000
500.000
20.000
0.000
0.000
Q15
F2 (120 MHz, 3 WS)
Q15
Q31
F3 ( 72 Mz, 2 WS)
FFT (64-points)
FFT (1024-points)
Q31
F3 (72 MHz, 2 WS)
F2(120MHz,3WS)
(s)
F4(168MHz,5WS)
(s)
Gain
F4/F3
64.847
115.694
22.101
x 2.9
Q31
63.442
69.683
40.679
x 2.8
Q15
1600.067
1532.139
496.952
x 3.08
Q31
1825.642
2765.861
1021.208
x 2.7
Q15
66
Stop Band
Filter order
165
Filter coefficients
166
Cut-off frequency
FSTOP1=1.9KHz, FSTOP2=2.1KHz
Sampling frequency
48KHz
Number of samples
128
Input signal
67
Q31
Q15
FIR
F2 (30MHz, 0WS)
Q31
Fast FIR
F3 (24MHz, 0WS)
Gain
(F2 vs F3)
x4.60
x1.96
x2.60
x3.99
F4 (30MHz, 0WS)
68
Q31
Q15
FIR
Fast FIR
F2 (120MHz, 3WS)
Q31
F3 (72MHz, 2WS)
F3(72 MHz,
2 WS)
F4 (168MHz, 5WS)
Q15 1396.99 s
66ns
605.81 s
28.5 ns
218.28 s
10 ns
Q31 1636.66 s
77ns
1613.72 s
76 ns
29 ns
Q15
760.68 s
36ns
566.33 s
26 ns
618.27 s
209.76 s
Q31 1488.29 s
70ns
907.73 s
42 ns
267.46 s
13 ns
10 ns
69
CONTENTS
Cortex-M4F (DSP and Floating point Unit)
Cortex-M4 and DSP features
Floating point unit
70
Overview
FPU : Floating Point Unit
Handles real number computation
Standardized by IEEE.754-2008
Number format
Arithmetic operations
Number conversion
Special values
4 rounding modes
5 exceptions and their handling
72
IEEE 754
ARM FPv4-SP Single Precision FPU
73
FPU usage
High level approach
Matrix, mathematical equations
C code generation
Floating point numbers (float)
FPU
No FPU
No FPU
Direct mapping
No code modification
High performance
Optimal code efficiency
Usage of SW lib
No code modification
Low performance
Medium code efficiency
74
Historical perspective
Usage of floating point as always been a need for computers since
the beginning (Konrad Zuse - 1935)
But the complexity of implementation discarded their usage during
decades (IBM 704 - 1956)
Floating point unit where implemented in mainframes with various
coding techniques depending of the manufacturer
IBM PC where designed to have floating point capabilities through
optional arithmetic coprocessors (80x87 series)
The standardization of floating point coding was done in the 80s
through the IEEE 754 standard in 1985
The Intel 80387 was the first intel coprocessor to implement the full
IEEE 754 standard in 1987
75
76
C language example
77
float function1()
# {
#
temp1 = number1 + number2;
VADD.F32 S1,S0,S1
#
temp2 = number1/temp1;
VDIV.F32 S0,S0,S1
#
#
return temp2;
BX
LR
# }
__aeabi_fadd on Cortex-M3
# __aeabi_fadd ()
TEQ
R0,R1
IT
MI
EORMI
R1,R1,#0x80000000
BMI.W
0x0800xxxx
SUBS
R2, R0, R1
ITT
CC
SUBCC
...
...
R1,R4
__aeabi_fadd
R1,R0
R0,R4
__aeabi_fdiv
{R4,PC}
__aeabi_fadd on Cortex-M4F
# __aeabi_fadd ()
VMOV
S0,R0
VMOV
S1,R1
VADD.F32 S0,S0,S1
VMOV
R0,S0
BX
LR
78
1.5x
improvement
696
17.8x
improvement
Best compromise
Development time
vs. performance
1593604
Cortex-M3
(A)
Cortex-M4F
89136
Cortex-M3
(B)
Cortex-M4F
79
80
80
Rounding issues
The precision has some limits
Rounding errors can be accumulated along the various operations an may
provide unaccurate results (do not do financial operations with floatings)
Few examples
If you are working on two numbers in different base, the hardware
automatically denormalize on of the two number to make the
calculation in the same base
If you are substracting two numbers very closed you are loosing the
relative precision (also called cancellation error)
81
IEEE 754
83
Number format
3 fields
Sign
Biased exponent (sum of an exponent plus a constant bias)
Fractions (or mantissa)
1-bit Sign
8-bit Exponent
23-bit Mantissa
1-bit Sign
11-bit Exponent
52-bit Mantissa
84
Number format
Half precision : 16-bit coding
16-bit
1-bit Sign
5-bit Exponent
10-bit Mantissa
85
86
Number value
Single precision coding of -7
Sign bit = 1
7 = 1.75 x 4 = (1 + + ) x 4 = (1 + + ) x 2 2
= (1 + 2-1 + 2-2) x 22
Exponent = 2 + bias = 2 + 127 = 129 = 0b10000001
Mantissa = 2-1 + 2-2 = 0b11000000000000000000000
Result
Binary coding : 0b 1 10000001 11000000000000000000000
Hexadecimal value : 0xC0E00000
87
Special values
Denormalized (Exponent field all 0, Mantisa non 0)
Too small to be normalized (but some can be normalized afterward)
(-1)s x ((Ni.2-i) x 2-bias
Signed zero
Signed because of saturation
88
Exponent
Mantissa
Number
+0
-0
Max
+oo
Max
-oo
Max
!=0 MSB=1
QNaN
Max
!=0 MSB=0
SNaN
!=0
Denormalized number
[1, Max-1]
Normalized number
89
Floating-point rounding
Round to nearest
Default rounding mode
If the two nearest are equally near : select the one with the LSB
equal to 0
Directed rounding
3 user-selectable directed rounding modes
Round toward +oo, -oo or 0
Usage
Program through FPU configuration registers
90
Floating-point operations
Add
Subtract
Multiply
Divide
Remainder
Square root
91
92
Exceptions
Invalid operation
Resulting in a NaN
Division by zero
Overflow
The result depend of the rounding mode and can produce a +/-oo
or the +/-Max value to be written in the destination register
Underflow
Write the denormalize number in the destination register
Inexact result
Caused by rounding
93
Exception handling
A TRAP can be requested by the user for any of the 5
exception with a specific handler
94
96
Introduction
Single precision FPU
Conversion between
Integer numbers
Single precision floating point numbers
Half precision floating point numbers
Dedicated registers
32 single precision registers (S0-S31) which can be viewed as 16
Doubleword registers for load/store operations (D0-D15)
FPSCR for status & configuration
97
Flush-to-zero mode
De-normalized numbers are treated as zero
Associated flags for input and output flush
98
Complete implementation
Cortex-M4F does NOT support all operations of IEEE
754-2008
Unsupported operations
Remainder
Round FP number to integer-value FP number
Binary to decimal conversions
Decimal to binary conversions
Direct comparison of SP and DP values
99
100
FPU instructions
101
Description
Assembler
Cycle
of float
VABS.F32
Addition
float
and multiply float
floating point
VNEG.F32
VNMUL.F32
VADD.F32
1
1
1
Subtract
float
VSUB.F32
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
102
FPU Load/Store/Compare/Convert
Operation
Load
Store
Move
Pop
Push
Compare
Convert
Description
multiple doubles (N doubles)
multiple floats (N floats)
single double
single float
multiple double registers (N doubles)
multiple float registers (N doubles)
single double register
single float register
top/bottom half of double to/from core register
immediate/float to float-register
two floats/one double to/from core registers
one float to/from core register
floating-point control/status to core register
core register to floating-point control/status
double registers from stack
float registers from stack
double registers to stack
float registers to stack
float with register or zero
float with register or zero
between integer, fixed-point, half precision and
float
Assembler
VLDM.64
VLDM.32
VLDR.64
VLDR.32
VSTM.64
VSTM.32
VSTR.64
VSTR.32
VMOV
VMOV
VMOV
VMOV
VMRS
VMSR
VPOP.64
VPOP.32
VPUSH.64
VPUSH.32
VCMP.F32
VCMPE.F32
VCVT.F32
Cycle
1+2*N
1+N
3
2
1+2*N
1+N
3
2
1
1
2
1
1
1
1+2*N
1+N
1+2*N
1+N
1
1
1
103
Exception management
No TRAP function : exception through interrupt
controller
Stack frame
17 entries in the stack (FPSCR + S0-S15)
104
IEEE754 compliancy
The Cortex-M4 Floating Point Unit is IEEE754 compliant :
The rounding more is selected in the FPSCR register (nearest even value by default)
!=0
Compliant options
FZ=0 and AHP=0 and DN=0
De-normalized number
Max
+infinity
Max
-infinity
Max
!=0 MSB=1
Max
!=0 MSB=0
Sign
Exponent
Mantissa
105
Underflow (IEEE754)
Inexact (IEEE754)
Overflow (IEEE754)
Comments
These flags are in the FPSCR register
When flush to zero mode is used:
the FPU add a specific exception : input denormal
the FPU handles the underflow and Inexact exception in a non-IEEE754 way
Examples
1234 / 0 => division by zero flag is set / the returned value is +infinity
Sqrt(-1) => Invalid Operation flag is set / the returned value is QNaN
Note: For details on each exception as well as the default returned value when such exceptions occurs,
please refer to ARM-7M architecture reference manual
106
Name
Type
Description
0xE000EF34
FPCCR
RW
0xE000EF38
FPCAR
RW
0xE000EF3C
FPDSCR
RW
0xE000EF40
MVFR0
RO
0xE000EF44
MVFR1
RO
107
108
Reserved
0x60
FPSCR
0x5C
S15
0x20
S0
0x1C
xPSR
0x1C
xPSR
0x18
ReturnAddress
0x18
ReturnAddress
0x14
LR (R14)
0x14
LR (R14)
0x10
R12
0x10
R12
0x0C
R3
0x0C
R3
0x08
R2
0x08
R2
0x04
R1
0x04
R1
0x00
R0
0x00
R0
Basic
Frame
Extended
Frame
109
Reserved
Reserved
Not stacked
Not stacked
Registers
are pushed
automatically
FPSCR
S15
Not stacked
S0
xPSR
xPSR
xPSR
ReturnAddress
ReturnAddress
ReturnAddress
LR (R14)
LR (R14)
LR (R14)
R12
R12
R12
R3
R3
R3
R2
R2
R2
R1
R1
R1
R0
R0
R0
ASPEN = 0
ASPEN = 1, LSPEN=1
ASPEN = 1, LSPEN=0
110
Not stacked
Not stacked
This keep it simple for the user to push the value if needed
Not stacked
xPSR
ReturnAddress
LR (R14)
R12
R3
R2
R1
R0
ASPEN = 1
LSPEN=1
111
112
How to clear
Comment
None
Lazy
FPU->FPCAR + 0x40
Automatic
Check LR value to
determine which stack was
used to preserve context.
113
LR Values
Return to (Mode)
Return Stack
Frame Type
0xFFFF_FFF1
Handler Mode
Main
Basic
0xFFFF_FFE1
Handler Mode
Main
Extended
0xFFFF_FFF9
Thread mode
Main
Basic
0xFFFF_FFE9
Thread mode
Main
Extended
0xFFFF_FFFD
Thread mode
Process
Basic
0xFFFF_FFED
Thread mode
Process
Extended
With polling
float x = 2.5f;
for(index = 0; index < 0xFFFF;i++)
{
x = 1.0f/(x*x);
if(__get_FPSCR() & 0x00000002)
{
DivZeroExc_Handler();
}
}
float x = 2.5f;
SYSCFG_ITConfig(SYSCFG_IT_DZC, ENABLE);
for(index = 0; index < 0xFFFF; index ++)
{
x = 1.0f/(x*x);
}
SYSCFG_ITConfig(SYSCFG_IT_DZC, DISABLE);
void FPU_IRQHandler(void)
{
DivZeroExc_Handler();
}
114
115
116
Sampling frequency
8KHz
117
60000
50000
40000
30000
20000
10000
0
Q15
F2 (30 MHz, 0 WS)
Q31
F3 (24 MHz, 0 WS)
Float
F4 (30 MHz, 0 WS)
Q15
F2 (30 MHz, 0WS)
Q31
F3 (24 MHz, 0 WS)
Gain
(F2 vs F3)
x2.23
x1.23
x11.17
x2.36
x1.36
x13.25
Float
F4 (30 MHz, 0 WS)
118
Stop Band
Filter order
165
Filter coefficients
166
Cut-off frequency
FSTOP1=1.9KHz, FSTOP2=2.1KHz
Sampling frequency
48KHz
Number of samples
128
Input signal
119
FIR Q32
FIR Float
F3(72 MHz,
2 WS)
Q15 1396.992 s
66ns
605.819 s
28.5 ns
218.280 s
10 ns
77ns
1613.722 s
76 ns
618.273 s
29 ns
Float 14782.510 s
696ns
1338.528 s
63 ns
531.160 s
25 ns
36ns
566.333 s
26 ns
209.761 s
10 ns
70ns
907.736 s
42 ns
267.464 s
13 ns
120
Summary
FPU is a key benefit for many application tasks that require precision
(to name just a few) :
loop control,
audio processing,
sensor signal conditioning,
motor control,
digital filtering,
Floating point number (Half precision) has larger dynamic range than
fixed-point
121
Cortex-M4 Hands-on
123
124
ADC
Low Pass
FIR Filter
DAC
Filter design
On Scilab console write:
wfir to get access to scilab filter designer wizard
Choose filter type : low pass filter.
Set filter characteristics
Cut-off frequency : 1KHz (Sampling Frequency = 48KHz)
Filter length : 64
fd = mopen(/fir_coefficient.txt,wt);
for i=1:30
mfprintf(fd,%d, ,coefficient(i));
end;
mclose(fd);
125
Firmware update
Copy Coefficient to Signal_FIR_Processing.c
Set NUM_TAPS to the number of coefficient you have generated
Initialize FIR Filter
Call FIR filter for Q15 data format initialization function from ARM CMSIS DSP lib
(function to modify FIR_PROCESSING_Q15Init)
126
Flash I/F
72MHz
2 x DMA
12 Channels
256 kB
FLASH
Memory
XTAL
4~32MHz
16 backup registers
CRC
64 Bytes
2x 12-bit DAC Ch
SPI 1
7x GP comparators
USART 1
1 x 16-bit TIMER
2ch (1ch w/ cpl/dt)
PLL
RTC
XTAL
32KHz
I-WDG
w/ AWU
LSI
32KHz
(max 36 MHz)
Up to 36 Ext. ITs
2 x 16-bit TIMER
1ch ( with cpl/dt)
HSI
8MHz 1%
2 x 16-bit Advanced
TIMER 6ch
Power Supply
POR/PDR/PVD
up to 48kB SRAM
4 x 12-bit ADC
39ch / 0.20 s
128
OPAMP
2 x 16-bit Basic TIMER
2x SPI, w/ 2 x I2S
2x IC
1 w/ FM+ 20mA
USART 2/3
UART 4/5
1 x USB
bxCAN
Win-WDG
1 x 32-bit GP TIMER
4ch
2 x 16-bit GP TIMER
4ch
STBY/VBAT
CORTEXTM-M4F
M4F
CPU
(max 72 MHz)
STM32F30x Series
ARM Lite Hi-Speed Bus
STM32F37x Series
Flash I/F
72MHz
256 KB
FLASH
Memory
HSI
8MHz 1%
PLL
XTAL
4~32MHz
up to 32 KB SRAM
16 backup registers
Reset Clock Ctrl
128 Bytes
CRC
Touch Sensing Ctrl
Power Supply
POR/PDR/PVD
RTC
XTAL
32KHz
I-WDG
w/ AWU
LSI
32KHz
(max 36MHz)
1 x 12-bit ADC
18ch / 1s
Win-WDG
Up to 29 Ext. ITs
SPI 1/I2S
2 x GP comparators
3 x 12-bit DAC Ch
2x IC
1 w/ FM+ 20mA
USART 1
3 x 16-bit SDADC
3 x 16-bit Basic
TIMER
2 x 32-bit GP TIMER
4ch
3 x 16-bit GP TIMER
4ch
4 x 16-bit GP TIMERS
1ch
2 x 16-bit GP TIMERS
2ch
USART 2/3
1 x USB
1x CEC
STBY/VBAT
2 x DMA
12 Channels
CPU
(max 72MHz)
129
CORTEXTM-M4F
M4F
ARM Lite Hi-Speed Bus
System Architecture
In STM32F30x
In STM32F37x
Five masters:
Five masters:
131
Five slaves:
DMAs)
Seven slaves:
Internal SRAM
check (STM32F30xonly)
0xFFFF FFFF
The boot configuration is defined with BOOT0 pin and BOOT1 bit in
USER Option Byte.
0xE010 0000
0xE000 0000
132
Boot modes
Depending on the Boot configuration, Embedded Flash memory,
System memory or Embedded SRAM memory is aliased at @0x00
thanks to memory remapping bits in SYSCFG registers.
Even when aliased, these memories are still accessible from their
original memory space.
Cortex-M4
internal
peripherals
BOOT Mode
Selection
Boot Mode
Aliasing
User Flash
System
memory
SystemMemory is
selected as boot space
Embedded
SRAM
Embedded SRAM is
selected as boot space
0x1FFF FFFF
BOOT1
BOOT0
0x1FFF F80C
1
0
Reserved
Reserved
Option Bytes
0x1FFF F800
System Memory
0x1FFF EC00
System Memory
Reserved
0x0804 0000
0x4800 17FF
Peripherals
Flash
0x0800 0000
0x4000 0000
Reserved
SRAM
0x2000 0000
CODE
0x0000 0000
Memory type
depending on
boot
configuration
0x0001 0000
0x0000 0000
Up to 256 KBytes
128 pages of 2KBytes size
Access time: 35ns
Half word (16-bit) program time: 52.5s (Typ)
Page erase time and Mass erase time: 20ms (Min), 40ms (Max)
135
136
137
138
Instructions-BUS
32 bits
Thumb-2
ARBITER *
16 bits
Thumb-2
FLASH
MEMORY
32 bits
64 bitsThumb-2
16 bits
Thumb
Memory
Accelerator
64 bits
64 bits
64 bits
64 bits
32 16 16 Bits
Thumb-2
32 bits
Thumb-2
CORTEX-M4
CPU
ARRAY
Data/Debug-BUS
16-bit
Data
32 bits
Data
8 bit
Data
Interrupt event
Event flag
End of programming
EOP
EOPIE
Error
WRPRTERR
PGERR
ERRIE
139
Write protection
The write protection is implemented with a choice of protecting 2 pages (4K) at a time
4 options bytes are used to protect all the 256KBytes main Flash program memory
Any programming or erase of a protected page is discarded and the Flash will return
protection error flag in the FLASH_SR status register
Un-protection
Erase the corresponding bit on WRPx option bytes, x = 0..3.
Reset the device (POR Reset) or set the FORCE_OPTLOAD bit to re-load the options bytes for
disabling any write protection.
The write protection bit values are visible also through FLASH_WRPR write protection
register.
Read protection
The read protection is activated by setting the RDP option byte and then, by applying
POR reset or using FORCE_OPTLOAD bit from FLASH_CR register to reload the
new RDP option byte.
Three levels of protection from no protection (Level 0) to maximum protection (Level
2 or No debug)
141
0xAA
0x55
Level 0
Level 1
0xCC
0x33
No read protection
All operations (if no write protection is set) from/to the Flash, option byte or the
RTC Backup registers are possible in all boot configurations (Flash user boot,
boot RAM, boot loader or debug).
142
User mode: Code executing in user mode can access main Flash memory and
option bytes with all operations.
Debug, boot RAM and boot loader modes: The main Flash memory and
backup registers (RTC_BKPxR in RTC) are totally inaccessible in these modes, a
simple read access generates a bus error and a Hard Fault interrupt. Any
attempted program/erase operations sets the PGERR flag.
Un-protection:
When the RPD is reprogrammed to the value 0xAA to move back to Level 0, a
Mass erase of the main Flash memory is performed and the backup registers
(RTC_BKPxR in RTC) are reset.
Un-protection:
Not possible :level 2 cannot be removed at all: it is an irreversible operation.
143
Level 1
RDP 0xCC
RDP 0xAA
Write options including RDP
= 0xCC
Level 2
RDP=0xCC
144
Level 0
RDP=0xAA
RDP = 0xAA
Other option(s) modified
Option byte write (RDP level increase) includes: Option byte erase and New option byte programming
Option byte write (RDP level decrease) includes: Option byte erase, New option byte programming and Mass Erase
Option byte write (RDP level identical) includes : Option byte erase and New option byte programming
145
Protection
level
User execution
Read
Write
Erase
Read
Write
Erase
Main
memory
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
N/A
N/A
N/A
System
memory
Yes
No
No
Yes
No
No
Yes
No
No
N/A
N/A
N/A
Option
bytes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
N/A
N/A
N/A
Backup
registers
Yes
Yes
N/A
No
No
N/A
Yes
Yes
N/A
N/A
N/A
N/A
Quiz
List all supported protections and How Enable/Disable them ?
____________
146
VDDA domain
A/D converter
D/A converter
COMP
Temp. sensor
Reset block
PLL
VDDA
VSSA
VDD domain
VSS
VDD
V18 domain
I/O Rings
STANDBY circuitry
(Wake-up logic,
IWWDG, RTC, LSE
crystal 32K osc,
RCC CSR )
Voltage Regulator
Backup domain
Core
Memories
Digital
peripherals
148
VDDA domain
A/D converter
D/A converter
COMP
Temp. sensor
Reset block
PLL
SDADCs
SDADC1_2_VDD
SDADC3_VDD
SDADC1_2_3_VSS
VDDA
VSSA
VDD domain
VSS
VDD
Voltage Regulator
Backup domain
I/O Rings
STANDBY circuitry
(Wake-up logic,
IWWDG, RTC, LSE
crystal 32K osc,
RCC CSR )
VBAT
V18 domain
Core
Memories
Digital
peripherals
149
Power Sequence
150
151
POR
Vtrh
40mv hysteresis
Vtrl
PDR
Tempo
2.5ms
Reset
152
153
Enabled by software
VDDA
PVD
Output
100mv hysteresis
Backup Domain
Backup Domain
VBAT
154
RTC_TAMPx
power switch
RCC BDCR
32KHz OSC
(LSE)
Wakeup
Logic
IWDG
154
155
156
STOP Mode: all peripherals clocks, PLL, HSI and HSE are disabled, SRAM and
registers contents are preserved.
If the RTC and IWDG are running, they are not stopped in STOP (either as their clock
sources)
To further reduce power consumption, the Voltage Regulator can be put in Low Power mode
Wake-up sources:
WFI was used for entry: any EXTI Line configured in Interrupt mode (the corresponding EXTI Interrupt
vector must be enabled in the NVIC)
WFE was used for entry: any EXTI Line configured in event mode
EXTI line source can be: one of the 16 external lines, PVD output, RTC alarm, COMPx, I2Cx,
USARTx or the CEC (*).
The I2Cx, USARTx, CEC (*) can be configured to enable the HSI RC oscillator for processing
incoming data. If this is used, the voltage regulator should not be put in the low-power mode but kept
in normal mode.
After resuming from STOP the clock configuration returns to its reset state (HSI used as system
clock).
(*): CEC is available in STM32F37x only.
Wake-up sources:
WKUPx pins rising edge
RTC alarm and tamper events
External reset in NRST pin
IWDG reset
After wake-up from STANDBY mode, program execution will restart in the same way as after a RESET.
157
SLEEP,
SLEEP now
or
SLEEP onexit
STOP
STANDBY
Entry
Wakeup
WFI
Any interrupt
WFE
Wake-up event
PDDS,
LPSDSR
bits +
SLEEPDEEP
bit +
WFI or WFE
PDDS bit +
SLEEPDEEP
bit +
WFI or WFE
Effect on
1.8V
domain
clocks
Effect on
VDD
domain
clocks
Voltage
regulator
CPU CLK
OFF
no effect on
other
clocks or
analog
clock
sources
None
ON
All 1.8V
domain
clocks
OFF
HSI and
HSE and
oscillator
s
OFF
ON, in low
power
mode
(dependin
g
on
PWR_CR)
OFF
IO state
158
Wakeup latency
None
All I/O pins
keep the same
state as in the
Run mode
HSI RC wakeup
time + regulator
wakeup time
from Low-power
mode
Reset phase
(*): Standby mode: all I/O pins are high impedance except:
- Reset pad (still available)
- RTC pins PC14 and PC15 if configured in the RTC registers.
- WKUP pin 1 (PA0) and WKUP pin 2(PC13), if enabled.
158
F3 Alpha Training
02/04/2012
160
Feature
RUN mode w/ execute from Flash on 72MHz
All peripherals clock ON
RUN mode w/ execute from Flash on 24MHz
All peripherals clock ON
RUN mode w/ execute from Flash on 8MHz
All peripherals clock ON
Sleep mode w/ execute from Flash at 48MHz
All peripherals clock ON
STOP w/ Voltage Regulator in low power
All oscillators OFF, PDR on VDDA is OFF
STANDBY w/ LSI and IWWDG OFF
PDR on VDDA is OFF
Typical values are measured at TA = 25 C, VDD =3.3 V VDDA= 3.3 V.
typ IDD/IDDA
(*)
Quiz
162
162
DMA Features
12 independently configurable channels: hardware requests or software trigger on each
channel.
DMA1: 7 Channels
DMA2: 5 Channels
Software programmable priorities: Very high, High, Medium or Low. (Hardware priority in
case of equality).
Programmable and Independent source and destination transfer data size: Byte,
Halfword or Word.
3 event flags for each channel: DMA Half Transfer, DMA Transfer complete and DMA
Transfer Error.
Memory-to-memory, peripheral-to-memory and memory-to-peripheral transfers and
peripheral-to-peripheral transfers.
Faulty channel is automatically hardware disabled in case of bus access error.
Programmable number of data to be transferred: up to 65535.
Support for circular buffer management.
164
ADC
Channel 1
Channel 2
Channel 3
Channel 4
Channel 5
SPI1_RX
SPI1_TX
SPI2_RX
SPI2_TX
USART1_TX
USART1_RX
USART2_RX
I2C2_TX
I2C2_RX
I2C1_TX
TIM1_CH4
TIM1_TRIG
TIM1_COM
TIM1_UP
TIM1_CH3
USART
USART3_TX
USART3_RX
I2C
TIM1 (*)
TIM1_CH1
TIM2_CH3
TIM3
TIM4
TIM6 /
DAC (*)
Channel 7
ADC1
SPI
TIM2
Channel 6
TIM1_CH2
TIM2_UP
TIM3_CH3
TIM2_CH1
TIM3_CH4
TIM3_UP
TIM4_CH1
USART2_TX
I2C1_RX
TIM2_CH2
TIM2_CH4
TIM3_CH1
TIM3_TRIG
TIM4_CH2
TIM4_CH3
TIM4_UP
TIM6_UP
DAC_CH1 (1)
Channel 1
Channel 2
Channel 3
Channel 4
Channel 5
TIM16_CH1
TIM16_UP
166
TIM16_CH1
TIM16_UP
(*) (1)
TIM17_CH
1
TIM17_UP
TIM17_CH1
TIM17_UP
(*) (1)
TIM18 /
DAC
channel 3 (**)
TIM19 (**)
Channel 7
TIM7_UP
DAC_CH2 (1)
TIM16
TIM17
Channel 6
TIM18_UP
DAC_CH3
TIM19_CH3
TIM19_CH4
TIM19_CH1
TIM19_CH2
TIM19_UP
Channel1
Channel2
Channel3
Channel4
Channel5
ADC
ADC2
ADC4
ADC2 (1)
SDADC1
ADC4 (1)
SDADC2
ADC3
SDADC3
SPI3
SPI3_RX
SPI3_TX
UART4(*)
UART4_RX
TIM6 / DAC
channel 1
TIM6_UP
DAC_CH1
TIM7 / DAC
channel 2
TIM8 / DAC
(*)
UART4_TX
TIM7_UP
DAC_CH2
TIM8_CH3
TIM8_UP
TIM8_CH4
TIM8_TRIG
TIM8_COM
TIM8_CH1
TIM18 / DAC
channel 3 (**)
TIM8_CH2
TIM18_UP
DAC_CH3
167
Quiz
How many DMA Channels are available in the STM32F3xx ?
____________
168
GPIO features
170
Up to 84 (in STM32F37x) and 87 (in STM32F30x) multifunction bidirectional I/O ports available on biggest package 100 pin.
Several I/Os are 5V tolerant (ADC, opamp, comparators pins are not).
All Standard I/Os are shared in 6 ports: GPIOA, GPIOB, GPIOC,
GPIOD, GPIOE, GPIOF.
Atomic Bit Set and Bit Reset using BSRR and BRR registers
GPIO connected to AHB bus, max toggling frequency 18 MHz
Configurable Output slew rate speed up to 50MHz
Locking mechanism (GPIOx_LCKR) provided to freeze the I/O
configuration
When the LOCK sequence has been applied on a port bit, it is no longer possible to
modify the configuration of the port bit until the next reset (no write access to the CRL
and CRH registers corresponding bit).
171
Analog
MODER(i)
[1:0]
OTYPER(i)
[1:0]
PUPDR(i)
[1:0]
I/O configuration
0
0
1
0
1
0
01
Read
0
0
1
0
1
0
0
0
1
0
1
0
00
0
0
1
0
1
0
Input floating
Input with Pull-up
Input with Pull-down
Bit Set/Reset
Register
10
Read / Write
11
Analog mode
On Off
VDD
VDD or VDD_FT(1)
On/Off
Schmitt
Trigger Input Driver
VDD
On/Off
OUTPUT
VSS
CONTROL
VSS
Output Driver
I/O pin
Pull - Up
0
1
0
Pull - Down
0
0
1
To On-chip Peripherals
VSS
Push-Pull
Open Drain
(1) VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.
171
172
Most of the peripherals shares the same pin (like USARTx_TX, TIMx_CH2,
I2Cx_SCL, SPIx_MISO, EVENTOUT)
Alternate functions multiplexers prevent to have several peripherals function pin
to be connected to a specific I/O at a time.
AF0
AF1
AF2
Pin x (016)
AF7
172
During and just after reset, the alternate functions are not active and the
I/O ports are configured in input floating mode. But, the debug pins
(JTAG/SWD) are in AF pull-up/pull-down after reset:
PA13: JTMS/SWDIO
PA14: JTCK/SWCLK
PA15: JTDI
PB3: JTDO
PB4: NJTRST
Quiz
174
How many I/Os and ports there are in the STM32F3xx microcontroller ?
____________
How many External interrupts and Wake-up pins, exist in the STM32F3xx
microcontroller?
____________
174
Same as STM32F1xx
but with New features and
new Name
Interrupt Mask
Register
Pending Request
Register
Rising Trigger
Selection Register
Falling Trigger
Selection Register
Edge Detect
Circuit
To NVIC
Pulse
Generator
Software Interrupt
Event Register
176
EXTI[15:0]
EXTI Features
Event Mask
Register
Quiz
177
177
178
STM32F3 Eco-system
Standard Peripheral Library
16/04/2012
STM32F3xx_StdPeriph_Driver subfolder:
Standard Peripherals drivers
Project folder
STM32F3xx_StdPeriph_Templates
subfolder
STM32F3xx_StdPeriph_Examples subfolder
Utilities folder
STM32_EVAL subfolder for the abstraction
layer of the of the supported evaluation board
Libraries: CMSIS
ARM DSP Library:
A suite of common signal processing
functions for use on Cortex-M processor
based devices. Written in C and CMSIS
compliant
STM32F3xx
Device CMSIS
files
CMSIS files
stm32f3xx.h file
system_stm32f3xx.c/.h files
startup_stm32f3xx.s
ARM DSP Library
16/04/2012
Libraries: stm32f3xx.h
Configuration section
Used device
Std_Periph_Lib use
Specific parameters
Libraries: stm32f3xx_system.c
SystemInit()
This function is called at startup just after reset and before branch to main
program. This call is made inside the "startup_stm32f3xx.s" file.
Setups the system clock (System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings)
Can be generated depending on the configuration made in the clock xls tool
Libraries: startup_stm32f3xx.c
Main Characteristics
Contains the vector table for the device
Libraries: Std_Periph_Drivers
STM32F3xx_StdPeriph_Driver subfolder
Contains all the subdirectories and files that make up
the core of the library:
inc sub-folder : the Peripheral's Drivers header files.
stm32f3xx_ppp.h (one header file per peripheral):
Function prototypes, data structures and enumeration.
Drivers are:
Strict ANSI-C coded
Software Toolchain independent
Projects:Std_Periph_Templates
Standard template projects for all the
supported toolchains that compile the
STM32F3xx Standard Peripheral's drivers
All the user-modifiable files that are
necessary to create a new project
stm32f3xx_conf.h
stm32f3xx_it.c/.h
main.c/.h(optional)
system_stm32f3xx.h
Projects:stm32f3xx_conf.h
Projects:stm32f3xx_it.c
Contains Cortex-M4 Processor Exception Handlers (ISRs)
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void SysTick_Handler(void);
Projects:main.c
main()
Standard C main() function entry
Start of application program
Projects:Std_Periph_Examples
Provides for each peripheral sub-folder, the minimum set of files
needed to run a typical example on how to use this peripheral:
readme.txt: brief text file describing the example and how to make it work.
stm32f3xx_conf.h: header file allowing to enable/disable the peripheral's drivers
header files inclusion.
stm32f3xx_it.c: source file containing the interrupt handlers
stm32f3xx_it.h: header file including all interrupt handler prototypes.
main.c: example of code.
system_stm32f3xx.c: this file provides functions to setup the STM32 system
Utilities
STM32_EVAL: abstraction layer to interact with the Human Interface
resources; buttons, LEDs, LCD and COM ports (USARTs) available on
STMicroelectronics evaluation boards.
Common: contains common drivers (lcd_log.c and fonts.c)
STM32303C_EVAL:Contains board specific functions
Peripheral drivers access through API to control the peripheral configuration and
operation
(+) no need of in-depth study of each peripheral specification and saves development time and
intregration cost
(-) drivers genericity may induce a non optimized size and/or speed of application code.
Procedure:
F1
series
F37x
family
F30x
family
Comment
FW compatibility
ADC
YES
YES
YES++
New design
CAN
YES
YES
YES
Same feature
Full
CEC
YES
YES+
NA
Enhancement
Not compatible
COMP
NA
YES
YES
NA
NA
CRC
YES
YES+
YES+
New feature
Partial
DAC
YES
YES
YES
Same feature
DBGMCU
YES
YES
YES
Same feature
Full
DMA
YES
YES
YES
Same feature
Full
EXTI
YES
YES
YES
Same feature
Full
F1
series
F37x
family
F30x
family
Comment
FW
compatibility
GPIO
YES
YES++
YES++
New design
Not compatible
I2C
YES
YES++
YES++
New design
Not compatible
I2S
YES
YES+
YES+
New fetaure
Partial
IWDG
YES
YES+
YES+
New fetaure
Partial
OPAMP
NA
NA
YES
NA
NA
PWR
YES
YES+
YES+
Enhancement
Partial
RCC
YES
YES+
YES+
New feature
Partial
RTC
YES
YES++
YES++
New peripheral
SDADC
NA
YES++
NA
New peripheral
NA
SDIO
YES
NA
NA
NA
NA
Not compatible
F1
series
F37x
family
F30x
family
Comment
FW compatibility
SPI
YES
YES+
YES+
New fetaure
Partial
SYSCFG
NA
YES
YES
NA
NA
TIM
YES
YES
YES++
USART
YES
YES+
YES+
New fetaure
Partial
WWDG
YES
YES
YES
Same
feature
Full
FSMC
YES
NA
NA
NA
NA
FLASH
YES
YES
YES
Compatible for
common feature
Not compatible
STM32F3 Eco-system
Tools
Customers
Internal
1st
FPGA
F3 basic
support
Validation
Porting on Tech/Tools Support
F3 advanced Firmware
&
support
development toolchains maintenance
verification
Synch with 3rd parties
3rd parties
198
http://gnbproject7mms.gnb.st.com/tools/1632toolssupport/default.aspx
199
Basic Support
200
Customers
Internal
1st
FPGA
F3 basic
support
Validation
Porting on Tech/Tools Support
F3 advanced Firmware
&
support
development toolchains
maintenance
verification
Synch with 3rd parties
3rd parties
1. Connection
2. Flash algorithm
201
Advanced Support
202
Customers
Internal
1st
FPGA
F3 basic
support
Validation
Porting on Tech/Tools Support
F3 advanced Firmware
&
support
development toolchains maintenance
verification
Synch with 3rd parties
3rd parties
(Available)
1. Connection
2. Flash algorithm
3. SFR Viewer (SVD-CMSIS)
Features:
Display, modify, program and erase the
target memory
Save the memory content to different
formats (Hex, SREC and Bin)
Display and modify the option bytes
Flash blank check
Compare the device memory content
with a file
MCU core registers display
Automatic mode
204
205
Readout Protection:
Flash protection against read (3 levels).
Tooltip windows:
Further description
option bit purpose
on
the
user
Write Protection
Flash protection against write operation.
nBoot1
Together with the BOOT0 pin, selects the
Boot mode:
nB00T1 checked/uncheked
BOOT0=0
=> Boot from Main Flash memory.
nB00T1 checked
BOOT0=1
=> Boot from System memory.
nB00T1 unchecked
BOOT0=1
=> Boot from Embedded SRAM.
nSRAM_Parity:
Enable/Disable the SRAM memory Parity
check.
206
Customers
Internal
1st
FPGA
F3 basic
support
Validation
Porting on Tech/Tools Support
F3 advanced Firmware
&
support
development toolchains maintenance
verification
Synch with 3rd parties
3rd parties
207
208
209
2. Add the support of "Connect under rest", "With Pre-Reset" "Normal", "HW Reset", "SW
Reset" options
3. Add the support of "Flash Download", "Flash Erase" from Flash menu
210
EWARM
MDK-ARM
RIDE7
Tasking
TrueSTUDIO
RedSuite (CodeRed), Crossworks (Rowley Associates), Multi
(GreenHills)
211
Lab Session:
Using ETM to identify
root cause of Hardfault
Requirements
Software Tools:
MDK-ARM v4.50
MDK-ARM STM32F3 Add-on Installer
Hardware Tools:
ULINKpro Debug Adaptor
Target Hardware:
STM3240G-EVAL
or
STM3230C-EVAL or STM3237C-EVAL
Objective
To demonstrate using the ETM interface to quickly and easily identify
the root cause of a hard fault condition.
Notes
The procedure for the Lab is the same for both target platforms:
STM3240G-EVAL
STM3230C-EVAL or STM3237C-EVAL
If you are using the STM3240G-EVAL you need to enable the ETM by
moving two jumpers:
JP1 and JP2 (just below the boot switches)
Set to 1-2 (labelled as Trace)
1 of 2
At the beginning of main() you will see calls to initialise the ADC,
LEDs serial port and systick timer.
2 of 2
All project configuration (for debug adaptor, trace settings etc) is done
for you.
Entering Debug
Before we enter the Debug view, we must rebuild the application.
Trace Window
There will already be some content in the Trace window
This is because the application is set to Run to Main on entering debug and the
trace interface collects ALL instructions from device reset.
Press
Or
1 of 4
We can work out what is wrong buy putting a Breakpoint onto the
HardFault Handler and then reviewing the trace information when we
hit the Breakpoint.
Left click in the margin of the startup file to add a breakpoint on the
hardfault handler:
2 of 4
When back in debug, all the windows from the previous session, and
the Breakpoint will be preserved.
Run the application with the
button
And in the source code window you can see we are at the Hardfault
Breakpoint.
3 of 4
Now you can see the last line of source code that was executed
Double click that line and the source code window will update (as will the disassembly window)
In this case, when the ADC reaches zero, the offending line of code generates a
hardfault by doing a divide by 0 operation.
Now we know what is wrong we can modify the source code to fix it...
Exit debug using the
button
button
button
button
JTAG
SWD
SWO
SWO
ETM
1Mb/s
100Mb/s
Streaming
JTAG
ULINK2:
SWD
ULINKpro:
Programming + Run-Control
ULINK2 +
Memory + Breakpoint Access
Serial Wire Trace (SWO)
Serial Wire Trace Capturing (SWO)
100Mbit/sec (Manchester Mode)
1Mbit/sec (UART mode)
ETM Streaming Trace
Up to 800Mbit/sec
100% Code Coverage and
Performance Analysis
Execution Profiling
SWO
Statistical sampling samples 1 in 1,000 cycles
Only gives an approximation of application performance
ETM
Limited to size of debug adapter trace buffer (typically 4MB)
Can only profile small parts of application (~10Secs)
Cannot soak test application for long periods
JTAG
SWD
SWO
ETM
100Mb/s
Streaming
SWD
SWO
ETM
100Mb/s
Streaming
Trace Navigation
JTAG
SWD
SWO
ETM
100Mb/s
Streaming
JTAG
SWD
SWO
ETM
100Mb/s
Streaming
JTAG
SWD
SWO
ETM
100Mb/s
Streaming
Performance Analysis
Optimize and Profile Applications
Identify hotspots quickly
Code Coverage
Implement 100% accurate Code Coverage on silicon
Essential for validation and verification
Further Information
Visit www.keil.com/arm
Product Overview
Users Manual
Application Notes
RCC introduction
Reset:
Initialize the device
Wakeup device
Safety functions (watchdog)
Clocks:
Select appropriate clock source:
Internal
External
Security functions:
In case of clock source malfunction
240
System RESET
Reset sources
241
Resets all registers except some RCC registers and Backup domain
Sources:
Power RESET
Resets all registers except the Backup domain
Sources:
Power On/Power down Reset (POR/PDR)
Exit from STANDBY
VDD
RPU
External
RESET
SYSTEM RESET
Filter
NRST
WWDG RESET
IWWDG RESET
PULSE
GENERATOR
(min 20s)
Software RESET
Low power management RESET
Option byte loader RESET
Power RESET
Standby exit
POR/PDR
242
243
244
32.768KHz
OSC32_IN
/32
RTCCLK
LSE Osc
/8
OSC32_OUT
LSI RC
245
~40kHz
SysTick
IWWDGCLK
HCLK
CSS
8MHz
PCLK1
HSI
HSI RC
/2
4 -32 MHz
OSC_OUT
/2, 3, ..16
PLL
x2, x3,
.. x16
PLLCLK
HSE
SYSCLK
AHB Prescaler
72 MHz max /1, 2, ..512
APB1
Prescaler
/1,2,4,8,16
If (APB1 pres=1)
Else
x1
x2
HSE Osc
PCLK2
OSC_IN
APB2
Prescaler
/1,2,4,8,16
/2, /3
USB
If (APB2 pres=1)
Else
x1
x2
PCLK2
PCLK1
SYSCLK
SYSCLK
USART1
HSI
ADC
USART2,
USART3
HSI
LSE
LSE
HSI
LSI
LSE
SYSCLK
TIMxCLKAPB2
VCO * 2
/2,4,6,8
MCO
TIMxCLKAPB1
PCLK2
SPI1/I2S1
PCLK1
SPI2, SPI3
I2S2, I2S3
SYSCLK
I2C1,
I2C2
LSE
CEC
HSI
HSE
PLLCLK/2
SYSCLK
/244
/1,2,3,4,5,6,7,8,10,12,14,16,18,20,22,24
/2
SDADC1,
SDADC2,
SDADC3
FLITFCLK
to Flash Programming interface
HSI RC
8 MHz
HSI
To I2Cx (x = 1,2)
SYSCLK
SYSCLK
PLLSRC
Ext.Clock
USB
prescaler
/1,1.5
PLLMUL
PLL
x2,x3..
x16
PLLCLK
SYSCLK
HSE
AHB
prescaler
/1,2,..512
/8
HSE
OSC 432 MHz
APB1
prescaler
/1,2,4,8,16
/2,/3,/16
USBCLK
to USB interface
To AHB bus, core,
memory and DMA
To cortex System
Timer (systick)
To FHCLK Cortex free
running clock
HCLK
HSI
OSC_IN
To I2Sx (x = 2,3)
I2S_CKIN pin
/2
OSC_OUT
PCLK1
If (APB1
prescale
r = 1)x1
else x2
CSS
To APB1 peripherals
To TIM 2,3,4,6,7
PCLK1
OSC32_OUT
OSC32_IN
LSE
OSC
32.768kh
z
/32
LSI RC
40 KHz
LSI
SYSCLK
HSI
LSE
RTCCLK
To
RTC
APB2
prescaler
/1,2,4,8,16
To IWDG
IWDGCLK
MCO
/2
PLLCLK
HSI
LSI
HSE
SYSCLK
LSE
ADC
Prescaler
/1,2,4
To USARTx ( x = 2..5)
PCLK2
To APB2 peripherals
RTCSEL[1:0]
MCO
246
If (APB2
prescale
r = 1)x1
else x2
To ADCxy
(xy = 12 ,32 )
To TIM 15,16,17
PCLK2
SYSCLK
ADC Prescaler
/1,2,4,6,8,10,12,1
6,32,64,128,256
HSI
To USART1
LSE
x2
To TIM1/8
247
TIM14 (in F37x) and TIM16 (in F30x) input capture can be
triggered by:
TI1_RMP[1:0] in TIM14_OR/
GPIO pin
RTCCLK
HSE/32
MCO output
TIM14
Or
TIM16
TI1
TIM16_OR
RTCCLK
HSE/32
MCO
GPIO
LSI
LSE
SYSCLK
HSI
Purposes:
HSE
PLLCLK/2
Measure HSI frequency using the precise LSE clock. HSI is used as system clock.
Knowing the (more precise) LSE frequency we can determine the HSI frequency.
Measure the LSI frequency using HSE or HSI. To fine tune IWWDG and/or RTC timing
(if LSI used as RTC clock).
Have rough indication of the frequency of external crystal by comparing HSI and
HSE/32
Quiz
What is the maximum AHB and APB1 and APB2 clock frequencies ?
What is the purpose of connecting LSE clock to TIM14/16 CH1 input
capture and how it could be done?
What is the purpose of the CSS?
248
250
31
00100010110011000100010010001000
251
CRC Operation
Operation:
Each write operation to the data register creates a combination of the previous CRC
value (stored in CRC_DR) and the new one. CRC computation is done on the whole 32bit data word or byte by byte depending on the format of the data being written.
The duration of the CRC computation depends on input data width:
4 AHB clock cycles for 32-bit
2 AHB clock cycles for 16-bit
1 AHB clock cycles for 8-bit
Polynomial can be changed after finishing current CRC calculation (or after CRC reset)
The input and output data can be bit reversed, to manage the various endianness
schemes (REV_IN [1:0], REV_OUT bits).
AHB Bus
32-bit (read access)
Initial value
CRC computation
Polynomial
252
Quiz
What are the new programmable parameters in CRC?
How many cycles are required to compute a CRC of 15 bytes from
RAM ?
What is the value taken into CRC computation if data input is :
0x11223344 and reversal mode is set to half word ?
0x44332211
0x22114433
0x448822CC
253
DAC introduction
Interfaces:
Two 12-bit DAC converters inside STM32F37x:
DAC1 with 2 DAC output channels
DAC2 with 1 output channel
255
TIM7_TRGO
DMAENx
TIM3/8_TRGO
TENx
MAMPx[3:0]
SWTRIGx
TIM6_TRGO
WAVEx[1:0]
TSELx[2:0]
TIM2_TRGO
TIM4_TRGO
TIM5/15_TRGO
Control Logic x
Ext_IT_9
DMA Request x
12 bits
Noise/triangle
DHRx
BOFF
12 bits
DORx
12 bits
VREF+
VDDA
VSSA
DAC_OUTx
256
Output current:
Optional output analog buffer (booster) to improve current capability (BOFF bit)
Without output analog buffer (BOFF bit = 1):
Rail to rail output: Vout = (VREF+ + 1LSB) (VREF+ - 1LSB)
Output impedance: 15k
Min. load for 1% error: >1.5M
DAC_OUT
RLOAD >= 5 K
VSS
257
12-bit mode:
Right alignment (in register DAC_DHR12Rx)
Left alignment (in register DAC_DHR12Lx)
Also in dual channel mode (registers DAC_DHR12RD, DAC_DHR12LD)
8 bits Right alignment:
alignment Load DAC_DHR8Rx [7:0]
DAC_DHR8Rx
D7
D6
D5
D4
D3
D2
D1
D0
D3
D2
D1
D0
DAC_DHR12Rx
D11 D10
D9
D8
D7
D6
D5
D4
D7
D5
D4
D3
D2
D1
D0
DAC_DHR12Lx
D11 D10
D9
D8
D6
258
Triggers:
Timers:
External pin
EXTI line9
Software
SWTRIG bit
259
260
261
DAC_DHR12LD
D11 D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
D11 D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
262
CPU
RAM
(Pattern 1)
(Pattern 2)
DACx
DAC Triggers
Channel x
output
DMA
263
Quiz
How many DAC channels are in the STM32F3x microcontroller ?
What are the possibilities to start a DAC channel conversion?
What are the different generated waves?
What is the min. load of DAC channel output?
264
WWDG_CFR
W6 W5 W4 W3 W2 W1 W0
comparator
= 1 when
T6:0 > W6:0
CM
P
W[6:0]
3Fh
Write WWDG_CR
WDGA T6 T5 T4 T3 T2 T1 T0
Refresh
not allowed
Refresh
Window
time
WWDG_CR
T6 bit
Reset
PCLK
(up to 48MHz)
PRESCALER
(WDGTB)
266
4096 * 1
4096 * 2
4096 * 4
4096 * 8
267
Prescaler
Register
Status
Register
Reload
Register
Key
Register
Window
Register
12-bit
reload value
LSI
(40KHz)
8-bit
PRESCALER
12-bit
down counter
IWWDG
Reset
12-bit
window comp
VDD voltage domain
Once enabled the IWWDG cant be disabled (LSI cant be disabled too)
Implemented in the VDD voltage domain:
Is still functional in STOP and STANDBY mode
268
IWDG reset flag (in RCC_CSR) to inform when a IWDG reset occurs
(after device reset)
Prescaled from the LSI clock (40kHz):
8-bit predivider: 4-256 (and 12-bit watchdog counter):
Min-max timeout value: 100s / 26.2s
269
Quiz
Which clock feeds the IWWDG down counter?
How can be the IWWDG started?
In which WDG is implemented the window option?
How to detect that device was reset by watchdogs?
270
Up to 18 MHz
bit rate
NEW!
273
274
(SD)
(MCLK)
(CK)
(WS)
274
275
275
NSS management
276
NSS input SSM selects HW control (NSS pin) or SW control (SSI bit):
Slave mode - select slave for communication
(optionally can be used for synchronization of a transaction begin)
Master mode - signalize conflict between masters
276
277
Master
Slave
NSS HW management
NSS SW management
277
278
Master
Slave
278
Master
Slave
279
280
Separated NSSs
At full duplex one slave
only (just selected by
NSS) can
communicate with
master at time
Slave
!
Master
Slave
Common NSS
Slaves at simplex
Rx only mode can
receive the same data
sent in parallel from
master
MISO pin cant be used
at this case
280
281
282
Example:
4-bit data frame length, MSB first, 16-bit threshold is set for
RxFIFO,
both FIFOs can be accessed by single 16-bit read or write
1x TxE event at transmitter - 1x RxNE event at receiver
283
DMA
DMA handles automatically:
284
BSY flag
Communication activity checking
(to prevent corruption of ongoing transfer)
Before SPI or its clock are disabled (at some modes)
Before entry to Halt
285
286
286
287
MOSI
Data 1
Data 2
Data n
CRC[1..n]
CRCNXT=1
Receiver - compares last frame(s)
MISO
Data 1
Data 2
Data n
CRC[1..n]
SCK
CRCERR
interrupt
NSS
287
288
K
R = 4.7 K
VDD
MOSI
CS
1234
SCK
MISO
5678
Master
288
289
290
Be careful!
When data packed mode is used
Keep Rx threshold & read access of Rx FIFO always in line either 8-bit or
16-bit (preferable -> limited number of events)
Change Rx threshold just before last odd data frame is received
CPHA=0
Dummy/Odd/CRC Frame
Control
window
291
Quiz
What is a maximum SPI speed?
When data packed mode is used?
What should be in line when access the RxFIFO?
Does a master take any care of the NSS signal level if it is
managed by SW?
How many bytes (maximum) can be stored into TxFIFO till it
is full when 8-bit access is used?
What should precede before SPI is disabled?
292
Dedicated transmission and reception flags (TxE and RxNE) with interrupt capability
294
295
296
USART features
USARTs1/2
/3
UART4
UART5
YES
NO
NO
YES
YES
NO
Multiprocessor communication
YES
YES
YES
Synchronous mode
YES
NO
NO
Smartcard mode
YES
NO
NO
YES
YES
YES
IrDA
YES
YES
YES
LIN
YES
YES
YES
YES
YES
YES
Receiver timeout
YES
YES
YES
Modbus Communication
YES
YES
YES
Autobaudrate detection
YES
YES
YES
Driver enable
YES
NO
NO
USART features
USART1
USART2
USART3
YES
YES
YES
YES
YES
YES
Multiprocessor communication
YES
YES
YES
Synchronous mode
YES
YES
YES
Smartcard mode
YES
YES
YES
YES
YES
YES
IrDA
YES
YES
YES
LIN
YES
YES
YES
YES
YES
YES
Receiver timeout
YES
YES
YES
Modbus Communication
YES
YES
YES
Autobaudrate detection
YES
YES
YES
Driver enable
YES
YES
YES
298
299
300
DMA Capability
301
Synchronous Mode
USART supports Full duplex synchronous communication mode
Slave
Master
SCLK
SCK
Rx
MISO
Tx
MOSI
USART
NSS
Full Duplex
SPI
302
USART
Tx
SCLK
303
T=0
STM32F3xx
STM32F1xx
3Mbits/s
4.5Mbits/s
The USART can handle automatic resending of data. The number of retries is
programmable (8 max).
A programmable guardtime is
automaticaly inserted between two
consecutive characters in
transmission.
Yes
No
New
T=1
304
R = 10 K
USART1
Tx
Half Duplex
USART2
Tx
305
306
Modbus communication
307
Auto-baudrate detection
Any character starting with a bit at 1 the USART will measure the duration of the START bit
(Falling edge to rising edge).
Any character starting with a 10xx bit pattern the USART will measure the duration of the START
bit and of the first data bit (Falling edge to Falling edge).
A 0x7F character frame (it may be a 0x7F character in LSB first mode or a 0xFE in MSB first mode).
In this case, the USART measures the duration of the start bit and the duration of bit 6.
A 0x55 character frame. In this case, the USART measures the duration of the start bit, the duration
of bit 0 and the duration of bit 6. In parallel, another check is performed for each intermediate
transition of RX line.
Once the automatic baudrate detection is activated, the USART will wait for the first character on the RX
line. The auto-baudrate completion is indicated by the setting of ABRF flag.
The clock source frequency must be compatible with the expected communication speed : When
oversampling by 16, the baud rate is between fCK/65535 and fCK/16. When oversampling by 8, the
baudrate is between fCK/65535 and fCK/8).
If the line is noisy, the correct baudrate detection is not guaranteed (BRR content may be corrupted))
308
USART Interrupts
Interrupt event
Interrupt flag
TXE
Transmission Complete
TC
CTS
CTSIF
RXNE
Overrun Error
ORE
IDLE
Parity Error
PE
LIN break
LBDF
NE, ORE, FE
Character Match
CMF
RTOF
End of Block
EOBF
WUF
309
310
Feature
STM32F3
STM32F1/2/L
Yes
Yes
1, 1.5, 2
0.5, 1, 1.5, 2
Yes
Yes
Yes
Yes
Programmable parity
Yes
Yes
Yes
Yes
Yes
No
Yes
No
IrDA
Yes
Yes
Yes
No
LIN
Yes
Yes
Smartcard
Yes (T = 0, T=1)
Yes (T = 0)
Yes
No
Yes
No
311
Feature
STM32F3
STM32F1/2/L
Receiver timeout
Yes
No
Auto-baudrate detection
Yes
No
Yes
Yes
Yes
No
Yes
No
Multiprocessor communication
Yes
Yes
Quiz
What are the features that are not supported by the UART4/5 in the STM32F30x?
____________
312
This lab illustrates the use of the USART to wake up the MCU
from STOP mode. The wake up method is teh START bit
detection.
F3 Alpha Training
02/04/2012
314
USART configuration
Select the USART clock : LSE or HSI.
Configure the USARTs Init Structure with the appropriate values:
BaudRate = 9600 baud // if HSI is clock source otherwise 1200 if LSE is clock
source
Word Length = 8 Bits
Stop Bit = 1 Stop Bit
Parity = No Parity
Hardware flow control disabled (RTS and CTS signals)
Receive and transmit enabled.
F3 Alpha Training
02/04/2012
315
Put the adequate condition to ensure that USART RX is ready by checking that
REACK flag is set:
Use the USART_GetFlagStatus function
Complete the function call to enable the Wake up from Stop Mode Interrupt:
USART_ITConfig(USART1, .... , ENABLE);
Check that USART is not performing any transfer before putting it in Stop Mode, by
checking the BUSY Flag:
Use the USART_GetFlagStatus function
02/04/2012
316
318
319
319
RCC_CFGR3 / I2C1SW
Analog
Noise
Filter
GPIO
logic
SCL
Data
Control
Digital
Noise
Filter
Analog
Noise
Filter
GPIO
logic
SDA
I2C1
SYSCLK
HSI
Clock
Control
Digital
Noise
Filter
I2CCLK
SYSCFG_CFGR1 / I2Cx_FM+
SYSCFG_CFGR1 / I2C_PBx_FM+
Registers
PCLK
APB bus
SMBA
320
321
321
Only analog filter can be enabled when Wakeup from STOP feature is enable.
322
322
Setup and Hold timings between SDA and SCL in transmission are programmable by
SW with PRESC, SDADEL and SCLDEL fields in I2C Timing Register
(I2Cx_TIMINGR).
SDADEL is used to generate Data Hold time. TSDADEL = SDADEL * (PRESC+1) * TI2CCLK
SCLDEL is used to generate Data Setup time. TSCLDEL = (SCLDEL+1) * (PRESC+1) * TI2CCLK
SDADEL
SCL
SDA
TSYNC1
SCL falling edge internal detection
The Setup and Hold configuration must be programmed when the I2C is disable.
323
323
SCL Low and High duration are programmable by SW with PRESC, SCLL and SCLH fields in I2C
Timing Register (I2Cx_TIMINGR).
SCL Low counter is (SCLL+1) * (PRESC+1) * TI2CCLK. . It starts counting after SCL falling edge internal detection. After
counting, SCL is released.
SCL High counter is (SCLH+1) * (PRESC+1) * TI2CCLK . It starts counting after SCL rising edge internal detection.
After counting SCL is driven low.
SCL Period:
TSYNC2
SCLH
SCLL
SCL
SDA
TSYNC1
SCL falling edge internal detection
The SCLL and SCLH configuration must be programmed when the I2C is disable.
324
324
000
address[7:1] = OA2[7:1]
001
010
...
111
324
325
325
When I2CCLK clock is HSI, the I2C is able to wakeup MCU from STOP when it
receives its slave address. All addressing mode are supported.
During STOP mode and no address reception : HSI is switched off.
On START detection, I2C enables HSI, used for address reception.
325
326
326
For payload <= 255 bytes : only 1 write action needed !! (apart data rd/wr)
START=1
I2Cx_CR2 is written w/ :
AUTOEND
0 : Software end mode
326
327
327
RELOAD
0 : No reload
1 : Reload mode
327
Slave mode
328
328
SBC
0 : Slave Byte
Control disable
1 : Slave Byte
Control enable
I2C events
Interrupt event
Interrupt flag
RXNE
TXIS
STOPF
TCR
Transfer Complete
TC
Address matched
ADDR
NACK reception
NACKF
329
329
329
SMBUS
330
330
331
331
331
Error conditions
Interrupt event
Interrupt flag
BERR
Arbitration Loss
ARLO
OVR
PECERR
TIMEOUT
ALERT
332
332
332
Quiz
333
333
This Lab illustrates the use of I2C is Master mode to write and read
data in RF EEPROM.
F3 Alpha Training
04/04/2012
335
F3 Alpha Training
04/04/2012
336
Presentation Title
04/04/2012
337
04/04/2012
338
I2S Peripheral
340
Master clock may be output to drive an external audio component. Ratio is fixed at
256xFs (where Fs is the audio sampling frequency).
I2SxCLK
PLLCLK
SPI/I2Sx
SYSCLK
I2Sx_SD(in/out)
I2Sx_WS
HSI
HSE
I2SSRC
I2Sx_ext
I2Sx_extSD(out/in)
SW
STM32F30xxx
Where x can be 2 or 3
I2Sx_ext can be used only in full duplex mode (Always in slave mode).
Both I2Sx and I2Sx_ext can be configured as transmitters or receivers
343
Half/Full-Duplex Communication
344
STM32F30xxx
I2Sx_WS
I2Sx_extSD(out/in)
SDout
WS
SDin
MCLK
I2Sx_MCLK
MCLK
Analog Interface
I2Sx_SD(in/out)
Audio Codec
CK
Digital Interface
I2Sx_SCK
And
2 x Full-Duplex Communication
UART controls *
I2S out
Bluetooth
I2S in
I2S out
Audio Codec
STM32F30xxx
I2S in
I2C controls **
Battery
Bluetooth Headset
* Depends on the Codec control method
** Depends on the Bluetooth control method
345
STM32F37xxx vs STM32F30xxx
Features
STM32F37xxx
STM32F30xxx
Instance
3 (I2S1, I2S2,I2S3)
2 (I2S2, I2S3)
Simplex
Simplex/full-duplex
No
Yes
Communication mode
External clock
346
Quiz
How many I2Ss are available in the STM32F30xxx and STM32F37xxx microcontroller?
____________
How to use I2Ss available in the STM32F30xxx in Full duplex mode?
____________
What are the standard audio frequencies supported by I2Ss?
____________
What are the different I2S error flags?
____________
347
348
CAN Peripheral
Reception
Two receive FIFOs with three stages
14 scalable filter banks
Configurable FIFO overrun
Time Stamp on SOF reception
Sleep Mode
Initialization
Mode
Normal
Mode
Operation mode
Test mode
- Slient mode
- LoopBack mode
- Loop back combined with silent mode
352
Mailbox 2
Mailbox 1
Master Status
Transmit Status
Interrupt Enable
Bit Timing
Error Status
Mailbox 0
Filter Master
Filter Scale
Filter Mode
Filter Activation
Master Control
Receive FIFO 0
Receive FIFO 1
Mailbox 2
Mailbox 2
Mailbox 1
Mailbox 1
Mailbox 0
Mailbox 0
Transmission
Scheduler
Acceptance Filters
Filter
Memory
Access
Controller
..
Filter range : 0 .. 13
..
13
353
Quiz
How many transmit mailboxes are in the STM32F3xxx bxCAN?
____________
354
Calendar with Sub seconds, seconds, minutes, hours, week day, date, month, year.
Two programmable alarms with interrupt function. The alarms can be triggered by
any combination of the calendar fields.
A periodic flag triggering an automatic wakeup interrupt. This flag is issued by a 16-bit
auto-reload timer with programmable resolution. This timer is also called wakeup
timer.
A second clock source (50 or 60Hz) can be used to update the calendar.
Maskable interrupts/events:
Digital calibration circuit (periodic counter correction) to achieve 0.95 ppm accuracy
Time-stamp function for event saving with sub second precision (1 event)
Backup registers which are reset when an tamper detection event occurs.
356
357
STM32F2x
STM32F0x
STM32F4x
RTC in VBAT
YES
Calendar in
BCD
YES
STM32F30x
Calendar Sub
seconds access
NO
YES
Resolution down to RTCCLK
Calendar
synchronization
on the fly
NO
YES
Alarm on
calendar
2 wo/ subseconds 1 w/
subseconds
Calendar
Calibration
Calib window :
64min
Calibration step:
-2ppm/ +4ppm
Range [63ppm+126ppm]
STM32F37x
2 w/ subseconds
STM32F0x
STM32F4x
Synchronization
on mains
STM32F30x
YES
NO
Timestamp
YES
Sec, Min,
Hour, Date
YES
Sec, Min, Hour, Date, Sub seconds
Tamper
YES
2 pins/1
event
Edge
detection
only
YES
2 pins/2 event
Level Detection
Configurable
filtering
YES
3 pins/ 3 events
Level Detection
with Configurable filtering
32-bit Backup
registers
20
20
16
PC13-14-15
output state kept
in Standby
NO
YES
NO
YES
STM32F37x
YES
Periodic wakeup
359
359
YES
32
Tamper Flag
RTC_TS
TimeStamp Registers
RTC_REFIN
TimeStamp Flag
Alarm B
RTCSEL [1:0]
HSE / 32
Smooth
Calibration
LSE
LSI
360
360
Alarm A
RTCCLK
ssr
(binary format)
PREDIV_A [6:0]
Alarm A Flag
Calendar
Calendar
Asynchronous
7bit Prescaler
Alarm B Flag
RTC_ALARM
Synchronous
15bit Prescaler
Day/date/month/year HH:mm:ss
(12/24 format)
PREDIV_S [14:0]
1 Hz
RTC_CALIB
512 Hz
COSEL
Wake-Up
16bit autoreload
Timer
WUCKSEL [2:0]
Periodic
wake up
Flag
361
361
362
362
Before to start using the RTC you have to program the clock
controller :
Configure and Enable the RTCCLK source in the RCC_BDCR register
362
The RTC remains active what ever the low power mode
When enabled, 5 events can exit the device from low power modes:
Alarm A
Alarm B
Wakeup
Tamper 1/ 2 / 3
TimeStamp
The RTC remains active in VBAT mode (VDD off) when clocked by LSE
The RTC remains active under Reset except at Power-on Reset
The RTC configuration registers including prescaler programming are not affected by
system Reset else than Power-on Reset.
When clocked by LSE, the RTC clock is not stopped under Reset, except power-on
reset.
363
363
364
364
RTC_CALIB
enabled
Tamper
enabled
Time
stamp
enabled
PC13MODE
PC13VALUE
Alarm out
output OD
Dont care
Dont care
Dont care
Dont care
Alarm out
output PP
Dont care
Dont care
Dont care
Dont care
Calibration out
output PP
Dont care
Dont care
Dont care
Dont care
TAMPER input
floating
Dont care
Dont care
TIMESTAMP
and TAMPER
input floating
Dont care
Dont care
TIMESTAMP
input floating
Dont care
Dont care
Output PP forced
PC13 output
data value
Standard GPIO
Dont care
Pin configuration
and function
365
365
LSEON
LSEBYP
PC14MODE
PC14VALUE
LSE oscillator
Dont care
Dont care
LSE BYPASS
Dont care
Dont care
Output PP forced
Dont care
PC14 output
data value
Standard GPIO
Dont care
Dont care
LSE ON
LSEBYP
PC15MODE
PC15VALUE
Dont care
Dont care
1
1
PC15 output
data value
Dont care
Output PP forced
Standard GPIO
Dont care
Dont care
365
366
366
Shadow
registers
Time
Date
Day : Month : Date : Year
DR
HH
mm : ss : ssr
TR
SSR
366
367
367
RTC initialization :
Enter in initialization phase mode by setting the INIT bit in ISR register
This mode is confirmed with the INITF flag also in ISR register
Program the prescaler register (PRER) according to the clock source to get 1Hz clock to
the calendar.
Load the initial date values in the 2 shadow registers (TR, DR).
And other configuration registers like RTC_CR (hour format, )
After reset the check of the INITS flag in ISR register indicates if the calendar is
already initialized (year not at zero) or not (like after Power-on).
To manage the daylight saving there are 3 bits in CR:
SUB1H or ADD1H to subtract or add one hour to the calendar
BCK to memorize above action
367
368
368
The shadow registers are automatically updated each time the RTCCLK
clock is synchronized with System Clock.
368
369
369
Reference Clock detection: A more precise second source clock (like mains 50
or 60 Hz) can be used to enhance the long-term precision of the calendar:
The second source clock is automatically detected and used to update the calendar
The LSE clock is automatically used to update the calendar whenever the second
source clock becomes unavailable
369
370
370
371
371
Wake-Up
RTCCLK
WakeUpCLK
Asynchrone 4bit
Prescaler
WUCKSEL[2:0]
ValueMax = div16
ValueMin = div2
16bit autoreload
Timer
ValueMax = 0xFFFF
ValueMin = 0x0000
Periodic wake
up Flag
RTCCLK = 32.768KHz
Resolution min=2xRTCCLK=61s
371
372
372
RTCCLK
Asynchrone 7bit
Prescaler
Synchrone 15bit
Prescaler
Wake-Up
WakeUpCLK
ck_spre
16bit autoreload
Timer
ValueMax = 0xFFFF
ValueMin = 0x0000
373
373
RTCCLK
Asynchrone 7bit
Prescaler
ValueMax = div 27
ValueMin = 1
Synchrone 13bit
Prescaler
Wake-Up
ck_spre
WakeUpCLK
16bit autoreload
Timer
ValueMax = 0xFFFF
ValueMin = 0x0000
Periodic
Wake-up
Flag
Accuracy
Total range
8s
1.91 ppm
[0 480ppm]
16s
0.95 ppm
[0 480ppm]
32s
0.48 ppm
[0 480ppm]
374
Tamper detection
3 tamper pins and events
RTC_TAMPx
Tamper
switch
STM32
Configurable filter:
Sampling rate : 128Hz, 64Hz, 32Hz, 16Hz, 8Hz, 4Hz,
2Hz, 1Hz
Number of consecutive identical events before issuing
an interrupt to wake-up the MCU : 1, 2, 4, 8
375
Floating input
(Not connected)
Switch opened
Voltage on Tamper
Detect Input
1 cycle pre-charge
2 cycles pre-charge
4 cycles pre-charge
(8 cycles not shown)
Switch closed
376
Quiz
What are the different RTC clock sources ?
--------------------------------------------------- What are the different RTC interrupts ?
------------------------------------------------------ What is the maximum RTC Sub second (RTC_SSR) resolution?
------------------------------------------------------- How many RTC Backup Registers are available?
----------------------------------------------------------
377
Counter
Type
Prescaler
factor
DMA
32 bit
Up, Down
and
Up/Down
1...65536
YES
16 bit
Up, Down
and
Up/Down
165536
16 bit
Up
16 bit
16 bit
General purpose
TIM2
General purpose
Capture
Compare
channels
Synchronization
Master
config
Slave
config
YES
YES
YES
YES
YES
165536
YES
YES
NO
Up
165536
NO
YES(1)
NO
Up
165536
NO
YES
YES
Basic
TIM15
(1)
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
TIM6/7/18
379
General purpose
Counter
resolution
Counter
Type
Prescaler
factor
DMA
32 bit
1...65536
YES
16 bit
165536
16 bit
Up
16 bit
Capture
Compare
channels
Synchronization
Master
config
Slave
config
YES
YES
YES
YES
YES
165536
YES
YES
NO
Up
165536
NO
YES(1)
NO
16 bit
Up
165536
NO
YES
YES
16 bit
Up
165536
NO
YES(2)
NO
16 bit
Up
165536
NO
NO
YES
General purpose
TIM15
1 channel
TIM12
(1)
(2)
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
TIM6/7/18
380
Up to 4 16-bit resolution
Capture Compare channels
(TIM3/4/19)
381
Clock
ITR 1
Trigger/Clock
ITR 2
ITR 3
Controller
Trigger
Output
ITR 4
Up to 4 32-bit resolution
Capture Compare channels
(TIM2/5)
16-Bit Prescaler
Auto Reload REG
Inter-timers synchronization
Up to 6 IT/DMA Requests
CH1
CH1
Encoder Interface
CH2
CH3
Capture Compare
Capture
Compare
Capture
Compare
Capture Compare
CH2
CH3
CH4
CH4
TIM2/5
TIM3/4/19
Clock
Trigger/Clock
ITR 1
ITR 2
Up to 2 16-bit resolution
Capture Compare channels
ITR 3
Controller
ITR 4
Inter-timers synchronization
16-Bit Prescaler
Encoder Interface
Only TIM15 has
complementery output on
channel1
Trigger
Output
CH1
CH1
Capture Compare
Capture Compare
CH1
Comp
CH2
CH2
TIM12
TIM15
382
Clock
ITR 1
383
Trigger/Clock
Trigger
Output
ITR 2
ITR 3
Controller
ITR 4
16-Bit Prescaler
Auto Reload REG
+/- 16/32-Bit Counter
CH1
CH1
CH1
Comp
Capture Compare
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
TIM6/7/18
Center Aligned
Update Event
TIM2/5
TIM3/4/19
Up counting
Down counting
384
Up counting
Update Event
TIM12
TIM15
TIM13/14
TIM16/17
TIM6/7/18
385
Update Event
The content of the preload register is transferred into the shadow register
depends on the Auto-reload Preload feature if enabled or not
If enabled, at each Update Event the transfer occurs
If not enabled, the transfer occurs Immediately
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
386
387
TIMxCLK
Trigger
Controller
Enable/Disable bit
Programable polarity
4 Bits External Trigger Filter
External Trigger Prescaler:
ITR1
Controller
ITR2
ITR3
ITR4
TI1F_ED
Prescaler off
Division by 2
Division by 4
Division by 8
TIM2/5
TI1FP1
TI2FP2
TIM3/4/19
TIM12
TIM15
TRGO
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
388
TI1
IC1
Prescaler
Prescaler
Prescaler
Prescaler
TRC
TI2
IC2
TRC
TI3
IC3
TRC
TI4
IC4
TRC
TIM2/5
TIM3/4/19
389
TIM2/5
TIM3/4/19
390
PWM
Counter
PWM
IC2
IC1 - DUTY
CYCLE
IC2 - PERIOD
10
The PWM Input functionality enables the measurement of the period and the pulse
width of an external waveform.
TIM2/5
TIM3/4/19
TIM12
TIM15
391
Set
Reset
Toggle
Remain unchanged
Timer Clock
Interrupt
Interrupt
OC1
New CCR1
CCR1
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
392
PWM Mode
Available on all channels
Two PWM mode available
PWM mode 1
PWM mode 2
Each PWM mode behavior (waveform shape) depends on the counting direction
Edge-aligned Mode
Center-aligned Mode
Timer Clock
Timer Clock
Update
Event
AutoReload
Capture Compare
AutoReload
Update
Event
Capture Compare
OCx
OCx
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
393
394
TI2
OC1REF
OC1
TIM_ARR
tDelay
tPulse
Repetitive Pulse
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
ii.
iii.
iv.
3.
2.
ii.
iii.
One Pulse Module Selection: Set or Reset the corresponding bit (OPM) in the Configuration
register (CR1).
TIM2/5
TIM3/4/19
TIM12
TIM15
TIM13/14
TIM16/17
395
Encoder
Interface
Encoder enhancement
A copy of the Update Interrupt Flag (UIF) is copied
into bit 31 of the counter register
TI1
TI2
TIM2/5
TIM3/4/19
TIM12
TIM15
396
2.
Select the polarity of each input: example TI1 and TI2 polarity not inverted.
3.
4.
TIM2/5
TIM3/4/19
TIM12
TIM15
397
Trigger &
Slave Mode
Controller
Hall A
Hall B
Hall C TI1
XOR
IC1
Prescaler
Prescaler
Prescaler
Prescaler
TRC
TI2
Input Filter &
Edge detector
IC2
TRC
TI3
Input Filter &
Edge detector
IC3
TRC
TI4
Input Filter &
Edge detector
IC4
TRC
TIM2/5
TIM3/4/19
398
TIM2/5
TIM3/4/19
399
Clock
Counter reset
Master ARR
Counter enable
Master CNT
Update event
Triggered Mode
Slave CNT
Clock
Gated Mode
Master Trigger
Out
New Master
CCR1
Master CCR1
Master CNT
Master CC1
Slave CNT
TIM2/5
TIM3/4/19
TIM12
TIM15
400
counter
Trigger
Controller
TRG 1
SLAVE / MASTER
Update
Timer 2
TRG 2
ITR 1
ITR 3
prescaler
Trigger
Controller
SLAVE
ITR 4
counter
Update
ITR0
ITR2
ITR 4
TIM2/5
TIM3/4/19
TIM12
Timer 15
prescaler
TIM15
counter
401
SLAVE 1
CLOCK
Timer 3
prescaler
Update
Trigger
Controller
TRG1
ITR1
ITR 3
prescaler
counter
ITR 4
counter
SLAVE 2
Timer 4
ITR 3
ITR 2
prescaler
counter
ITR 4
SLAVE 3
ITR3
TIM15
ITR 2
prescaler
ITR 4
TIM2/5
TIM3/4/19
TIM12
TIM15
counter
402
TIM2
Trigger
Controller
TIM3
Trigger
Controller
TRGO
TIM4
Trigger
Controller
TRGO
External Trigger
TIM2/5
TIM3/4/19
TIM12
TIM15
TRGO
403
405
406
The 1.5K pull-up allows the host to detect the device attachment and its
supported speed
High-speed device is detected first as full-speed device then high-speed
capability is detected through bus handshake called chirp sequence
407
408
409
USB Transaction
One bus transaction is composed of a:
Token packet (SETUP, IN, OUT) always issued by the host
Target device address
Target endpoint number
Direction of transaction (IN: Device to host or SETUP/OUT: host to device)
Token packet
PID ADDRESS
ENDPOINT CRC
PID
DATA
CRC
Handshake packet
PID
410
Device
OUT
Host
Device
IN
NAK
DATA0
ACK
IN
OUT
DATA0
DATA1
ACK
NAK
OUT
IN
DATA1
DATA1
ACK
ACK
411
USB Transfer
A USB transfer is composed of one or multiple bus transactions
Four types of USB transfers are defined:
Control: used for control and configuration requests (ex: device
enumeration)
Bulk: used for huge data transfers with no guaranteed delivery rate (ex:
printer, mass-storage drive,..)
Interrupt: used for interrupt driven devices that need to be polled
periodically for small size data transfer (ex: mouse, keyboard, joystick)
Isochronous: used for data streaming applications, that requires a
guaranteed delivery rate, but no error checking (ex: audio, video devices)
During each frame (in LS/FS) or micro-frame (in HS), the host will
schedule the needed transfers with different bandwidth allocation for
each transfer type
412
The maximum data packet size during the optional data stage is 8 bytes for
LS and 64 bytes in FS/HS
Transfer error management done through handshake packet and data PID
toggle mechanism
413
414
SETUP stage
DATA stage IN
STATUS stage
415
416
Clock synchronization between the host and device may be needed (ex:
audio speaker) it can be done by
Device synchronizing its clock to the SOF packet
Using a feedback pipe for flow control
417
Host software may have some latency for processing data and
issuing transfer requests on time due to other processes taking CPU
time
418
420
Main features
422
423
D-
Suspend Timer
Generate the Suspend interrupt when no SOF
is detected for 3ms
48 MHz
RX-TX
Suspend
Timer
Clock
Recovery
Control
Registers & Logic
Endpoint
Selection
Interrupt
Registers & Logic
Control
48MHz
USB Clock
Domain
SIE
APB Clock
Domain
Packet
Buffer
Interface
Endpoint
Registers
USB IP
Analog
Transceiver
PLL
Packet
Buffer
Memory
Arbiter
APB Interface
APB_CLK
APB bus
Register
Mapper
Interrupt
Mapper
APB Interface
Interrupt lines
USB Interrupt
APB
Interface
D+
APB
ARM
Cortex CPU
SRAM
Arbiter
USB IP
D-
Packet
EP2_TX
EP2_RX
EP1_TX
EP1_RX
EP0_TX
EP0_RX
Packet Memory Area
424
The hardware will automatically change the endpoint to NAK state after end of
each transaction, so it is up to application to re enable endpoint for next
transaction
The Transactional model has simple FW handling, but does not allow multiplepacket transfer without CPU intervention after each transferred packet
425
OUT/SETUP endpoint:
Endpoint status should be changed to ACK to allow OUT/SETUP data
packet reception on endpoint
426
EP1 RX
EP2_TX_COUNT
EP2_TX_ADDR
EP1_RX_COUNT
EP1 TX
EP1_RX_ADDR
EP1_TX_COUNT
EP1_TX_ADDR
EP0_RX_COUNT
EP0 RX
EP0_RX_ADDR
EP0_TX_COUNT
EP0 TX
EP0_TX_ADDR
427
EP1 BUFF1
CPU
USB
EP1 BUFF0
PMA
428
EP1 TX Buffer 1
EP1_TX_COUNT_1
EP1 TX Buffer 0
EP1_TX_ADDR_1
EP1_TX_COUNT_0
EP1_TX_ADDR_0
EP0_RX_COUNT
EP0 RX
EP0_RX_ADDR
EP0_TX_COUNT
EP0 TX
EP0_TX_ADDR
429
In order to achieve the best low power consumption, the STM32 can
enter in STOP mode (all peripherals and CPU clocks OFF)
430
431
Demo
RAM usage
7K Bytes
1400 Bytes
10K Bytes
2100 Bytes
7K Bytes
3400 Bytes
432
434
435
STM32F30xVx
STM32F30xRx
STM32F30xCx
3
3
3
3
3
3
3
3
3
3
3
3
3
3
0
0
3
3
2
3
3
3
0
0
24
18
17
436
STM32F37xVx
STM32F37xRx
STM32F37xCx
3
3
3
3
3
3
3
3
3
3
3
3
3
2
0
0
3
2
1
3
3
2
0
0
24
17
14
437
fHCLK
Clock
prescaler
Pulse
generator
Spread
spectrum
G1_IO1
G1_IO2
G1_IO3
G1_IO4
Group counters
TSC_IOG1CR
Interrupt
TSC_IOG2CR
TSC_IOGxCR
Gx_IO1
Gx_IO2
Gx_IO3
Gx_IO4
438
STM32 Device
G1_IO1
G1_IO2
G1_IO3
Rs
Rs
Rs
G1_IO4
Sampling
capacitor
Cs
Cx
(~20pF)
439
Charge cycle
VDD
Electrode
capacitor
charging
VIH
Charge transfer
440
441
S2
S5
S6
S4
Cs
S3
IO
register
Step
S3
S2
S1
Description
Closed
Opened
Closed
Cs discharge
Opened
Opened
Opened
Deadtime
Opened
Closed
Opened
Opened
Opened
Opened
Deadtime
Opened
Opened
Closed
Opened
Opened
Opened
Deadtime
Closed
Opened
Closed
Cx discharge
Complete and simple API for status reporting and application configuration
Touchkey, proximity, linear and rotary touch sensors support
Compliant with MISRA
Compliant with all STM32 C compilers
STM32F051 support planned for end Q2 2012
442
443
444
Quiz
How many channels are supported by STM32F3xx microcontrollers ?
____________
What type of sensors are supported by the STMTouch touch sensing library ?
____________
445
Optional 32.768 kHz crystal needed additionally for RTC, can run on
40KHz Low Speed Internal (LSI) RC oscillator
Only few mandatory external passive components for base system
on LQFP100 package.
STM32F30x Specific
features/peripherals
ADC1 & ADC2 are tightly coupled and can operate in dual mode (ADC1 is master)
ADC3 & ADC4 are tightly coupled and can operate in dual mode (ADC3 is master)
449
450
ADC Pins
Name
Signal Type
Remarks
VREF+
VDDA
VREF-
VSSA
VINP[18:1]
VINN[18:1]
451
452
VREF+
VDDA
ADEN/ADDIS
VOPAMPx
VTS
VINP [18:1]
VINN [18:1]
VREF-
SAR ADC
Sample
and hold
Start
AUTDLY
Address/data bus
ANALOG MUX
ADC_IN[15:1]
DMA Request
ADCAL
VREFINT
VBAT
ADSTP
Control
S/W
trigger
AREADY EOSMP
EXTI0
EOS
EOC
EXTI1
. . . . .
Analog Watchdog
H/W
trigger
AREADYIE EOSMPIE
EXTI15
EOCIE
EXTSEL[3:0] bits
J S/W
trigger
JEXTI0
JEXTSEL[3:0] bits
AWD3_OUT
JEXTI15
AWD2_OUT
. . . . .
AWD1_OUT
JEXTI1
ADC Clocks
ADC1 &ADC2
HCLK
ADC12_CK
AHB interface
/1 , /2 or /4
Analog ADC1
(master)
/1 /256
Analog ADC1
(slave)
CKMODE[0:1]
ADC3 &ADC4
HCLK
ADC34_CK
AHB interface
/1 , /2 or /4
Analog ADC3
(master)
/1 /256
Analog ADC4
(slave)
CKMODE[0:1]
453
ADCxy_CK
AHB div 1, 2 or 4
Benefits
Drawbacks
Clock
constraints
when using
injected
channels
FHCLK >= FADC/ 4 if the resolution of all channels are 12-bit or 10-bit
FHCLK >= FADC/ 3 if there are some channels with 8 bits resolution
FHCLK >= FADC/ 2 if there are some channels with 6 bits resolution
454
DEEPPWD
ADVREGEN
TADCVREG_STUP
ADC Calibration process
ADC Calibration
ADC OFF
ADC state
By Software
ADC
calibration
ADC OFF
455
ADC Calibration
456
ADCALDIF
1 : DIFFERENTIAL INPUT
ADCAL
ADC state
OFF
OFF
ADC Calibration
0x00
CALFACT_x[6:0]
By Software
startup
By Hardware
ADC Startup
Calibration factor
ADC
Calibration
OFF Request
Note: The calibration factor is lost when entering Standby, Vbat mode or when the ADC enter
deep power down mode. In this case it is possible to re-write the calibration factor into the
ADC_CALFACT register without recalibrating.
457
To enable ADC: Set ADEN=1 then wait till ADRDY flag will be equal to
1,
What ever is the digital and the analog clock of the ADC, ADRDY
signal guarantees that ADC data will be transmitted from one domain
to the other.
ADC cannot be re-programmed unless it is stopped (ADSTART = 0).
ADEN
T STAB
ADRDY
ADDIS
ADC state
By Software
OFF
startup
By Hardware
ADC Startup
ADC ready
Req OFF
OFF
OFF Request
Note: There is no hardware protection to prevent these forbidden write accesses and ADC
behavior may become in an unknown state. To recover from this situation, the ADC must be
disabled (clear all ADC_CR register bits).
458
Ch.0
1,5 cycles
Ch.2
Ch.8
Ch.4
Ch.7
1,5 cycles
4,5 cycles
Ch.3
19,5
cycles
61,5 cycles
181,5 cycles
Ch.11
61,5
cycles
459
ADCCLK
7.5 cycles
19.5 cycles
Selection
1.5 cycles
2.5 cycles
4.5 cycles
7.5 cycles
19.5 cycles
61.5 cycles
181.5 cycles
601.5 cycles
Sample Time
61.5 cycles
181.5 cycles
601.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
460
Resolution
Resolution
TConversion
12 bits
12,5 Cycles
10 bits
10,5 Cycles
8 bits
8,5 Cycles
6 bits
6,5 Cycles
12 bits
10 bits
16,6 us 6 Msps
8 bits
6 bits
11,1 us 9 Msps
461
End of sampling
The ADC indicates the end of sampling phase by setting the EOSMP
flag only for regular conversion.
The EOSMP flag is cleared by software by writing1 to it.
An interrupt can be generated if the EOSMPIE bit is set in the
ADC_IER register.
Sampling
Conversion
462
Note 1: When configuring the channel i in differential input mode, channel i+1 is
no longer usable in single-ended mode or in differential mode and must never be
configured to be converted.
463
Single channel
Start
Single channel
CHx
CHx
Stop
Start
Start
CHx
CHx
..
.
Multi--channels (Scan)
Multi
Multi--channels (Scan)
Multi
single conversion mode
CHn
..
.
CHn
Stop
Discontinuons conversion
mode
CHa
CHb
CHc
..
CHx
CHy
CHz
464
465
466
Queue overflow
A Queue overflow occurs when writing into JSQR register while the Queue
is full,
This overflow is signaled by the assertion of the JQOVF flag,
When an overflow occurs, the write access of JSQR register which has created the
overflow is ignored and the queue of context is unchanged,
An interrupt can be generated if bit JQOVFIE is set.
P2
P1
P3 Overflow ignored
Write JSQR
JSQR Queue
EMPTY
P1
P1, P2
By Hardware
By Software
JQOVF
Trigger
JSQR value
ADC state
EMPTY
P1
RDY
JEOS
P2
CONV1 CONV2 CONV3
RDY
EMPTY
CONV1
RDY
467
P1
P2
Write JSQR
JSQR Queue
EMPTY
P1
P2
P1, P2
Trigger
JSQR value
EMPTY
P1
RDY
ADC state
P2
CONV1
P1
sequence of 1 conversion
P2
sequence of 1 conversion
RDY
CONV1
RDY
CONV1
RDY
468
P1
P2
P3
Write JSQR
JSQR Queue
EMPTY
P1
P1, P2
P2
EMPTY
P3
EMPTY
ignored
Trigger
JSQR value
EMPTY
P1
RDY
ADC state
P2
CONV1
P1
sequence of 1 conversion
P2
sequence of 1 conversion
P3
sequence of 1 conversion
RDY
CONV1
EMPTY
RDY
P3
CONV1
EMPTY
RDY
469
D11
D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
Left alignment
D11
D10
SEXT D11
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
D10
D9
D8
D7
D6
D5
D4
D3
D2
D1
D0
470
OVRMOD=1:
The data register is overwritten with the last conversion result and the
previous unread data is lost. If OVR remains at 1, further conversions can be
performed and the ADC_DR register always contains the data from the latest
conversion.
471
472
Delay
Delay
Delay
EOC Flag
For injected conversions: when the JEOS bit has been cleared,
HW/SW Trigger
ADC State
1 2 3 4
Delay
1 2 3 4
Delay
JEOS Flag
Note : A trigger event (for the same group of conversions) occurring during an already ongoing sequence or during
this delay is ignored.
This is a way to automatically adapt the speed of the ADC to the speed of the system
473
.
.
.
.
.
.
AWD
Analog Watchdog
Low Threshold
High Threshold
Status Register
ADC_IN19
Note: The watchdog comparison is performed on the raw converted data before any alignment calculation and
before applying any offsets.
474
ADC state
RDY
CONV1
inside
CONV2
outside
CONV3
inside
CONV4
outside
CONV5
outside
CONV6
inside
EOC Flag
AWDx flag
ADCy_AWDx_OUT
Note: AWDx flag has no influence on the generation of ADCy_AWDx_OUT (ex: ADCy_AWDx_OUT can
toggle while AWDx flag remains at 1 if the software did not clear the flag).
475
476
477
CH15
CH14
CH13
CH12
ADC2
CH6
CH7
CH8
CH9
Trigger for
injected
channels
Conversion
478
CH15
CH14
CH13
CH12
ADC2
CH6
CH7
CH8
CH9
Trigger for
regular
channels
Conversion
479
Interleaved mode
The external trigger source, which start the conversion, comes from ADC1:
ADC1 starts immediately,
ADC2 starts after a configurable delay,
Results stored on the common data register ADC_CDR and on the each
ADCx_DR,
DMA request every 2 conversions
Sampling
ADC1
CH0
CH0
CH0
Conversion
End of Conversion on
ADC1
CH0
ADC2
CH0
CH0
End of Conversion on
ADC2
Trigger for
regular
channels
Delay
Once SW set ADSTART or ADSTP bits of the master ADC, the corresponding bits of the slave
ADC are also automatically set,
480
The external trigger source comes from the injected group multiplexer of the
master ADC,
ADC1
3th
JEOC
Trigger
CH0
CH1
2nd
Trigger
JEOC on ADC1
CH3
6th
JEOC
Trigger
CH10
ADC2
CH2
4th
JEOC
7th
Trigger
5th
JEOC
Trigger
481
Trigger
CH11
JEOC
8th
Trigger
CH12
JEOC on ADC2
CH13
Sampling
ADC1
ADC2
JEOC
CH15
JEOC
2nd
Trigger
CH7
JEOC
JEOC
JEOC, JEOS
4th
Trigger
JEOC, JEOS
CH12
CH14
CH6
CH8
JEOC
JEOC
CH15
CH12
CH14
CH6
JEOC, JEOS
Conversion
3td
Trigger
CH7
JEOC
CH8
JEOC
JEOC, JEOS
482
ADC1
CH0
ADC2
CH1
CH3
Trigger for
regular
channels
CH2
mode interrupted by
injected simultaneous
one
CH1
CH2
CH3
CH2
CH1
CH0
Sampling
Conversion
End of Conversion on
ADC1 and ADC2
ADC1
CH10
CH11
ADC2
CH15
CH14
CH0
CH1
ADC1 inj
ADC2 reg
CH3
CH0
1st
injected
Trigger
CH10
CH1
CH2
Sampling
End of Injected
Conversion on ADC1
CH0
CH1
ADC2 inj
2nd
injected
Trigger
CH11
Conversion
483
MDMA=0b00:
One DMA channel should be configured for each ADC to transfer the data available on
ADCx_DR register,
MDMA=0b10:
A single DMA request is generated each time both master and slave EOC events have
occurred,
Used in interleaved and in regular simultaneous mode when ADC resolution is 10 or 12 bits
MDMA=0b11:
A single DMA request is generated each time both master and slave EOC events have
occurred,
Used in interleaved and in regular simultaneous mode when ADC resolution is 6 or 8 bits
484
ADRDY
EOC
EOCIE
EOS
EOSIE
JEOC
JEOCIE
JEOS
JEOSIE
485
ADRDYIE
ADC
JQOVF
JQOVFIE
Global interrupt
(NVIC)
AWD1
AWD1IE
AWD2
AWD2IE
AWD3
AWD3IE
EOSMP
EOSMPIE
OVR
Flags
OVRIE
Quiz
How many ADC external input channels are in the STM32F3
microcontroller ?
--------------------------------------------------- What is the max ADC frequency ?
------------------------------------------------------ What is the queue of context ?
------------------------------------------------------- How to use DMA in single and in Dual ADC modes ?
----------------------------------------------------------
486
ADC Hands-on
This example describes how to use the ADC1 to convert
continuously the potentiometer analog signal
The converted value is displayed on the LCD Eval Board,
Presentation Title
25/10/2012
487
Channel-level enhancements
Up to 6 channels on Advanced control timers:
Up to 4 channels with input/output stages (as in TIM2/3/4)
Channels remain compatible with those on existing products timers
New features:
Compare-and-PWM-modes-only channels
No capture modes
No DMA channels nor Interrupt request lines
489
Counter
Output
490
Configuration sequence
Set the timer to slave mode: the Combined Reset+Trigger mode shall be used
Select the Retriggerable One Pulse mode through the OCxM[3:0] bit field
Retriggerable OPM mode 1
Retriggerable OPM mode 2
491
492
PWM mode 1
PWM mode 2
Independent
OCxM[3:0] = 4b0110
OCxM[3:0] = 4b0111
Asymmetric
OCxM[3:0] = 4b1110
OCxM[3:0] = 4b1111
Combined
OCxM[3:0] = 4b1100
OCxM[3:0] = 4b1101
493
OC1REF (PWM2)
OC2REF (PWM2)
OC1REFC or OC2REFC
Down-counting
494
495
Channelx
TIM_CHx
Output
Control
OCxREFC
OCyREFC
TIM_CHy
Output
Control
Channely
OCyREF
Counting Direction
OCyM[3:0]
496
CCR1
OC1REF
OC2REF
OC2REFC or
OC1REFC
497
CCR2
OC1REF
OC2REF
OC2REFC or
OC1REFC
498
499
Channelx
TIM_CHx
Output
Control
OCxREFC
OCyREFC
TIM_CHy
Output
Control
Channely
OCyREF
OCyM[3:0]
500
501
502
Pulse-type output
Counter Enable
CCI1F Flag
Level-type output
OC1REF
OC6REF
OC2REF
OC4REF
OC6REF
OC3REF
OC5REF
OC6REF
OC4REF
OC5REF
OC6REF
OC5REF
OC4REF
OC6REF
OC6REF
MMS2[3:0]
OC4REF
to ADC
503
Counter
OC1
OC4
OC2
OC3
OC5REF
OC1REFC
OC2REFC
OC3REFC
Preload
Active
OC4REF
OC6REF
TRGO2
xxx
100
001
xxx
100
504
Counter
OC1REFC
505
506
507
508
509
Configuration
Using ENCODER_MODE bit field within the SYSCFG_CFGR1 register (for more
details refer to SYSCFGR chapter)
Use case
Used with M/T technique for estimating Velocity and Acceleration for wide-range of
velocity values (especially for low velocity values)
510
Timers Hands-on
Preliminary: The aim from the following two hands-on is to get familiarized with
generating Phase-Shifted Signals using the new PWM modes:
Asymmetric PWM mode
Combined PWM mode
Introduction (1/3)
Phase-Shifted signals has the following properties
Adjustable frequency: through ARR register update
Adjustable delay: through the CCxR register update
Adjustable pulse length: through the CCyR register update
Delay: CCxR
Pulse length:
CCyR
512
Introduction (2/3)
Hardware requirements
MantaEdge Eval-Board
Two-channel (or more) oscilloscope
513
Introduction (3/3)
What should be seen on the oscilloscope display?
Channel1: A PWM signal with 50% duty cycle. This waveform is the reference to
which the Phase-shifted signal will be compared
Channel2: The Phase-shifted PWM signal
PWM Period
Channel1
Delay: CCxR
Channel2
Pulse length:
CCyR
514
After solving the issue, you may adjust the outputted waveform shape
Using Potentiometer to control the Phase-shift and Pulse-length parameters
Press key button to switch between Pulse-length and Phase-shift parameters
adjustment
515
After solving the issue, you may adjust the outputted waveform shape
Using Potentiometer to control the Phase-shift and Pulse-length parameters
Press key button to switch between Pulse-length and Phase-shift parameters
adjustment
516
Conclusions
To get the desired waveform using Asymmetric PWM mode
Counter should be configured in Center-aligned mode
Coupled channels Shall be configured into the same PWM mode
The phase-shift using asymmetric mode cannot exceed 180
517
518
Day 4:
Continue with STM32F30x Specific parts
Comparators (COMP) + Hands-on
Operational amplifiers (OPAMP) + Hands-on
STM32F30x Motor Control kit - Complete development platform with all the
hardware and software required to get STM32-based motor control applications
started quickly + STM32F30x new features/peripherals easing motor control
Comparators (COMP)
520
521
521
522
Blanking function
523
523
Quiz
524
How many options are for internal threshold setting if DAC is used by another
task?
Can the threshold go from 0 to VDDA ?
How can the lock bit be reset once activated ?
524
This lab illustrates the use of the COMP with the Timer 1 break
function.
F3 Alpha Training
02/04/2012
526
COMP_InitStructure.COMP_InvertingInput =--------;
COMP_InitStructure.COMP_NonInvertingInput =-------------------;
COMP_InitStructure.COMP_Hysteresis =----------------------;
COMP_InitStructure.COMP_Mode =-------------------;
COMP_InitStructure.COMP_OutputPol =-----------------;;
COMP_Cmd(------------, ENABLE);
F3 Alpha Training
02/04/2012
527
Presentation Title
02/04/2012
528
Operational Amplifier
Features (1/2)
Up to 4 operational amplifiers
Rail to Rail input/output
Low Offset voltage
Access to all terminals
Input multiplexer on inverting and non inverting inputs
Input multiplexer can be triggered by a timer and synchronized with a
PWM signal.
4 operating modes:
Standalone mode: External gain setting
Follower mode
PGA mode: internal gain setting (x2, x4, x8, x16)
PGA mode: internal gain setting (x2, x4, x8, x16) with inverting input used for
filtering.
530
Operating conditions
Features (2/2)
Input stage
Input: rail to rail
Offset: 10mV max
Ibias < +/-1A max (mostly I/O leakage)
Output stage
Speed
GBW: 8MHz
Slew rate 4.5V/s
unity gain stable
531
ADC
OpAmp
--
532
Follower mode
STM32F30x
+
These I/Os are
available
Always
connected to
OpAmp ouput
ADC
OpAmp
--
533
+
These I/Os are
available
Always
connected to
OpAmp ouput.
ADC
OpAmp
--
534
ADC
OpAmp
-Allows
optional lowpass filtering
NB: gain
dependant
cut-off
frequency
Equivalent to
535
536
536
This mode allows switching automatically from one inverting (or non inverting)
input to another inverting (or non inverting) input.
Benefit: useful in dual motor control with a need to measure the currents on the 3 phases on a first
motor and then on the second motor.
The automatic switch is triggered by TIM1 CC6 output arriving on the OPAMP
input multiplexers.
If TCM_EN bit is set, inverting and non inverting input selection is done using
VPS_SEL and VMS_SEL bits.
If TCM_EN bit is reset, inverting and non inverting input selection is done using
VP_SEL and VM_SEL bits.
CCR 6
T1 counter
T8 counter
ADC sampling points
T1 output (1 out of 3)
T8 output (1 out of 3)
T1 CC6 output onto OpAmp interface
(internal signal)
Sec.
Def.
Sec.
Def.
Sec.
Op Amp configuration
OPAMP calibration
538
538
At startup, trimmed offset values are initialized with the preset factory trimming value
The user can switch from the factory values to the user trimmed values using the
USER_TRIM bit in the OPAMP control register.
Quiz
539
539
This lab illustrates the use of the OPAMP to amplify the DAC
output.
F3 Alpha Training
02/04/2012
541
OPAMP_InitStructure.OPAMP_NonInvertingInput = -----------;
OPAMP_InitStructure.OPAMP_InvertingInput = -----------------;
OPAMP_PGAConfig (-------------, ---------, OPAMP_PGAConnect_No) ;
OPAMP_Cmd(------------------------, ENABLE);
F3 Alpha Training
02/04/2012
542
Presentation Title
02/04/2012
543
Main properties:
3 - ADCs in all packages (19 single ended and 10 differential inputs max.)
16-bit resolution, ENOB = 14 bits (SNR = 89dB)
Low power modes:
Slow (speed reduced 4x): up to 600uA (instead of 1200uA in run mode)
Standby: up to 200uA, wakeup time 50us
Power down: up to 10uA, wake up time 100us
546
Software
Timer
External pin
Synchronization to first SDADC (SDADC1)
547
548
SDADC pins
Name
Signal type
Remarks
SDADCx_VDD
Input, analog
Supply
SDADCx_VSS
Input, analog
supply ground
SDADCx_AIN[8:0]P
Analog input
SDADCx_AIN[8:0]M
Analog input
SD_VREF+
Input or In/Out,
positive analog
Reference
SD_VREF-
Input, negative
analog
reference
549
Voltage range:
Full speed mode operation: 2.4V 3.6V
Slow mode operation: 2.2V 3.6V
External
Dedicated SDADC_VREF+ , SDADC_VREF- pins
Voltage range 1.1V SDADCx_VDD
550
SDADC clock
Clock management:
System clock divided by divider (from 2 to 48, 50% duty cycle)
Clock range:
max. 6MHz standard conversion clock
max. slow mode clock 1.5MHz reduced speed, reduced power, lower voltage operation
min. clock speed = 500kHz
551
552
553
Regular conversions
Channel selection is defined as channel number in register
Cannot run in scan mode
Triggers:
Software (writing 1 to the RSWSTART bit)
Synchronous with SDADC1
554
Standard mode:
Normal:
Multiplexing more channels
One conversion takes 360 cycles (16.6ksps @ 6MHz)
555
Request precedence
Priority order of SDADC operations:
1. Calibration sequence
2. Injected conversions
3. Regular conversions
But:
Conversion which is already in progress is never interrupted by the request for
another action (current conversion is finished first)
Request is ignored if a like action is already pending or in progress
No action can start before stabilization has finished (wakeup from power down or
standby mode)
556
SDADC calibration
General properties for sigma delta converters:
Perfect linearity (due to 1-bit converter and oversampling)
Resolution increases with decreasing data rate
But large offset and gain error (need calibration)
Offset calibration:
Principle:
Short internally both channel inputs (positive and negative)
Perform conversion and store result to configuration register(s)
During standard conversion subtract from result the calibrated value
Implementation in STM32F37x:
Set in configuration registers:
required gain (1/2 .. 32)
common mode for calibration (VSSA, VDDA, VDDA/2)
557
Deterministic timing
Application requirements:
Launching conversion in precise intervals (e.g. FFT sampling by timer trigger)
Problem: waiting for some ongoing (regular) conversion
Solution in SDADC:
Start of each injected conversion with delay during which cannot be started regular
conversion
When bit JDS = 1 (Injected Delay Start) the start of each injected conversion is
delayed:
by 500 cycles if PDI = 0 (power down when idle)
by 600 cycles if PDI = 1, SLOWCK = 0 (because wakeup from power down takes 600 cycles)
Injected
conversion
request
Regular conversion
Wait
500cycles
Injected conversion
558
Inputs impedances
Analog inputs impedance:
Depends from:
selected SDADC clock
analog gain (0.5 8)
conversion is in progress
559
Quiz
How many analog input channels are in one SDADC in the
STM32F37x ?
What is the calibration result ?
What is the conversion modes regarding low power conversions ?
Which voltages can be used as reference voltage for SDADC ?
What is the priority regarding conversions order ?
560
Comparators (COMP)
F37x COMP vs F30x COMP
562
2 comparators (7 in STM32F30x)
A single register manages both comparators (in STM32F30x: one regsiter per
comparator).
No mux on the non inverting input
No blanking feature
ADC 1 MSPS
ADC Features
Same like in STM32F1 family:
12-bit, 1Msps
Triggers, self-calibration
Up to 18 input analog channels
Analog watchdog, interrupts, DMA
Programmable sampling time, Vref+ input range
Injected, regular channels, alignment
Continuous, single, scan conversion modes
Temperature sensor, Vrefint measuring
Added feature:
VBAT measuring
Presentation Title
25/10/2012
564
HDMI-CEC
32kHz kernel running from LSE or HSI/244 with wakeup from STOP
Multiple logical addresses support + listen mode
Configurable error handling with selectable extended timing tolerance
Selectable signal free time (SFT) before transmission HW or SW
CEC line needs an external 27k pull up and optional isolation
Presentation Title
25/10/2012
566
Presentation Title
25/10/2012
567
HDMI-CEC Interrupts
An interrupt is triggered:
if a receive block transfer completes
if a transmit block transfer completes
in case of any receive or transmit error
in case of RX or TX buffer overrun or underrun
for transmission or reception end
in case of arbitration lost
Presentation Title
25/10/2012
568
RX tolerance margins
Start Bit
3.7ms
4.5ms
Data Bit
0.6ms
1.5ms
2.4ms
1.05ms
RxTol bit
0b: Standard tolerance (in line with CEC specification)
Start bit: 200 rise & fall. Data bit: 200 rise , 350 fall
569
Errors handling
CEC specifications says only:
It is the responsibility of all devices acting as followers to detect the existence of spurious
pulses on the control signal line and notify all other devices (primarily the initiator) that a
potential error has occurred.
An error is defined as a period between falling edges that is less than a minimum data bit
period (i.e. too short to be a valid bit).
Other timing errors are not considered in CEC specification user define the action
The error notification (error bit) is a low period on the CEC line of 1.4 to 1.6 times
the nominal data bit period, that is, 3.6 ms nominally:
High
Impedance
3.6 ms 0.24ms
Low
Impedance
25/10/2012
570
571
1.5ms
2.4ms
1.05ms
Rising
Edge
0.0
0.3
RxTol=0
BRE
RxTol=1
Falling
Edge
RxTol=0
RxTol=1
0.4
BRE
0.0
0.3
0.4
0.8
0.9
1.2
1.3
1.7
BRE
BRE
0.8
0.9
1.2
SBPE
SBPE
1.3
1.8
BRE
BRE
1.7
1.8
1.9
2.05
2.75
Ok
Ok
2.9
LBPE
LBPE
572
573
574
0x1: 1
0x2: 1.5
0x3: 2
0xF: 7.5
575
SFT
576
IDLE
SFT
TX
IDLE
TXSOM
TXSOM
TXEND/RXEND
TXEND
SFT
IDLE
TX
SFT
RXEND
TXEND
TXSOM
BUSY (RX/TX)
SFT
TX
TXSOM
TXSOM
RXEND
TXSOM
TXEND
TX
SFT
SFT
IDLE
TX
TX
F100 CEC
F37x CEC
APB clock
-with PRESC frequency divider
x
x
x
no need
x
x
Rx Tolerance Margin
- Standard
- Extended
x
x
x
x
Multi-address configuration
577
Quiz
Which errors are handled by HDMI-CEC ?
What are the possible clock sources in STM32F37x CEC ?
What are the new features in STM32F37x CEC comparing to the CEC
in STM32F100 devices ?
Presentation Title
25/10/2012
578
STM32F3 MC kit
Not included
Main Features
Driving Strategy: Vector Control
PMSM motor sensored and
sensorless
Two (34-pin) dedicated motor control
connectors
Encoder sensor input
Hall sensor input
Tachometer sensor input
Current sensing mode:
3 shunt resistors
Single shunt
2nd Motor
Key Component
STM32F3xx (32-bit MCU ARM M4 with motor
control dedicated IPs)
L6390D (Gate Drivers)
VIPer16LD (Power Supply down converter)
L7815ABV, L78M05CDT, LD1117S33TR (Voltage
regulators)
STGP10NC60KD (IGBT)
TS391ILT, (Comparator)
M74HC14TTR (Logic)
580
STM32F100x
STM8/128-EVAL
STM32F103
STM3210E-EVAL
STM32100B-EVAL
STEVAL-IHM033V1
MC connector
STEVAL-IHM022V1
581
STEVAL-IHM025V1
1KW
STEVAL-IHM027V1
STEVAL-IHM021V2
STEVAL-IHM028V1
STEVAL-IHM032V1
100W
STEVAL-IHM035V1
STEVAL-IHM023V2
582
2000W
Power stage up to
3 x dual PowerMOSFETs STS8dnh3l
2 x PWM smart driver L6387E
1x step down converter L4976D
STEVAL-IEM003V1
Power stage up to 48V
3 x PWM smart driver L6388
6x LV Power MOSFET STV250N55F3
1x step down converter L4978D
583
STEVAL-IFN003V1
100w
STEVAL-IFN004V1
STEVAL-IHM036V1
PMSM FOC Motor Drive
STEVAL-IHM030V1
DC Brushed Motor Drive
1 x 8bit-Microcontroller STM8S
2 x PWM smart driver L6388
4 x LV Power MOSFET STV250N55F3
584
Key features:
Single/Dual simultaneous vector control (FOC)
Any combination of current reading topologies and/or
speed/position sensors is supported
Wide range of STM32 microcontrollers families
supported
Full customization and real time communication
through PC software ST MC Workbench
Wide range of motor control algorithms implemented
for specific applications
Application example based on FreeRTOS
Increase code safety through
MISRA C rules 2004 compliancy
Strict ANSI C compliancy
New object oriented FW architecture (better
code encapsulation, abstraction and modularity)
585
168Mhz
Cortex - M3
120Mhz
72Mhz
72Mhz
48Mhz
Cortex M0
586
1shunt
Flux
Weakening
IPMSM MTPA
3shunt
Feed Forward
Sensor-less
(STO + PLL)
Sensor-less
(STO +
Cordic)
FreeRTOS
Encoder
Hall sensors
Debug &
Tuning
ST MC
Workbench
support
USART based
com protocol
add-on
Max FOC
F100 ~11kHz
F0xx T.B.D.
F103, F2xx
ICS
Max FOC
~25kHz
Max FOC
F103 ~25kHz
F2xx T.B.D.
F4xx T.B.D.
F3xx T.B.D.
587
MC Workbench
Motor
Power Stage
Drive
Management
Control Stage
588
Serial communication
RS232 (Available)
SPI (T.B.I.)
I2C (T.B.I.)
589
590
Flexible
design
Cortex-M0
Cortex-M4
Cortex-M3
8/16-bit applications
16/32-bit applications
32-bit/DSC applications
MCU
+
-10% CPU
Load*
* Expected
C code generation
Floating point numbers (float)
FPU
No FPU
No FPU
Direct mapping
No code modification
High performance
Optimal code efficiency
Usage of SW lib
No code modification
Low performance
Medium code efficiency
Usage of integer
based format
Code modification
Corner case behavior
to be checked
(saturation, scaling)
Medium/high
performance
Medium code efficiency
591
SRAM on Ibus
0 WS
Maximum speed execution
For critical routines (control loops)
8Kbytes
-20% CPU
Load*
* Expected
FOC
Algorithm
592
Three shunt
Single shunt
593
Advantage
Costs reduction
Reduced temperature drift (possible compensation)
Programmable amplifier (x2, x4, )
Offset
+Vdd
OP-AMP
+
-
ADC
RShunt
STM32F3xx
594
Advantage
Costs reduction
Smart shutdown or active brake
Offset
+Vdd
BUS Voltage
Over current
Over voltage
Comparator
+
-
RShunt
BRK2
Comparator
ADV
TIM
Int. reference
BRK
Int. reference
STM32F3xx
Bus voltage
divider
595
Advantage
Int. reference
+Vdd
OP-AMP
Comparator
+
+
RShunt
ETR
ADV
TIM
DAC
Int. reference
STM32F3xx
OCREFCLR
OCREFCLR
596
For each configuration of the switches, the current that is flowing in the shunt resistor can be one of
the motor phase current.
ADVANTAGES
Single shunt requires just one sensing network
(reduced number of external components).
ST Patented method to exploit full vector plane.
Single shunt
Three shunts
597
OC2
OC3
OC5ref
OC1ref
OC2ref
OC3ref
598
OC4
OC4ref
OC6ref
TRGO2
ADC Start
ADC Start
ADC Start
ADC Start
599
Concept
Using two/three shunts topologies is required the simultaneous sampling of two
analog quantities. This is actually implemented using two different ADC peripheral.
Dual simultaneous motor driving (2/3 shunt topologies) can be achieved using just
two ADC peripheral if the sampling of each motor current is done in different times
(ADC sharing).
The FOC algorithm of each motor can request the ADC conversions while the
previous one is not already performed.
To perform automatically (saving CPU load) this mechanism the ADC context FIFO
has been implemented.
600
FOC1
ADC context 1
ADC
FOC2
ADC context 2
Waiting
Triggering signals
601
602