STM8S - Flash - and - Control - System
STM8S - Flash - and - Control - System
Flash &
Control System May 2009
4
STM8S Memory main features (2/2)
5
STM8S Family memory mapping
• The program memory always RAM (up to 6K) 00 0000h
starts at address 00 8000h
– End is determined by the Stack (up to 1K)
memory size (02 7FFFh for
128K). 00 4000h
Data E2PROM (up to 2K)
– Interrupt vectors are located at
the beginning of this memory Option bytes 00 4800h
area. 00 5000h
– Programmable User Boot Code Peripheral registers
area includes the It vectors
(from 1K up to 128K). Boot Vector 00 6000h
• The RAM starts from 00 0000h Boot ROM (2K)
– Up to 1KBytes Stack is located
00 8000h
at the end of the available RAM. User reset and IT Vectors
• The Data EEPROM starts from UBC area
00 4000h. Program memory
– The option bytes are located (up to 128K)
after the available data EEP
6
Memory organization granularities
Program 128 bytes
Memory Matrix
128 bytes
Data 128 bytes
Memory
Block
32 words = 128 bytes or 16 words = 64 bytes
7
STM8S family memory ranges
• Low density
– From 8 Kbytes of Flash Program 128 pages of 64 bytes
– 640 bytes of Data EEPROM 10 pages of 64 bytes
• Medium density
– From 16 to 32 Kbytes of Flash Program 64 pages of 512 bytes
– 1 Kbytes of Data EEPROM 2 pages of 512 bytes
• High density
– From 32 to 128 Kbytes of Flash Program 256 pages of 512 bytes
– Up to 2 Kbytes of Data EEPROM 4 pages of 512 bytes
8
Memory Access Security System (MASS)
(Unlock mechanism)
• In order to prevent any unwanted write access to the Program memory, to the
Data EEPROM and to the Option bytes, the whole NVM memory is Write
protected by default after a device reset.
• The memory lock must be removed by software before any programming
operation loading in the right order 2 MASS keys in a given Flash register.
9
Memory dedicated option bytes:
Read-out protection
• There are two option bytes dedicated to memory protection: the
Read-out protection (ROP) and the UBC protection
10
Memory dedicated option bytes:
UBC protection
11
Memory programming methods
12
In Circuit Programming
– It uses only one I/O that can also be used as PD1 GPIO pin.
• By default the pin is in SWIM mode after reset
• Switch to PD1 is done by software with a bit in the Global Configuration
Register (CFG_GCR)
• It is generally good to use a jumper on the application board.
13
SWIM connection
Supply
STM8 VDD
NRST
1
2
3
4
PD1
SWIM VDD
GND
4 3 2 1
SWIM connector
Dedicated connector with only 4-pins : 1
2
14
ST Boot Loader
• The Boot Loader is stored into the internal 2 Kbytes Boot ROM memory.
• This program uses USART (set as a normal UART), CAN or LIN peripherals
(handled in polling mode) to download/update into Program memory, Data
EEPROM and Option byte area respectively the code (including vector
table), the data and the option bytes, thus using ST proprietary protocol.
• According to the content of the Reset Vector location (0x8000) the host can
decide to re-program or not the EEPROM by checking two option bytes, as
showed in the following table:
• In Application Programming
– In case of in application programming, there is an user boot sector
containing a boot program that will reprogram part of the
application itself.
– A new version of the firmware to be updated is received by the boot
program using any possible protocol, usually a serial
communication port (USART, SPI, I2C, CAN, LIN ….).
• The User Boot Code area feature answers to the IAP
needs:
– For the IAP to be safe, the boot sector must always be write
protected.
– In the event of a power failure, the boot program will be able to
restart the firmware update from the beginning.
– The boot sector contains the Reset vector which points into the boot
program on the reset routine.
– The boot program contains the update communication driver.
16
In Application Programming (2)
Area to be
Application updated
firmware
17
Byte programming
• Byte programming is done with a simple load instruction at the target
address.
• If the write instruction is run from Program memory to itself, the core is
stalled during the whole programming phase, otherwise if it is fetched from
RAM the program can do something else (but no access to the program
memory).
• The interrupt remain pending until the operation is not completed (core is
stalled on IT when code fetched from RAM).
• If the write instruction is run from Program memory to Data EEPROM the
Read While Write (RWW) capability allows to continue the program without
constraints.
– RWW is NOT available for low density memory
• Control flags can be used to check the end of programming status.
• The programming lasts 3ms if the “word” was empty (no erase phase
needed) or 6ms if not.
• To erase a location, simply write 00h.
Don’t forget to unprotect the memory with MASS keys
18
Word programming
• Word programming allows the user to program 4 bytes with only one
programming cycle which minimizes the programming time.
• The mechanism is similar to byte programming but the activation is
done with dedicated bit and consecutive loads of 4 bytes in given
word.
19
Block programming (1)
20
Block programming (2)
• For block programming (Standard or fast block programming), the 128 data
bytes have to be sequentially loaded. The actual programming phase starts
automatically when the last byte is latched. The initial address must be the
first block address.
• Attention! The data loading operation for block writing has to be
performed from the RAM even when addressing the Data EEPROM.
• In case of Program memory programming after programming finishing only the
soft can return executing in Program memory.
• In case of Data EEPROM programming the soft can return into Program
memory as soon as dedicated flag HVOFF gives the green light when
programming HV starts and thus to perform other tasks. It means that the
RWW capability is available during the actual programming phase after the
data loading.
• The RWW is NOT available for low density memory
21
Option byte programming
22
Memory Programming
Nber of Programming Programming Fast Programming
Core
Bytes from: to: Programming Time
(1) In case of low density memory the RWW is not available. The core is stalled during
programming from Program memory to Data EEP or Opt Bytes
23
References
24
Quiz
25
STM8S CLOCK CONTROLLER
26
Features
• 4 clock sources:
– HSE crystal: 1-24 MHz High Speed External crystal
– HSE user-ext: Up to 24 MHz High Speed user-external clock
– HSI RC: 16 MHz High Speed Internal RC oscillator
– LSI RC: 128 kHz Low Speed Internal RC
27
Block Diagram (1/2)
Reset configuration
CKM[7:0]
HSE Ext.
C PU DIV [2:0 ]
fH SE
OSC IN
HS E OSC
/1
1 -24 M H z to CAN, AWU
OSC OUT /2
EXTCLK OPT BIT
/4
fMA STER /8 f C PU
Master
Clock /16
CSS HS ID IV[1: 0] Switch /32
/64
/8 /12 8
H SI R C fH SI /4 fHSID IV
16 M Hz /2
to CPU and
/1 Window Watchdog
fLSI
LSI RC
12 8 kH z
to AWU to peripherals
28
Block Diagram (1/2)
Peripheral Clock
Enable
to AWU
fLSI to Timers
CCO SEL[3:0]
Peripheral Clock
CANDIV[2:0]
Enable
/1, /2 ../8 to CAN fH S I
fH S I D IV
fH S E
fL SI
fM A S TE R
CCO = PE0 or PD0 pin fC P U
fC P U / 2
PE0 default configuration fC P U / 4
fC P U / 8
PD0 selected by option bit fC P U / 16
fC P U / 32
fC P U / 64
29
Clock Sources
30
Master Clock Switching
31
CSS: Clock Security System
32
PCG: Peripheral clock gating
33
CCO: Configurable Clock Output
34
Quiz
35
STM8S AUTO WAKE-UP (AWU) and BEEPER
36
Features
• BEEPER function
– 1 kHz, 2 kHz or 4 kHz output signal frequencies
37
AWU Block Diagram
CKAWUSEL
PRESC[1:0] OPTION bit
OPTION bits
HSE clock
(4 - 24 MHz)
Prescaler MSR
~ 128 kHz LS clock to Timer Input Capture
LSI RC (for measurement)
128 kHz
APR[5:0]
6-BIT PROG
COUNTER
AWUTB[3:0]
15 time bases
AWU COUNTERS AWU Interrupt
38
AWU description
• AWU operation
1. LSI measurement if needed (see dedicated slide)
2. Find the AWUTB[3:0] and APR[5:0] according to targeted wake-up interval
(see dedicated slide)
3. AWUEN=1 to enable the AWU interrupt and LS clock source to the
counters (if LSI RC is selected it will start automatically)
4. HALT
• In Halt mode (after Halt instruction):
– the counters start to run when entering this mode
– the AWU interrupt wakes-up the CPU at the regular programmed intervals :
This is the Active Halt mode
39
Time base selection (1/3)
• The Time base selection is done with the determination of 2
parameters:
– APR[5:0], it gives the prescaler division factor APRDIV
– AWUTB[3:0], it gives the counter output rank
The chosen Time base depends on precise LSI frequency.
We propose to define first 15 non overlapped ranges of intervals
according to counter output rank.
– 0001 > 2/fLS – 64/fLS, APRDIV moving from 2 to 64
– 0010 > 2x32/fLS - 2x2x32/fLS, APRDIV moving from 32 to 64 (std)
– 0011 > 2x64/fLS - 2x2x64/fLS, APRDIV moving from 32 to 64 (std)
– …
– 1101 > 211x64/fLS - 211x128/fLS, APRDIV moving from 32 to 64 (std)
– 1110 > 211x130/fLS - 211x320/fLS, APRDIV moving from 26 to 64
– 1111 > 211x330/fLS - 212x960/fLS, APRDIV moving from 11 to 64
40
Time base selection (2/3)
42
Beeper Block Diagram
43
Beeper description
• Beeper operation
1. LSI measurement and calibration if needed (see
dedicated slide)
2. Define BEEPDIV[4:0] values to get right BEEPDIV
division factor
3. Choice of BEEPSEL to select respectively:
fLS/(8xBEEPDIV) , fLS/(4xBEEPDIV) and fLS/(2xBEEPDIV)
4. BEEPEN =1
44
LSI Calibration for Beeper
45
Calibration (2/2)
fLSI/8 = 14.375KHz
-> A = 14
-> A/(1+2*A) = 0.483
-> x = 0.375
-> x is less than A/(1+2*A) therefore:
BEEPDIV[4:0] = A-2 = 12 = 0Ch
47
STM8S POWER SUPPLY,
RESET AND VOLTAGE DETECTION
48
Power Supply Features
I/Os
VDDIO
Refer to HW getting started Application Note
49
Voltage Detectors
• 2 Voltage Detectors
– BOR to monitor main power supply
– Power On Reset with Power Down Capability
NRST
VDD/VDDIO
VDD
Vth+
Vth-
1V
50
Reset Circuit Block Diagram
EXTERNAL
RESET
FILTER
POR/BOR
20us PULSE IWDG/WWDG/SW
GENERATOR SWIM
ILLEGAL OPCODE
EMS
51
External Reset
52
Internal Reset sources (1/2)
• Power On Reset (POR):
– The POR is always active only during Power On (rising edge)
– Generate trigger to start LVD, then switched off
• BOR
– When voltage falls bellow level, generate trigger for POR
• SWIM reset
– A specific SWIM command generates a reset when sent.
53
Internal Reset sources (2/2)
• EMS reset
– The most critical registers of the product are implemented with
their complement in such way any mismatch in the opposite values
on EMS disturbances leads to a reset:
• Copy of option byte registers,
– UBC Protection registers for instance
• Clock Controller switch registers,
– Clock master register
– Switch register
54
STM8S versus ST7
• ST7 • STM8
– LVD – POR
+ Power-On Reset • Starts the system
+ Voltage Drop Reset
+ 3 thresholds – BOR
- Option byte switchable • Voltage Drop Reset
- When deactivated, no • Fixed Threshold
more POR • Active during RUN
– AVD
• Interrupt
• 3 thresholds
• Activated with LVD
• Option byte
55
Quiz
56
STM8S POWER MANAGEMENT
57
Generalities (1/2)
58
Generalities (2/2)
59
Power management features
60
Clock management
62
Low power modes
63
Low power modes (1/3)
• Wait mode
– The MCU enters this mode when Wait For Interrupt instruction is
executed.
– The clock speed slow-down changing the clock source and PCG use are
both means to reduce further the consumption.
– Therefore there are again different low power levels for this low power Wait
mode.
64
Low power modes (2/3)
• Active Halt modes
– The MCU enters this mode when Halt instruction is executed.
• And if AWU and IWD are activated before.
– All clocks are stopped; the CPU and all the peripherals are disable by definition.
• Except LSI or HSE divided
– By default the clock configuration defined before to enter in this mode remains
unchanged.
65
Low power modes (3/3)
• Halt mode
– The MCU enters this mode when Halt instruction is executed.
• And if IWD and AWU are not activated
– All clocks are stopped; the CPU and all the peripherals are disabled
by definition; Main Regulator is switched off
66
Additional power controls (1/3)
67
Additional power controls (2/3)
68
Additional power controls (3/3)
69
Quiz
70
Window Watchdog (WWDG)
71
WWDG features
• Window Watchdog can be activated by Option byte
WWDG
WWDG_WR
or by software (setting WDGA) Reset
- W W W W W W W
• Configurable time-window, can be programmed to comparator 6 5 4 3 2 1 0
= 1 when
detect abnormally early or late application behavior T6:0 > W6:0
CM
P
• Conditional reset Write WWDG_CR
• To prevent WWDG reset: write T[6:0] bits at regular T[6:0] CNT down counter
Reset
72
Independent Watchdog (IWDG)
73
IWDG features
74
Quiz
• How the WWDG reset is refreshed ?
– By writing in WWDG_CR
75
Reference
76
CONFIDENTIALITY OBLIGATIONS:
IT IS CLASSIFIED “MICROCONTROLLERS, MEMORIES & SECURE MCUs (MMS) RESTRICTED AND ITS DISTRIBUTION IS SUBMITTED TO ST/MMS
AUTHORIZATION
AT ALL TIMES YOU SHOULD COMPLY WITH THE FOLLOWING SECURITY RULES:
- DO NOT COPY OR REPRODUCE ALL OR PART OF THIS DOCUMENT
- KEEP THIS DOCUMENT LOCKED AWAY
- FURTHER COPIES CAN BE PROVIDED ON A “NEED TO KNOW BASIS”, PLEASE CONTACT YOUR LOCAL ST SALES OFFICE OR
DOCUMENT WRITTER.
Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of
such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or
otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject to change without notice.
This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical
components in life support devices or systems without express written approval of STMicroelectronics.
The ST logo is registered trademark of STMicroelectronics
All other names are the property of their respective owners
© 2015 STMicroelectronics - All Rights Reserved
STMicroelectronics group of companies Australia - Brazil - Canada - China - Finland - France - Germany - Hong Kong -
India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States.
www.st.com