Rm0364 Stm32f334xx Advanced Armbased 32bit Mcus Stmicroelectronics
Rm0364 Stm32f334xx Advanced Armbased 32bit Mcus Stmicroelectronics
Reference manual
STM32F334xx advanced Arm®-based 32-bit MCUs
Introduction
This reference manual targets application developers. It provides complete information on
how to use the STM32F334xx microcontroller memory and peripherals.
The STM32F334xx is a family of microcontrollers with different memory sizes, packages
and peripherals.
For ordering information, mechanical and electrical device characteristics refer to the
STM32F334x4/x6/x8 datasheet.
For information on the Arm® Cortex®-M4 core with FPU, refer to the STM32 Cortex®-M4
MCUs and MPUs programming manual (PM0214).
Related documents
Available from STMicroelectronics web site www.st.com:
• STM32F334x4/x6/x8 datasheet
• STM32 Cortex®-M4 MCUs and MPUs programming manual (PM0214)
Contents
1 Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.2 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.3 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
1.4 Availability of peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
List of tables
List of figures
Figure 45. Flushing JSQR queue of context by setting ADDIS=1 (JQM=0). . . . . . . . . . . . . . . . . . . . 242
Figure 46. Flushing JSQR queue of context by setting ADDIS=1 (JQM=1). . . . . . . . . . . . . . . . . . . . 243
Figure 47. Example of JSQR queue of context when changing SW and HW triggers. . . . . . . . . . . . 243
Figure 48. Single conversions of a sequence, software trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Figure 49. Continuous conversion of a sequence, software trigger . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Figure 50. Single conversions of a sequence, hardware trigger . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Figure 51. Continuous conversions of a sequence, hardware trigger . . . . . . . . . . . . . . . . . . . . . . . . 246
Figure 52. Right alignment (offset disabled, unsigned value) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Figure 53. Right alignment (offset enabled, signed value). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Figure 54. Left alignment (offset disabled, unsigned value) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Figure 55. Left alignment (offset enabled, signed value) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Figure 56. Example of overrun (OVR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
Figure 57. AUTODLY=1, regular conversion in continuous mode, software trigger . . . . . . . . . . . . . 253
Figure 58. AUTODLY=1, regular HW conversions interrupted by injected conversions
(DISCEN=0; JDISCEN=0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Figure 59. AUTODLY=1, regular HW conversions interrupted by injected conversions . . . . . . . . . . . . .
(DISCEN=1, JDISCEN=1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Figure 60. AUTODLY=1, regular continuous conversions interrupted by injected conversions . . . . 256
Figure 61. AUTODLY=1 in auto- injected mode (JAUTO=1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Figure 62. Analog watchdog’s guarded area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
Figure 63. ADCy_AWDx_OUT signal generation (on all regular channels). . . . . . . . . . . . . . . . . . . . 259
Figure 64. ADCy_AWDx_OUT signal generation (AWDx flag not cleared by SW) . . . . . . . . . . . . . . 260
Figure 65. ADCy_AWDx_OUT signal generation (on a single regular channel) . . . . . . . . . . . . . . . . 260
Figure 66. ADCy_AWDx_OUT signal generation (on all injected channels) . . . . . . . . . . . . . . . . . . . 260
Figure 67. Dual ADC block diagram(1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Figure 68. Injected simultaneous mode on 4 channels: dual ADC mode . . . . . . . . . . . . . . . . . . . . . 263
Figure 69. Regular simultaneous mode on 16 channels: dual ADC mode . . . . . . . . . . . . . . . . . . . . 265
Figure 70. Interleaved mode on 1 channel in continuous conversion mode: dual ADC mode. . . . . . 267
Figure 71. Interleaved mode on 1 channel in single conversion mode: dual ADC mode. . . . . . . . . . 267
Figure 72. Interleaved conversion with injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Figure 73. Alternate trigger: injected group of each ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Figure 74. Alternate trigger: 4 injected channels (each ADC) in discontinuous mode . . . . . . . . . . . . 270
Figure 75. Alternate + regular simultaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Figure 76. Case of trigger occurring during injected conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Figure 77. DMA Requests in regular simultaneous mode when MDMA=0b00 . . . . . . . . . . . . . . . . . 272
Figure 78. DMA requests in regular simultaneous mode when MDMA=0b10 . . . . . . . . . . . . . . . . . . 273
Figure 79. DMA requests in interleaved mode when MDMA=0b10 . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Figure 80. Temperature sensor channel block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
Figure 81. VBAT channel block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Figure 82. VREFINT channel block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Figure 83. DAC1 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Figure 84. DAC2 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Figure 85. Data registers in single DAC channel mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Figure 86. Timing diagram for conversion with trigger disabled TEN = 0 . . . . . . . . . . . . . . . . . . . . . 321
Figure 87. Data registers in dual DAC channel mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Figure 88. DAC LFSR register calculation algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328
Figure 89. DAC conversion (SW trigger enabled) with LFSR wave generation. . . . . . . . . . . . . . . . . 328
Figure 90. DAC triangle wave generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
Figure 91. DAC conversion (SW trigger enabled) with triangle wave generation . . . . . . . . . . . . . . . 329
Figure 92. Comparator 2 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Figure 93. Comparator output blanking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Figure 94. STM32F334xx comparator and operational amplifier
connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354
Figure 95. Timer controlled Multiplexer mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Figure 96. Standalone mode: external gain setting mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Figure 97. Follower configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Figure 98. PGA mode, internal gain setting (x2/x4/x8/x16), inverting input not used . . . . . . . . . . . . 359
Figure 99. PGA mode, internal gain setting (x2/x4/x8/x16), inverting input used for
filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Figure 100. TSC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Figure 101. Surface charge transfer analog I/O group structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Figure 102. Sampling capacitor voltage variation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Figure 103. Charge transfer acquisition sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Figure 104. Spread spectrum variation principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Figure 105. Advanced-control timer block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Figure 106. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 388
Figure 107. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 388
Figure 108. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Figure 109. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Figure 110. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Figure 111. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Figure 112. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not preloaded) . . . . . 392
Figure 113. Counter timing diagram, update event when ARPE=1 (TIMx_ARR preloaded) . . . . . . . . 392
Figure 114. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Figure 115. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Figure 116. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Figure 117. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Figure 118. Counter timing diagram, update event when repetition counter is not used . . . . . . . . . . . 396
Figure 119. Counter timing diagram, internal clock divided by 1, TIMx_ARR = 0x6 . . . . . . . . . . . . . . 397
Figure 120. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Figure 121. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 398
Figure 122. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Figure 123. Counter timing diagram, update event with ARPE=1 (counter underflow) . . . . . . . . . . . . 399
Figure 124. Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 400
Figure 125. Update rate examples depending on mode and TIMx_RCR register settings . . . . . . . . . 401
Figure 126. External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
Figure 127. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 403
Figure 128. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Figure 129. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Figure 130. External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Figure 131. Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Figure 132. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 407
Figure 133. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
Figure 134. Output stage of capture/compare channel (channel 1, idem ch. 2 and 3) . . . . . . . . . . . . 408
Figure 135. Output stage of capture/compare channel (channel 4). . . . . . . . . . . . . . . . . . . . . . . . . . . 409
Figure 136. Output stage of capture/compare channel (channel 5, idem ch. 6) . . . . . . . . . . . . . . . . . 409
Figure 137. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Figure 138. Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Figure 139. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Figure 140. Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
Figure 141. Generation of 2 phase-shifted PWM signals with 50% duty cycle . . . . . . . . . . . . . . . . . . 417
Figure 142. Combined PWM mode on channel 1 and 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Figure 143. 3-phase combined PWM signals with multiple trigger pulses per period . . . . . . . . . . . . . 419
Figure 144. Complementary output with dead-time insertion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Figure 145. Dead-time waveforms with delay greater than the negative pulse . . . . . . . . . . . . . . . . . . 420
Figure 146. Dead-time waveforms with delay greater than the positive pulse. . . . . . . . . . . . . . . . . . . 421
Figure 147. Various output behavior in response to a break event on BKIN (OSSI = 1) . . . . . . . . . . . 424
Figure 148. PWM output state following BKIN and BKIN2 pins assertion (OSSI=1) . . . . . . . . . . . . . . 425
Figure 149. PWM output state following BKIN assertion (OSSI=0) . . . . . . . . . . . . . . . . . . . . . . . . . . . 426
Figure 150. Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Figure 151. 6-step generation, COM example (OSSR=1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
Figure 152. Example of one pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Figure 153. Retriggerable one pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Figure 154. Example of counter operation in encoder interface mode. . . . . . . . . . . . . . . . . . . . . . . . . 432
Figure 155. Example of encoder interface mode with TI1FP1 polarity inverted. . . . . . . . . . . . . . . . . . 433
Figure 156. Measuring time interval between edges on 3 signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Figure 157. Example of Hall sensor interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Figure 158. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Figure 159. Control circuit in Gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
Figure 160. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
Figure 161. Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 440
Figure 162. General-purpose timer block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
Figure 163. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 481
Figure 164. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 481
Figure 165. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
Figure 166. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Figure 167. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Figure 168. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
Figure 169. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not preloaded). . . . . 484
Figure 170. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR preloaded). . . . . . . . 485
Figure 171. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
Figure 172. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
Figure 173. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Figure 174. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Figure 175. Counter timing diagram, Update event when repetition counter
is not used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
Figure 176. Counter timing diagram, internal clock divided by 1, TIMx_ARR=0x6 . . . . . . . . . . . . . . . 489
Figure 177. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
Figure 178. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 490
Figure 179. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
Figure 180. Counter timing diagram, Update event with ARPE=1 (counter underflow). . . . . . . . . . . . 491
Figure 181. Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 492
Figure 182. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 493
Figure 183. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
Figure 184. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
Figure 185. External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
Figure 186. Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
Figure 187. Capture/Compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . 497
Figure 188. Capture/Compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
Figure 189. Output stage of Capture/Compare channel (channel 1) . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Figure 190. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Figure 191. Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
Figure 192. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
Figure 193. Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
Figure 194. Generation of 2 phase-shifted PWM signals with 50% duty cycle . . . . . . . . . . . . . . . . . . 505
Figure 195. Combined PWM mode on channels 1 and 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
Figure 346. Transfer bus diagrams for I2C master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 910
Figure 347. Timeout intervals for tLOW:SEXT, tLOW:MEXT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 915
Figure 348. Transfer sequence flowchart for SMBus slave transmitter N bytes + PEC. . . . . . . . . . . . 919
Figure 349. Transfer bus diagrams for SMBus slave transmitter (SBC=1) . . . . . . . . . . . . . . . . . . . . . 919
Figure 350. Transfer sequence flowchart for SMBus slave receiver N Bytes + PEC . . . . . . . . . . . . . 921
Figure 351. Bus transfer diagrams for SMBus slave receiver (SBC=1). . . . . . . . . . . . . . . . . . . . . . . . 922
Figure 352. Bus transfer diagrams for SMBus master transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923
Figure 353. Bus transfer diagrams for SMBus master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 925
Figure 354. USART block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 952
Figure 355. Word length programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 954
Figure 356. Configurable stop bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 956
Figure 357. TC/TXE behavior when transmitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 957
Figure 358. Start bit detection when oversampling by 16 or 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 958
Figure 359. Data sampling when oversampling by 16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
Figure 360. Data sampling when oversampling by 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 962
Figure 361. Mute mode using Idle line detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 969
Figure 362. Mute mode using address mark detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 970
Figure 363. Break detection in LIN mode (11-bit break length - LBDL bit is set) . . . . . . . . . . . . . . . . . 973
Figure 364. Break detection in LIN mode vs. Framing error detection. . . . . . . . . . . . . . . . . . . . . . . . . 974
Figure 365. USART example of synchronous transmission. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975
Figure 366. USART data clock timing diagram (M bits = 00). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975
Figure 367. USART data clock timing diagram (M bits = 01) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976
Figure 368. RX data setup/hold time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 976
Figure 369. ISO 7816-3 asynchronous protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978
Figure 370. Parity error detection using the 1.5 stop bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 979
Figure 371. IrDA SIR ENDEC- block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983
Figure 372. IrDA data modulation (3/16) -Normal Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984
Figure 373. Transmission using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985
Figure 374. Reception using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986
Figure 375. Hardware flow control between 2 USARTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986
Figure 376. RS232 RTS flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 987
Figure 377. RS232 CTS flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 988
Figure 378. USART interrupt mapping diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
Figure 379. SPI block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1016
Figure 380. Full-duplex single master/ single slave application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017
Figure 381. Half-duplex single master/ single slave application . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018
Figure 382. Simplex single master/single slave application (master in transmit-only/
slave in receive-only mode) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1019
Figure 383. Master and three independent slaves. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1020
Figure 384. Multi-master application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1021
Figure 385. Hardware/software slave select management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1022
Figure 386. Data clock timing diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023
Figure 387. Data alignment when data length is not equal to 8-bit or 16-bit . . . . . . . . . . . . . . . . . . . 1024
Figure 388. Packing data in FIFO for transmission and reception . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028
Figure 389. Master full-duplex communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
Figure 390. Slave full-duplex communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1032
Figure 391. Master full-duplex communication with CRC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033
Figure 392. Master full-duplex communication in packed mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1034
Figure 393. NSSP pulse generation in Motorola SPI master mode . . . . . . . . . . . . . . . . . . . . . . . . . . 1037
Figure 394. TI mode transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1038
Figure 395. CAN network topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1051
Figure 396. Single-CAN block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1052
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 STM 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:
• The Arm® Cortex®-M4 core integrates one debug port: SWD debug port (SWD-DP)
provides a 2-pin (clock and data) interface based on the Serial Wire Debug (SWD)
protocol. Refer to the Cortex®-M4 technical reference manual.
• Word: data of 32-bit length.
• Half-word: data of 16-bit length.
• Byte: data of 8-bit length.
• 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 JTAG protocol, 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.
I-bus
S0
Arm
Cortex-M4
D-bus
S1
S-bus
S2
DMA
S3
GPDMA1
M0 M1 M2 M3 M4 M5 M6
AHB dedicated
ICODE to GPIO ports
FLASH 64 K
64 bits FLITF DCODE
ADC1 and ADC2
2.1.5 BusMatrix
The BusMatrix manages the access arbitration between Masters. The arbitration uses a
Round Robin algorithm. The BusMatrix is composed of five masters (CPU AHB, System
bus, DCode bus, ICode bus, DMA1/2 bus) and seven slaves (FLITF, SRAM, CCM SRAM,
AHB2GPIO and AHB2APB1/2 bridges, and ADCs).
AHB/APB bridges
The two AHB/APB bridges provide full synchronous connections between the AHB and the
two APB buses. APB1 is limited to 36 MHz, APB2 operates at full speed (72 MHz).
Refer to Section 2.2.2: Memory map and register boundary addresses on page 48 for the
address mapping of the peripherals connected to this bridge.
After each device reset, all peripheral clocks are disabled (except for the SRAM and FLITF).
Before using a peripheral user has to enable its clock in the RCC_AHBENR,
RCC_APB2ENR or RCC_APB1ENR register.
When a 16- or 8-bit access is performed on an APB register, the access is transformed into
a 32-bit access: the bridge duplicates the 16- or 8-bit data to feed the 32-bit vector.
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.
AHB3 0x5000 0000 - 0x5000 03FF 1K ADC1 - ADC2 Section 13.7 on page 313
- 0x4800 1800 - 0x4FFF FFFF ~132 M Reserved -
0x4800 1400 - 0x4800 17FF 1K GPIOF
0x4800 1000 - 0x4800 13FF 1K Reserved
0x4800 0C00 - 0x4800 0FFF 1K GPIOD
AHB2 Section 9.4.12 on page 155
0x4800 0800 - 0x4800 0BFF 1K GPIOC
0x4800 0400 - 0x4800 07FF 1K GPIOB
0x4800 0000 - 0x4800 03FF 1K GPIOA
- 0x4002 4400 - 0x47FF FFFF ~128 M Reserved
0x4002 4000 - 0x4002 43FF 1K TSC Section 17.6.11 on page 381
0x4002 3400 - 0x4002 3FFF 3K Reserved -
0x4002 3000 - 0x4002 33FF 1K CRC Section 5.4.6 on page 81
0x4002 2400 - 0x4002 2FFF 3K Reserved -
AHB1 0x4002 2000 - 0x4002 23FF 1K Flash interface Section 3.6 on page 71
0x4002 1400 - 0x4002 1FFF 3K Reserved -
0x4002 1000 - 0x4002 13FF 1K RCC Section 8.4.14 on page 137
0x4002 0400 - 0x4002 0FFF 3K Reserved -
0x4002 0000 - 0x4002 03FF 1K DMA1 Section 11.6.7 on page 190
- 0x4001 8000 - 0x4001 FFFF 32 K Reserved -
The write protection can be enabled in the CCM SRAM protection register (SYSCFG_RCR)
in the SYSCFG block. This is a register with write 1 once mechanism, which means by
writing 1 on a bit, it sets up the write protection for that page of SRAM and it can be
removed/cleared by a system reset only. For more details, refer to the SYSCFG section.
nBOOT1 BOOT0 - -
x 0 Main Flash memory Main flash memory selected as boot area
1 1 System memory System memory selected as boot area
Embedded SRAM (on the DCode bus)
0 1 Embedded SRAM
selected as boot area
The values on both BOOT0 pin and nBOOT1 bit are latched on the 4th rising edge of
SYSCLK after a reset.
It is up to the user to set the nBOOT1 and BOOT0 to select the required boot mode. The
BOOT0 pin and nBOOT1 bit are also resampled 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 (0x1FFF D800).
• 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).
Instruction fetch
The Cortex®-M4 fetches the instruction over the ICode bus and the literal pool
(constant/data) over the DCode bus. The prefetch block aims at increasing the efficiency of
ICode bus accesses.
Prefetch buffer
The prefetch buffer is 2 blocks wide where each block consists of 8 bytes. The prefetch
blocks are direct-mapped. A block can be completely replaced on a single read to the Flash
memory as the size of the block matches the bandwidth of the Flash memory.
The implementation of this prefetch buffer makes a faster CPU execution possible as the
CPU fetches one word at a time with the next word readily available in the prefetch buffer.
This implies that the acceleration ratio is in the order of 2, assuming that the code is aligned
at a 64-bit boundary for the jumps.
Prefetch controller
The prefetch controller decides to access the Flash memory depending on the available
space in the prefetch buffer. The Controller initiates a read request when there is at least
one block free in the prefetch buffer.
After reset, the state of the prefetch buffer is on. The prefetch buffer must be switched on/off
only when no prescaler is applied on the AHB clock (SYSCLK must be equal to HCLK). The
prefetch buffer is usually switched on/off during the initialization routine, while the
microcontroller is running on the internal 8 MHz RC (HSI) oscillator.
Note: The prefetch buffer must be kept on (FLASH_ACR[4]=’1’) when using a prescaler different
from 1 on the AHB clock.
If there is not any high frequency clock available in the system, Flash memory accesses can
be made on a half cycle of HCLK (AHB clock). This mode can be selected by setting a
control bit in the Flash access control register.
Half-cycle access cannot be used when there is a prescaler different from 1 on the AHB
clock.
Access latency
In order to maintain the control signals to read the Flash memory, the ratio of the prefetch
controller clock period to the access time of the Flash memory has to be programmed in the
Flash access control register with the LATENCY[2:0] bits. This value gives the number of
cycles needed to maintain the control signals of the Flash memory and correctly read the
required data. After reset, the value is zero and only one cycle without additional wait states
is required to access the Flash memory.
DCode interface
The DCode interface consists of a simple AHB interface on the CPU side and a request
generator to the Arbiter of the Flash access controller. The DCode accesses have priority
over prefetch accesses. This interface uses the Access Time Tuner block of the prefetch
buffer.
In the case of a wrong key sequence, a bus error is detected and a Hard Fault interrupt is
generated. This is done after the first write cycle if KEY1 does not match, or during the
second write cycle if KEY1 has been correctly written but KEY2 does not match.
The FPEC and the FLASH_CR register can be locked again by user software by writing the
LOCK bit in the FLASH_CR register to 1.
Read FLASH_CR_LOCK
Yes
FLASH_CR_LOCK Perform unlock sequency
=1
No
Write FLASH_CR_PG to 1
FLASH_SR_BSY Yes
=1
No
The Flash memory interface preliminarily reads the value at the addressed main Flash
memory location and checks that it has been erased. If not, the program operation is
skipped and a warning is issued by the PGERR bit in FLASH_SR register (the only
exception to this is when 0x0000 is programmed. In this case, the location is correctly
programmed to 0x0000 and the PGERR bit is not set). If the addressed main Flash memory
location is write-protected by the FLASH_WRPR register, the program operation is skipped
and a warning is issued by the WRPRTERR bit in the FLASH_SR register. The end of the
program operation is indicated by the EOP bit in the FLASH_SR register.
The main Flash memory programming sequence in standard mode is as follows:
1. Check that no main Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register.
2. Set the PG bit in the FLASH_CR register.
3. Perform the data write (half-word) at the desired address.
4. Wait until the BSY bit is reset in the FLASH_SR register.
5. Check the EOP flag in the FLASH_SR register (it is set when the programming
operation has succeeded), and then clear it by software.
Note: The registers are not accessible in write mode when the BSY bit of the FLASH_SR register
is set.
Page erase
To erase a page, the procedure below must be followed:
1. Check that no Flash memory operation is ongoing by checking the BSY bit in the
FLASH_CR register.
2. Set the PER bit in the FLASH_CR register.
3. Program the FLASH_AR register to select a page to erase.
4. Set the STRT bit in the FLASH_CR register (see below note).
5. Wait for the BSY bit to be reset.
6. Check the EOP flag in the FLASH_SR register (it is set when the erase operation has
succeeded), and then clear it by software.
7. Clear the EOP flag.
Note: The software should start checking if the BSY bit equals ‘0’ at least one CPU cycle after
setting the STRT bit.
Read FLASH_CR_LOCK
Yes
FLASH_CR_LOCK Perform unlock sequency
=1
No
Write FLASH_CR_PER to 1
Write FLASH_CR_STRT to 1
FLASH_SR_BSY No
=0
Yes
Mass erase
The Mass erase command can be used to completely erase the user pages of the Flash
memory. The information block is unaffected by this procedure. The following sequence is
recommended:
1. Check that no Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register
2. Set the MER bit in the FLASH_CR register
3. Set the STRT bit in the FLASH_CR register (see below note)
4. Wait for the BSY bit to be reset
5. Check the EOP flag in the FLASH_SR register (it is set when the erase operation has
succeeded), and then clear it by software.
6. Clear the EOP flag.
Note: The software must start checking if the BSY bit equals ‘0’ at least one CPU cycle after
setting the STRT bit.
Read FLASH_CR_LOCK
Yes
FLASH_CR_LOCK Perform unlock sequency
=1
No
Write FLASH_CR_STRT to 1
FLASH_SR_BSY No
=0
Yes
Erase procedure
The option byte erase sequence (OPTERASE) is as follows:
• Check that no Flash memory operation is ongoing by reading the BSY bit in the
FLASH_SR register.
• Unlock the OPTWRE bit in the FLASH_CR register.
• Set the OPTER bit in the FLASH_CR register.
• Set the STRT bit in the FLASH_CR register.
• Wait for BSY to reset.
• Read the erased option bytes and verify.
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 into the main memory Flash area are possible. The
option bytes are also accessible by all operations.
erase of main memory Flash is performed and the backup registers (RTC_BKPxR in
the RTC) are reset.
Level 2: No debug
In this level, the protection level 1 is guaranteed. In addition, the Cortex®-M4 debug
capabilities are disabled. Consequently, the 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, all operations are allowed on the Main Flash memory. On the contrary, only
read and program operations can be performed on the option bytes.
Option bytes cannot be erased. Moreover, the RDP bytes cannot be programmed. Thus, the
level 2 cannot be removed at all: it is an irreversible operation. When attempting to program
the RDP byte, the protection error flag WRPRTERR is set in the FLASH_SR register and an
interrupt can be generated.
Note: The debug feature is also disabled under reset.
STMicroelectronics is not able to perform analysis on defective parts on which the level 2
protection has been set.
Note: When the Mass Erase command is used, the backup registers (RTC_BKPxR in the RTC)
are also reset.
To validate the protection level change, the option bytes must be reloaded through the
OBL_LAUNCH bit in Flash control register.
Write unprotection
To disable the write protection, two application cases are provided:
• Case 1: Read protection disabled after the write unprotection:
– Erase the entire option byte area by using the OPTER bit in the Flash memory
control register (FLASH_CR).
– Program the code 0xAA in the RDP byte to unprotect the memory. This operation
forces a Mass Erase of the main Flash memory.
– Set the OBL_LAUNCH bit in the Flash control register (FLASH_CR) to reload the
option bytes (and the new WRP[3:0] bytes), and to disable the write protection.
• Case 2: Read protection maintained active after the write unprotection, useful for in-
application programming with a user boot loader:
– Erase the entire option byte area by using the OPTER bit in the Flash memory
control register (FLASH_CR).
– Set the OBL_LAUNCH bit in the Flash control register (FLASH_CR) to reload the
option bytes (and the new WRP[3:0] bytes), and to disable the write protection.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PRFT PRFT HLF
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. LATENCY[2:0]
BS BE CYA
r rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WRPRT PG
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EOP Res. Res. BSY
ERR ERR
rw rw rw r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OBL_L
OPTWR OPT
Res. Res. AUNC EOPIE Res. ERRIE Res. LOCK STRT OPTER Res. MER PER PG
E PG
H
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
FAR[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
FAR[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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
VDDA_MONITOR
nRST_STDBY
nRST_STOP
RDPRT[1:0]
SRAM_PE
WDG_SW
OPTERR
nBOOT1
Data1
Data0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
r r r r r r r r 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
WRP[31:16]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WRP[15:0]
r r r r r r r r r r r r r r r r
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
PRFTBS
PRFTBE
HLFCYA
FLASH_ LATENCY
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.
ACR [2:0]
0x000
Reset
1 1 0 0 0 0
value
FLASH_
FKEYR[31:0]
KEYR
0x004
Reset
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
value
FLASH_
OPTKEYR[31:0]
OPTKEYR
0x008
Reset
x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Value
WRPRTERR
PGERR
FLASH_
EOP
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.
BSY
SR
0x00C
Reset
0 0 0 0
value
OBL_LAUNCH
OPTWRE
OPTPG
OPTER
EOPIE
ERRIE
LOCK
STRT
FLASH_
MER
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PER
PG
CR
0x010
Reset
0 0 0 0 1 0 0 0 0 0 0
value
FLASH_
FAR[31:0]
AR
0x014
Reset
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
value
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
VDDA_MONITOR
nRST_STDBY
nRST_STOP
RDPRT[1:0]
SRAM_PE
WDG_SW
OPTERR
nBOOT1
Data1
Data0
FLASH_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
OBR
0x01C
Reset
x x x x x x x x x x x x x x x x x x x x x x x x x x
value
FLASH_
WRP[31:0]
WRPR
0x020
Reset
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
value
There are six option bytes. They are configured by the end user depending on the
application requirements. As a configuration example, the watchdog may be selected in
hardware or software mode.
A 32-bit word is split up as follows in the option bytes.
The organization of these bytes inside the information block is as shown in Table 10.
The option bytes can be read from the memory locations listed in Table 10 or from the
Option byte register (FLASH_OBR).
Note: The new programmed option bytes (user, read/write protection) are loaded after a system
reset.
On every system reset, the option byte loader (OBL) reads the information block and stores
the data into the Option byte register (FLASH_OBR) and the Write protection register
(FLASH_WRPR). Each option byte also has its complement in the information block. During
option loading, by verifying the option bit and its complement, it is possible to check that the
loading has correctly taken place. If this is not the case, an option byte error (OPTERR) is
generated. When a comparison error occurs, the corresponding option byte is forced to
0xFF. The comparator is disabled when the option byte and its complement are both equal
to 0xFF (Electrical Erase state).
5.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
VDDA domain
A/D converter
D/A converter
VSSA Temp. sensor
V DDA Reset block
PLL
RCs
OPAMP
Comparators
I/O ring
VSS Core
Standby circuitry Memories
(Wakeup logic, Digital
VDD
IWDG) peripherals
Voltage regulator
RTC domain
LSE crystal 32K osc
VBAT BKP registers
RCC BDCR register
RTC
MS19668V2
• VDDA, VSSA= 2.0 to 3.6 V : external power supply for ADC, DAC, comparators,
operational amplifiers, temperature sensor, PLL, HSI 8 MHz oscillator, LSI 40 kHz
oscillator, and reset block.
VDDA must be in the 2.4 to 3.6 V range when the OPAMP and DAC are used.
It is forbidden to have VDDA < VDD - 0.4 V. An external Schottky diode must be placed
between VDD and VDDA to guarantee that this condition is met.
• VBAT= 1.65 to 3.6 V: Backup power supply for RTC, LSE oscillator, PC13 to PC15 and
backup registers when VDD is not present. When VDD supply is present, the internal
power switch switches the backup power to VDD. If VBAT is not used, it must be
connected to VDD.
6.1.1 Independent A/D and D/A converter supply and reference voltage
To improve conversion accuracy, the ADC and the DAC have an independent power supply
which can be separately filtered and shielded from noise on the PCB.
The ADC and DAC voltage supply input is available on a separate VDDA pin. An isolated
supply ground connection is provided on the VSSA pin.
For more details on the power on /power down reset threshold, refer to the electrical
characteristics section in the datasheet.
POR
40 mV
hysteresis
PDR
Temporization
t RSTTEMPO
Reset
MS19669V1
PVD output
MS19670V1
Note: To enter Stop mode, all EXTI Line pending bits (in Pending register
(EXTI_PR1)), all peripherals interrupt pending bits and RTC Alarm flag
Mode entry must be reset. Otherwise, the Stop mode entry procedure is ignored and
program execution continues.
If the application needs to disable the external oscillator (external clock)
before entering Stop mode, the system clock source must be first switched
to HSI and then clear the HSEON bit.
Otherwise, if before entering Stop mode the HSEON bit is kept at 1, the
security system (CSS) feature must be enabled to detect any external
oscillator (external clock) failure and avoid a malfunction when entering
Stop mode.
If WFI was used for entry:
– Any EXTI Line configured in Interrupt mode (the corresponding EXTI
Interrupt vector must be enabled in the NVIC).
– Some specific communication peripherals (USART, I2C) interrupts, when
programmed in wakeup mode (the peripheral must be programmed in
Mode exit wakeup mode and the corresponding interrupt vector must be enabled in
the NVIC).
Refer to Table 35: STM32F334xx vector table.
If WFE was used for entry:
Any EXTI Line configured in event mode. Refer to Section 12.2.3:
Wakeup event management
Wakeup latency HSI RC wakeup time + regulator wakeup time from Low-power mode
Debug mode
By default, the debug connection is lost if the application puts the MCU in Stop or Standby
mode while the debug features are used. This is due to the fact that the Arm® Cortex®-M4
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.
31 30 29 28 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. DBP PLS[2:0] PVDE CSBF CWUF PDDS LPDS
rw rw rw rw rw rc_w1 rc_w1 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. EWUP3 EWUP2 EWUP1 Res. Res. Res. Res. Res. PVDO SBF WUF
rw rw rw r r r
10
11
Offset Register
9
8
7
6
5
4
3
2
1
0
CWUF
PDDS
PVDE
CSBF
LPDS
DBP
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PWR_CR PLS[2:0]
0x000
Reset value 0 0 0 0 0 0 0 0 0
EWUP3
EWUP2
EWUP1
PVDO
WUF
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.
SBF
PWR_CSR
0x004
Reset value 0 0 0 0 0 0
7.1 Introduction
Several STM32F3 peripherals have internal interconnections. Knowing these
interconnections allows the following benefits:
• Autonomous communication between peripherals,
• Efficient synchronization between peripherals,
• Discard the software latency and minimize GPIOs configuration,
• Optimum number of available pins even with small packages,
• Avoid the use of connectors and design an optimized PCB with less dissipated energy.
HRTIM1
OPAMP
COMP2
COMP4
COMP6
DMA1
TIM15
TIM16
TIM17
ADC1
ADC2
DAC1
DAC2
IRTIM
Source /
TIM1
TIM2
TIM3
Destination
ADC1 x - x - - - - x - - - - - - - - x
ADC2 x - - - - - - x - - - - - - - - x
COMP2 - - - - - - - x - - - x x - - - x
COMP4 - - - - - - - - x - - - x - - - x
COMP6 - - - - - - - - - x x x x - - - x
OPAMP2 - - x - - - - - - - - - - - - - x
TIM1 x x x x - - x - - - - x x - - - x
SPI1 x - - - - - - - - - - - - - - - -
USART1 x - - - - - - - - - - - - - - - -
TIM15 x x x - x x - x - - - - x x x - x
TIM16 x - - - - - - - x - - - - - - x x
TIM17 x - - - - - - x x - - - - - - x x
TIM2 x x x x - x - x x - - - x x x - x
TIM3 x x x x x - - x x - - x - x x - x
TIM6 x x x - - - - - - - - - - x x - x
TIM7 x - - - - - - - - - - - - x x - x
USART2 x - - - - - - - - - - - - - - - -
USART3 x - - - - - - - - - - - - - - - -
I2C1 x - - - - - - - - - - - - - - - -
DAC1 x - - x x x - - - - - - - - - - -
HRTIM1
OPAMP
COMP2
COMP4
COMP6
DMA1
TIM15
TIM16
TIM17
IRTIM
ADC1
ADC2
DAC1
DAC2
Source /
TIM1
TIM2
TIM3
Destination
DAC2 x - - x x x - - - - - - - - - - -
TS - x - - - - - - - - - - - - - - -
VBAT - x - - - - - - - - - - - - - - -
Vrefint - x x x x - - - - - - - - - - - -
CSS - - - - - - - x x - - - - - - - x
PVD - - - - - - - x x - - - - - - - x
SRAM Parity
- - - - - - - x x - - - - - - - x
error
CPU Hardfault - - - - - - - x x - - - - - - - x
HSE - - - - - - - - - x - - - - - - -
HSI - - - - - - - - - x - - - - - - -
LSE - - - - - - - - - x - - - - - - -
LSI - - - - - - - - - x - - - - - - -
MCO - - - - - - - - - x - - - - - - -
RTC - - - - - - - - - x - - - - - - -
HRTIM1 x x x - - - - - - - - - - x x - -
1. The cells with gray shading indicate that there is no interconnection.
The output (from ADC) is on signals ADCx_AWDy_OUT (x = 1, 2 and y = 1..3 as there are 3
analog watchdogs per ADC) and the input (to timer) on signal TIM1_ETR (external trigger).
TIM1_ETR is connected to ADCx_AWDy_OUT through bits in TIM1_OR registers; refer to
Section 18.4.23: TIM1 option registers (TIM1_OR).
To select which timer input must be connected to the comparator output, the bits field
COMPxOUTSEL in the COMPx_CSR register are used.
The following table gives an overview of all possible comparator outputs redirection to the
timer inputs.
TIM1_BRK_ACTH
TIM1_BRK2 TIM2_IC4 TIM3_IC1
COMP2 - -
TIM1_OCrefClear TIM2_OCrefClear TIM3_OCrefClear
TIM1_IC1
TIM1_BRK TIM3_IC3 TIM15_OCrefCle
COMP4 - -
TIM1_BRK2 TIM3_OCrefClear arTIM15_IC2
Note: When the comparator output is configured to be connected internally to timers break input,
the following must be considered:
1/ COMP2/6 can be used to control TIM1_BRK_ACTH (this break is always active high with
no digital filter) and to control also TIM1_BRK2 input.
2/ COMP4 can be used to control TIM1_BRK and TIM1_BRK2 input (same as the other
comparators).
DAC1_CH1 X X X
DAC1_CH2 X X X
DAC2_CH1 X X X
The possible master/slave connections are summarized in the following table providing the
internal trigger connection:
TIM2 X X
TIM3 X X
TIM6 X X
TIM7 X X
TIM15 X X
EXTI line9 X X
The comparator outputs are connected directly to HRTIM1 in order to speed-up the
propagation delay.
8.1 Reset
There are three types of reset, defined as system reset, power reset and RTC domain reset.
R PU
External
reset Filter System reset
NRST
WWDG reset
IWDG reset
Pulse Power reset
generator Software reset
(min 20 μs) Low-power management reset
Option byte loader reset
Exit from Standby mode
MS19841V4
Software reset
The SYSRESETREQ bit in Cortex®-M4 application interrupt and reset control register must
be set to force a software reset on the device. Refer to the STM32 Cortex®-M4 MCUs and
MPUs programming manual (PM0214) for more details.
The backup registers are also reset when one of the following events occurs:
1. RTC tamper detection event.
2. Change of the read out protection from level 1 to level 0.
8.2 Clocks
Three different clock sources can be used to drive the system clock (SYSCLK):
• HSI 8 MHZ RC oscillator clock
• HSE oscillator clock
• PLL clock
The devices have the following additional clock sources:
• 40 kHz low speed internal RC (LSI RC) which drives the independent watchdog and
optionally the RTC used for Auto-wakeup from Stop/Standby mode.
• 32.768 kHz low speed external crystal (LSE crystal) which optionally drives the real-
time clock (RTCCLK)
Each clock source can be switched on or off independently when it is not used, to optimize
power consumption.
Several prescalers can be used to configure the AHB frequency, the high speed APB
(APB2) and the low speed APB (APB1) domains. The maximum frequency of the AHB and
APB2 domains is 72 MHz. The maximum allowed frequency of the APB1 domain is 36 MHz.
All the peripheral clocks are derived from their bus clock (HCLK, PCLK1 or PCLK2) except:
• The Flash memory programming interface clock (FLITFCLK) which is always the HSI
clock.
• The option byte loader clock which is always the HSI clock
• The ADCs clock which is derived from the PLL output. It can reach 72 MHz and can
then be divided by 1,2,4,6,8,10,12,16,32,64,128 or 256.
• The U(S)ARTs clock which is derived (selected by software) from one of the four
following sources:
– system clock
– HSI clock
– LSE clock
– APB1 or APB2 clock (PCLK1 or PCLK2 depending on which APB is mapped the
USART)
• The I2C1/2 clock which is derived (selected by software) from one of the two following
sources:
– system clock
– HSI clock
• The RTC clock which is derived from the LSE, LSI or from the HSE clock divided by 32.
• The IWDG clock which is always the LSI clock.
The RCC feeds the Cortex System Timer (SysTick) external clock with the AHB clock
(HCLK) divided by 8. The SysTick can work either with this clock or directly with the Cortex
clock (HCLK), configurable in the SysTick Control and Status Register.
FLITFCLK
to Flash programming interface
HSI
8 MHz HSI
HSI RC
/2
HCLK to AHB bus, core,
memory and DM A
PLLSRC SW /8 to cortex System timer
PLLMU L
HSI FHCLK Cortex free
PLL PLLCLK AHB
AHB APB1 running clock
PCLK1
x2,x3,.. prescaler prescaler to APB1 peripherals
x16 /1,2,..512 /1,2,4,8,16
HSE
SYSCLK
CSS If (APB1 prescaler to TIM 2,3,6,7
/2,/3,...
=1) x1 else x2
/16
PCLK1
OSC_OU T SYSCLK to USART
4-32 MHz HSI
HSE OSC LSE
OSC_IN
APB2
PCLK2
prescaler to APB2 peripherals
/32 /1,2,4,8,16
OSC32_IN RTCCLK to RTC
LSE OSC
32.768kHz LSE If (APB2 prescaler to TIM 15,16,17
OSC32_OU T
=1) x1 else x2
RTCSEL[1:0]
MSv32647V3
1. For full details about the internal and external clock source characteristics, please refer to the “Electrical characteristics”
section in your device datasheet.
2. TIM1 can be clocked from the PLLCLKx2 running up to 144 MHz when the system clock source is the PLL. Refer to
Section 8.2.10: Timers (TIMx) clock.
HRTIM1 can be clocked from the PLLCLKx2 with 2 possible configurations:
- HSE is the PLL clock source and PLLCLK is set to 72 MHz (HRTIM frequency is 144 MHz)
- HSI is the PLL clock source and PLLCLK is set to 64 MHz (HRTIM frequency is 128 MHz)
Refer to Section 8.2.11: High-resolution timer (HRTIM) clock.
3. The ADC clock can be derived from the AHB clock of the ADC bus interface, divided by a programmable factor (1, 2 or 4).
When the programmable factor is ‘1’, the AHB prescaler must be equal to ‘1’.
®
FCLK acts as Cortex -M4 free-running clock. For more details refer to the STM32 Cortex®-
M4 MCUs and MPUs programming manual (PM0214).
OSC_IN OSC_OUT
External clock
GPIO
External
source
MSv31915V1
OSC_IN OSC_OUT
Crystal/Ceramic
resonators
CL1 CL2
Load
capacitors
MSv31916V1
Calibration
RC oscillator frequencies can vary from one chip to another due to manufacturing process
variations, this is why each device is factory calibrated by ST for 1% accuracy at TA=25°C.
After reset, the factory calibration value is loaded in the HSICAL[7:0] bits in the Clock control
register (RCC_CR).
If the application is subject to voltage or temperature variations this may affect the RC
oscillator speed. The user can trim the HSI frequency in the application using the
HSITRIM[4:0] bits in the Clock control register (RCC_CR).
For more details on how to measure the HSI frequency variation, refer to Section 8.2.14:
Internal/external clock measurement with TIM16.
The HSIRDY flag in the Clock control register (RCC_CR) indicates if the HSI RC is stable or
not. At startup, the HSI RC output clock is not released until this bit is set by hardware.
The HSI RC can be switched on and off using the HSION bit in the Clock control register
(RCC_CR).
The HSI signal can also be used as a backup source (Auxiliary clock) if the HSE crystal
oscillator fails. Refer to Section 8.2.7: Clock security system (CSS) on page 111.
8.2.3 PLL
The internal PLL can be used to multiply the HSI or HSE output clock frequency. Refer to
Figure 10 and Clock control register (RCC_CR).
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.
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.
An interrupt can be generated when the PLL is ready, if enabled in the Clock interrupt
register (RCC_CIR).
The PLL output frequency must be set in the range 16-72 MHz.
If the HSE oscillator is used directly or indirectly as the system clock (indirectly means: it is
used as PLL input clock, and the PLL clock is used as system clock), a detected failure
causes a switch of the system clock to the HSI oscillator and the disabling of the HSE
oscillator. If the HSE clock (divided or not) is the clock entry of the PLL used as system clock
when the failure occurs, the PLL is disabled too.
The additional bit PLLNODIV in this register controls the divider bypass for a PLL clock input
to MCO. The MCO frequency can be reduced by a configurable divider, controlled by the
MCOPRE[2:0] bits of the Clock configuration register (RCC_CFGR).
TIM16
TI1_RMP[1:0]
GPIO
RTCCLK TI1
HSE/32
MCO
MS30477V1
The input capture channel of the Timer 16 can be a GPIO line or an internal clock of the
MCU. This selection is performed through the TI1_RMP [1:0] bits in the TIM16_OR register.
The possibilities available are the following ones.
• TIM16 Channel1 is connected to the GPIO. Refer to the alternate function mapping in
the device datasheets.
• TIM16 Channel1 is connected to the RTCCLK.
• TIM16 Channel1 is connected to the HSE/32 Clock.
• TIM16 Channel1 is connected to the microcontroller clock output (MCO), this selection
is controlled by the MCO[2:0] bits of the Clock configuration register (RCC_CFGR).
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 rw rw r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HSI
HSICAL[7:0] HSITRIM[4:0] Res. HSION
RDY
r r r r r r r r rw rw rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLNO PLL PLL
MCOPRE[2:0] Res. MCO[2:0] Res. Res. PLLMUL[3:0]
DIV XTPRE SRC
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. PPRE2[2:0] PPRE1[2:0] HPRE[3:0] SWS[1:0] SW[1:0]
rw rw rw rw rw rw rw rw rw rw r r rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLL HSE HSI LSE LSI
Res. Res. Res. Res. Res. Res. Res. Res. CSSC Res. Res.
RDYC RDYC RDYC RDYC RDYC
w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLL HSE HSI LSE LSI PLL HSE HSI LSE LSI
Res. Res. Res. CSSF Res. Res.
RDYIE RDYIE RDYIE RDYIE RDYIE RDYF RDYF RDYF RDYF RDYF
rw rw rw rw rw r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
HRTIM TIM17 TIM16 TIM15
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
1RST RST RST RST
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYS
USART1 SPI1 TIM1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CFG
RST Res. RST RST
RST
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DAC1 PWR DAC2R CAN Res. I2C1 USART3 USART2
Res. Res. Res. Res. Res. Res. Res. Res.
RST RST ST RST RST RST RST
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WWDG TIM7 TIM6 TIM3 TIM2
Res Res Res. Res. Res. Res. Res. Res. Res. Res. Res
RST RST RST RST RST
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IOPF IOPD IOPC IOPB IOPA
Res. Res. Res. ADC12EN Res. Res. Res. TSCEN Res. Res.. Res.
EN EN EN 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
CRC FLITF SRAM DMA1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
EN EN EN EN
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
HRTIM TIM17 TIM16 TIM15
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
ER1EN EN EN EN
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART SPI1 TIM1 SYS
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
1EN EN EN CFGEN
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DAC1 PWR DAC2 CAN I2C1 USART3 USART2
Res. Res. Res. Res Res. Res. Res. Res. Res.
EN EN EN EN EN 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
WWD TIM7E TIM3EN TIM2
Res. Res. Res. Res. Res. Res. Res. Res. Res. TIM6EN Res. Res.
GEN N Res. EN
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BDRST
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC LSE LSE
Res. Res. Res. Res. Res. RTCSEL[1:0] Res. Res. Res. LSEDRV[1:0] LSEON
EN BYP RDY
rw rw rw rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IW
LPWR WWDG SFT POR PIN OB V18PW
WDG RMVF Res. Res. Res. Res. Res. Res. Res.
RSTF STF RSTF RSTF RSTF LRSTF RRSTF
RSTF
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
LSI
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. LSION
RDY
r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADC12 TSC IOPF IOPD IOPC IOPB IOPA
Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST RST RST RST RST RST RST
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.
31 30 29 28 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. ADC12PRES[4:0] PREDIV[3: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
HRTIM TIM1 I2C1
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. USART1SW[1:0]
1SW SW SW
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
HSEBYP
PLLRDY
HSIRDY
CSSON
HSEON
HSERD
PLLON
HSION
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RCC_CR HSICAL[7:0] HSITRIM[4:0]
0x00
Reset value 0 0 0 0 0 0 x x x x x x x x 1 0 0 0 0 1 1
MCOPRE[2:0]
PLLXTPRE
PLLNODIV
PLLSRC
Res.
Res.
Res.
RCC_CFGR HPRE[3:0]
0x04 [2:0] [3:0] [2:0] [2: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
HSERDYIE
LSERDYIE
HSERDYC
PLLRDYIE
HSERDYF
LSERDYC
HSIRDYIE
PLLRDYC
LSERDYF
LSIRDYIE
HSIRDYC
PLLRDYF
HSIRDYF
LSIRDYC
LSIRDYF
CSSC
CSSF
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RCC_CIR
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFGRST
USART1RST
HRTIM1EN
TIM16RST
TIM15RST
TIM1RST
SPI1RST
RCC_
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.
0x0C APB2RSTR
Reset value 0 0 0 0 0 0 0
0x2C
0x1C
0x010
Offset
138/1124
RCC_
RCC_CSR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
APB1RSTR
RCC_BDCR
RCC_CFGR3
RCC_CFGR2
RCC_AHBENR
RCC_APB1ENR
RCC_APB2ENR
RCC_AHBRSTR
0
Res. Res. Res. LPWRSTF Res. Res. Res. Res. Res. 31
0
Res. Res. Res. WWDGRSTF Res. Res.. Res. Res. Res. 30
0
0
0
0
Res. Res. Res. IWDGRSTF Res. DAC1EN HRTIM1EN Res. DAC1RST 29
0
0
0
0
0
Res. Res. Res. PORRSTF Res. Res. Res. Res. Res. 27
0
0
0
0
0
0
0
0
Res. Res. Res. RMVF Res. Res. Res. TSCEN Res. 24
Res. Res. Res Res. Res. Res. Res. Res. Res. 23
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0364 Rev 4
0
0
0
0
0
0
0
0
0
0
0
SEL
[1:0]
RTC
0
0
0
0
[4:0]
0
0
ADC12PRES
0
1
0
1
0
[1:0]
DRV
0
0
0
0
0
0
0
0
0
0
0
0
PREDIV[3:0]
Res. LSION LSEON TIM2EN SYSCFGEN DMA1EN TIM2RST 0
RM0364
RM0364 General-purpose I/Os (GPIO)
9.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), a 32-bit set/reset register (GPIOx_BSRR), a 32-bit locking
register (GPIOx_LCKR) and two 32-bit alternate function selection registers (GPIOx_AFRH
and GPIOx_AFRL).
Figure 13 and Figure 14 show the basic structures of a standard and a 5-Volt tolerant I/O
port bit, respectively. Table 27 gives the possible port bit configurations.
Analog
To on-chip
peripheral Alternate function input
Read VDD
VDD
Bit set/reset registers
Protection
trigger on/off
Pull diode
up
Input driver I/O pin
Output data register
Write
To on-chip Analog
peripheral
Alternate function input
on/off
Input data register
Read
VDD VDD_FT (1)
TTL Schmitt
Bit set/reset registers
Protection
trigger on/off
Pull diode
up
Input driver I/O pin
Write
Output data register
1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.
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.
ai15940b
trigger
on/off
Write protection
Input driver diode
Output data register
pull
up
I/O pin
Output driver VDD on/off
ai15941b
Figure 17 shows the alternate function configuration of the I/O port bit.
Read
VDD VDD
TTL Schmitt on/off
Bit set/reset registers
trigger protection
Pull diode
Input driver up
Write
Output data register
I/O pin
Output driver VDD on/off
Pull protection
P-MOS down diode
Output
control VSS VSS
N-MOS
Read/write
VSS push-pull or
open-drain
From on-chip
peripheral Alternate function output
ai15942b
Analog
To on-chip
peripheral
Input data register
Read off
0
VDD
Bit set/reset registers
TTL Schmitt
trigger protection
Write diode
Output data register
Input driver
I/O pin
protection
diode
Read/write VSS
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
Note: bits 10 and 11 of GPIOF_MODER are reserved and must be kept at reset state.
31 30 29 28 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
OSPEEDR15 OSPEEDR14 OSPEEDR13 OSPEEDR12 OSPEEDR11 OSPEEDR10 OSPEEDR9 OSPEEDR8
[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
OSPEEDR7 OSPEEDR6 OSPEEDR5 OSPEEDR4 OSPEEDR3 OSPEEDR2 OSPEEDR1 OSPEEDR0
[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
PUPDR15[1:0] PUPDR14[1:0] PUPDR13[1:0] PUPDR12[1:0] PUPDR11[1:0] PUPDR10[1:0] PUPDR9[1:0] PUPDR8[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
PUPDR7[1:0] PUPDR6[1:0] PUPDR5[1:0] PUPDR4[1:0] PUPDR3[1:0] PUPDR2[1:0] PUPDR1[1:0] PUPDR0[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
IDR15 IDR14 IDR13 IDR12 IDR11 IDR10 IDR9 IDR8 IDR7 IDR6 IDR5 IDR4 IDR3 IDR2 IDR1 IDR0
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
ODR15 ODR14 ODR13 ODR12 ODR11 ODR10 ODR9 ODR8 ODR7 ODR6 ODR5 ODR4 ODR3 ODR2 ODR1 ODR0
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
LOCK sequence has been applied on a port bit, the value of this port bit can no longer be
modified until the next MCU reset or peripheral reset.
Note: A specific write sequence is used to write to the GPIOx_LCKR register. Only word access
(32-bit long) is allowed during this locking sequence.
Each lock bit freezes a specific configuration register (control and alternate function
registers).
Address offset: 0x1C
Reset value: 0x0000 0000
31 30 29 28 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
AFR7[3:0] AFR6[3:0] AFR5[3:0] AFR4[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
AFR3[3:0] AFR2[3:0] AFR1[3:0] AFR0[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 AFRy[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
AFRy selection:
1000: AF8 (Ports A and B only)
0000: AF0
1001: AF9 (Ports A and B only)
0001: AF1
1010: AF10 (Ports A and B only)
0010: AF2
1011: AF11 (Ports A and B only)
0011: AF3
1100: AF12 (Ports A and B only)
0100: AF4
1101: AF13 (Ports A and B only)
0101: AF5
1110: AF14 (Ports A and B only)
0110: AF6
1111: AF15 (Ports A and B only)
0111: AF7
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AFR15[3:0] AFR14[3:0] AFR13[3:0] AFR12[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
AFR11[3:0] AFR10[3:0] AFR9[3:0] AFR8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 AFRy[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
AFRy selection:
0000: AF0 1000: AF8 (Ports A and B only)
0001: AF1 1001: AF9 (Ports A and B only)
0010: AF2 1010: AF10 (Ports A and B only)
0011: AF3 1011: AF11 (Ports A and B only)
0100: AF4 1100: AF12 (Ports A and B only)
0101: AF5 1101: AF13 (Ports A and B only)
0110: AF6 1110: AF14 (Ports A and B only)
0111: AF7 1111: AF15 (Ports A and B only)
31 30 29 28 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
0x0C
9.4.12
RM0364
F)
F)
F)
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
GPIOA_PUPDR
GPIOx_MODER
GPIOB_MODER
GPIOA_MODER
GPIOx_OTYPER
GPIOx_OSPEEDR
GPIOB_OSPEEDR
GPIOA_OSPEEDR
Offset Register name
(where x = C, D and
(where x = A..D and
(where x = C, D and
0
0
0
0
0
0
1
Res. 31
PUPDR15[1:0] OSPEEDR15[1:0] OSPEEDR15[1:0] OSPEEDR15[1:0] MODER15[1:0] MODER15[1:0] MODER15[1:0]
1
0
0
1
0
0
0
Res. 30
1
0
0
1
0
0
1
Res. 29
PUPDR14[1:0] OSPEEDR14[1:0] OSPEEDR14[1:0] OSPEEDR14[1:0] MODER14[1:0] MODER14[1:0] MODER14[1:0]
0
0
0
1
0
0
0
Res. 28
0
0
0
1
0
0
1
Res. 27
PUPDR13[1:0] OSPEEDR13[1:0] OSPEEDR13[1:0] OSPEEDR13[1:0] MODER13[1:0] MODER13[1:0] MODER13[1:0]
GPIO register map
1
0
0
1
0
0
Res. 0 26
0
0
0
0
0
0
0
Res. 25
PUPDR12[1:0] OSPEEDR12[1:0] OSPEEDR12[1:0] OSPEEDR12[1:0] MODER12[1:0] MODER12[1:0] MODER12[1:0]
0
0
0
0
0
0
0
Res. 24
0
0
0
0
0
0
0
Res. 23
PUPDR11[1:0] OSPEEDR11[1:0] OSPEEDR11[1:0] OSPEEDR11[1:0] MODER11[1:0] MODER11[1:0] MODER11[1:0]
0
0
0
0
0
0
0
Res. 22
0
0
0
0
0
0
0
Res. 21
PUPDR10[1:0] OSPEEDR10[1:0] OSPEEDR10[1:0] OSPEEDR10[1:0] MODER10[1:0] MODER10[1:0] MODER10[1:0]
0
0
0
0
0
0
0
Res. 20
0
0
0
0
0
0
0
Res. 19
PUPDR9[1:0] OSPEEDR9[1:0] OSPEEDR9[1:0] OSPEEDR9[1:0] MODER9[1:0] MODER9[1:0] MODER9[1:0]
0
0
0
0
0
0
0
Res. 18
RM0364 Rev 4
0
0
0
0
0
0
0
Res. 17
PUPDR8[1:0] OSPEEDR8[1:0] OSPEEDR8[1:0] OSPEEDR8[1:0] MODER8[1:0] MODER8[1:0] MODER8[1:0]
0
0
0
0
0
0
0
Res. 16
0
0
0
0
0
0
0
0
OT15 15
PUPDR7[1:0] OSPEEDR7[1:0] OSPEEDR7[1:0] OSPEEDR7[1:0] MODER7[1:0] MODER7[1:0] MODER7[1:0]
0
0
0
0
0
0
0
0
OT14 14
0
0
0
0
0
0
0
0
OT13 13
PUPDR6[1:0] OSPEEDR6[1:0] OSPEEDR6[1:0] OSPEEDR6[1:0] MODER6[1:0] MODER6[1:0] MODER6[1:0]
0
0
0
0
0
0
0
0
OT12 12
0
0
0
0
0
0
0
0 OT11
Table 28. GPIO register map and reset values
0
0
0
0
0
0
0
OT10 10
The following table gives the GPIO register map and reset values.
0
0
0
0
0
1
0
OT9 9
PUPDR4[1:0] OSPEEDR4[1:0] OSPEEDR4[1:0] OSPEEDR4[1:0] MODER4[1:0] MODER4[1:0] MODER4[1:0]
0
0
0
0
0
0
0
OT8 8
0
0
1
0
0
1
0
OT7 7
PUPDR3[1:0] OSPEEDR3[1:0] OSPEEDR3[1:0] OSPEEDR3[1:0] MODER3[1:0] MODER3[1:0] MODER3[1:0]
0
0
1
0
0
0
0
OT6 6
0
0
0
0
0
0
0
0
OT5 5
PUPDR2[1:0] OSPEEDR2[1:0] OSPEEDR2[1:0] OSPEEDR2[1:0] MODER2[1:0] MODER2[1:0] MODER2[1:0]
0
0
0
0
0
0
0
0
OT4 4
0
0
0
0
0
0
0
0
OT3 3
PUPDR1[1:0] OSPEEDR1[1:0] OSPEEDR1[1:0] OSPEEDR1[1:0] MODER1[1:0] MODER1[1:0] MODER1[1:0]
0
0
0
0
0
0
0
0
OT2 2
0
0
0
0
0
0
0
0
OT1 1
PUPDR0[1:0] OSPEEDR0[1:0] OSPEEDR0[1:0] OSPEEDR0[1:0] MODER0[1:0] MODER0[1:0] MODER0[1:0]
0
0
0
0
0
0
0
0
OT0 0
155/1124
General-purpose I/Os (GPIO)
156
General-purpose I/Os (GPIO) RM0364
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
PUPDR15[1:0]
PUPDR14[1:0]
PUPDR13[1:0]
PUPDR12[1:0]
PUPDR10[1:0]
PUPDR11[1:0]
PUPDR9[1:0]
PUPDR8[1:0]
PUPDR7[1:0]
PUPDR6[1:0]
PUPDR5[1:0]
PUPDR4[1:0]
PUPDR3[1:0]
PUPDR2[1:0]
PUPDR1[1:0]
PUPDR0[1:0]
GPIOB_PUPDR
0x0C
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 1 0 0 0 0 0 0 0 0
GPIOx_IDR
IDR15
IDR14
IDR13
IDR12
IDR10
IDR11
IDR9
IDR8
IDR7
IDR6
IDR5
IDR4
IDR3
IDR2
IDR1
IDR0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
(where x = A..D and
0x10 F)
Reset value x x x x x x x x x x x x x x x x
GPIOx_ODR
ODR15
ODR14
ODR13
ODR12
ODR10
ODR11
ODR9
ODR8
ODR7
ODR6
ODR5
ODR4
ODR3
ODR2
ODR1
ODR0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
(where x = A..D and
0x14 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
(where x = A..D and
0x18 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
GPIOx_LCKR
LCK15
LCK14
LCK13
LCK12
LCK10
LCK11
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.
(where x = A..D and
0x1C F)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_AFRL
AFRLAFR7[3 AFRLAFR6[3 AFRLAFR5[3 AFRLAFR4[3 AFRLAFR3[3 AFRLAFR2[3: AFRLAFR1[3 AFRLAFR0[3
(where x = A..D and
0x20 :0] :0] :0] :0] :0] 0] :0] :0]
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
GPIOx_AFRH
AFRHAFR15[ AFRHAFR14[ AFRHAFR13[ AFRHAFR12[ AFRHAFR11[ AFRHAFR10[ AFRHAFR9[ AFRHAFR8[
(where x = A..D and
0x24 3:0] 3:0] 3:0] 3:0] 3:0] 3:0] 3:0] 3:0]
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
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
(where x = A..D and
0x28 F))
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The STM32F334xx devices feature a set of configuration registers. The main purposes of
the system configuration controller are the following:
• Enabling/disabling I2C Fm+ on some I/O ports
• Remapping some DMA trigger sources from TIM16, TIM17, TIM6, SPI1, I2C1,
DAC1_CH1,TIM7 and to different DMA channels
• Remapping the memory located at the beginning of the code area
• Managing the external interrupt line connection to the GPIOs
• Remapping TIM1 ITR3 source
• Remapping DAC1 and DAC2 triggers
• Managing robustness feature
• Configuring encoder mode
• CCM SRAM pages protection
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
I2C_ I2C_ I2C_ I2C_
ENCODER_ I2C1_
FPU_IE[5..0] Res Res Res PB9_ PB8_ PB7_ PB6_
MODE FMP
FMP FMP FMP FMP
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
DAC2_ TIM7_ TIM6_
TIM17_ TIM16_ DAC_ TIM1_
CH1_D DAC2_ DAC1_
DMA_ DMA_ Res Res Res TRIG_ ITR3_ Res Res Res Res MEM_MODE
MA_R DMA_ DMA_
RMP RMP RMP RMP
MP RMP RMP
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
PAGE PAGE PAGE PAGE
Res. Res. Res. Res Res Res Res Res Res Res Res Res
3_WP 2_WP 1_WP 0_WP
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
EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[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. 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
EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Some of the I/O pins mentioned in the above register may not be available on small
packages.
31 30 29 28 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
EXTI11[3:0] EXTI10[3:0] EXTI9[3:0] EXTI8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Some of the I/O pins mentioned in the above register may not be available on small
packages.
31 30 29 28 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
EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Some of the I/O pins mentioned in the above register may not be available on small
packages.
31 30 29 28 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
SRAM_
SRAM_ BYP_ADDR PVD_ LOCKUP
Res Res Res Res Res Res Res Res Res Res Res PARITY
PEF _PAR LOCK _LOCK
_LOCK
rc_w1 rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DAC1_ DAC1_
Res Res Res Res Res Res Res Res Res Res Res Res Res Res TRIG5_ TRIG3_
RMP RMP
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADC2_DMA_ I2C1_TX_DMA_ I2C1_RX_DMA_ SPI1_TX_DMA_ SPI1_RX_DMA_
Res Res Res Res Res Res
RMP RMP RMP RMP RMP
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
TIM7_DAC2_DMA_RMP
TIM6_DAC1_DMA_RMP
ENCODER_MODE [1:0]
DAC2_CH1_DMA_RMP
TIM17_DMA_RMP
TIM16_DMA_RMP
DAC_TRIG_RMP
TIM1_ITR3_RMP
I2C_PB9_FMP
I2C_PB8_FMP
I2C_PB7_FMP
I2C_PB6_FMP
MEM_MODE
I2C1_FMP
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
SYSCFG_CFGR1 FPU_IE[5..0]
0x00
Reset value 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X X
PAGE[3: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
SYSCFG_RCR
0x04 WP
Reset value 0 0 0 0
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
0x50
0x18
Offset
RM0364
.
.
.
Register
Reset value
Reset value
SYSCFG_CFGR3
SYSCFG_CFGR2
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
RM0364 Rev 4
0
DAC1_TRIG5_RMP Res 17
0
DAC1_TRIG3_RMP Res 16
.
.
Res. Res 15
Res Res 14
Res Res 13
Res Res 12
Res Res 11
Res Res 10
1
Res 9
Refer to Section 2.2 on page 47 for the register boundary addresses.
ADC2_DMA_RMP
0
0
SRAM_PEF 8
Table 29. SYSCFG register map and reset values (continued)
Res 7
I2C1_TX_DMA_RMP
0
Res 6
0
Res 5
I2C1_RX_DMA_RMP
0
0
BYP_ADDR_PAR 4
0
Res 3
SPI1_TX_DMA_RMP
0
0
PVD_LOCK 2
0
0
SRAM_PARITY_LOCK 1
SPI1_RX_DMA_RMP
0
0
LOCKUP_LOCK 0
System configuration controller (SYSCFG)
169/1124
169
Direct memory access controller (DMA) RM0364
11.1 Introduction
The direct memory access (DMA) controller is a bus master and system peripheral.
The DMA is used to perform programmable data transfers between memory-mapped
peripherals and/or memories, upon the control of an off-loaded CPU.
The DMA controller features a single AHB master architecture.
There is one instance of DMA with 7 channels.
Each channel is dedicated to managing memory access requests from one or more
peripherals. The DMA includes an arbiter for handling the priority between DMA requests.
11.3.1 DMA
DMA is implemented with the hardware configuration parameters shown in the table below.
Number of channels 7
High priority
ADC1
TIM2_CH3 HW request 1 Channel 1
(1)
TIM17_CH1
SW trigger 1
TIM17_UP (1)
(MEM2MEM bit)
(1)
SPI1_RX
USART3_TX
TIM1_CH1 HW request 2 Channel 2
TIM2_UP
TIM3_CH3 SW trigger 2
ADC2 ( MEM2MEM bit)
(1)
I2C1_TX
HRTIM1_M
(1)
SPI1_TX
USART3_RX Internal
TIM1_CH2 HW request 3 Channel 3 DMA
(1)
TIM6_UP request
(1) SW trigger 3
DAC1_CH1
(1)
TIM16_CH1 ( MEM2MEM bit)
(1)
TIM16_UP
(1)
I2C1_RX
(1) HRTIM1_A
SPI1_RX
USART1_TX
(1)
I2C1_TX HW request 4 Channel 4
TIM1_CH4
TIM1_TRIG SW trigger 4
TIM1_COM (1) ( MEM2MEM bit)
(1)
TIM7_UP SPI1_TX
(1) USART1_RX
DAC1_CH2 (1)
ADC2 I2C1_RX
HRTIM1_B TIM1_UP
TIM2_CH1 HW request 5 Channel 5
(1)
DAC2_CH1
TIM15_CH1 SW trigger 5
TIM15_UP ( MEM2MEM bit)
TIM15_TRIG
USART2_RX TIM15_COM
I2C1_TX (1) HRTIM1_C
TIM1_CH3 HW request 6 Channel 6
TIM3_CH1
TIM3_TRIG SW trigger 6
(1)
TIM16_CH1 ( MEM2MEM bit)
TIM16_UP (1) USART2_TX
(1)
SPI1_RX I2C1_RX (1)
HRTIM1_D TIM2_CH2
HW request 7 Channel 7
TIM2_CH4
TIM17_CH1 (1) SW trigger 7
(1)
TIM17_UP ( MEM2MEM bit)
(1)
SPI1_TX Low priority
HRTIM1_E
MS33151V1
1. DMA request mapped on this DMA channel only if the corresponding remapping bit is set in SYSCFG configuration register
1 (SYSCFG_CFGR1) and SYSCFG configuration register 3 (SYSCFG_CFGR3).
TIM7_UP
TIM7/DAC - - - DAC1_CH2 - - -
(1)
DAC - - - - DAC2_CH1(1) - -
TIM15_CH1
TIM15_UP
TIM15 - - - - - -
TIM15_TRIG
TIM15_COM
TIM16_CH1 TIM16_CH1
TIM16 - - - - -
TIM16_UP TIM16_UP(1)
TIM17_CH1 TIM17_CH1
TIM17 - - - - -
TIM17_UP TIM17_UP(1)
HRTIM1 - HRTIM1_M HRTIM1_A HRTIM1_B HRTIM1_C HRTIM1_D HRTIM1_E
1. DMA request mapped on this DMA channel only if the corresponding remapping bit is set in SYSCFG configuration
register 1 (SYSCFG_CFGR1) and SYSCFG configuration register 3 (SYSCFG_CFGR3)
ICode
FLITF Flash
DCode
Cortex-M4
System
ICode SRAM (4K) +
DCode SRAM (12K)
GPIOA, B, C, D, F
Bus matrix
ADCs 1, 2
DMA
DMA
Ch.1 CRC TS
Ch.2 Bridge 2
AHB System bus APB2
Ch.7 Bridge 1
DMA
DMA request
DAC1_CH1 TIM2
DAC1_CH2 TIM3
DAC2_CH1 TIM6
USART2 TIM7
USART3
I2C
DMA request
MS33149V2
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 32. Programmable data width and endian behavior (when PINC = MINC = 1)
Source Destinat
port ion port Destination
Number Source content:
width width content:
of data address / data
(MSIZE (PSIZE address / data
items to (DMA_CMARx if DMA transfers
if if (DMA_CPARx if
transfer DIR = 1, else
DIR = 1, DIR = 1, DIR = 1, else
(NDT) DMA_CPARx)
else else DMA_CMARx)
PSIZE) MSIZE)
@0x0 / B0 1: read B0[7:0] @0x0 then write 00B0[15:0] @0x0 @0x0 / 00B0
@0x1 / B1 2: read B1[7:0] @0x1 then write 00B1[15:0] @0x2 @0x2 / 00B1
8 16 4
@0x2 / B2 3: read B2[7:0] @0x2 then write 00B2[15:0] @0x4 @0x4 / 00B2
@0x3 / B3 4: read B3[7:0] @0x3 then write 00B3[15:0] @0x6 @0x6 / 00B3
@0x0 / B0 1: read B0[7:0] @0x0 then write 000000B0[31:0] @0x0 @0x0 / 000000B0
@0x1 / B1 2: read B1[7:0] @0x1 then write 000000B1[31:0] @0x4 @0x4 / 000000B1
8 32 4
@0x2 / B2 3: read B2[7:0] @0x2 then write 000000B2[31:0] @0x8 @0x8 / 000000B2
@0x3 / B3 4: read B3[7:0] @0x3 then write 000000B3[31:0] @0xC @0xC / 000000B3
@0x0 / B1B0 1: read B1B0[15:0] @0x0 then write B0[7:0] @0x0 @0x0 / B0
@0x2 / B3B2 2: read B3B2[15:0] @0x2 then write B2[7:0] @0x1 @0x1 / B2
16 8 4
@0x4 / B5B4 3: read B5B4[15:0] @0x4 then write B4[7:0] @0x2 @0x2 / B4
@0x6 / B7B6 4: read B7B6[15:0] @0x6 then write B6[7:0] @0x3 @0x3 / B6
@0x0 / B1B0 1: read B1B0[15:0] @0x0 then write B1B0[15:0] @0x0 @0x0 / B1B0
@0x2 / B3B2 2: read B3B2[15:0] @0x2 then write B3B2[15:0] @0x2 @0x2 / B3B2
16 16 4
@0x4 / B5B4 3: read B5B4[15:0] @0x4 then write B5B4[15:0] @0x4 @0x4 / B5B4
@0x6 / B7B6 4: read B7B6[15:0] @0x6 then write B7B6[15:0] @0x6 @0x6 / B7B6
@0x0 / B1B0 1: read B1B0[15:0] @0x0 then write 0000B1B0[31:0] @0x0 @0x0 / 0000B1B0
@0x2 / B3B2 2: read B3B2[15:0] @0x2 then write 0000B3B2[31:0] @0x4 @0x4 / 0000B3B2
16 32 4
@0x4 / B5B4 3: read B5B4[15:0] @0x4 then write 0000B5B4[31:0] @0x8 @0x8 / 0000B5B4
@0x6 / B7B6 4: read B7B6[15:0] @0x6 then write 0000B7B6[31:0] @0xC @0xC / 0000B7B6
@0x0 / B3B2B1B0 1: read B3B2B1B0[31:0] @0x0 then write B0[7:0] @0x0 @0x0 / B0
@0x4 / B7B6B5B4 2: read B7B6B5B4[31:0] @0x4 then write B4[7:0] @0x1 @0x1 / B4
32 8 4
@0x8 / BBBAB9B8 3: read BBBAB9B8[31:0] @0x8 then write B8[7:0] @0x2 @0x2 / B8
@0xC / BFBEBDBC 4: read BFBEBDBC[31:0] @0xC then write BC[7:0] @0x3 @0x3 / BC
@0x0 / B3B2B1B0 1: read B3B2B1B0[31:0] @0x0 then write B1B0[15:0] @0x0 @0x0 / B1B0
@0x4 / B7B6B5B4 2: read B7B6B5B4[31:0] @0x4 then write B5B4[15:0] @0x2 @0x2 / B5B4
32 16 4
@0x8 / BBBAB9B8 3: read BBBAB9B8[31:0] @0x8 then write B9B8[15:0] @0x4 @0x4 / B9B8
@0xC / BFBEBDBC 4: read BFBEBDBC[31:0] @0xC then write BDBC[15:0] @0x6 @0x6 / BDBC
@0x0 / B3B2B1B0 1: read B3B2B1B0[31:0] @0x0 then write B3B2B1B0[31:0] @0x0 @0x0 / B3B2B1B0
@0x4 / B7B6B5B4 2: read B7B6B5B4[31:0] @0x4 then write B7B6B5B4[31:0] @0x4 @0x4 / B7B6B5B4
32 32 4
@0x8 / BBBAB9B8 3: read BBBAB9B8[31:0] @0x8 then write BBBAB9B8[31:0] @0x8 @0x8 / BBBAB9B8
@0xC / BFBEBDBC 4: read BFBEBDBC[31:0] @0xC then write BFBEBDBC[31:0] @0xC @0xC / BFBEBDBC
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. 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
CHTIF7
CTCIF7
CHTIF6
CTCIF6
CHTIF5
CTCIF5
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
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
CTCIF7
CTCIF6
CTCIF5
CTCIF4
CTCIF3
CTCIF2
CTCIF1
CHTIF7
CHTIF6
CHTIF5
CHTIF4
CHTIF3
CHTIF2
CHTIF1
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.
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.
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_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
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
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
for a specific flag. Each input line can be masked independently for interrupt or event
generation, in addition the internal lines are sampled only in STOP mode. This controller
allows also to emulate the (only) external events by software, multiplexed with the
corresponding hardware event line, by writing to a dedicated register.
28 28 28 28 28
28
Event
mask
register
MS30250V1
PA0
PB0 EXTI0
PC0
PD0
PE0
PF0
PA1
PB1 EXTI1
PC1
PD1
PE1
PF1
...
PA15
PB15 EXTI15
PC15
PD15
PE15
PF15
MS19951V1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. MR30 Res. Res. Res. Res. MR25 Res. MR23 MR22 Res. MR20 MR19 Res. MR17 MR16
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MR15 MR14 MR13 MR12 MR11 MR10 MR9 MR8 MR7 MR6 MR5 MR4 MR3 MR2 MR1 MR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The reset value for the internal lines (23 and 25) and reserved lines is set to '1'.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. MR30 Res. Res. Res. Res. MR25 Res. MR23 MR22 Res. MR20 MR19 Res. MR17 MR16
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MR15 MR14 MR13 MR12 MR11 MR10 MR9 MR8 MR7 MR6 MR5 MR4 MR3 MR2 MR1 MR0
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. TR30 Res. Res. Res. Res. Res. Res. Res. TR22 Res. TR20 TR19 Res. TR17 TR16
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TR15 TR14 TR13 TR12 TR11 TR10 TR9 TR8 TR7 TR6 TR5 TR4 TR3 TR2 TR1 TR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The external wakeup lines are edge-triggered. No glitches must be generated on these
lines. If a rising edge on an external interrupt line occurs during a write operation in the
EXTI_RTSR register, the pending bit is not set.
Rising and falling edge triggers can be set for the same interrupt line. In this case, both
generate a trigger condition.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. TR30 Res Res. Res. Res. Res. Res. Res. TR22 Res. TR20 TR19 Res. TR17 TR16
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TR15 TR14 TR13 TR12 TR11 TR10 TR9 TR8 TR7 TR6 TR5 TR4 TR3 TR2 TR1 TR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 20:19 TRx: Falling trigger event configuration bit of line x (x = 20 to 19)
0: Falling trigger disabled (for Event and Interrupt) for input line
1: Falling trigger enabled (for Event and Interrupt) for input line.
Bit 18 Reserved, must be kept at reset value.
Bits 17:0 TRx: Falling trigger event configuration bit of line x (x = 17 to 0)
0: Falling trigger disabled (for Event and Interrupt) for input line
1: Falling trigger enabled (for Event and Interrupt) for input line.
Note: The external wakeup lines are edge-triggered. No glitches must be generated on these
lines. If a falling edge on an external interrupt line occurs during a write operation to the
EXTI_FTSR register, the pending bit is not set.
Rising and falling edge triggers can be set for the same interrupt line. In this case, both
generate a trigger condition.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SWIER SWIER SWIER SWIER SWIER SWIER
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
30 22 20 19 17 16
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
SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER
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. PR30 Res. Res. Res. Res. Res. Res. Res. PR22 Res. PR20 PR19 Res. PR17 PR16
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PR15 PR14 PR13 PR12 PR11 PR10 PR9 PR8 PR7 PR6 PR5 PR4 PR3 PR2 PR1 PR0
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. MR32
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. MR32
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. TR32
rw
Note: The external wakeup lines are edge-triggered. No glitches must be generated on these
lines. If a rising edge on an external interrupt line occurs during a write operation to the
EXTI_RTSR register, the pending bit is not set.
Rising and falling edge triggers can be set for the same interrupt line. In this case, both
generate a trigger condition.
31 30 29 28 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. TR32
rw
Note: The external wakeup lines are edge-triggered. No glitches must be generated on these
lines. If a falling edge on an external interrupt line occurs during a write operation to the
EXTI_FTSR register, the pending bit is not set.
Rising and falling edge triggers can be set for the same interrupt line. In this case, both
generate a trigger condition.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
SWIER
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
32
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. PR32
rc_w1
Table 36. External interrupt/event controller register map and reset values
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
MR[31:0]
MR[31:0]
MR[31:0]
MR[31:0]
MR[31:0]
MR[31:0]
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_IMR1 MR[31:0]
0x00
Reset value 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MR[31:0]
MR[31:0]
MR[31:0]
MR[31:0]
MR[31:0]
MR[31:0]
MR[31:0]
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_EMR1
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
TR[31:29]
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_RTSR1 TR[22:0]
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
0x2C
0x0C
0x0C
Offset
RM0364
EXTI_PR1
EXTI_PR1
Register
EXTI_IMR2
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
EXTI_EMR2
EXTI_FTSR2
EXTI_FTSR1
EXTI_FTSR1
EXTI_RTSR2
EXTI_RTSR1
EXTI_SWIER1
EXTI_SWIER1
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 31
0
0
0
0
0
0
TR[31:29] 0
PR
Res. Res. Res. Res. PR[31:29] SWIER[31:29] TR[31:29] TR[31:29] 30
[31:29]
[31:29]
SWIER
0
0
0
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0364 Rev 4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TR[22:0]
PR[22:0]
Res. Res. Res. Res. 10
SWIER[22:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
PR[22:0]
0
0
0
0
0
0
0
SWIER[22:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TR32 TR32 MR32 MR32 0
209/1124
Interrupts and events
210
0x34
0x30
Offset
210/1124
EXTI_PR2
Register
Reset value
Reset value
EXTI_SWIER2
Interrupts and events
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
RM0364 Rev 4
Res. Res. 17
Res. Res. 16
Res. 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 47 for the register boundary addresses.
Res. Res. 8
Res. Res. 7
Res. Res. 6
Res. Res. 5
Res. Res. 4
Res. Res. 3
Table 36. External interrupt/event controller register map and reset values (continued)
Res. Res. 2
Res. Res. 1
0
0
PR32 SWIER32 0
RM0364
RM0364 Analog-to-digital converters (ADC)
13.1 Introduction
This section describes the implementation of up to 2 ADCs:
• ADC1 and ADC2 are tightly coupled and can operate in dual mode (ADC1 is master).
Each ADC consists of a 12-bit successive approximation analog-to-digital converter.
Each ADC has up to 18 multiplexed channels. 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 ADCs are mapped on the AHB bus to allow fast data handling.
The analog watchdog features allow the application to detect if the input voltage goes
outside the user-defined high or low thresholds.
An efficient low-power mode is implemented to allow very low consumption at low
frequency.
• Conversion modes
– Each ADC can convert a single channel or can scan a sequence of channels
– Single mode converts selected inputs once per trigger
– Continuous mode converts selected inputs continuously
– Discontinuous mode
• Dual ADC mode
• Interrupt generation at the end of conversion (regular or injected), end of sequence
conversion (regular or injected), analog watchdog 1, 2 or 3 or overrun events
• 3 analog watchdogs per ADC
• ADC supply requirements: 2.0 V to 3.6 V
• ADC input range: VREF– ≤ VIN ≤ VREF+
Figure 23 shows the block diagram of one ADC.
VREF+
2.0 V to 3.6 V
Cortex
AREADY
M4 with
EOSMP
ADC Interrupt FPU
EOC
EOS IRQ
OVR
RDATA[11:0] JEOS master
AHB
JQOVF slave
AWDx
JDATA1[11:0] master
ADEN/ADDIS
JAUTO Analog Supply (VDDA)
2.0 V to 3.6 V JDATA2[11:0]
JDATA3[11:0] DMA
ADC_JSQRx
JDATA4[11:0] AHB
ADC_SQRx autopower-down interface DMA request
CONT
single/cont
VOPAMPx Bias & Ref
VTS
ADCAL
VREFINT self calibration DMACFG
VBAT VINP[18:1] Input DMAEN
ADC_IN selection & VIN SAR ADC
VINN[18:1] scan control
[15:1]
analog input CONVERTED
VREF- channels SMPx[2:0] DATA
sampling time start
Start & Stop
Control
AUTDLY OVRMOD
auto delayed S/W trigger overrun mode
ADSTP ALIGN
stop conv left/right
RES[1:0]
12, 10, 8 bits
JOFFSETx[11:0]
EXT0 JOFFSETx_CH[11:0]
EXT1 h/w
EXT2 trigger
....... DISCEN
....... EXTEN[1:0] DISCNU[:0]
trigger enable Analog watchdog 1,2,3
EXT13 and edge selection Discontinuous
EXT14
mode TIMERs
EXT15
AWD1 AWD1_OUT
EXTi mapped at AWD2 AWD2_OUT ETR
EXTSEL[3:0] AWD3 AWD3_OUT
product level trigger selection
J
S/W trigger
AWD1EN
JEXT0 JAWD1EN
JEXT1 H/W AWD1SGL
JEXT2 trigger
JDISCEN AWDCH1[4:0]
.......
....... JEXTEN[1:0] JDISCNUM[2:0] LT1[11:0]
trigger enable
JEXT13 and edge selection HT1[11:0]
JQM
JEXT14 Injced Context AWDCH2[18:0]
JEXT15 Queue Mode LT2[7:0]
JEXTi mapped at AWDCH3[18:0]
product level HT2[7:0]
JEXTSEL[3:0]
trigger selection HT3[7:0]
LT3[7:0]
MSv30260V4
Input, analog reference The higher/positive reference voltage for the ADC,
VREF+
positive 2.0 V ≤ VREF+ ≤ VDDA
Analog power supply equal VDDA:
VDDA Input, analog supply
2.0V ≤ VDDA ≤ 3.6 V
Input, analog reference The lower/negative reference voltage for the ADC,
VREF-
negative VREF- = VSSA
VSSA Input, analog supply ground Ground for analog power supply equal to VSS
Positive input analog Connected either to external channels: ADC_INi or
VINP[18:1]
channels for each ADC internal channels.
Negative input analog
VINN[18:1] Connected to VREF- or external channels: ADC_INi-1
channels for each ADC
Up to 16 analog input channels (x = ADC number = 1
or 2):
ADCx_IN15:1 External analog input signals
– 5 fast channels
– 10 slow channels
13.3.3 Clocks
Dual clock domain architecture
The dual clock-domain architecture means that each ADC clock is independent from the
AHB bus clock.
The input clock of the two ADCs (master and slave) can be selected between two different
clock sources (see Figure 24: ADC clock scheme):
a) The ADC clock can be a specific clock source, named “ADCxy_CK (xy=12 or 34)
which is independent and asynchronous with the AHB clock”.
It can be configured in the RCC to deliver up to 72 MHz (PLL output). Refer to
RCC Section for more information on generating ADC12_CK.
To select this scheme, bits CKMODE[1:0] of the ADCx_CCR register must be
reset.
b) The ADC clock can be derived from the AHB clock of the ADC bus interface,
divided by a programmable factor (1, 2 or 4). In this mode, a programmable divider
factor can be selected (/1, 2 or 4 according to bits CKMODE[1:0]).
To select this scheme, bits CKMODE[1:0] of the ADCx_CCR register must be
different from “00”.
Note: Software can use option b) by writing CKMODE[1:0]=01 only if the AHB prescaler of the
RCC is set to 1 (the duty cycle of the AHB clock must be 50% in this configuration).
Option a) has the advantage of reaching the maximum ADC clock frequency whatever the
AHB clock scheme selected. The ADC clock can eventually be divided by the following ratio:
1, 2, 4, 6, 8, 12, 16, 32, 64, 128, 256; using the prescaler configured with bits
ADCxPRES[4:0] in register RCC_CFGR2 (Refer to Section 8: Reset and clock control
(RCC)).
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).
Bits CKMODE[1:0]
of ADC12_CCR
MSv32648V1
1. Refer to the RCC section to see how HCLK and ADC12_CK can be generated.
ADC2
Differential Mode Channel Selection
VINP[1]
ADC2_IN1 VINN[1] fast channel
VINP[2]
ADC2_IN2 VINN[2] fast channel
VINP[3]
ADC2_IN3 VINN[3] fast channel
VINP[4]
ADC2_IN4 VINN[4] fast channel
VINP[5]
ADC2_IN5 VINN[5] fast channel
VREF+
VINP[6]
VINN[6] slow channel
VINP
VINP[7] SAR
VINN[7] slow channel ADC2
VINP[8] VINN
VINN[8] slow channel
VREF-
VINP[9]
VREF- VINN[9] slow channel
VINP[10] Single-ended
VREF+ Mode
VINN[10] slow channel
VINP[11]
ADC2_IN11 VINN[11] slow channel
VINP[12]
ADC2_IN12 VINN[12] slow channel
VINP[13]
ADC2_IN13 VINN[13] slow channel
VINP[14]
ADC2_IN14 VINN[14] slow channel
VINP[15]
ADC2_IN15 VINN[15] slow channel
VREF-
VREF+ VINP[16]
VREF- VINN[16] reserved
VINP[17]
VOPAMP2 VINN[17] slow channel
VREF-
VINP[18]
VREFINT
VREF- VINN[18] slow channel
VREF-
MS32681V1
Caution: When configuring the channel “i” in differential input mode, its negative input voltage is
connected to ADC_INi+1. As a consequence, channel “i+1” is no longer usable in single-
ended mode or in differential mode and must never be configured to be converted.
Some channels are shared between ADC1 and ADC2: this can make the channel on the
other ADC unusable. Only exception is interleave mode for ADC master and the slave.
Example: Configuring ADC1_IN5 in differential input mode will make ADC12_IN6 not
usable: in that case, the channels 6 of both ADC1 and ADC2 must never be converted.
Note: Channels 16, 17 and 18 of ADC1 and channels 17 and 18 of ADC2 are connected to
internal analog channels and are internally fixed to single-ended inputs configuration
(corresponding bits DIFSEL[i] is always zero). Channel 15 of ADC1 is also an internal
channel and the user must configure the corresponding bit DIFSEL[15] to zero.
will automatically be injected into the analog ADC. This loading is transparent and does not
add any cycle latency to the start of the conversion.
tCAB
ADCAL
MSv30263V2
ADC state Ready (not converting) Converting channel Ready Converting channel
(Single ended) (Single ended)
Updating calibration
Internal
calibration factor[6:0] F1 F2
Start conversion
(hardware or sofware)
WRITE ADC_CALFACT
CALFACT_S[6:0] F2
by s/w by h/w
MSv30529V2
Trigger event
ADC state RDY CONV CH 1 RDY CONV CH2 RDY CONV CH3 RDY CONV CH4
Single ended (Differential (Differential (Single inputs
inputs channel) inputs channel) inputs channel) channel)
Internal
calibration factor[6:0] F2 F3 F2
CALFACT_S[6:0] F2
CALFACT_D[6:0] F3
MSv30530V2
ADEN
tSTAB
ADRDY
ADDIS
ADC REQ
state OFF Startup RDY Converting CH RDY OFF
-OF
by S/W by H/W
MSv30264V2
Warning: The user must ensure that only one of the two ADCs is
converting VREFINT at the same time (it is forbidden to have
several ADCs converting VREFINT at the same time).
Note: To convert one of the internal analog channels, the corresponding analog sources must first
be enabled by programming bits VREFEN, TSEN or VBATEN in the ADCx_CCR registers.
It is possible to organize the conversions in two groups: regular and injected. A group
consists of a sequence of conversions that can be done on any channel and in any order.
For instance, it is possible to implement the conversion sequence in the following order:
ADC_IN3, ADC_IN8, ADC_IN2, ADC_IN2, ADC_IN0, ADC_IN2, ADC_IN2, ADC_IN15.
• A regular group is composed of up to 16 conversions. The regular channels and their
order in the conversion sequence must be selected in the ADCx_SQR registers. The
total number of conversions in the regular group must be written in the L[3:0] bits in the
ADCx_SQR1 register.
• An injected group is composed of up to 4 conversions. The injected channels and
their order in the conversion sequence must be selected in the ADCx_JSQR register.
The total number of conversions in the injected group must be written in the L[1:0] bits
in the ADCx_JSQR register.
ADCx_SQR registers must not be modified while regular conversions can occur. For this,
the ADC regular conversions must be first stopped by writing ADSTP=1 (refer to
Section 13.3.17: Stopping an ongoing conversion (ADSTP, JADSTP)).
It is possible to modify the ADCx_JSQR registers on-the-fly while injected conversions are
occurring. Refer to Section 13.3.21: Queue of context for injected conversions
13.3.16 Timing
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:
TADC = TSMPL + TSAR = 20.83 ns |min + 173.6 ns |12bit = 194.4 ns (for FADC_CLK = 72 MHz)
MS30532V1
When the JADSTP bit is set by software, any ongoing injected conversion is aborted with
partial result discarded (ADCx_JDRy register is not updated with the current conversion).
The scan sequence is also aborted and reset (meaning that relaunching the ADC would re-
start a new sequence).
Once this procedure is complete, bits ADSTP/ADSTART (in case of regular conversion), or
JADSTP/JADSTART (in case of injected conversion) are cleared by hardware and the
software must wait until ADSTART = 0 (or JADSTART = 0) before starting a new conversion.
Note: In auto-injection mode (JAUTO=1), setting ADSTP bit aborts both regular and injected
conversions (JADSTP must not be used).
JADSTART
Set Cleared
ADSTART by SW REGULAR CONVERSIONS ongoing by HW
Set Cleared
ADSTP by SW by HW
MS30533V2
Set Cleared
JADSTART by S/W INJECTED CONVERSIONS ongoing by H/W
(software is not allowed to configure injected conversions selection and triggers)
Set Cleared
JADSTP by S/W by H/W
MS30534V1
Table 39. Configuring the trigger polarity for regular external triggers
EXTEN[1:0]/
Source
JEXTEN[1:0]
Figure 33. Triggers are shared between ADC master & ADC slave
ADC MASTER
EXT0
EXTi mapped at EXT1
External regular trigger
product level ..............
EXT15
EXTSEL[3:0]
JEXTSEL[3:0]
ADC SLAVE
EXTSEL[3:0]
JEXT0
JEXTi mapped at JEXT1 External injected trigger
product level ..............
JEXT15
JEXTSEL[3:0]
MSv30535V1
Table 40 to Table 41 give all the possible external triggers of the two ADCs for regular and
injected conversion.
Table 40. ADC1 (master) & 2 (slave) - External triggers for regular channels
Name Source Type EXTSEL[3:0]
Table 40. ADC1 (master) & 2 (slave) - External triggers for regular channels (continued)
Name Source Type EXTSEL[3:0]
Table 41. ADC1 & ADC2 - External trigger for injected channels
Name Source Type JEXTSEL[3..0]
Auto-injection mode
If the JAUTO bit in the ADCx_CFGR register is set, then the channels in the injected group
are automatically converted after the regular group of channels. This can be used to convert
a sequence of up to 20 conversions programmed in the ADCx_SQR and ADCx_JSQR
registers.
In this mode, the ADSTART bit in the ADCx_CR register must be set to start regular
conversions, followed by injected conversions (JADSTART must be kept cleared). Setting
the ADSTP bit aborts both regular and injected conversions (JADSTP bit must not be used).
In this mode, external trigger on injected channels must be disabled.
If the CONT bit is also set in addition to the JAUTO bit, regular channels followed by injected
channels are continuously converted.
Note: It is not possible to use both the auto-injected and discontinuous modes simultaneously.
When the DMA is used for exporting regular sequencer’s data in JAUTO mode, it is
necessary to program it in circular mode (CIRC bit set in DMA_CCRx register). If the CIRC
bit is reset (single-shot mode), the JAUTO sequence will be stopped upon DMA Transfer
Complete event.
ADCCLK
Injection event
Reset ADC
(1)
max. latency
SOC
ai16049b
1. The maximum latency value can be found in the electrical characteristics of the STM32F334xx datasheets.
Note: When a regular group is converted in discontinuous mode, no rollover occurs (the last
subgroup of the sequence can have less than n conversions).
When all subgroups are converted, the next trigger starts the conversion of the first
subgroup. In the example above, the 4th trigger reconverts the channels 1, 2 and 3 in the
1st subgroup.
It is not possible to have both discontinuous mode and continuous mode enabled. In this
case (if DISCEN=1, CONT=1), the ADC behaves as if continuous mode was disabled.
All the parameters of the context are defined into a single register ADCx_JSQR and this
register implements a queue of 2 buffers, allowing the bufferization of up to 2 sets of
parameters:
• The JSQR register can be written at any moment even when injected conversions are
ongoing.
• Each data written into the JSQR register is stored into the Queue of context.
• At the beginning, the Queue is empty and the first write access into the JSQR register
immediately changes the context and the ADC is ready to receive injected triggers.
• Once an injected sequence is complete, the Queue is consumed and the context
changes according to the next JSQR parameters stored in the Queue. This new
context is applied for the next injected sequence of conversions.
• A Queue overflow occurs when writing into register JSQR while the Queue is full. This
overflow is signaled by the assertion of the flag JQOVF. When an overflow occurs, the
write access of JSQR register which has created the overflow is ignored and the queue
of context is unchanged. An interrupt can be generated if bit JQOVFIE is set.
• Two possible behaviors are possible when the Queue becomes empty, depending on
the value of the control bit JQM of register ADCx_CFGR:
– If JQM=0, the Queue is empty just after enabling the ADC, but then it can never be
empty during run operations: the Queue always maintains the last active context
and any further valid start of injected sequence will be served according to the last
active context.
– If JQM=1, the Queue can be empty after the end of an injected sequence or if the
Queue is flushed. When this occurs, there is no more context in the queue and
both injected software and hardware triggers are disabled. Therefore, any further
hardware or software injected triggers are ignored until the software re-writes a
new injected context into JSQR register.
• Reading JSQR register returns the current JSQR context which is active at that
moment. When the JSQR context is empty, JSQR is read as 0x0000.
• The Queue is flushed when stopping injected conversions by setting JADSTP=1 or
when disabling the ADC by setting ADDIS=1:
– If JQM=0, the Queue is maintained with the last active context.
– If JQM=1, the Queue becomes empty and triggers are ignored.
Note: When configured in discontinuous mode (bit JDISCEN=1), only the last trigger of the
injected sequence changes the context and consumes the Queue.The 1st trigger only
consumes the queue but others are still valid triggers as shown by the discontinuous mode
example below (length = 3 for both contexts):
• 1st trigger, discontinuous. Sequence 1: context 1 consumed, 1st conversion carried out
• 2nd trigger, disc. Sequence 1: 2nd conversion.
• 3rd trigger, discontinuous. Sequence 1: 3rd conversion.
• 4th trigger, discontinuous. Sequence 2: context 2 consumed, 1st conversion carried out.
• 5th trigger, discontinuous. Sequence 2: 2nd conversion.
• 6th trigger, discontinuous. Sequence 2: 3rd conversion.
P1 P2 P3
Write JSQR
Trigger 1
ADC J context
EMPTY P1 P2 P3
(returned by reading
JQSR)
ADC state RDY Conversion1 Conversion2 Conversion3 RDY Conversion1 RDY
MS30536V2
1. Parameters:
P1: sequence of 3 conversions, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 4 conversions, hardware trigger 1
Write JSQR
Trigger 1
Ignored
Trigger 2
ADC J context
EMPTY P1 P2 P3
(returned by reading
JQSR)
ADC state RDY Conversion1 Conversion2 RDY Conversion1 RDY
MS30537V2
1. Parameters:
P1: sequence of 2 conversions, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 2
P3: sequence of 4 conversions, hardware trigger 1
Figure 37. Example of JSQR queue of context with overflow before conversion
P1 P2 P3 => Overflow, P4
ignored
Write JSQR
JSQR
EMPTY P1 P1, P2 P2 P2, P4
queue
Cleared by SW
JQOVF
Trigger 1
Trigger 2
ADC
J context
EMPTY P1 P2
(returned by
reading JQSR)
JEOS
MS30538V2
1. Parameters:
P1: sequence of 2 conversions, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 2
P3: sequence of 3 conversions, hardware trigger 1
P4: sequence of 4 conversions, hardware trigger 1
Figure 38. Example of JSQR queue of context with overflow during conversion
P1 P2 P3 => Overflow, P4
ignored
Write JSQR
JSQR
EMPTY P1 P1, P2 P2 P2, P4
queue
Cleared by SW
JQOVF
Trigger 1
Trigger 2
ADC
J context
(returned by EMPTY P1 P2
reading JQSR)
JEOS
MS30539V2
1. Parameters:
P1: sequence of 2 conversions, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 2
P3: sequence of 3 conversions, hardware trigger 1
P4: sequence of 4 conversions, hardware trigger 1
Figure 39. Example of JSQR queue of context with empty queue (case JQM=0)
Write JSQR
EMPTY P1 P1, P2 P2 P3
JSQR queue
Trigger 1
ADC J context
(returned by EMPTY P1 P2 P3
reading JQSR)
ADC state RDY Conversion1 RDY Conversion1 RDY Conversion1 RDY Conversion1 RDY Conv
MS30540V3
1. Parameters:
P1: sequence of 1 conversion, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 1 conversion, hardware trigger 1
Note: When writing P3, the context changes immediately. However, because of internal
resynchronization, there is a latency and if a trigger occurs just after or before writing P3, it
can happen that the conversion is launched considering the context P2. To avoid this
situation, the user must ensure that there is no ADC trigger happening when writing a new
context that applies immediately.
Figure 40. Example of JSQR queue of context with empty queue (case JQM=1)
Queue becomes empty
and triggers are ignored
P1 P2 because JQM=1 P3
Write JSQR
JSQR
EMPTY P1 P1,P2 P2 EMPTY P3 EMPTY
queue
Ignored Ignored
Trigger 1
ADC
J context EMPTY P1 P2 EMPTY (0x0000) P3 EMPTY
(returned by reading JQSR)
ADC state RDY Conversion1 RDY Conversion1 RDY Conversion1 RDY
MS30541V1
1. Parameters:
P1: sequence of 1 conversion, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 1 conversion, hardware trigger 1
MS30544V2
1. Parameters:
P1: sequence of 1 conversion, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 1 conversion, hardware trigger 1
ADC J
context EMPTY P1 P3
(returned by reading JSQR)
ADC state RDY Conv1 STP RDY Conversion1 RDY Conversion1 RDY
(Aborted)
MS30543V1
1. Parameters:
P1: sequence of 1 conversion, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 1 conversion, hardware trigger 1
MS30544V1
1. Parameters:
P1: sequence of 1 conversion, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 1 conversion, hardware trigger 1
1. Parameters:
P1: sequence of 1 conversion, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 1 conversion, hardware trigger 1
ADC J context P1
(returned by reading JSQR)
MS30546V1
1. Parameters:
P1: sequence of 1 conversion, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 1 conversion, hardware trigger 1
MS30547V2
1. Parameters:
P1: sequence of 1 conversion, hardware trigger 1
P2: sequence of 1 conversion, hardware trigger 1
P3: sequence of 1 conversion, hardware trigger 1
Figure 47. Example of JSQR queue of context when changing SW and HW triggers
P1 P2 P3 P4
Write JSQR
JSQR
queue EMPTY P1 P1, P2 P2 P2, P3 P3 P3, P4 P4
ADC J
context EMPTY P1 P2 P3 P4
(returned by reading JSQR)
ADC state RDY Conversion1 RDY Conversion1 RDY Conversion1 RDY Conversion1
triggered by H/W triggered by H/W triggered by S/W triggered by H/W
Reset Reset
JADSTART Set by H/W Set by H/W Set
by S/W by S/W by S/W
Set Reset
JADSTP by S/W by H/W
MS30548V1
1. Parameters:
P1: sequence of 1 conversion, hardware trigger (JEXTEN /=0x0)
P2: sequence of 1 conversion, hardware trigger (JEXTEN /= 0x0)
P3: sequence of 1 conversion, software trigger (JEXTEN = 0x0)
P4: sequence of 1 conversion, hardware trigger (JEXTEN /= 0x0)
ADSTART(1)
EOC
EOS
ADC state(2) RDY CH1 CH9 CH10 CH17 RDY CH1 CH9 CH10 CH17 RDY
MS30549V1
1. EXTEN=0x0, CONT=0
2. Channels selected = 1,9, 10, 17; AUTDLY=0.
ADSTART(1)
EOC
EOS
ADSTP
ADC state(2) READY CH1 CH9 CH10 CH17 CH1 CH9 CH10 STP READY CH1 CH9
MS30550V1
1. EXTEN=0x0, CONT=1
2. Channels selected = 1,9, 10, 17; AUTDLY=0.
ADSTART
EOC
EOS
TRGX(1)
ADC state(2) RDY CH1 CH2 CH3 CH4 READY CH1 CH2 CH3 CH4 RDY
ADC_DR D1 D2 D3 D4 D1 D2 D3 D4
ADSTART
EOC
EOS
ADSTP
TRGx(1)
ADC(2) RDY CH1 CH2 CH3 CH4 CH1 CH2 CH3 CH4 CH1 STOP RDY
ADC_DR D1 D2 D3 D4 D1 D2 D3 D4
Special case: when left-aligned, the data are aligned on a half-word basis except when the
resolution is set to 6-bit. In that case, the data are aligned on a byte basis as shown in
Figure 54 and Figure 55.
Offset
An offset y (y=1,2,3,4) can be applied to a channel by setting the bit OFFSETy_EN=1 into
ADCx_OFRy register. The channel to which the offset will be applied is programmed into the
bits OFFSETy_CH[4:0] of ADCx_OFRy register. In this case, the converted value is
decreased by the user-defined offset written in the bits OFFSETy[11:0]. The result may be a
negative value so the read data is signed and the SEXT bit represents the extended sign
value.
Table 45 describes how the comparison is performed for all the possible resolutions for
analog watchdog 1.
signed 12-bit
00: 12-bit DATA[11:0] OFFSET[11:0] -
data
signed 10-bit The user must configure OFFSET[1:0]
01: 10-bit DATA[11:2],00 OFFSET[11:0]
data to “00”
DATA[11:4],00 signed 8-bit The user must configure OFFSET[3:0]
10: 8-bit OFFSET[11:0]
00 data to “0000”
DATA[11:6],00 signed 6-bit The user must configure OFFSET[5:0]
11: 6-bit OFFSET[11:0]
0000 data to “000000”
When reading data from ADCx_DR (regular channel) or from ADCx_JDRy (injected
channel, y=1,2,3,4) corresponding to the channel “i”:
• If one of the offsets is enabled (bit OFFSETy_EN=1) for the corresponding channel, the
read data is signed.
• If none of the four offsets is enabled for this channel, the read data is not signed.
Figure 52, Figure 53, Figure 54 and Figure 55 show alignments for signed and unsigned
data.
12-bit data
bit15 bit7 bit0
0 0 0 0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
10-bit data
bit15 bit7 bit0
0 0 0 0 0 0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
8-bit data
bit15 bit7 bit0
0 0 0 0 0 0 0 0 D7 D6 D5 D4 D3 D2 D1 D0
6-bit data
bit15 bit7 bit0
0 0 0 0 0 0 0 0 0 0 D5 D4 D3 D2 D1 D0
MS31015V1
12-bit data
bit15 bit7 bit0
SEXT SEXT SEXT SEXT D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
10-bit data
bit15 bit7 bit0
SEXT SEXT SEXT SEXT SEXT SEXT D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
8-bit data
bit15 bit7 bit0
SEXT SEXT SEXT SEXT SEXT SEXT SEXT SEXT D7 D6 D5 D4 D3 D2 D1 D0
6-bit data
bit15 bit7 bit0
SEXT SEXT SEXT SEXT SEXT SEXT SEXT SEXT SEXT SEXT D5 D4 D3 D2 D1 D0
MS31016V1
12-bit data
bit15 bit7 bit0
D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0
10-bit data
bit15 bit7 bit0
D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0
8-bit data
bit15 bit7 bit0
D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0 0 0
6-bit data
bit15 bit7 bit0
0 0 0 0 0 0 0 0 D5 D4 D3 D2 D1 D0 0 0
MS31017V1
12-bit data
bit15 bit7 bit0
SEXT D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0
10-bit data
bit15 bit7 bit0
SEXT D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0
8-bit data
bit15 bit7 bit0
SEXT D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0 0 0 0
6-bit data
bit15 bit7 bit0
SEXT SEXT SEXT SEXT SEXT SEXT SEXT SEXT SEXT D5 D4 D3 D2 D1 D0 0
MS31018V1
ADSTART(1)
EOC
EOS
OVR
ADSTP
TRGx(1)
ADC state(2) RDY CH1 CH2 CH3 CH4 CH5 CH6 CH7 STOP RDY
Overun
ADC_DR read access
ADC_DR D1
(OVRMOD=0) D2 D3 D4
ADC_DR D1 D2 D3 D4 D5 D6
(OVRMOD=1)
MS31019V1
Note: There is no overrun detection on the injected channels since there is a dedicated data
register for each of the four injected channels.
ADSTART(1)
EOC
EOS
ADSTP
ADC_DR read access
ADC state RDY CH1 DLY CH2 DLY CH3 DLY CH1 DLY STOP RDY
ADC_DR D1 D2 D3 D1
MS31020V1
1. AUTDLY=1
2. Regular configuration: EXTEN=0x0 (SW trigger), CONT=1, CHANNELS = 1,2,3
3. Injected configuration DISABLED
ADC state RDY CH1 DLY CH2 DLY CH5 CH6 CH3 DLY CH1 DLY CH2
regular regular injected regular injected regular regular
DLY (CH1) DLY (CH2) DLY (CH3) DLY (CH1)
EOC
EOS
ADC_DR
read access
ADC_DR D1 D2 D3 D1
Ignored
Injected
trigger
DLY (inj)
JEOS
ADC_JDR1 D5
ADC_JDR2 D6
1. AUTDLY=1
2. Regular configuration: EXTEN=0x1 (HW trigger), CONT=0, DISCEN=0, CHANNELS = 1, 2, 3
3. Injected configuration: JEXTEN=0x1 (HW Trigger), JDISCEN=0, CHANNELS = 5,6
EOC
EOS
ADC_DR read access
ADC_DR D1 D2 D3 D1
Ignored Ignored
Injected
trigger
DLY (inj)
JEOS
ADC_JDR1 D5
ADC_JDR2 D6
MS31022V1
1. AUTDLY=1
2. Regular configuration: EXTEN=0x1 (HW trigger), CONT=0, DISCEN=1, DISCNUM=1, CHANNELS = 1, 2, 3.
3. Injected configuration: JEXTEN=0x1 (HW Trigger), JDISCEN=1, CHANNELS = 5,6
ADSTART(1)
ADC
CH1 DLY CH2 DLY CH5 CH6 DLY CH3 DLY CH1
state RDY
regular regular injected injected regular regular
DLY (CH1) DLY (CH2) DLY (CH3)
EOC
EOS
ADC_DR read access
ADC_DR D1 D2 D3
Ignored
Injected
trigger
DLY (inj)
JEOS
ADC_JDR1 D5
ADC_JDR2 D6
MS31023V2
1. AUTDLY=1
2. Regular configuration: EXTEN=0x0 (SW trigger), CONT=1, DISCEN=0, CHANNELS = 1, 2, 3
3. Injected configuration: JEXTEN=0x1 (HW Trigger), JDISCEN=0, CHANNELS = 5,6
ADSTART(1) No delay
ADC state RDY CH1 DLY (CH1) CH2 CH5 CH6 DLY (inj) DLY(CH2) CH3 DLY CH1
regular regular injected injected regular regular
EOC
EOS
ADC_DR read access
ADC_DR D1 D2 D3
JEOS
ADC_JDR1 D5
ADC_JDR2 D6
MS31024V2
1. AUTDLY=1
2. Regular configuration: EXTEN=0x0 (SW trigger), CONT=1, DISCEN=0, CHANNELS = 1, 2
3. Injected configuration: JAUTO=1, CHANNELS = 5,6
Analog voltage
ai16048
None x 0 0
All injected channels 0 0 1
All regular channels 0 1 0
All regular and injected channels 0 1 1
Single(1) injected channel 1 0 1
Single(1) regular channel 1 1 0
(1)
Single regular or injected channel 1 1 1
1. Selected by the AWD1CH[4:0] bits. The channels must also be programmed to be converted in the
appropriate regular or injected sequence.
The AWD1 analog watchdog status bit is set if the analog voltage converted by the ADC is
below a lower threshold or above a higher threshold.
These thresholds are programmed in bits HT1[11:0] and LT1[11:0] of the ADCx_TR1
register for the analog watchdog 1. When converting data with a resolution of less than 12
bits (according to bits RES[1:0]), the LSB of the programmed thresholds must be kept
cleared because the internal comparison is always performed on the full 12-bit raw
converted data (left aligned).
Table 45 describes how the comparison is performed for all the possible resolutions for
analog watchdog 1.
LT1[11:0] and
00: 12-bit DATA[11:0] -
HT1[11:0]
LT1[11:0] and User must configure LT1[1:0] and HT1[1:0] to
01: 10-bit DATA[11:2],00
HT1[11:0] 00
LT1[11:0] and User must configure LT1[3:0] and HT1[3:0] to
10: 8-bit DATA[11:4],0000
HT1[11:0] 0000
LT1[11:0] and User must configure LT1[5:0] and HT1[5:0] to
11: 6-bit DATA[11:6],000000
HT1[11:0] 000000
1. The watchdog comparison is performed on the raw converted data before any alignment calculation and
before applying any offsets (the data which is compared is not signed).
1. The watchdog comparison is performed on the raw converted data before any alignment
calculation and before applying any offsets (the data which is compared is not signed).
ADC
RDY Conversion1 Conversion2 Conversion3 Conversion4 Conversion5 Conversion6 Conversion7
STATE
inside outside inside outside outside outside inside
EOC FLAG
ADCy_AWDx_OUT
MS31025V1
Figure 64. ADCy_AWDx_OUT signal generation (AWDx flag not cleared by SW)
ADC
RDY Conversion1 Conversion2 Conversion3 Conversion4 Conversion5 Conversion6 Conversion7
STATE
inside outside inside outside outside outside inside
EOC FLAG
ADCy_AWDx_OUT
MS31026V1
ADC
Conversion1 Conversion2 Conversion1 Conversion2 Conversion1 Conversion2 Conversion1 Conversion2
STATE
outside inside outside outside
EOC FLAG
EOS FLAG
ADCy_AWDx_OUT
ADC
RDY Conversion1 Conversion2 Conversion3 Conversion4 Conversion Conversion Conversion
STATE
inside outside inside outside outside outside inside
JEOS FLAG
ADCy_AWDx_OUT
MS31028V1
Address/data bus
channels
Injected
Slave ADC
channels
Internal triggers
ADCx_IN1
ADCx_IN2 GPIO Regular data register
ports (16-bits)
Dual mode
control
Master ADC
MSv31029V1
1. External triggers also exist on slave ADC but are not shown for the purposes of this diagram.
2. The ADC common data register (ADCx_CDR) contains both the master and slave ADC regular converted data.
• At the end of injected sequence of conversion event (JEOS) on the master ADC, the
converted data is stored into the master ADCx_JDRy registers and a JEOS interrupt is
generated (if enabled)
• At the end of injected sequence of conversion event (JEOS) on the slave ADC, the
converted data is stored into the slave ADCx_JDRy registers and a JEOS interrupt is
generated (if enabled)
• If the duration of the master injected sequence is equal to the duration of the slave
injected one (like in Figure 68), it is possible for the software to enable only one of the
two JEOS interrupt (ex: master JEOS) and read both converted data (from master
ADCx_JDRy and slave ADCx_JDRy registers).
Trigger
End of injected sequence on
Sampling MASTER and SLAVE ADC
Conversion
MS31900V1
ongoing regular sequence and the associated delay phases are ignored.
There is the same behavior for regular sequences occurring on the slave ADC.
Note: In MDMA mode (MDMA[1:0]=0b10 or 0b11), the user must program the same number of
conversions in the master’s sequence as in the slave’s sequence. Otherwise, the remaining
conversions will not generate a DMA request.
Trigger
End of regular sequence on
Sampling MASTER and SLAVE ADC
Conversion ai16054b
If DISCEN=1 then each “n” simultaneous conversions of the regular sequence require a
regular trigger event to occur (“n” is defined by DISCNUM).
This mode can be combined with AUTDLY mode:
• Once a simultaneous conversion of the sequence has ended, the next conversion in
the sequence is started only if the common data register, ADCx_CDR (or the regular
data register of the master ADC) has been read (delay phase).
• Once a simultaneous regular sequence of conversions has ended, a new regular
trigger event is accepted only if the common data register (ADCx_CDR) has been read
(delay phase). Any new regular trigger events occurring during the ongoing regular
sequence and the associated delay phases are ignored.
It is possible to use the DMA to handle data in regular simultaneous mode combined with
AUTDLY mode, assuming that multi-DMA mode is used: bits MDMA must be set to 0b10 or
0b11.
When regular simultaneous mode is combined with AUTDLY mode, it is mandatory for the
user to ensure that:
• The number of conversions in the master’s sequence is equal to the number of
conversions in the slave’s.
• For each simultaneous conversions of the sequence, the length of the conversion of
the slave ADC is inferior to the length of the conversion of the master ADC. Note that
the length of the sequence depends on the number of channels to convert and the
sampling time and the resolution of each channels.
Note: This combination of regular simultaneous mode and AUTDLY mode is restricted to the use
case when only regular channels are programmed: it is forbidden to program injected
channels in this combined mode.
The minimum delay which separates 2 conversions in interleaved mode is configured in the
DELAY bits in the ADCx_CCR register. This delay starts to count after the end of the
sampling phase of the master conversion. This way, an ADC cannot start a conversion if the
complementary ADC is still sampling its input (only one ADC can sample the input signal at
a given time).
• The minimum possible DELAY is 1 to ensure that there is at least one cycle time
between the opening of the analog switch of the master ADC sampling phase and the
closing of the analog switch of the slave ADC sampling phase.
• The maximum DELAY is equal to the number of cycles corresponding to the selected
resolution. However the user must properly calculate this delay to ensure that an ADC
does not start a conversion while the other ADC is still sampling its input.
If the CONT bit is set on both master and slave ADCs, the selected regular channels of both
ADCs are continuously converted.
Software is notified by interrupts when it can read the data:
• At the end of each conversion event (EOC) on the master ADC, a master EOC interrupt
is generated (if EOCIE is enabled) and software can read the ADCx_DR of the master
ADC.
• At the end of each conversion event (EOC) on the slave ADC, a slave EOC interrupt is
generated (if EOCIE is enabled) and software can read the ADCx_DR of the slave
ADC.
Note: It is possible to enable only the EOC interrupt of the slave and read the common data
register (ADCx_CDR). But in this case, the user must ensure that the duration of the
conversions are compatible to ensure that inside the sequence, a master conversion is
always followed by a slave conversion before a new master conversion restarts.
It is also possible to read the regular data using the DMA. Two methods are possible:
• Using the two DMA channels (one for the master and one for the slave). In this case
bits MDMA[1:0] must be kept cleared.
– Configure the DMA master ADC channel to read ADCx_DR from the master. DMA
requests are generated at each EOC event of the master ADC.
– Configure the DMA slave ADC channel to read ADCx_DR from the slave. DMA
requests are generated at each EOC event of the slave ADC.
• Using MDMA mode, which allows to save one DMA channel:
– Configure MDMA[1:0]=0b10 or 0b11 (depending on resolution).
– A single DMA channel is used (the one of the master). Configure the DMA master
ADC channel to read the common ADC register (ADCx_CDR).
– A single DMA request is generated each time both master and slave EOC events
have occurred. At that time, the slave ADC converted data is available in the
upper half-word of the ADCx_CDR 32-bit register and the master ADC converted
data is available in the lower half-word of ADCx_CCR register.
– Both EOC flags are cleared when the DMA reads the ADCx_CCR register.
Figure 70. Interleaved mode on 1 channel in continuous conversion mode: dual ADC
mode
Sampling
Conversion
MS31030V1
Figure 71. Interleaved mode on 1 channel in single conversion mode: dual ADC mode
Conversion
MS31031V1
CH11
Sampling Conversion
MS34460V1
MASTER ADC
SLAVE ADC
MASTER ADC
SLAVE ADC
Sampling
Conversion
ai16059-m
Note: Regular conversions can be enabled on one or all ADCs. In this case the regular
conversions are independent of each other. A regular conversion is interrupted when the
ADC has to perform an injected conversion. It is resumed when the injected conversion is
finished.
The time interval between 2 trigger events must be greater than or equal to 1 ADC clock
period. The minimum time interval between 2 trigger events that start conversions on the
same ADC is the same as in the single ADC mode.
Figure 74. Alternate trigger: 4 injected channels (each ADC) in discontinuous mode
1st trigger 3rd trigger 5th trigger 7th trigger
JEOC on JEOC on JEOC, JEOS on
JEOC on master ADC
master ADC master ADC master ADC
MASTER ADC
SLAVE ADC
Sampling
Conversion ai16060V2-m
ADC MASTER reg CH1 CH2 CH3 CH3 CH4 CH4 CH5
ADC SLAVE reg CH4 CH6 CH7 CH7 CH8 CH8 CH9
If a trigger occurs during an injected conversion that has interrupted a regular conversion,
the alternate trigger is served. Figure 76 shows the behavior in this case (note that the 6th
trigger is ignored because the associated alternate conversion is not complete).
ADC MASTER reg CH1 CH2 CH3 CH3 CH4 CH4 CH5 CH5 CH6
ADC MASTER inj CH14 CH14 CH14
ADC SLAVE reg CH7 CH8 CH9 CH9 CH10 CH10 CH11 CH11 CH12
ADC SLAVE inj CH15 CH15
6th trigger
2nd trigger 4th trigger (ignored)
ai16063V2
In simultaneous regular and interleaved modes, it is also possible to save one DMA channel
and transfer both data using a single DMA channel. For this MDMA bits must be configured
in the ADCx_CCR register:
• MDMA=0b10: A single DMA request is generated each time both master and slave
EOC events have occurred. At that time, two data items are available and the 32-bit
register ADCx_CDR contains the two half-words representing two ADC-converted data
items. The slave ADC data take the upper half-word and the master ADC data take the
lower half-word.
This mode is used in interleaved mode and in regular simultaneous mode when
resolution is 10-bit or 12-bit.
Example:
Interleaved dual mode: a DMA request is generated each time 2 data items are
available:
1st DMA request: ADCx_CDR[31:0] = SLV_ADCx_DR[15:0] |
MST_ADCx_DR[15:0]
2nd DMA request: ADCx_CDR[31:0] = SLV_ADCx_DR[15:0] |
MST_ADCx_DR[15:0]
MSv31034V2
Note: When using MDMA mode, the user must take care to configure properly the duration of the
master and slave conversions so that a DMA request is generated and served for reading
both data (master + slave) before a new conversion is available.
• MDMA=0b11: This mode is similar to the MDMA=0b10. The only differences are that
on each DMA request (two data items are available), two bytes representing two ADC
converted data items are transferred as a half-word.
This mode is used in interleaved and regular simultaneous mode when resolution is 6-
bit or when resolution is 8-bit and data is not signed (offsets must be disabled for all the
involved channels).
Example:
Interleaved dual mode: a DMA request is generated each time 2 data items are
available:
1st DMA request: ADCx_CDR[15:0] = SLV_ADCx_DR[7:0] | MST_ADCx_DR[7:0]
2nd DMA request: ADCx_CDR[15:0] = SLV_ADCx_DR[7:0] | MST_ADCx_DR[7:0]
Overrun detection
In dual ADC mode (when DUAL[4:0] is not equal to b00000), if an overrun is detected on
one of the ADCs, the DMA requests are no longer issued to ensure that all the data
transferred to the RAM are valid (this behavior occurs whatever the MDMA configuration). It
may happen that the EOC bit corresponding to one ADC remains set because the data
register of this ADC contains valid data.
DMA one shot mode/ DMA circular mode when MDMA mode is selected
When MDMA mode is selected (0b10 or 0b11), bit DMACFG of the ADCx_CCR register
must also be configured to select between DMA one shot mode and circular mode, as
explained in section Section : Managing conversions using the DMA (bits DMACFG of
master and slave ADCx_CFGR are not relevant).
temperature sensor measurement, calibration values are stored in system memory for each
device by ST during production.
During the manufacturing process, the calibration data of the temperature sensor and the
internal voltage reference are stored in the system memory area. The user application can
then read them and use them to improve the accuracy of the temperature sensor or the
internal reference. Refer to the STM32F334xx datasheet for additional information.
Main features
• Supported temperature range: –40 to 125 °C
• Precision: ±2 °C
The temperature sensor is internally connected to the ADC1_IN16 input channel which is
used to convert the sensor’s output voltage to a digital value. Refer to the electrical
characteristics section of STM32F334xx datasheet for the sampling time value to be applied
when converting the internal temperature sensor.
When not in use, the sensor can be put in power-down mode.
Figure 80 shows the block diagram of the temperature sensor.
Address/data bus
converted
data
ADCx
Temperature VTS
sensor ADC input
MSv31172V2
Note: The TSEN bit must be set to enable the conversion of the temperature sensor voltage VTS.
1. Select the ADC1_IN16 input channel (with the appropriate sampling time).
2. Program with the appropriate sampling time (refer to electrical characteristics section of
the STM32F334xx datasheet).
3. Set the TSEN bit in the ADC1_CCR register to wake up the temperature sensor from
power-down mode.
4. Start the ADC conversion.
5. Read the resulting VTS data in the ADC data register.
6. Calculate the actual temperature using the following formula:
Temperature (in °C) = {(V25 – VTS) / Avg_Slope} + 25
Where:
– V25 = VTS value for 25° C
– Avg_Slope = average slope of the temperature vs. VTS curve (given in mV/°C or
µV/°C)
Refer to the datasheet electrical characteristics section for the actual values of V25 and
Avg_Slope.
Note: The sensor has a startup time after waking from power-down mode before it can output VTS
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.
VBAT
Address/data bus
ADCx
VBAT/2
ADC input
MSv31035V2
Note: The VBATEN bit must be set to enable the conversion of internal channel ADC1_IN17
(VBATEN).
ADC12_VREFEN
control bit
ADC1
ADC2
VREFINT
Internal ADC1_IN18
power block
ADC2_IN18
MSv32649V1
Note: The VREFEN bit into ADC12_CCR register must be set to enable the conversion of internal
channels ADC1_IN18 or ADC2_IN18 (VREFINT).
Calculating the actual VDDA voltage using the internal reference voltage
The VDDA power supply voltage applied to the microcontroller may be subject to variation or
not precisely known. The embedded internal voltage reference (VREFINT) and its calibration
data acquired by the ADC during the manufacturing process at VDDA = 3.3 V can be used to
evaluate the actual VDDA voltage level.
The following formula gives the actual VDDA voltage supplying the device:
VDDA = 3.3 V ₓ VREFINT_CAL / VREFINT_DATA
Where:
• VREFINT_CAL is the VREFINT calibration value
• VREFINT_DATA is the actual VREFINT output value converted by ADC
For applications where VDDA value is not known, user must use the internal voltage
reference and VDDA can be replaced by the expression provided in the section Calculating
the actual VDDA voltage using the internal reference voltage, resulting in the following
formula:
V × VREFINT_CAL × ADCx_DATA-
V CHANNELx = 3.3
-----------------------------------------------------------------------------------------------------
VREFINT_DATA × FULL_SCALE
Where:
• VREFINT_CAL is the VREFINT calibration value
• ADCx_DATA is the value measured by the ADC on channel x (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 will be 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.
31 30 29 28 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. JQOVF AWD3 AWD2 AWD1 JEOS JEOC 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 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
JQ AWD3 AWD2 AWD1 EOSMP ADRDY
Res. Res. Res. Res. Res. JEOSIE JEOCIE OVRIE EOSIE EOCIE
OVFIE IE IE IE IE IE
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
AD ADCA
ADVREGEN[1:0] Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
CAL LDIF
rs rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JAD AD JAD AD AD AD
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
STP STP START START DIS EN
rs rs rs rs rs rs
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
JAWD1 AWD1 AWD1S JDISC DISC
Res. AWD1CH[4:0] JAUTO JQM DISCNUM[2:0]
EN EN GL EN EN
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
AUT OVR DMA DMA
Res. CONT EXTEN[1:0] EXTSEL[3:0] ALIGN RES[1:0] Res.
DLY MOD CFG EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 11:10 EXTEN[1:0]: External trigger enable and polarity selection for regular channels
These bits are set and cleared by software to select the external trigger polarity and enable the trigger
of a regular group.
00: Hardware trigger detection disabled (conversions can be launched by software)
01: Hardware trigger detection on the rising edge
10: Hardware trigger detection on the falling edge
11: Hardware trigger detection on both the rising and falling edges
Note: Software is allowed to write these bits only when ADSTART=0 (which ensures that no regular
conversion is ongoing).
Bits 9:6 EXTSEL[3:0]: External trigger selection for regular group
These bits select the external event used to trigger the start of conversion of a regular group:
0000: Event 0
0001: Event 1
0010: Event 2
0011: Event 3
0100: Event 4
0101: Event 5
0110: Event 6
0111: Event 7
...
1111: Event 15
Note: Software is allowed to write these bits only when ADSTART=0 (which ensures that no regular
conversion is ongoing).
Bit 5 ALIGN: Data alignment
This bit is set and cleared by software to select right or left alignment. Refer to Figure : Data register,
data alignment and offset (ADCx_DR, OFFSETy, OFFSETy_CH, ALIGN)
0: Right alignment
1: Left alignment
Note: Software is allowed to write this bit only when ADSTART=0 and JADSTART=0 (which ensures
that no conversion is ongoing).
Bits 4:3 RES[1:0]: Data resolution
These bits are written by software to select the resolution of the conversion.
00: 12-bit
01: 10-bit
10: 8-bit
11: 6-bit
Note: Software is allowed to write these bits only when ADSTART=0 and JADSTART=0 (which
ensures that no conversion is ongoing).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. SMP9[2:0] SMP8[2:0] SMP7[2:0] SMP6[2:0] SMP5[2:1]
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
SMP
SMP4[2:0] SMP3[2:0] SMP2[2:0] SMP1[2:0] Res. Res. Res.
5_0
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. SMP18[2:0] SMP17[2:0] SMP16[2:0] SMP15[2:1]
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
SMP15_0 SMP14[2:0] SMP13[2:0] SMP12[2:0] SMP11[2:0] SMP10[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
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 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
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. SQ4[4:0] Res. SQ3[4:0] Res. SQ2[4]
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
SQ2[3:0] Res. SQ1[4:0] Res. Res. L[3:0]
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. SQ9[4:0] Res. SQ8[4:0] Res. SQ7[4]
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
SQ7[3:0] Res. SQ6[4:0] Res. SQ5[4: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. SQ14[4:0] Res. SQ13[4:0] Res. SQ12[4]
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
SQ12[3:0] Res. SQ11[4:0] Res. SQ10[4: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. 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. SQ16[4:0] Res. SQ15[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
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
RDATA[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
Res. JSQ4[4:0] Res. JSQ3[4:0] Res. JSQ2[4:2]
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
JSQ2[1:0] Res. JSQ1[4:0] JEXTEN[1:0] JEXTSEL[3:0] JL[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 7:6 JEXTEN[1:0]: External Trigger Enable and Polarity Selection for injected channels
These bits are set and cleared by software to select the external trigger polarity and enable the
trigger of an injected group.
00: Hardware trigger detection disabled (conversions can be launched by software)
01: Hardware trigger detection on the rising edge
10: Hardware trigger detection on the falling edge
11: Hardware trigger detection on both the rising and falling edges
Note: Software is allowed to write these bits at any time, once the ADC is enabled (ADEN=1).
Note: If JQM=1 and if the Queue of Context becomes empty, the software and hardware
triggers of the injected sequence are both internally disabled (refer to Section 13.3.21:
Queue of context for injected conversions)
Bits 5:2 JEXTSEL[3:0]: External Trigger Selection for injected group
These bits select the external event used to trigger the start of conversion of an injected group:
0000: Event 0
0001: Event 1
0010: Event 2
0011: Event 3
0100: Event 4
0101: Event 5
0110: Event 6
0111: Event 7
...
1111: Event 15
Note: Software is allowed to write these bits at any time, once the ADC is enabled (ADEN=1).
Bits 1:0 JL[1:0]: Injected channel sequence length
These bits are written by software to define the total number of conversions in the injected
channel conversion sequence.
00: 1 conversion
01: 2 conversions
10: 3 conversions
11: 4 conversions
Note: Software is allowed to write these bits at any time, once the ADC is enabled (ADEN=1).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OFFSETy
OFFSETy_CH[4:0] Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
_EN
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. OFFSETy[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
JDATA[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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. AWD2CH[18:16]
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AWD2CH[15:1] Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The channels selected by AWD2CH must be also selected into the SQRi or JSQRi registers.
Note: Software is allowed to write these bits only when ADSTART=0 and JADSTART=0 (which
ensures that no conversion is ongoing).
Bit 0 Reserved, must be kept at reset value.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. AWD3CH[18:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AWD3CH[15:1] Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The channels selected by AWD3CH must be also selected into the SQRi or JSQRi registers.
Note: Software is allowed to write these bits only when ADSTART=0 and JADSTART=0 (which
ensures that no conversion is ongoing).
Bit 0 Reserved, must be kept at reset value.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DIFSEL[18:16]
r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DIFSEL[15:1] Res.
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. CALFACT_D[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. CALFACT_S[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
JQOVF_ AWD3_ AWD2_ AWD1_ JEOS_ JEOC_ OVR_ EOS_ EOC_ EOSMP_ ADRDY_
Res. Res. Res. Res. Res.
SLV SLV SLV SLV SLV SLV SLV SLV SLV SLV SLV
Slave ADC
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
JQOVF_ AWD3_ AWD2_ AWD1_ JEOS_ JEOC_ OVR_ EOS_ EOC_ EOSMP_ ADRDY_
Res. Res. Res. Res. Res.
MST MST MST MST MST MST MST MST MST MST MST
Master ADC
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
VBAT TS VREF
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CKMODE[1:0]
EN EN EN
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMA
MDMA[1:0] Res. DELAY[3:0] Res. Res. Res. DUAL[4:0]
CFG
rw rw rw rw rw rw rw rw rw rw rw rw
In all synchronous clock modes, there is no jitter in the delay from a timer trigger to the start of
a conversion.
Note: Software is allowed to write these bits only when the ADCs are disabled (ADCAL=0,
JADSTART=0, ADSTART=0, ADSTP=0, ADDIS=0 and ADEN=0).
Bits 15:14 MDMA[1:0]: Direct memory access mode for dual ADC mode
This bit-field is set and cleared by software. Refer to the DMA controller section for more
details.
00: MDMA mode disabled
01: reserved
10: MDMA mode enabled for 12 and 10-bit resolution
11: MDMA mode enabled for 8 and 6-bit resolution
Note: Software is allowed to write these bits only when ADSTART=0 (which ensures that no
regular conversion is ongoing).
Bit 13 DMACFG: DMA configuration (for dual ADC mode)
This bit is set and cleared by software to select between two DMA modes of operation and is
effective only when DMAEN=1.
0: DMA One Shot Mode selected
1: DMA Circular Mode selected
For more details, refer to Section : Managing conversions using the DMA
Note: Software is allowed to write these bits only when ADSTART=0 (which ensures that no
regular conversion is ongoing).
Bit 12 Reserved, must be kept at reset value.
00001 to 01001: Dual mode, master and slave ADCs working together
00001: Combined regular simultaneous + injected simultaneous mode
00010: Combined regular simultaneous + alternate trigger mode
00011: Combined Interleaved mode + injected simultaneous mode
00100: Reserved
00101: Injected simultaneous mode only
00110: Regular simultaneous mode only
00111: Interleaved mode only
01001: Alternate trigger mode only
All other combinations are reserved and must not be programmed
Note: Software is allowed to write these bits only when the ADCs are disabled (ADCAL=0,
JADSTART=0, ADSTART=0, ADSTP=0, ADDIS=0 and ADEN=0).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RDATA_SLV[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
RDATA_MST[15:0]
r r r r r r r r r r r r r r r r
Table 50. ADC register map and reset values for each ADC (offset=0x000
for master ADC, 0x100 for slave ADC, x=1..2)
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
EOSMP
ADRDY
JQOVF
AWD3
AWD2
AWD1
JEOC
JEOS
OVR
EOC
EOS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_ISR
0x00
Reset value 0 0 0 0 0 0 0 0 0 0 0
EOSMPIE
ADRDYIE
JQOVFIE
AWD3IE
AWD2IE
AWD1IE
JEOCIE
JEOSIE
OVRIE
EOCIE
EOSIE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_IER
0x04
Reset value 0 0 0 0 0 0 0 0 0 0 0
ADVREGEN[1:0]
JADSTART
ADCALDIF
ADSTART
JADSTP
ADCAL
ADSTP
ADDIS
ADEN
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_CR
0x08
Reset value 0 0 1 0 0 0 0 0 0 0
EXTEN[1:0]
AWD1SGL
JAWD1EN
OVRMOD
DMACFG
JDISCEN
AWD1EN
AUTDLY
DISCEN
DMAEN
JAUTO
ALIGN
CONT
DISCNUM EXTSEL RES
JQM
Res.
Res.
Res.
ADCx_CFGR AWD1CH[4:0]
0x0C [2:0] [3: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
0x10 Reserved Res.
SMP9 SMP8 SMP7 SMP6 SMP5 SMP4 SMP3 SMP2 SMP1
Res.
Res.
Res.
Res.
Res.
ADCx_SMPR1
0x14 [2:0] [2:0] [2:0] [2:0] [2:0] [2:0] [2:0] [2:0] [2: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
SMP18 SMP17 SMP16 SMP15 SMP14 SMP13 SMP12 SMP11 SMP10
Res.
Res.
Res.
Res.
Res.
ADCx_SMPR2
0x18 [2:0] [2:0] [2:0] [2:0] [2:0] [2:0] [2:0] [2:0] [2: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
0x1C 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.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x44-
Reserved
0x48
JEXTEN[1:0]
JEXTSEL
Res.
Res.
Res.
Res.
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x50-
Reserved Res
0x5C
Table 50. ADC register map and reset values for each ADC (offset=0x000
for master ADC, 0x100 for slave ADC, x=1..2) (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
OFFSET1_EN OFFSET1_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_OFR1 OFFSET1[11:0]
0x60 CH[4:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OFFSET2_EN
OFFSET2_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_OFR2 OFFSET2[11:0]
0x64 CH[4:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OFFSET3_EN
OFFSET3_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_OFR3 OFFSET3[11:0]
0x68 CH[4:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OFFSET4_EN
OFFSET4_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_OFR4 OFFSET4[11:0]
0x6C CH[4:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x70-
Reserved Res.
0x7C
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_JDR1 JDATA1[15:0]
0x80
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.
ADCx_JDR2 JDATA2[15:0]
0x84
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.
ADCx_JDR3 JDATA3[15:0]
0x88
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.
ADCx_JDR4 JDATA4[15:0]
0x8C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x8C-
Reserved Res.
0x9C
Res..
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_AWD2CR AWD2CH[18:1]
0xA0
Reset value 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.
ADCx_AWD3CR AWD3CH[18:1]
0xA4
Reset value 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.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0xA8-
Reserved
0xAC
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_DIFSEL DIFSEL[18:1]
0xB0
Reset value 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.
Res.
Res.
Table 51. ADC register map and reset values (master and slave ADC
common registers) offset =0x300, x=1)
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
EOSMP_MST
ADRDY_MST
JQOVF_MST
EOSMP_SLV
ADRDY_SLV
JQOVF_SLV
AWD3_MST
AWD2_MST
AWD1_MST
JEOC_MST
JEOS_MST
AWD3_SLV
AWD2_SLV
AWD1_SLV
JEOC_SLV
JEOS_SLV
OVR_MST
EOC_MST
EOS_MST
OVR_SLV
EOC_SLV
EOS_SLV
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_CSR
0x00
CKMODE[1:0]
MDMA[1:0]
DMACFG
VREFEN
VBATEN
TSEN
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADCx_CCR DELAY[3:0] DUAL[4:0]
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADCx_CDR RDATA_SLV[15:0] RDATA_MST[15:0]
0x0C
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
14.1 Introduction
The DAC module is a 12-bit, voltage output digital-to-analog converter. The DAC can be
configured in 8- or 12-bit mode and may be used in conjunction with the DMA controller. In
12-bit mode, the data could be left- or right-aligned. An input reference voltage,
VREF+(shared with ADC), is available. The output can optionally be buffered for higher
current drive.
Trigger selectorx
TIM7_TRGO DMAENx
TIM2_TRGO
TIM15_TRGO
or HRTIM1_DACTRG1
HRTIM1_DACTRG2
EXTI_9
DM A req ue stx
Control logic x TENx
12-bit
DHRx
MAMPx[3:0] bits
LFSRx Tiranglex
WAVEx[3:0] bits
12-bit BOFF
DORx
12-bit
VDDA
Digital-to-analog DAC1_ OU Ty
converterx
VSSA
MS32682V3
1. On STM32F334, there is no output buffer on the DAC1 channel 2. There is instead a switch allowing to
connect the DAC1_OUT2 to the corresponding I/O (PA5) (refer to DAC2 block diagram).
Trigger selectorx
DMAENx
TIM3_TRGO
TIM7_TRGO
TIM2_TRGO
TIM15_TRGO
HRTIM1_DACTRG3
EXTI_9 DMA requestx
12-bit TENx
DHRx Control logicx
OUTEN1
12-bit
DO Rx
12-bit
VDD A
Digital-to-analog DAC2_OUT1
VSS A
converterx
MSv32653V5
Note: Once the DACx channel y is enabled, the corresponding GPIO pin (PA4, PA5 or PA6) is
automatically connected to the analog converter output (DACx_OUTy). In order to avoid
parasitic consumption, the PA4, PA5 or PA6 pin should first be configured to analog (AIN).
corresponding I/O (PA6). The switch can be enabled and disabled through the OUTEN1 bit
in the DAC_CR register.
The DAC1 channel output buffer can be enabled and disabled through the BOFF1 bit in the
DAC_CR register.
31 24 15 7 0
8-bit right aligned
ai14710b
register is set) and a trigger occurs, the transfer is performed three PCLK1 clock cycles
later.
When DAC_DORx is loaded with the DAC_DHRx contents, the analog output voltage
becomes available after a time tSETTLING that depends on the power supply voltage and the
analog output load.
Figure 86. Timing diagram for conversion with trigger disabled TEN = 0
APB1_CLK
DHR 0x1AC
Output voltage
DOR 0x1AC available on DAC_OUT pin
tSETTLING ai14711b
1. To select TIM3_TRGO event as DAC1 trigger source, the DAC_ TRIG_RMP bit must be set in
SYSCFG_CFGR1 register.
Each time a DAC interface detects a rising edge on the selected timer TRGO output, or on
the selected external interrupt line 9, the last data stored into the DAC_DHRx register are
transferred into the DAC_DORx register. The DAC_DORx register is updated three APB1
cycles after the trigger occurs.
If the software trigger is selected, the conversion starts once the SWTRIG bit is set.
SWTRIG is reset by hardware once the DAC_DORx register has been loaded with the
DAC_DHRx register contents.
Note: TSELx[2:0] bit cannot be changed when the ENx bit is set. When software trigger is
selected, the transfer from the DAC_DHRx register to the DAC_DORx register takes only
one APB1 clock cycle.
31 24 15 7 0
8-bit right aligned
ai14709b
At the same time, the LFSR2 counter, with the mask configured by MAMP2[3:0], is added to
the DHR2 register and the sum is transferred into DAC_DOR2 (three APB clock cycles
later). The LFSR2 counter is then updated.
XOR
X6 X4 X X0
X 12
11 10 9 8 7 6 5 4 3 2 1 0
12
NOR
ai14713c
The LFSR value, that may be masked partially or totally by means of the MAMPx[3:0] bits in
the DAC_CR register, is added up to the DAC_DHRx contents without overflow and this
value is then stored into the DAC_DORx register.
If LFSR is 0x0000, a ‘1 is injected into it (antilock-up mechanism).
It is possible to reset LFSR wave generation by resetting the WAVEx[1:0] bits.
Figure 89. DAC conversion (SW trigger enabled) with LFSR wave generation
APB1_CLK
DHR 0x00
SWTRIG
ai14714b
Note: The DAC trigger must be enabled for noise generation by setting the TENx bit in the
DAC_CR register.
De
n
tio
cr
ta
em
en
en
em
ta
cr
tio
In
n
DAC_DHRx base value
0
ai14715c
Figure 91. DAC conversion (SW trigger enabled) with triangle wave generation
APB1_CLK
DHR 0xABE
SWTRIG
ai14716b
Note: The DAC trigger must be enabled for triangle generation by setting the TENx bit in the
DAC_CR register.
The MAMPx[3:0] bits must be configured before enabling the DAC, otherwise they cannot
be changed.
DMA underrun
The DAC DMA request is not queued so that if a second external trigger arrives before the
acknowledgment for the first external trigger is received (first request), then no new request
is issued and the DMA channelx underrun flag DMAUDRx in the DAC_SR register is set,
reporting the error condition. DMA data transfers are then disabled and no further DMA
request is treated. The DAC channelx continues to convert old data.
The software should clear the DMAUDRx flag by writing “1”, clear the DMAEN bit of the
used DMA stream and re-initialize both DMA and DAC channelx to restart the transfer
correctly. The software should modify the DAC trigger conversion frequency or lighten the
DMA workload to avoid a new DMA. Finally, the DAC conversion can be resumed by
enabling both DMA data transfer and conversion trigger.
For each DAC channel, an interrupt is also generated if the corresponding DMAUDRIEx bit
in the DAC_CR register is enabled.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BOFF2
DMAU DMA
Res. Res. MAMP2[3:0] WAVE2[1:0] TSEL2[2:0] TEN2 /OUTE EN2
DRIE2 EN2
N2
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
BOFF1
DMAU DMA
Res. Res. MAMP1[3:0] WAVE1[1:0] TSEL1[2:0] TEN1 /OUTE EN1
DRIE1 EN1
N1
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. Res. Res. SWTRIG2 SWTRIG1
w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. DACC1DHR[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
DACC1DHR[11:0] v Res. Res. Res.
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. DACC1DHR[7: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. DACC2DHR[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DACC2DHR[11:0] Res. Res. Res. Res.
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. DACC2DHR[7: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
DACC2DHR[7:0] DACC1DHR[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
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. DACC1DOR[11:0]
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. DACC2DOR[11:0]
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. DMAUDR2 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. DMAUDR1 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rc_w1
0x2C
0x1C
0x0C
Offset
RM0364
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
name
DHR8R2
DHR8R1
DHR8RD
DAC_CR
DHR12L2
DHR12L1
DHR12R2
DHR12R1
DHR12LD
DHR12RD
SWTRIGR
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
DAC_DOR2
DAC_DOR1
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMAUDRIE2 29
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMAEN2 28
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
14.10.15 DAC register map
MAMP2[3:0]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
DACC2DHR[11:0]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
WAVE2[1:0]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TSEL2[2:0] 20
DACC2DHR[11:0]
0
0
Table 55 summarizes the DAC registers.
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TEN2 18
0
0
RM0364 Rev 4
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BOFF2 17
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EN2 16
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 15
0
0
0
Res. Res. Res. Res. Res. Res. 0 Res. Res. Res. 14
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. DMAUDRIE1 13
0
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. 10
DACC2DHR[7:0]
MAMP1[3:0].
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
DACC1DHR[11:0]
DACC2DHR[11:0]
DACC1DHR[11:0]
0
0
0
0
0
0
0
0
0
0
0
Res. 7
WAVE1[1:0]
0
0
0
0
0
0
0
0
0
0
0
Res. 6
0
0
0
0
0
0
0
0
0
0
0
Res. 5
0
0
0
0
0
0
0
0
0
0
0
Res. TSEL1[2:0] 4
DACC1DHR[11:0]
DACC2DHR[11:0]
DACC1DHR[11:0]
DACC2DOR[11:0]
DACC1DOR[11:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
DACC1DHR[7:0]
DACC2DHR[7:0]
DACC1DHR[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Digital-to-analog converter (DAC1 and DAC2)
341/1124
Res. Res. Res. SWTRIG1 EN1 0
342
Digital-to-analog converter (DAC1 and DAC2) RM0364
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
DMAUDR2
DMAUDR1
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.
DAC_SR
0x34
Reset value 0 0
15 Comparator (COMP)
15.1 Introduction
STM32F334xx devices embed three ultra-fast comparators, COMP2, COMP4 and COMP6
that can be used either as standalone devices (all terminals are available on I/Os) or
combined with the timers.
The comparators can be used for a variety of functions including:
• Wakeup from low-power mode triggered by an analog signal,
• Analog signal conditioning,
• Cycle-by-cycle current control loop when combined with the DAC and a PWM output
from a timer.
COMP2_OUT
PA2/PA7/PA12/PB9
COMP2_INP +
PA7
COMP2 COMP interrupt request
(to EXTI)
PA2 -
PA4 (DAC1_CH1) Polarity
DAC1_CH2(1) selection
DAC2_CH1(1) TIM1_BKIN
VREFINT COMP2_INM TIM1_OCref_clr
¾ VREFINT TIM1_IC1
½ VREFINT
¼ VREFINT TIM2_IC4
TIM2_OCref_clr
TIM3_IC1
TIM3_OCref_clr
MS33192V2
1. In STM32F334xx devices, DAC1_CH2 and DAC2_CH1 outputs are connected directly, thus PA5 and PA6
are not available as COMP2_INM inputs.
DAC1_CH1/DAC1_CH2
DAC2_CH1
Comparator inverting
Vrefint
Input: connection to
internal signals ¾ Vrefint
½ Vrefint
¼ Vrefint
Comparator Inputs +: PA7 +: PB0 +: PB11
connected to I/Os
-: PA2 -: PB2 -: PB15
(+: non inverting input;
-: inverting input)
Comparator outputs T1BKIN
(motor control
T1BKIN2
protection)
PA2 PA10
Outputs on I/Os PB1
PA12 PC6
TIM1_OCREF_CLR
TIM1_IC1 TIM3_IC3 TIM2_IC2
TIM2_IC4 TIM3_OCrefClear TIM2_OCREF_CLR
Outputs to internal TIM2_OCREF_CLR TIM15_OCREF_CLR TIM16_OCREF_CLR
signals TIM3_IC1 TIM15_IC2 TIM16_IC1
TIM3_OCrefClear HRTIM_EEV2, HRTIM_EEV3,
HRTIM_EEV1, HRTIM_EEV7(1) HRTIM_EEV8(1)
HRTIM_EEV6(1)
1. COMP2/4/6 output is connected directly to HRTIM1 peripheral in order to speed-up the propagation
delays.
insure that the comparator programming cannot be altered in case of spurious register
access or program counter corruption.
For this purpose, the comparator control and status registers can be write-protected (read-
only).
Once the programming is completed, using bits 30:0 of COMPx_CSR, the COMPx LOCK bit
can be set to 1. This causes the whole COMPx_CSR register to become read-only,
including the COMPx LOCK bit.
The write protection can only be reset by a MCU reset.
PWM
Current limit
Current
Blanking window
Comp out
Comp out (to TIM_BK …)
Blank
MS30964V1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
COMP COMP4
Res. COMP4OUTSEL[3:0] Res. Res. Res. COMP4INMSEL[2:0] Res. Res.
4POL EN
rw rw rw rw rw rw rw rw rw
352/1124
Register
Reset value
Reset value
Reset value
COMP6_CSR
COMP4_CSR
COMP2_CSR
0
0
0
COMP6LOCK COMP4LOCK COMP2LOCK 31
Comparator (COMP)
0
0
0
COMP6OUT COMP4OUT COMP2OUT 30
Res. Res. Res. 29
Res. Res. Res. 28
Res. Res. Res. 27
Res. Res. Res. 26
Res. Res. Res. 25
COMP register map
0
0
0
COMP6INMSEL[3] COMP4INMSEL[3] COMP2INMSEL[3] 22
Res. Res. Res. 21
0
0
0
20
0
0
0
0
0
0
18
17
RM0364 Rev 4
Res. Res. Res.
16
0
0
0
0
0
0
13
The following table summarizes the comparator registers.
0
0
0
12
0
0
0
11
SEL[3:0]
SEL[3:0]
SEL[3:0]
Table 57. COMP register map and reset values
0
0
0
COMP6OUT
COMP4OUT
COMP2OUT
10
Res. Res. Res. 9
6
0
0
0
4
Res. Res. Res.
3
2
Res. Res. Res. 1
0
0
0
16.3.2 Clock
The OPAMP clock provided by the clock controller is synchronized with the PCLK2 (APB2
clock). There is no clock enable control bit provided in the RCC controller. To use a clock
source for the OPAMP, the SYSCFG clock enable control bit must be set in the RCC
controller.
PA12/PB9
+
COMP 2 COMP
Interrupt
-
PA2 TIM1_BKIN
DAC1_CH2 Polarity
selection TIM1_OCrefClear
DAC1_CH1 TIM1_IC1
DAC2_CH1 TIM2_IC4
VREFINT TIM2_OCRefCle
3/4 VREFINT TIM3_IC1
PA7 1/2 VREFINT TIM3_OCRefCle
1/4 VREFINT TIM1_BKIN2
PB0
TIM1_BKIN2
PB14 +
OPAMP2 ADC
PC5 -
PA5
PA6
MS32655V2
16.3.5 Calibration
The OPAMP interface continuously sends trimmed offset values to the 4 operational
amplifiers. At startup, these values are initialized with the preset ‘factory’ trimming value.
Furthermore each operational amplifier offset can be trimmed by the user.
The user can switch from the ‘factory’ values to the ‘user’ trimmed values using the
USER_TRIM bit in the OPAMP control register. This bit is reset at startup (‘factory’ values
are sent to the operational amplifiers).
The rail-to-rail input stage of the OPAMP is composed of two differential pairs:
• One pair composed of NMOS transistors
• One pair composed of PMOS transistors.
As these two pairs are independent, the trimming procedure calibrates each one separately.
The TRIMOFFSETN bits calibrate the NMOS differential pair offset and the TRIMOFFSETP
bits calibrate the PMOS differential pair offset.
To calibrate the NMOS differential pair, the following conditions must be met: CALON=1 and
CALSEL=11. In this case, an internal high voltage reference (0.9 x VDDA) is generated and
applied on the inverting and non inverting OPAMP inputs connected together. The voltage
applied to both inputs of the OPAMP can be measured (the OPAMP reference voltage can
be output through the TSTREF bit and connected internally to an ADC channel; refer to
Section 13: Analog-to-digital converters (ADC) on page 211). The software should
increment the TRIMOFFSETN bits in the OPAMP control register from 0x00 to the first value
that causes the OUTCAL bit to change from 1 to 0 in the OPAMP register. If the OUTCAL bit
is reset, the offset is calibrated correctly and the corresponding trimming value must be
stored.
The calibration of the PMOS differential pair is performed in the same way, with two
differences: the TRIMOFFSETP bits-fields are used and the CALSEL bits must be
programmed to ‘01’ (an internal low voltage reference (0.1 x VDDA) is generated and applied
on the inverting and non inverting OPAMP inputs connected together).
Note: During calibration mode, to get the correct OUTCAL value, please make sure the
OFFTRIMmax delay (specified in the datasheet electrical characteristics section) has
elapsed between the write of a trimming value (TRIMOFFSETP or TRIMOFFSETN) and the
read of the OUTCAL value,
To calibrate the NMOS differential pair, use the following software procedure:
1. Enable OPAMP by setting the OPAMPxEN bit
2. Enable the user offset trimming by setting the USERTRIM bit
3. Connect VM and VP to the internal reference voltage by setting the CALON bit
4. Set CALSEL to 11 (OPAMP internal reference =0.9 x VDDA)
5. In a loop, increment the TRIMOFFSETN value. To exit from the loop, the OUTCAL bit
must be reset. In this case, the TRIMOFFSETN value must be stored.
The same software procedure must be applied for PMOS differential pair calibration with
CALSEL = 01 (OPAMP internal reference = 0.1 VDDA).
CCR6 T1 counter
T8 counter
ADC sampling points
T1 output (1 out of 3)
T8 output (1 out of 3)
T1 CC6 output arriving on OPAMP input mux
STM32
VP0
VP1
VP2
VP3
+ ADC
VM0 OpAmp
p p
VM1
--
MS19226V1
1. This figure gives an example in an inverting configuration. Any other option is possible, including
comparator mode.
STM32
VP0
VP1
VP2
VP3
+ ADC
p p
OpAmp
Available I/Os VM0
VM1
--
Always connected
to OPAMP output
(can be used
during debug)
MS19227V1
1. This figure gives an example in an inverting configuration. Any other option is possible, including
comparator mode.
Figure 98. PGA mode, internal gain setting (x2/x4/x8/x16), inverting input not used
STM32
VP0
VP1
VP2
VP3
+ ADC
VM0 OpAmp
p p
VM1
Available I/Os --
Always connected
to OPAMP output
(can be used
during debug)
MS19228V1
Figure 99. PGA mode, internal gain setting (x2/x4/x8/x16), inverting input used for
filtering
STM32
VP0
VP1
VP2
VP3
+ ADC
VM0 OpAmp
p p
VM1 -
-
Allows
optional low-
passfiltering
NB:gain
depends on
cut-off
frequency Equivalentto
MS19229V1
10
11
9
8
7
6
5
4
3
2
1
0
TRIMOFFSETN
TRIMOFFSETP
USER_TRIM
OPAMP2EN
FORCE_VP
PGA_GAIN
VMS_SEL
VPS_SEL
TCM_EN
OUTCAL
VM_SEL
TSTREF
CALSEL
VP_SEL
CALON
LOCK
Res
OPAMP2_CSR
0x3C
Reset value X X X X X X X X X X X X X X X X 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
17.1 Introduction
The touch sensing controller provides a simple solution for adding capacitive sensing
functionality to any application. Capacitive sensing technology is able to detect finger
presence near an electrode that is protected from direct touch by a dielectric (for example
glass, plastic). The capacitive variation introduced by the finger (or any conductive object) is
measured using a proven implementation based on a surface charge transfer acquisition
principle.
The touch sensing controller is fully supported by the STMTouch touch sensing firmware
library, which is free to use and allows touch sensing functionality to be implemented reliably
in the end application.
SYNC
TSC_IOG1CR
TSC_IOG2CR
Gx_IO1
Gx_IO2
Gx_IO3
TSC_IOGxCR
Gx_IO4
MS30929V1
The remaining GPIOs are dedicated to the electrodes and are commonly called channels.
For some specific needs (such as proximity detection), it is possible to simultaneously
enable more than one channel per analog I/O group.
Electrode 1 Analog
RS1 I/O group
G1_IO1
CX1
G1_IO2
CS
Electrode 2
RS2
G1_IO3
CX2
Electrode 3 RS3
G1_IO4
CX3
MS30930V1
Note: Gx_IOy where x is the analog I/O group number and y the GPIO number within the selected
group.
The surface charge transfer acquisition principle consists of charging an electrode
capacitance (CX) and transferring a part of the accumulated charge into a sampling
capacitor (CS). This sequence is repeated until the voltage across CS reaches a given
threshold (VIH in our case). The number of charge transfers required to reach the threshold
is a direct representation of the size of the electrode capacitance.
The Table 60 details the charge transfer acquisition sequence of the capacitive sensing
channel 1. States 3 to 7 are repeated until the voltage across CS reaches the given
threshold. The same sequence applies to the acquisition of the other channels. The
electrode serial resistor RS improves the ESD immunity of the solution.
Output open-
Input floating
drain low with Input floating with analog switch Discharge all CX and
#1 with analog
analog switch closed CS
switch closed
closed
#2 Input floating Dead time
Output push-
#3 Input floating Charge CX1
pull high
#4 Input floating Dead time
Input floating with analog switch Charge transfer from
#5 Input floating
closed CX1 to CS
#6 Input floating Dead time
#7 Input floating Measure CS voltage
The voltage variation over the time on the sampling capacitor CS is detailed below:
VDD
Threshold =VIH
t
Burst duration
MS30931V1
CLK_AHB
CX HiZ
CS HiZ
CS reading
Pulse low
Pulse high
Discharge state (charge Pulse high Pulse low
State CX and CS
state
transfer from state state
(charge of CX)
CX to CS)
t
MSv30932V3
For higher flexibility, the charge transfer frequency is fully configurable. Both the pulse high
state (charge of CX) and the pulse low state (transfer of charge from CX to CS) duration can
be defined using the CTPH[3:0] and CTPL[3:0] bits in the TSC_CR register. The standard
range for the pulse high and low states duration is 500 ns to 2 µs. To ensure a correct
measurement of the electrode capacitance, the pulse high state duration must be set to
ensure that CX is always fully charged.
A dead time where both the sampling capacitor I/O and the channel I/O are in input floating
state is inserted between the pulse high and low states to ensure an optimum charge
transfer acquisition sequence. This state duration is 2 periods of HCLK.
At the end of the pulse high state and if the spread spectrum feature is enabled, a variable
number of periods of the SSCLK clock are added.
The reading of the sampling capacitor I/O, to determine if the voltage across CS has
reached the given threshold, is performed at the end of the pulse low state.
Note: The following TSC control register configurations are forbidden:
• bits PGPSC are set to ‘000’ and bits CTPL are set to ‘0000’
• bits PGPSC are set to ‘000’ and bits CTPL are set to ‘0001’
• bits PGPSC are set to ‘001’ and bits CTPL are set to ‘0000’
Deviation value
(SSD +1)
1
0 n-1 n n+1
Number of pulses
MS30933V1
The table below details the maximum frequency deviation with different HCLK settings:
The spread spectrum feature can be disabled/enabled using the SSE bit in the TSC_CR
register. The frequency deviation is also configurable to accommodate the device HCLK
clock frequency and the selected charge transfer frequency through the SSPSC and
SSD[6:0] bits in the TSC_CR register.
Table 62. I/O state depending on its mode and IODEF bit value
Sampling
Acquisition Unused I/O Channel I/O
IODEF bit capacitor I/O
status mode mode
mode
No effect
Sleep
TSC interrupts cause the device to exit Sleep mode.
Stop TSC registers are frozen
Standby The TSC stops its operation until the Stop or Standby mode is exited.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CTPH[3:0] CTPL[3:0] SSD[6:0] SSE
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
SYNC
SSPSC PGPSC[2:0] Res. Res. Res. Res. MCV[2:0] IODEF AM START TSCE
POL
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. MCEIE EOAIE
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. MCEIC EOAIC
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. MCEF EOAF
r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res.G6
Res. Res. Res. Res. Res. Res. Res. Res. G6_IO4 G6_IO2 G6_IO1 G5_IO4 G5_IO3 G5_IO2 G5_IO1
_IO3
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
G4_IO4 G4_IO3 G4_IO2 G4_IO1 G3_IO4 G3_IO3 G3_IO2 G3_IO1 G2_IO4 G2_IO3 G2_IO2 G2_IO1 G1_IO4 G1_IO3 G1_IO2 G1_IO1
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. G6_IO4 G6_IO3 G6_IO2 G6_IO1 G5_IO4 G5_IO3 G5_IO2 G5_IO1
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
G4_IO4 G4_IO3 G4_IO2 G4_IO1 G3_IO4 G3_IO3 G3_IO2 G3_IO1 G2_IO4 G2_IO3 G2_IO2 G2_IO1 G1_IO4 G1_IO3 G1_IO2 G1_IO1
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. G6_IO4 G6_IO3 G6_IO2 G6_IO1 G5_IO4 G5_IO3 G5_IO2 G5_IO1
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
G4_IO4 G4_IO3 G4_IO2 G4_IO1 G3_IO4 G3_IO3 G3_IO2 G3_IO1 G2_IO4 G2_IO3 G2_IO2 G2_IO1 G1_IO4 G1_IO3 G1_IO2 G1_IO1
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. G6_IO4 G6_IO3 G6_IO2 G6_IO1 G5_IO4 G5_IO3 G5_IO2 G5_IO1
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
G4_IO4 G4_IO3 G4_IO2 G4_IO1 G3_IO4 G3_IO3 G3_IO2 G3_IO1 G2_IO4 G2_IO3 G2_IO2 G2_IO1 G1_IO4 G1_IO3 G1_IO2 G1_IO1
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. G6S G5S G4S G3S G2S G1S
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. G6E G5E G4E G3E G2E G1E
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
r r r r r r r r r r r r r r
0x0024
0x0014
0x002C
0x001C
0x000C
Offset
RM0364
17.6.11
TSC_CR
TSC_ISR
TSC_IER
TSC_ICR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TSC_IOSCR
TSC_IOCCR
TSC_IOHCR
TSC_IOG2CR
TSC_IOG1CR
TSC_IOASCR
TSC_IOGCSR
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
CTPH[3:0]
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 0 27
TSC register map
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
CTPL[3:0]
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
0
0
1
0
Res. Res. Res. G6_IO4 G6_IO4 G6_IO4 G6_IO4 Res. Res. Res. 23
0
0
0
0
1
Res. Res. Res. G6_IO3 G6_IO3 G6_IO3 G6_IO3 Res. Res. Res. 22
0
0
0
0
0
1
Res. Res. G6S G6_IO2 G6_IO2 G6_IO2 G6_IO2 Res. Res. Res. 21
0
0
0
0
0
1
Res. Res. G5S G6_IO1 G6_IO1 G6_IO1 G6_IO1 Res. Res. Res. 20
0
0
0
0
0
1
SSD[6:0]
Res. Res. G4S G5_IO4 G5_IO4 G5_IO4 G5_IO4 Res. Res. Res. 19
0
0
0
0
0
1
Res. Res. G3S G5_IO3 G5_IO3 G5_IO3 G5_IO3 Res. Res. Res. 18
RM0364 Rev 4
0
0
0
0
0
1
Reserved
Reserved
Reserved
Reserved
Res. Res. G2S G5_IO2 G5_IO2 G5_IO2 G5_IO2 Res. Res. Res. 17
0
0
0
0
0
1
Res. Res. G1S G5_IO1 G5_IO1 G5_IO1 G5_IO1 Res. Res. Res. SSE 16
0
0
0
0
1
Res. Res. Res. G4_IO4 G4_IO4 G4_IO4 G4_IO4 Res. Res. Res. SSPSC 15
0
0
0
0
1
Res. Res. Res. G4_IO3 G4_IO3 G4_IO3 G4_IO3 Res. Res. Res. 14
0
0
0
0
1
0
0
Res. G4_IO2 G4_IO2 G4_IO2 G4_IO2 Res. Res. Res. PGPSC[2:0] 13
0
0
0
0
1
0
0
Res. G4_IO1 G4_IO1 G4_IO1 G4_IO1 Res. Res. Res. 12
0
0
0
1
0
0
Res. G3_IO4 G3_IO4 G3_IO4 G3_IO4 Res. Res. Res. Res.
Table 65. TSC register map and reset values
11
0
0
0
1
0
0
Res. G3_IO3 G3_IO3 G3_IO3 G3_IO3 Res. Res. Res. Res. 10
0
0
0
1
0
0
Res. G3_IO2 G3_IO2 G3_IO2 G3_IO2 Res. Res. Res. Res. 9
0
0
0
1
0
0
Res. G3_IO1 G3_IO1 G3_IO1 G3_IO1 Res. Res. Res. Res. 8
0
0
0
1
0
0
0
Res. G2_IO4 G2_IO4 G2_IO4 G2_IO4 Res. Res. Res. 7
0
0
0
1
0
0
0
Res. G2_IO3 G2_IO3 G2_IO3 G2_IO3 Res. Res. Res. 6
[2:0]
MCV
CNT[13:0]
CNT[13:0]
0
0
0
1
0
0
0
0
G6E G2_IO2 G2_IO2 G2_IO2 G2_IO2 Res. Res. Res. 5
0
0
0
1
0
0
0
0
G5E G2_IO1 G2_IO1 G2_IO1 G2_IO1 Res. Res. Res. IODEF 4
0
0
0
1
0
0
0
0
G4E G1_IO4 G1_IO4 G1_IO4 G1_IO4 Res. Res. Res. SYNCPOL 3
0
0
0
1
0
0
0
0
G3E G1_IO3 G1_IO3 G1_IO3 G1_IO3 Res. Res. Res. AM 2
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
381/1124
382
Touch sensing controller (TSC) RM0364
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.
Res.
Res.
TSC_IOG3CR CNT[13:0]
0x003C
Reset value Res. 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.
Res.
TSC_IOG4CR CNT[13:0]
0x0040
Reset value 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.
Res.
Res.
TSC_IOG5CR CNT[13:0]
0x0044
Reset value 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.
Res.
Res.
TSC_IOG6CR CNT[13:0]
0x0048
Reset value 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.
ITR0 TRG
ITR1 ITR
ITR2 Slave Reset, enable, up/down, count
TRC TRGI
ITR3 controller
mode
TI1F_ED
TI1FP1 Encoder
TI2FP2 Interface
REP register
U UI
Auto-reload register
Repetition
Stop, clear or up/down U
counter
CK_PSC PSC CK_CNT +/- CNT counter
prescaler DTG registers
CC1I CC1I
U TIMx_CH1
XOR TI1FP1 OC1REF
TI1 Input filter & TI1FP2 IC1 IC1PS Capture/Compare 1 register Output OC1
Prescaler DTG
edge detector control TIMx_CH1N
TIMx_CH1 TRC
CC2I OC1N
U CC2I TIMx_CH2
TI2FP1 OC2
TI2 Input filter & IC2 IC2PS OC2REF Output
TIMx_CH2 TI2FP2 Prescaler Capture/Compare 2 register
edge detector DTG control TIMx_CH2N
TRC OC2N
CC3I CC3I
U TIMx_CH3
TI3FP3 OC3REF
TI3 Input filter & IC3 IC3PS OC3
TIMx_CH3 TI3FP4 Prescaler Capture/Compare 3 register Output
DTG TIMx_CH3N
edge detector control
TRC OC3N
CC4I
U CC4I
TI4 TI4FP3 OC4
Input filter & IC4 IC4PS OC4REF Output TIMx_CH4
TIMx_CH4 TI4FP4 Prescaler Capture/Compare 4 register
edge detector control
TRC
ETRF
BRK Polarity selection BI
TIMx_BKIN filter
BRK_ACTH
Internal break event sources (see note below)
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 106 and Figure 107 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 106. 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 107. 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 112. 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 113. 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 118. 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 119. 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 18.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 123. 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 124. 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 125. 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
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
TIMx_SMCR
TS[2:0]
or TI2F or
TI1F or Encoder
ITRx mode
0xx
TI1_ED
100 TRGI External clock
TI1FP1 mode 1 CK_PSC
TI2F_Rising 101
TI2 Edge 0 TI2FP2 ETRF External clock
Filter 110
detector 1 ETRF mode 2
TI2F_Falling 111
CK_INT Internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
ECE SMS[2:0]
TIMx_SMCR
MS31196V1
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = ‘01’ in
the TIMx_CCMR1 register.
2. 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).
3. Select rising edge polarity by writing CC2P=0 and CC2NP=0 in the TIMx_CCER
register.
4. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
5. Select TI2 as the trigger input source by writing TS=110 in the TIMx_SMCR register.
6. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
Note: The capture prescaler is not used for triggering, so the user does not need to configure it.
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
or TI2F or
TI1F or Encoder
mode
ECE SMS[2:0]
TIMx_SMCR
MS33116V1
For example, to configure the upcounter to count each 2 rising edges on ETR, use the
following procedure:
f CK_INT
CNT_EN
ETR
ETRP
ETRF
Counter clock =
CK_CNT =CK_PSC
Counter register 34 35 36
MSv33111V3
TI1F_ED
To the slave mode controller
TI1 TI1F_Rising
Filter TI1F Edge 0 TI1FP1
fDTS downcounter 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
MS33115V1
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 134. 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
forced high (OCxREF is always active high) and OCx get opposite value to CCxP polarity
bit.
For example: CCxP=0 (OCx active high) => OCx is forced to high level.
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 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 = 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 138.
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 393
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 396.
Figure 140 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 141. 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 143. 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 18.3.26: 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 145. Dead-time waveforms with delay greater than the negative pulse
OCxREF
OCx
delay
OCxN
MS31096V1
Figure 146. Dead-time waveforms with delay greater than the positive pulse
OCxREF
OCx
OCxN
delay
MS31097V1
The dead-time delay is the same for each of the channels and is programmable with the
DTG bits in the TIMx_BDTR register. Refer to Section 18.4.20: TIM1 break and dead-time
register (TIM1_BDTR) for delay calculation.
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.
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 (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 18.4.20: TIM1 break and dead-time register (TIM1_BDTR). The LOCK bits
can be written only once after an MCU reset.
Figure 147 shows an example of behavior of the outputs in response to a break.
Figure 147. Various output behavior in response to a break event on BKIN (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 148 gives an example of OCx and OCxN output behavior in case of active signals on
BKIN and BKIN2 inputs. In this case, both outputs have active high polarities (CCxP =
CCxNP = 0 in TIMx_CCER register).
Figure 148. PWM output state following BKIN and BKIN2 pins assertion (OSSI=1)
BKIN2
BKIN
OCx
Deadtime Deadtime
I/O state
BKIN
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 150 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. Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.
2. TI2FP2 must detect a rising edge, write CC2P=’0’ and CC2NP=’0’ in the TIMx_CCER
register.
3. Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=110 in
the TIMx_SMCR register.
4. 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 154 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 155 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=’1’).
Figure 155. 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 157 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=110 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=101 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. Res. Res. Res. Res. Res. SMS[3]
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. Res. 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
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 69. 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
Res. Res. Res. Res. Res. Res. BK2P BK2E BK2F[3:0] BKF[3:0]
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 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. 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_ETR_ TIM1_ETR_
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
ADC2_RMP ADC1_RMP
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
0x1C
0x0C
Offset
RM0364
18.4.27
mode
mode
Output
Output
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. OC4M[3] Res. OC2M[3] Res. Res. Res. Res. Res. Res. Res. 24
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
0
CC6P Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
MMS2[3:0]
0
0
CC6E Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. OIS6 Res. 18
0
0
RM0364 Rev 4
CC5P Res. Res. Res. Res. Res. CC6IF Res. Res. Res. Res. 17
0
0
0
0
0
0
CC5E OC3M[3] Res. OC1M[3] Res. 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
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
0
CMS
[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
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)
475/1124
477
0x50
0x48
0x44
0x40
0x38
0x34
0x30
0x28
0x24
0x4C
0x3C
0x2C
Offset
476/1124
TIM1_OR
TIM1_CNT
TIM1_PSC
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
TIM1_CCR4
TIM1_CCR3
TIM1_CCR2
TIM1_CCR1
TIM1_BDTR
TIM1_DMAR
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 0 UIFCPY 31
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
Advanced-control timer (TIM1)
27
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
0
0
Res. Res. BK2P Res. Res. Res. Res. Res. Res. Res. Res. 25
0
0
Res. Res. BK2E Res. Res. Res. Res. Res. Res. Res. Res. 24
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
BK2F[3:0]
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
0
0
RM0364 Rev 4
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
BKF[3:0]
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
0
0
0
1
0
0
DMAB[15:0]
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
Res. BKE 12
0
0
0
0
0
0
0
0
1
0
0
Res. OSSR 11
0
0
0
0
0
0
0
0
1
0
0
Res. OSSI 10
0
0
0
0
0
0
0
0
1
0
0
DBL[4:0]
Res. 9
K
[1:0]
LOC
0
0
0
0
0
0
0
0
1
0
0
Table 70. TIM1 register map and reset values (continued)
Res. 8
0
0
0
0
0
0
0
1
0
0
Res. Res. 7
CNT[15:0]
REP[15:0]
PSC[15:0]
ARR[15:0]
CCR4[15:0]
CCR3[15:0]
CCR2[15:0]
CCR1[15:0]
0
0
0
0
0
0
0
1
0
0
Res. Res. 6
0
0
0
0
0
0
0
1
0
0
Res. Res. 5
0
0
0
0
0
0
0
0
1
0
0
Res. 4
0
0
0
0
0
0
0
1
0
0
0
0
3
DT[7:0]
TIM1_ETR_ADC2_RMP
0
0
0
0
0
0
0
1
0
0
0
0
2
0
0
0
0
0
0
0
1
0
0
0
0
DBA[4:0]
TIM1_ETR_ADC1_RMP
1
0
0
0
0
0
0
0
1
0
0
0
0
0
RM0364
RM0364 Advanced-control timer (TIM1)
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
OC6M[3]
OC5M[3]
TIM1_CCMR3
OC6CE
OC5CE
OC6PE
OC5PE
OC6FE
OC5FE
OC6M OC5M
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Output [2:0] [2:0]
0x54 Compare mode
Reset value 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.
TIM1_CCR6 CCR6[15:0]
0x5C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TI1FP1 Encoder
TI2FP2 interface
U
Auto-reload register UI
Stop, clear or up/down
U
CK_PSC PSC CK_CNT +/- CNT counter
prescaler
CC1I U CC1I
XOR TI1FP1 OC1REF
TI1 Input filter & IC1 IC1PS Output OC1 TIMx_CH1
TI1FP2 Prescaler Capture/Compare 1 register
edge detector control
TIMx_CH1 TRC
CC2I
U CC2I
TI2FP1
TI2 Input filter & IC2 Output OC2
TIMx_CH2 TI2FP2 Prescaler
IC2PS Capture/Compare 2 register OC2REF TIMx_CH2
edge detector control
TRC
CC3I CC3I
U
TI3FP3 OC3REF
TI3 Input filter & IC3 IC3PS Output OC3 TIMx_CH3
TI3FP4 Prescaler Capture/Compare 3 register
TIMx_CH3 edge detector control
TRC CC4I
U CC4I
TI4FP3
TI4 Input filter & IC4 Output OC4
TIMx_CH4 TI4FP4 Prescaler
IC4PS Capture/Compare 4 register OC4REF TIMx_CH4
edge detector control
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 163 and Figure 164 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 163. 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 164. 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 169. 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 170. 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 175. 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 19.4.1: TIMx control register 1
(TIMx_CR1)(x = 2 to 3) on page 524).
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 180. 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 181. 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
TIMx_SMCR
TS[2:0]
or TI2F or
TI1F or Encoder
ITRx mode
0xx
TI1_ED
100 TRGI External clock
TI1FP1 mode 1 CK_PSC
TI2F_Rising 101
TI2 Edge 0 TI2FP2 ETRF External clock
Filter 110
detector 1 ETRF mode 2
TI2F_Falling 111
CK_INT Internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
ECE SMS[2:0]
TIMx_SMCR
MS31196V1
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S= ‘01 in the
TIMx_CCMR1 register.
2. 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).
Note: The capture prescaler is not used for triggering, so it does not need to be configured.
3. Select rising edge polarity by writing CC2P=0 and CC2NP=0 and CC2NP=0 in the
TIMx_CCER register.
4. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
5. Select TI2 as the input source by writing TS=110 in the TIMx_SMCR register.
6. 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
or TI2F or
TI1F or Encoder
mode
ECE SMS[2:0]
TIMx_SMCR
MS33116V1
For example, to configure the upcounter to count each 2 rising edges on ETR, use the
following procedure:
1. As no filter is needed in this example, write ETF[3:0]=0000 in the TIMx_SMCR register.
2. Set the prescaler by writing ETPS[1:0]=01 in the TIMx_SMCR register
3. Select rising edge detection on the ETR pin by writing ETP=0 in the TIMx_SMCR
register
4. Enable external clock mode 2 by writing ECE=1 in the TIMx_SMCR register.
5. 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
To the slave mode controller
TI1 TI1F_Rising
Filter TI1F Edge 0 TI1FP1
fDTS downcounter 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
MS33115V1
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.
detected (sampled at fDTS frequency). Then write IC1F bits to 0011 in the
TIMx_CCMR1 register.
3. Select the edge of the active transition on the TI1 channel by writing the CC1P and
CC1NP and CC1NP bits to 000 in the TIMx_CCER register (rising edge in this case).
4. 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).
5. Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
6. 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 active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1
register (TI1 selected).
2. Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter
clear): write the CC1P to ‘0’ and the CC1NP bit to ‘0’ (active on rising edge).
3. Select the active input for TIMx_CCR2: write the CC2S bits to 10 in the TIMx_CCMR1
register (TI1 selected).
4. Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P
bit to ‘1’ and the CC2NP bit to ’0’ (active on falling edge).
5. Select the valid trigger input: write the TS bits to 101 in the TIMx_SMCR register
(TI1FP1 selected).
6. Configure the slave mode controller in reset mode: write the SMS bits to 100 in the
TIMx_SMCR register.
7. 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.
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 191.
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 Downcounting
mode on page 485.
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.
compare flag is set when the counter counts up, when it counts down or both when it counts
up and down depending on the CMS bits configuration. The direction bit (DIR) in the
TIMx_CR1 register is updated by hardware and must not be changed by software. Refer to
Center-aligned mode (up/down counting) on page 488.
Figure 193 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 194. 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 196 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. Map TI2FP2 on TI2 by writing CC2S=01 in the TIMx_CCMR1 register.
2. TI2FP2 must detect a rising edge, write CC2P=0 and CC2NP=’0’ in the TIMx_CCER
register.
3. Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=110 in
the TIMx_SMCR register.
4. 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 199 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 200 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=1).
Figure 200. 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=101 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=110 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
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=101 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
UEV
Master Slave
TRGO1 ITR2 CK_PSC
mode mode
Prescaler Counter control control
Prescaler Counter
Input
trigger
selection
MS33118V2
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 206) 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 TIM3 in master mode so that it outputs a periodic trigger signal on each
update event UEV. If MMS=010 is written in the TIM3_CR2 register, a rising edge is
output on TRGO each time an update event is generated.
2. To connect the TRGO output of TIM3 to TIM2, TIM2 must be configured in slave mode
using ITR2 as internal trigger. This is selected through the TS bits in the TIM2_SMCR
register (writing TS=010).
3. Then the slave mode controller must be put in external clock mode 1 (write SMS=111 in
the TIM2_SMCR register). This causes TIM2 to be clocked by the rising edge of the
periodic TIM3 trigger signal (which correspond to the TIM3 counter overflow).
4. Finally both timers must be enabled by setting their respective CEN bits (TIMx_CR1
register).
Note: If OCx is selected on TIM3 as the trigger output (MMS=1xx), its rising edge is used to clock
the counter of TIM2.
CK_INT
TIM3-OC1REF
TIM3-CNT FC FD FE FF 00 01
TIM2-TIF
Write TIF = 0
MS33119V1
In the example in Figure 207, the TIM2 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 TIM3. 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 208), we synchronize TIM3 and TIM2. TIM3 is the
master and starts from 0. TIM2 is the slave and starts from 0xE7. The prescaler ratio is the
same for both timers. TIM2 stops when TIM3 is disabled by writing ‘0 to the CEN bit in the
TIM3_CR1 register:
1. Configure TIM3 master mode to send its Output Compare 1 Reference (OC1REF)
signal as trigger output (MMS=100 in the TIM3_CR2 register).
2. Configure the TIM3 OC1REF waveform (TIM3_CCMR1 register).
3. Configure TIM2 to get the input trigger from TIM3 (TS=010 in the TIM2_SMCR
register).
4. Configure TIM2 in gated mode (SMS=101 in TIM2_SMCR register).
5. Reset TIM3 by writing ‘1 in UG bit (TIM3_EGR register).
6. Reset TIM2 by writing ‘1 in UG bit (TIM2_EGR register).
7. Initialize TIM2 to 0xE7 by writing ‘0xE7’ in the TIM2 counter (TIM2_CNTL).
8. Enable TIM2 by writing ‘1 in the CEN bit (TIM2_CR1 register).
9. Start TIM3 by writing ‘1 in the CEN bit (TIM3_CR1 register).
10. Stop TIM3 by writing ‘0 in the CEN bit (TIM3_CR1 register).
CK_INT
TIM3-CEN=CNT_EN
TIM3-CNT_INIT
TIM3-CNT 75 00 01 02
TIM2-CNT AB 00 E7 E8 E9
TIM2-CNT_INIT
TIM2-write CNT
TIM2-TIF
Write TIF = 0
MS33120V1
1. Configure TIM3 master mode to send its Update Event (UEV) as trigger output
(MMS=010 in the TIM3_CR2 register).
2. Configure the TIM3 period (TIM3_ARR registers).
3. Configure TIM2 to get the input trigger from TIM3 (TS=010 in the TIM2_SMCR
register).
4. Configure TIM2 in trigger mode (SMS=110 in TIM2_SMCR register).
5. Start TIM3 by writing ‘1 in the CEN bit (TIM3_CR1 register).
CK_INT
TIM3-UEV
TIM3-CNT FD FE FF 00 01 02
TIM2-CNT 45 46 47 48
TIM2-CEN=CNT_EN
TIM2-TIF
Write TIF = 0
MS33121V1
As in the previous example, both counters can be initialized before starting counting.
Figure 210 shows the behavior with the same configuration as in Figure 209 but in trigger
mode instead of gated mode (SMS=110 in the TIM2_SMCR register).
CK_INT
TIM3-CEN=CNT_EN
TIM3-CNT_INIT
TIM3-CNT 75 00 01 02
TIM2-CNT CD 00 E7 E8 E9 EA
TIM2-CNT_INIT
TIM2
write CNT
TIM2-TIF
Write TIF = 0
MS33122V1
aligned, TIM3 must be configured in Master/Slave mode (slave with respect to TI1, master
with respect to TIM2):
1. Configure TIM3 master mode to send its Enable as trigger output (MMS=001 in the
TIM3_CR2 register).
2. Configure TIM3 slave mode to get the input trigger from TI1 (TS=100 in the
TIM3_SMCR register).
3. Configure TIM3 in trigger mode (SMS=110 in the TIM3_SMCR register).
4. Configure the TIM3 in Master/Slave mode by writing MSM=1 (TIM3_SMCR register).
5. Configure TIM2 to get the input trigger from TIM3 (TS=000 in the TIM2_SMCR
register).
6. Configure TIM2 in trigger mode (SMS=110 in the TIM2_SMCR register).
When a rising edge occurs on TI1 (TIM3), both counters starts counting synchronously on
the internal clock and both TIF flags are set.
Note: In this example both timers are initialized before starting (by setting their respective UG
bits). Both counters starts from 0, but an offset can easily be inserted between them by
writing any of the counter registers (TIMx_CNT). One can see that the master/slave mode
insert a delay between CNT_EN and CK_PSC on TIM3.
Figure 211. Triggering TIM3 and TIM2 with TIM3 TI1 input
CK_INT
TIM3-TI1
TIM3-CEN=CNT_EN
TIM3-CK_PSC
TIM3-CNT 00 01 02 03 04 05 06 07 08 09
TIM3-TIF
TIM2-CEN=CNT_EN
TIM2-CK_PSC
TIM2-CNT 00 01 02 03 04 05 06 07 08 09
TIM2-TIF
MS33123V1
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.
The DMA controller destination is unique and must point to the virtual register TIMx_DMAR.
On a given timer event, the timer launches a sequence of DMA requests (burst). Each write
into the TIMx_DMAR register is actually redirected to one of the timer registers.
The DBL[4:0] bits in the TIMx_DCR register set the DMA burst length. The timer recognizes
a burst transfer when a read or a write access is done to the TIMx_DMAR address), i.e. the
number of transfers (either in half-words or in bytes).
The DBA[4:0] bits in the TIMx_DCR registers define the DMA base address for DMA
transfers (when read/write access are done through the TIMx_DMAR address). DBA is
defined as an offset starting from the address of the TIMx_CR1 register:
Example:
00000: TIMx_CR1
00001: TIMx_CR2
00010: TIMx_SMCR
As an example, the timer DMA burst feature is used to update the contents of the CCRx
registers (x = 2, 3, 4) upon 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 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 has 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. Res. Res. Res. Res. Res. SMS[3]
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
0x1C
0x0C
Offset
546/1124
19.4.22
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
General-purpose timers (TIM2/TIM3)
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
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
RM0364 Rev 4
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
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
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 (TIM2 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 (TIM2 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 (TIM2 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 (TIM2 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 (TIM2 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
BRK BI
TIMx_BKIN Polarity selection
BRK_ACTH
Internal break event sources
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
To other
REP register
timers for
cross-
Auto-reload register UI trigerring(1)
U
Repetition
Stop, clear or up/down U
counter
CK_PSC PSC CK_CNT
+/- CNT counter
prescaler DTG registers
C1I CC1I
U TIMx_CH1
TI1 TI1FP1 IC1
TIMx_CH1 Input filter & IC1PS OC1REF
Prescaler Capture/compare 1 register Output OC1
edge selector DTG control TIMx_CH1N
OC1N
BRK BI
TIMx_BKIN Polarity selection
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 20.4.22: 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 8.2.7: Clock security system
(CSS)
- A PVD output
- SRAM parity error signal
- Cortex®-M4 LOCKUP (Hardfault) output
- COMP 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 214 and Figure 215 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 214. 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 215. 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 220. 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 221. 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 222. 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 223 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
TIMx_SMCR
TS[2:0]
ITRx
0xx
TI1_ED
100 TRGI External clock
TI1FP1 mode 1
TI2F_Rising 101 CK_PSC
TI2 Edge 0 TI2FP2
Filter 110
detector 1
TI2F_Falling
CK_INT Internal clock
ICF[3:0] (internal clock) mode
CC2P
TIMx_CCMR1 TIMx_CCER
SMS[2:0]
TIMx_SMCR
MS31086V2
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = ‘01’ in
the TIMx_CCMR1 register.
2. 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).
3. Select rising edge polarity by writing CC2P=0 in the TIMx_CCER register.
4. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
5. Select TI2 as the trigger input source by writing TS=110 in the TIMx_SMCR register.
6. 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
TI1F_ED
To the slave mode controller
TI1 TI1F_Rising
Filter TI1F Edge 0 TI1FP1
fDTS downcounter TI1F_Falling 01
detector 1
TI2FP1 IC1 Divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P 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
MS31088V2
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
OCREF_CLR
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
OC2CE OC2M[3:0]
OIS2 TIMx_CR2
TIMx_CCMR1
MS31091V3
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.
Note: IC interrupt and/or DMA requests can be generated by software by setting the
corresponding CCxG bit in the TIMx_EGR 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.
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 231.
OC1REF= OC1
MS31092V1
As the preload registers are transferred to the shadow registers only when an update event
occurs, before starting the counter, all registers must be initialized by setting the UG bit in
the TIMx_EGR register.
OCx polarity is software programmable using the CCxP bit in the TIMx_CCER register. It
can be programmed as active high or active low. OCx output is enabled by a combination of
the CCxE, CCxNE, MOE, OSSI and OSSR bits (TIMx_CCER and TIMx_BDTR registers).
Refer to the TIMx_CCER register description for more details.
In PWM mode (1 or 2), TIMx_CNT and TIMx_CCRx are always compared to determine
whether TIMx_CCRx ≤ TIMx_CNT or TIMx_CNT ≤ TIMx_CCRx (depending on the direction
of the counter).
The TIM15/TIM16/TIM17 are capable of upcounting only. Refer to Upcounting mode on
page 554.
In the following example, we consider PWM mode 1. The reference PWM signal OCxREF is
high as long as TIMx_CNT < TIMx_CCRx else it becomes low. If the compare value in
TIMx_CCRx is greater than the auto-reload value (in TIMx_ARR) then OCxREF is held at
‘1’. If the compare value is 0 then OCxRef is held at ‘0’. Figure 232 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
by the two TIMx_CCRx registers. The resulting signals, OCxREFC, are made of an OR or
AND logical combination of two reference PWMs:
• OC1REFC (or OC2REFC) is controlled by the TIMx_CCR1 and TIMx_CCR2 registers
Combined PWM mode can be selected independently on two channels (one OCx output per
pair of CCR registers) by writing ‘1100’ (Combined PWM mode 1) or ‘1101’ (Combined PWM
mode 2) in the OCxM bits in the TIMx_CCMRx register.
When a given channel is used as a combined PWM channel, its complementary 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 233 represents 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,
OC2’
OC1’
OC2
OC1
OC1REF
OC2REF
OC1REF’
OC2REF’
OC1REFC
OC1REFC’
MS31094V1
OCxREF
OCx
delay
OCxN
delay
MS31095V1
Figure 235. Dead-time waveforms with delay greater than the negative pulse.
OCxREF
OCx
delay
OCxN
MS31096V1
Figure 236. 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 20.6.14: TIMx break and dead-time
register (TIMx_BDTR)(x = 16 to 17) on page 621 for delay calculation.
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.
The break is generated by the BRK inputs which has:
• Programmable polarity (BKP bit in the TIMx_BDTR register)
• Programmable enable bit (BKE bit in the TIMx_BDTR register)
It is also possible to generate break events by software using BG bit in TIMx_EGR register.
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
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. Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.
2. TI2FP2 must detect a rising edge, write CC2P=’0’ and CC2NP=’0’ in the TIMx_CCER
register.
3. Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=’110’ in
the TIMx_SMCR register.
4. TI2FP2 is used to start the counter by writing SMS to ‘110’ in the TIMx_SMCR register
(trigger mode).
The OPM waveform is defined by writing the compare registers (taking into account the
clock frequency and the counter prescaler).
• The tDELAY is defined by the value written in the TIMx_CCR1 register.
• The tPULSE is defined by the difference between the auto-reload value and the compare
value (TIMx_ARR - TIMx_CCR1).
• Let’s say one want to build a waveform with a transition from ‘0’ to ‘1’ when a compare
match occurs and a transition from ‘1’ to ‘0’ when the counter reaches the auto-reload
value. To do this PWM mode 2 must be enabled by writing OC1M=111 in the
TIMx_CCMR1 register. Optionally the preload registers can be enabled by writing
OC1PE=’1’ in the TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this
case one has to write the compare value in the TIMx_CCR1 register, the auto-reload
value in the TIMx_ARR register, generate an update by setting the UG bit and wait for
external trigger event on TI2. CC1P is written to ‘0’ in this example.
Since only 1 pulse is needed, a 1 must be written in the OPM bit in the TIMx_CR1 register to
stop the counter at the next update event (when the counter rolls over from the auto-reload
value back to 0).
Particular case: OCx fast enable
In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the
counter. Then the comparison between the counter and the compare value makes the
output toggle. But several clock cycles are needed for these operations and it limits the
minimum delay tDELAY min we can get.
If one wants to output a waveform with the minimum delay, the OCxFE bit can be set in the
TIMx_CCMRx register. Then OCxRef (and OCx) are forced in response to the stimulus,
without taking in account the comparison. Its new level is the same as if a compare match
had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.
TRGI
Counter
Output
MS33106V1
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. Res. Res. Res. Res. Res. SMS[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. 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
OC2CE OC2M[2:0] CC2S[1:0] OC1CE OC1M[2:0] CC1S[1:0]
PE FE PE FE
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. CC2NP Res. CC2P CC2E CC1NP CC1NE CC1P CC1E
rw rw rw rw rw rw rw
Table 76. 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
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 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.
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
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.
TIM15_CR1
0x00 [1:0]
Reset value 0 0 0 0 0 0 0 0
0x2C
0x0C
Offset
606/1124
mode
Output
name
TIM15_SR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIM15_CR2
TIM15_PSC
TIM15_CNT
TIM15_ARR
TIM15_EGR
TIM15_DIER
Input Capture
TIM15_CCER
TIM15_SMCR
Compare mode
TIM15_CCMR1
TIM15_CCMR1
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
0
Res. Res. Res. Res. Res. OC2M[3] Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
General-purpose timers (TIM15/TIM16/TIM17)
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
RM0364 Rev 4
0
0
Res. Res. Res. Res. Res. OC1M[3] Res. Res. Res. SMS[3] Res. 16
1
0
0
0
0
Res. OC2CE Res. Res. Res. Res. Res. 15
1
0
0
0
0
0
1
0
0
0
0
0
[2:0]
IC2F[3:0]
OC2M
1
0
0
0
0
Res. Res. Res. Res. Res. Res. 12
1
0
0
0
0
Res. OC2PE Res. Res. Res. Res. Res. 11
IC2
[1:0]
PSC
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
[1:0]
[1:0]
1
0
0
0
0
0
0
CC2S
CC2S
1
0
0
0
0
0
0
0
0
0
PSC[15:0]
CNT[15:0]
ARR[15:0]
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
IC1F[3:0]
OC1M
TS[2:0]
1
0
0
0
0
0
0
0
MMS[2:0]
1
0
0
0
0
0
0
[1:0]
PSC
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
SMS[2:0]
CC1S
CC1S
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.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIM15_RCR REP[7:0]
0x30
Reset value 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIM15_CCR1 CCR1[15:0]
0x34
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.
TIM15_CCR2 CCR2[15:0]
0x38
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OSSR
OSSI
LOCK
MOE
AOE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
BKP
BKE
TIM15_BDTR DTG[7:0]
0x44 [1:0]
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.
Res.
Res.
Res.
Res.
Res.
Res.
TIM15_DCR DBL[4:0] DBA[4:0]
0x48
Reset value 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.
TIM15_DMAR DMAB[15:0]
0x4C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
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. OC1CE OC1M[2:0] OC1PE OC1FE CC1S[1:0]
rw rw rw rw rw rw rw rw
Table 78. 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.
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 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. Res. Res. Res. Res. Res. Res. Res. Res. TI1RMP
rw rw
0x2C
0x0C
Offset
RM0364
20.6.18
mode
Output
name
TIMx_SR
TIMx_CR2
TIMx_CR1
TIMx_PSC
TIMx_CNT
TIMx_ARR
TIMx_EGR
Register
TIMx_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCER
Input Capture
TIMx_CCMR1
TIMx_CCMR1
Compare mode
below:
0
Res. Res. UIFCPY or Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
TIM16/TIM17 register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0364 Rev 4
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 79. TIM16/TIM17 register map and reset values
1
0
0
0
0
0
1
0
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
General-purpose timers (TIM15/TIM16/TIM17)
625/1124
CC1E UG UIF UIE CCPC CEN 0
626
0x50
0x48
0x44
0x34
0x30
0x4C
Offset
626/1124
name
TIM16_OR
TIMx_DCR
TIMx_RCR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCR1
TIMx_BDTR
TIMx_DMAR
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
Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. 22
General-purpose timers (TIM15/TIM16/TIM17)
RM0364 Rev 4
Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. 16
0
0
0
DBL[4:0]
Res. Res. 9
K
0
0
0
0
Res. Res. 8
0
0
0
0
Res. Res. 7
Table 79. TIM16/TIM17 register map and reset values (continued)
CCR1[15:0]
DMAB[15:0]
0
0
0
0
Res. Res. 6
0
0
0
0
Res. Res. 5
0
0
0
0
0
Res. 4
0
0
0
0
0
Res. 3
REP[7:0]
DTG[7:0]
0
0
0
0
0
Res. 2
0
0
0
0
0
0
DBA[4:0]
1
[1:0]
TI1_
0
RMP
0
0
0
0
0
RM0364
0
RM0364 High-Resolution Timer (HRTIM)
21.1 Introduction
The high-resolution timer can generate up to 10 digital signals with highly accurate timings.
It is primarily intended to drive power conversion systems such as switch mode power
supplies or lighting systems, but can be of general purpose usage, whenever a very fine
timing resolution is expected.
Its modular architecture allows to generate either independent or coupled waveforms. The
wave-shape is defined by self-contained timings (using counters and compare units) and a
broad range of external events, such as analog or digital feedbacks and synchronization
signals. This allows to produce a large variety of control signal (PWM, phase-shifted,
constant Ton,...) and address most of conversion topologies.
For control and monitoring purposes, the timer has also timing measure capabilities and
links to built-in ADC and DAC converters. Last, it features light-load management mode and
is able to handle various fault schemes for safe shut-down purposes.
Note: As a writing convention, references to the 5 timing units in the text and in registers are
generalized using the “x” letter, where x can be any value from A to E.
The block diagram of the timer is shown in Figure 244.
3 interface
IRQ requests Reset
7 Timer B 5 Run
DMA burst / HRTIM_CHB1
DMA requests Events 10 Set /Reset
controller Idle HRTIM_CHB2
6 crossbar
Reset Timer E
Ref 1
Run HRTIM_CHE1
4xCMP /
Event 4 HRTIM_CHE2
TIMx TRGO 2x CPT Idle
outputs blanking
External Events
conditioning window
ADC analog 10
Watchdogs
10 5
10 digitalinputs
Fault conditioning
5
5 digital inputs
MS31978V5
HRTIM_CHA1,
HRTIM_CHA2,
HRTIM_CHB1,
HRTIM_CHB2,
HRTIM_CHC1, Main HRTIM timer outputs. They can be coupled by pairs (HRTIM_CHx1 &
Outputs
HRTIM_CHC2, HRTIM_CHx2) with deadtime insertion or work independently.
HRTIM_CHD1,
HRTIM_CHD2,
HRTIM_CHE1,
HRTIM_CHE2
HRTIM_FLT[5:1], Fault inputs: immediately disable the HRTIM outputs when asserted (5 on-chip
Digital input
HRTIM_FLT_in[5:1] inputs and 5 off-chip HRTIM_FLTx inputs).
System fault gathering MCU internal fault events (Clock security system,
SYSFLT Digital input
SRAM parity error, Cortex®-M4 lockup (HardFault), PVD output).
Synchronization inputs to synchronize the whole HRTIM with other internal or
external timer resources:
HRTIM_SCIN1: reserved
HRTIM_SCIN[3:1]
Digital Input HRTIM_SCIN2: the source is a regular TIMx timer (via on-chip interconnect)
HRTIM_SCIN3: the source is an external HRTIM (via the HRTIM_SCIN input
pins)
HRTIM_EEV1[4:1]
HRTIM_EEV2[4:1]
HRTIM_EEV3[4:1]
HRTIM_EEV4[4:1]
HRTIM_EEV5[4:1] External events. Each of the 10 events can be selected among 4 sources,
Digital input either on-chip (from other built-in peripherals: comparator, ADC analog
HRTIM_EEV6[4:1] watchdog, TIMx timers, trigger outputs) or off-chip (HRTIM_EEVx input pins)
HRTIM_EEV7[4:1]
HRTIM_EEV8[4:1]
HRTIM_EEV9[4:1]
HRTIM_EEV10[4:1]
HRTIM register update enable inputs (on-chip interconnect) trigger the
UPD_EN[3:1] Digital input
transfer from shadow to active registers
BMtrig Digital input Burst mode trigger event (on-chip interconnect)
BMClk[4:1] Digital input Burst mode clock (on-chip interconnect)
Digital
ADCtrigOut[4:1] ADC start of conversion triggers
output
Digital
DACtrigOut[3:1] DAC conversion update triggers
output
Digital
IRQ[7:1] Interrupt requests
output
Digital
DMA[6:1] DMA requests
output
21.3.3 Clocks
The HRTIM must be supplied by the tHRTIM system clock to offer a full resolution. The tHRTIM
clock period is evenly divided into up to 32 intermediate steps using an edge positioning
logic. All clocks present in the HRTIM are derived from this reference clock.
Definition of terms
fHRTIM: main HRTIM clock . All subsequent clocks are derived and synchronous with
this source.
fHRCK: high-resolution equivalent clock. Considering the fHRTIM clock period division by
32, it is equivalent to a frequency of 144 x 32 = 4.608 GHz.
fDTG: deadtime generator clock. For convenience, only the tDTG period (tDTG = 1/fDTG)
is used in this document.
fCHPFRQ: chopper stage clock source.
f1STPW: clock source defining the length of the initial pulse in chopper mode. For
convenience, only the t1STPW period (t1STPW = 1/f1STPW) is used in this document.
fBRST: burst mode controller counter clock.
fSAMPLING: clock needed to sample the fault or the external events inputs.
fFLTS: clock derived from fHRTIM which is used as a source for fSAMPLING to filter fault
events.
fEEVS: clock derived from fHRTIM which is used as a source for fSAMPLING to filter
external events.
Table 81. Timer resolution and min. PWM frequency for fHRTIM = 144 MHz
Prescaling fHRCK
CKPSC[2:0] Resolution Min PWM frequency
ratio equivalent frequency
The High-resolution is available for edge positioning, PWM period adjustment and externally
triggered pulse duration.
The high-resolution is not available for the following features
• Timer counter read and write accesses
• Capture unit
For clock prescaling ratios below 32 (CKPSC[2:0] <5), the least significant bits of the
counter and capture registers are not significant. The least significant bits cannot be written
(counter register only) and return 0 when read.
For instance, if CKPSC[2:0] = 2 (prescaling by 4), writing 0xFFFF into the counter register
will yield an effective value of 0xFFF0. Conversely, any counter value between 0xFFFF and
0xFFF0 will be read as 0xFFF0.
Figure 245. Counter and capture register format vs clock prescaling factor
b15 b0 Prescaling
1
16
32
Initialization
At start-up, it is mandatory to initialize first the prescaler bitfields before writing the compare
and period registers. Once the timer is enabled (MCEN or TxCEN bit set in the
HRTIM_MCR register), the prescaler cannot be modified.
When multiple timers are enabled, the prescalers are synchronized with the prescaler of the
timer that was started first.
CPT1
REP
Capture 1
Repetition
CPT2
Capture 2 Master Other
Master
Master
Master
Counter timer timing units
timer
timer
timer
6
9
fHRTIM Prescaler
Counter Period
REP Set / reset
crossbar Out 1
CMP1
RST (2 outputs) To the
Reset CMP1 CMP2
output
Management CMP3 Out 2
Compare 1 Push-pull stage
Half CMP4 and deadtime
CMP2 Update management
Compare 2 Autodelay
CMP3 Events
Blanking and
Compare 3 windowing
CMP4
10
Compare 4 Autodelay
From external events
conditioning
The period and compare values must be within a lower and an upper limit related to the
high-resolution implementation and listed in Table 82:
• The minimum value must be greater than or equal to 3 periods of the fHRTIM clock
• The maximum value must be less than or equal to 0xFFFF - 1 periods of the fHRTIM
clock
Table 82. Period and Compare registers min and max values
CKPSC[2:0] value Min Max
0 0x0060 0xFFDF
1 0x0030 0xFFEF
2 0x0018 0xFFF7
3 0x000C 0xFFFB
Table 82. Period and Compare registers min and max values (continued)
CKPSC[2:0] value Min Max
4 0x0006 0xFFFD
≥5 0x0003 0xFFFD
Note: A compare value greater than the period register value will not generate a compare match
event.
Setting the TxEN bit enables the timer but does not start the counter.
A first reset event starts the counting and any subsequent reset is ignored
Single-shot
0 0 until the counter reaches the PER value.
Non-retriggerable
The PER event is then generated and the counter is stopped.
A reset event re-starts the counting operation from 0x0000.
Setting the TxEN bit enables the timer but does not start the counter.
A reset event starts the counting if the counter is stopped, otherwise it
Single-shot
0 1 clears the counter. When the counter reaches the PER value, the PER
Retriggerable event is generated and the counter is stopped.
A reset event re-starts the counting operation from 0x0000.
Setting the TxEN bit enables the timer and starts the counter
simultaneously.
Continuous
1 X When the counter reaches the PER value, it rolls-over to 0x0000 and
mode
resumes counting.
The counter can be reset at any time.
The TxEN bit can be cleared at any time to disable the timer and stop the counting.
Counter
Reset
Enable
PER
Counter
Reset*
Enable
PER
Counter
Reset*
Enable
Single-shot mode, retriggerable (CONT = 0, RETRIG = 1)
MS32260V1
Roll-over event
A counter roll-over event is generated when the counter goes back to 0 after having reached
the period value set in the HRTIM_PERxR register in continuous mode.
This event is used for multiple purposes in the HRTIM:
– To set/reset the outputs
– To trigger the register content update (transfer from preload to active)
– To trigger an IRQ or a DMA request
– To serve as a burst mode clock source or a burst start trigger
– as an ADC trigger
– To decrement the repetition counter
If the initial counter value is above the period value when the timer is started, or if a new
period is set while the counter is already above this value, the counter is not reset: it will
overflow at the maximum period value and the repetition counter will not decrement.
Timer reset
The reset of the timing unit counter can be triggered by up to 30 events that can be selected
simultaneously in the HRTIM_RSTxR register, among the following sources:
• The timing unit: Compare 2, Compare 4 and Update (3 events)
• The master timer: Reset and Compare 1..4 (5 events)
• The external events EXTEVNT1..10 (10 events)
• All other timing units (e.g. Timer B..E for timer A): Compare 1, 2 and 4 (12 events)
Several events can be selected simultaneously to handle multiple reset sources. In this
case, the multiple reset requests are ORed. When 2 counter reset events are generated
within the same fHRTIM clock cycle, the last counter reset is taken into account.
Additionally, it is possible to do a software reset of the counter using the TxRST bits in the
HRTIM_CR2 register. These control bits are grouped into a single register to allow the
simultaneous reset of several counters.
The reset requests are taken into account only once the related counters are enabled
(TxCEN bit set).
When the fHRTIM clock prescaling ratio is above 32 (counting period above fHRTIM), the
counter reset event is delayed to the next active edge of the prescaled clock. This allows to
maintain a jitterless waveform generation when an output transition is synchronized to the
reset event (typically a constant Ton time converter).
Figure 249 shows how the reset is handled for a clock prescaling ratio of 128 (fHRTIM divided
by 4).
fHRTIM
Prescaled
clock
Reset
event
Counter 5 1 2 0 1
Counter
(PER = 5)
TA1
Repetition counter
A common software practice is to have an interrupt generated when the period value is
reached, so that the maximum amount of time is left for processing before the next period
begins. The main purpose of the repetition counter is to adjust the period interrupt rate and
off-load the CPU by decoupling the switching frequency and the interrupt frequency.
The timing units have a repetition counter. This counter cannot be read, but solely
programmed with an auto-reload value in the HRTIM_REPxR register.
The repetition counter is initialized with the content of the HRTIM_REPxR register when the
timer is enabled (TXCEN bit set). Once the timer has been enabled, any time the counter is
cleared, either due to a reset event or due to a counter roll-over, the repetition counter is
decreased. When it reaches zero, a REP interrupt or a DMA request is issued if enabled
(REPIE and REPDE bits in the HRTIM_DIER register).
If the HRTIM_REPxR register is set to 0, an interrupt is generated for each and every
period. For any value above 0, a REP interrupt is generated after (HRTIM_REPxR + 1)
periods. Figure 250 presents the repetition counter operation for various values, in
continuous mode.
Counter
HRTIM_REPxR = 0 0* 0* 0* 0*
REP REP
HRTIM_REPxR = 2 1* 0* 2* 0*
REP
* denotes repetition counter internal values (not readable, for explanation purpose only)
MS32262V1
The repetition counter can also be used when the counter is reset before reaching the
period value (variable frequency operation) either in continuous or in single-shot mode
(Figure 251 here-below). The reset causes the repetition counter to be decremented, at the
exception of the very first start following counter enable (TxCEN bit set).
PER
Counter
Reset
2* 1* 0* 2* 1* 0*
REP event
* denotes repetition counter internal values (not readable, for explanation purpose only)
MS32263V1
A reset or start event from the HRTIM_SCIN[3:1] source causes the repetition to be
decremented as any other reset. However, in SYNCIN-started single-shot mode
(SYNCSTRTx bit set in the HRTIM_TIMxCR register), the repetition counter will be
decremented only on the 1st reset event following the period. Any subsequent reset will not
alter the repetition counter until the counter is re-started by a new request on
HRTIM_SCIN[3:1] inputs.
Source
CMP1
CMP2
CMP3
CMP4
CMP1
CMP2
CMP3
CMP4
CMP1
CMP2
CMP3
CMP4
CMP1
CMP2
CMP3
CMP4
CMP1
CMP2
CMP3
CMP4
Timer
- - - - 1 2 - 3 - 4 5 - 6 7 - - - - 8 9
A
Timer
1 2 - 3 - - - - - - 4 5 - - 6 7 8 9 - -
B
Destination
Timer
- 1 2 - - 3 4 - - - - - - 5 - 6 - 7 8 9
C
Timer
1 - - 2 - 3 - 4 5 - 6 7 - - - - 8 - - 9
D
Timer
- - 1 2 - - 3 4 5 6 - - 7 8 - 9 - - - -
E
Figure 252 represents how a PWM signal is generated using two compare events.
Figure 252. Compare events action on outputs: set on compare 1, reset on compare 2
fHRTIM
Clock
TA1
Output
Half mode
This mode aims at generating square signal with fixed 50% duty cycle and variable
frequency (typically for converters using resonant topologies). It allows to have the duty
cycle automatically forced to half of the period value when a new period is programmed.
This mode is enabled by writing HALF bit to 1 in the HRTIM_TIMxCR register. When the
HRTIM_PERxR register is written, it causes an automatic update of the Compare 1 value
with HRTIM_PERxR/2 value.
The output on which a square wave is generated must be programmed to have one
transition on CMP1 event, and one transition on the period event, as follows:
– HRTIM_SETxyR = 0x0000 0008, HRTIM_RSTxyR = 0x0000 0004, or
– HRTIM_SETxyR = 0x0000 0004, HRTIM_RSTxyR = 0x0000 0008
The HALF mode overrides the content of the HRTIM_CMP1xR register. The access to the
HRTIM_PERxR register only causes Compare 1 internal register to be updated. The user-
accessible HRTIM_CMP1xR register is not updated with the HRTIM_PERxR / 2 value.
When the preload is enabled (PREEN = 1, MUDIS, TxUDIS), Compare 1 active register is
refreshed on the Update event. If the preload is disabled (PREEN= 0), Compare 1 active
register is updated as soon as HRTIM_PERxR is written.
The period must be greater than or equal to 6 periods of the fHRTIM clock (0xC0 if
CKPSC[2:0] = 0, 0x60 if CKPSC[2:0] = 1, 0x30 if CKPSC[2:0] = 2,...) when the HALF mode
is enabled.
Capture
The timing unit has the capability to capture the counter value, triggered by internal and
external events. The purpose is to:
• measure events arrival timings or occurrence intervals
• update Compare 2 and Compare 4 values in auto-delayed mode (see Auto-delayed
mode).
The capture is done with fHRTIM resolution: for a clock prescaling ratio below 32
(CKPSC[2:0] < 5), the least significant bits of the register are not significant (read as 0).
The timer has 2 capture registers: HRTIM_CPT1xR and HRTIM_CPT2xR. The capture
triggers are programmed in the HRTIM_CPT1xCR and HRTIM_CPT2xCR registers.
The capture of the timing unit counter can be triggered by up to 28 events that can be
selected simultaneously in the HRTIM_CPT1xCR and HRTIM_CPT2xCR registers, among
the following sources:
• The external events, EXTEVNT1..10 (10 events)
• All other timing units (e.g. Timer B..E for timer A): Compare 1, 2 and output 1 set/reset
events (16 events)
• The timing unit: Update (1 event)
• A software capture (1 event)
Several events can be selected simultaneously to handle multiple capture triggers. In this
case, the concurrent trigger requests are ORed. The capture can generate an interrupt or a
DMA request when CPTxIE and CPTxDE bits are set in the HRTIM_TIMxDIER register.
Over-capture is not prevented by the circuitry: a new capture is triggered even if the
previous value was not read, or if the capture flag was not cleared.
CMP1
CMP2
Timer B
TB1 set
TB1 reset
Timer C
4 Capture 1
Timer D
4 Trigger
Timer E selection
4 (OR) Capture 1 register
External events 1..10
10
Timer A Update
CPT1
Software (IRQ & DMA)
Capture
fHRTIM Prescaler
Timer A counter
MS32265V1
Auto-delayed mode
This mode allows to have compare events generated relatively to capture events, so that for
instance an output change can happen with a programmed timing following a capture. In
this case, the compare match occurs independently from the timer counter value. It enables
the generation of waveforms with timings synchronized to external events without the need
of software computation and interrupt servicing.
As long as no capture is triggered, the content of the HRTIM_CMPxR register is ignored (no
compare event is generated when the counter value matches the Compare value. Once the
capture is triggered, the compare value programmed in HRTIM_CMPxR is summed with the
captured counter value in HRTIM_CPTxyR, and it updates the internal auto-delayed
compare register, as seen on Figure 254. The auto-delayed compare register is internal to
the timing unit and cannot be read. The HRTIM_CMPxR preload register is not modified
after the calculation.
This feature is available only for Compare 2 and Compare 4 registers. Compare 2 is
associated with capture 1, while Compare 4 is associated with capture 2. HRTIM_CMP2xR
and HRTIM_CMP4xR Compares cannot be programmed with a value below 3 fHRTIM clock
periods, as in the regular mode.
Capture 1
Counter
Trigger: CPT1,
00 !00 DELCMP2[1..0] CMP1 or CMP3
Autodelayed
Add
Compare 2
DELCMP2[1..0]
Compare 1 10
Compare 3 11
MS32266V1
The auto-delayed Compare is only valid from the capture up to the period event: once the
counter has reached the period value, the system is re-armed with Compare disabled until a
capture occurs.
DELCMP2[1:0] and DELCMP4[1:0] bits in HRTIM_TIMxCR register allow to configure the
auto-delayed mode as follows:
• 00
Regular compare mode: HRTIM_CMP2xR and HRTIM_CMP4xR register contents are
directly compared with the counter value.
• 01
Auto-delayed mode: Compare 2 and Compare 4 values are recomputed and used for
comparison with the counter after a capture 1/2 event.
• 1X
Auto-delayed mode with timeout: Compare 2 and Compare 4 values are recomputed
and used for comparison with the counter after a capture 1/2 event or after a
Compare 1 match (DELCMPx[1:0]= 10) or a Compare 3 match (DELCMPx[1:0]= 11) to
have a timeout function if capture 1/2 event is missing.
When the capture occurs, the comparison is done with the (HRTIM_CMP2/4xR +
HRTIM_CPT1/2xR) value. If no capture is triggered within the period, the behavior depends
on the DELCMPx[1:0] value:
• DELCMPx[1:0] = 01: the compare event is not generated
• DELCMPx[1:0] = 10 or 11: the comparison is done with the sum of the 2 compares (for
instance HRTIM_CMP2xR + HRTIM_CMP1xR). The captures are not taken into
account if they are triggered after CMPx + CMP1 (resp. CMPx + CMP3).
The captures are enabled again at the beginning of the next PWM period.
If the result of the auto-delayed summation is above 0xFFFF (overflow), the value is ignored
and no compare event will be generated until a new period is started.
Note: DELCMPx[1:0] bitfield must be reset when reprogrammed from one value to the other to re-
initialize properly the auto-delayed mechanism, for instance:
• DELCMPx[1:0] = 10
• DELCMPx[1:0] = 00
• DELCMPx[1:0] = 11
As an example, Figure 255 shows how the following signal can be generated:
• Output set when the counter is equal to Compare 1 value
• Output reset 4 cycles after a falling edge on a given external event
Note: To simplify the figure, the high-resolution is not used in this example (CKPSC[2:0] = 101),
thus the counter is incremented at the fHRTIM rate. Similarly, the external event signal is
shown without any resynchronization delay: practically, there is a delay of 1 to 2 fHRTIM clock
periods between the falling edge and the capture event due to an internal resynchronization
stage which is necessary to process external input signals.
Counter 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 0 1 2 3
HRTIM_CPT1xR Previous 7
Match
Capture
External event
Output
4 cycles
MSv40431V1
A regular compare channel (e.g. Compare 1) is used for the output set: as soon as the
counter matches the content of the compare register, the output goes to its active state.
A delayed compare is used for the output reset: the compare event can be generated only if
a capture event has occurred. No event is generated when the counter matches the delayed
compare value (counter = 4). Once the capture event has been triggered by the external
event, the content of the capture register is summed to the delayed compare value to have
the new compare value. In the example, the auto-delayed value 4 is summed to the capture
equal to 7 to give a value of 12 in the auto-delayed compare register. From this time on, the
compare event can be generated and will happen when the counter is equal to 12, causing
the output to be reset.
Overcapture management in auto-delayed mode
Overcapture is prevented when the auto-delayed mode is enabled (DELCMPx[1:0] = 01, 10,
11).
When multiple capture requests occur within the same counting period, only the first capture
is taken into account to compute the auto-delayed compare value. A new capture is possible
only:
• Once the auto-delayed compare has matched the counter value (compare event)
• Once the counter has rolled over (period)
• Once the timer has been reset
Changing auto-delayed compare values
When the auto-delayed compare value is preloaded (PREEN bit set), the new compare
value is taken into account on the next coming update event (for instance on the period
event), regardless of when the compare register was written and if the capture occurred
(see Figure 255, where the delay is changed when the counter rolls over).
When the preload is disabled (PREEN bit reset), the new compare value is taken into
account immediately, even if it is modified after the capture event has occurred, as per the
example below:
1. At t1, DELCMP2 = 1.
2. At t2, CMP2_act = 0x40 => comparison disabled
3. At t3, a capture event occurs capturing the value CPTR1 = 0x20. => comparison
enabled, compare value = 0x60
4. At t4, CMP2_act = 0x100 (before the counter reached value CPTR1 + 0x40) =>
comparison still enabled, new compare value = 0x120
5. At t5, the counter reaches the period value => comparison disabled, cmp2_act = 0x100
Similarly, if the CMP1(CMP3) value changes while DELCMPx = 10 or 11, and preload is
disabled:
1. At t1, DELCMP2 = 2.
2. At t2, CMP2_act = 0x40 => comparison disabled
3. At t3, CMP3 event occurs - CMP3_act = 0x50 before capture 1 event occurs =>
comparison enabled, compare value = 0x90
4. At t4, CMP3_act = 0x100 (before the counter reached value 0x90) => comparison still
enabled, Compare 2 event will occur at = 0x140
Push-pull mode
This mode primarily aims at driving converters using push-pull topologies. It also needs to
be enabled when the delayed idle protection is required, typically for resonant converters
(refer to Section 21.3.9: Delayed Protection).
The push-pull mode is enabled by setting PSHPLL bit in the HRTIM_TIMxCR register.
It applies the signals generated by the crossbar to output 1 and output 2 alternatively, on the
period basis, maintaining the other output to its inactive state. The redirection rate (push-pull
frequency) is defined by the timer’s period event, as shown on Figure 256. The push-pull
period is twice the timer counting period.
MS32268V1
The push-pull mode is only available when the timer operates in continuous mode: the
counter must not be reset once it has been enabled (TxCEN bit set). It is necessary to
disable the timer to stop a push-pull operation and to reset the counter before re-enabling it.
The signal shape is defined using HRTIM_SETxyR and HRTIM_RSTxyR for both outputs. It
is necessary to have HRTIM_SETx1R = HRTIM_SETx2R and HRTIM_RSTx1R =
HRTIM_RSTx2R to have both outputs with identical waveforms and to achieve a balanced
operation. Still, it is possible to have different programming on both outputs for other uses.
Note: The push-pull operation cannot be used when a deadtime is enabled (mutually exclusive
functions).
The CPPSAT status bit in HRTIM_TIMxISR indicates on which output the signal is currently
active. CPPSTAT is reset when the push-pull mode is disabled.
In the example given on Figure 257, the timer internal waveform is defined as follows:
• Output set on period event
• Output reset on Compare 1 match event
Counter
Compare 1
Roll-over events
Push-Pull logic
Set on Reset on
Crossbar output period compare 1
Output 1
Output 2
MS32269V1
Deadtime
A deadtime insertion unit allows to generate a couple of complementary signals from a
single reference waveform, with programmable delays between active state transitions. This
is commonly used for topologies using half-bridges or full bridges. It simplifies the software:
only 1 waveform is programmed and controlled to drive two outputs.
The Dead time insertion is enabled by setting DTEN bit in HRTIM_OUTxR register. The
complementary signals are built based on the reference waveform defined for output 1,
using HRTIM_SETx1R and HRTIM_RSTx1R registers: HRTIM_SETx2R and
HRTIM_RSTx2R registers are not significant when DTEN bit is set.
Note: The deadtime cannot be used simultaneously with the push-pull mode.
Two deadtimes can be defined in relationship with the rising edge and the falling edge of the
reference waveform, as in Figure 258.
Counter
Compare
Crossbar output 1
Deadtime rising
Deadtime falling
Output 1
Output 2
MS32270V1
Negative deadtime values can be defined when some control overlap is required. This is
done using the deadtime sign bits (SDTFx and SDTRx bits in HRTIM_DTxR register).
Figure 259 shows complementary signal waveforms depending on respective signs.
Deadtime rising
Deadtime falling
SDTRx = 0
SDTFx = 0
SDTRx = 1
SDTFx = 1
SDTRx = 0
SDTFx = 1
SDTRx = 1
SDTFx = 0
MS32271V1
The deadtime values are defined with DTFx[8:0] and DTRx[8:0] bitfields and based on a
specific clock prescaled according to DTPRSC[2:0] bits, as follows:
tDTx = +/- DTx[8:0] x tDTG
where x is either R or F and tDTG = (2(DTPRSC[2:0])) x (tHRTIM / 8).
Table 85 gives the resolution and maximum absolute values depending on the prescaler
value.
Figure 260 to Figure 263 present how the deadtime generator behaves for reference
waveforms with pulsewidth below the deadtime values, for all deadtime configurations.
Figure 260. Complementary outputs for low pulse width (SDTRx = SDTFx = 0)
Ref.
DTF DTR
TA1
TA2
Figure 261. Complementary outputs for low pulse width (SDTRx = SDTFx = 1)
Ref.
DTF
TA1
DTR
TA2
Figure 262. Complementary outputs for low pulse width (SDTRx = 0, SDTFx = 1)
Ref.
HRTIM_CHx1
HRTIM_CHx2
MS32274V3
Figure 263. Complementary outputs for low pulse width (SDTRx = 1, SDTFx=0)
Ref.
TA1
TA2
MS32275V1
For safety purposes, it is possible to prevent any spurious write into the deadtime registers
by locking the sign and/or the value of the deadtime using DTFLKx, DTRLKx, DTFSLKx and
DTRSLKx. Once these bits are set, the related bits and bitfields are becoming read only until
the next system reset.
Caution: DTEN bit must not be changed in the following cases:
- When the timer is enabled (TxEN bit set)
- When the timer outputs are set/reset by another timer (while TxEN is reset)
Otherwise, an unpredictable behavior would result.
It is therefore necessary to disable the timer (TxCEN bit reset) and have the corresponding
outputs disabled.
For the particular case where DTEN must be set while the burst mode is enabled with a
deadtime upon entry (BME = 1, DIDL = 1, IDLEM = 1), it is necessary to force the two
outputs in their IDLES state by software commands (SST, RST bits) before setting DTEN bit.
This is to avoid any side effect resulting from a burst mode entry that would happen
immediately before a deadtime enable.
Repetition
External SYNC
Synchronization
Unit
Counter
Start Reset
fHRTIM Prescaler ck Counter Period
REP
CMP1
CMP2 To Timer
CMP1 A..E
CMP3 crossbars
Compare 1 Half CMP4
CMP2 SYNC
Compare 2
CMP3
Compare 3
Register Denotes a register with preload
CMP4
MS32276V1
The master timer is based on the very same architecture as the timing units, with the
following differences:
• It does not have outputs associated with, nor output related control
• It does not have its own crossbar unit, nor push-pull or deadtime mode
• It can only be reset by the external synchronization circuitry
• It does not have a capture unit, nor the auto-delayed mode
• It does not include external event blanking and windowing circuitry
• It has a limited set of interrupt / DMA requests: Compare 1..4, repetition, register
update and external synchronization event.
The master timer control register includes all the timer enable bits, for the master and Timer
A..E timing units. This allows to have all timer synchronously started with a single write
access.
It also handles the external synchronization for the whole HRTIM timer (see
Section 21.3.17: Synchronizing the HRTIM with other timers or HRTIM instances), with both
MCU internal and external (inputs/outputs) resources.
Master timer control registers are mapped with the same offset as the timing units’ registers.
Figure 265. Short distance set/reset management for narrow pulse generation
f HRTIM clock
S
Simulaneous set/reset
R
Set Reset
Reset/set within
R S Set event is anticipated if interval is > t
2 successive periods HRTIM
tHRTIM
R S Set anticipated
Reset/set with > 1 x tHRTIM
interval including 1 x t HRTIM
High-Resolution
S maintained
R > 2 x tHRTIM
Reset/set with
interval including 2 x t HRTIM
Reset/set within
S R
the same period
S R
Reset/set with
t HRTIM
delay < tHRTIM
Reset/set with S R
interval including 1 x tHRTIM > 1 x tHRTIM
S R
Reset/set with
MS32277V1
If the set and reset events are generated within the same tHRTIM period, the reset event has
the highest priority and the set event is ignored.
If the set and reset events are generated with an interval below tHRTIM period, across 2
periods, a pulse of 1 tHRTIM period is generated.
If the set and reset events are generated with an interval below 2 tHRTIM periods, a pulse of 2
tHRTIM periods is generated.
If the set and reset events are generated with an interval between 2 and 3 tHRTIM periods,
the high-resolution is available if the interval is over 2 complete tHRTIM periods.
If the set and reset events are generated with an interval above 3 tHRTIM periods, the high-
resolution is always available.
Concurrent set request / Concurrent reset requests
When multiple sources are selected for a set event, an arbitration is performed when the set
requests occur within the same fHRTIM clock period.
In case of multiple requests from adjacent timers (TIMEVNT1..9), the request which occurs
first is taken into account. The arbitration is done in 2 steps, depending on:
1. the source (CMP4 → CMP3 → CMP2 → CMP1),
2. the delay.
If multiple requests from the master timer occur within the same fHRTIM clock period, a
predefined arbitration is applied and a single request will be taken into account, whatever
the effective high-resolution setting (from the highest to the lowest priority):
MSTCMP4 → MSTCMP3 → MSTCMP2 → MSTCMP1 → MSTCMPER
Note: It is advised to avoid generating multiple set (reset) requests from the master timer to a
given timer with an interval below 3x tHRTIM to maintain the high-resolution.
When multiple requests internal to the timer occur within the same fHRTIM clock period, a
predefined arbitration is applied and the requests are taken with the following priority,
whatever the effective timing (from highest to lowest):
CMP4 → CMP3 → CMP2 → CMP1 → PER
Note: Practically, this is of a primary importance only when using auto-delayed Compare 2 and
Compare 4 simultaneously (i.e. when the effective set/reset cannot be determined a priori
because it is related to an external event). In this case, the highest priority signal must be
affected to the CMP4 event.
Last, the highest priority is given to low-resolution events: EXTEVNT1..10, RESYNC
(coming from SYNC event if SYNCRSTx or SYNCSTRTx is set or from a software reset),
update and software set (SST). The update event is considered as having the largest delay
(0x1F if PSC = 0).
As a summary, in case of a close vicinity (events occurring within the same fHRTIM clock
period), the effective set (reset) event will be arbitrated between:
• Any TIMEVNT1..9 event
• A single source from the master (as per the fixed arbitration given above)
• A single source from the timer
• The “low-resolution events”.
The same arbitration principle applies for concurrent reset requests. In this case, the reset
request has the highest priority.
Output
Timer A..E Output
Timer A..E stage
Output
Timer A..E stage
Output
Timer A..E stage
Output
Timer A..E stage
stage
0
00
!00 Digital
Fast asynchronous path
Filter
EExFAST = 1
01
10 EExF[3:0]
EExSRC[1:0] Prescaler
11
EEVSD[1:0]
EExSNS[1:0]
MS45307V1
The 10 external events are initialized using the HRTIM_EECR1 and HRTIM EECR2
registers:
• to select up to 4 sources with the EExSRC[1:0] bits,
• to select the sensitivity with EExSNS[1:0] bits, to be either level-sensitive or edge-
sensitive (rising, falling or both),
• to select the polarity, in case of a level sensitivity, with EExPOL bit,
• to have a low latency mode, with EExFAST bits (see Latency to external events), for
external events 1 to 5.
Note: The external events used as triggers for reset, capture, burst mode, ADC triggers and
delayed protection are edge-sensitive even if EESNS bit is reset (level-sensitive selection):
if POL = 0 the trigger is active on external event rising edge, while if POL = 1 the trigger is
active on external event falling edge.
The external events are discarded as long as the counters are disabled (TxCEN bit reset) to
prevent any output state change and counter reset, except if they are used as ADC triggers.
Additionally, it is possible to enable digital noise filters, for external events 6 to 10, using
EExF[3:0] bits in the HRTIM_EECR3 register.
A digital filter is made of a counter in which a number N of valid samples is needed to
validate a transition on the output. If the input value changes before the counter has
reached the value N, the counter is reset and the transition is discarded (considered as a
spurious event). If the counter reaches N, the transition is considered as valid and
transmitted as a correct external event. Consequently, the digital filter adds a latency to the
external events being filtered, depending on the sampling clock and on the filter length
(number of valid samples expected).
The sampling clock is either the fHRTIM clock or a specific prescaled clock fEEVS derived
from fHRTIM, defined with EEVSD[1:0] bits in HRTIM_EECR3 register.
Table 86 summarizes the available sources and features associated with each of the 10
external events channels.
Table 87. Output set/reset latency and jitter vs external event operating mode
Response time Jitter on output pulse
EExFAST Response time jitter
latency (counter reset by ext. event)
The EExFAST mode is only available with level-sensitive programming (EExSNS[1:0] = 00);
the edge-sensitivity cannot be programmed.
It is possible to apply event filtering to external events (both blanking and windowing with
EExFLTR[3:0] != 0000, see Section 21.3.8). In this case, EExLTCHx bit must be reset: the
postponed mode is not supported, neither the windowing timeout feature.
Note: The external event configuration (source and polarity) must not be modified once the related
EExFAST bit is set.
A fast external event cannot be used to toggle an output: if must be enabled either in
HRTIM_SETxyR or HRTIM_RSTxyR registers, not in both.
When a set and a reset event - from 2 independent fast external events - occur
simultaneously, the reset has the highest priority in the crossbar and the output becomes
inactive.
When EExFAST bit is set, the output cannot be changed during the 11 fHRTIM clock periods
following the external event.
Figure 267 and Figure 268 give practical examples of the reaction time to external events,
for output set/reset and counter reset.
Figure 267. Latency to external events falling edge (counter reset and output set)
fHRTIM clock
External Event
HRTIMER
output
EExFAST = 1
MS32279V1
fHRTIM clock
External Event
2-3 cycles delay
External Event
after internal
re-synchronisation
HRTIMER
output
EExFAST = 0
5-6 cycles delay total
HRTIMER
output
EExFAST = 1
Minimal latency
(asynchronous path)
MS32293V1
Blanking mode
In event blanking mode (see Figure 269), the external event is ignored if it happens during a
given blanking period. This is convenient, for instance, to avoid a current limit to trip on
switching noise at the beginning of a PWM period. This mode is active for EExFLTR[3:0]
bitfield values ranging from 0001 to 1100.
External event
Ext./int. event
Blanking source
Blanking
Resulting event
MS32294V1
In event postpone mode, the external event is not taken into account immediately but is
memorized (latched) and generated as soon as the blanking period is completed, as shown
on Figure 270. This mode is enabled by setting EExLTCH bit in HRTIM_EEFxR1 and
HRTIM_EEFxR2 registers.
External event
Ext./int. event Latch Blanking source
Blanking
Resulting event
MS32295V1
Timer
- - - - 1 - 2 3 4 - 5 6 7 - - - - 8 - -
A
Timer
1 - 2 3 - - - - 4 5 - 6 - 7 - - 8 - - -
B
Destination
Timer
- 1 - - 2 - 3 4 - - - - 5 - 6 7 - - 8 -
C
Timer
1 - - - - 2 - - 3 4 - 5 - - - - 6 - 7 8
D
Timer
- 1 - - 2 - - - 3 - 4 5 6 - 7 8 - - - -
E
Figure 271 and Figure 272 give an example of external event blanking for all edge and level
sensitivities, in regular and postponed modes.
Counter
Compare 1
Blanking window
External event
EExLTCH = 0
EExLTCH = 1
MS32296V1
Blanking window
External event
MS32297V1
Windowing mode
In event windowing mode, the event is taken into account only if it occurs within a given time
window, otherwise it is ignored. This mode is active for EExFLTR[3:0] ranging from 1101 to
1111.
External event
Ext./int. event
Output
Windowing Blanking source
Resulting event
MS32298V1
EExLTCH bit in EEFxR1 and EEFxR2 registers allows to latch the signal, if set to 1: in this
case, an event is accepted if it occurs during the window but is delayed at the end of it.
• If EExLTCH bit is reset and the signal occurs during the window, it is passed through
directly.
• If EExLTCH bit is reset and no signal occurs, a timeout event is generated at the end of
the window.
A use case of the windowing mode is to filter synchronization signals. The timeout
generation allows to force a default synchronization event, when the expected
synchronization event is lacking (for instance during a converter start-up).
There are 3 sources for each external event windowing, coded as follows:
• 1101 and 1110: the windowing lasts from the counter reset to the compare match
(respectively Compare 2 and Compare 3)
• 1111: the windowing is related to another timing unit and lasts from its counter reset to
its Compare 2 match. The source is described as TIMWIN in the bit description and is
given in Table 89. As an example, the external events in timer B can be filtered by a
window starting from timer A counter reset to timer A Compare 2.
Note: The timeout event generation is not supported if the external event is programmed in fast
mode.
Figure 274 and Figure 275 present how the events are generated for the various edge and
level sensitivities, as well as depending on EExLTCH bit setting. Timeout events are
specifically mentioned for clarity reasons.
Counter
Compare 1
Window
External event
(Timeout)
EExLTCH = 0
(Timeout)
(Timeout)
EExLTCH = 1
Counter
Compare 1
window
External event
MS32330V1
Delayed Idle
In this mode, the active pulse is completed before the protection is activated. The selected
external event causes the output to enter in idle mode at the end of the active pulse (defined
by an output reset event in HRTIM_RSTx1R or HRTIM_RSTx2R).
Once the protection is triggered, the idle mode is permanently maintained but the counter
continues to run, until the output is re-enabled. Tx1OEN and Tx2OEN bits are not affected
by the delayed idle entry. To exit from delayed idle and resume operation, it is necessary to
overwrite Tx1OEN and Tx2OEN bits to 1. The output state will change on the first transition
to an active state following the output enable command.
Note: The delayed idle mode cannot be exited immediately after having been entered, before the
active pulse is completed: it is mandatory to make sure that the outputs are in idle state
before resuming the run mode. This can be done by waiting up to the next period, for
instance, or by polling the O1CPY and/or O2CPY status bits in the TIMxISR register.
The delayed idle mode can be applied to a single output (DLYPRT[2:0] = x00 or x01) or to
both outputs (DLYPRT[2:0] = x10).
An interrupt or a DMA request can be generated in response to a Delayed Idle mode entry.
The DLYPRT flag in HRTIM_TIMxISR is set as soon as the external event arrives,
independently from the end of the active pulse on output.
When the Delayed Idle mode is triggered, the output states can be determined using
O1STAT and O2STAT in HRTIM_TIMxISR. Both status bits are updated even if the delayed
idle is applied to a single output. When the push-pull mode is enabled, the IPPSTAT flag in
HRTIM_TIMxISR indicates during which period the delayed protection request occurred.
This mode is available whatever the timer operating mode (regular, push-pull, deadtime). It
is available with 2 external events only:
• EEV6 and EEV7 for Timer A, B and C
• EEV8 and EEV9 for Timer D and E
The delayed protection mode can be triggered only when the counter is enabled (TxCEN bit
set). It remains active even if the TxEN bit is reset, until the TxyOEN bits are set.
A1
A2 DLYPRT
DLYPRT
A2
A2
DLYPRT
A2 Run mode A2 Idle mode
MS32331V1
The delayed idle mode has a higher priority than the burst mode: any burst mode exit
request is discarded once the delayed idle protection has been triggered. On the contrary, If
the delayed protection is exited while the burst mode is active, the burst mode will be
resumed normally and the output will be maintained in the idle state until the burst mode
exits. Figure 277 gives an overview of these different scenarios.
Burst exit
Burst entry
Output
Delayed
protection
Delayed exit
protection
Entry
Output
MS32280V1
The same priorities are applied when the delayed burst mode entry is enabled (DIDL bit
set), as shown on Figure 278 below.
Crossbar
output
IDLES level
Output
Deadtime
Burst exit
Burst entry
Delayed
Delayed protection
protection exit
Crossbar
output
IDLES level
Output
Deadtime
MS32281V1
Balanced Idle
Only available in push-pull mode, it allows to have balanced pulsewidth on the two outputs
when one of the active pulse is shortened due to a protection. The pulsewidth, which was
terminated earlier than programmed, is copied on the alternate output and the two outputs
are then put in idle state, until the normal operation is resumed by software. This mode is
enabled by writing x11 in DLYPRT[2:0] bitfield in HRTIM_OUTxR.
This mode is available with 2 external events only:
• EEV6 and EEV7 for Timer A, B and C
• EEV8 and EEV9 for Timer D and E
PER
counter
CMP1
Taref
(internal)
TA1
TA2
EEV
TA1
Pulse length
copied
TA2
IPPSTAT = 0
TA1
TA2
DLYPRT
When the balanced Idle mode is enabled, the selected external event triggers a capture of
the counter value into the Compare 4 active register (this value is not user-accessible). The
push-pull is maintained for one additional period so that the shorten pulse can be repeated:
a new output reset event is generated while the regular output set event is maintained.
The Idle mode is then entered and the output takes the level defined by IDLESx bits in the
HRTIM_OUTxR register. The balanced idle mode entry is indicated by the DLYPRT flag,
while the IPPSTAT flag indicates during which period the external event occurred, to
determine the sequence of shorten pulses (HRTIM_CHA1 then HRTIM_CHA2 or vice
versa).
The timer operation is not interrupted (the counter continues to run).
To enable the balanced idle mode, it is necessary to have the following initialization:
– timer operating in continuous mode (CONT = 1)
– Push-pull mode enabled
– HRTIM_CMP4xR must be set to 0 and the content transferred into the active
register (for instance by forcing a software update)
– DELCMP4[1:0] bit field must be set to 00 (auto-delayed mode disabled)
– DLYPRT[2:0] = x11 (delayed protection enable)
Note: The HRTIM_CMP4xR register must not be written during a balanced idle operation. The
CMP4 event is reserved and cannot be used for another purpose.
In balanced idle mode, it is recommended to avoid multiple external events or software-
based reset events causing an output reset. If such an event arrives before a balanced idle
request within the same period, it will cause the output pulses to be unbalanced (1st pulse
length defined by the external event or software reset, while the 2nd pulse is defined by the
balanced idle mode entry).
The minimum pulsewidth that can be handled in balanced idle mode is 4 fHRTIM clock
periods (0x80 when CKPSC[2:0] = 0, 0x40 if CKPSC[2:0] = 1, 0x20 if CKPSC[2:0] = 2,...).
If the capture occurs before the counter has reached this minimum value, the current pulse
is extended up to 4 fHRTIM clock periods before being copied into the secondary output. In
any case, the pulsewidths are always balanced.
Tx1OEN and Tx2OEN bits are not affected by the balanced idle entry. To exit from balanced
idle and resume the operation, it is necessary to overwrite Tx1OEN and Tx2OEN bits to 1
simultaneously. The output state will change on the first active transition following the output
enable.
It is possible to resume operation similarly to the delayed idle entry. For instance, if the
external event arrives while output 1 is active (delayed idle effective after output 2 pulse),
the re-start sequence can be initiated for output 1 first. To do so, it is necessary to poll
CPPSTAT bit in the HRTIM_TIMxISR register. Using the above example (IPPSTAT flag
equal to 0), the operation will be resumed when CPPSTAT bit is 0.
In order to have a specific re-start sequence, it is possible to poll the CPPSTAT to know
which output will be active first. This allows, for instance, to re-start with the same sequence
as the idle entry sequence: if EEV arrives during output 1 active, the re-start sequence will
be initiated when the output 1 is active (CPPSTAT = 0).
Note: The balanced idle mode must not be disabled while a pulse balancing sequence is on-
going. It is necessary to wait until the CMP4 flag is set, thus indicating that the sequence is
completed, to reset the DLYPRTEN bit.
The balanced idle protection mode can be triggered only when the counter is enabled
(TxCEN bit set). It remains active even if the TxCEN bit is reset, until TxyOEN bits are set.
Balanced idle can be used together with the burst mode under the following conditions:
• TxBM bit must be reset (counter clock maintained during the burst, see
Section 21.3.13),
• No balanced idle protection must be triggered while the outputs are in a burst idle state.
The balanced idle mode has a higher priority than the burst mode: any burst mode exit
request is discarded once the balanced idle protection has been triggered. On the contrary,
if the delayed protection is exited while the burst mode is active, the burst mode will be
resumed normally.
Note: Although the output state is frozen in idle mode, a number of events are still generated on
the auxiliary outputs (see Section 21.3.16) during the idle period following the delayed
protection:
- Output set/reset interrupt or DMA requests
- External event filtering based on output signal
- Capture events triggered by set/reset
Table 90. HRTIM preloadable control registers and associated update sources
Timer Preloadable registers Preload enable Update sources
HRTIM_DIER
HRTIM_MPER Software
HRTIM_MREP Repetition event
PREEN bit in
Master Timer HRTIM_MCMP1R Burst DMA event
HRTIM_MCR
HRTIM_MCMP2R Repetition event following a burst
HRTIM_MCMP3R DMA event
HRTIM_MCMP4R
HRTIM_TIMxDIER
HRTIM_TIMxPER
HRTIM_TIMxREP Software
HRTIM_TIMxCMP1R TIMx Repetition event
HRTIM_TIMxCMP1CR TIMx Reset Event
HRTIM_TIMxCMP2R Burst DMA event
Timer x HRTIM_TIMxCMP3R PREEN bit in Update event from other timers
HRTIM_TIMxCR (TIMy, Master)
x = A..E HRTIM_TIMxCMP4R
Update event following a burst
HRTIM_DTxR
DMA event
HRTIM_SETx1R
Update enable input 1..3
HRTIM_RSTx1R
Update event following an update
HRTIM_SETx2R enable input 1..3
HRTIM_RSTx2R
HRTIM_RSTxR
HRTIM_ADC1R
TIMx or Master timer Update, depending on
HRTIM HRTIM_ADC2R
ADxUSRC[2:0] bits in HRTIM_CR1, if PREEN = 1 in the
Common HRTIM_ADC3R selected timer
HRTIM_ADC4R
Each timer (TIMA..E) can also have the update done as follows:
• By software: writing 1 into TxSWU bit in HRTIM_CR2 forces an immediate update of
the registers. In this case, any pending hardware update request is canceled.
• Update done when the counter rolls over and the repetition counter is equal to 0. This
is enabled when TxREPU bit is set in HRTIM_TIMxCR.
• Update done when the counter is reset or rolls over in continuous mode. This is
enabled when TxRSTU bit is set in HRTIM_TIMxCR. This is used for a timer operating
in single-shot mode, for instance.
• Update done once a Burst DMA is completed. This is enabled when
UPDGAT[3:0] = 0001 in HRTIM_TIMxCR.
• Update done on the update event following a Burst DMA completion (the event can be
enabled with TxREPU, MSTU or TxU). This is enabled when UPDGAT[3:0] = 0010 in
HRTIM_TIMxCR.
• Update done when receiving a request on the update enable input 1..3. This is enabled
when UPDGAT[3:0] = 0011, 0100, 0101 in HRTIM_TIMxCR.
• Update done on the update event following a request on the update enable input 1..3
(the event can be enabled with TxREPU, MSTU or TxU). This is enabled when
UPDGAT[3:0] = 0110, 0111, 1000 in HRTIM_TIMxCR
• Update done synchronously with any other timer or master update (for instance TIMA
can be updated simultaneously with TIMB). This is used for converters requiring
several timers, and is enabled by setting bits MSTU and TxU in HRTIM_TIMxCR
register.
The update enable inputs 1..3 allow to have an update event synchronized with on-chip
events coming from the general-purpose timers. These inputs are rising-edge sensitive.
Table 91 lists the connections between update enable inputs and the on-chip sources.
This allows to synchronize low frequency update requests with high-frequency signals (for
instance an update on the counter roll-over of a 100 kHz PWM that has to be done at a
100 Hz rate).
Note: The update events are synchronized to the prescaler clock when CKPSC[2:0] > 5.
An interrupt or a DMA request can be generated by the Timx update event.
MUDIS and TxUDIS bits in the HRTIM_CR1 register allow to temporarily disable the transfer
from preload to active registers, whatever the selected update event. This allows to modify
several registers in multiple timers. The regular update event takes place once these bits
are reset.
MUDIS and TxUDIS bits are all grouped in the same register. This allows the update of
multiple timers (not necessarily synchronized) to be disabled and resumed simultaneously.
The following example is a practical use case. A first power converter is controlled with the
master, TIMB and TIMC. TIMB and TIMC must be updated simultaneously with the master
timer repetition event. A second converter works in parallel with TIMA, TIMD and TIME, and
TIMD, TIME must be updated with TIMA repetition event.
First converter
In HRTIM_MCR, MREPU bit is set: the update will occur at the end of the master timer
counter repetition period. In HRTIM_TIMBCR and HRTIM_TIMCCR, MSTU bits are set to
have TIMB and TIMC timers updated simultaneously with the master timer.
When the power converter set-point has to be adjusted by software, MUDIS, TBUDIS and
TCUDIS bits of the HRTIM_CR register must be set prior to write accessing registers to
update the values (for instance the compare values). From this time on, any hardware
update request is ignored and the preload registers can be accessed without any risk to
have them transferred into the active registers. Once the software processing is over,
MUDIS, TBUDIS and TCUDIS bits must be reset. The transfer from preload to active
registers will be done as soon as the master repetition event occurs.
Second converter
In HRTIM_TIMACR, TAREPU bit is set: the update will occur at the end of the Timer A
counter repetition period. In HRTIM_TIMDCR and HRTIM_TIMECR, TAU bits are set to
have TIMD and TIME timers updated simultaneously with Timer A.
When the power converter set-point has to be adjusted by software, TAUDIS, TDUDIS and
TEUDIS bits of the HRTIM_CR register must be set prior to write accessing the registers to
update the values (for instance the compare values). From this time on, any hardware
update request is ignored and the preload registers can be accessed without any risk to
have them transferred into the active registers. Once the software processing is over,
TAUDIS, TDUDIS and TEUDIS bits can be reset: the transfer from preload to active
registers will be done as soon as the Timer A repetition event occurs.
1 x RUN
0 0 IDLE
0 1 FAULT
TxyOEN bit is both a control and a status bit: it must be set by software to have the output in
RUN mode. It is cleared by hardware when the output goes back in IDLE or FAULT mode.
When TxyOEN bit is cleared, TxyODS bit indicates whether the output is in the IDLE or
FAULT state. A third bit in the HRTIM_ODISR register allows to disable the output by
software.
RUN
Timing Unit Chopper 1x
IDLE
01 HRTIM_CHxy
CPHx FAULT
00
POLx
IDLE State
Active / Inactive
RUN entry: Software (OEN bit set)
IDLESx
Figure 281 summarizes the bit values for the three states and how the transitions are
triggered. Faults can be triggered by any external or internal fault source, as listed in
Section 21.3.15, while the Idle state can be entered when the burst mode or delayed
protections are active.
IDLE State
OEN = 0
ODS = 0
(Fault or breakpoint*)
& (FAULTx[1:0] > 0)
ODIS
bit set & OEN = 1
OEN ODIS
bit set bit set
OEN
bit set
RUN State FAULT State
O EN = 1 OEN = 0
O DS = X ODS = 1
MS32333V1
The FAULT and IDLE levels are defined as active or inactive. Active (or inactive) refers to
the level on the timer output that causes a power switch to be closed (or opened for an
inactive state).
The IDLE state has the highest priority: the transition FAULT → IDLE is possible even if the
FAULT condition is still valid, triggered by ODIS bit set.
The FAULT state has priority over the RUN state: if TxyOEN bit is set simultaneously with a
Fault event, the FAULT state will be entered. The condition is given on the transition IDLE →
FAULT, as in Figure 281: fault protection needs to be enabled (FAULTx[1:0] bits = 01, 10,
11) and the Txy OEN bit set with a fault active (or during a breakpoint if
DBG_HRTIM_STOP = 1).
The output polarity is programmed using POLx bits in HRTIM_OUTxR. When POLx = 0, the
polarity is positive (output active high), while it is active low in case of a negative polarity
(POLx = 1). Practically, the polarity is defined depending on the power switch to be driven
(PMOS vs. NMOS) or on a gate driver polarity.
The output level in the FAULT state is configured using FAULTx[1:0] bits in HRTIM_OUTxR,
for each output, as follows:
• 00: output never enters the fault state and stays in RUN or IDLE state
• 01: output at active level when in FAULT
• 10: output at inactive level when in FAULT
• 11: output is tri-stated when in FAULT. The safe state must be forced externally with
pull-up or pull-down resistors, for instance.
Note: FAULTx[1:0] bits must not be changed as long as the outputs are in FAULT state.
The level of the output in IDLE state is configured using IDLESx bit in HRTIM_OUTxR, as
follows:
• 0: output at inactive level when in IDLE
• 1: output at active level when in IDLE
When TxyOEN bit is set to enter the RUN state, the output is immediately connected to the
crossbar output. If the timer clock is stopped, the level will either be inactive (after an HRTIM
reset) or correspond to the RUN level (when the timer was stopped and the output
disabled).
During the HRTIM initialization, the output level can be prepositioned prior to have it in RUN
mode, using the software forced output set and reset in the HRTIM_SETx1R and
HRTIM_RSTx1R registers.
Counter
Output
Output
RUN IDLE RUN IDLE
state
Burst
clock
Burst
0 0 1 2 3 4 5 6 7 0 1 2 3 4 5
counter
HRTIM_BMCMP = 4
HRTIM_BMPER = 7
MS32283V1
Note: IDLEMx bit must not be changed while the burst mode is active.
The burst mode controller only acts on the output stage. A number of events are still
generated during the idle period:
• Output set/reset interrupt or DMA requests
• External event filtering based on Tx2 output signal
• Capture events triggered by output set/reset
During the burst mode, neither start not reset events are generated on the HRTIM_SCOUT
output, even if TxBM bit is set.
Operating mode
It is necessary to have the counter enabled (TxCEN bit set) before using the burst mode on
a given timing unit.The burst mode is enabled with BME bit in the HRTIM_BMCR register.
It can operate in continuous or single-shot mode, using BMOM bit in the HRTIM_BMCR
register. The continuous mode is enabled when BMOM = 1. The Burst operation is
maintained until BMSTAT bit in HRTIM_BMCR is reset to terminate it.
In single-shot mode (BMOM = 0), the idle sequence is executed once, following the burst
mode trigger, and the normal timer operation is resumed immediately after.
The duration of the idle and run periods is defined with a burst mode counter and 2
registers. The HRTIM_BMCMPR register defines the number of counts during which the
selected timer(s) are in an idle state (idle period). HRTIM_BMPER defines the overall burst
mode period (sum of the idle and run periods). Once the initial burst mode trigger has
occurred, the idle period length is HRTIM_BMCMPR+1, the overall burst period is
HRTIM_BMPER+1.
Note: The burst mode period must not be less than or equal to the deadtime duration defined with
DTRx[8:0] and DTFx[8:0] bitfields.
The counters of the timing units and the master timer can be stopped and reset during the
burst mode operation. HRTIM_BMCR holds 6 control bits for this purpose: MTBM (master)
and TABM..TEBM for Timer A..E.
When MTBM or TxBM bit is reset, the counter clock is maintained. This allows to keep a
phase relationship with other timers in multiphase systems, for instance.
When MTBM or TxBM bit is set, the corresponding counter is stopped and maintained in
reset state during the burst idle period. This allows to have the timer restarting a full period
when exiting from idle. If SYNCSRC[1:0] = 00 or 10 (synchronization output on the master
start or timer A start), a pulse is sent on the HRTIM_SCOUT output when exiting the burst
mode.
Note: TxBM bit must not be set when the balanced idle mode is active (DLYPRT[1:0] = 0x11).
Table 98. Burst mode clock sources from general purpose timer
BMCLK[3:0] Clock source
0110 TIM16 OC
0111 TIM17 OC
1000 TIM7 TRGO
1001 Reserved
The pulsewidth on TIM16/17 OC output must be at least N fHRTIM clock cycles long to be
detected by the HRTIM burst mode controller.
Counter
Output
Trigger on
external event Output
RUN IDLE RUN
state
MS32284V1
For TAEEV7 and TDEEV8 combined triggers (trigger on a Timer period following an
external event), the external event detection is always active, regardless of the burst mode
programming and the on-going burst operation:
• When the burst mode is enabled (BME=1) or the trigger is enabled (TAEEV7 or
TDEEV8 bit set in the BMTRG register) in between the external event and the timer
period event, the burst is triggered.
• The single-shot burst mode is re-triggered even if the external event occurs before the
burst end (as long as the corresponding period happens after the burst).
Note: TAEEV7 and TDEEV8 triggers are valid only after a period event. If the counter is reset
before the period event, the pending EEV7/8 event is discarded.
Figure 284. Delayed burst mode entry with deadtime enabled and IDLESx = 1
Burst Trigger
Output 1
IDLES1 = 1
DIDL1 = 0 Deadtime
DIDL2 = 0 violation
Output 2
IDLES2 = 0
Output 1
IDLES1 = 1
Output 2
IDLES2 = 0
MS32285V1
The delayed burst entry mode is enabled with DIDLx bit in the HRTIM_OUTxR register (one
enable bit per output). It forces a deadtime insertion before the output takes its idle state.
Each TIMx output has its own deadtime value:
– DTRx[8:0] on output 1 when DIDL1 = 1
– DTFx[8:0] on output 2 when DIDL2 = 1
DIDLx bits can be set only if one of the outputs has an active idle level during the burst
mode (IDLES = 1) and only when positive deadtimes are used (SDTR/SDTF set to 0).
Note: The delayed burst entry mode uses deadtime generator resources. Consequently, when any
of the 2 DIDLx bits is set and the corresponding timing unit uses the deadtime insertion
(DTEN bit set in HRTIM_OUTxR), it is not possible to use the timerx output 2 as a filter for
external events (Tx2 filtering signal is not available).
When durations defined by DTRx[8:0] and DTFx[8:0] are lower than 3 fHRTIM clock cycle
periods, the limitations related to the narrow pulse management listed in Section 21.3.6
must be applied.
When the burst mode entry arrives during the regular deadtime, it is aborted and a new
deadtime is re-started corresponding to the inactive period, as on Figure 285.
Tx1 IDLES
Tx2
IDLES
Regular deadtime
DT
(aborted when burst is triggered)
DT
MS32286V1
Figure 286. Burst mode exit when the deadtime generator is enabled
Timx
counter
Out1
crossbar
waveform
Tx1
Tx2
Tx1
Tx2
MS32287V1
The behavior described above is slightly different when the push-pull mode is enabled. The
push-pull mode forces an output reset at the beginning of the period if the output is inactive,
or symmetrically forces an active level if the output was high during the preceding period.
Consequently, an output with an active idle state can be reset at the time the burst mode is
exited even if no transition is explicitly programmed. For symmetrical reasons, an output can
be set at the time the burst mode is exited even if no transition is explicitly programmed, in
case it was active when it entered in idle state.
If the compare register only needs to be changed, a single write is necessary. If the period
only needs to be changed, it is also necessary to re-write the compare to have the new
values taken into account.
When BMPREN bits is reset, the write access into BMCMPR and BMPER directly updates
the active register. In this case, it is necessary to consider when the update is done during
the overall burst period, for the 2 cases below:
a) Compare register update
If the new compare value is above the current burst mode counter value, the new compare
is taken into account in the current period.
If the new compare value is below the current burst mode counter value, the new compare
is taken into account in the next burst period in continuous mode, and ignored in single-shot
mode (no compare match will occur and the idle state will last until the end of the idle
period).
b) Period register update
If the new period value is above the current burst mode counter value, the change is taken
into account in the current period.
Note: If the new period value is below the current burst mode counter value, the new period will
not be taken into account, the burst mode counter will overflow (at 0xFFFF) and the change
will be effective in the next period. In single-shot mode, the counter will roll over at 0xFFFF
and the burst mode will re-start for another period up to the new programmed value.
Burst mode emulation using a compound register
The burst mode controller only controls one or a set of timers for a single converter. When
the burst mode is necessary for multiple independent timers, it is possible to emulate a
simple burst mode controller using the DMA and the HRTIM_CMP1CxR compound register,
which holds aliases of both the repetition and the Compare 1 registers.
This is applicable to a converter which only requires a simple PWM (typically a buck
converter), where the duty cycle only needs to be updated. In this case, the CMP1 register
is used to reset the output (and define the duty cycle), while it is set on the period event.
In this case, a single 32-bit write access in CMP1CxR is sufficient to define the duty cycle
(with the CMP1 value) and the number of periods during which this duty cycle is maintained
(with the repetition value). To implement a burst mode, it is then only necessary to transfer
by DMA (upon repetition event) two 32-bit data in continuous mode, organized as follows:
CMPC1xR = {REP_Run; CMP1 = Duty_Cycle}, {REP_Idle; CMP1 = 0}
For instance, the values:
{0x0003 0000}: CMP1 = 0 for 3 periods
{0x0001 0800}: CMP1 = 0x0800 for 1 period
will provide a burst mode with 2 periods active every 6 PWM periods, as shown on
Figure 287.
Counter
Output
MS32288V1
21.3.14 Chopper
A high-frequency carrier can be added on top of the timing unit output signals to drive
isolation transformers. This is done in the output stage before the polarity insertion, as
shown on Figure 288, using CHP1 and CHP2 bits in the HRTIM_OUTxR register, to enable
chopper on outputs 1 and 2, respectively.
Chopper
fHRTIM Carrier Polarity
/16
generation
CHP1
Sync
x1 HRTIM_CHx1
Fault
Carrier
/
generation CHP2
Idle
Sync
x2 HRTIM_CHx2
MS32334V2
The chopper parameters can be adjusted using the HRIM_CHPxR register, with the
possibility to define a specific pulsewidth at the beginning of the pulse, to be followed by a
carrier frequency with programmable frequency and duty cycle, as in Figure 289.
CARFRQ[3:0] bits define the frequency, ranging from 562.5 kHz to 9 MHz (for
fHRTIM = 144 MHz) following the formula FCHPFRQ = fHRTIM / (16 x (CARFRQ[3:0]+1)).
The duty cycle can be adjusted by 1/8 step with CARDTY[2:0], from 0/8 up to 7/8 duty cycle.
When CARDTY[2:0] = 000 (duty cycle = 0/8), the output waveform only contains the starting
pulse following the rising edge of the reference waveform, without any added carrier.
The pulsewidth of the initial pulse is defined using the STRPW[3:0] bitfield as follows:
t1STPW = (STRPW[3:0]+1) x 16 x tHRTIM and ranges from 111 ns to 1.77 µs (for
fHRTIM=144 MHz).
The carrier frequency parameters are defined based on the fHRTIM frequency, and are not
dependent from the CKPSC[2:0] setting.
In chopper mode, the carrier frequency and the initial pulsewidth are combined with the
reference waveform using an AND function. A synchronization is performed at the end of
the initial pulse to have a repetitive signal shape.
The chopping signal is stopped at the end of the output waveform active state, without
waiting for the current carrier period to be completed. It can thus contain shorter pulses than
programmed.
A1
Carrier
Start
TA1
MS32335V1
Note: CHP1 and CHP2 bits must be set prior to the output enable done with TxyOEN bits in the
HRTIM_OENR register.
CARFRQ[2:0], CARDTY[2:0] and STRPW[3:0] bitfields cannot be modified while the
chopper mode is active (at least one of the two CHPx bits is set).
Figure 290. Fault protection circuitry (FAULT1 fully represented, FAULT2..5 partially)
FAULT1[1:0] FAULT2[1:0]
Tx1
Timer x
Tx2
FLT1 Fault 4
FAULT x pin Fault 5
Filter
FLT1E
Polarity Fault2
Fault3
COMPin
FLT3EN
+ FLT2EN
Ref. - SYSFLT FLT1EN
SYSFLT
Available only for FAULT1, 2, 3
MS32336V1
The polarity of the signal can be selected to define the active level, using the FLTxP polarity
bit in HRTIM_FLTINRx registers. If FLTxP = 0, the signal is active at low level; if FLTxP = 1,
it is active when high.
The fault information can be filtered after the polarity setting. If FLTxF[3:0] bitfield is set to
0000, the signal is not filtered and will act asynchronously, independently from the fHRTIM
clock. For all other FLTxF[3:0] bitfield values, the signal is digitally filtered. The digital filter is
made of a counter in which a number N of valid samples is needed to validate a transition on
the output. If the input value changes before the counter has reached the value N, the
counter is reset and the transition is discarded (considered as a spurious event). If the
counter reaches N, the transition is considered as valid and transmitted as a correct external
event. Consequently, the digital filter adds a latency to the external events being filtered,
depending on the sampling clock and on the filter length (number of valid samples
expected). Figure 291 shows how a spurious fault signal is filtered.
fHRTIM
Fault input
Filter counter 0 0 1 2 3 4 0 0 0 0
Filtered signal
Fault input
Filter counter 0 0 1 2 0 1 2 3 4 0
Filtered signal
MS32289V1
The filtering period ranges from 2 cycles of the fHRTIM clock up to 8 cycles of the fFLTS clock
divided by 32. fFLTS is defined using FLTSD[1:0] bits in the HRTIM_FLTINR2 register.
Table 100 summarizes the sampling rate and the filter length. A jitter of 1 sampling clock
period must be subtracted from the filter length to take into account the uncertainty due to
the sampling and have the effective filtering.
Table 100. Sampling rate and filter length vs FLTFxF[3:0] and clock setting
fFLTS vs FLTSD[1:0] Filter length for fHRTIM = 144 MHz
fHRTIM, N =2 fHRTIM, N =8
0001,0010,0011 fHRTIM fHRTIM fHRTIM fHRTIM
13.9 ns 55.5 ns
fHRTIM /2, N = 6 fHRTIM /16, N = 8
0100, 0101 fHRTIM /2 fHRTIM /4 fHRTIM /8 fHRTIM /16
83.3 ns 888.9 ns
fHRTIM /4, N = 6 fHRTIM /32, N = 8
0110, 0111 fHRTIM /4 fHRTIM /8 fHRTIM /16 fHRTIM /32
166.7 ns 1.777 µs
fHRTIM /8, N = 6 fHRTIM /64, N = 8
1000, 1001 fHRTIM /8 fHRTIM /16 fHRTIM /32 fHRTIM /64
333.3 ns 3.55 µs
Table 100. Sampling rate and filter length vs FLTFxF[3:0] and clock setting (continued)
fFLTS vs FLTSD[1:0] Filter length for fHRTIM = 144 MHz
The auxiliary outputs are taken either before or after the burst mode controller, depending
on the HRTIM operating mode. An overview is given on Figure 292.
Out 1
Out 1
Push-pull
Set / reset To the
or Burst mode
crossbar with output
deadtime controller
events ORing stage
insertion
Out 2 Out 2
Capture triggers
External event filtering
(Out 2 channel only)
MS32290V1
By default, the auxiliary outputs are copies of outputs Tx1 and Tx2. The exceptions are:
• The delayed idle and the balanced idle protections, when the deadtime is disabled
(DTEN = 0). When the protection is triggered, the auxiliary outputs are maintained and
follow the signal coming out of the crossbar. On the contrary, if the deadtime is enabled
(DTEN = 1), both main and auxiliary outputs are forced to an inactive level.
• The burst mode (TCEN=1, IDLEMx=1); there are 2 cases:
a) If DTEN=0 or DIDLx=0, the auxiliary outputs are not affected by the burst mode
entry and continue to follow the reference signal coming out of the crossbar (see
Figure 293).
b) If the deadtime is enabled (DTEN=1) together with the delayed burst mode entry
(DIDLx=1), the auxiliary outputs have the same behavior as the main outputs.
They are forced to the IDLES level after a deadtime duration, then they keep this
level during all the burst period. When the burst mode is terminated, the IDLES
level is maintained until a transition occurs to the opposite level, similarly to the
main output.
Figure 293. Auxiliary and main outputs during burst mode (DIDLx = 0)
Burst mode Burst mode
entry exit
Auxiliary
output1
Auxiliary
output2
Output
IDLES level
Tx1
Output
IDLES level
Tx2
IDLES level continued up
to the transition to the
opposite level
MS32291V1
The signal on the auxiliary output can be slightly distorted when exiting from the burst mode
or when re-enabling the outputs after a delayed protection, if this happens during a
deadtime. In this case, the deadtime applied to the auxiliary outputs is extended so that the
deadtime on the main outputs is respected. Figure 294 gives some examples.
Figure 294. Deadtime distortion on auxiliary output when exiting burst mode
Out1 reset request
Burst exit
Auxiliary
output1
Auxiliary
output2 Case 1: transition request to
Programmed the same level as IDLES
deadtime Same deadtime for main and
Output auxiliary outputs
IDLES = 0
Tx1
Output
IDLES = 0
Tx2
Auxiliary Extended
output1 deadtime
Auxiliary
Case 2: transition request to
output2
a level opposite to IDLES
Deadtime on auxiliary output
Output is extended
IDLES = 1
Tx1
Output IDLES = 0
Tx2
Programmed
deadtime
MS32292V1
Synchronization output
This section explains how the HRTIM must be configured to synchronize external resources
and act as a master unit.
Four events can be selected as the source to be sent to the synchronization output. This is
done using SYNCSRC[1:0] bits in the HRTIM_MCR register, as follows:
• 00: Master timer Start
This event is generated when MCEN bit is set or when the timer is re-started after
having reached the period value in single-shot mode. It is also generated on a reset
which occurs during the counting (when CONT or RETRIG bits are set).
• 01: Master timer Compare 1 event
• 10: Timer A start
This event is generated when TACEN bit is set or when the counter is reset and re-
starts counting in response to this reset. The following counter reset events are not
propagated to the synchronization output: counter roll-over in continuous mode, and
discarded reset request in single-shot non-retriggerable mode. The reset is only taken
into account when it occurs during the counting (CONT or RETRIG bits are set).
• 11: Timer A Compare 1 event
SYNCOUT[1:0] bits in the HRTIM_MCR register specify how the synchronization event is
generated.
The synchronization pulses are generated on the HRTIM_SCOUT output pin, with
SYNCOUT[1:0] = 1x. SYNCOUT[0] bit specifies the polarity of the synchronization signal. If
SYNCOUT[0] = 0, the HRTIM_SCOUT pin has a low idle level and issues a positive pulse of
16 fHRTIM clock cycles length for the synchronization). If SYNCOUT[0] = 1, the idle level is
high and a negative pulse is generated.
Note: The synchronization pulse is followed by an idle level of 16 fHRTIM clock cycles during which
any new synchronization request is discarded. Consequently, the maximum synchronization
frequency is fHRTIM/32.
The idle level on the HRTIM_SCOUT pin is applied as soon as the SYNCOUT[1:0] bits are
enabled (i.e. the bitfield value is different from 00).
The synchronization output initialization procedure must be done prior to the configuration of
the MCU outputs and counter enable, in the following order:
1. SYNCOUT[1:0] and SYNCSRC[1:0] bitfield configuration in HRTIM_MCR
2. HRTIM_SCOUT pin configuration (see the General-purpose I/Os section)
3. Master or Timer A counter enable (MCEN or TACEN bit set)
When the synchronization input mode is enabled and starts the counter (using
SYNCSTRTM/SYNCSTRTx bits) simultaneously with the synchronization output mode
(SYNCSRC[1:0] = 00 or 10), the output pulse is generated only when the counter is starting
or is reset while running. Any reset request clearing the counter without causing it to start
will not affect the synchronization output.
Synchronization input
The HRTIM can be synchronized by external sources, as per the programming of the
SYNCIN[1:0] bits in the HRTIM_MCR register:
• 00: synchronization input is disabled
• 01: reserved configuration
• 10: the on-chip TIM1 general purpose timer (TIM1 TRGO output)
• 11: a positive pulse on the HRTIM_SCIN input pin
This bitfield cannot be changed once the destination timer (master timer or timing unit) is
enabled (MCEN and/or TxCEN bit set).
The HRTIM_SCIN input is rising-edge sensitive. The timer behavior is defined with the
following bits present in HRTIM_MCR and HRTIM_TIMxCR registers (see Table 101 for
details):
• Synchronous start: the incoming signal starts the timer’s counter (SYNCSTRTM and/or
SYNCSTRTx bits set). TxCEN (MCEN) bits must be set to have the timer enabled and
the counter ready to start. In continuous mode, the counter will not start until the
synchronization signal is received.
• Synchronous reset: the incoming signal resets the counter (SYNCRSTM and/or
SYNCRSTx bits set). This event decrements the repetition counter as any other reset
event.
The synchronization events are taken into account only once the related counters are
enabled (MCEN or TxCEN bit set). A synchronization request triggers a SYNC interrupt.
Note: A synchronized start event resets the counter if the current counter value is above the active
period value.
The effect of the synchronization event depends on the timer operating mode, as
summarized in Table 101.
.
Start events are taken into account when the counter is stopped and:
– once the MCEN or TxCEN bits are set
– once the period has been reached.
0 1 A start occurring when the counter is stopped at the period value resets
the counter. A reset request clears the counter but does not start it (the
counter can solely be re-started with the synchronization). Any reset
Single-shot occurring during the counting is ignored (as during regular non-
non-retriggerable retriggerable mode).
Reset events are starting the timer counting. They are taken into account
only if the counter is stopped and:
– once the MCEN or TxCEN bits are set
1 X
– once the period has been reached.
When multiple reset requests are selected (from HRTIM_SCIN and from
internal events), only the first arriving request is taken into account.
The counter start is effective only if the counter is not started or period is
elapsed. Any synchronization event occurring after counter start has no
effect.
A start occurring when the counter is stopped at the period value resets
0 1
the counter. A reset request clears the counter but does not start it (the
Single-shot counter can solely be started by the synchronization). A reset occurring
retriggerable during counting is taken into account (as during regular retriggerable
mode).
The reset from HRTIM_SCIN is taken into account as any HRTIM counter
reset from internal events and is starting or re-starting the timer counting.
1 X
When multiple reset requests are selected, the first arriving request is
taken into account.
The timer is enabled (MCEN or TxCEN bit set) and is waiting for the
synchronization event to start the counter. Any synchronization event
0 1 occurring after the counter start has no effect (the counter can solely be
started by the synchronization). A reset request clears the counter but
Continuous does not start it.
mode
The reset from HRTIM_SCIN is taken into account as any HRTIM counter
reset from internal events and is starting or re-starting the timer counting.
1 X
When multiple reset requests are selected, the first arriving request is
taken into account.
When a synchronization reset event occurs within the same fHRTIM clock cycle as the period
event, this reset is postponed to a programmed period event (since both events are causing
a counter roll-over). This applies only when the high-resolution is active (CKPSC[2:0] < 5).
Figure 295 presents how the synchronized start is done in single-shot mode.
PER
Counter
SCIN
Internal reset
request
SYNCSTRT, Single-shot mode, non-retriggerable
PER
Counter
SCIN
Internal reset
request
MS32337V1
AD1USRC[2:0] AD2USRC[2:0]
AD4USRC[2:0]
AD3USRC[2:0]
Master update
Timer A update
Timer B update
Timer C update
Timer D update
Timer E update
MS32338V2
Note: The synchronization pulse is followed by an idle level of 32 APB clock cycles during which
any new DAC update request is ignored. Consequently, the maximum synchronization
frequency is fapb/64.
When DACSYNC[1:0] bits are enabled in multiple timers, the DACtrigOutx output will
consist of an OR of all timers’ update events. For instance, if DACSYNC = 1 in timer A and
in timer B, the update event in timer A will be ORed with the update event in timer B to
generate a DAC update trigger on the corresponding DACtrigOutx output, as shown on
Figure 297.
Timer A
counter
Timer B
counter
DAC
TrigOutx
MS32339V1
21.3.21 DMA
Most of the events able to generate an interrupt can also generate a DMA request, even
both simultaneously. Each timer (master, TIMA...E) has its own DMA enable register.
The individual DMA requests are ORed into 6 channels as follows:
• 1 channel for the master timer
• 1 channel per timing unit
Note: Before disabling a DMA channel (DMA enable bit reset in TIMxDIER), it is necessary to
disable first the DMA controller.
Table 103 is a summary of the events with their associated DMA enable bits.
HRTIM_PERBR
HRTIM_REPBR Re-direction
HRTIM_CMP1BR demultiplexer
HRTIM_CMP1BCR
HRTIM_CMP2BR
HRTIM_CMP3BR
HRTIM_CMP4BR
DMA controller
HRTIM_BDMADR
DMA unique
destination
MS32340V1
When the DMA trigger occurs, the HRTIM generates multiple 32-bit DMA requests and
parses the update register. If the control bit is set, the write access is redirected to the
associated register. If the bit is reset, the register update is skipped and the register parsing
is resumed until a new bit set is detected, to trigger a new request. Once the 6 update
registers (HRTIM_BDMUPR, 5x HRTIM_BDTxUPR) are parsed, the burst is completed and
the system is ready for another DMA trigger (see the flowchart on Figure 299).
Note: Any trigger occurring while the burst is on-going is discarded, except if it occurs during the
very last data transfer.
The burst DMA mode is permanently enabled (there is no enable bit). A burst DMA
operation is started by the first write access into the HRTIM_BDMADR register.
It is only necessary to have the DMA controller pointing to the HRTIM_BDMADR register as
the destination, in the memory, to the peripheral configuration with the peripheral increment
mode disabled (the HRTIM handles internally the data re-routing to the final destination
register).
To re-initialize the burst DMA mode if it was interrupted during a transaction, it is necessary
to write at least to one of the 6 update registers.
Write data into TIMACR bit Write data into TIMECR bit Write data into
MCR bit set?
HRTIM_MCR set? HRTIM_TIMACR set? HRTIM_TIMECR
Write data into TIMAICR Write data into TIMEICR Write data into
MCIR bit set?
HRTIM_MICR bit set? HRTIM_TIMAICR bit set? HRTIM_TIMEICR
MCMP4 bit Write data into TIMAFLTR Write data into TIMEFLTR Write data into
set? HRTIM_MCMP4 bit set? HRTIM_FLTAR bit set? HRTIM_FLTER
MS32341V1
Several options are available once the DMA burst is completed, depending on the register
update strategy.
If the PREEN bit is reset (preload disabled), the value written by the DMA is immediately
transferred into the active register and the registers are updated sequentially, following the
DMA transaction pace.
When the preload is enabled (PREEN bit set), there are 3 use cases:
1. The update is done independently from DMA burst transfers (UPDGAT[3:0] = 0000 in
HRTIM_TIMxCR and BRSTDMA[1:0] = 00 in HRTIM_MCR). In this case, and if it is
necessary to have all transferred data taken into account simultaneously, the user must
check that the DMA burst is completed before the update event takes place. On the
contrary, if the update event happens while the DMA transfer is on-going, only part of
the registers will be loaded and the complete register update will require 2 consecutive
update events.
2. The update is done when the DMA burst transfer is completed (UPDGAT[3:0] = 0000 in
HRTIM_TIMxCR and BRSTDMA[1:0] = 01 in HRTIM_MCR). This mode guarantees
that all new register values are transferred simultaneously. This is done independently
from the counter value and can be combined with regular update events, if necessary
(for instance, an update on a counter reset when TxRSTU is set).
3. The update is done on the update event following the DMA burst transfer completion
(UPDGAT[3:0] = 0010 in HRTIM_TIMxCR and BRSTDMA[1:0] = 10 in HRTIM_MCR).
This mode guarantees both a coherent update of all transferred data and the
synchronization with regular update events, with the timer counter. In this case, if a
regular update request occurs while the transfer is on-going, it will be discarded and
the effective update will happen on the next coming update request.
The chronogram on Figure 300 presents the active register content for 3 cases: PREEN=0,
UPDGAT[3:0] = 0001 and UPDGAT[3:0] = 0001 (when PREEN = 1).
Timer A
Counter
Repetition
event
DMA requests
Register content
CMP1 (previous) CMP1 (new)
PREEN=0
21.3.23 Debug
When a microcontroller enters the debug mode (Cortex®-M4 core halted), the TIMx counter
either continues to work normally or stops, depending on DBG_HRTIM_STOP configuration
bit in DBG module:
• DBG_HRTIM_STOP = 0: no behavior change, the HRTIM continues to operate.
• DBG_HRTIM_STOP = 1: all HRTIM timers, including the master, are stopped. The
outputs in RUN mode enter the FAULT state if FAULTx[1:0] = 01,10,11, or keep their
current state if FAULTx[1:0] = 00. The outputs in idle state are maintained in this state.
This is permanently maintained even if the MCU exits the halt mode. This allows to
maintain a safe state during the execution stepping. The outputs can be enabled again
by settings TxyOEN bit (requires the use of the debugger).
The topology is given on Figure 301 with the connection to the ADC for voltage reading.
MS32343V3
Figure 302 presents the management of two converters with identical frequency PWM
signals. The outputs are defined as follows:
• HRTIM_CHA1 set on period, reset on CMP1
• HRTIM_CHA2 set on CMP3, reset on PER
The ADC is triggered twice per period, precisely in the middle of the ON time, using CMP2
and CMP4 events.
PER
TIMA CMP4
CMP3
counter
CMP2
CMP1
TIMA HRTIM_CHA1
outputs (BUCK 1)
HRTIM_CHA2
(BUCK 2)
MS32344V2
Timers A..E provide either 10 buck converters coupled by pairs (both with identical switching
frequencies) or 6 completely independent converters (each of them having a different
switching frequency), using the master timer as the 6th time base.
HRTIM_
CHA1
VIN VOUT
HRTIM_
CHA2 ADC
MS32345V3
The main difference vs. a single-switch buck converter is the addition of a deadtime for an
almost complementary waveform generation on HRTIM_CHA2, based on the reference
waveform on HRTIM_CHA1 (see Figure 304).
PER
TIMA
counter
CMP2
CMP1
TIMA HRTIM_CHA1
outputs
HRTIM_CHA2
MS32346V2
The HRTIM is able to manage multiple converters. The number of converters that can be
controlled depends on the topologies and resources used (including the ADC triggers):
• 5 buck converters with synchronous rectification (SR), using the master timer and the 5
timers
• 4 buck converters (without SR), using the master timer and 2 timers
• ...
Figure 306 presents the topology of a 3-phase interleaved buck converter.
HRTIM
_CHA1
HRTIM
_CHC1
MS32347V3
The master timer is responsible for the phase management: it defines the phase
relationship between the converters by resetting the timers periodically. The phase-shift is
360° divided by the number of phases, 120° in the given example.
The duty cycle is then programmed into each of the timers. The outputs are defined as
follows:
• HRTIM_CHA1 set on master timer period, reset on TACMP1
• HRTIM_CHB1 set on master timer MCMP1, reset on TBCMP1
• HRTIM_CHC1 set on master timer MCMP2, reset on TCCMP1
The ADC trigger can be generated on TxCMP2 compare event. Since all ADC trigger
sources are phase-shifted because of the converter topology, it is possible to have all of
them combined into a single ADC trigger to save ADC resources (for instance 1 ADC
regular channel for the full multi-phase converter).
Master CMP2
counter CMP1
TIMA
counter CMP1
TIMB
counter CMP1
TIMC
counter CMP1
HRTIM_CHA1
HRTIM_CHB1
HRTIM_CHC1
MS32348V2
VIN
ZCD
VOUT
HRTIM_
CHA2 ADC
OC
MS32349V3
This converter is operating with a constant Ton time and a variable frequency due the Toff
time variation (depending on the input voltage). It must also include some features to
operate when no zero-crossing is detected, or to limit the Ton time in case of over-current
(OC). The OC feedback is usually conditioned with the built-in comparator and routed onto
an external event input.
Figure 308 presents the waveform during the various operating modes, with the following
parameters defined:
• Ton Min: masks spurious overcurrent (freewheeling diode recovery current),
represented as OC blanking
• Ton Max: practically, the converter set-point. It is defined by CMP1
• Toff Min: limits the frequency when the current limit is close to zero (demagnetization is
very fast). It is defined with CMP2.
• Toff Max: prevents the system to be stuck if no ZCD occurs. It is defined with CMP4 in
auto-delayed mode.
Both Toff values are auto-delayed since the value must be relative to the output falling edge.
CMP4
CMP1
Zero Current C C C C C
Detection
(ZCD)
ZCD blanking
OverCurrent
(OC)
OC blanking
HRTIM_
CHA1
Normal operation Over Current Toff Min Toff Max Normal operation
C Capture event
MS32350V2
BRSTDMA[1:0] MREPU Res. PREEN DACSYNC[1:0] Res. Res. Res. TECEN TDCEN TCCEN TBCEN TACEN MCEN
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
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. MUPD SYNC MREP MCMP4 MCMP3 MCMP2 MCMP1
r r r r r r r
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
w w w w w w w
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
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
MCNT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
MPER[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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 rw rw rw rw
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
MCMP1[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
MCMP2[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
MCMP3[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
MCMP4[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
TxRST TxREP
UPDGAT[3:0] PREEN DACSYNC[1:0] MSTU TEU TDU TCU TBU Res. Res.
U U
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
In HRTIM_TIMECR:
Reserved, must be kept at reset value
Bit 22 In HRTIM_TIMACR, HRTIM_TIMBCR, HRTIM_TIMCCR, HRTIM_TIMECR:
TDU: Timer D update
Register update is triggered by the timer D update
0: Update by timer D disabled
1: Update by timer D enabled
In HRTIM_TIMDCR:
Reserved, must be kept at reset value
Bit 21 In HRTIM_TIMACR, HRTIM_TIMBCR, HRTIM_TIMDCR, HRTIM_TIMECR:
TCU: Timer C update
Register update is triggered by the timer C update
0: Update by timer C disabled
1: Update by timer C enabled
In HRTIM_TIMCCR:
Reserved, must be kept at reset value
Bit 20 In HRTIM_TIMACR, HRTIM_TIMCCR, HRTIM_TIMDCR, HRTIM_TIMECR:
TBU: Timer B update
Register update is triggered by the timer B update
0: Update by timer B disabled
1: Update by timer B enabled
In HRTIM_TIMBCR:
Reserved, must be kept at reset value
Bit 19 In HRTIM_TIMBCR, HRTIM_TIMCCR, HRTIM_TIMDCR, HRTIM_TIMECR:
TAU: Timer A update
Register update is triggered by the timer A update
0: Update by timer A disabled
1: Update by timer A enabled
In HRTIM_TIMACR:
Reserved, must be kept at reset value
Bit 18 TxRSTU: Timerx reset update
Register update is triggered by Timerx counter reset or roll-over to 0 after reaching the period value
in continuous mode.
0: Update by timer x reset / roll-over disabled
1: Update by timer x reset / roll-over enabled
r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DLYPR
Res. RST RSTx2 SETx2 RSTx1 SETx1 CPT2 CPT1 UPD Res. REP CMP4 CMP3 CMP2 CMP1
T
r r r r r r r r r r r r r r
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
DLYPR RSTx2 SET2x RSTx1 SET1x
Res. RSTC CPT2C CPT1C UPDC Res. REPC CMP4C CMP3C CMP2C CMP1C
TC C C C C
w w w w w w w w w w w w w w w
DLYPR RSTx2 SETx2 RSTx1 SETx1 CPT2D CPT1D CMP4D CMP3D CMP2D CMP1D
Res. RSTDE UPDDE Res. REPDE
TDE DE DE DE DE E E E E E E
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
Bit 31 Reserved
Bit 30 DLYPRTDE: Delayed Protection DMA request Enable
This bit is set and cleared by software to enable/disable DMA requests on delayed protection.
0: Delayed protection DMA request disabled
1: Delayed protection DMA request enabled
Bit 29 RSTDE: Reset/roll-over DMA request Enable
This bit is set and cleared by software to enable/disable DMA requests on timer x counter reset or
roll-over in continuous mode.
0: Timer x counter reset/roll-over DMA request disabled
1: Timer x counter reset/roll-over DMA request enabled
Bit 28 RSTx2DE: Output 2 Reset DMA request Enable
Refer to RSTx1DE description
Bit 27 SETx2DE: Output 2 Set DMA request Enable
Refer to SETx1DE description
Bit 26 RSTx1DE: Output 1 Reset DMA request Enable
This bit is set and cleared by software to enable/disable Tx1 output reset DMA requests.
0: Tx1 output reset DMA request disabled
1: Tx1 output reset DMA request enabled
Bit 25 SETx1DE: Output 1 Set DMA request Enable
This bit is set and cleared by software to enable/disable Tx1 output set DMA requests.
0: Tx1 output set DMA request disabled
1: Tx1 output set DMA request enabled
Bit 24 CPT2DE: Capture 2 DMA request Enable
Refer to CPT1DE description
Bit 23 CPT1DE: Capture 1 DMA request Enable
This bit is set and cleared by software to enable/disable Capture 1 DMA requests.
0: Capture 1 DMA request disabled
1: Capture 1 DMA request enabled
Bit 22 UPDDE: Update DMA request Enable
This bit is set and cleared by software to enable/disable DMA requests on update event.
0: Update DMA request disabled
1: Update DMA request enabled
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
CNTx[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
PERx[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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 rw rw rw rw
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
CMP1x[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CMP1x[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
CMP2x[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
CMP3x[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
CMP4x[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
CPT1x[15:0]
r r r r r r r r r r r r r r r r
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
CPT2x[15:0]
r r r r r r r r r r r r r r r r
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
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
TIM TIM TIM TIM MST MST MST MST MST RESYN
CMP4 CMP3 CMP2 CMP1 PER SRT
EVNT4 EVNT3 EVNT2 EVNT1 CMP4 CMP3 CMP2 CMP1 PER C
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIM TIM TIM TIM MST MST MST MST MST RESYN
CMP4 CMP3 CMP2 CMP1 PER SST
EVNT4 EVNT3 EVNT2 EVNT1 CMP4 CMP3 CMP2 CMP1 PER C
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIM TIM TIM TIM MST MST MST MST MST RESYN
CMP4 CMP3 CMP2 CMP1 PER SRT
EVNT4 EVNT3 EVNT2 EVNT1 CMP4 CMP3 CMP2 CMP1 PER C
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV MSTC MSTC MSTC MSTC MSTPE
CMP4 CMP2 UPDT Res.
NT7 NT6 NT5 NT4 NT3 NT2 NT1 MP4 MP3 MP2 MP1 R
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV MSTC MSTC MSTC MSTC MSTPE
CMP4 CMP2 UPDT Res.
NT7 NT6 NT5 NT4 NT3 NT2 NT1 MP4 MP3 MP2 MP1 R
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV MSTC MSTC MSTC MSTC MSTPE
CMP4 CMP2 UPDT Res.
NT7 NT6 NT5 NT4 NT3 NT2 NT1 MP4 MP3 MP2 MP1 R
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV MSTC MSTC MSTC MSTC MSTPE
CMP4 CMP2 UPDT Res.
NT7 NT6 NT5 NT4 NT3 NT2 NT1 MP4 MP3 MP2 MP1 R
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV EXTEV MSTC MSTC MSTC MSTC MSTPE
CMP4 CMP2 UPDT Res.
NT7 NT6 NT5 NT4 NT3 NT2 NT1 MP4 MP3 MP2 MP1 R
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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 rw rw rw rw rw rw rw
Reserved (for TIME only) Reserved (for TIMD only) Reserved (for TIMC only) Reserved (for TIMB only)
TECMP TECMP TE1RS TE1SE TDCM TDCM TD1RS TD1SE TCCM TCCM TC1RS TC1SE TBCMP TBCMP TB1RS TB1SE
2 1 T T P2 P1 T T P2 P1 T T 2 1 T T
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
Reserved (for TIME only) Reserved (for TIMD only) Reserved (for TIMC only) Reserved (for TIMB only)
TECMP TECMP TE1RS TE1SE TDCM TDCM TD1RS TD1SE TCCM TCCM TC1RS TC1SE TBCMP TBCMP TB1RS TB1SE
2 1 T T P2 P1 T T P2 P1 T T 2 1 T T
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
rw 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
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 rw rw rw rw rw rw rw rw
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BMPER DLLRDY
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. SYSFLT FLT5 FLT4 FLT3 FLT2 FLT1
r r r r r
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BMPERC DLLRDYC
w w
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. SYSFLTC FLT5C FLT4C FLT3C FLT2C FLT1C
w w w w w
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BMPERIE DLLRDYIE
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. SYSFLTIE FLT5IE FLT4IE FLT3IE FLT2IE FLT1IE
rw rw rw rw rw
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
TE2O TE1O TD2O TD1O TC2O TC1O TB2O TB1O TA2O TA1O
Res. Res. Res. Res. Res. Res.
EN EN EN EN EN EN EN EN EN EN
rs rs rs rs rs rs rs rs rs rs
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
TE2OD TE1OD TD2OD TD1OD TC2OD TC1OD TB2OD TB1OD TA2OD TA1OD
Res. Res. Res. Res. Res. Res.
IS IS IS IS IS IS IS IS IS IS
w w w w w w w w w w
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
TE2OD TE1OD TD2OD TD1OD TC2OD TC1OD TB2OD TB1OD TA2OD TA1OD
Res. Res. Res. Res. Res. Res.
S S S S S S S S S S
r r r r r r r r r r
BMSTAT Res. Res. Res. Res. Res. Res. Res. Res. Res. TEBM TDBM TCBM TBBM TABM MTBM
rc_w0 rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BMPR
Res. Res. Res. Res. Res. BMPRSC[3:0] BMCLK[3:0] BMOM BME
EN
rw rw rw rw rw rw rw rw rw rw rw
TBCMP TBCMP TACMP TACMP MSTC MSTC MSTC MSTC MSTRE MSTRS
TCRST TBREP TBRST TAREP TARST SW
2 1 2 1 MP4 MP3 MP2 MP1 P T
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
BMCMP[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
BMPER[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
rw rw rw rw rw rw rw rw rw rw
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
AD1TE AD1TE AD1TE AD1TE AD1TD AD1TD AD1TD AD1TD AD1TC AD1TC AD1TC AD1TC AD1TB AD1TB AD1TB AD1TB
PER C4 C3 C2 PER C4 C3 C2 PER C4 C3 C2 RST PER C4 C3
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
AD1TB AD1TA AD1TA AD1TA AD1TA AD1TA AD1EE AD1EE AD1EE AD1EE AD1EE AD1MP AD1MC AD1MC AD1MC AD1MC
C2 RST PER C4 C3 C2 V5 V4 V3 V2 V1 ER 4 3 2 1
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 These bits select the trigger source for th ADC Trigger 1 output . Refer to HRTIM_ADC3R bits
description for details
AD2TE AD2TE AD2TE AD2TE AD2TD AD2TD AD2TD AD2TD AD2TD AD2TC AD2TC AD2TC AD2TC AD2TC AD2TB AD2TB
RST C4 C3 C2 RST PER C4 C3 C2 RST PER C4 C3 C2 PER C4
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
AD2TB AD2TB AD2TA AD2TA AD2TA AD2TA AD2EE AD2EE AD2EE AD2EE AD2EE AD2MP AD2MC AD2MC AD2MC AD2MC
C3 C2 PER C4 C3 C2 V10 V9 V8 V7 V6 ER 4 3 2 1
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 These bits select the trigger source for th ADC Trigger 2 output . Refer to HRTIM_ADC4R bits
description for details
ADC3 ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T
TEPER EC4 EC3 EC2 DPER DC4 DC3 DC2 CPER CC4 CC3 CC2 BRST BPER BC4 BC3
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
ADC3T ADC3T ADC3T ADC3T ADC3T ADC3T ADC3E ADC3E ADC3E ADC3E ADC3E ADC3M ADC3M ADC3M ADC3M ADC3M
BC2 ARST APER AC4 AC3 AC2 EV5 EV4 EV3 EV2 EV1 PER C4 C3 C2 C1
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T
ERST EC4 EC3 EC2 DRST DPER DC4 DC3 DC2 CRST CPER CC4 CC3 CC2 BPER BC4
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
ADC4T ADC4T ADC4T ADC4T ADC4T ADC4T ADC4E ADC4E ADC4E ADC4E ADC4E ADC4M ADC4M ADC4M ADC4M ADC4M
BC3 BC2 APER AC4 AC3 AC2 EV10 EV9 EV8 EV7 EV6 PER C4 C3 C2 C1
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bit 31 ADC4TERST: ADC trigger 4 on Timer E Reset and counter roll-over (1)
Refer to ADC4TCRST description
Bit 30 ADC4TEC4: ADC trigger 4 on Timer E Compare 4
Refer to ADC4TAC2 description
Bit 29 ADC4TEC3: ADC trigger 4 on Timer E Compare 3
Refer to ADC4TAC2 description
Bit 28 ADC4TEC2: ADC trigger 4 on Timer E Compare 2
Refer to ADC4TAC2 description
Bit 27 ADC4TDRST: ADC trigger 4 on Timer D Reset and counter roll-over (1)
Refer to ADC4TCRST description
Bit 26 ADC4TDPER: ADC trigger 4 on Timer D Period
Refer to ADC4TAPER description
Bit 25 ADC4TDC4: ADC trigger 4 on Timer D Compare 4
Refer to ADC4TAC2 description
Bit 24 ADC4TDC3: ADC trigger 4 on Timer D Compare 3
Refer to ADC4TAC2 description
Bit 23 ADC4TDC2: ADC trigger 2 on Timer D Compare 2
Refer to ADC4TAC2 description
Bit 22 ADC4TCRST: ADC trigger 4 on Timer C Reset and counter roll-over (1)
This bit enables the generation of an ADC Trigger upon Timer C reset and roll-over event, on ADC
Trigger 4 output.
Bit 21 ADC4TCPER: ADC trigger 4 on Timer C Period
Refer to ADC4TAPER description
Bit 20 ADC4TCC4: ADC trigger 4 on Timer C Compare 4
Refer to ADC4TAC2 description
Bit 19 ADC4TCC3: ADC trigger 4 on Timer C Compare 3
Refer to ADC4TAC2 description
Bit 18 ADC4TCC2: ADC trigger 4 on Timer C Compare 2
Refer to ADC4TAC2 description
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. CALRTE[1:0] CALEN CAL
rw rw rw wo
rwo 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
rwo rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Res. Res. Res. Res. Res. Res. FLTSD[1:0] 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
FLT5L FLT5S
Res. Res. Res. Res. Res. Res. Res. Res. FLT5F[3:0] FLT5P FLT5E
CK RC
rwo rw rw rw rw rw rw rw
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. MCMP4 MCMP3 MCMP2 MCMP1 MREP MPER MCNT MDIER MICR MCR
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
TIMxE TIMxR TIMxS TIMxR TIMxS TIMxD TIMxC TIMxC TIMxC TIMxC TIMxR TIMxP TIMxC TIMxDI TIMxIC TIMxC
EFR1 ST2R ET2R ST1R ET1R TxR MP4 MP3 MP2 MP1 EP ER NT ER R R
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
BDMADR[31:16]
wo wo wo wo wo wo wo wo wo wo wo wo wo wo wo wo
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BDMADR[15:0]
wo wo wo wo wo wo wo wo wo wo wo wo wo wo wo wo
Table 105. HRTIM Register map and reset values: Master timer
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
SYNCSRC[1:0]
BRSTDMA[1:0]
DACSYNC[1:0]
SYNCOUT[1:0]
SYNCSTRTM
SYNCIN[1:0]
SYNCRSTM
CKPSC[2:0]
RETRIG
MREPU
PREEN
TDCEN
TCCEN
TECEN
TBCEN
TACEN
MCEN
CONT
HALF
Res.
Res.
Res.
Res.
Res.
Res.
HRTIM_MCR
0x0000
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
MCMP4
MCMP3
MCMP2
MCMP1
MUPD
MREP
SYNC
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.
HRTIM_MISR
0x0004
Reset value 0 0 0 0 0 0 0
MCMP4C
MCMP3C
MCMP2C
MCMP1C
MUPDC
MREPC
SYNCC
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.
HRTIM_MICR
0x0008
Reset value 0 0 0 0 0 0 0
MCMP4DE
MCMP3DE
MCMP2DE
MCMP1DE
MCMP4IE
MCMP3IE
MCMP2IE
MCMP1IE
MUPDDE
MREPDE
SYNCDE
MUPDIE
MREPIE
SYNCIE
HRTIM_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
MDIER(1)
0x000C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
HRTIM_MCNT
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
MCNT[15:0]
R
0x0010
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x002C
0x001C
Offset
RM0364
1)
1)
name
HRTIM_
HRTIM_
HRTIM_
HRTIM_
Reserved
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
MCMP4R(1)
MCMP3R(1)
MCMP2R(1)
MCMP1R(1)
HRTIM_MREP(
HRTIM_MPER(
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
Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. 21
RM0364 Rev 4
Res. Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
1
Res. Res. 15
0
0
0
0
1
Res. Res. 14
0
0
0
0
1
Res. Res. 13
0
0
0
0
1
Res. Res. 12
0
0
0
0
1
Res. Res. 11
0
0
0
0
1
Res. Res. 10
0
0
0
0
1
Res. Res. 9
0
0
0
0
1
0 Res. Res. 8
0
0
0
1
Res. 7
MPER[15:0]
0
0
0
0
1
MCMP4[15:0]
MCMP3[15:0]
MCMP2[15:0]
MCMP1[15:0]
Res. 6
0
0
0
0
0
Res. 5
Table 105. HRTIM Register map and reset values: Master timer (continued)
0
0
0
0
1
Res. 4
0
0
0
0
1
Res. 3
MREP[7:0]
0
0
0
0
1
Res. 2
0
0
0
0
1
Res. 1
0
0
0
0
1
797/1124
High-Resolution Timer (HRTIM)
Res. 0
804
0x0030
0x0028
0x0024
0x0020
0x0018
0x0014
0x0010
0x0008
0x0004
0x0000
0x002C
0x001C
0x000C
Offset
798/1124
)
name
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
TIMxISR
TIMxICR
REPxR(1)
PERxR(1)
CMP4xR(1)
CMP3xR(1)
CMP2xR(1)
CMP1xR(1)
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
TIMxDIER(1)
CMP1CxR(1)
HRTIM_CNTxR
HRTIM_TIMxCR
HRTIM_CPT1xR
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. DLYPRTDE Res. Res. 30
[3:0]
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. RSTDE Res. Res. 29
UPDGAT
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. RSTx2DE Res. Res. 28
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. SETx2DE Res. Res. PREEN 27
High-Resolution Timer (HRTIM)
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. RSTx1DE Res. Res. 26
DACSYNC[1:0]
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. SET1xDE Res. Res. 25
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. CPT2DE Res. Res. MSTU 24
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. CPT1DE Res. Res. TEU 23
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. UPDDE Res. Res. TDU 22
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. O2CPY TCU 21
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. REPDE Res. O1CPY TBU 20
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. CMP4DE Res. O2STAT Res. 19
REPx[7:0]
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. CMP3DE Res. O1STAT TxRSTU 18
RM0364 Rev 4
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. CMP2DE Res. IPPSTAT TxREPU 17
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. CMP1DE Res. CPPSTAT Res. 16
0
0
0
0
0
0
0
1
0
0
Res. Res. Res. Res. 15
DELCMP4[1:0]
0
0
0
0
0
0
1
0
0
0
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
0
0
0
1
0
0
0
0
0
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
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
CPT1IE CPT1C CPT1 Res. 7
Table 106. HRTIM Register map and reset values: TIMx (x= A..E)
PERx[15:0]
CNTx[15:0]
0
0
0
CPT1x[15:0]
0
0
0
0
0
1
0
0
0
CMP1x[15:0]
CMP4x[15:0]
CMP3x[15:0]
CMP2x[15:0]
CMP1x[15:0]
UPDIE UPDC UPD PSHPLL 6
0
0
0
0
0
0
0
0
0
0
Res. Res. Res. HALF 5
0
0
0
0
0
0
0
1
0
0
0
0
0
REPIE REPC REP RETRIG 4
0
0
0
0
0
0
0
1
0
0
0
0
0
CMP4IE CMP4C CMP4 CONT 3
REPx[7:0]
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
CMP2IE CMP2C CMP2 CKPSCx[2:0] 1
0
0
0
0
0
0
0
1
0
0
0
0
0x004C
0x003C
Offset
RM0364
name
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
RSTAR(1)
SETx2R(1)
SETx1R(1)
RSTx2R(1)
RSTx1R(1)
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
HRTIM_DTxR(1)
HRTIM_EEFxR2
HRTIM_EEFxR1
HRTIM_CPT2xR
0
0
0
0
0
Res. Res. Res. UPDATE UPDATE UPDATE UPDATE DTFLKx Res. 31
0
0
0
0
0
0
TIMECMP4 Res. Res. EXTEVNT10 EXTEVNT10 EXTEVNT10 EXTEVNT10 DTFSLKx Res. 30
0
0
0
0
0
TIMECMP2 Res. Res. EXTEVNT9 EXTEVNT9 EXTEVNT9 EXTEVNT9 Res. Res. 29
0
0
0
0
0
0
0
TIMECMP1 EXTEVNT8 EXTEVNT8 EXTEVNT8 EXTEVNT8 Res. Res. 28
0
0
0
0
0
0
0
TIMDCMP4 EXTEVNT7 EXTEVNT7 EXTEVNT7 EXTEVNT7 Res. Res. 27
0]
:0]
0
0
0
0
0
0
0
TIMDCMP2 EXTEVNT6 EXTEVNT6 EXTEVNT6 EXTEVNT6 Res. Res. 26
EE5FLTR[3:
0
0
0
0
0
0
0
0
EE10FLTR[3
TIMDCMP1 EXTEVNT5 EXTEVNT5 EXTEVNT5 EXTEVNT5 SDTFx Res. 25
0
0
0
0
0
0
0
0
TIMCCMP4 EE10LTCH EE5LTCH EXTEVNT4 EXTEVNT4 EXTEVNT4 EXTEVNT4 Res. 24
0
0
0
0
0
0
TIMCCMP2 Res. Res. EXTEVNT3 EXTEVNT3 EXTEVNT3 EXTEVNT3 Res. 23
0
0
0
0
0
0
0
TIMCCMP1 EXTEVNT2 EXTEVNT2 EXTEVNT2 EXTEVNT2 0 Res. 22
0
0
0
0
0
0
0
0
0]
0]
0
0
0
0
0
0
0
0
EE9FLTR[3:
EE4FLTR[3:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0364 Rev 4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0]
0]
0
0
0
0
0
0
0
0
0
EE8FLTR[3:
EE3FLTR[3:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0]
0]
0
0
0
0
0
0
0
0
0
EE7FLTR[3:
EE2FLTR[3:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
CPT2x[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0]
0]
0
0
0
0
0
0
0
0
0
EE6FLTR[3:
EE1FLTR[3:
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
799/1124
High-Resolution Timer (HRTIM)
804
0x0058
0x0054
0x0054
0x0054
0x0054
0x005C
0x005C
0x005C
0x005C
Offset
800/1124
name
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
RSTER(1)
RSTDR(1)
RSTCR(1)
RSTBR(1)
CPT1DCR
CPT1CCR
CPT1BCR
CPT1ACR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
HRTIM_CHPxR
0
0
0
0
TECMP2 TECMP2 TECMP2 TECMP2 Res. Res. Res. Res. Res. 31
0
0
0
0
0
0
0
0
TECMP1 TECMP1 TECMP1 TECMP1 Res. TIMDCMP4 TIMECMP4 TIMECMP4 TIMECMP4 30
0
0
0
0
0
0
0
0
TE1RST TE1RST TE1RST TE1RST Res. TIMDCMP2 TIMECMP2 TIMECMP2 TIMECMP2 29
0
0
0
0
0
0
0
0
TE1SET TE1SET TE1SET TE1SET Res. TIMDCMP1 TIMECMP1 TIMECMP1 TIMECMP1 28
0
0
0
0
0
0
0
Res. TDCMP2 TDCMP2 TDCMP2 Res. TIMCCMP4 TIMCCMP4 TIMDCMP4 TIMDCMP4 27
High-Resolution Timer (HRTIM)
0
0
0
0
0
0
0
Res. TDCMP1 TDCMP1 TDCMP1 Res. TIMCCMP2 TIMCCMP2 TIMDCMP2 TIMDCMP2 26
0
0
0
0
0
0
0 25
Res. TD1RST TD1RST TD1RST Res. TIMCCMP1 TIMCCMP1 TIMDCMP1 TIMDCMP1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0364 Rev 4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
EXEV9CPT EXEV9CPT EXEV9CPT EXEV9CPT EXTEVNT2 EXTEVNT2 EXTEVNT2 EXTEVNT2 10
0
0
0
0
0
0
0
0
0
EXEV8CPT EXEV8CPT EXEV8CPT EXEV8CPT EXTEVNT1 EXTEVNT1 EXTEVNT1 EXTEVNT1 9
[3:0]
0
0
0
0
0
0
0
0
0
EXEV7CPT EXEV7CPT EXEV7CPT EXEV7CPT MSTCMP4 MSTCMP4 MSTCMP4 MSTCMP4 8
STRTPW
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
EXEV5CPT EXEV5CPT EXEV5CPT EXEV5CPT MSTCMP2 MSTCMP2 MSTCMP2 MSTCMP2 6
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
CARDTY
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
name
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
CPT2ECR
CPT1ECR
CPT2DCR
CPT2CCR
CPT2BCR
CPT2ACR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
HRTIM_FLTxR
HRTIM_OUTxR
0
0
0
0
0
FLTLCK Res. Res. TECMP2 TECMP2 TECMP2 TECMP2 Res. 31
0
0
0
0
Res. Res. Res. TECMP1 TECMP1 TECMP1 TECMP1 Res. 30
0
0
0
0
Res. Res. Res. TE1RST TE1RST TE1RST TE1RST Res. 29
0
0
0
0
Res. Res. Res. TE1SET TE1SET TE1SET TE1SET Res. 28
0
0
0
0
0
Res. Res. TDCMP2 Res. TDCMP2 TDCMP2 TDCMP2 TDCMP2 27
0
0
0
0
0
Res. Res. TDCMP1 Res. TDCMP1 TDCMP1 TDCMP1 TDCMP1 26
0
0
0
0
0 25
Res. Res. TD1RST Res. TD1RST TD1RST TD1RST TD1RST
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0364 Rev 4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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. DTEN EXEV7CPT EXEV7CPT EXEV7CPT EXEV7CPT EXEV7CPT EXEV7CPT 8
0
0
0
0
0
0
0
Res. DIDL1 EXEV6CPT EXEV6CPT EXEV6CPT EXEV6CPT EXEV6CPT EXEV6CPT 7
0
0
0
0
0
0
0
Res. CHP1 EXEV5CPT EXEV5CPT EXEV5CPT EXEV5CPT EXEV5CPT EXEV5CPT 6
0
0
0
0
0
0
0
Res. EXEV4CPT EXEV4CPT EXEV4CPT EXEV4CPT EXEV4CPT EXEV4CPT 5
FAULT1[1:0 ]
Table 106. HRTIM Register map and reset values: TIMx (x= A..E) (continued)
0
0
0
0
0
0
0
FLT5EN EXEV3CPT EXEV3CPT EXEV3CPT EXEV3CPT EXEV3CPT EXEV3CPT 4
0
0
0
0
0
0
0
FLT4EN IDLES1 EXEV2CPT EXEV2CPT EXEV2CPT EXEV2CPT EXEV2CPT EXEV2CPT 3
0
0
0
0
0
0
0
FLT3EN IDLEM1 EXEV1CPT EXEV1CPT EXEV1CPT EXEV1CPT EXEV1CPT EXEV1CPT 2
0
0
0
0
0
0
0
FLT2EN POL1 UPDCPT UPDCPT UPDCPT UPDCPT UPDCPT UPDCPT 1
0
0
0
0
0
0
0
FLT1EN Res. SWCPT SWCPT SWCPT SWCPT SWCPT SWCPT 0
801/1124
High-Resolution Timer (HRTIM)
804
0x008
0x0028
0x0024
0x0020
0x0018
0x0014
0x0010
0x0004
0x0000
0x001C
0x000C
Offset
802/1124
name
HRTIM_
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
HRTIM_IER
HRTIM_ISR
HRTIM_ICR
BMCMPR(1)
HRTIM_CR2
HRTIM_CR1
HRTIM_DISR
HRTIM_ODSR
HRTIM_OENR
HRTIM_BMCR
HRTIM_BMTRG
0
0
Res. OCHPEV BMSTAT 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
0
High-Resolution Timer (HRTIM)
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
0
0
Res. TECMP2 Res. Res. Res. Res. Res. Res. Res. Res. AD4USRC[2:0] 26
0
0
Res. TECMP1 Res. Res. Res. Res. Res. Res. Res. Res. 25
0
0
Res. TEREP Res. Res. Res. Res. Res. Res. Res. Res. 24
0
0
Res. TERST Res. Res. Res. Res. Res. Res. Res. Res. AD3USRC[2:0] 23
0
0
Res. TDCMP2 Res. Res. Res. Res. Res. Res. Res. Res. 22
0
0
0
Res. TDCMP1 TEBM Res. Res. Res. Res. Res. Res. Res. 21
0
0
0
Res. TDREP TDBM Res. Res. Res. Res. Res. Res. Res. AD2USRC[2:0] 20
0
0
0
Res. TDRST TCBM Res. Res. Res. Res. Res. Res. Res. 19
0
0
0
Res. TCCMP2 TBBM Res. Res. Res. Res. Res. Res. Res. 18
0
0
0
0
0
0
RM0364 Rev 4
Res. TCCMP1 TABM Res. Res. Res. BMPERIE BMPERC BMPER Res. AD1USRC[2:0] 17
0
0
0
0
0
0
Res. TCREP MTBM Res. Res. Res. DLLRDYIE DLLRDYC DLLRDY Res. 16
0
TCRST Res. Res. Res. Res. Res. Res. Res. Res. Res. 15
0
TBCMP2 Res. Res. Res. Res. Res. Res. Res. Res. Res. 14
0
0
TBCMP1 Res. Res. Res. Res. Res. Res. Res. TERST Res. 13
0
0
TBREP Res. Res. Res. Res. Res. Res. Res. TDRST Res. 12
0
0
TBRST Res. Res. Res. Res. Res. Res. Res. TCRST Res. 11
0
0
0
TACMP2 BMPREN Res. Res. Res. Res. Res. Res. TBRST Res. 10
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TARST TD2ODS TD2ODIS TD2OEN Res. Res. Res. Res. Res. 7
0
0
0
0
0
BMCMP[15:0]
MSTCMP4 TD1ODS TD1ODIS TD1OEN Res. Res. Res. Res. Res. 6
Table 107. HRTIM Register map and reset values: Common functions
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
BMPRSC[3:0] BMCLK[3:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
MSTRST BMOM TA2ODS TA2ODIS TA2OEN FLT2IE FLT2C FLT2 TASWU TAUDIS 1
0
0
0
0
0
0
0
0
0
0
0x004C
0x003C
0x002C
Offset
RM0364
name
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
HRTIM_EECR3
HRTIM_EECR2
HRTIM_EECR1
HRTIM_DLLCR
HRTIM_ADC4R(1)
HRTIM_ADC3R(1)
HRTIM_ADC2R(1)
HRTIM_ADC1R(1)
HRTIM_BMPER(1)
HRTIM_FLTINxR1
0
0
0
0
0
FLT4LCK Res. AD2TERST ADC3TEPER AD2TERST AD1TEPER Res. Res. Res. Res. 31
0
0
0
0
0
Res. AD2TEC4 AD1TEC4 AD2TEC4 AD1TEC4 Res. Res. Res. Res. 30
0
0
0
0
0
0
Res. AD2TEC3 AD1TEC3 AD2TEC3 AD1TEC3 Res. Res. EE5FAST Res. 29
0
0
0
0
0
0
0
0
Res. AD2TEC2 AD1TEC2 AD2TEC2 AD1TEC2
EE10SNS[1:0] EE10SNS[1:0] EE5SNS[1:0]
Res. 28
FLT4F[3:0]
0
0
0
0
0
0
0
0
Res. AD2TDRST AD1TDPER AD2TDRST AD1TDPER Res. 27
0
0
0
0
0
0
0
0
FLT4SRC Res. AD2TDPER AD1TDC4 AD2TDPER AD1TDC4 EE10POL EE10POL EE5POL Res. 26
0
0
0
0
0
0
0
0
FLT4P Res. AD2TDC4 AD1TDC3 AD2TDC4 AD1TDC3
EE10SRC[1:0] EE10SRC[1:0] EE5SRC[1:0]
Res. 25
0
0
0
0
0
0
0
0
FLT4E Res. AD2TDC3 AD1TDC2 AD2TDC3 AD1TDC2 Res. 24
0
0
0
0
0
FLT3LCK Res. AD2TDC2 AD1TCPER AD2TDC2 AD1TCPER Res. Res. 0 EE4FAST Res. 23
0
0
0
0
0
0
0
0
Res. AD2TCRST AD1TCC4 AD2TCRST AD1TCC4 Res.
EE9SNS[1:0] EE4SNS[1:0]
Res. 22
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
FLT3F[3:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0364 Rev 4
FLT3P Res. AD2TBPER AD1TBC4 AD2TBPER AD1TBC4 Res. Res. EE3FAST Res. 17
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
FLT2F[3:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
BMPER[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
FLT1F[3:0]
0
0
0
0
0
0
0
0
0
0
Table 107. HRTIM Register map and reset values: Common functions (continued)
0
0
0
0
0
0
0
0
0
0
FLT1SRC AD2MC3 AD1MC3 AD2MC3 AD1MC3 Res. EE6POL EE1POL 2
0
0
0
0
0
0
0
0
0
0
FLT1P CALEN AD2MC2 AD1MC2 AD2MC2 AD1MC2 1
EE6SRC[1:0] EE6SRC[1:0] EE1SRC[1:0]
0
0
0
0
0
0
0
0
0
0
FLT1E CAL AD2MC1 AD1MC1 AD2MC1 AD1MC1 0
803/1124
High-Resolution Timer (HRTIM)
804
1.
0x0070
0x0068
0x0064
0x0060
0x0058
0x0054
0x006C
0x005C
Offset
804/1124
name
HRTIM_
HRTIM_
HRTIM_
HRTIM_
HRTIM_
BDTEUPR
BDTDUPR
BDTCUPR
BDTBUPR
BDMUPDR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
HRTIM_BDMADR
HRTIM_FLTINxR2
HRTIM_BDTAUPR
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
High-Resolution Timer (HRTIM)
0
Res. Res. Res. Res. Res. Res. Res. 26
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. 23
0
Res. Res. Res. Res. Res. Res. Res. 21
0
0
0
0
0
0
TIMEFLTR TIMDFLTR TIMCFLTR TIMBFLTR TIMAFLTR Res. Res. 20
0
0
0
0
0
0
TIMEOUTR TIMDOUTR TIMCOUTR TIMBOUTR TIMAOUTR Res. Res. 19
0
0
0
0
0
0
TIMECHPR TIMDCHPR TIMCCHPR TIMBCHPR TIMACHPR Res. Res. 18
0
0
0
0
0
0
RM0364 Rev 4
TIMERSTR TIMDRSTR TIMCRSTR TIMBRSTR TIMARSTR Res. Res. 17
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
BDMADR[31:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 107. HRTIM Register map and reset values: Common functions (continued)
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 TIM16 and TIM17 as shown in Figure 309.
To generate the infrared remote control signals, the IR interface must be enabled and TIM16
channel 1 (TIM16_OC1) and TIM17 channel 1 (TIM17_OC1) must be properly configured to
generate correct waveforms.
The infrared receiver can be implemented easily through a basic input capture mode.
Figure 309. IRTIM internal hardware connections with TIM16 and TIM17
TIM17_CH1
IRTIM IR_OUT
TIM16_CH1
MS34517V1
All standard IR pulse modulation modes can be obtained by programming the two timer
output compare channels.
TIM17 is used to generate the high frequency carrier signal, while TIM16 generates the
modulation envelope.
The infrared function is output on the IR_OUT pin. The activation of this function is done
through the GPIOx_AFRx register by enabling the related alternate function bit.
The high sink LED driver capability (only available on the PB9 pin) can be activated through
the I2C_PB9_FMP bit in the SYSCFG_CFGR1 register and used to sink the high current
needed to directly control an infrared LED.
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 311 and Figure 312 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 311. 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 312. 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 317. 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 318. 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
23.4.9
818/1124
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)
RM0364 Rev 4
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:
RM0364
24.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 25 on page
828.
CORE
Prescaler register Status register Reload register Key register
IWDG_PR IWDG_SR IWDG_RLR IWDG_KR
MS19944V2
1. The register interface is located in the CORE 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
24.4.6
RM0364
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.
RM0364 Rev 4
17
Res. Res. Res. Res. Res. 16
0
Res. Res. 11
Table 109. 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 47 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)
827/1124
0
827
System window watchdog (WWDG) RM0364
25.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 APB1 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: APB1 clock period measured in ms
4096: value corresponding to internal divider
As an example, lets assume APB1 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. Res. Res. Res. Res. EWI WDGTB[1:0] W[6:0]
rs rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 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.
Res.
WWDG_CR T[6:0]
0x000
Reset value 0 1 1 1 1 1 1 1
WDGTB1
WDGTB0
Res.
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
Reset value 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
26.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.
The RTC includes also a periodic programmable wakeup flag with interrupt capability.
Two 32-bit registers contain the seconds, minutes, hours (12- or 24-hour format), day (day
of week), date (day of month), month, and year, expressed in binary coded decimal format
(BCD). The sub-seconds value is also available in binary format.
Compensations for 28-, 29- (leap year), 30-, and 31-day months are performed
automatically. Daylight saving time compensation can also be performed.
Additional 32-bit registers contain the programmable alarm subseconds, seconds, minutes,
hours, day, and date.
A digital calibration feature is available to compensate for any deviation in crystal oscillator
accuracy.
After RTC domain reset, all RTC registers are protected against possible parasitic write
accesses.
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).
ck_apre
RTC_CALR RTC_PRER (default 256 Hz) RTC_PRER ck_spre
Smooth Asynchronous Synchronous (default 1 Hz)
calibration 7-bit prescaler 15-bit prescaler
(default = 128) (default = 256) Calendar
Shadow registers
Shadow register
RTC_TR
RTC_SSR
RTC_DR
RTC_CALIB
Output RTC_OUT
control
RTC_ALARM
Alarm A
= ALRAF
RTC_ALRMAR
RTC_ALRMASSR
MSv19901V3
RTC_ALARM
1 Don’t care Don’t care Don’t care Don’t care 0
output OD
RTC_ALARM
1 Don’t care Don’t care Don’t care Don’t care 1
output PP
RTC_CALIB
0 1 Don’t care Don’t care Don’t care Don’t care
output PP
RTC_TAMP1
0 0 1 0 Don’t care Don’t care
input floating
RTC_TS and
RTC_TAMP1 0 0 1 1 Don’t care Don’t care
input floating
RTC_TS input
0 0 0 1 Don’t care Don’t care
floating
Output PP PC13 output
0 0 0 0 1
forced data value
Wakeup pin or
Standard 0 0 0 0 0 Don’t care
GPIO
1. OD: open drain; PP: push-pull.
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 26.3.6: Periodic auto-wakeup for details).
register (RTC_ISR)). The copy is not performed in Stop and Standby mode. When exiting
these modes, the shadow registers are updated after up to 1 RTCCLK period.
When the application reads the calendar registers, it accesses the content of the shadow
registers. It is possible to make a direct access to the calendar registers by setting the
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_ISR 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 RTC_ALARM output provided it has been
enabled through bits OSEL[1:0] of RTC_CR register. RTC_ALARM 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.
read access must be done. In any case the APB1 clock frequency must never be lower than
the RTC clock frequency.
The RSF bit is set in RTC_ISR register each time the calendar registers are copied into the
RTC_SSR, RTC_TR and RTC_DR shadow registers. The copy is performed every
RTCCLK cycles. To ensure consistency between the 3 values, reading either RTC_SSR or
RTC_TR locks the values in the higher-order calendar shadow registers until RTC_DR is
read. In case the software makes read accesses to the calendar in a time interval smaller
than 1 RTCCLK period: RSF must be cleared by software after the first calendar read, and
then the software must wait until RSF is set before reading again the RTC_SSR, RTC_TR
and RTC_DR registers.
After waking up from low-power mode (Stop or Standby), RSF must be cleared by software.
The software must then wait until it is set again before reading the RTC_SSR, RTC_TR and
RTC_DR registers.
The RSF bit must be cleared after wakeup and not before entering low-power mode.
After a system reset, the software must wait until RSF is set before reading the RTC_SSR,
RTC_TR and RTC_DR registers. Indeed, a system reset resets the shadow registers to
their default values.
After an initialization (refer to Calendar initialization and configuration on page 841): the
software must wait until RSF is set before reading the RTC_SSR, RTC_TR and RTC_DR
registers.
After synchronization (refer to Section 26.3.10: RTC synchronization): the software must
wait until RSF is set before reading the RTC_SSR, RTC_TR and RTC_DR registers.
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.
(RTC_TSSSR, RTC_TSTR and RTC_TSDR), the RTC tamper and alternate function
configuration register (RTC_TAFCR), the RTC backup registers (RTC_BKPxR), the wakeup
timer register (RTC_WUTR), the Alarm A and Alarm B registers
(RTC_ALRMASSR/RTC_ALRMAR and RTC_ALRMBSSR/RTC_ALRMBR).
In addition, when it is clocked by the LSE, the RTC keeps on running under system reset if
the reset source is different from the RTC domain reset one (refer to the RTC clock section
of the Reset and clock controller for details on the list of RTC clock sources not affected by
system reset). When a RTC domain reset occurs, the RTC is stopped and all the RTC
registers are set to their reset values.
Each 1 Hz clock edge is compared to the nearest RTC_REFIN clock edge (if one is found
within a given time window). In most cases, the two clock edges are properly aligned. When
the 1 Hz clock becomes misaligned due to the imprecision of the LSE clock, the RTC shifts
the 1 Hz clock a bit so that future 1 Hz clock edges are aligned. Thanks to this mechanism,
the calendar becomes as precise as the reference clock.
The RTC detects if the reference clock source is present by using the 256 Hz clock
(ck_apre) generated from the 32.768 kHz quartz. The detection is performed during a time
window around each of the calendar updates (every 1 s). The window equals 7 ck_apre
periods when detecting the first reference clock edge. A smaller window of 3 ck_apre
periods is used for subsequent calendar updates.
Each time the reference clock is detected in the window, the synchronous prescaler which
outputs the ck_spre clock is forced to reload. This has no effect when the reference clock
and the 1 Hz clock are aligned because the prescaler is being reloaded at the same
moment. When the clocks are not aligned, the reload shifts future 1 Hz clock edges a little
for them to be aligned with the reference clock.
If the reference clock halts (no reference clock edge occurred during the 3 ck_apre window),
the calendar is updated continuously based solely on the LSE clock. The RTC then waits for
the reference clock using a large 7 ck_apre period detection window centered on the
ck_spre edge.
When the RTC_REFIN detection is enabled, PREDIV_A and PREDIV_S must be set to their
default values:
• PREDIV_A = 0x007F
• PREVID_S = 0x00FF
Note: RTC_REFIN clock detection is not available in Standby mode.
Using this mode and measuring the accuracy of the 1 Hz output over exactly 32 seconds
guarantees that the measure is within 0.477 ppm (0.5 RTCCLK cycles over 32 seconds, due
to the limitation of the calibration resolution).
• CALW16 bit of the RTC_CALR register can be set to 1 to force a 16- second calibration
cycle period.
In this case, the RTC precision can be measured during 16 seconds with a maximum error
of 0.954 ppm (0.5 RTCCLK cycles over 16 seconds). However, since the calibration
resolution is reduced, the long term RTC precision is also reduced to 0.954 ppm: CALM[0]
bit is stuck at 0 when CALW16 is set to 1.
• CALW8 bit of the RTC_CALR register can be set to 1 to force a 8- second calibration
cycle period.
In this case, the RTC precision can be measured during 8 seconds with a maximum error of
1.907 ppm (0.5 RTCCLK cycles over 8s). The long term RTC precision is also reduced to
1.907 ppm: CALM[1:0] bits are stuck at 00 when CALW8 is set to 1.
Re-calibration on-the-fly
The calibration register (RTC_CALR) can be updated on-the-fly while RTC_ISR/INITF=0, by
using the follow process:
1. Poll the RTC_ISR/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.
Optionally, a tamper event can cause a time-stamp to be recorded. See the description of
the TAMPTS control bit in Section 26.6.16: RTC tamper and alternate function configuration
register (RTC_TAFCR).
Caution: To avoid losing tamper detection events, the signal used for edge detection is logically
ANDed with the corresponding TAMPxE bit in order to detect a tamper detection event in
case it occurs before the RTC_TAMPx pin is enabled.
• When TAMPxTRG = 0: if the RTC_TAMPx is already high before tamper detection is
enabled (TAMPxE bit set to 1), a tamper event is detected as soon as the RTC_TAMPx
input is enabled, even if there was no rising edge on the RTC_TAMPx input after
TAMPxE was set.
• When TAMPxTRG = 1: if the RTC_TAMPx is already low before tamper detection is
enabled, a tamper event is detected as soon as the RTC_TAMPx input is enabled
(even if there was no falling edge on the RTC_TAMPx input after TAMPxE was set.
After a tamper event has been detected and cleared, the RTC_TAMPx should be disabled
and then re-enabled (TAMPxE set to 1) before re-programming the backup registers
(RTC_BKPxR). This prevents the application from writing to the backup registers while the
RTC_TAMPx input value still indicates a tamper detection. This is equivalent to a level
detection on the RTC_TAMPx input.
Note: Tamper detection is still active when VDD power is switched off. To avoid unwanted resetting
of the backup registers, the pin to which the RTC_TAMPx is mapped should be externally
tied to the correct level.
Note: When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is
automatically configured as output.
When COSEL bit is cleared, the RTC_CALIB output is the output of the 6th stage of the
asynchronous prescaler.
When COSEL bit is set, the RTC_CALIB output is the output of the 8th stage of the
synchronous prescaler.
Alarm output
The RTC_ALARM pin can be configured in output open drain or output push-pull using the
control bit ALARMOUTTYPE in the RTC_TAFCR register.
Note: Once the RTC_ALARM output is enabled, it has priority over RTC_CALIB (COE bit is don't
care and must be kept cleared).
When the RTC_CALIB or RTC_ALARM output is selected, the RTC_OUT pin is
automatically configured as output.
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 alarm, RTC
Stop tamper event, RTC timestamp event, and RTC Wakeup cause the device to exit the Stop
mode.
The RTC remains active when the RTC clock source is LSE or LSI. RTC alarm, RTC
Standby tamper event, RTC timestamp event, and RTC Wakeup cause the device to exit the
Standby mode.
System reset: 0x0000 0000 when BYPSHAD = 0. Not affected when BYPSHAD = 1.
31 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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. COE OSEL[1:0] POL COSEL BKP SUB1H ADD1H
rw rw rw rw rw rw w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BYPS
TSIE WUTIE ALRBIE ALRAIE TSE WUTE ALRBE ALRAE Res. FMT REFCKON TSEDGE WUCKSEL[2:0]
HAD
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Bits 7, 6 and 4 of this register can be written in initialization mode only (RTC_ISR/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_ISR
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.
This register is write protected. The write access procedure is described in RTC register
write protection on page 841.
Caution: TSE must be reset when TSEDGE is changed to avoid spuriously setting of TSF.
31 30 29 28 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. RECALPF
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ALRB
Res. TAMP2F TAMP1F TSOVF TSF WUTF ALRBF ALRAF INIT INITF RSF INITS SHPF WUTWF ALRAWF
WF
rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rw r rc_w0 r r r r r
Note: The bits ALRAF, ALRBF, WUTF and TSF are cleared 2 APB clock cycles after programming
them to 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. 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
MSK4 WDSEL DT[1:0] DU[3:0] MSK3 PM HT[1:0] HU[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
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
MSK4 WDSEL DT[1:0] DU[3:0] MSK3 PM HT[1:0] HU[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
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. 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
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
ADD1S 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. 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
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
PC15 PC15 PC14 PC14 PC13 PC13
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
MODE VALUE MODE VALUE MODE VALUE
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMPP TAMPPRCH TAMPT TAMP2 TAMP2 TAMP1 TAMP1
TAMPFLT[1:0] TAMPFREQ[2:0] Res. Res. TAMPIE
UDIS [1:0] S TRG E TRG E
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Caution: When TAMPFLT = 0, TAMPxE must be reset when TAMPxTRG is changed to avoid
spuriously setting TAMPxF.
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. 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
10
11
9
8
7
6
5
4
3
2
1
0
name
HT[1:0]
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PM
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DT[1:0]
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
MT
Reset value 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1
WUCKSEL[2:0]
REFCKON
BYPSHAD
OSEL[1:0]
TSEDGE
ALRBIE
ALRAIE
ADD1H
COSEL
SUB1H
ALRBE
ALRAE
WUTIE
WUTE
TSIE
COE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FMT
POL
BKP
TSE
RTC_CR
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
RECALPF
ALRBWF
.TAMP2F
ALRAWF
WUT WF
TAMP1F
TSOVF
ALRBF
ALRAF
WUTF
SHPF
INITS
INITF
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RSF
TSF
INIT
RTC_ISR
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_WUTR WUT[15:0]
0x14
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0x3C
0x2C
0x1C
Offset
876/1124
RTC_
RTC_
name
RTC_SSR
RTC_WPR
Register
RTC_TSTR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
RTC_TSDR
RTC_ CALR
ALRMBSSR
ALRMASSR
RTC_TAFCR
RTC_TSSSR
RTC_SHIFTR
RTC_ALRMBR
RTC_ALRMAR
0
0
0
Res. Res. Res. Res. Res. Res. Res. ADD1S Res. Res. MSK4 MSK4 31
Real-time clock (RTC)
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WDSEL 0 WDSEL 30
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
DT[1:0] DT[1:0]
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
0
0
0
0
0
0
0
0
[3:0]
[3:0]
0
0
0
0
MASKSS
MASKSS
0
0
0
0
0
0
0
Res. Res. PC15MODE Res. Res. Res. Res. Res. Res. Res. MSK3 MSK3 23
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0364 Rev 4
17
HU[3:0]
HU[3:0]
HU[3:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
CALW8 Res. 14
TAMPPRCH[1:0]
0
0
0
0
0
0
0
0
0
0
0
WDU[1:0]
CALW16 MNT[2:0] Res. 13
0
0
0
0
0
0
0
0
0
0
MNT[2:0]
MNT[2:0]
Res. MT Res. 12
TAMPFLT[1:0]
0
0
0
0
0
0
0
0
0
0
Res. Res. 11
0
0
0
0
0
0
0
0
0
0
Res. Res. 10
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res.
Table 116. RTC register map and reset values (continued)
8
0
0
0
0
0
0
0
0
0
0
SS[14:0]
SS[14:0]
0
0
0
0
0
0
0
0
0
0
Res. Res. 6
SUBFS[14:0]
0
0
0
0
0
0
0
0
0
0
0
Res. 5
DT[1:0]
ST[2:0]
ST[2:0]
ST[2:0]
0
0
0
0
0
0
0
0
0
0
0
0
TAMP2TRG 4
KEY
0
0
0
0
0
0
0
0
0
0
0
0
TAMP2E
CALM[8:0]
3
0
0
0
0
0
0
0
0
0
0
0
0
TAMPIE 2
0
0
0
0
0
0
0
0
0
0
0
0
TAMP1TRG 1
SU[3:0]
SU[3:0]
SU[3:0]
DU[3:0]
0
0
0
0
0
0
0
0
0
0
0
0
TAMP1E
RM0364
0
RM0364 Real-time clock (RTC)
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
RTC_ALARM_TYPE
TSINSEL[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.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_ OR
0x4C
Reset value 0 0 0
RTC_BKP0R BKP[31: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
27.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 27.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.
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 I2C is clocked by an independent clock source which allows the I2C to operate
independently from the PCLK frequency.
For I2C I/Os supporting 20 mA output current drive for Fast-mode Plus operation, the driving
capability is enabled through control bits in the system configuration controller (SYSCFG).
Refer to Section 27.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 121: 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 334. 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 335. 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 27.4.10: 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 341. 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 342. 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 344. 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 345. 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 129: 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 915 section, the TIMEOUT flag is set in the I2C_ISR register.
Refer to Table 130: Examples of TIMEOUTB settings for various I2CCLK frequencies
Caution: Changing the TIMEOUTB configuration is not allowed when the TEXTEN bit is set.
Figure 348. 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 349. 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 350. 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 351. 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 27.3: I2C
implementation.
In addition to I2C master transfer management (refer to Section 27.4.9: 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 27.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 27.3: I2C implementation): the PEC transfer is
managed with the NBYTES counter. Refer to SMBus Slave receiver on page 920 and
SMBus Master receiver on page 924.
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 (HSI): 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 27.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 27.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 27.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
946/1124
27.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
Inter-integrated circuit (I2C) interface
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]
RM0364 Rev 4
[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 134. 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
RM0364
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
28.1 Introduction
The universal synchronous asynchronous receiver transmitter (USART) offers a flexible
means of Full-duplex data exchange with external equipment requiring an industry standard
NRZ asynchronous serial data format. The USART offers a very wide range of baud rates
using a programmable baud rate generator.
It supports synchronous one-way communication and Half-duplex Single-wire
communication, as well as multiprocessor communications. It also supports the LIN (Local
Interconnect Network), Smartcard protocol and IrDA (Infrared Data Association) SIR
ENDEC specifications and Modem operations (CTS/RTS).
High speed data communication is possible by using the DMA (direct memory access) for
multibuffer configuration.
Serial data are transmitted and received through these pins in normal USART mode. The
frames are comprised of:
• An Idle Line prior to transmission or reception
• A start bit
• A data word (7, 8 or 9 bits) least significant bit first
• 0.5, 1, 1.5, 2 stop bits indicating that the frame is complete
• The USART interface uses a baud rate generator
• A status register (USART_ISR)
• Receive and transmit data registers (USART_RDR, USART_TDR)
• A baud rate register (USART_BRR)
• A guard-time register (USART_GTPR) in case of Smartcard mode.
Refer to Section 28.8: USART registers on page 992 for the definitions of each bit.
The following pin is required to interface in synchronous mode and Smartcard mode:
• CK: Clock output. This pin outputs the transmitter data clock for synchronous
transmission corresponding to SPI master mode (no clock pulses on start bit and stop
bit, and a software option to send a clock pulse on the last data bit). In parallel, data
can be received synchronously on RX. This can be used to control peripherals that
have shift registers. The clock phase and polarity are software programmable. In
Smartcard mode, CK output can provide the clock to the smartcard.
The following pins are required in RS232 Hardware flow control mode:
• CTS: Clear To Send blocks the data transmission at the end of the current transfer
when high
• RTS: Request to send indicates that the USART is ready to receive data (when low).
The following pin is required in RS485 Hardware control mode:
• DE: Driver Enable activates the transmission mode of the external transceiver.
Note: DE and RTS share the same pin.
PRDATA PWDATA
Read Write DR (data register)
(CPU or DMA) (CPU or DMA)
USART_GTPR register
GT PSC CK control CK
RTS/ Hardware
DE flow
CTS controller Receiver
clock
Transmit Wakeup Receiver
control unit control
USART
interrupt
control
USART_BRR register
TE Transmitter
rate controller
/USARTDIV or 2/USARTDIV
Transmitter (depending on the
BRR[15:0]
clock oversampling mode)
(Note 1)
Receiver rate
RE controller
fCK
(Note 2) Conventional baud rate generator
MS19821V7
1. For details on coding USARTDIV in the USART_BRR register, refer to Section 28.5.4: USART baud rate
generation.
2. fCK can be fLSE, fHSI, fPCLK, fSYS.
Clock **
Start
Idle frame bit
Clock **
Start
Idle frame bit
Clock **
Start
Idle frame bit
Character transmission
During an USART transmission, data shifts out 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 (see Figure 354).
Every character is preceded by a start bit which is a logic level low for one bit period. The
character is terminated by a configurable number of stop bits.
The following stop bits are supported by USART: 0.5, 1, 1.5 and 2 stop bits.
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 transmission of data. Resetting the TE bit during the
transmission will corrupt the data on the TX pin as the baud rate counters will get frozen.
The current data being transmitted will be lost.
An idle frame will be sent after the TE bit is enabled.
Configurable stop bits
The number of stop bits to be transmitted with every character can be programmed in
Control register 2, bits 13,12.
• 1 stop bit: This is the default value of number of stop bits.
• 2 stop bits: This will be supported by normal USART, Single-wire and Modem modes.
• 1.5 stop bits: To be used in Smartcard mode.
• 0.5 stop bit: To be used when receiving data in Smartcard mode.
An idle frame transmission will include the stop bits.
A break transmission will be 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 356). It is not possible to
transmit long breaks (break of length greater than 9/10/11 low bits).
When no transmission is taking place, a write instruction to the USART_TDR register places
the data in the shift register, the data transmission starts, and the TXE bit is set.
If a frame is transmitted (after the stop bit) and the TXE bit is set, the TC bit goes high. An
interrupt is generated if the TCIE bit is set in the USART_CR1 register.
After writing the last data in the USART_TDR register, it is mandatory to wait for TC=1
before disabling the USART or causing the microcontroller to enter the low-power mode
(see Figure 357: TC/TXE behavior when transmitting).
Break characters
Setting the SBKRQ bit transmits a break character. The break frame length depends on the
M bits (see Figure 355).
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.
In the case the application needs to send the break character following all previously
inserted data, including the ones not yet transmitted, the software should wait for the TXE
flag assertion before setting the SBKRQ bit.
Idle characters
Setting the TE bit drives the USART to send an idle frame before the first data frame.
In the USART, the start bit is detected when a specific sequence of samples is recognized.
This sequence is: 1 1 1 0 X 0 X 0X 0X 0 X 0X 0.
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, interrupt generated if RXNEIE=1) 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 (RXNE flag set, interrupt generated if RXNEIE=1) but the NF 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 conditions a. or b. 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 shifts in least significant bit first (default configuration)
through the RX pin. In this mode, the USART_RDR register consists of a buffer (RDR)
between the internal bus and the receive shift register.
Character reception procedure
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 multibuffer communication.
6. Set the RE bit USART_CR1. This enables the receiver which begins searching for a
start bit.
When a character is received:
• The RXNE bit is set to indicate that the content of the shift register is transferred to the
RDR. In other words, data has been received and can be read (as well as its
associated error flags).
• An interrupt is generated if the RXNEIE bit is set.
• The error flags can be set if a frame error, noise or an overrun error has been detected
during reception. PE flag can also be set with RXNE.
• In multibuffer, RXNE is set after every byte received and is cleared by the DMA read of
the Receive data Register.
• In single buffer mode, clearing the RXNE bit is performed by a software read to the
USART_RDR register. The RXNE flag can also be cleared by writing 1 to the RXFRQ
in the USART_RQR register. The RXNE bit must be cleared before the end of the
reception of the next character to avoid an overrun error.
Break character
When a break character is received, the USART handles it as a framing error.
Idle character
When an idle frame is detected, there is the same procedure as for a received data
character plus an interrupt if the IDLEIE bit is set.
Overrun error
An overrun error occurs when a character is received when 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 RXNE flag is set after every byte received. 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 will not be lost. The previous data is available when a read to
USART_RDR is performed.
• The shift register will be overwritten. After that point, any data received during overrun
is lost.
• An interrupt is generated if either the RXNEIE bit is set or EIE bit is set.
• The ORE bit is reset by setting the ORECF bit in the ICR register.
Note: The ORE bit, when set, indicates that at least 1 data has been lost. 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, then it means that the last valid data has already been read and thus there is
nothing to be read in the RDR. This case can occur when the last valid data is read in the
RDR at the same time as the new (and lost) data is received.
The oversampling method can be selected by programming the OVER8 bit in the
USART_CR1 register and can be either 16 or 8 times the baud rate clock (Figure 359 and
Figure 360).
Depending on the application:
• Select oversampling by 8 (OVER8=1) to achieve higher speed (up to fCK/8). In this
case the maximum receiver tolerance to clock deviation is reduced (refer to
Section 28.5.5: Tolerance of the USART receiver to clock deviation on page 966)
• 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 fCK/16 where
fCK is the clock source frequency.
Programming the ONEBIT bit in the USART_CR3 register selects the method used to
evaluate the logic level. There are two options:
• The majority vote of the three samples in the center of the received bit. In this case,
when the 3 samples used for the majority vote are not equal, the NF bit is set
• A single sample in the center of the received bit
Depending on the application:
– select the three samples’ majority vote method (ONEBIT=0) when operating in a
noisy environment and reject the data when a noise is detected (refer to
Figure 136) because this indicates that a glitch occurred during the sampling.
– select the single sample method (ONEBIT=1) when the line is noise-free to
increase the receiver’s tolerance to clock deviations (see Section 28.5.5:
Tolerance of the USART receiver to clock deviation on page 966). In this case the
NF bit will never be set.
When noise is detected in a frame:
• The NF bit is set at the rising edge of the RXNE bit.
• The invalid data is transferred from the Shift register to the USART_RDR register.
• No interrupt is generated in case of single byte communication. However this bit rises
at the same time as the RXNE bit which itself generates an interrupt. In case of
multibuffer communication an interrupt will be issued if the EIE bit is set in the
USART_CR3 register.
The NF bit is reset by setting NFCF bit in ICR register.
Note: Oversampling by 8 is not available in LIN, Smartcard and IrDA modes. In those modes, the
OVER8 bit is forced to ‘0’ by hardware.
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.
• No interrupt is generated in case of single byte communication. However this bit rises
at the same time as the RXNE bit which itself generates an interrupt. In case of
multibuffer communication an interrupt will be 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.
Equation 1: Baud rate for standard USART (SPI mode included) (OVER8 = 0 or 1)
In case of oversampling by 16, the equation is:
f CK
Tx/Rx baud = --------------------------------
USARTDIV
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 or 8, USARTDIV must be greater than or equal to 16d.
Example 1
To obtain 9600 baud with fCK = 8 MHz.
• In case of oversampling by 16:
USARTDIV = 8 000 000/9600
BRR = USARTDIV = 833d = 0341h
• In case of oversampling by 8:
USARTDIV = 2 * 8 000 000/9600
USARTDIV = 1666,66 (1667d = 683h)
BRR[3:0] = 3h << 1 = 1h
BRR = 0x681
Example 2
To obtain 921.6 Kbaud with fCK = 48 MHz.
• In case of oversampling by 16:
USARTDIV = 48 000 000/921 600
BRR = USARTDIV = 52d = 34h
• In case of oversampling by 8:
USARTDIV = 2 * 48 000 000/921 600
USARTDIV = 104 (104d = 68h)
BRR[3:0] = USARTDIV[3:0] >> 1 = 8h >> 1 = 4h
BRR = 0x64
Table 137. Error calculation for programmed baud rates at fCK = 72MHz in both cases of
oversampling by 16 or by 8(1)
Baud rate Oversampling by 16 (OVER8 = 0) Oversampling by 8 (OVER8 = 1)
% Error =
(Calculated -
S.No Desired Actual BRR Actual BRR % Error
Desired)B.Rate /
Desired B.Rate
where
DWU is the error due to sampling point deviation when the wakeup from Stop mode is
used.
when M[1:0] = 01:
t WUUSART
DWU = --------------------------
-
11 × Tbit
Table 138. 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 139. 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 138 and Table 139 may slightly differ in the special case when
the received frames contain some Idle frames of exactly 10-bit durations when M bits = 00
(11-bit durations when M bits =01 or 9- bit durations when M bits = 10).
start bit (BRs), then at the end of bit 6 (based on the measurement done from falling
edge to falling edge: BR6). Bit 0 to bit 6 are sampled at BRs while further bits of the
character are sampled at BR6.
• Mode 3: A 0x55 character frame. In this case, the baud rate is updated first at the end
of the start bit (BRs), then at the end of bit 0 (based on the measurement done from
falling edge to falling edge: BR0), and finally at the end of bit 6 (BR6). Bit 0 is sampled
at BRs, bit 1 to bit 6 are sampled at BR0, and further bits of the character are sampled
at BR6.
In parallel, another check is performed for each intermediate transition of RX line. An
error is generated if the transitions on RX are not sufficiently synchronized with the
receiver (the receiver being based on the baud rate calculated on bit 0).
Prior to activating auto baud rate detection, the USART_BRR register must be initialized by
writing a non-zero baud rate value.
The automatic baud rate detection is activated by setting the ABREN bit in the USART_CR2
register. The USART will then wait for the first character on the RX line. The auto baud rate
operation completion is indicated by the setting of the ABRF flag in the USART_ISR
register. If the line is noisy, the correct baud rate detection cannot be guaranteed. In this
case the BRR value may be corrupted and the ABRE error flag will be set. This also
happens if the communication speed is not compatible with the automatic baud rate
detection range (bit duration not between 16 and 65536 clock periods (oversampling by 16)
and not between 8 and 65536 clock periods (oversampling by 8)).
The RXNE interrupt will signal the end of the operation.
At any later time, the auto baud rate detection may be relaunched by resetting the ABRF
flag (by writing a 0).
Note: If the USART is disabled (UE=0) during an auto baud rate operation, the BRR value may be
corrupted.
In mute mode:
• None of the reception status bits can be set.
• All the receive interrupts are inhibited.
• The RWU bit in USART_ISR register is set to 1. RWU can be controlled automatically
by hardware or by software, through the MMRQ bit in the USART_RQR register, under
certain conditions.
The USART can enter or exit from mute mode using one of two methods, depending on the
WAKE bit in the USART_CR1 register:
• Idle Line detection if the WAKE bit is reset,
• Address Mark detection if the WAKE bit is set.
RXNE RXNE
MSv31154V1
Note: If the MMRQ is set while the IDLE character has already elapsed, mute mode will not be
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).
The USART enters mute mode when an address character is received which does not
match its programmed address. In this case, the RWU bit is set by hardware. The RXNE
flag is not set for this address byte and no interrupt or DMA request is issued when the
USART enters mute mode.
The USART also enters mute mode when the MMRQ bit is written to 1. The RWU bit is also
automatically set in this case.
The USART exits from mute mode when an address character is received which matches
the programmed address. Then the RWU bit is cleared and subsequent bytes are received
normally. The RXNE bit is set for the address character since the RWU bit has been
cleared.
An example of mute mode behavior using address mark detection is given in Figure 362.
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 duration) 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 bits values) and the parity bit.
As an example, if data=00110101, and 4 bits are set, then the parity bit will be 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 bits values) and the parity bit.
As an example, if data=00110101 and 4 bits set, then the parity bit will be 1 if odd parity is
selected (PS bit in USART_CR1 = 1).
LIN transmission
The procedure explained in Section 28.5.2: USART transmitter 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 bits 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 2 bits of value ‘1’ are sent to allow 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 will be 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 363: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 973.
Examples of break frames are given on Figure 364: Break detection in LIN mode vs.
Framing error detection on page 974.
Figure 363. 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 364. Break detection in LIN mode vs. Framing error detection
RXNE /FE
LBDF
RXNE /FE
LBDF
MSv31157V1
Note: The CK pin works in conjunction with the TX pin. Thus, the clock is provided only if the
transmitter is enabled (TE=1) and data is being transmitted (the data register USART_TDR
written). This means that it is not possible to receive synchronous data without transmitting
data.
The LBCL, CPOL and CPHA bits have to be selected when the USART is disabled (UE=0)
to ensure that the clock pulses function correctly.
RX Data out
TX Data in
Synchronous device
USART
(e.g. slave SPI)
CK Clock
MSv31158V2
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
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
CK
(capture strobe on CK rising
edge in this example)
tSETUP tHOLD
Note: The function of CK is different in Smartcard mode. Refer to Section 28.5.13: USART
Smartcard mode for more details.
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 bit field. 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 can 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 guard-
time). 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 bits
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/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 bit field, 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 de-assertion 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: A break character is 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 370 details 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 370. Parity error detection using the 1.5 stop bits
Sampling at Sampling at
8th, 9th, 10th 8th, 9th, 10th
Sampling at Sampling at
8th, 9th, 10th 8th, 9th, 10th
MSv31163V1
The USART can provide a clock to the smartcard through the CK output. In Smartcard
mode, CK is not associated to the communication but is simply derived from the internal
peripheral input clock through a 5-bit prescaler. The division ratio is configured in the
prescaler register USART_GTPR. CK frequency can be programmed from fCK/2 to fCK/62,
where fCK is the peripheral input clock.
Method 2
The USART is programmed in 9-bit/no-parity mode, no bit inversion. In this mode it receives
any of the two TS patterns as:
(H) LHHL LLL LLH = 0x103 -> inverse convention to be chosen
(H) LHHL HHH LLH = 0x13B -> direct convention to be chosen
The software checks the received character against these two patterns and, if any of them
match, then programs the USART accordingly for the next character reception.
If none of the two is recognized, a card reset may be generated in order to restart the
negotiation.
• The IrDA specification requires the acceptance of pulses greater than 1.41 µs. The
acceptable pulse width is programmable. Glitch detection logic on the receiver end
filters out pulses of width less than 2 PSC periods (PSC is the prescaler value
programmed in the USART_GTPR). Pulses of width less than 1 PSC period are always
rejected, but those of width greater than one and less than two periods may be
accepted or rejected, those greater than 2 periods will be accepted as a pulse. The
IrDA encoder/decoder doesn’t work when PSC=0.
• The receiver can communicate with a low-power transmitter.
• In IrDA mode, the STOP bits in the USART_CR2 register must be configured to “1 stop
bit”.
SIREN
TX
OR USART_TX
SIR
Transmit IrDA_OUT
Encoder
USART
SIR
RX
Receive IrDA_IN
DEcoder
USART_RX
MSv31164V2
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
communication is complete. This is required to avoid corrupting the last transmission before
disabling the USART or entering Stop mode. Software must wait until TC=1. The TC flag
remains cleared during all data transfers and it is set by hardware at the end of transmission
of the last frame.
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
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
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 respectively to 1 (in the USART_CR3 register).
RTS
MSv31168V2
CTS CTS
CTS
Note: For correct behavior, CTS 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.
USART is not requesting it. The LSE clock is not OFF but there is a clock gating to
avoid useless consumption.
The MCU wakeup from Stop mode can be done using the standard RXNE interrupt. In this
case, the RXNEIE bit must be set before entering Stop mode.
Alternatively, a specific interrupt may be selected through the WUS bit fields.
In order to be able to wake up the MCU from Stop mode, the UESM bit in the USART_CR1
control register must be set prior to entering Stop mode.
When the wakeup event is detected, the WUF flag is set by hardware and a wakeup
interrupt is generated if the WUFIE bit is set.
Note: Before entering Stop mode, the user must ensure that the USART is not performing a
transfer. BUSY flag cannot ensure that Stop mode is never entered during a running
reception.
The WUF flag is set when a wakeup event is detected, independently of whether the MCU is
in Stop or in an active mode.
When entering Stop mode just after having initialized and enabled the receiver, the REACK
bit must be checked to ensure the USART is actually enabled.
When DMA is used for reception, it must be disabled before entering Stop mode and re-
enabled upon exit from Stop mode.
The wakeup from Stop mode feature is not available for all modes. For example it doesn’t
work in SPI mode because the SPI operates in master mode only.
If we consider an ideal case where the parameters DTRA, DQUANT, DREC and DTCL are
at 0%, the DWU max is 4.86 %. In reality, we need to consider at least the HSI inaccuracy.
Let us consider HSI inaccuracy = 1 %, tWUUSART = 3.125 μs (in case of wakeup from stop
mode, with the main regulator in Run mode).
DWU max = 4.86 % - 1 % = 3.86 %
Tbit min = 3.125 μs / (9 ₓ 3.86 %) = 9 μs
In these conditions, the maximum baud rate allowing to wakeup correctly from Stop mode is
1/9 μs = 111 Kbaud.
Sleep No effect. USART interrupt causes the device to exit Sleep mode.
The USART is able to wake up the MCU from Stop mode when the UESM
bit is set and the USART clock is set to HSI or LSE.
Stop
The MCU wakeup from Stop mode can be done using either a standard
RXNE or a WUF interrupt.
The USART is powered down and must be reinitialized when the device
Standby
has exited from Standby mode.
The USART interrupt events are connected to the same interrupt vector (see Figure 378).
• During transmission: Transmission Complete, Clear to Send, Transmit data Register
empty or Framing error (in Smartcard mode) interrupt.
• During reception: Idle Line detection, Overrun error, Receive data register not empty,
Parity error, LIN break detection, Noise Flag, Framing Error, Character match, etc.
These events generate an interrupt if the corresponding Enable Control Bit is set.
MSv19820V1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. M1 EOBIE RTOIE DEAT[4:0] DEDT[4: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
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:4] ADD[3: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
SWAP LINEN STOP[1:0] CLKEN CPOL CPHA LBCL Res. LBDIE LBDL ADDM7 Res. Res. Res. Res.
rw rw rw rw rw rw rw rw rw rw rw
Note: The 3 bits (CPOL, CPHA, LBCL) 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
SCARC SCARC SCARC
Res. Res. Res. Res. Res. Res. Res. Res. Res. WUFIE WUS1 WUS0 Res.
NT2 NT1 NT0
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OVRDI ONEBI
DEP DEM DDRE CTSIE CTSE RTSE DMAT DMAR SCEN NACK HDSEL IRLP IREN EIE
S T
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 21:20 WUS[1:0]: Wakeup from Stop mode interrupt flag selection
This bit-field specify the event which activates the WUF (wakeup from Stop 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.
This bit field can only be written when the USART is disabled (UE=0).
Note: If the USART does not support the wakeup from Stop feature, this bit is reserved and
must be kept at reset value.
Bits 19:17 SCARCNT[2:0]: Smartcard auto-retry count
This bit-field specifies the number of retries in transmit and receive, 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 and PE bits set).
This bit field must be programmed only when the USART is disabled (UE=0).
When the USART is enabled (UE=1), this bit field 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. Please refer to Section 28.4: USART implementation on page 950.
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. Please refer to Section 28.4: USART implementation on page 950.
Bit 14 DEM: Driver enable mode
This bit allows 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 28.4: USART implementation on page 950.
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 will be 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 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
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. Please refer to Section 28.4: USART implementation on
page 950.
31 30 29 28 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
Res. Res. Res. Res. Res. Res. Res. Res. Res. REACK TEACK WUF RWU SBKF CMF BUSY
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 Res. EOBF RTOF CTS CTSIF LBDF TXE TC RXNE IDLE ORE NF FE PE
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.
rc_w1 rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. EOBCF RTOCF Res. CTSCF LBDCF Res. TCCF Res. IDLECF ORECF NCF FECF PECF
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
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
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
RXNEIE
OVER8
DEDT4
DEDT3
DEDT2
DEDT1
DEDT0
IDLEIE
DEAT4
DEAT3
DEAT2
DEAT1
DEAT0
EOBIE
RTOIE
WAKE
TXEIE
UESM
CMIE
MME
PEIE
TCIE
PCE
Res.
Res.
Res.
M1
M0
RE
UE
PS
TE
USART_CR1
0x00
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
MSBFIRST
ABRMOD1
ABRMOD0
DATAINV
ADDM7
RTOEN
ABREN
CLKEN
RXINV
TXINV
LINEN
SWAP
LBDIE
CPHA
CPOL
LBCL
LBDL
STOP
Res.
Res.
Res.
Res.
Res.
USART_CR2 ADD[7:4] ADD[3:0]
[1: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
SCARCNT2:0]
OVRDIS
ONEBIT
HDSEL
WUFIE
CTSIE
DMAR
DDRE
SCEN
NACK
DMAT
CTSE
RTSE
IREN
WUS
IRLP
DEM
DEP
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EIE
USART_CR3
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
USART_BRR BRR[15:0]
0x0C
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.
Reset value 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
MMRQ
SBKRQ
ABRRQ
RXFRQ
TXFRQ
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.
USART_RQR
0x18
Reset value 0 0 0 0 0
1014/1124
Register
Reset value
Reset value
Reset value
Reset value
USART_ISR
USART_ICR
USART_TDR
USART_RDR
Res. Res. Res. Res. 31
Res. Res. Res. Res. 30
Res. Res. Res. Res. 29
Res. Res. Res. Res. 28
Res. Res. Res. Res. 27
Res. Res. Res. Res. 26
Res. Res. Res. Res. 25
Res. Res. Res. Res. 24
Res. Res. Res. Res. 23
0
RM0364 Rev 4
Res. Res. CMCF CMF 17
0
0
0
LBDCF LBDF 8
Table 143. USART register map and reset values (continued)
Res. TXE 7
0
1
TCCF TC 6
0
Res. RXNE 5
0
0
IDLECF IDLE 4
0
0
X X X X X X
X X X X X X
TDR[8:0]
RDR[8:0]
ORECF ORE 3
0
0
X
X
NCF NF 2
0
0
X
X
FECF FE 1
0
0
X
X
PECF PE 0
RM0364
RM0364 Serial peripheral interface (SPI)
29.1 Introduction
The SPI interface can be used to communicate with external devices using the SPI protocol.
SPI 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.
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 29.4.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 29.4.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 29.4.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 29.4.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 29.4.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 386, 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 387. 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 29.4.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 29.4.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 388 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
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 389 on page 1031 through
Figure 392 on page 1034:
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.
29.4.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 394). 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 394: 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.
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 Res. Res. TXE RXNE
RR
r r r r r r r r rc_w0 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
0x0C
Offset
29.6.8
RM0364
SPIx_SR
SPIx_DR
SPIx_CR2
SPIx_CR1
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
SPIx_CRCPR
SPIx_TXCRCR
SPIx_RXCRCR
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
SPI register map
RM0364 Rev 4
Res. Res. Res. Res. Res. Res. Res. 17
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
FRXTH CRCNEXT 12
FTLVL[1:0]
0
0
0
0
0
0
0
Table 146. SPI register map and reset values
CRCL 11
0
0
0
0
0
1
0
FRLVL[1:0]
RXONLY 10
0
0
0
0
0
1
0
SSM 9
DS[3:0]
FRE SSI 8
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TXCRC[15:0]
RXCRC[15:0]
0
0
0
0
0
0
0
MODF ERRIE 5
0
0
0
0
0
0
0
CRCERR FRF 4
BR [2:0]
0
0
0
0
0
0
0 Res. NSSP 3
0
1
0
0
0
1049/1124
Serial peripheral interface (SPI)
1049
Controller area network (bxCAN) RM0364
30.1 Introduction
The Basic Extended CAN peripheral, named bxCAN, interfaces the CAN network. It
supports the CAN protocols version 2.0A and B. It has been designed to manage a high
number of incoming messages efficiently with a minimum CPU load. It also meets the
priority requirements for transmit messages.
For safety-critical applications, the CAN controller provides all hardware functions for
supporting the CAN Time Triggered Communication option.
Furthermore, application tasks require more CPU time, therefore real-time constraints
caused by message reception have to be reduced.
• A receive FIFO scheme allows the CPU to be dedicated to application tasks for a long
time period without losing messages.
The standard HLP (Higher Layer Protocol) based on standard CAN drivers requires an
efficient interface to the CAN controller.
CAN node 2
CAN node n
MCU
Application
CAN
Controller
CAN CAN
Rx Tx
CAN
Transceiver
CAN CAN
High Low
CAN Bus
MS30392V1
30.3.3 Tx mailboxes
Three transmit mailboxes are provided to the software for setting up messages. The
transmission Scheduler decides which mailbox has to be transmitted first.
Receive FIFO
Two receive FIFOs are used by hardware to store the incoming messages. Three complete
messages can be stored in each FIFO. The FIFOs are managed completely by hardware.
Rx FIFO 0 Status
Rx FIFO 1 Status
Con trol /Status /C on figura tio n
Transmission
Interrup t Enabl e scheduler
C A N 2.0 B Active Cor e
Error Status
Accep tance Filters
Bit Tim ing 13
.. .. 12
Mem ory 2 3
Filter Master 1
Access Filter 0
Filter Mod e C ontroller
Master Fil ters S lav e Filters
Fi lter Sc ale (0 to 27) (0 to 27)
Fi lter Ac tivation
MSv46408V1
To initialize the registers associated with the CAN filter banks (mode, scale, FIFO
assignment, activation and filter values), software has to set the FINIT bit (CAN_FMR). Filter
initialization also can be done outside the initialization mode.
Note: When FINIT=1, CAN reception is deactivated.
The filter values also can be modified by deactivating the associated filter activation bits (in
the CAN_FA1R register).
If a filter bank is not used, it is recommended to leave it non active (leave the corresponding
FACT bit cleared).
Reset
Sleep
SLAK = 1
INAK = 0
Q SL
R EE
.IN SL P.
IN
C
N EE R
.SY K P. Q
.A
EP . AC IN
R C
K
SLE EP Q
.A
E
SL C
K
Normal INRQ.ACK
Initialization
SLAK = 0 SLAK = 0
INAK = 0
INAK = 1
INRQ.SYNC.SLEEP
ai15902
1. ACK = The wait state during which hardware confirms a request by setting the INAK or SLAK bits in the
CAN_MSR register
2. SYNC = The state during which bxCAN waits until the CAN bus is idle, meaning 11 consecutive recessive
bits have been monitored on CANRX
bxCAN
Tx Rx
=1
CANTX CANRX
MS30393V2
bxCAN
Tx Rx
CANTX CANRX
MS30394V2
This mode is provided for self-test functions. To be independent of external events, the CAN
Core ignores acknowledge errors (no dominant bit sampled in the acknowledge slot of a
data / remote frame) in Loop Back Mode. In this mode, the bxCAN performs an internal
feedback from its Tx output to its Rx input. The actual value of the CANRX input pin is
disregarded by the bxCAN. The transmitted messages can be monitored on the CANTX pin.
bxCAN
Tx Rx
=1
CANTX CANRX
MS30395V2
Transmit priority
By identifier
When more than one transmit mailbox is pending, the transmission order is given by the
identifier of the message stored in the mailbox. The message with the lowest identifier value
has the highest priority according to the arbitration of the CAN protocol. If the identifier
values are equal, the lower mailbox number is scheduled first.
By transmit request order
The transmit mailboxes can be configured as a transmit FIFO by setting the TXFP bit in the
CAN_MCR register. In this mode the priority order is given by the transmit request order.
This mode is very useful for segmented transmission.
Abort
A transmission request can be aborted by the user setting the ABRQ bit in the CAN_TSR
register. In pending or scheduled state, the mailbox is aborted immediately. An abort
request while the mailbox is in transmit state can have two results. If the mailbox is
transmitted successfully the mailbox becomes empty with the TXOK bit set in the
CAN_TSR register. If the transmission fails, the mailbox becomes scheduled, the
transmission is aborted and becomes empty with TXOK cleared. In all cases the mailbox
becomes empty again at least at the end of the current transmission.
EMPTY
RQCP=X
TXOK=X
TXRQ=1
TME = 1
PENDING
RQCP=0 Mailbox has
TXOK=0 highest priority
ABRQ=1
TME = 0
EMPTY
Transmit succeeded
RQCP=1
TXOK=1
TME = 1
MS30396V2
Valid message
A received message is considered as valid when it has been received correctly according to
the CAN protocol (no error until the last but one bit of the EOF field) and It passed through
the identifier filtering successfully, see Section 30.7.4: Identifier filtering.
EMPTY
FMP=0x00 Valid Message
FOVR=0 Received
PENDING_1
Release FMP=0x01
Mailbox FOVR=0
PENDING_2
FMP=0x10
FOVR=0
PENDING_3
FMP=0x11 Valid Message
FOVR=0 Received
OVERRUN
Release FMP=0x11
Mailbox FOVR=1
RFOM=1
Valid Message
Received
MS30397V2
FIFO management
Starting from the empty state, the first valid message received is stored in the FIFO which
becomes pending_1. The hardware signals the event setting the FMP[1:0] bits in the
CAN_RFR register to the value 01b. The message is available in the FIFO output mailbox.
The software reads out the mailbox content and releases it by setting the RFOM bit in the
CAN_RFR register. The FIFO becomes empty again. If a new valid message has been
received in the meantime, the FIFO stays in pending_1 state and the new message is
available in the output mailbox.
If the application does not release the mailbox, the next valid message is stored in the FIFO
which enters pending_2 state (FMP[1:0] = 10b). The storage process is repeated for the
next valid message putting the FIFO into pending_3 state (FMP[1:0] = 11b). At this point,
the software must release the output mailbox by setting the RFOM bit, so that a mailbox is
free to store the next valid message. Otherwise the next valid message received causes a
loss of message.
Refer also to Section 30.7.5: Message storage
Overrun
Once the FIFO is in pending_3 state (i.e. the three mailboxes are full) the next valid
message reception leads to an overrun and a message is lost. The hardware signals the
overrun condition by setting the FOVR bit in the CAN_RFR register. Which message is lost
depends on the configuration of the FIFO:
• If the FIFO lock function is disabled (RFLM bit in the CAN_MCR register cleared) the
last message stored in the FIFO is overwritten by the new incoming message. In this
case the latest messages are always available to the application.
• If the FIFO lock function is enabled (RFLM bit in the CAN_MCR register set) the most
recent message is discarded and the software has the three oldest messages in the
FIFO available.
This hardware filtering saves CPU resources which would be otherwise needed to perform
filtering by software. Each filter bank x consists of two 32-bit registers, CAN_FxR0 and
CAN_FxR1.
Scalable width
To optimize and adapt the filters to the application needs, each filter bank can be scaled
independently. Depending on the filter scale a filter bank provides:
• One 32-bit filter for the STDID[10:0], EXTID[17:0], IDE and RTR bits.
• Two 16-bit filters for the STDID[10:0], RTR, IDE and EXTID[17:15] bits.
Refer to Figure 403.
Furthermore, the filters can be configured in mask mode or in identifier list mode.
Mask mode
In mask mode the identifier registers are associated with mask registers specifying which
bits of the identifier are handled as “must match” or as “don’t care”.
ID CAN_FxR2[15:8] CAN_FxR2[7:0]
n+1
Mask CAN_FxR2[31:24] CAN_FxR2[23:16]
ID=Identifier
Filter Bank Mode
MSv30398V4
The index value of the filter number does not take into account the activation state of the
filter banks. In addition, two independent numbering schemes are used, one for each FIFO.
Refer to Figure 404 for an example.
2
1 ID Mask (32-bit) 2 4 ID List (32-bit) 3
3
4 Deactivated 4
3 ID List (16-bit) 5 7
ID Mask (16-bit) 5
6
Deactivated 7 6
5 8 ID Mask (16-bit)
ID List (32-bit) 8 7
8
9 Deactivated 9
6 ID Mask (16-bit) 10 10
10 ID List (16-bit)
11
11 12
9 ID List (32-bit) 11 ID List (32-bit)
12 13
ID=Identifier
MS30399V2
Filter bank
Num Receive FIFO
Identifier 0
0
Identifier 1 Message
Identifier List
Identifier 4 Identifier #4 Match Stored
2
Identifier 5
Identifier & Mask
1
Identifier
Mask 2 Filter number stored in the
FMI
Filter Match Index field
within the CAN_RDTxR
Identifier register
4 3
Mask
No Match
Found
Message Discarded
MS31000V2
The example above shows the filtering principle of the bxCAN. On reception of a message,
the identifier is compared first with the filters configured in identifier list mode. If there is a
match, the message is stored in the associated FIFO and the index of the matching filter is
stored in the Filter Match Index. As shown in the example, the identifier matches with
Identifier #2 thus the message content and FMI 2 is stored in the FIFO.
If there is no match, the incoming identifier is then compared with the filters configured in
mask mode.
If the identifier does not match any of the identifiers configured in the filters, the message is
discarded by hardware without disturbing the software.
Transmit mailbox
The software sets up the message to be transmitted in an empty transmit mailbox. The
status of the transmission is indicated by hardware in the CAN_TSR register.
0 CAN_TIxR
4 CAN_TDTxR
8 CAN_TDLxR
12 CAN_TDHxR
Receive mailbox
When a message has been received, it is available to the software in the FIFO output
mailbox. Once the software has handled the message (e.g. read it) the software must
release the FIFO output mailbox by means of the RFOM bit in the CAN_RFR register to
make the next incoming message available. The filter match index is stored in the MFMI
field of the CAN_RDTxR register. The 16-bit time stamp value is stored in the TIME[15:0]
field of CAN_RDTxR.
0 CAN_RIxR
4 CAN_RDTxR
8 CAN_RDLxR
12 CAN_RDHxR
BUS OFF
ai15903
Bus-Off recovery
The Bus-Off state is reached when TEC is greater than 255, this state is indicated by BOFF
bit in CAN_ESR register. In Bus-Off state, the bxCAN is no longer able to transmit and
receive messages.
Depending on the ABOM bit in the CAN_MCR register, bxCAN recovers from Bus-Off
(become error active again) either automatically or on software request. But in both cases
the bxCAN has to wait at least for the recovery sequence specified in the CAN standard
(128 occurrences of 11 consecutive recessive bits monitored on CANRX).
If ABOM is set, the bxCAN starts the recovering sequence automatically after it has entered
Bus-Off state.
If ABOM is cleared, the software must initiate the recovering sequence by requesting
bxCAN to enter and to leave initialization mode.
Note: In initialization mode, bxCAN does not monitor the CANRX signal, therefore it cannot
complete the recovery sequence. To recover, bxCAN must be in normal mode.
A valid edge is defined as the first transition in a bit time from dominant to recessive bus
level provided the controller itself does not send a recessive bit.
If a valid edge is detected in BS1 instead of SYNC_SEG, BS1 is extended by up to SJW so
that the sample point is delayed.
Conversely, if a valid edge is detected in BS2 instead of SYNC_SEG, BS2 is shortened by
up to SJW so that the transmit point is moved earlier.
As a safeguard against programming errors, the configuration of the Bit Timing Register
(CAN_BTR) is only possible while the device is in Standby mode.
Note: For a detailed description of the CAN bit timing and resynchronization mechanism, refer to
the ISO 11898 standard.
1 x tq tBS1 tBS2
MS31001V2
ACK
SOF
IDE
r0
RTR
Inter-Frame Space
Inter-Frame Space Data Frame (Extended Identifier) or Overload Frame
64 + 8 *N
Arbitration Field Arbitration Field Ctrl Field Data Field CRC Field ACK Field
2
32 32 8 *N 16 7
SRR
IDE
r1
r0
ACK
RTR
Inter-Frame Space
Inter-Frame Space Remote Frame
or Overload Frame
44
Arbitration Field Ctrl Field CRC Field ACK Field
2
32 6 16 7
IDE
r0
ACK
RTR
Notes:
0 <= N <= 8
Data Frame or SOF = Start Of Frame
Any Frame Inter-Frame Space Remote Frame ID = Identifier
Suspend RTR = Remote Transmission Request
Intermission Bus Idle IDE = Identifier Extension Bit
3 Transmission
8 r0 = Reserved Bit
DLC = Data Length Code
CRC = Cyclic Redundancy Code
End of Frame or Error flag: 6 dominant bits if node is error
Error Delimiter or Inter-Frame Space active, else 6 recessive bits.
Overload Delimiter Overload Frame or Error Frame Suspend transmission: applies to error
passive nodes only.
Overload Overload Overload EOF = End of Frame
Flag Echo Delimiter ACK = Acknowledge bit
Ctrl = Control
6 6 8
ai15154b
FMPIE0
FMP0
& FIFO 0
INTERRUPT
FFIE0
CAN_RF0R FULL0
& +
FOVIE0
FOVR0
&
FMPIE1
FMP1
& FIFO 1
INTERRUPT
FFIE1
CAN_RF1R FULL1
& +
FOVIE1
FOVR1
&
ERRIE
EWGIE
EWGF &
EPVIE
CAN_ESR EPVF & &
BOFIE
+
ERRI
BOFF & CAN_MSR STATUS CHANGE
ERROR
LECIE
1 LEC 6 & INTERRUPT
WKUIE
WKUI
&
CAN_MSR
SLKIE
SLAKI
&
MS31002V2
31 30 29 28 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. DBF
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RESET Res. Res. Res. Res. Res. Res. Res. TTCM ABOM AWUM NART RFLM TXFP SLEEP INRQ
rs 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. RX SAMP RXM TXM Res. Res. Res. SLAKI WKUI ERRI SLAK INAK
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LOW2 LOW1 LOW0 TME2 TME1 TME0 CODE[1:0] ABRQ2 Res. Res. Res. TERR2 ALST2 TXOK2 RQCP2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ABRQ1 Res. Res. Res. TERR1 ALST1 TXOK1 RQCP1 ABRQ0 Res. Res. Res. TERR0 ALST0 TXOK0 RQCP0
31 30 29 28 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. RFOM0 FOVR0 FULL0 Res. FMP0[1:0]
rs rc_w1 rc_w1 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. RFOM1 FOVR1 FULL1 Res. FMP1[1:0]
rs rc_w1 rc_w1 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. SLKIE WKUIE
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
REC[7:0] TEC[7:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. LEC[2:0] Res. BOFF EPVF EWGF
rw rw rw r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SILM LBKM Res. Res. Res. Res. SJW[1:0] Res. TS2[2:0] TS1[3:0]
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
This register also implements the TX request control (bit 0) - reset value 0.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
STID[10:0]/EXID[28:18] EXID[17:13]
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
TIME[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. DLC[3:0]
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATA3[7:0] DATA2[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
DATA1[7:0] DATA0[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
DATA7[7:0] DATA6[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
DATA5[7:0] DATA4[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
STID[10:0]/EXID[28:18] EXID[17:13]
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
r r r r r r r r r r r r r r r
CAN receive FIFO mailbox data length control and time stamp register
(CAN_RDTxR) (x = 0..1)
Address offsets: 0x1B4, 0x1C4
Reset value: 0xXXXX XXXX
All RX registers are write protected.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIME[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
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
DATA3[7:0] DATA2[7: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
DATA1[7:0] DATA0[7: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
DATA7[7:0] DATA6[7: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
DATA5[7:0] DATA4[7: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. Res. Res. Res. Res. Res. Res. Res. FINIT
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. FBM13 FBM12 FBM11 FBM10 FBM9 FBM8 FBM7 FBM6 FBM5 FBM4 FBM3 FBM2 FBM1 FBM0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Refer to Figure 403: Filter bank scale configuration - register organization on page 1061.
31 30 29 28 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 FSC13 FSC12 FSC11 FSC10 FSC9 FSC8 FSC7 FSC6 FSC5 FSC4 FSC3 FSC2 FSC1 FSC0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Refer to Figure 403: Filter bank scale configuration - register organization on page 1061.
31 30 29 28 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 FFA13 FFA12 FFA11 FFA10 FFA9 FFA8 FFA7 FFA6 FFA5 FFA4 FFA3 FFA2 FFA1 FFA0
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
FACT1 FACT1 FACT1 FACT1
Res Res FACT9 FACT8 FACT7 FACT6 FACT5 FACT4 FACT3 FACT2 FACT1 FACT0
3 2 1 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
FB31 FB30 FB29 FB28 FB27 FB26 FB25 FB24 FB23 FB22 FB21 FB20 FB19 FB18 FB17 FB16
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
FB15 FB14 FB13 FB12 FB11 FB10 FB9 FB8 FB7 FB6 FB5 FB4 FB3 FB2 FB1 FB0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
In all configurations:
Note: Depending on the scale and mode configuration of the filter the function of each register can
differ. For the filter mapping, functions description and mask registers association, refer to
Section 30.7.4: Identifier filtering on page 1059.
A Mask/Identifier register in mask mode has the same bit mapping as in identifier list
mode.
For the register mapping/addresses of the filter banks refer to Table 149 on page 1090.
0x17F
0x01C
0x00C
0x020-
Offset
30.9.5
1090/1124
-
CAN_IER
CAN_TSR
CAN_BTR
CAN_ESR
CAN_TI0R
CAN_MSR
CAN_MCR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
CAN_RF1R
CAN_RF0R
x
0
0
0
Res. SILM Res. Res. Res. Res. Res. 31
x
0
0
0
Res. LBKM Res. Res. Res. LOW[2:0] Res. Res. 30
x
0
0
Res. Res. Res. Res. Res. Res. Res. 29
x
0
1
Res. Res. Res. Res. Res. Res. Res. 28
x
0
1
Res. Res. Res. Res. Res. TME[2:0] Res. Res. 27
REC[7:0]
x
0
1
Controller area network (bxCAN)
x
0
0
0
Res. Res. Res. Res. Res. Res. 25
bxCAN register map
SJW[1:0] CODE[1:0]
x
0
0
0
Res. Res. Res. Res. Res. Res. 24
STID[10:0]/EXID[28:18]
x
0
0
Res. Res. Res. Res. Res. ABRQ2 Res. Res. 23
x
0
0
Res. Res. Res. Res. Res. Res. Res. 22
x
1
0
Res. Res. Res. Res. Res. Res. Res. 21
TS2[2:0]
x
0
0
Res. Res. Res. Res. Res. Res. Res. 20
x
0
0
0
Res. Res. Res. Res. TERR2 Res. Res. 19
TEC[7:0]
x
0
0
0
Res. Res. Res. Res. ALST2 Res. Res. 18
x
1
0
0
RM0364 Rev 4
Res. SLKIE Res. Res. TXOK2 Res. Res. 17
TS1[3:0]
x
1
0
0
0
1
x
0
0
0
x
Res. Res. Res. Res. Res. Res. Res. Res. Res. 14
x
Res. Res. Res. Res. Res. Res. Res. Res. Res. 13
x
Res. Res. Res. Res. Res. Res. Res. Res. Res. 12
x
0
0
1
EXID[17:0]
x
0
0
1
Table 149. bxCAN register map and reset values
x
0
0
0
0
x
0
0
0
0
x
0
0
0
x
0
0
0
0
x
0
0
0
0
0
0
x
0
0
0
0
0
0
0
BRP[9:0]
x
0
0
0
0
0
0
0
x
0
0
0
0
0
0
x
0
0
0
0
0
0
1
1
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.
TGT
CAN_TDT0R TIME[15:0] DLC[3:0]
0x184
Reset value x x x x x x x x x x x x x x x x - - - - - - - x - - - - x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
TXRQ
RTR
IDE
CAN_TI1R STID[10:0]/EXID[28:18] EXID[17:0]
0x190
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TGT
CAN_TDT1R TIME[15:0] DLC[3:0]
0x194
Reset value x x x x x x x x x x x x x x x x - - - - - - - x - - - - x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
TXRQ
RTR
CAN_TI2R STID[10:0]/EXID[28:18] EXID[17:0] IDE
0x1A0
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TGT
Reset value x x x x x x x x x x x x x x x x - - - - - - - x - - - - x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Res.
RTR
IDE
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.
CAN_RDT0R TIME[15:0] FMI[7:0] DLC[3:0]
0x1B4
Reset value x x x x x x x x x x x x x x x x x x x x x x x x - - - - x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Res.
RTR
IDE
CAN_RI1R STID[10:0]/EXID[28:18] EXID[17:0]
0x1C0
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x -
Res.
Res.
Res.
Res.
CAN_RDT1R TIME[15:0] FMI[7:0] DLC[3:0]
0x1C4
Reset value x x x x x x x x x x x x x x x x x x x x x x x x - - - - x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
0x1D0-
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.
0x1FF
-
FINIT
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.
CAN_FMR
0x200
Reset value 1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CAN_FM1R FBM[13:0]
0x204
Reset value 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.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
-
0x208
-
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CAN_FS1R FSC[13:0]
0x20C
Reset value 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.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x210 -
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.
Res.
Res.
CAN_FFA1R FFA[13:0]
0x214
Reset value 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.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x218 -
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CAN_FA1R FACT[13:0]
0x21C
Reset value 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.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x220 -
0x224-
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.
0x23F
-
CAN_F0R1 FB[31:0]
0x240
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
CAN_F0R2 FB[31:0]
0x244
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
CAN_F1R1 FB[31:0]
0x248
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
CAN_F1R2 FB[31:0]
0x24C
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
. . .
. . .
. . .
. . .
CAN_F27R1 FB[31:0]
0x318
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
CAN_F27R2 FB[31:0]
0x31C
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
31.1 Overview
The STM32F334xx devices are built around a Cortex®-M4 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
STM32F334xx MCUs.
Two interfaces for debug are available:
• Serial wire
• JTAG debug port
Cortex-M4 Data
System
Core interface
JTMS/
SWDIO External private
peripheral bus (PPB)
JTDI
Bridge ETM
JTDO/
TRACESWO SWJ-DP AHB-AP
TRACESWO
NJTRST Internal private NVIC Trace port
peripheral bus (PPB) TRACECK
JTCK/ TPIU
SWCLK
DWT TRACED[3:0]
FPB
DBGMCU
ITM
MS19234V
Note: The debug features embedded in the Cortex-M4 core are a subset of the Arm CoreSight
Design Kit.
The Cortex®-M4 core provides integrated on-chip debug support. It is comprised of:
• SWJ-DP: Serial wire / JTAG debug port
• AHP-AP: AHB access port
• ITM: Instrumentation trace macrocell
• FPB: Flash patch breakpoint
• DWT: Data watchpoint trigger
• TPUI: Trace port unit interface (available on larger packages, where the corresponding
pins are mapped)
It also includes debug features dedicated to the STM32F334xx:
• Flexible debug pinout assignment
• MCU debug box (support for low-power modes, control over peripheral clocks, etc.)
Note: For further information on the debug feature supported by the Cortex®-M4 core, refer to the
Cortex®-M4 with FPU-r0p1 Technical Reference Manual and to the CoreSight Design Kit-
r0p1 TRM (see Section 31.2: Reference Arm documentation).
Figure 412 shows that the asynchronous TRACE output (TRACESWO) is multiplexed with
TDO. This means that the asynchronous trace can only be used with SW-DP, not JTAG-DP.
Note: When the APB bridge write buffer is full, it takes one extra APB cycle when writing the
AFIO_MAPR register. This is because the deactivation of the JTAGSW pins is done in two
cycles to guarantee a clean level on the nTRST and TCK input signals of the core.
• Cycle 1: the JTAGSW input signals to the core are tied to 1 or 0 (to 1 for nTRST, TDI
and TMS, to 0 for TCK)
• Cycle 2: the GPIO controller takes the control signals of the SWJTAG IO pins (like
controls of direction, pull-up/down, Schmitt trigger activation, etc.).
31.4.4 Using serial wire and releasing the unused debug pins as GPIOs
To use the serial wire DP to release some GPIOs, the user software must change the GPIO
(PA15, PB3 and PB4) configuration mode in the GPIO_MODER register. This releases
PA15, PB3 and PB4 which now become available as GPIOs.
When debugging, the host performs the following actions:
• Under system reset, all SWJ pins are assigned (JTAG-DP + SW-DP).
• Under system reset, the debugger host sends the JTAG sequence to switch from the
JTAG-DP to the SW-DP.
• Still under system reset, the debugger sets a breakpoint on vector reset.
• The system reset is released and the Core halts.
• All the debug communications from this point are done using the SW-DP. The other
JTAG pins can then be reassigned as GPIOs by the user software.
Note: For user software designs, note that:
To release the debug pins, remember that they are first configured either in input-pull-up
(nTRST, TMS, TDI) or pull-down (TCK) or output tristate (TDO) for a certain duration after
reset until the instant when the user software releases the pins.
When debug pins (JTAG or SW or TRACE) are mapped, changing the corresponding IO pin
configuration in the IOPORT controller has no effect.
STM32 MCU
NJTRST
JTMS
SW-DP
Selected
Boundary scan
TAP Corte x-M4 TAP
IR is 5-bit wide IR is 4-bit wide
JTDO
ai14981c
DBGMCU_IDCODE
Address: 0xE004 2000
Only 32-bits 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
BYPASS
1111
[1 bit]
IDCODE ID CODE
1110
[32 bits] 0x3BA00477 (Cortex®-M4 r0p1 ID Code)
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)
Refer to the Cortex®-M4 r0p1 TRM for a detailed description of DPACC and APACC
registers.
The packet request is always followed by the turnaround time (default 1 bit) where neither
the host nor target drive the line.
001: FAULT
0..2 ACK 010: WAIT
100: OK
The ACK Response must be followed by a turnaround time only if it is a READ transaction
or if a WAIT or FAULT acknowledge has been received.
The DATA transfer must be followed by a turnaround time only if it is a READ transaction.
Further details of the SW-DP state machine can be found in the Cortex®-M4 r0p1 TRM and
the CoreSight Design Kit r0p1TRM.
Note: Important: these registers are not reset by a system reset. They are only reset by a power-
on reset.
Refer to the Cortex®-M4 r0p1 TRM for further details.
The DWT also provides some means to give some profiling informations. For this, some
counters are accessible to give the number of:
• Clock cycle
• Folded instructions
• Load store unit (LSU) operations
• Sleep cycles
• CPI (clock per instructions)
• Interrupt overhead
Example of configuration
To output a simple value to the TPIU:
• Configure the TPIU and assign TRACE I/Os by configuring the DBGMCU_CR (refer to
Section 31.15.3: Debug MCU configuration register)
• Write 0xC5ACCE55 to the ITM Lock Access Register to unlock the write access to the
ITM registers
• Write 0x00010005 to the ITM Trace Control Register to enable the ITM with Sync
enabled and an ATB ID different from 0x00
• Write 0x1 to the ITM Trace Enable Register to enable the Stimulus Port 0
• Write 0x1 to the ITM Trace Privilege Register to unmask stimulus ports 7:0
• Write the value to output in the Stimulus Port Register 0: this can be done by software
(using a printf function)
DBGMCU_CR
Address: 0xE004 2004
Only 32-bit access supported
POR Reset: 0x0000 0000 (not reset by system reset)
31 30 29 28 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_ DBG_
Res Res Res Res Res Res Res Res Res. Res. Res. Res STAND
STOP SLEEP
BY
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBG_I2C1_SMBUS_TIMEOUT
DBG_CAN_STOP
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DBG_WWDG_STOP
DBG_IWDG_STOP
DBG_TIM7_STOP
DBG_TIM6_STOP
DBG_TIM3_STOP
DBG_TIM2_STOP
DBG_RTC_STOP
Res
Res
Res
Res
Res
Res
Res
Res
Res
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
DBG_HRTIM1_STOP
DBG_TIM17_STOP
DBG_TIM16_STOP
DBG_TIM15_STOP
DBG_TIM1_STOP
Res Res Res Res Res Res Res Res Res Res Res
rw rw rw rw rw
31.16.1 Introduction
The TPIU acts as a bridge between the on-chip trace data from the ITM and the ETM.
The output data stream encapsulates the trace source ID, that is then captured by a trace
port analyzer (TPA).
The core embeds a simple TPIU, especially designed for low-cost debug (consisting of a
special version of the CoreSight TPIU).
No Trace
0 XX Released (1) -
(default state)
Asynchronous Released
1 00 TRACESWO - -
Trace (usable as GPIO)
Synchronous
1 01 TRACECK TRACED[0] - - -
Trace 1 bit
Synchronous
1 10 Released (1) TRACECK TRACED[0] TRACED[1] - -
Trace 2 bit
Synchronous
1 11 TRACECK TRACED[0] TRACED[1] TRACED[2] TRACED[3]
Trace 4 bit
1. When Serial Wire mode is used, it is released. But when JTAG is used, it is assigned to JTDO.
Note: By default, the TRACECLKIN input clock of the TPIU is tied to GND. It is assigned to HCLK
two clock cycles after the bit TRACE_IOEN has been set.
Addr.
31.17
1116/1124
.
IDCODE
APB2_FZ
APB1_FZ
DBGMCU_
DBGMCU_
DBGMCU_
Register
Reset value
Reset value
Reset value
Reset value(1)
DBGMCU_CR
X
Res Res Res 31
Debug support (DBG)
X
Res Res Res 30
X
Res Res Res 29
X
Res Res Res 28
X
Res Res Res 27
X
Res Res Res 26
0
X
Res DBG_CAN_STOP Res 25
DBG register map
0
X X X X
RM0364 Rev 4
Res Res Res 17
X
0
Res DBG_IWDG_STOP Res Res 12
0
X
0
X
0
X
Res Res 7
Res.
X
1. The reset value is product dependent. For more information, refer to Section 31.6.1: MCU device ID code.
Res Res.
0
X
0
0
X
0
X
The device electronic signature is stored in the System memory area of the Flash memory
module, and can be read using the debug 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 STM32F334xx microcontroller.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UID[31:16]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UID[15:0]
r r r r r r r r r r r r r r r r
Bits 31:0 UID[31:0]: X and Y coordinates on the wafer expressed in BCD format
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UID[63:48]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UID[47:32]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UID[95:80]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UID[79:64]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FLASH_SIZE
r r r r r r r r r r r r r r r r
33 Revision history
Index
A CAN_TIxR . . . . . . . . . . . . . . . . . . . . . . . . . . 1079
CAN_TSR . . . . . . . . . . . . . . . . . . . . . . . . . . 1072
ADCx_AWD2CR . . . . . . . . . . . . . . . . . . . . . .305
COMP2_CSR . . . . . . . . . . . . . . . . . . . . . . . . 347
ADCx_AWD3CR . . . . . . . . . . . . . . . . . . . . . .306
COMP4_CSR . . . . . . . . . . . . . . . . . . . . . . . . 348
ADCx_CALFACT . . . . . . . . . . . . . . . . . . . . . .307
COMP6_CSR . . . . . . . . . . . . . . . . . . . . . . . . 350
ADCx_CCR . . . . . . . . . . . . . . . . . . . . . . . . . .310
CRC_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
ADCx_CDR . . . . . . . . . . . . . . . . . . . . . . . . . .313
CRC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
ADCx_CFGR . . . . . . . . . . . . . . . . . . . . . . . . .287
CRC_IDR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
ADCx_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . .284
CRC_INIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
ADCx_CSR . . . . . . . . . . . . . . . . . . . . . . . . . .308
CRC_POL . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
ADCx_DIFSEL . . . . . . . . . . . . . . . . . . . . . . . .306
ADCx_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . .301
ADCx_IER . . . . . . . . . . . . . . . . . . . . . . . . . . .282 D
ADCx_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . .280 DAC_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
ADCx_JDRy . . . . . . . . . . . . . . . . . . . . . . . . . .305 DAC_DHR12L1 . . . . . . . . . . . . . . . . . . . . . . . 336
ADCx_JSQR . . . . . . . . . . . . . . . . . . . . . . . . .302 DAC_DHR12L2 . . . . . . . . . . . . . . . . . . . . . . . 337
ADCx_OFRy . . . . . . . . . . . . . . . . . . . . . . . . .304 DAC_DHR12LD . . . . . . . . . . . . . . . . . . . . . . 338
ADCx_SMPR1 . . . . . . . . . . . . . . . . . . . . . . . .291 DAC_DHR12R1 . . . . . . . . . . . . . . . . . . . . . . 335
ADCx_SMPR2 . . . . . . . . . . . . . . . . . . . . . . . .293 DAC_DHR12R2 . . . . . . . . . . . . . . . . . . . . . . 336
ADCx_SQR1 . . . . . . . . . . . . . . . . . . . . . . . . .296 DAC_DHR12RD . . . . . . . . . . . . . . . . . . . . . . 338
ADCx_SQR2 . . . . . . . . . . . . . . . . . . . . . . . . .297 DAC_DHR8R1 . . . . . . . . . . . . . . . . . . . . . . . 336
ADCx_SQR3 . . . . . . . . . . . . . . . . . . . . . . . . .299 DAC_DHR8R2 . . . . . . . . . . . . . . . . . . . . . . . 337
ADCx_SQR4 . . . . . . . . . . . . . . . . . . . . . . . . .300 DAC_DHR8RD . . . . . . . . . . . . . . . . . . . . . . . 338
ADCx_TR1 . . . . . . . . . . . . . . . . . . . . . . . . . . .293 DAC_DOR1 . . . . . . . . . . . . . . . . . . . . . . . . . . 339
ADCx_TR2 . . . . . . . . . . . . . . . . . . . . . . . . . . .294 DAC_DOR2 . . . . . . . . . . . . . . . . . . . . . . . . . . 339
ADCx_TR3 . . . . . . . . . . . . . . . . . . . . . . . . . . .295 DAC_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
DAC_SWTRIGR . . . . . . . . . . . . . . . . . . . . . . 335
C DBGMCU_APB1_FZ . . . . . . . . . . . . . . . . . . 1113
DBGMCU_APB2_FZ . . . . . . . . . . . . . . . . . . 1114
CAN_BTR . . . . . . . . . . . . . . . . . . . . . . . . . .1078
DBGMCU_CR . . . . . . . . . . . . . . . . . . . . . . . 1112
CAN_ESR . . . . . . . . . . . . . . . . . . . . . . . . . .1077
DBGMCU_IDCODE . . . . . . . . . . . . . . . . . . 1100
CAN_FA1R . . . . . . . . . . . . . . . . . . . . . . . . .1088
DMA_CCRx . . . . . . . . . . . . . . . . . . . . . . . . . . 186
CAN_FFA1R . . . . . . . . . . . . . . . . . . . . . . . .1087
DMA_CMARx . . . . . . . . . . . . . . . . . . . . . . . . 190
CAN_FiRx . . . . . . . . . . . . . . . . . . . . . . . . . .1089
DMA_CNDTRx . . . . . . . . . . . . . . . . . . . . . . . 189
CAN_FM1R . . . . . . . . . . . . . . . . . . . . . . . . .1086
DMA_CPARx . . . . . . . . . . . . . . . . . . . . . . . . . 189
CAN_FMR . . . . . . . . . . . . . . . . . . . . . . . . . .1086
DMA_IFCR . . . . . . . . . . . . . . . . . . . . . . . . . . 185
CAN_FS1R . . . . . . . . . . . . . . . . . . . . . . . . .1087
DMA_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
CAN_IER . . . . . . . . . . . . . . . . . . . . . . . . . . .1076
CAN_MCR . . . . . . . . . . . . . . . . . . . . . . . . . .1069
CAN_MSR . . . . . . . . . . . . . . . . . . . . . . . . . .1071 E
CAN_RDHxR . . . . . . . . . . . . . . . . . . . . . . . .1085 EXTI_EMR . . . . . . . . . . . . . . . . . . . . . . 202, 206
CAN_RDLxR . . . . . . . . . . . . . . . . . . . . . . . .1085 EXTI_FTSR . . . . . . . . . . . . . . . . . . . . . . 203, 207
CAN_RDTxR . . . . . . . . . . . . . . . . . . . . . . . .1084 EXTI_IMR . . . . . . . . . . . . . . . . . . . . . . . 201, 206
CAN_RF0R . . . . . . . . . . . . . . . . . . . . . . . . .1074 EXTI_PR . . . . . . . . . . . . . . . . . . . . . . . . 205, 208
CAN_RF1R . . . . . . . . . . . . . . . . . . . . . . . . .1075 EXTI_RTSR . . . . . . . . . . . . . . . . . . . . . . 202, 206
CAN_RIxR . . . . . . . . . . . . . . . . . . . . . . . . . .1083 EXTI_SWIER . . . . . . . . . . . . . . . . . . . . . 204, 207
CAN_TDHxR . . . . . . . . . . . . . . . . . . . . . . . .1082
CAN_TDLxR . . . . . . . . . . . . . . . . . . . . . . . .1082
CAN_TDTxR . . . . . . . . . . . . . . . . . . . . . . . .1081
F HRTIM_EEFxR2 . . . . . . . . . . . . . . . . . . . . . . 750
HRTIM_FLTINR1 . . . . . . . . . . . . . . . . . . . . . 789
FLASH_ACR . . . . . . . . . . . . . . . . . . . . . . . . . .66
HRTIM_FLTINR2 . . . . . . . . . . . . . . . . . . . . . 791
FLASH_CR . . . . . . . . . . . . . . . . . . . . . . . . . . .68
HRTIM_FLTxR . . . . . . . . . . . . . . . . . . . . . . . 763
FLASH_KEYR . . . . . . . . . . . . . . . . . . . . . . . . .66
HRTIM_ICR . . . . . . . . . . . . . . . . . . . . . . . . . . 768
FLASH_OPTKEYR . . . . . . . . . . . . . . . . . . . . .67
HRTIM_IER . . . . . . . . . . . . . . . . . . . . . . . . . . 769
FLASH_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
HRTIM_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . 767
HRTIM_MCMP1R . . . . . . . . . . . . . . . . . . . . . 724
G HRTIM_MCMP2R . . . . . . . . . . . . . . . . . . . . . 725
GPIOx_AFRH . . . . . . . . . . . . . . . . . . . . . . . . .153 HRTIM_MCMP3R . . . . . . . . . . . . . . . . . . . . . 725
GPIOx_AFRL . . . . . . . . . . . . . . . . . . . . . . . . .153 HRTIM_MCMP4R . . . . . . . . . . . . . . . . . . . . . 726
GPIOx_BRR . . . . . . . . . . . . . . . . . . . . . . . . . .154 HRTIM_MCNTR . . . . . . . . . . . . . . . . . . . . . . 723
GPIOx_BSRR . . . . . . . . . . . . . . . . . . . . . . . .151 HRTIM_MCR . . . . . . . . . . . . . . . . . . . . . . . . . 716
GPIOx_IDR . . . . . . . . . . . . . . . . . . . . . . . . . .150 HRTIM_MDIER . . . . . . . . . . . . . . . . . . . . . . . 721
GPIOx_LCKR . . . . . . . . . . . . . . . . . . . . . . . . .151 HRTIM_MICR . . . . . . . . . . . . . . . . . . . . . . . . 720
GPIOx_MODER . . . . . . . . . . . . . . . . . . . . . . .148 HRTIM_MISR . . . . . . . . . . . . . . . . . . . . . . . . 719
GPIOx_ODR . . . . . . . . . . . . . . . . . . . . . . . . .151 HRTIM_MPER . . . . . . . . . . . . . . . . . . . . . . . . 723
GPIOx_OSPEEDR . . . . . . . . . . . . . . . . . . . . .149 HRTIM_MREP . . . . . . . . . . . . . . . . . . . . . . . . 724
GPIOx_OTYPER . . . . . . . . . . . . . . . . . . . . . .149 HRTIM_ODISR . . . . . . . . . . . . . . . . . . . . . . . 771
GPIOx_PUPDR . . . . . . . . . . . . . . . . . . . . . . .150 HRTIM_ODSR . . . . . . . . . . . . . . . . . . . . . . . . 772
HRTIM_OENR . . . . . . . . . . . . . . . . . . . . . . . . 770
HRTIM_OUTxR . . . . . . . . . . . . . . . . . . . . . . . 760
H HRTIM_PERxR . . . . . . . . . . . . . . . . . . . . . . . 737
HRTIM_ADC1R . . . . . . . . . . . . . . . . . . . . . . .782 HRTIM_REPxR . . . . . . . . . . . . . . . . . . . . . . . 738
HRTIM_ADC2R . . . . . . . . . . . . . . . . . . . . . . .783 HRTIM_RSTAR . . . . . . . . . . . . . . . . . . . . . . . 751
HRTIM_ADC3R . . . . . . . . . . . . . . . . . . . . . . .784 HRTIM_RSTBR . . . . . . . . . . . . . . . . . . . . . . . 753
HRTIM_ADC4R . . . . . . . . . . . . . . . . . . . . . . .786 HRTIM_RSTCR . . . . . . . . . . . . . . . . . . . . . . . 753
HRTIM_BDMADR . . . . . . . . . . . . . . . . . . . . .795 HRTIM_RSTDR . . . . . . . . . . . . . . . . . . . . . . . 753
HRTIM_BDMUPR . . . . . . . . . . . . . . . . . . . . .793 HRTIM_RSTER . . . . . . . . . . . . . . . . . . . . . . . 754
HRTIM_BDTxUPR . . . . . . . . . . . . . . . . . . . . .794 HRTIM_RSTx1R . . . . . . . . . . . . . . . . . . . . . . 746
HRTIM_BMCMPR . . . . . . . . . . . . . . . . . . . . .777 HRTIM_RSTx2R . . . . . . . . . . . . . . . . . . . . . . 747
HRTIM_BMCR . . . . . . . . . . . . . . . . . . . . . . . .773 HRTIM_SETx1R . . . . . . . . . . . . . . . . . . . . . . 744
HRTIM_BMPER . . . . . . . . . . . . . . . . . . . . . . .777 HRTIM_SETx2R . . . . . . . . . . . . . . . . . . . . . . 746
HRTIM_BMTRGR . . . . . . . . . . . . . . . . . . . . .775 HRTIM_TIMxCR . . . . . . . . . . . . . . . . . . . . . . 727
HRTIM_CHPxR . . . . . . . . . . . . . . . . . . . . . . .754 HRTIM_TIMxDIER . . . . . . . . . . . . . . . . . . . . 734
HRTIM_CMP1CxR . . . . . . . . . . . . . . . . . . . . .739 HRTIM_TIMxICR . . . . . . . . . . . . . . . . . . . . . . 733
HRTIM_CMP1xR . . . . . . . . . . . . . . . . . . . . . .738 HRTIM_TIMxISR . . . . . . . . . . . . . . . . . . . . . . 731
HRTIM_CMP2xR . . . . . . . . . . . . . . . . . . . . . .739
HRTIM_CMP3xR . . . . . . . . . . . . . . . . . . . . . .740 I
HRTIM_CMP4xR . . . . . . . . . . . . . . . . . . . . . .740
HRTIM_CNTxR . . . . . . . . . . . . . . . . . .