rm0490 stm32c0x1 Advanced Armbased 32bit Mcus Stmicroelectronics
rm0490 stm32c0x1 Advanced Armbased 32bit Mcus Stmicroelectronics
Reference manual
STM32C0x1 advanced Arm®-based 32-bit MCUs
Introduction
This reference manual complements the datasheets of the STM32C0x1 microcontrollers,
providing information required for application and in particular for software development. It
pertains to the superset of feature sets available on STM32C0x1 microcontrollers.
For feature set, ordering information, and mechanical and electrical characteristics of a
particular STM32C0x1 device, refer to its corresponding datasheet.
For information on the Arm® Cortex®-M0+ core, refer to the Cortex®-M0+ technical
reference manual.
Related documents
• “Cortex®-M0+ Technical Reference Manual”, available from: http://infocenter.arm.com
• PM0223 programming manual for Cortex®-M0+ core(a)
• STM32C0x1 datasheets(a)
• AN2606 application note on booting STM32 MCUs(a)
Contents
1 Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.2 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.3 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
1.4 Availability of peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
12.5.8 EXTI CPU wakeup with event mask register (EXTI_EMR1) . . . . . . . . 228
12.5.9 EXTI register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
List of tables
List of figures
Figure 101. PWM output state following BRK assertion (OSSI=0) . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
Figure 102. Output redirection (BRK2 request not represented) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Figure 103. Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Figure 104. 6-step generation, COM example (OSSR=1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Figure 105. Example of one pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Figure 106. Retriggerable one pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Figure 107. Example of counter operation in encoder interface mode. . . . . . . . . . . . . . . . . . . . . . . . . 347
Figure 108. Example of encoder interface mode with TI1FP1 polarity inverted. . . . . . . . . . . . . . . . . . 348
Figure 109. Measuring time interval between edges on 3 signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Figure 110. Example of Hall sensor interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Figure 111. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Figure 112. Control circuit in Gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Figure 113. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Figure 114. Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Figure 115. General-purpose timer block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Figure 116. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 399
Figure 117. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 399
Figure 118. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
Figure 119. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Figure 120. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Figure 121. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
Figure 122. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not preloaded). . . . . 402
Figure 123. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR preloaded). . . . . . . . 403
Figure 124. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Figure 125. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Figure 126. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Figure 127. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Figure 128. Counter timing diagram, Update event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Figure 129. Counter timing diagram, internal clock divided by 1, TIMx_ARR=0x6 . . . . . . . . . . . . . . . 407
Figure 130. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
Figure 131. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 408
Figure 132. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409
Figure 133. Counter timing diagram, Update event with ARPE=1 (counter underflow). . . . . . . . . . . . 409
Figure 134. Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 410
Figure 135. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 411
Figure 136. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Figure 137. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Figure 138. External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Figure 139. Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Figure 140. Capture/Compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . 414
Figure 141. Capture/Compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Figure 142. Output stage of Capture/Compare channel (channel 1) . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Figure 143. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Figure 144. Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Figure 145. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Figure 146. Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
Figure 147. Generation of 2 phase-shifted PWM signals with 50% duty cycle . . . . . . . . . . . . . . . . . . 423
Figure 148. Combined PWM mode on channels 1 and 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Figure 149. Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
Figure 150. Example of one-pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
Figure 151. Retriggerable one-pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Figure 152. Example of counter operation in encoder interface mode . . . . . . . . . . . . . . . . . . . . . . . . 429
Figure 153. Example of encoder interface mode with TI1FP1 polarity inverted . . . . . . . . . . . . . . . . . 430
Figure 154. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Figure 155. Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
Figure 156. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Figure 157. Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Figure 158. Master/Slave timer example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Figure 159. Master/slave connection example with 1 channel only timers . . . . . . . . . . . . . . . . . . . . . 435
Figure 160. Gating TIMz with OC1REF of TIMy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Figure 161. Gating TIMz with Enable of TIMy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Figure 162. Triggering TIMz with update of TIMy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Figure 163. Triggering TIMz with Enable of TIMy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Figure 164. Triggering TIMy and TIMz with TIMy TI1 input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Figure 165. General-purpose timer block diagram (TIM14) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
Figure 166. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 470
Figure 167. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 470
Figure 168. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Figure 169. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Figure 170. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Figure 171. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
Figure 172. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
Figure 173. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
Figure 174. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 475
Figure 175. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 475
Figure 176. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Figure 177. Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Figure 178. Output compare mode, toggle on OC1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Figure 179. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480
Figure 180. TIM16/TIM17 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
Figure 181. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 496
Figure 182. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 496
Figure 183. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Figure 184. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Figure 185. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Figure 186. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Figure 187. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Figure 188. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Figure 189. Update rate examples depending on mode and TIMx_RCR register settings . . . . . . . . . 502
Figure 190. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 503
Figure 191. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Figure 192. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Figure 193. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 505
Figure 194. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Figure 195. Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 506
Figure 196. Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
Figure 197. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
Figure 198. Complementary output with dead-time insertion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
Figure 199. Dead-time waveforms with delay greater than the negative pulse. . . . . . . . . . . . . . . . . . 512
Figure 200. Dead-time waveforms with delay greater than the positive pulse. . . . . . . . . . . . . . . . . . . 512
1 Documentation conventions
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
b. This is an exhaustive list of all abbreviations applicable to STMicroelectronics microcontrollers, some of
them may not be used in the current document.
1.3 Glossary
This section gives a brief definition of acronyms and abbreviations used in this document:
• Word: data of 32-bit length.
• Half-word: data of 16-bit length.
• Byte: data of 8-bit length.
• SWD-DP (SWD DEBUG PORT): SWD-DP provides a 2-pin (clock and data) interface
based on the Serial Wire Debug (SWD) protocol. Please refer to the Cortex®-M0+
technical reference manual.
• IAP (in-application programming): IAP is the ability to re-program the flash memory
of a microcontroller while the user program is running.
• ICP (in-circuit programming): ICP is the ability to program the flash memory of a
microcontroller using the SWD protocol or the bootloader while the device is mounted
on the user application board.
• Option bytes: product configuration bits stored in the flash memory.
• OBL: option byte loader.
• AHB: advanced high-performance bus.
• APB: advanced peripheral bus.
IOPORT
SRAM
Arm®
Cortex®-M0+ System bus Bus matrix
core AHB-to-APB
AHB bridge APB
DMA1/DMAMUX
DMA bus
channels 1..3
SYSCFG,
ADC,
TIM1, TIM3
TIM14, TIM16, TIM17,
CRC IWDG, WWDG,
RTC, PWR,
RCC I2C1
EXTI USART1, USART2,
SPI1/I2S,
DMA requests DBGMCU
DMA bus
This bus connects the AHB master interface of the DMA to the bus matrix that manages the
access of CPU and DMA to SRAM, Flash memory and AHB/APB peripherals.
Bus matrix
The bus matrix arbitrates the access between the core system bus and the DMA master
bus. The arbitration uses a Round Robin algorithm. The bus matrix is composed of masters
(CPU, DMA) and slaves (Flash memory interface, SRAM and AHB-to-APB bridge).
AHB peripherals are connected to the system bus through the bus matrix to allow DMA
access.
2.2.1 Introduction
Program memory, data memory, registers and I/O ports are organized within the same linear
4-Gbyte address space.
The bytes are coded in memory in Little Endian format. The lowest numbered byte in a word
is considered the word’s least significant byte and the highest numbered byte the most
significant.
Reserved space
0xFFFF FFFF
block 7
Arm Cortex M0+
0xE000 0000 internal peripherals
0 x 5 F F F F FFF
block 6 IOPORT 0x5000 0000
0xC000 0000
0x4FFF FFFF
block 5
AHB
0xA000 0000
0x4002 0000
0x4001 FFFF
block 4
APB
0x8000 0000
0x4000 0000
block 3
0x6000 0000
0x1FFF 787F
Option bytes
0x1FFF 7800
Engineering bytes
block 2 0x1FFF 7500
0x1FFF 74FF
Peripherals OTP
0x4000 0000 0x1FFF 7000
System memory
block 1
0x1FFF 0000
RAM
0x2000 0000
0x0800 7FFF
block 0 Code
Main Flash memory
0x0800 0000
0x0000 0000
Cortex®-M0+ internal
- 0xE000 0000 - 0xE00F FFFF 1MB -
peripherals
0x5000 1800 - 0x5FFF 17FF ~256 MB Reserved -
0x5000 1400 - 0x5000 17FF 1 KB GPIOF Section 6.4.12 on page 160
0x5000 1000 - 0x5000 13FF 1 KB Reserved -
IOPORT 0x5000 0C00 - 0x5000 0FFF 1 KB GPIOD Section 6.4.12 on page 160
0x5000 0800 - 0x5000 0BFF 1 KB GPIOC Section 6.4.12 on page 160
0x5000 0400 - 0x5000 07FF 1 KB GPIOB Section 6.4.12 on page 160
0x5000 0000 - 0x5000 03FF 1 KB GPIOA Section 6.4.12 on page 160
STM32C011xx 6
STM32C031xx 12
The SRAM can be accessed by bytes, half-words (16 bits) or full words (32 bits), at
maximum system clock frequency without wait state and thus by both CPU and DMA.
Parity check
The user can enable the parity check using the option bit RAM_PARITY_CHECK in the user
option byte (refer to Section 3.4: FLASH option bytes).
The data bus width is 36 bits because 4 bits are available for parity check (1 bit per byte) in
order to increase memory robustness, as required for instance by Class B or SIL norms.
The parity bits are computed and stored when writing into the SRAM. Then, they are
automatically checked when reading. If one bit fails, an NMI is generated.
Note: When enabling the SRAM parity check, it is advised to initialize by software the whole
SRAM at the beginning of the code, to avoid getting parity errors when reading non-
initialized locations.
0 0 x 1 0 Embedded SRAM
1 x x x x Main Flash memory
The boot mode configuration is latched on the 4th rising edge of SYSCLK after a reset. It is
up to the user to set boot mode configuration related to the required boot mode.
The boot mode configuration is also re-sampled when exiting from Standby mode.
Consequently they must be kept in the required Boot mode configuration in Standby mode.
After this startup delay has elapsed, the CPU fetches the top-of-stack value from address
0x0000 0000, then starts code execution from the address stored in the boot memory at
0x0000 0004.
Depending on the selected boot mode, main Flash memory, system memory or SRAM is
accessible as follows:
• Boot from main Flash memory: the main Flash memory is aliased in the boot memory
space (0x0000 0000), but still accessible from its original memory space
(0x0800 0000). In other words, the Flash memory contents can be accessed starting
from address 0x0000 0000 or 0x0800 0000.
• Boot from system memory: the system memory is aliased in the boot memory space
(0x0000 0000), but still accessible from its original memory space 0x1FFF0000.
• Boot from the embedded SRAM: the SRAM is aliased in the boot memory space
(0x0000 0000), but it is still accessible from its original memory space (0x2000 0000).
The BOOT_LOCK bit allows forcing a unique entry point in the Main Flash memory for boot,
regardless of the other boot mode configuration bits. See Section 3.5.6: Forcing boot from
flash memory.
Empty check
Internal empty check flag (the EMPTY bit of the FLASH access control register
(FLASH_ACR)) is implemented to allow easy programming of virgin devices by the boot
loader. This flag is used when BOOT0 pin is defining Main Flash memory as the target boot
area. When the flag is set, the device is considered as empty and System memory (boot
loader) is selected instead of the Main Flash as a boot area to allow user to program the
Flash memory.
This flag is updated only during Option bytes loading: it is set when the content of the
address 0x0800 0000 is read as 0xFFFF FFFF, otherwise it is cleared. It means a power
reset or setting of OBL_LAUNCH bit in FLASH_CR register is needed to clear this flag after
programming of a virgin device to execute user code after System reset. The EMPTY bit
can also directly be written by software.
Note: If the device is programmed for a first time but the Option bytes are not reloaded, the device
still selects System memory as a boot area after a System reset.
Physical remap
Once the boot mode is selected, the application software can modify the memory accessible
in the code area. This modification is performed by programming the MEM_MODE bits in
the SYSCFG configuration register 1 (SYSCFG_CFGR1).
through one of the following interfaces: USART1 and I2C1. On the manufacturing
line, the devices are programmed and protected against spurious write/erase
operations. For further details, refer to the AN2606 available from www.st.com.
– 1 Kbyte (128 double words) OTP (one-time programmable) for user data. The
OTP data cannot be erased and can be written only once. If only one bit is at 0,
the entire double word (64 bits) cannot be written anymore, even with the value
0x0000 0000 0000 0000.
The OTP area cannot be read when RDP level is 1 and boot source is not the
Main flash memory area.
– Option bytes for user configuration.
The following table shows the mapping of the flash memory into Information block and Main
memory area.
2K (only first
0x1FFF 7800 - 0x1FFF 7FFF 128 bytes Option bytes
used)
Information
block 0x1FFF 7400 - 0x1FFF 77FF 1K Engineering bytes
0x1FFF 7000 - 0x1FFF 73FF 1K OTP area
0x1FFF 0000 - 0x1FFF 17FF 6K System memory
0x0800 7800 - 0x0800 7FFF 2K Page 15
... ... ...
Main
0x0800 1000 - 0x0800 17FF 2K Page 2
memory
0x0800 0800 - 0x0800 0FFF 2K Page 1
0x0800 0000 - 0x0800 07FF 2K Page 0
Upon power-on reset or upon wakeup from Standby, the HCLK clock frequency is
automatically set to 12 MHz and the LATENCY[2:0] bitfield to 000. See Section 5.2: Clocks.
To change HCLK frequency, respect the following sequence:
When the code is not sequential (branch), the instruction may not be present in the currently
used instruction line or in the prefetched instruction line. In this case (miss), the penalty in
terms of number of cycles is at least equal to the number of wait states.
If a loop is present in the current buffer, no new access is performed.
Cache memory
To limit the time lost due to jumps, it is possible to retain two cache lines of 64 bits (16 bytes)
in the instruction cache memory. This feature can be enabled by setting the instruction
cache enable (ICEN) bit of the FLASH access control register (FLASH_ACR). Each time a
miss occurs (requested data not present in the currently used instruction line, in the
prefetched instruction line or in the instruction cache memory), the line read is copied into
the instruction cache memory. If some data contained in the instruction cache memory are
requested by the CPU, they are provided without inserting any delay. Once all the
instruction cache memory lines are filled, the LRU (least recently used) policy is used to
determine the line to replace in the instruction memory cache. This feature is particularly
useful in case of code containing loops.
The Instruction cache memory is enabled after system reset.
No data cache is available on Cortex®-M0+.
The FLASH_CR registers can be locked again by software by setting the LOCK bit in one of
these registers.
Note: The FLASH_CR register cannot be written when the BSY1 bit of the FLASH status register
(FLASH_SR) is set. Any attempt to write to this register with the BSY1 bit set causes the
AHB bus to stall until the BSY1 bit is cleared.
No No Page is erased No
No Yes
0 x Page erase aborted No
Yes No Yes
(no page erase started)
Yes Yes
1 x Protected pages only No Yes
No No Memory is erased No
No Yes
0 x No
Yes No Erase aborted (no erase started) Yes
Yes Yes
1 x Erase aborted (no erase started) No Yes
Standard programming
The flash memory programming sequence in standard mode is as follows:
1. Check that no Main flash memory operation is ongoing by checking the BSY1 bit of the
FLASH status register (FLASH_SR)..
2. Check and clear all error programming flags due to a previous programming. If not,
PGSERR is set.
3. Set the PG bit of the FLASH control register (FLASH_CR).
4. Perform the data write operation at the desired memory address, inside Main memory
block or OTP area. Only double word (64 bits) can be programmed.
a) Write a first word in an address aligned with double word
b) Write the second word.
5. Wait until the BSY1 bit of the FLASH status register (FLASH_SR) is cleared.
6. Check that the EOP flag in the FLASH status register (FLASH_SR) is set
(programming operation succeeded), and clear it by software.
7. Clear the PG bit of the FLASH control register (FLASH_CR) if there no more
programming request anymore.
Note: When the flash memory interface has received a good sequence (a double word),
programming is automatically launched and the BSY1 bit set.
The HSI48 internal oscillator (with a divide by three to provide 16 MHz) is automatically
enabled when the PG bit is set. It is automatically disabled when the PG bit is cleared,
except if previously enabled with the HSION bit of the RCC_CR register.
Fast programming
The main purpose of this mode is to reduce the page programming time. It is achieved by
eliminating the need for verifying the flash memory locations before they are programmed,
thus saving the time of high voltage ramping and falling for each double word.
This mode allows programming a row (32 double words = 256 bytes).
During fast programming, the flash memory clock (HCLK) frequency must be at least
8 MHz.
Only the Main memory can be programmed in Fast programming mode.
The Main flash memory programming sequence in standard mode is described below:
1. Perform a mass or page erase. If not, PGSERR is set.
2. Check that no Main flash memory operation is ongoing by checking the BSY1 bit of the
FLASH status register (FLASH_SR)..
3. Check and clear all error programming flag due to a previous programming.
4. Set the FSTPG bit in FLASH control register (FLASH_CR).
5. Write 16 double-words to program a row (128 bytes).
6. Wait until the BSY1 bit of the FLASH status register (FLASH_SR) is cleared.
7. Check that the EOP flag in the FLASH status register (FLASH_SR) is set
(programming operation succeeded), and clear it by software.
8. Clear the FSTPG bit of the FLASH status register (FLASH_SR) if there are no more
programming requests anymore.
Note: When attempting to write in Fast programming mode while a read operation is ongoing, the
programming is aborted without any system notification (no error flag is set).
When the flash memory interface has received the first double word, programming is
automatically launched. The BSY1 bit is set when the high voltage is applied for the first
double word, and it is cleared when the last double word has been programmed or in case
of error.
The HSI48 internal oscillator (with a divide by three to provide 16 MHz) is automatically
enabled when the FSTPG bit is set. It is automatically disabled when the FSTPG bit is
cleared, except if previously enabled with the HSION bit of the RCC_CR register.
The 16 double words must be written successively. The high voltage is kept on the flash
memory for all the programming. Maximum time between two double words write requests
is the time programming (around 20 µs). If a second double word arrives after this time
programming, fast programming is interrupted and MISSERR is set.
High voltage must not exceed 8 ms for a full row between two erases. This is guaranteed by
the sequence of 16 double words successively written with a clock system greater or equal
to 8 MHz. An internal time-out counter counts 7 ms when Fast programming is set and stops
the programming when time-out is over. In this case the FASTERR bit is set.
If an error occurs, high voltage is stopped and next double word to programmed is not
programmed. Anyway, all previous double words have been properly programmed.
Programming errors
Several kind of errors can be detected. In case of error, the flash memory operation
(programming or erasing) is aborted.
• PROGERR: Programming error
In standard programming: PROGERR is set if the word to write is not previously erased
(except if the value to program is full zero and the target address is in the Main
memory).
• SIZERR: Size programming error
In standard programming or in fast programming: only double word can be
programmed, and only 32-bit data can be written. SIZERR is set if a byte or an
half-word is written.
• PGAERR: Alignment programming error
PGAERR is set if one of the following conditions occurs:
– In standard programming: the first word to be programmed is not aligned with a
double word address, or the second word doesn’t belong to the same double word
address.
– In fast programming: the data to program doesn’t belong to the same row than the
previous programmed double words, or the address to program is not greater than
the previous one.
• PGSERR: Programming sequence error
PGSERR is set if one of the following conditions occurs:
– In the standard programming sequence or the fast programming sequence: a data
is written when PG and FSTPG are cleared.
– In the standard programming sequence or the fast programming sequence: MER1
and PER are not cleared when PG or FSTPG is set.
– In the fast programming sequence: the Mass erase is not performed before setting
the FSTPG bit.
– In the mass erase sequence: PG, FSTPG, and PER are not cleared when MER1 is
set.
– In the page erase sequence: PG, FSTPG and MER1 are not cleared when PER is
set.
Table 10 shows the organization of the option bytes (the lower word only) in the flash
memory information block. The software can read the option bytes from these flash memory
locations or from their corresponding option registers referenced in the table. Refer to
sections 3.7.6 to 3.7.13 for the description of the option register bitfields, also applicable to
the option byte bitfields.
10
11
9
8
7
6
5
4
3
2
1
0
Address(1) option register
(section) Option byte 3 Option byte 2 Option byte 1 Option byte 0
HSE_NOT_REMAPPED(2)
SECURE_MUXING_EN
RAM_PARITY_CHECK
NRST_MODE[1:0]
nRST_STDBY
nRST_SHDW
IWDG_STOP
IWDG_STBY
nBOOT_SEL
nRST_STOP
WWDG_SW
BORR_LEV
BORF_LEV
IWDG_SW
Reserved
Reserved
BOR_EN
nBOOT0
nBOOT1
IRHEN
FLASH_OPTR
RDP
0x1FFF7800 (3.7.6)
Factory value X X 1 1 1 1 1 1 1 1 1 X 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0
FLASH_PCROP1ASR PCROP1A
Reserved
0x1FFF7808 (3.7.7) _STRT
Factory value X X X X X X X X X X X X X X X X X X X X X X X X X X 1 1 1 1 1 1
PCROP_RDP
FLASH_PCROP1AER PCROP1A
Reserved
0x1FFF7810 (3.7.8) _END
Factory value 0 X X X X X X X X X X X X X X X X X X X X X X X X X 0 0 0 0 0 0
FLASH_WRP1AR WRP1A WRP1A
Reserved Reserved
0x1FFF7818 (3.7.9) _END _STRT
Factory value X X X X X X X X X X X X 0 0 0 0 X X X X X X X X X X X X 1 1 1 1
FLASH_WRP1BR WRP1B WRP1B
Reserved Reserved
0x1FFF7820 (3.7.10) _END _STRT
Factory value X X X X X X X X X X X X 0 0 0 0 X X X X X X X X X X X X 1 1 1 1
FLASH_PCROP1BSR PCROP1B
0x1FFF7828 Reserved
(3.7.11) _STRT
Factory value X X X X X X X X X X X X X X X X X X X X X X X X X X 1 1 1 1 1 1
FLASH_ PCROP1BER PCROP1B
Reserved
0x1FFF7830 (3.7.12) _END
Factory value X X X X X X X X X X X X X X X X X X X X X X X X X X 0 0 0 0 0 0
BOOT_LOCK
FLASH_SECR
Reserved Reserved SEC_SIZE
0x1FFF7870 (3.7.13)
Factory value X X X X X X X X X X X X X X X 0 X X X X X X X X X X X 0 0 0 0 0
1. The upper 32 bits of the double-word address contain the inverted data from the lower 32 bits.
2. Only relevant to 48-pin packages that are only available for STM32C031xx.
Note: If the read protection is set while the debugger is still connected through SWD, apply power
reset instead of system reset.
There are three levels of read protection from no protection (Level 0) to maximum protection
or no debug (Level 2).
The flash memory is protected when the RDP option byte and its complement contain the
pair of values shown in Table 11.
The System memory area is read-accessible whatever the protection level. It is never
accessible for program/erase operation.
Level 0: no protection
Read, program and erase operations within the Main flash memory area are possible. The
option bytes are also accessible by all operations.
Level 2: No debug
In this level, the protection Level 1 is guaranteed. In addition, the CPU debug port, the boot
from RAM (boot RAM mode) and the boot from System memory (boot loader mode) are no
more available. In user execution mode (boot FLASH mode), all operations are allowed on
the Main flash memory.
Note: The CPU debug port is also disabled under reset.
Note: STMicroelectronics is not able to perform analysis on defective parts on which the Level 2
protection has been set.
Table 12: Mass erase upon RDP regression from Level 1 to Level 0
PCROP
PCROP_RDP Mass erase
area
None x
Full
Part of 1
flash Partial
memory (flash memory pages not overlapping with PCROP area)
0
Full flash
None
memory
Note: Mass erase (full or partial) is only triggered by the RDP regression from Level 1 to Level 0.
RDP level increase (Level 0 to Level 1, 1 to 2, or 0 to 2) does not cause any mass erase.
To validate the protection level change, the option bytes must be reloaded by setting the
OBL_LAUNCH bit of the FLASH control register (FLASH_CR).
Level 1
5'30xAA 0xCC
RDP = 0xAA
RDP = 0xCC 5'3[&&[$$
Level 2 Level 0
RDP = 0xCC RDP = 0xAA
RDP = 0xCC
MSv33468V3
Table 13. Access status versus protection level and execution modes
Debug/ BootFromRam/
Protection User execution (BootFromFlash)
Area BootFromLoader
level
Read Write Erase Read Write Erase
when the RDP protection is changed from Level 1 to Level 0 (refer to Changing the read
protection level).
Each PCROP area is defined by a start subpage offset and an end subpage offset into the
flash memory. These offsets are defined with the corresponding bitfields of the PCROP
address registers FLASH PCROP area A start address register (FLASH_PCROP1ASR),
FLASH PCROP area A end address register (FLASH_PCROP1AER), FLASH PCROP area
B start address register (FLASH_PCROP1BSR), and FLASH PCROP area B end address
register (FLASH_PCROP1BER).
A PCROP area x (A or B) is defined from the address:
flash memory base address + [PCROP1x_STRT x 0x200] (included)
to the address:
flash memory base address + [(PCROP1x_END + 1) x 0x200] (excluded).
The minimum PCROP area size is two PCROP subpages (2 x 512 bytes):
PCROP1x_END = PCROP1x_STRT + 1.
When
PCROP1x_END = PCROP1x_STRT,
the full flash memory is PCROP-protected.
For example, to PCROP-protect the address area from 0x0800 0800 to 0x0800 13FF, set
the PCROP start subpage bitfield of the FLASH_PCROP1xSR register and the PCROP end
subpage bitfield of the FLASH_PCROP1xER register (x = A or B) as follows:
– PCROP1x_STRT = 0x04 (PCROP area start address 0x0800 0800)
– PCROP1x_END = 0x09 (PCROP area end address 0x0800 13FF)
Data read access to a PCROP-protected address raises the RDERR flag.
PCROP-protected addresses are also write protected. Write access to a PCROP-protected
address raises the WRPERR flag.
PCROP-protected areas are also erase protected. Attempts to erase a page including at
least one PCROP-protected subpage fails. Moreover, software mass erase cannot be
performed if a PCROP-protected area is defined.
Deactivation of PCROP can only occur upon the RDP change from Level 1 to Level 0.
Modification of user options to clear PCROP or to decrease the size of a PCROP-protected
area do not have any effect to the PCROP areas. On the contrary, it is possible to increase
the size of the PCROP-protected areas.
With the option bit PCROP_RDP cleared, the change of RDP from Level 1 to Level 0
triggers a partial mass erase that preserves the contents of the flash memory pages
overlapping with PCROP-protected areas. Refer to section Changing the read protection
level for details.
Note: With PCROP_RDP cleared, it is recommended to either define the PCROP area start and
end onto flash memory page boundaries (2-Kbyte granularity), or to keep reserved and
empty the PCROP-unprotected memory space of the PCROP area boundary pages (pages
inside which the PCROP area starts and ends).
Note: When the flash memory read protection level is selected (RDP level = 1), it is not possible to
program or erase the memory if the CPU debug features are connected (single wire) or boot
code is being executed from SRAM or system flash memory, even if WRP is not activated.
Any attempt generates a hard fault (BusFault).
Note: To validate the WRP options, the option bytes must be reloaded by setting the
OBL_LAUNCH bit in flash memory control register.
SEC_PROT = 0 SEC_PROT = 1
Securable memory not secured Securable memory secured
Option
Execution of code Execution of code
byte
loading within securable memory outside securable memory
timeline
Power up DBG_SWEN = 0 DBG_SWEN = 1 SEC_PROT = 1
Software management
MSv42192V1
Data miss during fast programming error MISSERR Write MISSERR=1 N/A
Fast programming error FASTERR Write FASTERR=1 N/A
1. EOP is set only if EOPIE is set.
2. OPERR is set only if ERRIE is set.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBG
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EMPTY
_SWEN
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. ICRST Res. ICEN PRFTEN Res. Res. Res. Res. Res. LATENCY[2:0]
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
KEY[31:16]
w w w w w w w w w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
KEY[15:0]
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OPTKEY[31:16]
w w w w w w w w w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OPTKEY[15:0]
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CFGBSY Res. BSY1
r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OPTV RD FAST MISS PGS SIZ PGA WRP PROG OP
Res. Res. Res. Res. Res. EOP
ERR ERR ERR ERR ERR ERR ERR ERR ERR ERR
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OPT SEC_ OBL_ RD OPT
LOCK Res. ERRIE EOPIE Res. Res. Res. Res. Res. FSTPG STRT
LOCK PROT LAUNCH ERRIE STRT
rs rs rw rc_w1 rw rw rw rw rs rs
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. PNB[3:0] MER1 PER PG
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SECUR HSE_N
RAM_P IWGD
NRST_MODE n n nBOOT E_MUX OT_RE WWDG IWDG IWDG
Res. Res. IRHEN ARITY_ Res. _
[1:0] BOOT0 BOOT1 _SEL ING_E MAPPE _SW _STOP _SW
CHECK STDBY
N D
rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
nRST_ nRST_ nRST_ BOR_
BORF_LEV[1:0] BORR_LEV[1:0] RDP[7:0]
SHDW STDBY STOP EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PCROP1A_STRT[5:0]
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PCROP_RDP Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rs
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PCROP1A_END[5:0]
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WRP1A_END[3:0]
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WRP1A_STRT[3:0]
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WRP1B_END[3:0]
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WRP1B_STRT[3:0]
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PCROP1B_STRT[5:0]
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PCROP1B_END[5:0]
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BOOT_LOCK
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SEC_SIZE[4:0]
rw rw rw rw rw
0x038
0x034
0x030
0x028
0x024
0x020
0x014
0x010
0x008
0x000
0x07F
0x02C
0x00C
Offset
0x03C -
3.7.14
RM0490
KEYR
FLASH_
FLASH_
FLASH_
FLASH_
FLASH_
FLASH_
Reserved
Reserved
Reserved
WRP1BR
WRP1AR
Register
FLASH_SR
FLASH_CR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
FLASH_OPT
FLASH_ACR
PCROP1BER
PCROP1BSR
PCROP1AER
PCROP1ASR
FLASH_KEYR
FLASH_OPTR
1
0
0
X
Res. Res. Res. Res. Res. PCROP_RDP. Res. Res. Res. LOCK Res. Res. Res. 31
1
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. OPTLOCK Res. Res. Res. 30
0
0
X
Res. Res. Res. Res. Res. Res. Res. IRHEN Res. Res. Res. Res. Res. 29
0
0
0
X
Res. Res. Res. Res. Res. Res. Res. Res. SEC_PROT Res. Res. Res. 28
NRST_MODE[1:0]
0
0
0
X
Res. Res. Res. Res. Res. Res. Res. Res. OBL_LAUNCH Res. Res. Res. 27
0
0
0
X
Res. Res. Res. Res. Res. Res. Res. .nBOOT0 Res. RDERRIE Res. Res. Res. 26
0
0
0
X
Res. Res. Res. Res. Res. Res. Res. nBOOT1 Res. ERRIE Res. Res. Res. 25
FLASH register map
0
0
0
X
Res. Res. Res. Res. Res. Res. Res. nBOOT_SEL Res. EOPIE Res. Res. Res. 24
0
0
X
Res. Res. Res. Res. Res. Res. SECURE_MUXING_EN Res. Res. Res. Res. Res. 23
0
0
X
Res. Res. Res. Res. Res. Res. Res. RAM_PARITY_CHECK Res. Res. Res. 0 Res. Res. 22
0
X
Res. Res. Res. Res. Res. Res. Res. HSE_NOT_REMAPPED Res. Res. Res. Res. Res. 21
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
0
0
X
X
X
Res. Res. Res. Res. Res. WWDG_SW Res. Res. Res. Res. Res. 19
0
0
0
0
1
X
X
X
Res. Res. Res. Res. Res. IWDG_STBY Res. FSTPG CFGBSY Res. DBG_SWEN 18
[3:0]
[3:0]
0
0
0
X
X
X
RM0490 Rev 3
Res. Res. Res. Res. Res. IWDG_STOP Res. OPTSTRT Res. Res. Res. 17
0
0
0
X
X
X
X
Res. Res. Res. Res. Res. IWDG_SW Res. STRT BSY1 Res. EMPTY
WRP1B_END
WRP1A_END
16
0
0
X
X
Res. Res. Res. Res. Res. Res. Res. nRST_SHDW Res. Res. OPTVERR Res. Res. 15
KEYR[31:0]
0
0
X
Res. Res. Res. Res. Res. Res. Res. nRST_STDBY Res. Res. RDERR Res. Res. 14
OPTKEY[31:0]
0
0
X
Res. Res. Res. Res. Res. Res. Res. nRST_STOP Res. Res. Res. Res. Res. 13
0
0
X
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 12
BORF_LEV[1:0]
0
0
0
X
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ICRST 11
Table 18. FLASH register map and reset values
0
0
X
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 10
BORR_LEV[1:0]
0
0
0
1
X
Res. Res. Res. Res. Res. Res. Res. Res. Res. FASTERR Res. ICEN 9
0
0
0
0
X
Res. Res. Res. Res. Res. Res. Res. BOR_EN Res. Res. MISERR Res. PRFTEN 8
0
0
X
Res. Res. Res. Res. Res. Res. Res. Res. Res. PGSERR Res. Res. 7
0
0
0
0
X
Res. Res. Res. Res. Res. Res. Res. Res. SIZERR Res. Res. 6
0
0
0
0
X
X
X
X
X
Res. Res. Res. Res. PGAERR Res. Res. 5
0
0
0
0
X
X
X
X
X
Res. Res. Res. Res. WRPERR Res. Res. 4
PNB[3:0]
0
0
0
0
X
X
X
X
X
X
X
Res. Res. PROGERR Res. Res. 3
RDP[7:0]
[5:0]
[5:0]
0
0
0
0
X
X
X
X
X
X
X
0
0
0
X
X
X
X
X
X
X
WRP1B
WRP1A
[2:0]
PCROP1B_STRT
PCROP1A_STRT
_STRT[3:0]
_STRT[3:0]
0
0
0
0
0
X
X
X
X
X
X
X
PCROP1B_END[5:0]
PCROP1A_END[5:0]
Res. Res. PG EOP Res. 0
LATENCY
Embedded flash memory (FLASH)
79/825
80
Embedded flash memory (FLASH) RM0490
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
BOOT_LOCK
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FLASH_SECR SEC_SIZE[4:0]
0x080
Reset value X X X X X X
VDDA domain
VREF+(1)
VREF+
VDDA A/D converter
VSSA
(1) Internally connected
to VDDA on packages
VDDIO1
without VREF+ pin I/O ring VDDIO1 domain
Flash memory
RTC domain
RTC
The regulator is enabled upon reset and remains enabled as long as the device operates in
Run, Sleep, or Stop mode.
In Standby and Shutdown modes, the regulator is disabled and the VCORE domain is not
powered. As a consequence, the SRAM and register contents are lost.
VDD
VBORR4
VBORF4
VBORR3
VBORF3
VBORR2
VBORF2
VBORR1
VBORF1
VPOR
VPDR
t
tRSTTEMPO(1)
1. The reset temporization tRSTTEMPO starts when VDD crosses VPOR threshold, indifferently from the
configuration of the BOR Option bits.
For more details on the brown-out reset thresholds, refer to the electrical characteristics
section in the datasheet.
Shutdown mode
Sleep mode
The following table gives an overview of the device resources available in each operating
mode and their capability to wake the device up from a low-power mode to Run mode. Refer
to the table footnotes for complementary information.
CPU Y - - - - - - -
Flash memory Y Y A(3) - - - - -
SRAM Y Y U - - - - -
(4)
VCORE supply Y Y Y - - - - -
BOR/POR/PDR O O U U U U -(5) -
NRST Y Y Y Y Y Y Y Y
DMA/DMAMUX O U - - - - - -
HSI48 Y U(6) -(6) - - - - -
HSE O U - - - - - -
LSI O U U - U - - -
LSE O U U - - - - -
CSS O U - - - - - -
CSS on LSE O U U O - - - -
RTC / Auto wakeup O U U O - - - -
USART1 O U(7) U(7) O(7) - - - -
(7)
USART2 O U - - - - - -
I2C1 O U(8) U(8) O(8) - - - -
SPI1/I2S1 O U - - - - - -
(9)
ADC O U - - - - - -
(9)
Temperature sensor O U - - - - - -
TIMx O U - - - - - -
IWDG O U U O U O - -
WWDG O U - - - - - -
SysTick timer O U - - - - - -
CRC O U - - - - - -
GPIOs O U U (10) (11) (10) (11)
O
Individual peripheral clocks O A(12) A(12) - - - - -
1. Y = (yes): resource enabled upon reset and upon wakeup from Stop, Standby, and Shutdown; O = (optional): resource
disabled by default, and possible to enable by software; U = (unchanged): resource kept in the same operating state as
before low-power mode entry; A = (automatic): resource can be set for automatic disable/power-down upon transiting to
low-power mode; - = resource not available / without wakeup capability (grayed-out columns)
2. The grayed-out column indicates the capability of the resource to wake the device up from a low-power mode.
3. Possibility of automatic power-down.
4. When not available (voltage regulator disabled), the SRAM and register contents are lost.
5. The supply voltage monitoring is disabled and the product behavior is not guaranteed in case of a power voltage drop.
6. When the HSI48 is off, peripherals with wakeup capability, such as I2C1, can wake the HSI48 oscillator up to allow
temporary operation to assess the device wakeup condition such as I²C address match, then stop HSI48 if the wakeup
condition is not met, or wake the device up if it is met. When the HSI48 is restarted by a peripheral with wake-up capability,
during the low-power mode it only delivers clock to that peripheral.
7. USART reception is functional in Sleep and Stop mode. It generates a wakeup interrupt on START, address match, or
received frame event. The peripheral has the capability to restart the HSI48 oscillator to assess the address match and
received frame event device wakeup conditions.
8. I²C address detection is functional in Sleep and Stop mode. It generates a wakeup interrupt on address match. The
peripheral has the capability to restart the HSI48 oscillator to assess the address match event device wakeup condition.
9. Keeps consuming idle current unless disabled prior to entering Stop mode.
10. I/Os can be configured to keep, in Standby and Shutdown mode, internal pull-up or pull-down, or to float. Refer to PUCRx
and PDCRx registers and the APC bit of the PWR_CR3 register. This configuration is kept when exiting Standby mode but
it is lost when exiting Shutdown mode.
11. WKUPx I/Os (up to five, depending on the package), with wakeup from Standby/Shutdown mode capability.
12. Through the RCC_AHBSMENR and RCC_APBSMENRx registers, the software can configure the individual peripheral
clocks to automatically disable upon entering Sleep and Stop modes.
For low-power modes other than Sleep, the low-power mode entry is delayed (as opposed
to aborted) until a potential ongoing Flash memory or APB access is terminated.
The selection of the low-power mode to enter is determined by the SLEEPDEEP and
LPMS[2:0] bitfields.
Refer to the following table (including the table footnotes) for details about low-power mode
entry conditions. All the conditions in a table row must be met for the corresponding low-
power mode entry to occur.
Event pending(3)
SLEEPONEXIT
Flash memory
WUFx bit set
SLEEPDEEP
APB access
LPMS[2:0]
pending(2)
Low-power Low-power mode
Interrupt
access
mode entry stimulus
WFI 0 - - Aa - - - -
Sleep WFE 0 - - - Aa - - -
Return from ISR 0 1 - Aa - - - -
WFI 1 - 000 Aa - - Ad Ad
Stop WFE 1 - 000 - Aa - Ad Ad
Return from ISR 1 1 000 Aa - - Ad Ad
WFI 1 - 011 Aa - Aa Ad Ad
Standby WFE 1 - 011 - Aa Aa Ad Ad
Return from ISR 1 1 011 Aa - Aa Ad Ad
WFI 1 - 1XX Aa - Aa Ad Ad
Shutdown WFE 1 - 1XX - Aa Aa Ad Ad
Return from ISR 1 1 1XX Aa - Aa Ad Ad
1. “-” = don’t care or not applicable. “X” = don’t care (bit value). “Aa” = Absent/none; abort the low-power
mode entry if present. “Ad” = Absent/none; delay the low-power mode entry as long as present.
2. Any EXTI line interrupt flag (in EXTI rising edge pending register 1 (EXTI_RPR1) and EXTI falling edge
pending register 1 (EXTI_FPR1)) or any peripheral wakeup interrupt flag is set.
3. Any enabled EXTI event. For the sleep mode, also any peripheral event with the associated interrupt
enabled in the peripheral.
EXTI interrupt(2)
SEVONPEND
EXTI event(3)
Mode
Low-power Wakeup
WUFx bit
Interrupt
entry
mode latency HSIDIV
stimulus Clock SBF(6)
[2:0](5)
WFI or - E - - R -
return from
ISR - E R - E -
0 E - - R -
0 E R - E - As before As before
Sleep None 0
entry entry
0 E - R - -
WFE
1 E - - R -
1 E R - - -
1 E - R - -
WFI or
return from - E R - E -
ISR
HSI48 /
0 E R - E - Flash As before
Stop HSISYS 0
memory entry
0 E - R - -
WFE startup(7)
1 E R - - -
1 E - R - -
Reset
Standby - - - - - - R HSISYS 010 1
phase
Reset
Shutdown - - - - - - R HSISYS 010 0
phase
1. “-” = don’t care or not applicable, “E” = enabled, “R” = enabled and raised.
2. Any EXTI line set as unmasked in EXTI CPU wakeup with interrupt mask register (EXTI_IMR1).
3. Any EXTI line set as unmasked in EXTI CPU wakeup with event mask register (EXTI_EMR1)
4. Any IRQ interrupt listed in Table 40: Vector table and activated in the NVIC_ISER register (refer to the product
programming manual).
5. Bitfield of RCC clock control register (RCC_CR), controlling the HSISYS prescale. The value HSIDIV[2:0] = 010
corresponds to division by four.
6. Flag in PWR status register 1 (PWR_SR1).
7. The longer of HSI48 oscillator startup time and Flash memory startup time (from Stop mode).
Note: For any NVIC IRQ interrupt, EXTI interrupt or EXTI event, the table assumes that the
mechanism is activated through the NVIC ISER, EXTI_IMR1, or EXTI_EMR1 register,
respectively. For any interrupt or event, it also has to be activated in the peripheral.
Some peripherals send their interrupt request signal to both NVIC and EXTI and can
generate both NVIC IRQ and EXTI interrupts if configured to do so. Some other peripherals
only send their interrupt signal to NVIC and they can therefore only generate an NVIC
interrupt. The latter type of peripheral cannot wake the system up from Stop mode.
Upon waking up from Sleep and Stop modes, the pending bits associated to the
interrupt/event having woken up the system must be cleared. It may also be necessary to
clear the interrupt flag in the peripheral.
Upon waking up from Standby and Shutdown mode, the program execution restarts in the
same way as upon a reset (boot pin sampling, option bytes loading, reset vector is fetched,
and so on).
Auto-wakeup from Stop mode
The RTC can wake the device up from Stop mode at regular intervals, without any external
stimulus. For this purpose, select LSI or LSE as RTC clock source, through the
RTCSEL[1:0] bitfield of the RCC control/status register 1 (RCC_CSR1).
The LSI oscillator does not require an external quartz and reduces the system cost, at
expense of accuracy. The LSE oscillator with an external quartz ensures higher accuracy
but it leads to an extra cost.
To enable the wakeup from Stop mode with RTC alarm:
• Configure the EXTI Line 19 to be sensitive to rising edge.
• Configure the RTC to generate wakeup event.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FPD_ FPD_
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. LPMS[2:0]
SLP STOP
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EWUP EWUP EWUP EWUP EWUP
EIWUL Res. Res. Res. Res. APC Res. Res. Res. Res. Res.
6 4 3 2 1
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WP6 Res. WP4 WP3 WP2 WP1
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WUFI Res. Res. Res. Res. Res. Res. SBF Res. Res. WUF6 Res. WUF4 WUF3 WUF2 WUF1
r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FLASH
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
_RDY
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CWUF CWUF CWUF CWUF CWUF
Res. Res. Res. Res. Res. Res. Res. CSBF Res. Res. Res.
6 4 3 2 1
w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PU15 PU14 PU13 PU12 PU11 PU10 PU9 PU8 PU7 PU6 PU5 PU4 PU3 PU2 PU1 PU0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PD15 PD14 PD13 PD12 PD11 PD10 PD9 PD8 PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PU15 PU14 PU13 PU12 PU11 PU10 PU9 PU8 PU7 PU6 PU5 PU4 PU3 PU2 PU1 PU0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PD15 PD14 PD13 PD12 PD11 PD10 PD9 PD8 PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PU15 PU14 PU13 Res. Res. Res. Res. Res. PU7 PU6 Res. Res. Res. Res. Res. Res.
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PD15 PD14 PD13 Res. Res. Res. Res. Res. PD7 PD6 Res. Res. Res. Res. Res. Res.
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PU3 PU2 PU1 PU0
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PD3 PD2 PD1 PD0
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PU2 PU1 PU0
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PD2 PD1 PD0
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BKP[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
FPD_STOP
FPD_SLP
LPMS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PWR_CR1
0x000 [2:0]
Reset value 0 1 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EIWUL Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EWUP6 Res.
Res.
EWUP4 Res.
EWUP3 Res.
EWUP2 Res.
EWUP1 Res.
0x004 Reserved
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
APC
PWR_CR3
0x008
Reset value 1 0 0 0 0 0 0
WP6
WP4
WP3
WP2
WP1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PWR_CR4
0x00C
Reset value 0 0 0 0 0
WUF6
WUF4
WUF3
WUF2
WUF1
WUFI
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SBF
PWR_SR1
0x010
Reset value 0 0 0 0 0 0 0
FLASH_RDY
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PWR_SR2
0x014
Reset value 0
06C
0x078
0x074
0x070
0x048
0x038
0x034
0x030
0x028
0x024
0x020
0x018
0x07C
0x04C
0x03C
0x02C
0x050-
0x040-
Offset
102/825
Reserved
Reserved
PWR_SCR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
PWR_BKP3R
PWR_BKP2R
PWR_BKP1R
PWR_BKP0R
PWR_PDCRF
PWR_PUCRF
PWR_PDCRB
PWR_PUCRB
PWR_PDCRA
PWR_PUCRA
PWR_PDCRD
PWR_PUCRD
PWR_PDCRC
PWR_PUCRC
Power control (PWR)
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0490 Rev 3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. PD15 PU15 PD15 PU15 PD15 PU15 Res. 15
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. PD14 PU14 PD14 PU14 PD14 PU14 Res. 14
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. PD13 PU13 PD13 PU13 PD13 PU13 Res. 13
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. PD12 PU12 PD12 PU12 Res. 12
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. PD11 PU11 PD11 PU11 Res. 11
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. PD10 PU10 PD10 PU10 Res. 10
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. PD9 PU9 PD9 PU9 Res. 9
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. PD8 PU8 PD8 PU8 CSBF 8
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. PD7 PU7 PD7 PU7 PD7 PU7 Res. 7
BKP[15:0]
BKP[15:0]
BKP[15:0]
BKP[15:0]
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. PD6 PU6 PD6 PU6 PD6 PU6 Res. 6
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. PD5 PU5 PD5 PU5 CWUF6 5
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. PD4 PU4 PD4 PU4 Res. 4
0
0
0
0
0
0
0
Res. Res. Res. Res. PD3 PU3 Res. Res. PD3 PU3 PD3 PU3 CWUF4 3
0
0
0
0
0
0
0
0
0
Res. PD2 PU2 Res. PD2 PU2 Res. Res. PD2 PU2 PD2 PU2 CWUF3 2
0
0
0
0
0
0
0
0
0
Res. PD1 PU1 Res. PD1 PU1 Res. Res. PD1 PU1 PD1 PU1 CWUF2 1
0
0
0
0
0
0
0
0
0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Res. PD0 PU0 Res. PD0 PU0 Res. Res. PD0 PU0 PD0 PU0 CWUF1 0
RM0490
RM0490 Reset and clock control (RCC)
5.1 Reset
There are three types of reset, defined as system reset, power reset and RTC domain reset.
threshold. This function allows the detection of internal reset sources by external
components when the line faces a significant capacitive load.
• Reset input
In this mode, any valid reset signal on the NRST pin is propagated to device internal
logic, but resets generated internally by the device are not visible on the pin. In this
configuration, GPIO functionality (PF2) is not available.
• GPIO
In this mode, the pin can be used as PF2 standard GPIO. The reset function of the pin
is not available. Reset is only possible from device internal reset sources and it is not
propagated to the pin.
VDD
RPU
System reset
External
reset Filter
NRST
Internal
Pulse
reset sources
generator
(min 20 ȝs)
Bidirectional
reset
Reset holder D Q
CLEAR
MSv47935V1
Caution: Upon power reset or wakeup from shutdown mode, the NRST pin is configured as Reset
input/output and driven low by the system until it is reconfigured to the expected mode when
the option bytes are loaded, in the fourth clock cycle after the end of tRSTTEMPO time (see
datasheet).
Software reset
The SYSRESETREQ bit in Cortex®-M0+ Application interrupt and reset control register
must be set to force a software reset on the device (refer to the programming manual
PM0223).
5.2 Clocks
The device provides the following clock sources producing primary clocks:
• HSI48 RC - a high-speed fully-integrated RC oscillator producing HSI48 clock
(48 MHz)
• HSE OSC - a high-speed oscillator with external crystal/ceramic resonator or external
clock source, producing HSE clock (4 to 48 MHz)
• LSI RC - a low-speed fully-integrated RC oscillator producing LSI clock (about 32 kHz)
• LSE OSC - a low-speed oscillator with external crystal/ceramic resonator or external
clock source, producing LSE clock (accurate 32.768 kHz or external clock up to
1 MHz)
• I2S_CKIN - pin for direct clock input for I2S1 peripheral
Each oscillator can be switched on or off independently when it is not used, to optimize
power consumption. Check sub-sections of this section for more functional details. For
electrical characteristics of the internal and external clock sources, refer to the device
datasheet.
The device produces secondary clocks by dividing the primary clocks:
• HSISYS - a clock derived from HSI48 through division by a factor programmable from 1
to 128
• SYSCLK - a clock obtained through selecting one of LSE, LSI, HSE and HSISYS
clocks
• HSIKER - a clock derived from HSI48 through division by a factor programmable from
1 to 8
• HCLK - a clock derived from SYSCLK through division by a factor programmable from
1 to 512
• HCLK8 - a clock derived from HCLK through division by eight
• PCLK - a clock derived from HCLK through division by a factor programmable from 1 to
16
• TIMPCLK - a clock derived from PCLK, running at PCLK frequency if the APB
prescaler division factor is set to 1, or at twice the PCLK frequency otherwise
More secondary clocks are generated by fixed division of HSE, HSI48 and HCLK clocks.
The HSISYS is used as system clock source after startup from reset, with the division by
four (producing 12 MHz frequency).
The HCLK clock and PCLK clock are used for clocking the AHB and the APB domains,
respectively. Their maximum allowed frequency is 48 MHz.
The peripherals are clocked with the clocks from the bus they are attached to (HCLK for
AHB, PCLK for APB) except:
• TIMx
– TIMPCLK running at PCLK frequency if the APB prescaler division factor is set to
1, or at twice the PCLK frequency otherwise
• USART1, with these clock sources to select from:
– SYSCLK (system clock)
– HSIKER
– LSE
– PCLK (APB clock)
The wakeup from Stop mode is supported only when the clock is HSI48 or LSE.
• ADC, with these clock sources to select from:
– SYSCLK (system clock)
– HSIKER
to TIM1/3/
(1) 14/16/17
LSE x1, x2
LSI TIMPCLK
OSC_OUT HSE OSC SYSCLK
4-48 MHz HSE HSE
OSC_IN PCLK
Clock HSISYS LSE
detector to USART1
HSIKER
SYSCLK
HSI48 PCLK
HSIKER to I2C1
HSI48 RC /1,2,4,…,128
48 MHz HSISYS SYSCLK
SYSCLK
HSIKER to I2S1
I2S_CKIN I2S_CKIN
1. TIMPCLK runs at PCLK frequency if the APB prescaler division factor is set to 1, or at twice the PCLK frequency otherwise
OSC_IN OSC_OUT
External clock
GPIO
(OSC_EN as AF)
External
source
OSC_IN OSC_OUT
Crystal/Ceramic
resonators
CL1 CL2
Load
capacitors
Note: For details on pin availability, refer to the pinout section in the corresponding device
datasheet.
To minimize the consumption, it is recommended to use the square signal.
Calibration
RC oscillator frequencies can vary from one chip to another due to manufacturing process
variations. To compensate for this variation, each device is factory calibrated to 1 %
accuracy at TA=25°C.
After reset, the factory calibration value is loaded in the HSICAL[7:0] bits in the RCC internal
clock source calibration register (RCC_ICSCR).
Voltage or temperature variations in the application may affect the HSI48 frequency of the
RC oscillator. It can be trimmed using the HSITRIM[6:0] bits in the RCC internal clock
source calibration register (RCC_ICSCR).
For more details on how to measure the HSI48 frequency variation, refer to Section 5.2.13:
Internal/external clock measurement with TIM14/TIM16/TIM17.
The HSIRDY flag in the RCC clock control register (RCC_CR) indicates if the HSI48 RC is
stable or not. At startup, the HSI48 RC output clock is not released until this bit is set by
hardware.
The HSI48 RC can be switched on and off using the HSION bit in the RCC clock control
register (RCC_CR).
The HSI48 signal can also be used as a backup source (auxiliary clock) if the HSE crystal
oscillator fails. Refer to Section 5.2.6: Clock security system (CSS) on page 111.
The LSERDY flag in the RCC control/status register 1 (RCC_CSR1) indicates whether the
LSE crystal is stable or not. At startup, the LSE crystal output clock signal is not released
until this bit is set by hardware. An interrupt can be generated if enabled in the RCC clock
interrupt enable register (RCC_CIER).
The CSSI is linked to the Cortex®-M0+ NMI (non-maskable interrupt) exception vector. It
makes the software aware of a HSE clock failure to allow it to perform rescue operations.
Note: If the CSS is enabled and the HSE clock fails, the CSSI occurs and an NMI is automatically
generated. The NMI is executed infinitely unless the CSS interrupt pending bit is cleared. It
is therefore necessary that the NMI ISR clears the CSSI by setting the CSSC bit in the RCC
clock interrupt clear register (RCC_CICR).
If HSE is selected directly or indirectly as system clock, and a failure of HSE clock is
detected, the system clock switches automatically to HSISYS and the HSE oscillator is
disabled.
configured so as to get a PCLK frequency greater then or equal to the RTCCLK frequency
for a proper operation of the RTC.
RTC does not operate if the VDD supply is powered off or if the internal voltage regulator is
powered off (removing power from the VCORE domain).
When the RTC clock is LSE or LSI, the RTC remains clocked and functional under system
reset.
LSCO
The LSCO pin allows outputting on of low-speed clocks:
• LSI
• LSE
The selection is controlled by the LSCOSEL bit and enabled with the LSCOEN bit of the
RCC control/status register 1 (RCC_CSR1). The configuration registers of the
corresponding GPIO port must be programmed in alternate function mode.
This function remains available in Stop mode.
TIM14
By setting the TI1SEL[3:0] field of the TIM14_TISEL register, the clock selected for the input
capture channel1 of TIM14 can be one of:
• GPIO (refer to the alternate function mapping in the device datasheets)
• RTC clock (RTCCLK)
• HSE clock divided by 32
• MCO (MCU clock output)
• MCO2 (MCU clock output)
MCO and MCO2 are controlled by the MCOSEL[2:0] and MCO2SEL[2:0] bitfields,
respectively, of the clock configuration register (RCC_CFGR). All clock sources can be
selected for the MCO and MCO2 pins.
TIM 14
TI1SEL[3:0]
GPIO
RTCCLK
TI1
HSE / 32
MCO
MCO2
TIM16
By setting the TI1SEL[3:0] field of the TIM16_TISEL register, the clock selected for the input
capture channel1 of TIM16 can be one of:
• GPIO (refer to the alternate function mapping in the device datasheets).
• LSI clock
• LSE clock
• MCO2
MCO2 is controlled by the MCO2SEL[2:0] bitfield of the clock configuration register
(RCC_CFGR). All clock sources can be selected for the MCO2 pin.
TIM 16
TI1SEL[3:0]
GPIO
LSI
TI1
LSE
MCO2
TIM17
By setting the TI1SEL[3:0] field of the TIM17_TISEL register, the clock selected for the input
capture channel1 of TIM17 can be one of:
• GPIO Refer to the alternate function mapping in the device datasheets.
• HSE clock divided by 32
• MCO (MCU clock output)
• MCO2 (MCU clock output)
MCO and MCO2 are controlled by the MCOSEL[2:0] and MCO2SEL[2:0] bitfields,
respectively, of the clock configuration register (RCC_CFGR). All clock sources can be
selected for the MCO and MCO2 pins.
TIM 17
TI1SEL[3:0]
GPIO
HSE / 32 TI1
MCO
MCO2
The basic concept consists in providing a relative measurement (for example, the
HSISYS/LSE ratio): the measurement accuracy is therefore closely related to the ratio
between the two clock sources. Increasing the ratio allows improving the measurement
accuracy.
Generated by the HSE oscillator, the HSE clock (divided by 32) used as time reference is
the second best method for reaching a good HSI48 frequency measurement accuracy. It is
recommended in absence of the LSE clock.
In order to further improve the precision of the HSI48 oscillator calibration, it is advised to
employ one or a combination of the following measures to increase the frequency
measurement accuracy:
• set the HSISYS divider to 1 for HSISYS frequency to be equal to HSI48 frequency
• average the results of multiple consecutive measurements
• use the input capture prescaler of the timer (one capture every up to eight periods)
active when the device enters Stop mode (these peripherals do not have the capability
to turn on the LSE oscillator).
• Standby and Shutdown modes stop all clocks in the VCORE domain and disable the
HSI48, and HSE oscillators.
The CPU deepsleep mode can be overridden for debugging, by setting the DBG_STOP or
DBG_STANDBY bits in the DBGMCU_CR register.
When leaving the Stop mode, HSISYS becomes automatically the system clock.
When leaving the Standby and Shutdown modes, HSISYS (with frequency equal to
HSI48/4) becomes automatically the system clock. At wakeup from Standby and Shutdown
mode, the user trim is lost.
If a Flash memory programming operation is ongoing, Stop, Standby, and Shutdown entry is
delayed until the Flash memory interface access is finished. If an access to the APB domain
is ongoing, the Stop, Standby, and Shutdown entry is delayed until the APB access is
finished.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CSS HSE HSE HSE
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
ON BYP RDY ON
rs rw r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HSI HSI
Res. Res. HSIDIV[2:0] HSION HSIKERDIV[2:0] Res. Res. Res. Res. Res.
RDY KERON
rw rw rw r rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. HSITRIM[6:0] HSICAL[7:0]
rw rw rw rw rw rw rw r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. MCOPRE[2:0] Res. MCOSEL[2:0] Res. MCO2PRE[2:0] Res. MCO2SEL[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. PPRE[2:0] HPRE[3:0] Res. Res. SWS[2:0] SW[2:0]
rw rw rw rw rw rw rw r r r rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HSE HSI LSE LSI
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RDYIE RDYIE RDYIE RDYIE
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LSE HSE HSI LSE LSI
Res. Res. Res. Res. Res. Res. CSSF Res. Res. Res. Res.
CSSF RDYF RDYF RDYF RDYF
r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LSE HSE HSI LSE LSI
Res. Res. Res. Res. Res. Res. CSSC Res. Res. Res. Res.
CSSC RDYC RDYC RDYC RDYC
w w w w w w
RCC
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GPIOF GPIOD GPIOC GPIOB GPIOA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST RST RST RST RST
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRC FLASH DMA1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST RST RST
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PWR DBG I2C1 USART2
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST RST RST RST
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIM3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADC TIM17 TIM16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST RST RST
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYS
TIM14 USART1 SPI1 TIM1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CFG
RST RST RST RST
RST
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GPIOF GPIOD GPIOC GPIOB GPIOA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
EN EN EN EN EN
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRC FLASH DMA1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
EN EN EN
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PWR DBG I2C1 USART2
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
EN EN EN EN
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC
WWDG TIM3
Res. Res. Res. Res. APB Res. Res. Res. Res. Res. Res. Res. Res. Res.
EN EN
EN
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADC TIM17 TIM16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
EN EN EN
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYS
TIM14 USART1 SPI1 TIM1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CFG
EN EN EN EN
EN
rw rw rw rw rw
5.4.15 RCC I/O port in Sleep mode clock enable register (RCC_IOPSMENR)
Address offset: 0x44
Reset value: 0x0000 002F
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GPIOF GPIOD GPIOC GPIOB GPIOA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
SMEN SMEN SMEN SMEN SMEN
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRC SRAM FLASH DMA1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
SMEN SMEN SMEN SMEN
rw rw rw rw
This register can individually program which APB peripheral clocks are disabled (bit cleared)
upon the device entering Sleep or Stop mode. When a bit of this register is set (enable), the
corresponding peripheral clock is supplied in Sleep or Stop mode according to the setting of
the RCC_APBENR1 register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PWR DBG I2C1 USART2
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
SMEN SMEN SMEN SMEN
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC
WWDG TIM3
Res. Res. Res. Res. APB Res. Res. Res. Res. Res. Res. Res. Res. Res.
SMEN SMEN
SMEN
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADC TIM17 TIM16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
SMEN SMEN SMEN
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYS
TIM14 USART1 SPI1 TIM1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CFG
SMEN SMEN SMEN SMEN
SMEN
rw rw rw rw rw
Bit 14 USART1SMEN: USART1 clock enable during Sleep and Stop modes
Set and cleared by software.
0: Disable
1: Enable
Bit 13 Reserved, must be kept at reset value.
Bit 12 SPI1SMEN: SPI1 clock enable during Sleep mode
Set and cleared by software.
0: Disable
1: Enable
Bit 11 TIM1SMEN: TIM1 timer clock enable during Sleep mode
Set and cleared by software.
0: Disable
1: Enable
Bits 10:1 Reserved, must be kept at reset value.
Bit 0 SYSCFGSMEN: SYSCFG clock enable during Sleep and Stop modes
Set and cleared by software.
0: Disable
1: Enable
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADCSEL[1:0] Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART1SEL
I2S1SEL[1:0] I2C1SEL[1:0] Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
[1:0]
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LSCO LSCO RTCRS
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
SEL EN T
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC LSE LSE LSE LSE LSE
Res. Res. Res. Res. Res. RTCSEL[1:0] Res. Res. LSEON
EN CSSD CSSON DRV BYP RDY
rw rw rw r rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LPWR WWDG IWDG SFT PWR PIN OBL
Res. RMVF Res. Res. Res. Res. Res. Res. Res.
RSTF RSTF RSTF RSTF RSTF RSTF RSTF
r r r r r r r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LSI
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. LSION
RDY
r rw
0x18
0x14
0x10
0x08
0x04
0x00
0x1C
0x0C
142/825
5.4.22
Register
RCC_CR
Reserved
Reserved
Reserved
RCC_CIFR
RCC_CIER
Reset value
Reset value
Reset value
Reset value
Reset value
RCC_CFGR
RCC_ICSCR
Res. Res. Res. Res. Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. MCOPRE[3:0] Res. Res. 29
0
1: Ready
1: Enable
Res. Res. Res. Res. Res. Res. Res. 28
0: Disable
0: Not ready
Reset and clock control (RCC)
0
Res. Res. Res. Res. Res. Res. Res. 26
0
Res. Res. Res. Res. Res. MCOSEL[2:0] Res. Res. 25
0
Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. 23
Bit 0 LSION: LSI oscillator enable
Bit 1 LSIRDY: LSI oscillator ready
0
Res. Res. Res. Res. Res. Res. Res. 22
0
Res. Res. Res. Res. Res. MCO2PRE[3:0] Res. Res. 21
0
Res. Res. Res. Res. Res. Res. Res. 20
0
Bits 22:2 Reserved, must be kept at reset value.
0
0
Res. Res. Res. Res. Res. Res. HSEBYP 18
RM0490 Rev 3
0
0
MCO2SEL[2:0]
the Independent Watchdog or by the RTC.
0
0
Res. Res. Res. Res. Res. Res. HSEON 16
Res. Res. Res. Res. Res. Res. Res. Res. 15
0
1
Res. Res. Res. Res. Res. Res. 14
0
0
0
Res. Res. Res. Res. Res. PPRE[2:0] 13
0
0
0
Res. Res. Res. Res. Res. HSIDIV[2:0] 12
0
0
0
Res. Res. Res. Res. Res. 11
Table 23. RCC register map and reset values
0
0
1
Res. Res. Res. Res. Res. HSIRDY 10
Set and cleared by software to enable/disable the LSI oscillator:
HPRE[3:0]
HSITRIM[6:0]
0
0
0
LSECSSF Res. Res. Res. Res. HSIKERON 9
The following table gives the RCC register map and the reset values.
0
0
1
0
0
0
0
HSERDYF HSERDYIE Res. Res. Res. SWS[2:0] Res. 4
Set and cleared by hardware to indicate when the LSI oscillator is ready (stable):
0
0
HSIRDYF HSIRDYIE Res. Res. Res. Res. 3
0
HSICAL[7:0]
0
0
LSERDYF LSERDYIE Res. Res. Res. SW[2:0] Res. 1
After the LSION bit is cleared, LSIRDY goes low after 3 LSI oscillator clock cycles. This bit
0
0
X X X X X X X X
can be set even if LSION = 0 if the LSI is requested by the Clock Security System on LSE, by
RM0490
0x44
0x40
0x38
0x34
0x30
0x28
0x24
0x20
0x3C
0x2C
RM0490
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
IOPENR
Register
AHBENR
IOPRSTR
APBENR2
APBENR1
AHBRSTR
RCC_CICR
APBRSTR2
APBRSTR1
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
IOPSMENR
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
0
0
Res. Res. PWREN Res. Res. Res. PWRRST Res. Res. Res. 28
0
0
Res. Res. DBGEN Res. Res. Res. DBGRST Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
0
Res. Res. I2C1EN Res. Res. Res. I2C1RST Res. Res. Res. 21
0
0
Res. ADCEN Res. Res. Res. ADCRST Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
0
0
Res. TIM17EN Res. Res. Res. TIM17RST Res. Res. Res. Res. 18
RM0490 Rev 3
0
0
0
0
Res. TIM16EN USART2EN Res. Res. TIM16RST USART2RST Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
Res. TIM14EN Res. Res. Res. TIM14RST Res. Res. Res. Res. 15
0
0
Res. USART1EN Res. Res. Res. USART1RST Res. Res. Res. Res. 14
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 13
0
0
0
0
Res. SPI1EN Res. CRCEN Res. SPI1RST Res. CRCRST. Res. Res. 12
0
0
Res. TIM1EN Res. Res. Res. TIM1RST Res. Res. Res. Res. 11
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 10
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. LSECSSC 9
Table 23. RCC register map and reset values (continued)
1
0
0
Res. Res. Res. FLASHEN Res. Res. Res. FLASHRST. Res. CSSC 8
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 7
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 6
1
0
0
GPIOFSMEN Res. Res. Res. GPIOFEN Res. Res. Res. GPIOFRST Res. 5
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. HSERDYC 4
1
0
0
0
GPIODSMEN Res. Res. Res. GPIODEN Res. Res. Res. GPIODRST HSIRDYC 3
1
0
0
GPIOCSMEN Res. Res. Res. GPIOCEN Res. Res. Res. GPIOCRST Res. 2
1
0
0
0
0
0
GPIOBSMEN Res. TIM3EN Res. GPIOBEN Res. TIM3RST Res. GPIOBRST LSERDYC 1
1
0
0
0
0
0
0
0
Reset and clock control (RCC)
143/825
GPIOASMEN SYSCFGEN Res. DMA1EN GPIOAEN SYSCFGRST Res. DMA1RST GPIOARST LSIRDYC 0
144
set
Off-
0x60
0x58
0x54
0x48
0x5C
144/825
RCC_
RCC_
RCC_
Register
Reserved
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
RCC_CSR2
RCC_CSR1
AHBSMENR
RCC_CCIPR
0x50 APBSMENR2
0x4C APBSMENR1
0
0
LPWRRSTF Res. Res. Res. Res. Res. 31
ADCSEL[1:0]
0
0
WWDGRSTF Res. Res. Res. Res. Res. 30
0
IWDGRSTF Res. Res. Res. Res. Res. Res. 29
0
1
SFTRSTF Res. Res. Res. Res. PWRSMEN Res. 28
0
1
Reset and clock control (RCC)
0
PINRSTF Res. Res. Res. Res. Res. Res. 26
0
0
OBLRSTF LSCOSEL Res. Res. Res. Res. Res. 25
0
Res. LSCOEN Res. Res. Res. Res. Res. 24
0
RMVF Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. 22
1
1
Res. Res. Res. Res. ADCSMEN Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. 19
1
Res. Res. Res. Res. TIM17SMEN Res. Res. 18
RM0490 Rev 3
1
1
0
Res. RTCRST Res. Res. Res. Res. Res. 16
0
0
1
0
1
0
Res. Res. Res. Res. Res. Res. 13
I2C1SEL[1:0]
0
1
1
0
1
0
1
0
Res. LSECSSD Res. Res. Res. Res. Res. 6
0
Res. LSECSSON Res. Res. Res. Res. Res. 5
Res.
0
Res. Res. Res. Res. Res. Res. 4
Res. LSEDRV Res. Res. Res. Res. Res. 3
0
0
0
1
0
0
1
1
RM0490
6.1 Introduction
Each general-purpose I/O port has four 32-bit configuration registers (GPIOx_MODER,
GPIOx_OTYPER, GPIOx_OSPEEDR and GPIOx_PUPDR), two 32-bit data registers
(GPIOx_IDR and GPIOx_ODR) and a 32-bit set/reset register (GPIOx_BSRR). In addition
all GPIOs have a 32-bit locking register (GPIOx_LCKR) and two 32-bit alternate function
selection registers (GPIOx_AFRH and GPIOx_AFRL).
Figure 14 shows the basic structures of a standard I/O port bit. Table 24 gives the possible
port bit configurations.
To/from on-chip
peripherals, Analog input/output
power control
Digital input
and EXTI Input data register
On/off
Read
Bit set/reset registers
VDDIOx
TTL Schmitt trigger
on/off Pull
Write
Output data register
Input driver up
I/O pin
Output driver VDDIOx
on/off Pull
P-MOS down
Output
Read/write control
N-MOS VSS
MSv33182V2
0 0 0 GP output PP
0 0 1 GP output PP + PU
0 1 0 GP output PP + PD
0 SPEED 1 1 Reserved
01
1 [1:0] 0 0 GP output OD
1 0 1 GP output OD + PU
1 1 0 GP output OD + PD
1 1 1 Reserved (GP output OD)
0 0 0 AF PP
0 0 1 AF PP + PU
0 1 0 AF PP + PD
0 SPEED 1 1 Reserved
10
1 [1:0] 0 0 AF OD
1 0 1 AF OD + PU
1 1 0 AF OD + PD
1 1 1 Reserved
x x x 0 0 Input Floating
x x x 0 1 Input PU
00
x x x 1 0 Input PD
x x x 1 1 Reserved (input floating)
x x x 0 0 Input/output Analog
x x x 0 1
11
x x x 1 0 Reserved
x x x 1 1
1. GP = general-purpose, PP = push-pull, PU = pull-up, PD = pull-down, OD = open-drain, AF = alternate
function.
There is no need for the software to disable interrupts when programming the GPIOx_ODR
at bit level: it is possible to modify one or more bits in a single atomic AHB write access.
MSv33183V2
VSS Push-pull or
open-drain
MSv33184V3
Analog input/output
To/from on-chip
peripheral Alternate function input
VSS
From on-chip Alternate function output Push-pull
peripheral or open-drain
MSv31479V2
Off
Read
0
Bit set/reset registers
Write
Output data register
Input driver
I/O pin
Output driver
Read/write
MSv33185V2
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OT15 OT14 OT13 OT12 OT11 OT10 OT9 OT8 OT7 OT6 OT5 OT4 OT3 OT2 OT1 OT0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OSPEED15 OSPEED14 OSPEED13 OSPEED12 OSPEED11 OSPEED10 OSPEED9 OSPEED8
[1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OSPEED7 OSPEED6 OSPEED5 OSPEED4 OSPEED3 OSPEED2 OSPEED1 OSPEED0
[1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PUPD15[1:0] PUPD14[1:0] PUPD13[1:0] PUPD12[1:0] PUPD11[1:0] PUPD10[1:0] PUPD9[1:0] PUPD8[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PUPD7[1:0] PUPD6[1:0] PUPD5[1:0] PUPD4[1:0] PUPD3[1:0] PUPD2[1:0] PUPD1[1:0] PUPD0[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ID15 ID14 ID13 ID12 ID11 ID10 ID9 ID8 ID7 ID6 ID5 ID4 ID3 ID2 ID1 ID0
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OD15 OD14 OD13 OD12 OD11 OD10 OD9 OD8 OD7 OD6 OD5 OD4 OD3 OD2 OD1 OD0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BR15 BR14 BR13 BR12 BR11 BR10 BR9 BR8 BR7 BR6 BR5 BR4 BR3 BR2 BR1 BR0
w w w w w w w w w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BS15 BS14 BS13 BS12 BS11 BS10 BS9 BS8 BS7 BS6 BS5 BS4 BS3 BS2 BS1 BS0
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. LCKK
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LCK15 LCK14 LCK13 LCK12 LCK11 LCK10 LCK9 LCK8 LCK7 LCK6 LCK5 LCK4 LCK3 LCK2 LCK1 LCK0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AFSEL7[3:0] AFSEL6[3:0] AFSEL5[3:0] AFSEL4[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AFSEL3[3:0] AFSEL2[3:0] AFSEL1[3:0] AFSEL0[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AFSEL15[3:0] AFSEL14[3:0] AFSEL13[3:0] AFSEL12[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AFSEL11[3:0] AFSEL10[3:0] AFSEL9[3:0] AFSEL8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 AFSELy[3:0]: Alternate function selection for port x, I/O y (y = 8 to 15)
These bits are written by software to configure alternate function I/Os
0000: AF0 1000: AF8
0001: AF1 1001: AF9
0010: AF2 1010: AF10
0011: AF3 1011: AF11
0100: AF4 1100: AF12
0101: AF5 1101: AF13
0110: AF6 1110: AF14
0111: AF7 1111: AF15
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BR15 BR14 BR13 BR12 BR11 BR10 BR9 BR8 BR7 BR6 BR5 BR4 BR3 BR2 BR1 BR0
w w w w w w w w w w w w w w w w
10
11
9
8
7
6
5
4
3
2
1
0
MODE15[1:0]
MODE14[1:0]
MODE13[1:0]
MODE12[1:0]
MODE10[1:0]
MODE11[1:0]
MODE9[1:0]
MODE8[1:0]
MODE7[1:0]
MODE6[1:0]
MODE5[1:0]
MODE4[1:0]
MODE3[1:0]
MODE2[1:0]
MODE1[1:0]
MODE0[1:0]
GPIOx_MODER
(x = A, B, C, D, F)
0x00
Reset value (port A) 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Reset value
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
(ports other than A)
GPIOx_OTYPER
OT15
OT14
OT13
OT12
OT10
OT11
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
OT9
OT8
OT7
OT6
OT5
OT4
OT3
OT2
OT1
OT0
0x04 (x = A, B, C, D, F)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OSPEED15[1:0]
OSPEED14[1:0]
OSPEED13[1:0]
OSPEED12[1:0]
OSPEED10[1:0]
OSPEED11[1:0]
OSPEED9[1:0]
OSPEED8[1:0]
OSPEED7[1:0]
OSPEED6[1:0]
OSPEED5[1:0]
OSPEED4[1:0]
OSPEED3[1:0]
OSPEED2[1:0]
OSPEED1[1:0]
OSPEED0[1:0]
GPIOx_OSPEEDR
(x = A, B, C, D, F)
0x08
PUPD14[1:0]
PUPD13[1:0]
PUPD12[1:0]
PUPD10[1:0]
PUPD11[1:0]
PUPD9[1:0]
PUPD8[1:0]
PUPD7[1:0]
PUPD6[1:0]
PUPD5[1:0]
PUPD4[1:0]
PUPD3[1:0]
PUPD2[1:0]
PUPD1[1:0]
PUPD0[1:0]
GPIOx_PUPDR
(x = A, B, C, D, F)
0x0C
Reset value (port A) 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reset value
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(ports other than A)
GPIOx_IDR
ID15
ID14
ID13
ID12
ID10
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ID11
ID9
ID8
ID7
ID6
ID5
ID4
ID3
ID2
ID1
ID0
0x10 (x = A, B, C, D, F)
Reset value x x x x x x x x x x x x x x x x
GPIOx_ODR
OD15
OD14
OD13
OD12
OD10
OD11
OD9
OD8
OD7
OD6
OD5
OD4
OD3
OD2
OD1
OD0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x14 (x = A, B, C, D, F)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_BSRR
BR15
BR14
BR13
BR12
BR10
BS15
BS14
BS13
BS12
BS10
BR11
BS11
BR9
BR8
BR7
BR6
BR5
BR4
BR3
BR2
BR1
BR0
BS9
BS8
BS7
BS6
BS5
BS4
BS3
BS2
BS1
BS0
0x18 (x = A, B, C, D, F)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
LCK15
LCK14
LCK13
LCK12
LCK10
LCK11
GPIOx_LCKR
LCKK
LCK9
LCK8
LCK7
LCK6
LCK5
LCK4
LCK3
LCK2
LCK1
LCK0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x1C (x = A, B, C, D, F)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_AFRL AFSEL7 AFSEL6 AFSEL5 AFSEL4 AFSEL3 AFSEL2 AFSEL1 AFSEL0
0x20 (x = A, B, C, D, F) [3:0] [3:0] [3:0] [3:0] [3:0] [3:0] [3:0] [3:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_AFRH AFSEL15 AFSEL14 AFSEL13 AFSEL12 AFSEL11 AFSEL10 AFSEL9 AFSEL8
0x24 (x = A, B, C, D, F) [3:0] [3:0] [3:0] [3:0] [3:0] [3:0] [3:0] [3:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_BRR
BR15
BR14
BR13
BR12
BR10
BR11
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
BR9
BR8
BR7
BR6
BR5
BR4
BR3
BR2
BR1
BR0
0x28 (x = A, B, C, D, F)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The devices feature a set of configuration registers. The main purposes of the system
configuration controller are the following:
• Enabling/disabling I2C Fast Mode Plus on some I/O ports
• Configuring the IR modulation signal and its output polarity
• Remapping of some I/O ports
• Remapping the memory located at the beginning of the code area
• Flag pending interrupts from each interrupt line
• Managing robustness feature
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
I2C_ I2C_ I2C_ I2C_ I2C_ I2C_ I2C_
PC14_ I2C1_ PB9_ PB8_
Res. Res. Res. Res. Res. Res. Res. PA10_ PA9_ Res. PB7_ PB6_
FMP
FMP(1) FMP FMP FMP(1) FMP(1) FMP FMP
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IR_MOD IR_ PA12_ PA11_ MEM_MODE
Res. Res. Res. Res. Res. Res. Res. Res. Res.
[1:0] POL RMP RMP [1:0]
rw rw rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral or function, otherwise reserved.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LOCKU
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. P_LOC
K
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. PINMUX5[1:0] PINMUX4[1:0] PINMUX3[1:0] PINMUX2[1:0] PINMUX1[1:0] PINMUX0[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WWDG
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RTC Res.
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FLASH
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. _ Res.
ITF
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RCC
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI1 EXTI0
r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI3 EXTI2
r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. EXTI15 EXTI14 EXTI13 EXTI12 EXTI11 EXTI10 EXTI9 EXTI8 EXTI7 EXTI6 EXTI5 EXTI4
r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMA1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
_CH1
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMA1 DMA1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
_CH3 _CH2
r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMAM
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
UX
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ADC
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIM1_B TIM1_ TIM1_ TIM1_
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RK UPD TRG CCU
r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIM1_
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
CC
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TIM3
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TIM14
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TIM16
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TIM17
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. I2C1
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SPI1
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
1
r
Res.
Res.
0x88
0x84
0x80
0x18
0x17
0x00
0x7F
0x3B
0x8C
0x3C
0x40 to
0x04 to
0x1C to
Offset
174/825
7.1.25
14
30
Res.
Res.
13
29
Res.
Res.
Reserved
Reserved
Reserved
Reserved
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
SYSCFG_CFGR3
SYSCFG_CFGR2
SYSCFG_CFGR1
SYSCFG_ITLINE3
SYSCFG_ITLINE2
SYSCFG_ITLINE0
Res. Res. Res. Res. Res. Res.
12
28
31
Res.
Res.
Res.
Res.
26
Res.
Res.
0
Res. Res. Res. Res. Res. I2C_PC14_FMP 24
9
25
Res.
Res.
0
Res. Res. Res. Res. Res. I2C_PA10_FMP 23
System configuration controller (SYSCFG)
0
Res. Res. Res. Res. Res. I2C_PA9_FMP 22
8
21
Res.
Res.
0
Res. Res. Res. Res. Res. I2C1_FMP 20
Bits 31:1 Reserved, must be kept at reset value.
0
Res. Res. Res. Res. Res. I2C_PB9_FMP 19
7
23
0
Res.
Res.
RM0490 Rev 3
0
Res. Res. Res. Res. Res. I2C_PB7_FMP 17
0
Res. Res. Res. Res. Res. I2C_PB6_FMP
6
22
16
Res.
Res.
Reserved
Reserved
Reserved
Reserved
Res. Res. Res. Res. Res. Res. 14
5
21
13
Res. Res. Res. Res. Res. Res.
Bit 0 USART2: USART2 interrupt request pending (EXTI line 26)
12
0
Res. Res. Res. Res. Res.
4
11
20
PINMUX5
Res.
Res.
0
Res. Res. Res. Res. Res.
Table 26. SYSCFG register map and reset values
10
0
Res. Res. Res. Res. Res. 9
PINMUX4
3
19
0
Res. Res. Res. Res. BOOSTEN
Res.
Res.
8
0
0
Res. Res. Res. Res. 7
The following table gives the SYSCFG register map and the reset values.
PINMUX3 IR_MOD
0
0
Res. Res. Res. Res.
2
6
18
Res.
Res.
0
Res. Res. Res. Res. IR_POL 5
PINMUX2
0
0
Res. Res. Res. Res. PA12_RMP 4
1
17
0
Res. Res. Res. Res. PA11_RMP
Res.
Res.
PINMUX1
3
0
Res. Res. Res. Res. Res. 2
0
0
0
FLASH_ITF RTC Res. Res.
r
0
1
16
PINMUX0 MEM_MODE[1:0]
Res.
0
0
X X
WWDG LOCUP_LOCK
USART
0
RM0490
0x98
0x94
0x90
0xB8
0xB4
0xB0
0xA8
0xA4
0xA0
0x9C
0xD8
0xD4
0xD0
0xC8
0xC0
0xBC
0xAC
0xCC
0xC4-
Offset
RM0490
Reserved
Reserved
Reserved
Reserved
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
SYSCFG_ITLINE9
SYSCFG_ITLINE7
SYSCFG_ITLINE6
SYSCFG_ITLINE5
SYSCFG_ITLINE4
SYSCFG_ITLINE11
SYSCFG_ITLINE22
SYSCFG_ITLINE21
SYSCFG_ITLINE19
SYSCFG_ITLINE16
SYSCFG_ITLINE14
SYSCFG_ITLINE13
SYSCFG_ITLINE12
SYSCFG_ITLINE10
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0490 Rev 3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 15
Reserved
Reserved
Reserved
Reserved
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 14
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 13
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 12
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI15 Res. Res. Res. 11
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI14 Res. Res. Res. 10
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI13 Res. Res. Res. 9
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI12 Res. Res. Res. 8
Table 26. SYSCFG register map and reset values (continued)
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI11 Res. Res. Res. 7
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI10 Res. Res. Res. 6
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI9 Res. Res. Res. 5
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI8 Res. Res. Res. 4
0
0
Res. Res. Res. Res. Res. TIM1_BRK Res. Res. Res. Res. EXTI7 Res. Res. Res. 3
0
0
Res. Res. Res. Res. Res. TIM1_UPD Res. Res. Res. Res. EXTI6 Res. Res. Res. 2
0
0
0
0
0
Res. Res. Res. Res. Res. TIM1_TRG Res. Res. DMA1_CH3 Res. EXTI5 EXTI3 EXTI1 Res. 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TIM17 TIM16 TIM14 TIM3 TIM1_CC TIM1_CCU ADC DMAMUX DMA1_CH2 DMA1_CH1 EXTI4 EXTI2 EXTI0 RCC 0
System configuration controller (SYSCFG)
175/825
176
0xF0
0xE8
0xE4
0xE0
0xEC
0xDC
Offset
176/825
Reserved
Reserved
Register
Reset value
Reset value
Reset value
Reset value
Reset value
SYSCFG_ITLINE28
SYSCFG_ITLINE27
SYSCFG_ITLINE25
SYSCFG_ITLINE23
RM0490 Rev 3
Res. Res. Res. Res. 17
Res. Res. Res. Res. 16
Res. Res. Res. Res. 15
Reserved
Reserved
8 Interconnect matrix
8.1 Introduction
Several peripherals have direct connections between them.
This allows autonomous communication and/or synchronization between peripherals,
saving CPU resources thus power consumption.
In addition, these hardware connections remove software latency and allow design of
predictable systems.
Depending on peripherals, these interconnections can operate in Run, Sleep, and Stop
mode.
For availability of peripherals on different STM32C0x1 products, refer to Section 1.4:
Availability of peripherals.
DMAMUX
Source
TIM14
TIM16
TIM17
IRTIM
ADC1
TIM1
TIM3
TIM16 - - - - - - - 8.3.7
USART1 - - - - - - - 8.3.7
USART2 - - - - - - - 8.3.7
ADC 8.3.3 - - - - - - -
VREFINT - - - - 8.3.5 - -
LSE - - - 8.3.4 - - - -
LSI - - - 8.3.4 - - - -
DMAMUX
Source
TIM14
TIM16
TIM17
IRTIM
ADC1
TIM1
TIM3
RTC - - 8.3.4 - - - - -
1. Numbers in the table are links to corresponding sub-sections in Section 8.3: Interconnection details.
2. The “-” symbol in grayed cells means “no interconnection”.
8.3.1 From TIM1, TIM3, TIM14, and TIM17, to TIM1 and TIM3
Purpose
Some of the TIMx timers are linked together internally for timer synchronization or chaining.
When one timer is configured in master mode, it can reset, start, stop or clock the counter of
another timer configured in slave mode.
A description of the feature is provided in: Section 16.3.19: Timer synchronization.
The modes of synchronization are detailed in:
• Section 15.3.26: Timer synchronization for advanced-control timer TIM1
• Section 16.3.18: Timers and external trigger synchronization for general-purpose timer
TIM3
Triggering signals
The output (from master) is on signal TIMx_TRGO (and TIMx_TRGOx), following a
configurable timer event.
With TIM14 and TIM17 timers that do not have a trigger output, the output compare 1 is
used instead.
The input (to slave) is on signals TIMx_ITR0/ITR1/ITR2/ITR3.
The input and output signals for TIM1 are shown in Figure 55: Advanced-control timer block
diagram.
The possible master/slave connections are given in Table 65: TIM1 internal trigger
connection.
Triggering signals
The output (from timer) is on signal TIMx_TRGO, TIMx_TRGO2 or TIMx_CCx event.
The input (to ADC) is on signal TRG[7:0].
The connection between timers and ADC is provided in Table 53: External triggers.
Triggering signals
The output (from ADC) is on signals ADC_AWDx_OUT x = 1, 2, 3 (three watchdogs per
ADC) and the input (to timer) on signal TIMx_ETR (external trigger).
8.3.4 From HSE, LSE, LSI, MCO, MCO2, and RTC, to TIM14,
TIM16, and TIM17
Purpose
External clocks (HSE, LSE), internal clock (LSI), microcontroller output clock (MCO and
MCO2), RTC clock, and GPIO can be selected as inputs to capture channel 1 of some of
TIM14/16/TIM17 timers.
The timers allow calibrating or precisely measuring internal clocks such as HSI48 or LSI,
using accurate clocks such as LSE or HSE/32 for timing reference. See details in
Section 5.2.13: Internal/external clock measurement with TIM14/TIM16/TIM17.
When low-speed external (LSE) oscillator is used, no additional hardware connections are
required.
9.1 Introduction
The direct memory access (DMA) controller is a bus master and system peripheral.
The DMA is used to perform programmable data transfers between memory-mapped
peripherals and/or memories, upon the control of an off-loaded CPU.
The DMA controller features a single AHB master architecture.
There is one instance of DMA with 3 channels.
Each channel is dedicated to managing memory access requests from one or more
peripherals. The DMA includes an arbiter for handling the priority between DMA requests.
9.3.1 DMA1
DMA1 is implemented with the hardware configuration parameters shown in the table below.
Number of channels 3
Ch 2
Ch 3
DMAMUX
dma_it[1..3] MSv69118V1
The DMA controller performs direct memory transfer by sharing the AHB system bus with
other system masters. The bus matrix implements round-robin scheduling. DMA requests
may stop the CPU access to the system bus for a number of bus cycles, when CPU and
DMA target the same destination (memory or peripheral).
According to its configuration through the AHB slave interface, the DMA controller arbitrates
between the DMA channels and their associated received requests. The DMA controller
also schedules the DMA data transfers over the single AHB port master.
The DMA controller generates an interrupt per channel to the interrupt controller.
The start address used for the first single transfer is the base address of the
peripheral or memory, and is programmed in the DMA_CPARx or DMA_CMARx
register.
– a single data write (byte, half-word or word) to the peripheral data register or a
location in the memory, addressed through an internal current peripheral/memory
address register.
The start address used for the first transfer is the base address of the peripheral or
memory, and is programmed in the DMA_CPARx or DMA_CMARx register.
• post-decrementing of the programmed DMA_CNDTRx register
This register contains the remaining number of data items to transfer (number of AHB
‘read followed by write’ transfers).
This sequence is repeated until DMA_CNDTRx is null.
Note: The AHB master bus source/destination address must be aligned with the programmed size
of the transferred single data to the source/destination.
Pointer incrementation
The peripheral and memory pointers may be automatically incremented after each transfer,
depending on the PINC and MINC bits of the DMA_CCRx register.
If the incremented mode is enabled (PINC or MINC set to 1), the address of the next
transfer is the address of the previous one incremented by 1, 2 or 4, depending on the data
size defined in PSIZE[1:0] or MSIZE[1:0]. The first transfer address is the one programmed
in the DMA_CPARx or DMA_CMARx register. During transfers, these registers keep the
initially programmed value. The current transfer addresses (in the current internal
peripheral/memory address register) are not accessible by software.
If the channel x is configured in non-circular mode, no DMA request is served after the last
data transfer (once the number of single data to transfer reaches zero). The DMA channel
must be disabled in order to reload a new number of data items into the DMA_CNDTRx
register.
Note: If the channel x is disabled, the DMA registers are not reset. The DMA channel registers
(DMA_CCRx, DMA_CPARx and DMA_CMARx) retain the initial values programmed during
the channel configuration phase.
In circular mode, after the last data transfer, the DMA_CNDTRx register is automatically
reloaded with the initially programmed value. The current internal address registers are
reloaded with the base address values from the DMA_CPARx and DMA_CMARx registers.
Note: The two last steps of the channel configuration procedure may be merged into a single
access to the DMA_CCRx register, to configure and enable the channel.
automatically reloaded with the initial value programmed during the channel configuration
phase, and the DMA requests continue to be served.
In order to stop a circular transfer, the software needs to stop the peripheral from generating
DMA requests (such as quit the ADC scan mode), before disabling the DMA channel.
The software must explicitly program the DMA_CNDTRx value before starting/enabling a
transfer, and after having stopped a circular transfer.
Memory-to-memory mode
The DMA channels may operate without being triggered by a request from a peripheral. This
mode is called memory-to-memory mode, and is initiated by software.
If the MEM2MEM bit in the DMA_CCRx register is set, the channel, if enabled, initiates
transfers. The transfer stops once the DMA_CNDTRx register reaches zero.
Note: The memory-to-memory mode must not be used in circular mode. Before enabling a
channel in memory-to-memory mode (MEM2MEM = 1), the software must clear the CIRC
bit of the DMA_CCRx register.
Peripheral-to-peripheral mode
Any DMA channel can operate in peripheral-to-peripheral mode:
• when the hardware request from a peripheral is selected to trigger the DMA channel
This peripheral is the DMA initiator and paces the data transfer from/to this peripheral
to/from a register belonging to another memory-mapped peripheral (this one being not
configured in DMA mode).
• when no peripheral request is selected and connected to the DMA channel
The software configures a register-to-register transfer by setting the MEM2MEM bit of
the DMA_CCRx register.
Regardless of their usual naming, these ‘memory’ register, field and bit are used to
define the destination peripheral in peripheral-to-peripheral mode.
Table 30. Programmable data width and endian behavior (when PINC = MINC = 1)
Source Destinat
port ion port Destination
Number Source content:
width width content:
of data address / data
(MSIZE (PSIZE address / data
items to (DMA_CMARx if DMA transfers
if if (DMA_CPARx if
transfer DIR = 1, else
DIR = 1, DIR = 1, DIR = 1, else
(NDT) DMA_CPARx)
else else DMA_CMARx)
PSIZE) MSIZE)
@0x0 / B0 1: read B0[7:0] @0x0 then write 00B0[15:0] @0x0 @0x0 / 00B0
@0x1 / B1 2: read B1[7:0] @0x1 then write 00B1[15:0] @0x2 @0x2 / 00B1
8 16 4
@0x2 / B2 3: read B2[7:0] @0x2 then write 00B2[15:0] @0x4 @0x4 / 00B2
@0x3 / B3 4: read B3[7:0] @0x3 then write 00B3[15:0] @0x6 @0x6 / 00B3
@0x0 / B0 1: read B0[7:0] @0x0 then write 000000B0[31:0] @0x0 @0x0 / 000000B0
@0x1 / B1 2: read B1[7:0] @0x1 then write 000000B1[31:0] @0x4 @0x4 / 000000B1
8 32 4
@0x2 / B2 3: read B2[7:0] @0x2 then write 000000B2[31:0] @0x8 @0x8 / 000000B2
@0x3 / B3 4: read B3[7:0] @0x3 then write 000000B3[31:0] @0xC @0xC / 000000B3
@0x0 / B1B0 1: read B1B0[15:0] @0x0 then write B0[7:0] @0x0 @0x0 / B0
@0x2 / B3B2 2: read B3B2[15:0] @0x2 then write B2[7:0] @0x1 @0x1 / B2
16 8 4
@0x4 / B5B4 3: read B5B4[15:0] @0x4 then write B4[7:0] @0x2 @0x2 / B4
@0x6 / B7B6 4: read B7B6[15:0] @0x6 then write B6[7:0] @0x3 @0x3 / B6
@0x0 / B1B0 1: read B1B0[15:0] @0x0 then write B1B0[15:0] @0x0 @0x0 / B1B0
@0x2 / B3B2 2: read B3B2[15:0] @0x2 then write B3B2[15:0] @0x2 @0x2 / B3B2
16 16 4
@0x4 / B5B4 3: read B5B4[15:0] @0x4 then write B5B4[15:0] @0x4 @0x4 / B5B4
@0x6 / B7B6 4: read B7B6[15:0] @0x6 then write B7B6[15:0] @0x6 @0x6 / B7B6
@0x0 / B1B0 1: read B1B0[15:0] @0x0 then write 0000B1B0[31:0] @0x0 @0x0 / 0000B1B0
@0x2 / B3B2 2: read B3B2[15:0] @0x2 then write 0000B3B2[31:0] @0x4 @0x4 / 0000B3B2
16 32 4
@0x4 / B5B4 3: read B5B4[15:0] @0x4 then write 0000B5B4[31:0] @0x8 @0x8 / 0000B5B4
@0x6 / B7B6 4: read B7B6[15:0] @0x6 then write 0000B7B6[31:0] @0xC @0xC / 0000B7B6
@0x0 / B3B2B1B0 1: read B3B2B1B0[31:0] @0x0 then write B0[7:0] @0x0 @0x0 / B0
@0x4 / B7B6B5B4 2: read B7B6B5B4[31:0] @0x4 then write B4[7:0] @0x1 @0x1 / B4
32 8 4
@0x8 / BBBAB9B8 3: read BBBAB9B8[31:0] @0x8 then write B8[7:0] @0x2 @0x2 / B8
@0xC / BFBEBDBC 4: read BFBEBDBC[31:0] @0xC then write BC[7:0] @0x3 @0x3 / BC
@0x0 / B3B2B1B0 1: read B3B2B1B0[31:0] @0x0 then write B1B0[15:0] @0x0 @0x0 / B1B0
@0x4 / B7B6B5B4 2: read B7B6B5B4[31:0] @0x4 then write B5B4[15:0] @0x2 @0x2 / B5B4
32 16 4
@0x8 / BBBAB9B8 3: read BBBAB9B8[31:0] @0x8 then write B9B8[15:0] @0x4 @0x4 / B9B8
@0xC / BFBEBDBC 4: read BFBEBDBC[31:0] @0xC then write BDBC[15:0] @0x6 @0x6 / BDBC
@0x0 / B3B2B1B0 1: read B3B2B1B0[31:0] @0x0 then write B3B2B1B0[31:0] @0x0 @0x0 / B3B2B1B0
@0x4 / B7B6B5B4 2: read B7B6B5B4[31:0] @0x4 then write B7B6B5B4[31:0] @0x4 @0x4 / B7B6B5B4
32 32 4
@0x8 / BBBAB9B8 3: read BBBAB9B8[31:0] @0x8 then write BBBAB9B8[31:0] @0x8 @0x8 / BBBAB9B8
@0xC / BFBEBDBC 4: read BFBEBDBC[31:0] @0xC then write BFBEBDBC[31:0] @0xC @0xC / BFBEBDBC
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. TEIF3 HTIF3 TCIF3 GIF3 TEIF2 HTIF2 TCIF2 GIF2 TEIF1 HTIF1 TCIF1 GIF1
r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. CTEIF3 CHTIF3 CTCIF3 CGIF3 CTEIF2 CHTIF2 CTCIF2 CGIF2 CTEIF1 CHTIF1 CTCIF1 CGIF1
w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MEM2
Res. PL[1:0] MSIZE[1:0] PSIZE[1:0] MINC PINC CIRC DIR TEIE HTIE TCIE EN
MEM
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
NDT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PA[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MA[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
10
11
9
8
7
6
5
4
3
2
1
0
HTIF3
TCIF3
HTIF2
TCIF2
HTIF1
TCIF1
TEIF3
TEIF2
TEIF1
GIF3
GIF2
GIF1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DMA_ISR
0x000
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
CHTIF3
CTCIF3
CHTIF2
CTCIF2
CHTIF1
CTCIF1
CTEIF3
CTEIF2
CTEIF1
CGIF3
CGIF2
CGIF1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DMA_IFCR
0x004
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
MEM2MEM
MSIZE[1:0]
PSIZE[1:0]
PL[1:0]
MINC
CIRC
PINC
HTIE
TCIE
TEIE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DIR
EN
DMA_CCR1
0x008
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DMA_CNDTR1 NDTR[15:0]
0x00C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CPAR1 PA[31:0]
0x010
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CMAR1 MA[31:0]
0x014
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x018 Reserved Reserved.
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
MEM2MEM
MSIZE[1:0]
PSIZE[1:0]
PL[1:0]
MINC
CIRC
PINC
HTIE
TCIE
TEIE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DIR
EN
DMA_CCR2
0x01C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DMA_CNDTR2 NDTR[15:0]
0x020
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CPAR2 PA[31:0]
0x024
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CMAR2 MA[31:0]
0x028
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x02C Reserved Reserved.
MEM2MEM
MSIZE[1:0]
PSIZE[1:0]
PL[1:0]
MINC
CIRC
PINC
HTIE
TCIE
TEIE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DIR
EN
DMA_CCR3
0x030
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DMA_CNDTR3 NDTR[15:0]
0x034
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CPAR3 PA[31:0]
0x038
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CMAR3 MA[31:0]
0x03C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10.1 Introduction
A peripheral indicates a request for DMA transfer by setting its DMA request signal. The
DMA request is pending until served by the DMA controller that generates a DMA
acknowledge signal, and the corresponding DMA request signal is deasserted.
In this document, the set of control signals required for the DMA request/acknowledge
protocol is not explicitly shown or described, and it is referred to as DMA request line.
The DMAMUX request multiplexer enables routing a DMA request line between the
peripherals and the DMA controller of the product. The routing function is ensured by a
programmable multi-channel DMA request line multiplexer. Each channel selects a unique
DMA request line, unconditionally or synchronously with events from its DMAMUX
synchronization inputs. The DMAMUX may also be used as a DMA request generator from
programmable events on its input trigger signals.
The number of DMAMUX instances and their main characteristics are specified in
Section 10.3.1.
The assignment of DMAMUX request multiplexer inputs to the DMA request lines from
peripherals and to the DMAMUX request generator outputs, the assignment of DMAMUX
request multiplexer outputs to DMA controller channels, and the assignment of DMAMUX
synchronizations and trigger inputs to internal and external signals depend upon product
implementation. They are detailed in Section 10.3.2.
p Channel 1
Channel 0
DMA requests xq
re
DMAMUX_C0CR
x_
from peripherals: 1
mu
0
dm
select
n+p+2 m DMA requests
1 to DMA controllers:
0
Request generator dmamux_req_outx
n+3
Channel n n
Sync
dmamux_req_genx
DMAMUX_RGCnCR n+2 m
DMA channels
1 events:
n+1 0
dmamux_evtx
s 1 0
Channel 1 1 2
DMAMUX_RGC1CR
1
Channel 0 0
DMAMUX_RGC0CR
Interrupt
interface
t 1 0 s 1 0
DMAMUX features two main sub-blocks: the request line multiplexer and the request line
generator.
The implementation assigns:
• DMAMUX request multiplexer sub-block inputs (dmamux_reqx) from peripherals
(dmamux_req_inx) and from channels of the DMAMUX request generator sub-block
(dmamux_req_genx)
• DMAMUX request outputs to channels of DMA controllers (dmamux_req_outx)
• Internal or external signals to DMA request trigger inputs (dmamux_trgx)
• Internal or external signals to synchronization inputs (dmamux_syncx)
Figure 21. Synchronization mode of the DMAMUX request line multiplexer channel
Selected
dmamux_reqx
Not pending
dmamux_syncx
dmamux_req_outx
dmamux_evtx
Example: DMAMUX_CCRx configured with: NBREQ=4, SE=1, EGE=1, SPOL=01 (rising edge)
MSv41974V1
Figure 22. Event generation of the DMA request line multiplexer channel
Selected
dmamux_reqx Not pending
dmamux_req_outx
SE
EGE
dmamux_evtx
MSv41975V1
If EGE is enabled, the multiplexer channel generates a channel event, as a pulse of one
AHB clock cycle, when its DMA request counter is automatically reloaded with the value of
the programmed NBREQ field, as shown in Figure 21 and Figure 22.
Note: If EGE is enabled and NBREQ = 0, an event is generated after each served DMA request.
Note: A synchronization event (edge) is detected if the state following the edge remains stable for
more than two AHB clock cycles.
Upon writing into DMAMUX_CxCR register, the synchronization events are masked during
three AHB clock cycles.
Note: The GNBREQ field value can be written by software only when the enable GE bit of the
corresponding generator channel x is disabled.
There is no hardware write protection.
A trigger event (edge) is detected if the state following the edge remains stable for more
than two AHB clock cycles.
Upon writing into DMAMUX_RGxCR register, the trigger events are masked during three
AHB clock cycles.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. SYNC_ID[4:0] NBREQ[4:0] SPOL[1:0] SE
rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. EGE SOIE Res. Res. DMAREQ_ID[5:0]
rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SOF2 SOF1 SOF0
r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CSOF CSOF CSOF
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
2 1 0
w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. GNBREQ[4:0] GPOL[1:0] GE
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. OIE Res. Res. Res. SIG_ID[4:0]
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. OF3 OF2 OF1 OF0
r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. COF3 COF2 COF1 COF0
w w w w
0x144
0x140
0x108
0x104
0x100
0x084
0x080
0x008
0x004
0x000
0x13C
0x10C
0x07C
0x3FC
0x0FC
0x110 -
Offset
0x148 -
0x088 -
10.6.7
RM0490
Reserved
Reserved
Reserved
Reserved
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
DMAMUX_CFR
DMAMUX_CSR
DMAMUX_C2CR
DMAMUX_C1CR
DMAMUX_C0CR
DMAMUX_RGSR
DMAMUX_RG3CR
DMAMUX_RG2CR
DMAMUX_RG1CR
DMAMUX_RG0CR
DMAMUX_RGCFR
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 0 28
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
DMAMUX register map
SYNC_ID[4:0]
SYNC_ID[4:0]
SYNC_ID[4:0]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
GNBREQ[4:0]
GNBREQ[4:0]
GNBREQ[4:0]
GNBREQ[4:0]
0
0
0
0
0
0
0
RM0490 Rev 3
[1:0]
[1:0]
[1:0]
[1:0]
[1:0]
[1:0]
[1:0]
0 0
0 0
0 0
0 0
0
0
0
GPOL
GPOL
GPOL
GPOL
17
0
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 10
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EGE EGE EGE 9
Res. Res. Res. Res. OIE OIE OIE OIE Res. Res. Res. Res. SOIE SOIE SOIE 8
register boundary address table for the DMAMUX register base address.
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 7
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 6
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 5
0
0
0
0
0
0
0
0
0
Res. COF3 OF3 Res. 0 Res. Res. Res. Res. 3
0
0
0
0
0
0
0
0
0
0
The following table summarizes the DMAMUX registers and reset values. Refer to the
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
213/825
213
Nested vectored interrupt controller (NVIC) RM0490
- - - - Reserved 0x0000_0000
- -3 fixed Reset Reset 0x0000_0004
Non maskable interrupt. SRAM
- -2 fixed NMI_Handler parity error, HSE CSS and LSE CSS 0x0000_0008
are linked to the NMI vector.
- -1 fixed HardFault_Handler All class of fault 0x0000_000C
0x0000_0010
0x0000_0014
0x0000_0018
- - - - Reserved 0x0000_001C
0x0000_0020
0x0000_0024
0x0000_0028
System service call via SWI
- 3 settable SVC_Handler 0x0000_002C
instruction
0x0000_0030
- - - - Reserved
0x0000_0034
- 5 settable PendSV_Handler Pendable request for system service 0x0000_0038
- 6 settable SysTick_Handler System tick timer 0x0000_003C
0 7 settable WWDG Window watchdog interrupt 0x0000_0040
1 - - - Reserved 0x0000_0044
2 9 settable RTC RTC interrupts (EXTI lines 19) 0x0000_0048
3 10 settable FLASH Flash global interrupt 0x0000_004C
4 11 settable RCC RCC global interrupt 0x0000_0050
5 12 settable EXTI0_1 EXTI line 0 & 1 interrupt 0x0000_0054
6 13 settable EXTI2_3 EXTI line 2 & 3 interrupt 0x0000_0058
7 14 settable EXTI4_15 EXTI line 4 to 15 interrupt 0x0000_005C
8 - - - Reserved 0x0000_0060
9 16 settable DMA1_Channel1 DMA1 channel 1 interrupt 0x0000_0064
10 17 settable DMA1_Channel2_3 DMA1 channel 2 & 3 interrupts 0x0000_0068
11 18 settable DMAMUX DMAMUX interrupts 0x0000_006C
12 19 settable ADC ADC interrupt 0x0000_0070
TIM1_BRK_UP_TRG TIM1 break, update, trigger and
13 20 settable 0x0000_0074
_COM commutation interrupts
14 21 settable TIM1_CC TIM1 Capture Compare interrupt 0x0000_0078
15 - - - Reserved 0x0000_007C
16 23 settable TIM3 TIM3 global interrupt 0x0000_0080
17 - - - Reserved 0x0000_0084
18 - - - Reserved 0x0000_0088
19 26 settable TIM14 TIM14 global interrupt 0x0000_008C
20 - - - Reserved 0x0000_0090
21 28 settable TIM16 TIM16 global interrupt 0x0000_0094
22 29 settable TIM17 TIM17 global interrupt 0x0000_0098
I2C1 global interrupt (combined with
23 30 settable I2C1 0x0000_009C
EXTI 23)
24 - - - Reserved 0x0000_00A0
25 32 settable SPI1 SPI1/I2S1 global interrupt 0x0000_00A4
26 - - - Reserved 0x0000_00A8
USART1 global interrupt (combined
27 34 settable USART1 0x0000_00AC
with EXTI 25)
The Extended interrupt and event controller (EXTI) manages the CPU and system wakeup
through configurable and direct event inputs (lines). It provides wakeup requests to the
power control, and generates an interrupt request to the CPU NVIC and events to the CPU
event input. For the CPU an additional event generation block (EVG) is needed to generate
the CPU event signal.
The EXTI wakeup requests allow the system to be woken up from Stop modes.
The interrupt request and event request generation can also be used in Run mode.
The EXTI also includes the EXTI I/O port multiplexer.
AHB interface
Registers
hclk
exti[15:0]
To interconnect
EXTImux
GPIO
IOPort sys_wakeup
c_wakeup PWR
Configurable event(15:0)
it_exti_per(y)*
Direct event(x) or
configurable event(y) Event
Peripherals
Wakeup
c_evt_exti c_event
Trigger events Masking Pulse rxev
c_evt_rst
c_fclk CPU
Interrupt Direct event(x)
EVG
EXTI
* it_exti_per(y) are only available for configurable events (y)
MS44733V2
EXTI_R/FPR1
EXTI_RTSR1
EXTI_FTSR1
EXTI_EMR1
EXTI_IMR1
Event input
Logic implementation
type
Synch
Other CPU Wakeups c_wakeup
CPU Wakeup(y)
The software interrupt event register allows triggering configurable events by software,
writing the corresponding register bit, irrespective of the edge selection setting.
The rising edge and falling edge selection registers allow to enable and select the
configurable event active trigger edge or both edges.
The CPU has its dedicated interrupt mask register and a dedicated event mask registers.
The enabled event allows generating an event on the CPU. All events for a CPU are OR-ed
together into a single CPU event signal. The event pending registers (EXTI_RPR1 and
EXTI_FPR1) is not set for an unmasked CPU event.
The configurable events have unique interrupt pending request registers, shared by the
CPU. The pending register is only set for an unmasked interrupt. Each configurable event
provides a common interrupt to the CPU. The configurable event interrupts need to be
acknowledged by software in the EXTI_RPR1 and/or EXTI_FPR1 registers.
When a CPU interrupt or CPU event is enabled, the asynchronous edge detection circuit is
reset by the clocked delay and rising edge detect pulse generator. This guarantees the
wakeup of the EXTI hclk clock before the asynchronous edge detection circuit is reset.
Note: A detected configurable event interrupt pending request can be cleared by the CPU. The
system cannot enter low-power modes as long as an interrupt pending request is active.
The EXTI direct event is able to generate a CPU event. This CPU event wakes up the CPU.
The CPU event may occur before the interrupt flag of the associated peripheral is set.
Synch
rst CPU Wakeup(x) c_wakeup
EXTI hclk
MS46536V1
………....
………....
MS44726V1
The EXTIs multiplexer outputs are available as output signals from the EXTI, to trigger other
functional blocks. The EXTI multiplexer outputs are available independently of mask setting
through the EXTI_IMR and EXTI_EMR registers.
The EXTI lines (event inputs) are connected as shown in the following table.
For configurable event inputs, upon an edge on the event input, an event request is
generated if that edge (rising or/and falling) is enabled. When the associated CPU interrupt
is unmasked, the corresponding RPIFn and/or FPIFn bit is/are set in the EXTI_RPR or/and
EXTI_FPR register, waking up the CPU subsystem and activating CPU interrupt signal. The
RPIFn and/or FPIFn pending bit is cleared by writing 1 to it, which clears the CPU interrupt
request.
For direct event inputs, when enabled in the associated peripheral, an event request is
generated on the rising edge only. There is no corresponding CPU pending bit in the EXTI.
When the associated CPU interrupt is unmasked, the corresponding CPU subsystem is
woken up. The CPU is woken up (interrupted) by the peripheral synchronous interrupt.
The CPU event must be unmasked to generate an event. Upon an enabled edge occurring
on an event input, a CPU event pulse is generated. There is no event pending bit.
For the configurable event inputs, the software can generate an event request by setting the
corresponding bit of the software interrupt/event register EXTI_SWIER1, which has the
effect of a rising edge on the event input. The pending rising edge event flag is set in the
EXTI_RPR1 register, irrespective of the EXTI_RTSR1 register setting.
All the registers can be accessed with word (32-bit), half-word (16-bit) and byte (8-bit)
access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RT15 RT14 RT13 RT12 RT11 RT10 RT9 RT8 RT7 RT6 RT5 RT4 RT3 RT2 RT1 RT0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FT15 FT14 FT13 FT12 FT11 FT10 FT9 FT8 FT7 FT6 FT5 FT4 FT3 FT2 FT1 FT0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SWI SWI SWI SWI SWI SWI
SWI9 SWI8 SWI7 SWI6 SWI5 SWI4 SWI3 SWI2 SWI1 SWI0
15 14 13 12 11 10
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RPIF15 RPIF14 RPIF13 RPIF12 RPIF11 RPIF10 RPIF9 RPIF8 RPIF7 RPIF6 RPIF5 RPIF4 RPIF3 RPIF2 RPIF1 RPIF0
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FPIF15 FPIF14 FPIF13 FPIF12 FPIF11 FPIF10 FPIF9 FPIF8 FPIF7 FPIF6 FPIF5 FPIF4 FPIF3 FPIF2 FPIF1 FPIF0
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
EXTIm+3[7:0] EXTIm+2[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EXTIm+1[7:0] EXTIm[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IM31 Res. Res. Res. Res. Res. IM25 Res. IM23 Res. Res. Res. IM19 Res. Res. Res.
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IM15 IM14 IM13 IM12 IM11 IM10 IM9 IM8 IM7 IM6 IM5 IM4 IM3 IM2 IM1 IM0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
EM31 Res. Res. Res. Res. Res. EM25 Res. EM23 Res. Res. Res. EM19 Res. Res. Res.
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EM15 EM14 EM13 EM12 EM11 EM10 EM9 EM8 EM7 EM6 EM5 EM4 EM3 EM2 EM1 EM0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_RTSR1 RT[15:0]
0x000
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_FTSR1 FT[15:0]
0x004
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_SWIER1 SWI[15:0]
0x008
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_RPR1 RPIF[15:0]
0x00C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_FPR1 FPIF[16:0]
0x010
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x014-
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reserved
0x05C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 47. EXTI controller register map and reset values (continued)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
IM31
IM25
IM23
IM19
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_IMR1 IM[15:0]
0x080
Reset value 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EM31
EM25
EM23
EM19
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_EMR1 EM[15:0]
0x084
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x088-
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reserved
0x08C
13.1 Introduction
The CRC (cyclic redundancy check) calculation unit is used to get a CRC code from 8-, 16-
or 32-bit data word and a generator polynomial.
Among other applications, CRC-based techniques are used to verify data transmission or
storage integrity. In the scope of the functional safety standards, they offer a means of
verifying the flash memory integrity. The CRC calculation unit helps compute a signature of
the software during runtime, to be compared with a reference signature generated at link
time and stored at a given memory location.
CRC_CR
CRC computation
CRC_POL
CRC_IDR
MS19882V3
The data size can be dynamically adjusted to minimize the number of write accesses for a
given number of bytes. For instance, a CRC for 5 bytes can be computed with a word write
followed by a byte write.
The input data can be reversed to manage the various endianness schemes. The reversing
operation can be performed on 8 bits, 16 bits and 32 bits depending on the REV_IN[1:0] bits
in the CRC_CR register.
For example, 0x1A2B3C4D input data are used for CRC calculation as:
• 0x58D43CB2 with bit-reversal done by byte
• 0xD458B23C with bit-reversal done by half-word
• 0xB23CD458 with bit-reversal done on the full word
The output data can also be reversed by setting the REV_OUT bit in the CRC_CR register.
The operation is done at bit level. For example, 0x11223344 output data are converted to
0x22CC4488.
The CRC calculator can be initialized to a programmable value using the RESET control bit
in the CRC_CR register (the default value is 0xFFFFFFFF).
The initial CRC value can be programmed with the CRC_INIT register. The CRC_DR
register is automatically initialized upon CRC_INIT register write access.
The CRC_IDR register can be used to hold a temporary value related to CRC calculation. It
is not affected by the RESET bit in the CRC_CR register.
Polynomial programmability
The polynomial coefficients are fully programmable through the CRC_POL register, and the
polynomial size can be configured to be 7, 8, 16 or 32 bits by programming the
POLYSIZE[1:0] bits in the CRC_CR register. Even polynomials are not supported.
Note: The type of an even polynomial is X+X2+..+Xn, while the type of an odd polynomial is
1+X+X2+..+Xn.
If the CRC data is less than 32-bit, its value can be read from the least significant bits of the
CRC_DR register.
To obtain a reliable CRC calculation, the change on-fly of the polynomial value or size can
not be performed during a CRC calculation. As a result, if a CRC calculation is ongoing, the
application must either reset it or perform a CRC_DR read before changing the polynomial.
The default polynomial value is the CRC-32 (Ethernet) polynomial: 0x4C11DB7.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DR[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IDR[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IDR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
REV_
Res. Res. Res. Res. Res. Res. Res. Res. REV_IN[1:0] POLYSIZE[1:0] Res. Res. RESET
OUT
rw rw rw rw rw rs
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CRC_INIT[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRC_INIT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
POL[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
POL[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
name
CRC_DR DR[31:0]
0x00
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
CRC_IDR IDR[31:0]
0x04
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
POLYSIZE[1:0]
REV_IN[1:0]
REV_OUT
RESET
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CRC_CR
0x08
Reset value 0 0 0 0 0 0
CRC_INIT CRC_INIT[31:0]
0x10
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
CRC_POL POL[31:0]
0x14
Reset value 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1
14.1 Introduction
The 12-bit ADC is a successive approximation analog-to-digital converter. It has up to 23
multiplexed channels allowing it to measure signals from 19 external and 4 internal sources.
A/D conversion of the various channels can be performed in single, continuous, scan or
discontinuous mode. The result of the ADC is stored in a left-aligned or right-aligned 16-bit
data register.
The analog watchdog feature allows the application to detect if the input voltage goes
outside the user-defined higher or lower thresholds.
An efficient low-power mode is implemented to allow very low consumption at low
frequency.
A built-in hardware oversampler allows analog performances to be improved while off-
loading the related computational burden from the CPU.
Resolution 12 bits
Maximum sampling speed 2.5 Msps
Hardware offset calibration X
Single-ended inputs X
Differential inputs -
Oversampling mode X
Data register 16 bits
DMA support X
Number of analog watchdogs 3
Number of external channels 13 19
Number of internal channels 4
Analog
supply
(VDDA)
ADREADY
EOSMP ADC interrupt
EOS
EOC
OVR
AUTOFF
AWDx
AHB
Auto-off mode slave
SCANDIR ADEN/ADDIS
up/down
CHSEL[22:0]
CONT AHB
single/continuous DMA request
interface
APB
DATA[15:0]
interface
VDDA
VSSA Suppy and
VREFINT LFTRIG reference
DMAEN
VSENSE ADCAL self-
Input DMACFG
VIN[X] calibration Over-
ADC_IN[22:17, selection & SAR ADC
VIN sampler
14:11,8:0] Analog input scan
channels control CONVERTED
DATA
SMP[2:0]
sampling time
start ADC_AWDx
Start & Stop _OUT
control OVRMOD to analog
(overrun mode) watchdogs
AUTDLY
ADSTART ALIGN AWDxEN
Auto-delayed
SW trigger (left/right)
conversion AWDxSGL
ADSTP RES[1:0]
stop conversion (12, 10, 8 bits) AWDCHx[4:0]
LTx[11:0]
TOVS HTx[11:0]
TRG0
OVSS[3:0]
TRG1
OVSR[3:0]
TRG2
DISCEN OVSE
TRG3 HW
Discontinuous
EXTEN[1:0] trigger
TRG4 mode enable
trigger enable
TRG5 and edge selection
TRG6
TRG7
EXTSEL[2:0]
trigger selection
MSv68740V4
1. TRGi are mapped at product level. Refer to Table External triggers in Section 14.4.1: ADC pins and internal signals.
Input, analog power Analog power supply and positive reference voltage
VDDA
supply for the ADC
injected into the analog ADC. This loading is transparent and does not add any cycle
latency to the start of the conversion.
Software calibration procedure
1. Ensure that ADEN = 0, AUTOFF = 0, ADVREGEN = 1 and DMAEN = 0.
2. Set ADCAL = 1.
3. Wait until ADCAL = 0 (or until EOCAL = 1). This can be handled by interrupt if the
interrupt is enabled by setting the EOCALIE bit in the ADC_IER register
4. The calibration factor can be read from bits 6:0 of ADC_DR or ADC_CALFACT
registers.
5. To reduce the noise effect of the calibration factor extraction, the software can make
average of eight CALFACT[6:0] values (optional).
ADCAL
CALIBRATION
ADC_DR[6:0] 0x00 FACTOR
ADC_CALFACT[6:0]
by S/W by H/W
MS33703V1
ADC state Ready (not converting) Converting channel Ready Converting channel
Updating (Single ended) (Single ended)
calibration
Internal
calibration factor[6:0] F1 F2
Start conversion
(hardware or software)
WRITE ADC_CALFACT
CALFACT[6:0] F2
by S/W by H/W
MS31925V1
ADEN
t STAB
ADR DY
ADDIS
ADC
OFF Startup RDY CONVERTING CH RDY REQ
stat -OF OFF
by S/W by H/W
MS30264V2
Note: In Auto-off mode (AUTOFF = 1) the power-on/off phases are performed automatically, by
hardware and the ADRDY flag is not set.
When the bus clock is much faster than the analog ADC_CK clock, a minimum delay of ten
analog ADC_CK cycles must be respected between ADEN and ADDIS bit settings.
RCC ADITF
(Reset & Clock Controller)
APB interface
PCLK
Bits CKMODE[1:0]
of ADC_CFGR2
/1 or /2 or /4 Others
Analog ADC_CK Analog
ADC
00
ADC /1,2,4,6,8,10,12
asynchronous 16,32,64,128,256
clock Bits CKMODE[1:0]
of ADC_CFGR2
Bits PRESC[3:0]
of ADC_CCR
MSv31926V2
1. Refer to Section Reset and clock control (RCC) for how the PCLK clock and ADC asynchronous clock are
enabled.
The input clock of the analog ADC can be selected between two different clock sources (see
Figure 32: ADC clock scheme to see how the PCLK clock and the ADC asynchronous clock
are enabled):
a) The ADC clock can be a specific clock source, named “ADC asynchronous clock“
which is independent and asynchronous with the APB clock.
Refer to RCC Section for more information on generating this clock source.
To select this scheme, bits CKMODE[1:0] of the ADC_CFGR2 register must be
reset.
b) The ADC clock can be derived from the APB clock of the ADC bus interface,
divided by a programmable factor (1, 2 or 4) according to bits CKMODE[1:0].
To select this scheme, bits CKMODE[1:0] of the ADC_CFGR2 register must be
different from “00”.
In option a), the generated ADC clock can eventually be divided by a prescaler (1, 2, 4, 6, 8,
10, 12, 16, 32, 64, 128, 256) when programming the bits PRESC[3:0] in the ADC_CCR
register).
Option a) has the advantage of reaching the maximum ADC clock frequency whatever the
APB clock scheme selected.
Option b) has the advantage of bypassing the clock domain resynchronizations. This can be
useful when the ADC is triggered by a timer and if the application requires that the ADC is
precisely triggered without any uncertainty (otherwise, an uncertainty of the trigger instant is
added by the resynchronizations between the two clock domains).
SYSCLK, or HSIKER
00 Latency is not deterministic (jitter)
clock(2)
Latency is deterministic (no jitter) and equal to
PCLK divided by 2 01
3.25 ADC clock cycles
Latency is deterministic (no jitter) and equal to
PCLK divided by 4 10
3.125 ADC clock cycles
Latency is deterministic (no jitter) and equal to
PCLK divided by 1 11
3 ADC clock cycles
1. Refer to the device datasheet for the maximum ADC_CLK frequency.
2. Selected with ADCSEL bitfield of the RCC_CCIPR register.
Caution: When selecting CKMODE[1:0] = 11 (PCLK divided by 1), the user must ensure that the
PCLK has a 50% duty cycle. This is done by selecting a system clock with a 50% duty cycle
and configuring the APB prescaler in bypass modes in the RCC (refer to there Reset and
clock controller section). If an internal source clock is selected, the AHB and APB prescalers
do not divide the clock.
ADC
Channel selection
VIN[0]
ADC_IN0
VIN[1]
ADC_IN1
VIN[2]
ADC_IN2
VIN[3]
ADC_IN3
VIN[4]
ADC_IN4
VIN[5]
ADC_IN5
VIN[6]
ADC_IN6
VIN[7]
ADC_IN7
VIN[8]
ADC_IN8
VSENSE VIN[9]
VDDA
VIN[10]
VREFINT
VIN[11]
ADC_IN11 VIN
SAR
VIN[12]
ADC_IN12 ADC1
VIN[13]
ADC_IN13
VIN[14]
ADC_IN14
VIN[15] VSSA
VDDA
VSSA VIN[16]
VIN[17]
ADC_IN17(1)
VIN[18]
ADC_IN18(1)
VIN[19]
ADC_IN19(1)
VIN[20]
ADC_IN20(1)
VIN[21]
ADC_IN21(1)
VIN[22]
ADC_IN22(1)
MSv68741V3
14.4.13 Timings
The elapsed time between the start of a conversion and the end of conversion is the sum of
the configured sampling time plus the successive approximation time depending on data
resolution:
tCONV = tSMPL + tSAR = 42.9 ns |min + 357.1 ns |12bit = 0.400 µs |min (for fADC_CLK = 35 MHz)
(3) (3)
WLATENCY WLATENCY WLATENCY (3)
ADC_DR
MSv33174V1
1. EXTEN = 00 or EXTEN ≠ 00
2. Trigger latency (refer to datasheet for more details)
3. ADC_DR register write latency (refer to datasheet for more details)
set by SW cleared by HW
ADSTOP
ADC_DR DATA N-1
MS30337V1
Note: The polarity of the external trigger can be changed only when the ADC is not converting
(ADSTART = 0).
The EXTSEL[2:0] control bits are used to select which of 8 possible events can trigger
conversions.
Refer to Table 53: External triggers in Section 14.4.1: ADC pins and internal signals for the
list of all the external triggers that can be used for regular conversion.
The software source trigger events can be generated by setting the ADSTART bit in the
ADC_CR register.
Note: The trigger selection can be changed only when the ADC is not converting (ADSTART = 0).
ADSTART(1)
EOC
EOS
SCANDIR
ADC state(2) RDY CH0 CH9 CH10 CH17 RDY CH17 CH10 CH9 CH0 RDY
by S/W by H/W
MSv30338V3
ADSTART(1)
EOC
EOS
ADSTP
SCANDIR
ADC state(2) RDY CH0 CH9 CH10 CH17 CH0 CH9 CH10 STP RDY CH17 CH10
by S/W by H/W
MSv30339V2
ADSTART(1)
EOC
EOS
TRGx(1)
ADC state(2) RDY CH0 CH1 CH2 CH3 RDY CH0 CH1 CH2 CH3 RDY
ADC_DR D0 D1 D2 D3 D0 D1 D2 D3
by S/W by H/W
triggered ignored
MSv30340V2
ADSTART(1)
EOC
EOS
ADSTP
TRGx(1)
ADC state(2) RDY CH0 CH1 CH2 CH3 CH0 CH1 CH2 CH3 CH0 STOP RDY
ADC_DR D0 D1 D2 D3 D0 D1 D2 D3
by S/W by H/W
triggered ignored
MSv30341V2
ALIGN RES 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MS30342V1
When an overrun condition occurs, the ADC keeps operating and can continue to convert
unless the software decides to stop and reset the sequence by setting the ADSTP bit in the
ADC_CR register.
The OVR flag is cleared by software by writing 1 to it.
It is possible to configure if the data is preserved or overwritten when an overrun event
occurs by programming the OVRMOD bit in the ADC_CFGR1 register:
• OVRMOD = 0
– An overrun event preserves the data register from being overwritten: the old data
is maintained and the new conversion is discarded. If OVR remains at 1, further
conversions can be performed but the resulting data is discarded.
• 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.
ADSTART(1)
EOC
EOS
OVR
ADSTP
TRGx(1)
ADC state(2)
RDY CH0 CH1 CH2 CH0 CH1 CH2 CH0 STOP RDY
ADC_DR
(OVRMOD=0) D0 D1 D2 D0
ADC_DR
(OVRMOD=1) D0 D1 D2 D0 D1 D2
by S/W by H/W
triggered
MSv30343V3
14.6.4 Managing converted data without using the DMA without overrun
It may be useful to let the ADC convert one or more channels without reading the data after
each conversion. In this case, the OVRMOD bit must be configured at 1 and the OVR flag
should be ignored by the software. When OVRMOD = 1, an overrun event does not prevent
the ADC from continuing to convert and the ADC_DR register always contains the latest
conversion data.
When the DMA transfer is complete (all the transfers configured in the DMA controller have
been done):
• The content of the ADC data register is frozen.
• Any ongoing conversion is aborted and its partial result discarded
• No new DMA request is issued to the DMA controller. This avoids generating an
overrun error if there are still conversions which are started.
• The scan sequence is stopped and reset
• The DMA is stopped
ADSTART
EOC
EOS
ADSTP
ADC state RDY CH1 DLY CH2 DLY CH3 DLY CH1 DLY STOP RDY
ADC_DR D1 D2 D3 D1
by S/W by H/W
MSv30344V2
Auto-off mode can be combined with the wait mode conversion (WAIT = 1) for applications
clocked at low frequency. This combination can provide significant power savings if the ADC
is automatically powered-off during the wait phase and restarted as soon as the ADC_DR
register is read by the application (see Figure 45: Behavior with WAIT = 1, AUTOFF = 1).
TRGx
EOC
EOS
ADC_DR Read
access
ADC state RDY Startup CH1 CH2 CH3 CH4 OFF Startup
ADC_DR D1 D2 D3 D4
by S/W by H/W
triggered
MSv30345V2
1. EXTSEL = TRGx, EXTEN = 01 (rising edge), CONT = x, ADSTART = 1, CHSEL = 0xF, SCANDIR = 0, WAIT = 1,
AUTOFF = 1
TRGx
EOC
EOS
ADC_DR Read
access DLY DLY DLY DLY
OFF
OFF
ADC state RDY Startup CH1 OFF Startup CH2 Startup CH3 OFF Startup CH1 CH2
D1 D2 D3 D4
ADC_DR
by S/W by H/W
triggered
MSv30346V2
1. EXTSEL = TRGx, EXTEN = 01 (rising edge), CONT = x, ADSTART = 1, CHSEL = 0xF, SCANDIR = 0, WAIT = 1,
AUTOFF = 1
Table 58 shows how to configure the AWD1SGL and AWD1EN bits in the ADC_CFGR1
register to enable the analog watchdog on one or more channels.
Analog voltage
MS45396V1
None x 0
All channels 0 1
(1)
Single channel 1 1
1. Selected by the AWD1CH[4:0] bits
The AWD comparison is performed at the end of each ADC conversion. The
ADC_AWDx_OUT rising edge and falling edge occurs two ADC_CLK clock cycles after the
comparison.
As ADC_AWDx_OUT is generated by the ADC_CLK domain and AWD flag is generated by
the APB clock domain, the rising edges of these signals are not synchronized.
ADC STATE RDY Conversion1 Conversion2 Conversion3 Conversion4 Conversion5 Conversion6 Conversion7
inside outside inside outside outside outside inside
EOC FLAG
ADC_AWDx_OUT
MSv45362V1
Figure 48. ADC_AWDx_OUT signal generation (AWDx flag not cleared by software)
ADC STATE RDY Conversion1 Conversion2 Conversion3 Conversion4 Conversion5 Conversion6 Conversion7
not cleared by SW
AWDx FLAG
ADC_AWDx_OUT
ADC STATE Conversion1 Conversion2 Conversion1 Conversion2 Conversion1 Conversion2 Conversion1 Conversion2
EOC FLAG
EOS FLAG
Cleared Cleared
by SW by SW
AWDx FLAG
ADCy_AWDx_OUT
MSv45364V1
Threshold updated
MSv45365V1
14.9 Oversampler
The oversampling unit performs data preprocessing to offload the CPU. It can handle
multiple conversions and average them into a single data with increased data width, up to
16-bit.
It provides a result with the following form, where N and M can be adjusted:
n = N–1
1
Result = ----- ×
M ∑ Conversion ( t n )
n=0
19 15 11 7 3 0
Raw 20-bit data
Shifting
15 0
Truncation
and rounding
MS31928V2
The Figure 52 gives a numerical example of the processing, from a raw 20-bit accumulated
data to the final 16-bit result.
19 15 11 7 3
Raw 20-bit data: 3 B 7 D 7
15 0
Final result after 5-bits shift
and rounding to nearest 1 D B F
MS31929V1
The Table 59 below gives the data format for the various N and M combination, for a raw
conversion data equal to 0xFFF.
Table 59. Maximum output results vs N and M. Grayed values indicates truncation
1-bit 2-bit 3-bit 4-bit 5-bit 6-bit 7-bit 8-bit
Oversa No-shift
Max shift shift shift shift shift shift shift shift
mpling OVSS =
ratio Raw data OVSS = OVSS = OVSS = OVSS = OVSS = OVSS = OVSS = OVSS =
0000
0001 0010 0011 0100 0101 0110 0111 1000
2x 0x1FFE 0x1FFE 0x0FFF 0x0800 0x0400 0x0200 0x0100 0x0080 0x0040 0x0020
4x 0x3FFC 0x3FFC 0x1FFE 0x0FFF 0x0800 0x0400 0x0200 0x0100 0x0080 0x0040
8x 0x7FF8 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x0800 0x0400 0x0200 0x0100 0x0080
16x 0xFFF0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x0800 0x0400 0x0200 0x0100
32x 0x1FFE0 0xFFE0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x0800 0x0400 0x0200
64x 0x3FFC0 0xFFC0 0xFFE0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x0800 0x0400
128x 0x7FF80 0xFF80 0xFFC0 0xFFE0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x0800
256x 0xFFF00 0xFF00 0xFF80 0xFFC0 0xFFE0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF
Trigger Trigger
MS33700V1
Main features
• Linearity: ±2 °C max., precision depending on calibration
Temperature + VSENSE
sensor ADC VIN[9]
-
Address/data bus
converted data
VREFEN control bit
ADC
+ VREFINT
Internal power ADC VIN[10]
block -
MSv68742V2
Where:
• TS_CAL1 is the temperature sensor calibration value acquired at TS_CAL1_TEMP
(refer to the datasheet for TS_CAL1 value)
• TS_DATA is the actual temperature sensor output value converted by ADC
Refer to the specific device datasheet for more information about TS_CAL1 calibration
point.
• Avg_Slope is the coefficient of the temperature sensor output voltage expressed in
mV/°C (refer to the datasheet for Avg_Slope value).
Note: The sensor has a startup time after waking from power down mode before it can output
VSENSE at the correct level. The ADC also has a startup time after power-on, so to minimize
the delay, the ADEN and TSEN bits should be set at the same time.
Calculating the actual VDDA voltage using the internal reference voltage
The VDDA power supply voltage applied to the device may be subject to variation or not
precisely known. The embedded internal voltage reference (VREFINT) and its calibration
data, acquired by the ADC during the manufacturing process at VDDA_Charac, can be used to
evaluate the actual VDDA voltage level.
The following formula gives the actual VDDA voltage supplying the device:
VDDA = VDDA_Charac x VREFINT_CAL / VREFINT_DATA
Where:
• VDDA_Charac is the value of VDDA voltage characterized at VREFINT during the
manufacturing process. It is specified in the device datasheet.
• VREFINT_CAL is the VREFINT calibration value
• VREFINT_DATA is the actual VREFINT output value converted by ADC
For applications where VDDA value is not known, you must use the internal voltage
reference and VDDA can be replaced by the expression provided in Section : Calculating the
actual VDDA voltage using the internal reference voltage, resulting in the following formula:
V DDA_Charac × VREFINT_CAL × ADC_DATA x
V CHANNELx = ---------------------------------------------------------------------------------------------------------------------------------
-
VREFINT_DATA × NUM_CODES
Where:
• VDDA_Charac is the value of VDDA voltage characterized at VREFINT during the
manufacturing process. It is specified in the device datasheet.
• VREFINT_CAL is the VREFINT calibration value
• ADC_DATAx is the value measured by the ADC on channelx (right-aligned)
• VREFINT_DATA is the actual VREFINT output value converted by the ADC
• NUM_CODES is the number of ADC output codes. For example with 12-bit resolution,
it is 212 = 4096 or with 8-bit resolution, 28 = 256.
Note: If ADC measurements are done using an output format other than 12 bit right-aligned, all the
parameters must first be converted to a compatible format before the calculation is done.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. CCRDY Res. EOCAL Res. AWD3 AWD2 AWD1 Res. Res. OVR EOS EOC EOSMP ADRDY
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCRD EOCAL AWD3I AWD2I AWD1I EOSMP ADRDY
Res. Res. Res. Res. Res. Res. OVRIE EOSIE EOCIE
YIE IE E E E IE IE
rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADVR
ADCAL Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
EGEN
rs rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADSTA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ADSTP Res. ADDIS ADEN
RT
rs rs rs rs
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AWD1E AWD1S CHSEL DISCE
Res. AWD1CH[4:0] Res. Res. Res. Res. Res. Res.
N GL RMOD N
rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AUTOF OVRM SCAND DMAC DMAE
WAIT CONT EXTEN[1:0] Res. EXTSEL[2:0] ALIGN RES[1:0]
F OD IR FG N
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CKMODE[1:0] LFTRIG Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. TOVS OVSS[3:0] OVSR[2:0] Res. OVSE
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE
Res.
L22 L21 L20 L19 L18 L17 L16 L15 L14 L13 L12 L11 L10 L9 L8
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE SMPSE
Res. SMP2[2:0] Res. SMP1[2:0]
L7 L6 L5 L4 L3 L2 L1 L0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL
Res. Res. Res. Res. Res. Res. Res. Res. Res.
22 21 20 19 18 17 16
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL CHSEL
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATA[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2
Res. Res. Res. Res. Res. Res. Res. Res. Res.
CH22 CH21 CH20 CH19 CH18 CH17 CH16
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2 AWD2
CH15 CH14 CH13 CH12 CH11 CH10 CH9 CH8 CH7 CH6 CH5 CH4 CH3 CH2 CH1 CH0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3
Res. Res. Res. Res. Res. Res. Res. Res. Res.
CH22 CH21 CH20 CH19 CH18 CH17 CH16
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3 AWD3
CH15 CH14 CH13 CH12 CH11 CH10 CH9 CH8 CH7 CH6 CH5 CH4 CH3 CH2 CH1 CH0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. CALFACT[6:0]
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
VREF
Res. Res. Res. Res. Res. Res. Res. Res. TSEN PRESC[3:0] Res. Res.
EN
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
10
11
9
8
7
6
5
4
3
2
1
0
name
CCRDY.
EOSMP
ADRDY
EOCAL
AWD3
AWD2
AWD1
OVR
EOC
EOS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_ISR
0x00
Reset value 0 0 0 0 0 0 0 0 0 0
CCRDYIE.
EOSMPIE
ADRDYIE
EOCALIE
AWD3IE
AWD2IE
AWD1IE
OVRIE
EOCIE
EOSIE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_IER
0x04
Reset value 0 0 0 0 0 0 0 0 0 0
ADVREGEN
ADSTART
ADCAL
ADSTP
ADDIS
ADEN
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_CR
0x08
Reset value 0 0 0 0 0 0
CHSELRMOD
EXTEN[1:0]
AWD1SGL
OVRMOD
SCANDIR
DMACFG
AWD1EN
AUTOFF
DISCEN
DMAEN
ALIGN
CONT
EXTSEL RES
WAIT
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_CFGR1 AWDCH[4:0]
0x0C [2:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0xB4
0xA4
0xA0
0x3C
0x2C
0x1C
0x308
Offset
296/825
1)
0)
name
ADC_DR
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
ADC_CCR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
ADC_SMPR
ADC_CFGR2
ADC_CHSELR
ADC_CHSELR
ADC_AWD3TR
ADC_AWD2TR
ADC_AWD1TR
ADC_AWD3CR
ADC_AWD2CR
(CHSELRMOD=
(CHSELRMOD=
ADC_CALFACT
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
CKMODE[1:0]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. SMPSEL22. 30
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. SMPSEL21. 0 LFTRIG 29
SQ8[3:0]
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. SMPSEL20. Res. 28
1
0
1
1
0
Res. Res. Res. Res. Res. Res. SMPSEL19. Res. 27
1
0
1
1
0
Res. Res. Res. Res. Res. Res. SMPSEL18. Res. 26
Analog-to-digital converter (ADC)
1
0
1
1
Res. Res. Res. Res. Res. Res. 0 SMPSEL17 Res. 25
SQ7[3:0]
1
0
1
1
0
Res. Res. Res. Res. Res. Res. SMPSEL16 Res. 24
1
0
1
1
0
0
TSEN Res. Res. Res. Res. Res. SMPSEL15 Res. 23
0
0
0
0
1
0
0
1
1
VREFEN Res. AWD3CH22 AWD2CH22 Res. CHSEL22 SMPSEL14 Res. 22
0
0
0
0
0
1
0
1
PRESC3 Res. AWD3CHL21 AWD2CHL21 Res. CHSEL21 1 SMPSEL13 Res. 21
SQ6[3:0]
HT3[11:0]
HT2[11:0]
HT1[11:0]
0
0
1
0
0
1
1
0
0
PRESC2 Res. AWD3CH20 AWD2CH20 Res. CHSEL20 SMPSEL12 Res. 20
0
0
0
1
0
1
1
0
0
0
0
1
0
0
1
1
0
0
1
0
1
1
RM0490 Rev 3
Res. Res. AWD3CH17 AWD2CH17 Res. CHSEL17 SMPSEL9 Res. 17
SQ5[3:0]
1
0
0
0
1
1
0
0
Res. Res. AWD3CH15 AWD2CH15 Res. CHSEL15 Res. Res. SMPSEL7 Res. 15
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
0
0 0 0 0
0 0 0 0
0
0 0
0
Res. Res. AWD3CH14 AWD2CH14 Res. CHSEL14 Res. Res. SMPSEL6 Res. 14
0
0
0
0
0
0
Res. Res. AWD3CH13 AWD2CH13 Res. CHSEL13 Res. Res. SMPSEL5 Res.
0
0
0
0
Res. Res. AWD3CH12 AWD2CH12 Res. CHSEL12 Res. Res. SMPSEL4 Res. 12
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
0
0
0
0
0
0
0
0
0
DATA[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
LT3[11:0]
LT2[11:0]
LT1[11:0]
SQ2[3:0]
SMP2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
CALFACT[6:0]
0
0
0
0
0
0
0
0
0
0
0
SQ1[3:0]
SMP1
OVSE
0
0
0
0
0
0
0
0
0
0
0
In this section, “TIMx” should be understood as “TIM1” since there is only one instance of
this type of timer for the products to which this reference manual applies.
TI1FP1 Encoder
TI2FP2 Interface
REP register
U UI
Auto-reload register
Repetition
Stop, clear or up/down U
counter
CK_PSC PSC CK_CNT +/-
XOR CNT counter
prescaler DTG registers
CC1I U CC1I
TI1[0] TI1 Input TIMx_CH1
TIMx_CH1 TI1FP1 OC1REF
filter & IC1 IC1PS Output OC1
TI1FP2 Prescaler Capture/Compare 1 register
TI1[1..15] edge DTG
control TIMx_CH1N
detector TRC
CC2I OC1N
U CC2I TIMx_CH2
TI2[0] Input TI2FP1
TIMx_CH2 IC2 OC2
TI2 filter & TI2FP2 Output
Prescaler
IC2PS Capture/Compare 2 register OC2REF
TI2[1..15] edge DTG control TIMx_CH2N
detector TRC OC2N
Output OC5
Capture/Compare 5 register OC5REF
control
Output OC6
Capture/Compare 6 register OC6REF
control
Internal
sources SBIF
ETRF
BIF
TIMx_BKIN BRK request
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit register (in the TIMx_PSC register).
It can be changed on the fly as this control register is buffered. The new prescaler ratio is
taken into account at the next update event.
Figure 56 and Figure 57 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 56. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
MS31076V2
Figure 57. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Timerclock = CK_CNT
F7 F8 F9 FA FB FC 00 01
Counter register
0 3
Prescaler control register
0 3
Prescaler buffer
0 0 1 2 3 0 1 2 3
Prescaler counter
MS31077V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
MS31078V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
MS31079V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
MS31080V2
CK_PSC
Timerclock = CK_CNT
Counter register 1F 20 00
Counter overflow
MS31081V2
Figure 62. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Figure 63. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload shadow
register F5 36
Downcounting mode
In downcounting mode, the counter counts from the auto-reload value (content of the
TIMx_ARR register) down to 0, then restarts from the auto-reload value and generates a
counter underflow event.
If the repetition counter is used, the update event (UEV) is generated after downcounting is
repeated for the number of times programmed in the repetition counter register
(TIMx_RCR) + 1. Else the update event is generated at each counter underflow.
Setting the UG bit in the TIMx_EGR register (by software or by using the slave mode
controller) also generates an update event.
The UEV update event can be disabled by software by setting the UDIS bit in TIMx_CR1
register. This is to avoid updating the shadow registers while writing new values in the
preload registers. Then no update event occurs until UDIS bit has been written to 0.
However, the counter restarts from the current auto-reload value, whereas the counter of the
prescaler restarts from 0 (but the prescale rate doesn’t change).
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or
DMA request is sent). This is to avoid generating both update and capture interrupts when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The repetition counter is reloaded with the content of TIMx_RCR register.
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that the auto-reload is updated before the counter is
reloaded, so that the next period is the expected one.
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
(cnt_udf)
MS31184V1
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
MS31185V1
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
MS31186V1
CK_PSC
Timerclock = CK_CNT
Counter register 20 1F 00 36
Counter underflow
MS31187V1
Figure 68. Counter timing diagram, update event when repetition counter is not used
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
Auto-reload preload
register FF 36
DMA request is sent). This is to avoid generating both update and capture interrupts when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The repetition counter is reloaded with the content of TIMx_RCR register
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register)
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that if the update source is a counter overflow, the auto-
reload is updated before the counter is reloaded, so that the next period is the expected
one (the counter is loaded with the new value).
The following figures show some examples of the counter behavior for different clock
frequencies.
Figure 69. Counter timing diagram, internal clock divided by 1, TIMx_ARR = 0x6
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 04 03 02 01 00 01 02 03 04 05 06 05 04 03
Counter underflow
Counter overflow
1. Here, center-aligned mode 1 is used (for more details refer to Section 15.4: TIM1 registers).
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
MS31190V1
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_PSC
Timerclock = CK_CNT
Counter register 20 1F 01 00
Counter underflow
MS31192V1
Figure 73. Counter timing diagram, update event with ARPE=1 (counter underflow)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 06 05 04 03 02 01 00 01 02 03 04 05 06 07
Counter underflow
Auto-reload preload
register FD 36
Auto-reload active
register FD 36
MS31193V1
Figure 74. Counter timing diagram, Update event with ARPE=1 (counter overflow)
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 36 35 34 33 32 31 30 2F
Counter overflow
MS31194V1
In Center aligned mode, for odd values of RCR, the update event occurs either on the
overflow or on the underflow depending on when the RCR register was written and when
the counter was launched: if the RCR was written before launching the counter, the UEV
occurs on the underflow. If the RCR was written after launching the counter, the UEV occurs
on the overflow.
For example, for RCR = 3, the UEV is generated each 4th overflow or underflow event
depending on when the RCR was written.
Figure 75. Update rate examples depending on mode and TIMx_RCR register settings
TIMx_RCR = 0
UEV
TIMx_RCR = 1
UEV
UEV
TIMx_RCR = 2
TIMx_RCR = 3 UEV
TIMx_RCR = 3
and
UEV
re-synchronization
(by SW) (by SW) (by SW)
UEV Update event: Preload registers transferred to active registers and update interrupt generated
Update Event if the repetition counter underflow occurs when the counter is equal to the auto-reload value.
MSv31195V1
ETR
ETR input 0 ETRP To the Output mode controller
Divider Filter
To the CK_PSC circuitry
1 /1, /2, /4, /8 fDTS downcounter
To the Slave mode controller
The ETR input comes from multiple sources: input pins (default configuration) and analog
watchdogs. The selection is done with the ETRSEL[3:0] bitfield.
TIM1_AF1[17:14]
ETR input
NC
MSv50978V1
Internal clock
CEN=CNT_EN
UG
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MSv31085V3
or TI2F or
TI1F or Encoder
ITRx mode
000xx
TIMx_CH2 TI1_ED TRGI External clock
00100
TI1FP1 00101 mode 1 CK_PSC
TI2[0]
TI2F_Rising
TI2 Edge 0 TI2FP2 00110 ETRF External clock
TI2[1..15] Filter
detector 1 ETRF 00111 mode 2
TI2F_Falling
(1) CK_INT Internal clock
ICF[3:0] CC2P (internal clock) mode
TIMx_CCMR1 TIMx_CCER
ECE SMS[2:0]
TIMx_SMCR
MSv40117V1
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
MS31087V2
or TI2F or
TI1F or Encoder
mode
TIMx_AF1[17:14]
TRGI
External clock
ETR pin ETR mode 1 CK_PSC
0
Divider ETRP ETRF External clock
Filter
1 /1, /2, /4, /8 f downcounter mode 2
(1) DTS
ECE SMS[2:0]
TIMx_SMCR
MSv40118V1
f CK_INT
CNT_EN
ETR
ETRP
ETRF
Counter clock =
CK_CNT =CK_PSC
Counter register 34 35 36
MSv33111V3
TI1F_ED
TI1[0]
TIMx_CH1 To the slave mode controller
TI1[1..15]
Filter TI1F_Rising
downcounter TI1F Edge 0 TI1FP1
fDTS TI1F_Falling 01
detector 1
TI2FP1 IC1 Divider IC1PS
10 /1, /2, /4, /8
ICF[3:0] CC1P/CC1NP
TRC
11
TIMx_CCMR1 TIMx_CCER (from slave mode
TI2F_Rising controller)
0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_Falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
MSv40120V2
The output stage generates an intermediate waveform which is then used for reference:
OCxRef (active high). The polarity acts at the end of the chain.
APB Bus
MCU-peripheral interface
CC1S[1]
CC1S[0] Capture/compare preload register
CC1S[1]
MSv63030V1
Figure 85. Output stage of capture/compare channel (channel 1, idem ch. 2 and 3)
TIMx_SMCR
OCCS
OCREF_CLR To the master mode
0
controller
ETRF 0 Output
1 OC1
enable
‘0’ 1
x0 circuit
ocref_clr_int OC1REF OC1REFC
01
OC1_DT CC1P
CNT>CCR1 Output 11
Output Dead-time TIM1_CCER
mode
CNT=CCR1 selector generator
controller OC1N_DT
11
10 0
(1) Output OC1N
OCxREF ‘0’ 0x enable
OC5REF 1 circuit
OIS1 OIS1N
TIM1_CR2
MS31199V2
TIMx_SMCR
OCCS
CC4E CC4P
OC3REF
TIM1_CCER TIM1_CCER CC4E TIM1_CCER
TIMx_SMCR
OCCS
ocref_clr_int
‘0’ 0 0 (1)
CNT > CCR5 Output OC5
Output enable
OC5REF
mode 1 1 circuit
CNT = CCR5
controller
CC5E CC5P
TIM1_CCER TIM1_CCER CC5E TIM1_CCER
OC5CE OC5M[3:0]
MOE OSSI TIM1_BDTR
TIM1_CCMR2
OIS5 TIM1_CR2
MS33101V2
detected (sampled at fDTS frequency). Then write IC1F bits to 0011 in the
TIMx_CCMR1 register.
4. Select the edge of the active transition on the TI1 channel by writing CC1P and CC1NP
bits to 0 in the TIMx_CCER register (rising edge in this case).
5. Program the input prescaler. In our example, we wish the capture to be performed at
each valid transition, so the prescaler is disabled (write IC1PS bits to ‘00’ in the
TIMx_CCMR1 register).
6. Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
7. If needed, enable the related interrupt request by setting the CC1IE bit in the
TIMx_DIER register, and/or the DMA request by setting the CC1DE bit in the
TIMx_DIER register.
When an input capture occurs:
• The TIMx_CCR1 register gets the value of the counter on the active transition.
• CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures
occurred whereas the flag was not cleared.
• An interrupt is generated depending on the CC1IE bit.
• A DMA request is generated depending on the CC1DE bit.
In order to handle the overcapture, it is recommended to read the data before the
overcapture flag. This is to avoid missing an overcapture which could happen after reading
the flag and before reading the data.
Note: IC interrupt and/or DMA requests can be generated by software by setting the
corresponding CCxG bit in the TIMx_EGR register.
1. Select the proper TI1x source (internal or external) with the TI1SEL[3:0] bits in the
TIMx_TISEL register.
2. Select the active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1
register (TI1 selected).
3. Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter
clear): write the CC1P and CC1NP bits to ‘0’ (active on rising edge).
4. Select the active input for TIMx_CCR2: write the CC2S bits to 10 in the TIMx_CCMR1
register (TI1 selected).
5. Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P
and CC2NP bits to CC2P/CC2NP=’10’ (active on falling edge).
6. Select the valid trigger input: write the TS bits to 00101 in the TIMx_SMCR register
(TI1FP1 selected).
7. Configure the slave mode controller in reset mode: write the SMS bits to 0100 in the
TIMx_SMCR register.
8. Enable the captures: write the CC1E and CC2E bits to ‘1’ in the TIMx_CCER register.
Procedure
1. Select the counter clock (internal, external, prescaler).
2. Write the desired data in the TIMx_ARR and TIMx_CCRx registers.
3. Set the CCxIE bit if an interrupt request is to be generated.
4. Select the output mode. For example:
– Write OCxM = 0011 to toggle OCx output pin when CNT matches CCRx
– Write OCxPE = 0 to disable preload register
– Write CCxP = 0 to select active high polarity
– Write CCxE = 1 to enable the output
5. Enable the counter by setting the CEN bit in the TIMx_CR1 register.
The TIMx_CCRx register can be updated at any time by software to control the output
waveform, provided that the preload register is not enabled (OCxPE=’0’, else TIMx_CCRx
shadow register is updated only at the next update event UEV). An example is given in
Figure 89.
OC1REF= OC1
MS31092V1
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘1’
CCRx>8
CCxIF
OCXREF ‘0’
CCRx=0
CCxIF
MS31093V1
• Downcounting configuration
Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to the
Downcounting mode on page 306
In PWM mode 1, the reference signal OCxRef is low as long as
TIMx_CNT > TIMx_CCRx else it becomes high. If the compare value in TIMx_CCRx is
greater than the auto-reload value in TIMx_ARR, then OCxREF is held at ‘1’. 0% PWM
is not possible in this mode.
TIMx_CR1 register is updated by hardware and must not be changed by software. Refer to
the Center-aligned mode (up/down counting) on page 309.
Figure 91 shows some center-aligned PWM waveforms in an example where:
• TIMx_ARR=8,
• PWM mode is the PWM mode 1,
• The flag is set when the counter counts down corresponding to the center-aligned
mode 1 selected for CMS=01 in TIMx_CR1 register.
Counter register 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1
OCxREF
CCRx = 4
CCxIF CMS=01
CMS=10
CMS=11
OCxREF
CCRx=7
CMS=10 or 11
CCxIF
‘1’
OCxREF
CCRx=8
CCxIF CMS=01
CMS=10
CMS=11
‘1’
OCxREF
CCRx>8
CCxIF CMS=01
CMS=10
CMS=11
‘0’
OCxREF
CCRx=0
CCxIF CMS=01
CMS=10
CMS=11
AI14681b
in the TIMx_CR1 register. Moreover, the DIR and CMS bits must not be changed at the
same time by the software.
• Writing to the counter while running in center-aligned mode is not recommended as it
can lead to unexpected results. In particular:
– The direction is not updated if a value greater than the auto-reload value is written
in the counter (TIMx_CNT>TIMx_ARR). For example, if the counter was counting
up, it continues to count up.
– The direction is updated if 0 or the TIMx_ARR value is written in the counter but no
Update Event UEV is generated.
• The safest way to use center-aligned mode is to generate an update by software
(setting the UG bit in the TIMx_EGR register) just before starting the counter and not to
write the counter while it is running.
Figure 92. Generation of 2 phase-shifted PWM signals with 50% duty cycle
Counter register 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1
OC1REFC
CCR1=0
CCR2=8
OC3REFC
CCR3=3
CCR4=5
MS33117V1
OC2’
OC1’
OC2
OC1
OC1REF
OC2REF
OC1REF’
OC2REF’
OC1REFC
OC1REFC’
MS31094V1
Figure 94. 3-phase combined PWM signals with multiple trigger pulses per period
ARR
OC5
OC6
OC1
OC4
OC2
OC3
Counter
OC5ref
OC1refC
OC2refC
GC5C[3:0]
OC3refC
OC4ref
OC6ref
TRGO2
MS33102V1
The TRGO2 waveform shows how the ADC can be synchronized on given 3-phase PWM
signals. Refer to Section 15.3.27: ADC synchronization for more details.
Dead-time insertion is enabled by setting both CCxE and CCxNE bits, and the MOE bit if the
break circuit is present. There is one 10-bit dead-time generator for each channel. From a
reference waveform OCxREF, it generates 2 outputs OCx and OCxN. If OCx and OCxN are
active high:
• The OCx output signal is the same as the reference signal except for the rising edge,
which is delayed relative to the reference rising edge.
• The OCxN output signal is the opposite of the reference signal except for the rising
edge, which is delayed relative to the reference falling edge.
If the delay is greater than the width of the active output (OCx or OCxN) then the
corresponding pulse is not generated.
The following figures show the relationships between the output signals of the dead-time
generator and the reference signal OCxREF. (we suppose CCxP=0, CCxNP=0, MOE=1,
CCxE=1 and CCxNE=1 in these examples)
OCxREF
OCx
delay
OCxN
delay
MS31095V1
Figure 96. Dead-time waveforms with delay greater than the negative pulse
OCxREF
OCx
delay
OCxN
MS31096V1
Figure 97. Dead-time waveforms with delay greater than the positive pulse
OCxREF
OCx
OCxN
delay
MS31097V1
The dead-time delay is the same for each of the channels and is programmable with the
DTG bits in the TIMx_BDTR register. Refer to Section 15.4.20: TIM1 break and dead-time
register (TIM1_BDTR) for delay calculation.
The output enable signal and output levels during break are depending on several control
bits:
– the MOE bit in TIMx_BDTR register allows the outputs to be enabled/disabled by
software and is reset in case of break or break2 event.
– the OSSI bit in the TIMx_BDTR register defines whether the timer controls the
output in inactive state or releases the control to the GPIO controller (typically to
have it in Hi-Z mode)
– the OISx and OISxN bits in the TIMx_CR2 register which are setting the output
shut-down level, either active or inactive. The OCx and OCxN outputs cannot be
set both to active level at a given time, whatever the OISx and OISxN values.
Refer to Table 66: Output control bits for complementary OCx and OCxN channels
with break feature on page 378 for more details.
When exiting from reset, the break circuit is disabled and the MOE bit is low. The break
functions can be enabled by setting the BKE and BK2E bits in the TIMx_BDTR register. The
break input polarities can be selected by configuring the BKP and BK2P bits in the same
register. BKE/BK2E and BKP/BK2P can be modified at the same time. When the BKE/BK2E
and BKP/BK2P bits are written, a delay of 1 APB clock cycle is applied before the writing is
effective. Consequently, it is necessary to wait 1 APB clock period to correctly read back the
bit after the write operation.
Because MOE falling edge can be asynchronous, a resynchronization circuit has been
inserted between the actual signal (acting on the outputs) and the synchronous control bit
(accessed in the TIMx_BDTR register). It results in some delays between the asynchronous
and the synchronous signals. In particular, if MOE is set to 1 whereas it was low, a delay
must be inserted (dummy instruction) before reading it correctly. This is because the write
acts on the asynchronous signal whereas the read reflects the synchronous signal.
The break can be generated from multiple sources which can be individually enabled and
with programmable edge sensitivity, using the TIMx_OR2 and TIMx_OR3 registers.
The sources for break (BRK) channel are:
• An external source connected to one of the BKIN pin (as per selection done in the
GPIO alternate function registers), with polarity selection and optional digital filtering
• An internal source:
– the Cortex®-M0+ LOCKUP output
– the SRAM parity error signal
– a clock failure event generated by the CSS detector
The source for break2 (BRK2) is an external source connected to one of the BKIN pin (as
per selection done in the GPIO alternate function registers), with polarity selection and
optional digital filtering.
Break events can also be generated by software using BG and B2G bits in the TIMx_EGR
register. The software break generation using BG and B2G is active whatever the BKE and
BK2E enable bits values.
All sources are ORed before entering the timer BRK or BRK2 inputs, as per Figure 98
below.
Lockup LOCK
Core Lockup
Parity LOCK
RAM parity Error
CSS
BIF flag
BKE
B2IF flag
BK2E
Note: An asynchronous (clockless) operation is only guaranteed when the programmable filter is
disabled. If it is enabled, a fail safe clock mode (for example by using the CSS) must be
used to guarantee that break events are handled.
When one of the breaks occurs (selected level on one of the break inputs):
• The MOE bit is cleared asynchronously, putting the outputs in inactive state, idle state
or even releasing the control to the GPIO controller (selected by the OSSI bit). This
feature is enabled even if the MCU oscillator is off.
• Each output channel is driven with the level programmed in the OISx bit in the
TIMx_CR2 register as soon as MOE=0. If OSSI=0, the timer releases the output control
(taken over by the GPIO controller), otherwise the enable output remains high.
• When complementary outputs are used:
– The outputs are first put in inactive state (depending on the polarity). This is done
asynchronously so that it works even if no clock is provided to the timer.
– If the timer clock is still present, then the dead-time generator is reactivated in
order to drive the outputs with the level programmed in the OISx and OISxN bits
after a dead-time. Even in this case, OCx and OCxN cannot be driven to their
active level together. Note that because of the resynchronization on MOE, the
dead-time duration is slightly longer than usual (around 2 ck_tim clock cycles).
– If OSSI=0, the timer releases the output control (taken over by the GPIO controller
which forces a Hi-Z state), otherwise the enable outputs remain or become high as
soon as one of the CCxE or CCxNE bits is high.
• The break status flag (SBIF, BIF and B2IF bits in the TIMx_SR register) is set. An
interrupt is generated if the BIE bit in the TIMx_DIER register is set.
• If the AOE bit in the TIMx_BDTR register is set, the MOE bit is automatically set again
at the next update event (UEV). As an example, this can be used to perform a
regulation. Otherwise, MOE remains low until the application sets it to ‘1’ again. In this
case, it can be used for security and the break input can be connected to an alarm from
power drivers, thermal sensors or any security components.
Note: If the MOE is reset by the CPU while the AOE bit is set, the outputs are in idle state and
forced to inactive level or Hi-Z depending on OSSI value.
If both the MOE and AOE bits are reset by the CPU, the outputs are in disabled state and
driven with the level programmed in the OISx bit in the TIMx_CR2 register.
Note: The break inputs are active on level. Thus, the MOE cannot be set while the break input is
active (neither automatically nor by software). In the meantime, the status flag BIF and B2IF
cannot be cleared.
In addition to the break input and the output management, a write protection has been
implemented inside the break circuit to safeguard the application. It allows the configuration
of several parameters to be freezed (dead-time duration, OCx/OCxN polarities and state
when disabled, OCxM configurations, break enable and polarity). The application can
choose from 3 levels of protection selected by the LOCK bits in the TIMx_BDTR register.
Refer to Section 15.4.20: TIM1 break and dead-time register (TIM1_BDTR). The LOCK bits
can be written only once after an MCU reset.
Figure 99 shows an example of behavior of the outputs in response to a break.
Figure 99. Various output behavior in response to a break event on BRK (OSSI = 1)
BREAK (MOE )
OCxREF
OCx
(OCxN not implemented, CCxP=0, OISx=1)
OCx
(OCxN not implemented, CCxP=0, OISx=0)
OCx
(OCxN not implemented, CCxP=1, OISx=1)
OCx
(OCxN not implemented, CCxP=1, OISx=0)
OCx
OCx
OCx
OCxN delay
(CCxE=1, CCxP=0, OISx=0, CCxNE=0, CCxNP=0, OISxN=1)
OCx
OCxN delay
(CCxE=1, CCxP=0, OISx=1, CCxNE=0, CCxNP=0, OISxN=0)
OCx
OCxN
(CCxE=1, CCxP=0, CCxNE=0, CCxNP=0, OISx=OISxN=0 or OISx=OISxN=1)
MS31098V1
– Inactive then
forced output
state (after a
deadtime)
ON after deadtime
Active X – Outputs disabled OFF
insertion
if OSSI = 0
(control taken
over by GPIO
logic)
Inactive Active Inactive OFF OFF
Figure 100 gives an example of OCx and OCxN output behavior in case of active signals on
BRK and BRK2 inputs. In this case, both outputs have active high polarities (CCxP =
CCxNP = 0 in TIMx_CCER register).
Figure 100. PWM output state following BRK and BRK2 pins assertion (OSSI=1)
BRK2
BRK
OCx
Deadtime Deadtime
I/O state
BRK
0 0 X Armed
0 1 0 Armed
0 1 1 Disarmed
1 X X Armed
AF output
(open drain)
MSv42028V2
The OCxREF signal of a given channel can be cleared when a high level is applied on the
ocref_clr_int input (OCxCE enable bit in the corresponding TIMx_CCMRx register set to 1).
OCxREF remains low until the next transition to the active state, on the following PWM
cycle. This function can only be used in Output compare and PWM modes. It does not work
in Forced mode. ocref_clr_int input can be selected between the OCREF_CLR input and
ETRF (ETR after the filter) by configuring the OCCS bit in the TIMx_SMCR register.
When ETRF is chosen, ETR must be configured as follows:
1. The External Trigger Prescaler should be kept off: bits ETPS[1:0] of the TIMx_SMCR
register set to ‘00’.
2. The external clock mode 2 must be disabled: bit ECE of the TIMx_SMCR register set to
‘0’.
3. The External Trigger Polarity (ETP) and the External Trigger Filter (ETF) can be
configured according to the user needs.
Figure 103 shows the behavior of the OCxREF signal when the ETRF Input becomes High,
for both values of the enable bit OCxCE. In this example, the timer TIMx is programmed in
PWM mode.
(CCRx)
Counter (CNT)
ETRF
OCxREF
(OCxCE = ‘0’)
OCxREF
(OCxCE = ‘1’)
ocref_clr_int ocref_clr_int
becomes high still high
MS33105V2
Note: In case of a PWM with a 100% duty cycle (if CCRx>ARR), then OCxREF is enabled again at
the next counter overflow.
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY tPULSE t
MS31099V1
For example one may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
Let’s use TI2FP2 as trigger 1:
1. Select the proper TI2x source (internal or external) with the TI2SEL[3:0] bits in the
TIMx_TISEL register.
2. Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.
3. TI2FP2 must detect a rising edge, write CC2P=’0’ and CC2NP=’0’ in the TIMx_CCER
register.
4. Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=00110
in the TIMx_SMCR register.
5. TI2FP2 is used to start the counter by writing SMS to ‘110’ in the TIMx_SMCR register
(trigger mode).
The OPM waveform is defined by writing the compare registers (taking into account the
clock frequency and the counter prescaler).
• The tDELAY is defined by the value written in the TIMx_CCR1 register.
• The tPULSE is defined by the difference between the auto-reload value and the compare
value (TIMx_ARR - TIMx_CCR1).
• Let’s say one want to build a waveform with a transition from ‘0’ to ‘1’ when a compare
match occurs and a transition from ‘1’ to ‘0’ when the counter reaches the auto-reload
value. To do this PWM mode 2 must be enabled by writing OC1M=111 in the
TIMx_CCMR1 register. Optionally the preload registers can be enabled by writing
OC1PE=’1’ in the TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this
case one has to write the compare value in the TIMx_CCR1 register, the auto-reload
value in the TIMx_ARR register, generate an update by setting the UG bit and wait for
external trigger event on TI2. CC1P is written to ‘0’ in this example.
In our example, the DIR and CMS bits in the TIMx_CR1 register should be low.
Since only 1 pulse (Single mode) is needed, a 1 must be written in the OPM bit in the
TIMx_CR1 register to stop the counter at the next update event (when the counter rolls over
from the auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0',
so the Repetitive Mode is selected.
Particular case: OCx fast enable:
In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the
counter. Then the comparison between the counter and the compare value makes the
output toggle. But several clock cycles are needed for these operations and it limits the
minimum delay tDELAY min we can get.
If one wants to output a waveform with the minimum delay, the OCxFE bit can be set in the
TIMx_CCMRx register. Then OCxRef (and OCx) are forced in response to the stimulus,
without taking in account the comparison. Its new level is the same as if a compare match
had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.
TRGI
Counter
Output
MS33106V2
A quadrature encoder can be connected directly to the MCU without external interface logic.
However, comparators are normally be used to convert the encoder’s differential outputs to
digital signals. This greatly increases noise immunity. The third encoder output which
indicate the mechanical zero position, may be connected to an external interrupt input and
trigger a counter reset.
The Figure 107 gives an example of counter operation, showing count signal generation
and direction control. It also shows how input jitter is compensated where both edges are
selected. This might occur if the sensor is positioned near to one of the switching points. For
this example we assume that the configuration is the following:
• CC1S=’01’ (TIMx_CCMR1 register, TI1FP1 mapped on TI1).
• CC2S=’01’ (TIMx_CCMR2 register, TI1FP2 mapped on TI2).
• CC1P=’0’ and CC1NP=’0’ (TIMx_CCER register, TI1FP1 non-inverted, TI1FP1=TI1).
• CC2P=’0’ and CC2NP=’0’ (TIMx_CCER register, TI1FP2 non-inverted, TI1FP2= TI2).
• SMS=’011’ (TIMx_SMCR register, both inputs are active on both rising and falling
edges).
• CEN=’1’ (TIMx_CR1 register, Counter enabled).
TI1
TI2
Counter
up down up
MS33107V1
Figure 108 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=’1’).
Figure 108. Example of encoder interface mode with TI1FP1 polarity inverted.
TI1
TI2
Counter
down up down
MS33108V1
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. Dynamic information can be obtained (speed, acceleration, deceleration)
by measuring the period between two encoder events using a second timer configured in
capture mode. The output of the encoder which indicates the mechanical zero can be used
for this purpose. Depending on the time between two events, the counter can also be read
at regular times. This can be done by latching the counter value into a third input capture
register if available (then the capture signal must be periodic and can be generated by
another timer). when available, it is also possible to read its value through a DMA request.
The IUFREMAP bit in the TIMx_CR1 register forces a continuous copy of the update
interrupt flag (UIF) into the timer counter register’s bit 31 (TIMxCNT[31]). This allows both
the counter value and a potential roll-over condition signaled by the UIFCPY flag to be read
in an atomic way. It eases the calculation of angular speed by avoiding race conditions
caused, for instance, by a processing shared between a background task (counter reading)
and an interrupt (update interrupt).
There is no latency between the UIF and UIFCPY flag assertions.
In 32-bit timer implementations, when the IUFREMAP bit is set, bit 31 of the counter is
overwritten by the UIFCPY flag upon read access (the counter’s most significant bit is only
accessible in write mode).
TI1
TI2
TI3
XOR
TIMx
Counter
MS33109V1
Example: one wants to change the PWM configuration of the advanced-control timer TIM1
after a programmed delay each time a change occurs on the Hall inputs connected to one of
the TIMx timers.
• Configure 3 timer inputs ORed to the TI1 input channel by writing the TI1S bit in the
TIMx_CR2 register to ‘1’,
• Program the time base: write the TIMx_ARR to the max value (the counter must be
cleared by the TI1 change. Set the prescaler to get a maximum counter period longer
than the time between 2 changes on the sensors,
• Program the channel 1 in capture mode (TRC selected): write the CC1S bits in the
TIMx_CCMR1 register to ‘01’. The digital filter can also be programmed if needed,
• Program the channel 2 in PWM 2 mode with the desired delay: write the OC2M bits to
‘111’ and the CC2S bits to ‘00’ in the TIMx_CCMR1 register,
• Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
register to ‘101’,
In the advanced-control timer TIM1, the right ITR input must be selected as trigger input, the
timer is programmed to generate PWM signals, the capture/compare control signals are
preloaded (CCPC=1 in the TIMx_CR2 register) and the COM event is controlled by the
trigger input (CCUS=1 in the TIMx_CR2 register). The PWM control bits (CCxE, OCxM) are
written after a COM event for the next step (this can be done in an interrupt subroutine
generated by the rising edge of OC2REF).
The Figure 110 describes this example.
TIH1
TIH2
Interfacing timer
TIH3
Counter (CNT)
(CCR2)
TRGO=OC2REF
COM
OC1
Advanced-control timers (TIM1)
OC1N
OC2
OC2N
OC3
OC3N
MS32672V1
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
MS31401V1
TI1
cnt_en
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
MS31402V1
register. Write CC2P=1 and CC2NP=0 in TIMx_CCER register to validate the polarity
(and detect low level only).
• Configure the timer in trigger mode by writing SMS=110 in TIMx_SMCR register. Select
TI2 as the input source by writing TS=00110 in TIMx_SMCR register.
When a rising edge occurs on TI2, the counter starts counting on the internal clock and the
TIF flag is set.
The delay between the rising edge on TI2 and the actual start of the counter is due to the
resynchronization circuit on TI2 input.
TI2
cnt_en
Counter register 34 35 36 37 38
TIF
MS31403V1
In the following example, the upcounter is incremented at each rising edge of the ETR
signal as soon as a rising edge of TI1 occurs:
1. Configure the external trigger input circuit by programming the TIMx_SMCR register as
follows:
– ETF = 0000: no filter
– ETPS = 00: prescaler disabled
– ETP = 0: detection of rising edges on ETR and ECE=1 to enable the external clock
mode 2.
2. Configure the channel 1 as follows, to detect rising edges on TI:
– IC1F = 0000: no filter.
– The capture prescaler is not used for triggering and does not need to be
configured.
– CC1S = 01in TIMx_CCMR1 register to select only the input capture source
– CC1P = 0 and CC1NP = 0 in TIMx_CCER register to validate the polarity (and
detect rising edge only).
3. Configure the timer in trigger mode by writing SMS=110 in TIMx_SMCR register. Select
TI1 as the input source by writing TS=00101 in TIMx_SMCR register.
A rising edge on TI1 enables the counter and sets the TIF flag. The counter then counts on
ETR rising edges.
The delay between the rising edge of the ETR signal and the actual reset of the counter is
due to the resynchronization circuit on ETRP input.
TI1
CEN/CNT_EN
ETR
Counter register 34 35 36
TIF
MS33110V1
Note: The clock of the slave peripherals (timer, ADC, ...) receiving the TRGO or the TRGO2
signals must be enabled prior to receive events from the master timer, and the clock
frequency (prescaler) must not be changed on-the-fly while triggers are received from the
master timer.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UIFRE
Res. Res. Res. Res. Res. CKD[1:0] ARPE CMS[1:0] DIR OPM URS UDIS CEN
MAP
rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. MMS2[3:0] Res. OIS6 Res. OIS5
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. OIS4 OIS3N OIS3 OIS2N OIS2 OIS1N OIS1 TI1S MMS[2:0] CCDS CCUS Res. CCPC
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TS[4:3] Res. Res. Res. SMS[3]
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ETP ECE ETPS[1:0] ETF[3:0] MSM TS[2:0] OCCS SMS[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. TDE COMDE CC4DE CC3DE CC2DE CC1DE UDE BIE TIE COMIE CC4IE CC3IE CC2IE CC1IE UIE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CC6IF CC5IF
rc_w0 rc_w0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. SBIF CC4OF CC3OF CC2OF CC1OF B2IF BIF TIF COMIF CC4IF CC3IF CC2IF CC1IF UIF
rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. B2G BG TG COMG CC4G CC3G CC2G CC1G UG
w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IC2F[3:0] IC2PSC[1:0] CC2S[1:0] IC1F[3:0] IC1PSC[1:0] CC1S[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
corresponding CCxS bits. All the other bits of this register have a different function for input
capture and for output compare modes. It is possible to combine both modes independently
(e.g. channel 1 in input capture mode and channel 2 in output compare mode).
Output compare mode:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. OC2M[3] Res. Res. Res. Res. Res. Res. Res. OC1M[3]
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OC2 OC2 OC2 OC1 OC1 OC1
OC2M[2:0] CC2S[1:0] OC1M[2:0] CC1S[1:0]
CE PE FE CE PE FE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IC4F[3:0] IC4PSC[1:0] CC4S[1:0] IC3F[3:0] IC3PSC[1:0] CC3S[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. OC4M[3] Res. Res. Res. Res. Res. Res. Res. OC3M[3]
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OC4 OC4 OC4 OC3 OC3 OC3
OC4M[2:0] CC4S[1:0] OC3M[2:0] CC3S[1:0]
CE PE FE CE PE FE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CC6P CC6E Res. Res. CC5P CC5E
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CC4NP Res. CC4P CC4E CC3NP CC3NE CC3P CC3E CC2NP CC2NE CC2P CC2E CC1NP CC1NE CC1P CC1E
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Table 66. Output control bits for complementary OCx and OCxN channels with break feature
Control bits Output states(1)
MOE bit OSSI bit OSSR bit CCxE bit CCxNE bit OCx output state OCxN output state
Note: The state of the external I/O pins connected to the complementary OCx and OCxN channels
depends on the OCx and OCxN channel state and the GPIO registers.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UIF
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
CPY
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSC[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ARR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
REP[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR1[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
If channel CC1 is configured as input: CR1 is the counter value transferred by the last
input capture 1 event (IC1). The TIMx_CCR1 register is read-only and cannot be
programmed.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR2[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR3[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
If channel CC3 is configured as input: CCR3 is the counter value transferred by the last
input capture 3 event (IC3). The TIMx_CCR3 register is read-only and cannot be
programmed.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR4[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BK2 BK
Res. Res. BK2BID BKBID BK2P BK2E BK2F[3:0] BKF[3:0]
DSRM DSRM
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MOE AOE BKP BKE OSSR OSSI LOCK[1:0] DTG[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: As the bits BK2BID, BKBID, BK2DSRM, BKDSRM, BK2P, BK2E, BK2F[3:0], BKF[3:0],
AOE, BKP, BKE, OSSI, OSSR and DTG[7:0] can be write-locked depending on the LOCK
configuration, it can be necessary to configure all of them during the first write access to the
TIMx_BDTR register.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. DBL[4:0] Res. Res. Res. DBA[4:0]
rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DMAB[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMAB[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. OC6M[3] Res. Res. Res. Res. Res. Res. Res. OC5M[3]
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OC6 OC6 OC5
OC6M[2:0] OC6FE Res. Res. OC5M[2:0] OC5PE OC5FE Res. Res.
CE PE CE
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
GC5C3 GC5C2 GC5C1 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR5[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR6[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ETRSEL[3:2]
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ETRSEL[1:0] Res. Res. Res. Res. BKINP Res. Res. Res. Res. Res. Res. Res. Res. BKINE
rw rw rw rw
Note: Refer to Figure 77: TIM1 ETR input circuitry and to Figure 98: Break and Break2 circuitry
overview.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BK2
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BK2INE
INP
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. TI4SEL[3:0] Res. Res. Res. Res. TI3SEL[3:0]
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. TI2SEL[3:0] Res. Res. Res. Res. TI1SEL[3:0]
rw rw rw rw rw rw rw rw
0x1C
0x0C
Offset
RM0490
15.4.29
mode
mode
Output
Output
name
TIM1_SR
TIM1_CR2
TIM1_CR1
TIM1_EGR
Register
TIM1_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIM1_CCER
TIM1_SMCR
Input Capture
Input Capture
TIM1_CCMR2
TIM1_CCMR2
TIM1_CCMR1
TIM1_CCMR1
Compare mode
Compare mode
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
TIM1 register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
0
0
Res. Res. OC4M[3] Res. OC2M[3] Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. 0
0 Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
0
0
CC6P Res. Res. Res. Res. Res. Res. Res. TS Res. 21
MMS2[3:0]
[4:3]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. OIS6 Res. 18
0
0
RM0490 Rev 3
CC5P Res. Res. Res. Res. Res. CC6IF Res. Res. Res. Res. 17
0
0
0
0
0
0
CC5E Res. OC3M[3] Res. OC1M[3] Res. CC5IF Res. SMS[3] OIS5 Res. 16
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2:0]
[2:0]
S
IC4F[3:0]
IC2F[3:0]
OC4M
OC2M
[1:0]
ETP
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
IC4
IC2
[1:0]
[1:0]
PSC
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
S
S
S
S
[1:0]
[1:0]
[1:0]
[1:0]
[1:0]
CC4
CC4
CC2
CC2
CKD
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2:0]
[2:0]
[2:0]
MMS
IC3F[3:0]
IC1F[3:0]
OC3M
OC1M
TS[2:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
IC3
IC1
[1:0]
[1:0]
PSC
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
S
S
S
S
[1:0]
[1:0]
[1:0]
[1:0]
CC3
CC3
CC1
CC1
0
0
0
0
0
0
0
0
0
0
0
SMS[2:0]
0
Advanced-control timer (TIM1)
393/825
395
0x58
0x54
0x50
0x48
0x44
0x40
0x38
0x34
0x30
0x28
0x24
0x4C
0x3C
0x2C
Offset
394/825
Output
name
Reserved
TIM1_PSC
TIM1_CNT
TIM1_DCR
TIM1_RCR
TIM1_ARR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIM1_CCR5
TIM1_CCR4
TIM1_CCR3
TIM1_CCR2
TIM1_CCR1
TIM1_BDTR
TIM1_DMAR
TIM1_CCMR3
Compare mode
0
GC5C3 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 0 UIFCP 31
0
GC5C2 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
0
GC5C1 Res. Res. BK2BID Res. Res. Res. Res. Res. Res. Res. Res. 29
0
Res. Res. Res. BKBID Res. Res. Res. Res. Res. Res. Res. Res. 28
0
Res. Res. Res. BK2DSRM Res. Res. Res. Res. Res. Res. Res. Res.
Advanced-control timer (TIM1)
27
0
Res. Res. Res. BKDSRM Res. Res. Res. Res. Res. Res. Res. Res. 26
0
Res. Res. Res. BK2P Res. Res. Res. Res. Res. Res. Res. Res. 25
0
0
Res. OC6M[3] Res. BK2E Res. Res. Res. Res. Res. Res. Res. Res. 24
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
BK2F[3:0]
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0490 Rev 3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
BKF[3:0]
0
0
Res. OC5M[3] Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
0
0
0
0
0
1
0
0
Res.
15
DMAB[31:0]
0
0
0
0
0
0
0
0
0
1
0
0
Res. AOE 14
0
0
0
0
0
0
0
0
0
1
0
0
Res. BKP 13
[2:0]
OC6M
0
0
0
0
0
0
0
0
0
0
1
0
0
BKE 12
0
0
0
0
0
0
0
0
0
0
1
0
0
OC6PE OSSR 11
0
0
0
0
0
0
0
0
0
0
1
0
0
OC6FE OSSI 10
DBL[4:0]
0
0
0
0
0
0
0
0
0
1
0
0
Res. 9
K
[1:0]
LOC
0
0
0
0
0
0
0
0
0
1
0
0
Table 67. TIM1 register map and reset values (continued)
Res. 8
0
0
0
0
0
0
0
0
0
1
0
0
OC5CE Res. 7
REP[15:0]
PSC[15:0]
CNT[15:0]
ARR[15:0]
CCR5[15:0]
CCR4[15:0]
CCR3[15:0]
CCR2[15:0]
CCR1[15:0]
0
0
0
0
0
0
0
0
0
1
0
0
Res. 6
0
0
0
0
0
0
0
0
0
1
0
0
Res. 5
[2:0]
OC5M
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
OC5PE 3
DT[7:0]
0
0
0
0
0
0
0
0
0
0
1
0
0
OC5FE 2
0
0
0
0
0
0
0
0
0
1
0
0
DBA[4:0]
Res. 1
0
0
0
0
0
0
0
0
0
1
0
0
Res. 0
RM0490
0x68
0x64
0x60
0x5C
Offset
RM0490
name
TIM1_AF2
TIM1_AF1
Register
Reset value
Reset value
Reset value
Reset value
TIM1_CCR6
TIM1_TISEL
Res. Res. Res. Res. 31
Res. Res. Res. Res. 30
Res. Res. Res. Res. 29
Res. Res. Res. Res. 28
0
Res. Res. Res. 27
0
Res. Res. Res. 26
0
Res. Res. Res. 25
TI4SEL[3:0]
0
Res. Res. Res. 24
Res. Res. Res. Res. 23
Res. Res. Res. Res. 22
Res. Res. Res. Res. 21
Res. Res. Res. Res. 20
0
Res. Res. Res. 19
0
RM0490 Rev 3
Res. Res. 17
TI3SEL[3:0]
0
Res. Res. 16
Res
[3:0]
0
0
Res. Res. 15
ETRSEL
0
Res. Res. 14
0
Res. Res. 11
0
Res. Res. 10
0
0
0
BK2INP BKINP 9
Refer to Section 2.2 on page 39 for the register boundary addresses.
TI2SEL[3:0]
0
0
Table 67. TIM1 register map and reset values (continued)
Res. Res. 8
0
Res. Res. 3
0
0
Res. Res. 2
0
0
Res. Res. 1
TI1SEL[3:0]
0
0
1
BK2INE BKINE 0
Advanced-control timer (TIM1)
395/825
395
General-purpose timer (TIM3) RM0490
TI1FP1 Encoder
TI2FP2 interface
U
Auto-reload register UI
Stop, clear or up/down
U
CK_PSC PSC CK_CNT +/- CNT counter
XOR prescaler
CC1I U CC1I
TI1[0] TI1 Input
TIMx_CH1 TI1FP1 OC1REF
filter & IC1 IC1PS Output OC1 TIMx_CH1
TI1FP2 Prescaler Capture/Compare 1 register
TI1[1..15] edge control
detector TRC
CC2I
U CC2I
TI2[0] Input
TIMx_CH2 TI2FP1
IC2 Output OC2
TI2 filter & TI2FP2 Prescaler
IC2PS Capture/Compare 2 register OC2REF TIMx_CH2
TI2[1..15] edge control
detector TRC
CC3I CC3I
TI3[0] Input U
TIMx_CH3 TI3FP3
TI3 filter & TI3FP4 IC3 OC3REF Output OC3
IC3PS Capture/Compare 3 register TIMx_CH3
TI3[1..15] edge Prescaler control
detector TRC
CC4I
U CC4I
TI4[0] Input
TIMx_CH4 TI4FP3
TI4 filter & TI4FP4 IC4 IC4PS OC4REF Output OC4
Prescaler Capture/Compare 4 register TIMx_CH4
TI4[1..15] edge control
detector TRC
ETRF
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit/32-bit register (in the TIMx_PSC
register). It can be changed on the fly as this control register is buffered. The new prescaler
ratio is taken into account at the next update event.
Figure 116 and Figure 117 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 116. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
MS31076V2
Figure 117. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Timerclock = CK_CNT
F7 F8 F9 FA FB FC 00 01
Counter register
0 3
Prescaler control register
0 3
Prescaler buffer
0 0 1 2 3 0 1 2 3
Prescaler counter
MS31077V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
MS31078V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
MS31079V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
MS31080V2
CK_PSC
Timerclock = CK_CNT
Counter register 1F 20 00
Counter overflow
MS31081V2
Figure 122. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload preload
register FF 36
Figure 123. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload shadow
register F5 36
Downcounting mode
In downcounting mode, the counter counts from the auto-reload value (content of the
TIMx_ARR register) down to 0, then restarts from the auto-reload value and generates a
counter underflow event.
An Update event can be generate at each counter underflow or by setting the UG bit in the
TIMx_EGR register (by software or by using the slave mode controller)
The UEV update event can be disabled by software by setting the UDIS bit in TIMx_CR1
register. This is to avoid updating the shadow registers while writing new values in the
preload registers. Then no update event occurs until UDIS bit has been written to 0.
However, the counter restarts from the current auto-reload value, whereas the counter of the
prescaler restarts from 0 (but the prescale rate doesn’t change).
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or
DMA request is sent). This is to avoid generating both update and capture interrupts when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that the auto-reload is updated before the counter is
reloaded, so that the next period is the expected one.
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
(cnt_udf)
MS31184V1
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
MS31185V1
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
MS31186V1
CK_PSC
Timerclock = CK_CNT
Counter register 20 1F 00 36
Counter underflow
MS31187V1
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
Auto-reload preload
register FF 36
DMA request is sent). This is to avoid generating both update and capture interrupt when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that if the update source is a counter overflow, the auto-
reload is updated before the counter is reloaded, so that the next period is the expected
one (the counter is loaded with the new value).
The following figures show some examples of the counter behavior for different clock
frequencies.
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 04 03 02 01 00 01 02 03 04 05 06 05 04 03
Counter underflow
Counter overflow
1. Here, center-aligned mode 1 is used (for more details refer to Section 16.4.1: TIM3 control register 1
(TIM3_CR1) on page 441).
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
MS31190V1
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_PSC
Timerclock = CK_CNT
Counter register 20 1F 01 00
Counter underflow
MS31192V1
Figure 133. Counter timing diagram, Update event with ARPE=1 (counter underflow)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 06 05 04 03 02 01 00 01 02 03 04 05 06 07
Counter underflow
Auto-reload preload
register FD 36
Auto-reload active
register FD 36
MS31193V1
Figure 134. Counter timing diagram, Update event with ARPE=1 (counter overflow)
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 36 35 34 33 32 31 30 2F
Counter overflow
MS31194V1
Internal clock
CEN=CNT_EN
UG
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MSv67545V1
or TI2F or
TI1F or Encoder
ITRx mode
000xx
TIMx_CH2 TI1_ED TRGI External clock
00100
TI1FP1 00101 mode 1 CK_PSC
TI2[0]
TI2F_Rising
TI2 Edge 0 TI2FP2 00110 ETRF External clock
TI2[1..15] Filter
detector 1 ETRF 00111 mode 2
TI2F_Falling
(1) CK_INT Internal clock
ICF[3:0] CC2P (internal clock) mode
TIMx_CCMR1 TIMx_CCER
ECE SMS[2:0]
TIMx_SMCR
MSv40117V1
Note: The capture prescaler is not used for triggering, so it does not need to be configured.
4. Select rising edge polarity by writing CC2P=0 and CC2NP=0 and CC2NP=0 in the
TIMx_CCER register.
5. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
6. Select TI2 as the input source by writing TS=00110 in the TIMx_SMCR register.
7. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
MS31087V2
TI2F or
or
TI1F or Encoder
ETR0 input from AF controller mode
For example, to configure the upcounter to count each 2 rising edges on ETR, use the
following procedure:
1. Select the proper ETR source (internal or external) with the ETRSEL[3:0] bits in the
TIMx_AF1 register.
2. As no filter is needed in this example, write ETF[3:0]=0000 in the TIMx_SMCR register.
3. Set the prescaler by writing ETPS[1:0]=01 in the TIMx_SMCR register
4. Select rising edge detection on the ETR pin by writing ETP=0 in the TIMx_SMCR
register
5. Enable external clock mode 2 by writing ECE=1 in the TIMx_SMCR register.
6. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
The counter counts once each 2 ETR rising edges.
The delay between the rising edge on ETR and the actual clock of the counter is due to the
resynchronization circuit on the ETRP signal. As a consequence, the maximum frequency
which can be correctly captured by the counter is at most ¼ of TIMxCLK frequency. When
the ETRP signal is faster, the user should apply a division of the external signal by a proper
ETPS prescaler setting.
f CK_INT
CNT_EN
ETR
ETRP
ETRF
Counter clock =
CK_CNT =CK_PSC
Counter register 34 35 36
MSv33111V3
TI1F_ED
TI1[0]
TIMx_CH1 To the slave mode controller
TI1[1..15]
Filter TI1F_Rising
downcounter TI1F Edge 0 TI1FP1
fDTS TI1F_Falling 01
detector 1
TI2FP1 IC1 Divider IC1PS
10 /1, /2, /4, /8
ICF[3:0] CC1P/CC1NP
TRC
11
TIMx_CCMR1 TIMx_CCER (from slave mode
TI2F_Rising controller)
0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_Falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
MSv40120V1
The output stage generates an intermediate waveform which is then used for reference:
OCxRef (active high). The polarity acts at the end of the chain.
APB Bus
MCU-peripheral interface
CC1S[1]
CC1S[0] Capture/compare preload register
CC1S[1]
MSv63030V1
TIMx_SMCR
OCCS
CC1E CC1P
OC2REF
TIMx_CCER TIMx_CCER CC1E TIMx_CCER
OC1CE OC1M[3:0]
TIMx_CCMR1
MS33145V5
The capture/compare block is made of one preload register and one shadow register. Write
and read always access the preload register.
In capture mode, captures are actually done in the shadow register, which is copied into the
preload register.
In compare mode, the content of the preload register is copied into the shadow register
which is compared to the counter.
1. The PWM input mode can be used only with the TIMx_CH1/TIMx_CH2 signals due to the fact that only
TI1FP1 and TI2FP2 are connected to the slave mode controller.
Procedure
1. Select the counter clock (internal, external, prescaler).
2. Write the desired data in the TIMx_ARR and TIMx_CCRx registers.
3. Set the CCxIE and/or CCxDE bits if an interrupt and/or a DMA request is to be
generated.
4. Select the output mode. For example, one must write OCxM=011, OCxPE=0, CCxP=0
and CCxE=1 to toggle OCx output pin when CNT matches CCRx, CCRx preload is not
used, OCx is enabled and active high.
5. Enable the counter by setting the CEN bit in the TIMx_CR1 register.
The TIMx_CCRx register can be updated at any time by software to control the output
waveform, provided that the preload register is not enabled (OCxPE=0, else TIMx_CCRx
shadow register is updated only at the next update event UEV). An example is given in
Figure 144.
OC1REF= OC1
MS31092V1
cleared by an external event through the ETR signal until the next PWM period), the
OCREF signal is asserted only:
• When the result of the comparison or
• When the output compare mode (OCxM bits in TIMx_CCMRx register) switches from
the “frozen” configuration (no comparison, OCxM=‘000) to one of the PWM modes
(OCxM=‘110 or ‘111).
This forces the PWM by software while the timer is running.
The timer is able to generate PWM in edge-aligned mode or center-aligned mode
depending on the CMS bits in the TIMx_CR1 register.
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘1’
CCRx>8
CCxIF
OCXREF ‘0’
CCRx=0
CCxIF
MS31093V1
Downcounting configuration
Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to Downcounting
mode on page 403.
In PWM mode 1, the reference signal ocxref is low as long as TIMx_CNT>TIMx_CCRx else
it becomes high. If the compare value in TIMx_CCRx is greater than the auto-reload value in
TIMx_ARR, then ocxref is held at 100%. PWM is not possible in this mode.
Counter register 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1
OCxREF
CCRx = 4
CCxIF CMS=01
CMS=10
CMS=11
OCxREF
CCRx=7
CMS=10 or 11
CCxIF
‘1’
OCxREF
CCRx=8
CCxIF CMS=01
CMS=10
CMS=11
‘1’
OCxREF
CCRx>8
CCxIF CMS=01
CMS=10
CMS=11
‘0’
OCxREF
CCRx=0
CCxIF CMS=01
CMS=10
CMS=11
AI14681b
Figure 147. Generation of 2 phase-shifted PWM signals with 50% duty cycle
Counter register 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1
OC1REFC
CCR1=0
CCR2=8
OC3REFC
CCR3=3
CCR4=5
MS33117V1
When a given channel is used as combined PWM channel, its secondary channel must be
configured in the opposite PWM mode (for instance, one in Combined PWM mode 1 and the
other in Combined PWM mode 2).
Note: The OCxM[3:0] bit field is split into two parts for compatibility reasons, the most significant
bit is not contiguous with the 3 least significant ones.
Figure 148 shows an example of signals that can be generated using Asymmetric PWM
mode, obtained with the following configuration:
• Channel 1 is configured in Combined PWM mode 2,
• Channel 2 is configured in PWM mode 1,
• Channel 3 is configured in Combined PWM mode 2,
• Channel 4 is configured in PWM mode 1
OC2’
OC1’
OC2
OC1
OC1REF
OC2REF
OC1REF’
OC2REF’
OC1REFC
OC1REFC’
MS31094V1
The OCxREF signal for a given channel can be reset by applying a high level on the ETRF
input (OCxCE enable bit set to 1 in the corresponding TIMx_CCMRx register). OCxREF
remains low until the next transition to the active state, on the following PWM cycle.
This function can be used only in the output compare and PWM modes. It does not work in
forced mode.
For example, the OCxREF signal can be connected to the output of a comparator to be
used for current handling. In this case, ETR must be configured as follows:
1. The external trigger prescaler should be kept off: bits ETPS[1:0] in the TIMx_SMCR
register are cleared to 00.
2. The external clock mode 2 must be disabled: bit ECE in the TIM1_SMCR register is
cleared to 0.
3. The external trigger polarity (ETP) and the external trigger filter (ETF) can be
configured according to the application’s needs.
Figure 149 shows the behavior of the OCxREF signal when the ETRF input becomes high,
for both values of the OCxCE enable bit. In this example, the timer TIMx is programmed in
PWM mode.
(CCRx)
Counter (CNT)
ETRF
OCxREF
(OCxCE = ‘0’)
OCxREF
(OCxCE = ‘1’)
ocref_clr_int ocref_clr_int
becomes high still high
MS33105V2
Note: In case of a PWM with a 100% duty cycle (if CCRx>ARR), OCxREF is enabled again at the
next counter overflow.
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY tPULSE t
MS31099V1
For example one may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
Let’s use TI2FP2 as trigger 1:
1. Select the proper TI2x source (internal or external) with the TI2SEL[3:0] bits in the
TIMx_TISEL register.
2. Map TI2FP2 on TI2 by writing CC2S=01 in the TIMx_CCMR1 register.
3. TI2FP2 must detect a rising edge, write CC2P=0 and CC2NP=’0’ in the TIMx_CCER
register.
4. Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=00110
in the TIMx_SMCR register.
5. TI2FP2 is used to start the counter by writing SMS to ‘110 in the TIMx_SMCR register
(trigger mode).
The OPM waveform is defined by writing the compare registers (taking into account the
clock frequency and the counter prescaler).
• The tDELAY is defined by the value written in the TIMx_CCR1 register.
• The tPULSE is defined by the difference between the auto-reload value and the compare
value (TIMx_ARR - TIMx_CCR1).
• Let’s say one want to build a waveform with a transition from ‘0 to ‘1 when a compare
match occurs and a transition from ‘1 to ‘0 when the counter reaches the auto-reload
value. To do this PWM mode 2 must be enabled by writing OC1M=111 in the
TIMx_CCMR1 register. Optionally the preload registers can be enabled by writing
OC1PE=1 in the TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this
case one has to write the compare value in the TIMx_CCR1 register, the auto-reload
value in the TIMx_ARR register, generate an update by setting the UG bit and wait for
external trigger event on TI2. CC1P is written to ‘0 in this example.
In our example, the DIR and CMS bits in the TIMx_CR1 register should be low.
Since only 1 pulse (Single mode) is needed, a 1 must be written in the OPM bit in the
TIMx_CR1 register to stop the counter at the next update event (when the counter rolls over
from the auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0',
so the Repetitive Mode is selected.
TRGI
Counter
Output
MS33106V2
An external incremental encoder can be connected directly to the MCU without external
interface logic. However, comparators are normally be used to convert the encoder’s
differential outputs to digital signals. This greatly increases noise immunity. The third
encoder output which indicate the mechanical zero position, may be connected to an
external interrupt input and trigger a counter reset.
Figure 152 gives an example of counter operation, showing count signal generation and
direction control. It also shows how input jitter is compensated where both edges are
selected. This might occur if the sensor is positioned near to one of the switching points. For
this example we assume that the configuration is the following:
• CC1S= 01 (TIMx_CCMR1 register, TI1FP1 mapped on TI1)
• CC2S= 01 (TIMx_CCMR2 register, TI2FP2 mapped on TI2)
• CC1P and CC1NP = ‘0’ (TIMx_CCER register, TI1FP1 noninverted, TI1FP1=TI1)
• CC2P and CC2NP = ‘0’ (TIMx_CCER register, TI2FP2 noninverted, TI2FP2=TI2)
• SMS= 011 (TIMx_SMCR register, both inputs are active on both rising and falling
edges)
• CEN= 1 (TIMx_CR1 register, Counter is enabled)
TI1
TI2
Counter
up down up
MS33107V1
Figure 153 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=1).
Figure 153. Example of encoder interface mode with TI1FP1 polarity inverted
TI1
TI2
Counter
down up down
MS33108V1
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. Dynamic information can be obtained (speed, acceleration, deceleration)
by measuring the period between two encoder events using a second timer configured in
capture mode. The output of the encoder which indicates the mechanical zero can be used
for this purpose. Depending on the time between two events, the counter can also be read
at regular times. This can be done by latching the counter value into a third input capture
register if available (then the capture signal must be periodic and can be generated by
another timer). when available, it is also possible to read its value through a DMA request
generated by a Real-Time clock.
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
MS31401V2
CC1P=1 and CC1NP=0 in TIMx_CCER register to validate the polarity (and detect low
level only).
2. Configure the timer in gated mode by writing SMS=101 in TIMx_SMCR register. Select
TI1 as the input source by writing TS=00101 in TIMx_SMCR register.
3. Enable the counter by writing CEN=1 in the TIMx_CR1 register (in gated mode, the
counter doesn’t start if CEN=0, whatever is the trigger input level).
The counter starts counting on the internal clock as long as TI1 is low and stops as soon as
TI1 becomes high. The TIF flag in the TIMx_SR register is set both when the counter starts
or stops.
The delay between the rising edge on TI1 and the actual stop of the counter is due to the
resynchronization circuit on TI1 input.
TI1
cnt_en
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
MS31402V1
1. The configuration “CCxP=CCxNP=1” (detection of both rising and falling edges) does not have any effect
in gated mode because gated mode acts on a level and not on an edge.
Note: The configuration “CCxP=CCxNP=1” (detection of both rising and falling edges) does not
have any effect in gated mode because gated mode acts on a level and not on an edge.
The delay between the rising edge on TI2 and the actual start of the counter is due to the
resynchronization circuit on TI2 input.
TI2
cnt_en
Counter register 34 35 36 37 38
TIF
MS31403V1
TI1
CEN/CNT_EN
ETR
Counter register 34 35 36
TIF
MS33110V1
Clock
TS SMS
MMS
UEV
Master Slave
TRGO ITR2 CK_PSC
Prescaler Counter mode mode Prescaler Counter
control control
Input
trigger
selection
MSv62394V1
TIM_mstr TIM_slv
Clock
Prescaler Counter TS SMS
Output Slave
tim_oc1 tim_itr CK_PSC
mode
control control
Compare 1 Prescaler Counter
Input
TIM_CH1 trigger
selection
MSv65225V1
Note: The timers with one channel only (see Figure 159) do not feature a master mode. However,
the OC1 output signal can be used to trigger some other timers (including timers described
in other sections of this document). Check the “TIMx internal trigger connection” table of any
TIMx_SMCR register on the device to identify which timers can be targeted as slave.
The OC1 signal pulse width must be programmed to be at least 2 clock cycles of the
destination timer, to make sure the slave timer detects the trigger.
For instance, if the destination's timer CK_INT clock is 4 times slower than the source timer,
the OC1 pulse width must be 8 clock cycles.
1. Configure TIMy master mode to send its Output Compare 1 Reference (OC1REF)
signal as trigger output (MMS=100 in the TIMy_CR2 register).
2. Configure the TIMy OC1REF waveform (TIMy_CCMR1 register).
3. Configure TIMz to get the input trigger from TIMy (TS=00 in the TIMz_SMCR register).
4. Configure TIMz in gated mode (SMS=101 in TIMz_SMCR register).
5. Enable TIMz by writing ‘1 in the CEN bit (TIMz_CR1 register).
6. Start TIMy by writing ‘1 in the CEN bit (TIMy_CR1 register).
Note: The counter z clock is not synchronized with counter 1, this mode only affects the TIMz
counter enable signal.
CK_INT
TIMy-OC1REF
TIMy-CNT FC FD FE FF 00 01
TIMz-TIF
Write TIF = 0
MSv37634V1
In the example in Figure 160, the TIMz counter and prescaler are not initialized before being
started. So they start counting from their current value. It is possible to start from a given
value by resetting both timers before starting TIMy. Then any value can be written in the
timer counters. The timers can easily be reset by software using the UG bit in the
TIMx_EGR registers.
In the next example (refer to Figure 161), we synchronize TIMy and TIMz. TIMy is the
master and starts from 0. TIMz is the slave and starts from 0xE7. The prescaler ratio is the
same for both timers. TIMz stops when TIMy is disabled by writing ‘0 to the CEN bit in the
TIMy_CR1 register:
1. Configure TIMy master mode to send its Output Compare 1 Reference (OC1REF)
signal as trigger output (MMS=100 in the TIMy_CR2 register).
2. Configure the TIMy OC1REF waveform (TIMy_CCMR1 register).
3. Configure TIMz to get the input trigger from TIMy (TS=00 in the TIMz_SMCR register).
4. Configure TIMz in gated mode (SMS=101 in TIMz_SMCR register).
5. Reset TIMy by writing ‘1 in UG bit (TIMy_EGR register).
6. Reset TIMz by writing ‘1 in UG bit (TIMz_EGR register).
7. Initialize TIMz to 0xE7 by writing ‘0xE7’ in the TIMz counter (TIMz_CNTL).
8. Enable TIMz by writing ‘1 in the CEN bit (TIMz_CR1 register).
9. Start TIMy by writing ‘1 in the CEN bit (TIMy_CR1 register).
10. Stop TIMy by writing ‘0 in the CEN bit (TIMy_CR1 register).
CK_INT
TIMy-CEN=CNT_EN
TIMy-CNT_INIT
TIMy-CNT 75 00 01 02
TIMz-CNT AB 00 E7 E8 E9
TIMz-CNT_INIT
TIMz-write CNT
TIMz-TIF
Write TIF = 0
MSv37635V1
CK_INT
TIMy-UEV
TIMy-CNT FD FE FF 00 01 02
TIMz-CNT 45 46 47 48
TIMz-CEN=CNT_EN
TIMz-TIF
Write TIF = 0
MSv37636V1
As in the previous example, both counters can be initialized before starting counting.
Figure 163 shows the behavior with the same configuration as in Figure 162 but in trigger
mode instead of gated mode (SMS=110 in the TIMz_SMCR register).
CK_INT
TIMy-CEN=CNT_EN
TIMy-CNT_INIT
TIMy-CNT 75 00 01 02
TIMz-CNT CD 00 E7 E8 E9 EA
TIMz-CNT_INIT
TIMz
write CNT
TIMz-TIF
Write TIF = 0
MSv37637V1
Figure 164. Triggering TIMy and TIMz with TIMy TI1 input
CK_INT
TIMy-TI1
TIMy-CEN=CNT_EN
TIMy-CK_PSC
TIMy-CNT 00 01 02 03 04 05 06 07 08 09
TIMy-TIF
TIMz-CEN=CNT_EN
TIMz-CK_PSC
TIMz-CNT 00 01 02 03 04 05 06 07 08 09
TIMz-TIF
MSv37638V1
Note: The clock of the slave peripherals (timer, ADC, ...) receiving the TRGO or the TRGO2
signals must be enabled prior to receive events from the master timer, and the clock
frequency (prescaler) must not be changed on-the-fly while triggers are received from the
master timer.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TS[4:3] Res. Res. Res. SMS[3]
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ETP ECE ETPS[1:0] ETF[3:0] MSM TS[2:0] OCCS SMS[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IC2F[3:0] IC2PSC[1:0] CC2S[1:0] IC1F[3:0] IC1PSC[1:0] CC1S[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OC2M OC1M
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
[3] [3]
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OC2CE OC2M[2:0] OC2PE OC2FE CC2S[1:0] OC1CE OC1M[2:0] OC1PE OC1FE CC1S[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IC4F[3:0] IC4PSC[1:0] CC4S[1:0] IC3F[3:0] IC3PSC[1:0] CC3S[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OC4M OC3M
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
[3] [3]
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OC4CE OC4M[2:0] OC4PE OC4FE CC4S[1:0] OC3CE OC3M[2:0] OC3PE OC3FE CC3S[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The state of the external IO pins connected to the standard OCx channels depends on the
OCx channel state and the GPIO control and alternate function registers.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UIFCPY Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ARR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR1[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR2[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR3[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR4[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ETRSEL[3:2]
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ETRSEL[1:0] Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TI3SEL[3:0]
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. TI2SEL[3:0] Res. Res. Res. Res. TI1SEL[3:0]
rw rw rw rw rw rw rw rw
0x1C
0x0C
Offset
RM0490
16.4.24
mode
mode
Output
Output
name
TIMx_SR
TIMx_CR2
TIMx_CR1
TIMx_EGR
Register
TIMx_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCER
TIMx_SMCR
Input Capture
Input Capture
TIMx_CCMR2
TIMx_CCMR2
TIMx_CCMR1
TIMx_CCMR1
Compare mode
Compare mode
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
TIMx register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
0
0
Res. Res. OC4M[3] Res. OC2M[3] Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
TS
[4:3]
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
RM0490 Rev 3
0
0
0
Res. Res. OC3M[3] Res. OC1M[3] Res. Res. Res. SMS[3] Res. Res. 16
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2:0]
[2:0]
IC4F[3:0]
IC2F[3:0]
OC4M
OC2M
[1:0]
0
0
0
0
0
0
0
0
ETPS
0
0
0
0
0
0
0
0
0
IC4
IC2
[1:0]
[1:0]
PSC
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[1:0]
[1:0]
[1:0]
[1:0]
[1:0]
CKD
0
0
0
0
0
0
0
0
CC4S
CC4S
CC2S
CC2S
CC3E Res. Res. UDE Res. 8
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2:0]
[2:0]
IC3F[3:0]
IC1F[3:0]
OC3M
OC1M
TS[2:0]
0
0
0
0
0
0
0
0
0
0
0
MMS[2:0]
0
0
0
0
0
0
0
0
0
0
IC3
IC1
[1:0]
[1:0]
PSC
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[1:0]
[1:0]
[1:0]
[1:0]
0
0
0
0
0
0
0
0
0
0
SMS[2:0]
CC3S
CC3S
CC1S
CC1S
465/825
466
0x68
0x60
0x48
0x44
0x40
0x38
0x34
0x30
0x28
0x24
0x4C
0x3C
0x2C
Offset
466/825
name
TIM3_AF1
TIMx_PSC
TIMx_CNT
TIMx_DCR
TIMx_ARR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCR4
TIMx_CCR3
TIMx_CCR2
TIMx_CCR1
TIM3_TISEL
TIMx_DMAR
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. UIFCPY 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
General-purpose timer (TIM3)
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
RM0490 Rev 3
Reserved
Reserved
TI3SEL[3:0]
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
[3:0]
0
0
0
0
0
0
1
0
0
Res. Res. 15
ETRSEL
0
0
0
0
0
0
1
0
0
Res. Res. 14
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
Res. Res. 12
0
0
0
0
0
0
0
1
0
0
Res. 11
0
0
0
0
0
0
0
1
0
0
Res. 10
0
0
0
0
0
0
0
1
0
0
DBL[4:0]
Res. 9
TI2SEL[3:0]
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
ARR[15:0]
CCR4[15:0]
CCR3[15:0]
CCR2[15:0]
CCR1[15:0]
DMAB[15:0]
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
Res. Res. 4
0
0
0
0
0
0
0
1
0
0
Res. 3
0
0
0
0
0
0
0
1
0
0
Res. 2
0
0
0
0
0
0
0
1
0
0
DBA[4:0]
Res. 1
TI1SEL[3:0]
0
0
0
0
0
0
0
1
0
0
Res. 0
RM0490
RM0490 General-purpose timers (TIM14)
U Auto-reload register
UI
Stop, clear
U
CK_PSC PSC CK_CNT +/-
CNT counter
prescaler
C1I CC1I
TI1[0] Input U
TIMx_CH1 TI1FP1 IC1 Capture/compare 1
filter & Prescaler IC1PS OC1REF Output OC1
register TIMx_CH1
TI1[1..15] edge control
selector
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
1. This signal can be used as trigger for some slave timers, see Section 17.3.11: Using timer output as trigger
for other timers (TIM14).
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit register (in the TIMx_PSC register).
It can be changed on the fly as this control register is buffered. The new prescaler ratio is
taken into account at the next update event.
Figure 166 and Figure 167 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 166. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
MS31076V2
Figure 167. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Timerclock = CK_CNT
F7 F8 F9 FA FB FC 00 01
Counter register
0 3
Prescaler control register
0 3
Prescaler buffer
0 0 1 2 3 0 1 2 3
Prescaler counter
MS31077V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
MS31078V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
MS31079V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
MS31080V2
CK_PSC
Timerclock = CK_CNT
Counter register 1F 20 00
Counter overflow
MS31081V2
Figure 172. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload preload
register FF 36
Figure 173. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload shadow
register F5 36
Internal clock
CEN=CNT_EN
UG
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MSv31085V3
TI1[0]
TIMx_CH1
TI1[1..15]
Filter TI1F_Rising
downcounter TI1F Edge 0 TI1FP1
fDTS TI1F_Falling 01
detector 1
IC1 Divider IC1PS
/1, /2, /4, /8
ICF[3:0] CC1P/CC1NP
TIMx_CCMR1 TIMx_CCER
TIMx_CCMR1 TIMx_CCER
MSv45749V1
The output stage generates an intermediate waveform which is then used for reference:
OCxRef (active high). The polarity acts at the end of the chain.
APB Bus
MCU-peripheral interface
CC1S[1]
CC1S[0] Capture/compare preload register
CC1S[1]
MSv63030V1
OC1REF OC1REFC
‘0’ 0 0 Output
CNT > CCR1 Output OC1
Output enable
mode 1 1 circuit
selector
CNT = CCR1 controller
OC2REF(1)
CC1E CC1P CC1E
TIM1_CCER TIM1_CCER TIM1_CCER
OC1M[3:0]
TIMx_CCMR1
MSv45743V3
cleared by software by writing it to ‘0’ or by reading the captured data stored in the
TIMx_CCRx register. CCxOF is cleared when it is written with 0.
The following example shows how to capture the counter value in TIMx_CCR1 when TI1
input rises. To do this, use the following procedure:
1. Select the proper TI1[x] source (internal or external) with the TI1SEL[3:0] bits in the
TIMx_TISEL register.
2. Select the active input: TIMx_CCR1 must be linked to the TI1 input, so write the CC1S
bits to ‘01’ in the TIMx_CCMR1 register. As soon as CC1S becomes different from ‘00’,
the channel is configured in input mode and the TIMx_CCR1 register becomes read-
only.
3. Program the appropriate input filter duration in relation with the signal connected to the
timer (by programming the ICxF bits in the TIMx_CCMRx register if the input is one of
the TIx inputs). Let’s imagine that, when toggling, the input signal is not stable during at
must 5 internal clock cycles. We must program a filter duration longer than these 5
clock cycles. We can validate a transition on TI1 when 8 consecutive samples with the
new level have been detected (sampled at fDTS frequency). Then write IC1F bits to
‘0011’ in the TIMx_CCMR1 register.
4. Select the edge of the active transition on the TI1 channel by programming CC1P and
CC1NP bits to ‘00’ in the TIMx_CCER register (rising edge in this case).
5. Program the input prescaler. In our example, we wish the capture to be performed at
each valid transition, so the prescaler is disabled (write IC1PS bits to ‘00’ in the
TIMx_CCMR1 register).
6. Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
7. If needed, enable the related interrupt request by setting the CC1IE bit in the
TIMx_DIER register.
When an input capture occurs:
• The TIMx_CCR1 register gets the value of the counter on the active transition.
• CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures
occurred whereas the flag was not cleared.
• An interrupt is generated depending on the CC1IE bit.
In order to handle the overcapture, it is recommended to read the data before the
overcapture flag. This is to avoid missing an overcapture which could happen after reading
the flag and before reading the data.
Note: IC interrupt requests can be generated by software by setting the corresponding CCxG bit in
the TIMx_EGR register.
The OCxREF signal can be forced low by writing the OCxM bits to ‘0100’ in the
TIMx_CCMRx register.
Anyway, the comparison between the TIMx_CCRx shadow register and the counter is still
performed and allows the flag to be set. Interrupt requests can be sent accordingly. This is
described in the output compare mode section below.
OC1REF= OC1
MS31092V1
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘1’
CCRx>8
CCxIF
OCXREF ‘0’
CCRx=0
CCxIF
MS31093V1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UIFRE
Res. Res. Res. Res. Res. CKD[1:0] ARPE Res. Res. Res. OPM URS UDIS CEN
MAP
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CC1IE UIE
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. CC1OF Res. Res. Res. Res. Res. Res. Res. CC1IF UIF
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CC1G UG
w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. IC1F[3:0] IC1PSC[1:0] CC1S[1:0]
rw rw rw rw rw rw rw rw
corresponding CCxS bits. All the other bits of this register have a different function in input
and in output mode.
Output compare mode:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OC1M
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
[3]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. OC1M[2:0] OC1PE OC1FE CC1S[1:0]
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CC1NP Res. CC1P CC1E
rw rw rw
Note: The state of the external I/O pins connected to the standard OCx channels depends on the
OCx channel state and the GPIO registers.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UIF
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
CPY
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSC[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ARR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR1[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TI1SEL[3:0]
rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
name
UIFREMA
ARPE
UDIS
CKD
OPM
CEN
URS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_CR1
[1:0]
0x00
Reset value 0 0 0 0 0 0 0 0
UIE
TIMx_DIER
0x0C
Reset value 0 0
0x2C
0x1C
0x38 to
Offset
492/825
mode
mode
name
TIMx_SR
Reserved
Reserved
Reserved
TIMx_PSC
TIMx_CNT
TIMx_EGR
TIMx_ARR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCR1
TIMx_CCER
Input capture
TIM14_TISEL
TIMx_CCMR1
TIMx_CCMR1
Output compare
0
Res. Res. Res. Res. UIFCPY Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
General-purpose timers (TIM14)
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
RM0490 Rev 3
0
Res. Res. Res. Res. Res. Res. Res. OC1M[3] Res. Res. 16
0
0
0
0
Res. Res. Res. Res. Res. Res. 15
Res.
Res.
Res.
0
0
0
0
Res. Res. Res. Res. Res. Res. 14
0
0
0
0
Res. Res. Res. Res. Res. Res. 13
0
0
0
0
Res. Res. Res. Res. Res. Res. 12
0
0
0
0
Res. Res. Res. Res. Res. Res. 11
0
0
0
0
Res. Res. Res. Res. Res. Res. 10
0
0
0
0
0
0
0
0
0
0
0
0
0
0
ARR[15:0]
0
0
0
0
0
0
CCR1[15:0]
Res. Res. Res. Res. 6
0
0
0
0
0
0
IC1F[3:0]
OC1M
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[1:0]
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TI1SEL[3:0]
[1:0]
[1:0]
0
0
0
0
0
0
0
0
0
0
CC1S
CC1S
CC1E UG UIF 0
RM0490
RM0490 General-purpose timers (TIM16/TIM17)
REP register
To other
Auto-reload register UI timers for
U cross-
Repetition U trigerring(1)
Stop, clear or up/down counter
CK_PSC PSC CK_CNT
+/- CNT counter
prescaler DTG registers
C1I CC1I
TI1[0] Input U TIMx_CH1
TIMx_CH1 TI1FP1 IC1
filter & IC1PS OC1REF Output OC1
Prescaler Capture/compare 1 register
TI1[1..15] edge DTG control TIMx_CH1N
detector
OC1N
Internal sources
SBIF
BIF
BRK request
TIMx_BKIN Break circuitry(2)
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
1. This signal can be used as trigger for some slave timer, see Section 18.3.18: Using timer output as trigger for other timers
(TIM16/TIM17).
2. The internal break event source can be:
- A clock failure event generated by CSS. For further information on the CSS, refer to Section 5.2.6: Clock security system
(CSS)
- SRAM parity error signal
- Cortex®-M0+ LOCKUP (Hardfault) output
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit register (in the TIMx_PSC register).
It can be changed on the fly as this control register is buffered. The new prescaler ratio is
taken into account at the next update event.
Figure 181 and Figure 182 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 181. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
MS31076V2
Figure 182. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Timerclock = CK_CNT
F7 F8 F9 FA FB FC 00 01
Counter register
0 3
Prescaler control register
0 3
Prescaler buffer
0 0 1 2 3 0 1 2 3
Prescaler counter
MS31077V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
MS31078V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
MS31079V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
MS31080V2
CK_PSC
Timerclock = CK_CNT
Counter register 1F 20 00
Counter overflow
MS31081V2
Figure 187. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload preload
register FF 36
Figure 188. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload shadow
register F5 36
Figure 189. Update rate examples depending on mode and TIMx_RCR register
settings
Edge-aligned mode
Upcounting
Counter
TIMx_CNT
TIMx_RCR = 0 UEV
TIMx_RCR = 1 UEV
TIMx_RCR = 2 UEV
TIMx_RCR = 3 UEV
TIMx_RCR = 3
and
re-synchronization UEV
(by SW)
MS31084V2
Figure 190 shows the behavior of the control circuit and the upcounter in normal mode,
without prescaler.
Internal clock
CEN=CNT_EN
UG
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MSv31085V3
TS[4:0]
ITRx
000xx
TI1_ED
00100 TRGI External clock
TI1FP1
00101 mode 1 CK_PSC
TI2[0] TI2F_Rising
Edge 0 TI2FP2
Filter 00110
TI2[1..15] detector 1
TI2F_Falling
CK_INT Internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
SMS[2:0]
TIMx_SMCR
MSv40935V1
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Select the proper TI2[x] source (internal or external) with the TI2SEL[3:0] bits in the
TIMx_TISEL register.
2. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = ‘01’ in
the TIMx_CCMR1 register.
3. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1
register (if no filter is needed, keep IC2F=0000).
4. Select rising edge polarity by writing CC2P=0 in the TIMx_CCER register.
5. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
6. Select TI2 as the trigger input source by writing TS=00110 in the TIMx_SMCR register.
7. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
Note: The capture prescaler is not used for triggering, so it does not need to be configured.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
MS31087V2
TI1[0]
TI1F_Rising
0 TI1FP1
TI1[1..15] Filter Edge
TI1F_Falling 01
fDTS downcounter detector 1
The output stage generates an intermediate waveform which is then used for reference:
OCxRef (active high). The polarity acts at the end of the chain.
APB Bus
MCU-peripheral interface
CC1S[1]
CC1S[0] Capture/compare preload register
CC1S[1]
MSv63030V1
The capture/compare block is made of one preload register and one shadow register. Write
To the master
mode controller
OC2REFC
OC2REF
‘0’ 0 0
CNT > CCR2 Output OC2
Output enable
Output
mode 1 1 circuit
CNT = CCR2 selector
controller
CC2E CC2P
OC1REF
TIMx_CCER TIMx_CCER CC2E TIMx_CCER
OC2M[3:0]
OIS2 TIMx_CR2
TIMx_CCMR1
MSv65242V1
cleared by software by writing it to ‘0’ or by reading the captured data stored in the
TIMx_CCRx register. CCxOF is cleared when it is written with 0.
The following example shows how to capture the counter value in TIMx_CCR1 when TI1
input rises. To do this, use the following procedure:
1. Select the proper TI1x source (internal or external) with the TI1SEL[3:0] bits in the
TIMx_TISEL register.
2. Select the active input: TIMx_CCR1 must be linked to the TI1 input, so write the CC1S
bits to 01 in the TIMx_CCMR1 register. As soon as CC1S becomes different from 00,
the channel is configured in input and the TIMx_CCR1 register becomes read-only.
3. Program the appropriate input filter duration in relation with the signal connected to the
timer (when the input is one of the TIx (ICxF bits in the TIMx_CCMRx register). Let’s
imagine that, when toggling, the input signal is not stable during at least 5 internal clock
cycles. We must program a filter duration longer than these 5 clock cycles. We can
validate a transition on TI1 when 8 consecutive samples with the new level have been
detected (sampled at fDTS frequency). Then write IC1F bits to 0011 in the
TIMx_CCMR1 register.
4. Select the edge of the active transition on the TI1 channel by writing CC1P bit to 0 in
the TIMx_CCER register (rising edge in this case).
5. Program the input prescaler. In our example, we wish the capture to be performed at
each valid transition, so the prescaler is disabled (write IC1PS bits to ‘00’ in the
TIMx_CCMR1 register).
6. Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
7. If needed, enable the related interrupt request by setting the CC1IE bit in the
TIMx_DIER register, and/or the DMA request by setting the CC1DE bit in the
TIMx_DIER register.
When an input capture occurs:
• The TIMx_CCR1 register gets the value of the counter on the active transition.
• CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures
occurred whereas the flag was not cleared.
• An interrupt is generated depending on the CC1IE bit.
• A DMA request is generated depending on the CC1DE bit.
In order to handle the overcapture, it is recommended to read the data before the
overcapture flag. This is to avoid missing an overcapture which could happen after reading
the flag and before reading the data.
Note: IC interrupt and/or DMA requests can be generated by software by setting the
corresponding CCxG bit in the TIMx_EGR register.
1. Select the active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1
register (TI1 selected).
Procedure
1. Select the counter clock (internal, external, prescaler).
2. Write the desired data in the TIMx_ARR and TIMx_CCRx registers.
3. Set the CCxIE bit if an interrupt request is to be generated.
4. Select the output mode. For example:
– Write OCxM = 011 to toggle OCx output pin when CNT matches CCRx
– Write OCxPE = 0 to disable preload register
– Write CCxP = 0 to select active high polarity
– Write CCxE = 1 to enable the output
5. Enable the counter by setting the CEN bit in the TIMx_CR1 register.
The TIMx_CCRx register can be updated at any time by software to control the output
waveform, provided that the preload register is not enabled (OCxPE=’0’, else TIMx_CCRx
shadow register is updated only at the next update event UEV). An example is given in
Figure 196.
OC1REF= OC1
MS31092V1
As the preload registers are transferred to the shadow registers only when an update event
occurs, before starting the counter, all registers must be initialized by setting the UG bit in
the TIMx_EGR register.
OCx polarity is software programmable using the CCxP bit in the TIMx_CCER register. It
can be programmed as active high or active low. OCx output is enabled by a combination of
the CCxE, CCxNE, MOE, OSSI and OSSR bits (TIMx_CCER and TIMx_BDTR registers).
Refer to the TIMx_CCER register description for more details.
In PWM mode (1 or 2), TIMx_CNT and TIMx_CCRx are always compared to determine
whether TIMx_CCRx ≤ TIMx_CNT or TIMx_CNT ≤ TIMx_CCRx (depending on the direction
of the counter).
The TIM16/TIM17 are capable of upcounting only. Refer to Upcounting mode on page 497.
In the following example, we consider PWM mode 1. The reference PWM signal OCxREF is
high as long as TIMx_CNT < TIMx_CCRx else it becomes low. If the compare value in
TIMx_CCRx is greater than the auto-reload value (in TIMx_ARR) then OCxREF is held at
‘1’. If the compare value is 0 then OCxRef is held at ‘0’. Figure 197 shows some edge-
aligned PWM waveforms in an example where TIMx_ARR=8.
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘1’
CCRx>8
CCxIF
OCXREF ‘0’
CCRx=0
CCxIF
MS31093V1
The polarity of the outputs (main output OCx or complementary OCxN) can be selected
independently for each output. This is done by writing to the CCxP and CCxNP bits in the
TIMx_CCER register.
The complementary signals OCx and OCxN are activated by a combination of several
control bits: the CCxE and CCxNE bits in the TIMx_CCER register and the MOE, OISx,
OISxN, OSSI and OSSR bits in the TIMx_BDTR and TIMx_CR2 registers. Refer to
Table 75: Output control bits for complementary OCx and OCxN channels with break feature
(TIM16/17) on page 534 for more details. In particular, the dead-time is activated when
switching to the idle state (MOE falling down to 0).
Dead-time insertion is enabled by setting both CCxE and CCxNE bits, and the MOE bit if the
break circuit is present. There is one 10-bit dead-time generator for each channel. From a
reference waveform OCxREF, it generates 2 outputs OCx and OCxN. If OCx and OCxN are
active high:
• The OCx output signal is the same as the reference signal except for the rising edge,
which is delayed relative to the reference rising edge.
• The OCxN output signal is the opposite of the reference signal except for the rising
edge, which is delayed relative to the reference falling edge.
If the delay is greater than the width of the active output (OCx or OCxN) then the
corresponding pulse is not generated.
The following figures show the relationships between the output signals of the dead-time
generator and the reference signal OCxREF. (we suppose CCxP=0, CCxNP=0, MOE=1,
CCxE=1 and CCxNE=1 in these examples)
OCxREF
OCx
delay
OCxN
delay
MS31095V1
Figure 199. Dead-time waveforms with delay greater than the negative pulse.
OCxREF
OCx
delay
OCxN
MS31096V1
Figure 200. Dead-time waveforms with delay greater than the positive pulse.
OCxREF
OCx
OCxN
delay
MS31097V1
The dead-time delay is the same for each of the channels and is programmable with the
DTG bits in the TIMx_BDTR register. Refer to Section 18.4.14: TIMx break and dead-time
register (TIMx_BDTR)(x = 16 to 17) on page 537 for delay calculation.
Lockup LOCK
Core Lockup
System break requests
SBIF flag
Parity LOCK
RAM parity Error
CSS
Software break
requests: BG
Caution: An asynchronous (clockless) operation is only guaranteed when the programmable filter is
disabled. If it is enabled, a fail safe clock mode (example, using the CSS) must be used to
guarantee that break events are handled.
When a break occurs (selected level on the break input):
• The MOE bit is cleared asynchronously, putting the outputs in inactive state, idle state
or even releasing the control to the GPIO (selected by the OSSI bit). This feature
functions even if the MCU oscillator is off.
• Each output channel is driven with the level programmed in the OISx bit in the
TIMx_CR2 register as soon as MOE=0. If OSSI=0, the timer releases the output control
(taken over by the GPIO) else the enable output remains high.
• When complementary outputs are used:
– The outputs are first put in reset state inactive state (depending on the polarity).
This is done asynchronously so that it works even if no clock is provided to the
timer.
– If the timer clock is still present, then the dead-time generator is reactivated in
order to drive the outputs with the level programmed in the OISx and OISxN bits
after a dead-time. Even in this case, OCx and OCxN cannot be driven to their
active level together. Note that because of the resynchronization on MOE, the
dead-time duration is a bit longer than usual (around 2 ck_tim clock cycles).
– If OSSI=0 then the timer releases the enable outputs (taken over by the GPIO
which forces a Hi-Z state) else the enable outputs remain or become high as soon
as one of the CCxE or CCxNE bits is high.
• The break status flag (BIF bit in the TIMx_SR register) is set. An interrupt can be
generated if the BIE bit in the TIMx_DIER register is set.
• If the AOE bit in the TIMx_BDTR register is set, the MOE bit is automatically set again
at the next update event UEV. This can be used to perform a regulation, for instance.
Else, MOE remains low until it is written with 1 again. In this case, it can be used for
security and the break input can be connected to an alarm from power drivers, thermal
sensors or any security components.
Note: If the MOE is reset by the CPU while the AOE bit is set, the outputs are in idle state and
forced to inactive level or Hi-Z depending on OSSI value.
If both the MOE and AOE bits are reset by the CPU, the outputs are in disabled state and
driven with the level programmed in the OISx bit in the TIMx_CR2 register.
Note: The break inputs is acting on level. Thus, the MOE cannot be set while the break input is
active (neither automatically nor by software). In the meantime, the status flag BIF cannot
be cleared.
The break can be generated by the BRK input which has a programmable polarity and an
enable bit BKE in the TIMx_BDTR register.
In addition to the break input and the output management, a write protection has been
implemented inside the break circuit to safeguard the application. It allows the configuration
of several parameters to be freezed (dead-time duration, OCx/OCxN polarities and state
when disabled, OCxM configurations, break enable and polarity). The protection can be
selected among 3 levels with the LOCK bits in the TIMx_BDTR register. Refer to
Section 18.4.14: TIMx break and dead-time register (TIMx_BDTR)(x = 16 to 17) on
page 537. The LOCK bits can be written only once after an MCU reset.
The Figure 202 shows an example of behavior of the outputs in response to a break.
BREAK (MOE )
OCxREF
OCx
(OCxN not implemented, CCxP=0, OISx=1)
OCx
(OCxN not implemented, CCxP=0, OISx=0)
OCx
(OCxN not implemented, CCxP=1, OISx=1)
OCx
(OCxN not implemented, CCxP=1, OISx=0)
OCx
OCx
OCx
OCxN delay
(CCxE=1, CCxP=0, OISx=0, CCxNE=0, CCxNP=0, OISxN=1)
OCx
OCxN delay
(CCxE=1, CCxP=0, OISx=1, CCxNE=0, CCxNP=0, OISxN=0)
OCx
OCxN
(CCxE=1, CCxP=0, CCxNE=0, CCxNP=0, OISx=OISxN=0 or OISx=OISxN=1)
MS31098V1
0 0 X Armed
0 1 0 Armed
0 1 1 Disarmed
1 X X Armed
The following procedure must be followed to re-arm the protection after a break event:
• The BKDSRM bit must be set to release the output control
• The software must wait until the system break condition disappears (if any) and clear
the SBIF status flag (or clear it systematically before re-arming)
• The software must poll the BKDSRM bit until it is cleared by hardware (when the
application break condition disappears)
From this point, the break circuitry is armed and active, and the MOE bit can be set to re-
enable the PWM outputs.
AF output
(open drain)
MSv42028V2
Counter (CNT)
tim_ocxref
Write COM to 1
COM event
CCxE = 1 CCxE = 1
CCxNE = 0 Write OCxM to 0100 CCxNE = 0
OCxM = 0010 (forced inactive) OCxM = 0100
tim_ocx
Example 1
tim_ocxn
Write CCxNE to 1
CCxE = 0
CCxE = 1 and OCxM to 0101
CCxNE = 1
CCxNE = 0 OCxM = 0101
OCxM = 0100 (forced inactive)
tim_ocx
Example 2
tim_ocxn
tim_ocx
Example 3
tim_ocxn
MSv62343V1
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY tPULSE t
MS31099V1
For example one may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
Let’s use TI2FP2 as trigger 1:
1. Select the proper TI2[x] source (internal or external) with the TI2SEL[3:0] bits in the
TIMx_TISEL register.
2. Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.
3. TI2FP2 must detect a rising edge, write CC2P=’0’ and CC2NP=’0’ in the TIMx_CCER
register.
4. Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=’00110’
in the TIMx_SMCR register.
5. TI2FP2 is used to start the counter by writing SMS to ‘110’ in the TIMx_SMCR register
(trigger mode).
The OPM waveform is defined by writing the compare registers (taking into account the
clock frequency and the counter prescaler).
• The tDELAY is defined by the value written in the TIMx_CCR1 register.
• The tPULSE is defined by the difference between the auto-reload value and the compare
value (TIMx_ARR - TIMx_CCR1).
• Let’s say one want to build a waveform with a transition from ‘0’ to ‘1’ when a compare
match occurs and a transition from ‘1’ to ‘0’ when the counter reaches the auto-reload
value. To do this PWM mode 2 must be enabled by writing OC1M=111 in the
TIMx_CCMR1 register. Optionally the preload registers can be enabled by writing
OC1PE=’1’ in the TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this
case one has to write the compare value in the TIMx_CCR1 register, the auto-reload
value in the TIMx_ARR register, generate an update by setting the UG bit and wait for
external trigger event on TI2. CC1P is written to ‘0’ in this example.
Since only 1 pulse is needed, a 1 must be written in the OPM bit in the TIMx_CR1 register to
stop the counter at the next update event (when the counter rolls over from the auto-reload
value back to 0).
Particular case: OCx fast enable
In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the
counter. Then the comparison between the counter and the compare value makes the
output toggle. But several clock cycles are needed for these operations and it limits the
minimum delay tDELAY min we can get.
If one wants to output a waveform with the minimum delay, the OCxFE bit can be set in the
TIMx_CCMRx register. Then OCxRef (and OCx) are forced in response to the stimulus,
without taking in account the comparison. Its new level is the same as if a compare match
had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.
The DMA controller destination is unique and must point to the virtual register TIMx_DMAR.
On a given timer event, the timer launches a sequence of DMA requests (burst). Each write
into the TIMx_DMAR register is actually redirected to one of the timer registers.
The DBL[4:0] bits in the TIMx_DCR register set the DMA burst length. The timer recognizes
a burst transfer when a read or a write access is done to the TIMx_DMAR address), i.e. the
number of transfers (either in half-words or in bytes).
The DBA[4:0] bits in the TIMx_DCR registers define the DMA base address for DMA
transfers (when read/write access are done through the TIMx_DMAR address). DBA is
defined as an offset starting from the address of the TIMx_CR1 register.
Example:
00000: TIMx_CR1,
00001: TIMx_CR2,
00010: TIMx_SMCR,
For example, the timer DMA burst feature could be used to update the contents of the CCRx
registers (x = 2, 3, 4) on an update event, with the DMA transferring half words into the
CCRx registers.
This is done in the following steps:
1. Configure the corresponding DMA channel as follows:
– DMA channel peripheral address is the DMAR register address
– DMA channel memory address is the address of the buffer in the RAM containing
the data to be transferred by DMA into the CCRx registers.
– Number of data to transfer = 3 (See note below).
– Circular mode disabled.
2. Configure the DCR register by configuring the DBA and DBL bit fields as follows:
DBL = 3 transfers, DBA = 0xE.
3. Enable the TIMx update DMA request (set the UDE bit in the DIER register).
4. Enable TIMx
5. Enable the DMA channel
This example is for the case where every CCRx register is to be updated once. If every
CCRx register is to be updated twice for example, the number of data to transfer should be
6. Let's take the example of a buffer in the RAM containing data1, data2, data3, data4, data5
and data6. The data is transferred to the CCRx registers as follows: on the first update DMA
request, data1 is transferred to CCR2, data2 is transferred to CCR3, data3 is transferred to
CCR4 and on the second update DMA request, data4 is transferred to CCR2, data5 is
transferred to CCR3 and data6 is transferred to CCR4.
Note: A null value can be written to the reserved registers.
For instance, if the destination's timer CK_INT clock is 4 times slower than the source timer,
the OC1 pulse width must be 8 clock cycles.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. IC1F[3:0] IC1PSC[1:0] CC1S[1:0]
rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OC1M
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
[3]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. OC1M[2:0] OC1PE OC1FE CC1S[1:0]
rw rw rw rw rw rw rw
Table 75. Output control bits for complementary OCx and OCxN channels with break feature
(TIM16/17)
Control bits Output states(1)
MOE bit OSSI bit OSSR bit CCxE bit CCxNE bit OCx output state OCxN output state
Note: The state of the external I/O pins connected to the complementary OCx and OCxN channels
depends on the OCx and OCxN channel state and GPIO control and alternate function
registers.
Note: As the BKBID, BKDSRM, BKF[3:0], AOE, BKP, BKE, OSSI, OSSR and DTG[7:0] bits may
be write-locked depending on the LOCK configuration, it may be necessary to configure all
of them during the first write access to the TIMx_BDTR register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. BKINP Res. Res. Res. Res. Res. Res. Res. Res. BKINE
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TI1SEL[3:0]
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. BKINP Res. Res. Res. Res. Res. Res. Res. Res. BKINE
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TI1SEL[3:0]
rw rw rw rw
0x2C
0x0C
Offset
RM0490
18.4.21
mode
Output
name
TIMx_SR
TIMx_CR2
TIMx_CR1
TIMx_PSC
TIMx_CNT
TIMx_ARR
TIMx_EGR
Register
TIMx_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCER
Input Capture
TIMx_CCMR1
TIMx_CCMR1
Compare mode
below:
0
Res. Res. UIFCPY or Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
TIM16/TIM17 register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0490 Rev 3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
0
Res. Res. Res. Res. Res. OC1M[3] Res. Res. Res. Res. Res. 16
1
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 15
1
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 14
1
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 13
1
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 12
1
0
0
0
1
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 10
1
0
0
0
0
0
0
Table 76. TIM16/TIM17 register map and reset values
1
0
0
0
0
0
1
0
0
0
0
0
0
0
PSC[15:0]
CNT[15:0]
ARR[15:0]
1
0
0
0
0
Res. Res. Res. Res. Res. Res. 6
1
0
0
0
0
0
0
0
IC1F[3:0]
OC1M
1
0
0
0
0
1
0
0
0
0
0
0
0
[1:0]
PSC
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
[1:0]
[1:0]
CC1
CC1
1
0
0
0
0
0
0
0
0
0
0
TIM16/TIM17 registers are mapped as 16-bit addressable registers as described in the table
543/825
General-purpose timers (TIM16/TIM17)
544
0x68
0x68
0x60
0x60
0x48
0x44
0x34
0x30
0x4C
Offset
544/825
name
TIMx_DCR
TIMx_RCR
Register
TIM17_AF1
TIM16_AF1
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCR1
TIMx_BDTR
TIMx_DMAR
TIM17_TISEL
TIM16_TISEL
Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
0
Res. Res. Res. Res. Res. Res. BKBID Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
0
Res. Res. Res. Res. Res. Res. BKDSRM Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
General-purpose timers (TIM16/TIM17)
RM0490 Rev 3
Res. Res. Res. Res. Res. Res. Res. Res. 17
BKF[3:0]
0
0
0
0
0
0
0
0
0
0
DBL[4:0]
0
0
0
0
CCR1[15:0]
DMAB[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
Res. Res. 3
REP[7:0]
DTG[7:0]
0
0
0
0
0
0
0
Res. Res. 2
0
0
0
0
0
0
0
DBA[4:0]
Res. Res. 1
TI1SEL[3:0]
TI1SEL[3:0]
0
0
0
0
0
1
1
0
0
BKINE BKINE
RM0490
0
RM0490 Infrared interface (IRTIM)
An infrared interface (IRTIM) for remote control is available on the device. It can be used
with an infrared LED to perform remote control functions.
It uses internal connections with USART1, USART2, TIM16 and TIM17 as shown in
Figure 206.
To generate the infrared remote control signals, the IR interface must be enabled and TIM16
channel 1 (TIM16_OC1) and TIM17 channel 1 (TIM17_OC1) must be properly configured to
generate correct waveforms.
The infrared receiver can be implemented easily through a basic input capture mode.
Figure 206. IRTIM internal hardware connections with TIM16 and TIM17
TIM17_CH1
IRTIM
IR_OUT
TIM16_CH1
USART1
USART2
IR_MOD[1:0] IR_POL
All standard IR pulse modulation modes can be obtained by programming the two timer
output compare channels.
TIM17 is used to generate the high frequency carrier signal, while TIM16 or alternatively
USART1 or USART2 generates the modulation envelope according to the setting of the
IR_MOD[1:0] bits in the SYSCFG_CFGR1 register.
The polarity of the output signal from IRTIM is controlled by the IR_POL bit in the
SYSCFG_CFGR1 register and can be inverted by setting of this bit.
The infrared function is output on the IR_OUT pin. The activation of this function is done
through the GPIOx_AFRx register by enabling the related alternate function bit.
The high sink LED driver capability (only available on the PB9 and PC14 pins) can be
activated through the I2C_PB9_FMP bit and/or I2C_PC14_FMP bit in the SYSCFG_CFGR1
register and used to sink the high current needed to directly control an infrared LED.
20.1 Introduction
The devices feature an embedded watchdog peripheral that offers a combination of high
safety level, timing accuracy and flexibility of use. The Independent watchdog peripheral
detects and solves malfunctions due to software failure, and triggers system reset when the
counter reaches a given timeout value.
The independent watchdog (IWDG) is clocked by its own dedicated low-speed clock (LSI)
and thus stays active even if the main clock fails.
The IWDG is best suited for applications that require the watchdog to run as a totally
independent process outside the main application, but have lower timing accuracy
constraints. For further information on the window watchdog, refer to Section 21: System
window watchdog (WWDG).
VDD
Prescaler register Status register Reload register Key register
IWDG_PR IWDG_SR IWDG_RLR IWDG_KR
MSv37838V1
1. The register interface is located in the VDD voltage domain. The watchdog function is located in the VDD
voltage domain, still functional in Stop and Standby modes.
When the independent watchdog is started by writing the value 0x0000 CCCC in the IWDG
key register (IWDG_KR), the counter starts counting down from the reset value of 0xFFF.
When it reaches the end of count value (0x000) a reset signal is generated (IWDG reset).
Whenever the key value 0x0000 AAAA is written in the IWDG key register (IWDG_KR), the
IWDG_RLR value is reloaded in the counter and the watchdog reset is prevented.
Once running, the IWDG cannot be stopped.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
KEY[15:0]
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PR[2:0]
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. RL[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WVU RVU PVU
r r r
Note: If several reload, prescaler, or window values are used by the application, it is mandatory to
wait until RVU bit is reset before changing the reload value, to wait until PVU bit is reset
before changing the prescaler value, and to wait until WVU bit is reset before changing the
window value. However, after updating the prescaler and/or the reload/window value it is not
necessary to wait until RVU or PVU or WVU is reset before continuing code execution
except in case of low-power mode entry.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. WIN[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw
0x0C
Offset
554/825
20.4.6
name
IWDG_SR
IWDG_PR
IWDG_KR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
IWDG_RLR
IWDG_WINR
Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. 27
Independent watchdog (IWDG)
25
Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. 18
Res. Res. Res. Res. Res.
RM0490 Rev 3
17
Res. Res. Res. Res. Res. 16
0
Res. Res. 11
Table 77. IWDG register map and reset values
1
1
0
Res. Res. 10
The following table gives the IWDG register map and reset values.
1
1
0
Res. Res. 9
Refer to Section 2.2 on page 39 for the register boundary addresses.
1
1
0
Res. Res. 8
1
1
0
Res. Res. 7
KEY[15:0]
1
1
0
Res. Res. 6
1
1
0
Res. Res. 5
RL[11:0]
WIN[11:0]
1
1
0
Res. Res. 4
1
1
0
Res. Res. 3
1
1
0
0
0
WVU 2
1
1
0
0
0
RVU 1
PR[2:0]
1
1
0
0
0
PVU
RM0490
0
RM0490 System window watchdog (WWDG)
21.1 Introduction
The system window watchdog (WWDG) is used to detect the occurrence of a software fault,
usually generated by external interference or by unforeseen logical conditions, which
causes the application program to abandon its normal sequence.
The watchdog circuit generates an MCU reset on expiry of a programmed time period,
unless the program refreshes the contents of the down-counter before the T6 bit is cleared.
An MCU reset is also generated if the 7-bit down-counter value (in the control register) is
refreshed before the down-counter reaches the window register value. This implies that the
counter must be refreshed in a limited window.
The WWDG clock is prescaled from the APB clock and has a configurable time-window that
can be programmed to detect abnormally late or early application behavior.
The WWDG is best suited for applications requiring the watchdog to react within an
accurate timing window.
WWDG_CFR
CMP
wwdg_out_rst
Logic
= 0x40 ?
WWDG_CR
T[6:0]
EWI wwdg_it
preload
cnt_out EWIF
T[6:0]
W[6:0]
0x3F
Time
Tpclk x 4096 x 2WDGTB
0x41
0x40
0x3F
wwdg_ewit
EWIF = 0
wwdg_rst
T6 bit
MS47266V1
where:
tWWDG: WWDG timeout
tPCLK: APB clock period measured in ms
4096: value corresponding to internal divider
As an example, if APB frequency is 48 MHz, WDGTB[1:0] is set to 3 and T[5:0] is set to 63:
3
t WWDG = ( 1 ⁄ 48000 ) × 4096 × 2 × ( 63 + 1 ) = 43.69ms
Refer to the datasheet for the minimum and maximum values of tWWDG.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. WDGA T[6:0]
rs rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. WDGTB[2:0] Res. EWI Res. Res. W[6:0]
rw rw rw rs rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EWIF
rc_w0
10
11
9
8
7
6
5
4
3
2
1
0
name
WDGA
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x000
WWDG_CR Res. T[6:0]
Reset value 0 1 1 1 1 1 1 1
WDGTB
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EWI
WWDG_CFR W[6:0]
0x004 [2:0]
Reset value 0 0 0 0 1 1 1 1 1 1 1
EWIF
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
WWDG_SR
0x008
Reset value 0
22.1 Introduction
The RTC provides an automatic wakeup to manage all low-power modes.
The real-time clock (RTC) is an independent BCD timer/counter. The RTC provides a time-
of-day clock/calendar with programmable alarm interrupts.
As long as the supply voltage remains in the operating range, the RTC never stops,
regardless of the device status (Run mode, low-power mode or under reset).
TSF
Time stamp detection
RTC_TS
Time stamp registers
RTC_TSTR
RTC_TSDR
RTC_TSSR
RTC_REFIN
CALIB
RTC_OUT1
Output
ALARM= control
TAMPALARM RTC_OUT2
OSEL[1:0]
Alarm A ALRAF
rtc_alra_trg
RTC_ALRMAR =
RTC_ALRMASSR
rtc_it
IRQ interface
rtc_pclk
Registers interface
rtc_pclk clock domain
MSv67530V1
• RTC_OUT1 and RTC_OUT2 which selects one of the following two outputs:
– CALIB: 512 Hz or 1 Hz clock output (with an LSE frequency of 32.768 kHz). This
output is enabled by setting the COE bit in the RTC_CR register.
– TAMPALRM: This output is the ALARM output.
ALARM is enabled by configuring the OSEL[1:0] bits in the RTC_CR register which select
the alarm A output.
The RTC kernel clock is usually the LSE at 32.768 kHz although it is possible to select other
clock sources in the RCC (refer to RCC for more details).
The triggers outputs can be used as triggers for other peripherals.
TAMPALRM_TYPE
TAMPALRM_PU
OSEL[1:0]
OUT2EN
COE
TSE
Pin function
In addition, it is possible to output RTC_OUT2 thanks to OUT2EN bit. The different functions
are mapped on RTC_OUT1 or on RTC_OUT2 depending on OSEL, COE and OUT2EN
configuration, as show in table Table 82.
00 0 - -
00 1 0 CALIB -
01 or 10 or 11 Don’t care TAMPALRM -
00 0 - -
00 1 - CALIB
1
01 or 10 or 11 0 - TAMPALRM
01 or 10 or 11 1 TAMPALRM CALIB
The ck_apre clock is used to clock the binary RTC_SSR subseconds downcounter. When it
reaches 0, RTC_SSR is reloaded with the content of PREDIV_S.
fck_spre is given by the following formula:
f RTCCLK
f CK_SPRE = -----------------------------------------------------------------------------------------------
( PREDIV_S + 1 ) × ( PREDIV_A + 1 )
When the BYPSHAD control bit is set in the RTC_CR register (bypass shadow
registers)
Reading the calendar registers gives the values from the calendar counters directly, thus
eliminating the need to wait for the RSF bit to be set. This is especially useful after exiting
from low-power modes (Stop or Standby), since the shadow registers are not updated
during these modes.
When the BYPSHAD bit is set to 1, the results of the different registers might not be
coherent with each other if an RTCCLK edge occurs between two read accesses to the
registers. Additionally, the value of one of the registers may be incorrect if an RTCCLK edge
occurs during the read operation. The software must read all the registers twice, and then
compare the results to confirm that the data is coherent and correct. Alternatively, the
software can just compare the two results of the least-significant calendar register.
Note: While BYPSHAD = 1, instructions which read the calendar registers require one extra APB
cycle to complete.
As soon as a shift operation is initiated by a write to the RTC_SHIFTR register, the SHPF
flag is set by hardware to indicate that a shift operation is pending. This bit is cleared by
hardware as soon as the shift operation has completed.
Caution: This synchronization feature is not compatible with the reference clock detection feature:
firmware must not write to RTC_SHIFTR when REFCKON = 1.
The smooth digital calibration is performed during a calibration cycle of about 220 RTCCLK
pulses, or 32 seconds when the input frequency is 32768 Hz. This cycle is maintained by a
20-bit counter, cal_cnt[19:0], clocked by RTCCLK.
The smooth calibration register (RTC_CALR) specifies the number of RTCCLK clock cycles
to be masked during the calibration cycle:
• Setting the bit CALM[0] to 1 causes exactly one pulse to be masked during the
calibration cycle.
• Setting CALM[1] to 1 causes two additional cycles to be masked
• Setting CALM[2] to 1 causes four additional cycles to be masked
• and so on up to CALM[8] set to 1 which causes 256 clocks to be masked.
Note: CALM[8:0] (RTC_CALR) specifies the number of RTCCLK pulses to be masked during the
calibration cycle. Setting the bit CALM[0] to 1 causes exactly one pulse to be masked during
the calibration cycle at the moment when cal_cnt[19:0] is 0x80000; CALM[1] = 1 causes two
other cycles to be masked (when cal_cnt is 0x40000 and 0xC0000); CALM[2] = 1 causes
four other cycles to be masked (cal_cnt = 0x20000/0x60000/0xA0000/ 0xE0000); and so on
up to CALM[8] = 1 which causes 256 clocks to be masked (cal_cnt = 0xXX800).
While CALM allows the RTC frequency to be reduced by up to 487.1 ppm with fine
resolution, the bit CALP can be used to increase the frequency by 488.5 ppm. Setting CALP
to 1 effectively inserts an extra RTCCLK pulse every 211 RTCCLK cycles, which means that
512 clocks are added during every calibration cycle.
Using CALM together with CALP, an offset ranging from -511 to +512 RTCCLK cycles can
be added during the calibration cycle, which translates to a calibration range of -487.1 ppm
to +488.5 ppm with a resolution of about 0.954 ppm.
The formula to calculate the effective calibrated frequency (FCAL) given the input frequency
(FRTCCLK) is as follows:
FCAL = FRTCCLK x [1 + (CALP x 512 - CALM) / (220 + CALM - CALP x 512)]
In this case, CALM[7:0] equals 0x100 (the midpoint of the CALM range) is the correct
setting if RTCCLK is exactly 32768.00 Hz.
Re-calibration on-the-fly
The calibration register (RTC_CALR) can be updated on-the-fly while RTC_ICSR/INITF = 0,
by using the follow process:
1. Poll the RTC_ICSR/RECALPF (re-calibration pending flag).
2. If it is set to 0, write a new value to RTC_CALR, if necessary. RECALPF is then
automatically set to 1
3. Within three ck_apre cycles after the write operation to RTC_CALR, the new calibration
settings take effect.
By setting the TSIE bit in the RTC_CR register, an interrupt is generated when a timestamp
event occurs.
If a new timestamp event is detected while the timestamp flag (TSF) is already set, the
timestamp overflow flag (TSOVF) flag is set and the timestamp registers (RTC_TSTR and
RTC_TSDR) maintain the results of the previous event.
Note: TSF is set 2 ck_apre cycles after the timestamp event occurs due to synchronization
process.
There is no delay in the setting of TSOVF. This means that if two timestamp events are
close together, TSOVF can be seen as '1' while TSF is still '0'. As a consequence, it is
recommended to poll TSOVF only after TSF has been set.
Caution: If a timestamp event occurs immediately after the TSF bit is supposed to be cleared, then
both TSF and TSOVF bits are set. To avoid masking a timestamp event occurring at the
same moment, the application must not write 0 into TSF bit unless it has already read it to 1.
TAMPALRM output
The TAMPALRM pin can be configured in output open drain or output push-pull using the
control bit TAMPALRM_TYPE in the RTC_CR register. It is possible to apply the internal
pull-up in output mode thanks to TAMPALRM_PU in the RTC_CR.
Note: Once the TAMPALRM output is enabled, it has priority over CALIB on RTC_OUT1.
In case the TAMPALRM is configured open-drain in the RTC, the RTC_OUT1 GPIO must be
configured as input.
No effect
Sleep
RTC interrupts cause the device to exit the Sleep mode.
The RTC remains active when the RTC clock source is LSE or LSI. RTC interrupts
Stop
cause the device to exit the Stop mode.
Standby The RTC is powered down and must be re-initialized after exiting Standby mode.
Shutdown The RTC is powered down and must be re-initialized after exiting Shutdown mode.
The table below summarizes the RTC pins and functions capability in all modes.
RTC_TS Yes No
RTC_REFIN Yes No
RTC_OUT1 Yes No
RTC_OUT2 Yes No
write 1 in
Alarm A ALRAF ALRAIE Yes Yes(3) No
CALRAF
RTC
write 1 in
Timestamp TSF TSIE Yes Yes(3) No
CTSF
1. The event flags are in the RTC_SR register.
2. The interrupt masked flags (resulting from event flags AND enable control bits) are in the RTC_MISR register.
3. Wakeup from Stop mode is possible only when the RTC clock source is LSE or LSI.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. PM HT[1:0] HU[3:0]
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. MNT[2:0] MNU[3:0] Res. ST[2:0] SU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. YT[3:0] YU[3:0]
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WDU[2:0] MT MU[3:0] Res. Res. DT[1:0] DU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The calendar is frozen when reaching the maximum value, and can’t roll over.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SS[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RECAL
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
PF
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ALRAW
Res. Res. Res. Res. Res. Res. Res. Res. INIT INITF RSF INITS SHPF Res. Res.
F
rw r rc_w0 r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. PREDIV_A[6:0]
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. PREDIV_S[14:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TAMP TAMP
OUT2
ALRM_ ALRM_ Res. Res. Res. Res. Res. COE OSEL[1:0] POL COSEL BKP SUB1H ADD1H
EN
TYPE PU
rw rw rw rw rw rw rw rw rw w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ALRA BYP REFCK TS
TSIE Res. Res. TSE Res. Res. ALRAE Res. FMT Res. Res. Res.
IE SHAD ON EDGE
rw rw rw rw rw rw rw rw
Note: Bits 6 and 4 of this register can be written in initialization mode only (RTC_ICSR/INITF = 1).
It is recommended not to change the hour during the calendar hour increment as it could
mask the incrementation of the calendar hour.
ADD1H and SUB1H changes are effective in the next second.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. KEY[7:0]
w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CALW
CALP CALW8 Res. Res. Res. Res. CALM[8:0]
16
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADD1S Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. SUBFS[14:0]
w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. PM HT[1:0] HU[3:0]
r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. MNT[2:0] MNU[3:0] Res. ST[2:0] SU[3:0]
r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WDU[2:0] MT MU[3:0] Res. Res. DT[1:0] DU[3:0]
r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SS[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
WD
MSK4 DT[1:0] DU[3:0] MSK3 PM HT[1:0] HU[3:0]
SEL
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSK2 MNT[2:0] MNU[3:0] MSK1 ST[2:0] SU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. MASKSS[3:0] Res. Res. Res. Res. Res. Res. Res. Res.
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. SS[14:0]
rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TSOVF TSF Res. Res. ALRAF
r r r
Note: The bits of this register are cleared 2 APB clock cycles after setting their corresponding
clear bit in the RTC_SCR register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TSOV TS ALRA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
MF MF MF
r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CTSOV CTS CALRA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
F F F
w w w
0x2C
0x0C
Offset
590/825
22.6.18
RTC_TR
RTC_CR
RTC_DR
Reserved
Reserved
RTC_SSR
RTC_WPR
RTC_ICSR
Register
RTC_TSTR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
RTC_TSDR
RTC_PRER
RTC_ CALR
RTC_TSSSR
RTC_SHIFTR
0
0
Res. Res. Res. ADD1S Res. Res. OUT2EN Res. Res. Res. Res. Res. 31
Real-time clock (RTC)
0
Res. Res. Res. Res. Res. Res. TAMPALRM_TYPE Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. Res. TAMPALRM_PU Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RTC register map
26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
0
0
Res. Res. Res. Res. Res. Res. COE Res. Res. Res. Res. 23
0
0
1
0
0
O
SEL
[1:0]
0
0
1
0
0
HT[1:0]
HT
[1:0]
0
0
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
0
0
RM0490 Rev 3
17
YU[3:0]
HU[3:0]
HU[3:0]
0
0
1
0
0
0
Res.
0
Res.
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
WDU[1:0]
WDU[2:0]
0
0
0
0
0
0
0
0
MNT[2:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
MU[3:0]
MU[3:0]
MNU[3:0]
MNU[3:0]
0
0
0
0
1
0
0
0
0
0
Res. ALRAE Res. 8
0
0
1
0
0
0
0
SS[15:0]
SS[15:0]
0
0
0
0
1
0
0
0
0
0
SUBFS[14:0]
0
0
0
0
0
1
0
0
0
0
0
0
BYPSHAD RSF 5
DT
DT
ST[2:0]
ST[2:0]
[1:0]
[1:0]
0
0
0
0
0
1
0
0
0
0
0
0
REFCKON INITS 4
0
0
0
0
0
1
0
0
0
0
0
0
TSEDGE SHPF
CALM[8:0]
3
KEY[7:0]
0
1
0
0
0
0
0
0
0
0
Res. Res. 2
0
1
0
0
0
0
0
0
0
0
Res. Res. 1
SU[3:0]
SU[3:0]
DU[3:0]
DU[3:0]
0
1
0
0
0
0
1
0
0
0
1
Res. ALRAWF 0
RM0490
0x58
0x54
0x50
0x44
0x40
0x5C
0x4C
0x48 -
Offset
RM0490
RTC_
RTC_SR
Reserved
Reserved
RTC_SCR
RTC_MISR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
ALRMASSR
RTC_ALRMAR
0
Res. Res. Res. Res. MSK4 31
0
Res. Res. Res. Res. WDSEL 30
0
0
0
MASKSS
0
0
RM0490 Rev 3
17
HU[3:0]
0
MNT[2:0]
0
0
0
0
0
0
0
0
0
591/825
591
Inter-integrated circuit (I2C) interface RM0490
23.1 Introduction
The I2C (inter-integrated circuit) bus interface handles communications between the
microcontroller and the serial I2C bus. It provides multimaster capability, and controls all I2C
bus-specific sequencing, protocol, arbitration and timing. It supports Standard-mode (Sm),
Fast-mode (Fm) and Fast-mode Plus (Fm+).
It is also SMBus (system management bus) and PMBus® (power management bus)
compatible.
DMA can be used to reduce CPU overload.
I2CCLK
i2c_ker_ck
Data control
Digital Analog
Shift register noise noise GPIO
filter I2C_SDA
filter logic
SMBUS
PEC
generation/
check
Wake-up
on
address
match Clock control
Master clock
generation Digital Analog
noise noise
Slave clock GPIO I2C_SCL
filter filter
stretching logic
SMBus
timeout
check
SMBus alert
control/status I2C_SMBA
PCLK
i2c_pclk Registers
APB bus
MSv46198V2
The I2C is clocked by an independent clock source, which allows the I2C to operate
independently from the PCLK frequency.
For I2C I/Os supporting 20 mA output current drive for Fast-mode Plus operation, the driving
capability is enabled through control bits in the system configuration controller (SYSCFG).
Refer to Section 23.3: I2C implementation.
i2c_ker_ck Input I2C kernel clock, also named I2CCLK in this document
i2c_pclk Input I2C APB clock
I2C interrupts, refer to Table 103 for the full list of
i2c_it Output
interrupt sources
i2c_rx_dma Output I2C receive data DMA request (I2C_RX)
i2c_tx_dma Output I2C transmit data DMA request (I2C_TX)
By default, it operates in slave mode. The interface automatically switches from slave to
master when it generates a START condition, and from master to slave if an arbitration loss
or a STOP generation occurs, allowing multimaster capability.
Communication flow
In master mode, the I2C interface initiates a data transfer and generates the clock signal. A
serial data transfer always begins with a START condition and ends with a STOP condition.
Both START and STOP conditions are generated in master mode by software.
In slave mode, the interface is capable of recognizing its own addresses (7- or 10-bit), and
the general call address. The general call address detection can be enabled or disabled by
software. The reserved SMBus addresses can also be enabled by software.
Data and addresses are transferred as 8-bit bytes, MSB first. The first byte(s) following the
START condition contains the address (one in 7-bit mode, two in 10-bit mode). The address
is always transmitted in master mode.
A ninth clock pulse follows the eight clock cycles of a byte transfer, during which the receiver
must send an acknowledge bit to the transmitter (see Figure 212).
SDA
MSB ACK
SCL
1 2 8 9
Start Stop
condition condition
MS19854V1
Acknowledge can be enabled or disabled by software. The I2C interface addresses can be
selected by software.
Noise filters
Before enabling the I2C peripheral by setting the PE bit in I2C_CR1 register, the user must
configure the noise filters, if needed. By default, an analog noise filter is present on the SDA
and SCL inputs. This filter is compliant with the I2C specification, which requires the
suppression of spikes with pulse width up to 50 ns in Fast-mode and Fast-mode Plus. The
user can disable this analog filter by setting the ANFOFF bit, and/or select a digital filter by
configuring the DNF[3:0] bit in the I2C_CR1 register.
When the digital filter is enabled, the level of the SCL or the SDA line is internally changed
only if it remains stable for more than DNF x I2CCLK periods. This allows spikes with a
programmable length of 1 to 15 I2CCLK periods to be suppressed.
Caution: The filter configuration cannot be changed when the I2C is enabled.
I2C timings
The timings must be configured to guarantee correct data hold and setup times, in master
and slave modes. This is done by programming the PRESC[3:0], SCLDEL[3:0] and
SDADEL[3:0] bits in the I2C_TIMINGR register.
The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C
configuration window.
SDA
tHD;DAT
Data hold time: in case of transmission, the data is sent on SDA output after
the SDADEL delay, if it is already available in I2C_TXDR.
SCLDEL
SCL stretched low by the I2C
SCL
SDA
tSU;DAT
SU;STA
Data setup time: in case of transmission, the SCLDEL counter starts
when the data is sent on SDA output. MSv40108V1
MS49608V1
When the SCL falling edge is internally detected, a delay (tSDADEL, impacting the hold time
tHD;DAT) is inserted before sending SDA output: tSDADEL = SDADEL x tPRESC + tI2CCLK, where
tPRESC = (PRESC + 1) x tI2CCLK.
The total SDA output delay is:
tSYNC1 + {[SDADEL x (PRESC + 1) + 1] x tI2CCLK}
tSYNC1 duration depends upon:
– SCL falling slope
– When enabled, input delay brought by the analog filter: tAF(min) < tAF < tAF(max)
– When enabled, input delay brought by the digital filter: tDNF = DNF x tI2CCLK
– Delay due to SCL synchronization to I2CCLK clock (two to three I2CCLK periods)
To bridge the undefined region of the SCL falling edge, the user must program SDADEL in
such a way that:
{tf (max) + tHD;DAT (min) - tAF(min) - [(DNF + 3) x tI2CCLK]} / {(PRESC + 1) x tI2CCLK} ≤ SDADEL
SDADEL ≤ {tHD;DAT (max) - tAF(max) - [(DNF + 4) x tI2CCLK]} / {(PRESC + 1) x tI2CCLK}
Note: tAF(min) / tAF(max) are part of the equation only when the analog filter is enabled. Refer to the
device datasheet for tAF values.
The maximum tHD;DAT can be, respectively, 3.45, 0.9, and 0.45 µs for Standard-mode, Fast-
mode, and Fast-mode Plus. It must be lower than the maximum of tVD;DAT by a transition
time. This maximum must only be met if the device does not stretch the LOW period (tLOW)
of the SCL signal. If the clock stretches the SCL, the data must be valid by the set-up time
before it releases the clock.
The SDA rising edge is usually the worst case. In this case the previous equation becomes:
SDADEL ≤ {tVD;DAT (max) - tr (max) - tAF (max) - [(DNF + 4) x tI2CCLK]} / {(PRESC + 1) x tI2CCLK}.
Note: This condition can be violated when NOSTRETCH = 0, because the device stretches SCL
low to guarantee the set-up time, according to the SCLDEL value.
Refer to Table 91 for tf, tr, tHD;DAT, and tVD;DAT standard values.
• After tSDADEL, or after sending SDA output when the slave had to stretch the clock
because the data was not yet written in I2C_TXDR register, SCL line is kept at low level
during the setup time. This setup time is tSCLDEL = (SCLDEL+ 1) x tPRESC, where
tPRESC = (PRESC+ 1) x tI2CCLK. tSCLDEL impacts the setup time tSU;DAT.
To bridge the undefined region of the SDA transition (rising edge usually worst case), the
user must program SCLDEL in such a way that:
{[tr (max) + tSU;DAT (min)] / [(PRESC+ 1)] x tI2CCLK]} - 1 ≤ SCLDEL
Refer to Table 91 for tr and tSU;DAT standard values.
The SDA and SCL transition time values to use are the ones in the application. Using the
maximum values from the standard increases the constraints for the SDADEL and SCLDEL
calculation, but ensures the feature, whatever the application.
Note: At every clock pulse, after SCL falling edge detection, the I2C master or slave stretches SCL
low during at least [(SDADEL + SCLDEL + 1) x (PRESC + 1) + 1] x tI2CCLK, in both
transmission and reception modes. In transmission mode, if the data is not yet written in
I2C_TXDR when SDADEL counter is finished, the I2C keeps on stretching SCL low until the
next data is written. Then new data MSB is sent on SDA output, and SCLDEL counter starts,
continuing stretching SCL low to guarantee the data setup time.
If NOSTRETCH = 1 in slave mode, the SCL is not stretched. Consequently the SDADEL
must be programmed so that it guarantees a sufficient setup time.
Additionally, in master mode, the SCL clock high and low levels must be configured by
programming the PRESC[3:0], SCLH[7:0] and SCLL[7:0] bit fields in the I2C_TIMINGR
register.
• When the SCL falling edge is internally detected, a delay is inserted before releasing
the SCL output.
This delay is tSCLL = (SCLL + 1) x tPRESC where tPRESC = (PRESC + 1) x tI2CCLK.
tSCLL impacts the SCL low time tLOW.
• When the SCL rising edge is internally detected, a delay is inserted before forcing the
SCL output to low level. This delay is tSCLH = (SCLH + 1) x tPRESC, where
tPRESC = (PRESC+ 1) x tI2CCLK. tSCLH impacts the SCL high time tHIGH.
Refer to I2C master initialization for more details.
Caution: Changing the timing configuration is not allowed when the I2C is enabled.
The I2C slave NOSTRETCH mode must also be configured before enabling the peripheral.
Refer to I2C slave initialization for more details.
Caution: Changing the NOSTRETCH configuration is not allowed when the I2C is enabled.
Initial settings
Configure PRESC[3:0],
End
MS19847V2
communication control bits, as well as status bits come back to their reset value. The
configuration registers are not impacted.
Here is the list of impacted register bits:
1. I2C_CR2 register: START, STOP, NACK
2. I2C_ISR register: BUSY, TXE, TXIS, RXNE, ADDR, NACKF, TCR, TC, STOPF, BERR,
ARLO, OVR
and in addition when the SMBus feature is supported:
1. I2C_CR2 register: PECBYTE
2. I2C_ISR register: PECERR, TIMEOUT, ALERT
PE must be kept low during at least three APB clock cycles in order to perform the software
reset. This is ensured by writing the following software sequence:
1. Write PE = 0
2. Check PE = 0
3. Write PE = 1
Reception
The SDA input fills the shift register. After the eighth SCL pulse (when the complete data
byte is received), the shift register is copied into I2C_RXDR register if it is empty
(RXNE = 0). If RXNE = 1, meaning that the previous received data byte has not yet been
read, the SCL line is stretched low until I2C_RXDR is read. The stretch is inserted between
the eighth and ninth SCL pulse (before the acknowledge pulse).
RXNE
rd data0 rd data1
MS19848V1
Transmission
If the I2C_TXDR register is not empty (TXE = 0 ), its content is copied into the shift register
after the ninth SCL pulse (the acknowledge pulse). Then the shift register content is shifted
out on SDA line. If TXE = 1, meaning that no data is written yet in I2C_TXDR, SCL line is
stretched low until I2C_TXDR is written. The stretch is done after the ninth SCL pulse.
data1
data2
Shift register xx xx xx
TXE
wr data1 wr data2
MS19849V1
When RELOAD = 0 in master mode, the counter can be used in two modes:
• Automatic end mode (AUTOEND = ‘1’ in the I2C_CR2 register). In this mode, the
master automatically sends a STOP condition once the number of bytes programmed
in the NBYTES[7:0] bit field is transferred.
• Software end mode (AUTOEND = ‘0’ in the I2C_CR2 register). In this mode, software
action is expected once the number of bytes programmed in the NBYTES[7:0] bit field
is transferred; the TC flag is set and an interrupt is generated if the TCIE bit is set. The
SCL signal is stretched as long as the TC flag is set. The TC flag is cleared by software
when the START or STOP bit is set in the I2C_CR2 register. This mode must be used
when the master wants to send a RESTART condition.
Caution: The AUTOEND bit has no effect when the RELOAD bit is set.
support clock stretching, the I2C must be configured with NOSTRETCH = 1 in the I2C_CR1
register.
After receiving an ADDR interrupt, if several addresses are enabled the user must read the
ADDCODE[6:0] bits in the I2C_ISR register in order to check which address matched. DIR
flag must also be checked in order to know the transfer direction.
Slave
initialization
Initial settings
End
MS19850V2
Slave transmitter
A transmit interrupt status (TXIS) is generated when the I2C_TXDR register becomes
empty. An interrupt is generated if the TXIE bit is set in the I2C_CR1 register.
The TXIS bit is cleared when the I2C_TXDR register is written with the next data byte to be
transmitted.
When a NACK is received, the NACKF bit is set in the I2C_ISR register and an interrupt is
generated if the NACKIE bit is set in the I2C_CR1 register. The slave automatically releases
the SCL and SDA lines in order to let the master perform a STOP or a RESTART condition.
The TXIS bit is not set when a NACK is received.
When a STOP is received and the STOPIE bit is set in the I2C_CR1 register, the STOPF
flag is set in the I2C_ISR register and an interrupt is generated. In most applications, the
SBC bit is usually programmed to ‘0’. In this case, If TXE = 0 when the slave address is
received (ADDR = 1), the user can choose either to send the content of the I2C_TXDR
register as the first data byte, or to flush the I2C_TXDR register by setting the TXE bit in
order to program a new data byte.
In Slave byte control mode (SBC = 1), the number of bytes to be transmitted must be
programmed in NBYTES in the address match interrupt subroutine (ADDR = 1). In this
case, the number of TXIS events during the transfer corresponds to the value programmed
in NBYTES.
Caution: When NOSTRETCH = 1, the SCL clock is not stretched while the ADDR flag is set, so the
user cannot flush the I2C_TXDR register content in the ADDR subroutine, in order to
program the first data byte. The first data byte to be sent must be previously programmed in
the I2C_TXDR register:
• This data can be the data written in the last TXIS event of the previous transmission
message.
• If this data byte is not the one to be sent, the I2C_TXDR register can be flushed by
setting the TXE bit in order to program a new data byte. The STOPF bit must be
cleared only after these actions, in order to guarantee that they are executed before the
first data transmission starts, following the address acknowledge.
If STOPF is still set when the first data transmission starts, an underrun error is
generated (the OVR flag is set).
If a TXIS event is needed, (transmit interrupt or transmit DMA request), the user must
set the TXIS bit in addition to the TXE bit, in order to generate a TXIS event.
Figure 218. Transfer sequence flow for I2C slave transmitter, NOSTRETCH = 0
Slave
transmission
Slave initialization
No
I2C_ISR.ADDR
=1?
Yes
SCL
stretched
Read ADDCODE and DIR in I2C_ISR
Optional: Set I2C_ISR.TXE = 1
Set I2C_ICR.ADDRCF
No
I2C_ISR.TXIS
=1?
Yes
Write I2C_TXDR.TXDATA
MS19851V2
Figure 219. Transfer sequence flow for I2C slave transmitter, NOSTRETCH = 1
Slave
transmission
Slave initialization
No
No
I2C_ISR.TXIS I2C_ISR.STOPF
=1? =1?
Yes Yes
Set I2C_ICR.STOPCF
MS19852V2
Figure 220. Transfer bus diagrams for I2C slave transmitter (mandatory events only)
legend:
Example I2C slave transmitter 3 bytes with 1st data flushed,
NOSTRETCH=0: transmission
ADDR TXIS TXIS TXIS TXIS reception
S Address A A A data3 NA P
SCL stretch
data1 data2
TXE
EV1: ADDR ISR: check ADDCODE and DIR, set TXE, set ADDRCF
EV2: TXIS ISR: wr data1
EV3: TXIS ISR: wr data2
EV4: TXIS ISR: wr data3
EV5: TXIS ISR: wr data4 (not sent)
legend :
Example I2C slave transmitter 3 bytes without 1st data flush,
NOSTRETCH=0: transmission
ADDR TXIS TXIS TXIS reception
SCL stretch
S Address A data1 A data2 A data3 NA P
TXE
legend:
Example I2C slave transmitter 3 bytes, NOSTRETCH=1:
transmission
TXIS TXIS TXIS STOPF
reception
TXE
EV1: wr data1
EV2: TXIS ISR: wr data2
EV3: TXIS ISR: wr data3
EV4: TXIS ISR: wr data4 (not sent)
EV5: STOPF ISR: (optional: set TXE and TXIS), set STOPCF
MS19853V2
Slave receiver
RXNE is set in I2C_ISR when the I2C_RXDR is full, and generates an interrupt if RXIE is
set in I2C_CR1. RXNE is cleared when I2C_RXDR is read.
When a STOP is received and STOPIE is set in I2C_CR1, STOPF is set in I2C_ISR and an
interrupt is generated.
Figure 221. Transfer sequence flow for slave receiver with NOSTRETCH = 0
Slave reception
Slave initialization
No
I2C_ISR.ADDR
=1?
Yes
SCL
stretched
Read ADDCODE and DIR in I2C_ISR
Set I2C_ICR.ADDRCF
No
I2C_ISR.RXNE
=1?
Yes
Write I2C_RXDR.RXDATA
MS19855V2
Figure 222. Transfer sequence flow for slave receiver with NOSTRETCH = 1
Slave reception
Slave initialization
No
No
I2C_ISR.RXNE I2C_ISR.STOPF
=1? =1?
Yes Yes
MS19856V2
Transmission
ADDR RXNE RXNE RXNE
Reception
RXNE
Transmission
RXNE RXNE RXNE
Reception
RXNE
tSYNC2 SCLH
SCLL
tSYNC1
SCL
SCL high level detected SCL high level detected SCL high level detected
SCLH counter starts SCLH counter starts SCLH counter starts
SCLL SCLL
MS19858V1
Caution: To be I2C or SMBus compliant, the master clock must respect the timings given in the
following table.
Note: SCLL is also used to generate the tBUF and tSU:STA timings, and SCLH is also used to generate
the tHD:STA and tSU:STO timings.
Refer to Section 23.4.10 for examples of I2C_TIMINGR settings vs. I2CCLK frequency.
Note: The START bit is reset by hardware when the slave address is sent on the bus, whatever
the received acknowledge value. The START bit is also reset by hardware if an arbitration
loss occurs.
In 10-bit addressing mode, when the slave address first 7 bits are NACKed by the slave, the
master re-launches automatically the slave address transmission until ACK is received. In
this case ADDRCF must be set if a NACK is received from the slave, in order to stop
sending the slave address.
If the I2C is addressed as a slave (ADDR = 1) while the START bit is set, the I2C switches to
slave mode and the START bit is cleared.
Note: The same procedure is applied for a repeated start condition. In this case BUSY = 1.
Master
initialization
Initial settings
End
MS19859V2
11110XX 0 11110XX 1
Write Read
MSv41066V1
• If the master addresses a 10-bit address slave, transmits data to this slave and then
reads data from the same slave, a master transmission flow must be done first. Then a
repeated start is set with the 10 bit slave address configured with HEAD10R = 1. In this
case the master sends this sequence: ReStart + Slave address 10-bit header Read.
11110XX 0
Write
11110XX 1
Slave address
Sr R/W A DATA A DATA A P
1st 7 bits
Read
MS19823V1
Master transmitter
In the case of a write transfer, the TXIS flag is set after each byte transmission, after the
ninth SCL pulse when an ACK is received.
A TXIS event generates an interrupt if the TXIE bit is set in the I2C_CR1 register. The flag is
cleared when the I2C_TXDR register is written with the next data byte to be transmitted.
The number of TXIS events during the transfer corresponds to the value programmed in
NBYTES[7:0]. If the total number of data bytes to be sent is greater than 255, reload mode
must be selected by setting the RELOAD bit in the I2C_CR2 register. In this case, when
NBYTES data have been transferred, the TCR flag is set and the SCL line is stretched low
until NBYTES[7:0] is written to a non-zero value.
The TXIS flag is not set when a NACK is received.
• When RELOAD = 0 and NBYTES data have been transferred:
– In automatic end mode (AUTOEND = 1), a STOP is automatically sent.
– In software end mode (AUTOEND = 0), the TC flag is set and the SCL line is
stretched low in order to perform software actions:
A RESTART condition can be requested by setting the START bit in the I2C_CR2
register with the proper slave address configuration, and number of bytes to be
transferred. Setting the START bit clears the TC flag and the START condition is
sent on the bus.
A STOP condition can be requested by setting the STOP bit in the I2C_CR2
register. Setting the STOP bit clears the TC flag and the STOP condition is sent on
the bus.
• If a NACK is received: the TXIS flag is not set, and a STOP condition is automatically
sent after the NACK reception. the NACKF flag is set in the I2C_ISR register, and an
interrupt is generated if the NACKIE bit is set.
Figure 228. Transfer sequence flow for I2C master transmitter for N ≤ 255 bytes
Master
transmission
Master initialization
NBYTES = N
AUTOEND = 0 for RESTART; 1 for STOP
Configure slave address
Set I2C_CR2.START
No
No
I2C_ISR.NACKF = I2C_ISR.TXIS
1? =1?
Yes Yes
Write I2C_TXDR
End
NBYTES No
transmitted?
Yes
Yes
I2C_ISR.TC =
1?
End
MS19860V2
Figure 229. Transfer sequence flow for I2C master transmitter for N > 255 bytes
Master
transmission
Master initialization
No
No
I2C_ISR.NACKF I2C_ISR.TXIS
= 1? = 1?
Yes Yes
Write I2C_TXDR
End
No
NBYTES
transmitted ?
Yes
Yes
I2C_ISR.TC
= 1?
Set I2C_CR2.START
with slave addess No
NBYTES ...
I2C_ISR.TCR
= 1?
Yes
IF N< 256
NBYTES = N; N = 0; RELOAD = 0
AUTOEND = 0 for RESTART; 1 for STOP
End
ELSE
NBYTES = 0xFF; N = N-255
RELOAD = 1
MS19861V3
reception
S Address A data1 A data2 A P
SCL stretch
INIT EV1 EV2
TXE
NBYTES xx 2
transmission
S Address A data1 A data2 A ReS Address
reception
NBYTES xx 2
MS19862V2
Master receiver
In the case of a read transfer, the RXNE flag is set after each byte reception, after the eighth
SCL pulse. An RXNE event generates an interrupt if the RXIE bit is set in the I2C_CR1
register. The flag is cleared when I2C_RXDR is read.
If the total number of data bytes to be received is greater than 255, reload mode must be
selected by setting the RELOAD bit in the I2C_CR2 register. In this case, when
NBYTES[7:0] data have been transferred, the TCR flag is set and the SCL line is stretched
low until NBYTES[7:0] is written to a non-zero value.
• When RELOAD = 0 and NBYTES[7:0] data have been transferred:
– In automatic end mode (AUTOEND = 1), a NACK and a STOP are automatically
sent after the last received byte.
– In software end mode (AUTOEND = 0), a NACK is automatically sent after the last
received byte, the TC flag is set and the SCL line is stretched low in order to allow
software actions:
A RESTART condition can be requested by setting the START bit in the I2C_CR2
register with the proper slave address configuration, and number of bytes to be
transferred. Setting the START bit clears the TC flag and the START condition,
followed by slave address, are sent on the bus.
A STOP condition can be requested by setting the STOP bit in the I2C_CR2
register. Setting the STOP bit clears the TC flag and the STOP condition is sent on
the bus.
Figure 231. Transfer sequence flow for I2C master receiver for N ≤ 255 bytes
Master reception
Master initialization
NBYTES = N
AUTOEND = 0 for RESTART; 1 for STOP
Configure slave address
Set I2C_CR2.START
No
I2C_ISR.RXNE
=1?
Yes
Read I2C_RXDR
NBYTES No
received?
Yes
Yes
I2C_ISR.TC =
1?
End
MS19863V2
Figure 232. Transfer sequence flow for I2C master receiver for N > 255 bytes
Master reception
Master initialization
No
I2C_ISR.RXNE
=1?
Yes
Read I2C_RXDR
NBYTES No
received?
Yes
Yes
I2C_ISR.TC =
1?
Yes
IF N< 256
NBYTES =N; N=0;RELOAD=0
AUTOEND=0 for RESTART; 1 for STOP
ELSE
NBYTES =0xFF;N=N-255
RELOAD=1
End
MS19864V2
RXNE RXNE
legend:
reception
INIT EV1 EV2
SCL stretch
NBYTES xx 2
transmission
S Address A data1 A data2 NA ReS Address
reception
NBYTES
xx 2 N
MS19865V1
Introduction
The system management bus (SMBus) is a two-wire interface through which various
devices can communicate with each other and with the rest of the system. It is based on I2C
principles of operation. The SMBus provides a control bus for system and power
management related tasks.
This peripheral is compatible with the SMBus specification (http://smbus.org).
The system management bus specification refers to three types of devices
• A slave is a device that receives or responds to a command.
• A master is a device that issues commands, generates the clocks and terminates the
transfer.
• A host is a specialized master that provides the main interface to the system’s CPU. A
host must be a master-slave and must support the SMBus host notify protocol. Only
one host is allowed in a system.
This peripheral can be configured as master or slave device, and also as a host.
Bus protocols
There are eleven possible command protocols for any given device. A device may use any
or all of the eleven protocols to communicate. The protocols are Quick Command, Send
Byte, Receive Byte, Write Byte, Write Word, Read Byte, Read Word, Process Call, Block
Read, Block Write and Block Write-Block Read Process Call. These protocols must be
implemented by the user software.
For more details on these protocols, refer to SMBus specification (http://smbus.org).
SMBus alert
The SMBus ALERT optional signal is supported. A slave-only device can signal the host
through the SMBALERT# pin that it wants to talk. The host processes the interrupt and
simultaneously accesses all SMBALERT# devices through the alert response address
(0b0001 100). Only the device(s) which pulled SMBALERT# low acknowledges the alert
response address.
When configured as a slave device(SMBHEN = 0), the SMBA pin is pulled low by setting the
ALERTEN bit in the I2C_CR1 register. The Alert Response Address is enabled at the same
time.
When configured as a host (SMBHEN = 1), the ALERT flag is set in the I2C_ISR register
when a falling edge is detected on the SMBA pin and ALERTEN = 1. An interrupt is
generated if the ERRIE bit is set in the I2C_CR1 register. When ALERTEN = 0, the ALERT
line is considered high even if the external SMBA pin is low.
If the SMBus ALERT pin is not needed, the SMBA pin can be used as a standard GPIO if
ALERTEN = 0.
The PEC is calculated by using the C(x) = x8 + x2 + x + 1 CRC-8 polynomial on all the
message bytes (including addresses and read/write bits).
The peripheral embeds a hardware PEC calculator and allows a not acknowledge to be sent
automatically when the received byte does not match with the hardware calculated PEC.
Timeouts
This peripheral embeds hardware timers in order to be compliant with the three timeouts
defined in SMBus specification.
Start Stop
tLOW:SEXT
ClkAck ClkAck
tLOW:MEXT tLOW:MEXT tLOW:MEXT
SMBCLK
SMBDAT
MS19866V1
Timeout detection
The timeout detection is enabled by setting the TIMOUTEN and TEXTEN bits in the
I2C_TIMEOUTR register. The timers must be programmed in such a way that they detect a
timeout before the maximum time given in the SMBus specification.
• tTIMEOUT check
To enable the tTIMEOUT check, the 12-bit TIMEOUTA[11:0] bits must be programmed
with the timer reload value, to check the tTIMEOUT parameter. The TIDLE bit must be
configured to ‘0’ to detect the SCL low level timeout.
Then the timer is enabled by setting the TIMOUTEN in the I2C_TIMEOUTR register.
If SCL is tied low for a time greater than (TIMEOUTA + 1) x 2048 x tI2CCLK, the
TIMEOUT flag is set in the I2C_ISR register.
Refer to Table 99.
Caution: Changing the TIMEOUTA[11:0] bits and TIDLE bit configuration is not allowed when the
TIMEOUTEN bit is set.
• tLOW:SEXT and tLOW:MEXT check
Depending on if the peripheral is configured as a master or as a slave, The 12-bit
TIMEOUTB timer must be configured in order to check tLOW:SEXT for a slave and
tLOW:MEXT for a master. As the standard specifies only a maximum, the user can choose
the same value for the both.
Then the timer is enabled by setting the TEXTEN bit in the I2C_TIMEOUTR register.
If the SMBus peripheral performs a cumulative SCL stretch for a time greater than
(TIMEOUTB + 1) x 2048 x tI2CCLK, and in the timeout interval described in Bus idle
detection section, the TIMEOUT flag is set in the I2C_ISR register.
Refer to Table 100
Caution: Changing the TIMEOUTB configuration is not allowed when the TEXTEN bit is set.
Figure 235. Transfer sequence flow for SMBus slave transmitter N bytes + PEC
SMBus slave
transmission
Slave initialization
No
I2C_ISR.ADDR =
1?
Yes
No
I2C_ISR.TXIS
=1?
Yes
Write I2C_TXDR.TXDATA
MS19867V2
Figure 236. Transfer bus diagrams for SMBus slave transmitter (SBC = 1)
legend:
Example SMBus slave transmitter 2 bytes + PEC,
transmission
ADDR TXIS TXIS reception
NBYTES 3
EV1: ADDR ISR: check ADDCODE, program NBYTES=3, set PECBYTE, set ADDRCF
EV2: TXIS ISR: wr data1
EV3: TXIS ISR: wr data2
MS19869V2
Figure 237. Transfer sequence flow for SMBus slave receiver N bytes + PEC
SMBus slave
reception
Slave initialization
No
I2C_ISR.ADDR =
1?
Yes
No
I2C_ISR.RXNE =1?
I2C_ISR.TCR = 1?
Yes
Read I2C_RXDR.RXDATA
Program I2C_CR2.NACK = 0
I2C_CR2.NBYTES = 1
N=N-1
No
N = 1?
Yes
Read I2C_RXDR.RXDATA
Program RELOAD = 0
NACK = 0 and NBYTES = 1
No
I2C_ISR.RXNE =1?
Yes
Read I2C_RXDR.RXDATA
End
MS19868V2
Figure 238. Bus transfer diagrams for SMBus slave receiver (SBC = 1)
legend:
Example SMBus slave receiver 2 bytes + PEC
transmission
ADDR RXNE RXNE RXNE
reception
NBYTES 3
EV1: ADDR ISR: check ADDCODE and DIR, program NBYTES = 3, PECBYTE=1, RELOAD=0, set ADDRCF
EV2: RXNE ISR: rd data1
EV3: RXNE ISR: rd data2
EV4: RXNE ISR: rd PEC
Example SMBus slave receiver 2 bytes + PEC, with ACK control legend :
(RELOAD=1/0) transmission
ADDR RXNE,TCR RXNE,TCR RXNE
reception
NBYTES 1
EV1: ADDR ISR: check ADDCODE and DIR, program NBYTES = 1, PECBYTE=1, RELOAD=1, set ADDRCF
EV2: RXNE-TCR ISR: rd data1, program NACK=0 and NBYTES = 1
EV3: RXNE-TCR ISR: rd data2, program NACK=0, NBYTES = 1 and RELOAD=0
EV4: RXNE-TCR ISR: rd PEC
MS19870V2
This section is relevant only when the SMBus feature is supported (refer to Section 23.3).
In addition to I2C master transfer management (refer to Section 23.4.9), some additional
software flows are provided to support the SMBus.
transmitted, the I2C_PECR register content is transmitted and the TC flag is set after the
PEC transmission, stretching the SCL line low. The RESTART condition must be
programmed in the TC interrupt subroutine.
Caution: The PECBYTE bit has no effect when the RELOAD bit is set.
Example SMBus master transmitter 2 bytes + PEC, automatic end mode (STOP)
TXIS TXIS
legend:
reception
INIT EV1 EV2
SCL stretch
TXE
NBYTES xx 3
INIT: program Slave address, program NBYTES = 3, AUTOEND=1, set PECBYTE, set START
EV1: TXIS ISR: wr data1
EV2: TXIS ISR: wr data2
Example SMBus master transmitter 2 bytes + PEC, software end mode (RESTART)
TC legend:
TXIS TXIS
transmission
S Address A data1 A data2 A PEC A Rstart Address
reception
xx 3 N
NBYTES
INIT: program Slave address, program NBYTES = 3, AUTOEND=0, set PECBYTE, set START
EV1: TXIS ISR: wr data1
EV2: TXIS ISR: wr data2
EV3: TC ISR: program Slave address, program NBYTES = N, set START
MS19871V2
Example SMBus master receiver 2 bytes + PEC, automatic end mode (STOP)
reception
INIT EV1 EV2 EV3
SCL stretch
NBYTES xx 3
INIT: program Slave address, program NBYTES = 3, AUTOEND=1, set PECBYTE, set START
EV1: RXNE ISR: rd data1
EV2: RXNE ISR: rd data2
EV3: RXNE ISR: rd PEC
Example SMBus master receiver 2 bytes + PEC, software end mode (RESTART)
transmission
S Address A data1 A data2 A PEC NA Restart Address
reception
NBYTES
xx 3 N
INIT: program Slave address, program NBYTES = 3, AUTOEND=0, set PECBYTE, set START
EV1: RXNE ISR: rd data1
EV2: RXNE ISR: rd data2
EV3: RXNE ISR: read PEC
EV4: TC ISR: program Slave address, program NBYTES = N, set START
MS19872V2
In case of an address match, the I2C stretches SCL low during MCU wake-up time. The
stretch is released when ADDR flag is cleared by software, and the transfer goes on
normally.
If the address does not match, the HSI48 is switched off again and the MCU is not woken
up.
Note: If the I2C clock is the system clock, or if WUPEN = 0, the HSI48 is not switched on after a
START is received.
Only an ADDR interrupt can wake-up the MCU. Therefore do not enter Stop mode when the
I2C is performing a transfer as a master, or as an addressed slave after the ADDR flag is
set. This can be managed by clearing SLEEPDEEP bit in the ADDR interrupt routine and
setting it again only after the STOPF flag is set.
Caution: The digital filter is not compatible with the wake-up from Stop mode feature. If the DNF bit is
not equal to 0, setting the WUPEN bit has no effect.
Caution: This feature is available only when the I2C clock source is the HSI48 oscillator.
Caution: Clock stretching must be enabled (NOSTRETCH = 0) to ensure proper operation of the
wake-up from Stop mode feature.
Caution: If wake-up from Stop mode is disabled (WUPEN = 0), the I2C peripheral must be disabled
before entering Stop mode (PE = 0).
Alert (ALERT)
This section is relevant only when the SMBus feature is supported (refer to Section 23.3).
The ALERT flag is set when the I2C interface is configured as a Host (SMBHEN = 1), the
alert pin detection is enabled (ALERTEN = 1) and a falling edge is detected on the SMBA
pin. An interrupt is generated if the ERRIE bit is set in the I2C_CR1 register.
Sleep No effect. I2C interrupts cause the device to exit the Sleep mode.
The I2C registers content is kept.
– WUPEN = 1 and I2C is clocked by an internal oscillator (HSI48): the address
Stop(1) recognition is functional. The I2C address match condition causes the device to exit the
Stop mode.
– WUPEN = 0: the I2C must be disabled before entering Stop mode.
Standby The I2C peripheral is powered down and must be reinitialized after exiting Standby mode.
1. Refer to Section 23.3 for information about the Stop modes supported by each instance. If wake-up from a
specific Stop mode is not supported, the instance must be disabled before entering this Stop mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ALERT SMBD SMBH WUPE NOSTR
Res. Res. Res. Res. Res. Res. Res. Res. PECEN GCEN SBC
EN EN EN N ETCH
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RXDMA TXDMA ANF STOP NACK ADDR
Res. DNF[3:0] ERRIE TCIE RXIE TXIE PE
EN EN OFF IE IE IE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PEC AUTO RE
Res. Res. Res. Res. Res. NBYTES[7:0]
BYTE END LOAD
rs rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HEAD1 RD_
NACK STOP START ADD10 SADD[9:0]
0R WRN
rs rs rs rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OA1
OA1EN Res. Res. Res. Res. OA1[9:0]
MODE
rw rw rw rw rw rw rw rw rw rw rw rw
one is completed. The latency of the second write access can be up to 2x PCLK1 +
6 x I2CCLK.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OA2EN Res. Res. Res. Res. OA2MSK[2:0] OA2[7:1] Res.
rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SCLH[7:0] SCLL[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register must be configured when the I2C is disabled (PE = 0).
Note: The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C
Configuration window.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TEXTEN Res. Res. Res. TIMEOUTB[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIMOUTEN Res. Res. TIDLE TIMEOUTA[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: If the SMBus feature is not supported, this register is reserved and forced by hardware to
“0x00000000”. Refer to Section 23.3.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. ADDCODE[6:0] DIR
r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIME PEC
BUSY Res. ALERT OVR ARLO BERR TCR TC STOPF NACKF ADDR RXNE TXIS TXE
OUT ERR
r r r r r r r r r r r r r rs rs
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ALERT TIMOU ARLOC BERRC STOPC NACKC ADDR
Res. Res. PECCF OVRCF Res. Res. Res. Res. Res.
CF TCF F F F F CF
w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r
Note: If the SMBus feature is not supported, this register is reserved and forced by hardware to
“0x00000000”. Refer to Section 23.3.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. RXDATA[7:0]
r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. TXDATA[7:0]
rw rw rw rw rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
name
NOSTRETCH
RXDMAEN
TXDMAEN
ALERTEN
SMBDEN
SMBHEN
ANFOFF
ADDRIE
WUPEN
NACKIE
STOPIE
PECEN
ERRIE
GCEN
RXIE
TCIE
TXIE
SBC
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PE
I2C_CR1 DNF[3:0]
0x0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
AUTOEND
PECBYTE
HEAD10R
RD_WRN
RELOAD
ADD10
START
NACK
STOP
Res.
Res.
Res.
Res.
Res.
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OA1MODE
OA1EN
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
I2C_OAR1 OA1[9:0]
0x8
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
OA2EN
OA2MS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
I2C_OAR2 OA2[7:1]
K [2:0]
0xC
Reset value 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x1C
Offset
RM0490
I2C_
name
I2C_ISR
I2C_ICR
I2C_TXDR
I2C_PECR
I2C_RXDR
Register
TIMEOUTR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
0
Res. Res. Res. Res. Res. TEXTEN 31
Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. 28
0
0
0
0
0
RM0490 Rev 3
0
0
0
Table 104. I2C register map and reset values (continued)
0
0
0
Res. TCR 7
0
0
0
0
0
Res. TC 6
0
0
0
0
0
STOPCF STOPF 5
0
0
0
0
0
NACKCF NACKF 4
TIMEOUTA[11:0]
0
0
0
0
0
ADDRCF ADDR 3
PEC[7:0]
TXDATA[7:0]
0
0
0
0
0
RXDATA[7:0]
Res. RXNE 2
0
0
0
0
0
Res. TXIS 1
1
0
0
0
0
657/825
Inter-integrated circuit (I2C) interface
Res. TXE
657
Universal synchronous receiver transmitter (USART) RM0490
USART1 FULL
USART2 BASIC
USART
usart_ker_ck clock domain
usart_wkup
IRQ Interface
usart_it usart_pclk
usart_tx_dma clock domain
DMA Interface
usart_rx_dma
COM Controller
CK
USART_CR1
USART_ISR
USART_CR2 CTS/NSS
Hardware
USART_CR3 flow control
RTS/DE
USART_RQR
32-bit APB bus
TxFIFO
USART_TDR
RX Shift Reg RX
...
RxFIFO
USART_RDR
USART_
RTOR Baudrate
USART_GTPR generator &
USART_BRR orversampling
usart_pclk
USART_ usart_ker_ck_pres
usart_ker_ck PRESC
MSv40854V3
The simplified block diagram given in Figure 241 shows two fully-independent clock
domains:
• The usart_pclk clock domain
The usart_pclk clock signal feeds the peripheral bus interface. It must be active when
accesses to the USART registers are required.
• The usart_ker_ck kernel clock domain.
The usart_ker_ck is the USART clock source. It is independent from usart_pclk and
delivered by the RCC. The USART registers can consequently be written/read even
when the usart_ker_ck clock is stopped.
When the dual clock domain feature is disabled, the usart_ker_ck clock is the same as
the usart_pclk clock.
There is no constraint between usart_pclk and usart_ker_ck: usart_ker_ck can be faster
or slower than usart_pclk. The only limitation is the software ability to manage the
communication fast enough.
When the USART operates in SPI slave mode, it handles data flow using the serial interface
clock derived from the external CK signal provided by the external master SPI device. The
usart_ker_ck clock must be at least 3 times faster than the clock on the CK input.
Clock **
Start
Idle frame bit
Clock **
Start
Idle frame bit
Clock **
Start
Idle frame bit
Character transmission
During an USART transmission, data shifts out the least significant bit first (default
configuration) on the TX pin. In this mode, the USART_TDR register consists of a buffer
(TDR) between the internal bus and the transmit shift register.
When FIFO mode is enabled, the data written to the transmit data register (USART_TDR)
are queued in the TXFIFO.
Every character is preceded by a start bit which corresponds to a low logic level for one bit
period. The character is terminated by a configurable number of stop bits.
The number of stop bits can be configured to 0.5, 1, 1.5 or 2.
Note: The TE bit must be set before writing the data to be transmitted to the USART_TDR.
The TE bit should not be reset during data transmission. Resetting the TE bit during the
transmission corrupts the data on the TX pin as the baud rate counters get frozen. The
current data being transmitted are then lost.
An idle frame is sent when the TE bit is enabled.
Configurable stop bits
The number of stop bits to be transmitted with every character can be programmed in
USART_CR2, bits 13,12.
• 1 stop bit: This is the default value of number of stop bits.
• 2 stop bits: This is supported by normal USART, Single-wire and Modem modes.
• 1.5 stop bits: To be used in Smartcard mode.
An idle frame transmission includes the stop bits.
A break transmission features 10 low bits (when M[1:0] = ‘00’) or 11 low bits (when
M[1:0] = ‘01’) or 9 low bits (when M[1:0] = ‘10’) followed by 2 stop bits (see Figure 243). It is
not possible to transmit long breaks (break of length greater than 9/10/11 low bits).
TX line
Set by hardware Set by hardware
TXE flag cleared by software cleared by software Set by hardware
USART_DR F1 F2 F3
Set by hardware
TC flag
ai17121b
Note: When FIFO management is enabled, the TXFNF flag is used for data transmission.
Break characters
Setting the SBKRQ bit transmits a break character. The break frame length depends on the
M bit (see Figure 242).
If a ‘1’ is written to the SBKRQ bit, a break character is sent on the TX line after completing
the current character transmission. The SBKF bit is set by the write operation and it is reset
by hardware when the break character is completed (during the stop bits after the break
character). The USART inserts a logic 1 signal (stop) for the duration of 2 bits at the end of
the break frame to guarantee the recognition of the start bit of the next frame.
When the SBKRQ bit is set, the break character is sent at the end of the current
transmission.
When FIFO mode is enabled, sending the break character has priority on sending data even
if the TXFIFO is full.
Idle characters
Setting the TE bit drives the USART to send an idle frame before the first data frame.
RX line
Ideal 4
sample 1 2 3 6 7 8 9 10 11 12 13 14 15 16
5
clock Sampled values
Real X X X 9
sample X X X 0 11 1 2 13 14 15 16
X X 1
clock
6/16
7/16 7/16
One-bit time
Conditions 1 X X 0 X X
to validate 1 1
0
0 X
0 0
0 0
X X X
X
the start bit
Falling edge At least 2 bits At least 2 bits
detection out of 3 at 0 out of 3 at 0
ai15471b
Note: If the sequence is not complete, the start bit detection aborts and the receiver returns to the
idle state (no flag is set), where it waits for a falling edge.
The start bit is confirmed (RXNE flag set and interrupt generated if RXNEIE = 1, or RXFNE
flag set and interrupt generated if RXFNEIE = 1 if FIFO mode enabled) if the 3 sampled bits
are at ‘0’ (first sampling on the 3rd, 5th and 7th bits finds the 3 bits at ‘0’ and second
sampling on the 8th, 9th and 10th bits also finds the 3 bits at ‘0’).
The start bit is validated but the NE noise flag is set if,
a) for both samplings, 2 out of the 3 sampled bits are at ‘0’ (sampling on the 3rd, 5th
and 7th bits and sampling on the 8th, 9th and 10th bits)
or
b) for one of the samplings (sampling on the 3rd, 5th and 7th bits or sampling on the
8th, 9th and 10th bits), 2 out of the 3 bits are found at ‘0’.
If neither of the above conditions are met, the start detection aborts and the receiver returns
to the idle state (no flag is set).
Character reception
During an USART reception, data are shifted out least significant bit first (default
configuration) through the RX pin.
Character reception procedure
To receive a character, follow the sequence below:
1. Program the M bits in USART_CR1 to define the word length.
2. Select the desired baud rate using the baud rate register USART_BRR
3. Program the number of stop bits in USART_CR2.
4. Enable the USART by writing the UE bit in USART_CR1 register to ‘1’.
5. Select DMA enable (DMAR) in USART_CR3 if multibuffer communication is to take
place. Configure the DMA register as explained in Section 24.5.19: Continuous
communication using USART and DMA.
6. Set the RE bit USART_CR1. This enables the receiver which begins searching for a
start bit.
When a character is received:
• When FIFO mode is disabled, the RXNE bit is set to indicate that the content of the
shift register is transferred to the RDR. In other words, data have been received and
can be read (as well as their associated error flags).
• When FIFO mode is enabled, the RXFNE bit is set to indicate that the RXFIFO is not
empty. Reading the USART_RDR returns the oldest data entered in the RXFIFO.
When a data is received, it is stored in the RXFIFO together with the corresponding
error bits.
• An interrupt is generated if the RXNEIE (RXFNEIE when FIFO mode is enabled) bit is
set.
• The error flags can be set if a frame error, noise, parity or an overrun error was
detected during reception.
• In multibuffer communication mode:
– When FIFO mode is disabled, the RXNE flag is set after every byte reception. It is
cleared when the DMA reads the Receive data Register.
– When FIFO mode is enabled, the RXFNE flag is set when the RXFIFO is not
empty. After every DMA request, a data is retrieved from the RXFIFO. A DMA
request is triggered when the RXFIFO is not empty i.e. when there are data to be
read from the RXFIFO.
• In single buffer mode:
– When FIFO mode is disabled, clearing the RXNE flag is done by performing a
software read from the USART_RDR register. The RXNE flag can also be cleared
by programming RXFRQ bit to ‘1’ in the USART_RQR register. The RXNE flag
must be cleared before the end of the reception of the next character to avoid an
overrun error.
– When FIFO mode is enabled, the RXFNE is set when the RXFIFO is not empty.
After every read operation from USART_RDR, a data is retrieved from the
RXFIFO. When the RXFIFO is empty, the RXFNE flag is cleared. The RXFNE flag
can also be cleared by programming RXFRQ bit to ‘1’ in USART_RQR. When the
RXFIFO is full, the first entry in the RXFIFO must be read before the end of the
reception of the next character, to avoid an overrun error. The RXFNE flag
generates an interrupt if the RXFNEIE bit is set. Alternatively, interrupts can be
generated and data can be read from RXFIFO when the RXFIFO threshold is
reached. In this case, the CPU can read a block of data defined by the
programmed threshold.
Break character
When a break character is received, the USART handles it as a framing error.
Idle character
When an idle frame is detected, it is handled in the same way as a data character reception
except that an interrupt is generated if the IDLEIE bit is set.
Overrun error
• FIFO mode disabled
An overrun error occurs if a character is received and RXNE has not been reset.
Data can not be transferred from the shift register to the RDR register until the RXNE
bit is cleared. The RXN E flag is set after every byte reception.
An overrun error occurs if RXNE flag is set when the next data is received or the
previous DMA request has not been serviced. When an overrun error occurs:
– the ORE bit is set;
– the RDR content is not lost. The previous data is available by reading the
USART_RDR register.
– the shift register is overwritten. After that, any data received during overrun is lost.
– an interrupt is generated if either the RXNEIE or the EIE bit is set.
• FIFO mode enabled
An overrun error occurs when the shift register is ready to be transferred and the
receive FIFO is full.
Data can not be transferred from the shift register to the USART_RDR register until
there is one free location in the RXFIFO. The RXFNE flag is set when the RXFIFO is
not empty.
An overrun error occurs if the RXFIFO is full and the shift register is ready to be
transferred. When an overrun error occurs:
– The ORE bit is set.
– The first entry in the RXFIFO is not lost. It is available by reading the
USART_RDR register.
– The shift register is overwritten. After that point, any data received during overrun
is lost.
– An interrupt is generated if either the RXFNEIE or EIE bit is set.
The ORE bit is reset by setting the ORECF bit in the USART_ICR register.
Note: The ORE bit, when set, indicates that at least 1 data has been lost.
When the FIFO mode is disabled, there are two possibilities
• if RXNE = 1, then the last valid data is stored in the receive register (RDR) and can be
read,
• if RXNE = 0, the last valid data has already been read and there is nothing left to be
read in the RDR register. This case can occur when the last valid data is read in the
RDR register at the same time as the new (and lost) data is received.
usart_ker_ck_pres
USARTx_BRR register
usart_ker_ck USARTx_PRESC[3:0] and oversampling
MSv40855V1
Some usart_ker_ck sources enable the USART to receive data while the MCU is in low-
power mode. Depending on the received data and wake-up mode selected, the USART
wakes up the MCU, when needed, in order to transfer the received data, by performing a
software read to the USART_RDR register or by DMA.
For the other clock sources, the system must be active to enable USART communications.
The communication speed range (specially the maximum communication speed) is also
determined by the clock source.
The receiver implements different user-configurable oversampling techniques (except in
synchronous mode) for data recovery by discriminating between valid incoming data and
noise. This enables obtaining the best a trade-off between the maximum communication
speed and noise/clock inaccuracy immunity.
The oversampling method can be selected by programming the OVER8 bit in the
USART_CR1 register either to 16 or 8 times the baud rate clock (see Figure 247 and
Figure 248).
Depending on your application:
• select oversampling by 8 (OVER8 = 1) to achieve higher speed (up to
usart_ker_ck_pres/8). In this case the maximum receiver tolerance to clock deviation is
reduced (refer to Section 24.5.8: Tolerance of the USART receiver to clock deviation on
page 678)
• select oversampling by 16 (OVER8 = 0) to increase the tolerance of the receiver to
clock deviations. In this case, the maximum speed is limited to maximum
RX line
sampled values
Sample clock 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
6/16
7/16 7/16
One bit time
MSv31152V1
RX line
sampled values
Sample
clock (x8) 1 2 3 4 5 6 7 8
2/8
3/8 3/8
One bit time
MSv31153V1
000 0 0
001 1 0
010 1 0
011 1 1
100 1 0
101 1 1
110 1 1
111 0 1
Framing error
A framing error is detected when the stop bit is not recognized on reception at the expected
time, following either a de-synchronization or excessive noise.
When the framing error is detected:
• the FE bit is set by hardware;
• the invalid data is transferred from the Shift register to the USART_RDR register
(RXFIFO in case FIFO mode is enabled).
• no interrupt is generated in case of single byte communication. However this bit rises at
the same time as the RXNE bit (RXFNE in case FIFO mode is enabled) which itself
generates an interrupt. In case of multibuffer communication an interrupt is issued if the
EIE bit is set in the USART_CR3 register.
The FE bit is reset by writing ‘1’ to the FECF in the USART_ICR register.
Note: Framing error is not supported in SPI mode.
USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register.
• When OVER8 = 0, BRR = USARTDIV.
• When OVER8 = 1
– BRR[2:0] = USARTDIV[3:0] shifted 1 bit to the right.
– BRR[3] must be kept cleared.
– BRR[15:4] = USARTDIV[15:4]
Note: The baud counters are updated to the new value in the baud registers after a write operation
to USART_BRR. Hence the baud rate register value should not be changed during
communication.
In case of oversampling by 16 and 8, USARTDIV must be greater than or equal to 16.
where
DWU is the error due to sampling point deviation when the wake-up from low-
power mode is used.
when M[1:0] = 01:
t WUUSART
DWU = --------------------------
-
11 × Tbit
tWUUSART is the time between the detection of the start bit falling edge and the
instant when the clock (requested by the peripheral) is ready and reaching the
peripheral, and the regulator is ready.
The USART receiver can receive data correctly at up to the maximum tolerated deviation
specified in Table 108, Table 109, depending on the following settings:
• 9-, 10- or 11-bit character length defined by the M bits in the USART_CR1 register
• Oversampling by 8 or 16 defined by the OVER8 bit in the USART_CR1 register
• Bits BRR[3:0] of USART_BRR register are equal to or different from 0000.
• Use of 1 bit or 3 bits to sample the data, depending on the value of the ONEBIT bit in
the USART_CR3 register.
Table 108. Tolerance of the USART receiver when BRR [3:0] = 0000
OVER8 bit = 0 OVER8 bit = 1
M bits
ONEBIT = 0 ONEBIT = 1 ONEBIT = 0 ONEBIT = 1
Table 109. Tolerance of the USART receiver when BRR[3:0] is different from 0000
OVER8 bit = 0 OVER8 bit = 1
M bits
ONEBIT = 0 ONEBIT = 1 ONEBIT = 0 ONEBIT = 1
00 3.33% 3.88% 2% 3%
01 3.03% 3.53% 1.82% 2.73%
10 3.7% 4.31% 2.22% 3.33%
Note: The data specified in Table 108 and Table 109 may slightly differ in the special case when
the received frames contain some Idle frames of exactly 10-bit times when M bits = 00 (11-
bit times when M = 01 or 9- bit times when M = 10).
RXNE RXNE
MSv31154V1
Note: If the MMRQ is set while the IDLE character has already elapsed, Mute mode is not entered
(RWU is not set).
If the USART is activated while the line is IDLE, the idle state is detected after the duration
of one IDLE frame (not only after the reception of one character frame).
RX IDLE Addr=0 Data 1 Data 2 IDLE Addr=1 Data 3 Data 4 Addr=2 Data 5
Non-matching address
MSv31155V1
Modbus/RTU
In this mode, the end of one block is recognized by a “silence” (idle line) for more than 2
character times. This function is implemented through the programmable timeout function.
The timeout function and interrupt must be activated, through the RTOEN bit in the
USART_CR2 register and the RTOIE in the USART_CR1 register. The value corresponding
to a timeout of 2 character times (for example 22 x bit time) must be programmed in the
RTO register. When the receive line is idle for this duration, after the last stop bit is received,
an interrupt is generated, informing the software that the current block reception is
completed.
Modbus/ASCII
In this mode, the end of a block is recognized by a specific (CR/LF) character sequence.
The USART manages this mechanism using the character match function.
By programming the LF ASCII code in the ADD[7:0] field and by activating the character
match interrupt (CMIE = 1), the software is informed when a LF has been received and can
check the CR/LF in the DMA buffer.
Even parity
The parity bit is calculated to obtain an even number of “1s” inside the frame of the 6, 7 or 8
LSB bits (depending on M bit values) and the parity bit.
As an example, if data = 00110101 and 4 bits are set, the parity bit is equal to 0 if even parity
is selected (PS bit in USART_CR1 = 0).
Odd parity
The parity bit is calculated to obtain an odd number of “1s” inside the frame made of the 6, 7
or 8 LSB bits (depending on M bit values) and the parity bit.
As an example, if data = 00110101 and 4 bits set, then the parity bit is equal to 1 if odd parity
is selected (PS bit in USART_CR1 = 1).
LIN transmission
The procedure described in Section 24.5.4 has to be applied for LIN Master transmission. It
must be the same as for normal USART transmission with the following differences:
• Clear the M bit to configure 8-bit word length.
• Set the LINEN bit to enter LIN mode. In this case, setting the SBKRQ bit sends 13 ‘0
bits as a break character. Then two bits of value ‘1 are sent to enable the next start
detection.
LIN reception
When LIN mode is enabled, the break detection circuit is activated. The detection is totally
independent from the normal USART receiver. A break can be detected whenever it occurs,
during Idle state or during a frame.
When the receiver is enabled (RE = 1 in USART_CR1), the circuit looks at the RX input for
a start signal. The method for detecting start bits is the same when searching break
characters or data. After a start bit has been detected, the circuit samples the next bits
exactly like for the data (on the 8th, 9th and 10th samples). If 10 (when the LBDL = 0 in
USART_CR2) or 11 (when LBDL = 1 in USART_CR2) consecutive bits are detected as ‘0,
and are followed by a delimiter character, the LBDF flag is set in USART_ISR. If the LBDIE
bit = 1, an interrupt is generated. Before validating the break, the delimiter is checked for as
it signifies that the RX line has returned to a high level.
If a ‘1 is sampled before the 10 or 11 have occurred, the break detection circuit cancels the
current detection and searches for a start bit again.
If the LIN mode is disabled (LINEN = 0), the receiver continues working as normal USART,
without taking into account the break detection.
If the LIN mode is enabled (LINEN = 1), as soon as a framing error occurs (i.e. stop bit
detected at ‘0, which is the case for any break frame), the receiver stops until the break
detection circuit receives either a ‘1, if the break word was not complete, or a delimiter
character if a break has been detected.
The behavior of the break detector state machine and the break flag is shown on the
Figure 251: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 687.
Examples of break frames are given on Figure 252: Break detection in LIN mode vs.
Framing error detection on page 688.
Figure 251. Break detection in LIN mode (11-bit break length - LBDL bit is set)
Case 1: break signal not long enough => break discarded, LBDF is not set
Break frame
RX line
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 1
Case 2: break signal just long enough => break detected, LBDF is set
Break frame
RX line
Delimiter is immediate
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 B10 Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 0
LBDF
Case 3: break signal long enough => break detected, LBDF is set
Break frame
RX line
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 wait delimiter Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 0
LBDF
MSv31156V1
Figure 252. Break detection in LIN mode vs. Framing error detection
RXNE /FE
LBDF
RXNE /FE
LBDF
MSv31157V1
Note: In master mode, the CK pin operates in conjunction with the TX pin. Thus, the clock is
provided only if the transmitter is enabled (TE = 1) and data are being transmitted
(USART_TDR data register written). This means that it is not possible to receive
synchronous data without transmitting data.
RX Data out
TX Data in
Synchronous device
USART
(slave SPI)
CK Clock
MSv31158V2
Figure 254. USART data clock timing diagram in synchronous master mode
(M bits = 00)
Data on TX
0 1 2 3 4 5 6 7
(from master)
Start LSB MSB Stop
Data on RX
0 1 2 3 4 5 6 7
(from slave)
LSB MSB
*
Capture strobe
*LBCL bit controls last data pulse
MSv34709V2
Figure 255. USART data clock timing diagram in synchronous master mode
(M bits = 01)
Idle or
Idle or next
preceding Start M bits =01 (9 data bits) Stop
transmission
transmission
Clock (CPOL=0,
CPHA=0) *
Clock (CPOL=0,
CPHA=1) *
Clock (CPOL=1, *
CPHA=0)
Clock (CPOL=1, *
CPHA=1)
Data on TX
0 1 2 3 4 5 6 7 8
(from master)
Start LSB MSB Stop
Data on RX
0 1 2 3 4 5 6 7 8
(from slave)
LSB MSB
Capture *
strobe
*LBCL bit controls last data pulse
MSv34710V1
Slave mode
The synchronous slave mode is selected by programming the SLVEN bit in the
USART_CR2 register to ‘1’. In synchronous slave mode, the following bits must be kept
cleared:
• LINEN and CLKEN bits in the USART_CR2 register,
• SCEN, HDSEL and IREN bits in the USART_CR3 register.
In this mode, the USART can be used to control bidirectional synchronous serial
communications in slave mode. The CK pin is the input of the USART in slave mode.
Note: When the peripheral is used in SPI slave mode, the frequency of peripheral clock source
(usart_ker_ck_pres) must be greater than 3 times the CK input frequency.
The CPOL bit and the CPHA bit in the USART_CR2 register are used to select the clock
polarity and the phase of the external clock, respectively (see Figure 256).
An underrun error flag is available in slave transmission mode. This flag is set when the first
clock pulse for data transmission appears while the software has not yet loaded any value to
USART_TDR.
The slave supports the hardware and software NSS management.
Figure 256. USART data clock timing diagram in synchronous slave mode
(M bits = 00)
M bits = 00 (8 data bits)
Data on TX
0 1 2 3 4 5 6 7
(from slave)
LSB MSB
Data on RX
0 1 2 3 4 5 6 7
(from master)
LSB MSB
Capture strobe
MSv45359V1
In case of underrun error, it is still possible to write to the TDR register. Clearing the
underrun error enables sending new data.
If an underrun error occurred and there is no new data written in TDR, then the TC flag is set
at the end of the frame.
Note: An underrun error may occur if the moment the data is written to the USART_TDR is too
close to the first CK transmission edge. To avoid this underrun error, the USART_TDR
should be written 3 usart_ker_ck cycles before the first CK edge.
WithParity error
Guard time
S 0 1 2 3 4 5 6 7 p
Start bit
Line pulled low by receiver
during stop in case of parity error
MSv31162V1
When connected to a Smartcard, the TX output of the USART drives a bidirectional line that
is also driven by the Smartcard. The TX pin must be configured as open drain.
Smartcard mode implements a single wire half duplex communication protocol.
• Transmission of data from the transmit shift register is guaranteed to be delayed by a
minimum of 1/2 baud clock. In normal operation a full transmit shift register starts
shifting on the next baud clock edge. In Smartcard mode this transmission is further
delayed by a guaranteed 1/2 baud clock.
• In transmission, if the Smartcard detects a parity error, it signals this condition to the
USART by driving the line low (NACK). This NACK signal (pulling transmit line low for 1
baud clock) causes a framing error on the transmitter side (configured with 1.5 stop
bits). The USART can handle automatic re-sending of data according to the protocol.
The number of retries is programmed in the SCARCNT bitfield. If the USART continues
receiving the NACK after the programmed number of retries, it stops transmitting and
signals the error as a framing error. The TXE bit (TXFNF bit in case FIFO mode is
enabled) may be set using the TXFRQ bit in the USART_RQR register.
• Smartcard auto-retry in transmission: A delay of 2.5 baud periods is inserted between
the NACK detection by the USART and the start bit of the repeated character. The TC
bit is set immediately at the end of reception of the last repeated character (no
guardtime). If the software wants to repeat it again, it must insure the minimum 2 baud
periods required by the standard.
• If a parity error is detected during reception of a frame programmed with a 1.5 stop bit
period, the transmit line is pulled low for a baud clock period after the completion of the
receive frame. This is to indicate to the Smartcard that the data transmitted to the
USART has not been correctly received. A parity error is NACKed by the receiver if the
NACK control bit is set, otherwise a NACK is not transmitted (to be used in T = 1
mode). If the received character is erroneous, the RXNE (RXFNE in case FIFO mode
is enabled)/receive DMA request is not activated. According to the protocol
specification, the Smartcard must resend the same character. If the received character
is still erroneous after the maximum number of retries specified in the SCARCNT
bitfield, the USART stops transmitting the NACK and signals the error as a parity error.
• Smartcard auto-retry in reception: the BUSY flag remains set if the USART NACKs the
card but the card doesn’t repeat the character.
• In transmission, the USART inserts the Guard Time (as programmed in the Guard Time
register) between two successive characters. As the Guard Time is measured after the
stop bit of the previous character, the GT[7:0] register must be programmed to the
desired CGT (Character Guard Time, as defined by the 7816-3 specification) minus 12
(the duration of one character).
• The assertion of the TC flag can be delayed by programming the Guard Time register.
In normal operation, TC is asserted when the transmit shift register is empty and no
further transmit requests are outstanding. In Smartcard mode an empty transmit shift
register triggers the Guard Time counter to count up to the programmed value in the
Guard Time register. TC is forced low during this time. When the Guard Time counter
reaches the programmed value TC is asserted high. The TCBGT flag can be used to
detect the end of data transfer without waiting for guard time completion. This flag is set
just after the end of frame transmission and if no NACK has been received from the
card.
• The deassertion of TC flag is unaffected by Smartcard mode.
• If a framing error is detected on the transmitter end (due to a NACK from the receiver),
the NACK is not detected as a start bit by the receive block of the transmitter.
According to the ISO protocol, the duration of the received NACK can be 1 or 2 baud
clock periods.
• On the receiver side, if a parity error is detected and a NACK is transmitted the receiver
does not detect the NACK as a start bit.
Note: Break characters are not significant in Smartcard mode. A 0x00 data with a framing error is
treated as data and not as a break.
No Idle frame is transmitted when toggling the TE bit. The Idle frame (as defined for the
other configurations) is not defined by the ISO protocol.
Figure 258 shows how the NACK signal is sampled by the USART. In this example the
USART is transmitting data and is configured with 1.5 stop bits. The receiver part of the
USART is enabled in order to check the integrity of the data and the NACK signal.
Figure 258. Parity error detection using the 1.5 stop bits
Sampling at Sampling at
8th, 9th, 10th 8th, 9th, 10th
Sampling at Sampling at
8th, 9th, 10th 8th, 9th, 10th
MSv31163V1
The USART can provide a clock to the Smartcard through the CK output. In Smartcard
mode, CK is not associated to the communication but is simply derived from the internal
peripheral input clock through a 5-bit prescaler. The division ratio is configured in the
USART_GTPR register. CK frequency can be programmed from usart_ker_ck_pres/2 to
usart_ker_ck_pres/62, where usart_ker_ck_pres is the peripheral input clock divided by a
programmed prescaler.
Block mode (T = 1)
In T = 1 (block) mode, the parity error transmission can be deactivated by clearing the
NACK bit in the USART_CR3 register.
When requesting a read from the Smartcard, in block mode, the software must program the
RTOR register to the BWT (block wait time) - 11 value. If no answer is received from the
card before the expiration of this period, a timeout interrupt is generated. If the first
character is received before the expiration of the period, it is signaled by the RXNE/RXFNE
interrupt.
Note: The RXNE/RXFNE interrupt must be enabled even when using the USART in DMA mode to
read from the Smartcard in block mode. In parallel, the DMA must be enabled only after the
first received byte.
After the reception of the first character (RXNE/RXFNE interrupt), the RTO register must be
programmed to the CWT (character wait time -11 value), in order to enable the automatic
check of the maximum wait time between two consecutive characters. This time is
expressed in baud time units. If the Smartcard does not send a new character in less than
the CWT period after the end of the previous character, the USART signals it to the software
through the RTOF flag and interrupt (when RTOIE bit is set).
Note: As in the Smartcard protocol definition, the BWT/CWT values should be defined from the
beginning (start bit) of the last character. The RTO register must be programmed to BWT -
11 or CWT -11, respectively, taking into account the length of the last character itself.
A block length counter is used to count all the characters received by the USART. This
counter is reset when the USART is transmitting. The length of the block is communicated
by the Smartcard in the third byte of the block (prologue field). This value must be
programmed to the BLEN field in the USART_RTOR register. When using DMA mode,
before the start of the block, this register field must be programmed to the minimum value
(0x0). With this value, an interrupt is generated after the 4th received character. The
software must read the LEN field (third byte), its value must be read from the receive buffer.
In interrupt driven receive mode, the length of the block may be checked by software or by
programming the BLEN value. However, before the start of the block, the maximum value of
BLEN (0xFF) may be programmed. The real value is programmed after the reception of the
third character.
If the block is using the LRC longitudinal redundancy check (1 epilogue byte), the
BLEN = LEN. If the block is using the CRC mechanism (2 epilog bytes), BLEN = LEN+1
must be programmed. The total block length (including prologue, epilogue and information
fields) equals BLEN+4. The end of the block is signaled to the software through the EOBF
flag and interrupt (when EOBIE bit is set).
In case of an error in the block length, the end of the block is signaled by the RTO interrupt
(Character Wait Time overflow).
Note: The error checking code (LRC/CRC) must be computed/verified by software.
TX
OR USART_TX
SIR
SIREN Transmit IrDA_OUT
Encoder
USART
SIR
RX
Receive IrDA_IN
DEcoder
USART_RX
MSv31164V1
Start Stop
bit bit
0 1 0 1 0 0 1 1 0 1
TX
IrDA_OUT
Bit period 3/16
IrDA_IN
RX 0 1 0 1 0 0 1 1 0 1
MSv31165V1
USART_TDR F1 F2 F3
TC flag Set by
hardware
DMA writes
USART_TDR
Cleared
DMA TCIF flag by
Set by hardware software
(transfer
complete)
ai17192b
Note: When FIFO management is enabled, the DMA request is triggered by Transmit FIFO not full
(i.e. TXFNF = 1).
Set by hardware
RXNE flag cleared by DMA read
DMA request
USART_RDR F1 F2 F3
DMA reads
USART_RDR
Cleared
DMA TCIF flag Set by hardware by
(transfer complete) software
Note: When FIFO management is enabled, the DMA request is triggered by Receive FIFO not
empty (i.e. RXFNE = 1).
USART 1 USART 2
TX RX
TX circuit RX circuit
CTS RTS
RX TX
RX circuit TX circuit
RTS CTS
MSv31169V2
RS232 RTS and CTS flow control can be enabled independently by writing the RTSE and
CTSE bits to ‘1’ in the USART_CR3 register.
RTS
MSv68794V1
Note: When FIFO mode is enabled, RTS is asserted only when RXFIFO is full.
CTS CTS
CTS
Note: For correct behavior, CTS must be deasserted at least 3 USART clock source periods
before the end of the current character. In addition it should be noted that the CTSCF flag
may not be set for pulses shorter than 2 x PCLK periods.
Note: Before entering low-power mode, make sure that no USART transfers are ongoing.
Checking the BUSY flag cannot ensure that low-power mode is never entered when data
reception is ongoing.
The WUF flag is set when a wake-up event is detected, independently of whether the MCU
is in low-power or active mode.
When entering low-power mode just after having initialized and enabled the receiver, the
REACK bit must be checked to make sure the USART is enabled.
When DMA is used for reception, it must be disabled before entering low-power mode and
re-enabled when exiting from low-power mode.
When the FIFO is enabled, waking up from low-power mode on address match is only
possible when Mute mode is enabled.
Figure 266 shows the USART behavior when the wake-up event is verified.
Figure 266. Wake-up event verified (wake-up event = address match, FIFO disabled)
Start bit
Start bit
Idle
Stop bit
Stop bit
RX line Rx data 1 Rx data 2
Startup time
usart_ker_ck
ON
OFF
MSv40856V2
Figure 267 shows the USART behavior when the wake-up event is not verified.
Figure 267. Wake-up event not verified (wake-up event = address match,
FIFO disabled)
Idle Idle
Stop bit
RX line Rx data 1
Startup time
usart_ker_ck
ON OFF
OFF
Low-power mode
MSv40857V2
Note: The figures above are valid when address match or any received frame is used as wake-up
event. If the wake-up event is the start bit detection, the USART sends the wake-up event to
the MCU at the end of the start bit.
Determining the maximum USART baud rate that enables to correctly wake
up the device from low-power mode
The maximum baud rate that enables to correctly wake up the device from low-power mode
depends on the wake-up time parameter (refer to the device datasheet) and on the USART
receiver tolerance (see Section 24.5.8: Tolerance of the USART receiver to clock deviation).
Let us take the example of OVER8 = 0, M bits = ‘01’, ONEBIT = 0 and BRR [3:0] = 0000.
In these conditions, according to Table 108: Tolerance of the USART receiver when BRR
[3:0] = 0000, the USART receiver tolerance equals 3.41%.
DTRA + DQUANT + DREC + DTCL + DWU < USART receiver tolerance
DWUmax = tWUUSART/ (11 x Tbit Min)
Tbit Min = tWUUSART/ (11 x DWUmax)
where tWUUSART is the wake-up time from low-power mode.
If we consider the ideal case where DTRA, DQUANT, DREC and DTCL parameters are at
0%, the maximum value of DWU is 3.41%. In reality, we need to consider at least the
usart_ker_ck inaccuracy.
For example, if HSI48 is used as usart_ker_ck, and the HSI48 inaccuracy is of 1%, then we
obtain:
tWUUSART = 3 µs (values provided only as examples; for correct values, refer to the
device datasheet).
DWUmax = 3.41% - 1% = 2.41%
Tbit min = 3 µs/ (11 x 2.41%) = 11.32 µs.
As a result, the maximum baud rate that enables to wake up correctly from low-power
mode is: 1/11.32 µs = 88.36 Kbaud.
Sleep No effect. USART interrupts cause the device to exit Sleep mode.
The content of the USART registers is kept.
Stop(1) The USART is able to wake up the microcontroller from Stop mode when
the USART is clocked by an oscillator available in Stop mode.
The USART peripheral is powered down and must be reinitialized after
Standby
exiting Standby mode.
1. Refer to Section 24.4: USART implementation to know if the wake-up from Stop mode is supported for a
given peripheral instance. If an instance is not functional in a given Stop mode, it must be disabled before
entering this Stop mode.
RXNEIE/
Overrun error detected ORE RXFNEIE Write 1 in ORECF No
1. The USART can wake up the device from Stop mode only if the peripheral instance supports the wake-up from Stop mode
feature. Refer to Section 24.4: USART implementation for the list of supported Stop modes.
2. RXFF flag is asserted if the USART receives n+1 data (n being the RXFIFO size): n data in the RXFIFO and 1 data in
USART_RDR. In Stop mode, USART_RDR is not clocked. As a result, this register is not written and once n data are
received and written in the RXFIFO, the RXFF interrupt is asserted (RXFF flag is not set).
3. When OVRDIS = 0.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RXF FIFO
TXFEIE M1 EOBIE RTOIE DEAT[4:0] DEDT[4:0]
FIE EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TXFNFI RXFNE
OVER8 CMIE MME M0 WAKE PCE PS PEIE TCIE IDLEIE TE RE UESM UE
E IE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FIFO
Res. Res. M1 EOBIE RTOIE DEAT[4:0] DEDT[4:0]
EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RXNEI
OVER8 CMIE MME M0 WAKE PCE PS PEIE TXEIE TCIE IDLEIE TE RE UESM UE
E
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MSBFI DATAIN
ADD[7:0] RTOEN ABRMOD[1:0] ABREN TXINV RXINV
RST V
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DIS_
SWAP LINEN STOP[1:0] CLKEN CPOL CPHA LBCL Res. LBDIE LBDL ADDM7 Res. Res. SLVEN
NSS
rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The CPOL, CPHA and LBCL bits should not be written while the transmitter is enabled.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RXF TCBG
TXFTCFG[2:0] RXFTCFG[2:0] TXFTIE WUFIE WUS[1:0] SCARCNT[2:0] Res.
TIE TIE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OVR ONE HD
DEP DEM DDRE CTSIE CTSE RTSE DMAT DMAR SCEN NACK IRLP IREN EIE
DIS BIT SEL
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
If the USART does not support the wake-up from Stop feature, this bit is reserved and
must be kept at reset value. Refer to Section 24.4: USART implementation on
page 660.
Bits 21:20 WUS[1:0]: Wake-up from low-power mode interrupt flag selection
This bitfield specifies the event which activates the WUF (wake-up from low-power mode
flag).
00: WUF active on address match (as defined by ADD[7:0] and ADDM7)
01: Reserved.
10: WUF active on start bit detection
11: WUF active on RXNE/RXFNE.
This bitfield can only be written when the USART is disabled (UE = 0).
If the USART does not support the wake-up from Stop feature, this bit is reserved and
must be kept at reset value. Refer to Section 24.4: USART implementation on
page 660.
Bits 19:17 SCARCNT[2:0]: Smartcard auto-retry count
This bitfield specifies the number of retries for transmission and reception in Smartcard
mode.
In transmission mode, it specifies the number of automatic retransmission retries, before
generating a transmission error (FE bit set).
In reception mode, it specifies the number or erroneous reception trials, before generating a
reception error (RXNE/RXFNE and PE bits set).
This bitfield must be programmed only when the USART is disabled (UE = 0).
When the USART is enabled (UE = 1), this bitfield may only be written to 0x0, in order to
stop retransmission.
0x0: retransmission disabled - No automatic retransmission in transmit mode.
0x1 to 0x7: number of automatic retransmission attempts (before signaling error)
Note: If Smartcard mode is not supported, this bit is reserved and must be kept at reset
value. Refer to Section 24.4: USART implementation on page 660.
Bit 16 Reserved, must be kept at reset value.
Bit 15 DEP: Driver enable polarity selection
0: DE signal is active high.
1: DE signal is active low.
This bit can only be written when the USART is disabled (UE = 0).
Note: If the Driver Enable feature is not supported, this bit is reserved and must be kept at
reset value. Refer to Section 24.4: USART implementation on page 660.
Bit 14 DEM: Driver enable mode
This bit enables the user to activate the external transceiver control, through the DE signal.
0: DE function is disabled.
1: DE function is enabled. The DE signal is output on the RTS pin.
This bit can only be written when the USART is disabled (UE = 0).
Note: If the Driver Enable feature is not supported, this bit is reserved and must be kept at
reset value. Section 24.4: USART implementation on page 660.
Bit 13 DDRE: DMA Disable on reception error
0: DMA is not disabled in case of reception error. The corresponding error flag is set but
RXNE is kept 0 preventing from overrun. As a consequence, the DMA request is not
asserted, so the erroneous data is not transferred (no DMA request), but next correct
received data is transferred (used for Smartcard mode).
1: DMA is disabled following a reception error. The corresponding error flag is set, as well
as RXNE. The DMA request is masked until the error flag is cleared. This means that the
software must first disable the DMA request (DMAR = 0) or clear RXNE/RXFNE is case
FIFO mode is enabled) before clearing the error flag.
This bit can only be written when the USART is disabled (UE=0).
Note: The reception errors are: parity error, framing error or noise error.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BRR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GT[7:0] PSC[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
This bitfield can only be written when the USART is disabled (UE = 0).
Note: Bits [7:5] must be kept cleared if Smartcard mode is used.
This bitfield is reserved and forced by hardware to ‘0’ when the Smartcard and IrDA
modes are not supported. Refer to Section 24.4: USART implementation on page 660.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BLEN[7:0] RTO[23:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTO[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: RTOR can be written on-the-fly. If the new value is lower than or equal to the counter, the
RTOF flag is set.
This register is reserved and forced by hardware to “0x00000000” when the Receiver
timeout feature is not supported. Refer to Section 24.4: USART implementation on page 660.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ABRR
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TXFRQ RXFRQ MMRQ SBKRQ
Q
w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RE TE
Res. Res. Res. Res. TXFT RXFT TCBGT RXFF TXFE WUF RWU SBKF CMF BUSY
ACK ACK
r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ABRF ABRE UDR EOBF RTOF CTS CTSIF LBDF TXFNF TC RXFNE IDLE ORE NE FE PE
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RE TE
Res. Res. Res. Res. Res. Res. TCBGT Res. Res. WUF RWU SBKF CMF BUSY
ACK ACK
r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ABRF ABRE UDR EOBF RTOF CTS CTSIF LBDF TXE TC RXNE IDLE ORE NE FE PE
r r r r r r r r r r r r r r r r
0: No overrun error
1: Overrun error is detected
Note: When this bit is set, the USART_RDR register content is not lost but the shift register is
overwritten. An interrupt is generated if the ORE flag is set during multi buffer
communication if the EIE bit is set.
This bit is permanently forced to 0 (no overrun detection) when the bit OVRDIS is set in
the USART_CR3 register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WUCF Res. Res. CMCF Res.
w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TCBGT TXFEC IDLEC
Res. Res. UDRCF EOBCF RTOCF Res. CTSCF LBDCF TCCF ORECF NECF FECF PECF
CF F F
w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. RDR[8:0]
r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. TDR[8:0]
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PRESCALER[3:0]
rw rw rw rw
0x1C
0x1C
0x0C
Offset
744/825
24.8.15
name
enabled
disabled
Register
FIFO mode
FIFO mode
reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
USART_ISR
USART_ISR
USART_ICR
USART_CR3
USART_CR2
USART_CR1
USART_CR1
USART_BRR
USART_RDR
FIFO enabled
USART_RQR
FIFO disabled
USART_GTPR
USART_RTOR
31
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. RXFFIE
30
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. TXFTCFG[2:0] Res. TXFEIE
29
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. FIFOEN FIFOEN
28
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. RXFTIE M1 M1
27
0
0
0
0
0
Res. Res. Res. TXFT Res. Res. Res. EOBIE EOBIE
ADD[7:0]
BLEN[7:0]
26
0
0
0
0
RXFTCFG[2:0] 0
Res. Res. Res. RXFT Res. Res. Res. RTOIE RTOIE
25
0
0
0
0
0
0
24
0
0
0
0
0
X X X X
Res. Res. Res. RXFF Res. Res. Res. TCBGTIE
23
0
0
0
0
0
1
Res. Res. Res. TXFE Res. Res. Res. TXFTIE RTOEN
22
0
0
0
0
0
0
0
Res. Res. REACK REACK Res. Res. Res. WUFIE
DEAT[4:0]
DEAT[4:0]
ABRMOD[1:0]
21
0
0
0
0
0
0
0
Res. Res. TEACK TEACK Res. Res. Res.
[1:0]
20
0
0
0
0
0
0
0
0
WUS
Res. WUCF WUF WUF Res. Res. Res. ABREN
19
0
0
0
0
0
0
0
Res. Res. RWU RWU Res. Res. Res. MSBFIRST
18
0
0
0
0
0
0
0
Res. Res. SBKF SBKF Res. Res. Res. DATAINV
Universal synchronous receiver transmitter (USART)
SCAR
17
CNT2:0]
0
0
0
0
0
0
0
0
Res. CMCF CMF CMF Res. Res. Res. TXINV
DEDT[4:0]
DEDT[4:0]
RM0490 Rev 3
16
0
0
0
0
0
0
Res. Res. BUSY BUSY Res. Res. Res. Res. RXINV
15
0
0
0
0
0
0
0
0
0
Res. Res. ABRF ABRF Res. DEP SWAP OVER8 OVER8
14
0
0
0
0
0
0
0
0
0
Res. Res. ABRE ABRE Res. DEM LINEN CMIE CMIE
13
0
0
0
0
0
0
0
0
0
0
Res. UDRCF UDR UDR Res. DDRE MME MME
[1:0]
12
0
0
0
0
0
0
0
0
0
0
Res. EOBCF EOBF EOBF Res. OVRDIS M0 M0
STOP
11
0
0
0
0
0
0
0
0
0
0
Res. RTOCF RTOF RTOF Res. ONEBIT CLKEN WAKE WAKE
GT[7:0]
RTO[23:0]
10
0
0
0
0
0
0
0
0
0
Res. Res. CTS CTS Res. CTSIE CPOL PCE PCE
Table 113. USART register map and reset values
The table below gives the USART register map and reset values.
0
0
0
0
0
0
0
0
0
0
Res. CTSCF CTSIF CTSIF Res. CTSE CPHA PS PS
8
0
0
0
0
0
0
0
0
0
0
0
LBDCF LBDF LBDF Res. RTSE LBCL PEIE PEIE
7
0
0
0
0
1
1
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
RDR[8:0]
ORECF ORE ORE RXFRQ HDSEL DIS_NSS TE TE
PSC[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
reset value
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
USART_TDR TDR[8:0]
0x28
Reset value 0 0 0 0 0 0 0 0 0
USART_ PRESCALE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x2C PRESC R[3:0]
Reset value 0 0 0 0
Refer to Section 2.2: Memory organization for the register boundary addresses.
25.1 Introduction
The SPI/I²S interface can be used to communicate with external devices using the SPI
protocol or the I2S audio protocol. SPI or I2S mode is selectable by software. SPI Motorola
mode is selected by default after a device reset.
The serial peripheral interface (SPI) protocol supports half-duplex, full-duplex and simplex
synchronous, serial communication with external devices. The interface can be configured
as master and in this case it provides the communication clock (SCK) to the external slave
device. The interface is also capable of operating in multimaster configuration.
The integrated interchip sound (I2S) protocol is also a synchronous serial communication
interface. It can operate in slave or master mode with half-duplex communication. It can
address four different audio standards including the Philips I2S standard, the MSB- and
LSB-justified standards and the PCM standard.
Read
Rx
FIFO
CRC controller
MOSI
MISO Shift register
RXONLY
CRCEN
CPOL CRCNEXT
CPHA CRCL
Tx DS[0:3]
FIFO
Write Communication
BIDIOE
controller
NSS
NSS logic
MS30117V1
Four I/O pins are dedicated to SPI communication with external devices.
• MISO: Master In / Slave Out data. In the general case, this pin is used to transmit data
in slave mode and receive data in master mode.
• MOSI: Master Out / Slave In data. In the general case, this pin is used to transmit data
in master mode and receive data in slave mode.
• SCK: Serial Clock output pin for SPI masters and input pin for SPI slaves.
• NSS: Slave select pin. Depending on the SPI and NSS settings, this pin can be used to
either:
– select an individual slave device for communication
– synchronize the data frame or
– detect a conflict between multiple masters
See Section 25.5.5: Slave select (NSS) pin management for details.
The SPI bus allows the communication between one master device and one or more slave
devices. The bus consists of at least two wires - one for the clock signal and the other for
synchronous data transfer. Other signals can be added depending on the data exchange
between SPI nodes and their slave select signal management.
Full-duplex communication
By default, the SPI is configured for full-duplex communication. In this configuration, the
shift registers of the master and slave are linked using two unidirectional lines between the
MOSI and the MISO pins. During SPI communication, data is shifted synchronously on the
SCK clock edges provided by the master. The master transmits the data to be sent to the
slave via the MOSI line and receives data from the slave via the MISO line. When the data
frame transfer is complete (all the bits are shifted) the information between the master and
slave is exchanged.
MISO MISO
Rx shift register Tx shift register
MOSI MOSI
Tx shift register Rx shift register
MSv39623V1
1. The NSS pins can be used to provide a hardware control flow between master and slave. Optionally, the
pins can be left unused by the peripheral. Then the flow has to be handled internally for both master and
slave. For more details see Section 25.5.5: Slave select (NSS) pin management.
Half-duplex communication
The SPI can communicate in half-duplex mode by setting the BIDIMODE bit in the
SPIx_CR1 register. In this configuration, one single cross connection line is used to link the
shift registers of the master and slave together. During this communication, the data is
synchronously shifted between the shift registers on the SCK clock edge in the transfer
direction selected reciprocally by both master and slave with the BDIOE bit in their
SPIx_CR1 registers. In this configuration, the master’s MISO pin and the slave’s MOSI pin
are free for other application uses and act as GPIOs.
(2)
MISO MISO
Rx shift register Tx shift register
(3)
MOSI Nȍ (2)
Tx shift register MOSI Rx shift register
MSv39624V1
1. The NSS pins can be used to provide a hardware control flow between master and slave. Optionally, the
pins can be left unused by the peripheral. Then the flow has to be handled internally for both master and
slave. For more details see Section 25.5.5: Slave select (NSS) pin management.
2. In this configuration, the master’s MISO pin and the slave’s MOSI pin can be used as GPIOs.
3. A critical situation can happen when communication direction is changed not synchronously between two
nodes working at bidirectionnal mode and new transmitter accesses the common data line while former
transmitter still keeps an opposite value on the line (the value depends on SPI configuration and
communication data). Both nodes then fight while providing opposite output levels on the common line
temporary till next node changes its direction settings correspondingly, too. It is suggested to insert a serial
resistance between MISO and MOSI pins at this mode to protect the outputs and limit the current blowing
between them at this situation.
Simplex communications
The SPI can communicate in simplex mode by setting the SPI in transmit-only or in receive-
only using the RXONLY bit in the SPIx_CR1 register. In this configuration, only one line is
used for the transfer between the shift registers of the master and slave. The remaining
MISO and MOSI pins pair is not used for communication and can be used as standard
GPIOs.
• Transmit-only mode (RXONLY=0): The configuration settings are the same as for full-
duplex. The application has to ignore the information captured on the unused input pin.
This pin can be used as a standard GPIO.
• Receive-only mode (RXONLY=1): The application can disable the SPI output function
by setting the RXONLY bit. In slave configuration, the MISO output is disabled and the
pin can be used as a GPIO. The slave continues to receive data from the MOSI pin
while its slave select signal is active (see 25.5.5: Slave select (NSS) pin management).
Received data events appear depending on the data buffer configuration. In the master
configuration, the MOSI output is disabled and the pin can be used as a GPIO. The
clock signal is generated continuously as long as the SPI is enabled. The only way to
stop the clock is to clear the RXONLY bit or the SPE bit and wait until the incoming
pattern from the MISO pin is finished and fills the data buffer structure, depending on its
configuration.
MSv39625V1
1. The NSS pins can be used to provide a hardware control flow between master and slave. Optionally, the
pins can be left unused by the peripheral. Then the flow has to be handled internally for both master and
slave. For more details see Section 25.5.5: Slave select (NSS) pin management.
2. An accidental input information is captured at the input of transmitter Rx shift register. All the events
associated with the transmitter receive flow must be ignored in standard transmit only mode (e.g. OVR
flag).
3. In this configuration, both the MISO pins can be used as GPIOs.
Note: Any simplex communication can be alternatively replaced by a variant of the half-duplex
communication with a constant setting of the transaction direction (bidirectional mode is
enabled while BDIO bit is not changed).
NSS (1)
MISO MISO
Rx shift register Tx shift register
MOSI MOSI
Tx shift register Rx shift register
MISO
Tx shift register
MOSI
Rx shift register
SCK
NSS
Slave 2
MISO
Tx shift register
MOSI
Rx shift register
SCK
NSS
Slave 3
MSv39626V1
1. NSS pin is not used on master side at this configuration. It has to be managed internally (SSM=1, SSI=1) to
prevent any MODF error.
2. As MISO pins of the slaves are connected together, all slaves must have the GPIO configuration of their
MISO pin set as alternate function open-drain (see I/O alternate function input/output section (GPIO)).
If potentially both nodes raised their mastering request at the same time a bus conflict event
appears (see mode fault MODF event). Then the user can apply some simple arbitration
process (e.g. to postpone next attempt by predefined different time-outs applied at both
nodes).
MISO MISO
Rx (Tx) shift register Rx (Tx) shift register
MOSI MOSI
Tx (Rx) shift register Tx (Rx) shift register
MSv39628V1
1. The NSS pin is configured at hardware input mode at both nodes. Its active level enables the MISO line
output control as the passive node is configured as a slave.
NSS Master
Slave mode
Inp. mode
Vdd OK Non active
NSS Input
0
NSS GPIO
pin logic
MSv35526V6
Figure 275, shows an SPI full-duplex transfer with the four combinations of the CPHA and
CPOL bits.
Note: Prior to changing the CPOL/CPHA bits the SPI must be disabled by resetting the SPE bit.
The idle state of SCK must correspond to the polarity selected in the SPIx_CR1 register (by
pulling up SCK if CPOL=1 or pulling down SCK if CPOL=0).
CPHA =1
CPOL = 1
CPOL = 0
Capture strobe
CPHA =0
CPOL = 1
CPOL = 0
Capture strobe
ai17154e
Figure 276. Data alignment when data length is not equal to 8-bit or 16-bit
DS <= 8 bits: data is right-aligned on byte DS > 8 bits: data is right-aligned on 16 bit
Example: DS = 5 bit Example: DS = 14 bit
7 5 4 0 15 14 13 0
XXX Data frame TX XX Data frame TX
7 5 4 0 15 14 13 0
000 Data frame RX 00 Data frame RX
MS19589V2
Note: The minimum data length is 4 bits. If a data length of less than 4 bits is selected, it is forced
to an 8-bit data frame size.
Another way to manage the data exchange is to use DMA (see Communication using DMA
(direct memory addressing)).
If the next data is received when the RXFIFO is full, an overrun event occurs (see
description of OVR flag at Section 25.5.10: SPI status flags). An overrun event can be
polled or handled by an interrupt.
The BSY bit being set indicates ongoing transaction of a current data frame. When the clock
signal runs continuously, the BSY flag stays set between data frames at master but
becomes low for a minimum duration of one SPI clock at slave between each data frame
transfer.
Sequence handling
A few data frames can be passed at single sequence to complete a message. When
transmission is enabled, a sequence begins and continues while any data is present in the
TXFIFO of the master. The clock signal is provided continuously by the master until TXFIFO
becomes empty, then it stops waiting for additional data.
In receive-only modes, half-duplex (BIDIMODE=1, BIDIOE=0) or simplex (BIDIMODE=0,
RXONLY=1) the master starts the sequence immediately when both SPI is enabled and
receive-only mode is activated. The clock signal is provided by the master and it does not
stop until either SPI or receive-only mode is disabled by the master. The master receives
data frames continuously up to this moment.
While the master can provide all the transactions in continuous mode (SCK signal is
continuous) it has to respect slave capability to handle data flow and its content at anytime.
When necessary, the master must slow down the communication and provide either a
slower clock or separate frames or data sessions with sufficient delays. Be aware there is no
underflow error signal for master or slave in SPI mode, and data from the slave is always
transacted and processed by the master even if the slave could not prepare it correctly in
time. It is preferable for the slave to use DMA, especially when data frames are shorter and
bus rate is high.
Each sequence must be encased by the NSS pulse in parallel with the multislave system to
select just one of the slaves for communication. In a single slave system it is not necessary
to control the slave with NSS, but it is often better to provide the pulse here too, to
synchronize the slave with the beginning of each data sequence. NSS can be managed by
both software and hardware (see Section 25.5.5: Slave select (NSS) pin management).
When the BSY bit is set it signifies an ongoing data frame transaction. When the dedicated
frame transaction is finished, the RXNE flag is raised. The last bit is just sampled and the
complete data frame is stored in the RXFIFO.
the SPI is disabled at the master transmitter while a frame transaction is ongoing or next
data frame is stored in TXFIFO, the SPI behavior is not guaranteed.
When the master is in any receive only mode, the only way to stop the continuous clock is to
disable the peripheral by SPE=0. This must occur in specific time window within last data
frame transaction just between the sampling time of its first bit and before its last bit transfer
starts (in order to receive a complete number of expected data frames and to prevent any
additional “dummy” data reading after the last valid data frame). Specific procedure must be
followed when disabling SPI in this mode.
Data received but not read remains stored in RXFIFO when the SPI is disabled, and must
be processed the next time the SPI is enabled, before starting a new sequence. To prevent
having unread data, ensure that RXFIFO is empty when disabling the SPI, by using the
correct disabling procedure, or by initializing all the SPI registers with a software reset via
the control of a specific register dedicated to peripheral reset (see the SPIiRST bits in the
RCC_APBiRSTR registers).
Standard disable procedure is based on pulling BSY status together with FTLVL[1:0] to
check if a transmission session is fully completed. This check can be done in specific cases,
too, when it is necessary to identify the end of ongoing transactions, for example:
• When NSS signal is managed by software and master has to provide proper end of
NSS pulse for slave, or
• When transactions’ streams from DMA or FIFO are completed while the last data frame
or CRC frame transaction is still ongoing in the peripheral bus.
The correct disable procedure is (except when receive only mode is used):
1. Wait until FTLVL[1:0] = 00 (no more data to transmit).
2. Wait until BSY=0 (the last data frame is processed).
3. Disable the SPI (SPE=0).
4. Read data until FRLVL[1:0] = 00 (read all the received data).
The correct disable procedure for certain receive only modes is:
1. Interrupt the receive flow by disabling SPI (SPE=0) in the specific time window while
the last data frame is ongoing.
2. Wait until BSY=0 (the last data frame is processed).
3. Read data until FRLVL[1:0] = 00 (read all the received data).
Note: If packing mode is used and an odd number of data frames with a format less than or equal
to 8 bits (fitting into one byte) has to be received, FRXTH must be set when FRLVL[1:0] =
01, in order to generate the RXNE event to read the last odd data frame and to keep good
FIFO pointer alignment.
Data packing
When the data frame size fits into one byte (less than or equal to 8 bits), data packing is
used automatically when any read or write 16-bit access is performed on the SPIx_DR
register. The double data frame pattern is handled in parallel in this case. At first, the SPI
operates using the pattern stored in the LSB of the accessed word, then with the other half
stored in the MSB. Figure 277 provides an example of data packing mode sequence
handling. Two data frames are sent after the single 16-bit access the SPIx_DR register of
the transmitter. This sequence can generate just one RXNE event in the receiver if the
RXFIFO threshold is set to 16 bits (FRXTH=0). The receiver then has to access both data
frames by a single 16-bit read of SPIx_DR as a response to this single RXNE event. The
RxFIFO threshold setting and the following read access must be always kept aligned at the
receiver side, as data can be lost if it is not in line.
A specific problem appears if an odd number of such “fit into one byte” data frames must be
handled. On the transmitter side, writing the last data frame of any odd sequence with an 8-
bit access to SPIx_DR is enough. The receiver has to change the Rx_FIFO threshold level
for the last data frame received in the odd sequence of frames in order to generate the
RXNE event.
SCK
16-bit access when write to data register 16-bit access when read from data register
SPI_DR= 0x040A when TxE=1 SPI_DR= 0x040A when RxNE=1
MS19590V1
1. In this example: Data size DS[3:0] is 4-bit configured, CPOL=0, CPHA=1 and LSBFIRST =0. The Data
storage is always right aligned while the valid bits are performed on the bus only, the content of LSB byte
goes first on the bus, the unused bits are not taken into account on the transmitter side and padded by
zeros at the receiver side.
When starting communication using DMA, to prevent DMA channel management raising
error events, these steps must be followed in order:
1. Enable DMA Rx buffer in the RXDMAEN bit in the SPI_CR2 register, if DMA Rx is
used.
2. Enable DMA streams for Tx and Rx in DMA registers, if the streams are used.
3. Enable DMA Tx buffer in the TXDMAEN bit in the SPI_CR2 register, if DMA Tx is used.
4. Enable the SPI by setting the SPE bit.
To close communication it is mandatory to follow these steps in order:
1. Disable DMA streams for Tx and Rx in the DMA registers, if the streams are used.
2. Disable the SPI by following the SPI disable procedure.
3. Disable DMA Tx and Rx buffers by clearing the TXDMAEN and RXDMAEN bits in the
SPI_CR2 register, if DMA Tx and/or DMA Rx are used.
Communication diagrams
Some typical timing schemes are explained in this section. These schemes are valid no
matter if the SPI events are handled by polling, interrupts or DMA. For simplicity, the
LSBFIRST=0, CPOL=0 and CPHA=1 setting is used as a common assumption here. No
complete configuration of DMA streams is provided.
The following numbered notes are common for Figure 278 on page 763 through Figure 281
on page 766:
1. The slave starts to control MISO line as NSS is active and SPI is enabled, and is
disconnected from the line when one of them is released. Sufficient time must be
provided for the slave to prepare data dedicated to the master in advance before its
transaction starts.
At the master, the SPI peripheral takes control at MOSI and SCK signals (occasionally
at NSS signal as well) only if SPI is enabled. If SPI is disabled the SPI peripheral is
disconnected from GPIO logic, so the levels at these lines depends on GPIO setting
exclusively.
2. At the master, BSY stays active between frames if the communication (clock signal) is
continuous. At the slave, BSY signal always goes down for at least one clock cycle
between data frames.
3. The TXE signal is cleared only if TXFIFO is full.
4. The DMA arbitration process starts just after the TXDMAEN bit is set. The TXE
interrupt is generated just after the TXEIE is set. As the TXE signal is at an active level,
data transfers to TxFIFO start, until TxFIFO becomes full or the DMA transfer
completes.
5. If all the data to be sent can fit into TxFIFO, the DMA Tx TCIF flag can be raised even
before communication on the SPI bus starts. This flag always rises before the SPI
transaction is completed.
6. The CRC value for a package is calculated continuously frame by frame in the
SPIx_TXCRCR and SPIx_RXCRCR registers. The CRC information is processed after
the entire data package has completed, either automatically by DMA (Tx channel must
be set to the number of data frames to be processed) or by SW (the user must handle
CRCNEXT bit during the last data frame processing).
While the CRC value calculated in SPIx_TXCRCR is simply sent out by transmitter,
received CRC information is loaded into RxFIFO and then compared with the
SPIx_RXCRCR register content (CRC error flag can be raised here if any difference).
This is why the user must take care to flush this information from the FIFO, either by
software reading out all the stored content of RxFIFO, or by DMA when the proper
number of data frames is preset for Rx channel (number of data frames + number of
CRC frames) (see the settings at the example assumption).
7. In data packed mode, TxE and RxNE events are paired and each read/write access to
the FIFO is 16 bits wide until the number of data frames are even. If the TxFIFO is ¾
full FTLVL status stays at FIFO full level. That is why the last odd data frame cannot be
stored before the TxFIFO becomes ½ full. This frame is stored into TxFIFO with an 8-
bit access either by software or automatically by DMA when LDMA_TX control is set.
8. To receive the last odd data frame in packed mode, the Rx threshold must be changed
to 8-bit when the last data frame is processed, either by software setting FRXTH=1 or
automatically by a DMA internal signal when LDMA_RX is set.
NSS
SCK
BSY 2 2
SPE
3 3
TXE
FTLVL 00 10 11 10 11 10 00
4
MISO DRx1 LSB DRx2 LSB DRx3 LSB
1 1
RXNE
FRLVL 00 10 00 10 00 10 00
NSS
SCK
BSY 2
SPE 1
3 3
TXE
FTLVL 00 10 11 10 11 10 00
RXNE
FRLVL 00 10 00 10 00 10 00
MSv32123V2
NSS
SCK
BSY 2
SPE
TXE 3
FTLVL 00 10 11 10 00
4
MISO DRx1 LSB DRx2 LSB CRC LSB
1 1
RXNE
FRLVL 00 10 00 10 00 10 00
NSS
SCK
BSY 2
DTx1-2 DTx3-4 DTx5
MOSI 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1
SPE
3 3
TXE
FTLVL 00 10 11 10 11 10 01 00
4
MISO 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1 5 4 3 2 1
The FRE flag is cleared when SPIx_SR register is read. If the ERRIE bit is set, an interrupt
is generated on the NSS error detection. In this case, the SPI should be disabled because
data consistency is no longer guaranteed and communications should be reinitiated by the
master when the slave SPI is enabled again.
NSS
output
SCK
output
MOSI
output MSB LSB MSB LSB
MISO
input Do not care MSB LSB Do not care MSB LSB Do not care
Note: Similar behavior is encountered when CPOL = 0. In this case the sampling edge is the rising
edge of SCK, and NSS assertion and deassertion refer to this sampling edge.
25.5.13 TI mode
TI protocol in master mode
The SPI interface is compatible with the TI protocol. The FRF bit of the SPIx_CR2 register
can be used to configure the SPI to be compliant with this protocol.
The clock polarity and phase are forced to conform to the TI protocol requirements whatever
the values set in the SPIx_CR1 register. NSS management is also specific to the TI protocol
which makes the configuration of NSS management through the SPIx_CR1 and SPIx_CR2
registers (SSM, SSI, SSOE) impossible in this case.
In slave mode, the SPI baud rate prescaler is used to control the moment when the MISO
pin state changes to HiZ when the current transaction finishes (see Figure 283). Any baud
rate can be used, making it possible to determine this moment with optimal flexibility.
However, the baud rate is generally set to the external master clock baud rate. The delay for
the MISO signal to become HiZ (trelease) depends on internal resynchronization and on the
baud rate value set in through the BR[2:0] bits in the SPIx_CR1 register. It is given by the
formula:
t baud_rate t baud_rate
- + 4 × t pclk < t release < ---------------------
--------------------- - + 6 × t pclk
2 2
If the slave detects a misplaced NSS pulse during a data frame transaction the TIFRE flag is
set.
If the data size is equal to 4-bits or 5-bits, the master in full-duplex mode or transmit-only
mode uses a protocol with one more dummy data bit added after LSB. TI NSS pulse is
generated above this dummy bit clock cycle instead of the LSB in each period.
This feature is not available for Motorola SPI communications (FRF bit set to 0).
Figure 283: TI mode transfer shows the SPI communication waveforms when TI mode is
selected.
NSS
g
t RELEASE
in
in
in
er
er
er
pl
pl
pl
gg
gg
gg
m
m
sa
sa
sa
tri
tri
tri
SCK
FRAME 1 FRAME 2
MS19835V2
CRC principle
CRC calculation is enabled by setting the CRCEN bit in the SPIx_CR1 register before the
SPI is enabled (SPE = 1). The CRC value is calculated using an odd programmable
polynomial on each bit. The calculation is processed on the sampling clock edge defined by
the CPHA and CPOL bits in the SPIx_CR1 register. The calculated CRC value is checked
automatically at the end of the data block as well as for transfer managed by CPU or by the
DMA. When a mismatch is detected between the CRC calculated internally on the received
data and the CRC sent by the transmitter, a CRCERR flag is set to indicate a data corruption
error. The right procedure for handling the CRC calculation depends on the SPI
configuration and the chosen transfer management.
Note: The polynomial value should only be odd. No even values are supported.
If the SPI is disabled during a communication the following sequence must be followed:
1. Disable the SPI
2. Clear the CRCEN bit
3. Enable the CRCEN bit
4. Enable the SPI
Note: When the SPI interface is configured as a slave, the NSS internal signal needs to be kept
low during transaction of the CRC phase once the CRCNEXT signal is released. That is why
the CRC calculation cannot be used at NSS Pulse mode when NSS hardware mode should
be applied at slave normally.
At TI mode, despite the fact that clock phase and clock polarity setting is fixed and
independent on SPIx_CR1 register, the corresponding setting CPOL=0 CPHA=1 has to be
kept at the SPIx_CR1 register anyway if CRC is applied. In addition, the CRC calculation
has to be reset between sessions by SPI disable sequence with re-enable the CRCEN bit
described above at both master and slave side, else CRC calculation can be corrupted at
this specific mode.
Tx buffer
CRC CH
16-bit BSY OVR MODF UDR TxE RxNE FRE
ERR SIDE
MOSI/SD
Shift register
MISO LSB first Communication
16-bit control
Rx buffer
NSS/WS
I2S
I2SE
MOD
SPI LSB
SPE BR2 BR1 BR0 MSTR CPOL CPHA
baud rate generator First
CK
I2SMOD
MCK I2SxCLK
MCKOE ODD I2SDIV[7:0]
MS32126V1
For all data formats and communication standards, the most significant bit is always sent
first (MSB first).
The I2S interface supports four audio standards, configurable using the I2SSTD[1:0] and
PCMSYNC bits in the SPIx_I2SCFGR register.
CK
WS transmission reception
Channel left
Channel
right
MS19591V1
Data are latched on the falling edge of CK (for the transmitter) and are read on the rising
edge (for the receiver). The WS signal is also latched on the falling edge of CK.
CK
WS Transmission Reception
MS19592V1
This mode needs two write or read operations to/from the SPIx_DR register.
• In transmission mode:
If 0x8EAA33 has to be sent (24-bit):
0x8EAA 0x33XX
MS19593V2
• In reception mode:
If data 0x8EAA33 is received:
0x8EAA 0x33XX
MS19594V1
Figure 289. I2S Philips standard (16-bit extended to 32-bit packet frame)
CK
WS Transmission Reception
MS19599V1
When 16-bit data frame extended to 32-bit channel frame is selected during the I2S
configuration phase, only one access to the SPIx_DR register is required. The 16 remaining
bits are forced by hardware to 0x0000 to extend the data to 32-bit format.
If the data to transmit or the received data are 0x76A3 (0x76A30000 extended to 32-bit), the
operation shown in Figure 290 is required.
Figure 290. Example of 16-bit data frame extended to 32-bit channel frame
0x76A3
MS19595V1
For transmission, each time an MSB is written to SPIx_DR, the TXE flag is set and its
interrupt, if allowed, is generated to load the SPIx_DR register with the new value to send.
This takes place even if 0x0000 have not yet been sent because it is done by hardware.
For reception, the RXNE flag is set and its interrupt, if allowed, is generated when the first
16 MSB half-word is received.
In this way, more time is provided between two write or read operations, which prevents
underrun or overrun conditions (depending on the direction of the data transfer).
CK
WS Transmission Reception
Channel left
Channel right
MS30100 V1
Data are latched on the falling edge of CK (for transmitter) and are read on the rising edge
(for the receiver).
WS Transmission Reception
Channel right
MS30101V1
CK
WS Transmission Reception
Channel right
MS30102V1
CK
WS
Transmission Reception
16- or 32-bit data
SD
MSB LSB MSB
Channel left
Channel right
MS30103V1
CK
WS Reception
Transmission
8-bit data 24-bit remaining
SD 0 forced
MSB LSB
MS30104V1
• In transmission mode:
If data 0x3478AE have to be transmitted, two write operations to the SPIx_DR register
are required by software or by DMA. The operations are shown below.
0xXX34 0x78AE
• In reception mode:
If data 0x3478AE are received, two successive read operations from the SPIx_DR
register are required on each RXNE event.
First read from Data register Second read from Data register
conditioned by RXNE=1 conditioned by RXNE=1
0xXX34 0x78AE
MS19597V1
CK
Reception
WS
Transmission
16-bit data 16-bit remaining
SD 0 forced
MSB LSB
When 16-bit data frame extended to 32-bit channel frame is selected during the I2S
configuration phase, Only one access to the SPIx_DR register is required. The 16 remaining
bits are forced by hardware to 0x0000 to extend the data to 32-bit format. In this case it
corresponds to the half-word MSB.
If the data to transmit or the received data are 0x76A3 (0x0000 76A3 extended to 32-bit),
the operation shown in Figure 299 is required.
Figure 299. Example of 16-bit data frame extended to 32-bit channel frame
0x76A3
MS19598V1
In transmission mode, when a TXE event occurs, the application has to write the data to be
transmitted (in this case 0x76A3). The 0x000 field is transmitted first (extension on 32-bit).
The TXE flag is set again as soon as the effective data (0x76A3) is sent on SD.
In reception mode, RXNE is asserted as soon as the significant half-word is received (and
not the 0x0000 field).
In this way, more time is provided between two write or read operations to prevent underrun
or overrun conditions.
PCM standard
For the PCM standard, there is no need to use channel-side information. The two PCM
modes (short and long frame) are available and configurable using the PCMSYNC bit in
SPIx_I2SCFGR register.
In PCM mode, the output signals (WS, SD) are sampled on the rising edge of CK signal.
The input signals (WS, SD) are captured on the falling edge of CK.
Note that CK and WS are configured as output in MASTER mode.
CK
WS
short frame
13-bits
WS
long frame
MS30106V1
For long frame synchronization, the WS signal assertion time is fixed to 13 bits in master
mode.
For short frame synchronization, the WS synchronization signal is only one cycle long.
Figure 301. PCM standard waveforms (16-bit extended to 32-bit packet frame)
CK
WS
short frame
Up to 13-bits
WS
long frame
16 bits
SD MSB LSB
MS30107V1
Note: For both modes (master and slave) and for both synchronizations (short and long), the
number of bits between two consecutive pieces of data (and so two synchronization signals)
needs to be specified (DATLEN and CHLEN bits in the SPIx_I2SCFGR register) even in
slave mode.
CK (O), CKPOL = 0
CK (O), CKPOL = 1
CK (O), CKPOL = 0
CK (O), CKPOL = 1
dum Left sample Right sample
SD (O)
I2SE
CK (O), CKPOL = 0
CK (O), CKPOL = 1
dum Sample1 Sample 2
SD (O)
I2SE
Master PCM long frame
WS (O)
CK (O), CKPOL = 0
CK (O), CKPOL = 1
dum Sample1 Sample 2
SD (O)
I2SE
dum: not significant data
MSv37520V2
In slave mode, the way the frame synchronization is detected, depends on the value of
ASTRTEN bit.
If ASTRTEN = 0, when the audio interface is enabled (I2SE = 1), then the hardware waits for
the appropriate transition on the incoming WS signal, using the CK signal.
The appropriate transition is a falling edge on WS signal when I2S Philips Standard is used,
or a rising edge for other standards. The falling edge is detected by sampling first WS to 1
and then to 0, and vice-versa for the rising edge detection.
If ASTRTEN = 1, the user has to enable the audio interface before the WS becomes active.
This means that the I2SE bit must be set to 1 when WS = 1 for I2S Philips standard, or when
WS = 0 for other standards.
32- or 64-bits
FS
sampling point sampling point
MS30108V1
When the master mode is configured, a specific action needs to be taken to properly
program the linear divider in order to communicate with the desired audio frequency.
MCK
MCKOE
I²SMOD
CHLEN
MS30109V1
1. Where x can be 2 or 3.
Figure 304 presents the communication clock architecture. The I2SxCLK clock is provided
by the reset and clock controller (RCC) of the product. The I2SxCLK clock can be
asynchronous with respect to the SPI/I2S APB clock.
The audio sampling frequency may be 192 kHz, 96 kHz, 48 kHz, 44.1 kHz, 32 kHz,
22.05 kHz, 16 kHz, 11.025 kHz or 8 kHz (or any other value within this range).
In order to reach the desired frequency, the linear divider needs to be programmed
according to the formulas below:
Fs = F I2SxCLK
-----------------------------------------------------------------------------------------------------------
256 × ( ( 2 × I2SDIV ) + ODD )
Fs = F I2SxCLK
------------------------------------------------------------------------------------------------------------------------------------------------------------------
32 × ( CHLEN + 1 ) × ( ( 2 × I2SDIV ) + ODD )
CHLEN = 0 when the channel frame is 16-bit wide and,
CHLEN = 1 when the channel frame is 32-bit wide.
Fs = F I2SxCLK
-----------------------------------------------------------------------------------------------------------
128 × ( ( 2 × I2SDIV ) + ODD )
Fs = F I2SxCLK
------------------------------------------------------------------------------------------------------------------------------------------------------------------
16 × ( CHLEN + 1 ) × ( ( 2 × I2SDIV ) + ODD )
CHLEN = 0 when the channel frame is 16-bit wide and,
CHLEN = 1 when the channel frame is 32-bit wide.
Where FS is the audio sampling frequency, and FI2SxCLKis the frequency of the kernel clock
provided to the SPI/I2S block.
Table 116. Audio-frequency precision using 48 MHz clock derived from HSE(1)
SYSCLK Data Target fs
I2SDIV I2SODD MCLK Real fs (kHz) Error
(MHz) length (Hz)
1. This table gives only example values for different clock configurations. Other configurations allowing
optimum clock precision are possible.
Procedure
1. Select the I2SDIV[7:0] bits in the SPIx_I2SPR register to define the serial clock baud
rate to reach the proper audio sample frequency. The ODD bit in the SPIx_I2SPR
register also has to be defined.
2. Select the CKPOL bit to define the steady level for the communication clock. Set the
MCKOE bit in the SPIx_I2SPR register if the master clock MCK needs to be provided
to the external DAC/ADC audio component (the I2SDIV and ODD values should be
computed depending on the state of the MCK output, for more details refer to
Section 25.7.4: Clock generator).
3. Set the I2SMOD bit in the SPIx_I2SCFGR register to activate the I2S functions and
choose the I2S standard through the I2SSTD[1:0] and PCMSYNC bits, the data length
through the DATLEN[1:0] bits and the number of bits per channel by configuring the
CHLEN bit. Select also the I2S master mode and direction (Transmitter or Receiver)
through the I2SCFG[1:0] bits in the SPIx_I2SCFGR register.
4. If needed, select all the potential interrupt sources and the DMA capabilities by writing
the SPIx_CR2 register.
5. The I2SE bit in SPIx_I2SCFGR register must be set.
WS and CK are configured in output mode. MCK is also an output, if the MCKOE bit in
SPIx_I2SPR is set.
Transmission sequence
The transmission sequence begins when a half-word is written into the Tx buffer.
Lets assume the first data written into the Tx buffer corresponds to the left channel data.
When data are transferred from the Tx buffer to the shift register, TXE is set and data
corresponding to the right channel have to be written into the Tx buffer. The CHSIDE flag
indicates which channel is to be transmitted. It has a meaning when the TXE flag is set
because the CHSIDE flag is updated when TXE goes high.
A full frame has to be considered as a left channel data transmission followed by a right
channel data transmission. It is not possible to have a partial frame where only the left
channel is sent.
The data half-word is parallel loaded into the 16-bit shift register during the first bit
transmission, and then shifted out, serially, to the MOSI/SD pin, MSB first. The TXE flag is
set after each transfer from the Tx buffer to the shift register and an interrupt is generated if
the TXEIE bit in the SPIx_CR2 register is set.
For more details about the write operations depending on the I2S standard mode selected,
refer to Section 25.7.2: Supported audio protocols).
To ensure a continuous audio data transmission, it is mandatory to write the SPIx_DR
register with the next data to transmit before the end of the current transmission.
To switch off the I2S, by clearing I2SE, it is mandatory to wait for TXE = 1 and BSY = 0.
Reception sequence
The operating mode is the same as for transmission mode except for the point 3 (refer to the
procedure described in Section 25.7.5: I2S master mode), where the configuration should
set the master reception mode through the I2SCFG[1:0] bits.
Whatever the data or channel length, the audio data are received by 16-bit packets. This
means that each time the Rx buffer is full, the RXNE flag is set and an interrupt is generated
if the RXNEIE bit is set in SPIx_CR2 register. Depending on the data and channel length
configuration, the audio value received for a right or left channel may result from one or two
receptions into the Rx buffer.
Clearing the RXNE bit is performed by reading the SPIx_DR register.
CHSIDE is updated after each reception. It is sensitive to the WS signal generated by the
I2S cell.
For more details about the read operations depending on the I2S standard mode selected,
refer to Section 25.7.2: Supported audio protocols.
If data are received while the previously received data have not been read yet, an overrun is
generated and the OVR flag is set. If the ERRIE bit is set in the SPIx_CR2 register, an
interrupt is generated to indicate the error.
To switch off the I2S, specific actions are required to ensure that the I2S completes the
transfer cycle properly without initiating a new data transfer. The sequence depends on the
configuration of the data and channel lengths, and on the audio protocol mode selected. In
the case of:
• 16-bit data length extended on 32-bit channel length (DATLEN = 00 and CHLEN = 1)
using the LSB justified mode (I2SSTD = 10)
a) Wait for the second to last RXNE = 1 (n – 1)
b) Then wait 17 I2S clock cycles (using a software loop)
c) Disable the I2S (I2SE = 0)
• 16-bit data length extended on 32-bit channel length (DATLEN = 00 and CHLEN = 1) in
MSB justified, I2S or PCM modes (I2SSTD = 00, I2SSTD = 01 or I2SSTD = 11,
respectively)
a) Wait for the last RXNE
b) Then wait 1 I2S clock cycle (using a software loop)
c) Disable the I2S (I2SE = 0)
• For all other combinations of DATLEN and CHLEN, whatever the audio mode selected
through the I2SSTD bits, carry out the following sequence to switch off the I2S:
a) Wait for the second to last RXNE = 1 (n – 1)
b) Then wait one I2S clock cycle (using a software loop)
c) Disable the I2S (I2SE = 0)
Note: The BSY flag is kept low during transfers.
configuration. In slave mode, there is no clock to be generated by the I2S interface. The
clock and WS signals are input from the external master connected to the I2S interface.
There is then no need, for the user, to configure the clock.
The configuration steps to follow are listed below:
1. Set the I2SMOD bit in the SPIx_I2SCFGR register to select I2S mode and choose the
I2S standard through the I2SSTD[1:0] bits, the data length through the DATLEN[1:0]
bits and the number of bits per channel for the frame configuring the CHLEN bit. Select
also the mode (transmission or reception) for the slave through the I2SCFG[1:0] bits in
SPIx_I2SCFGR register.
2. If needed, select all the potential interrupt sources and the DMA capabilities by writing
the SPIx_CR2 register.
3. The I2SE bit in SPIx_I2SCFGR register must be set.
Transmission sequence
The transmission sequence begins when the external master device sends the clock and
when the NSS_WS signal requests the transfer of data. The slave has to be enabled before
the external master starts the communication. The I2S data register has to be loaded before
the master initiates the communication.
For the I2S, MSB justified and LSB justified modes, the first data item to be written into the
data register corresponds to the data for the left channel. When the communication starts,
the data are transferred from the Tx buffer to the shift register. The TXE flag is then set in
order to request the right channel data to be written into the I2S data register.
The CHSIDE flag indicates which channel is to be transmitted. Compared to the master
transmission mode, in slave mode, CHSIDE is sensitive to the WS signal coming from the
external master. This means that the slave needs to be ready to transmit the first data
before the clock is generated by the master. WS assertion corresponds to left channel
transmitted first.
Note: The I2SE has to be written at least two PCLK cycles before the first clock of the master
comes on the CK line.
The data half-word is parallel-loaded into the 16-bit shift register (from the internal bus)
during the first bit transmission, and then shifted out serially to the MOSI/SD pin MSB first.
The TXE flag is set after each transfer from the Tx buffer to the shift register and an interrupt
is generated if the TXEIE bit in the SPIx_CR2 register is set.
Note that the TXE flag should be checked to be at 1 before attempting to write the Tx buffer.
For more details about the write operations depending on the I2S standard mode selected,
refer to Section 25.7.2: Supported audio protocols.
To secure a continuous audio data transmission, it is mandatory to write the SPIx_DR
register with the next data to transmit before the end of the current transmission. An
underrun flag is set and an interrupt may be generated if the data are not written into the
SPIx_DR register before the first clock edge of the next data communication. This indicates
to the software that the transferred data are wrong. If the ERRIE bit is set into the SPIx_CR2
register, an interrupt is generated when the UDR flag in the SPIx_SR register goes high. In
this case, it is mandatory to switch off the I2S and to restart a data transfer starting from the
left channel.
To switch off the I2S, by clearing the I2SE bit, it is mandatory to wait for TXE = 1 and
BSY = 0.
Reception sequence
The operating mode is the same as for the transmission mode except for the point 1 (refer to
the procedure described in Section 25.7.6: I2S slave mode), where the configuration should
set the master reception mode using the I2SCFG[1:0] bits in the SPIx_I2SCFGR register.
Whatever the data length or the channel length, the audio data are received by 16-bit
packets. This means that each time the RX buffer is full, the RXNE flag in the SPIx_SR
register is set and an interrupt is generated if the RXNEIE bit is set in the SPIx_CR2
register. Depending on the data length and channel length configuration, the audio value
received for a right or left channel may result from one or two receptions into the RX buffer.
The CHSIDE flag is updated each time data are received to be read from the SPIx_DR
register. It is sensitive to the external WS line managed by the external master component.
Clearing the RXNE bit is performed by reading the SPIx_DR register.
For more details about the read operations depending the I2S standard mode selected, refer
to Section 25.7.2: Supported audio protocols.
If data are received while the preceding received data have not yet been read, an overrun is
generated and the OVR flag is set. If the bit ERRIE is set in the SPIx_CR2 register, an
interrupt is generated to indicate the error.
To switch off the I2S in reception mode, I2SE has to be cleared immediately after receiving
the last RXNE = 1.
Note: The external master components should have the capability of sending/receiving data in 16-
bit or 32-bit packets via an audio channel.
synchronization is lost, the following steps are required to recover from this state and
resynchronize the external master device with the I2S slave device:
1. Disable the I2S.
2. Enable it again when the correct level is detected on the WS line (WS line is high in I2S
mode or low for MSB- or LSB-justified or PCM modes.
Desynchronization between master and slave devices may be due to noisy environment on
the CK communication clock or on the WS frame synchronization line. An error interrupt can
be generated if the ERRIE bit is set. The desynchronization flag (FRE) is cleared by
software when the status register is read.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BIDI CRC CRCN RX LSB
BIDIOE CRCL SSM SSI SPE BR[2:0] MSTR CPOL CPHA
MODE EN EXT ONLY FIRST
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LDMA LDMA FRXT
Res. DS[3:0] TXEIE RXNEIE ERRIE FRF NSSP SSOE TXDMAEN RXDMAEN
_TX _RX H
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRCE
Res. Res. Res. FTLVL[1:0] FRLVL[1:0] FRE BSY OVR MODF UDR CHSIDE TXE RXNE
RR
r r r r r r r r rc_w0 r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The polynomial value should be odd only. No even value is supported.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RXCRC[15:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TXCRC[15:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ASTR
Res. Res. Res. I2SMOD I2SE I2SCFG[1:0] PCMSYNC Res. I2SSTD[1:0] CKPOL DATLEN[1:0] CHLEN
TEN
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. MCKOE ODD I2SDIV[7:0]
rw rw rw rw rw rw rw rw rw rw
15
14
13
12
10
11
0
reset value
BIDIMODE
CRCNEXT
LSBFIRST
RXONLY
CRCEN
BIDIOE
MSTR
CPHA
CPOL
CRCL
SSM
SPE
SSI
SPIx_CR1 BR [2:0]
0x00
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RXDMAEN
TXDMAEN
LDMA_RX
LDMA_TX
RXNEIE
FRXTH
ERRIE
TXEIE
SSOE
NSSP
Res.
FRF
SPIx_CR2 DS[3:0]
0x04
Reset value 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0
FRLVL[1:0]
FTLVL[1:0]
CRCERR
CHSIDE
MODF
RXNE
OVR
UDR
Res.
Res.
Res.
FRE
BSY
TXE
SPIx_SR
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 1 0
SPIx_DR DR[15:0]
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPIx_CRCPR CRCPOLY[15:0]
0x10
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
SPIx_RXCRCR RXCRC[15:0]
0x14
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPIx_TXCRCR TXCRC[15:0]
0x18
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DATLEN[1:0]
I2SCFG[1:0]
PCMSYNC
ASTRTEN
I2SMOD
I2SSTD
CKPOL
CHLEN
I2SE
Res.
Res.
Res.
Res.
SPIx_I2SCFGR
0x1C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
MCKOE
ODD
Res.
Res.
Res.
Res.
Res.
Res.
SPIx_I2SPR I2SDIV[7:0]
0x20
Reset value 0 0 0 0 0 0 0 0 1 0
26.1 Overview
The STM32C0x1 devices are built around a Cortex®-M0+ core which contains hardware
extensions for advanced debugging features. The debug extensions allow the core to be
stopped either on a given instruction fetch (breakpoint) or data access (watchpoint). When
stopped, the core’s internal state and the system’s external state may be examined. Once
examination is complete, the core and the system may be restored and program execution
resumed.
The debug features are used by the debugger host when connecting to and debugging the
STM32C0x1 MCUs.
One interface for debug is available:
• Serial wire
Figure 305. Block diagram of STM32C0x1 MCU and Cortex®-M0+-level debug support
Debug AP
Bridge DBGMCU
SWDIO SW-DP
SWCLK Debug AP
NVIC
DWT
BPU
MS19240V2
1. The debug features embedded in the Cortex®-M0+ core are a subset of the Arm CoreSight Design Kit.
®
The Arm Cortex -M0+ core provides integrated on-chip debug support. It is comprised of:
• SW-DP: Serial wire
• BPU: Break point unit
• DWT: Data watchpoint trigger
Refer to the Cortex®-M0+ TRM for a detailed description of DPACC and APACC registers.
The packet request is always followed by the turnaround time (default 1 bit) where neither
the host nor target drive the line.
001: FAULT
0..2 ACK 010: WAIT
100: OK
The ACK Response must be followed by a turnaround time only if it is a READ transaction
or if a WAIT or FAULT acknowledge has been received.
The DATA transfer must be followed by a turnaround time only if it is a READ transaction.
Note: Note that the SW-DP state machine is inactive until the target reads this ID code.
• The SW-DP state machine is in RESET STATE either after power-on reset, or after the
line is high for more than 50 cycles
• The SW-DP state machine is in IDLE STATE if the line is low for at least two cycles
after RESET state.
• After RESET state, it is mandatory to first enter into an IDLE state AND to perform a
READ access of the DP-SW ID CODE register. Otherwise, the target issues a FAULT
acknowledge response on another transactions.
Further details of the SW-DP state machine can be found in the Cortex®-M0+ TRM and the
CoreSight Design Kit r1p0 TRM.
Purpose is to:
– request a system or debug power-on
– configure the transfer operation for AP
accesses
01 Read/Write 0 DP-CTRL/STAT
– control the pushed compare and pushed
verify operations.
– read some status flags (overrun, power-on
acknowledges)
Purpose is to configure the physical serial
WIRE
01 Read/Write 1 port protocol (like the duration of the
CONTROL
turnaround time)
Enables recovery of the read data from a
READ
10 Read corrupted debugger transfer, without
RESEND
repeating the original AP transfer.
The purpose is to select the current access
10 Write SELECT
port and the active 4-words register window
This read buffer is useful because AP
accesses are posted (the result of a read AP
request is available on the next AP
11 Read/Write READ BUFFER transaction).
This read buffer captures data from the AP,
presented as the result of a previous read,
without initiating a new transaction
Table 124. 32-bit debug port registers addressed through the shifted value A[3:2]
Address A[3:2] value Description
Table 124. 32-bit debug port registers addressed through the shifted value A[3:2]
Address A[3:2] value Description
DP SELECT register: Used to select the current access port and the
active 4-words register window.
– Bits 31:24: APSEL: select the current AP
0x8 10 – Bits 23:8: reserved
– Bits 7:4: APBANKSEL: select the active 4-words register window on the
current AP
– Bits 3:0: reserved
DP RDBUFF register: Used to allow the debugger to get the final result
0xC 11 after a sequence of operations (without requesting new JTAG-DP
operation)
These registers are not reset by a system reset. They are only reset by a power-on reset.
Refer to the Cortex®-M0+ TRM for further details.
To Halt on reset, it is necessary to:
• enable the bit0 (VC_CORRESET) of the Debug and Exception Monitor Control
Register
• enable the bit0 (C_DEBUGEN) of the Debug Halting Control and Status Register
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
REV_ID[15:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. DEV_ID[11:0]
r r r r r r r r r r r r
A 1.0 0x1000
STM32C011xx 0x443
Z 1.1 0x1001
A 1.0 0x1000
STM32C031xx 0x453
Z 1.1 0x1001
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DBG_
DBG_
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. STAND Res.
STOP
BY
rw rw
Upon Stop mode exit, the software must re-establish the desired clock configuration.
Bit 0 Reserved, must be kept at reset value.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBG_I2C1_SMBUS_TIMEOUT
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DBG_WWDG_STOP
DBG_IWDG_STOP
DBG_TIM3_STOP
DBG_RTC_STOP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBG_TIM17_STOP
DBG_TIM16_STOP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DBG_TIM14_STOP
DBG_TIM1_STOP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw rw
0x0C
Offset
816/825
.
DBG_
DBG_
DBG_
IDCODE
DBG_CR
(DBG_IDCODE).
APB_FZ2
APB_FZ1
Register
Reset value
Reset value
Reset value
Reset value(1)
X
Res. Res. Res. 31
Debug support (DBG)
X
Res. Res. Res. 30
X
Res. Res. Res. 29
Res. Res. Res. X
X 28
Res. Res. Res. 27
X
0
X X X X
0
X
0
X
RM0490 Rev 3
17
X
0
0
0
0
X
0
X
The device electronic signature is stored in the System memory area of the Flash memory
module, and can be read using the debug inter face or by the CPU. It contains factory-
programmed identification and calibration data that allow the user firmware or other external
devices to automatically match to the characteristics of the STM32C0x1 microcontroller.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UID[31:16]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UID[15:0]
r r r r r r r r r r r r r r r r
Bits 31:0 UID[31:0]: X and Y coordinates on the wafer expressed in BCD format
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UID[63:48]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UID[47:32]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UID[95:80]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UID[79:64]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FLASH_SIZE
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PKG[3:0]
r r r r
The STMicroelectronics group of companies (ST) places a high value on product security,
which is why the ST product(s) identified in this documentation may be certified by various
security certification bodies and/or may implement our own security measures as set forth
herein. However, no level of security certification and/or built-in security measures can
guarantee that ST products are resistant to all forms of attacks. As such, it is the
responsibility of each of ST's customers to determine if the level of security provided in an
ST product meets the customer needs both in relation to the ST product alone, as well as
when combined with other components and/or software for the customer end product or
application. In particular, take note that:
• ST products may have been certified by one or more security certification bodies, such
as Platform Security Architecture (www.psacertified.org) and/or Security Evaluation
standard for IoT Platforms (www.trustcb.com). For details concerning whether the ST
product(s) referenced herein have received security certification along with the level
and current status of such certification, either visit the relevant certification standards
website or go to the relevant product page on www.st.com for the most up to date
information. As the status and/or level of security certification for an ST product can
change from time to time, customers should re-check security certification status/level
as needed. If an ST product is not shown to be certified under a particular security
standard, customers should not assume it is certified.
• Certification bodies have the right to evaluate, grant and revoke security certification in
relation to ST products. These certification bodies are therefore independently
responsible for granting or revoking security certification for an ST product, and ST
does not take any responsibility for mistakes, evaluations, assessments, testing, or
other activity carried out by the certification body with respect to any ST product.
• Industry-based cryptographic algorithms (such as AES, DES, or MD5) and other open
standard technologies which may be used in conjunction with an ST product are based
on standards which were not developed by ST. ST does not take responsibility for any
flaws in such cryptographic algorithms or open technologies or for any methods which
have been or may be developed to bypass, decrypt or crack such algorithms or
technologies.
• While robust security testing may be done, no level of certification can absolutely
guarantee protections against all attacks, including, for example, against advanced
attacks which have not been tested for, against new or unidentified forms of attack, or
against any form of attack when using an ST product outside of its specification or
intended use, or in conjunction with other components or software which are used by
customer to create their end product or application. ST is not responsible for resistance
against such attacks. As such, regardless of the incorporated security features and/or
any information or support that may be provided by ST, each customer is solely
responsible for determining if the level of attacks tested for meets their needs, both in
relation to the ST product alone and when incorporated into a customer end product or
application.
• All security features of ST products (inclusive of any hardware, software,
documentation, and the like), including but not limited to any enhanced security
features added by ST, are provided on an "AS IS" BASIS. AS SUCH, TO THE EXTENT
PERMITTED BY APPLICABLE LAW, ST DISCLAIMS ALL WARRANTIES, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, unless the
applicable written and signed contract terms specifically provide otherwise.
29 Revision history
Index
A EXTI_FPR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 225
EXTI_FTSR1 . . . . . . . . . . . . . . . . . . . . . . . . . 224
ADC_AWD1TR . . . . . . . . . . . . . . . . . . . . . . .287
EXTI_IMR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 227
ADC_AWD2CR . . . . . . . . . . . . . . . . . . . . . . .293
EXTI_RPR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 225
ADC_AWD2TR . . . . . . . . . . . . . . . . . . . . . . .288
EXTI_RTSR1 . . . . . . . . . . . . . . . . . . . . . . . . . 223
ADC_AWD3CR . . . . . . . . . . . . . . . . . . . . . . .293
EXTI_SWIER1 . . . . . . . . . . . . . . . . . . . . . . . . 224
ADC_AWD3TR . . . . . . . . . . . . . . . . . . . . . . .292
ADC_CALFACT . . . . . . . . . . . . . . . . . . . . . . .294
ADC_CCR . . . . . . . . . . . . . . . . . . . . . . . . . . .294 F
ADC_CFGR1 . . . . . . . . . . . . . . . . . . . . . . . . .282 FLASH_ACR . . . . . . . . . . . . . . . . . . . . . . . . . . 67
ADC_CFGR2 . . . . . . . . . . . . . . . . . . . . . . . . .285 FLASH_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
ADC_CHSELR . . . . . . . . . . . . . . . . . . . . 289-290 FLASH_KEYR . . . . . . . . . . . . . . . . . . . . . . . . . 68
ADC_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . .280 FLASH_OPTKEYR . . . . . . . . . . . . . . . . . . . . . 68
ADC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . .292 FLASH_OPTR . . . . . . . . . . . . . . . . . . . . . . . . . 72
ADC_IER . . . . . . . . . . . . . . . . . . . . . . . . . . . .278 FLASH_PCROP1AER . . . . . . . . . . . . . . . . . . . 75
ADC_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . .276 FLASH_PCROP1ASR . . . . . . . . . . . . . . . . . . . 75
ADC_SMPR . . . . . . . . . . . . . . . . . . . . . . . . . .286 FLASH_PCROP1BER . . . . . . . . . . . . . . . . . . . 78
FLASH_PCROP1BSR . . . . . . . . . . . . . . . . . . . 77
C FLASH_SECR . . . . . . . . . . . . . . . . . . . . . . . . . 78
FLASH_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
CRC_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . .235
FLASH_WRP1AR . . . . . . . . . . . . . . . . . . . . . . 76
CRC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . .234
FLASH_WRP1BR . . . . . . . . . . . . . . . . . . . . . . 77
CRC_IDR . . . . . . . . . . . . . . . . . . . . . . . . . . . .234
CRC_INIT . . . . . . . . . . . . . . . . . . . . . . . . . . . .236
CRC_POL . . . . . . . . . . . . . . . . . . . . . . . . . . .236 G
GPIOx_AFRH . . . . . . . . . . . . . . . . . . . . . . . . 159
D GPIOx_AFRL . . . . . . . . . . . . . . . . . . . . . . . . 158
GPIOx_BRR . . . . . . . . . . . . . . . . . . . . . . . . . 159
DBG_APB_FZ1 . . . . . . . . . . . . . . . . . . . . . . .813
GPIOx_BSRR . . . . . . . . . . . . . . . . . . . . . . . . 156
DBG_APB_FZ2 . . . . . . . . . . . . . . . . . . . . . . .814
GPIOx_IDR . . . . . . . . . . . . . . . . . . . . . . . . . . 156
DBG_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . .813
GPIOx_LCKR . . . . . . . . . . . . . . . . . . . . . . . . 157
DBG_IDCODE . . . . . . . . . . . . . . . . . . . . . . . .812
GPIOx_MODER . . . . . . . . . . . . . . . . . . . . . . 154
DMA_CCRx . . . . . . . . . . . . . . . . . . . . . . . . . .193
GPIOx_ODR . . . . . . . . . . . . . . . . . . . . . . . . . 156
DMA_CMARx . . . . . . . . . . . . . . . . . . . . . . . . .197
GPIOx_OSPEEDR . . . . . . . . . . . . . . . . . . . . 155
DMA_CNDTRx . . . . . . . . . . . . . . . . . . . . . . . .195
GPIOx_OTYPER . . . . . . . . . . . . . . . . . . . . . . 154
DMA_CPARx . . . . . . . . . . . . . . . . . . . . . . . . .196
GPIOx_PUPDR . . . . . . . . . . . . . . . . . . . . . . . 155
DMA_IFCR . . . . . . . . . . . . . . . . . . . . . . . . . . .192
DMA_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . .191
DMAMUX_CFR . . . . . . . . . . . . . . . . . . . . . . .210 I
DMAMUX_CSR . . . . . . . . . . . . . . . . . . . . . . .210 I2C_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
DMAMUX_CxCR . . . . . . . . . . . . . . . . . . . . . .209 I2C_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
DMAMUX_RGCFR . . . . . . . . . . . . . . . . . . . .212 I2C_ICR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654
DMAMUX_RGSR . . . . . . . . . . . . . . . . . . . . . .212 I2C_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
DMAMUX_RGxCR . . . . . . . . . . . . . . . . . . . . .211 I2C_OAR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 648
I2C_OAR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 648
E I2C_PECR . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
I2C_RXDR . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
EXTI_EMR1 . . . . . . . . . . . . . . . . . . . . . . . . . .228
I2C_TIMEOUTR . . . . . . . . . . . . . . . . . . . . . . 650
EXTI_EXTICRx . . . . . . . . . . . . . . . . . . . . . . .226
I2C_TIMINGR . . . . . . . . . . . . . . . . . . . . . . . . 649
T TIM3_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 441
TIM3_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
TIM1_AF1 . . . . . . . . . . . . . . . . . . . . . . . . . . .390
TIM3_DCR . . . . . . . . . . . . . . . . . . . . . . . . . . 463
TIM1_AF2 . . . . . . . . . . . . . . . . . . . . . . . . . . .391
TIM3_DIER . . . . . . . . . . . . . . . . . . . . . . . . . . 447
TIM1_ARR . . . . . . . . . . . . . . . . . . . . . . . . . . .379
TIM3_DMAR . . . . . . . . . . . . . . . . . . . . . . . . . 463
TIM1_BDTR . . . . . . . . . . . . . . . . . . . . . . . . . .382
TIM3_EGR . . . . . . . . . . . . . . . . . . . . . . . . . . 450
TIM1_CCER . . . . . . . . . . . . . . . . . . . . . . . . . .376
TIM3_PSC . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
TIM1_CCMR1 . . . . . . . . . . . . . . . . . . . . 369-370
TIM3_SMCR . . . . . . . . . . . . . . . . . . . . . . . . . 444
TIM1_CCMR2 . . . . . . . . . . . . . . . . . . . . 373-374
TIM3_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
TIM1_CCMR3 . . . . . . . . . . . . . . . . . . . . . . . .388
TIM3_TISEL . . . . . . . . . . . . . . . . . . . . . . . . . 464
TIM1_CCR1 . . . . . . . . . . . . . . . . . . . . . . . . . .380
TIMx_ARR . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
TIM1_CCR2 . . . . . . . . . . . . . . . . . . . . . . . . . .381
TIMx_BDTR . . . . . . . . . . . . . . . . . . . . . . . . . . 537
TIM1_CCR3 . . . . . . . . . . . . . . . . . . . . . . . . . .381
TIMx_CCER . . . . . . . . . . . . . . . . . . . . . . . . . 532
TIM1_CCR4 . . . . . . . . . . . . . . . . . . . . . . . . . .382
TIMx_CCMR1 . . . . . . . . . . . . . . . . . . . . 529-530
TIM1_CCR5 . . . . . . . . . . . . . . . . . . . . . . . . . .389
TIMx_CCR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 536
TIM1_CCR6 . . . . . . . . . . . . . . . . . . . . . . . . . .390
TIMx_CNT . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
TIM1_CNT . . . . . . . . . . . . . . . . . . . . . . . . . . .379
TIMx_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
TIM1_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . .358
TIMx_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
TIM1_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . .359
TIMx_DCR . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
TIM1_DCR . . . . . . . . . . . . . . . . . . . . . . . . . . .386
TIMx_DIER . . . . . . . . . . . . . . . . . . . . . . . . . . 526
TIM1_DIER . . . . . . . . . . . . . . . . . . . . . . . . . .364
TIMx_DMAR . . . . . . . . . . . . . . . . . . . . . . . . . 540
TIM1_DMAR . . . . . . . . . . . . . . . . . . . . . . . . .387
TIMx_EGR . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
TIM1_EGR . . . . . . . . . . . . . . . . . . . . . . . . . . .368
TIMx_PSC . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
TIM1_PSC . . . . . . . . . . . . . . . . . . . . . . . . . . .379
TIMx_RCR . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
TIM1_RCR . . . . . . . . . . . . . . . . . . . . . . . . . . .380
TIMx_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
TIM1_SMCR . . . . . . . . . . . . . . . . . . . . . . . . .362
TIM1_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . .366
TIM1_TISEL . . . . . . . . . . . . . . . . . . . . . . . . . .392 U
TIM14_ARR . . . . . . . . . . . . . . . . . . . . . . . . . .490 USART_BRR . . . . . . . . . . . . . . . . . . . . . . . . . 726
TIM14_CCER . . . . . . . . . . . . . . . . . . . . . . . . .488 USART_CR1 . . . . . . . . . . . . . . . . . . . . . 710, 714
TIM14_CCMR1 . . . . . . . . . . . . . . . . . . . 485-486 USART_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . 717
TIM14_CCR1 . . . . . . . . . . . . . . . . . . . . . . . . .490 USART_CR3 . . . . . . . . . . . . . . . . . . . . . . . . . 721
TIM14_CNT . . . . . . . . . . . . . . . . . . . . . . . . . .489 USART_GTPR . . . . . . . . . . . . . . . . . . . . . . . 726
TIM14_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . .482 USART_ICR . . . . . . . . . . . . . . . . . . . . . . . . . 740
TIM14_DIER . . . . . . . . . . . . . . . . . . . . . . . . .483 USART_ISR . . . . . . . . . . . . . . . . . . . . . 729, 735
TIM14_EGR . . . . . . . . . . . . . . . . . . . . . . . . . .484 USART_PRESC . . . . . . . . . . . . . . . . . . . . . . 743
TIM14_PSC . . . . . . . . . . . . . . . . . . . . . . . . . .490 USART_RDR . . . . . . . . . . . . . . . . . . . . . . . . 742
TIM14_SR . . . . . . . . . . . . . . . . . . . . . . . . . . .483 USART_RQR . . . . . . . . . . . . . . . . . . . . . . . . 728
TIM14_TISEL . . . . . . . . . . . . . . . . . . . . . . . . .491 USART_RTOR . . . . . . . . . . . . . . . . . . . . . . . 727
TIM16_AF1 . . . . . . . . . . . . . . . . . . . . . . . . . .541 USART_TDR . . . . . . . . . . . . . . . . . . . . . . . . . 742
TIM16_TISEL . . . . . . . . . . . . . . . . . . . . . . . . .541
TIM17_AF1 . . . . . . . . . . . . . . . . . . . . . . . . . .542
TIM17_TISEL . . . . . . . . . . . . . . . . . . . . . . . . .542 W
TIM3_AF1 . . . . . . . . . . . . . . . . . . . . . . . . . . .464 WWDG_CFR . . . . . . . . . . . . . . . . . . . . . . . . . 559
TIM3_ARR . . . . . . . . . . . . . . . . . . . . . . . . . . .460 WWDG_CR . . . . . . . . . . . . . . . . . . . . . . . . . . 558
TIM3_CCER . . . . . . . . . . . . . . . . . . . . . . . . . .457 WWDG_SR . . . . . . . . . . . . . . . . . . . . . . . . . . 560
TIM3_CCMR1 . . . . . . . . . . . . . . . . . . . .451, 453
TIM3_CCMR2 . . . . . . . . . . . . . . . . . . . . 455-456
TIM3_CCR1 . . . . . . . . . . . . . . . . . . . . . . . . . .460
TIM3_CCR2 . . . . . . . . . . . . . . . . . . . . . . . . . .461
TIM3_CCR3 . . . . . . . . . . . . . . . . . . . . . . . . . .461
TIM3_CCR4 . . . . . . . . . . . . . . . . . . . . . . . . . .462
TIM3_CNT . . . . . . . . . . . . . . . . . . . . . . . 458-459
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgment.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. For additional information about ST trademarks, refer to www.st.com/trademarks. All other
product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.