Rm0454 Stm32g0x0 Advanced Armbased 32bit Mcus Stmicroelectronics
Rm0454 Stm32g0x0 Advanced Armbased 32bit Mcus Stmicroelectronics
Reference manual
STM32G0x0 advanced Arm®-based 32-bit MCUs
Introduction
This reference manual complements the datasheets of the STM32G0x0 microcontrollers,
providing information required for application and in particular for software development. It
pertains to the superset of feature sets available on STM32G0x0 microcontrollers.
For feature set, ordering information, and mechanical and electrical characteristics of a
particular STM32G0x0 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)
• STM32G0x0 datasheets(a)
• AN2606 application note on booting STM32 MCUs(a)
Contents
1 Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.2 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.3 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
1.4 Availability of peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
List of tables
List of figures
Figure 101. PWM output state following BRK assertion (OSSI=0) . . . . . . . . . . . . . . . . . . . . . . . . . . . 378
Figure 102. Output redirection (BRK2 request not represented) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Figure 103. Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Figure 104. 6-step generation, COM example (OSSR=1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Figure 105. Example of one pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Figure 106. Retriggerable one pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Figure 107. Example of counter operation in encoder interface mode. . . . . . . . . . . . . . . . . . . . . . . . . 385
Figure 108. Example of encoder interface mode with TI1FP1 polarity inverted. . . . . . . . . . . . . . . . . . 386
Figure 109. Measuring time interval between edges on 3 signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Figure 110. Example of Hall sensor interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Figure 111. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Figure 112. Control circuit in Gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Figure 113. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
Figure 114. Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Figure 115. General-purpose timer block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
Figure 116. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 437
Figure 117. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 437
Figure 118. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Figure 119. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Figure 120. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Figure 121. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Figure 122. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not preloaded). . . . . 440
Figure 123. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR preloaded). . . . . . . . 441
Figure 124. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Figure 125. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442
Figure 126. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
Figure 127. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
Figure 128. Counter timing diagram, Update event when repetition counter
is not used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
Figure 129. Counter timing diagram, internal clock divided by 1, TIMx_ARR=0x6 . . . . . . . . . . . . . . . 445
Figure 130. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Figure 131. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 446
Figure 132. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Figure 133. Counter timing diagram, Update event with ARPE=1 (counter underflow). . . . . . . . . . . . 447
Figure 134. Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 448
Figure 135. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 449
Figure 136. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
Figure 137. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
Figure 138. External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Figure 139. Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
Figure 140. Capture/Compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . 452
Figure 141. Capture/Compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Figure 142. Output stage of Capture/Compare channel (channel 1) . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Figure 143. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Figure 144. Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Figure 145. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
Figure 146. Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
Figure 147. Generation of 2 phase-shifted PWM signals with 50% duty cycle . . . . . . . . . . . . . . . . . . 461
Figure 148. Combined PWM mode on channels 1 and 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Figure 149. Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Figure 150. Example of one-pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Figure 151. Retriggerable one-pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Figure 199. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
Figure 200. Update rate examples depending on mode and TIMx_RCR register settings . . . . . . . . . 558
Figure 201. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 559
Figure 202. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559
Figure 203. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
Figure 204. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 561
Figure 205. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
Figure 206. Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 562
Figure 207. Output stage of capture/compare channel (channel 2 for TIM15) . . . . . . . . . . . . . . . . . . 562
Figure 208. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
Figure 209. Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
Figure 210. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
Figure 211. Combined PWM mode on channel 1 and 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
Figure 212. Complementary output with dead-time insertion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
Figure 213. Dead-time waveforms with delay greater than the negative pulse. . . . . . . . . . . . . . . . . . 569
Figure 214. Dead-time waveforms with delay greater than the positive pulse. . . . . . . . . . . . . . . . . . . 570
Figure 215. Break circuitry overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
Figure 216. Output behavior in response to a break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
Figure 217. Output redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
Figure 218. Example of one pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Figure 219. Retriggerable one pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Figure 220. Measuring time interval between edges on 2 signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
Figure 221. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
Figure 222. Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
Figure 223. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
Figure 224. IRTIM internal hardware connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
Figure 225. Independent watchdog block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
Figure 226. Watchdog block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
Figure 227. Window watchdog timing diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
Figure 228. RTC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Figure 229. TAMP block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
Figure 230. I2C1 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706
Figure 231. I2C2 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707
Figure 232. I2C bus protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709
Figure 233. Setup and hold timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
Figure 234. I2C initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
Figure 235. Data reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
Figure 236. Data transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716
Figure 237. Slave initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
Figure 238. Transfer sequence flowchart for I2C slave transmitter,
NOSTRETCH= 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
Figure 239. Transfer sequence flowchart for I2C slave transmitter,
NOSTRETCH= 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722
Figure 240. Transfer bus diagrams for I2C slave transmitter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723
Figure 241. Transfer sequence flowchart for slave receiver with NOSTRETCH=0 . . . . . . . . . . . . . . 724
Figure 242. Transfer sequence flowchart for slave receiver with NOSTRETCH=1 . . . . . . . . . . . . . . 725
Figure 243. Transfer bus diagrams for I2C slave receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
Figure 244. Master clock generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
Figure 245. Master initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
Figure 246. 10-bit address read access with HEAD10R=0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
Figure 247. 10-bit address read access with HEAD10R=1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730
Figure 248. Transfer sequence flowchart for I2C master transmitter for N≤255 bytes . . . . . . . . . . . . 731
Figure 249. Transfer sequence flowchart for I2C master transmitter for N>255 bytes . . . . . . . . . . . . 732
Figure 250. Transfer bus diagrams for I2C master transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
Figure 251. Transfer sequence flowchart for I2C master receiver for N≤255 bytes . . . . . . . . . . . . . . 735
Figure 252. Transfer sequence flowchart for I2C master receiver for N >255 bytes . . . . . . . . . . . . . . 736
Figure 253. Transfer bus diagrams for I2C master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737
Figure 254. Timeout intervals for tLOW:SEXT, tLOW:MEXT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742
Figure 255. Transfer sequence flowchart for SMBus slave transmitter N bytes + PEC. . . . . . . . . . . . 746
Figure 256. Transfer bus diagrams for SMBus slave transmitter (SBC=1) . . . . . . . . . . . . . . . . . . . . . 746
Figure 257. Transfer sequence flowchart for SMBus slave receiver N Bytes + PEC . . . . . . . . . . . . . 748
Figure 258. Bus transfer diagrams for SMBus slave receiver (SBC=1). . . . . . . . . . . . . . . . . . . . . . . . 749
Figure 259. Bus transfer diagrams for SMBus master transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
Figure 260. Bus transfer diagrams for SMBus master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 752
Figure 261. USART block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
Figure 262. Word length programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 782
Figure 263. Configurable stop bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 784
Figure 264. TC/TXE behavior when transmitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 787
Figure 265. Start bit detection when oversampling by 16 or 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 788
Figure 266. usart_ker_ck clock divider block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 791
Figure 267. Data sampling when oversampling by 16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 792
Figure 268. Data sampling when oversampling by 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793
Figure 269. Mute mode using Idle line detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
Figure 270. Mute mode using address mark detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
Figure 271. Break detection in LIN mode (11-bit break length - LBDL bit is set) . . . . . . . . . . . . . . . . . 804
Figure 272. Break detection in LIN mode vs. Framing error detection. . . . . . . . . . . . . . . . . . . . . . . . . 805
Figure 273. USART example of synchronous master transmission. . . . . . . . . . . . . . . . . . . . . . . . . . . 806
Figure 274. USART data clock timing diagram in synchronous master mode
(M bits = 00) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
Figure 275. USART data clock timing diagram in synchronous master mode
(M bits = 01) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
Figure 276. USART data clock timing diagram in synchronous slave mode
(M bits = 00) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808
Figure 277. ISO 7816-3 asynchronous protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 810
Figure 278. Parity error detection using the 1.5 stop bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812
Figure 279. IrDA SIR ENDEC block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816
Figure 280. IrDA data modulation (3/16) - Normal mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816
Figure 281. Transmission using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 818
Figure 282. Reception using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819
Figure 283. Hardware flow control between 2 USARTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819
Figure 284. RS232 RTS flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 820
Figure 285. RS232 CTS flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821
Figure 286. Wakeup event verified (wakeup event = address match, FIFO disabled) . . . . . . . . . . . . 824
Figure 287. Wakeup event not verified (wakeup event = address match,
FIFO disabled) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824
Figure 288. SPI block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 865
Figure 289. Full-duplex single master/ single slave application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866
Figure 290. Half-duplex single master/ single slave application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
Figure 291. Simplex single master/single slave application (master in transmit-only/
slave in receive-only mode) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 868
Figure 292. Master and three independent slaves. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869
Figure 293. Multi-master application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 870
Figure 294. Hardware/software slave select management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871
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.
TIM4 No No No Yes
TIM6 and TIM7 No Yes Yes Yes
TIM15 No No Yes Yes
I2C3 No No No Yes
SPI3 No No No Yes
I2S2 No No No Yes
USART3, USART4 No No Yes Yes
USART5, USART6 No No No Yes
USART3 independent
N/A N/A No Yes
clock selection
I2C2 independent clock
No No No Yes
selection
USB No No No Yes
UCPDx_STROBE bits No No Yes Yes
DMA2 No No No Yes
MCO2 No No No Yes
GPIO port E No No No Yes
Switchable I/O
Yes Yes No Yes
clamping diode
PLLQCLK No No No Yes
IOPORT
SRAM
Arm®
Cortex®-M0+ System bus Bus matrix
core AHB-to-APB
AHB bridge APB
DMA1/2
DMAMUX DMA bus
channels 1 to 12
SYSCFG,
ADC
TIM1, TIM2, TIM3, TIM4
TIM6, TIM7,
TIM14 to TIM17,
RCC CRC IWDG, WWDG,
RTC, PWR,
I2C1, I2C2, I2C3
EXTI USART1 to USART6,
SPI1/I2S1, SPI2/I2S2, SPI3
USB
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 manages the access arbitration 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 on 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.
The addressable memory space is divided into eight main blocks, of 512 Mbytes each.
Reserved space
0 x 4 0 0 2 63FF
AHB
block 6
0x4002 0000
0xC000 0000
0x4001 5BFF
block 5
APB
0xA000 0000
0x4001 0000
0x4000 A7FF
block 4
APB
0x8000 0000
0x4000 0000
block 3
0x6000 0000
0x1FFF 787F
Option bytes
0x1FFF 7800
Engineering bytes
block 2 0x1FFF 7500
0x1FFF 73FF
Peripherals OTP
0x4000 0000 0x1FFF 7000
System memory
block 1
0x1FFF 0000
RAM
0x2000 0000
(2 )
block 0 Code
Main Flash memory
0x0800 0000
0x0000 0000
(1 )
Addressable Main Flash memory /
space System memory /
RAM (3)
0x0000 0000
1. STM32G0B0xx: 0x0007 FFFF; STM32G070xx: 0x0001 FFFF; STM32G050xx, STM32G030xx: 0x0000 FFFF.
2. STM32G0B0xx: 0x0807 FFFF; STM32G070xx: 0x0801 FFFF; STM32G050xx, STM32G030xx: 0x0800 FFFF.
3. Depends on boot configuration
All the memory map areas that are not allocated to on-chip memories and peripherals are
considered as reserved. For the detailed mapping of available memory and register areas,
refer to the following tables.
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 188
0x5000 1000 - 0x5000 13FF 1 KB GPIOE Section 6.4.12 on page 188
IOPORT 0x5000 0C00 - 0x5000 0FFF 1 KB GPIOD Section 6.4.12 on page 188
0x5000 0800 - 0x5000 0BFF 1 KB GPIOC Section 6.4.12 on page 188
0x5000 0400 - 0x5000 07FF 1 KB GPIOB Section 6.4.12 on page 188
0x5000 0000 - 0x5000 03FF 1 KB GPIOA Section 6.4.12 on page 188
STM32G050xx 16 18
STM32G030xx 8 8
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. The same error
can also be linked to the BRK_IN Break input of TIM1/15/16/17, with the
SRAM_PARITY_LOCK control bit in the SYSCFG configuration register 2
(SYSCFG_CFGR2). The SRAM Parity Error flag (SRAM_PEF) is available in the SYSCFG
configuration register 2 (SYSCFG_CFGR2).
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.
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 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).
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).
When an ECC error is detected, the address of the failing double word is saved in
ADDR_ECC[16:0] bitfield of the FLASH_ECCR register. ADDR_ECC[2:0] are always
cleared. The bus-ID of the CPU accessing the address is saved in CPUID[2:0].
While ECCC or ECCD is set, FLASH_ECCR is not updated if a new ECC error occurs.
FLASH_ECCR is updated only when ECC flags are cleared.
Note: For a virgin data: 0xFF FFFF FFFF FFFF FFFF, one error is detected and corrected, but two
errors detection is not supported.
When an ECC error is reported, a new read at the failing address may not generate an ECC
error if the data is still present in the current buffer, even if ECCC and ECCD are cleared. If
this is not the desired behavior, the user must reset the cache.
Table 10. Number of wait states according to Flash memory clock (HCLK) frequency
0 WS (1 HCLK cycles) ≤ 24 ≤8
1 WS (2 HCLK cycles) ≤ 48 ≤ 16
2 WS (3 HCLK cycles) ≤ 64 -
After power reset, the HCLK clock frequency is 16 MHz in Range 1 and 0 wait state (WS) is
configured in the FLASH_ACR register.
When wakeup from Standby, the HCLK clock frequency is 16 MHz in Range 1 and 0 wait
state (WS) is configured in the FLASH_ACR register.
When changing the Flash memory clock frequency or Range, the following software
sequences must be applied in order to tune the number of wait states needed to access the
Flash memory:
RCC_CFGR register, or/and the AHB prescaler value (HPREF bit), of the RCC_CFGR
register.
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+.
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 EOP flag of 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 BSY1 bit is set. The internal oscillator HSI16
(16 MHz) is enabled automatically when PG bit is set, and disabled automatically when PG
bit is cleared, except if the HSI16 is previously enabled with HSION in RCC_CR register.
ECC is calculated from the double word to program.
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 32 double words to program a row (256 bytes).
6. Wait until the BSY1 bit of the FLASH status register (FLASH_SR) is cleared.
7. Check that EOP flag of 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 on going, 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 internal oscillator HSI16 (16 MHz) is enabled automatically when FSTPG bit is
set, and disabled automatically when FSTPG bit is cleared, except if the HSI16 is previously
enabled with HSION in RCC_CR register.
The 32 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 32 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).
• 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.
– PGSERR is set also if PROGERR, SIZERR, PGAERR, WRPERR, MISSERR,
FASTERR or PGSERR is set due to a previous programming error.
1. Check that the busy flag of the bank to erase (BSY1 or BSY2) in the FLASH status
register (FLASH_SR) is low (no erase/programming in progress).
2. Set up the page erase, by setting the PER, PSB, and BKER bitfileds of the FLASH
control register (FLASH_CR).
3. Trigger the erase operation by setting the STRT bit of the FLASH control register
(FLASH_CR). This sets the corresponding busy flag BSY1 or BSY2.
The erase operation is completed when the corresponding busy flag (BSY1 or BSY2) is
back to low. The EOP interrupt can be used to indicate that event to the application
software.
The organization of these bytes in the information block is shown in Table 12 (superset for
single-bank and dual-bank devices). The option bytes can be read from the Flash memory
locations listed in Table 12 or from the Option byte registers:
• FLASH option register (FLASH_OPTR)
• FLASH WRP area A address register (FLASH_WRP1AR)
• FLASH WRP area B address register (FLASH_WRP1BR)
• FLASH WRP2 area A address register (FLASH_WRP2AR)
• FLASH WRP2 area B address register (FLASH_WRP2BR)
10
11
9
8
7
6
5
4
3
2
1
0
RAM_PARITY_CHECK
nSWAP_BANK
nRST_STDBY
IWDG_STOP
DUAL_BANK
IWDG_STBY
nBOOT_SEL
nRST_STOP
WWDG_SW
IWDG_SW
Reserved
Reserved
Reserved
Reserved
nBOOT0
nBOOT1
0x1FFF7800 RDP
0x1FFF7808
- Reserved
0x1FFF7840
0x1FFF7818 Reserved WRP1A_END Reserved WRP1A_STRT
0x1FFF7820 Reserved WRP1B_END Reserved WRP1B_STRT
0x1FFF7848 Reserved WRP2A_END Reserved WRP2A_STRT
0x1FFF7850 Reserved WRP2B_END Reserved WRP2B_STRT
1. The upper 32-bits of the double-word address contain the inverted data from the lower 32 bits.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RAM_P
IWGD
n n nBOOT ARITY DUAL_ nSWAP WWDG IWDG IWDG
Res. Res. Res. Res. Res. Res. _STDB
BOOT0 BOOT1 _SEL _CHEC BANK _BANK _SW _STOP _SW
Y
K
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
nRST_ nRST_
Res. Res. Res. Res. Res. Res. RDP[7:0]
STDBY STOP
r r r r r r r r r r
Bit 13 nRST_STOP
0: Reset generated when entering the Stop mode
1: No reset generated when entering the Stop mode
Bits 12:8 Reserved, must be kept at reset value.
Bits 7:0 RDP[7:0]: Read protection level
0xAA: Level 0, read protection not active
0xCC: Level 2, chip read protection active
Others: Level 1, memories read protection active
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. WRP1A_END[6: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. Res. Res. Res. Res. Res. Res. Res. Res. WRP1A_STRT[6:0]
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. WRP1B_END[6: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. Res. Res. Res. Res. Res. Res. Res. Res. WRP1B_STRT[6:0]
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. WRP2A_END[6: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. Res. Res. Res. Res. Res. Res. Res. Res. WRP2A_STRT[6:0]
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. WRP2B_END[6: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. Res. Res. Res. Res. Res. Res. Res. Res. WRP2B_STRT[6:0]
r r r r r r r
loaded after reset. Those mismatch values force a secure configuration that might
permanently lock the device. To prevent this, only program option bytes in a safe
environment – safe supply, no pending watchdog, and clean reset line.
Flash memory, the option bytes, the backup registers (TAMP_BKPxR in TAMP) and the
SRAM.
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 13.
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 and the backup registers 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.
Level 1
RDP ≠ 0xAA ≠ 0xCC
RDP = 0xAA
RDP = 0xCC RDP ≠ 0xCC ≠ 0xAA
Level 2 Level 0
RDP = 0xCC RDP = 0xAA
RDP = 0xCC
MSv33468V3
Table 14. Access status versus protection level and execution modes
Debug/ BootFromRam/
Protection User execution (BootFromFlash)
Area BootFromLoader
level
Read Write Erase Read Write Erase
Table 14. Access status versus protection level and execution modes (continued)
Debug/ BootFromRam/
Protection User execution (BootFromFlash)
Area BootFromLoader
level
Read Write Erase Read Write Erase
1 Yes Yes(3) Yes Yes Yes(3) Yes
Option bytes (1)
2 Yes No No N/A N/A(1) N/A(1)
Backup 1 Yes Yes N/A No No No(4)
registers 2 Yes Yes N/A N/A(1) N/A(1) N/A(1)
1 Yes Yes N/A No No N/A
OTP (1)
2 Yes Yes N/A N/A N/A(1) N/A(1)
1. When the protection Level 2 is active, the Debug port, the boot from RAM and the boot from System memory are disabled.
2. The System memory is only read-accessible, whatever the protection level (0, 1 or 2) and execution mode.
3. The Flash Main memory is erased when the RDP option byte is programmed with all level of protections disabled (0xAA).
4. The backup registers are erased when RDP changes from Level 1 to Level 0.
Note: To validate the WRP options, the option bytes must be reloaded by setting the
OBL_LAUNCH bit in Flash memory control 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. EMPTY
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 BSY2 BSY1
r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OPTV FAST MISS PGS SIZ PGA WRP PROG OP
Res. Res. Res. Res. Res. Res. EOP
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OPT OBL_ OPT
LOCK Res. Res. Res. ERRIE EOPIE Res. Res. Res. Res. Res. FSTPG STRT
LOCK LAUNCH STRT
rs rs rc_w1 rw rw rw rs rs
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MER2 Res. BKER PNB[9:0] MER1 PER PG
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. WRP1A_END[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. Res. Res. Res. Res. Res. Res. Res. Res. WRP1A_STRT[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
Res. Res. Res. Res. Res. Res. Res. Res. Res. WRP1B_END[6: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. Res. Res. Res. Res. Res. WRP1B_STRT[6: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. WRP2A_END[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. Res. Res. Res. Res. Res. Res. Res. Res. WRP2A_STRT[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
Res. Res. Res. Res. Res. Res. Res. Res. Res. WRP2B_END[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. Res. Res. Res. Res. Res. Res. Res. Res. WRP2B_STRT[6:0]
rw rw rw rw rw rw rw
0x07F
0x02B
0x04C
0x02C
0x00C
Offset
0x034 -
0x024 -
3.7.13
RM0454
KEYR
FLASH_
FLASH_
FLASH_
FLASH_
Reserved
Reserved
Reserved
WRP2BR
WRP2AR
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
FLASH_KEYR
FLASH_OPTR
FLASH_ECCR
0
1
0
0
Res. Res. Res. Res. Res. Res. Res. ECCD LOCK Res. Res. Res. 31
0
1
0
0
Res. Res. Res. Res. Res. Res. Res. ECCC OPTLOCK Res. Res. Res. 30
0
0
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. 28
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. OBL_LAUNCH Res. Res. Res. 27
0
0
X
Res. Res. Res. Res. Res. Res. .nBOOT0 Res. Res. Res. Res. Res. 26
0
0
0
X
Res. Res. Res. Res. Res. Res. nBOOT1 Res. ERRIE Res. Res. Res. 25
FLASH register map
0
0
0
0
X
Res. Res. Res. Res. Res. Res. nBOOT_SEL ECCCIE EOPIE Res. Res. Res. 24
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
0
0
X
X
X
X
X
Res. Res. RAM_PARITY_CHECK Res. Res. Res. 0 Res. Res. 22
0
X
X
X
X
X
Res. Res. DUAL_BANK Res. Res. Res. Res. Res. 21
0
0
0
X
X
X
X
Res. Res. Res. SYSF_ECC Res. Res. Res. Res. 20
0
0
X
X
X
X
X
Res. Res. WWDG_SW Res. Res. Res. Res. Res. 19
0
0
0
0
X
X
X
X
X
Res. Res. IWDG_STBY Res. FSTPG CFGBSY Res. Res. 18
0
0
0
0
X
X
X
X
X
RM0454 Rev 5
Res. Res. IWDG_STOP Res. OPTSTRT BSY2 Res. Res. 17
WRP2B_END[6:0]
WRP2A_END[6:0]
WRP1B_END[6:0]
WRP1A_END[6:0]
0
0
0
0
X
X
X
X
X
X
Res. Res. IWDG_SW Res. STRT BSY1 Res. EMPTY 16
0
0
0
X
X
Res. Res. Res. Res. Res. Res. Res. Res. MER2 OPTVERR Res. Res. 15
KEYR[31:0]
0
0
X
Res. Res. Res. Res. Res. Res. nRST_STDBY Res. Res. Res. Res. Res. 14
OPTKEY[31:0]
0
0
0
0
X
Res. Res. Res. Res. Res. Res. nRST_STOP BKER Res. Res. Res. 13
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 12
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. ICRST 11
Table 17. FLASH register map and reset values
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 10
0
0
1
0
0
0
Res. Res. Res. Res. Res. Res. Res. FASTERR Res. ICEN 9
0
0
0
Res. Res. Res. Res. Res. Res. Res. MISERR Res. PRFTEN 8
0
0
0
0
0
X
Res. Res. Res. Res. Res. Res. PGSERR Res. Res. 7
PNB[9:0]
0
0
0
0
X
X
X
X
X
Res. Res. SIZERR Res. Res. 6
0
0
0
0
0
X
X
X
X
X
Res. Res. PGAERR Res. Res. 5
ADDR_ECC[13:0]
0
0
0
0
0
X
X
X
X
X
Res. Res. WRPERR Res. Res. 4
0
0
0
0
0
X
X
X
X
X
Res. Res. PROGERR Res. Res. 3
RDP[7:0]
0
0
0
0
X
X
X
X
X
Res. Res. MER1 Res. Res. 2
0
0
0
0
0
0
X
X
X
X
Res. Res. X PER OPERR Res. 1
[2:0]
WRP2B_STRT[6:0]
WRP2A_STRT[6:0]
WRP1B_STRT[6:0]
WRP1A_STRT[6:0]
0
0
0
0
0
0
X
X
X
X
X
Res. Res. PG EOP Res. 0
LATENCY
Embedded Flash memory (FLASH)
85/989
85
Power control (PWR) RM0454
VDDA domain
VREF+
VREF+
VDDA A/D converter
VSSA
VDDIO1 domain
VDDIO1
I/O ring
VDD domain
Reset block
Temp. sensor VCORE domain
PLL, HSI
Core
VSS Standby circuitry
VSS/VSSA (Wakeup, IWDG) SRAM
VDD VCORE Digital
VDD/VDDA Voltage
regulator peripherals
RTC domain
BKP registers
VBAT
LSE crystal 32.768 kHz osc
RCC BDCR register
RTC and TAMP
MSv47920V1
If no external battery is used in the user application, it is recommended to connect VBAT pin
externally to VDD/VDDA pin with a 100 nF external ceramic decoupling capacitor.
When the RTC domain is supplied by VDD (power switch connected to VDD), all the related
pin functions are available:
When the RTC domain is supplied by VBAT (power switch connected to VBAT because VDD
is not present), only the following functions are available:
• PC13, PC14 and PC15 can be controlled only by RTC, TAMP or LSE (refer to
Section 23.3: RTC functional description)
• RTC_OUT1 function on PC13
• RTC_TS function on PC13 or PA4
• TAMP_IN1 function on PC13 or PA4 and TAMP_IN2 function on PA0
Note: Due to the fact that the power switch can transfer only a limited amount of current (3 mA),
the use of GPIO PC13 to PC15 in output mode is restricted: the speed has to be limited to
2 MHz with a maximum load of 30 pF and these I/Os must not be used as a current source
(e.g. to drive a LED).
VDD
VPOR
VPDR
t
tRSTTEMPO
Reset
POR threshold
PDR threshold
MSv47933V1
Standby mode
Sleep mode
MSv47934V1
Wakeup capability
Wakeup capability
CPU Y - Y - - - - - -
Flash memory Y Y O(2) O(2) O(2) - - - -
(3) Y(3)
SRAM Y Y Y Y - - - -
Backup Registers Y Y Y Y Y - Y - Y
DMA1/2 O O O O - - - - -
Low-power sleep
Low-power run
Wakeup capability
Wakeup capability
Function Run Sleep VBAT
- -
(4)
HSI16 O O O O - - - -
HSE O O O O - - - - -
LSI O O O O O - O - -
LSE O O O O O - O - O
PLL O O - - - - - - -
IWDG O O O O O O O O -
WWDG O O O O - - - - -
SysTick timer O O O O - - - - -
CRC O O O O - - - - -
USB O O - - - - - - -
up to
(8) 5
GPIOs O O O O O O -
pins
(9)
1. Legend: Y = Yes (Enable). O = Optional (Disable by default. Can be enabled by software). - = Not available.
2. The Flash memory can be configured in power-down mode. By default, it is not in power-down mode.
Debug mode
By default, the debug connection is lost if the user application puts the MCU in Stop 0,
Stop1, or Standby mode while the debug features are used. This is due to the fact that the
Cortex®-M0+ core is no longer clocked.
However, by setting some configuration bits in the DBGMCU_CR register, the software can
be debugged even when using the low-power modes extensively. For more details, refer to
Section 29.9.1: Debug support for low-power modes.
In Stop 0 mode, the following features can be selected by programming individual control
bits:
• Independent watchdog (IWDG): the IWDG is started by writing to its Key register or by
hardware option. Once started, it cannot be stopped except upon a reset. See
Section 21.3: IWDG functional description.
• real-time clock (RTC): this is configured by the RTCEN bit in the RTC domain control
register (RCC_BDCR).
• Internal RC oscillator (LSI): this is configured by the LSION bit in the Control/status
register (RCC_CSR).
• External 32.768 kHz oscillator (LSE): this is configured by the LSEON bit in the RTC
domain control register (RCC_BDCR).
Several peripherals can be used in Stop 0 mode and can add consumption if they are
enabled and clocked by LSI or LSE, or when they request the HSI16 clock: USART1,
USART2, and I2C1.
The ADC and the temperature sensor can consume power during the Stop 0 mode, unless
they are disabled before entering this mode.
In Standby mode, the following features can be selected by programming individual control
bits:
• Independent watchdog (IWDG): the IWDG is started by writing to its Key register or by
hardware option. Once started it cannot be stopped except by a reset. See
Section 21.3: IWDG functional description.
• Real-time clock (RTC) and tamper (TAMP): this is configured by the RTCEN bit in the
RTC domain control register (RCC_BDCR)
• Internal RC oscillator (LSI): this is configured by the LSION bit in the Control/status
register (RCC_CSR).
• External 32.768 kHz oscillator (LSE): this is configured by the LSEON bit in the RTC
domain control register (RCC_BDCR)
the three alternative RTC clock sources can be selected by programming the RTCSEL[1:0]
bits in the RTC domain control register (RCC_BDCR):
• Low-power 32.768 kHz external crystal oscillator (LSE OSC)
This clock source provides a precise time base with very low-power consumption.
• Low-power internal RC Oscillator (LSI)
This clock source has the advantage of saving the cost of the 32.768 kHz crystal. This
internal RC Oscillator is designed to add minimum power consumption.
To wake up from Stop mode with an RTC alarm or an RTC wakeup event, it is necessary to:
• Configure the EXTI Line 19 to be sensitive to rising edge.
• Configure the RTC to generate the wakeup event.
To wake up from Standby mode, there is no need to configure the EXTI line 19.
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_ FPD_
Res. LPR Res. Res. Res. VOS[1:0] DBP Res. Res. LPMS[2:0]
LPSLP LPRUN STOP
rw rw rw rw rw rw rw rw rw rw
Bit 5 FPD_LPSLP: Flash memory powered down during Low-power sleep mode
This bit determines whether the Flash memory is put in power-down mode or remains in idle
mode when the device enters Low-power sleep mode.
0: Flash memory idle
1: Flash memory powered down
Bit 4 FPD_LPRUN: Flash memory powered down during Low-power run mode
This bit determines whether the Flash memory is put in power-down mode or remains in idle
mode when the device enters Low-power run mode. The Flash memory can be put in power-
down mode only when the user code is executed from SRAM.
0: Flash memory idle
1: Flash memory powered down
Bit 3 FPD_STOP: Flash memory powered down during Stop mode
This bit determines whether the Flash memory is put in power-down mode or remains in idle
mode when the device enters Stop mode.
0: Flash memory idle
1: Flash memory powered down
Bits 2:0 LPMS[2:0]: Low-power mode selection
These bits select the low-power mode entered when CPU enters deepsleep mode.
000: Stop 0 mode
001: Stop 1 mode
010: Reserved
011: Standby mode
Note: 1xx: 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
Res. Res. Res. Res. Res. USV Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
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 EWUP
EIWUL Res. Res. Res. Res. APC Res. Res. Res. Res.
6 5 4 3 2 1
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. VBRS VBE Res. Res. WP6 WP5 WP4 WP3 WP2 WP1
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
WUFI Res. Res. Res. Res. Res. Res. SBF Res. Res. WUF6 WUF5 WUF4 WUF3 WUF2 WUF1
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
REGLP REGLP FLASH
Res. Res. Res. Res. Res. VOSF Res. Res. Res. Res. Res. Res. Res.
F S _RDY
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
CWUF CWUF CWUF CWUF CWUF CWUF
Res. Res. Res. Res. Res. Res. Res. CSBF Res. Res.
6 5 4 3 2 1
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
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 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 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
Reset value: 0x0000 0000. This register is not reset when exiting Standby modes and with
PWRRST bit in the APB peripheral reset register 1 (RCC_APBRSTR1).
Access: Additional APB cycles are needed to access this register vs. a standard APB
access (3 for a write and 2 for a read).
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. 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
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. 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
0x02C
0x00C
Offset
4.4.20
RM0454
PWR_SR2
PWR_SR1
PWR_CR4
PWR_CR3
PWR_CR2
PWR_CR1
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
PWR_PDCRB
PWR_PUCRB
PWR_PDCRA
PWR_PUCRA
PWR_PDCRC
PWR_PUCRC
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. 30
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. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
PWR register map
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. 25
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. 23
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. 21
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. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0454 Rev 5
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. 16
0
0
0
0
0
0
0
1
PD15 PU15 PD15 PU15 PD15 PU15 Res. Res. WUFI Res. EIWUL Res. Res. 15
0
0
0
0
0
0
0
PD14 PU14 PD14 PU14 PD14 PU14 Res. Res. Res. Res. Res. Res. LPR 14
0
0
0
0
0
0
PD13 PU13 PD13 PU13 PD13 PU13 Res. Res. Res. Res. Res. Res. Res. 13
0
0
0
0
0
0
PD12 PU12 PD12 PU12 PD12 PU12 Res. Res. Res. Res. Res. Res. Res. 12
0
0
0
0
0
0
PD11 PU11 PD11 PU11 PD11 PU11 Res. Res. Res. Res. Res. Res. Res.
Table 26. PWR register map and reset values
11
0
0
0
0
0
0
0
0
0
0
PD10 PU10 PD10 PU10 PD10 PU10 Res. VOSF Res. Res. APC USV 10
[1:0]
VOS
0
0
0
0
0
0
0
0
1
PD9 PU9 PD9 PU9 PD9 PU9 Res. REGLPF Res. VBRS Res. Res. 9
0
0
0
0
0
0
0
0
0
0
0
PD8 PU8 PD8 PU8 PD8 PU8 CSBF REGLPS SBF VBE Res. Res. DBP 8
0
0
0
0
0
0
PD7 PU7 PD7 PU7 PD7 PU7 Res. 0 FLASH_RDY Res. Res. Res. Res. Res. 7
0
0
0
0
0
0
PD6 PU6 PD6 PU6 PD6 PU6 Res. Res. Res. Res. Res. Res. Res. 6
0
0
0
0
0
0
0
0
0
0
0
PD5 PU5 PD5 PU5 PD5 PU5 CWUF6 Res. WUF6 WP6 EWUP6 Res. FPD_LPSLP 5
0
0
0
0
0
0
0
0
0
0
0
PD4 PU4 PD4 PU4 PD4 PU4 CWUF5 Res. WUF5 WP5 EWUP5 Res. FPD_LPRUN 4
0
0
0
0
0
0
0
0
0
0
1
PD3 PU3 PD3 PU3 PD3 PU3 CWUF4 Res. WUF4 WP4 EWUP4 Res. FPD_STOP 3
0
0
0
0
0
0
0
PD2 PU2 PD2 PU2 PD2 PU2 Res. Res. Res. Res. Res. Res. 2
0
0
0
0
0
0
0
0
0
0
0
PD1 PU1 PD1 PU1 PD1 PU1 CWUF2 Res. WUF2 WP2 EWUP2 Res. 1
[2:0]
LPMS
0
0
0
0
0
0
0
0
0
0
0
PD0 PU0 PD0 PU0 PD0 PU0 CWUF1 Res. WUF1 WP1 EWUP1 Res. 0
Power control (PWR)
117/989
118
0x048
0x044
0x040
0x038
0x04C
0x03C
Offset
118/989
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
PWR_PDCRF
PWR_PUCRF
PWR_PDCRE
PWR_PUCRE
PWR_PDCRD
PWR_PUCRD
Power control (PWR)
RM0454 Rev 5
Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. 16
0
0
0
0
0
0
0
0
0
0
5.1 Reset
There are three types of reset, defined as system reset, power reset and RTC domain reset.
VDD
RPU
System reset
External
reset Filter
NRST WWDG reset
IWDG reset
Pulse Software reset
generator
(min 20 μs) Low-power manager reset
Option byte loader reset
POR
MSv40966V2
Caution: Upon power reset, 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 trstempo.
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:
• HSI16 RC - a high-speed fully-integrated RC oscillator producing HSI16 clock (about
16 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 or/and multiplying the primary clocks:
• HSISYS - a clock derived from HSI16 through division by a factor programmable from 1
to 128
• PLLPCLK, PLLQCLK and PLLRCLK - clocks output from the PLL block
• SYSCLK - a clock obtained through selecting one of LSE, LSI, HSE, PLLRCLK, and
HSISYS clocks
• 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, HSI16 and HCLK clocks.
The HSISYS is used as system clock source after startup from reset, with the division by 1
(producing HSI16 frequency).
The HCLK clock and PCLK clock are used for clocking the AHB and the APB domains,
respectively. Their maximum allowed frequency is 64 MHz.
The peripherals are clocked with the clocks from the bus they are attached to (HCLK for
AHB, PCLK for APB) except:
• TIMx, with these clock sources to select from:
– TIMPCLK (selectable for all timers) running at PCLK frequency if the APB
prescaler division factor is set to 1, or at twice the PCLK frequency otherwise
• ADC, with these clock sources to select from:
– SYSCLK (system clock)
– HSI16
– PLLPCLK
• USARTx, with these clock sources to select from:
– SYSCLK (system clock)
– HSI16
– LSE
– PCLK (APB clock)
The wakeup from Stop mode is supported only when the clock is HSI16 or LSE.
• I2Cx, with these clock sources to select from:
– SYSCLK (system clock)
– HSI16
– PCLK (APB clock)
The wakeup from Stop mode is supported only when the clock is HSI16.
• I2Sx, with these clock sources to select from:
– SYSCLK (system clock)
– HSI16
– PLLPCLK
– I2S_CKIN pin
LSE to PWR
LSI
to AHB bus, core, memory and DMA
MCO2(2) SYSCLK
/ 1...1024
HSE AHB HCLK FCLK Cortex free-running clock
MCO HSI16 PRESC
(2)
/ 1...1024 / 1,2,..512
PLLPCLK(2) to Cortex system timer
HCLK8
PLLQCLK(2) /8
LSE
PLLRCLK
LSI APB PCLK to APB peripherals
PRESC
HSE SYSCLK / 1,2,4,8,16
OSC_OUT HSE OSC PLLRCLK
4-48 MHz
HSE PCLK to USART2(1)
HSISYS LSE to USART1
OSC_IN Clock HSI16
detector SYSCLK to USART3(2)
HSISYS
/1…128
PCLK
HSI RC HSI16 to I2C1
HSI16
16 MHz SYSCLK to I2C2(2)
PLL
HSE x1, x2
fPLLIN to TIM1/3/6/7/14/16/17
VCO x /M HSI16 TIMPCLK to TIM15(1)
fVCO /N to TIM4(2)
/ R fPLLR PLLRCLK
PLLQCLK(2) SYSCLK
/ Q fPLLQ HSI16 to ADC
/P
fPLLP PLLPCLK PLLPCLK
SYSCLK
PLLPCLK
to I2S1
HSI16
I2S_CKIN I2S_CKIN to I2S2(2)
OSC_IN OSC_OUT
External clock
GPIO
(OSC_EN as AF)
External
source
OSC_IN OSC_OUT
Crystal/Ceramic
resonators
CL1 CL2
Load
capacitors
Calibration
RC oscillator frequencies can vary from one chip to another due to manufacturing process
variations.
After reset, the factory calibration value is loaded in the HSICAL[7:0] bits in the Internal
clock source calibration register (RCC_ICSCR).
Voltage or temperature variations in the application may affect the HSI16 frequency of the
RC oscillator. It can be trimmed using the HSITRIM[6:0] bits in the Internal clock source
calibration register (RCC_ICSCR).
For more details on how to measure the HSI16 frequency variation, refer to Section 5.2.15:
Internal/external clock measurement with TIM14/TIM16/TIM17.
The HSIRDY flag in the Clock control register (RCC_CR) indicates if the HSI16 RC is stable
or not. At startup, the HSI16 RC output clock is not released until this bit is set by hardware.
The HSI16 RC can be switched on and off using the HSION bit in the Clock control register
(RCC_CR).
The HSI16 signal can also be used as a backup source (auxiliary clock) if the HSE crystal
oscillator fails. Refer to Section 5.2.8: Clock security system (CSS) on page 129.
5.2.3 PLL
The internal PLL multiplies the frequency of HSI16- or HSE-based clock fetched on its input,
to produce three independent clock outputs. The allowed input frequency range is from 2.66
to 16 MHz. The dedicated divider PLLM with division factor programmable from one to eight
allows setting a frequency within the valid PLL input range. Refer to Figure 8: Clock tree and
PLL configuration register (RCC_PLLCFGR).
The PLL configuration (selection of the input clock and multiplication factor) must be done
before enabling the PLL. Once the PLL is enabled, these parameters cannot be changed.
To modify the PLL configuration, proceed as follows:
1. Disable the PLL by setting PLLON to 0 in Clock control register (RCC_CR).
2. Wait until PLLRDY is cleared. The PLL is now fully stopped.
3. Change the desired parameter.
4. Enable the PLL again by setting PLLON to 1.
5. Enable the desired PLL outputs by configuring PLLPEN, PLLQEN, and PLLREN in PLL
configuration register (RCC_PLLCFGR).
An interrupt can be generated when the PLL is ready, if enabled in the Clock interrupt
enable register (RCC_CIER).
The enable bit of each PLL output clock (PLLPEN, PLLQEN, and PLLREN) can be modified
at any time without stopping the PLL. PLLREN cannot be cleared if PLLRCLK is used as
system clock.
HSI16 16 16
HSE 48 16
PLLPCLK 122(1) 40(2)
The software must then disable the LSECSSON bit, stop the defective 32 kHz oscillator (by
clearing LSEON), and change the RTC clock source (no clock, LSI or HSE, with RTCSEL),
or take any appropriate action to secure the application.
The frequency of the LSE oscillator must exceed 30 kHz to avoid false positive detections.
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
RTC domain control register (RCC_BDCR). The configuration registers of the
corresponding GPIO port must be programmed in alternate function mode.
This function remains available in Stop 0, Stop 1 and Standby modes.
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)
The last option is controlled by the MCOSEL[3:0] field of the clock configuration register
(RCC_CFGR). All clock sources can be selected for the MCO pin.
TIM 14
TI1SEL[3:0]
GPIO
RTCCLK
TI1
HSE / 32
MCO
MSv42174V1
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
• RTC wakeup interrupt signal
The last option requires to enable the RTC interrupt.
TIM 16
TI1SEL[3:0]
GPIO
LSI
TI1
LSE
RTC wakeup interrupt
MSv42175V1
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 divided by 32
• MCO (MCU clock output)
The last option is controlled by the MCOSEL[3:0] field of the clock configuration register
(RCC_CFGR). All clock sources can be selected for the MCO pin.
TIM 17
TI1SEL[3:0]
GPIO
HSE / 32 TI1
MCO
MSv42176V1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLL CSS HSE HSE HSE
Res. Res. Res. Res. Res. Res. PLLON Res. Res. Res. Res.
RDY ON BYP RDY ON
r rw 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 Res. Res. Res. Res. Res. Res. Res. Res.
RDY KERON
rw rw rw r 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
1. Only significant on devices integrating the corresponding output, otherwise reserved. Refer to Section 1.4: Availability of
peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLL PLL PLL
PLLR[2:0]
REN PLLQ[2:0](1) QEN
Res. Res. PLLP[4:0]
PEN
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. PLLN[7:0] Res. PLLM[2:0] Res. Res. PLLSRC[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw
1. Only significant on devices integrating PLLQCLK, otherwise reserved. Refer to Section 1.4: Availability of peripherals.
Bits 31:29 PLLR[2:0]: PLL VCO division factor R for PLLRCLK clock output
This bitfield is controlled by software. It sets the PLL VCO division factor R as follows:
000: Reserved
001: 2
010: 3
011: 4
100: 5
101: 6
110: 7
111: 8
The bitfield can be written only when the PLL is disabled.
The PLLRCLK clock can be selected as system clock.
Caution: The software must set this bitfield so as not to exceed 64 MHz on this clock.
Bit 28 PLLREN: PLLRCLK clock output enable
This bit is controlled by software to enable/disable the PLLRCLK clock output of the PLL:
0: Disable
1: Enable
This bit cannot be written when PLLRCLK output of the PLL is selected for system clock.
Disabling the PLLRCLK clock output, when not used, allows saving power.
Bits 27:25 PLLQ[2:0]: PLL VCO division factor Q for PLLQCLK clock output(1)
This bitfield is controlled by software. It sets the PLL VCO division factor Q as follows:
000: Reserved
001: 2
010: 3
011: 4
100: 5
101: 6
110: 7
111: 8
The bitfield can be written only when the PLL is disabled.
Caution: The software must set this bitfield so as not to exceed 128 MHz on this clock.
Bit 24 PLLQEN: PLLQCLK clock output enable(1)
This bit is controlled by software to enable/disable the PLLQCLK clock output of the PLL:
0: Disable
1: Enable
Disabling the PLLQCLK clock output, when not used, allows saving power.
Bits 23:22 Reserved, must be kept at reset value.
Bits 21:17 PLLP[4:0]: PLL VCO division factor P for PLLPCLK clock output
This bitfield is controlled by software. It sets the PLL VCO division factor P as follows:
00000: Reserved
00001: 2
...
11111: 32
The bitfield can be written only when the PLL is disabled.
Caution: The software must set this bitfield so as not to exceed 122 MHz on this clock.
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
PLL HSE HSI LSE LSI
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RDYIE RDYIE RDYIE RDYIE RDYIE
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
LSE PLL HSE HSI LSE LSI
Res. Res. Res. Res. Res. Res. CSSF Res. Res. Res.
CSSF RDYF RDYF RDYF RDYF RDYF
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
LSE PLL HSE HSI LSE LSI
Res. Res. Res. Res. Res. Res. CSSC Res. Res. Res.
CSSC RDYC RDYC RDYC RDYC RDYC
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
GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST RST(1) RST RST RST RST
rw rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
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
rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PWR DBG I2C3 I2C2 I2C1 USART4 USART3 USART2
Res. Res. Res. Res. Res. Res. Res. Res.
RST RST RST(1) RST RST RST(1) RST(1) RST
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SPI3 SPI2 USB USART6 USART5 TIM7 TIM6 TIM4 TIM3
Res. Res. Res. Res. Res. Res. Res.
RST(1) RST RST(1) RST(1) RST(1) RST(1) RST(1) RST(1) RST
rw rw rw rw rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
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
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
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
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
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
GPIOE
GPIOF SMEN GPIOD GPIOC GPIOB GPIOA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
SMEN (1) SMEN SMEN SMEN SMEN
rw rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved with zero reset value. Refer to
Section 1.4: Availability of peripherals.
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
DMA2
CRC SRAM FLASH SMEN DMA1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
SMEN SMEN SMEN (1) SMEN
rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved with zero reset value. Refer to
Section 1.4: Availability of peripherals.
Bit 8 FLASHSMEN: Flash memory interface clock enable during Sleep mode
Set and cleared by software.
0: Disable
1: Enable
This bit can be activated only when the Flash memory is in power down mode.
Bits 7:2 Reserved, must be kept at reset value.
Bit 1 DMA2SMEN: DMA2 and DMAMUX clock enable during Sleep mode(1)
Set and cleared by software.
0: Disable
1: Enable
Clock to DMAMUX during Sleep mode is enabled as long as the clock in Sleep mode is
enabled to at least one DMA peripheral.
Bit 0 DMA1SMEN: DMA1 and DMAMUX clock enable during Sleep mode
Set and cleared by software.
0: Disable
1: Enable
Clock to DMAMUX during Sleep mode is enabled as long as the clock in Sleep mode is
enabled to at least one DMA peripheral.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
I2C3 USART4 USART3
PWR DBG SMEN I2C2 I2C1 SMEN SMEN USART2
Res. Res. Res. Res. Res. Res. Res. Res.
SMEN SMEN (1) SMEN SMEN (1) (1) SMEN
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USB
SPI3 RTC USART6 USART5 TIM7 TIM6 TIM4
SPI2 SME Res. WWDG TIM3
SMEN APB SMEN SMEN Res. Res. SMEN SMEN Res. SMEN Res.
(1) SMEN N SMEN (1) (1) (1) (1) (1) SMEN
(1) SMEN
rw rw rw rw rw rw rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved with zero reset value. Refer to
Section 1.4: Availability of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw 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
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved with zero reset value. Refer to
Section 1.4: Availability of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIM15 TIM1
ADCSEL[1:0] Res. Res. Res. Res. Res. Res. Res. Res.
SEL(1) SEL
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART3SEL USART2SEL USART1SEL
I2C2I2S1SEL[1:0] I2C1SEL[1:0] Res. Res. Res. Res.
[1:0](1) [1:0](1) [1:0]
rw rw rw rw rw rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral supporting independent clock selection (or supporting
the corresponding function), otherwise reserved. Refer to Section 1.4: Availability of peripherals and Section 26.4: USART
implementation.
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. USBSEL(1) Res. Res. Res. Res. Res. Res. Res. Res. I2S2SEL I2S1SEL
rw rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral or function, otherwise reserved with zero reset value.
Refer to Section 1.4: Availability of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LSCO LSCO
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BDRST
SEL EN
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC LSE LSE LSE LSE
Res. Res. Res. Res. Res. RTCSEL[1:0] Res. LSEDRV[1:0] LSEON
EN CSSD CSSON BYP RDY
rw rw rw r rw rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LPWR WWDG IWWG 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
10
11
9
8
7
6
5
4
3
2
1
0
set
HSIDIV[2:0]
HSIKERON
HSERDY
HSEBYP
PLLRDY
HSIRDY
CSSON
HSEON
PLLON
HSION
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RCC_CR
0x00
Reset value 0 0 0 0 0 0 0 0 0 1 0 1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
MCO2SEL[3:0]
MCOPRE[3:0]
MCOSEL[3:0]
HPRE[3:0]
PPRE[2:0]
SWS[2:0]
SW[2:0]
Res.
Res.
Res.
RCC_CFGR
0x08
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
PLLQ[2:0]
PLLR[2:0]
PLLP[4:0]
PLLQEN
PLL
PLLREN
PLLPEN
RCC_PLL PLLM
Res.
Res.
Res.
Res.
Res.
Res.
PLLN[6:0] SRC
0x0C CFGR [2:0]
[1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 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.
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.
Res. Res.
Res. Res.
PLLRDYIE Res. Res.
HSERDYIE Res. Res.
HSIRDYIE Res. Res.
Res. Res.
LSERDYIE Res. Res.
LSIRDYIE Res. Res.
0x10 Reserved
0x14 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.
Res.
Res.
RCC_CIER
0x18
Reset value 0 0 0 0 0
0x38
0x34
0x30
0x28
0x24
0x20
0x2C
0x1C
170/989
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
IOPENR
Register
AHBENR
IOPRSTR
AHBRSTR
RCC_CIFR
RCC_CICR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
APBRSTR2
APBRSTR1
Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. PWRRST Res. Res. Res. Res. 28
0 0
Reset and clock control (RCC)
0 0 0
Res. Res. Res. I2C1RST Res. Res. Res. Res. 21
0
Res. Res. ADCRST Res. Res. Res. Res. Res. 20
Res. Res. Res. USART4RST Res. Res. Res. Res. 19
Res.. Res. TIM17RST USART3RST Res.. Res. Res. Res. 18
RM0454 Rev 5
0 0 0
Res. Res. TIM16RST USART2RST Res. Res. Res. Res. 17
Res.. Res. TIM15RST Res. .Res. Res. Res. Res. 16
Res. Res. TIM14RST SPI3RST Res. Res. Res. Res. 15
0 0 0 0 0
Res. Res. USART1RST SPI2RST Res. Res. Res. Res. 14
0 0 0
Res. Res. Res. USBRST Res. Res. Res. Res. 13
0
CRCEN Res. SPI1RST Res. 0 CRCRST. Res. Res. Res. 12
0 0
Res. Res. TIM1RST Res. Res. Res. Res. Res. 11
Res. Res. Res. Res. Res. Res. Res. Res. 10
Res. Res. Res. USART6RST Res. Res. LSECSSC LSECSSF 9
Table 28. RCC register map and reset values (continued)
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
RM0454
0x54
0x50
0x48
0x44
0x40
0x3C
RM0454
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
Register
APBENR2
APBENR1
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
IOPSMENR
AHBSMENR
RCC_CCIPR
APBSMENR2
0x4C APBSMENR1
ADCSEL[1:0] Res. Res. Res. Res. Res. Res. 31
0 0
Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. 29
Res. PWRSMEN Res. Res. Res. PWREN 28
1 1
0 0
0
TIM15SEL Res. Res. Res. Res. Res. Res. 24
Res. Res. I2C3SMEN Res. Res. Res. I2C3EN 23
0
TIM1SEL Res. I2C2SMEN Res. Res. Res. I2C2EN 22
1 1 1
0 0 0
1
0
RM0454 Rev 5
1 1 1
0 0 0
1 1 1 1 1
0 0 0 0 0
1 1 1
0 0 0
0 0 0 0
1
SPI1SMEN Res. CRCSMEN Res. SPI1EN Res. 12
1 1
0 0
1 1
0 0
1 1
1 1
0 0
0 0 0 0 0 0
1
1 1
1 1 1 1 1 1
0
Reset and clock control (RCC)
171/989
SYSCFGSMEN Res. DMA1SMEN GPIOASMEN SYSCFGEN Res. 0
172
set
Off-
0x60
0x58
0x5C
172/989
Register
RCC_CSR
Reset value
Reset value
Reset value
RCC_BDCR
LPWRRSTF Res. RCC_CCIPR2
Res. 31
WWDGRSTF Res. Res. 30
IWDGRSTF Res. Res. 29
SFTRSTF Res. Res. 28
Reset and clock control (RCC)
0 0 0 0 0 0 0
OBLRSTF LSCOSEL Res. 25
0 0
Res. LSCOEN Res. 24
0
RMVF Res. Res. 23
Res. Res. Res. 22
Res. Res. Res. 21
Res. Res. Res. 20
Res. Res. Res. 19
Res. Res. Res. 18
RM0454 Rev 5
Res. Res. Res. 17
Res. BDRST Res. 16
0 0
Res. Res. 12
Res. Res. Res. 11
Res. Res. Res. 10
Res. RTC SEL[1:0] Res. 9
Refer to Section 2.2 on page 44 for the register boundary addresses.
Table 28. RCC register map and reset values (continued)
0 0
Res. 8
Res. Res. Res. 7
Res. LSECSSD Res. 6
Res. LSECSSON Res. 5
Res. LSE DRV[1:0] Res. 4
Res. I2S2SEL[1:0] 3
Res. LSEBYP 2
LSIRDY LSERDY I2S1SEL[1:0] 1
0 0
0 0 0 0 0 0 0
0 0 0 0
RM0454
LSION LSEON 0
RM0454 General-purpose I/Os (GPIO)
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 13 shows the basic structures of a standard I/O port bit. Table 29 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.
Each I/O pin has a multiplexer with up to eight alternate function inputs (AF0 to AF7) that
can be configured through the GPIOx_AFRL (for pin 0 to 7) and GPIOx_AFRH (for pin 8 to
15) registers:
• After reset the multiplexer selection is alternate function 0 (AF0). The I/Os are
configured in alternate function mode through GPIOx_MODER register.
• The specific alternate function assignments for each pin are detailed in the device
datasheet.
In addition to this flexible I/O multiplexing architecture, each peripheral has alternate
functions mapped onto different I/O pins to optimize the number of peripherals available in
smaller packages.
To use an I/O in a given configuration, the user has to proceed as follows:
• Debug function: after each device reset these pins are assigned as alternate function
pins immediately usable by the debugger host
• GPIO: configure the desired I/O as output, input or analog in the GPIOx_MODER
register.
• Peripheral alternate function:
– Connect the I/O to the desired AFx in one of the GPIOx_AFRL or GPIOx_AFRH
register.
– Select the type, pull-up/pull-down and output speed via the GPIOx_OTYPER,
GPIOx_PUPDR and GPIOx_OSPEEDER registers, respectively.
– Configure the desired I/O as an alternate function in the GPIOx_MODER register.
• Additional functions:
– ADC connection can be enabled in ADC registers regardless the configured GPIO
mode. When ADC uses a GPIO, it is recommended to configure the GPIO in
analog mode, through the GPIOx_MODER register.
– For the additional functions like RTC, TAMP, WKUPx and oscillators, configure the
required function in the related RTC, TAMP, PWR and RCC registers. These
functions have priority over the configuration in the standard GPIO registers.
Refer to the “Alternate function mapping” table in the device datasheet for the detailed
mapping of the alternate function I/O pins.
See Section 6.4.5: GPIO port input data register (GPIOx_IDR) (x = A to F) and
Section 6.4.6: GPIO port output data register (GPIOx_ODR) (x = A to F) for the register
descriptions.
thus select any one of the possible functions for each I/O. The AF selection signal being
common to the alternate function input and alternate function output, a single channel is
selected for the alternate function input/output of a given I/O.
To know which functions are multiplexed on each GPIO pin refer to the device datasheet.
On
Read
Bit set/reset registers
VDDIOx
TTL Schmitt trigger
on/off Pull
Write
Output data register
Input driver up
I/O pin
Output driver
on/off Pull
down
Read/write
VSS
MSv33183V2
On
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
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
Bits 31:0 AFSELy[3:0]: Alternate function selection for port x pin y (y = 0..7)
These bits are written by software to configure alternate function I/Os
AFSELy selection:
1000: Reserved
0000: AF0
1001: Reserved
0001: AF1
1010: Reserved
0010: AF2
1011: Reserved
0011: AF3
1100: Reserved
0100: AF4
1101: Reserved
0101: AF5
1110: Reserved
0110: AF6
1111: Reserved
0111: AF7
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 pin y (y = 8..15)
These bits are written by software to configure alternate function I/Os
AFSELy selection:
0000: AF0 1000: Reserved
0001: AF1 1001: Reserved
0010: AF2 1010: Reserved
0011: AF3 1011: Reserved
0100: AF4 1100: Reserved
0101: AF5 1101: Reserved
0110: AF6 1110: Reserved
0111: AF7 1111: 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
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
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
port B to F
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 to 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 to 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 to 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
port B to F
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 to 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 to 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 to 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 to 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 to 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 to 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
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
• Enabling/disabling the analog switch booster
• 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
w w rw rw rw rw rw rw rw
1. Only significant on devices integrating the corresponding peripheral or function, otherwise reserved. Refer to Section 1.4:
Availability of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PB2_ PB1_ PB0_ PA13_ PA6_ PA5_ PA3_ PA1_
Res. Res. Res. Res. Res. Res. Res. Res. CDEN CDEN CDEN CDEN CDEN CDEN CDEN CDEN
(1) (1) (1) (1) (1) (1) (1) (1)
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SRAM_
SRAM_ ECC_ LOCKUP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PARITY
PEF LOCK _LOCK
_LOCK
rc_w1 rw rw rw
1. Only significant on devices integrating switchable clamping diodes, otherwise reserved. Refer to Section 1.4: Availability of
peripherals.
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 TAMP
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_ FLASH_
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
ECC ITF
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. 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
USB
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. (1) Res. Res.
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability of
peripherals.
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
DMA2_ DMA2_ DMA2_ DMA2_ DMA2 DMA1 DMA1
CH5 CH4 CH3 CH2 _CH1 _CH7 _CH6 DMA1 DMA1
Res. Res. Res. Res. Res. Res. DMAMUX
(1) (1) (1) (1) (1) (1) (1) _CH5 _CH4
r r r r r r r r r r
1. Only significant on devices integrating the corresponding DMA instance and channel, otherwise reserved. Refer to
Section 1.4: Availability of peripherals.
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_ TIM1_ TIM1_ TIM1_
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
BRK 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. (1) TIM3
TIM4
r r
1. Only significant on devices integrating TIM4, otherwise reserved. Refer to Section 1.4: Availability of peripherals.
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. TIM6(1)
r
1. Only significant on devices integrating TIM4, otherwise reserved. Refer to Section 1.4: Availability of peripherals.
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. TIM7(1)
r
1. Only significant on devices integrating TIM4, otherwise reserved. Refer to Section 1.4: Availability of peripherals.
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. TIM15(1)
r
1. Only significant on devices integrating TIM15, otherwise reserved. Refer to Section 1.4: Availability of peripherals.
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. I2C3(1) I2C2
r r
1. Only significant on devices integrating I2C3, otherwise reserved. Refer to Section 1.4: Availability of peripherals.
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SPI3(1) SPI2
r r
1. Only significant on devices integrating SPI3, otherwise reserved. Refer to Section 1.4: Availability of peripherals.
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. USART1
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. USART2
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
USART6 USART5 USART4 USART3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. (1) (1) Res. (1) (1)
r r r r
1. Only significant on devices integrating the corresponding peripheral, otherwise reserved. Refer to Section 1.4: Availability
of peripherals.
0x7F
0x8C
0x04 to
0x1D to
Offset
7.1.31
RM0454
Reserved
Reserved
Reserved
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
SYSCFG_CFGR2
SYSCFG_CFGR1
SYSCFG_ITLINE6
SYSCFG_ITLINE5
SYSCFG_ITLINE4
SYSCFG_ITLINE3
SYSCFG_ITLINE2
SYSCFG_ITLINE0
Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. 25
SYSCFG register map
0
Res. Res. Res. Res. Res. Res. Res. I2C3_FMP 24
0
Res. Res. Res. Res. Res. Res. Res. I2C_PA10_FMP 23
0
Res. Res. Res. Res. Res. Res. Res. I2C_PA9_FMP 22
0
Res. Res. Res. Res. Res. Res. Res. I2C2_FMP 21
0
Res. Res. Res. Res. Res. Res. Res. I2C1_FMP 20
Bits 31:5 Reserved, must be kept at reset value.
0
Bit 2 Reserved, must be kept at reset value.
0
Res. Res. Res. Res. Res. Res. Res. I2C_PB8_FMP 18
RM0454 Rev 5
0
Res. Res. Res. Res. Res. Res. Res. I2C_PB7_FMP 17
Bit 1 USART4: USART4 interrupt request pending(1)
Bit 3 USART5: USART5 interrupt request pending(1)
Bit 4 USART6: USART6 interrupt request pending(1)
0
Res. Res. Res. Res. Res. Res. Res. I2C_PB6_FMP 16
Res. Res. Res. Res. Res. Res. Res. Res. 15
Reserved
Reserved
Reserved
Res. Res. Res. Res. Res. Res. Res. Res. 14
Res. Res. Res. Res. Res. Res. Res. Res. 13
Res. Res. Res. Res. Res. Res. Res. Res. 12
Bit 0 USART3: USART3 interrupt request pending (EXTI line 28)(1)
10
0
0
Res. Res. Res. Res. Res. Res. SRAM_PEF BOOSTEN 8
0
IR_MOD
0
0
0
0
0
0
0
0
0
0
0
0
0
X X
205/989
System configuration controller (SYSCFG)
207
0xB8
0xB4
0xB0
0xA8
0xA4
0xA0
0x9C
0xD8
0xD4
0xD0
0xC8
0xC4
0xC0
0xBC
0xAC
0xCC
Offset
206/989
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
Reset value
SYSCFG_ITLINE9
SYSCFG_ITLINE8
SYSCFG_ITLINE7
SYSCFG_ITLINE11
SYSCFG_ITLINE22
SYSCFG_ITLINE21
SYSCFG_ITLINE20
SYSCFG_ITLINE19
SYSCFG_ITLINE18
SYSCFG_ITLINE17
SYSCFG_ITLINE16
SYSCFG_ITLINE14
SYSCFG_ITLINE13
SYSCFG_ITLINE12
SYSCFG_ITLINE10
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
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. 27
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. 25
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. 23
System configuration controller (SYSCFG)
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. 21
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. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0454 Rev 5
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. 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 15
Reserved
Res. 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. Res. 13
Res. 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. Res. Res. Res. Res. EXTI15 11
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EXTI14 10
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMA2_CH5 Res. Res. Res. EXTI13 9
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMA2_CH4 Res. Res. Res. EXTI12 8
Table 31. SYSCFG register map and reset values (continued)
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMA2_CH3 Res. Res. Res. EXTI11 7
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMA2_CH2 Res. Res. Res. EXTI10 6
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMA2_CH1 Res. Res. Res. EXTI9 5
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMA1_CH7 Res. Res. Res. EXTI8 4
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. TIM1_BRK Res. DMA1_CH6 Res. Res. Res. EXTI7 3
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. TIM1_UPD Res. DMA1_CH5 Res. Res. USB EXTI6 2
0
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. TIM4 Res. TIM1_TRG Res. DMA1_CH4 DMA1_CH3 Res. Res. EXTI5 1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TIM17 TIM16 TIM15 TIM14 TIM7 TIM6 TIM3 TIM1_CC TIM1_CCU ADC DMAMUX DMA1_CH2 DMA1_CH1 Res. EXTI4 0
RM0454
0xF4
0xF0
0xFF
0xE8
0xE4
0xE0
0xEC
0xDC
0xF8 -
Offset
RM0454
Reserved
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
SYSCFG_ITLINE29
SYSCFG_ITLINE28
SYSCFG_ITLINE27
SYSCFG_ITLINE26
SYSCFG_ITLINE25
SYSCFG_ITLINE24
SYSCFG_ITLINE23
RM0454 Rev 5
Res. Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. 16
Res. Res. Res. Res. Res. Res. Res. 15
Reserved
Res. Res. Res. Res. Res. Res. Res. 14
Res. Res. Res. Res. Res. Res. Res. 13
Res. Res. Res. Res. Res. Res. Res. 12
Res. Res. Res. Res. Res. Res. Res. 11
Res. Res. Res. Res. Res. Res. Res. 10
Res. Res. Res. Res. Res. Res. Res. 9
Refer to Section 2.2 on page 44 for the register boundary addresses.
Res. Res. Res. Res. Res. Res. Res. 8
Table 31. SYSCFG register map and reset values (continued)
207/989
System configuration controller (SYSCFG)
207
Interconnect matrix RM0454
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, Low-power
run, Low-power sleep, Stop 0, and Stop 1 modes.
For availability of peripherals on different STM32G0x0 products, refer to Section 1.4:
Availability of peripherals.
DMAMUX
Source
TIM14
TIM15
TIM16
TIM17
IRTIM
TIM1
TIM3
TIM4
ADC
TIM6 - - - - - - - 8.3.2 - -
USART1 - - - - - - - - - 8.3.7
USART4 - - - - - - - - - 8.3.7
ADC 8.3.3 - - - - - - - - -
T. sensor - - - - - - - 8.3.5 - -
VBAT - - - - - - - 8.3.5 - -
VREFINT - - - - - - 8.3.5 - -
LSE - - - - - 8.3.4 - - - -
LSI - - - - - 8.3.4 - - - -
DMAMUX
Source
TIM14
TIM15
TIM16
TIM17
IRTIM
TIM1
TIM3
TIM4
ADC
MCO - - - 8.3.4 - - 8.3.4 - - -
EXTI - - - - - - - 8.3.2 - -
RTC and
- - - 8.3.4 - 8.3.4 - - - -
TAMP
SYST ERR 8.3.6 8.3.6 8.3.6 - 8.3.6 8.3.6 8.3.6 - - -
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”.
Triggering signals
The output (from master) is on signal TIMx_TRGO (and TIMx_TRGOx), following a
configurable timer event.
With TIM14, TIM16, 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 69: TIM1 internal trigger
connection.
8.3.2 From TIM1, TIM3, TIM4, TIM6, TIM15, and EXTI, to ADC
Purpose
The general-purpose timers TIM3, TIM4, and TIM15, basic timer TIM6, advanced-control
timer TIM1, and EXTI can be used to generate an ADC triggering event.
TIMx synchronization is described in: Section 15.3.27: ADC synchronization.
ADC synchronization is described in: Section 14.4: Conversion on external trigger and
trigger polarity (EXTSEL, EXTEN).
Triggering signals
The output (from timer) is on signal TIMx_TRGO, TIMx_TRGO2 or TIMx_CCx event.
The input (to ADC) is on signal EXT[15:0], JEXT[15:0].
The connection between timers and ADC is provided in Relevant power modes
These interconnections operate in Run, Sleep, Low-power run, and Low-power sleep power
modes.
Triggering signals
The output (from ADC) is on signals ADCn_AWDx_OUT n = 1 (for ADC) 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, RTC and TAMP, to TIM14,
TIM16, and TIM17
Purpose
External clocks (HSE, LSE), internal clock (LSI), microcontroller output clock (MCO and
MCO2), RTC clock, RTC wakeup interrupt, 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 HSI16 or LSI,
using accurate clocks such as LSE or HSE/32 for timing reference. See details in
Section 5.2.15: Internal/external clock measurement with TIM14/TIM16/TIM17.
When low-speed external (LSE) oscillator is used, no additional hardware connections are
required.
8.3.5
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.
Refer to Section 9.3 for information on DMA implementation.
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 DMA
The devices incorporate one or two DMA controller instances. The following implementation
table shows the number of DMA channels for either instance. A dash indicates that the
instance is not implemented.
DMA1 5 7 7
DMA2 - - 5
DMA
Ch 1
...
Ch 7
dma_it[1..7]
MSv48187V1
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.
A DMA block transfer may be requested from a peripheral, or triggered by the software in
case of memory-to-memory transfer.
After an event, the following steps of a single DMA transfer occur:
1. The peripheral sends a single DMA request signal to the DMA controller.
2. The DMA controller serves the request, depending on the priority of the channel
associated to this peripheral request.
3. As soon as the DMA controller grants the peripheral, an acknowledge is sent to the
peripheral by the DMA controller.
4. The peripheral releases its request as soon as it gets the acknowledge from the DMA
controller.
5. Once the request is de-asserted by the peripheral, the DMA controller releases the
acknowledge.
The peripheral may order a further single request and initiate another single DMA transfer.
The request/acknowledge protocol is used when a peripheral is either the source or the
destination of the transfer. For example, in case of memory-to-peripheral transfer, the
peripheral initiates the transfer by driving its single request signal to the DMA controller. The
DMA controller reads then a single data in the memory and writes this data to the peripheral.
For a given channel x, a DMA block transfer consists of a repeated sequence of:
• a single DMA transfer, encapsulating two AHB transfers of a single data, over the DMA
AHB bus master:
– a single data read (byte, half-word or word) from 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 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.
register content may not correctly reflect the remaining data transfers versus the
aborted source and destination buffer/register.
• Abort and restart a channel
This corresponds to the software sequence: disable an active channel, then
reconfigure the channel and enable it again.
This is supported by the hardware if the following conditions are met:
– The application guarantees that, when the software is disabling the channel, a
DMA data transfer is not occurring at the same time over its master port. For
example, the application can first disable the peripheral in DMA mode, in order to
ensure that there is no pending hardware DMA request from this peripheral.
– The software must operate separated write accesses to the same DMA_CCRx
register: First disable the channel. Second reconfigure the channel for a next block
transfer including the DMA_CCRx if a configuration change is needed. There are
read-only DMA_CCRx register fields when DMA_CCRx.EN=1. Finally enable
again the channel.
When a channel transfer error occurs, the EN bit of the DMA_CCRx register is cleared by
hardware. This EN bit can not be set again by software to re-activate the channel x, until the
TEIFx bit of the DMA_ISR register is set.
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.
Table 35. 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
Assuming the AHB/APB bridge is an AHB 32-bit slave peripheral that does not take into
account the HSIZE data, any AHB byte or half-word transfer is changed into a 32-bit APB
transfer as described below:
• An AHB byte write transfer of 0xB0 to one of the 0x0, 0x1, 0x2 or 0x3 addresses, is
converted to an APB word write transfer of 0xB0B0B0B0 to the 0x0 address.
• An AHB half-word write transfer of 0xB1B0 to the 0x0 or 0x2 addresses, is converted to
an APB word write transfer of 0xB1B0B1B0 to the 0x0 address.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. TEIF7 HTIF7 TCIF7 GIF7 TEIF6 HTIF6 TCIF6 GIF6 TEIF5 HTIF5 TCIF5 GIF5
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
TEIF4 HTIF4 TCIF4 GIF4 TEIF3 HTIF3 TCIF3 GIF3 TEIF2 HTIF2 TCIF2 GIF2 TEIF1 HTIF1 TCIF1 GIF1
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
CTCIF7
CTCIF6
CTCIF5
CHTIF7
CHTIF6
CHTIF5
CTEIF7
CTEIF6
CTEIF5
CGIF7
CGIF6
CGIF5
Res. Res. Res. Res.
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
CHTIF4
CTCIF4
CHTIF3
CTCIF3
CHTIF2
CTCIF2
CHTIF1
CTCIF1
CTEIF4
CTEIF3
CTEIF2
CTEIF1
CGIF4
CGIF3
CGIF2
CGIF1
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
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
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
HTIF7
TCIF7
HTIF6
TCIF6
HTIF5
TCIF5
HTIF4
TCIF4
HTIF3
TCIF3
HTIF2
TCIF2
HTIF1
TCIF1
TEIF7
TEIF6
TEIF5
TEIF4
TEIF3
TEIF2
TEIF1
GIF7
GIF6
GIF5
GIF4
GIF3
GIF2
GIF1
Res.
Res.
Res.
Res.
DMA_ISR
0x000
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
CHTIF7
CTCIF7
CHTIF6
CTCIF6
CHTIF5
CTCIF5
CHTIF4
CTCIF4
CHTIF3
CTCIF3
CHTIF2
CTCIF2
CHTIF1
CTCIF1
CTEIF7
CTEIF6
CTEIF5
CTEIF4
CTEIF3
CTEIF2
CTEIF1
CGIF7
CGIF6
CGIF5
CGIF4
CGIF3
CGIF2
CGIF1
Res.
Res.
Res.
Res.
DMA_IFCR
0x004
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
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.
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.
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
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
0x040 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_CCR4
0x044
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_CNDTR4 NDTR[15:0]
0x048
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CPAR4 PA[31:0]
0x04C
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_CMAR4 MA[31:0]
0x050
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
0x054 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_CCR5
0x058
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_CNDTR5 NDTR[15:0]
0x05C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CPAR5 PA[31:0]
0x060
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_CMAR5 MA[31:0]
0x064
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
0x068 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_CCR6
0x06C
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_CNDTR6 NDTR[15:0]
0x070
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CPAR6 PA[31:0]
0x074
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_CMAR6 MA[31:0]
0x078
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
0x07C 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_CCR7
0x080
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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.
DMA_CNDTR7 NDTR[15:0]
0x084
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CPAR7 PA[31:0]
0x088
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_CMAR7 MA[31:0]
0x08C
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 it is 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 controllers 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 on the product
implementation, and are detailed inSection 10.3.2.
p Channel 1
Channel 0
x
DMA requests eq
_r
DMAMUX_C0CR
from peripherals: 1
ux
am
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)
Caution: A same non-null DMAREQ_ID can be assigned to two different channels only if the
application ensures that these channels are not requested to be served at the same time. In
other words, if two different channels receive a same asserted hardware request at the
same time, an unpredictable DMA hardware behavior occurs.
On top of the DMA request selection, the synchronization mode and/or the event generation
may be configured and enabled, if required.
Figure 20. 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 21. 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 20 and Figure 21.
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 must be written by software only when the enable GE bit of the
corresponding generator channel x is disabled.
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. DMAREQ_ID[6: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. SOF11 SOF10 SOF9 SOF8 SOF7 SOF6 SOF5 SOF4 SOF3 SOF2 SOF1 SOF0
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
CSOF CSOF CSOF CSOF CSOF CSOF CSOF CSOF CSOF CSOF CSOF CSOF
Res. Res. Res. Res.
11 10 9 8 7 6 5 4 3 2 1 0
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. 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
10
11
9
8
7
6
5
4
3
2
1
0
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
DMAMUX_C0CR SYNC_ID[4:0] NBREQ[4:0] DMAREQ_ID[6:0]
SE
0x000
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
SE
DMAMUX_C1CR SYNC_ID[4:0] NBREQ[4:0] DMAREQ_ID[6:0]
0x004
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
SE
DMAMUX_C2CR SYNC_ID[4:0] NBREQ[4:0] DMAREQ_ID[6:0]
0x008
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
DMAMUX_C3CR SYNC_ID[4:0] NBREQ[4:0] DMAREQ_ID[6:0]
SE
0x00C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
SE
DMAMUX_C4CR SYNC_ID[4:0] NBREQ[4:0] DMAREQ_ID[6: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
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
SE
DMAMUX_C5CR SYNC_ID[4:0] NBREQ[4:0] DMAREQ_ID[6: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
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
0x018
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
SE
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
SE
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1: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
SPOL
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
SE
SOIE
EGE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
[1:0]
SE
Reserved
0x07C
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DMAMUX_CSR
0x080
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
CSOF10
CSOF11
CSOF9
CSOF8
CSOF7
CSOF6
CSOF5
CSOF4
CSOF3
CSOF2
CSOF1
CSOF0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DMAMUX_CFR
0x084
Reset value 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.
GPOL Res.
[1:0] Res.
Res.
Res. Res.
Res. Res.
Res. Res.
Res. Res.
Res. Res.
Res. Res.
Res. Res.
OIE Res.
Res. Res.
Res. Res.
Res. Res.
Res.
Res.
Res.
Res.
Res.
Reserved
0x0FC
GE
0x13C
0x10C
0x3FC
0x110 -
Offset
0x148 -
RM0454
Reserved
Reserved
Register
Reset value
Reset value
Reset value
Reset value
Reset value
DMAMUX_RGSR
DMAMUX_RG3CR
DMAMUX_RG2CR
DMAMUX_RG1CR
DMAMUX_RGCFR
Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. 24
0
0
0
0
0
0
RM0454 Rev 5
[1:0] [1:0] [1:0]
0
0
0
10
Res. Res. Res. Res. Res. Res. Res. 9
Refer to Section 2.2 on page 44 for the register boundary addresses.
0
0
0
0
0
0
0
0
0
0
0
0
0
0
249/989
DMA request multiplexer (DMAMUX)
249
Nested vectored interrupt controller (NVIC) RM0454
- - - - Reserved 0x0000_0000
- -3 fixed Reset Reset 0x0000_0004
Non maskable interrupt. The SRAM
parity err., Flash ECC double err.,
- -2 fixed NMI_Handler 0x0000_0008
HSE CSS and LSE CSS 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
RTC and TAMP interrupts
2 9 settable RTC / TAMP 0x0000_0048
(combined EXTI lines 19 & 21)
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
DMA1_Channel4_5_6
_7 / DMAMUX / DMA1 channel 4, 5, 6, 7, DMAMUX,
11 18 settable 0x0000_006C
DMA2_Channel1_2_3 DMA2 channel 1, 2, 3, 4, 5 interrupts
_4_5
ADC interrupt (ADC combined with
12 19 settable ADC 0x0000_0070
EXTI 17 & 18)
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+TIM4 TIM3 global interrupt 0x0000_0080
17 24 settable TIM6 TIM6 global interrupt 0x0000_0084
18 25 settable TIM7 TIM7 global interrupt 0x0000_0088
19 26 settable TIM14 TIM14 global interrupt 0x0000_008C
20 27 settable TIM15 TIM15 global interrupt 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 31 settable I2C2 / I2C3 I2C2 and I2C3 global interrupt 0x0000_00A0
25 32 settable SPI1 SPI1 global interrupt 0x0000_00A4
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 modes.
The EXTI also includes the EXTI I/O port mux.
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 mux outputs are available as output signals from the EXTI, to trigger other
functional blocks. The EXTI mux 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. IM26 IM25 IM24 IM23 IM22 IM21 Res. IM19 Res. Res. Res.
rw rw rw rw 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. EM26 EM25 EM24 EM23 EM22 EM21 Res. EM19 Res. Res. Res.
rw rw rw rw 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
0x070-
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
0x07C
Table 52. 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
IM26
IM25
IM24
IM23
IM22
IM21
IM19
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_IMR1 IM[15:0]
0x080
Reset value 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EM31
EM26
EM25
EM24
EM23
EM22
EM21
EM19
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 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 computation
MS19882V2
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: input data 0x1A2B3C4D is 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, output data 0x11223344 is converted into
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.
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 19
multiplexed channels allowing it to measure signals from 16 external and 3 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.
VDD/VDDA VREF+
AREADY
EOSMP ADC interrupt IRQ
SCANDIR AUTOFF EOSEQ
EOC CPU
up/down Auto-off mode
ADEN/ADDIS OVR Master
DATA[15:0] AWD
AHB
CH_SEL[18:0] AHB
Supply & to slave
CONT LFTRIG APB
reference APB Master
single/cont. ADCAL self interface
VBAT Input calibration DMA
VREFINT selection SAR ADC DMA request
VSENSE VIN
ADC_IN & scan SMP[2:0] DMAEN
[18:15, 11:0] VIN[x] control sampling CONVERTED Oversa DMACFG
time start DATA mpler
EXTSEL[1:0]
Trigger selection
MSv47998V3
Input, analog power Analog power supply and positive reference voltage
VDDA
supply for the ADC, VDDA ≥ VDD
Input, analog supply Ground for analog power supply. Must be at VSS
VSSA
ground potential
Input, analog reference
VREF+ The higher/positive reference voltage for the ADC.
positive
ADC_INx Analog input signals 16 external analog input channels
If the main voltage regulator enters low-power mode (such as Low-power run mode), this
buffer is disabled and the ADC cannot be used.
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.
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 31: 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).
HSI16, SYSCLK, or
00 Latency is not deterministic (jitter)
PLLPCLK(3)
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.5 ADC clock cycles
1. Refer to the device datasheet for the maximum ADC_CLK frequency.
2. If the trigger is generated by TIM1 or TIM15 clocked at twice the CPU clock frequency, then the latency is
not deterministic and can be increased by one TIM1 or TIM15 clock cycle.
3. 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.
STM32G0xx
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] VREF+
ADC_IN7
VIN[8]
ADC_IN8
VIN
SAR
VIN[9]
ADC_IN9 ADC1
VIN[10]
ADC_IN10
VIN[11] VREF-
ADC_IN11
VIN[12]
VSENSE
VIN[13]
VREFINT
VIN[14]
VBAT/3
VIN[15]
ADC_IN15
VIN[16]
ADC_IN16
VIN[17]
ADC_IN17
VIN[18]
ADC_IN18
MSv45361V3
14.3.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 57: External triggers in Section 14.3.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.5.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
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 62 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 47. 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
Threshould updated
MSv45365V1
14.8 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 51 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 63 below gives the data format for the various N and M combination, for a raw
conversion data equal to 0xFFF.
Table 63. 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
• Supported temperature range: –40 to 125 °C
• Linearity: ±2 °C max., precision depending on calibration
Temperature + VSENSE
sensor ADC VIN[12]
-
Address/data bus
converted data
VREFEN control bit
ADC
+ VREFINT
Internal power ADC VIN[13]
block -
MSv62466V1
TS_CAL2_TEMP – TS_CAL1_TEMP
Temperature ( in °C ) = ---------------------------------------------------------------------------------------------------- × ( TS_DATA – TS_CAL1 ) + TS_CAL1_TEMP
TS_CAL2 – TS_CAL1
Where:
• TS_CAL2 is the temperature sensor calibration value acquired at TS_CAL2_TEMP
(refer to the datasheet for TS_CAL2 value)
• 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 and
TS_CAL2 calibration points.
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 VREF+ voltage using the internal reference voltage
VREF+ voltage may be subject to variation or not precisely known. The embedded internal
reference voltage (VREFINT) and its calibration data acquired by the ADC during the
manufacturing process at VREF+_charac can be used to evaluate the actual VREF+ voltage
level.
The following formula gives the actual VREF+ voltage supplying the device:
Where:
• VREF+_Charac is the value of VREF+ 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 VREF+ value is not known, you must use the internal voltage
reference and VREF+ can be replaced by the expression provided in Section : Calculating
the actual VREF+ voltage using the internal reference voltage, resulting in the following
formula:
V REF+_Charac × VREFINT_CAL × ADC_DATA x
V CHANNELx = -------------------------------------------------------------------------------------------------------------------------
VREFINT_DATA × FULL_SCALE
Where:
• VREF+_Charac is the value of VREF+ 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
• full_SCALE is the maximum digital value of the ADC output. For example with 12-bit
resolution, it is 212 - 1 = 4095 or with 8-bit resolution, 28 - 1 = 255.
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.
the correct operation of the ADC, the VBAT pin is internally connected to a bridge divider.
This bridge is automatically enabled when VBATEN is set, to connect VBAT to the ADC
VIN[14] input channel. As a consequence, the converted digital value is half the VBAT
voltage. To prevent any unwanted consumption on the battery, it is recommended to enable
the bridge divider only when needed for ADC conversion.
Address/data bus
ADC
VBAT/3
+
ADC VIN[14]
-
MSv45367V2
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 AWD1SG CHSEL
Res. AWD1CH[4:0] Res. Res. Res. Res. Res. Res. DISCEN
N L RMOD
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
SCAND DMAC
AUTOFF WAIT CONT OVRMOD EXTEN[1:0] Res. EXTSEL[2:0] ALIGN RES[1:0] DMAEN
IR FG
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
Res. Res. Res. Res. Res.
L18 L17 L16 L15 L14 L13 L12 L11 L10 L9 L8
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
18 17 16
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
CH18 CH17 CH16
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
CH18 CH17 CH16
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
VBAT VREF
Res. Res. Res. Res. Res. Res. Res. TSEN PRESC[3:0] Res. Res.
EN EN
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. Res. Res.
0x2C
0x1C
0x0C
Offset
14.13
RM0454
1)
0)
ADC_CR
Reserved
Reserved
ADC_IER
ADC_ISR
Register
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_CFGR1
ADC_CHSELR
ADC_CHSELR
ADC_AWD3TR
ADC_AWD2TR
ADC_AWD1TR
(CHSELRMOD=
(CHSELRMOD=
0
0
0
Res. Res. Res. Res. Res.. Res. ADCAL Res. Res. 31
CKMODE[1:0]
0
0
0
Res. Res. Res. Res. Res.. Res. Res. Res. 30
0
0
0
Res. Res. Res. Res. Res.. LFTRIG Res. Res. Res. 29
SQ8[3:0]
0
0
0
Res. Res. Res. Res. Res.. Res. ADVREGEN Res. Res. 28
1
0
1
1
0
Res. Res.. Res. Res. Res. Res. 27
AWDCH[4:0]
1
0
1
1
0
0
Res. SMPSEL18. Res. Res. Res. Res. 26
1
0
1
1
0
Res. SMPSEL17 Res. Res. Res. Res. Res. 25
SQ7[3:0]
ADC register map
1
0
1
1
0
Res. SMPSEL16 Res. Res. Res. Res. Res. 24
1
0
1
1
0
0
Res SMPSEL15 Res. AWD1EN Res. Res. Res. 23
1
0
1
1
0
0
Res SMPSEL14 Res. AWD1SGL Res. Res. Res. 22
1
0
1
1
0
0
Res SMPSEL13 Res. CHSELRMOD Res. Res. Res. 21
SQ6[3:0]
HT3[11:0]
HT2[11:0]
HT1[11:0]
1
0
1
1
0
Res SMPSEL12 Res. Res. Res. Res. Res. 20
1
0
1
1
0
Res SMPSEL11 Res. Res. Res. Res. Res. 19
1
0
1
1
0
0
CHSEL18 SMPSEL10 Res. Res. Res. Res. Res. 18
1
0
1
1
RM0454 Rev 5
CHSEL17 SMPSEL9 Res. Res. Res. Res. Res. 17
SQ5[3:0]
1
0
1
1
0
0
CHSEL16 SMPSEL8 Res. DISCEN Res. Res. Res. 16
The following table summarizes the ADC registers.
0
0
0
Res. CHSEL15 Res. Res. SMPSEL7 Res. AUTOFF Res. Res. Res. 15
Reserved
Reserved
0
0 0 0 0
0
0
Res. CHSEL14 Res. Res. SMPSEL6 Res. WAIT Res. Res. Res. 14
0
0
0
0
0
0
Res. CHSEL13 Res. Res. SMPSEL5 Res. CONT Res. CCRDYIE. CCRDY. 13
SQ4[3:0]
0
0
0
0
Res. CHSEL12 Res. Res. SMPSEL4 Res. OVRMOD Res. Res. Res. 12
EOCALIE EOCAL
0
0
0
0
0
0
0
0
EXTEN[1:0]
11
0
0
0
0
0
0
CHSEL10 SMPSEL2 Res. Res. Res. Res. 10
0
0
0
0
0
0
0
0
SQ3[3:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
OVSS[3:0]
EXTSEL
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2: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
0
0
0
0
0
SQ1[3:0]
SMP1
0 OVSE
0
0
0
0
0
0
0
0
0
333/989
Analog-to-digital converter (ADC)
334
...
...
...
0x40
0x38
0x34
0x30
0xB4
0xA4
0xA0
0x3C
0x308
Offset
334/989
ADC_DR
Reserved
Reserved
Reserved
Reserved
ADC_CCR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
ADC_AWD3CR
ADC_AWD2CR
ADC_CALFACT
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
Res. Res. Res. Res. Res. 26
Analog-to-digital converter (ADC)
0
VBATEN Res. Res. Res. Res. 24
0
TSEN Res. Res Res Res. 23
0
VREFEN Res. Res Res Res. 22
0
PRESC3 Res. Res Res Res. 21
0
PRESC2 Res. Res Res Res. 20
0
PRESC1 Res. Res Res Res. 19
0
0
0
RM0454 Rev 5
Res. Res. AWD3CH17 AWD2CH17 Res. 17
0
Reserved
Reserved
Reserved
Reserved
0 0 0 0
0
0 0
8
0
0
0
0
0
0
0
0
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
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MS31085V2
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 344
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 347.
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 70: Output control bits for complementary OCx and OCxN channels
with break feature on page 416 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
AFIO controller), with polarity selection and optional digital filtering
• An internal source:
– the Cortex®-M0+ LOCKUP output
– the SRAM parity error signal
– a Flash memory ECC dual error detection
– 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 AFIO controller), 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
ECC LOCK
Double ECC Error
CSS
Software break requests: BG
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 internal PLL and/or
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: 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 update event (UEV) occurs. 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
MS33106V1
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 70. 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
RM0454
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
RM0454 Rev 5
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)
431/989
433
0x58
0x54
0x50
0x48
0x44
0x40
0x38
0x34
0x30
0x28
0x24
0x4C
0x3C
0x2C
Offset
432/989
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
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
RM0454 Rev 5
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 71. 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
RM0454
0x68
0x64
0x60
0x5C
Offset
RM0454
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
RM0454 Rev 5
Res. Res. 17
TI3SEL[3:0]
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
0
BK2INP BKINP 9
Refer to Section 2.2 on page 44 for the register boundary addresses.
TI2SEL[3:0]
0
0
Table 71. 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
1
BK2INE BKINE 0
Advanced-control timer (TIM1)
433/989
433
General-purpose timers (TIM3/TIM4) RM0454
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
Figure 128. 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 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: TIMx control register 1
(TIMx_CR1)(x = 3 to 4) on page 479).
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
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MS31085V2
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 441.
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 update event (UEV) occurs.
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
MS33106V1
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
1. Configure the channel 1 to detect low levels on TI1. Configure the input filter duration
(in this example, we do not need any filter, so we keep IC1F=0000). The capture
prescaler is not used for triggering, so it does not need to be configured. The CC1S bits
select the input capture source only, CC1S=01 in TIMx_CCMR1 register. Write
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.
CC2P=1 and CC2NP=0 in TIMx_CCER register to validate the polarity (and detect low
level only).
2. 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
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
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 will detect 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 and AFIO registers.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CNT[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
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 CNT[30: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
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
ARR[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
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
CCR1[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
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
CCR2[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
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
CCR3[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
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
CCR4[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
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. 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
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
RM0454
16.4.26
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
RM0454 Rev 5
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
505/989
507
General-purpose timers (TIM3/TIM4) RM0454
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
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_PSC PSC[15:0]
0x28
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ARR[31:16]
TIMx_ARR ARR[15:0]
0x2C ( only, reserved on the other timers)
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
0x30 Reserved
CCR1[31:16]
TIMx_CCR1 CCR1[15:0]
0x34 ( only, reserved on the other timers)
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
CCR2[31:16]
TIMx_CCR2 CCR2[15:0]
0x38 ( only, reserved on the other timers)
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
CCR3[31:16]
TIMx_CCR3 CCR3[15:0]
0x3C ( only, reserved on the other timers)
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
CCR4[31:16]
TIMx_CCR4 CCR4[15:0]
0x40 ( only, reserved on the other timers)
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
0x44 Reserved
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_DMAR DMAB[15:0]
0x4C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ETRSEL
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.
TIM3_AF1
[3:0]
0x60
Reset value 0 0 0 0
ETRSEL
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.
TIM4_AF1
[3:0]
0x60
Reset value 0 0 0 0
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIM3_TISEL TI3SEL[3:0] TI2SEL[3:0] TI1SEL[3:0]
0x68
Reset value 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.
Res.
Res.
Res.
Res.
TIM4_TISEL TI3SEL[3:0] TI2SEL[3:0] TI1SEL[3:0]
0x68
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
Trigger TRGO
Internal clock (CK_INT) controller
TIMxCLK from RCC
Auto-reload register
U UI
Stop, clear or up
U
CK_PSC PSC CK_CNT
+ CNT counter
prescaler
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 the TIMx_PSC 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
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MS31085V2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UIFRE
Res. Res. Res. Res. Res. Res. Res. ARPE Res. Res. Res. OPM URS UDIS CEN
MAP
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. MMS[2:0] 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. Res. UDE Res. Res. Res. Res. Res. Res. Res. 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. Res. Res. Res. Res. Res. Res. Res. Res. Res. UIF
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. Res. Res. Res. Res. Res. Res. Res. Res. UG
w
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
0x2C
0x0C
0x18-
Offset
520/989
17.4.9
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
0
Res. Res. UIFCPY or Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. 30
Basic timers (TIM6/TIM7)
RM0454 Rev 5
17
Reserved
Reserved
1
0
0
Res. Res. Res. Res. Res. 15
1
0
0
Res. Res. Res. Res. Res. 14
1
0
0
Res. Res. Res. Res. Res. 13
1
0
0
Res. Res. Res. Res. Res. 12
1
0
0
0
1
0
0
Res. Res. Res. Res. Res. 10
1
0
0
Res. Res. Res. Res. Res. 9
1
0
0
0
PSC[15:0]
CNT[15:0]
ARR[15:0]
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
1
0
0
0
0
0
0
TIMx registers are mapped as 16-bit addressable registers as described in the table below:
RM0454
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 18.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 176 and Figure 177 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 176. 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 177. 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 182. 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 183. 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
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MS31085V2
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
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
URS
CEN
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
546/989
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
RM0454 Rev 5
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
RM0454
RM0454 General-purpose timers (TIM15/TIM16/TIM17)
Internal sources
SBIF
BIF
BRK request
TIMx_BKIN Break circuitry(1)
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
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 19.4.23: 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.8: 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 192 and Figure 193 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 192. 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 193. 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 198. 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 199. 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 200. 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
only by software (except UG which remains cleared automatically). As soon as the CEN bit
is written to 1, the prescaler is clocked by the internal clock CK_INT.
Figure 201 shows the behavior of the control circuit and the upcounter in normal mode,
without prescaler.
Internal clock
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MS31085V2
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
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
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.
already high, then the over-capture flag CCxOF (TIMx_SR register) is set. CCxIF can be
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.
For example, one can measure the period (in TIMx_CCR1 register) and the duty cycle (in
TIMx_CCR2 register) of the PWM applied on TI1 using the following procedure (depending
on CK_INT frequency and prescaler value):
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 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 ‘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 100 in the
TIMx_SMCR register.
8. Enable the captures: write the CC1E and CC2E bits to ‘1’ in the TIMx_CCER register.
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.
Anyway, the comparison between the TIMx_CCRx shadow register and the counter is still
performed and allows the flag to be set. Interrupt and DMA requests can be sent
accordingly. This is described in the output compare mode section below.
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 209.
OC1REF= OC1
MS31092V1
‘1’. If the compare value is 0 then OCxRef is held at ‘0’. Figure 210 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
OC2’
OC1’
OC2
OC1
OC1REF
OC2REF
OC1REF’
OC2REF’
OC1REFC
OC1REFC’
MS31094V1
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 213. Dead-time waveforms with delay greater than the negative pulse.
OCxREF
OCx
delay
OCxN
MS31096V1
Figure 214. 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 19.6.14: TIMx break and dead-time
register (TIMx_BDTR)(x = 16 to 17) on page 625 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 to enable /disable the outputs 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 81:
Output control bits for complementary OCx and OCxN channels with break feature
(TIM15) on page 601 for more details.
When exiting from reset, the break circuit is disabled and the MOE bit is low. The break
function is enabled by setting the BKE bit in the TIMx_BDTR register. The break input
polarity can be selected by configuring the BKP bit in the same register. BKE and BKP can
be modified at the same time. When the BKE and BKP 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.
A programmable filter (BKF[3:0] bits in the TIMx_BDTR register allows to filter out spurious
events.
The break can be generated from multiple sources which can be individually enabled and
with programmable edge sensitivity, using the TIMx_AF1 register.
The sources for break (BRK) channel are:
• An external source connected to one of the BKIN pin (as per selection done in the
AFIO controller), with polarity selection and optional digital filtering
• An internal source:
– A system break:
- the Cortex®-M0+ LOCKUP output
- the SRAM parity error signal
- a Flash ECC error
- a clock failure event generated by the CSS detector
Lockup LOCK
Core Lockup
System break requests
SBIF flag
Parity LOCK
RAM parity Error
ECC LOCK
ECC 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 internal PLL and/or 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 AFIO controller (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 AFIO controller) 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 AFIO
controller 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: 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 19.6.14: TIMx break and dead-time register (TIMx_BDTR)(x = 16 to 17) on
page 625. The LOCK bits can be written only once after an MCU reset.
The Figure 216 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
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).
TRGI
Counter
Output
MS33106V1
the counter value and a potential roll-over condition signaled by the UIFCPY flag, to be
atomically read. In particular cases, it can ease the calculations 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 assertions of the UIF and UIFCPY flags.
TI1
TI2
Counter
MS31400V1
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
TI2
cnt_en
Counter register 34 35 36 37 38
TIF
MS31403V1
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.
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
Res. Res. Res. Res. Res. Res. Res. Res. MSM TS[2:0] Res. SMS[2:0]
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
COMD
Res. TDE Res. Res. CC2DE CC1DE UDE BIE TIE COMIE Res. Res. CC2IE CC1IE UIE
E
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
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
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
OC2 OC2 OC1 OC1
Res. OC2M[2:0] CC2S[1:0] Res. OC1M[2:0] CC1S[1:0]
PE FE PE FE
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. CC2NP Res. CC2P CC2E CC1NP CC1NE CC1P CC1E
rw rw rw rw rw rw rw
Table 81. Output control bits for complementary OCx and OCxN channels with break feature
(TIM15)
Control bits Output states(1)
MOE bit OSSI bit OSSR bit CCxE bit CCxNE bit OCx output state OCxN output state
Output Disabled (not driven by the timer: Hi-Z)
X 0 0 OCx=0
OCxN=0, OCxN_EN=0
Output Disabled (not driven
OCxREF + Polarity
0 0 1 by the timer: Hi-Z)
OCxN=OCxREF XOR CCxNP
OCx=0
Output Disabled (not driven by
OCxREF + Polarity
0 1 0 the timer: Hi-Z)
OCx=OCxREF XOR CCxP
1 X OCxN=0
OCREF + Polarity + dead- Complementary to OCREF (not
X 1 1
time OCREF) + Polarity + dead-time
Off-State (output enabled
OCxREF + Polarity
1 0 1 with inactive state)
OCxN=OCxREF XOR CCxNP
OCx=CCxP
OCxREF + Polarity Off-State (output enabled with
1 1 0 OCx=OCxREF xor CCxP, inactive state)
OCx_EN=1 OCxN=CCxNP, OCxN_EN=1
0 X X
Output disabled (not driven by the timer: Hi-Z)
0 0
0 1 Off-State (output enabled with inactive state)
0 X
1 1 0 Asynchronously: OCx=CCxP, OCxN=CCxNP
Then if the clock is present: OCx=OISx and OCxN=OISxN
1 1 after a dead-time, assuming that OISx and OISxN do not
correspond to OCX and OCxN both in active state
1. When both outputs of a channel are not used (control taken over by GPIO controller), the OISx, OISxN, CCxP and CCxNP
bits must be kept cleared.
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 AFIO 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
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.
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. TI2SEL[3:0] Res. Res. Res. Res. TI1SEL[3:0]
rw rw rw rw rw rw rw rw
0x0C
Offset
RM0454
19.5.21
name
TIM15_SR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIM15_CR2
TIM15_CR1
TIM15_EGR
TIM15_DIER
TIM15_SMCR
below:
Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. 26
0001: Reserved
0001: Reserved
0010: TIM3_IC1
0010: TIM3_IC2
Others: Reserved
Others: Reserved
0
Res. Res. Res. Res. Res. 21
TS
[4:3]
0
Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. 19
Bits 7:4 Reserved, must be kept at reset value.
RM0454 Rev 5
0
Res. Res. Res. SMS[3] Res. Res. 16
Res. Res. Res. Res. Res. Res. 15
0
Res. Res. TDE Res. Res. Res. 14
0
Res. Res. COMDE Res. Res. Res. 13
Res. Res. Res. Res. Res. Res. 12
0
Res. Res. Res. Res. Res. UIFREMA 11
0
0
0
Table 82. TIM15 register map and reset values
0
0
0
0
Res. CC1OF CC1DE Res. OIS1N 9
[1:0]
CKD
0
0
0
Res. Res. UDE Res. OIS1 8
0
0
0
0
0
0
BG BIF BIE MSM TI1S ARPE 7
0
0
0
0
0
TG TIF TIE Res. 6
0
0
0
0
0
COMG COMIF COMIE Res. 5
TS[2:0]
0
0
MMS[2:0]
Res. Res. Res. Res. 4
0
0
0
0
0
0
0
0
TIM15 registers are mapped as 16-bit addressable registers as described in the table
0
0
0
0
0
0
0
0
0
0
0
SMS[2:0]
UG UIF UIE CCPC CEN 0
General-purpose timers (TIM15/TIM16/TIM17)
609/989
633
0x48
0x44
0x38
0x34
0x30
0x28
0x24
0x20
0x18
0x2C
Offset
610/989
mode
Output
name
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIM15_PSC
TIM15_CNT
TIM15_DCR
TIM15_RCR
TIM15_ARR
Input Capture
TIM15_CCR2
TIM15_CCR1
TIM15_BDTR
TIM15_CCER
Compare mode
TIM15_CCMR1
TIM15_CCMR1
0
Res. Res. Res. Res. Res. Res. Res. UIFCPY or 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
0
Res. BKBID Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
0
Res. BKDSRM Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. OC2M[3] 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
General-purpose timers (TIM15/TIM16/TIM17)
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
BKF[3:0]
RM0454 Rev 5
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. OC1M[3] 16
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
IC2F[3:0]
OC2M
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
[1:0]
PSC
0
0
0
1
0
0
0
0
0
0
0
1
0
0
0
0
DBL[4:0]
Res. Res. 9
[1:0]
[1:0]
[1:0]
0
0
0
1
0
0
0
0
CC2S
CC2S
LOCK
Res. Res. 8
Table 82. TIM15 register map and reset values (continued)
0
0
0
1
0
0
0
0
0
ARR[15:0]
CCR2[15:0]
CCR1[15:0]
0
0
0
1
0
0
0
0
0
Res. Res. 6
0
0
0
1
0
0
0
0
0
0
Res. CC2P 5
[2:0]
IC1F[3:0]
OC1M
0
0
0
1
0
0
0
0
0
0
CC2E 4
0
0
0
1
0
0
0
0
0
0
REP[7:0]
CC1NP OC1PE 3
DTG[7:0]
IC1
[1:0]
PSC
0
0
0
1
0
0
0
0
0
0
CC1NE OC1FE 2
0
0
0
1
0
0
0
0
0
0
0
DBA[4:0]
CC1P 1
[1:0]
[1:0]
0
0
0
0
0
0
1
0
0
0
0
CC1S
CC1S
CC1E 0
RM0454
RM0454 General-purpose timers (TIM15/TIM16/TIM17)
Register
Offset
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIM15_DMAR DMAB[15:0]
0x4C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKINP
BKINE
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.
TIM15_AF1
0x60
Reset value 0 1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIM15_TISEL TI2SEL[3:0] TI1SEL[3:0]
0x68
Reset value 0 0 0 0 0 0 0 0
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 83. 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 AFIO 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
632/989
19.6.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
General-purpose timers (TIM15/TIM16/TIM17)
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
RM0454 Rev 5
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 84. 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
RM0454
0x4C
Offset
RM0454
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
0
RM0454 Rev 5
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
General-purpose timers (TIM15/TIM16/TIM17)
633/989
0
633
Infrared interface (IRTIM) RM0454
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, USART4 (on STM32G070/B0xx) or USART2
(STM32G030/50xx), TIM16 and TIM17 as shown in Figure 224.
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.
TIM17_CH1
IRTIM
IR_OUT
TIM16_CH1
USART1
USART4(1)
IR_MOD[1:0] IR_POL
MS44790V2
21.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 22 on page
644.
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
21.4.6
RM0454
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
Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res.
IWDG register map
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.
RM0454 Rev 5
17
Res. Res. Res. Res. Res. 16
0
Res. Res. 11
Table 85. 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 44 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
Independent watchdog (IWDG)
643/989
0
643
System window watchdog (WWDG) RM0454
22.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 becomes cleared. An MCU
reset is also generated if the 7-bit down-counter value (in the control register) is refreshed
before the down-counter has reached 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 which require the watchdog to react within an
accurate timing window.
WWDG
Register interface CMP = 1 when
W[6:0] T[6:0] > W[6:0]
APB bus
WWDG_CFR
CMP
wwdg_out_rst
WWDG_SR WDGA
Write to WWDG_CR
T[6:0] T6
= 0x40 ?
readback
Logic
WWDG_CR T[6:0] EWI wwdg_it
cnt_out EWIF
preload
7-bit DownCounter (CNT)
MS47214V1
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, lets assume APB frequency is equal to 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 the 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
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
WDGA
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
WWDG_CR Res. T[6:0]
0x000
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
23.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).
The RTC is functional in VBAT mode.
rtc_tamp_evt
rtc_its TSF
Time stamp detection
RTC_TS
Time stamp registers
RTC_TSTR
RTC_TSDR
RTC_TSSR
RTC_REFIN
CALIB
RTC_OUT1
TAMP Output
TAMPALARM
TAMPOE control
RTC_OUT2
ALARM
ck_wut RTC_WUTR
WUTF OSEL[1:0]
rtc_wut_trg
16-bit wakeup =0
auto reload timer
ck_wut clock domain
Alarm A ALRAF
rtc_alra_trg
RTC_ALRMAR =
RTC_ALRMASSR
Alarm B ALRBF
rtc_alrb_trg
RTC_ALRMBR =
RTC_ALRMBSSR
rtc_it
IRQ interface
rtc_pclk
Registers interface
rtc_pclk clock domain
MSv47411V2
• 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 OR between TAMP and ALARM outputs.
ALARM is enabled by configuring the OSEL[1:0] bits in the RTC_CR register which select
the alarm A, alarm B or wakeup outputs. TAMP is enabled by setting the TAMPOE bit in the
RTC_CR register which selects the tamper event outputs.
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). Some functions are not available
in some low-power modes or VBAT when the selected clock is not LSE. Refer to
Section 23.4: RTC low-power modes for more details.
TAMPALRM_TYPE
TAMPALRM_PU
OSEL[1:0]
TAMPOE
OUT2EN
TAMP1E
COE
TSE
PC13 Pin function
01 or
10 or 0
11
TAMPALRM output Don’t Don’t Don’t Don’t
00 1 0 0
Push-Pull care care care care
01 or
10 or 1
11
TAMPALRM_TYPE
TAMPALRM_PU
OSEL[1:0]
TAMPOE
OUT2EN
TAMP1E
COE
TSE
PC13 Pin function
01 or
10 or 0
11
Don’t Don’t Don’t Don’t
No pull 00 1 1 0
care care care care
01 or
10 or 1
TAMPALRM 11
output
Open-Drain(2) 01 or
10 or 0
11
Internal Don’t Don’t Don’t Don’t
00 1 1 1
pull-up care care care care
01 or
10 or 1
11
Don’t Don’t Don’t Don’t
CALIB output PP 00 0 1 0
care care care care
Don’t
00 0 0
care
Don’t Don’t
TAMP_IN1 input floating 00 0 1 1 0
care care
Don’t Don’t 1
0
care care
Don’t
00 0 0
care
RTC_TS and TAMP_IN1 Don’t Don’t
00 0 1 1 1
input floating care care
Don’t Don’t 1
0
care care
Don’t
00 0 0
care
Don’t Don’t
RTC_TS input floating 00 0 1 0 1
care care
Don’t Don’t 1
0
care care
TAMPALRM_TYPE
TAMPALRM_PU
OSEL[1:0]
TAMPOE
OUT2EN
TAMP1E
COE
TSE
PC13 Pin function
Don’t
00 0 0
care
Wakeup pin or Standard Don’t Don’t
00 0 1 0 0
GPIO care care
Don’t Don’t 1
0
care care
1. OD: open drain; PP: push-pull.
2. In this configuration the GPIO must be configured in input.
In addition, it is possible to output RTC_OUT2 on PA4 pin thanks to OUT2EN bit. This
output is not available in VBAT mode. The different functions are mapped on RTC_OUT1 or
on RTC_OUT2 depending on OSEL, COE and OUT2EN configuration, as show in table
Table 91.
For PA4, the GPIO should be configured as an alternate function.
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 )
The ck_spre clock can be used either to update the calendar or as timebase for the 16-bit
wakeup auto-reload timer. To obtain short timeout periods, the 16-bit wakeup auto-reload
timer can also run with the RTCCLK divided by the programmable 4-bit asynchronous
prescaler (see Section 23.3.7: Periodic auto-wakeup for details).
BYPSHAD control bit in the RTC_CR register. By default, this bit is cleared, and the user
accesses the shadow registers.
When reading the RTC_SSR, RTC_TR or RTC_DR registers in BYPSHAD = 0 mode, the
frequency of the APB clock (fAPB) must be at least 7 times the frequency of the RTC clock
(fRTCCLK).
The shadow registers are reset by system reset.
the RTC_SR register, and the wakeup counter is automatically reloaded with its
reload value (RTC_WUTR register value).
The WUTF flag must then be cleared by software.
When the periodic wakeup interrupt is enabled by setting the WUTIE bit in the RTC_CR
register, it can exit the device from low-power modes.
The periodic wakeup flag can be routed to the TAMPALRM output provided it has been
enabled through bits OSEL[1:0] of RTC_CR register. TAMPALRM output polarity can be
configured through the POL bit in the RTC_CR register.
System reset, as well as low-power modes (Sleep, Stop and Standby) have no influence on
the wakeup timer.
1. Set INIT bit to 1 in the RTC_ICSR register to enter initialization mode. In this mode, the
calendar counter is stopped and its value can be updated.
2. Poll INITF bit of in the RTC_ICSR register. The initialization phase mode is entered
when INITF is set to 1. It takes around 2 RTCCLK clock cycles (due to clock
synchronization).
3. To generate a 1 Hz clock for the calendar counter, program both the prescaler factors
in RTC_PRER register.
4. Load the initial time and date values in the shadow registers (RTC_TR and RTC_DR),
and configure the time format (12 or 24 hours) through the FMT bit in the RTC_CR
register.
5. Exit the initialization mode by clearing the INIT bit. The actual calendar counter value is
then automatically loaded and the counting restarts after 4 RTCCLK clock cycles.
When the initialization sequence is complete, the calendar starts counting.
Note: After a system reset, the application can read the INITS flag in the RTC_ICSR register to
check if the calendar has been initialized or not. If this flag equals 0, the calendar has not
been initialized since the year field is set at its Backup domain reset default value (0x00).
To read the calendar after initialization, the software must first check that the RSF flag is set
in the RTC_ICSR register.
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.
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 calibration register (RTC_CALR) specifies the number of RTCCLK clock cycles
to be masked during the 32-second cycle:
• Setting the bit CALM[0] to 1 causes exactly one pulse to be masked during the 32-
second 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
32-second cycle. Setting the bit CALM[0] to 1 causes exactly one pulse to be masked during
the 32-second 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 32-second cycle.
Using CALM together with CALP, an offset ranging from -511 to +512 RTCCLK cycles can
be added during the 32-second 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)]
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.
When the TAMPOE control bit is set is the RTC_CR, all external and internal tamper flags
are ORed and routed to the TAMPALRM output. If OSEL = 00 the TAMPALRM output
reflects only the tampers flags. If OSEL ≠ 00, the signal on TAMPALRM provides both
tamper flags and alarm A, B, or wakeup flag.
The polarity of the TAMPALRM output is determined by the POL control bit in RTC_CR so
that the opposite of the selected flags bit is output when POL is set 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.
When TAMPALRM output is selected, the RTC_OUT1 pin is automatically configured but
the RTC_OUT2 pin must be set as alternate function. 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.
The RTC remains active when the RTC clock source is LSE or LSI. RTC interrupts
Standby
cause the device to exit the Standby mode.
The table below summarizes the RTC pins and functions capability in all modes.
write 1 in
Alarm A ALRAF ALRAIE Yes Yes(3)
CALRAF
write 1 in
Alarm B ALRBF ALRBIE Yes Yes(3)
CALRBF
RTC
write 1 in
Timestamp TSF TSIE Yes Yes(3)
CTSF
Wakeup timer write 1 in
WUTF WUTIE Yes Yes(3)
interrupt CWUTF
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 and Standby modes 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
WUTW ALRB ALRAW
Res. Res. Res. Res. Res. Res. Res. Res. INIT INITF RSF INITS SHPF
F WF F
rw r rc_w0 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. 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
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
WUT[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
TAMP TAMP
OUT2 TAMP TAMP
ALRM_ ALRM_ Res. Res. ITSE COE OSEL[1:0] POL COSEL BKP SUB1H ADD1H
EN OE TS
TYPE PU
rw rw rw 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
ALRB ALRA BYP REFCK TS
TSIE WUTIE TSE WUTE ALRBE ALRAE Res. FMT WUCKSEL[2:0]
IE IE SHAD ON EDGE
rw rw rw rw rw rw rw 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).
WUT = wakeup unit counter value. WUT = (0x0000 to 0xFFFF) + 0x10000 added when
WUCKSEL[2:1 = 11].
Bits 2 to 0 of this register can be written only when RTC_CR WUTE bit = 0 and RTC_ICSR
WUTWF bit = 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
WDSE
MSK4 DT[1:0] DU[3:0] MSK3 PM HT[1:0] HU[3:0]
L
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
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. ITSF TSOVF TSF WUTF ALRBF ALRAF
r r r 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
ITS TSOV TS WUT ALRB ALRA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
MF MF MF MF MF MF
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
CITS CTSOV CTS CWUT CALRB CALRA
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
F F F F F F
w w w w w w
0x2C
0x0C
Offset
RM0454
23.6.21
RTC_TR
RTC_CR
RTC_DR
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
Reset value
RTC_TSDR
RTC_PRER
RTC_WUTR
RTC_ CALR
RTC_TSSSR
RTC_SHIFTR
0
0
Res. Res. Res. ADD1S Res. Res. OUT2EN Res. Res. Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. TAMPALRM_TYPE Res. Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. Res. TAMPALRM_PU Res. Res. Res. Res. Res. Res. 29
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. 27
0
Res. Res. Res. Res. Res. Res. TAMPOE Res. Res. Res. Res. Res. Res.
RTC register map
26
0
Res. Res. Res. Res. Res. Res. TAMPTS Res. Res. Res. Res. Res. Res. 25
0
Res. Res. Res. Res. Res. Res. ITSE Res. Res. Res. Res. Res. Res. 24
0
0
Res. Res. Res. Res. Res. Res. COE Res. 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
RM0454 Rev 5
17
YU[3:0]
HU[3:0]
HU[3:0]
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
1
0
WDU[1:0]
WDU[2:0]
0
0
0
0
1
0
0
0
0
MNT[2:0]
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
MU[3:0]
MU[3:0]
MNU[3:0]
MNU[3:0]
0
0
0
1
0
0
0
0
1
0
0
0
0
0
1
1
0
0
0
SS[15:0]
SS[15:0]
WUT[15:0]
0
0
0
0
0
1
1
0
0
0
SUBFS[14:0]
0
0
0
0
0
1
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
1
1
0
0
0
0
0
0
REFCKON INITS 4
0
0
0
0
0
1
1
0
0
0
0
0
0
TSEDGE SHPF
CALM[8:0]
3
KEY[7:0]
0
0
0
0
0
1
1
0
0
0
0
1
0
WUT WF 2
0
0
0
0
0
1
1
0
0
0
0
1
0
ALRBWF 1
SU[3:0]
SU[3:0]
DU[3:0]
DU[3:0]
WUCK
SEL[2:0]
0
1
1
1
0
0
0
0
0
0
1
0
ALRAWF 0
Real-time clock (RTC)
687/989
703
Real-time clock (RTC) RM0454
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
WDSEL
MSK4
MSK3
MSK2
MSK1
DT HT
PM
RTC_ALRMAR DU[3:0] HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
0x40 [1: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 0 0 0 0 0 0 0 0
RTC_ MASKSS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SS[14:0]
0x44 ALRMASSR [3:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
WDSEL
MSK4
MSK3
MSK2
MSK1
DT HT
PM
RTC_ALRMBR DU[3:0] HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
0x48 [1: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 0 0 0 0 0 0 0 0
RTC_ MASKSS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SS[14:0]
0x4C ALRMBSSR [3:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TSOVF
ALRBF
ALRAF
WUTF
ITSF
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.
TSF
RTC_SR
0x50
Reset value 0 0 0 0 0 0
TSOVMF
ALRBMF
ALRAMF
WUTMF
ITSMF
TSMF
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.
RTC_MISR
0x54
Reset value 0 0 0 0 0 0
CTSOVF
CALRBF
CALRAF
CWUTF
CITSF
CTSF
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.
RTC_SCR
0x5C
Reset value 0 0 0 0 0 0
24.1 Introduction
5 32-bit backup registers are retained in all low-power modes and also in VBAT mode. They
can be used to store sensitive data as their content is protected by an tamper detection
circuit. Up to 3 tamper pins and 4 internal tampers are available for anti-tamper detection.
The external tamper pins can be configured for edge detection, or level detection with or
without filtering.
TAMP1F
Tamper detection
TAMP_IN1
EDGE detection
tamp_trg1
LEVEL detection
TAMP2F
Tamper detection
TAMP_IN2
EDGE detection
tamp_trg2
LEVEL detection
...
...
LEVEL detection
ITAMP1F
ITAMP1F
ITAMPyF
ITAMPyF
TAMP1F
TAMPxF
tamp_ker_ck
tamp_evt
tamp_erase
tamp_it
IRQ interface
Backup registers
Registers interface
tamp_pclk
tamp_pclk clock domain
MSv43847V4
The TAMP 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). Some detections modes are
not available in some low-power modes or VBAT when the selected clock is not LSE (refer to
Section 24.4: TAMP low-power modes for more details.
This feature is available only when the tamper is configured in the Level detection with
filtering on tamper inputs (passive mode) mode (TAMPFLT ≠ 00 and active mode is not
selected).
No effect.
Sleep
TAMP interrupts cause the device to exit the Sleep mode.
No effect on all features, except for level detection with filtering mode which remain
Stop active only when the clock source is LSE or LSI.
Tamper events cause the device to exit the Stop mode.
No effect on all features, except for level detection with filtering mode which remain
Standby active only when the clock source is LSE or LSI.Tamper events cause the device to exit
the Standby mode.
Write 1 in
Tamper x(3) TAMPxF TAMPxIE Yes Yes(4)
CTAMPxF
TAMP
Internal Write 1 in
ITAMPyF ITAMPyIE Yes Yes(4)
tamper y(3) CITAMPxF
1. The event flags are in the TAMP_SR register.
2. The interrupt masked flags (resulting from event flags AND enable control bits) are in the TAMP_MISR
register.
3. The number of tampers and internal tampers events depend on products.
4. In case of level detection with filtering passive tamper mode, wakeup from Stop and Standby modes is
possible only when the TAMP clock source is LSE or LSI.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ITAMP6 ITAMP5 ITAMP4 ITAMP3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
E E E E
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP3 TAMP2 TAMP1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
E E E
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TAMP3 TAMP2 TAMP1 TAMP3 TAMP2 TAMP1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
TRG TRG TRG MSK MSK MSK
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP3 TAMP2 TAMP1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
NOER NOER NOER
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
TAMP TAMPPRCH TAMPFLT TAMPFREQ
Res. Res. Res. Res. Res. Res. Res. Res.
PUDIS [1:0] [1:0] [2:0]
rw rw rw rw rw rw rw rw
Note: This register concerns only the tamper inputs in passive mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ITAMP6 ITAMP5 ITAMP4 ITAMP3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
IE IE IE IE
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP TAMP TAMP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
3IE 2IE 1IE
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ITAMP6 ITAMP5 ITAMP4 ITAMP3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
F F F F
r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP TAMP TAMP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
3F 2F 1F
r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ITAMP6 ITAMP5 ITAMP4 ITAMP3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
MF MF MF MF
r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP TAMP TAMP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
3MF 2MF 1MF
r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
C C C C
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ITAMP ITAMP ITAMP ITAMP Res. Res.
6F 5F 4F 3F
w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CTAMP CTAMP CTAMP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
3F 2F 1F
w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BKP[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
BKP[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
0x3C
0x2C
0x0C
0 to 4)
0x04*x,
0x100 +
Offset
24.6.9
RM0454
TAMP_SR
TAMP_IER
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TAMP_CR2
TAMP_CR1
TAMP_SCR
TAMP_MISR
TAMP_FLTCR
TAMP_BKPxR
0
Res. Res. Res. Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. Res. Res. 29
0
Res. Res. Res. Res. Res. Res. Res. 28
0
Res. Res. Res. Res. Res. Res. Res. 27
0
0
Res. Res. Res. Res. Res. TAMP3TRG Res. 26
TAMP register map
0
0
Res. Res. Res. Res. Res. TAMP2TRG Res. 25
0
0
Res. Res. Res. Res. Res. TAMP1TRG Res. 24
0
Res. Res. Res. Res. Res. Res. Res. 23
0
Res. Res. Res. Res. Res. Res. Res. 22
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
Res.
RM0454 Rev 5
Res. Res. Res. Res. TAMP2MSK Res. 17
0
0
0
Res. Res. Res. Res. Res. Res. Res. 15
BKP[31:0]
0
Res. Res. Res. Res. Res. Res. Res. 14
0
Res. Res. Res. Res. Res. Res. Res. 13
0
Res. Res. Res. Res. Res. Res. Res. 12
0
Res. Res. Res. Res. Res. Res. Res. 11
Table 101. TAMP register map and reset values
0
Res. Res. Res. Res. Res. Res. Res. 10
0
Res. Res. Res. Res. Res. Res. Res. 9
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
703/989
Tamper and backup registers (TAMP)
703
Inter-integrated circuit (I2C) interface RM0454
25.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.
The following additional features are also available depending on the product
implementation (see Section 25.3: I2C implementation):
• SMBus specification rev 3.0 compatibility:
– Hardware PEC (Packet Error Checking) generation and verification with ACK
control
– Command and data acknowledge control
– Address resolution protocol (ARP) support
– Host and Device support
– SMBus alert
– Timeouts and idle condition detection
• PMBus rev 1.3 standard compatibility
• Independent clock: a choice of independent clock sources allowing the I2C
communication speed to be independent from the PCLK reprogramming
• Wakeup from Stop mode on address match.
If SMBus feature is supported: the additional optional SMBus Alert pin (SMBA) is also
available.
I2CCLK
I2c_ker_ck
Data control
Digital Analog
Shift register noise noise GPIO
filter I2C_SDA
filter logic
SMBUS
PEC
generation/
check
Wakeup
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 & I2C_SMBA
status
PCLK
I2c_pclk Registers
APB bus
MSv46198V2
The I2C1 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 25.3: I2C implementation.
I2CCLK
PCLK
Data control
Digital Analog
Shift register noise noise GPIO
filter I2C1_SDA
filter logic
SMBUS
PEC
generation/
check
Wakeup
on
address
match Clock control
Master clock
generation Digital Analog
noise noise
Slave clock GPIO I2C1_SCL
filter filter
stretching logic
SMBus
Timeout
check
SMBus Alert
control & I2C1_SMBA
status
Registers
APB bus
MSv46199V2
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 25.3: I2C implementation.
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 contain the address (one in 7-bit mode, two in 10-bit mode). The address
is always transmitted in Master mode.
A 9th clock pulse follows the 8 clock cycles of a byte transfer, during which the receiver must
send an acknowledge bit to the transmitter. Refer to the following figure.
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 analog filter is compliant with the I2C specification which requires the
suppression of spikes with a 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: Changing the filter configuration is not allowed when the I2C is enabled.
I2C timings
The timings must be configured in order to guarantee a correct data hold and setup time,
used 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 is inserted before sending
SDA output. This delay is tSDADEL = SDADEL x tPRESC + tI2CCLK where tPRESC = (PRESC+1)
x tI2CCLK.
TSDADEL impacts the hold time tHD;DAT.
In order 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 106: I2C-SMBus specification data setup and hold times for tr and tSU;DAT
standard values.
The SDA and SCL transition time values to be used 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, in case 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 in such a way to guarantee also 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] bits 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 .
Initial settings
Configure PRESC[3:0],
End
MS19847V2
Reception
The SDA input fills the shift register. After the 8th 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 8th and 9th
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 9th 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 9th SCL pulse.
data1
data2
Shift register xx xx xx
TXE
wr data1 wr data2
MS19849V1
By default, the slave uses its clock stretching capability, which means that it stretches the
SCL signal at low level when needed, in order to perform software actions. If the master
does not 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.
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
Slave
transmission
Slave initialization
No
No
I2C_ISR.TXIS I2C_ISR.STOPF
=1? =1?
Yes Yes
Set I2C_ICR.STOPCF
MS19852V2
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 241. Transfer sequence flowchart 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 242. Transfer sequence flowchart for slave receiver with NOSTRETCH=1
Slave reception
Slave initialization
No
No
I2C_ISR.RXNE I2C_ISR.STOPF
=1? =1?
Yes Yes
MS19856V2
SCL stretch
S Address A data1 A data2 A data3 A
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: In order to be I2C or SMBus compliant, the master clock must respect the timings given the
table below.
Note: SCLL is also used to generate the tBUF and tSU:STA timings.
SCLH is also used to generate the tHD:STA and tSU:STO timings.
Refer to Section 25.4.11: I2C_TIMINGR register configuration examples for examples of
I2C_TIMINGR settings vs. I2CCLK frequency.
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, when the ADDRCF bit is set.
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 9th
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 248. Transfer sequence flowchart 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 249. Transfer sequence flowchart 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 8th
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 251. Transfer sequence flowchart 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 252. Transfer sequence flowchart 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
PRESC 1 1 0 0
SCLL 0xC7 0x13 0x9 0x6
tSCLL 200x250 ns = 50 µs 20x250 ns = 5.0 µs 10x125 ns = 1250 ns 7x125 ns = 875 ns
SCLH 0xC3 0xF 0x3 0x3
tSCLH 196x250 ns = 49 µs 16x250 ns = 4.0µs 4x125 ns = 500 ns 4x125 ns = 500 ns
(1)
tSCL ~100 µs(2) ~10 µs(2) ~2500 ns(3) ~2000 ns(4)
SDADEL 0x2 0x2 0x1 0x0
tSDADEL 2x250 ns = 500 ns 2x250 ns = 500 ns 1x125 ns = 125 ns 0 ns
SCLDEL 0x4 0x4 0x3 0x1
tSCLDEL 5x250 ns = 1250 ns 5x250 ns = 1250 ns 4x125 ns = 500 ns 2x125 ns = 250 ns
1. SCL period tSCL is greater than tSCLL + tSCLH due to SCL internal detection delay. Values provided for tSCL are examples
only.
2. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 500 ns. Example with tSYNC1 + tSYNC2 = 1000 ns.
3. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 500 ns. Example with tSYNC1 + tSYNC2 = 750 ns.
4. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 500 ns. Example with tSYNC1 + tSYNC2 = 655 ns.
PRESC 3 3 1 0
SCLL 0xC7 0x13 0x9 0x4
tSCLL 200 x 250 ns = 50 µs 20 x 250 ns = 5.0 µs 10 x 125 ns = 1250 ns 5 x 62.5 ns = 312.5 ns
SCLH 0xC3 0xF 0x3 0x2
tSCLH 196 x 250 ns = 49 µs 16 x 250 ns = 4.0 µs 4 x 125 ns = 500 ns 3 x 62.5 ns = 187.5 ns
(1)
tSCL ~100 µs(2) ~10 µs(2) ~2500 ns(3) ~1000 ns(4)
SDADEL 0x2 0x2 0x2 0x0
tSDADEL 2 x 250 ns = 500 ns 2 x 250 ns = 500 ns 2 x 125 ns = 250 ns 0 ns
SCLDEL 0x4 0x4 0x3 0x2
tSCLDEL 5 x 250 ns = 1250 ns 5 x 250 ns = 1250 ns 4 x 125 ns = 500 ns 3 x 62.5 ns = 187.5 ns
1. SCL period tSCL is greater than tSCLL + tSCLH due to SCL internal detection delay. Values provided for tSCL are examples
only.
2. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 250 ns. Example with tSYNC1 + tSYNC2 = 1000 ns.
3. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 250 ns. Example with tSYNC1 + tSYNC2 = 750 ns.
4. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 250 ns. Example with tSYNC1 + tSYNC2 = 500 ns.
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. 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 should be
implemented by the user software.
For more details of 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.
Timeouts
This peripheral embeds hardware timers in order to be compliant with the 3 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
In order to enable the tTIMEOUT check, the 12-bit TIMEOUTA[11:0] bits must be
programmed with the timer reload value in order to check the tTIMEOUT parameter. The
TIDLE bit must be configured to ‘0’ in order 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 114: Examples of TIMEOUTA settings for various I2CCLK frequencies
(max tTIMEOUT = 25 ms).
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 on page 742 section, the TIMEOUT flag is set in the I2C_ISR register.
Refer to Table 115: Examples of TIMEOUTB settings for various I2CCLK frequencies
Caution: Changing the TIMEOUTB configuration is not allowed when the TEXTEN bit is set.
Figure 255. Transfer sequence flowchart 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 256. 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 257. Transfer sequence flowchart 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 258. 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 SMBus feature is supported. Refer to Section 25.3: I2C
implementation.
In addition to I2C master transfer management (refer to Section 25.4.10: I2C master mode)
some additional software flowcharts are provided to support SMBus.
When the SMBus master wants to send a RESTART condition after the PEC, software
mode must be selected (AUTOEND=0). In this case, once NBYTES-1 have been
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
Alert (ALERT)
This section is relevant only when the SMBus feature is supported. Refer to Section 25.3:
I2C implementation.
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.
DMA must be initialized before setting the START bit. The end of transfer is managed
with the NBYTES counter.
• In slave mode with NOSTRETCH=0, when all data are transferred using DMA, the
DMA must be initialized before the address match event, or in the ADDR interrupt
subroutine, before clearing the ADDR flag.
• If SMBus is supported (see Section 25.3: I2C implementation): the PEC transfer is
managed with the NBYTES counter. Refer to SMBus Slave receiver on page 747 and
SMBus Master receiver on page 751.
Note: If DMA is used for reception, the RXIE bit does not need to be enabled.
Sleep No effect. I2C interrupts cause the device to exit the Sleep mode.
The I2C registers content is kept. If WUPEN = 1 and I2C is clocked by an internal
oscillator (HSI16): the address recognition is functional. The I2C address match
Stop(1)
condition causes the device to exit the Stop mode. If WUPEN=0: the I2C must be
disabled before entering Stop mode
The I2C peripheral is powered down and must be reinitialized after exiting
Standby
Standby mode.
1. Refer to Section 25.3: I2C implementation for information about the Stop modes supported by each
instance. If wakeup 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 AUTOE RE
Res. Res. Res. Res. Res. NBYTES[7:0]
BYTE ND 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
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 25.3: I2C implementation.
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 25.3: I2C implementation.
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
0xC
0x24
0x20
0x18
0x14
0x10
0x1C
Offset
RM0454
25.7.12
I2C_
I2C_
name
I2C_ISR
I2C_ICR
I2C_CR2
I2C_CR1
TIMINGR
I2C_PECR
I2C_OAR2
I2C_OAR1
I2C_RXDR
Register
TIMEOUTR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
0
0
Res. Res. Res. Res. TEXTEN Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
0
PRESC[3:0]
Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
0
I2C register map
0
0
Res. Res. Res. Res. Res. Res. Res. PECBYTE Res. 26
0
0
Res. Res. Res. Res. Res. Res. Res. AUTOEND Res. 25
0
0
Res. Res. Res. Res. Res. Res. Res. RELOAD Res. 24
0
0
0
0
0
0
0
0
0
0
[3:0]
0
0
0
0
0
SCLDEL
0
0
0
0
0
TIMEOUTB[11:0]
0
0
0
0
0
ADDCODE[6:0]
0
0
0
0
0
NBYTES[7:0]
RM0454 Rev 5
[3:0]
0
0
0
0
0
SDADEL
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res. Res. ALERTCF ALERT Res. Res. Res. START Res. 13
0
0
0
0
0
0
Res. Res. TIMOUTCF TIMEOUT TIDLE Res. Res. HEAD10R ANFOFF 12
0
0
0
0
0
0
Res. Res. PECCF PECERR Res. Res. ADD10 11
Table 119. I2C register map and reset values
SCLH[7:0]
0
0
0
0
0
0
0
0
The table below provides the I2C register map and reset values.
0
0
0
0
0
0
0
0
Res. Res. ARLOCF ARLO 9
DNF[3:0]
K [2:0]
OA2MS
0
0
0
0
0
0
0
0
Res. Res. BERRCF BERR 8
0
0
0
0
0
0
0
0
0
Res. TCR ERRIE 7
0
0
0
0
0
0
0
0
0
Res. TC TCIE 6
0
0
0
0
0
0
0
0
0
0
STOPCF STOPF STOPIE 5
0
0
0
0
0
0
0
0
0
0
NACKCF NACKF NACKIE 4
OA1[9:0]
TIMEOUTA[11:0]
SADD[9:0]
OA2[7:1]
0
0
0
0
0
0
0
0
0
0
ADDRCF ADDR ADDRIE 3
PEC[7:0]
SCLL[7:0]
0
0
0
0
0
0
0
0
0
RXDATA[7:0]
Res. RXNE RXIE 2
0
0
0
0
0
0
0
0
0
Res. TXIS TXIE 1
1
0
0
0
0
0
0
0
0
773/989
Inter-integrated circuit (I2C) interface
774
Inter-integrated circuit (I2C) interface RM0454
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
I2C_TXDR TXDATA[7:0]
0x28
Reset value 0 0 0 0 0 0 0 0
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 261 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 SCLK 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 263). It is
not possible to transmit long breaks (break of length greater than 9/10/11 low bits).
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 262).
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 state
Idle Start bit
RX line
Ideal
sample 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
clock
Sampled values
Real
sample X X X X X X X X 9 10 11 12 13 14 15 16
clock
6/16
7/16 7/16
One-bit time
Conditions
to validate 1 1 1 0 X 0 X 0 X 0 0 0 0 X X 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 26.5.10: USART
multiprocessor communication.
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 wakeup 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 267 and
Figure 268).
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 26.5.8: Tolerance of the USART receiver to clock deviation on
page 795)
• 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 wakeup 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 123, Table 124, 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 123. 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 124. 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 123 and Table 124 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 26.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 271: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 804.
Examples of break frames are given on Figure 272: Break detection in LIN mode vs.
Framing error detection on page 805.
Figure 271. 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 272. Break detection in LIN mode vs. Framing error detection
RXNE /FE
LBDF
RXNE /FE
LBDF
MSv31157V1
Note: In master mode, the SCLK 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
(e.g. slave SPI)
SCLK Clock
MSv31158V1
Figure 274. 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 275. 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 SCLK 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 276).
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 276. 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 SCLK transmission edge. To avoid this underrun error, the USART_TDR
should be written 3 usart_ker_ck cycles before the first SCLK 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 278 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 278. 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 SCLK output. In Smartcard
mode, SCLK 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. SCLK 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.
nRTS
MSv31168V1
Note: When FIFO mode is enabled, nRTS is deasserted only when RXFIFO is full.
CTS CTS
nCTS
Note: For correct behavior, nCTS must be asserted 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 wakeup 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 286 shows the USART behavior when the wakeup event is verified.
Figure 286. Wakeup event verified (wakeup 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 287 shows the USART behavior when the wakeup event is not verified.
Figure 287. Wakeup event not verified (wakeup 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 wakeup
event. If the wakeup event is the start bit detection, the USART sends the wakeup 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 wakeup time parameter (refer to the device datasheet) and on the USART
receiver tolerance (see Section 26.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 123: 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 wakeup 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 HSI is used as usart_ker_ck, and the HSI 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 wakeup 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 26.4: USART implementation to know if the wakeup 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 Wakeup from Stop mode
feature. Refer to Section 26.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
OVER8 CMIE MME M0 WAKE PCE PS PEIE TXFNFIE TCIE RXFNEIE IDLEIE TE RE UESM UE
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
OVER8 CMIE MME M0 WAKE PCE PS PEIE TXEIE TCIE RXNEIE IDLEIE TE RE UESM UE
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
ADD[7:0] RTOEN ABRMOD[1:0] ABREN DATAINV TXINV RXINV
RST
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 wakeup from Stop feature, this bit is reserved and
must be kept at reset value. Refer to Section 26.4: USART implementation on
page 777.
Bits 21:20 WUS[1:0]: Wakeup from low-power mode interrupt flag selection
This bitfield specifies the event which activates the WUF (Wakeup 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 wakeup from Stop feature, this bit is reserved and
must be kept at reset value. Refer to Section 26.4: USART implementation on
page 777.
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 26.4: USART implementation on page 777.
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 26.4: USART implementation on page 777.
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 26.4: USART implementation on page 777.
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 26.4: USART implementation on page 777.
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 26.4: USART implementation on page 777.
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. TXFRQ RXFRQ MMRQ SBKRQ ABRRQ
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
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
Res. Res. UDRCF EOBCF RTOCF Res. CTSCF LBDCF TCCF IDLECF ORECF NECF FECF PECF
CF 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
RM0454
26.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
USART_ISR
USART_ISR
USART_ICR
USART_CR3
USART_CR2
USART_CR1
USART_CR1
USART_BRR
FIFO enabled
USART_RQR
FIFO disabled
USART_GTPR
USART_RTOR
31
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. RXFFIE
30
0
0
0
0
Res. Res. Res. Res. Res. Res. TXFTCFG[2:0] Res. TXFEIE
29
0
0
0
0
0
Res. Res. Res. Res. Res. Res. FIFOEN FIFOEN
28
0
0
0
0
0
Res. Res. Res. Res. Res. Res. RXFTIE M1 M1
27
0
0
0
0
0
Res. Res. TXFT Res. Res. Res. EOBIE EOBIE
ADD[7:0]
BLEN[7:0]
26
0
0
0
0
0
Res. Res. RXFT Res. Res. Res. RXFTCFG[2:0] RTOIE RTOIE
25
0
0
0
0
0
0
Res. TCBGT TCBGT Res. Res. Res.
USART register map
24
0
0
0
0
0
X X X X
Res. Res. RXFF Res. Res. Res. TCBGTIE
23
0
0
0
0
0
1
Res. Res. TXFE Res. Res. Res. TXFTIE RTOEN
22
0
0
0
0
0
0
0
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. TEACK TEACK Res. Res. Res.
[1:0]
20
0
0
0
0
0
0
0
0
WUS
WUCF WUF WUF Res. Res. Res. ABREN
19
0
0
0
0
0
0
0
Res. RWU RWU Res. Res. Res. MSBFIRST
18
0
0
0
0
0
0
0
Res. SBKF SBKF Res. Res. Res. DATAINV
SCAR
17
CNT2:0]
0
0
0
0
0
0
0
0
CMCF CMF CMF Res. Res. Res. TXINV
DEDT[4:0]
DEDT[4:0]
RM0454 Rev 5
16
0
0
0
0
0
0
Res. BUSY BUSY Res. Res. Res. Res. RXINV
15
0
0
0
0
0
0
0
0
0
Res. ABRF ABRF Res. DEP SWAP OVER8 OVER8
14
0
0
0
0
0
0
0
0
0
Res. ABRE ABRE Res. DEM LINEN CMIE CMIE
13
0
0
0
0
0
0
0
0
0
0
UDRCF UDR UDR Res. DDRE MME MME
[1:0]
12
0
0
0
0
0
0
0
0
0
0
EOBCF EOBF EOBF Res. OVRDIS M0 M0
STOP
11
0
0
0
0
0
0
0
0
0
0
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. CTS CTS Res. CTSIE CPOL PCE PCE
Table 128. 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
CTSCF CTSIF CTSIF Res. CTSE CPHA PS PS
8
0
0
0
0
0
0
0
0
0
0
LBDCF LBDF LBDF Res. RTSE LBCL PEIE PEIE
7
0
0
0
1
1
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
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
861/989
Universal synchonous receiver transmitter (USART)
862
Universal synchonous receiver transmitter (USART) RM0454
Register
Offset
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
name
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.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
USART_RDR RDR[8:0]
0x24
Reset value 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.
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.
27.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 27.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 27.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 1kΩ (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 27.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_CR2 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 27.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 27.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. OVF
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 295, 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 296. 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 27.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 27.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 297 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 298 on page 880 through Figure 301
on page 883:
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.
27.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 303). 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 303: 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
tr i
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 309. 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 310 is required.
Figure 310. Example of 16-bit data frame extended to 32-bit channel frame
Only one access to SPIx_DR
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 319 is required.
Figure 319. 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 321. 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 324 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.
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 27.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 27.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 27.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 27.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 27.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 27.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 27.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
BIDIM CRCE CRCN RXONL LSBFIR
BIDIOE CRCL SSM SSI SPE BR[2:0] MSTR CPOL CPHA
ODE N EXT Y ST
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
0x1C
0x0C
Offset
RM0454
27.9.10
SPIx_SR
SPIx_DR
SPIx_CR2
SPIx_CR1
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
SPIx_I2SPR
SPIx_CRCPR
SPIx_TXCRCR
SPIx_RXCRCR
SPIx_I2SCFGR
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
SPI/I2S register map
RM0454 Rev 5
Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
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 133 shows the SPI/I2S register map and reset values.
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
Res. I2SE
FRLVL[1:0]
RXONLY 10
0
0
0
0
0
0
0
0
1
MCKOE SSM 9
DS[3:0]
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
PCMSYNC BSY TXEIE LSBFIRST 7
DR[15:0]
0
0
0
0
0
0
0
0
TXCRC[15:0]
RXCRC[15:0]
0
0
0
0
0
0
0
0
0
MODF ERRIE 5
I2SSTD
0
0
0
0
0
0
0
0
0
CRCERR FRF 4
BR [2:0]
0
0
0
0
0
0
0
0
0
I2SDIV[7:0]
0
0
1
0
0
0
0
0
0
1
0
TXE TXDMAEN CPOL 1
0
0
1
0
0
0
0
0
0
CHLEN RXNE RXDMAEN CPHA 0
Serial peripheral interface / integrated interchip sound (SPI/I2S)
919/989
919
Universal serial bus full-speed host/device interface (USB) RM0454
28.1 Introduction
The USB peripheral implements an interface between a full-speed USB 2.0 bus and the
APB1 bus.
USB suspend/resume are supported, which permits to stop the device clocks for low-power
consumption.
Host mode X
Number of endpoints 8
Size of dedicated packet buffer memory SRAM 2048 bytes
Dedicated packet buffer memory SRAM access scheme 32 bits
USB 2.0 Link Power Management (LPM) support in device X
Battery Charging Detection (BCD) support for device X
Embedded pull-up resistor on USB_DP line X
1. X= supported
DP DM NOE
USB PHY
USB clock (48 MHz)
Suspend timer
Control
RX-TX Clock recovery
registers and logic
Endpoint/
Control
channel Interrupt
selection registers and logic
S.I.E.
Register
Register Interrupt
Arbiter Packet buffer mapper
mapper mapper
memory
APB wrapper
APB interface
Each endpoint/channel is associated with a buffer description block indicating where the
endpoint/channel-related memory area is located, how large it is or how many bytes must
be transmitted. When a token for a valid function/endpoint pair is recognized by the USB
peripheral, the related data transfer (if required and if the endpoint/channel is configured)
takes place. The data buffered by the USB peripheral are loaded in an internal 16-bit
register and memory access to the dedicated buffer is performed. When all the data have
been transferred, if needed, the proper handshake packet over the USB is generated or
expected according to the direction of the transfer.
At the end of the transaction, an endpoint/channel-specific interrupt is generated, reading
status registers and/or using different interrupt response routines. The microcontroller can
determine:
• which endpoint/channel has to be served,
• which type of transaction took place, if errors occurred (bit stuffing, format, CRC,
protocol, missing ACK, over/underrun, etc.).
Special support is offered to isochronous transfers and high throughput bulk transfers,
implementing a double buffer usage, which permits to always have an available buffer for
the USB peripheral while the microcontroller uses the other one.
A special bit THR512 in register USB_ISTR allows notification of 512 bytes being received
in (or transmitted from) the buffer. This bit must be used for long ISO packets (from 512 to
1023 bytes) as it facilitates early start or read/write of data. In this way, the first 512 bytes
can be handled by software while avoiding use of double buffer mode. This bit works when
only one ISO endpoint is configured.
The unit can be placed in low-power mode (SUSPEND mode), by writing in the control
register, whenever required. At this time, all static power dissipation is avoided, and the USB
clock can be slowed down or stopped. The detection of activity at the USB inputs, while in
low-power mode, wakes the device up asynchronously. A special interrupt source can be
connected directly to a wakeup line to permit the system to immediately restart the normal
clock generation and/or support direct clock start/stop.
charging capability (CDP or DCP cases in the standard), the host port is always presented
as a default standard data port (SDP).
Note: For LPM (link power management) this feature is not supported in Host mode.
28.4.1 Description of USB blocks used in both Device and Host modes
The USB peripheral implements all the features related to USB interfacing, which include
the following blocks:
• USB physical interface (USB PHY): this block is maintaining the electrical interface to
an external USB host. It contains the differential analog transceiver itself, controllable
embedded pull-up resistor (connected to USB_DP line) and support for battery
charging detection (BCD), multiplexed on same USB_DP and USB_DM lines. The
output enable control signal of the analog transceiver (active low) is provided externally
on USB_NOE. It can be used to drive some activity LED or to provide information about
the actual communication direction to some other circuitry.
• Serial interface engine (SIE): the functions of this block include: synchronization
pattern recognition, bit-stuffing, CRC generation and checking, PID
verification/generation, and handshake evaluation. It must interface with the USB
transceivers and uses the virtual buffers provided by the packet buffer interface for
local data storage. This unit also generates signals according to USB peripheral
events, such as start of frame (SOF), USB_Reset, data errors etc. and to endpoint
related events like end of transmission or correct reception of a packet; these signals
are then used to generate interrupts.
• Timer: this block generates a start-of-frame locked clock pulse and detects a global
suspend (from the host) when no traffic has been received for 3 ms.
• Packet buffer interface: this block manages the local memory implementing a set of
buffers in a flexible way, both for transmission and reception. It can choose the proper
buffer according to requests coming from the SIE and locate them in the memory
addresses pointed by the endpoint/channel registers. It increments the address after
each exchanged byte until the end of packet, keeping track of the number of
exchanged bytes and preventing the buffer to overrun the maximum capacity.
• Endpoint/channel-related registers: each endpoint/channel has an associated register
containing the endpoint/channel type and its current status. For mono-
directional/single-buffer endpoints, a single register can be used to implement two
distinct endpoints. The number of registers is 8, allowing up to 16 mono-
directional/single-buffer or up to 7 double-buffer endpoints in any combination. For
example the USB peripheral can be programmed to have 4 double buffer endpoints
and 8 single-buffer/mono-directional endpoints.
• Control registers: these are the registers containing information about the status of the
whole USB peripheral and used to force some USB events, such as resume and
power-down.
• Interrupt registers: these contain the interrupt masks and a record of the events. They
can be used to inquire an interrupt reason, the interrupt status or to clear the status of a
pending interrupt.
Note: * Endpoint/channel 0 is always used for control transfer in single-buffer mode.
The USB peripheral is connected to the APB1 bus through an APB1 interface, containing
the following blocks:
• Packet memory: this is the local memory that physically contains the packet buffers. It
can be used by the packet buffer interface, which creates the data structure and can be
accessed directly by the application software. The size of the packet memory is
2048 bytes, structured as 512 words of 32 bits.
• Arbiter: this block accepts memory requests coming from the APB1 bus and from the
USB interface. It resolves the conflicts by giving priority to APB1 accesses, while
always reserving half of the memory bandwidth to complete all USB transfers. This
time-duplex scheme implements a virtual dual-port SRAM that allows memory access,
while an USB transaction is happening. Multiword APB1 transfers of any length are
also allowed by this scheme.
• Register mapper: this block collects the various byte-wide and bit-wide registers of the
USB peripheral in a structured 32-bit wide word set addressed by the APB1.
• APB1 wrapper: this provides an interface to the APB1 for the memory and register. It
also maps the whole USB peripheral in the APB1 address space.
• Interrupt mapper: this block is used to select how the possible USB events can
generate interrupts and map them to the NVIC.
Figure 326. Packet buffer areas with examples of buffer description table locations
Buffer for
double-buffered
IN endpoint 3
..
.
Buffer for
double-buffered
OUT endpoint 2
..
.
Transmission buffer
for
single-buffered
endpoint 1
..
0x1C CHEP_RXTXBD_3* [TX] .
0x18 CHEP_TXRXBD_3 [TX]
0x14 CHEP_RXTXBD_2 [RX] Reception buffer for
0x10 CHEP_TXRXBD_2* [RX] endpoint 0
0x0C CHEP_RXTXBD_1 [RX]
Not used
0x08 CHEP_TXRXBD_1 [TX]
0x04 CHEP_RXTXBD_0 [RX]
0x00 CHEP_TXRXBD_0 [TX] Transmission buffer
for endpoint 0
Packet buffers
(*) indicates alternate mode. MSv32129V2
Each packet buffer is used either during reception or transmission starting from the bottom.
The USB peripheral never changes the contents of memory locations adjacent to the
allocated memory buffers; if a packet bigger than the allocated buffer length is received
(buffer overrun condition) the data is copied to the memory only up to the last available
location.
Endpoint initialization
The first step to initialize an endpoint is to write appropriate values to the
ADDRn_TX/ADDRn_RX fields in the CHEP_TXBD_n and CHEP_RXBD_n registers (in
SRAM) so that the USB peripheral finds the data to be transmitted already available and the
data to be received can be buffered. The UTYPE bits in the USB_CHEPnR register must be
set according to the endpoint type, eventually using the EPKIND bit to enable any special
required feature. On the transmit side, the endpoint must be enabled using the STATTX bits
in the USB_CHEPnR register and COUNTn_TX must be initialized. For reception, STATRX
bits must be set to enable reception and COUNTn_RX must be written with the allocated
buffer size using the BLSIZE and NUM_BLOCK fields. Unidirectional endpoints, except
isochronous and double-buffered bulk endpoints, need to initialize only bits and registers
related to the supported direction. Once the transmission and/or reception are enabled,
register USB_CHEPnR and locations ADDRn_TX/ADDRn_RX, COUNTn_TX/COUNTn_RX
(respectively), should not be modified by the application software, as the hardware can
change their value on the fly. When the data transfer operation is completed, notified by a
CTR interrupt event, they can be accessed again to re-enable a new operation.
indicated channel, the STATTX field now has transitioned to DISABLE. In the case of a NAK
being received (when the peripheral is not ready) STATTX is now in NAK. In the case of a
STALL response, STATTX is in STALL. In this last case, the bus should be reset.
On receiving the ACK receipt by the device, the USB_CHEPnR register is updated in the
following way: DTOGTX bit is toggled.
An error condition is signaled via the bits VTTX and ERR_TX in the case of:
• No handshake being received in time
• False EOP
• Bit stuffing error
• Invalid handshake PID
do not require to be re-written, and the USB_CHEPnR register is updated in the following
way: DTOGRX bit is toggled, the endpoint is made invalid by setting STATRX = 10 (NAK)
and bit VTRX is set. If the transaction has failed due to errors or buffer overrun condition,
none of the previously listed actions take place. The application software must first identify
the endpoint, which is requesting microcontroller attention by examining the IDN and DIR
bits in the USB_ISTR register. The VTRX event is serviced by first determining the
transaction type (SETUP bit in the USB_CHEPnR register); the application software must
clear the interrupt flag bit and get the number of received bytes reading the COUNTn_RX
location inside the buffer description table entry related to the endpoint being processed.
After the received data is processed, the application software should set the STATRX bits to
11 (VALID) in the USB_CHEPnR, enabling further transactions. While the STATRX bits are
equal to 10 (NAK), any OUT request addressed to that endpoint is NAKed, indicating a flow
control condition: the USB host retries the transaction until it succeeds. It is mandatory to
execute the sequence of operations in the above mentioned order to avoid losing the
notification of a second OUT transaction addressed to the same endpoint following
immediately the one which triggered the CTR interrupt.
Data reception in Host mode (IN packets)
Data reception in Host mode follows the same general principles as Device mode. The main
differences are again due to the protocol. In the device, data can be received or not,
depending on readiness after previous operations, whereas the host only requests receive
data when it is ready and able to store them.
ADDRn_TX should be set to the location in the packet memory reserved for the packet for
transmission. The contents received in the data phase response to the IN token packet are
then written to that address in the packet memory and COUNTn_TX gets updated by
hardware during this process to indicate the number of bytes in the packet.
DEVADDR should be written for the correct endpoint and then STATRX should be set to
VALID in order to trigger the reception. The reception is then scheduled by the HFS.
After a successful reception the interrupt CTR (correct transfer) is triggered. By examining
IDN and DIR bits, the corresponding channel and direction is understood. On the indicated
channel, the STATRX field now has transitioned to DISABLE. In the case of a NAK being
received (when the peripheral is not ready) STATRX now is in NAK. In the case of a STALL
response, STATRX is in STALL. In this last case, the bus should be reset. During an IN
packet an error condition is signaled via the bits VTRX and ERR_RX in case of:
• False EOP
• Bit stuffing error
• Wrong CRC
required to STALL the transaction in the case of errors. To do so, at all data stages before
the last, the unused direction should be set to STALL, so that, if the host reverses the
transfer direction too soon, it gets a STALL as a status stage.
While enabling the last data stage, the opposite direction should be set to NAK, so that, if
the host reverses the transfer direction (to perform the status stage) immediately, it is kept
waiting for the completion of the control operation. If the control operation completes
successfully, the software changes NAK to VALID, otherwise to STALL. At the same time, if
the status stage is an OUT, the STATUS_OUT (EPKIND in the USB_CHEPnR register) bit
should be set, so that an error is generated if a status transaction is performed with non-
zero data. When the status transaction is serviced, the application clears the STATUS_OUT
bit and sets STATRX to VALID (to accept a new command) and STATTX to NAK (to delay a
possible status stage immediately following the next setup).
Since the USB specification states that a SETUP packet cannot be answered with a
handshake different from ACK, eventually aborting a previously issued command to start
the new one, the USB logic does not permit a control endpoint to answer with a NAK or
STALL packet to a SETUP token received from the host.
When the STATRX bits are set to 01 (STALL) or 10 (NAK) and a SETUP token is received,
the USB accepts the data, performing the required data transfers and sends back an ACK
handshake. If that endpoint has a previously issued VTRX request not yet acknowledged by
the application (for example VTRX bit is still set from a previously completed reception), the
USB discards the SETUP transaction and does not answer with any handshake packet
regardless of its state, simulating a reception error and forcing the host to send the SETUP
token again. This is done to avoid losing the notification of a SETUP transaction addressed
to the same endpoint immediately following the transaction, which triggered the VTRX
interrupt.
The memory buffer which is currently being used by the USB peripheral is defined by DTOG
buffer flag, while the buffer currently in use by application software is identified by SW_BUF
buffer flag. The relationship between the buffer flag value and the used packet buffer is the
same in both cases, and it is listed in the following table.
USB_CHEP_TXRXBD_0 USB_CHEP_RXTXBD_0
0 1 (ADDRn_TX_0 / COUNTn_TX_0) (ADDRn_TX_1 / COUNTn_TX_1)
Buffer description table locations. Buffer description table locations
USB_CHEP_RXTXBD_0 USB_CHEP_TXRXBD_0
1 0 (ADDRn_TX_0 / COUNTn_TX_0) (ADDRn_TX_0 / COUNTn_TX_0)
Transmit Buffer description table locations Buffer description table locations.
(IN) USB_CHEP_TXRXBD_0
0 0 None (1) (ADDRn_TX_0 / COUNTn_TX_0)
Buffer description table locations.
USB_CHEP_RXTXBD_0
1 1 None (1) (ADDRn_TX_0 / COUNTn_TX_0)
Buffer description table locations.
USB_CHEP_RXTXBD_0 USB_CHEP_TXRXBD_0
(ADDRn_RX_0 / (ADDRn_RX_0 /
0 1
COUNTn_RX_0) COUNTn_RX_0)
Buffer description table locations. Buffer description table locations.
USB_CHEP_TXRXBD_0 USB_CHEP_RXTXBD_0
(ADDRn_RX_0 / (ADDRn_RX_0 /
1 0
COUNTn_RX_0) COUNTn_RX_0)
Receive Buffer description table locations Buffer description table locations.
(OUT) USB_CHEP_RXTXBD_0
(1) (ADDRn_RX_0 /
0 0 None
COUNTn_RX_0)
Buffer description table locations.
USB_CHEP_TXRXBD_0
(ADDRn_RX_0 /
1 1 None (1)
COUNTn_RX_0)
Buffer description table locations.
1. Endpoint in NAK Status.
USB_CHEP_TXRXBD_0 USB_CHEP_RXTXBD_0
0 1 (ADDRn_TX_0 / COUNTn_TX_0) (ADDRn_TX_1 / COUNTn_TX_1)
Buffer description table locations. Buffer description table locations
USB_CHEP_RXTXBD_0 USB_CHEP_TXRXBD_0
1 0 (ADDRn_TX_0 / COUNTn_TX_0) (ADDRn_TX_0 / COUNTn_TX_0)
Transmit Buffer description table locations Buffer description table locations.
(OUT) USB_CHEP_TXRXBD_0
0 0 None (1) (ADDRn_TX_0 / COUNTn_TX_0)
Buffer description table locations.
USB_CHEP_RXTXBD_0
1 1 None (1) (ADDRn_TX_0 / COUNTn_TX_0)
Buffer description table locations.
USB_CHEP_RXTXBD_0 USB_CHEP_TXRXBD_0
(ADDRn_RX_0 / (ADDRn_RX_0 /
0 1
COUNTn_RX_0) COUNTn_RX_0)
Buffer description table locations. Buffer description table locations.
USB_CHEP_TXRXBD_0 USB_CHEP_RXTXBD_0
(ADDRn_RX_0 / (ADDRn_RX_0 /
1 0
COUNTn_RX_0) COUNTn_RX_0)
Receive Buffer description table locations Buffer description table locations.
(IN) USB_CHEP_RXTXBD_0
(1) (ADDRn_RX_0 /
0 0 None
COUNTn_RX_0)
Buffer description table locations.
USB_CHEP_TXRXBD_0
(ADDRn_RX_0 /
1 1 None (1)
COUNTn_RX_0)
Buffer description table locations.
1. Endpoint in NAK Status.
The isochronous behavior for an endpoint is selected by setting the UTYPE bits at 10 in its
USB_CHEPnR register; since there is no handshake phase the only legal values for the
STATRX/STATTX bit pairs are 00 (DISABLED) and 11 (VALID), any other value produces
results not compliant to USB standard. Isochronous endpoints implement double-buffering
to ease application software development, using both ‘transmission’ and ‘reception’ packet
memory areas to manage buffer swapping on each successful transaction in order to have
always a complete buffer to be used by the application, while the USB peripheral fills the
other.
The memory buffer which is currently used by the USB peripheral is defined by the DTOG
bit related to the endpoint direction (DTOGRX for ‘reception’ isochronous endpoints,
DTOGTX for ‘transmission’ isochronous endpoints, both in the related USB_CHEPnR
register) according to Table 138.
USB_CHEP_TXRXBD_0 USB_CHEP_RXTXBD_0
0 (ADDRn_TX_0 / COUNTn_TX_0) (ADDRn_TX_1 / COUNTn_TX_1)
Transmit Buffer description table locations. Buffer description table locations
(IN) USB_CHEP_RXTXBD_0 USB_CHEP_TXRXBD_0
1 (ADDRn_TX_0 / COUNTn_TX_0) (ADDRn_TX_0 / COUNTn_TX_0)
Buffer description table locations Buffer description table locations.
USB_CHEP_RXTXBD_0 USB_CHEP_TXRXBD_0
0 (ADDRn_RX_0 / COUNTn_RX_0) (ADDRn_RX_0 / COUNTn_RX_0)
Receive Buffer description table locations. Buffer description table locations.
(OUT) USB_CHEP_TXRXBD_0 USB_CHEP_RXTXBD_0
1 (ADDRn_RX_0 / COUNTn_RX_0) (ADDRn_RX_0 / COUNTn_RX_0)
Buffer description table locations Buffer description table locations.
USB_CHEP_TXRXBD_0 USB_CHEP_RXTXBD_0
0 (ADDRn_TX_0 / COUNTn_TX_0) (ADDRn_TX_1 / COUNTn_TX_1)
Transmit Buffer description table locations. Buffer description table locations
(OUT) USB_CHEP_RXTXBD_0 USB_CHEP_TXRXBD_0
1 (ADDRn_TX_0 / COUNTn_TX_0) (ADDRn_TX_0 / COUNTn_TX_0)
Buffer description table locations Buffer description table locations.
USB_CHEP_RXTXBD_0 USB_CHEP_TXRXBD_0
0 (ADDRn_RX_0 / COUNTn_RX_0) (ADDRn_RX_0 / COUNTn_RX_0)
Receive Buffer description table locations. Buffer description table locations.
(IN) USB_CHEP_TXRXBD_0 USB_CHEP_RXTXBD_0
1 (ADDRn_RX_0 / COUNTn_RX_0) (ADDRn_RX_0 / COUNTn_RX_0)
Buffer description table locations Buffer description table locations.
The isochronous behavior for an endpoint is selected by setting the UTYPE bits at 10 in its
USB_CHEPnR register; since there is no handshake phase the only legal values for the
STATRX/STATTX bit pairs are 00 (DISABLED) and 11 (VALID),
Just as in Device mode, the mechanism allows automatic toggle of the DTOG bit. Note that
in Host mode, at the same time as this toggle, the STATTX or STATRX of the completed
buffer is automatically set to DISABLED, permitting the future buffer to be accessed before
re-enabling it by setting it to 11 (VALID).
The actual procedure used to suspend the USB peripheral is device dependent since
according to the device composition, different actions may be required to reduce the total
consumption.
A brief description of a typical suspend procedure is provided below, focused on the USB-
related aspects of the application software routine responding to the SUSP notification of
the USB peripheral:
1. Set the SUSPEN bit in the USB_CNTR register to 1. This action activates the suspend
mode within the USB peripheral. As soon as the suspend mode is activated, the check
on SOF reception is disabled to avoid any further SUSP interrupts being issued while
the USB is suspended.
2. Remove or reduce any static power consumption in blocks different from the USB
peripheral.
3. Set SUSPRDY bit in USB_CNTR register to 1 to remove static power consumption in
the analog USB transceivers but keeping them able to detect resume activity.
4. Optionally turn off external oscillator and device PLL to stop any activity inside the
device.
When an USB event occurs while the device is in SUSPEND mode, the RESUME
procedure must be invoked to restore nominal clocks and regain normal USB behavior.
Particular care must be taken to insure that this process does not take more than 10 ms
when the wakening event is an USB reset sequence (see “Universal Serial Bus
Specification” for more details). The start of a resume or reset sequence, while the USB
peripheral is suspended, clears the SUSPRDY bit in USB_CNTR register asynchronously.
Even if this event can trigger a WKUP interrupt if enabled, the use of an interrupt response
routine must be carefully evaluated because of the long latency due to system clock restart;
to have the shorter latency before re-activating the nominal clock it is suggested to put the
resume procedure just after the end of the suspend one, so its code is immediately
executed as soon as the system clock restarts. To prevent ESD discharges or any other kind
of noise from waking-up the system (the exit from suspend mode is an asynchronous
event), a suitable analog filter on data line status is activated during suspend; the filter width
is about 70 ns.
The following is a list of actions a resume procedure should address:
1. Optionally turn on external oscillator and/or device PLL.
2. Clear SUSPEN bit of USB_CNTR register.
3. If the resume triggering event has to be identified, bits RXDP and RXDM in the
USB_FNR register can be used according to Table 140, which also lists the intended
software action in all the cases. If required, the end of resume or reset sequence can
be detected monitoring the status of the above mentioned bits by checking when they
reach the “10” configuration, which represent the idle bus state; moreover at the end of
a reset sequence the RST_DCON bit in USB_ISTR register is set to 1, issuing an
interrupt if enabled, which should be handled as usual.
A device may require to exit from suspend mode as an answer to particular events not
directly related to the USB protocol (for example a mouse movement wakes up the whole
system). In this case, the resume sequence can be started by setting the L2RES bit in the
USB_CNTR register to 1 and resetting it to 0 after an interval between 1 ms and 15 ms (this
interval can be timed using ESOF interrupts, occurring with a 1 ms period when the system
clock is running at nominal frequency). Once the L2RES bit is clear, the resume sequence is
completed by the host PC and its end can be monitored again using the RXDP and RXDM
bits in the USB_FNR register.
Note: The L2RES bit must be anyway used only after the USB peripheral has been put in suspend
mode, setting the SUSPEN bit in USB_CNTR register to 1.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
THR
HOST Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
512M
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PMA WKUP SUSP RST_D ESOF L1REQ L1RE L2RE SUS SUSP USB
CTRM ERRM SOFM Res. PDWN
OVRM M M CONM M M S S PEN RDY RST
rw rw rw rw rw rw rw rw rw rw rw rw r rw rw
To avoid spurious clearing of some bits, it is recommended to clear them with a load
instruction where all bits which must not be altered are written with 1, and all bits to be
cleared are written with 0 (these bits can only be cleared by software). Read-modify-write
cycles should be avoided because between the read and the write operations another bit
could be set by the hardware and the next write clears it before the microprocessor has the
time to service the event.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LS_ DCON_ THR
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
DCON STAT 512
r r rc_w0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PMA RST_
CTR ERR WKUP SUSP SOF ESOF L1REQ Res. Res. DIR IDN[3:0]
OVR DCON
r rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 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
RXDP RXDM LCK LSOF[1:0] FN[10: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
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. EF ADD[6: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
REM LPM LPM
Res. Res. Res. Res. Res. Res. Res. Res. BESL[3:0] Res.
WAKE ACK EN
r r r r r 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
DPPU_ PS2 DC DCD BCD
Res. Res. Res. Res. Res. Res. Res. SDET PDET SDEN PDEN
DPD DET DET EN EN
rw r r r r rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ERR_R ERR_T
Res. Res. Res. Res. Res. LS_EP NAK DEVADDR[6:0]
X X
rc_w0 rc_w0 rw rc_w0 rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DTOG EP DTOG
VTRX STATRX[1:0] SETUP UTYPE[1:0] VTTX STATTX[1:0] EA[3:0]
RX KIND TX
rc_w0 t t t r rw rw rw rc_w0 t t t rw rw rw rw
- A transaction ended with a NAK sets this bit and NAK answer is reported to application
reading the NAK state from the STATRX field of this register. One NAKed transaction keeps
pending and is automatically retried by the host at the next frame, or the host can
immediately retry by resetting STATRX state to VALID.
- A transaction ended by STALL handshake sets this bit and the STALL answer is reported
to application reading the STALL state from the STATRX field of this register. Host
application should consequently disable the channel and re-enumerate.
This bit is read/write but only 0 can be written, writing 1 has no effect.
00 BULK
01 CONTROL
10 ISO
11 INTERRUPT
00 BULK DBL_BUF
01 CONTROL STATUS_OUT
SBUF_ISO: This bit is set by the software to enable the
10 ISO
single-buffering feature for isochronous endpoint
11 INTERRUPT Not used
NAK:
Device mode: the endpoint is NAKed and all transmission requests result in a
10
NAK handshake.
Host mode: this indicates that the device has NAKed the transmission request.
11 VALID: this endpoint/channel is enabled for transmission.
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADDRn_TX[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
the restrictions on the number of available bits, buffer size is represented using the number
of allocated memory blocks, where block size can be selected to choose the trade-off
between fine-granularity/small-buffer and coarse-granularity/large-buffer. The size of
allocated buffer is a part of the endpoint/channel descriptor and it is normally defined during
the enumeration process according to its maxPacketSize parameter value (see “Universal
Serial Bus Specification”).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw 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
ADDRn_RX[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
16 (10000) 32 bytes
... ... ...
29 (11101) 58 bytes ...
30 (11110) 60 bytes 992 bytes
31 (11111) 62 bytes 1023 bytes
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw 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
ADDRn_RX[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
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
ADDRn_TX[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
DTOGRX
DTOGTX
ERR_RX
ERR_TX
STAT UTYP STATT
EPKIND
SETUP
LS_EP
VTRX
VTTX
NAK
Res.
Res.
Res.
Res.
Res.
USB_CHEP0R DEVADDR[6:0] RX E X EA[3:0]
0x00
[1:0] [1: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 0 0 0
DTOGRX
DTOGTX
ERR_RX
ERR_TX
STAT UTYP STATT
EPKIND
SETUP
LS_EP
VTRX
VTTX
Res.
Res.
Res.
Res.
Res.
NAK
USB_CHEP1R DEVADDR[6:0] RX E X EA[3:0]
0x04 [1:0] [1: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 0 0 0
DTOGRX
DTOGTX
ERR_RX
ERR_TX
EPKIND
SETUP
LS_EP
VTRX
VTTX
NAK
Res.
Res.
Res.
Res.
Res.
DTOGRX
DTOGTX
ERR_RX
ERR_TX
EPKIND
SETUP
LS_EP
VTRX
VTTX
NAK
Res.
Res.
Res.
Res.
Res.
DTOGRX
DTOGTX
ERR_RX
ERR_TX
EPKIND
SETUP
LS_EP
VTRX
VTTX
Res.
Res.
Res.
Res.
Res.
NAK
DTOGTX
ERR_RX
ERR_TX
EPKIND
SETUP
LS_EP
VTRX
VTTX
NAK
Res.
Res.
Res.
Res.
Res.
DTOGTX
ERR_RX
ERR_TX
VTRX
VTTX
NAK
Res.
Res.
Res.
Res.
Res.
DTOGTX
ERR_RX
ERR_TX
VTRX
VTTX
Res.
Res.
Res.
Res.
Res.
NAK
SUSPRDY
THR512M
SUSPEN
L1REQM
USBRST
WKUPM
SUSPM
ESOFM
L1RES
L2RES
PDWN
ERRM
CTRM
SOFM
HOST
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
USB_CNTR
0x40
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
DCON_STAT
RST_DCON
LS_DCON
PMAOVR
THR512
L1REQ
WKUP
ESOF
SUSP
ERR
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CTR
SOF
DIR
USB_ISTR IDN[3:0]
0x44
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RXDM
RXDP
LSOF
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
LCK
USB_FNR FN[10:0]
0x48 [1:0]
Reset value 0 0 0 0 0 x x x x x x x x x x x
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
USB_DADDR EF ADD[6:0]
0x4C
Reset value 0 0 0 0 0 0 0 0
Register
Reset value
Reset value
USB_BCDR
USB_LPMCSR
Res. Res. 31
Res. Res. 30
Res. Res. 29
Res. Res. 28
Res. Res. 27
Res. Res. 26
Res. Res. 25
Res. Res. 24
Res. Res. 23
Res. Res. 22
Res. Res. 21
Res. Res. 20
Res. Res. 19
Res. Res. 18
Res. Res.
RM0454 Rev 5
17
Res. Res. 16
0
DPPU_DPD Res. 15
Res. Res. 14
Res. Res. 13
Res. Res. 12
Res. Res. 11
Res. Res. 10
Res. Res. 9
Refer to Section 2.2 on page 44 for the register boundary addresses.
Res. Res.
Table 147. USB register map and reset values (continued)
8
0
0
PS2DET 7
0
0
SDET 6
0
0
PDET 5
BESL[3:0]
0
0
DCDET 4
0
0
SDEN REMWAKE 3
0
PDEN Res. 2
0
0
DCDEN LPMACK 1
0
0
BCDEN LPMEN
Universal serial bus full-speed host/device interface (USB)
965/989
0
965
Debug support (DBG) RM0454
29.1 Overview
The STM32G0x0 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
STM32G0x0 MCUs.
One interface for debug is available:
• Serial wire
Figure 327. Block diagram of STM32G0x0 MCU and Cortex®-M0+-level debug support
Bus matrix
System
interface
Cortex-M0
Core
Debug AP
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.
WDATA or
0..31 Write or Read data
RDATA
32 Parity Single parity of the 32 data bits
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-up
– 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-up
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 153. 32-bit debug port registers addressed through the shifted value A[3:2]
Address A[3:2] value Description
Table 153. 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
DBG_IDCODE
Address offset: 0x00
Only 32-bit access supported. Read-only
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
REV_ID
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
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
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.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBG_I2C2_SMBUS_TIMEOUT(1)
DBG_I2C1_SMBUS_TIMEOUT
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_WWDG_STOP
DBG_IWDG_STOP
DBG_TIM7_STOP
DBG_TIM6_STOP
DBG_TIM3_STOP
DBG_RTC_STOP
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
rw rw rw rw rw rw
1. Only significant on devices integrating I2C2, otherwise reserved. Refer to Section 1.4: Availability of peripherals.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBG_TIM15_STOP(1)
DBG_TIM17_STOP
DBG_TIM16_STOP
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
DBG_TIM14_STOP
DBG_TIM1_STOP
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
rw rw
1. Only significant on devices integrating TIM15, otherwise reserved. Refer to Section 1.4: Availability of peripherals
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
DBG_
Res.
Res.
Res.
Res.
REV_ID DEV_ID
0x00 IDCODE
Reset value(1) X X X X X X X X X X X X X X X X 0 1 1 0 X X X X X X X X X X X X
DBG_STANDBY
DBG_STOP
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.
DBG_CR
0x04
Reset value 0 0
0x0C
Offset
RM0454
DBG_
DBG_
(DBG_IDCODE).
APB_FZ2
APB_FZ1
Register
Reset value
Reset value
Res. Res. 31
Res. Res. 30
Res. Res. 29
Res. Res. 28
Res. Res. 27
Res. Res. 26
Res. Res. 25
Res. Res. 24
Res. Res. 23
0
Res. DBG_I2C2_SMBUS_TIMEOUT 22
0
Res. DBG_I2C1_SMBUS_TIMEOUT 21
Res. Res. 20
Res. Res. 19
0
0 DBG_TIM17_STOP Res. 18
DBG_TIM16_STOP Res.
RM0454 Rev 5
17
0
DBG_TIM15_STOP Res. 16
0
DBG_TIM14_STOP Res. 15
Res. Res. 14
Res. Res. 13
0
Res. DBG_IWDG_STOP 12
0
0
DBG_TIM1_STOP DBG_WWDG_STOP 11
0
Res. DBG_RTC_STOP 10
Res. Res. 9
Refer to Section 2.2 on page 44 for the register boundary addresses.
Res. Res. 8
Table 156. DBG register map and reset values (continued)
Res. Res. 7
Res. Res. 6
0
Res. DBG_TIM7_STOP 5
0
Res. DBG_TIM6_STOP 4
1. The reset value is product dependent. For more information, refer to Section 29.10.1: DBG device ID code register
Res. Res. 3
Res. Res. 2
0
Res. DBG_TIM3_STOP 1
Res. Res. 0
979/989
Debug support (DBG)
979
Device electronic signature RM0454
The device electronic signature is stored in the System memory area of the Flash memory
module, and can be read using the debug interface 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 STM32G0x0 microcontroller.
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
31 Revision history
– Section 30.1: Flash memory size data register: reset value corrected
– Table 35: Programmable data width and endian behavior (when
PINC = MINC = 1): NDT in the first row corrected from 8 to 4
– Table 39: DMAMUX: assignment of multiplexer inputs to resources:
TIM16/17_TRG_COM corrected to TIM16/17_COM
– Section 14.2: ADC main features: VTS corrected to VSENSE
– Section 14.3.1: ADC pins and internal signals: tables and their organization
(External triggers table brought to this section)
– Table 58: Latency between trigger and start of conversion: latency values
– Section : Calculating the actual VREF+ voltage using the internal reference
voltage - corrected from VDDA to VREF+
– Section 15: Advanced-control timer (TIM1): general update
– Figure 141: Capture/Compare channel 1 main circuit and Figure 142: Output
stage of Capture/Compare channel (channel 1) updated
– Figure 159: Master/slave connection example with 1 channel only timers
added
– Table 74: Output control bit for standard OCx channels updated
3 – Section 16.4.24: TIM3 timer input selection register (TIM3_TISEL): removed
27-May-2020
cont’d TI4SEL[3:0] and TI3SEL[3:0]
– Figure 175: General-purpose timer block diagram (TIM14): updated
– Figure 186: Capture/compare channel 1 main circuit and Figure 187: Output
stage of capture/compare channel (channel 1) updated
– Section 18.3.11: Using timer output as trigger for other timers (TIM14) added
– Figure 205: Capture/compare channel 1 main circuit updated
– Section 19.4.23: Using timer output as trigger for other timers
(TIM16/TIM17) added
– Former Section 28.3.4 Advanced watchdog interrupt feature moved to
Section 22.4: WWDG interrupts
– Section 25.4.3: I2C pins and internal signals added
– Section 25.7.3: I2C own address 1 register (I2C_OAR1) and Section 25.7.8:
I2C interrupt clear register (I2C_ICR) updated
– Section 26.4: USART implementation updated - tables reorganized
– Section 38: USB Type-C™ / USB Power Delivery interface (UCPD): general
update
– Table 155: DEV_ID and REV_ID field values
– Section 29.10.2: DBG configuration register (DBG_CR)
Index
A EXTI_FPR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 261
EXTI_FTSR1 . . . . . . . . . . . . . . . . . . . . . . . . . 260
ADC_AWD1TR . . . . . . . . . . . . . . . . . . . . . . .324
EXTI_IMR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 263
ADC_AWD2CR . . . . . . . . . . . . . . . . . . . . . . .330
EXTI_RPR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 261
ADC_AWD2TR . . . . . . . . . . . . . . . . . . . . . . .325
EXTI_RTSR1 . . . . . . . . . . . . . . . . . . . . . . . . . 259
ADC_AWD3CR . . . . . . . . . . . . . . . . . . . . . . .330
EXTI_SWIER1 . . . . . . . . . . . . . . . . . . . . . . . . 260
ADC_AWD3TR . . . . . . . . . . . . . . . . . . . . . . .329
ADC_CALFACT . . . . . . . . . . . . . . . . . . . . . . .331
ADC_CCR . . . . . . . . . . . . . . . . . . . . . . . . . . .331 F
ADC_CFGR1 . . . . . . . . . . . . . . . . . . . . . . . . .318 FLASH_ACR . . . . . . . . . . . . . . . . . . . . . . . . . . 74
ADC_CFGR2 . . . . . . . . . . . . . . . . . . . . . . . . .322 FLASH_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
ADC_CHSELR . . . . . . . . . . . . . . . . . . . . 326-327 FLASH_ECCR . . . . . . . . . . . . . . . . . . . . . . . . . 79
ADC_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . .316 FLASH_ECCR2 . . . . . . . . . . . . . . . . . . . . . . . . 80
ADC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . .329 FLASH_KEYR . . . . . . . . . . . . . . . . . . . . . . . . . 75
ADC_IER . . . . . . . . . . . . . . . . . . . . . . . . . . . .314 FLASH_OPTKEYR . . . . . . . . . . . . . . . . . . . . . 75
ADC_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . .312 FLASH_OPTR . . . . . . . . . . . . . . . . . . . . . . . . . 80
ADC_SMPR . . . . . . . . . . . . . . . . . . . . . . . . . .323 FLASH_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
FLASH_WRP1AR . . . . . . . . . . . . . . . . . . . . . . 82
C FLASH_WRP1BR . . . . . . . . . . . . . . . . . . . . . . 82
FLASH_WRP2AR . . . . . . . . . . . . . . . . . . . . . . 83
CRC_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . .271
FLASH_WRP2BR . . . . . . . . . . . . . . . . . . . . . . 84
CRC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . .270
CRC_IDR . . . . . . . . . . . . . . . . . . . . . . . . . . . .270
CRC_INIT . . . . . . . . . . . . . . . . . . . . . . . . . . . .272 G
CRC_POL . . . . . . . . . . . . . . . . . . . . . . . . . . .272 GPIOx_AFRH . . . . . . . . . . . . . . . . . . . . . . . . 187
GPIOx_AFRL . . . . . . . . . . . . . . . . . . . . . . . . 186
D GPIOx_BRR . . . . . . . . . . . . . . . . . . . . . . . . . 187
GPIOx_BSRR . . . . . . . . . . . . . . . . . . . . . . . . 184
DBG_APB_FZ1 . . . . . . . . . . . . . . . . . . . . . . .975
GPIOx_IDR . . . . . . . . . . . . . . . . . . . . . . . . . . 184
DBG_APB_FZ2 . . . . . . . . . . . . . . . . . . . . . . .977
GPIOx_LCKR . . . . . . . . . . . . . . . . . . . . . . . . 185
DBG_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . .975
GPIOx_MODER . . . . . . . . . . . . . . . . . . . . . . 182
DBG_IDCODE . . . . . . . . . . . . . . . . . . . . . . . .974
GPIOx_ODR . . . . . . . . . . . . . . . . . . . . . . . . . 184
DMA_CCRx . . . . . . . . . . . . . . . . . . . . . . . . . .226
GPIOx_OSPEEDR . . . . . . . . . . . . . . . . . . . . 183
DMA_CMARx . . . . . . . . . . . . . . . . . . . . . . . . .230
GPIOx_OTYPER . . . . . . . . . . . . . . . . . . . . . . 182
DMA_CNDTRx . . . . . . . . . . . . . . . . . . . . . . . .229
GPIOx_PUPDR . . . . . . . . . . . . . . . . . . . . . . . 183
DMA_CPARx . . . . . . . . . . . . . . . . . . . . . . . . .230
DMA_IFCR . . . . . . . . . . . . . . . . . . . . . . . . . . .225
DMA_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . .223 I
DMAMUX_CFR . . . . . . . . . . . . . . . . . . . . . . .245 I2C_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758
DMAMUX_CSR . . . . . . . . . . . . . . . . . . . . . . .245 I2C_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761
DMAMUX_CxCR . . . . . . . . . . . . . . . . . . . . . .244 I2C_ICR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770
DMAMUX_RGCFR . . . . . . . . . . . . . . . . . . . .247 I2C_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 768
DMAMUX_RGSR . . . . . . . . . . . . . . . . . . . . . .247 I2C_OAR1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
DMAMUX_RGxCR . . . . . . . . . . . . . . . . . . . . .246 I2C_OAR2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 765
I2C_PECR . . . . . . . . . . . . . . . . . . . . . . . . . . . 771
E I2C_RXDR . . . . . . . . . . . . . . . . . . . . . . . . . . . 772
I2C_TIMEOUTR . . . . . . . . . . . . . . . . . . . . . . 767
EXTI_EMR1 . . . . . . . . . . . . . . . . . . . . . . . . . .264
I2C_TIMINGR . . . . . . . . . . . . . . . . . . . . . . . . 766
EXTI_EXTICRx . . . . . . . . . . . . . . . . . . . . . . .262
I2C_TXDR . . . . . . . . . . . . . . . . . . . . . . . 772-773
U
USART_BRR . . . . . . . . . . . . . . . . . . . . . . . . .843
USART_CR1 . . . . . . . . . . . . . . . . . . . . .827, 831
USART_CR2 . . . . . . . . . . . . . . . . . . . . . . . . .834
USART_CR3 . . . . . . . . . . . . . . . . . . . . . . . . .838
USART_GTPR . . . . . . . . . . . . . . . . . . . . . . . .843
USART_ICR . . . . . . . . . . . . . . . . . . . . . . . . . .857
USART_ISR . . . . . . . . . . . . . . . . . . . . . .846, 852
USART_PRESC . . . . . . . . . . . . . . . . . . . . . . .860
USART_RDR . . . . . . . . . . . . . . . . . . . . . . . . .859
USART_RQR . . . . . . . . . . . . . . . . . . . . . . . . .845
USART_RTOR . . . . . . . . . . . . . . . . . . . . . . . .844
USART_TDR . . . . . . . . . . . . . . . . . . . . . . . . .859
USB_BCDR . . . . . . . . . . . . . . . . . . . . . . . . . .949
USB_CHEP_RXTXBD_n . . . . . . . . . . . . . . . .963
USB_CHEP_TXRXBD_n . . . . . . . . . . . .960, 962
USB_CHEPnR . . . . . . . . . . . . . . . . . . . . . . . .951
USB_CNTR . . . . . . . . . . . . . . . . . . . . . . . . . .941
USB_DADDR . . . . . . . . . . . . . . . . . . . . . . . . .948
USB_FNR . . . . . . . . . . . . . . . . . . . . . . . . . . .947
USB_ISTR . . . . . . . . . . . . . . . . . . . . . . . . . . .944
USB_LPMCSR . . . . . . . . . . . . . . . . . . . . . . . .949
W
WWDG_CFR . . . . . . . . . . . . . . . . . . . . . . . . .648
WWDG_CR . . . . . . . . . . . . . . . . . . . . . . . . . .647
WWDG_SR . . . . . . . . . . . . . . . . . . . . . . . . . .649
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, please 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.