Stm32f103 Reference Manual
Stm32f103 Reference Manual
Reference manual
STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx
and STM32F107xx advanced ARM-based 32-bit MCUs
Introduction
This reference manual targets application developers. It provides complete information on
how to use the STM32F101xx, STM32F102xx, STM32F103xx and
STM32F105xx/STM32F107xx microcontroller memory and peripherals. The STM32F101xx,
STM32F102xx, STM32F103xx and STM32F105xx/STM32F107xx will be referred to as
STM32F10xxx throughout the document, unless otherwise specified.
The STM32F10xxx is a family of microcontrollers with different memory sizes, packages and
peripherals.
For ordering information, mechanical and electrical device characteristics please refer to the
low-, medium-, high- and XL-density STM32F101xx and STM32F103xx datasheets, to the
low- and medium-density STM32F102xx datasheets and to the
STM32F105xx/STM32F107xx connectivity line datasheet.
For information on programming, erasing and protection of the internal Flash memory
please refer to:
● PM0075, the Flash programming manual for low-, medium- high-density and
connectivity line STM32F10xxx devices
● PM0068, the Flash programming manual for XL-density STM32F10xxx devices.
For information on the ARM Cortex™-M3 core, please refer to the STM32F10xxx Cortex™-
M3 programming manual (PM0056).
Related documents
Available from www.st.com:
■ STM32F101xx, STM32F102xx, STM32F103xx, STM32F105xx/STM32F107xx and
datasheets
■ STM32F10xxx Cortex™-M3 programming manual (PM0056)
■ STM32F10xxx Flash programming manual (PM0075)
■ STM32F10xxx XL-density Flash programming manual (PM0068)
Contents
2 Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.1 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.2 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.3 Peripheral availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
25.4.1 The I2S audio protocol is not available in low- and medium-density
devices. This section concerns only high-density, XL-density and
connectivity line devices. I2S general description 695
25.4.2 Supported audio protocols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696
25.4.3 Clock generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
25.4.4 I2S master mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708
25.4.5 I2S slave mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709
25.4.6 Status flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
25.4.7 Error flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712
25.4.8 I2S interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712
25.4.9 DMA features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713
25.5 SPI and I2S registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
25.5.1 SPI control register 1 (SPI_CR1) (not used in I2S mode) . . . . . . . . . . 714
25.5.2 SPI control register 2 (SPI_CR2) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716
25.5.3 SPI status register (SPI_SR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717
25.5.4 SPI data register (SPI_DR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718
25.5.5 SPI CRC polynomial register (SPI_CRCPR) (not used in I2S
mode) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718
25.5.6 SPI RX CRC register (SPI_RXCRCR) (not used in I2S mode) . . . . . . 719
25.5.7 SPI TX CRC register (SPI_TXCRCR) (not used in I2S mode) . . . . . . 719
25.5.8 SPI_I2S configuration register (SPI_I2SCFGR) . . . . . . . . . . . . . . . . . . 720
25.5.9 SPI_I2S prescaler register (SPI_I2SPR) . . . . . . . . . . . . . . . . . . . . . . . 721
25.5.10 SPI register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722
List of tables
List of figures
Figure 49. DMA block diagram in low-, medium- high- and XL-density devices . . . . . . . . . . . . . . . . 267
Figure 50. DMA1 request mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
Figure 51. DMA2 request mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Figure 52. Advanced-control timer block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Figure 53. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 286
Figure 54. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 286
Figure 55. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Figure 56. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Figure 57. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Figure 58. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Figure 59. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not preloaded) . . . . . 288
Figure 60. Counter timing diagram, update event when ARPE=1
(TIMx_ARR preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Figure 61. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Figure 62. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Figure 63. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Figure 64. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Figure 65. Counter timing diagram, update event when repetition counter
is not used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Figure 66. Counter timing diagram, internal clock divided by 1, TIMx_ARR = 0x6 . . . . . . . . . . . . . . 292
Figure 67. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Figure 68. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 293
Figure 69. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Figure 70. Counter timing diagram, update event with ARPE=1 (counter underflow) . . . . . . . . . . . . 294
Figure 71. Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 294
Figure 72. Update rate examples depending on mode and TIMx_RCR register settings . . . . . . . . . 295
Figure 73. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 296
Figure 74. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Figure 75. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Figure 76. External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Figure 77. Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Figure 78. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 299
Figure 79. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Figure 80. Output stage of capture/compare channel (channel 1 to 3) . . . . . . . . . . . . . . . . . . . . . . . 300
Figure 81. Output stage of capture/compare channel (channel 4). . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Figure 82. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Figure 83. Output compare mode, toggle on OC1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Figure 84. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Figure 85. Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
Figure 86. Complementary output with dead-time insertion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Figure 87. Dead-time waveforms with delay greater than the negative pulse. . . . . . . . . . . . . . . . . . 307
Figure 88. Dead-time waveforms with delay greater than the positive pulse. . . . . . . . . . . . . . . . . . . 308
Figure 89. Output behavior in response to a break.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
Figure 90. Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
Figure 91. 6-step generation, COM example (OSSR=1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Figure 92. Example of one pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
Figure 93. Example of counter operation in encoder interface mode. . . . . . . . . . . . . . . . . . . . . . . . . 316
Figure 94. Example of encoder interface mode with TI1FP1 polarity inverted. . . . . . . . . . . . . . . . . . 316
Figure 95. Example of hall sensor interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Figure 96. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Figure 97. Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Figure 98. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Figure 99. Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Figure 100. General-purpose timer block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
Figure 101. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 353
Figure 102. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 354
Figure 103. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Figure 104. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Figure 105. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Figure 106. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Figure 107. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not preloaded). . . . . 356
Figure 108. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR preloaded). . . . . . . . 357
Figure 109. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Figure 110. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Figure 111. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Figure 112. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Figure 113. Counter timing diagram, Update event when repetition counter
is not used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Figure 114. Counter timing diagram, internal clock divided by 1, TIMx_ARR=0x6 . . . . . . . . . . . . . . . 360
Figure 115. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Figure 116. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 361
Figure 117. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361
Figure 118. Counter timing diagram, Update event with ARPE=1 (counter underflow). . . . . . . . . . . . 362
Figure 119. Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 362
Figure 120. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 363
Figure 121. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Figure 122. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364
Figure 123. External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Figure 124. Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
Figure 125. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 366
Figure 126. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Figure 127. Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 367
Figure 128. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Figure 129. Output compare mode, toggle on OC1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Figure 130. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Figure 131. Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373
Figure 132. Example of one-pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Figure 133. Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Figure 134. Example of counter operation in encoder interface mode . . . . . . . . . . . . . . . . . . . . . . . . 377
Figure 135. Example of encoder interface mode with TI1FP1 polarity inverted . . . . . . . . . . . . . . . . . 378
Figure 136. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Figure 137. Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Figure 138. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Figure 139. Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Figure 140. Master/Slave timer example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Figure 141. Gating timer 2 with OC1REF of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Figure 142. Gating timer 2 with Enable of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Figure 143. Triggering timer 2 with update of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Figure 144. Triggering timer 2 with Enable of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Figure 145. Triggering timer 1 and 2 with timer 1 TI1 input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Figure 146. General-purpose timer block diagram (TIM9 and TIM12) . . . . . . . . . . . . . . . . . . . . . . . . 411
Figure 147. General-purpose timer block diagram (TIM10/11/13/14) . . . . . . . . . . . . . . . . . . . . . . . . 412
Figure 148. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 414
Figure 149. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 414
Figure 348. System time update using the Fine correction method. . . . . . . . . . . . . . . . . . . . . . . . . . . 975
Figure 349. PTP trigger output to TIM2 ITR1 connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 977
Figure 350. PPS output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 978
Figure 351. Descriptor ring and chain structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 979
Figure 352. TxDMA operation in Default mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983
Figure 353. TxDMA operation in OSF mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985
Figure 354. ransmit descriptor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986
Figure 355. Receive DMA operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 992
Figure 356. Rx DMA descriptor structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 994
Figure 357. Interrupt scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000
Figure 358. Ethernet MAC remote wakeup frame filter register (ETH_MACRWUFFR). . . . . . . . . . . 1010
Figure 359. Block diagram of STM32 MCU and Cortex™-M3-level debug support . . . . . . . . . . . . . 1048
Figure 360. SWJ debug port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049
Figure 361. JTAG TAP connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1054
Figure 362. TPIU block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1071
Medium-density STM32F102xx
Medium-density STM32F103xx
Low-density STM32F101xx
Low-density STM32F102xx
Low-density STM32F103xx
STM32F105xx
STM32F107xx
Section 2:
Documentation • • • • • • • • • •
conventions
Section 3: Memory and
bus architecture
• • • • • • • • • •
Section 4: CRC
calculation unit
• • • • • • • • • •
Section 5: Power
control (PWR)
• • • • • • • • • •
Section 6: Backup
registers (BKP)
• • • • • • • • • •
Section 7: Low-,
medium-, high- and XL-
density reset and clock
• • • • • • • •
control (RCC)
Section 8: Connectivity
line devices: reset and • •
clock control (RCC)
Section 9: General-
purpose and alternate-
function I/Os (GPIOs
• • • • • • • • • •
and AFIOs)
Section 10: Interrupts
and events
• • • • • • • • • •
Section 13: Direct
memory access • • • • • • • • • •
controller (DMA)
Medium-density STM32F102xx
Medium-density STM32F103xx
Low-density STM32F101xx
Low-density STM32F102xx
Low-density STM32F103xx
STM32F105xx
STM32F107xx
Section 11: Analog-to-
digital converter (ADC)
• • • • • • • • • •
Section 12: Digital-to-
analog converter (DAC)
• • • •
Section 14: Advanced-
control timers • • • • • •
(TIM1&TIM8)
Section 15: General-
purpose timers (TIM2 to • • • • • • • • • •
TIM5)
Section 16: General-
purpose timers (TIM9 to • (1) • (1)
TIM14)
Section 17: Basic
timers (TIM6&TIM7)
• • • •
Section 18: Real-time
clock (RTC)
• • • • • • • • • •
Section 19:
Independent watchdog • • • • • • • • • •
(IWDG)
Section 20: Window
watchdog (WWDG)
• • • • • • • • • •
Section 21: Flexible
static memory • •
controller (FSMC)
Section 26: Secure
digital input/output • •
interface (SDIO)
Section 23: Universal
serial bus full-speed • • • • •
device interface (USB)
Section 24: Controller
area network (bxCAN)
• • • • •
Medium-density STM32F102xx
Medium-density STM32F103xx
Low-density STM32F101xx
Low-density STM32F102xx
Low-density STM32F103xx
STM32F105xx
STM32F107xx
Section 25: Serial
peripheral interface • • • • • • • • • •
(SPI)
Section 26: Inter-
integrated circuit (I2C) • • • • • • • • • •
interface
Section 27: Universal
synchronous
asynchronous receiver
• • • • • • • • • •
transmitter (USART)
Section 28: USB on-
the-go full-speed • •
(OTG_FS)
Section 29: Ethernet
(ETH): media access
control (MAC) with
•
DMA controller
Section 30: Device
electronic signature
• • • • • • • • • •
Section 31: Debug
support (DBG)
• • • • • • • • • •
The section in this row must be read when using the peripherals in columns
•
marked with “•"
The section in this row can optionally be read when using the peripherals in
◊
columns marked with “◊"
Ethernet (ETH)
USART
Section 2:
Documentation • • • • • • • • • • • • • • • • • • • •
conventions
Section 3: Memory and
bus architecture
• • • • • • • • • • • • • • • • • • • •
Section 4: CRC
calculation unit
Section 5: Power
control (PWR)
• • • • • • • • • • • • • • • • • • • •
Section 6: Backup
registers (BKP)
• ◊
Section 7: Low-,
medium-, high- and XL-
density reset and clock
• • • • • • • • • • • • • • • • • • • •
control (RCC)
Section 8: Connectivity
line devices: reset and • • • • • • • • • • • • • • • • • • • •
clock control (RCC)
Section 9: General-
purpose and alternate-
function I/Os (GPIOs
◊ • • • • • • ◊ • • • • • • • • • • •
and AFIOs)
Section 10: Interrupts
and events
◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊
Ethernet (ETH)
USART
Section 13: Direct
memory access ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊
controller (DMA)
Section 11: Analog-to-
digital converter (ADC)
•
Section 12: Digital-to-
analog converter (DAC)
•
Section 14: Advanced-
control timers ◊ ◊ •
(TIM1&TIM8)
Section 15: General-
purpose timers (TIM2 to ◊ ◊ •
TIM5)
Section 16: General-
purpose timers (TIM9 to •
TIM14)
Section 17: Basic
timers (TIM6&TIM7)
◊ •
Section 18: Real-time
clock (RTC)
• •
Section 19:
Independent watchdog •
(IWDG)
Section 20: Window
watchdog (WWDG)
•
Section 21: Flexible
static memory •
controller (FSMC)
Section 26: Secure
digital input/output •
interface (SDIO)
Ethernet (ETH)
USART
Section 23: Universal
serial bus full-speed •
device interface (USB)
Section 24: Controller
area network (bxCAN)
•
Section 25: Serial
peripheral interface •
(SPI)
Section 26: Inter-
integrated circuit (I2C) •
interface
Section 27: Universal
synchronous
asynchronous receiver
•
transmitter (USART)
Section 28: USB on-
the-go full-speed •
(OTG_FS)
Section 29: Ethernet
(ETH): media access
control (MAC) with
•
DMA controller
Section 30: Device
electronic signature
Section 31: Debug
support (DBG)
◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊ ◊
2 Documentation conventions
2.2 Glossary
● Low-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 16 and 32 Kbytes.
● Medium-density devices are STM32F101xx, STM32F102xx and STM32F103xx
microcontrollers where the Flash memory density ranges between 64 and 128 Kbytes.
● High-density devices are STM32F101xx and STM32F103xx microcontrollers where
the Flash memory density ranges between 256 and 512 Kbytes.
● XL-density devices are STM32F101xx and STM32F103xx microcontrollers where the
Flash memory density ranges between 768 Kbytes and 1 Mbyte.
● Connectivity line devices are STM32F105xx and STM32F107xx microcontrollers.
● Word: data of 32-bit length.
● Half-word: data of 16-bit length.
● Byte: data of 8-bit length.
SRAM
Bus matrix
DMA1 DMA
FSMC
SDIO
Ch.1
AHB system bus Bridge 2
Ch.2
Bridge 1 APB 1
APB2
DMA
Ch.2
ai14800c
SRAM
Bus matrix
DMA1 DMA
Reset & clock
control (RCC)
Ch.1
AHB system bus Bridge 2
Ch.2
DMA
Bridge 1 APB 1
APB2
Ch.7
ADC1 GPIOC DAC SPI3/I2S
ADC2 GPIOD PWR SPI2/I2S
DMA request USART1 GPIOE BKP IWDG
SPI1 EXTI CAN1 WWDG
TIM1 AFIO CAN2 RTC
GPIOA I2C2 TIM7
DMA2 GPIOB I2C1 TIM6
UART5 TIM5
UART4 TIM4
DMA
USART3 TIM3
Ch.1 USART2 TIM2
Ch.2
DMA request
Ch.5
Ethernet MAC
USB OTG FS
ai15810
ICode bus
This bus connects the Instruction bus of the Cortex™-M3 core to the Flash memory
instruction interface. Prefetching is performed on this bus.
DCode bus
This bus connects the DCode bus (literal load and debug access) of the Cortex™-M3 core
to the Flash memory Data interface.
System bus
This bus connects the system bus of the Cortex™-M3 core (peripherals bus) to a BusMatrix
which manages the arbitration between the core and the DMA.
DMA bus
This bus connects the AHB master interface of the DMA to the BusMatrix which manages
the access of CPU DCode and DMA to SRAM, Flash memory and peripherals.
BusMatrix
The BusMatrix manages the access arbitration between the core system bus and the DMA
master bus. The arbitration uses a Round Robin algorithm. In connectivity line devices, the
BusMatrix is composed of five masters (CPU DCode, System bus, Ethernet DMA, DMA1
and DMA2 bus) and three slaves (FLITF, SRAM and AHB2APB bridges). In other devices,
the BusMatrix is composed of four masters (CPU DCode, System bus, DMA1 bus and
DMA2 bus) and four slaves (FLITF, SRAM, FSMC and AHB2APB bridges).
AHB peripherals are connected on system bus through a BusMatrix to allow DMA access.
Note: For further information on the Flash memory interface registers, please refer to the:
● “STM32F10xxx XL-density Flash programming manual” (PM0068) for XL-density
devices
● “STM32F10xxx Flash programming manual” (PM0075) for other devices
Note: 1 These options should be used in accordance with the Flash memory access time. The wait
states represent the ratio of the SYSCLK (system clock) period to the Flash memory access
time:
zero wait state, if 0 < SYSCLK ≤ 24 MHz
one wait state, if 24 MHz < SYSCLK ≤ 48 MHz
two wait states, if 48 MHz < SYSCLK ≤ 72 MHz
2 Half cycle configuration is not available in combination with a prescaler on the AHB. The
system clock (SYSCLK) should be equal to the HCLK clock. This feature can therefore be
used only with a low-frequency clock of 8 MHz or less. It can be generated from the HSI or
the HSE but not from the PLL.
3 The prefetch buffer must be kept on when using a prescaler different from 1 on the AHB
clock.
4 The prefetch buffer must be switched on/off only when SYSCLK is lower than 24 MHz and
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.
5 Using DMA: DMA accesses Flash memory on the DCode bus and has priority over ICode
instructions. The DMA provides one free cycle after each transfer. Some instructions can be
performed together with DMA transfer.
The values on the BOOT pins are latched on the 4th rising edge of SYSCLK after a reset. It
is up to the user to set the BOOT1 and BOOT0 pins after Reset to select the required boot
mode.
The BOOT pins are also re-sampled when exiting from Standby mode. Consequently they
must be kept in the required Boot mode configuration in Standby mode. After this startup
delay has elapsed, the CPU fetches the top-of-stack value from address 0x0000 0000, then
starts code execution from the boot memory starting from 0x0000 0004.
Due to its fixed memory map, the code area starts from address 0x0000 0000 (accessed
through the ICode/DCode buses) while the data area (SRAM) starts from address
0x2000 0000 (accessed through the system bus). The Cortex-M3 CPU always fetches the
reset vector on the ICode bus, which implies to have the boot space available only in the
code area (typically, Flash memory). STM32F10xxx microcontrollers implement a special
mechanism to be able to boot also from SRAM and not only from main Flash memory and
System memory.
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 (0x800 0000).
In other words, the Flash memory contents can be accessed starting from address
0x0000 0000 or 0x800 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 B000 in
connectivity line devices, 0x1FFF F000 in other devices).
● Boot from the embedded SRAM: SRAM is accessible only at address 0x2000 0000.
Note: When booting from SRAM, in the application initialization code, you have to relocate the
vector table in SRAM using the NVIC exception table and offset register.
For XL-density devices, when booting from the main Flash memory, you have an option to
boot from any of two memory banks. By default, boot from Flash memory bank 1 is selected.
You can choose to boot from Flash memory bank 2 by clearing the BFB2 bit in the user
option bytes. When this bit is cleared and the boot pins are in the boot from main Flash
memory configuration, the device boots from system memory, and the boot loader jumps to
execute the user application programmed in Flash memory bank 2. For further details,
please refer to AN2606.
Note: When booting from Bank2, in the applications initialization code, you have to relocate the
vector table to the Bank2 base address. (0x0808 0000) using the NVIC exception table and
offset register.
AHB bus
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
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IDR[7:0]
Reserved
rw rw rw rw rw rw rw rw
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RESET
Reserved
w
Table 10. CRC calculation unit register map and reset values
Offset Register 31-24 23-16 15-8 7 6 5 4 3 2 1 0
CRC_CR RESET
0x08 Reserved
Reset value 0
VDDA domain
(VSSA) VREF-
A/D converter
(from 2.4 V up to VDDA)VREF+ D/A converter
Temp. sensor
(VDD) VDDA Reset block
PLL
(VSS) VSSA
I/O Ring
VSS Core
Standby circuitry Memories
VDD (Wakeup logic, digital
IWDG) peripherals
Voltage Regulator
Backup domain
LSE crystal 32K osc
VBAT
BKP registers
RCC BDCR register
RTC
Note: 1 VDDA and VSSA must be connected to VDD and VSS, respectively.
5.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 pin VSSA.
When available (according to package), VREF- must be tied to VSSA.
VDD/VDDA
POR
40 mV
hysteresis
PDR
Temporization
tRSTTEMPO
Reset
PVD output interrupt can be generated when VDD/VDDA drops below the PVD threshold
and/or when VDD/VDDA rises above the PVD threshold depending on EXTI line16
rising/falling edge configuration. As an example the service routine could perform
emergency shutdown tasks.
100 mV
PVD threshold hysteresis
PVD output
Note: To enter Stop mode, all EXTI Line pending bits (in Pending register
(EXTI_PR)) and RTC Alarm flag must be reset. Otherwise, the Stop mode
entry procedure is ignored and program execution continues.
If WFI was used for entry:
Any EXTI Line configured in Interrupt mode (the corresponding EXTI
Interrupt vector must be enabled in the NVIC). Refer to Section 10.1.2:
Mode exit Interrupt and exception vectors on page 190.
If WFE was used for entry:
Any EXTI Line configured in event mode. Refer to Section 10.2.3:
Wakeup event management on page 199
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 Cortex™-M3 core is
no longer clocked.
However, by setting some configuration bits in the DBGMCU_CR register, the software can
be debugged even when using the low-power modes extensively. For more details, refer to
Section 31.16.1: Debug support for low-power modes.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
9
8
7
6
5
4
3
2
1
0
CWUF
PDDS
PVDE
CSBF
LPDS
DBP
PWR_CR PLS[2:0]
0x000 Reserved
Reset value 0 0 0 0 0 0 0 0 0
EWUP
PVDO
WUF
SBF
PWR_CSR
0x004 Reserved Reserved
Reset value 0 0 0 0
Note: Setting the TPAL and TPE bits at the same time is always safe, however resetting both at
the same time can generate a spurious Tamper event. For this reason it is recommended to
change the TPAL bit only when the TPE bit is reset.
Offset Register
9
8
7
6
5
4
3
2
1
0
0x00 Reserved
BKP_DR1 D[15:0]
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR2 D[15:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR3 D[15:0]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR4 D[15:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR5 D[15:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR6 D[15:0]
0x18 Reserved
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
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
BKP_DR7 D[15:0]
0x1C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR8 D[15:0]
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR9 D[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR10 D[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ASOS
ASOE
CCO
BKP_RTCCR CAL[6:0]
0x2 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
TPAL
TPE
BKP_CR
0x30 Reserved
Reset value 0 0
TPIE
CTE
TEF
CTI
TIF
BKP_CSR
0x34 Reserved Reserved
Reset value 0 0 0 0 0
0x38 Reserved
0x3C Reserved
BKP_DR11 D[15:0]
0x40 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR12 D[15:0]
0x44 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR13 D[15:0]
0x48 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR14 D[15:0]
0x4C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR15 D[15:0]
0x50 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR16 D[15:0]
0x54 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR17 D[15:0]
0x58 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR18 D[15:0]
0x5C Reserved
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
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
BKP_DR20 D[15:0]
0x64 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR21 D[15:0]
0x68 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR22 D[15:0]
0x6C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR23 D[15:0]
0x70 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR24 D[15:0]
0x74 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR25 D[15:0]
0x78 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR26 D[15:0]
0x7C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR27 D[15:0]
0x80 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR28 D[15:0]
0x84 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR30 D[15:0]
0x8C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR31 D[15:0]
0x90 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR32 D[15:0]
0x94 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR33 D[15:0]
0x98 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR34 D[15:0]
0x9C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR35 D[15:0]
0xA0 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR36 D[15:0]
0xA4 Reserved
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
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
BKP_DR37 D[15:0]
0xA8 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR38 D[15:0]
0xAC Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR40 D[15:0]
0xB4 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BKP_DR42 D[15:0]
0xBC Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
7.1 Reset
There are three types of reset, defined as system reset, power reset and backup domain
reset.
Software reset
The SYSRESETREQ bit in Cortex™-M3 Application Interrupt and Reset Control Register
must be set to force a software reset on the device. Refer to the STM32F10xxx Cortex-M3
programming manual (see Related documents on page 1) for more details.
205
%XTERNAL 3YSTEM RESET
RESET &ILTER
.234
77$' RESET
0ULSE
)7$' RESET
GENERATOR
0OWER RESET
MIN S
3OFTWARE RESET
,OW POWER MANAGEMENT RESET
AIB
7.2 Clocks
Three different clock sources can be used to drive the system clock (SYSCLK):
● HSI oscillator clock
● HSE oscillator clock
● PLL clock
The devices have the following two secondary 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.
)3#,+
TO )3
0ERIPHERAL CLOCK
ENABLE )3#,+
TO )3
0ERIPHERAL CLOCK
3$)/#,+
ENABLE TO 3$)/
-(Z 0ERIPHERAL CLOCK
(3) 2# (3) ENABLE
&3-##,+
TO &3-#
0ERIPHERAL CLOCK
ENABLE
(#,+
-(Z MAX TO !(" BUS CORE
#LOCK MEMORY AND $-!
%NABLE
TO #ORTEX 3YSTEM TIMER
0,,32# 37
0,,-5, &#,+ #ORTEX
(3) FREE RUNNING CLOCK
X 393#,+ !(" !0"
-(Z MAX 0#,+
X X X 0,,#,+ -(Z
0RESCALER 0RESCALER
TO !0"
0,, MAX PERIPHERALS
0ERIPHERAL #LOCK
(3%
%NABLE
4)-
)F !0" PRESCALER X TO 4)-
#33 ELSE X 4)-8#,+
0ERIPHERAL #LOCK
%NABLE
0,,8402% !0"
-(Z MAX 0#,+
0RESCALER
/3#?/54 PERIPHERALS TO !0"
-(Z 0ERIPHERAL #LOCK
(3% /3# %NABLE
/3#?).
4)- TIMERS TO 4)- AND
)F !0" PRESCALER X
ELSE X 4)-X#,+
0ERIPHERAL #LOCK
%NABLE
!$# TO !$# OR
/3#?). TO 24#
,3% /3# ,3% 0RESCALER
!$##,+ -(Z MAX
K(Z 24##,+
/3#?/54
(#,+
24#3%,;=
4O 3$)/ !(" INTERFACE
0ERIPHERAL CLOCK
TO )NDEPENDENT 7ATCHDOG )7$' ENABLE
,3) 2# ,3)
K(Z )7$'#,+
1. When the HSI is used as a PLL clock input, the maximum system clock frequency that can be achieved is
64 MHz.
2. For full details about the internal and external clock source characteristics, please refer to the “Electrical
characteristics” section in your device datasheet.
Several prescalers allow the configuration of the AHB frequency, the high speed APB
(APB2) and the low speed APB (APB1) domains. The maximum frequency of the AHB and
the APB2 domains is 72 MHz. The maximum allowed frequency of the APB1 domain is
36 MHz. The SDIO AHB interface is clocked with a fixed frequency equal to HCLK/2
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 with the Cortex clock
(HCLK), configurable in the SysTick Control and Status Register. The ADCs are clocked by
the clock of the High Speed domain (APB2) divided by 2, 4, 6 or 8.
The Flash memory programming interface clock (FLITFCLK) is always the HSI clock.
The timer clock frequencies are automatically fixed by hardware. There are two cases:
1. if the APB prescaler is 1, the timer clock frequencies are set to the same frequency as
that of the APB domain to which the timers are connected.
2. otherwise, they are set to twice (×2) the frequency of the APB domain to which the
timers are connected.
FCLK acts as Cortex™-M3’s free-running clock. For more details refer to the ARM Cortex™-
M3 r1p1 Technical Reference Manual (TRM).
OSC_OUT
External clock
(HiZ)
External
source
OSC_IN OSC_OUT
Crystal/Ceramic
resonators
CL1 CL2
Load
capacitors
Calibration
RC oscillator frequencies can vary from one chip to another due to manufacturing process
variations, 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. You can trim the HSI frequency in the application using the HSITRIM[4:0]
bits in the Clock control register (RCC_CR).
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 7.2.7: Clock security system (CSS) on page 94.
7.2.3 PLL
The internal PLL can be used to multiply the HSI RC output or HSE crystal output clock
frequency. Refer to Figure 8 and Clock control register (RCC_CR).
The PLL configuration (selection of HSI oscillator divided by 2 or HSE oscillator for PLL
input clock, and multiplication factor) must be done before enabling the PLL. Once the PLL
enabled, these parameters cannot be changed.
An interrupt can be generated when the PLL is ready if enabled in the Clock interrupt
register (RCC_CIR).
If the USB interface is used in the application, the PLL must be programmed to output 48 or
72 MHz. This is needed to provide a 48 MHz USBCLK.
LSI calibration
The frequency dispersion of the Low Speed Internal RC (LSI) oscillator can be calibrated to
have accurate RTC time base and/or IWDG timeout (when LSI is used as clock source for
these peripherals) with an acceptable accuracy.
This calibration is performed by measuring the LSI clock frequency with respect to TIM5
input clock (TIM5CLK). According to this measurement done at the precision of the HSE
oscillator, the software can adjust the programmable 20-bit prescaler of the RTC to get an
accurate time base or can compute accurate IWDG timeout.
Use the following procedure to calibrate the LSI:
1. Enable TIM5 timer and configure channel4 in input capture mode
2. Set the TIM5CH4_IREMAP bit in the AFIO_MAPR register to connect the LSI clock
internally to TIM5 channel4 input capture for calibration purpose.
3. Measure the frequency of LSI clock using the TIM5 Capture/compare 4 event or
interrupt.
4. Use the measured LSI frequency to update the 20-bit prescaler of the RTC depending
on the desired time base and/or to compute the IWDG timeout.
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
HSI
HSICAL[7:0] HSITRIM[4:0] HSION
RDY
Res.
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
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 r r 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
PLL HSE HSI LSE LSI PLL HSE HSI LSE LSI
CSSF
RDYIE RDYIE RDYIE RDYIE RDYIE RDYF RDYF RDYF RDYF RDYF
Reserved Reserved
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADC3 USART1 TIM8 SPI1 TIM1 ADC2 ADC1 IOPG IOPF IOPE IOPD IOPC IOPB IOPA AFIO
Res.
RST RST RST RST RST RST RST RST RST RST RST RST RST RST RST
rw rw rw rw rw rw rw rw rw rw rw rw rw rw Res. 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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SPI3 SPI2 WWD TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
RST RST GRST RST RST RST RST RST RST RST RST RST
Reserved Reserved
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
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
ADC3 USAR TIM8 SPI1 TIM1 ADC2 ADC1 IOPG IOPF IOPE IOPD IOPC IOPB IOPA AFIO
EN T1EN EN EN EN EN EN EN EN EN EN EN EN EN EN
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
DAC PWR BKP CAN USB I2C2 I2C1 UART5E UART4 USART USART
EN EN EN EN EN EN EN N EN 3EN 2EN
Reserved Res. Res. Res.
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
SPI3 SPI2 WWD TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
EN EN Reserved GEN Reserved EN EN EN EN EN EN EN EN EN
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
BDRST
Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
LSI
LSION
RDY
Reserved
r rw
0x1C
0x0C
0x010
Offset
7.3.11
RM0008
Table 18.
RCC_CR
RCC_CIR
RCC_CSR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
RCC_CFGR
RCC_BDCR
RCC_AHBENR
RCC_APB1ENR
RCC_APB2ENR
RCC_APB1RSTR
RCC_APB2RSTR
0
LPWRSTF 31
Reserved Reserved
0
WWDGRSTF 30
0
0
0
IWDGRSTF DACEN DACRST 29
0
0
0
SFTRSTF PWREN PWRRST
Reserved
28
Reserved
1
0
0
PORRSTF BKPEN BKPRST 27
Reserved
1
0
PINRSTF Reserved Reserved
RCC register map
26
Reserved
Reserved
0
0
0
0
0
0
0
24
0
0
0
USBEN USBRST CSSC Reserved
Reserved
23
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Reserved
20
0
0
0
0
0
0
0
0
0
0
0
0
18
0
0
0
0
0
0
0
0
0
Reserved
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TIM8EN TIM8RST 13
Reserved Reserved
0
0
0
0
0
Reserved
PPRE2
0
0
0
0
0
0
0
Reserved
11
HSICAL[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
9
[2:0]
The following table gives the RCC register map and the reset values.
PPRE1
SEL
[1:0]
RTC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
Reserved
4
HSITRIM[4:0]
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
SWS
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
119/1096
Low-, medium-, high- and XL-density reset and clock control (RCC)
0
Connectivity line devices: reset and clock control (RCC) RM0008
8.1 Reset
There are three types of reset, defined as system reset, power reset and backup domain
reset.
Software reset
The SYSRESETREQ bit in Cortex™-M3 Application Interrupt and Reset Control Register
must be set to force a software reset on the device. Refer to the STM32F10xxx Cortex-M3
programming manual (see Related documents on page 1) for more details.
205
%XTERNAL 3YSTEM RESET
RESET &ILTER
.234
77$' RESET
0ULSE
)7$' RESET
GENERATOR
0OWER RESET
MIN S
3OFTWARE RESET
,OW POWER MANAGEMENT RESET
AIB
8.2 Clocks
Three different clock sources can be used to drive the system clock (SYSCLK):
● HSI oscillator clock
● HSE oscillator clock
● PLL clock
The devices have the following two secondary 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.
40 kHz
LSI to independent watchdog
RC IWDGCLK
LSI
OSC32_IN 32.768 kHz to RTC
LSE LSE
RTCCLK
OSC32_OUT OSC
/128
CSS
RTCSEL[1:0]
HSE
MCO[3:0]
HCLK to AHB bus, core memory and DMA
HSE
HSI /8 to Cortex System timer
MCO PLLCLK/2 FCLK Cortex free running clock
PLL2CLK 36 MHz max
PLL3CLK/2 APB1 prescaler PCLK1
PLL3CLK /1, 2, 4, 8, 16 Peripheral clock enable to APB1 peripherals
XT1
to TIM2,3,4,5,
TIM2,3,4,5,6,7 6&7
If(APB1 prescaler =1) x1
SYSCLK AHB prescaler
72 MHz max. else x2 TIMxCLK
/1,/2 ../512
(see note1) Peripheral clock enable
72 MHz max
APB2 prescaler PCLK2
/1, 2, 4, 8, 16 Peripheral clock enable to APB2 peripherals
Ethernet
PHY
TIM1
to TIM1
If(APB2 prescaler =1) x1
else x2 TIMxCLK
ETH_MII_TX_CLK MACTXCLK Peripheral clock enable
MII_RMII_SEL
/2, /20
in AFIO_MAPR
to Ethernet MAC
ETH_MII_RX_CLK MACRXCLK ADC prescaler ADCCLK to ADC1,2
/2, 4, 6, 8 14 MHz max
MACRMIICLK
ai15699d
1. When the HSI is used as a PLL clock input, the maximum system clock frequency that can be achieved is
36 MHz.
2. For full details about the internal and external clock source characteristics, please refer to the “Electrical
characteristics” section in your device datasheet.
The advanced clock controller features 3 PLLs to provide a high degree of flexibility to the
application in the choice of the external crystal or oscillator to run the core and peripherals
at the highest frequency and guarantee the appropriate frequency for the Ethernet and USB
OTG FS.
A single 25 MHz crystal can clock the entire system and all peripherals including the
Ethernet and USB OTG FS peripherals. In order to achieve high-quality audio performance,
an audio crystal can be used. In this case, the I2S master clock can generate all standard
sampling frequencies from 8 kHz to 96 kHz with less than 0.5% accuracy.
For more details about clock configuration for applications requiring Ethernet, USB OTG FS
and/or I2S (audio), please refer to "Appendix A Applicative block diagrams" in your
connectivity line device datasheet.
Several prescalers allow the configuration of the AHB frequency, the high speed APB
(APB2) and the low speed APB (APB1) domains. The maximum frequency of the AHB and
the APB2 domains is 72 MHz. The maximum allowed frequency of the APB1 domain is
36 MHz.
All peripheral clocks are derived from the system clock (SYSCLK) except:
● The Flash memory programming interface clock (FLITFCLK) is always the HSI clock
● The USB OTG FS 48 MHz clock which is derived from the PLL VCO clock (2 ×
PLLCLK), followed by a programmable prescaler (divide by 3 or 2). This selection is
made through the OTGFSPRE bit in the RCC_CFGR register. For proper USB OTG FS
operation, the PLL should be configured to output 72 MHz or 48 MHz.
● The I2S2 and I2S3 clocks which can be derived from the system clock (SYSCLK) or the
PLL3 VCO clock (2 × PLL3CLK). This selection is made through the I2SxSRC bit in the
RCC_CFGR2 register. For more information on PLL3 and how to configure the I2S
clock to achieve high-quality audio performance, please refer to Section 25.4.3: Clock
generator.
● The Ethernet MAC clocks (TX, RX and RMII) which are provided from the external
PHY. For further information on the Ethernet configuration, please refer to
Section 29.4.4: MII/RMII selection.
When the Ethernet is used, the AHB clock frequency must be at least 25 MHz.
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 with the Cortex clock
(HCLK), configurable in the SysTick Control and Status Register. The ADCs are clocked by
the clock of the High Speed domain (APB2) divided by 2, 4, 6 or 8.
The timer clock frequencies are automatically fixed by hardware. There are two cases:
1. if the APB prescaler is 1, the timer clock frequencies are set to the same frequency as
that of the APB domain to which the timers are connected.
2. otherwise, they are set to twice (×2) the frequency of the APB domain to which the
timers are connected.
FCLK acts as Cortex™-M3’s free-running clock. For more details refer to the ARM Cortex™-
M3 r1p1 Technical Reference Manual (TRM).
OSC_OUT
External clock
(HiZ)
External
source
OSC_IN OSC_OUT
Crystal/ceramic
resonators
CL1 CL2
Load
capacitors
Calibration
RC oscillator frequencies can vary from one chip to another due to manufacturing process
variations, 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. You can trim the HSI frequency in the application using the HSITRIM[4:0]
bits in the Clock control register (RCC_CR).
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 128.
8.2.3 PLLs
The main PLL provides a frequency multiplier starting from one of the following clock
sources:
● HSI clock divided by 2
● HSE or PLL2 clock through a configurable divider
Refer to Figure 11 and Clock control register (RCC_CR).
PLL2 and PLL3 are clocked by HSE through a specific configurable divider. Refer to
Figure 11 and Clock configuration register2 (RCC_CFGR2)
The configuration of each PLL (selection of clock source, predivision factor and
multiplication factor) must be done before enabling the PLL. Each PLL should be enabled
after its input clock becomes stable (ready flag). Once the PLL is enabled, these parameters
can not be changed.
When changing the entry clock source of the main PLL, the original clock source must be
switched off only after the selection of the new clock source (done through bit PLLSRC in
the Clock configuration register (RCC_CFGR)).
An interrupt can be generated when the PLL is ready if enabled in the Clock interrupt
register (RCC_CIR).
LSI calibration
The frequency dispersion of the Low Speed Internal RC (LSI) oscillator can be calibrated to
have accurate RTC time base and/or IWDG timeout (when LSI is used as clock source for
these peripherals) with an acceptable accuracy.
This calibration is performed by measuring the LSI clock frequency with respect to TIM5
input clock (TIM5CLK). According to this measurement done at the precision of the HSE
oscillator, the software can adjust the programmable 20-bit prescaler of the RTC to get an
accurate time base or can compute accurate IWDG timeout.
Use the following procedure to calibrate the LSI:
1. Enable TIM5 timer and configure channel4 in input capture mode
2. Set the TIM5CH4_IREMAP bit in the AFIO_MAPR register to connect the LSI clock
internally to TIM5 channel4 input capture for calibration purpose.
3. Measure the frequency of LSI clock using the TIM5 Capture/compare 4 event or
interrupt.
4. Use the measured LSI frequency to update the 20-bit prescaler of the RTC depending
on the desired time base and/or to compute the IWDG timeout.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLL3 PLL3 PLL2 PLL2
PLLRDY PLLON CSSON HSEBYP HSERDY HSEON
Reserved RDY ON RDY ON Reserved
r rw r rw r rw rw rw r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HSICAL[7:0] HSITRIM[4:0] HSIRDY HSION
Res.
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
OTGFS PLL PLL
MCO[3:0] PLLMUL[3:0]
Reserved Res. PRE XTPRE SRC
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
ADC PRE[1:0] 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 rw rw r r 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
PLL3 PLL2 PLL HSE HSI LSE LSI PLL3 PLL2 PLL HSE HSI LSE LSI
CSSF
RDYIE RDYIE RDYIE RDYIE RDYIE RDYIE RDYIE RDYF RDYF RDYF RDYF RDYF RDYF RDYF
Res.
rw rw rw rw rw rw rw r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART1 SPI1 TIM1 ADC2 ADC1 IOPE IOPD IOPC IOPB IOPA AFIO
Res. RST Res. RST RST RST RST Reserved RST RST RST RST RST Res. RST
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ETH
MACR
Reserved XEN
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ETHM
ETHM OTGF FLITFE SRAM DMA2 DMA1
ACTX CRCEN
ACEN SEN N EN EN EN
EN Res. Reserved Res. Res.
rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USAR SPI1 TIM1 ADC2 ADC1 IOPE IOPD IOPC IOPB IOPA AFIO
T1EN EN EN EN EN EN EN EN EN EN EN
Res. Res. Reserved 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
DAC PWR BKP CAN2 CAN1 I2C2 I2C1 UART5E UART4 USART USART
Reserved EN EN EN EN EN EN EN N EN 3EN 2EN
Reserved Res.
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BDRST
Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
LSI
LSION
RDY
Reserved
r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ETHMAC OTGFS
RST RST
Res. Res. Reserved
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 rw rw rw rw
Offset Register
9
8
7
6
5
4
3
2
1
0
PLL3 RDY
PLL2 RDY
PLL3 ON
PLL2 ON
PLL RDY
HSERDY
HSEBYP
HSIRDY
CSSON
HSEON
PLLON
HSION
Reserved
RCC_CR Reser HSICAL[7:0] HSITRIM[4:0]
0x000 Reserved
ved
Reset value 0 0 0 0 0 0 0 0 0 0 x x x x x x x x 1 0 0 0 0 1 1
OTGFSPRE
PLLXTPRE
PLLSRC
ADC
Reserved
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
PLL3RDYIE
PLL2RDYIE
PLL3RDYC
PLL2RDYC
HSERDYIE
PLL3RDYF
PLL2RDYF
LSERDYIE
HSERDYC
PLLRDYIE
HSERDYF
LSERDYC
HSIRDYIE
PLLRDYC
LSERDYF
LSIRDYIE
HSIRDYC
PLLRDYF
HSIRDYF
Reserved
LSIRDYC
LSIRDYF
CSSC
CSSF
RCC_CIR
0x008 Reserved
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
USART1RST
ADC2RST
ADC1RST
IOPDRST
IOPCRST
IOPERST
IOPBRST
AFIORST
Reserved
Reserved
Reserved
TIM1RST
IOPARST
SPI1RST
Reserved
RCC_APB2RSTR
0x00C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
USART3RST
USART2RST
WWDGRST
UART5RST
UART4RST
CAN2RST
CAN1RST
PWRRST
TIM4RST
TIM3RST
TIM2RST
SPI3RST
SPI2RST
I2C2RST
I2C1RST
DACRST
BKPRST
TM7RST
TM6RST
TM5RST
Reserved
Reserved
Reserved
RCC_APB1RSTR Reser
0x010 Reserved
ved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
ETHMACRXEN
ETHMACTXEN
ETHMACEN
OTGFSEN
Reserved
Reserved
Reserved
SRAMEN
DM2AEN
DM1AEN
FLITFEN
CRCEN
RCC_AHBENR
0x014 Reserved Reserved
Reset value 0 0 0 0 0 1 1 0 0
USART1EN
Reserved
Reserved
ADC2EN
ADC1EN
IOPDEN
IOPCEN
IOPEEN
IOPBEN
AFIOEN
TIM1EN
IOPAEN
SPI1EN
Reserved
Reserved
0x018 RCC_APB2ENR
Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
USART3EN
USART2EN
WWDGEN
UART5EN
UART4EN
CAN2EN
CAN1EN
PWREN
TIM7EN
TIM6EN
TIM5EN
TIM4EN
TIM3EN
TIM2EN
SPI3EN
SPI2EN
I2C2EN
I2C1EN
DACEN
BKPEN
Reserved
Reserved
Reserved
RCC_APB1ENR Reser
0x01C Reserved
ved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
LSERDY
LSEBYP
RTCEN
BDRST
LSEON
RTC
RCC_BDCR SEL
0x020 Reserved Reserved Reserved
[1:0]
Reset value 0 0 0 0 0 0 0
WWDGRSTF
IWDGRSTF
LPWRSTF
PORRSTF
SFTRSTF
PINRSTF
LSIRDY
Reserved
LSION
RMVF
RCC_CSR
0x024 Reserved
Reset value 0 0 0 0 1 1 0 0 0
ETHMACRST
OTGFSRST
Reserved
RCC_AHBSTR
0x028 Reserved Reserved
Reset value 0 0
PREDIV1SRC
I2S3SRC
I2S2SRC
PLL3MUL PLL2MUL
RCC_CFGR2 PREDIV2[3:0] PREDIV1[3:0]
0x02C Reserved [3:0] [3:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Read VDD
TTL Schmitt
Bit set/reset registers
Protection
trigger on/off diode
Write
ai14781
on/off
Read
VDD_FT(1)
TTL Schmitt
Bit set/reset registers
trigger on/off
Write
ai14782
1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.
00 Reserved
01 Max. output speed 10 MHz
10 Max. output speed 2 MHz
11 Max. output speed 50 MHz
or for reset only GPIOx_BRR) to select the bits you want to modify. The unselected bits will
not be modified.
VDD
on/off
Input data register
on
Read
VDD or VDD_FT(1)
Bit set/reset registers
TTL Schmitt
trigger protection
on/off diode
Write
Output data register
output driver
protection
diode
VSS
Read/write
ai14783
1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.
The Figure 16 on page 159 shows the Output configuration of the I/O Port bit.
TTL Schmitt
Bit set/reset registers
trigger Protection
diode
Write
Input driver
Output data register
I/O pin
ai14784
1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.
TTL Schmitt
Protection
Bit set/reset registers
trigger
diode
Input driver I/O pin
Write
Output data register
ai14785
1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.
Analog Input
To on-chip
peripheral
TTL Schmitt
Protection
trigger
diode
Write
Output data register
Protection
diode
VSS
Read/write
From on-chip
peripheral
ai14786
SPIx_MISO Simplex bidirectional data wire / master Not used. Can be used as a GPIO
Simplex bidirectional data wire/ slave
Alternate function push-pull
(point to point)
Simplex bidirectional data wire/ slave
Alternate function open drain
(multi-slave)
Hardware master /slave Input floating/ Input pull-up / Input pull-down
SPIx_NSS Hardware master/ NSS output enabled Alternate function push-pull
Software Not used. Can be used as a GPIO
As soon as the USB is enabled, these pins are connected to the USB
USB_DM / USB_DP
internal transceiver automatically.
1. This table applies to low-, medium-, high and XL-density devices only.
ADC/DAC Analog
FSMC_A[25:0]
Alternate function push-pull
FSMC_D[15:0]
FSMC_NOE
Alternate function push-pull
FSMC_NWE
FSMC_NE[4:1]
FSMC_NCE[3:2]
Alternate function push-pull
FSMC_NCE4_1
FSMC_NCE4_2
FSMC_NWAIT
Input floating/ Input pull-up
FSMC_CD
FSMC_NIOS16,
FSMC_INTR Input floating
FSMC_INT[3:2]
FSMC_NL
Alternate function push-pull
FSMC_NBL[1:0]
FSMC_NIORD, FSMC_NIOWR
Alternate function push-pull
FSMC_NREG
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CNF7[1:0] MODE7[1:0] CNF6[1:0] MODE6[1:0] CNF5[1:0] MODE5[1:0] CNF4[1:0] MODE4[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
CNF3[1:0] MODE3[1:0] CNF2[1:0] MODE2[1:0] CNF1[1:0] MODE1[1:0] CNF0[1:0] MODE0[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
CNF15[1:0] MODE15[1:0] CNF14[1:0] MODE14[1:0] CNF13[1:0] MODE13[1:0] CNF12[1:0] MODE12[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
CNF11[1:0] MODE11[1:0] CNF10[1:0] MODE10[1:0] CNF9[1:0] MODE9[1:0] CNF8[1:0] MODE8[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
Reserved
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
Reserved
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LCKK
Reserved
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
To optimize the number of free GPIOs during debugging, this mapping can be configured in
different ways by programming the SWJ_CFG[1:0] bits in the AF remap and debug I/O
configuration register (AFIO_MAPR). Refer to Table 37
Table 38. ADC1 external trigger injected conversion alternate function remapping(1)
Alternate function ADC1_ETRGINJ_REMAP = 0 ADC1_ETRGINJ_REMAP = 1
Table 39. ADC1 external trigger regular conversion alternate function remapping(1)
Alternate function ADC1_ETRGREG_REMAP = 0 ADC1_ETRGREG_REMAP = 1
Table 40. ADC2 external trigger injected conversion alternate function remapping(1)
Alternate function ADC2_ETRGINJ_REMAP = 0 ADC2_ETRGINJ_REMAP = 1
Table 41. ADC2 external trigger regular conversion alternate function remapping(1)
Alternate function ADC2_ETRGREG_REG = 0 ADC2_ETRGREG_REG = 1
Memory map and bit definitions for low-, medium- high- and XL-density
devices:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADC2_ ADC1_
ADC2_ET ADC1_ET TIM5CH
SWJ_ ETRGR ETRGIN
RGINJ_R RGREG_ 4_IREM
Reserved CFG[2:0] Reserved EG_RE J_REM
EMAP REMAP AP
MAP AP
w w w rw rw rw rw rw
TIM5CH
SWJ_CFG[2:0] 4_IREM
Reserved Reserved AP
w w w rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PD01_ CAN_REMAP TIM4_ TIM3_REMAP TIM2_REMAP TIM1_REMAP USART3_ USART2_ USART1_ I2C1_ SPI1_
REMAP [1:0] REMAP [1:0] [1:0] [1:0] REMAP[1:0] REMAP REMAP REMAP REMAP
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
9
8
7
6
5
4
3
2
1
0
CNF7 MODE7 CNF6 MODE6 CNF5 MODE5 CNF4 MODE4 CNF3 MODE3 CNF2 MODE2 CNF1 MODE1 CNF0 MODE0
GPIOx_CRL
0x00 [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0]
Reset value 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 1 0 0
CNF MODE1 CNF MODE1 CNF MODE1 CNF MODE1 CNF MODE1 CNF MODE1 CNF CNF
MODE9 MODE8
GPIOx_CRH 15 5 14 4 13 3 12 2 11 1 10 0 9 8
0x04 [1:0] [1:0]
[1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0]
Reset value 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 1 0 0
GPIOx_IDR IDR[15:0]l
0x08 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_ODR ODR[15:0]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_BRR BR[15:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
LCKK
GPIOx_LCKR LCK[15:0]
0x18 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC1_ETRGREG_REMAP
ADC2_ETRGINJ_REMAP
ADC1_ETRGINJ_REMAP
USART3_REMAP[1]
USART3_REMAP[0]
TIM5CH4_IREMAP
TIM3_REMPAP[1]
TIM3_REMPAP[0]
TIM2_REMPAP[1]
TIM2_REMPAP[0]
TIM1_REMPAP[1]
TIM1_REMPAP[0]
USART2_REMAP
USART1_REMAP
CAN1_REMAP[1]
CAN1_REMAP[0]
TIM4_REMPAP
PD01_REMAP
SPI1_REMAP
I2C1_REMAP
SWJ_CFG[2]
SWJ_CFG[1]
SWJ_CFG[0]
AFIO_MAPR
low-, medium-,
0x04 high- and XL- Reserved Reserved
density devices
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
USART3_REMAP[1]
USART3_REMAP[0]
TIM2ITR1_IREMAP
TIM5CH4_IREMAP
PTP_PPS_REMAP
TIM3_REMPAP[1]
TIM3_REMPAP[0]
TIM2_REMPAP[1]
TIM2_REMPAP[0]
TIM1_REMPAP[1]
TIM1_REMPAP[0]
USART2_REMAP
USART1_REMAP
CAN1_REMAP[1]
CAN1_REMAP[0]
TIM4_REMPAP
CAN2_REMAP
PD01_REMAP
MII_RMII_SEL
SPI3_REMAP
SPI1_REMAP
I2C1_REMAP
ETH_REMAP
SWJ_CFG[2]
SWJ_CFG[1]
SWJ_CFG[0]
AFIO_MAPR
Reserved
Reserved
Reserved
connectivity line
0x04
devices
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
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
USART3_REMAP[1:0]
TIM5CH4_IREMAP
TIM3_REMAP[1:0]
TIM2_REMAP[1:0]
TIM1_REMAP[1:0]
USART2_REMAP
USART1_REMAP
PD01_REMAP
TIM4_REMAP
SPI1_REMAP
I2C1_REMAP
Reserved
SWJ_
AFIO_MAPR
0x04 Reserved CFG[2:0] Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIM14_REMAP
TIM13_REMAP
TIM11_REMAP
TIM10_REMAP
TIM9_REMAP
FSMC_NADV
AFIO_MAPR2
0x1C Reserved Reserved
Reset value 0 0 0 0 0 0
TIM1_DMA_REMAP
TIM12_REMAP
TIM14_REMAP
TIM13_REMAP
TIM17_REMAP
TIM16_REMAP
TIM15_REMAP
MISC_ REMAP
CEC_REMAP
FSMC_NADV
AFIO_MAPR2
0x1C Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
Priority
Type of
Acronym Description Address
priority
- - - Reserved 0x0000_0000
-3 fixed Reset Reset 0x0000_0004
Position
Priority
Type of
Acronym Description Address
priority
Position
Priority
Type of
Acronym Description Address
priority
Position
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
- - - Reserved 0x0000_0000
-3 fixed Reset Reset 0x0000_0004
Nonmaskable interrupt. The RCC
-2 fixed NMI Clock Security System (CSS) is 0x0000_0008
linked to the NMI vector.
-1 fixed HardFault All class of fault 0x0000_000C
0 settable MemManage Memory management 0x0000_0010
1 settable BusFault Prefetch fault, memory access fault 0x0000_0014
2 settable UsageFault Undefined instruction or illegal state 0x0000_0018
0x0000_001C -
- - - Reserved
0x0000_002B
System service call via SWI
3 settable SVCall 0x0000_002C
instruction
4 settable Debug Monitor Debug monitor 0x0000_0030
- - - Reserved 0x0000_0034
5 settable PendSV Pendable request for system service 0x0000_0038
6 settable SysTick Systick timer 0x0000_003C
0 7 settable WWDG Window watchdog interrupt 0x0000_0040
Position
Priority
Type of
Acronym Description Address
priority
Position
Priority
Type of
Acronym Description Address
priority
Position
Priority
Type of
Acronym Description Address
priority
- - - Reserved 0x0000_0000
-3 fixed Reset Reset 0x0000_0004
Non maskable interrupt. The RCC
-2 fixed NMI Clock Security System (CSS) is 0x0000_0008
linked to the NMI vector.
-1 fixed HardFault All class of fault 0x0000_000C
0 settable MemManage Memory management 0x0000_0010
1 settable BusFault Prefetch fault, memory access fault 0x0000_0014
2 settable UsageFault Undefined instruction or illegal state 0x0000_0018
0x0000_001C -
- - - Reserved
0x0000_002B
System service call via SWI
3 settable SVCall 0x0000_002C
instruction
4 settable Debug Monitor Debug Monitor 0x0000_0030
- - - Reserved 0x0000_0034
5 settable PendSV Pendable request for system service 0x0000_0038
6 settable SysTick System tick timer 0x0000_003C
0 7 settable WWDG Window watchdog interrupt 0x0000_0040
PVD through EXTI Line detection
1 8 settable PVD 0x0000_0044
interrupt
2 9 settable TAMPER Tamper interrupt 0x0000_0048
3 10 settable RTC RTC global interrupt 0x0000_004C
4 11 settable FLASH Flash global interrupt 0x0000_0050
5 12 settable RCC RCC global interrupt 0x0000_0054
6 13 settable EXTI0 EXTI Line0 interrupt 0x0000_0058
7 14 settable EXTI1 EXTI Line1 interrupt 0x0000_005C
8 15 settable EXTI2 EXTI Line2 interrupt 0x0000_0060
9 16 settable EXTI3 EXTI Line3 interrupt 0x0000_0064
10 17 settable EXTI4 EXTI Line4 interrupt 0x0000_0068
11 18 settable DMA1_Channel1 DMA1 Channel1 global interrupt 0x0000_006C
12 19 settable DMA1_Channel2 DMA1 Channel2 global interrupt 0x0000_0070
13 20 settable DMA1_Channel3 DMA1 Channel3 global interrupt 0x0000_0074
14 21 settable DMA1_Channel4 DMA1 Channel4 global interrupt 0x0000_0078
15 22 settable DMA1_Channel5 DMA1 Channel5 global interrupt 0x0000_007C
16 23 settable DMA1_Channel6 DMA1 Channel6 global interrupt 0x0000_0080
Position
Priority
Type of
Acronym Description Address
priority
Position
Priority
Type of
Acronym Description Address
priority
!-"! !0"BUS
4O .6)# INTERRUPT
CONTROLLER
Event
mask
register
-36
generated. The pending bit corresponding to the interrupt line is also set. This request is
reset by writing a ‘1’ in the pending register.
To generate the event, the event line should be configured and enabled. This is done by
programming the two trigger registers with the desired edge detection and by enabling the
event request by writing a ‘1’ to the corresponding bit in the event mask register. When the
selected edge occurs on the event line, an event pulse is generated. The pending bit
corresponding to the event line is not set
An interrupt/event request can also be generated by software by writing a ‘1’ in the software
interrupt/event register.
PA0
PB0
PC0
EXTI0
PD0
PE0
PF0
PG0
PA1
PB1
PC1
EXTI1
PD1
PE1
PF1
PG1
PA15
PB15
PC15
EXTI15
PD15
PE15
PF15
PG15
1. To configure the AFIO_EXTICRx for the mapping of external interrupt/event lines onto GPIOs, the AFIO
clock should first be enabled. Refer to Section 7.3.7: APB2 peripheral clock enable register
(RCC_APB2ENR) for low-, medium-, high- and XL-density devices and, to Section 8.3.7: APB2 peripheral
clock enable register (RCC_APB2ENR) for connectivity line devices.
The four other EXTI lines are connected as follows:
● EXTI line 16 is connected to the PVD output
● EXTI line 17 is connected to the RTC Alarm event
● EXTI line 18 is connected to the USB Wakeup event
● EXTI line 19 is connected to the Ethernet Wakeup event (available only in connectivity
line devices)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MR19 MR18 MR17 MR16
Reserved
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
MR19 MR18 MR17 MR16
Reserved
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
TR19 TR18 TR17 TR16
Reserved
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 external interrupt line occurs during writing of EXTI_RTSR register, the
pending bit will not be set.
Rising and Falling edge triggers can be set for the same interrupt line. In this configuration,
both generate a trigger condition.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TR19 TR18 TR17 TR16
Reserved
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 falling edge on external interrupt line occurs during writing of EXTI_FTSR register, the
pending bit will not be set.
Rising and Falling edge triggers can be set for the same interrupt line. In this configuration,
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
Reserved 19 18 17 16
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
PR19 PR18 PR17 PR16
Reserved
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
Table 64. External interrupt/event controller register map and reset values
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
EXTI_IMR MR[19:0]
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EXTI_EMR MR[19:0]
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EXTI_RTSR TR[19:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EXTI_FTSR TR[19:0]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EXTI_SWIER SWIER[19:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
EXTI_PR PR[19:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Interrupt
Flags enable bits
End of conversion
EOC EOCIE
End of injected conversion ADC Interrupt to NVIC
JEOC JEOCIE
Analog watchdog event
AWD AWDIE
Analog watchdog
Compare Result
High Threshold (12 bits)
Low Threshold (12 bits)
Address/data bus
Injected data registers
VREF+ (4 x 16 bits)
VREF-
Regular data register
VDDA (16 bits)
VSSA
Analog DMA request
MUX
ADCx_IN0
ADCx_IN1
GPIO up to 4 Injected
ADCCLK
Ports channels Analog to digital
up to 16 converter
Regular
ADCx_IN15 channels
Temp. sensor
VREFINT
TIM1_TRGO
TIM1_CH4 JEXTRIG
TIM2_TRGO bit
TIM2_CH1
Start trigger
TIM3_CH4
TIM4_TRGO (injected group)
EXTI_15
TIM8_CH4(2)
JEXTSEL[2:0] bits
EXTRIG TIM1_TRGO
ADCx-ETRGINJ_REMAP bit JEXTRIG
bit TIM1_CH4
bit
TIM4_CH3
TIM8_CH2 Start trigger
TIM8_CH4 (injected group)
EXTSEL[2:0] bits TIM5_TRGO
TIM1_CH1 TIM5_CH4
TIM1_CH2 Start trigger
TIM1_CH3 EXTSEL[2:0] bits
(regular group)
TIM2_CH2
TIM3_TRGO TIM3_CH1
TIM2_CH3 EXTRIG
TIM4_CH4 bit
TIM1_CH3
TIM8_CH1 Start trigger
EXTI_11 TIM8_TRGO (regular group)
(2)
TIM8_TRGO TIM5_CH1
TIM5_CH3
ADCx_ETRGREG_REMAP bit
Triggers for ADC3(1)
ai14802d
1. ADC3 has regular and injected conversion triggers different from those of ADC1 and ADC2.
2. TIM8_CH4 and TIM8_TRGO with their corresponding remap bits exist only in High-density and XL-density
products.
Input, analog reference The higher/positive reference voltage for the ADC,
VREF+
positive 2.4 V ≤ VREF+ ≤ VDDA
Analog power supply equal to VDD and
VDDA(1) Input, analog supply
2.4 V ≤ VDDA ≤ 3.6 V
Input, analog reference The lower/negative reference voltage for the ADC,
VREF-
negative VREF- = VSSA
Input, analog supply
VSSA(1) Ground for analog power supply equal to VSS
ground
ADCx_IN[15:0] Analog signals Up to 21 analog channels(2)
1. VDDA and VSSA have to be connected to VDD and VSS, respectively.
2. For full details about the ADC I/O pins, please refer to the “Pinouts and pin descriptions” section of the
corresponding device datasheet.
ADC_CLK
SET ADON
None x 0 0
All injected channels 0 0 1
All regular channels 0 1 0
All regular and injected channels 0 1 1
(1)
Single injected channel 1 0 1
Single(1) regular channel 1 1 0
Single(1) regular or injected channel 1 1 1
1. Selected by AWDCH[4:0] bits
Auto-injection
If the JAUTO bit is set, then the injected group channels are automatically converted after
the regular group channels. This can be used to convert a sequence of up to 20 conversions
programmed in the ADC_SQRx and ADC_JSQR registers.
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.
For ADC clock prescalers ranging from 4 to 8, a delay of 1 ADC clock period is automatically
inserted when switching from regular to injected sequence (respectively injected to regular).
When the ADC clock prescaler is set to 2, the delay is 2 ADC clock periods.
Note: It is not possible to use both auto-injected and discontinuous modes simultaneously.
ADC clock
Inj. event
Reset ADC
SOC
max latency(1)
1. The maximum latency value can be found in the electrical characteristics of the STM32F101xx and
STM32F103xx datasheets.
Injected group
This mode is enabled by setting the JDISCEN bit in the ADC_CR1 register. It can be used to
convert the sequence selected in the ADC_JSQR register, channel by channel, after an
external trigger event.
When an external trigger occurs, it starts the next channel conversions selected in the
ADC_JSQR registers until all the conversions in the sequence are done. The total sequence
length is defined by the JL[1:0] bits in the ADC_JSQR register.
Example:
n = 1, channels to be converted = 1, 2, 3
1st trigger: channel 1 converted
2nd trigger: channel 2 converted
3rd trigger: channel 3 converted and EOC and JEOC events generated
4th trigger: channel 1
Note: 1 When all injected channels are converted, the next trigger starts the conversion of the first
injected channel. In the example above, the 4th trigger reconverts the 1st injected channel
1.
2 It is not possible to use both auto-injected and discontinuous modes simultaneously.
3 The user must avoid setting discontinuous mode for both regular and injected groups
together. Discontinuous mode must be enabled only for one group conversion.
11.4 Calibration
The ADC has an built-in self calibration mode. Calibration significantly reduces accuracy
errors due to internal capacitor bank variations. During calibration, an error-correction code
(digital word) is calculated for each capacitor, and during all subsequent conversions, the
error contribution of each capacitor is removed using this code.
Calibration is started by setting the CAL bit in the ADC_CR2 register. Once calibration is
over, the CAL bit is reset by hardware and normal conversion can be performed. It is
recommended to calibrate the ADC once at power-on. The calibration codes are stored in
the ADC_DR as soon as the calibration phase ends.
Note: 1 It is recommended to perform a calibration after each power-up.
2 Before starting a calibration the ADC must have been in power-off state (ADON bit = ‘0’) for
at least two ADC clock cycles.
CLK
Regular group
0 0 0 0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Regular group
D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0
Table 67. External trigger for regular channels for ADC1 and ADC2
Source Type EXTSEL[2:0]
Table 68. External trigger for injected channels for ADC1 and ADC2
Source Connection type JEXTSEL[2:0]
The software source trigger events can be generated by setting a bit in a register
(SWSTART and JSWSTART in ADC_CR2).
A regular group conversion can be interrupted by an injected trigger.
Regular
channels ADC2 (Slave)
injected
channels
internal triggers
Address/data bus
Regular data register
(16 bits)(2)
ADCx_IN0
Regular
ADCx_IN1 channels
GPIO
Ports
Injected
channels
ADCx_IN15
Temp. sensor
VREFINT Dual mode
control
EXTI_15
Start trigger mux
(injected group)
1. External triggers are present on ADC2 but are not shown for the purposes of this diagram.
2. In some dual ADC modes, the ADC1 data register (ADC1_DR) contains both ADC1 and ADC2 regular converted data over
the entire 32 bits.
Sampling
Conversion
ADC2 CH0 CH1 CH2 CH3
ADC1 CH3 CH2 CH1 CH0
Sampling
Conversion
ADC1 CH0 CH1 CH2 CH3 ... CH15
ADC2 CH15 CH14 CH13 CH12 ... CH0
Sampling
End of conversion on ADC2
Conversion
ADC2 CH0 ... CH0
ADC1 CH0 ... CH0
Trigger
End of conversion on ADC1
7 ADCCLK
cycles
After an EOC interrupt is generated by ADC1 (if enabled through the EOCIE bit) a 32-bit
DMA transfer request is generated (if the DMA bit is set) which transfers to SRAM the
ADC1_DR 32-bit register containing the ADC2 converted data in the upper halfword and the
ADC1 converted data in the lower halfword.
A new ADC2 start is automatically generated after 28 ADC clock cycles
CONT bit can not be set in the mode since it continuously converts the selected regular
channel.
Note: The application must ensure that no external trigger for injected channel occurs when
interleaved mode is enabled.
14 ADCCLK
cycles
28 ADCCLK
cycles
ADC1 ...
ADC2
If the injected discontinuous mode is enabled for both ADC1 and ADC2:
● When the 1st trigger occurs, the first injected channel in ADC1 is converted.
● When the 2nd trigger arrives, the first injected channel in ADC2 are converted
● and so on....
A JEOC interrupt, if enabled, is generated after all injected group channels of ADC1 are
converted.
A JEOC interrupt, if enabled, is generated after all injected group channels of ADC2 are
converted.
If another external trigger occurs after all injected group channels have been converted then
the alternate trigger process restarts.
Figure 35. Alternate trigger: 4 injected channels (each ADC) in discontinuous model
1st trigger 3rd trigger 5th trigger 7th trigger Sampling
JEOC on ADC1 Conversion
ADC1
ADC2
JEOC on ADC2
ADC1 inj
CH0
2nd trig
If a trigger occurs during an injected conversion that has interrupted a regular conversion, it
will be ignored. Figure 37 shows the behavior in this case (2nd trig is ignored).
Figure 38. Interleaved single channel with injected sequence CH11, CH12
Sampling
ADC1 CH0 CH0 CH0 Conversion
ADC2 CH0 CH0 CH0
CH11 CH12
Trigger
CH12 CH11
CH0 CH0
CH0 CH0
TEMPERATURE VSENSE
SENSOR ADCx_IN16
Address/data bus
converted data
ADC1
VREFINT
INTERNAL
ADCx_IN17
POWER
BLOCK
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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 rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TSVRE SWSTA JSWST EXTTR
EXTSEL[2:0] Res.
Reserved FE RT ART IG
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JEXTT RST
JEXTSEL[2:0] ALIGN Reserved DMA CAL CONT ADON
RIG Reserved CAL
rw rw rw rw rw Res. rw rw rw rw rw
Res. 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] SMP0[2:0]
5_0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JOFFSETx[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HT[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LT[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
L[3:0] SQ16[4:1]
Reserved
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SQ10_
SQ9[4:0] SQ8[4:0] SQ7[4:0]
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
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
JL[1:0] JSQ4[4:1]
Reserved
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: Unlike a regular conversion sequence, if JL[1:0] length is less than four, the channels
are converted in a sequence starting from (4-JL). Example: ADC_JSQR[21:0] = 10
00011 00011 00111 00010 means that a scan conversion will convert the following
channel sequence: 7, 3, 3. (not 2, 7, 3)
Bits 14:10 JSQ3[4:0]: 3rd conversion in injected sequence (when JL[1:0] = 3)
Bits 9:5 JSQ2[4:0]: 2nd conversion in injected sequence (when JL[1:0] = 3)
Bits 4:0 JSQ1[4:0]: 1st conversion in injected sequence (when JL[1:0] = 3)
1. When JL=3 ( 4 injected conversions in the sequencer), the ADC converts the channels in this order:
JSQ1[4:0] >> JSQ2[4:0] >> JSQ3[4:0] >> JSQ4[4:0]
When JL=2 ( 3 injected conversions in the sequencer), the ADC converts the channels in this order:
JSQ2[4:0] >> JSQ3[4:0] >> JSQ4[4:0]
When JL=1 ( 2 injected conversions in the sequencer), the ADC converts the channels in this order:
JSQ3[4:0] >> JSQ4[4:0]
When JL=0 (1 injected conversion in the sequencer), the ADC converts only JSQ4[4:0] channel
Reserved
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
ADC2DATA[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
DATA[15:0]
r r r r r r r r r r r r r r r r
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
JSTRT
JEOC
STRT
AWD
EOC
ADC_SR
0x00 Reserved
Reset value 0 0 0 0 0
AWD SGL
JDISCEN
JAWDEN
JEOC IE
DISCEN
AWDEN
AWDIE
JAUTO
EOCIE
Reserved
SCAN
DUALMOD DISC
ADC_CR1 AWDCH[4:0]
0x04 Reserved [3:0] NUM [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
JSWSTART
JEXTTRIG
SWSTART
TSVREFE
EXTTRIG
RSTCAL
ALIGN
Reserved
Reserved
ADON
CONT
EXTSEL JEXTSEL
DMA
CAL
ADC_CR2
0x08 Reserved [2:0] [2:0] Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JOFR1 JOFFSET1[11:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JOFR2 JOFFSET2[11:0]
0x18 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JOFR3 JOFFSET3[11:0]
0x1C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JOFR4 JOFFSET4[11:0]
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_HTR HT[11:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_LTR LT[11:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
SQ16[4:0] 16th SQ15[4:0] 15th SQ14[4:0] 14th SQ13[4:0] 13th
conversion in conversion in conversion in conversion in
ADC_SQR1 L[3:0]
0x2C Reserved regular sequence regular sequence regular sequence regular sequence
bits bits bits bits
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
SQ12[4:0] 12th SQ11[4:0] 11th SQ10[4:0] 10th SQ9[4:0] 9th SQ8[4:0] 8th SQ7[4:0] 7th
Reserved
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
JSQ4[4:0] 4th JSQ3[4:0] 3rd JSQ2[4:0] 2nd JSQ1[4:0] 1st
conversion in conversion in conversion in conversion in
ADC_JSQR JL[1:0]
0x38 Reserved injected sequence injected sequence injected sequence injected sequence
bits bits bits bits
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JDR1 JDATA[15:0]
0x3C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JDR2 JDATA[15:0]
0x40 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JDR3 JDATA[15:0]
0x44 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_JDR4 JDATA[15:0]
0x48 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Trigger selectorx
TIM2_T RGO
TIM4_T RGO DMAENx
TIM5_T RGO
TIM6_T RGO
TIM7_T RGO
TIM8_T RGO(1)
EXTI_9
DM A req ue stx
Control logicx TENx
12-bit
DHRx
LFSRx trianglex MAMPx[3:0] bits
WAVENx[1:0] bits
12-bit
DORx
12-bit
VDDA
Digital-to-analog DAC_ OU Tx
VSSA
converterx
VR EF+
ai14708c
Input, analog reference The higher/positive reference voltage for the DAC,
VREF+
positive 2.4 V ≤ VREF+ ≤ VDDA (3.3 V)
VDDA Input, analog supply Analog power supply
Input, analog supply
VSSA Ground for analog power supply
ground
DAC_OUTx Analog output signal DAC channelx analog output
Note: Once the DAC channelx is enabled, the corresponding GPIO pin (PA4 or PA5) is
automatically connected to the analog converter output (DAC_OUTx). In order to avoid
parasitic consumption, the PA4 or PA5 pin should first be configured to analog (AIN).
ai14710
ai14709
Figure 43. Timing diagram for conversion with trigger disabled TEN = 0
APB1_CLK
DHR 0x1AC
Output voltage
DOR 0x1AC available on DAC_OUT pin
tSETTLING
ai14711b
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 is
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: 1 TSELx[2:0] bit cannot be changed when the ENx bit is set.
2 When software trigger is selected, it takes only one APB1 clock cycle for DAC_DHRx-to-
DAC_DORx register transfer.
XOR
X6 X4 X X0
12
X
11 10 9 8 7 6 5 4 3 2 1 0
12
NOR
ai14713b
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 45. DAC conversion (SW trigger enabled) with LFSR wave generation
APB1_CLK
DHR 0x00
SWTRIG
ai14714
Note: DAC trigger must be enabled for noise generation, by setting the TENx bit in the DAC_CR
register.
CR
TA
EM
EN
EN
EM
TAT
CR
IO
)N
AIC
Figure 47. DAC conversion (SW trigger enabled) with triangle wave generation
APB1_CLK
DHR 0xABE
SWTRIG
ai14714
Note: 1 DAC trigger must be enabled for noise generation, by setting the TENx bit in the DAC_CR
register.
2 MAMPx[3:0] bits must be configured before enabling the DAC, otherwise they cannot be
changed.
DAC_DOR1 (three APB1 clock cycles later). The DAC channel1 triangle counter is then
updated.
When a DAC channel2 trigger arrives, the DAC channel2 triangle counter, with the same
triangle amplitude, is added to the DHR2 register and the sum is transferred into
DAC_DOR2 (three APB1 clock cycles later). The DAC channel2 triangle counter is then
updated.
added to the DHR2 register and the sum is transferred into DAC_DOR2 (three APB1 clock
cycles later). The DAC channel2 triangle counter is then updated.
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DACC2DOR[11:0]
Reserved
r r r r r r r r r r r r
9
8
7
6
5
4
3
2
1
0
DMAEN2
DMAEN1
BOFF2
BOFF1
TEN2
TEN1
WAVE WAVE TSEL1
EN2
EN1
DAC_CR MAMP2[3:0] TSEL2[2:0] MAMP1[3:0]
0x00 Reserved 2[2:0] Reserved 1[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
SWTRIG2
SWTRIG1
DAC_SWTRIG
0x04 R Reserved
Reset value 0 0
DAC_DHR12R
DACC1DHR[11:0]
0x08 1 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
DAC_DHR12L
DACC1DHR[11:0]
0x0C 1 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
DAC_DHR8R1 DACC1DHR[7:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0
DAC_DHR12R
DACC2DHR[11:0]
0x14 2 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
DAC_DHR12L
DACC2DHR[11:0]
0x18 2 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
DAC_DHR8R2 DACC2DHR[7:0]
0x1C Reserved
DAC_DHR12R
DACC2DHR[11:0] DACC1DHR[11:0]
0x20 D Reserved Reserved
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
DAC_DHR12L
DACC2DHR[11:0] DACC1DHR[11:0]
0x24 D Reserved Reserved
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
DAC_DHR8RD DACC2DHR[7:0] DACC1DHR[7:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DAC_DOR1 DACC1DOR[11:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
DAC_DOR2 DACC2DOR[11:0]
0x30 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
"US MATRIX
$-! #H $-!
2ESET CLOCK
#H CONTROL 2##
#H "RIDGE
"RIDGE !0"
!0"
!RBITER
$-!
#H
$-!
!RBITER
!(" 3LAVE
%THERNET -!#
Figure 49. DMA block diagram in low-, medium- high- and XL-density devices
ICode
FLITF Flash
DCode
Cortex-M3
Sys tem
SRAM
Bus matrix
DMA1 Ch.1 DMA FSMC
Ch.2 SDIO
Ch.5
AHB Slave
13.3.2 Arbiter
The arbiter manages the channel requests based on their priority and launches the
peripheral/memory access sequences.
The priorities are managed in two stages:
● Software: each channel priority can be configured in the DMA_CCRx register. There
are four levels:
– Very high priority
– High priority
– Medium priority
– Low priority
● Hardware: if 2 requests have the same software priority level, the channel with the
lowest number will get priority versus the channel with the highest number. For
example, channel 2 gets priority over channel 4.
Note: In high-density, XL-density and connectivity line devices, the DMA1 controller has priority
over the DMA2 controller.
Pointer incrementation
Peripheral and memory pointers can optionally be automatically post-incremented after
each transaction depending on the PINC and MINC bits in the DMA_CCRx register. If
incremented mode is enabled, the address of the next transfer will be the address of the
previous one incremented by 1, 2 or 4 depending on the chosen data size. The first transfer
address is the one programmed in the DMA_CPARx/DMA_CMARx registers. During
transfer operations, 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 is configured in noncircular mode, no DMA request is served after the last
transfer (that is once the number of data items to be transferred has reached zero). In order
to reload a new number of data items to be transferred into the DMA_CNDTRx register, the
DMA channel must be disabled.
Note: If a DMA channel 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 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/DMA_CMARx registers.
Circular mode
Circular mode is available to handle circular buffers and continuous data flows (e.g. ADC
scan mode). This feature can be enabled using the CIRC bit in the DMA_CCRx register.
When circular mode is activated, the number of data to be transferred is automatically
reloaded with the initial value programmed during the channel configuration phase, and the
DMA requests continue to be served.
Memory-to-memory mode
The DMA channels can also work without being triggered by a request from a peripheral.
This mode is called Memory to Memory mode.
If the MEM2MEM bit in the DMA_CCRx register is set, then the channel initiates transfers as
soon as it is enabled by software by setting the Enable bit (EN) in the DMA_CCRx register.
The transfer stops once the DMA_CNDTRx register reaches zero. Memory to Memory
mode may not be used at the same time as Circular mode.
Table 76. Programmable data width & endian behavior (when bits PINC = MINC = 1)
Number
Source of data Destination
Destination Source content:
port items to Transfer operations content:
port width address / data
width transfer address / data
(NDT)
@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 B3[7:0] @0x2 then WRITE 00B2[15:0] @0x4 @0x4 / 00B2
@0x3 / B3 4: READ B4[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 B3[7:0] @0x2 then WRITE 000000B2[31:0] @0x8 @0x8 / 000000B2
@0x3 / B3 4: READ B4[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[7:0] @0x0 @0x0 / B1B0
@0x4 / B7B6B5B4 2: READ B7B6B5B4[31:0] @0x4 then WRITE B5B4[7:0] @0x1 @0x2 / B5B4
32 16 4
@0x8 / BBBAB9B8 3: READ BBBAB9B8[31:0] @0x8 then WRITE B9B8[7:0] @0x2 @0x4 / B9B8
@0xC / BFBEBDBC 4: READ BFBEBDBC[31:0] @0xC then WRITE BDBC[7:0] @0x3 @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
Addressing an AHB peripheral that does not support byte or halfword write
operations
When the DMA initiates an AHB byte or halfword write operation, the data are duplicated on
the unused lanes of the HWDATA[31:0] bus. So when the used AHB slave peripheral does
not support byte or halfword write operations (when HSIZE is not used by the peripheral)
and does not generate any error, the DMA writes the 32 HWDATA bits as shown in the two
examples below:
● To write the halfword “0xABCD”, the DMA sets the HWDATA bus to “0xABCDABCD”
with HSIZE = HalfWord
● To write the byte “0xAB”, the DMA sets the HWDATA bus to “0xABABABAB” with
HSIZE = Byte
Assuming that the AHB/APB bridge is an AHB 32-bit slave peripheral that does not take the
HSIZE data into account, it will transform any AHB byte or halfword operation into a 32-bit
APB operation in the following manner:
● an AHB byte write operation of the data “0xB0” to 0x0 (or to 0x1, 0x2 or 0x3) will be
converted to an APB word write operation of the data “0xB0B0B0B0” to 0x0
● an AHB halfword write operation of the data “0xB1B0” to 0x0 (or to 0x2) will be
converted to an APB word write operation of the data “0xB1B0B1B0” to 0x0
For instance, if you want to write the APB backup registers (16-bit registers aligned to a 32-
bit address boundary), you must configure the memory source size (MSIZE) to “16-bit” and
the peripheral destination size (PSIZE) to “32-bit”.
13.3.6 Interrupts
An interrupt can be produced on a Half-transfer, Transfer complete or Transfer error for each
DMA channel. Separate interrupt enable bits are available for flexibility.
Note: In high-density and XL-density devices, DMA2 Channel4 and DMA2 Channel5 interrupts are
mapped onto the same interrupt vector. In connectivity line devices, DMA2 Channel4 and
DMA2 Channel5 interrupts have separate interrupt vectors. All other DMA1 and DMA2
Channel interrupts have their own interrupt vector.
Channel 1 EN bit
USART3_TX
TIM1_CH1 HW request 2
Channel 2
TIM2_UP
TIM3_CH3 SW trigger (MEM2MEM bit)
SPI1_RX
Channel 2 EN bit
USART3_RX
TIM1_CH2 HW request 3
Channel 3
TIM3_CH4
TIM3_UP
SW trigger (MEM2MEM bit)
SPI1_TX
internal
USART1_TX Channel 3 EN bit
TIM1_CH4 DMA1
TIM1_TRIG HW request 4 request
Channel 4
TIM1_COM
TIM4_CH2
SW trigger (MEM2MEM bit)
SPI/I2S2_RX
I2C2_TX
Channel 4 EN bit
USART1_RX
TIM1_UP
HW request 5
SPI/I2S2_TX Channel 5
TIM2_CH1
TIM4_CH3 SW trigger (MEM2MEM bit)
I2C2_RX
Channel 5 EN bit
USART2_RX
TIM1_CH3 HW REQUEST 6
Channel 6
TIM3_CH1
TIM3_TRIG SW TRIGGER (MEM2MEM bit)
I2C1_TX
Channel 6 EN bit
USART2_TX HW request 7
TIM2_CH2 Channel 7
TIM2_CH4 Low priority
SW trigger (MEM2MEM bit)
TIM4_UP
I2C1_RX
Channel 7 EN bit
DMA2 controller
The 5 requests from the peripherals (TIMx[5,6,7,8], ADC3, SPI/I2S3, UART4,
DAC_Channel[1,2] and SDIO) are simply logically ORed before entering the DMA2, this
means that only one request must be enabled at a time. Refer to Figure 51: DMA2 request
mapping.
The peripheral DMA requests can be independently activated/de-activated by programming
the DMA control bit in the registers of the corresponding peripheral.
Note: The DMA2 controller and its relative requests are available only in high-density, XL-density
and connectivity line devices.
TIM8_CH1 HW request 3
Channel 3
UART4_RX
TIM6_UP/DAC_Channel1
SW trigger (MEM2MEM bit)
internal
Channel 3 EN bit
DMA2
TIM5_CH2 HW request 4 request
SDIO Channel 4
TIM7_UP/DAC_Channel2
SW trigger (MEM2MEM bit)
Channel 4 EN bit
ADC3
HW request 5
TIM8_CH2 Channel 5
TIM5_CH1 LOW PRIORITY
UART4_TX SW trigger (MEM2MEM bit)
Channel 5 EN bit
ADC3(1) ADC3
SPI/I2S3 SPI/I2S3_RX SPI/I2S3_TX
UART4 UART4_RX UART4_TX
(1)
SDIO SDIO
TIM5_CH4 TIM5_CH3
TIM5 TIM5_CH2 TIM5_CH1
TIM5_TRIG TIM5_UP
TIM6/ TIM6_UP/
DAC_Channel1 DAC_Channel1
TIM7_UP/
TIM7
DAC_Channel2
TIM8_CH4
TIM8_CH3
TIM8 TIM8_TRIG TIM8_CH1 TIM8_CH2
TIM8_UP
TIM8_COM
1. ADC3, SDIO and TIM8 DMA requests are available only in high-density and XL-density devices.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TEIF7 HTIF7 TCIF7 GIF7 TEIF6 HTIF6 TCIF6 GIF6 TEIF5 HTIF5 TCIF5 GIF5
Reserved
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
CTEIF7 CHTIF7 CTCIF7 CGIF7 CTEIF6 CHTIF6 CTCIF6 CGIF6 CTEIF5 CHTIF5 CTCIF5 CGIF5
Reserved
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
CTEIF4 CHTIF4 CTCIF4 CGIF4 CTEIF3 CHTIF3 CTCIF3 CGIF3 CTEIF2 CHTIF2 CTCIF2 CGIF2 CTEIF1 CHTIF1 CTCIF1 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
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MEM2
PL[1:0] MSIZE[1:0] PSIZE[1:0] MINC PINC CIRC DIR TEIE HTIE TCIE EN
Res. 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
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
NDT
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
PA
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
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
MA
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
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
HTIF7
HTIF6
HTIF5
HTIF4
HTIF3
HTIF2
HTIF1
TCIF7
TCIF6
TCIF5
TCIF4
TCIF3
TCIF2
TCIF1
TEIF7
TEIF6
TEIF5
TEIF4
TEIF3
TEIF2
TEIF1
GIF7
GIF6
GIF5
GIF4
GIF3
GIF2
GIF1
DMA_ISR
0x000 Reserved
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
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
DMA_IFCR
0x004 Reserved
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
M SIZE [1:0]
MEM2MEM
PSIZE [1:0]
MINC
CIRC
PINC
HTIE
TCIE
PL
TEIE
DIR
EN
DMA_CCR1
0x008 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CNDTR1 NDT[15:0]
0x00C Reserved
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
M SIZE [1:0]
MEM2MEM
PSIZE [1:0]
MINC
CIRC
PINC
HTIE
TCIE
PL
TEIE
DIR
EN
DMA_CCR2
0x01C Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CNDTR2 NDT[15:0]
0x020 Reserved
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
M SIZE [1:0]
MEM2MEM
PSIZE [1:0]
MINC
CIRC
PINC
HTIE
TCIE
PL
TEIE
DIR
EN
DMA_CCR3
0x030 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CNDTR3 NDT[15:0]
0x034 Reserved
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
M SIZE [1:0]
MEM2MEM
PSIZE [1:0]
MINC
CIRC
PINC
HTIE
TCIE
PL
TEIE
DIR
EN
DMA_CCR4
0x044 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CNDTR4 NDT[15:0]
0x048 Reserved
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
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
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
M SIZE [1:0]
MEM2MEM
PSIZE [1:0]
MINC
CIRC
PINC
HTIE
TCIE
PL
TEIE
DIR
EN
DMA_CCR5
0x058 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CNDTR5 NDT[15:0]
0x05C Reserved
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
M SIZE [1:0]
MEM2MEM
PSIZE [1:0]
MINC
CIRC
PINC
HTIE
TCIE
PL
TEIE
DIR
EN
DMA_CCR6
0x06C Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CNDTR6 NDT[15:0]
0x070 Reserved
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
M SIZE [1:0]
MEM2MEM
PSIZE [1:0]
MINC
CIRC
PINC
HTIE
TCIE
PL
TEIE
DIR
EN
DMA_CCR7
0x080 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_CNDTR7 NDT[15:0]
0x084 Reserved
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
0x090 Reserved
TI1F_ED
TI1FP1 Encoder
TI2FP2 Interface
REP Register
UI
U AutoReload Register
Repetition
counter U
Stop, Clear or Up/Down
ETRF
BRK BI
TIMx_BKIN Polarity Selection
Notes:
Reg Preload registers transferred
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 54 and Figure 55 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 53. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
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
Figure 54. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 00 01
Prescaler buffer 0 3
Prescaler counter 0 0 1 2 3 0 1 2 3
preload registers. Then no update event occurs until the UDIS bit has been written to 0.
However, the counter restarts from 0, as well as the counter of the prescaler (but the
prescale rate does not 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 auto-reload shadow register is updated with the preload value (TIMx_ARR),
● The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_PSC
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
Counter register 1F 20 00
Counter overflow
Figure 59. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
CK_PSC
CEN
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
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). 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
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
CK_PSC
CNT_EN
Counter underflow
CK_PSC
CNT_EN
Counter underflow
CK_PSC
Counter register 20 1F 00 36
Counter underflow
Figure 65. Counter timing diagram, update event when repetition counter
is not used
CK_PSC
CEN
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
Auto-reload register FF 36
The UEV update event can be disabled by software by setting the UDIS bit in the 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 continues counting up and down, based on the current auto-reload
value.
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an UEV update event 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 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 66. Counter timing diagram, internal clock divided by 1, TIMx_ARR = 0x6
CK_PSC
CNT_EN
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 14.4: TIM1&TIM8 registers on page 323).
CK_PSC
CNT_EN
Counter underflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
Counter register 20 1F 01 00
Counter underflow
Figure 70. Counter timing diagram, update event with ARPE=1 (counter underflow)
CK_PSC
CEN
Counter register 06 05 04 03 02 01 00 01 02 03 04 05 06 07
Counter underflow
Figure 71. 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
Figure 72. Update rate examples depending on mode and TIMx_RCR register
settings
Upcounting Downcounting
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) (by SW) (by SW)
UEV Update Event: Preload registers transferred to active registers and update interrupt generated
Internal clock
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
TI2F or
or
TI1F or encoder
ITRx 0xx mode
TI1_ED 100
TI1FP1 101 TRGI external clock
TI2F_Rising
mode 1 CK_PSC
0
TI2 Filter Edge TI2FP2 110
Detector TI2F_Falling ETRF external clock
1 ETRF 111 mode 2
ICF[3:0] CC2P CK_INT internal clock
TIMx_CCMR1 TIMx_CCER mode
(internal clock)
ECE SMS[2:0]
TIMx_SMCR
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 you don’t 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
TI2F or
or
TI1F or encoder
mode
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.
fCK_INT
CNT_EN
ETR
ETRP
ETRF
Counter register 34 35 36
TI1F_ED
to the slave mode controller
TI1F_Rising 0
TI1 TI1F
filter Edge TI1FP1
01
fDTS downcounter Detector TI1F_Falling
1
TI2FP1 IC1 divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P/CC1NP TRC
TIMx_CCER 11
TIMx_CCMR1 (from slave mode
controller)
TI2F_rising 0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
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
(if 16-bit)
8 8
high
low
S write CCR1H
read CCR1H S write_in_progress
read_in_progress
Capture/compare preload register write CCR1L
read CCR1L R
R CC1S[1]
output
capture_transfer compare_transfer mode
CC1S[0]
CC1S[1] input
mode OC1PE
Capture/compare shadow register OC1PE
CC1S[0] UEV
TIM1_CCMR1
comparator (from time
IC1PS capture base unit)
CC1E CNT>CCR1
Counter
CNT=CCR1
CC1G
TIM1_EGR
ETR 0
Output OC1
‘0’ enable
x0 1 circuit
10
OC1_DT CC1P
CNT>CCR1 11
Output mode OC1REF Dead-time TIM1_CCER
CNT=CCR1 controller generator
OC1N_DT
11
10 0 OC1N
Output
‘0’ 0x enable
1 circuit
OC1CE OC1M[2:0] DTG[7:0] CC1NE CC1E CC1NP MOE OSSI OSSR TIM1_BDTR
TIM1_CCMR1 TIM1_BDTR TIM1_CCER TIM1_CCER
CC4P
CNT > CCR4
Output mode OC4 REF TIM1_CCER
CNT = CCR4 controller
CC4E TIM1_CCER
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.
The following example shows how to capture the counter value in TIMx_CCR1 when TI1
input rises. To do this, use the following procedure:
● Select the active input: TIMx_CCR1 must be linked to the TI1 input, so write the CC1S
bits to 01 in the TIMx_CCMR1 register. As soon as CC1S becomes different from 00,
the channel is configured in input and the TIMx_CCR1 register becomes read-only.
● Program the input filter duration you need with respect to the signal you connect to the
timer (when the input is one of the TIx (ICxF bits in the TIMx_CCMRx register). Let’s
imagine that, when toggling, the input signal is not stable during at must 5 internal clock
cycles. We must program a filter duration longer than these 5 clock cycles. We can
validate a transition on TI1 when 8 consecutive samples with the new level have been
detected (sampled at fDTS frequency). Then write IC1F bits to 0011 in the
TIMx_CCMR1 register.
● Select the edge of the active transition on the TI1 channel by writing CC1P bit to 0 in
the TIMx_CCER register (rising edge in this case).
● 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).
● Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
● 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, you 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):
● Select the active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1
register (TI1 selected).
● Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter
clear): write the CC1P bit to ‘0’ (active on rising edge).
● Select the active input for TIMx_CCR2: write the CC2S bits to 10 in the TIMx_CCMR1
register (TI1 selected).
● Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P
bit to ‘1’ (active on falling edge).
● Select the valid trigger input: write the TS bits to 101 in the TIMx_SMCR register
(TI1FP1 selected).
● Configure the slave mode controller in reset mode: write the SMS bits to 100 in the
TIMx_SMCR register.
● Enable the captures: write the CC1E and CC2E bits to ‘1’ in the TIMx_CCER register.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
1. The PWM input mode can be used only with the TIMx_CH1/TIMx_CH2 signals due to the fact that only
TI1FP1 and TI2FP2 are connected to the slave mode controller.
Anyway, the comparison between the TIMx_CCRx shadow register and the counter is still
performed and allows the flag to be set. Interrupt and DMA requests can be sent
accordingly. This is described in the output compare mode section below.
oc1ref=OC1
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
● Downcounting configuration
Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to Section :
Downcounting mode on page 289
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.
#OUNTER REGISTER
/#X2%&
##2X
##X)& #-3
#-3
#-3
/#X2%&
##2X
#-3 OR
##X)&
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
AIB
OCxREF
OCx
delay
OCxN
delay
Figure 87. Dead-time waveforms with delay greater than the negative pulse.
OCxREF
OCx
delay
OCxN
Figure 88. Dead-time waveforms with delay greater than the positive pulse.
OCxREF
OCx
OCxN
delay
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 14.4.18: TIM1&TIM8 break and dead-
time register (TIMx_BDTR) on page 344 for delay calculation.
must insert a delay (dummy instruction) before reading it correctly. This is because you write
the asynchronous signal and read the synchronous signal.
When a break occurs (selected level on the break input):
● The MOE bit is cleared asynchronously, putting the outputs in inactive state, idle state
or in reset state (selected by the OSSI bit). This feature functions even if the MCU
oscillator is off.
● Each output channel is driven with the level programmed in the OISx bit in the
TIMx_CR2 register as soon as MOE=0. If OSSI=0 then the timer releases the enable
output else the enable output remains high.
● When complementary outputs are used:
– The outputs are first put in reset state inactive state (depending on the polarity).
This is done asynchronously so that it works even if no clock is provided to the
timer.
– If the timer clock is still present, then the dead-time generator is reactivated in
order to drive the outputs with the level programmed in the OISx and OISxN bits
after a dead-time. Even in this case, OCx and OCxN cannot be driven to their
active level together. Note that because of the resynchronization on MOE, the
dead-time duration is a bit longer than usual (around 2 ck_tim clock cycles).
– If OSSI=0 then the timer releases the enable outputs else the enable outputs
remain or become high as soon as one of the CCxE or CCxNE bits is high.
● The break status flag (BIF bit in the TIMx_SR register) is set. An interrupt can be
generated if the BIE bit in the TIMx_DIER register is set. A DMA request can be sent if
the BDE bit in the TIMx_DIER register is set.
● If the AOE bit in the TIMx_BDTR register is set, the MOE bit is automatically set again
at the next update event UEV. This can be used to perform a regulation, for instance.
Else, MOE remains low until you write it to ‘1’ again. In this case, it can be used for
security and you can connect the break input to an alarm from power drivers, thermal
sensors or any security components.
Note: The break inputs is acting on level. Thus, the MOE cannot be set while the break input is
active (neither automatically nor by software). In the meantime, the status flag BIF cannot be
cleared.
The break can be generated by the BRK input which has a programmable polarity and an
enable bit BKE in the TIMx_BDTR Register.
In addition to the break input and the output management, a write protection has been
implemented inside the break circuit to safeguard the application. It allows you to freeze the
configuration of several parameters (dead-time duration, OCx/OCxN polarities and state
when disabled, OCxM configurations, break enable and polarity). You can choose from 3
levels of protection selected by the LOCK bits in the TIMx_BDTR register. Refer to
Section 14.4.18: TIM1&TIM8 break and dead-time register (TIMx_BDTR) on page 344. The
LOCK bits can be written only once after an MCU reset.
Figure 89 shows an example of behavior of the outputs in response to a break.
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)
(CCRx)
counter (CNT)
ETRF
OCxREF
(OCxCE=’0’)
OCxREF
(OCxCE=’1’)
OCREF_CLR OCREF_CLR
becomes high still high
OCxREF
Write COM to 1
COM event
CCxE=1 write OCxM to 100 CCxE=1
CCxNE=0 CCxNE=0
OCxM=100 (forced inactive) OCxM=100
OCx
Example 1
OCxN
Write CCxNE to 1
and OCxM to 101 CCxE=0
CCxE=1 CCxNE=1
CCxNE=0 OCxM=101
OCx OCxM=100 (forced inactive)
Example 2
OCxN
write CCxNE to 0
CCxE=1
and OCxM to 100 CCxE=1
CCxNE=0 CCxNE=0
OCxM=100 (forced inactive) OCxM=100
OCx
Example 3
OCxN
ai14910
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY t
tPULSE
For example you 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:
● Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.
● TI2FP2 must detect a rising edge, write CC2P=’0’ in the TIMx_CCER register.
● Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=’110’ in
the TIMx_SMCR register.
● 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 you 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 you enable PWM mode 2 by writing OC1M=111 in the TIMx_CCMR1
register. You can optionally enable the preload registers by writing OC1PE=’1’ in the
TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this case you have 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.
You only want 1 pulse (Single mode), so you write '1 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 you want to output a waveform with the minimum delay, you can set the OCxFE bit 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.
repetition counter, trigger output features continue to work as normal. Encoder mode and
External clock mode 2 are not compatible and must not be selected together.
In this mode, the counter is modified automatically following the speed and the direction of
the incremental encoder and its content, therefore, always represents the encoder’s
position. The count direction correspond to the rotation direction of the connected sensor.
The table summarizes the possible combinations, assuming TI1 and TI2 don’t switch at the
same time.
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 93 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’ (TIMx_CCER register, TI1FP1 non-inverted, TI1FP1=TI1).
● CC2P=’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
Figure 94 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=’1’).
Figure 94. Example of encoder interface mode with TI1FP1 polarity inverted.
forward jitter backward jitter forward
TI1
TI2
Counter
down up down
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. You can obtain dynamic information (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. You can do this 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.
written after a COM event for the next step (this can be done in an interrupt subroutine
generated by the rising edge of OC2REF).
Figure 95 describes this example.
TIH1
TIH2
TIH3
Interfacing timer
counter (CNT)
(CCR2)
TRGO=OC2REF
advanced-control timers (TIM1&TIM8)
COM
OC1
OC1N
OC2
OC2N
OC3
OC3N
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
TI1
cnt_en
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
TI2
cnt_en
Counter register 34 35 36 37 38
TIF
TI1
CEN/CNT_EN
ETR
Counter register 34 35 36
TIF
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CKD[1:0] ARPE CMS[1:0] DIR OPM URS UDIS CEN
Reserved
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
OIS4 OIS3N OIS3 OIS2N OIS2 OIS1N OIS1 TI1S MMS[2:0] CCDS CCUS CCPC
Res. Res.
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
ETP ECE ETPS[1:0] ETF[3:0] MSM TS[2:0] Res. SMS[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw Res. rw 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] OC1M[2:0]
CE PE FE CC2S[1:0] CE PE FE CC1S[1:0]
IC2F[3:0] IC2PSC[1:0] IC1F[3:0] IC1PSC[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Table 83. Output control bits for complementary OCx and OCxN channels with
break feature
Control bits Output states(1)
MOE OSSI OSSR CCxE CCxNE
OCx output state OCxN output state
bit bit bit bit bit
Output Disabled (not driven by Output Disabled (not driven by the
0 0 0 the timer) timer)
OCx=0, OCx_EN=0 OCxN=0, OCxN_EN=0
Output Disabled (not driven by
OCxREF + Polarity OCxN=OCxREF
0 0 1 the timer)
xor CCxNP, OCxN_EN=1
OCx=0, OCx_EN=0
OCxREF + Polarity Output Disabled (not driven by the
0 1 0 OCx=OCxREF xor CCxP, timer)
OCx_EN=1 OCxN=0, OCxN_EN=0
Complementary to OCREF (not
OCREF + Polarity + dead-time
0 1 1 OCREF) + Polarity + dead-time
OCx_EN=1
OCxN_EN=1
1 X
Output Disabled (not driven by Output Disabled (not driven by the
1 0 0 the timer) timer)
OCx=CCxP, OCx_EN=0 OCxN=CCxNP, OCxN_EN=0
Off-State (output enabled with OCxREF + Polarity
1 0 1 inactive state) OCxN=OCxREF xor CCxNP,
OCx=CCxP, OCx_EN=1 OCxN_EN=1
OCxREF + Polarity Off-State (output enabled with
1 1 0 OCx=OCxREF xor CCxP, inactive state)
OCx_EN=1 OCxN=CCxNP, OCxN_EN=1
Complementary to OCREF (not
OCREF + Polarity + dead-time
1 1 1 OCREF) + Polarity + dead-time
OCx_EN=1
OCxN_EN=1
0 0 0 Output Disabled (not driven by the timer)
0 0 1 Asynchronously: OCx=CCxP, OCx_EN=0, OCxN=CCxNP,
OCxN_EN=0
0 1 0
Then if the clock is present: OCx=OISx and OCxN=OISxN after a
0 1 1 dead-time, assuming that OISx and OISxN do not correspond to OCX
1 0 0 and OCxN both in active state.
0 X
1 0 1 Off-State (output enabled with inactive state)
1 1 0 Asynchronously: OCx=CCxP, OCx_EN=1, OCxN=CCxNP,
OCxN_EN=1
Then if the clock is present: OCx=OISx and OCxN=OISxN after a
1 1 1 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 (CCxE = CCxNE = 0), 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 the GPIO and AFIO registers.
Note: As the bits 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.
9
8
7
6
5
4
3
2
1
0
ARPE
UDIS
OPM
CKD CMS
URS
CEN
DIR
TIMx_CR1
0x00 Reserved [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0
OIS3N
OIS2N
OIS1N
Reserved
CCPC
CCDS
CCUS
OIS4
OIS3
OIS2
OIS1
TI1S
TIMx_CR2 MMS[2:0]
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CC3IE Reserved
MSM
ETPS
ECE
ETP
TIMx_SMCR ETF[3:0] TS[2:0] SMS[2:0]
0x08 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
COMDE
CC4DE
CC3DE
CC2DE
CC1DE
COMIE
CC4IE
CC2IE
CC1IE
UDE
TDE
UIE
BIE
TIE
TIMx_DIER
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CC4OF
CC3OF
CC2OF
CC1OF
COMIF
Reserved
CC4IF
CC3IF
CC2IF
CC1IF
UIF
BIF
TIF
TIMx_SR
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
CC4G
CC3G
CC2G
CC1G
COM
UG
BG
TG
TIMx_EGR
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0
TIMx_CCMR1
OC2CE
OC1CE
OC2PE
OC1PE
OC2FE
OC1FE
OC2M CC2S OC1M CC1S
Output Compare
Reserved [2:0] [1:0] [2:0] [1:0]
mode
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC2 IC1
CC2S CC1S
Input Capture IC2F[3:0] PSC IC1F[3:0] PSC
Reserved [1:0] [1:0]
mode [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCMR2
OC3CE
OC4PE
OC3PE
OC4FE
OC3FE
O24CE
CC2NP
CC2NE
CC1NP
CC1NE
CC4P
CC4E
CC3P
CC3E
CC2P
CC2E
CC1P
CC1E
TIMx_CCER
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CNT CNT[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_ARR ARR[15:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_RCR REP[7:0]
0x30 Reserved
Reset value 0 0 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
TIMx_CCR1 CCR1[15:0]
0x34 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR2 CCR2[15:0]
0x38 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR3 CCR3[15:0]
0x3C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR4 CCR4[15:0]
0x40 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OSSR
OSSI
MOE
LOCK
AOE
BKP
BKE
TIMx_BDTR DT[7:0]
0x44 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_DMAR DMAB[15:0]
0x4C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TI1FP1 Encoder
TI2FP2 Interface
U Autoreload register UI
Notes:
Reg Preload registers transferred
to active registers on U event
according to control bit
event
The auto-reload register is preloaded. Writing to or reading from the auto-reload register
accesses the preload register. The content of the preload register are transferred into the
shadow register permanently or at each update event (UEV), depending on the auto-reload
preload enable bit (ARPE) in TIMx_CR1 register. The update event is sent when the counter
reaches the overflow (or underflow when downcounting) and if the UDIS bit equals 0 in the
TIMx_CR1 register. It can also be generated by software. The generation of the update
event is described in detail for each configuration.
The counter is clocked by the prescaler output CK_CNT, which is enabled only when the
counter enable bit (CEN) in TIMx_CR1 register is set (refer also to the slave mode controller
description to get more details on counter enabling).
Note that the actual counter enable signal CNT_EN is set 1 clock cycle after CEN.
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 101 and Figure 102 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 101. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CNT_EN
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
Figure 102. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CNT_EN
Counter register F7 F8 F9 FA FB FC 00 01
Prescaler buffer 0 3
Prescaler counter 0 0 1 2 3 0 1 2 3
CK_INT
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_INT
CNT_EN
Counter overflow
CK_INT
CNT_EN
Counter overflow
CK_INT
Counter register 1F 20 00
Counter overflow
Figure 107. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_INT
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
Figure 108. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CNT_EN
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
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_INT
CNT_EN
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
CK_INT
CNT_EN
Counter underflow
CK_INT
CNT_EN
Counter underflow
CK_INT
Counter register 20 1F 00 36
Counter underflow
Figure 113. Counter timing diagram, Update event when repetition counter
is not used
CK_INT
CNT_EN
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
Auto-reload register FF 36
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 the UDIS bit has been written to 0.
However, the counter continues counting up and down, based on the current auto-reload
value.
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 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_INT
CNT_EN
Counter register 04 03 02 01 00 01 02 03 04 05 06 05 04 03
Counter underflow
Counter overflow
1. Here, center-aligned mode 1 is used (for more details refer to Section 15.4.1: TIMx control register 1 (TIMx_CR1) on
page 388).
CK_INT
CNT_EN
Counter underflow
CK_INT
CNT_EN
CK_INT
Counter register 20 1F 01 00
Counter underflow
Figure 118. Counter timing diagram, Update event with ARPE=1 (counter underflow)
CK_INT
CNT_EN
Counter register 06 05 04 03 02 01 00 01 02 03 04 05 06 07
Counter underflow
Figure 119. Counter timing diagram, Update event with ARPE=1 (counter overflow)
CK_INT
CNT_EN
Counter register F7 F8 F9 FA FB FC 36 35 34 33 32 31 30 2F
Counter overflow
CK_INT
CEN=CNT_EN
UG
CNT_INIT
COUNTER REGISTER 31 32 33 34 35 36 00 01 02 03 04 05 06 07
TI2F or
or
TI1F or encoder
ITRx 001 mode
TI1F_ED 100
TI1FP1 101 TRGI external clock
TI2F_Rising
mode 1 CK_PSC
0
TI2 Filter Edge TI2FP2 110
Detector TI2F_Falling ETRF external clock
1 ETRF 111 mode 2
ICF[3:0] CC2P CK_INT internal clock
TIMx_CCMR1 TIMx_CCER mode
(internal clock)
ECE SMS[2:0]
TIMx_SMCR
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
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 you don’t need to configure it.
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 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
TI2F or
or
TI1F or encoder
mode
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.
CK_INT
CNT_EN
ETR
ETRP
ETRF
Counter register 34 35 36
TI1F_ED
to the slave mode controller
TI1F_Rising 0
TI1 TI1F
filter Edge TI1FP1
01
fDTS downcounter Detector TI1F_Falling
1
TI2FP1 IC1 divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P TRC
11
TIMx_CCMR1 TIMx_CCER (from slave mode
controller)
TI2F_rising 0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
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
(if 16-bit)
8 8
high
low
S write CCR1H
read CCR1H S write_in_progress
read_in_progress
Capture/Compare Preload Register write CCR1L
read CCR1L R
R CC1S[1]
output
capture_transfer compare_transfer mode
CC1S[0]
CC1S[1] input
mode OC1PE
Capture/Compare Shadow Register OC1PE
CC1S[0] UEV
TIMx_CCMR1
comparator (from time
IC1PS capture base unit)
CC1E CNT>CCR1
Counter
CNT=CCR1
CC1G
TIMx_EGR
OCREF_CLR
0
ocref_clr_int
ETRF 1
To the master mode 0
controller Output OC1
OCCS Enable
1 Circuit
TIMx_SMCR
CC1P
CNT > CCR1
Output mode oc1ref TIMx_CCER
CNT = CCR1 controller
CC1E
OC1M[2:0] TIMx_CCER
TIMx_CCMR1 ai17187
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.
● Select the edge of the active transition on the TI1 channel by writing the CC1P bit to 0
in the TIMx_CCER register (rising edge in this case).
● 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).
● Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
● 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, you 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):
● Select the active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1
register (TI1 selected).
● Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter
clear): write the CC1P to ‘0’ (active on rising edge).
● Select the active input for TIMx_CCR2: write the CC2S bits to 10 in the TIMx_CCMR1
register (TI1 selected).
● Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P
bit to ‘1’ (active on falling edge).
● Select the valid trigger input: write the TS bits to 101 in the TIMx_SMCR register
(TI1FP1 selected).
● Configure the slave mode controller in reset mode: write the SMS bits to 100 in the
TIMx_SMCR register.
● Enable the captures: write the CC1E and CC2E bits to ‘1 in the TIMx_CCER register.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
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.
OC1REF=OC1
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
Downcounting configuration
Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to Section :
Downcounting mode on page 357.
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.
#OUNTER REGISTER
/#X2%&
##2X
##X)& #-3
#-3
#-3
/#X2%&
##2X
#-3 OR
##X)&
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
gg
/#X2%&
##2X
##X)& #-3
#-3
#-3
AIB
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY
tPULSE t
For example you 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:
● Map TI2FP2 on TI2 by writing IC2S=01 in the TIMx_CCMR1 register.
● TI2FP2 must detect a rising edge, write CC2P=0 in the TIMx_CCER register.
● Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=110 in
the TIMx_SMCR register.
● 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 you 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 you enable PWM mode 2 by writing OC1M=111 in the TIMx_CCMR1
register. You can optionally enable the preload registers by writing OC1PE=1 in the
TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this case you have 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.
You only want 1 pulse (Single mode), so you write '1 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.
(CCRx)
counter (CNT)
ETRF
OCxREF
(OCxCE=0)
OCxREF
(OCxCE=1)
OCREF_CLR OCREF_CLR
becomes high still high
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 134 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=0 (TIMx_CCER register, TI1FP1 noninverted, TI1FP1=TI1)
● CC2P=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
Figure 135 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=1).
Figure 135. Example of encoder interface mode with TI1FP1 polarity inverted
forward jitter backward jitter forward
TI1
TI2
Counter
down up down
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. You can obtain dynamic information (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. You can do this 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.
prescaler is not used for triggering, so you don’t need to configure it. The CC1S bits
select the input capture source only, CC1S = 01 in the TIMx_CCMR1 register. Write
CC1P=0 in TIMx_CCER register to validate the polarity (and detect rising edges only).
● Configure the timer in reset mode by writing SMS=100 in TIMx_SMCR register. Select
TI1 as the input source by writing TS=101 in TIMx_SMCR register.
● Start the counter by writing CEN=1 in the TIMx_CR1 register.
The counter starts counting on the internal clock, then behaves normally until TI1 rising
edge. When TI1 rises, the counter is cleared and restarts from 0. In the meantime, the
trigger flag is set (TIF bit in the TIMx_SR register) and an interrupt request, or a DMA
request can be sent if enabled (depending on the TIE and TDE bits in TIMx_DIER register).
The following figure shows this behavior when the auto-reload register TIMx_ARR=0x36.
The delay between the rising edge on TI1 and the actual reset of the counter is due to the
resynchronization circuit on TI1 input.
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
TI1
CNT_EN
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
TI2
CNT_EN
Counter register 34 35 36 37 38
TIF
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 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
TIM1 TIM2
Input
trigger
selection
For example, you can configure Timer 1 to act as a prescaler for Timer 2. Refer to
Figure 140. To do this:
● Configure Timer 1 in master mode so that it outputs a periodic trigger signal on each
update event UEV. If you write MMS=010 in the TIM1_CR2 register, a rising edge is
output on TRGO1 each time an update event is generated.
● To connect the TRGO1 output of Timer 1 to Timer 2, Timer 2 must be configured in
slave mode using ITR1 as internal trigger. You select this through the TS bits in the
TIM2_SMCR register (writing TS=000).
● Then you put the slave mode controller in external clock mode 1 (write SMS=111 in the
TIM2_SMCR register). This causes Timer 2 to be clocked by the rising edge of the
periodic Timer 1 trigger signal (which correspond to the timer 1 counter overflow).
● Finally both timers must be enabled by setting their respective CEN bits (TIMx_CR1
register).
Note: If OCx is selected on Timer 1 as trigger output (MMS=1xx), its rising edge is used to clock
the counter of timer 2.
OC1REF of Timer 1 is high. Both counter clock frequencies are divided by 3 by the
prescaler compared to CK_INT (fCK_CNT = fCK_INT/3).
● Configure Timer 1 master mode to send its Output Compare 1 Reference (OC1REF)
signal as trigger output (MMS=100 in the TIM1_CR2 register).
● Configure the Timer 1 OC1REF waveform (TIM1_CCMR1 register).
● Configure Timer 2 to get the input trigger from Timer 1 (TS=000 in the TIM2_SMCR
register).
● Configure Timer 2 in gated mode (SMS=101 in TIM2_SMCR register).
● Enable Timer 2 by writing ‘1 in the CEN bit (TIM2_CR1 register).
● Start Timer 1 by writing ‘1 in the CEN bit (TIM1_CR1 register).
Note: The counter 2 clock is not synchronized with counter 1, this mode only affects the Timer 2
counter enable signal.
CK_INT
TIMER1-OC1REF
TIMER1-CNT FC FD FE FF 00 01
TIMER 2-TIF
Write TIF=0
In the example in Figure 141, the Timer 2 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 Timer 1. You can then write any value
you want 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, we synchronize Timer 1 and Timer 2. Timer 1 is the master and starts
from 0. Timer 2 is the slave and starts from 0xE7. The prescaler ratio is the same for both
timers. Timer 2 stops when Timer 1 is disabled by writing ‘0 to the CEN bit in the TIM1_CR1
register:
● Configure Timer 1 master mode to send its Output Compare 1 Reference (OC1REF)
signal as trigger output (MMS=100 in the TIM1_CR2 register).
● Configure the Timer 1 OC1REF waveform (TIM1_CCMR1 register).
● Configure Timer 2 to get the input trigger from Timer 1 (TS=000 in the TIM2_SMCR
register).
● Configure Timer 2 in gated mode (SMS=101 in TIM2_SMCR register).
● Reset Timer 1 by writing ‘1 in UG bit (TIM1_EGR register).
● Reset Timer 2 by writing ‘1 in UG bit (TIM2_EGR register).
● Initialize Timer 2 to 0xE7 by writing ‘0xE7’ in the timer 2 counter (TIM2_CNTL).
● Enable Timer 2 by writing ‘1 in the CEN bit (TIM2_CR1 register).
● Start Timer 1 by writing ‘1 in the CEN bit (TIM1_CR1 register).
● Stop Timer 1 by writing ‘0 in the CEN bit (TIM1_CR1 register).
CK_INT
TIMER1-CEN=CNT_EN
TIMER1-CNT_INIT
TIMER1-CNT 75 00 01 02
TIMER2-CNT AB 00 E7 E8 E9
TIMER2-CNT_INIT
TIMER2
write CNT
TIMER 2-TIF
Write TIF=0
CK_INT
TIMER1-UEV
TIMER1-CNT FD FE FF 00 01 02
TIMER2-CNT 45 46 47 48
TIMER2-CEN=CNT_EN
TIMER 2-TIF
Write TIF=0
As in the previous example, you can initialize both counters before starting counting.
Figure 144 shows the behavior with the same configuration as in Figure 143 but in trigger
mode instead of gated mode (SMS=110 in the TIM2_SMCR register).
CK_INT
TIMER1-CEN=CNT_EN
TIMER1-CNT_INIT
TIMER1-CNT 75 00 01 02
TIMER2-CNT CD 00 E7 E8 E9 EA
TIMER2-CNT_INIT
TIMER2
write CNT
TIMER 2-TIF
Write TIF=0
CK_INT
TIMER 1-TI1
TIMER1-CEN=CNT_EN
TIMER 1-CK_PSC
TIMER1-CNT 00 01 02 03 04 05 06 07 08 09
TIMER1-TIF
TIMER2-CEN=CNT_EN
TIMER 2-CK_PSC
TIMER2-CNT 00 01 02 03 04 05 06 07 08 09
TIMER2-TIF
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.
Offset Register
9
8
7
6
5
4
3
2
1
0
ARPE
UDIS
OPM
CEN
URS
CKD CMS
DIR
TIMx_CR1
[1:0] [1:0]
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
CCDS
TI1S
MMS[2:0
TIMx_CR2 Reserve
]
0x04 Reserved
d
Reset value 0 0 0 0 0
ETP
MSM
Reserved
ECE
ETP
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
COMDE
CC4DE
CC3DE
CC2DE
CC1DE
CC4IE
CC3IE
CC2IE
CC1IE
Reserved
Reserved
UDE
TDE
UIE
TIE
TIMx_DIER
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
CC4OF
CC3OF
CC2OF
CC1OF
CC4IF
CC3IF
CC2IF
CC1IF
Reserved
Reserved
UIF
TIF
TIMx_SR
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
CC4G
CC3G
CC2G
CC1G
Reserved
UG
TG
TIMx_EGR
0x14 Reserved
Reset value 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
TIMx_CCMR1
OC2CE
OC1CE
OC2PE
OC1PE
OC2FE
OC1FE
CC2 CC1
Output OC2M OC1M
S S
Compare [2:0] [2:0]
Reserved [1:0] [1:0]
mode
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC2 CC2 IC1 CC1
Input Capture IC2F[3:0] PSC S IC1F[3:0] PSC S
mode Reserved [1:0] [1:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCMR2
OC3CE
OC4PE
OC3PE
OC4FE
OC3FE
O24CE
CC4 CC3
Output OC4M OC3M
S S
Compare [2:0] [2:0]
Reserved [1:0] [1:0]
mode
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x1C
TIMx_CCMR2 IC4 CC4 IC3 CC3
Input Capture IC4F[3:0] PSC S IC3F[3:0] PSC S
mode Reserved [1:0] [1:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CC4P
CC4E
CC3P
CC3E
CC2P
CC2E
CC1P
CC1E
Reserved
Reserved
Reserved
TIMx_CCER
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0
TIMx_CNT CNT[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_ARR ARR[15:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x30 Reserved
TIMx_CCR1 CCR1[15:0]
0x34 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR2 CCR2[15:0]
0x38 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR3 CCR3[15:0]
0x3C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR4 CCR4[15:0]
0x40 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x44 Reserved
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
TIMx_DCR DBL[4:0] DBA[4:0]
Reserve
0x48 Reserved
d
Reset value 0 0 0 0 0 0 0 0 0 0
TIMx_DMAR DMAB[15:0]
0x4C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ITR0
Trigger
ITR1 TGI controller
ITR
ITR2 TRC TRGI
ITR3 Slave
Reset, Enable, Count
mode
TI1F_ED controller
TI1FP1
TI2FP2
U Auto-reload register UI
Stop, Clear
U
CK_PSC PSC CK_CNT CNT
+/-
Prescaler COUNTER
CC1I CC1I
TI1 TI1FP1
Input filter &
IC1 IC1PS U OC1REF output OC1
TIMx_CH1 TI1FP2 Prescaler Capture/Compare 1 register TIMx_CH1
Edge detector control
TRC
CC2I
CC2I
TI2FP1 IC2 IC2PS U
TI2 Input filter & OC2REF output OC2
TIMx_CH2
TIMx_CH2 TI2FP2 Prescaler Capture/Compare 2 register
Edge detector control
TRC
Notes:
Reg Preload registers transferred
to active registers on U event
according to control bit
event
interrupt
ai17190
5 !UTORELOAD REGISTER 5)
3TOP #LEAR
5
#+?03# 03# #+?#.4 #.4
PRESCALER COUNTER
##) ##)
4) 4)&0 )# 5
)NPUT FILTER )#03 OUTPUT
4)-X?#( 0RESCALER #APTURE#OMPARE REGISTER /#2%& /#
4)-X?#(
EDGE DETECTOR CONTROL
.OTES
EVENT
-36
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 149 and Figure 150 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 148. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
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
Figure 149. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Counter register F7 F8 F9 FA FB FC 00 01
Prescaler buffer 0 3
Prescaler counter 0 0 1 2 3 0 1 2 3
setting the UIF flag (thus no interrupt 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 auto-reload shadow register is updated with the preload value (TIMx_ARR),
● The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_PSC
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
CNT_EN
Counter overflow
CK_PSC
Counter register 1F 20 00
Counter overflow
Figure 154. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
Figure 155. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CEN
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Internal clock
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
TI2F or
or
TI1F or
ITRx 0xx
TI1_ED
100
TI1FP1 101 TRGI external clock
TI2F_Rising 0
mode 1 CK_PSC
TI2 Filter Edge TI2FP2 110
Detector TI2F_Falling
1
CK_INT internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
SMS[2:0]
TIMx_SMCR
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 the 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 you don’t 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
TI1F_ED
to the slave mode controller
TI1F_Rising 0
TI1 TI1F
filter Edge TI1FP1
01
fDTS downcounter Detector TI1F_Falling
1
TI2FP1 IC1 divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P/CC1NP TRC
11
TIMx_CCMR1 TIMx_CCER (from slave mode
controller)
TI2F_rising 0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
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
(if 16-bit)
8 8
high
low
S write CCR1H
read CCR1H S write_in_progress
read_in_progress
Capture/compare preload register write CCR1L
read CCR1L R
R CC1S[1]
output
capture_transfer compare_transfer mode
CC1S[0]
CC1S[1] input
mode OC1PE
Capture/compare shadow register OC1PE
CC1S[0] UEV
TIM1_CCMR1
comparator (from time
IC1PS capture base unit)
CC1E CNT>CCR1
Counter
CNT=CCR1
CC1G
TIM1_EGR
##0
#.4 ##2
/UTPUT MODE /#?2%& 4)-X?##%2
#.4 ##2 CONTROLLER
##% 4)-X?##%2
/#-;=
4)-X?##-2
AI
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.
cleared by software by writing it to ‘0’ or by reading the captured data stored in the
TIMx_CCRx register. CCxOF is cleared when you write it to ‘0’.
The following example shows how to capture the counter value in TIMx_CCR1 when TI1
input rises. To do this, use the following procedure:
1. Select the active input: TIMx_CCR1 must be linked to the TI1 input, so write the CC1S
bits to ‘01’ in the TIMx_CCMR1 register. As soon as CC1S becomes different from ‘00’,
the channel is configured in input mode and the TIMx_CCR1 register becomes read-
only.
2. Program the input filter duration you need with respect to the signal you connect to the
timer (when the input is one of the TIx (ICxF bits in the TIMx_CCMRx register). Let’s
imagine that, when toggling, the input signal is not stable during at must 5 internal clock
cycles. We must program a filter duration longer than these 5 clock cycles. We can
validate a transition on TI1 when 8 consecutive samples with the new level have been
detected (sampled at fDTS frequency). Then write IC1F bits to ‘0011’ in the
TIMx_CCMR1 register.
3. Select the edge of the active transition on the TI1 channel by programming CC1P and
CC1NP bits to ‘00’ in the TIMx_CCER register (rising edge in this case).
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.
When an input capture occurs:
● The TIMx_CCR1 register gets the value of the counter on the active transition.
● CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures
occurred whereas the flag was not cleared.
● An interrupt is generated depending on the CC1IE bit.
In order to handle the overcapture, it is recommended to read the data before the
overcapture flag. This is to avoid missing an overcapture which could happen after reading
the flag and before reading the data.
Note: IC interrupt requests can be generated by software by setting the corresponding CCxG bit in
the TIMx_EGR register.
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): program the CC1P and CC1NP bits to ‘00’ (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): program the
CC2P and CC2NP bits to ‘11’ (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.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
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.
oc1ref=OC1
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘
CCRx>8
CCxIF
OCXREF ‘
CCRx=0
CCxIF
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY
tPULSE t
For example you 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.
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 you 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 you enable PWM mode 2 by writing OC1M=’111’ in the TIMx_CCMR1
register. You can optionally enable the preload registers by writing OC1PE=’1’ in the
TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this case you have 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.
You only want 1 pulse (Single mode), so you write '1 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 you want to output a waveform with the minimum delay, you can set the OCxFE bit 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.
1. Configure the channel 1 to detect rising edges on TI1. Configure the input filter duration
(in this example, we don’t need any filter, so we keep IC1F=’0000’). The capture
prescaler is not used for triggering, so you don’t need to configure it. The CC1S bits
select the input capture source only, CC1S = ‘01’ in the TIMx_CCMR1 register.
Program CC1P and CC1NP to ‘00’ in TIMx_CCER register to validate the polarity (and
detect rising edges only).
2. Configure the timer in reset mode by writing SMS=’100’ in TIMx_SMCR register. Select
TI1 as the input source by writing TS=’101’ in TIMx_SMCR register.
3. Start the counter by writing CEN=’1’ in the TIMx_CR1 register.
The counter starts counting on the internal clock, then behaves normally until TI1 rising
edge. When TI1 rises, the counter is cleared and restarts from 0. In the meantime, the
trigger flag is set (TIF bit in the TIMx_SR register) and an interrupt request can be sent if
enabled (depending on the TIE bit in TIMx_DIER register).
The following figure shows this behavior when the auto-reload register TIMx_ARR=0x36.
The delay between the rising edge on TI1 and the actual reset of the counter is due to the
resynchronization circuit on TI1 input.
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
TI1
cnt_en
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
TI2
cnt_en
Counter register 34 35 36 37 38
TIF
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TS[2:0] SMS[2:0]
Reserved Res.
rw rw rw rw rw rw
Note: The states of the external I/O pins connected to the standard OCx channels depend on the
state of the OCx channel and on the GPIO registers.
Offset Register
9
8
7
6
5
4
3
2
1
0
Reserved
Reserved
Reserved
ARPE
UDIS
OPM
CKD
URS
CEN
TIMx_CR1
0x00 Reserved [1:0]
Reset value 0 0 0 0 0 0 0
Reserved
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
Reserved Reserved Reserved
Reserved Reserved Reserved
OC1PE Reserved Reserved Reserved
CC2IE
CC1IE
UIE
TIE
TIMx_DIER
0x0C Reserved
Reset value 0 0 0 0
CC2OF
CC1OF
Reserved
Reserved
CC2IF
CC1IF
UIF
TIF
TIMx_SR
0x10 Reserved
Reset value 0 0 0 0 0 0
CC2G
CC1G
UG
TG
TIMx_EGR
0x14 Reserved
Reset value 0 0 0 0
TIMx_CCMR1
OC2PE
OC2FE
OC1FE
Reserved
OC2M CC2S OC1M CC1S
Output Compare
Reserved [2:0] [1:0] [2:0] [1:0]
mode
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC2 IC1
CC2S CC1S
Input Capture IC2F[3:0] PSC IC1F[3:0] PSC
Reserved [1:0] [1:0]
mode [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x1C Reserved
CC2NP
CC1NP
Reserved
Reserved
CC2P
CC2E
CC1P
CC1E
TIMx_CCER
0x20 Reserved
Reset value 0 0 0 0 0 0
TIMx_CNT CNT[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_ARR ARR[15:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x30 Reserved
TIMx_CCR1 CCR1[15:0]
0x34 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_CCR2 CCR2[15:0]
0x38 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x3C to
Reserved
0x4C
Note: The state of the external I/O pins connected to the standard OCx channels depends on the
OCx channel state and the GPIO registers.
UDIS
CKD
CEN
URS
TIMx_CR1
0x00 Reserved [1:0]
Reset value 0 0 0 0 0 0
TIMx_SMCR
0x08 Not Available
Reset value
CC1IE
UIE
TIMx_DIER
0x0C Reserved
Reset value 0 0
CC1OF
CC1IF
UIF
TIMx_SR
0x10 Reserved Reserved
Reset value 0 0 0
CC1G
UG
TIMx_EGR
0x14 Reserved
Reset value 0 0
TIMx_CCMR1
OC1PE
OC1FE
OC1M CC1S
Output compare
Reserved [2:0] [1:0]
mode
Reset value 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC1
CC1S
Input capture IC1F[3:0] PSC
Reserved [1:0]
mode [1:0]
Reset value 0 0 0 0 0 0 0 0
0x1C Reserved
CC1NP
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
CC1P
CC1E
TIMx_CCER
0x20 Reserved
Reset value 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
TIMx_CNT CNT[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_ARR ARR[15:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x30 Reserved
TIMx_CCR1 CCR1[15:0]
0x34 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x38 to
Reserved
0x4C
U
Auto-reload Register UI
Stop, Clear or up
U
CK_PSC PSC CK_CNT CNT
±
Prescaler COUNTER
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 170 and Figure 171 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 170. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CNT_EN
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
Figure 171. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CNT_EN
Counter register F7 F8 F9 FA FB FC 00 01
Prescaler buffer 0 3
Prescaler counter 0 0 1 2 3 0 1 2 3
CK_INT
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_INT
CNT_EN
Counter overflow
CK_INT
CNT_EN
Counter overflow
CK_INT
Counter register 1F 20 00
Counter overflow
Figure 176. Counter timing diagram, update event when ARPE = 0 (TIMx_ARR not
preloaded)
CK_INT
CNT_EN
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
Figure 177. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CNT_EN
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
CK_INT
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
Reserved
ARPE
UDIS
OPM
URS
CEN
TIMx_CR1
0x00 Reserved
Reset value 0 0 0 0 0
Reserved
TIMx_CR2 MMS[2:0]
0x04 Reserved
Reset value 0 0 0
0x08 Reserved
Reserved
UDE
UIE
TIMx_DIER
0x0C Reserved
Reset value 0 0
UIF
TIMx_SR
0x10 Reserved
Reset value 0
UG
TIMx_EGR
0x14 Reserved
Reset value 0
0x18 Reserved
0x1C Reserved
0x20 Reserved
TIMx_CNT CNT[15:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_PSC PSC[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TIMx_ARR ARR[15:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
18.3.1 Overview
The RTC consists of two main units (see Figure 179 on page 465). The first one (APB1
Interface) is used to interface with the APB1 bus. This unit also contains a set of 16-bit
registers accessible from the APB1 bus in read or write mode (for more information refer to
Section 18.4: RTC registers on page 468). The APB1 interface is clocked by the APB1 bus
clock in order to interface with the APB1 bus.
The other unit (RTC Core) consists of a chain of programmable counters made of two main
blocks. The first block is the RTC prescaler block, which generates the RTC time base
TR_CLK that can be programmed to have a period of up to 1 second. It includes a 20-bit
programmable divider (RTC Prescaler). Every TR_CLK period, the RTC generates an
interrupt (Second Interrupt) if it is enabled in the RTC_CR register. The second block is a
32-bit programmable counter that can be initialized to the current system time. The system
time is incremented at the TR_CLK rate and compared with a programmable date (stored in
the RTC_ALR register) in order to generate an alarm interrupt, if enabled in the RTC_CR
control register.
APB1 bus
PCLK1
RTC_CR
RTC_PRL
RTC_Second
SECF
Reload 32-bit programmable
counter SECIE
TR_CLK RTC_Overflow
RTC_DIV RTC_CNT OWF
rising OWIE
edge RTC_Alarm
= ALRF
RTC prescaler
ALRIE
RTC_ALR not powered in Standby
powered in Standby
NVIC interrupt
powered in Standby controller
RTC_Alarm exit
WKUP pin Standby mode
WKP_STDBY
powered in Standby
ai14969b
Configuration procedure:
1. Poll RTOFF, wait until its value goes to ‘1’
2. Set the CNF bit to enter configuration mode
3. Write to one or more RTC registers
4. Clear the CNF bit to exit configuration mode
5. Poll RTOFF, wait until its value goes to ‘1’ to check the end of the write operation.
The write operation only executes when the CNF bit is cleared; it takes at least three
RTCCLK cycles to complete.
Figure 180. RTC second and alarm waveform example with PR=0003, ALARM=00004
RTCCLK
RTC_PR 0002 0001 0000 0003 0002 0001 0000 0003 0002 0001 0000 0003 0002 0001 0000 0003 0002 0001 0000 0003 0002 0001 0000 0003
RTC_Second
RTC_ALARM
1 RTCCLK
RTC_PR 0002 0001 0000 0003 0002 0001 0000 0003 0002 0001 0000 0003 0002 0001 0000 0003 0002 0001 0000 0003 0002 0001 0000 0003
RTC_Second
RTC_Overflow
1 RTCCLK
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OWIE ALRIE SECIE
Reserved
rw rw rw
These bits are used to mask interrupt requests. Note that at reset all interrupts are disabled,
so it is possible to write to the RTC registers to ensure that no interrupt requests are pending
after initialization. It is not possible to write to the RTC_CRH register when the peripheral is
completing a previous write operation (flagged by RTOFF=0, see Section 18.3.4 on page
466).
The RTC functions are controlled by this control register. Some bits must be written using a
specific configuration procedure (see Configuration procedure:).
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
The functions of the RTC are controlled by this control register. It is not possible to write to
the RTC_CR register while the peripheral is completing a previous write operation (flagged
by RTOFF=0, see Section 18.3.4 on page 466).
Note: 1 Any flag remains pending until the appropriate RTC_CR request bit is reset by software,
indicating that the interrupt request has been granted.
2 At reset the interrupts are disabled, no interrupt requests are pending and it is possible to
write to the RTC registers.
3 The OWF, ALRF, SECF and RSF bits are not updated when the APB1 clock is not running.
4 The OWF, ALRF, SECF and RSF bits can only be set by hardware and only cleared by
software.
5 If ALRF = 1 and ALRIE = 1, the RTC global interrupt is enabled. If EXTI Line 17 is also
enabled through the EXTI Controller, both the RTC global interrupt and the RTC Alarm
interrupt are enabled.
6 If ALRF = 1, the RTC Alarm interrupt is enabled if EXTI Line 17 is enabled through the EXTI
Controller in interrupt mode. When the EXTI Line 17 is enabled in event mode, a pulse is
generated on this line (no RTC Alarm interrupt generation).
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PRL[19:16]
Reserved
w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PRL[15:0]
w w w w w w w w w w w w w w w w
Note: If the input clock frequency (fRTCCLK) is 32.768 kHz, write 7FFFh in this register to get a
signal period of 1 second.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC_DIV[19:16]
Reserved
r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTC_DIV[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
RTC_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
RTC_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
RTC_ALR[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
RTC_ALR[15:0]
w w w w w w w w w w w w w w w w
9
8
7
6
5
4
3
2
1
0 SECIE
ALRIE
OWIE
RTC_CRH
0x00 Reserved
Reset value 0 0 0
RTOFF
SECF
ALRF
OWF
CNF
RSF
RTC_CRL
0x04 Reserved
Reset value 1 0 0 0 0 0
RTC_PRLH PRL[19:16]
0x08 Reserved
Reset value 0 0 0 0
RTC_PRLL PRL[15:0]
0x0C Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_DIVH DIV[31:16]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_DIVL DIV[15:0]
0x14 Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_CNTL CNT[15:0]
0x1C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_ALRH ALR[31:16]
0x20 Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
RTC_ALRL ALR[15:0]
0x24 Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Whenever the key value 0xAAAA is written in the IWDG_KR register, the IWDG_RLR value
is reloaded in the counter and the watchdog reset is prevented.
#/2%
0RESCALER REGISTER 3TATUS REGISTER 2ELOAD REGISTER +EY REGISTER
)7$'?02 )7$'?32 )7$'?2,2 )7$'?+2
-36
Note: The watchdog function is implemented in the VDD voltage domain that is still functional in
Stop and Standby modes.
/4 0 0.1 409.6
/8 1 0.2 819.2
/16 2 0.4 1638.4
/32 3 0.8 3276.8
/64 4 1.6 6553.6
The LSI can be calibrated so as to compute the IWDG timeout with an acceptable accuracy.
For more details refer to LSI clock on page 93.
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
RVU PVU
Reserved
r r
Note: If several reload values or prescaler values are used by application, it is mandatory to wait
until RVU bit is reset before changing the reload value and to wait until PVU bit is reset
before changing the prescaler value. However, after updating the prescaler and/or the
reload value it is not necessary to wait until RVU or PVU is reset before continuing code
execution (even in case of low-power mode entry, the write operation is taken into account
and will complete)
IWDG_SR
0x0C Reserved
Reset value 0 0
- W6 W5 W4 W3 W2 W1 W0
comparator
= 1 when
T6:0 > W6:0 CMP
Write WWDG_CR
Watchdog control register (WWDG_CR)
WDGA T6 T5 T4 T3 T2 T1 T0
6-bit downcounter (CNT)
PCLK1
(from RCC clock controller)
WDG prescaler
(WDGTB)
The application program must write in the WWDG_CR register at regular intervals during
normal operation to prevent an MCU reset. This operation must occur only when the counter
value is lower than the window register value. The value to be stored in the WWDG_CR
register must be between 0xFF and 0xC0:
case, the corresponding interrupt service routine (ISR) should reload the WWDG counter to
avoid the WWDG reset, then trigger the required actions.
The EWI interrupt is cleared by writing '0' to the EWIF bit in the WWDG_SR register.
Note: When the EWI interrupt cannot be served, e.g. due to a system lock in a higher priority task,
the WWDG reset will eventually be generated.
7;=
X&
4IME
2EFRESH NOT ALLOWED 2EFRESH ALLOWED
4 BIT
2%3%4
AIB
where:
tWWDG: WWDG timeout
tPCLK1: APB1 clock period measured in ms
Refer to the table below for the minimum and maximum values of the TWWDG.
1 0 113 µs 7.28 ms
2 1 227 µs 14.56 ms
4 2 455 µs 29.12 ms
8 3 910 µs 58.25 ms
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WDGA T[6:0]
Reserved
rs rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WDGTB[1:0]
EWI W[6:0]
Reserved
rs rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EWIF
Reserved
rc_w0
9
8
7
6
5
4
3
2
1
0
WDGA
WWDG_CR T[6:0]
0x00 Reserved
Reset value 0 1 1 1 1 1 1 1
WDGTB1
WDGTB0
EWI
WWDG_CFR W[6:0]
0x04 Reserved
Reset value 0 0 0 1 1 1 1 1 1 1
EWIF
WWDG_SR
0x08 Reserved
Reset value 0
● Write enable and byte lane select outputs for use with PSRAM and SRAM devices
● Translation of 32-bit wide AHB transactions into consecutive 16-bit or 8-bit accesses to
external 16-bit or 8-bit devices
● A Write FIFO, 2 words long, each word is 32 bits wide, only stores data and not the
address. Therefore, this FIFO only buffers AHB write burst transactions. This makes it
possible to write to slow memories and free the AHB quickly for other operations. Only
one burst at a time is buffered: if a new AHB burst or single transaction occurs while an
operation is in progress, the FIFO is drained. The FSMC will insert wait states until the
current memory access is complete).
● External asynchronous wait control
The FSMC registers that define the external device type and associated characteristics are
usually set at boot time and do not change until the next reset or power-up. However, it is
possible to change the settings at any time.
FSMC_NE[4:1]
FSMC_NL (or NADV) NOR/PSRAM
FSMC_NBL[1:0] signals
From clock NOR FSMC_CLK
controller memory
HCLK controller
FSMC_A[25:0]
FSMC_D[15:0] Shared
AHB bus
FSMC_NCE[3:2] NAND
FSMC_INT[3:2] signals
NAND/PC Card
memory FSMC_INTR
controller FSMC_NCE4_1
FSMC_NCE4_2
FSMC_NIORD
FSMC_NIOWR PC Card
FSMC_NIOS16 signals
FSMC_NREG
FSMC_CD
ai14718c
The effect of this AHB error depends on the AHB master which has attempted the R/W
access:
● If it is the Cortex™-M3 CPU, a hard fault interrupt is generated
● If is a DMA, a DMA transfer error is generated and the corresponding DMA channel is
automatically disabled.
The AHB clock (HCLK) is the reference clock for the FSMC.
Configuration registers
The FSMC can be configured using a register set. See Section 21.5.6, for a detailed
description of the NOR Flash/PSRAM controller registers. See Section 21.6.8, for a detailed
description of the NAND Flash/PC Card registers.
6000 0000h
Bank 1
NOR / PSRAM
4 × 64 MB
6FF F FFF Fh
7000 0000h
Bank 2
4 × 64 MB
7FF F FFF Fh
NAND Flash
8000 0000h
Bank 3
4 × 64 MB
8FF F FFF Fh
9000 0000h
Bank 4
PC Card
4 × 64 MB
9FF F FFF Fh
ai14719
00 Bank 1 NOR/PSRAM 1
01 Bank 1 NOR/PSRAM 2
10 Bank 1 NOR/PSRAM 3
11 Bank 1 NOR/PSRAM 4
1. HADDR are internal AHB address lines that are translated to external memory.
HADDR[25:0] contain the external memory address. Since HADDR is a byte address
whereas the memory is addressed in words, the address actually issued to the memory
varies according to the memory data width, as shown in the following table.
For NAND Flash memory, the common and attribute memory spaces are subdivided into
three sections (see in Table 103 below) located in the lower 256 Kbytes:
● Data section (first 64 Kbytes in the common/attribute memory space)
● Command section (second 64 Kbytes in the common / attribute memory space)
● Address section (next 128 Kbytes in the common / attribute memory space)
The application software uses the 3 sections to access the NAND Flash memory:
● To send a command to NAND Flash memory: the software must write the command
value to any memory location in the command section.
● To specify the NAND Flash address that must be read or written: the software must
write the address value to any memory location in the address section. Since an
address can be 4 or 5 bytes long (depending on the actual memory size), several
consecutive writes to the address section are needed to specify the full address.
● To read or write data: the software reads or writes the data value from or to any
memory location in the data section.
Since the NAND Flash memory automatically increments addresses, there is no need to
increment the address of the data section to access consecutive memory locations.
NOR Flash memories are addressed in 16-bit words. The maximum capacity is 512 Mbit (26
address lines).
NOR-Flash memories are addressed in 16-bit words. The maximum capacity is 512 Mbit
(26 address lines).
PSRAM/SRAM
PSRAM memories are addressed in 16-bit words. The maximum capacity is 512 Mbit (26
address lines).
Asynchronous R 8 16 Y
Asynchronous W 8 16 N
Asynchronous R 16 16 Y
Asynchronous W 16 16 Y
Split into 2 FSMC
NOR Flash Asynchronous R 32 16 Y
accesses
(muxed I/Os
and nonmuxed Asynchronous Split into 2 FSMC
W 32 16 Y
I/Os) accesses
Asynchronous
R - 16 N Mode is not supported
page
Synchronous R 8 16 N
Synchronous R 16 16 Y
Synchronous R 32 16 Y
Asynchronous R 8 16 Y
Asynchronous W 8 16 Y Use of byte lanes NBL[1:0]
Asynchronous R 16 16 Y
Asynchronous W 16 16 Y
Split into 2 FSMC
Asynchronous R 32 16 Y
accesses
PSRAM
(multiplexed Split into 2 FSMC
Asynchronous W 32 16 Y
I/Os and accesses
nonmultiplexed Asynchronous
I/Os) R - 16 N Mode is not supported
page
Synchronous R 8 16 N
Synchronous R 16 16 Y
Synchronous R 32 16 Y
Synchronous W 8 16 Y Use of byte lanes NBL[1:0]
Synchronous W 16/32 16 Y
Asynchronous R 8 / 16 16 Y
Asynchronous W 8 / 16 16 Y Use of byte lanes NBL[1:0]
SRAM and Split into 2 FSMC
ROM Asynchronous R 32 16 Y
accesses
Split into 2 FSMC
Asynchronous W 32 16 Y
accesses
Mode 1 - SRAM/CRAM
Memory transaction
A[25:0]
NBL[1:0]
NEx
NOE
NWE
High
A[25:0]
NBL[1:0]
NEx
NOE
1HCLK
NWE
The one HCLK cycle at the end of the write transaction helps guarantee the address and
data hold time after the NWE rising edge. Due to the presence of this one HCLK cycle, the
DATAST value must be greater than zero (DATAST > 0).
31-16 0x0000
15 ASYNCWAIT Set to 1 if the memory supports this feature. Otherwise keep at 0.
14-10 0x0
9 WAITPOL Meaningful only if bit 15 is 1
8 BURSTEN 0x0
7 -
6 FACCEN -
5-4 MWID As needed
3-2 MTYP As needed, exclude 10 (NOR Flash)
1 MUXEN 0x0
0 MBKEN 0x1
31-16 0x0000
Duration of the second access phase (DATAST+1 HCLK cycles for
15-8 DATAST write accesses, DATAST+3 HCLK cycles for read accesses).
This value cannot be 0 (minimum is 1).
7-4 0x0
3-0 ADDSET Duration of the first access phase (ADDSET+1 HCLK cycles).
A[25:0]
NBL[1:0]
NEx
NOE
NWE
High
A[25:0]
NBL[1:0]
NEx
NOE
1HCLK
NWE
The differences compared with mode1 are the toggling of NOE and the independent read
and write timings.
31-16 0x0000
15 ASYNCWAIT Set to 1 if the memory supports this feature. Otherwise keep at 0.
14 EXTMOD 0x1
13-10 0x0
9 WAITPOL Meaningful only if bit 15 is 1
8 BURSTEN 0x0
7 -
6 FACCEN -
5-4 MWID As needed
3-2 MTYP As needed, exclude 10 (NOR Flash)
1 MUXEN 0x0
0 MBKEN 0x1
31-30 0x0
29-28 ACCMOD 0x0
27-16 0x000
Duration of the second access phase (DATAST+3 HCLK cycles) in
15-8 DATAST
read. This value cannot be 0 (minimum is 1)
7-4 0x0
3-0 ADDSET Duration of the first access phase (ADDSET+1 HCLK cycles) in read.
31-30 0x0
29-28 ACCMOD 0x0
27-16 0x000
Duration of the second access phase (DATAST+1 HCLK cycles) in
15-8 DATAST
write. This value cannot be 0 (minimum is 1).
7-4 0x0
Duration of the first access phase (ADDSET+1 HCLK cycles) in write
3-0 ADDSET
A[25:0]
NADV
NEx
NOE
NWE
High
A[25:0]
NADV
NEx
NOE
1HCLK
NWE
Memory transaction
A[25:0]
NADV
NEx
NOE
1HCLK
NWE
The differences with mode1 are the toggling of NADV and the independent read and write
timings when extended mode is set (Mode B).
31-16 0x0000
15 ASYNCWAIT Set to 1 if the memory supports this feature. Otherwise keep at 0.
14 EXTMOD 0x1 for mode B, 0x0 for mode 2
13-10 0x0
9 WAITPOL Meaningful only if bit 15 is 1
8 BURSTEN 0x0
7 -
6 FACCEN 0x1
5-4 MWID As needed
3-2 MTYP 10 (NOR Flash)
1 MUXEN 0x0
0 MBKEN 0x1
31-30 0x0
29-28 ACCMOD 0x1 if extended mode is set
27-16 0x000
Duration of the access second phase (DATAST+3 HCLK cycles) in
15-8 DATAST
read. This value can not be 0 (minimum is 1)
7-4 0x0
Duration of the access first phase (ADDSET+1 HCLK cycles) in
3-0 ADDSET
read.
31-30 0x0
29-28 ACCMOD 0x1 if extended mode is set
27-16 0x000
Duration of the access second phase (DATAST+1 HCLK cycles) in
15-8 DATAST
write. This value can not be 0 (minimum is 1).
7-4 0x0
Duration of the access first phase (ADDSET+1 HCLK cycles) in
3-0 ADDSET
write.
Note: The FSMC_BWTRx register is valid only if extended mode is set (mode B), otherwise all its
content is don’t care.
A[25:0]
NADV
NEx
NOE
NWE
High
A[25:0]
NADV
NEx
NOE
1HCLK
NWE
The differences compared with mode1 are the toggling of NOE and NADV and the
independent read and write timings.
31-16 0x0000
15 ASYNCWAIT Set to 1 if the memory supports this feature. Otherwise keep at 0.
14 EXTMOD 0x1
13-10 0x0
9 WAITPOL Meaningful only if bit 15 is 1
8 BURSTEN 0x0
7 -
6 FACCEN 1
5-4 MWID As needed
3-2 MTYP 0x02 (NOR Flash)
1 MUXEN 0x0
0 MBKEN 0x1
31-30 0x0
29-28 ACCMOD 0x2
27-16 0x000
Duration of the second access phase (DATAST+3 HCLK cycles) in
15-8 DATAST
read. This value cannot be 0 (minimum is 1)
7-4 0x0
Duration of the first access phase (ADDSET+1 HCLK cycles) in
3-0 ADDSET
read.
31-30 0x0
29-28 ACCMOD 0x2
27-16 0x000
Duration of the second access phase (DATAST+1 HCLK cycles) in
15-8 DATAST
write. This value cannot be 0 (minimum is 1)
7-4 0x0
Duration of the first access phase (ADDSET+1 HCLK cycles) in
3-0 ADDSET
write.
A[25:0]
NADV
NEx
NOE
NWE
High
ModeD write accessesThe differences with mode1 are the toggling of NADV, NOE that
Memory transaction
A[25:0]
NADV
NEx
NOE
1HCLK
NWE
goes on toggling after NADV changes and the independent read and write timings.
31-16 0x0000
15 ASYNCWAIT Set to 1 if the memory supports this feature. Otherwise keep at 0.
14 EXTMOD 0x1
13-10 0x0
9 WAITPOL Meaningful only if bit 15 is 1
8 BURSTEN 0x0
7 -
6 FACCEN Set according to memory support
5-4 MWID As needed
3-2 MTYP As needed
1 MUXEN 0x0
0 MBKEN 0x1
31-30 0x0
29-28 ACCMOD 0x2
27-16 0x000
Duration of the second access phase (DATAST+3 HCLK cycles) in
15-8 DATAST
read. This value cannot be 0 (minimum is 1)
Duration of the middle phase of the read access (ADDHLD+1 HCLK
7-4 ADDHLD
cycles)
Duration of the first access phase (ADDSET+1 HCLK cycles) in
3-0 ADDSET
read.
31-30 0x0
29-28 ACCMOD 0x2
27-16 0x000
Duration of the second access phase (DATAST+1 HCLK cycles) in
15-8 DATAST
write. This value cannot be 0 (minimum is 1)
Duration of the middle phase of the write access (ADDHLD+1 HCLK
7-4 ADDHLD
cycles)
3-0 ADDSET Duration of the first access phase (ADDSET+1 HCLK cycles) in write.
A[25:16]
NADV
NEx
NOE
NWE
High
1. The bus turnaround delay (BUSTURN + 1) and the delay between side-by-side transactions overlap, so
BUSTURN ≤ 5 has not impact.
A[25:16]
NADV
NEx
NOE
1HCLK
NWE
The difference with mode D is the drive of the lower address byte(s) on the databus.
31-16 0x0000
15 ASYNCWAIT Set to 1 if the memory supports this feature. Otherwise keep at 0.
14 EXTMOD 0x0
13-10 0x0
9 WAITPOL Meaningful only if bit 15 is 1
8 BURSTEN 0x0
7 -
6 FACCEN 0x1
5-4 MWID As needed
3-2 MTYP 0x2 (NOR)
1 MUXEN 0x1
0 MBKEN 0x1
31-20 0x0000
Duration of the last phase of the access (BUSTURN+1 HCLK)
19-16 BUSTURN
Memory transaction
A[25:0]
NOE
DATA DRIVEN
D[15:0]
BY MEMORY
(#,+
AI
Memory transaction
A[25:0]
NEx
NWE
3HCLK
ai15797
Single-burst transfer
When the selected bank is configured in synchronous burst mode, if an AHB single-burst
transaction is requested, the FSMC performs a burst transaction of length 1 (if the AHB
transfer is 16-bit), or length 2 (if the AHB transfer is 32-bit) and de-assert the chip select
signal when the last data is strobed.
Clearly, such a transfer is not the most efficient in terms of cycles (compared to an
asynchronous read). Nevertheless, a random asynchronous access would first require to re-
program the memory access mode, which would altogether last longer.
Wait management
For synchronous burst NOR Flash, NWAIT is evaluated after the programmed latency
period, (DATALAT+2) CLK clock cycles.
If NWAIT is sensed active (low level when WAITPOL = 0, high level when WAITPOL = 1),
wait states are inserted until NWAIT is sensed inactive (high level when WAITPOL = 0, low
level when WAITPOL = 1).
When NWAIT is inactive, the data is considered valid either immediately (bit WAITCFG = 1)
or on the next clock edge (bit WAITCFG = 0).
During wait-state insertion via the NWAIT signal, the controller continues to send clock
pulses to the memory, keeping the chip select and output enable signals valid, and does not
consider the data valid.
There are two timing configurations for the NOR Flash NWAIT signal in burst mode:
● Flash memory asserts the NWAIT signal one data cycle before the wait state (default
after reset)
● Flash memory asserts the NWAIT signal during the wait state
These two NOR Flash wait state configurations are supported by the FSMC, individually for
each chip select, thanks to the WAITCFG bit in the FSMC_BCRx registers (x = 0..3).
HCLK
CLK
A[25:16] addr[25:16]
NADV
NWAIT
(WAITCFG = 0)
NWAIT
(WAITCFG = 1)
ai15798
(#,+
#,+
!;= ADDR;=
.%X
./%
(IGH
.7%
.!$6
.7!)4
7!)4#&'
CLOCK CLOCK
CYCLE CYCLE
$ATA STROBES $ATA STROBES
AIB
1. Byte lane outputs BL are not shown; for NOR access, they are held high, and, for PSRAM (CRAM) access, they are held
low.
31-20 0x0000
19 CBURSTRW No effect on synchronous read
18-15 0x0
14 EXTMOD 0x0
When high, the first data after latency period is taken as always
13 WAITEN
valid, regardless of the wait from memory value
12 WREN no effect on synchronous read
11 WAITCFG to be set according to memory
10 WRAPMOD no effect
9 WAITPOL to be set according to memory
8 BURSTEN 0x1
7 FWPRLVL Set to protect memory from accidental write access
6 FACCEN Set according to memory support
5-4 MWID As needed
3-2 MTYP 0x1 or 0x2
1 MUXEN As needed
0 MBKEN 0x1
HCLK
CLK
A[25:16] addr[25:16]
NEx
Hi-Z
NOE
NWE
NADV
NWAIT
(WAITCFG = 0)
1. Memory must issue NWAIT signal one cycle in advance, accordingly WAITCFG must be programmed to 0.
2. Byte Lane (NBL) outputs are not shown, they are held low while NEx is active.
31-20 0x0000
19 CBURSTRW 0x1
18-15 0x0
14 EXTMOD 0x0
When high, the first data after latency period is taken as always
13 WAITEN
valid, regardless of the wait from memory value
12 WREN no effect on synchronous read
11 WAITCFG 0x0
10 WRAPMOD no effect
9 WAITPOL to be set according to memory
8 BURSTEN no effect on synchronous write
7 FWPRLVL Set to protect memory from accidental writes
6 FACCEN Set according to memory support
5-4 MWID As needed
3-2 MTYP 0x1
1 MUXEN As needed
0 MBKEN 0x1
31-30 - 0x0
27-24 DATLAT Data latency
0x0 to get CLK = HCLK (not supported)
23-20 CLKDIV
0x1 to get CLK = 2 × HCLK
19-16 BUSTURN No effect
15-8 DATAST No effect
7-4 ADDHLD No effect
3-0 ADDSET No effect
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
ASCYCWAIT
CBURSTRW
WRAPMOD
BURSTEN
WAITCFG
WAITPOL
EXTMOD
FACCEN
WAITEN
MUXEN
MBKEN
WREN
MWID
MTYP
Reserved
Reserved
Reserved
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
BUSTURN
ACCMOD
ADDHLD
ADDSET
DATAST
CLKDIV
DATLAT
Reserved
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
Note: PSRAMs (CRAMs) have a variable latency due to internal refresh. Therefore these
memories issue the NWAIT signal during the whole latency phase to prolong the latency as
needed.
With PSRAMs (CRAMs) the filed DATLAT must be set to 0, so that the FSMC exits its
latency phase soon and starts sampling NWAIT from memory, then starts to read or write
when the memory is ready.
This method can be used also with the latest generation of synchronous Flash memories
that issue the NWAIT signal, unlike older Flash memories (check the datasheet of the
specific Flash memory being used).
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
ACCM
DATLAT CLKDIV DATAST ADDHLD ADDSET
Res. OD Reserved
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
There is no theoretical capacity limitation as the FSMC can manage as many address
cycles as needed.
There is no theoretical capacity limitation as the FSMC can manage as many address
cycles as needed.
Asynchronous R 8 8 Y
Asynchronous W 8 8 Y
Asynchronous R 16 8 Y Split into 2 FSMC accesses
NAND 8-bit
Asynchronous W 16 8 Y Split into 2 FSMC accesses
Asynchronous R 32 8 Y Split into 4 FSMC accesses
Asynchronous W 32 8 Y Split into 4 FSMC accesses
Asynchronous R 8 16 Y
Asynchronous W 8 16 N
Asynchronous R 16 16 Y
NAND 16-bit
Asynchronous W 16 16 Y
Asynchronous R 32 16 Y Split into 2 FSMC accesses
Asynchronous W 32 16 Y Split into 2 FSMC accesses
Figure 204. NAND/PC Card controller timing for common memory access
HCLK
Address
NCEx(2)
NREG, High
NIOW,
NIOR
MEMxSET + 1 MEMxWAIT + 1 MEMxHOLD + 1
NWE,
NOE(1)
MEMxHIZ
write_data
read_data Valid
ai14732d
1. NOE remains high (inactive) during write access. NWE remains high (inactive) during read access.
2. NCEx goes low as soon as NAND access is requested and remains low until a different memory bank is accessed.
the start address for read operations. Using the attribute memory space makes it
possible to use a different timing configuration of the FSMC, which can be used to
implement the prewait functionality needed by some NAND Flash memories (see
details in Section 21.6.5: NAND Flash pre-wait functionality on page 529).
4. The controller waits for the NAND Flash to be ready (R/NB signal high) to become
active, before starting a new access (to same or another memory bank). While waiting,
the controller maintains the NCE signal active (low).
5. The CPU can then perform byte read operations in the common memory space to read
the NAND Flash page (data field + Spare field) byte by byte.
6. The next NAND Flash page can be read without any CPU command or address write
operation, in three different ways:
– by simply performing the operation described in step 5
– a new random address can be accessed by restarting the operation at step 3
– a new command can be sent to the NAND Flash device by restarting at step 2
NCE
CLE
ALE
NWE
High
NOE
tR
I/O[7:0] 0x00 A7-A0 A16-A9 A24-A17 A25
tWB
R/NB
(1) (2) (3) (4) (5)
ai14733
the odd byte on D15-8 and nCE1 accesses the even byte on D7-0 if A0=0 or the odd byte on
D7-0 if A0=1. The full word is accessed on D15-0 if both nCE2 and nCE1 are low.
The memory space is selected by asserting low nOE for read accesses or nWE for write
accesses, combined with the low assertion of nCE2/nCE1 and nREG.
● If pin nREG=1 during the memory access, the common memory space is selected
● If pin nREG=0 during the memory access, the attribute memory space is selected
The I/O Space is selected by asserting low nIORD for read accesses or nIOWR for write
accesses [instead of nOE/nWE for memory Space], combined with nCE2/nCE1. Note that
nREG must also be asserted low during accesses to I/O Space.
Three type of accesses are allowed for a 16-bit PC Card:
● Accesses to Common Memory Space for data storage can be either 8-bit accesses at
even addresses or 16 bit AHB accesses.
Note that 8-bit accesses at odd addresses are not supported and will not lead to the
low assertion of nCE2. A 32-bit AHB request is translated into two 16-bit memory
accesses.
● Accesses to Attribute Memory Space where the PC Card stores configuration
information are limited to 8-bit AHB accesses at even addresses.
Note that a 16-bit AHB access will be converted into a single 8-bit memory transfer:
nCE1 will be asserted low, NCE2 will be asserted high and only the even Byte on D7-
D0 will be valid. Instead a 32-bit AHB access will be converted into two 8-bit memory
transfers at even addresses: nCE1 will be asserted low, NCE2 will be asserted high
and only the even bytes will be valid.
● Accesses to I/O Space must be limited to AHB 16 bit accesses.
nCE1
A7-1
Allowed/not
A10
A9
A0
1 0 1 0 1 X X X-X X YES
Read/Write byte on D7-D0
YES Common YES
Memory
0 1 1 0 1 X X X-X X Space Read/Write byte on D15-D8 Not supported
0 0 1 0 1 X X X-X 0 Read/Write word on D15-D0 YES
Read or Write Configuration
X 0 0 0 1 0 1 X-X 0 YES
Attribute Registers
Space Read or Write CIS (Card
X 0 0 0 1 0 0 X-X 0 YES
Information Structure)
1 0 0 0 1 X X X-X 1 Invalid Read or Write (odd address) YES
Attribute
0 1 0 0 1 X X X-X x Space Read or Write (odd address) YES
nIORD /nIOWR
nOE/nWE
nREG
nCE2
nCE1
A7-1
Allowed/not
A10
A9
A0
Space Access Type
Allowed
The FSMC Bank 4 gives access to those 3 memory spaces as described in Section 21.4.2:
NAND/PC Card address mapping - Table 102: Memory mapping and timing registers
Wait Feature
The CompactFlash Storage or PC Card may request the FSMC to extend the length of the
access phase programmed by MEMWAITx/ATTWAITx/IOWAITx bits, asserting the nWAIT
signal after nOE/nWE or nIORD/nIOWR activation if the wait feature is enabled through the
PWAITEN bit in the FSMC_PCRx register. In order to detect the nWAIT assertion correctly,
the MEMWAITx/ATTWAITx/IOWAITx bits must be programmed as follows:
xxWAITx >= 4 + max_wait_assertion_time/HCLK
Where max_wait_assertion_time is the maximum time taken by NWAIT to go low once
nOE/nWE or nIORD/nIOWR is low.
After the de-assertion of nWAIT, the FSMC extends the WAIT phase for 4 HCLK clock
cycles.
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
PWAITEN
ECCEN
PBKEN
PTYP
Reserved
ECCPS TAR TCLR PWID
Reserved Res.
rw 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
FEMPT
Reserved
IREN
IFEN
ILEN
IRS
IFS
r rw rw rw rw ILS
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
MEMHIZx MEMHOLDx MEMWAITx MEMSETx
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
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
ATTHIZx ATTHOLDx ATTWAITx ATTSETx
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
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
IOHIZx IOHOLDx IOWAITx IOSETx
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
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
ECCx
r
9
8
7
6
5
4
3
2
1
0
ASYNCWAIT
CBURSTRW
BURSTEN
WAITCFG
WAITPOL
Reserved
EXTMOD
FACCEN
WAITEN
MUXEN
MBKEN
WREN
MWID
MTYP
0xA000 FSMC_BCR1 Reserved Reserved
0000
Reset value
BURSTEN
WAITCFG
WAITPOL
Reserved
EXTMOD
FACCEN
WAITEN
MUXEN
MBKEN
WREN
MWID
MTYP
0xA000
FSMC_BCR2 Reserved Reserved
0008
BURSTEN
WAITCFG
WAITPOL
Reserved
EXTMOD
FACCEN
WAITEN
MUXEN
MBKEN
WREN
MTYP
MWID
0xA000
FSMC_BCR3 Reserved Reserved
0010
BURSTEN
WAITCFG
WAITPOL
EXTMOD
Reserved
FACCEN
WAITEN
MUXEN
MBKEN
WREN
MTYP
MWID
0xA000
FSMC_BCR4 Reserved Reserved
0018
0xA000 ACCM
FSMC_BTR1 Res. DATLAT CLKDIV BUSTURN DATAST ADDHLD ADDSET
0004 OD
0xA000 ACCM
FSMC_BTR2 Res. DATLAT CLKDIV BUSTURN DATAST ADDHLD ADDSET
000C OD
0xA000 ACCM
FSMC_BTR3 Res. DATLAT CLKDIV BUSTURN DATAST ADDHLD ADDSET
0014 OD
0xA000 ACCM
FSMC_BTR4 Res. DATLAT CLKDIV BUSTURN DATAST ADDHLD ADDSET
001C OD
0xA000 ACCM
FSMC_BWTR1 Res. DATLAT CLKDIV Reserved DATAST ADDHLD ADDSET
0104 OD
0xA000 ACCM
FSMC_BWTR2 Res. DATLAT CLKDIV Reserved DATAST ADDHLD ADDSET
010C OD
0xA000 ACCM
FSMC_BWTR3 Res. DATLAT CLKDIV Reserved DATAST ADDHLD ADDSET
0114 OD
0xA000 ACCM
FSMC_BWTR4 Res. DATLAT CLKDIV Reserved DATAST ADDHLD ADDSET
011C OD
PWAITEN PWAITEN PWAITEN
Reserved Reserved Reserved
ECCEN
PBKEN
PTYP
0xA000
FSMC_PCR2 Reserved ECCPS TAR TCLR Res. PWID
0060
ECCEN
PBKEN
PTYP
0xA000
FSMC_PCR3 Reserved ECCPS TAR TCLR Res. PWID
0080
FEMPT FEMPT FEMPT ECCEN
PBKEN
PTYP
0xA000
FSMC_PCR4 Reserved ECCPS TAR TCLR Res. PWID
00A0
IREN
IFEN
0xA000
ILEN
IRS
IFS
ILS
FSMC_SR2 Reserved
0064
IREN
IFEN
0xA000
ILEN
IRS
IFS
ILS
FSMC_SR3 Reserved
0084
IREN
IFEN
0xA000
ILEN
IRS
IFS
ILS
FSMC_SR4 Reserved
00A4
0xA000
FSMC_PMEM2 MEMHIZx MEMHOLDx MEMWAITx MEMSETx
0068
0xA000
FSMC_PMEM3 MEMHIZx MEMHOLDx MEMWAITx MEMSETx
0088
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
0xA000
FSMC_PMEM4 MEMHIZx MEMHOLDx MEMWAITx MEMSETx
00A8
0xA000
FSMC_PATT2 ATTHIZx ATTHOLDx ATTWAITx ATTSETx
006C
0xA000
FSMC_PATT3 ATTHIZx ATTHOLDx ATTWAITx ATTSETx
008C
0xA000
FSMC_PATT4 ATTHIZx ATTHOLDx ATTWAITx ATTSETx
00AC
0xA000
FSMC_PIO4 IOHIZx IOHOLDx IOWAITx IOSETx
00B0
0xA000
FSMC_ECCR2 ECCx
0074
0xA000
FSMC_ECCR3 ECCx
0094
interface using a protocol that utilizes the existing MMC access primitives. The interface
electrical and signaling definition is as defined in the MMC reference.
The MultiMediaCard/SD bus connects cards to the controller.
The current version of the SDIO supports only one SD/SDIO/MMC4.2 card at any one time
and a stack of MMC4.1 or previous.
SDIO_D
ai14734
SDIO_D Data block crc Data block crc Data block crc
ai14735
SDIO_D Busy Data block crc Busy Data block crc Busy
ai14737
Note: The SDIO will not send any data as long as the Busy signal is asserted (SDIO_D0 pulled
low).
From host to
card(s) From card to host Stop command
stops data transfer
Data from card to host
ai14738
From host to
card(s) From card to host Stop command
stops data transfer
Data from host to card
ai14739
SDIO SDIO_CK
Interrupts and
DMA request SDIO_CMD
HCLK/2 SDIOCLK
ai14740
By default SDIO_D0 is used for data transfer. After initialization, the host can change the
databus width.
If a MultiMediaCard is connected to the bus, SDIO_D0, SDIO_D[3:0] or SDIO_D[7:0] can be
used for data transfer. MMC V3.31 or previous, supports only 1 bit of data so only SDIO_D0
can be used.
If an SD or SD I/O card is connected to the bus, data transfer can be configured by the host
to use SDIO_D0 or SDIO_D[3:0]. All data lines are operating in push-pull mode.
SDIO_CMD has two operational modes:
● Open-drain for initialization (only for MMCV3.31 or previous)
● Push-pull for command transfer (SD/SD I/O card MMC4.2 use push-pull drivers also for
initialization)
SDIO_CK is the clock to the card: one bit is transferred on both command and data lines
with each clock cycle. The clock frequency can vary between 0 MHz and 20 MHz (for a
MultiMediaCard V3.31), between 0 and 48 MHz for a MultiMediaCard V4.0/4.2, or between
0 and 25 MHz (for an SD/SD I/O card).
The SDIO uses two clock signals:
● SDIO adapter clock (SDIOCLK = HCLK)
● AHB bus clock (HCLK/2)
PCLK2 and SDIO_CK clock frequencies must respect the following condition:
The signals shown in Table 137 are used on the MultiMediaCard/SD/SD I/O card bus.
SDIO adapter
Command
Card bus
SDIO_CMD
path
Adapter
registers
To AHB
interface Data path
SDIO_D[7:0]
FIFO
HCLK/2 SDIOCLK
ai14740
The SDIO adapter is a multimedia/secure digital memory card bus master that provides an
interface to a multimedia card stack or to a secure digital memory card. It consists of five
subunits:
● Adapter register block
● Control unit
● Command path
● Data path
● Data FIFO
Note: The adapter registers and FIFO use the AHB bus clock domain (HCLK/2). The control unit,
command path and data path use the SDIO adapter clock domain (SDIOCLK).
Control unit
The control unit contains the power management functions and the clock divider for the
memory card clock.
There are three power phases:
● power-off
● power-up
● power-on
Control unit
Power management
ai14804
The control unit is illustrated in Figure 213. It consists of a power management subunit and
a clock management subunit.
The power management subunit disables the card bus output signals during the power-off
and power-up phases.
The clock management subunit generates and controls the SDIO_CK signal. The SDIO_CK
output can use either the clock divide or the clock bypass mode. The clock output is inactive:
● after reset
● during the power-off or power-up phases
● if the power saving mode is enabled and the card bus is in the Idle state (eight clock
periods after both the command and data path subunits enter the Idle phase)
Command path
The command path unit sends commands to and receives responses from the cards.
Adapter registers
SDIO_CMDin
CMD
Argument
CRC SDIO_CMDout
Shift
CMD register
ai14805
CE-ATA Command
On reset Completion signal
received or Wait_CPL
CPSM disabled or
Command CRC failed
Pend
Enabled and
CPSM Disabled or
command start Receive
CPSM disabled or command timeout
no response
Last Data
Response
started
Send
When the Wait state is entered, the command timer starts running. If the timeout is reached
before the CPSM moves to the Receive state, the timeout flag is set and the Idle state is
entered.
Note: The command timeout has a fixed value of 64 SDIO_CK clock periods.
If the interrupt bit is set in the command register, the timer is disabled and the CPSM waits
for an interrupt request from one of the cards. If a pending bit is set in the command register,
the CPSM enters the Pend state, and waits for a CmdPend signal from the data path
subunit. When CmdPend is detected, the CPSM moves to the Send state. This enables the
data counter to trigger the stop command transmission.
Note: The CPSM remains in the Idle state for at least eight SDIO_CK periods to meet the NCC and
NRC timing constraints. NCC is the minimum delay between two host commands, and NRC is
the minimum delay between the host command and the card response.
SDIO_CMD Hi-Z Controller drives Hi-Z Card drives Hi-Z Controller drives
ai14707
● Command format
– Command: a command is a token that starts an operation. Command are sent
from the host either to a single card (addressed command) or to all connected
cards (broadcast command are available for MMC V3.31 or previous). Commands
are transferred serially on the CMD line. All commands have a fixed length of 48
bits. The general format for a command token for MultiMediaCards, SD-Memory
cards and SDIO-Cards is shown in Table 138. CE-ATA commands are an
extension of MMC commands V4.2, and so have the same format.
The command path operates in a half-duplex mode, so that commands and
responses can either be sent or received. If the CPSM is not in the Send state, the
SDIO_CMD output is in the Hi-Z state, as shown in Figure 216 on page 549. Data
on SDIO_CMD are synchronous with the rising edge of SDIO_CK. Table shows
the command format.
47 1 0 Start bit
46 1 1 Transmission bit
[45:40] 6 - Command index
[39:8] 32 - Argument
[7:1] 7 - CRC7
0 1 1 End bit
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 - Command index
[39:8] 32 - Argument
[7:1] 7 - CRC7(or 1111111)
0 1 1 End bit
The command register contains the command index (six bits sent to a card) and the
command type. These determine whether the command requires a response, and whether
the response is 48 or 136 bits long (see Section 22.9.4 on page 584). The command path
implements the status flags shown in Table 141:
The CRC generator calculates the CRC checksum for all bits before the CRC code. This
includes the start bit, transmitter bit, command index, and command argument (or card
status). The CRC checksum is calculated for the first 120 bits of CID or CSD for the long
response format. Note that the start bit, transmitter bit and the six reserved bits are not used
in the CRC calculation.
The CRC checksum is a 7-bit value:
CRC[6:0] = Remainder [(M(x) * x7) / G(x)]
G(x) = x7 + x3 + 1
M(x) = (start bit) * x39 + ... + (last bit before CRC) * x0, or
M(x) = (start bit) * x119 + ... + (last bit before CRC) * x0
Data path
The data path subunit transfers data to and from cards. Figure 217 shows a block diagram
of the data path.
Data FIFO
SDIO_Din[7:0]
Transmit
CRC SDIO_Dout[7:0]
Shift
register
Receive
ai14808
The card databus width can be programmed using the clock control register. If the 4-bit wide
bus mode is enabled, data is transferred at four bits per clock cycle over all four data signals
(SDIO_D[3:0]). If the 8-bit wide bus mode is enabled, data is transferred at eight bits per
clock cycle over all eight data signals (SDIO_D[7:0]). If the wide bus mode is not enabled,
only one bit per clock cycle is transferred over SDIO_D0.
Depending on the transfer direction (send or receive), the data path state machine (DPSM)
moves to the Wait_S or Wait_R state when it is enabled:
● Send: the DPSM moves to the Wait_S state. If there is data in the transmit FIFO, the
DPSM moves to the Send state, and the data path subunit starts sending data to a
card.
● Receive: the DPSM moves to the Wait_R state and waits for a start bit. When it
receives a start bit, the DPSM moves to the Receive state, and the data path subunit
starts receiving data from a card.
Data path state machine (DPSM)
The DPSM operates at SDIO_CK frequency. Data on the card bus signals is synchronous to
the rising edge of SDIO_CK. The DPSM has six states, as shown in Figure 218: Data path
state machine (DPSM).
ReadWait Stop
Disabled or
end of data
Disabled or
Busy Rx FIFO empty or timeout or
start bit error
Not busy
Enable and send Data received and
Wait_R Read Wait Started and
SD I/O mode enabled
End of packet
Send
Receive
ai14809b
● Idle: the data path is inactive, and the SDIO_D[7:0] outputs are in Hi-Z. When the data
control register is written and the enable bit is set, the DPSM loads the data counter
with a new value and, depending on the data direction bit, moves to either the Wait_S
or the Wait_R state.
● Wait_R: if the data counter equals zero, the DPSM moves to the Idle state when the
receive FIFO is empty. If the data counter is not zero, the DPSM waits for a start bit on
SDIO_D. The DPSM moves to the Receive state if it receives a start bit before a
timeout, and loads the data block counter. If it reaches a timeout before it detects a
start bit, or a start bit error occurs, it moves to the Idle state and sets the timeout status
flag.
● Receive: serial data received from a card is packed in bytes and written to the data
FIFO. Depending on the transfer mode bit in the data control register, the data transfer
mode can be either block or stream:
– In block mode, when the data block counter reaches zero, the DPSM waits until it
receives the CRC code. If the received code matches the internally generated
CRC code, the DPSM moves to the Wait_R state. If not, the CRC fail status flag is
set and the DPSM moves to the Idle state.
– In stream mode, the DPSM receives data while the data counter is not zero. When
the counter is zero, the remaining data in the shift register is written to the data
FIFO, and the DPSM moves to the Wait_R state.
If a FIFO overrun error occurs, the DPSM sets the FIFO error flag and moves to the Idle
state:
● Wait_S: the DPSM moves to the Idle state if the data counter is zero. If not, it waits until
the data FIFO empty flag is deasserted, and moves to the Send state.
Note: The DPSM remains in the Wait_S state for at least two clock periods to meet the NWR timing
requirements, where NWR is the number of clock cycles between the reception of the card
response and the start of the data transfer from the host.
● Send: the DPSM starts sending data to a card. Depending on the transfer mode bit in
the data control register, the data transfer mode can be either block or stream:
– In block mode, when the data block counter reaches zero, the DPSM sends an
internally generated CRC code and end bit, and moves to the Busy state.
– In stream mode, the DPSM sends data to a card while the enable bit is high and
the data counter is not zero. It then moves to the Idle state.
If a FIFO underrun error occurs, the DPSM sets the FIFO error flag and moves to the
Idle state.
● Busy: the DPSM waits for the CRC status flag:
– If it does not receive a positive CRC status, it moves to the Idle state and sets the
CRC fail status flag.
– If it receives a positive CRC status, it moves to the Wait_S state if SDIO_D0 is not
low (the card is not busy).
If a timeout occurs while the DPSM is in the Busy state, it sets the data timeout flag and
moves to the Idle state.
The data timer is enabled when the DPSM is in the Wait_R or Busy state, and
generates the data timeout error:
– When transmitting data, the timeout occurs if the DPSM stays in the Busy state for
longer than the programmed timeout period
– When receiving data, the timeout occurs if the end of the data is not true, and if the
DPSM stays in the Wait_R state for longer than the programmed timeout period.
● Data: data can be transferred from the card to the host or vice versa. Data is
transferred via the data lines. They are stored in a FIFO of 32 words, each word is 32
bits wide.
Data FIFO
The data FIFO (first-in-first-out) subunit is a data buffer with a transmit and receive unit.
The FIFO contains a 32-bit wide, 32-word deep data buffer, and transmit and receive logic.
Because the data FIFO operates in the AHB clock domain (HCLK/2), all signals from the
subunits in the SDIO clock domain (SDIOCLK) are resynchronized.
Depending on the TXACT and RXACT flags, the FIFO can be disabled, transmit enabled, or
receive enabled. TXACT and RXACT are driven by the data path subunit and are mutually
exclusive:
– The transmit FIFO refers to the transmit logic and data buffer when TXACT is
asserted
– The receive FIFO refers to the receive logic and data buffer when RXACT is
asserted
● Transmit FIFO:
Data can be written to the transmit FIFO through the AHB interface when the SDIO is
enabled for transmission.
The transmit FIFO is accessible via 32 sequential addresses. The transmit FIFO
contains a data output register that holds the data word pointed to by the read pointer.
When the data path subunit has loaded its shift register, it increments the read pointer
and drives new data out.
If the transmit FIFO is disabled, all status flags are deasserted. The data path subunit
asserts TXACT when it transmits data.
TXFIFOF Set to high when all 32 transmit FIFO words contain valid data.
TXFIFOE Set to high when the transmit FIFO does not contain valid data.
Set to high when 8 or more transmit FIFO words are empty. This flag can be used
TXFIFOHE
as a DMA request.
Set to high when the transmit FIFO contains valid data. This flag is the inverse of
TXDAVL
the TXFIFOE flag.
Set to high when an underrun error occurs. This flag is cleared by writing to the
TXUNDERR
SDIO Clear register.
● Receive FIFO
When the data path subunit receives a word of data, it drives the data on the write
databus. The write pointer is incremented after the write operation completes. On the
read side, the contents of the FIFO word pointed to by the current value of the read
pointer is driven onto the read databus. If the receive FIFO is disabled, all status flags
are deasserted, and the read and write pointers are reset. The data path subunit
asserts RXACT when it receives data. Table 144 lists the receive FIFO status flags.
The receive FIFO is accessible via 32 sequential addresses.
RXFIFOF Set to high when all 32 receive FIFO words contain valid data
RXFIFOE Set to high when the receive FIFO does not contain valid data.
Set to high when 8 or more receive FIFO words contain valid data. This flag can be
RXFIFOHF
used as a DMA request.
Set to high when the receive FIFO is not empty. This flag is the inverse of the
RXDAVL
RXFIFOE flag.
Set to high when an overrun error occurs. This flag is cleared by writing to the SDIO
RXOVERR
Clear register.
SDIO interrupts
The interrupt logic generates an interrupt request signal that is asserted when at least one
of the selected status flags is high. A mask register is provided to allow selection of the
conditions that will generate an interrupt. A status flag generates the interrupt request if a
corresponding mask flag is set.
SDIO/DMA interface: procedure for data transfers between the SDIO and
memory
In the example shown, the transfer is from the SDIO host controller to an MMC (512 bytes
using CMD24 (WRITE_BLOCK). The SDIO FIFO is filled by data stored in a memory using
the DMA controller.
1. Do the card identification process
2. Increase the SDIO_CK frequency
3. Select the card by sending CMD7
4. Configure the DMA2 as follows:
a) Enable DMA2 controller and clear any pending interrupts
b) Program the DMA2_Channel4 source address register with the memory location’s
base address and DMA2_Channel4 destination address register with the
SDIO_FIFO register address
c) Program DMA2_Channel4 control register (memory increment, not peripheral
increment, peripheral and source width is word size)
d) Enable DMA2_Channel4
By using these commands without including the voltage range as the operand, the SDIO
card host can query each card and determine the common voltage range before placing out-
of-range cards in the inactive state. This query is used when the SDIO card host is able to
select a common voltage range or when the user requires notification that cards are not
usable.
The host can abort reading at any time, within a multiple block operation, regardless of its
type. Transaction abort is done by sending the stop transmission command.
If the card detects an error (for example, out of range, address misalignment or internal
error) during a multiple block read operation (both types) it stops the data transmission and
remains in the data state. The host must than abort the operation by sending the stop
transmission command. The read error is reported in the response to the stop transmission
command.
If the host sends a stop transmission command after the card transmits the last block of a
multiple block operation with a predefined number of blocks, it is responded to as an illegal
command, since the card is no longer in the data state. If the host uses partial blocks whose
accumulated length is not block-aligned and block misalignment is not allowed, the card
detects a block misalignment error condition at the beginning of the first misaligned block
(ADDRESS_ERROR error bit is set in the status register).
22.4.7 Stream access, stream write and stream read (MultiMediaCard only)
In stream mode, data is transferred in bytes and no CRC is appended at the end of each
block.
8 × 2 writebllen ) ( – NSAC ))
Maximumspeed = MIN (TRANSPEED,(------------------------------------------------------------------------
TAAC × R2WFACTOR
8 × 2 readbllen ) ( – NSAC ))
Maximumspeed = MIN (TRANSPEED,(-----------------------------------------------------------------------
TAAC × R2WFACTOR
The card indicates that an erase is in progress by holding SDIO_D low. The actual erase
time may be quite long, and the host may issue CMD7 to deselect the card.
Password protect
The password protection feature enables the SDIO card host module to lock and unlock a
card with a password. The password is stored in the 128-bit PWD register and its size is set
in the 8-bit PWD_LEN register. These registers are nonvolatile so that a power cycle does
not erase them. Locked cards respond to and execute certain commands. This means that
the SDIO card host module is allowed to reset, initialize, select, and query for status,
however it is not allowed to access data on the card. When the password is set (as indicated
by a nonzero value of PWD_LEN), the card is locked automatically after power-up. As with
the CSD and CID register write commands, the lock/unlock commands are available in the
transfer state only. In this state, the command does not include an address argument and
the card must be selected before using it. The card lock/unlock commands have the
structure and bus transaction types of a regular single-block write command. The
transferred data block includes all of the required information for the command (the
password setting mode, the PWD itself, and card lock/unlock). The command data block
size is defined by the SDIO card host module before it sends the card lock/unlock command,
and has the structure shown in Table 158.
The bit settings are as follows:
● ERASE: setting it forces an erase operation. All other bits must be zero, and only the
command byte is sent
● LOCK_UNLOCK: setting it locks the card. LOCK_UNLOCK can be set simultaneously
with SET_PWD, however not with CLR_PWD
● CLR_PWD: setting it clears the password data
● SET_PWD: setting it saves the password data to memory
● PWD_LEN: it defines the length of the password in bytes
● PWD: the password (new or currently used, depending on the command)
The following sections list the command sequences to set/reset a password, lock/unlock the
card, and force an erase.
Locking a card
1. Select a card (SELECT/DESELECT_CARD, CMD7), if none is already selected.
2. Define the block length (SET_BLOCKLEN, CMD16) to send, given by the 8-bit card
lock/unlock mode (byte 0 in Table 158), the 8-bit PWD_LEN, and the number of bytes of
the current password.
3. Send LOCK/UNLOCK (CMD42) with the appropriate data block size on the data line
including the 16-bit CRC. The data block indicates the mode (LOCK_UNLOCK = 1), the
length (PWD_LEN), and the password (PWD) itself.
4. When the password is matched, the card is locked and the CARD_IS_LOCKED status
bit is set in the card status register. When the password sent does not correspond (in
size and/or content) to the expected password, the LOCK_UNLOCK_FAILED error bit
is set in the card status register, and the lock fails.
It is possible to set the password and to lock the card in the same sequence. In this case,
the SDIO card host module performs all the required steps for setting the password (see
Setting the password on page 562), however it is necessary to set the LOCK_UNLOCK bit
in Step 3 when the new password command is sent.
When the password is previously set (PWD_LEN is not 0), the card is locked automatically
after power on reset. An attempt to lock a locked card or to lock a card that does not have a
password fails and the LOCK_UNLOCK_FAILED error bit is set in the card status register.
The unlocking function is only valid for the current power session. When the PWD field is not
clear, the card is locked automatically on the next power-up.
An attempt to unlock an unlocked card fails and the LOCK_UNLOCK_FAILED error bit is set
in the card status register.
Forcing erase
If the user has forgotten the password (PWD content), it is possible to access the card after
clearing all the data on the card. This forced erase operation erases all card data and all
password data.
1. Select a card (SELECT/DESELECT_CARD, CMD7), if none is already selected.
2. Set the block length (SET_BLOCKLEN, CMD16) to 1 byte. Only the 8-bit card
lock/unlock byte (byte 0 in Table 158) is sent.
3. Send LOCK/UNLOCK (CMD42) with the appropriate data byte on the data line including
the 16-bit CRC. The data block indicates the mode (ERASE = 1). All other bits must be
zero.
4. When the ERASE bit is the only bit set in the data field, all card contents are erased,
including the PWD and PWD_LEN fields, and the card is no longer locked. When any
other bits are set, the LOCK_UNLOCK_FAILED error bit is set in the card status
register and the card retains all of its data, and remains locked.
An attempt to use a force erase on an unlocked card fails and the LOCK_UNLOCK_FAILED
error bit is set in the card status register.
SIZE_OF_PROTECTED_AREA
Setting this field differs between standard- and high-capacity cards. In the case of a
standard-capacity card, the capacity of protected area is calculated as follows:
Protected area = SIZE_OF_PROTECTED_AREA_* MULT * BLOCK_LEN.
SIZE_OF_PROTECTED_AREA is specified by the unit in MULT*BLOCK_LEN.
In the case of a high-capacity card, the capacity of protected area is specified in this field:
Protected area = SIZE_OF_PROTECTED_AREA
SIZE_OF_PROTECTED_AREA is specified by the unit in bytes.
SPEED_CLASS
This 8-bit field indicates the speed class and the value can be calculated by PW/2 (where
PW is the write performance).
00h Class 0
01h Class 2
02h Class 4
03h Class 6
04h – FFh Reserved
PERFORMANCE_MOVE
This 8-bit field indicates Pm (performance move) and the value can be set by 1 [MB/sec]
steps. If the card does not move used RUs (recording units), Pm should be considered as
infinity. Setting the field to FFh means infinity.
AU_SIZE
This 4-bit field indicates the AU size and the value can be selected in the power of 2 base
from 16 KB.
09h 4 MB
Ah – Fh Reserved
The maximum AU size, which depends on the card capacity, is defined in Table 150. The
card can be set to any AU size between RU size and maximum AU size.
ERASE_SIZE
This 16-bit field indicates NERASE. When NERASE numbers of AUs are erased, the timeout
value is specified by ERASE_TIMEOUT (Refer to ERASE_TIMEOUT). The host should
determine the proper number of AUs to be erased in one operation so that the host can
show the progress of the erase operation. If this field is set to 0, the erase timeout
calculation is not supported.
ERASE_TIMEOUT
This 6-bit field indicates TERASE and the value indicates the erase timeout from offset when
multiple AUs are being erased as specified by ERASE_SIZE. The range of
ERASE_TIMEOUT can be defined as up to 63 seconds and the card manufacturer can
choose any combination of ERASE_SIZE and ERASE_TIMEOUT depending on the
implementation. Determining ERASE_TIMEOUT determines the ERASE_SIZE.
--------- ---------
63 63 [sec]
ERASE_OFFSET
This 2-bit field indicates TOFFSET and one of four values can be selected. This field is
meaningless if the ERASE_SIZE and ERASE_TIMEOUT fields are set to 0.
0h 0 [sec]
1h 1 [sec]
2h 2 [sec]
3h 3 [sec]
suspend/resume operation on the MMC/SD bus, the MMC/SD module performs the
following steps:
1. Determines the function currently using the SDIO_D [3:0] line(s)
2. Requests the lower-priority or slower transaction to suspend
3. Waits for the transaction suspension to complete
4. Begins the higher-priority transaction
5. Waits for the completion of the higher priority transaction
6. Restores the suspended transaction
SD I/O ReadWait
The optional ReadWait (RW) operation is defined only for the SD 1-bit and 4-bit modes. The
ReadWait operation allows the MMC/SD module to signal a card that it is reading multiple
registers (IO_RW_EXTENDED, CMD53) to temporarily stall the data transfer while allowing
the MMC/SD module to send commands to any function within the SD I/O device. To
determine when a card supports the ReadWait protocol, the MMC/SD module must test
capability bits in the internal card registers. The timing for ReadWait is based on the
interrupt period.
The bus transaction for a GEN_CMD is the same as the single-block read or write
commands (WRITE_BLOCK, CMD24 or READ_SINGLE_BLOCK,CMD17). In this case, the
argument denotes the direction of the data transfer rather than the address, and the data
block has vendor-specific format and meaning.
The card must be selected (in transfer state) before sending GEN_CMD (CMD56). The data
block size is defined by SET_BLOCKLEN (CMD16). The response to GEN_CMD (CMD56)
is in R1b format.
Command types
Both application-specific and general commands are divided into the four following types:
● broadcast command (BC): sent to all cards; no responses returned.
● broadcast command with response (BCR): sent to all cards; responses received
from all cards simultaneously.
● addressed (point-to-point) command (AC): sent to the card that is selected; does
not include a data transfer on the SDIO_D line(s).
● addressed (point-to-point) data transfer command (ADTC): sent to the card that is
selected; includes a data transfer on the SDIO_D line(s).
Command formats
See Table 138 on page 549 for command formats.
CMD32
Reserved. These command indexes cannot be used in order to maintain backward compatibility with older
...
versions of the MultiMediaCard.
CMD34
Sets the address of the first erase
CMD35 ac [31:0] data address R1 ERASE_GROUP_START group within a range to be selected
for erase.
Sets the address of the last erase
CMD36 ac [31:0] data address R1 ERASE_GROUP_END group within a continuous range to be
selected for erase.
Reserved. This command index cannot be used in order to maintain backward compatibility with older
CMD37
versions of the MultiMediaCards
Erases all previously selected write
CMD38 ac [31:0] stuff bits R1 ERASE
blocks.
CMD40 bcr [31:0] stuff bits R5 GO_IRQ_STATE Places the system in the interrupt mode.
CMD41 Reserved
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 X Command index
[39:8] 32 X Card status
[7:1] 7 X CRC7
0 1 1 End bit
22.5.2 R1b
It is identical to R1 with an optional busy signal transmitted on the data line. The card may
become busy after receiving these commands based on its state prior to the command
reception.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘111111’ Reserved
[39:8] 32 X OCR register
[7:1] 7 ‘1111111’ Reserved
0 1 1 End bit
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘100111’ CMD39
[31:16] 16 X RCA
[39:8] Argument field [15:8] 8 X register address
[7:0] 8 X read register contents
[7:1] 7 X CRC7
0 1 1 End bit
22.5.6 R4b
For SD I/O only: an SDIO card receiving the CMD5 will respond with a unique SDIO
response R4. The format is:
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 X Reserved
39 16 X Card is ready
[38:36] 3 X Number of I/O functions
[39:8] Argument field 35 1 X Present memory
[34:32] 3 X Stuff bits
[31:8] 24 X I/O ORC
[7:1] 7 X Reserved
0 1 1 End bit
Once an SD I/O card has received a CMD5, the I/O portion of that card is enabled to
respond normally to all further commands. This I/O enable of the function within the I/O card
will remain set until a reset, power cycle or CMD52 with write to I/O reset is received by the
card. Note that an SD memory-only card may respond to a CMD5. The proper response for
a memory-only card would be Present memory = 1 and Number of I/O functions = 0. A
memory-only card built to meet the SD Memory Card specification version 1.0 would detect
the CMD5 as an illegal command and not respond. The I/O aware host will send CMD5. If
the card responds with response R4, the host determines the card’s configuration based on
the data contained within the R4 response.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘101000’ CMD40
RCA [31:16] of winning
[31:16] 16 X
card or of the host
[39:8] Argument field
Not defined. May be used
[15:0] 16 X
for IRQ data
[7:1] 7 X CRC7
0 1 1 End bit
22.5.8 R6
Only for SD I/O. The normal response to CMD3 by a memory device. It is shown in
Table 166.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘101000’ CMD40
The card [23:8] status bits are changed when CMD3 is sent to an I/O-only card. In this case,
the 16 bits of response are the SD I/O-only values:
● Bit [15] COM_CRC_ERROR
● Bit [14] ILLEGAL_COMMAND
● Bit [13] ERROR
● Bits [12:0] Reserved
As SDIO_CK is stopped, any command can be issued to the card. During a read/wait
interval, the SDIO can detect SDIO interrupts on SDIO_D1.
When ‘0’ is received on the CMD line, the CPSM enters the Idle state. No new command
can be sent for 7 bit cycles. Then, for the last 5 cycles (out of the 7) the CMD line is driven to
‘1’ in push-pull mode.
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
PWRC
Reserved TRL
rw rw
Note: At least seven HCLK clock periods are needed between two write accesses to this register.
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
NEGEDGE
HWFC_EN
PWRSAV
BYPASS
CLKEN
WID
CLKDIV
Reserved BUS
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: 1 While the SD/SDIO card or MultiMediaCard is in identification mode, the SDIO_CK
frequency must be less than 400 kHz.
2 The clock frequency can be changed to the maximum card bus frequency when relative
card addresses are assigned to all cards.
3 At least seven HCLK clock periods are needed between two write accesses to this register.
SDIO_CK can also be stopped during the read wait interval for SD I/O cards: in this case the
SDIO_CLKCR register does not control SDIO_CK.
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
CMDARG
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
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
SDIOSuspend
ENCMDcompl
CE-ATACMD
CMDINDEX
WAITPEND
WAITRESP
CPSMEN
WAITINT
nIEN
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: 1 At least seven HCLK clock periods are needed between two write accesses to this register.
2 MultiMediaCards can send two kinds of response: short responses, 48 bits long, or long
responses,136 bits long. SD card and SD I/O card can send only short responses, the
argument can vary according to the type of response: the software will distinguish the type
of response according to the sent command. CE-ATA devices send only short responses.
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
RESPCMD
Reserved
r r r r r r
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
CARDSTATUSx
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
The Card Status size is 32 or 127 bits, depending on the response type.
The most significant bit of the card status is received first. The SDIO_RESP3 register LSB is
always 0b.
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
DATATIME
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
Note: A data transfer must be written to the data timer register and the data length register before
being written to the data control register.
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
DATALENGTH
Reserved
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
Note: For a block data transfer, the value in the data length register must be a multiple of the block
size (see SDIO_DCTRL). A data transfer must be written to the data timer register and the
data length register before being written to the data control register.
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
RWSTART
DTMODE
RWSTOP
RWMOD
SDIOEN
DMAEN
DTDIR
DTEN
DBLOCKSIZE
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
Bit 2 DTMODE: Data transfer mode selection 1: Stream or SDIO multibyte data transfer.
0: Block data transfer
1: Stream or SDIO multibyte data transfer on STM32F10xxx XL-density devices.
Stream data transfer on STM32F10xxx high-density devices.
Bit 1 DTDIR: Data transfer direction selection
0: From controller to card.
1: From card to controller.
[0] DTEN: Data transfer enabled bit
Data transfer starts if 1b is written to the DTEN bit. Depending on the direction bit, DTDIR,
the DPSM moves to the Wait_S, Wait_R state or Readwait if RW Start is set immediately at
the beginning of the transfer. It is not necessary to clear the enable bit after the end of a data
transfer but the SDIO_DCTRL must be updated to enable a new data transfer
Note: At least seven HCLK clock periods are needed between two write accesses to this register.
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
DATACOUNT
Reserved
r r r r r r r r r r r r r r r r r r r r r r r r r
Note: This register should be read only when the data transfer is complete.
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
TXUNDERR
DTIMEOUT
CTIMEOUT
CEATAEND
CMDREND
RXFIFOHF
STBITERR
CMDSENT
TXFIFOHE
DCRCFAIL
CCRCFAIL
DBCKEND
RXOVERR
DATAEND
RXFIFOE
Reserved
RXFIFOF
TXFIFOE
CMDACT
TXFIFOF
RXDAVL
TXDAVL
RXACT
SDIOIT
TXACT
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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TXUNDERRC
DTIMEOUTC
CTIMEOUTC
CEATAENDC
CMDRENDC
STBITERRC
CMDSENTC
DCRCFAILC
CCRCFAILC
RXOVERRC
DBCKENDC
DATAENDC
SDIOITC
Reserved Reserved
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
TXUNDERRIE
DTIMEOUTIE
CTIMEOUTIE
CEATAENDIE
CMDRENDIE
RXFIFOHFIE
STBITERRIE
CMDSENTIE
TXFIFOHEIE
DCRCFAILIE
CCRCFAILIE
DBCKENDIE
RXOVERRIE
DATAENDIE
RXFIFOEIE
RXFIFOFIE
TXFIFOEIE
CMDACTIE
TXFIFOFIE
RXDAVLIE
TXDAVLIE
RXACTIE
SDIOITIE
TXACTIE
Reserved
rw rw rw rw rw rw rw rw 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
FIFOCOUNT
Reserved
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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FIF0Data
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
9
8
7
6
5
4
3
2
1
0
PWRCTRL
Reserved
0x00 SDIO_POWER
NEGEDGE
HWFC_EN
Reserved
PWRSAV
WIDBUS
BYPASS
CLKDIV
CLKEN
0x04 SDIO_CLKCR
CMDINDEX
WAITPEND
WAITRESP
Reserved
CPSMEN
WAITINT
nIEN
0x0C SDIO_CMD
SDIO_RESPCM
0x10 Reserved RESPCMD
D
0x14 SDIO_RESP1 CARDSTATUS1
0x18 SDIO_RESP2 CARDSTATUS2
0x1C SDIO_RESP3 CARDSTATUS3
0x20 SDIO_RESP4 CARDSTATUS4
0x24 SDIO_DTIMER DATATIME
0x28 SDIO_DLEN Reserved DATALENGTH
DBLOCKSIZE
RWSTART
DTMODE
RWSTOP
Reserved
RWMOD
SDIOEN
DMAEN
DTDIR
DTEN
0x2C SDIO_DCTRL
CMDREND
RXFIFOHF
TXFIFOHE
STBITERR
CMDSENT
DCRCFAIL
CCRCFAIL
RXOVERR
DBCKEND
DATAEND
RXFIFOE
RXFIFOF
Reserved
TXFIFOE
CMDACT
TXFIFOF
RXDAVL
TXDAVL
RXACT
SDIOIT
TXACT
0x34 SDIO_STA
0x3C
Offset
596/1096
SDIO_ICR
Register
SDIO_FIFO
SDIO_MASK
SDIO_FIFOCNT
31
30
29
Reserved Reserved 28
27
Reserved
26
25
24
CEATAENDIE CEATAENDC 23
SDIOITIE SDIOITC 22
Table 168. SDIO register map (continued)
Secure digital input/output interface (SDIO)
RXDAVLIE 21
TXDAVLIE 20
RXFIFOEIE 19
TXFIFOEIE 18
RXFIFOFIE 17
TXFIFOFIE Reserved
16
TXFIFOHEIE 14
RXACTIE 13
TXACTIE 12
CMDACTIE 11
FIFOCOUNT
DBCKENDIE DBCKENDC 10
Refer to Table 3 on page 50 for the register boundary addresses.
STBITERRIE STBITERRC 9
DATAENDIE DATAENDC 8
CMDSENTIE CMDSENTC 7
CMDRENDIE CMDRENDC 6
RXOVERRIE RXOVERRC 5
TXUNDERRIE TXUNDERRC 4
DTIMEOUTIE DTIMEOUTC 3
CTIMEOUTIE CTIMEOUTC 2
DCRCFAILIE DCRCFAILC 1
CCRCFAILIE CCRCFAILC
RM0008
0
RM0008 Universal serial bus full-speed device interface (USB)
DP DM
USB
Control
RX-TX Clock
registers & logic
Suspend recovery
timer Control
Endpoint Interrupt
selection registers & logic
S.I.E.
Packet
buffer Endpoint Endpoint
interface registers registers
Packet
Register Interrupt
Arbiter buffer
mapper mapper
memory
APB1 wrapper
APB1 interface
PCLK1 APB1 bus IRQs to NVIC
The USB peripheral provides an USB compliant connection between the host PC and the
function implemented by the microcontroller. Data transfer between the host PC and the
system memory occurs through a dedicated packet buffer memory accessed directly by the
USB peripheral. The size of this dedicated buffer memory must be according to the number
of endpoints used and the maximum packet size. This dedicated memory is sized to 512
bytes and up to 16 mono-directional or 8 bidirectional endpoints can be used.The USB
peripheral interfaces with the USB host, detecting token packets, handling data
transmission/reception, and processing handshake packets as required by the USB
standard. Transaction formatting is performed by the hardware, including CRC generation
and checking.
Each endpoint is associated with a buffer description block indicating where the endpoint
related memory area is located, how large it is or how many bytes must be transmitted.
When a token for a valid function/endpoint pair is recognized by the USB peripheral, the
related data transfer (if required and if the endpoint is configured) takes place. The data
buffered by the USB peripheral is loaded in an internal 16 bit register and memory access to
the dedicated buffer is performed. When all the data has been transferred, if needed, the
proper handshake packet over the USB is generated or expected according to the direction
of the transfer.
At the end of the transaction, an endpoint-specific interrupt is generated, reading status
registers and/or using different interrupt response routines. The microcontroller can
determine:
● Which endpoint has to be served
● Which type of transaction took place, if errors occurred (bit stuffing, format, CRC,
protocol, missing ACK, over/underrun, etc.)
Special support is offered to Isochronous transfers and high throughput bulk transfers,
implementing a double buffer usage, which allows to always have an available buffer for the
USB peripheral while the microcontroller uses the other one.
The unit can be placed in low-power mode (SUSPEND mode), by writing in the control
register, whenever required. At this time, all static power dissipation is avoided, and the USB
clock can be slowed down or stopped. The detection of activity at the USB inputs, while in
low-power mode, wakes the device up asynchronously. A special interrupt source can be
connected directly to a wakeup line to allow the system to immediately restart the normal
clock generation and/or support direct clock start/stop.
● Control Registers: These are the registers containing information about the status of
the whole USB peripheral and used to force some USB events, such as resume and
power-down.
● Interrupt Registers: These contain the Interrupt masks and a record of the events. They
can be used to inquire an interrupt reason, the interrupt status or to clear the status of a
pending interrupt.
Note: * Endpoint 0 is always used for control transfer in single-buffer mode.
The USB peripheral is connected to the APB1 bus through an APB1 interface, containing
the following blocks:
● Packet Memory: This is the local memory that physically contains the Packet Buffers. It
can be used by the Packet Buffer interface, which creates the data structure and can be
accessed directly by the application software. The size of the Packet Memory is 512
bytes, structured as 256 words by 16 bits.
● Arbiter: This block accepts memory requests coming from the APB1 bus and from the
USB interface. It resolves the conflicts by giving priority to APB1 accesses, while
always reserving half of the memory bandwidth to complete all USB transfers. This
time-duplex scheme implements a virtual dual-port SRAM that allows memory access,
while an USB transaction is happening. Multiword APB1 transfers of any length are
also allowed by this scheme.
● Register Mapper: This block collects the various byte-wide and bit-wide registers of the
USB peripheral in a structured 16-bit wide word set addressed by the APB1.
● APB1 Wrapper: This provides an interface to the APB1 for the memory and register. It
also maps the whole USB peripheral in the APB1 address space.
● Interrupt Mapper: This block is used to select how the possible USB events can
generate interrupts and map them to three different lines of the NVIC:
– USB low-priority interrupt (Channel 20): Triggered by all USB events (Correct
transfer, USB reset, etc.). The firmware has to check the interrupt source before
serving the interrupt.
– USB high-priority interrupt (Channel 19): Triggered only by a correct transfer event
for isochronous and double-buffer bulk transfer to reach the highest possible
transfer rate.
– USB wakeup interrupt (Channel 42): Triggered by the wakeup event from the USB
Suspend mode.
accesses. The USB peripheral logic uses a dedicated clock. The frequency of this dedicated
clock is fixed by the requirements of the USB standard at 48 MHz, and this can be different
from the clock used for the interface to the APB1 bus. Different clock configurations are
possible where the APB1 clock frequency can be higher or lower than the USB peripheral
one.
Note: Due to USB data rate and packet memory interface requirements, the APB1 clock frequency
must be greater than 8 MHz to avoid data overrun/underrun problems.
Each endpoint is associated with two packet buffers (usually one for transmission and the
other one for reception). Buffers can be placed anywhere inside the packet memory
because their location and size is specified in a buffer description table, which is also
located in the packet memory at the address indicated by the USB_BTABLE register. Each
table entry is associated to an endpoint register and it is composed of four 16-bit words so
that table start address must always be aligned to an 8-byte boundary (the lowest three bits
of USB_BTABLE register are always “000”). Buffer descriptor table entries are described in
the Section 23.5.3: Buffer descriptor table. If an endpoint is unidirectional and it is neither an
Isochronous nor a double-buffered bulk, only one packet buffer is required (the one related
to the supported transfer direction). Other table locations related to unsupported transfer
directions or unused endpoints, are available to the user. Isochronous and double-buffered
bulk endpoints have special handling of packet buffers (Refer to Section 23.4.4: Isochronous
transfers and Section 23.4.3: Double-buffered endpoints respectively). The relationship
between buffer description table entries and packet buffer areas is depicted in Figure 220.
Figure 220. Packet buffer areas with examples of buffer description table locations
Buffer for
double-buffered
IN Endpoint 3
Each packet buffer is used either during reception or transmission starting from the bottom.
The USB peripheral will never change the contents of memory locations adjacent to the
allocated memory buffers; if a packet bigger than the allocated buffer length is received
(buffer overrun condition) the data will be copied to the memory only up to the last available
location.
Endpoint initialization
The first step to initialize an endpoint is to write appropriate values to the
ADDRn_TX/ADDRn_RX registers so that the USB peripheral finds the data to be
transmitted already available and the data to be received can be buffered. The EP_TYPE
bits in the USB_EPnR register must be set according to the endpoint type, eventually using
the EP_KIND bit to enable any special required feature. On the transmit side, the endpoint
must be enabled using the STAT_TX bits in the USB_EPnR register and COUNTn_TX must
be initialized. For reception, STAT_RX bits must be set to enable reception and
COUNTn_RX must be written with the allocated buffer size using the BL_SIZE and
NUM_BLOCK fields. Unidirectional endpoints, except Isochronous and double-buffered bulk
endpoints, need to initialize only bits and registers related to the supported direction. Once
the transmission and/or reception are enabled, register USB_EPnR and locations
ADDRn_TX/ADDRn_RX, COUNTn_TX/COUNTn_RX (respectively), should not be modified
by the application software, as the hardware can change their value on the fly. When the
data transfer operation is completed, notified by a CTR interrupt event, they can be
accessed again to re-enable a new operation.
condition: the USB host will retry the transaction until it succeeds. It is mandatory to execute
the sequence of operations in the above mentioned order to avoid losing the notification of a
second IN transaction addressed to the same endpoint immediately following the one which
triggered the CTR interrupt.
processed. After the received data is processed, the application software should set the
STAT_RX bits to ‘11 (Valid) in the USB_EPnR, enabling further transactions. While the
STAT_RX bits are equal to ‘10 (NAK), any OUT request addressed to that endpoint is
NAKed, indicating a flow control condition: the USB host will retry the transaction until it
succeeds. It is mandatory to execute the sequence of operations in the above mentioned
order to avoid losing the notification of a second OUT transaction addressed to the same
endpoint following immediately the one which triggered the CTR interrupt.
Control transfers
Control transfers are made of a SETUP transaction, followed by zero or more data stages,
all of the same direction, followed by a status stage (a zero-byte transfer in the opposite
direction). SETUP transactions are handled by control endpoints only and are very similar to
OUT ones (data reception) except that the values of DTOG_TX and DTOG_RX bits of the
addressed endpoint registers are set to 1 and 0 respectively, to initialize the control transfer,
and both STAT_TX and STAT_RX are set to ‘10 (NAK) to let software decide if subsequent
transactions must be IN or OUT depending on the SETUP contents. A control endpoint must
check SETUP bit in the USB_EPnR register at each CTR_RX event to distinguish normal
OUT transactions from SETUP ones. A USB device can determine the number and direction
of data stages by interpreting the data transferred in the SETUP stage, and is required to
STALL the transaction in the case of errors. To do so, at all data stages before the last, the
unused direction should be set to STALL, so that, if the host reverses the transfer direction
too soon, it gets a STALL as a status stage.
While enabling the last data stage, the opposite direction should be set to NAK, so that, if
the host reverses the transfer direction (to perform the status stage) immediately, it is kept
waiting for the completion of the control operation. If the control operation completes
successfully, the software will change NAK to VALID, otherwise to STALL. At the same time,
if the status stage will be an OUT, the STATUS_OUT (EP_KIND in the USB_EPnR register)
bit should be set, so that an error is generated if a status transaction is performed with not-
zero data. When the status transaction is serviced, the application clears the STATUS_OUT
bit and sets STAT_RX to VALID (to accept a new command) and STAT_TX to NAK (to delay
a possible status stage immediately following the next setup).
Since the USB specification states that a SETUP packet cannot be answered with a
handshake different from ACK, eventually aborting a previously issued command to start the
new one, the USB logic doesn’t allow a control endpoint to answer with a NAK or STALL
packet to a SETUP token received from the host.
When the STAT_RX bits are set to ‘01 (STALL) or ‘10 (NAK) and a SETUP token is received,
the USB accepts the data, performing the required data transfers and sends back an ACK
handshake. If that endpoint has a previously issued CTR_RX request not yet acknowledged
by the application (i.e. CTR_RX bit is still set from a previously completed reception), the
USB discards the SETUP transaction and does not answer with any handshake packet
regardless of its state, simulating a reception error and forcing the host to send the SETUP
token again. This is done to avoid losing the notification of a SETUP transaction addressed
to the same endpoint immediately following the transaction, which triggered the CTR_RX
interrupt.
bulk endpoint type is the most suited model. This is because the host schedules bulk
transactions so as to fill all the available bandwidth in the frame, maximizing the actual
transfer rate as long as the USB function is ready to handle a bulk transaction addressed to
it. If the USB function is still busy with the previous transaction when the next one arrives, it
will answer with a NAK handshake and the host PC will issue the same transaction again
until the USB function is ready to handle it, reducing the actual transfer rate due to the
bandwidth occupied by re-transmissions. For this reason, a dedicated feature called
‘double-buffering’ can be used with bulk endpoints.
When ‘double-buffering’ is activated, data toggle sequencing is used to select, which buffer
is to be used by the USB peripheral to perform the required data transfers, using both
‘transmission’ and ‘reception’ packet memory areas to manage buffer swapping on each
successful transaction in order to always have a complete buffer to be used by the
application, while the USB peripheral fills the other one. For example, during an OUT
transaction directed to a ‘reception’ double-buffered bulk endpoint, while one buffer is being
filled with new data coming from the USB host, the other one is available for the
microcontroller software usage (the same would happen with a ‘transmission’ double-
buffered bulk endpoint and an IN transaction).
Since the swapped buffer management requires the usage of all 4 buffer description table
locations hosting the address pointer and the length of the allocated memory buffers, the
USB_EPnR registers used to implement double-buffered bulk endpoints are forced to be
used as unidirectional ones. Therefore, only one STAT bit pair must be set at a value
different from ‘00 (Disabled): STAT_RX if the double-buffered bulk endpoint is enabled for
reception, STAT_TX if the double-buffered bulk endpoint is enabled for transmission. In case
it is required to have double-buffered bulk endpoints enabled both for reception and
transmission, two USB_EPnR registers must be used.
To exploit the double-buffering feature and reach the highest possible transfer rate, the
endpoint flow control structure, described in previous chapters, has to be modified, in order
to switch the endpoint status to NAK only when a buffer conflict occurs between the USB
peripheral and application software, instead of doing it at the end of each successful
transaction. The memory buffer which is currently being used by the USB peripheral is
defined by the DTOG bit related to the endpoint direction: DTOG_RX (bit 14 of USB_EPnR
register) for ‘reception’ double-buffered bulk endpoints or DTOG_TX (bit 6 of USB_EPnR
register) for ‘transmission’ double-buffered bulk endpoints. To implement the new flow
control scheme, the USB peripheral should know which packet buffer is currently in use by
the application software, so to be aware of any conflict. Since in the USB_EPnR register,
there are two DTOG bits but only one is used by USB peripheral for data and buffer
sequencing (due to the unidirectional constraint required by double-buffering feature) the
other one can be used by the application software to show which buffer it is currently using.
This new buffer flag is called SW_BUF. In the following table the correspondence between
USB_EPnR register bits and DTOG/SW_BUF definition is explained, for the cases of
‘transmission’ and ‘reception’ double-buffered bulk endpoints.
The memory buffer which is currently being used by the USB peripheral is defined by DTOG
buffer flag, while the buffer currently in use by application software is identified by SW_BUF
buffer flag. The relationship between the buffer flag value and the used packet buffer is the
same in both cases, and it is listed in the following table.
The application software can always override the special flow control implemented for
double-buffered bulk endpoints, writing an explicit status different from ‘11 (Valid) into the
STAT bit pair of the related USB_EPnR register. In this case, the USB peripheral will always
use the programmed endpoint status, regardless of the buffer usage condition.
When an USB event occurs while the device is in SUSPEND mode, the RESUME procedure
must be invoked to restore nominal clocks and regain normal USB behavior. Particular care
must be taken to insure that this process does not take more than 10mS when the wakening
event is an USB reset sequence (See “Universal Serial Bus Specification” for more details).
The start of a resume or reset sequence, while the USB peripheral is suspended, clears the
LP_MODE bit in USB_CNTR register asynchronously. Even if this event can trigger an
WKUP interrupt if enabled, the use of an interrupt response routine must be carefully
evaluated because of the long latency due to system clock restart; to have the shorter
latency before re-activating the nominal clock it is suggested to put the resume procedure
just after the end of the suspend one, so its code is immediately executed as soon as the
system clock restarts. To prevent ESD discharges or any other kind of noise from waking-up
the system (the exit from suspend mode is an asynchronous event), a suitable analog filter
on data line status is activated during suspend; the filter width is about 70ns.
The following is a list of actions a resume procedure should address:
1. Optionally turn on external oscillator and/or device PLL.
2. Clear FSUSP bit of USB_CNTR register.
3. If the resume triggering event has to be identified, bits RXDP and RXDM in the
USB_FNR register can be used according to Table 172, which also lists the intended
software action in all the cases. If required, the end of resume or reset sequence can
be detected monitoring the status of the above mentioned bits by checking when they
reach the “10” configuration, which represent the Idle bus state; moreover at the end of
a reset sequence the RESET bit in USB_ISTR register is set to 1, issuing an interrupt if
enabled, which should be handled as usual.
A device may require to exit from suspend mode as an answer to particular events not
directly related to the USB protocol (e.g. a mouse movement wakes up the whole system).
In this case, the resume sequence can be started by setting the RESUME bit in the
USB_CNTR register to ‘1 and resetting it to 0 after an interval between 1mS and 15mS (this
interval can be timed using ESOF interrupts, occurring with a 1mS period when the system
clock is running at nominal frequency). Once the RESUME bit is clear, the resume
sequence will be completed by the host PC and its end can be monitored again using the
RXDP and RXDM bits in the USB_FNR register.
Note: The RESUME bit must be anyway used only after the USB peripheral has been put in
suspend mode, setting the FSUSP bit in USB_CNTR register to 1.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CTRM PMAOVRM ERRM WKUPM SUSPM RESETM SOFM ESOFM RESUME FSUSP LP_MODE PDWN FRES
Reserved
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
PMA
CTR ERR WKUP SUSP RESET SOF ESOF DIR EP_ID[3:0]
OVR
Reserved
r rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 r r r r r
This register contains the status of all the interrupt sources allowing application software to
determine, which events caused an interrupt request.
The upper part of this register contains single bits, each of them representing a specific
event. These bits are set by the hardware when the related event occurs; if the
corresponding bit in the USB_CNTR register is set, a generic interrupt request is generated.
The interrupt routine, examining each bit, will perform all necessary actions, and finally it will
clear the serviced bits. If any of them is not cleared, the interrupt is considered to be still
pending, and the interrupt line will be kept high again. If several bits are set simultaneously,
only a single interrupt will be generated.
Endpoint transaction completion can be handled in a different way to reduce interrupt
response latency. The CTR bit is set by the hardware as soon as an endpoint successfully
completes a transaction, generating a generic interrupt request if the corresponding bit in
USB_CNTR is set. An endpoint dedicated interrupt condition is activated independently
from the CTRM bit in the USB_CNTR register. Both interrupt conditions remain active until
software clears the pending bit in the corresponding USB_EPnR register (the CTR bit is
actually a read only bit). For endpoint-related interrupts, the software can use the Direction
of Transaction (DIR) and EP_ID read-only bits to identify, which endpoint made the last
interrupt request and called the corresponding interrupt service routine.
The user can choose the relative priority of simultaneously pending USB_ISTR events by
specifying the order in which software checks USB_ISTR bits in an interrupt service routine.
Only the bits related to events, which are serviced, are cleared. At the end of the service
routine, another interrupt will be requested, to service the remaining conditions.
To avoid spurious clearing of some bits, it is recommended to clear them with a load
instruction where all bits which must not be altered are written with 1, and all bits to be
cleared are written with ‘0 (these bits can only be cleared by software). Read-modify-write
cycles should be avoided because between the read and the write operations another bit
could be set by the hardware and the next write will clear it before the microprocessor has
the time to serve the event.
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 r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BTABLE[15:3]
Reserved
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
rc_w0 t t t r rw rw rw rc_w0 t t t rw rw rw rw
They are also reset when an USB reset is received from the USB bus or forced through bit
FRES in the CTLR register, except the CTR_RX and CTR_TX bits, which are kept
unchanged to avoid missing a correct packet notification immediately followed by an USB
reset event. Each endpoint has its USB_EPnR register where n is the endpoint identifier.
Read-modify-write cycles on these registers should be avoided because between the read
and the write operations some bits could be set by the hardware and the next write would
modify them before the CPU has the time to detect the change. For this purpose, all bits
affected by this problem have an ‘invariant’ value that must be used whenever their
modification is not required. It is recommended to modify these registers with a load
instruction where all the bits, which can be modified only by the hardware, are written with
their ‘invariant’ value.
00 BULK
01 CONTROL
10 ISO
11 INTERRUPT
00 BULK DBL_BUF
01 CONTROL STATUS_OUT
10 ISO Not used
11 INTERRUPT Not used
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADDRn_TX[15:1] -
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
COUNTn_TX[9:0]
Reserved
rw rw rw rw rw rw rw rw rw rw
Bits 15:10 These bits are not used since packet size is limited by USB specifications to 1023 bytes. Their
value is not considered by the USB peripheral.
Bits 9:0 COUNTn_TX[9:0]: Transmission byte count
These bits contain the number of bytes to be transmitted by the endpoint associated with the
USB_EPnR register at the next IN token addressed to it.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
COUNTn_TX_1[9:0]
Reserved
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
COUNTn_TX_0[9:0]
Reserved
rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADDRn_RX[15:1] -
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 r r r r r r r r r r
This table location is used to store two different values, both required during packet
reception. The most significant bits contains the definition of allocated buffer size, to allow
buffer overflow detection, while the least significant part of this location is written back by the
USB peripheral at the end of reception to give the actual number of received bytes. Due to
the restrictions on the number of available bits, buffer size is represented using the number
of allocated memory blocks, where block size can be selected to choose the trade-off
between fine-granularity/small-buffer and coarse-granularity/large-buffer. The size of
allocated buffer is a part of the endpoint descriptor and it is normally defined during the
enumeration process according to its maxPacketSize parameter value (See “Universal
Serial Bus Specification”).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BLSIZE
NUM_BLOCK_1[4:0] COUNTn_RX_1[9:0]
_1
rw rw rw rw rw rw r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BLSIZE
NUM_BLOCK_0[4:0] COUNTn_RX_0[9:0]
_0
rw rw rw rw rw rw r r r r r r r r r r
DTOG_TX
EP_KIND
CTR_RX
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR_TX
STAT_ EP STAT_
SETUP
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR_TX
STAT_ EP STAT_
SETUP
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR_TX
STAT_ EP STAT_
SETUP
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR_TX
STAT_ EP STAT_
SETUP
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR_TX
STAT_ EP STAT_
SETUP
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
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR_TX
STAT_ EP STAT_
SETUP
USB_EP6R RX TYPE TX EA[3:0]
0x18 Reserved
[1:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DTOG_RX
DTOG_TX
EP_KIND
CTR_RX
CTR_TX
STAT_ EP STAT_
SETUP
USB_EP7R RX TYPE TX EA[3:0]
0x1C Reserved
[1:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x20-
Reserved
0x3F
PMAOVRM
RESUME
LPMODE
RESETM
WKUPM
SUSPM
ESOFM
FSUSP
PDWN
ERRM
CTRM
SOFM
FRES
USB_CNTR
0x40 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 1 1
PMAOVR
RESET
WKUP
ESOF
SUSP
ERR
CTR
SOF
DIR
USB_ISTR EP_ID[3:0]
0x44 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
RXDM
RXDP
LSOF
LCK
USB_FNR FN[10:0]
0x48 Reserved [1:0]
Reset value 0 0 0 0 0 x x x x x x x x x x x
USB_DADDR EF ADD[6:0]
0x4C Reserved
Reset value 0 0 0 0 0 0 0 0
USB_BTABLE BTABLE[15:3]
0x50 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
CAN node 2
CAN node n
MCU
Application
CAN
Controller
CAN CAN
Rx Tx
CAN
Transceiver
CAN CAN
High Low
CAN Bus
24.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 1 Status
Acceptance Filters
Interrupt Enable
27
CAN 2.0B Active Core .. .. 26
Error Status Memory 2 3
1
Access Filter 0
Bit Timing Controller
Filter Mode
Transmission
Filter Scale Scheduler
Slave Slave
Slave Receive FIFO 0 Receive FIFO 1
Filter FIFO Assign Tx Mailboxes 2 2
Filter Activation 2 1 1
1 Mailbox 0 Mailbox 0
Mailbox 0
CAN2 (Slave)
Control/Status/Configuration
Master Control
Master Status
Tx Status
Rx FIFO 0 Status
CAN 2.0B Active Core
Rx FIFO 1 Status
Interrupt Enable
Error Status
Note: CAN 2 start filter bank number n is configurable by writing to
Bit Timing the CAN2SB[5:0] bits in the CAN_ FMR register.
ai16094
To synchronize, bxCAN waits until the CAN bus is idle, this means 11 consecutive recessive
bits have been monitored on CANRX.
bxCAN can be woken up (exit Sleep mode) either by software clearing the SLEEP bit or on
detection of CAN bus activity.
On CAN bus activity detection, hardware automatically performs the wakeup sequence by
clearing the SLEEP bit if the AWUM bit in the CAN_MCR register is set. If the AWUM bit is
cleared, software has to clear the SLEEP bit when a wakeup interrupt occurs, in order to exit
from Sleep mode.
Note: If the wakeup interrupt is enabled (WKUIE bit set in CAN_IER register) a wakeup interrupt
will be generated on detection of CAN bus activity, even if the bxCAN automatically performs
the wakeup sequence.
After the SLEEP bit has been cleared, Sleep mode is exited once bxCAN has synchronized
with the CAN bus, refer to Figure 223: bxCAN operating modes. The Sleep mode is exited
once the SLAK bit has been cleared by hardware.
3LEEP
3,!+
).!+
1
.2 3,
) %%
# 0
9. )
.2
3 3, 1
%0 #+ %% !
% ! 0 #+
3, )
% %0 .2
3, 1
!
#+
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
remain in recessive state. Silent mode can be used to analyze the traffic on a CAN bus
without affecting it by the transmission of dominant bits (Acknowledge Bits, Error Frames).
bxCAN
Tx Rx
=1
CANTX CANRX
bxCAN
Tx Rx
CANTX CANRX
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
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 will be scheduled first.
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
will become 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
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 24.7.4: Identifier filtering.
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
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 will be 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
will cause a loss of message.
Refer also to Section 24.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 will lead to an overrun and a message will be 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 will be overwritten by the new incoming message. In
this case the latest messages will be always available to the application.
● If the FIFO lock function is enabled (RFLM bit in the CAN_MCR register set) the most
recent message will be discarded and the software will have the three oldest messages
in the FIFO available.
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 229.
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”.
FBMx = 0
ID CAN_FxR1[31:24] CAN_FxR1[23:16] CAN_FxR1[15:8] CAN_FxR1[7:0]
n
Mask CAN_FxR2[31:24] CAN_FxR2[23:16] CAN_FxR2[15:8] CAN_FxR2[7:0]
FSCx = 1
n
Mask CAN_FxR1[31:24] CAN_FxR1[23:16]
ID CAN_FxR2[15:8] CAN_FxR2[7:0]
n+1
Mask CAN_FxR2[31:24] CAN_FxR2[23:16]
FSCx = 0
2
1 ID Mask (32-bit) 2 4 ID List (32-bit) 3
3
4 Deactivated 4
3 ID List (16-bit) 7
5 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
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
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
%22/2 !#4)6%
%22/2 0! 33)6%
"53 /&&
AI
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 will recover 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 will start 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, please
refer to the ISO 11898 standard.
1 x tq tBS1 tBS2
Inter-Frame Space
Inter-Frame Space Data Frame (Standard identifier) or Overload Frame
44 + 8 * N
Arbitration Field Ctrl Field Data Field CRC Field Ack Field
2
32 6 8*N 16 7
IDE
r0
RTR
SOF
ACK
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 6 8*N 16 7
r1
RTR
IDE
r0
SRR
SOF
ACK
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
ACK
Data Frame or Inter-Frame Space
Remote Frame Error Frame or Overload Frame Notes:
Error Flag Echo Error Delimiter 0 <= N <= 8
Flag
6 6 8 SOF = Start Of Frame
ID = Identifier
RTR = Remote Transmission Request
Data Frame or IDE = Identifier Extension Bit
Any Frame Inter-Frame Space Remote Frame r0 = Reserved Bit
Suspend DLC = Data Length Code
Intermission Transmission Bus Idle
3 CRC = Cyclic Redundancy Code
8
Error flag: 6 dominant bits if node is error
ai15154
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
&
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBF
Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SLKIE WKUIE
Reserved
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
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
BRP[9:0]
Reserved
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]
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
CAN mailbox data length control and time stamp register (CAN_TDTxR)
(x=0..2)
All bits of this register are write protected when the mailbox is not in empty state.
Address offsets: 0x184, 0x194, 0x1A4
Reset value: 0xXXXX XXXX
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
TGT DLC[3:0]
Reserved Reserved
rw 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
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
FMI[7:0] DLC[3:0]
Reserved
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
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FINIT
Reserved
rw
CAN2SB[5:0] FINIT
Reserved Reserved
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FBM27 FBM26 FBM25 FBM24 FBM23 FBM22 FBM21 FBM20 FBM19 FBM18 FBM17 FBM16
Reserved
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
FBM15 FBM14 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 rw rw
Note: Please refer to Figure 229: Filter bank scale configuration - register organization on
page 640
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FSC27 FSC26 FSC25 FSC24 FSC23 FSC22 FSC21 FSC20 FSC19 FSC18 FSC17 FSC16
Reserved
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
FSC15 FSC14 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 rw rw
Note: Please refer to Figure 229: Filter bank scale configuration - register organization on
page 640.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FFA27 FFA26 FFA25 FFA24 FFA23 FFA22 FFA21 FFA20 FFA19 FFA18 FFA17 FFA16
Reserved
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
FFA15 FFA14 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 rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FACT27 FACT26 FACT25 FACT24 FACT23 FACT22 FACT21 FACT20 FACT19 FACT18 FACT17 FACT16
Reserved
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
FACT15 FACT14 FACT13 FACT12 FACT11 FACT10 FACT9 FACT8 FACT7 FACT6 FACT5 FACT4 FACT3 FACT2 FACT1 FACT0
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
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 24.7.4: Identifier filtering on page 638.
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 please refer to the Table 181 on
page 669.
9
8
7
6
5
4
3
2
1
0
RESET
SLEEP
AWUM
ABOM
TTCM
RFLM
NART
TXFP
INRQ
DBF
CAN_MCR
0x000 Reserved Reserved
Reset value 1 0 0 0 0 0 0 0 1 0
SAMP
SLAKI
WKUI
SLAK
ERRI
INAK
RXM
TXM
RX
CAN_MSR
0x004 Reserved Reserved
Reset value 1 1 0 0 0 0 0 1 0
CODE[1:0]
RQCP2
RQCP1
RQCP0
ABRQ2
ABRQ1
ABRQ0
TERR2
TXOK2
TERR1
TXOK1
TERR0
TXOK0
ALST2
ALST1
ALST0
CAN_TSR LOW[2:0] TME[2:0]
0x008 Reserved Reserved Reserved
Reset value 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FMP0[1:0]
RFOM0
FOVR0
FULL0
Reserved
CAN_RF0R
0x00C Reserved
Reset value 0 0 0 0 0
FMP1[1:0]
RFOM1
FOVR1
FULL1
Reserved
CAN_RF1R
0x010 Reserved
Reset value 0 0 0 0 0
FMPIE1
FMPIE0
FOVIE1
FOVIE0
EWGIE
WKUIE
ERRIE
TMEIE
Reserved
BOFIE
EPVIE
LECIE
SLKIE
FFIE1
FFIE0
CAN_IER
0x014 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
LEC[2:0]
EWGF
Reserved
BOFF
EPVF
CAN_ESR REC[7:0] TEC[7:0]
0x018 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SJW[1:0]
Reserved
LBKM
SILM
Reset value 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0
0x020-
Reserved
0x17F TXRQ
RTR
IDE
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
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
TXRQ
RTR
IDE
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
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
TGT
CAN_TDT1R TIME[15:0] DLC[3:0]
0x194 Reserved Reserved
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_TI2R STID[10:0]/EXID[28:18] EXID[17:0]
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
TGT
CAN_TDT2R TIME[15:0] DLC[3:0]
0x1A4 Reserved Reserved
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
Reserved
RTR
IDE
CAN_RI0R STID[10:0]/EXID[28:18] EXID[17:0]
0x1B0
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
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
Reserved
RTR
IDE
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-
Reserved
0x1FF
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0 FINIT
CAN_FMR CAN2SB[5:0]
0x200 Reserved Reserved
Reset value 0 0 1 1 1 0 1
CAN_FM1R FBM[27:0]
0x204 Reserved
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
0x208 Reserved
CAN_FS1R FSC[27:0]
0x20C Reserved
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
0x210 Reserved
CAN_FFA1R FFA[27:0]
0x214 Reserved
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
0x218 Reserved
CAN_FA1R FACT[27:0]
0x21C Reserved
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
0x220 Reserved
0x224-
Reserved
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
Warning: Since some SPI3/I2S3 pins are shared with JTAG pins
(SPI3_NSS/I2S3_WS with JTDI and SPI3_SCK/I2S3_CK with
JTDO), they are not controlled by the IO controller and are
reserved for JTAG usage (after each Reset).
For this purpose, prior to configure the SPI3/I2S3 pins, the
user has to disable the JTAG and use the SWD interface
(when debugging the application), or disable both JTAG/SWD
interfaces (for standalone applications). For more
information on the configuration of JTAG/SWD interface pins,
please refer to Section 9.3.5: JTAG/SWD alternate function
remapping.
2EAD
2X BUFFER
-/3) 30)?#2
48% 28.% %22 48$- 28$-
33/% !%. !%.
)% )% )%
3HIFT REGISTER
-)3/
,3" FIRST 30)?32
-/$ #2#
"39 /62 %22 48% 28.%
4X BUFFER &
7RITE
#OMMUNICATION
CONTROL
3#+ "2;=
"AUD RATE GENERATOR
.33
AI
enters the master mode fault state: the MSTR bit is automatically cleared and the
device is configured in slave mode (refer to Section 25.3.10: Error flags on page 693).
A basic example of interconnections between a single master and a single slave is
illustrated in Figure 237.
MOSI MOSI
#0/,
OR BITS DEPENDING ON THE $ATA FRAME FORMAT BIT SEE $&& IN 30)?#2
.33
TO SLAVE
#APTURE STROBE
#0(!
#0/,
#0/,
OR BITS DEPENDING ON THE $ATA FRAME FORMAT BIT SEE $&& IN 30)?#2
-/3) -3"IT ,3"IT
.33
TO SLAVE
#APTURE STROBE
AIB
1. These timings are shown with the LSBFIRST bit reset in the SPI_CR1 register.
Procedure
1. Set the DFF bit to define 8- or 16-bit data frame format
2. Select the CPOL and CPHA bits to define one of the four relationships between the
data transfer and the serial clock (see Figure 238). For correct data transfer, the CPOL
and CPHA bits must be configured in the same way in the slave device and the master
device.
3. The frame format (MSB-first or LSB-first depending on the value of the LSBFIRST bit in
the SPI_CR1 register) must be the same as the master device.
4. In Hardware mode (refer to Slave select (NSS) pin management on page 676), the
NSS pin must be connected to a low level signal during the complete byte transmit
sequence. In NSS software mode, set the SSM bit and clear the SSI bit in the SPI_CR1
register.
5. Clear the MSTR bit and set the SPE bit (both in the SPI_CR1 register) to assign the
pins to alternate functions.
In this configuration the MOSI pin is a data input and the MISO pin is a data output.
Transmit sequence
The data byte is parallel-loaded into the Tx buffer during a write cycle.
The transmit sequence begins when the slave device receives the clock signal and the most
significant bit of the data on its MOSI pin. The remaining bits (the 7 bits in 8-bit data frame
format, and the 15 bits in 16-bit data frame format) are loaded into the shift-register. The
TXE flag in the SPI_SR register is set on the transfer of data from the Tx Buffer to the shift
register and an interrupt is generated if the TXEIE bit in the SPI_CR2 register is set.
Receive sequence
For the receiver, when data transfer is complete:
● The Data in shift register is transferred to Rx Buffer and the RXNE flag (SPI_SR
register) is set
● An Interrupt is generated if the RXNEIE bit is set in the SPI_CR2 register.
After the last sampling clock edge the RXNE bit is set, a copy of the data byte received in
the shift register is moved to the Rx buffer. When the SPI_DR register is read, the SPI
peripheral returns this buffered value.
Clearing of the RXNE bit is performed by reading the SPI_DR register.
Procedure
1. Select the BR[2:0] bits to define the serial clock baud rate (see SPI_CR1 register).
2. Select the CPOL and CPHA bits to define one of the four relationships between the
data transfer and the serial clock (see Figure 238).
3. Set the DFF bit to define 8- or 16-bit data frame format
4. Configure the LSBFIRST bit in the SPI_CR1 register to define the frame format.
5. If the NSS pin is required in input mode, in hardware mode, connect the NSS pin to a
high-level signal during the complete byte transmit sequence. In NSS software mode,
set the SSM and SSI bits in the SPI_CR1 register. If the NSS pin is required in output
mode, the SSOE bit only should be set.
6. The MSTR and SPE bits must be set (they remain set only if the NSS pin is connected
to a high-level signal).
In this configuration the MOSI pin is a data output and the MISO pin is a data input.
Transmit sequence
The transmit sequence begins when a byte is written in the Tx Buffer.
The data byte is parallel-loaded into the shift register (from the internal bus) during the first
bit transmission and then shifted out serially to the MOSI pin MSB first or LSB first
depending on the LSBFIRST bit in the SPI_CR1 register. The TXE flag is set on the transfer
of data from the Tx Buffer to the shift register and an interrupt is generated if the TXEIE bit in
the SPI_CR2 register is set.
Receive sequence
For the receiver, when data transfer is complete:
● The data in the shift register is transferred to the RX Buffer and the RXNE flag is set
● An interrupt is generated if the RXNEIE bit is set in the SPI_CR2 register
At the last sampling clock edge the RXNE bit is set, a copy of the data byte received in the
shift register is moved to the Rx buffer. When the SPI_DR register is read, the SPI
peripheral returns this buffered value.
Clearing the RXNE bit is performed by reading the SPI_DR register.
A continuous transmit stream can be maintained if the next data to be transmitted is put in
the Tx buffer once the transmission is started. Note that TXE flag should be ‘1 before any
attempt to write the Tx buffer is made.
Note: When a master is communicating with SPI slaves which need to be de-selected between
transmissions, the NSS pin must be configured as GPIO or another GPIO must be used and
toggled by software.
Figure 239. TXE/RXNE/BSY behavior in Master / full-duplex mode (BIDIMODE=0 and RXONLY=0)
in the case of continuous transfers
Example in Master mode with CPOL=1, CPHA=1
SCK
DATA1 = 0xF1 DATA2 = 0xF2 DATA3 = 0xF3
MISO/MOSI (out) b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7 b0 b1 b2 b3 b4 b5 b6 b7
software software waits software waits software waits software waits software waits
writes 0xF1 until TXE=1 and until RXNE=1 until TXE=1 and until RXNE=1 until RXNE=1
into SPI_DR writes 0xF2 into and reads 0xA1 writes 0xF3 into and reads 0xA2 and reads 0xA3
SPI_DR from SPI_DR SPI_DR from SPI_ DR from SPI_DR
ai17343
Figure 240. TXE/RXNE/BSY behavior in Slave / full-duplex mode (BIDIMODE=0, RXONLY=0) in the
case of continuous transfers
Example in Slave mode with CPOL=1, CPHA=1
SCK
software software waits software waits software waits software waits software waits
writes 0xF1 until TXE=1 and until RXNE=1 until TXE=1 and until RXNE=1 until RXNE=1
into SPI_DR writes 0xF2 into and reads 0xA1 writes 0xF3 into and reads 0xA2 and reads 0xA3
SPI_DR from SPI_DR SPI_DR from SPI_ DR from SPI_DR
ai17344
Figure 241. TXE/BSY behavior in Master transmit-only mode (BIDIMODE=0 and RXONLY=0) in the
case of continuous transfers
Example in Master mode with CPOL=1, CPHA=1
SCK
Figure 242. TXE/BSY in Slave transmit-only mode (BIDIMODE=0 and RXONLY=0) in the case of
continuous transfers
Example in slave mode with CPOL=1, CPHA=1
SCK
Figure 243. RXNE behavior in receive-only mode (BIDIRMODE=0 and RXONLY=1) in the case of
continuous transfers
Example with CPOL=1, CPHA=1, RXONLY=1
SCK
software waits until RXNE=1 software waits until RXNE=1 software waits until RXNE=1
and reads 0xA1 from SPI_DR and reads 0xA2 from SPI_DR and reads 0xA3 from SPI_DR
ai17347
Figure 244. TXE/BSY behavior when transmitting (BIDIRMODE=0 and RXONLY=0) in the case of
discontinuous transfers
Example with CPOL=1, CPHA=1
SCK
TXE flag
BSY flag
software writes 0xF1 software waits until TXE=1 but is software waits until TXE=1 but software waits software waits until BSY=0
into SPI_DR late to write 0xF2 into SPI_DR is late to write 0xF3 into until TXE=1
SPI_DR
ai17348
SPI communication using the CRC is possible through the following procedure:
1. Program the CPOL, CPHA, LSBFirst, BR, SSM, SSI and MSTR values.
2. Program the polynomial in the SPI_CRCPR register.
3. Enable the CRC calculation by setting the CRCEN bit in the SPI_CR1 register. This
also clears the SPI_RXCRCR and SPI_TXCRCR registers.
4. Enable the SPI by setting the SPE bit in the SPI_CR1 register.
5. Start the communication and sustain the communication until all but one byte or half-
word have been transmitted or received.
– In full duplex or transmitter-only mode, when the transfers are managed by
software, when writing the last byte or half word to the Tx buffer, set the
CRCNEXT bit in the SPI_CR1 register to indicate that the CRC will be transmitted
after the transmission of the last byte.
– In receiver only mode, set the bit CRCNEXT just after the reception of the second
to last data to prepare the SPI to enter in CRC Phase at the end of the reception of
the last data. CRC calculation is frozen during the CRC transfer.
6. After the transfer of the last byte or half word, the SPI enters the CRC transfer and
check phase. In full duplex mode or receiver-only mode, the received CRC is compared
to the SPI_RXCRCR value. If the value does not match, the CRCERR flag in SPI_SR is
set and an interrupt can be generated when the ERRIE bit in the SPI_CR2 register is
set.
Note: When the SPI is in slave mode, be careful to enable CRC calculation only when the clock is
stable, that is, when the clock is in the steady state. If not, a wrong CRC calculation may be
done. In fact, the CRC is sensitive to the SCK slave input clock as soon as CRCEN is set,
and this, whatever the value of the SPE bit.
With high bitrate frequencies, be careful when transmitting the CRC. As the number of used
CPU cycles has to be as low as possible in the CRC transfer phase, it is forbidden to call
software functions in the CRC transmission sequence to avoid errors in the last data and
CRC reception. In fact, CRCNEXT bit has to be written before the end of the
transmission/reception of the last data.
For high bit rate frequencies, it is advised to use the DMA mode to avoid the degradation of
the SPI speed performance due to CPU accesses impacting the SPI bandwidth.
When the STM32F10xxx are configured as slaves and the NSS hardware mode is used, the
NSS pin needs to be kept low between the data phase and the CRC phase.
When the SPI is configured in slave mode with the CRC feature enabled, CRC calculation
takes place even if a high level is applied on the NSS pin. This may happen for example in
case of a multislave environment where the communication master addresses slaves
alternately.
Between a slave deselection (high level on NSS) and a new slave selection (low level on
NSS), the CRC value should be cleared on both master and slave sides in order to
resynchronize the master and slave for their respective CRC calculation.
To clear the CRC, follow the procedure below:
1. Disable SPI (SPE = 0)
2. Clear the CRCEN bit
3. Set the CRCEN bit
4. Enable the SPI (SPE = 1)
BUSY flag
This BSY flag is set and cleared by hardware (writing to this flag has no effect). The BSY
flag indicates the state of the communication layer of the SPI.
When BSY is set, it indicates that the SPI is busy communicating. There is one exception in
master mode / bidirectional receive mode (MSTR=1 and BDM=1 and BDOE=0) where the
BSY flag is kept low during reception.
The BSY flag is useful to detect the end of a transfer if the software wants to disable the SPI
and enter Halt mode (or disable the peripheral clock). This avoids corrupting the last
transfer. For this, the procedure described below must be strictly respected.
The BSY flag is also useful to avoid write collisions in a multimaster system.
The BSY flag is set when a transfer starts, with the exception of master mode / bidirectional
receive mode (MSTR=1 and BDM=1 and BDOE=0).
It is cleared:
● when a transfer is finished (except in master mode if the communication is continuous)
● when the SPI is disabled
● when a master mode fault occurs (MODF=1)
When communication is not continuous, the BSY flag is low between each communication.
When communication is continuous:
● in master mode, the BSY flag is kept high during all the transfers
● in slave mode, the BSY flag goes low for one SPI clock cycle between each transfer
Note: Do not use the BSY flag to handle each data transmission or reception. It is better to use the
TXE and RXNE flags instead.
SCK
reset
BSY flag set by hardware by hardware
software configures the DMA writes DMA writes DMA writes DMA transfer is software waits software waits until BSY=0
DMA SPI Tx channel DATA1 into DATA2 into DATA3 into complete (TCIF=1 in until TXE=1
to send 3 data items SPI_DR SPI_DR SPI_DR DMA_ISR)
and enables the SPI
ai17349
SCK
DMA request
Rx buffer
0xA1 0xA2 0xA3
(read from SPI_DR)
software configures the DMA reads DMA reads DMA reads The DMA transfer is
DMA SPI Rx channel DATA1 from DATA2 from DATA3 from complete (TCIF=1 in
to receive 3 data items SPI_DR SPI_DR SPI_DR DMA_ISR)
and enables the SPI
ai17350
As a security, hardware does not allow the setting of the SPE and MSTR bits while the
MODF bit is set.
In a slave device the MODF bit cannot be set. However, in a multimaster configuration, the
device can be in slave mode with this MODF bit set. In this case, the MODF bit indicates that
there might have been a multimaster conflict for system control. An interrupt routine can be
used to recover cleanly from this state by performing a reset or returning to a default state.
Overrun condition
An overrun condition occurs when the master device has sent data bytes and the slave
device has not cleared the RXNE bit resulting from the previous data byte transmitted.
When an overrun condition occurs:
● the OVR bit is set and an interrupt is generated if the ERRIE bit is set.
In this case, the receiver buffer contents will not be updated with the newly received data
from the master device. A read from the SPI_DR register returns this byte. All other
subsequently transmitted bytes are lost.
Clearing the OVR bit is done by a read from the SPI_DR register followed by a read access
to the SPI_SR register.
CRC error
This flag is used to verify the validity of the value received when the CRCEN bit in the
SPI_CR1 register is set. The CRCERR flag in the SPI_SR register is set if the value
received in the shift register does not match the receiver SPI_RXCRCR value.
25.4.1 The I2S audio protocol is not available in low- and medium-density devices. This section
concerns only high-density, XL-density and connectivity line devices. I2S general
description
The block diagram of the I2S is shown in Figure 247.
4X BUFFER
#(
"39 /62 -/$& #2# 5$2 4X% 2X.%
%22 3)$%
BIT
-/3) 3$
3HIFT REGISTER
-)3/
,3" FIRST #OMMUNICATION
BIT CONTROL
2X BUFFER
.3373
)3
-/$ )3%
30) ,3"
30% "2 "2 "2 -342 #0/, #0(!
BAUD RATE GENERATOR &IRST
#+
)3-/$
-#+
-#+/%
/$$ )3$)6;= )3X#,+
AI
The SPI could function as an audio I2S interface when the I2S capability is enabled (by
setting the I2SMOD bit in the SPI_I2SCFGR register). This interface uses almost the same
pins, flags and interrupts as the SPI.
The I2S shares three common pins with the SPI:
● SD: Serial Data (mapped on the MOSI pin) to transmit or receive the two time-
multiplexed data channels (in simplex mode only).
● WS: Word Select (mapped on the NSS pin) is the data control signal output in master
mode and input in slave mode.
● CK: Serial Clock (mapped on the SCK pin) is the serial clock output in master mode
and serial clock input in slave mode.
An additional pin could be used when a master clock output is needed for some external
audio devices:
● MCK: Master Clock (mapped separately) is used, when the I2S is configured in master
mode (and when the MCKOE bit in the SPI_I2SPR register is set), to output this
additional clock generated at a preconfigured frequency rate equal to 256 × FS, where
FS is the audio sampling frequency.
The I2S uses its own clock generator to produce the communication clock when it is set in
master mode. This clock generator is also the source of the master clock output. Two
additional registers are available in I2S mode. One is linked to the clock generator
configuration SPI_I2SPR and the other one is a generic I2S configuration register
SPI_I2SCFGR (audio standard, slave/master mode, data format, packet frame, clock
polarity, etc.).
The SPI_CR1 register and all CRC registers are not used in the I2S mode. Likewise, the
SSOE bit in the SPI_CR2 register and the MODF and CRCERR bits in the SPI_SR are not
used.
The I2S uses the same SPI register for data transfer (SPI_DR) in 16-bit wide mode.
For all data formats and communication standards, the most significant bit is always sent
first (MSB first).
The I2S interface supports four audio standards, configurable using the I2SSTD[1:0] and
PCMSYNC bits in the SPI_I2SCFGR register.
Figure 248. I2S Phillips protocol waveforms (16/32-bit full accuracy, CPOL = 0)
CK
WS
Transmission Reception
Channel left
Channel right
Data are latched on the falling edge of CK (for the transmitter) and are read on the rising
edge (for the receiver). The WS signal is also latched on the falling edge of CK.
Figure 249. I2S Phillips standard waveforms (24-bit frame with CPOL = 0)
CK
WS
Transmission Reception
24-bit data 8-bit remaining
SD
0 forced
MSB LSB
This mode needs two write or read operations to/from the SPI_DR.
● In transmission mode:
if 0x8EAA33 has to be sent (24-bit):
0x8EAA 0x33XX
Only the 8 MSBs are sent to complete the 24 bits
8 LSB bits have no meaning and could be
anything
● In reception mode:
if data 0x8EAA33 is received:
First read from Data register Second read from Data register
0x8EAA 0x3300
Only the 8MSB are right
The 8 LSB will always be 00
Figure 252. I2S Phillips standard (16-bit extended to 32-bit packet frame with
CPOL = 0)
CK
WS
Transmission Reception
16-bit data 16-bit remaining
SD
0 forced
MSB LSB
When 16-bit data frame extended to 32-bit channel frame is selected during the I2S
configuration phase, only one access to SPI_DR is required. The 16 remaining bits are
forced by hardware to 0x0000 to extend the data to 32-bit format.
If the data to transmit or the received data are 0x76A3 (0x76A30000 extended to 32-bit), the
operation shown in Figure 253 is required.
0X76A3
For transmission, each time an MSB is written to SPI_DR, the TXE flag is set and its
interrupt, if allowed, is generated to load SPI_DR with the new value to send. This takes
place even if 0x0000 have not yet been sent because it is done by hardware.
For reception, the RXNE flag is set and its interrupt, if allowed, is generated when the first
16 MSB half-word is received.
In this way, more time is provided between two write or read operations, which prevents
underrun or overrun conditions (depending on the direction of the data transfer).
Figure 254. MSB Justified 16-bit or 32-bit full-accuracy length with CPOL = 0
CK
WS
Transmission Reception
Channel left
Channel right
Data are latched on the falling edge of CK (for transmitter) and are read on the rising edge
(for the receiver).
CK
WS
Transmission Reception
Figure 256. MSB Justified 16-bit extended to 32-bit packet frame with CPOL = 0
CK
WS
Transmission Reception
CK
WS
Transmission Reception
Channel left
Channel right
CK
WS
Transmission Reception
● In transmission mode:
If data 0x3478AE have to be transmitted, two write operations to the SPI_DR register
are required from software or by DMA. The operations are shown below.
0xXX34 0x78AE
Only the 8 LSB bits of the half-word
are significant. Whatever the 8 MSBs
a field of 0x00 is forced instead
● In reception mode:
If data 0x3478AE are received, two successive read operations from SPI_DR are
required on each RXNE event.
0x0034 0x78AE
Only the 8 LSB bits of the half-word
are significant. Whatever the 8 MSBs,
a field of 0x00 is forced instead
Figure 261. LSB Justified 16-bit extended to 32-bit packet frame with CPOL = 0
CK
WS
Transmission Reception
When 16-bit data frame extended to 32-bit channel frame is selected during the I2S
configuration phase, Only one access to SPI_DR is required. The 16 remaining bits are
forced by hardware to 0x0000 to extend the data to 32-bit format. In this case it corresponds
to the half-word MSB.
If the data to transmit or the received data are 0x76A3 (0x0000 76A3 extended to 32-bit),
the operation shown in Figure 262 is required.
Figure 262. Example of LSB justified 16-bit extended to 32-bit packet frame
0X76A3
In transmission mode, when TXE is asserted, the application has to write the data to be
transmitted (in this case 0x76A3). The 0x000 field is transmitted first (extension on 32-bit).
TXE is asserted again as soon as the effective data (0x76A3) is sent on SD.
In reception mode, RXNE is asserted as soon as the significant half-word is received (and
not the 0x0000 field).
In this way, more time is provided between two write or read operations to prevent underrun
or overrun conditions.
PCM standard
For the PCM standard, there is no need to use channel-side information. The two PCM
modes (short and long frame) are available and configurable using the PCMSYNC bit in
SPI_I2SCFGR.
WS
short
frame
fixed to 13-bit
WS
long
frame
SD 16-bit
MSB LSB MSB
For long frame synchronization, the WS signal assertion time is fixed 13 bits in master
mode.
For short frame synchronization, the WS synchronization signal is only one cycle long.
Figure 264. PCM standard waveforms (16-bit extended to 32-bit packet frame)
CK
WS
short
frame
fixed to 13-bit
WS
long
frame
SD 16-bit
MSB LSB
Note: For both modes (master and slave) and for both synchronizations (short and long), the
number of bits between two consecutive pieces of data (and so two synchronization signals)
needs to be specified (DATLEN and CHLEN bits in the SPI_I2SCFGR register) even in slave
mode.
32-bits or 64-bits
FS
sampling point
sampling point
When the master mode is configured, a specific action needs to be taken to properly
program the linear divider in order to communicate with the desired audio frequency.
MCK
0 CK
I2SxCLK 8-bit Linear
Divider by 4 Div2 0 1
Divider +
reshaping stage 1
MCKOE
1. Where x could be 2 or 3.
Figure 265 presents the communication clock architecture. . The I2SxCLK source is the
system clock (provided by the HSI, the HSE or the PLL, and sourcing the AHB clock). For
connectivity line devices, tThe I2SxCLK source can be either SYSCLK or the PLL3 VCO
(2 × PLL3CLK) clock in order to achieve the maximum accuracy. This selection is made
using the I2S2SRC and I2S3SRC bits in the RCC_CFGR2 register.
The audio sampling frequency can be 96 kHz, 48 kHz, 44.1 kHz, 32 kHz, 22.05 kHz,
16 kHz, 11.025 kHz or 8 kHz (or any other value within this range). In order to reach the
desired frequency, the linear divider needs to be programmed according to the formulas
below:
When the master clock is generated (MCKOE in the SPI_I2SPR register is set):
FS = I2SxCLK / [(16*2)*((2*I2SDIV)+ODD)*8)] when the channel frame is 16-bit wide
FS = I2SxCLK / [(32*2)*((2*I2SDIV)+ODD)*4)] when the channel frame is 32-bit wide
When the master clock is disabled (MCKOE bit cleared):
FS = I2SxCLK / [(16*2)*((2*I2SDIV)+ODD))] when the channel frame is 16-bit wide
FS = I2SxCLK / [(32*2)*((2*I2SDIV)+ODD))] when the channel frame is 32-bit wide
Table 183, Table 184 and Table 185 provide example precision values for different clock
configurations.
Note: Other configurations are possible that allow optimum clock precision.
Table 183. Audio-frequency precision using standard 8 MHz HSE (high-density and XL-density
devices only)
I2S_DIV I2S_ODD Real fS (KHz) Error
SYSCLK Target fS
MCLK
(MHz) (Hz)
16-bit 32-bit 16-bit 32-bit 16-bit 32-bit 16-bit 32-bit
Table 185. Audio-frequency precision using standard 14.7456 MHz and PLL3
(connectivity line devices only)
Data Target Real fs
PREDIV2 PLL3MUL I2SDIV I2SODD MCLK Error
length fs(Hz) (KHz)
Procedure
1. Select the I2SDIV[7:0] bits in the SPI_I2SPR register to define the serial clock baud
rate to reach the proper audio sample frequency. The ODD bit in the SPI_I2SPR
register also has to be defined.
2. Select the CKPOL bit to define the steady level for the communication clock. Set the
MCKOE bit in the SPI_I2SPR register if the master clock MCK needs to be provided to
the external DAC/ADC audio component (the I2SDIV and ODD values should be
computed depending on the state of the MCK output, for more details refer to
Section 25.4.3: Clock generator).
3. Set the I2SMOD bit in SPI_I2SCFGR to activate the I2S functionalities and choose the
I2S standard through the I2SSTD[1:0] and PCMSYNC bits, the data length through the
DATLEN[1:0] bits and the number of bits per channel by configuring the CHLEN bit.
Select also the I2S master mode and direction (Transmitter or Receiver) through the
I2SCFG[1:0] bits in the SPI_I2SCFGR register.
4. If needed, select all the potential interruption sources and the DMA capabilities by
writing the SPI_CR2 register.
5. The I2SE bit in SPI_I2SCFGR register must be set.
WS and CK are configured in output mode. MCK is also an output, if the MCKOE bit in
SPI_I2SPR is set.
Transmission sequence
The transmission sequence begins when a half-word is written into the Tx buffer.
Assumedly, the first data written into the Tx buffer correspond to the channel Left data.
When data are transferred from the Tx buffer to the shift register, TXE is set and data
corresponding to the channel Right have to be written into the Tx buffer. The CHSIDE flag
indicates which channel is to be transmitted. It has a meaning when the TXE flag is set
because the CHSIDE flag is updated when TXE goes high.
A full frame has to be considered as a Left channel data transmission followed by a Right
channel data transmission. It is not possible to have a partial frame where only the left
channel is sent.
The data half-word is parallel loaded into the 16-bit shift register during the first bit
transmission, and then shifted out, serially, to the MOSI/SD pin, MSB first. The TXE flag is
set after each transfer from the Tx buffer to the shift register and an interrupt is generated if
the TXEIE bit in the SPI_CR2 register is set.
For more details about the write operations depending on the I2S standard mode selected,
refer to Section 25.4.2: Supported audio protocols).
To ensure a continuous audio data transmission, it is mandatory to write the SPI_DR with
the next data to transmit before the end of the current transmission.
To switch off the I2S, by clearing I2SE, it is mandatory to wait for TXE = 1 and BSY = 0.
Reception sequence
The operating mode is the same as for the transmission mode except for the point 3 (refer to
the procedure described in Section 25.4.4: I2S master mode), where the configuration
should set the master reception mode through the I2SCFG[1:0] bits.
Whatever the data or channel length, the audio data are received by 16-bit packets. This
means that each time the Rx buffer is full, the RXNE flag is set and an interrupt is generated
if the RXNEIE bit is set in SPI_CR2 register. Depending on the data and channel length
configuration, the audio value received for a right or left channel may result from one or two
receptions into the Rx buffer.
Clearing the RXNE bit is performed by reading the SPI_DR register.
CHSIDE is updated after each reception. It is sensitive to the WS signal generated by the
I2S cell.
For more details about the read operations depending on the I2S standard mode selected,
refer to Section 25.4.2: Supported audio protocols.
If data are received while the previously received data have not been read yet, an overrun is
generated and the OVR flag is set. If the ERRIE bit is set in the SPI_CR2 register, an
interrupt is generated to indicate the error.
To switch off the I2S, specific actions are required to ensure that the I2S completes the
transfer cycle properly without initiating a new data transfer. The sequence depends on the
configuration of the data and channel lengths, and on the audio protocol mode selected. In
the case of:
● 16-bit data length extended on 32-bit channel length (DATLEN = 00 and CHLEN = 1)
using the LSB justified mode (I2SSTD = 10)
a) Wait for the second to last RXNE = 1 (n – 1)
b) Then wait 17 I2S clock cycles (using a software loop)
c) Disable the I2S (I2SE = 0)
● 16-bit data length extended on 32-bit channel length (DATLEN = 00 and CHLEN = 1) in
MSB justified, I2S or PCM modes (I2SSTD = 00, I2SSTD = 01 or I2SSTD = 11,
respectively)
a) Wait for the last RXNE
b) Then wait 1 I2S clock cycle (using a software loop)
c) Disable the I2S (I2SE = 0)
● For all other combinations of DATLEN and CHLEN, whatever the audio mode selected
through the I2SSTD bits, carry out the following sequence to switch off the I2S:
a) Wait for the second to last RXNE = 1 (n – 1)
b) Then wait one I2S clock cycle (using a software loop)
c) Disable the I2S (I2SE = 0)
Note: The BSY flag is kept low during transfers.
are input from the external master connected to the I2S interface. There is then no need, for
the user, to configure the clock.
The configuration steps to follow are listed below:
1. Set the I2SMOD bit in the SPI_I2SCFGR register to reach the I2S functionalities and
choose the I2S standard through the I2SSTD[1:0] bits, the data length through the
DATLEN[1:0] bits and the number of bits per channel for the frame configuring the
CHLEN bit. Select also the mode (transmission or reception) for the slave through the
I2SCFG[1:0] bits in SPI_I2SCFGR register.
2. If needed, select all the potential interrupt sources and the DMA capabilities by writing
the SPI_CR2 register.
3. The I2SE bit in SPI_I2SCFGR register must be set.
Transmission sequence
The transmission sequence begins when the external master device sends the clock and
when the NSS_WS signal requests the transfer of data. The slave has to be enabled before
the external master starts the communication. The I2S data register has to be loaded before
the master initiates the communication.
For the I2S, MSB justified and LSB justified modes, the first data item to be written into the
data register corresponds to the data for the left channel. When the communication starts,
the data are transferred from the Tx buffer to the shift register. The TXE flag is then set in
order to request the right channel data to be written into the I2S data register.
The CHSIDE flag indicates which channel is to be transmitted. Compared to the master
transmission mode, in slave mode, CHSIDE is sensitive to the WS signal coming from the
external master. This means that the slave needs to be ready to transmit the first data before
the clock is generated by the master. WS assertion corresponds to left channel transmitted
first.
Note: The I2SE has to be written at least two PCLK cycles before the first clock of the master
comes on the CK line.
The data half-word is parallel-loaded into the 16-bit shift register (from the internal bus)
during the first bit transmission, and then shifted out serially to the MOSI/SD pin MSB first.
The TXE flag is set after each transfer from the Tx buffer to the shift register and an interrupt
is generated if the TXEIE bit in the SPI_CR2 register is set.
Note that the TXE flag should be checked to be at 1 before attempting to write the Tx buffer.
For more details about the write operations depending on the I2S standard mode selected,
refer to Section 25.4.2: Supported audio protocols.
To secure a continuous audio data transmission, it is mandatory to write the SPI_DR
register with the next data to transmit before the end of the current transmission. An
underrun flag is set and an interrupt may be generated if the data are not written into the
SPI_DR register before the first clock edge of the next data communication. This indicates
to the software that the transferred data are wrong. If the ERRIE bit is set into the SPI_CR2
register, an interrupt is generated when the UDR flag in the SPI_SR register goes high. In
this case, it is mandatory to switch off the I2S and to restart a data transfer starting from the
left channel.
To switch off the I2S, by clearing the I2SE bit, it is mandatory to wait for TXE = 1 and BSY =
0.
Reception sequence
The operating mode is the same as for the transmission mode except for the point 1 (refer to
the procedure described in Section 25.4.5: I2S slave mode), where the configuration should
set the master reception mode using the I2SCFG[1:0] bits in the SPI_I2SCFGR register.
Whatever the data length or the channel length, the audio data are received by 16-bit
packets. This means that each time the RX buffer is full, the RXNE flag in the SPI_SR
register is set and an interrupt is generated if the RXNEIE bit is set in the SPI_CR2 register.
Depending on the data length and channel length configuration, the audio value received for
a right or left channel may result from one or two receptions into the RX buffer.
The CHSIDE flag is updated each time data are received to be read from SPI_DR. It is
sensitive to the external WS line managed by the external master component.
Clearing the RXNE bit is performed by reading the SPI_DR register.
For more details about the read operations depending the I2S standard mode selected, refer
to Section 25.4.2: Supported audio protocols.
If data are received while the precedent received data have not yet been read, an overrun is
generated and the OVR flag is set. If the bit ERRIE is set in the SPI_CR2 register, an
interrupt is generated to indicate the error.
To switch off the I2S in reception mode, I2SE has to be cleared immediately after receiving
the last RXNE = 1.
Note: The external master components should have the capability of sending/receiving data in 16-
bit or 32-bit packets via an audio channel.
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
PCMSY
I2SMOD I2SE I2SCFG I2SSTD CKPOL DATLEN CHLEN
NC
Reserved Reserved
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
Offset Register
9
8
7
6
5
4
3
2
1
0
BIDIMODE
CRCNEXT
LSBFIRST
RXONLY
CRCEN
BIDIOE
MSTR
CPHA
CPOL
SSM
SPE
DFF
SSI
SPI_CR1 BR [2:0]
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RXDMAEN
TXDMAEN
RXNEIE
ERRIE
Reserved
TXEIE
SSOE
SPI_CR2
0x04 Reserved
Reset value 0 0 0 0 0 0
CRCERR
CHSIDE
MODF
RXNE
UDR
OVR
BSY
TXE
SPI_SR
0x08 Reserved
Reset value 0 0 0 0 0 0 1 0
SPI_DR DR[15:0]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPI_CRCPR CRCPOLY[15:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
SPI_RXCRCR RxCRC[15:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPI_TXCRCR TxCRC[15:0]
0x18 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
PCMSYNC
I2SMOD
DATLEN
I2SCFG
I2SSTD
CHLEN
CKPOL
Reserved
I2SE
SPI_I2SCFGR
0x1C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
MCKOE
ODD
SPI_I2SPR I2SDIV
0x20 Reserved
Reset value 0 0 0 0 0 0 0 0 1 0
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 may be enabled or disabled
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 Figure 267.
SDA
MSB ACK
SCL
1 2 8 9
Start Stop
condition condition
Acknowledge may be enabled or disabled by software. The I2C interface addresses (dual
addressing 7-bit/ 10-bit and/or general call address) can be selected by software.
The block diagram of the I2C interface is shown in Figure 268.
Data register
Data
SDA Data shift register
control
Clock control
Register (CCR)
Control registers
(CR1&CR2)
Control
Status registers logic
(SR1&SR2)
SMBA
ai17189
1. SMBA is an optional signal in SMBus mode. This signal is not applicable if SMBus is disabled.
Slave transmitter
Following the address reception and after clearing ADDR, the slave sends bytes from the
DR register to the SDA line via the internal shift register.
The slave stretches SCL low until ADDR is cleared and DR filled with the data to be sent
(see Figure 269 Transfer sequencing EV1 EV3).
When the acknowledge pulse is received:
● The TxE bit is set by hardware with an interrupt if the ITEVFEN and the ITBUFEN bits
are set.
If TxE is set and some data were not written in the I2C_DR register before the end of the
next data transmission, the BTF bit is set and the interface waits until BTF is cleared by a
read to I2C_SR1 followed by a write to the I2C_DR register, stretching SCL low.
ai18209
Slave receiver
Following the address reception and after clearing ADDR, the slave receives bytes from the
SDA line into the DR register via the internal shift register. After each byte the interface
generates in sequence:
● An acknowledge pulse if the ACK bit is set
● The RxNE bit is set by hardware and an interrupt is generated if the ITEVFEN and
ITBUFEN bit is set.
If RxNE is set and the data in the DR register is not read before the end of the next data
reception, the BTF bit is set and the interface waits until BTF is cleared by a read from
I2C_SR1 followed by a read from the I2C_DR register, stretching SCL low (see Figure 270
Transfer sequencing).
ai18208
1. The EV1 event stretches SCL low until the end of the corresponding software sequence.
2. The EV2 software sequence must be completed before the end of the current byte transfer
3. After checking the SR1 register content, the user should perform the complete clearing sequence for each
flag found set.
Thus, for ADDR and STOPF flags, the following sequence is required inside the I2C interrupt routine:
READ SR1
if (ADDR == 1) {READ SR1; READ SR2}
if (STOPF == 1) {READ SR1; WRITE CR1}
The purpose is to make sure that both ADDR and STOPF flags are cleared if both are found set.
Master mode is selected as soon as the Start condition is generated on the bus with a
START bit.
The following is the required sequence in master mode.
● Program the peripheral input clock in I2C_CR2 Register in order to generate correct
timings
● Configure the clock control registers
● Configure the rise time register
● Program the I2C_CR1 register to enable the peripheral
● Set the START bit in the I2C_CR1 register to generate a Start condition
The peripheral input clock frequency must be at least:
● 2 MHz in Standard mode
● 4 MHz in Fast mode
Start condition
Setting the START bit causes the interface to generate a Start condition and to switch to
Master mode (M/SL bit set) when the BUSY bit is cleared.
Note: In master mode, setting the START bit causes the interface to generate a ReStart condition
at the end of the current byte transfer.
Once the Start condition is sent:
● The SB bit is set by hardware and an interrupt is generated if the ITEVFEN bit is set.
Then the master waits for a read of the SR1 register followed by a write in the DR register
with the Slave address (see Figure 271 and Figure 272 Transfer sequencing EV5).
The master can decide to enter Transmitter or Receiver mode depending on the LSB of the
slave address sent.
● In 7-bit addressing mode,
– To enter Transmitter mode, a master sends the slave address with LSB reset.
– To enter Receiver mode, a master sends the slave address with LSB set.
● In 10-bit addressing mode,
– To enter Transmitter mode, a master sends the header (11110xx0) and then the
slave address, (where xx denotes the two most significant bits of the address).
– To enter Receiver mode, a master sends the header (11110xx0) and then the
slave address. Then it should send a repeated Start condition followed by the
header (11110xx1), (where xx denotes the two most significant bits of the
address).
The TRA bit indicates whether the master is in Receiver or Transmitter mode.
Master transmitter
Following the address transmission and after clearing ADDR, the master sends bytes from
the DR register to the SDA line via the internal shift register.
The master waits until the first data byte is written into I2C_DR (see Figure 271 Transfer
sequencing EV8_1).
When the acknowledge pulse is received, the TxE bit is set by hardware and an interrupt is
generated if the ITEVFEN and ITBUFEN bits are set.
If TxE is set and a data byte was not written in the DR register before the end of the last data
transmission, BTF is set and the interface waits until BTF is cleared by a read from I2C_SR1
followed by a write to I2C_DR, stretching SCL low.
Closing the communication
After the last byte is written to the DR register, the STOP bit is set by software to generate a
Stop condition (see Figure 271 Transfer sequencing EV8_2). The interface automatically
goes back to slave mode (M/SL bit cleared).
Note: Stop condition should be programmed during EV8_2 event, when either TxE or BTF is set.
EV5: SB=1, cleared by reading SR1 register followed by writing DR register with Address.
EV6: ADDR=1, cleared by reading SR1 register followed by reading SR2.
EV8_1: TxE=1, shift register empty, data register empty, write Data1 in DR.
EV8: TxE=1, shift register not empty,.data register empty, cleared by writing DR register
EV8_2: TxE=1, BTF = 1, Program Stop request. TxE and BTF are cleared by hardware by the Stop condition
EV9: ADD10=1, cleared by reading SR1 register followed by writing DR register.
Notes: 1- The EV5, EV6, EV9, EV8_1 and EV8_2 events stretch SCL low until the end of the corresponding software sequence.
2- The EV8 software sequence must complete before the end of the current byte transfer. In case EV8 software
sequence can not be managed before the current byte end of transfer, it is recommended to use BTF instead
of TXE with the drawback of slowing the communication.
ai15881b
Master receiver
Following the address transmission and after clearing ADDR, the I2C interface enters
Master Receiver mode. In this mode the interface receives bytes from the SDA line into the
DR register via the internal shift register. After each byte the interface generates in
sequence:
1. An acknowledge pulse if the ACK bit is set
2. The RxNE bit is set and an interrupt is generated if the ITEVFEN and ITBUFEN bits are
set (see Figure 272 Transfer sequencing EV7).
If the RxNE bit is set and the data in the DR register is not read before the end of the last
data reception, the BTF bit is set by hardware and the interface waits until BTF is cleared by
a read in the SR1 register followed by a read in the DR register, stretching SCL low.
Closing the communication
Method 1: This method is for the case when the I2C is used with interrupts that have the
highest priority in the application.
The master sends a NACK for the last byte received from the slave. After receiving this
NACK, the slave releases the control of the SCL and SDA lines. Then the master can send
a Stop/Restart condition.
1. To generate the nonacknowledge pulse after the last received data byte, the ACK bit
must be cleared just after reading the second last data byte (after second last RxNE
event).
2. To generate the Stop/Restart condition, software must set the STOP/START bit just
after reading the second last data byte (after the second last RxNE event).
3. In case a single byte has to be received, the Acknowledge disable and the Stop
condition generation are made just after EV6 (in EV6_1, just after ADDR is cleared).
After the Stop condition generation, the interface goes automatically back to slave mode
(M/SL bit cleared).
Figure 273. Method 2: transfer sequence diagram for master receiver when N>2
1. The EV5, EV6 and EV9 events stretch SCL low until the end of the corresponding software sequence.
2. The EV7 software sequence must complete before the end of the current byte transfer.In case EV7
software sequence can not be managed before the current byte end of transfer, it is recommended to use
BTF instead of RXNE with the drawback of slowing the communication.
When 3 bytes remain to be read:
● RxNE = 1 => Nothing (DataN-2 not read).
● DataN-1 received
● BTF = 1 because both shift and data registers are full: DataN-2 in DR and DataN-1 in
the shift register => SCL tied low: no other data will be received on the bus.
● Clear ACK bit
● Read DataN-2 in DR => This will launch the DataN reception in the shift register
● DataN received (with a NACK)
● Program START/STOP
● Read DataN-1
● RxNE = 1
● Read DataN
The procedure described above is valid for N>2. The cases where a single byte or two bytes
are to be received should be handled differently, as described below:
● Case of a single byte to be received:
– In the ADDR event, clear the ACK bit.
– Clear ADDR
– Program the STOP/START bit.
– Read the data after the RxNE flag is set.
● Case of two bytes to be received:
– Set POS and ACK
– Wait for the ADDR flag to be set
– Clear ADDR
– Clear ACK
– Wait for BTF to be set
– Program STOP
– Read DR twice
Figure 274. Method 2: transfer sequence diagram for master receiver when N=2
S Header A Address A
EV5 EV9 EV6
1. The EV5, EV6 and EV9 events stretch SCL low until the end of the corresponding software sequence.
2. The EV6_1 software sequence must complete before the ACK pulse of the current byte transfer.
Figure 275. Method 2: transfer sequence diagram for master receiver when N=1
S Address A Data1 NA P
EV5 EV6_3 EV7
S Header A Address A
EV5 EV9 EV6
Sr Header A Data1 NA P
EV5 EV6_3 EV7
1. The EV5, EV6 and EV9 events stretch SCL low until the end of the corresponding software sequence.
26.3.6 SMBus
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. A system may use SMBus to pass messages to and from devices instead of
toggling individual control lines.
The System Management Bus Specification refers to three types of devices. A slave is a
device that is receiving or responding 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.
Device identification
Any device that exists on the System Management Bus as a slave has a unique address
called the Slave Address. For the list of reserved slave addresses, refer to the SMBus
specification ver. 2.0 (http://smbus.org/specs/).
Bus protocols
The SMBus specification supports up to 9 bus protocols. For more details of these protocols
and SMBus address types, refer to SMBus specification ver. 2.0 (http://smbus.org/specs/).
These protocols should be implemented by the user software.
Timeout error
There are differences in the timing specifications between I2C and SMBus.
SMBus defines a clock low timeout, TIMEOUT of 35 ms. Also SMBus specifies TLOW:
SEXT as the cumulative clock low extend time for a slave device. SMBus specifies TLOW:
MEXT as the cumulative clock low extend time for a master device. For more details on
these timeouts, refer to SMBus specification ver. 2.0 (http://smbus.org/specs/).
The status flag Timeout or Tlow Error in I2C_SR1 shows the status of this feature.
1. Set the I2C_DR register address in the DMA_CPARx register. The data will be moved
to this address from the memory after each TxE event.
2. Set the memory address in the DMA_CMARx register. The data will be loaded into
I2C_DR from this memory after each TxE event.
3. Configure the total number of bytes to be transferred in the DMA_CNDTRx register.
After each TxE event, this value will be decremented.
4. Configure the channel priority using the PL[0:1] bits in the DMA_CCRx register
5. Set the DIR bit and, in the DMA_CCRx register, configure interrupts after half transfer
or full transfer depending on application requirements.
6. Activate the channel by setting the EN bit in the DMA_CCRx register.
When the number of data transfers which has been programmed in the DMA Controller
registers is reached, the DMA controller sends an End of Transfer EOT/ EOT_1 signal to the
I2C interface and the DMA generates an interrupt, if enabled, on the DMA channel interrupt
vector.
Note: Do not enable the ITBUFEN bit in the I2C_CR2 register if DMA is used for transmission.
Note: 1 SB, ADDR, ADD10, STOPF, BTF, RxNE and TxE are logically ORed on the same interrupt
channel.
2 BERR, ARLO, AF, OVR, PECERR, TIMEOUT and SMBALERT are logically ORed on the
same interrupt channel.
STOPF
it_event
BTF
TxE
ITBUFEN
RxNE
ITERREN
BERR
ARLO
it_error
AF
OVR
PECERR
TIMEOUT
SMBALERT
NO SMB
SWRST ALERT PEC POS ACK STOP START ENGC ENPEC ENARP SMBUS PE
Res. STRETCH TYPE Res.
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
SMB SMBDE GEN
PEC[7:0] DUALF TRA BUSY MSL
HOST FAULT CALL Res.
r r r r r r r r r r r r r r r
Note: Reading I2C_SR2 after reading I2C_SR1 clears the ADDR flag, even if the ADDR flag was
set after reading I2C_SR1. Consequently, I2C_SR2 must be read only when ADDR is found
set in I2C_SR1 or when the STOPF bit is cleared.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
F/S DUTY CCR[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 11:0 CCR[11:0]: Clock control register in Fast/Standard mode (Master mode)
Controls the SCL clock in master mode.
Standard mode or SMBus:
Thigh = CCR * TPCLK1
Tlow = CCR * TPCLK1
Fast mode:
If DUTY = 0:
Thigh = CCR * TPCLK1
Tlow = 2 * CCR * TPCLK1
If DUTY = 1: (to reach 400 kHz)
Thigh = 9 * CCR * TPCLK1
Tlow = 16 * CCR * TPCLK1
For instance: in standard mode, to generate a 100 kHz SCL frequency:
If FREQR = 08, TPCLK1 = 125 ns so CCR must be programmed with 0x28
(0x28 <=> 40d x 125 ns = 5000 ns.)
Note: 1. The minimum allowed value is 0x04, except in FAST DUTY mode where the
minimum allowed value is 0x01
2. thigh = tr(SCL) + tw(SCLH). See device datasheet for the definitions of parameters
3. tlow = tf(SCL) + tw(SCLL). See device datasheet for the definitions of parameters
4. These timings are without filters.
5. The CCR register must be configured only when the I2C is disabled (PE = 0).
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
NOSTRETCH
SMBTYPE
SWRST
SMBUS
ENPEC
ENARP
ALERT
START
Reserved
Reserved
ENGC
STOP
POS
PEC
ACK
PE
I2C_CR1
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ITERREN
ITBUFEN
ITEVTEN
DMAEN
Reserved
LAST
I2C_CR2 FREQ[5:0]
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
ADDMODE
ADD0
I2C_OAR1 ADD[9:8] ADD[7:1]
0x08 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
ENDUAL
I2C_OAR2 ADD2[7:1]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0
I2C_DR DR[7:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0
SMBALERT
TIMEOUT
PECERR
STOPF
ADD10
Reserved
Reserved
ADDR
BERR
ARLO
RxNE
OVR
BTF
TxE
SB
AF
I2C_SR1
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SMBDEFAULT
SMBHOST
GENCALL
DUALF
Reserved
BUSY
MSL
TRA
I2C_SR2 PEC[7:0]
0x18 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reserved
DUTY
F/S
I2C_CCR CCR[11:0]
0x1C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
I2C_TRISE TRISE[5:0]
0x20 Reserved
Reset value 0 0 0 0 1 0
Refer to Table 3: Register boundary addresses for the register boundary addresses table.
Through these pins, serial data is transmitted and received in normal USART mode as
frames comprising:
● An Idle Line prior to transmission or reception
● A start bit
● A data word (8 or 9 bits) least significant bit first
● 0.5,1, 1.5, 2 Stop bits indicating that the frame is complete
● This interface uses a fractional baud rate generator - with a 12-bit mantissa and 4-bit
fraction
● A status register (USART_SR)
● Data register (USART_DR)
● A baud rate register (USART_BRR) - 12-bit mantissa and 4-bit fraction.
● A Guardtime Register (USART_GTPR) in case of Smartcard mode.
Refer to Section 27.6: USART registers on page 789 for the definitions of each bit.
The following pin is required to interface in synchronous mode:
● CK: Transmitter 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 (e.g. LCD drivers). The clock phase and polarity
are software programmable. In smartcard mode, CK can provide the clock to the
smartcard.
The following pins are required in Hardware flow control mode:
● nCTS: Clear To Send blocks the data transmission at the end of the current transfer
when high
● nRTS: Request to send indicates that the USART is ready to receive a data (when
low).
PWDATA PRDATA
Write Read (DATA REGISTER) DR
TX IrDA
SIR
RX ENDEC Transmit Shift Register Receive Shift Register
BLOCK
SW_RX
GTPR
GT PSC CK CONTROL CK
CR3 CR2
DMAT DMAR SCEN NACK HD IRLP IREN LINE STOP[1:0] CKEN CPOL CPHA LBCL
CR2 CR1
USART Address UE M WAKE PCE PS PEIE
nRTS Hardware
flow
nCTS controller
WAKE RECEIVER
TRANSMIT UP RECEIVER CLOCK
CONTROL UNIT CONTROL
CR1 SR
TXEIE TCIE RXNE
IE
IDLE TE RE RWU SBK CTS LBD TXE TC RXNE IDLE ORE NE FE PE
IE
USART
INTERRUPT
CONTROL
USART_BRR
TE TRANSMITTER RATE
TRANSMITTER
CONTROL
CLOCK
/16 /USARTDIV
DIV_Mantissa DIV_Fraction
15 4 0
fPCLKx(x=1,2)
RECEIVER RATE
RE CONTROL
CONVENTIONAL BAUD RATE GENERATOR
Start
Idle frame bit
Start
Idle frame bit
27.3.2 Transmitter
The transmitter can send data words of either 8 or 9 bits depending on the M bit status.
When the transmit enable bit (TE) is set, the data in the transmit shift register is output on
the TX pin and the corresponding clock pulses are output on the CK pin.
Character transmission
During a USART transmission, data shifts out least significant bit first on the TX pin. In this
mode, the USART_DR register consists of a buffer (TDR) between the internal bus and the
transmit shift register (see Figure 277).
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: 1 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.
2 An idle frame will be sent after the TE bit is enabled.
a) 1 Stop Bit
Possible Next Data Frame
Parity
Data Frame
Bit Next
Start Start
Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit
1 1/2 stop bits
b) 1 1/2 stop Bits
Possible Next Data Frame
Parity
Data Frame
Bit Next
Start 2 Stop Start
Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bits Bit
Procedure:
1. Enable the USART by writing the UE bit in USART_CR1 register to 1.
2. Program the M bit in USART_CR1 to define the word length.
3. Program the number of stop bits in USART_CR2.
4. Select DMA enable (DMAT) in USART_CR3 if Multi buffer Communication is to take
place. Configure the DMA register as explained in multibuffer communication.
5. Select the desired baud rate using the USART_BRR register.
6. Set the TE bit in USART_CR1 to send an idle frame as first transmission.
7. Write the data to send in the USART_DR register (this clears the TXE bit). Repeat this
for each data to be transmitted in case of single buffer.
8. After writing the last data into the USART_DR register, wait until TC=1. This indicates
that the transmission of the last frame is complete. This is required for instance when
the USART is disabled or enters the Halt mode to avoid corrupting the last
transmission.
When a transmission is taking place, a write instruction to the USART_DR register stores
the data in the TDR register and which is copied in the shift register at the end of the current
transmission.
When no transmission is taking place, a write instruction to the USART_DR register places
the data directly in the shift register, the data transmission starts, and the TXE bit is
immediately 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 into the USART_DR 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 280: TC/TXE behavior when transmitting).
The TC bit is cleared by the following software sequence:
1. A read from the USART_SR register
2. A write to the USART_DR register
Note: The TC bit can also be cleared by writing a ‘0’ to it. This clearing sequence is recommended
only for Multibuffer communication.
TX line
USART_DR F1 F2 F3
TC flag set
by hardware
software software waits until TXE=1 TC is not set TC is not set TC is set because
enables the and writes F2 into DR because TXE=0 because TXE=0 TXE=1
USART
software waits until TXE=1 software waits until TXE=1 software waits until TC=1
and writes F1 into DR and writes F3 into DR
ai17121b
Break characters
Setting the SBK bit transmits a break character. The break frame length depends on the M
bit (see Figure 278).
If the SBK bit is set to ‘1’ a break character is sent on the TX line after completing the current
character transmission. This bit is reset by hardware when the break character is completed
(during the stop bit of the break character). The USART inserts a logic 1 bit at the end of the
last break frame to guarantee the recognition of the start bit of the next frame.
Note: If the software resets the SBK bit before the commencement of break transmission, the
break character will not be transmitted. For two consecutive breaks, the SBK bit should be
set after the stop bit of the previous break.
Idle characters
Setting the TE bit drives the USART to send an idle frame before the first data frame.
27.3.3 Receiver
The USART can receive data words of either 8 or 9 bits depending on the M bit in the
USART_CR1 register.
RX line
Ideal
sample
clock 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
sampled values
Real
sample X X X X X X X X 9 10 11 12 13 14 15 16
clock
6/16
7/16 7/16
One-bit time
Conditions
to validate 1 1 1 0 X 0 X 0 X 0 0 0 0 X X X X X X
the start bit
Falling edge At least 2 bits At least 2 bits
detection out of 3 at 0 out of 3 at 0 ai15471
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 NE noise
flag is set if, for both samplings, at least 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). If this condition is not met,
the start detection aborts and the receiver returns to the idle state (no flag is set).
If, 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, the start bit is validated but the NE noise
flag bit is set.
Character reception
During a USART reception, data shifts in least significant bit first through the RX pin. In this
mode, the USART_DR register consists of a buffer (RDR) between the internal bus and the
received shift register.
Procedure:
1. Enable the USART by writing the UE bit in USART_CR1 register to 1.
2. Program the M bit in USART_CR1 to define the word length.
3. Program the number of stop bits in USART_CR2.
4. Select DMA enable (DMAR) in USART_CR3 if multibuffer communication is to take
place. Configure the DMA register as explained in multibuffer communication. STEP 3
5. Select the desired baud rate using the baud rate register USART_BRR
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. It indicates 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.
● In multibuffer, RXNE is set after every byte received and is cleared by the DMA read to
the Data Register.
● In single buffer mode, clearing the RXNE bit is performed by a software read to the
USART_DR register. The RXNE flag can also be cleared by writing a zero to it. The
RXNE bit must be cleared before the end of the reception of the next character to avoid
an overrun error.
Note: The RE bit should not be reset while receiving data. If the RE bit is disabled during
reception, the reception of the current byte will be aborted.
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 a data received 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_DR 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 both the EIE and DMAR bits
are set.
● The ORE bit is reset by a read to the USART_SR register followed by a USART_DR
register read operation.
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. It may also occur
when the new data is received during the reading sequence (between the USART_SR
register read access and the USART_DR read access).
Noise error
Over-sampling techniques are used (except in synchronous mode) for data recovery by
discriminating between valid incoming data and noise.
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
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_DR 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 a USART_SR register read operation followed by a USART_DR
register read operation.
USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register.
Note: The baud counters are updated with the new value of the Baud registers after a write to
USART_BRR. Hence the Baud rate register value should not be changed during
communication.
Example 2:
To program USARTDIV = 0d25.62
This leads to:
DIV_Fraction = 16*0d0.62 = 0d9.92
The nearest real number is 0d10 = 0xA
DIV_Mantissa = mantissa (0d25.620) = 0d25 = 0x19
Then, USART_BRR = 0x19A hence USARTDIV = 0d25.625
Example 3:
To program USARTDIV = 0d50.99
This leads to:
DIV_Fraction = 16*0d0.99 = 0d15.84
The nearest real number is 0d16 = 0x10 => overflow of DIV_frac[3:0] => carry must be
added up to the mantissa
DIV_Mantissa = mantissa (0d50.990 + carry) = 0d51 = 0x33
Then, USART_BRR = 0x330 hence USARTDIV = 0d51.000
Note: 1 The lower the CPU clock the lower will be the accuracy for a particular Baud rate. The upper
limit of the achievable baud rate can be fixed with this data.
2 Only USART1 is clocked with PCLK2 (72 MHz Max). Other USARTs are clocked with
PCLK1 (36 MHz Max).
Note: The figures specified in Table 193 and Table 194 may slighly differ in the special case when
the received frames contain some Idle frames of exactly 10-bit times when M=0 (11-bit times
when M=1).
The non addressed devices may be placed in mute mode by means of the muting function.
In mute mode:
● None of the reception status bits can be set.
● All the receive interrupts are inhibited.
● The RWU bit in USART_CR1 register is set to 1. RWU can be controlled automatically
by hardware or written by the software 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
In this example, the current address of the receiver is 1 RXNE RXNE RXNE
(programmed in the USART_CR2 register)
RX IDLE Addr=0 Data 1 Data 2 IDLE Addr=1 Data 3 Data 4 Addr=2 Data 5
RWU written to 1
(RXNE was cleared)
Note: In case of wake up by an address mark, the MSB bit of the data is taken into account and
not the parity bit
Even parity: the parity bit is calculated to obtain an even number of “1s” inside the frame
made of the 7 or 8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.
Ex: data=00110101; 4 bits set => 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 7 or 8 LSB bits (depending on whether M is equal to 0 or 1) and the parity bit.
Ex: data=00110101; 4 bits set => parity bit will be 1 if odd parity is selected (PS bit in
USART_CR1 = 1).
Transmission mode: If the PCE bit is set in USART_CR1, then the MSB bit of the data
written in the data register is transmitted but is changed by the parity bit (even number of
“1s” if even parity is selected (PS=0) or an odd number of “1s” if odd parity is selected
(PS=1)). If the parity check fails, the PE flag is set in the USART_SR register and an
interrupt is generated if PEIE is set in the USART_CR1 register.
LIN transmission
The same procedure explained in Section 27.3.2 has to be applied for LIN Master
transmission than for normal USART transmission with the following differences:
● Clear the M bit to configure 8-bit word length.
● Set the LINEN bit to enter LIN mode. In this case, setting the SBK bit sends 13 ‘0’ bits
as a break character. Then a bit of value ‘1’ is sent to allow the next start detection.
LIN reception
A break detection circuit is implemented in the USART. 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 LBD flag is set in USART_SR. 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 285: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 776.
Examples of break frames are given on Figure 286: Break detection in LIN mode vs.
Framing error detection on page 777.
Figure 285. Break detection in LIN mode (11-bit break length - LBDL bit is set)
Case 1: break signal not long enough => break discarded, LBD is not set
Capture Strobe
Break State machine Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 Idle
Read Samples 0 0 0 0 0 0 0 0 0 0 1
Case 2: break signal just long enough => break detected, LBD is set
Capture Strobe
delimiter is immediate
Break State machine Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 B10 Idle
Read Samples 0 0 0 0 0 0 0 0 0 0 0
LBD
Case 3: break signal long enough => break detected, LBD is set
Capture Strobe
Break State machine Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 wait delimiter Idle
Read Samples 0 0 0 0 0 0 0 0 0 0 0
LBD
Figure 286. Break detection in LIN mode vs. Framing error detection
In these examples, we suppose that LBDL=1 (11-bit break length), M=0 (8-bit data)
RXNE / FE
LBD
RXNE / FE
LBD
Note: 1 The CK pin works in conjunction with the TX pin. Thus, the clock is provided only if the
transmitter is enabled (TE=1) and a data is being transmitted (the data register USART_DR
has been written). This means that it is not possible to receive a synchronous data without
transmitting data.
2 The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the
receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. These
bits should not be changed while the transmitter or the receiver is enabled.
3 It is advised that TE and RE are set in the same instruction in order to minimize the setup
and the hold time of the receiver.
4 The USART supports master mode only: it cannot receive or send data related to an input
clock (CK is always an output).
RX Data out
TX Data in
CK Clock
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
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
CK (capture strobe on CK
rising edge in this example)
Data on RX valid DATA bit
(from slave)
tSETUP tHOLD
Note: The function of CK is different in Smartcard mode. Refer to the Smartcard mode chapter for
more details.
Apart from this, the communications are similar to what is done in normal USART mode.
The conflicts on the line must be managed by the software (by the use of a centralized
arbiter, for instance). In particular, the transmission is never blocked by hardware and
continue to occur as soon as a data is written in the data register while the TE bit is set.
27.3.11 Smartcard
The Smartcard mode is selected by setting the SCEN bit in the USART_CR3 register. In
smartcard mode, the following bits must be kept cleared:
● LINEN bit in the USART_CR2 register,
● HDSEL and IREN bits in the USART_CR3 register.
Moreover, the CLKEN bit may be set in order to provide a clock to the smartcard.
The Smartcard interface is designed to support asynchronous protocol Smartcards as
defined in the ISO 7816-3 standard. The USART should be configured as:
● 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register
● 1.5 stop bits when transmitting and receiving : where STOP=’11’ in the USART_CR2
register.
Note: It is also possible to choose 0.5 stop bit for receiving but it is recommended to use 1.5 stop
bits for both transmitting and receiving to avoid switching between the two configurations.
Figure 291 shows examples of what can be seen on the data line with and without parity
error.
S 0 1 2 3 4 5 6 7 P
Start
bit
S 0 1 2 3 4 5 6 7 P
When connected to a smartcard, the TX output of the USART drives a bidirectional line that
the smartcard also drives into. To do so, SW_RX must be connected on the same IO than
TX at product level. The Transmitter output enable TX_EN is asserted during the
transmission of the start bit and the data byte, and is deasserted during the stop bit (weak
pull up), so that the receive can drive the line in case of a parity error. If TX_EN is not used,
TX is driven at high level during the stop bit: Thus the receiver can drive the line as long as
TX is configured in open-drain.
Figure 292. Parity error detection using the 1.5 stop bits
sampling at sampling at
8th, 9th, 10th 16th, 17th, 18th
sampling at sampling at
8th, 9th, 10th 8th, 9th, 10th
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.
● IrDA is a half duplex communication protocol. If the Transmitter is busy (i.e. the
USARTsends data to the IrDA encoder), any data on the IrDA receive line is ignored by
the IrDA decoder and if the Receiver is busy (USART receives decoded data from the
USART), data on the TX from the USART to IrDA is not encoded by IrDA. While
receiving data, transmission should be avoided as the data to be transmitted could be
corrupted.
● A ‘0’ is transmitted as a high pulse and a ‘1’ is transmitted as a ‘0’. The width of the
pulse is specified as 3/16th of the selected bit period in normal mode (see Figure 294).
● The SIR decoder converts the IrDA compliant receive signal into a bit stream for
USART.
● The SIR receive logic interprets a high state as a logic one and low pulses as logic
zeros.
● The transmit encoder output has the opposite polarity to the decoder input. The SIR
output is in low state when idle.
● The IrDA specification requires the acceptance of pulses greater than 1.41 us. 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 IrDA low-power Baud Register, 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”.
TX
OR USART_TX
SIR
Transmit IrDA_OUT
SIREN Encoder
USART
SIR
RX Receive IrDA_IN
Decoder
USART_RX
IrDA_OUT
3/16
IrDA_IN
RX 0 0 1
0 1 0 1 0 1 1
1. Write the USART_DR register address in the DMA control register to configure it as the
destination of the transfer. The data will be moved to this address from memory after
each TXE event.
2. Write the memory address in the DMA control register to configure it as the source of
the transfer. The data will be loaded into the USART_DR register from this memory
area after each TXE event.
3. Configure the total number of bytes to be transferred to the DMA control register.
4. Configure the channel priority in the DMA register
5. Configure DMA interrupt generation after half/ full transfer as required by the
application.
6. Clear the TC bit in the SR register by writing 0 to it.
7. Activate the channel in the DMA register.
When the number of data transfers programmed in the DMA Controller is reached, the DMA
controller generates an interrupt on the DMA channel interrupt vector.
In transmission mode, once the DMA has written all the data to be transmitted (the TCIF flag
is set in the DMA_ISR register), the TC flag can be monitored to make sure that the USART
communication is complete. This is required to avoid corrupting the last transmission before
disabling the USART or entering the Stop mode. The software must wait until TC=1. The TC
flag remains cleared during all data transfers and it is set by hardware at the last frame’s end
of transmission.
TX line
USART_DR F1 F2 F3
set
TC flag by hardware
DMA writes
SPI_DR
clear
flag DMA TCIF set by hardware by software
(Transfer complete)
software configures DMA writes F1 DMA writes F2 DMA writes F3 The DMA transfer
the DMA to send 3 into into into is complete software waits until TC=1
data and enables the USART_DR USART_DR USART_DR. (TCIF=1 in
USART DMA_ISR)
ai17192
TX line
set by hardware
RXNE flag cleared by DMA read
DMA request
USART_DR F1 F2 F3
cleared
DMA TCIF flag set by hardware by software
(Transfer complete)
software configures the DMA reads F1 DMA reads F2 DMA reads F3 The DMA transfer
DMA to receive 3 data from from from is complete
blocks and enables USART_DR USART_DR USART_DR (TCIF=1 in
the USART DMA_ISR)
ai17193
USART 1 USART 2
TX RX
RX TX
RX circuit TX circuit
nRTS nCTS
RTS and CTS flow control can be enabled independently by writing respectively RTSE and
CTSE bits to 1 (in the USART_CR3 register).
nRTS
nCTS
The USART interrupt events are connected to the same interrupt vector (see Figure 300).
● During transmission: Transmission Complete, Clear to Send or Transmit Data Register
empty interrupt.
● While receiving: Idle Line detection, Overrun error, Receive Data register not empty,
Parity error, LIN break detection, Noise Flag (only in multi buffer communication) and
Framing Error (only in multi buffer communication).
These events generate an interrupt if the corresponding Enable Control Bit is set.
TC
TCIE
TXE
TXEIE
CTS
CTSIE
USART
IDLE
IDLEIE interrupt
RXNEIE
ORE
RXNEIE
RXNE
PE
PEIE
LBD
LBDIE
FE
NE
ORE EIE
DMAR
Asynchronous mode X X X X X
Hardware Flow Control X X X NA NA
Multibuffer Communication (DMA) X X X X NA
Multiprocessor Communication X X X X X
Synchronous X X X NA NA
Smartcard X X X NA NA
Half-Duplex (Single-Wire mode) X X X X X
IrDA X X X X X
LIN X X X X X
1. X = supported; NA = not applicable.
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DR[8:0]
Reserved
rw rw rw rw rw rw rw rw rw
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DIV_Mantissa[11:0] DIV_Fraction[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Note: These 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
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
RXNE
IDLE
ORE
CTS
LBD
TXE
NE
TC
PE
FE
USART_SR
0x00 Reserved
Reset value 0 0 1 1 0 0 0 0 0 0
USART_DR DR[8:0]
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0
DIV_Fraction
USART_BRR DIV_Mantissa[15:4]
0x08 Reserved [3:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RXNEIE
IDLEIE
WAKE
TXEIE
RWU
PEIE
TCIE
PCE
SBK
UE
RE
PS
TE
USART_CR1
M
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CLKEN
Reserved
Reserved
LINEN
LBDIE
CPHA
CPOL
LBCL
LBDL
STOP
USART_CR2 ADD[3:0]
0x10 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
HDSEL
DMAR
CTSIE
SCEN
NACK
DMAT
CTSE
RTSE
IREN
IRLP
EIE
USART_CR3
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Cortex-M3
USB2.0 OTG DP
Power&
OTG FS FS
Clock DM
Core UTMIFS PHY
CTRL USB duspend
ID
System clock USB clock
USB Clock at 48 MHz domain domain VBUS
RAM bus
1.25 Kbytes
USB data
FIFOs
ai17106
6$$
%.
34-03342
'0)/
#URRENT LIMITED 6 0WR
/VERCURRENT POWER DISTRIBUTION
'0)/ )21 SWITCH
34-&XX
34-&XX
53"MICRO !" CONNECTOR
6"53
0!
$-
0!
/3#?). $0
0!
)$
0!
/3#?/54
633
AIC
1. External voltage regulator only needed when building a VBUS powered device
2. STMPS2141STR needed only if the application has to support a VBUS powered device. A basic power
switch can be used if 5 V are available on the application board.
6$$
6 TO 6$$
6OLATGE REGULATOR
34-&XX
34-&XX
6"53
53" 3TD " CONNECTOR
0!
$-
0!
/3#?). $0
0!
633
/3#?/54
AI
Soft disconnect
The powered state can be exited by software with the soft disconnect feature. The DP pull-
up resistor is removed by setting the soft disconnect bit in the device control register (SDIS
bit in OTG_FS_DCTL), causing a device disconnect detection interrupt on the host side
even though the USB cable was not really removed from the host port.
Default state
In the Default state the OTG_FS expects to receive a SET_ADDRESS command from the
host. No other USB operation is possible. When a valid SET_ADDRESS command is
decoded on the USB, the application writes the corresponding number into the device
address field in the device configuration register (DAD bit in OTG_FS_DCFG). The OTG_FS
then enters the address state and is ready to answer host transactions at the configured
USB address.
Suspended state
The OTG_FS peripheral constantly monitors the USB activity. After counting 3 ms of USB
idleness, the early suspend interrupt (ESUSP bit in OTG_FS_GINTSTS) is issued, and
confirmed 3 ms later, if appropriate, by the suspend interrupt (USBSUSP bit in
OTG_FS_GINTSTS). The device suspend bit is then automatically set in the device status
register (SUSPSTS bit in OTG_FS_DSTS) and the OTG_FS enters the suspended state.
The suspended state may optionally be exited by the device itself. In this case the
application sets the remote wakeup signaling bit in the device control register (WKUPINT bit
in OTG_FS_DCTL) and clears it after 1 to 15 ms.
When a resume signaling is detected from the host, the resume interrupt (RWUSIG bit in
OTG_FS_GINTSTS) is generated and the device suspend bit is automatically cleared.
Endpoint control
● The following endpoint controls are available to the application through the device
endpoint-x IN/OUT control register (DIEPCTLx/DOEPCTLx):
– Endpoint enable/disable
– Endpoint activate in current configuration
– Program USB transfer type (isochronous, bulk, interrupt)
– Program supported packet size
– Program Tx-FIFO number associated with the IN endpoint
– Program the expected or transmitted data0/data1 PID (bulk/interrupt only)
– Program the even/odd frame during which the transaction is received or
transmitted (isochronous only)
– Optionally program the NAK bit to always negative-acknowledge the host
regardless of the FIFO status
– Optionally program the STALL bit to always stall host tokens to that endpoint
– Optionally program the SNOOP mode for OUT endpoint not to check the CRC
field of received data
Endpoint transfer
The device endpoint-x transfer size registers (DIEPTSIZx/DOEPTSIZx) allow the application
to program the transfer size parameters and read the transfer status. Programming must be
done before setting the endpoint enable bit in the endpoint control register. Once the
endpoint is enabled, these fields are read-only as the OTG FS core updates them with the
current transfer status.
The following transfer parameters can be programmed:
● Transfer size in bytes
● Number of packets that constitute the overall transfer size
Endpoint status/interrupt
The device endpoint-x interrupt registers (DIEPINTx/DOPEPINTx) indicate the status of an
endpoint with respect to USB- and AHB-related events. The application must read these
registers when the OUT endpoint interrupt bit or the IN endpoint interrupt bit in the core
interrupt register (OEPINT bit in OTG_FS_GINTSTS or IEPINT bit in OTG_FS_GINTSTS,
respectively) is set. Before the application can read these registers, it must first read the
device all endpoints interrupt (OTG_FS_DAINT) register to get the exact endpoint number
for the device endpoint-x interrupt register. The application must clear the appropriate bit in
this register to clear the corresponding bits in the DAINT and GINTSTS registers
The peripheral core provides the following status checks and interrupt generation:
● Transfer completed interrupt, indicating that data transfer was completed on both the
application (AHB) and USB sides
● Setup stage has been done (control-out only)
● Associated transmit FIFO is half or completely empty (in endpoints)
● NAK acknowledge has been transmitted to the host (isochronous-in only)
● IN token received when Tx-FIFO was empty (bulk-in/interrupt-in only)
● Out token received when endpoint was not yet enabled
● Babble error condition has been detected
● Endpoint disable by application is effective
● Endpoint NAK by application is effective (isochronous-in only)
● More than 3 back-to-back setup packets were received (control-out only)
● Timeout condition detected (control-in only)
● Isochronous out packet has been dropped, without generating an interrupt
%.
'0)/ 34-03342
#URRENT LIMITED 6 0WR
/VERCURRENT POWER DISTRIBUTION
'0)/ )21 SWITCH
34-&XX
34-&XX 6"53
AIB
1. STMPS2141STR needed only if the application has to support a VBUS powered device. A basic power
switch can be used if 5 V are available on the application board.
VBUS valid
The VBUS input ensures that valid VBUS levels are supplied by the charge pump during USB
operations.
Any unforeseen VBUS voltage drop below the VBUS valid threshold (4.25 V) leads to an OTG
interrupt triggered by the session end detected bit (SEDET bit in OTG_FS_GOTGINT). The
application is then required to remove the VBUS power and clear the port power bit. The
charge pump overcurrent flag can also be used to prevent electrical damage. Connect the
overcurrent flag output from the charge pump to any GPIO input and configure it to generate
a port interrupt on the active level. The overcurrent ISR must promptly disable the VBUS
generation and clear the port power bit.
When VBUS is at a valid level and a remote B-device is attached, the OTG_FS core issues a
host port interrupt triggered by the device connected bit in the host port control and status
register (PCDET bit in OTG_FS_HPRT).
Host enumeration
After detecting a peripheral connection the host must start the enumeration process by
sending USB reset and configuration commands to the new peripheral.
Before starting to drive a USB reset, the application waits for the OTG interrupt triggered by
the debounce done bit (DBCDNE bit in OTG_FS_GOTGINT), which indicates that the bus is
stable again after the electrical debounce caused by the attachment of a pull-up resistor on
DP (FS) or DM (LS).
The application drives a USB reset signaling (single-ended zero) over the USB by keeping
the port reset bit set in the host port control and status register (PRST bit in
OTG_FS_HPRT) for a minimum of 10 ms and a maximum of 20 ms. The application takes
care of the timing count and then of clearing the port reset bit.
Once the USB reset sequence has completed, the host port interrupt is triggered by the port
enable/disable change bit (PENCHNG bit in OTG_FS_HPRT). This informs the application
that the speed of the enumerated peripheral can be read from the port speed field in the
host port control and status register (PSPD bit in OTG_FS_HPRT) and that the host is
starting to drive SOFs (FS) or Keep alives (LS). The host is now ready to complete the
peripheral enumeration by sending peripheral configuration commands.
Host suspend
The application decides to suspend the USB activity by setting the port suspend bit in the
host port control and status register (PSUSP bit in OTG_FS_HPRT). The OTG_FS core
stops sending SOFs and enters the suspended state.
The suspended state can be optionally exited on the remote device’s initiative (remote
wakeup). In this case the remote wakeup interrupt (WKUPINT bit in OTG_FS_GINTSTS) is
generated upon detection of a remote wakeup signaling, the port resume bit in the host port
control and status register (PRES bit in OTG_FS_HPRT) self-sets, and resume signaling is
automatically driven over the USB. The application must time the resume window and then
clear the port resume bit to exit the suspended state and restart the SOF.
If the suspended state is exited on the host initiative, the application must set the port
resume bit to start resume signaling on the host port, time the resume window and finally
clear the port resume bit.
Each host channel can be configured to support in/out and any type of periodic/nonperiodic
transaction. Each host channel makes us of proper control (HCCHARx), transfer
configuration (HCTSIZx) and status/interrupt (HCINTx) registers with associated mask
(HCINTMSKx) registers.
corresponding bits in the HAINT and GINTSTS registers. The mask bits for each interrupt
source of each channel are also available in the OTG_FS_HCINTMSK-x register.
● The host core provides the following status checks and interrupt generation:
– Transfer completed interrupt, indicating that the data transfer is complete on both
the application (AHB) and USB sides
– Channel has stopped due to transfer completed, USB transaction error or disable
command from the application
– Associated transmit FIFO is half or completely empty (IN endpoints)
– ACK response received
– NAK response received
– STALL response received
– USB transaction error due to CRC failure, timeout, bit stuff error, false EOP
– Babble error
– fraMe overrun
– dAta toggle error
STM32F105xx
STM32F107xx
VSS
ai17120
The OTG FS core provides means to monitor, track and configure SOF framing in the host
and peripheral, as well as an SOF pulse output connectivity feature.
Such utilities are especially useful for adaptive audio clock generation techniques, where the
audio peripheral needs to synchronize to the isochronous stream provided by the PC, or the
host needs to trim its framing rate according to the requirements of the audio peripheral.
register (SOFOUTEN bit in OTG_FS_GCCFG). The SOF pulse signal is also internally
connected to the TIM2 input trigger, so that the input capture feature, the output compare
feature and the timer can be triggered by the SOF pulse. The TIM2 connection is enabled of
.
The end of periodic frame interrupt (GINTSTS/EOPF) is used to notify the application when
80%, 85%, 90% or 95% of the time frame interval elapsed depending on the periodic frame
interval field in the device configuration register (PFIVL bit in OTG_FS_DCFG). This feature
can be used to determine if all of the isochronous traffic for that frame is complete.
To save dynamic power, the USB data FIFO is clocked only when accessed by the OTG_FS
core.
/4'?&3?(&)2
WRITE
/4'?&3?(&)2
VALUE
&RAME
x x x x
TIMER
AI
ai15611
Rx packets RXFSIZ[31:16]
Any channel DFIFO pop
access from AHB Rx FIFO control
Rx start address
fixed to 0
MAC push A1 = 0
ai15610
Transmit FIFO RAM allocation: the minimum RAM space required for each IN Endpoint
Transmit FIFO is the maximum packet size for that particular IN endpoint.
Note: More space allocated in the transmit IN Endpoint FIFO results in better performance on the
USB.
OTG_FS to fill in the available RAM space at best regardless of the current USB sequence.
With these features:
● The application gains good margins to calibrate its intervention in order to optimize the
CPU bandwidth usage:
– It can accumulate large amounts of transmission data in advance compared to
when they are effectively sent over the USB
– It benefits of a large time margin to download data from the single receive FIFO
● The USB Core is able to maintain its full operating rate, that is to provide maximum full-
speed bandwidth with a great margin of autonomy versus application intervention:
– It has a large reserve of transmission data at its disposal to autonomously manage
the sending of data over the USB
– It has a lot of empty space available in the receive buffer to autonomously fill it in
with the data coming from the USB
As the OTG_FS core is able to fill in the 1.25 Kbyte RAM buffer very efficiently, and as
1.25 Kbyte of transmit/receive data is more than enough to cover a full speed frame, the
USB system is able to withstand the maximum full-speed data rate for up to one USB frame
(1 ms) without any CPU intervention.
OR
Global interrupt
mask (Bit 0)
AHB configuration
register
AND
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17:10 9 8 7:3 2 1 0
OTG
interrupt
Device all endpoints register
interrupt register
16:9 3:0 Device all endpoints
OUT endpoints IN endpoints interrupt mask register
ai15616b
1. The core interrupt register bits are shown in OTG_FS core interrupt register (OTG_FS_GINTSTS) on
page 838.
Reserved
2 0000h
DFIFO
debug read/
Direct access to data FIFO RAM
write to this
for debugging (128 Kbyte)
region
3 FFFFh
ai15615b
OTG_FS_GOTGCTL 0x000 OTG_FS control and status register (OTG_FS_GOTGCTL) on page 829
Table 199. Core global control and status registers (CSRs) (continued)
Address
Acronym Register name
offset
OTG_FS_GRXSTSR 0x01C OTG_FS Receive status debug read/OTG status read and pop registers
OTG_FS_GRXSTSP 0x020 (OTG_FS_GRXSTSR/OTG_FS_GRXSTSP) on page 845
OTG_FS_GRXFSIZ 0x024 OTG_FS Receive FIFO size register (OTG_FS_GRXFSIZ) on page 846
OTG_FS_HFIR 0x404 OTG_FS Host frame interval register (OTG_FS_HFIR) on page 851
0x920
0x940 OTG device endpoint-x control register (OTG_FS_DIEPCTLx) (x = 1..3,
OTG_FS_DIEPCTLx
... where x = Endpoint_number) on page 870
0xAE0
0xB20
0xB40
... OTG device endpoint-x control register (OTG_FS_DIEPCTLx) (x = 1..3,
OTG_FS_DOEPCTLx
0xCC0 where x = Endpoint_number) on page 870
0xCE0
0xCFD
Table 203. Power and clock gating control and status registers
Register name Acronym Offset address: 0xE00–0xFFF
Reserved 0xE05–0xFFF
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
HSHNPEN
HNGSCS
SRQSCS
DHNPEN
CIDSTS
HNPRQ
BSVLD
ASVLD
DBCT
SRQ
r r r r rw rw rw r rw r
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
HNSSCHG
ADTOCHG
SRSSCHG
DBCDNE
HNGDET
SEDET
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
PTXFELVL
GINTMSK
TXFELVL
Reserved Reserved
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
r/rw HNPCAP
r/rw SRPCAP
PHYSEL
CTXPKT
FDMOD
FHMOD
TRDT TOCAL
Reserved
Reserved
rw rw rw rw wo 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
RXFFLSH
TXFFLSH
AHBIDL
HSRST
CSRST
FCRST
Reserved
TXFNUM
Reserved
r rw rs rs rs rs rs
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
IPXFR/INCOMPISOOUT
GOUTNAKEFF
ENUMDNE
GINAKEFF
USBSUSP
ISOODRP
CIDSCHG
HPRTINT
Reserved
IISOIXFR
USBRST
DISCINT
NPTXFE
WKUINT
SRQINT
OTGINT
OEPINT
RXFLVL
ESUSP
PTXFE
IEPINT
HCINT
CMOD
EOPF
MMIS
SOF
Reserved
Reserved
Reserved
rc_w1
rc_w1
rc_w1 r r r Res. rc_w1 r r rc_w1 r r r r r r
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
IPXFRM/IISOOXFRM
GONAKEFFM
ENUMDNEM
GINAKEFFM
USBSUSPM
ISOODRPM
CIDSCHGM
IISOIXFRM
NPTXFEM
RXFLVLM
ESUSPM
USBRST
PTXFEM
DISCINT
EPMISM
OTGINT
OEPINT
EOPFM
MMISM
SRQIM
IEPINT
PRTIM
SOFM
WUIM
HCIM
Reserved
Reserved
Reserved
Reserved
Reserved
rw rw rw rw rw rw r rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
OTG_FS Receive status debug read/OTG status read and pop registers
(OTG_FS_GRXSTSR/OTG_FS_GRXSTSP)
Address offset for Read: 0x01C
Address offset for Pop: 0x020
Reset value: 0x0000 0000
A read to the Receive status debug read register returns the contents of the top of the
Receive FIFO. A read to the Receive status read and pop register additionally pops the top
data entry out of the RxFIFO.
The receive status contents must be interpreted differently in host and device modes. The
core ignores the receive status pop/read when the receive FIFO is empty and returns a
value of 0x0000 0000. The application must only pop the Receive Status FIFO when the
Receive FIFO non-empty bit of the Core interrupt register (RXFLVL bit in
OTG_FS_GINTSTS) is asserted.
Host mode:
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
PKTSTS DPID BCNT CHNUM
Reserved
r r r r
Device mode:
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
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
RXFD
Reserved
r/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
NPTXFD/TX0FD NPTXFSA/TX0FSA
r/rw r/rw
Host mode
Device mode
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
Reserved
r r r
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
SOFOUTEN
VBUSBSEN
VBUSASEN
.PWRDWN
Reserved
Reserved Reserved
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
PRODUCT_ID
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
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
PTXFSIZ PTXSA
r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r
w w w w w w w w w w w w w w w w 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
INEPTXFD INEPTXSA
r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r r/r
w w w w w w w w w w w w w w w w 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
FSLSPCS
FSLSS
Reserved
r 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
FRIVL
Reserved
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
FTREM FRNUM
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PTXQTOP PTXQSAV PTXFSAVL
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
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
HAINT
Reserved
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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HAINTM
Reserved
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
POCCHNG
PENCHNG
PCDET
PSUSP
PCSTS
PLSTS
PPWR
POCA
PRES
PENA
PRST
Reserved
PSPD PTCTL
Reserved
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
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
DAD MCNT EPNUM MPSIZ
rs rs 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
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
FRMOR
DTERR
BBERR
TXERR
STALL
XFRC
CHH
NAK
ACK
Reserved
Reserved
Reserved
rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_
w1 w1 w1 w1 w1 w1 w1 w1 w1
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
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
CHHM
NAKM
ACKM
NYET
Reserved
Reserved
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
Reserved
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
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
NZLSOHSK
PFIVL
DSPD
Reserved
DAD
Reserved
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
POPRGDNE
CGONAK
SGONAK
GONSTS
RWUSIG
CGINAK
SGINAK
GINSTS
TCTL
SDIS
Reserved
rw w w w w rw rw rw r r rw rw
Table 204 contains the minimum duration (according to device state) for which the Soft
disconnect (SDIS) bit must be set for the USB host to detect a device disconnect. To
accommodate clock jitter, it is recommended that the application add some extra delay to
the specified minimum duration.
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
ENUMSPD
SUSPSTS
EERR
FNSOF
Reserved Reserved
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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ITTXFEMSK
INEPNMM
INEPNEM
XFRCM
EPDM
Reserved
TOM
Reserved
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
OTEPDM
XFRCM
STUPM
EPDM
Reserved
Reserved
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
OEPINT IEPINT
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OEPM IEPM
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
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
VBUSDT
Reserved
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
DVBUSP
Reserved
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
INEPTXFEM
Reserved
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
USBAEP
NAKSTS
EPENA
EPDIS
STALL
CNAK
SNAK
Reserved
Reserved
Reserved
TXFNUM EPTYP MPSIZ
Reserved
r r w w rw rw rw rw rs r r r r 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
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
CNAK
SNAK
Stall
Reserved
TXFNUM MPSIZ
Reserved
rw/
rs rs w w w w rw rw rw rw rw rw r r rw rw rw rw rw rw rw rw rw rw rw rw
rs
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
USBAEP
NAKSTS
EPENA
EPDIS
SNPM
CNAK
SNAK
Reserved
Reserved
Stall
EPTYP MPSIZ
Reserved Reserved
w r w w rs rw r r r r r r
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
SODDFRM/SD1PID
SD0PID/SEVNFRM
EONUM/DPID
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
SNPM
CNAK
SNAK
Stall
MPSIZ
Reserved Reserved
rw/
rs rs w w w w rw rw rw r r rw rw rw rw rw rw rw rw rw rw rw rw
rs
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
EPDISD
INEPNE
ITTXFE
XFRC
TXFE
TOC
Reserved
Reserved
Reserved
rc_
rc_ rc_ rc_ rc_
r w1
w1 w1 w1 w1
/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
B2BSTUP
OTEPDIS
EPDISD
XFRC
STUP
Reserved
Reserved
Reserved
Reserved
rc_
rc_ rc_ rc_ rc_
w1
w1 w1 w1 w1
/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
PKTCNT XFRSIZ
Reserved Reserved
rw rw rw rw rw rw rw rw rw
PKTCNT
Reserved
STUPC
XFRSIZ
NT Reserved Reserved
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
MCNT PKTCNT XFRSIZ
Reserved
rw/ rw/
r/r r/r 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
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
INEPTFSAV
Reserved
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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RXDPID/S
Reserved
PKTCNT XFRSIZ
TUPCNT
rw/r/ rw/r/
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
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
GATEHCLK
PHYSUSP
STPPCLK
Reserved Reserved
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
Offset Register
9
8
7
6
5
4
3
2
1
0
HSHNPEN
HNGSCS
SRQSCS
DHNPEN
CIDSTS
HNPRQ
BSVLD
ASVLD
DBCT
OTG_FS_GOT
SRQ
0x000 GCTL Reserved Reserved Reserved
Reset value 0 0 0 1 0 0 0 0 0 0
HNSSCHG
ADTOCHG
SRSSCHG
DBCDNE
HNGDET
SEDET
Reserved
OTG_FS_GOT
0x004 GINT Reserved Reserved Res.
Reset value 0 0 0 0 0 0
PTXFELVL
GINTMSK
TXFELVL
OTG_FS_GAH
0x008 BCFG Reserved Reserved
Reset value 0 0 0
HNPCAP
SRPCAP
PHYSEL
CTXPKT
FDMOD
FHMOD
OTG_FS_GUS
TRDT TOCAL
0x00C BCFG Reserved Reserved
Reset value 0 1 0 1 0 0 1 0 0 0
RXFFLSH
TXFFLSH
Reserved
AHBIDL
HSRST
CSRST
FCRST
OTG_FS_GRST
TXFNUM
0x010 CTL Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0
IPXFR/INCOMPISOOUT
GOUTNAKEFF
ENUMDNE
GINAKEFF
USBSUSP
ISOODRP
CIDSCHG
HPRTINT
IISOIXFR
USBRST
DISCINT
NPTXFE
WKUINT
SRQINT
OTGINT
OEPINT
RXFLVL
ESUSP
PTXFE
IEPINT
HCINT
CMOD
Reserved
Reserved
Reserved
Reserved
EOPF
MMIS
OTG_FS_GINT
SOF
0x014 STS
Reset value 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
IPXFRM/IISOOXFRM
GONAKEFFM
ENUMDNEM
GINAKEFFM
USBSUSPM
CIDSCHGM
ISOODRPM
IISOIXFRM
NPTXFEM
RXFLVLM
ESUSPM
PTXFEM
USBRST
DISCINT
EPMISM
OTGINT
OEPINT
EOPFM
MMISM
SRQIM
IEPINT
PRTIM
Reserved
Reserved
Reserved
Reserved
Reserved
SOFM
WUIM
HCIM
OTG_FS_GINT
0x018 MSK
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
OTG_FS_GRXS
TSR (host PKTSTS DPID BCNT CHNUM
Reserved
mode)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x01C
OTG_FS_GRXS
TSR (Device FRMNUM PKTSTS DPID BCNT EPNUM
Reserved
mode)
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
OTG_FS_GRXS
TSR (host PKTSTS DPID BCNT CHNUM
Reserved
mode)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x020
OTG_FS_GRXS
TSPR (Device FRMNUM PKTSTS DPID BCNT EPNUM
Reserved
mode)
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
OTG_FS_GRXF
RXFD
0x024 SIZ Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
OTG_FS_HNPT
XFSIZ/
NPTXFD/TX0FD NPTXFSA/TX0FSA
0x028 OTG_FS_DIEP
TXF0
Reset value 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 0
OTG_FS_HNPT
NPTXQTOP NPTQXSAV NPTXFSAV
Res.
0x02C XSTS
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
SOFOUTEN
VBUSBSEN
VBUSASEN
.PWRDWN
Reserved
OTG_FS_
0x038 GCCFG Reserved Reserved
Reset value 0 0 0 0
OTG_FS_CID PRODUCT_ID
0x03C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0
OTG_FS_HPTX
PTXFSIZ PTXSA
0x100 FSIZ
Reset value 0 0 0 0 0 1 1 1 0 1 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0
OTG_FS_DIEP
INEPTXFD INEPTXSA
0x104 TXF1
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
OTG_FS_DIEP
INEPTXFD INEPTXSA
0x108 TXF2
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
OTG_FS_DIEP
INEPTXFD INEPTXSA
0x10C TXF3
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
FSLSPCS
FSLSS
OTG_FS_HCFG
0x400 Reserved
Reset value 0 0 0
OTG_FS_HFIR FRIVL
0x404 Reserved
Reset value 1 1 1 0 1 0 1 0 0 1 1 0 0 0 0 0
OTG_FS_HFNU
FTREM FRNUM
0x408 M
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1
OTG_FS_HPTX
PTXQTOP PTXQSAV PTXFSAVL
0x410 STS
Reset value 0 0 0 0 0 0 0 0 Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y
OTG_FS_HAIN
HAINT
0x414 T Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTG_FS_HAIN
HAINTM
0x418 TMSK Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
POCCHNG
PENCHNG
Reserved
PSUSP
PCDET
PCSTS
PLSTS
PPWR
POCA
PRES
PENA
PRST
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x500 HAR0
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
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x520 HAR1
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
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x540 HAR2
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
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x560 HAR3
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
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x580 HAR4
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
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x5A0 HAR5
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
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x5C0 HAR6
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
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
Reserved
OTG_FS_HCC
DAD MCNT EPNUM MPSIZ
0x5E0 HAR7
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
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
NAK
ACK
0x508 T0 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
NAK
ACK
0x528 T1 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
NAK
ACK
0x548 T2 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
NAK
ACK
0x568 T3 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
NAK
ACK
0x588 T4 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
OTG_FS_HCIN XFRC
CHH
NAK
ACK
0x5A8 T5 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
NAK
ACK
0x5C8 T6 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMOR
DTERR
BBERR
TXERR
Reserved
Reserved
STALL
XFRC
OTG_FS_HCIN
CHH
NAK
ACK
0x5E8 T7 Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
NAKM
ACKM
NYET
OTG_FS_HCIN
0x50C TMSK0 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
NAKM
ACKM
NYET
OTG_FS_HCIN
0x52C TMSK1 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
NAKM
ACKM
NYET
OTG_FS_HCIN
0x54C TMSK2 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
NAKM
ACKM
NYET
OTG_FS_HCIN
0x56C TMSK3 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
NAKM
ACKM
NYET
OTG_FS_HCIN
0x58C TMSK4 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
NAKM
ACKM
NYET
OTG_FS_HCIN
0x5AC TMSK5 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
NAKM
ACKM
NYET
OTG_FS_HCIN
0x5CC TMSK6 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
Reserved
CHHM
NAKM
ACKM
NYET
OTG_FS_HCIN
0x5EC TMSK7 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
OTG_FS_HCTS
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved
DSPD
DAD
OTG_FS_DCFG
0x800 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
POPRGDNE
CGONAK
SGONAK
GONSTS
RWUSIG
CGINAK
SGINAK
GINSTS
TCTL
SDIS
OTG_FS_DCTL
0x804 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ENUMSPD
SUSPSTS
EERR
OTG_FS_DSTS FNSOF
0x808 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ITTXFEMSK
INEPNMM
INEPNEM
XFRCM
Reserved
EPDM
OTG_FS_DIEP
TOM
0x810 MSK Reserved
Reset value 0 0 0 0 0 0
OTEPDM
XFRCM
STUPM
Reserved
EPDM
OTG_FS_DOEP
0x814 MSK Reserved
Reset value 0 0 0 0
OTG_FS_DAIN
OEPINT IEPINT
0x818 T
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
OTG_FS_DAIN
OEPM IEPM
0x81C TMSK
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
OTG_FS_DVBU
VBUSDT
0x828 SDIS Reserved
Reset value 0 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1
OTG_FS_DVBU
DVBUSP
0x82C SPULSE Reserved
Reset value 0 1 0 1 1 0 1 1 1 0 0 0
OTG_FS_DIEP
INEPTXFEM
0x834 EMPMSK Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
USBAEP
NAKSTS
EPENA
Reserved
Reserved
Reserved
EPDIS
CNAK
SNAK
TXFNUM
0x900 CTL0 P Reserved Z
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
TG_FS_DTXFS
INEPTFSAV
0x918 TS0 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
SODDFRM/SD1PID
SD0PID/SEVNFRM
EONUM/DPID
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
Reserved
CNAK
SNAK
OTG_FS_DIEP
Stall
TXFNUM MPSIZ
0x920 CTL1 Reserved
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
TG_FS_DTXFS
INEPTFSAV
0x938 TS1 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
Reserved
CNAK
SNAK
OTG_FS_DIEP
Stall
TXFNUM MPSIZ
0x940 CTL2 Reserved
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
TG_FS_DTXFS
INEPTFSAV
0x958 TS2 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
Reserved
CNAK
SNAK
OTG_FS_DIEP
Stall
TXFNUM MPSIZ
0x960 CTL3 Reserved
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
TG_FS_DTXFS
INEPTFSAV
0x978 TS3 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
USBAEP
NAKSTS
EPENA
EPDIS
Reserved
Reserved
SNPM
CNAK
SNAK
Stall
0xB00 CTL0 Reserved P Reserved Z
Reset value 0 0 0 0 0 0 0 0 0 1 0 0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
SNPM
CNAK
SNAK
OTG_FS_DOEP
Stall
MPSIZ
0xB20 CTL1 Reserved Reserved
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
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
SNPM
CNAK
SNAK
OTG_FS_DOEP
Stall
MPSIZ
0xB40 CTL2 Reserved Reserved
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
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
SNPM
CNAK
SNAK
OTG_FS_DOEP
Stall
MPSIZ
0xB60 CTL3 Reserved Reserved
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
INEPNE
EPDISD
ITTXFE
Reserved
Reserved
XFRC
TXFE
OTG_FS_DIEPI TOC
0x908 NT0 Reserved
Reset value 1 0 0 0 0
EPDISD 0
INEPNE
ITTXFE
Reserved
Reserved
XFRC
TXFE
OTG_FS_DIEPI
TOC
Reset value 1 0 0 0 0 0
INEPNE
EPDISD
ITTXFE
Reserved
Reserved
XFRC
TXFE
OTG_FS_DIEPI
TOC
Reset value 1 0 0 0 0 0
EPDISD
INEPNE
ITTXFE
Reserved
Reserved
XFRC
TXFE
OTG_FS_DIEPI
TOC
Reset value 1 0 0 0 0 0
B2BSTUP
OTEPDIS
EPDISD
Reserved
Reserved
Reserved
XFRC
STUP
OTG_FS_DOEP
0xB08 INT0 Reserved
Reset value 0 0 0 0 0
B2BSTUP
OTEPDIS
EPDISD
Reserved
Reserved
Reserved
XFRC
STUP
OTG_FS_DOEP
0xB28 INT1 Reserved
Reset value 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
B2BSTUP
OTEPDIS
EPDISD
Reserved
Reserved
Reserved
XFRC
STUP
OTG_FS_DOEP
0xB48 INT2 Reserved
Reset value 0 0 0 0 0
B2BSTUP
OTEPDIS
EPDISD
Reserved
Reserved
Reserved
XFRC
STUP
OTG_FS_DOEP
0xB68 INT3 Reserved
Reset value 0 0 0 0 0
OTG_FS_DIEP PKTC
XFRSIZ
0x910 TSIZ0 Reserved NT Reserved
Reset value 0 0 0 0 0 0 0 0 0
OTG_FS_DIEP
Reserved Reserved Reserved Reserved
OTG_FS_DOEP STUP
XFRSIZ
0xB10 TSIZ0 CNT Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
STUPCNT
RXDPID/
Reserved
OTG_FS_DOEP
PKTCNT XFRSIZ
0xB30 TSIZ1
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
STUPCNT
RXDPID/
Reserved
OTG_FS_DOEP
PKTCNT XFRSIZ
0xB50 TSIZ2
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
STUPCNT
RXDPID/
Reserved
OTG_FS_DOEP
PKTCNT XFRSIZ
0xB70 TSIZ3
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
GATEHCLK
PHYSUSP
STPPCLK
Reserved
OTG_FS_PCG
0xE00 CCTL Reserved
Reset value
This section explains the initialization of the OTG_FS controller after power-on. The
application must follow the initialization sequence irrespective of host or device mode
operation. All core global registers are initialized according to the core’s configuration:
1. Program the following fields in the OTG_FS_GAHBCFG register:
– Global interrupt mask bit GINTMSK = 1
– RxFIFO non-empty (RXFLVL bit in OTG_FS_GINTSTS)
– Periodic TxFIFO empty level
2. Program the following fields in the OTG_FS_GUSBCFG register:
– HNP capable bit
– SRP capable bit
– FS timeout calibration field
– USB turnaround time field
3. The software must unmask the following bits in the OTG_FS_GINTMSK register:
OTG interrupt mask
Mode mismatch interrupt mask
4. The software can read the CMOD bit in OTG_FS_GINTSTS to determine whether the
OTG_FS controller is operating in host or device mode.
register to determine the enumeration speed and perform the steps listed in Endpoint
initialization on enumeration completion on page 910.
At this point, the device is ready to accept SOF packets and perform control transfers on
control endpoint 0.
Halting a channel
The application can disable any channel by programming the OTG_FS_HCCHARx register
with the CHDIS and CHENA bits set to 1. This enables the OTG_FS host to flush the posted
requests (if any) and generates a channel halted interrupt. The application must wait for the
CHH interrupt in OTG_FS_HCINTx before reallocating the channel for other transactions.
The OTG_FS host does not interrupt the transaction that has already been started on the
USB.
Before disabling a channel, the application must ensure that there is at least one free space
available in the non-periodic request queue (when disabling a non-periodic channel) or the
periodic request queue (when disabling a periodic channel). The application can simply
flush the posted requests when the Request queue is full (before disabling the channel), by
programming the OTG_FS_HCCHARx register with the CHDIS bit set to 1, and the CHENA
bit cleared to 0.
The application is expected to disable a channel on any of the following conditions:
Operational model
The application must initialize a channel before communicating to the connected device.
This section explains the sequence of operation to be performed for different types of USB
transactions.
● Writing the transmit FIFO
The OTG_FS host automatically writes an entry (OUT request) to the periodic/non-
periodic request queue, along with the last Word write of a packet. The application must
ensure that at least one free space is available in the periodic/non-periodic request
queue before starting to write to the transmit FIFO. The application must always write to
the transmit FIFO in Words. If the packet size is non-Word aligned, the application must
use padding. The OTG_FS host determines the actual packet size based on the
programmed maximum packet size and transfer size.
Start
Read GNPTXSTS/HPTXFSIZ
registers for available FIFO
and queue spaces
Yes
Write 1 packet
data to
transmit FIFO
More packets
to send?
No
Start
No
RXFLVL
interrupt ?
Yes
PKTSTS
No
0b0010?
No
Yes
Yes
BCNT > 0?
ai15674
SETUP transaction operates in the same way but has only one packet. The
assumptions are:
– The application is attempting to send two maximum-packet-size packets (transfer
size = 1, 024 bytes).
– The non-periodic transmit FIFO can hold two packets (128 bytes for FS).
– The non-periodic request queue depth = 4.
● Normal bulk and control OUT/SETUP operations
The sequence of operations in (channel 1) is as follows:
a) Initialize channel 1
b) Write the first packet for channel 1
c) Along with the last Word write, the core writes an entry to the non-periodic request
queue
d) As soon as the non-periodic queue becomes non-empty, the core attempts to
send an OUT token in the current frame
e) Write the second (last) packet for channel 1
f) The core generates the XFRC interrupt as soon as the last transaction is
completed successfully
g) In response to the XFRC interrupt, de-allocate the channel for other transfers
h) Handling non-ACK responses
ch_2 D AT A0
MPS
3
AC K
set _ch_en
(ch _2) IN
4
D AT A0
5
RXFLVL interrupt
ACK
1 ch_1
read_rx_sts
read_rx_fifo
MPS
O UT
ch_2
set _ch_en
(ch _2) ch_2 D AT A1
MPS
ch_2
7 ACK
XFRC interrupt
6
De-allocate IN
(ch_1)
D AT A1
RXFLVL interrupt
1 6 ACK
read_rx_stsre
MPS
ad_rx_fifo
Disable
(ch _2) 9
RXFLVL interrupt
read_rx_sts 11 10
CHH interrupt
r
De-allocate 12
(ch _2) 13
ai15675
The channel-specific interrupt service routine for bulk and control OUT/SETUP
transactions is shown in the following code samples.
● Interrupt service routine for bulk/control OUT/SETUP and bulk/control IN
transactions
a) Bulk/Control OUT/SETUP
Unmask (NAK/TXERR/STALL/XFRC)
if (XFRC)
{
Reset Error Count
Mask ACK
De-allocate Channel
}
else if (STALL)
{
Transfer Done = 1
Unmask CHH
Disable Channel
}
else if (NAK or TXERR )
{
Rewind Buffer Pointers
Unmask CHH
Disable Channel
if (TXERR)
{
Increment Error Count
Unmask ACK
}
else
{
Reset Error Count
}
}
else if (CHH)
{
Mask CHH
if (Transfer Done or (Error_count == 3))
{
De-allocate Channel
}
else
{
Re-initialize Channel
}
}
else if (ACK)
{
Reset Error Count
Mask ACK
}
The application is expected to write the data packets into the transmit FIFO as and
when the space is available in the transmit FIFO and the Request queue. The
application can make use of the NPTXFE interrupt in OTG_FS_GINTSTS to find the
transmit FIFO space.
b) Bulk/Control IN
Unmask (TXERR/XFRC/BBERR/STALL/DTERR)
if (XFRC)
{
Reset Error Count
Unmask CHH
Disable Channel
ch_2 D AT A0
MPS
3
AC K
set _ch_en
(ch _2) IN
4
D AT A0
5
RXFLVL interrupt
ACK
1 ch_1
read_rx_sts
read_rx_fifo
MPS
O UT
ch_2
set _ch_en
(ch _2) ch_2 D AT A1
MPS
ch_2
7 ACK
XFRC interrupt
6
De-allocate IN
(ch_1)
D AT A1
RXFLVL interrupt
1 6 ACK
read_rx_stsre
MPS
ad_rx_fifo
Disable
(ch _2) 9
RXFLVL interrupt
read_rx_sts 11 10
CHH interrupt
r
De-allocate 12
(ch _2) 13
ai15675
f) The core generates the RXFLVL interrupt for the transfer completion status entry
in the receive FIFO.
g) The application must read and ignore the receive packet status when the receive
packet status is not an IN data packet (PKTSTS in GRXSTSR ≠ 0b0010).
h) The core generates the XFRC interrupt as soon as the receive packet status is
read.
i) In response to the XFRC interrupt, disable the channel and stop writing the
OTG_FS_HCCHAR2 register for further requests. The core writes a channel
disable request to the non-periodic request queue as soon as the
OTG_FS_HCCHAR2 register is written.
j) The core generates the RXFLVL interrupt as soon as the halt status is written to
the receive FIFO.
k) Read and ignore the receive packet status.
l) The core generates a CHH interrupt as soon as the halt status is popped from the
receive FIFO.
m) In response to the CHH interrupt, de-allocate the channel for other transfers.
n) Handling non-ACK responses
● Control transactions
Setup, Data, and Status stages of a control transfer must be performed as three
separate transfers. Setup-, Data- or Status-stage OUT transactions are performed
similarly to the bulk OUT transactions explained previously. Data- or Status-stage IN
transactions are performed similarly to the bulk IN transactions explained previously.
For all three stages, the application is expected to set the EPTYP field in
OTG_FS_HCCHAR1 to Control. During the Setup stage, the application is expected to
set the PID field in OTG_FS_HCTSIZ1 to SETUP.
● Interrupt OUT transactions
A typical interrupt OUT operation is shown in Figure 315. The assumptions are:
– The application is attempting to send one packet in every frame (up to 1 maximum
packet size), starting with the odd frame (transfer size = 1 024 bytes)
– The periodic transmit FIFO can hold one packet (1 KB)
– Periodic request queue depth = 4
The sequence of operations is as follows:
a) Initialize and enable channel 1. The application must set the ODDFRM bit in
OTG_FS_HCCHAR1.
b) Write the first packet for channel 1.
c) Along with the last Word write of each packet, the OTG_FS host writes an entry to
the periodic request queue.
d) The OTG_FS host attempts to send an OUT token in the next (odd) frame.
e) The OTG_FS host generates an XFRC interrupt as soon as the last packet is
transmitted successfully.
f) In response to the XFRC interrupt, reinitialize the channel for the next transfer.
OU T Odd
(micro)
DATA0
frame
M PS
5
6 XFRC interrupt ACK
init _reg(ch_1) 4 IN
write_tx_fifo
(ch_1) 1 5
MPS DATA0
RXFLVL interrupt
ACK
read_rx_sts
read_rx_fifo
1
6 MPS
RXFLVL interrupt
read_rx_sts ch_1
7 8
XFRC interrupt
ch_2
init_reg(ch _2)
9
set_ch_en
(ch_2)
Even
OU T (micro)
XFRC interrupt frame
DATA1
init _reg(ch_1)
MPS
write_tx_fifo 1
ACK
(ch_1) MPS
IN
DATA1
ai15676
Disable Channel
if (STALL)
{
Transfer Done = 1
}
}
else
if (NAK or TXERR)
{
Rewind Buffer Pointers
Reset Error Count
Mask ACK
Unmask CHH
Disable Channel
}
else
if (CHH)
{
Mask CHH
if (Transfer Done or (Error_count == 3))
{
De-allocate Channel
}
else
{
Re-initialize Channel (in next b_interval - 1 Frame)
}
}
else
if (ACK)
{
Reset Error Count
Mask ACK
}
The application uses the NPTXFE interrupt in OTG_FS_GINTSTS to find the transmit
FIFO space.
b) Interrupt IN
Unmask (NAK/TXERR/XFRC/BBERR/STALL/FRMOR/DTERR)
if (XFRC)
{
Reset Error Count
Mask ACK
if (OTG_FS_HCTSIZx.PKTCNT == 0)
{
De-allocate Channel
}
else
{
Transfer Done = 1
Unmask CHH
Disable Channel
}
}
else
if (STALL or FRMOR or NAK or DTERR or BBERR)
{
Mask ACK
Unmask CHH
Disable Channel
if (STALL or BBERR)
{
Reset Error Count
Transfer Done = 1
}
else
if (!FRMOR)
{
Reset Error Count
}
}
else
if (TXERR)
{
Increment Error Count
Unmask ACK
Unmask CHH
Disable Channel
}
else
if (CHH)
{
Mask CHH
if (Transfer Done or (Error_count == 3))
{
De-allocate Channel
}
else
Re-initialize Channel (in next b_interval - 1 /Frame)
}
}
else
if (ACK)
{
Reset Error Count
Mask ACK
}
● Interrupt IN transactions
The assumptions are:
– The application is attempting to receive one packet (up to 1 maximum packet size)
in every frame, starting with odd (transfer size = 1 024 bytes).
– The receive FIFO can hold at least one maximum-packet-size packet and two
status Words per packet (1 031 bytes).
– Periodic request queue depth = 4.
● Normal interrupt IN operation
The sequence of operations is as follows:
a) Initialize channel 2. The application must set the ODDFRM bit in
OTG_FS_HCCHAR2.
b) Set the CHENA bit in OTG_FS_HCCHAR2 to write an IN request to the periodic
request queue.
c) The OTG_FS host writes an IN request to the periodic request queue for each
OTG_FS_HCCHAR2 register write with the CHENA bit set.
d) The OTG_FS host attempts to send an IN token in the next (odd) frame.
e) As soon as the IN packet is received and written to the receive FIFO, the OTG_FS
host generates an RXFLVL interrupt.
f) In response to the RXFLVL interrupt, read the received packet status to determine
the number of bytes received, then read the receive FIFO accordingly. The
application must mask the RXFLVL interrupt before reading the receive FIFO, and
unmask after reading the entire packet.
g) The core generates the RXFLVL interrupt for the transfer completion status entry
in the receive FIFO. The application must read and ignore the receive packet
status when the receive packet status is not an IN data packet (PKTSTS in
GRXSTSR ≠ 0b0010).
h) The core generates an XFRC interrupt as soon as the receive packet status is
read.
i) In response to the XFRC interrupt, read the PKTCNT field in OTG_FS_HCTSIZ2.
If the PKTCNT bit in OTG_FS_HCTSIZ2 is not equal to 0, disable the channel
before re-initializing the channel for the next transfer, if any). If PKTCNT bit in
OTG_FS_HCTSIZ2 = 0, reinitialize the channel for the next transfer. This time, the
application must reset the ODDFRM bit in OTG_FS_HCCHAR2.
OU T Odd
(micro)
DATA0
frame
M PS
5
6 XFRC interrupt ACK
init _reg(ch_1) 4 IN
write_tx_fifo
(ch_1) 1 5
MPS DATA0
RXFLVL interrupt
ACK
read_rx_sts
read_rx_fifo
1
6 MPS
RXFLVL interrupt
read_rx_sts ch_1
7 8
XFRC interrupt
ch_2
init_reg(ch _2)
9
set_ch_en
(ch_2)
Even
OU T (micro)
XFRC interrupt frame
DATA1
init _reg(ch_1)
MPS
write_tx_fifo 1
ACK
(ch_1) MPS
IN
DATA1
ai15676
else
if (CHH)
{
Mask CHH
De-allocate Channel
}
Code sample: Isochronous IN
Unmask (TXERR/XFRC/FRMOR/BBERR)
if (XFRC or FRMOR)
{
if (XFRC and (OTG_FS_HCTSIZx.PKTCNT == 0))
{
Reset Error Count
De-allocate Channel
}
else
{
Unmask CHH
Disable Channel
}
}
else
if (TXERR or BBERR)
{
Increment Error Count
Unmask CHH
Disable Channel
}
else
if (CHH)
{
Mask CHH
if (Transfer Done or (Error_count == 3))
{
De-allocate Channel
}
else
{
Re-initialize Channel
}
}
● Isochronous IN transactions
The assumptions are:
– The application is attempting to receive one packet (up to 1 maximum packet size)
in every frame starting with the next odd frame (transfer size = 1 024 bytes).
– The receive FIFO can hold at least one maximum-packet-size packet and two
status Word per packet (1 031 bytes).
– Periodic request queue depth = 4.
The sequence of operations is as follows:
a) Initialize channel 2. The application must set the ODDFRM bit in
OTG_FS_HCCHAR2.
b) Set the CHENA bit in OTG_FS_HCCHAR2 to write an IN request to the periodic
request queue.
c) The OTG_FS host writes an IN request to the periodic request queue for each
OTG_FS_HCCHAR2 register write with the CHENA bit set.
d) The OTG_FS host attempts to send an IN token in the next odd frame.
e) As soon as the IN packet is received and written to the receive FIFO, the OTG_FS
host generates an RXFLVL interrupt.
f) In response to the RXFLVL interrupt, read the received packet status to determine
the number of bytes received, then read the receive FIFO accordingly. The
application must mask the RXFLVL interrupt before reading the receive FIFO, and
unmask it after reading the entire packet.
g) The core generates an RXFLVL interrupt for the transfer completion status entry in
the receive FIFO. This time, the application must read and ignore the receive
packet status when the receive packet status is not an IN data packet (PKTSTS bit
in OTG_FS_GRXSTSR ≠ 0b0010).
h) The core generates an XFRC interrupt as soon as the receive packet status is
read.
i) In response to the XFRC interrupt, read the PKTCNT field in OTG_FS_HCTSIZ2.
If PKTCNT≠ 0 in OTG_FS_HCTSIZ2, disable the channel before re-initializing the
channel for the next transfer, if any. If PKTCNT = 0 in OTG_FS_HCTSIZ2,
reinitialize the channel for the next transfer. This time, the application must reset
the ODDFRM bit in OTG_FS_HCCHAR2.
● Selecting the queue depth
Choose the periodic and non-periodic request queue depths carefully to match the
number of periodic/non-periodic endpoints accessed.
The non-periodic request queue depth affects the performance of non-periodic
transfers. The deeper the queue (along with sufficient FIFO size), the more often the
core is able to pipeline non-periodic transfers. If the queue size is small, the core is able
to put in new requests only when the queue space is freed up.
The core’s periodic request queue depth is critical to perform periodic transfers as
scheduled. Select the periodic queue depth, based on the number of periodic transfers
scheduled in a microframe. If the periodic request queue depth is smaller than the
periodic transfers scheduled in a microframe, a frame overrun condition occurs.
● Handling babble conditions
OTG_FS controller handles two cases of babble: packet babble and port babble.
Packet babble occurs if the device sends more data than the maximum packet size for
the channel. Port babble occurs if the core continues to receive data from the device at
EOF2 (the end of frame 2, which is very close to SOF).
When OTG_FS controller detects a packet babble, it stops writing data into the Rx
buffer and waits for the end of packet (EOP). When it detects an EOP, it flushes already
written data in the Rx buffer and generates a Babble interrupt to the application.
When OTG_FS controller detects a port babble, it flushes the RxFIFO and disables the
port. The core then generates a Port disabled interrupt (HPRTINT in
OTG_FS_GINTSTS, PENCHNG in OTG_FS_HPRT). On receiving this interrupt, the
application must determine that this is not due to an overcurrent condition (another
cause of the Port Disabled interrupt) by checking POCA in OTG_FS_HPRT, then
perform a soft reset. The core does not send any more tokens after it has detected a
port babble condition.
At this point, the device is ready to receive SOF packets and is configured to perform control
transfers on control endpoint 0.
Endpoint activation
This section describes the steps required to activate a device endpoint or to configure an
existing device endpoint to a new type.
1. Program the characteristics of the required endpoint into the following fields of the
OTG_FS_DIEPCTLx register (for IN or bidirectional endpoints) or the
OTG_FS_DOEPCTLx register (for OUT or bidirectional endpoints).
– Maximum packet size
– USB active endpoint = 1
– Endpoint start data toggle (for interrupt and bulk endpoints)
– Endpoint type
– TxFIFO number
2. Once the endpoint is activated, the core starts decoding the tokens addressed to that
endpoint and sends out a valid handshake for each valid token received for the
endpoint.
Endpoint deactivation
This section describes the steps required to deactivate an existing endpoint.
1. In the endpoint to be deactivated, clear the USB active endpoint bit in the
OTG_FS_DIEPCTLx register (for IN or bidirectional endpoints) or the
OTG_FS_DOEPCTLx register (for OUT or bidirectional endpoints).
2. Once the endpoint is deactivated, the core ignores tokens addressed to that endpoint,
which results in a timeout on the USB.
Note: 1 The application must meet the following conditions to set up the device core to handle traffic:
NPTXFEM and RXFLVLM in the OTG_FS_GINTMSK register must be cleared.
completed. After this entry is popped from the receive FIFO, the core asserts a
Transfer Completed interrupt on the specified OUT endpoint.
5. After the data payload is popped from the receive FIFO, the RXFLVL interrupt
(OTG_FS_GINTSTS) must be unmasked.
6. Steps 1–5 are repeated every time the application detects assertion of the interrupt line
due to RXFLVL in OTG_FS_GINTSTS. Reading an empty receive FIFO can result in
undefined core behavior.
Figure 317 provides a flowchart of the above procedure.
Y rd_data.BCNT = 0 rcv_out_pkt ()
word_cnt =
packet mem[0: word_cnt – 1] = BCNT[11:2]
C +
store in rd_rxfifo(rd_data.EPNUM, (BCNT[1] | BCNT[1])
memory word_cnt)
ai15677b
● SETUP transactions
This section describes how the core handles SETUP packets and the application’s
sequence for handling SETUP transactions.
● Application requirements
1. To receive a SETUP packet, the STUPCNT field (OTG_FS_DOEPTSIZx) in a control
OUT endpoint must be programmed to a non-zero value. When the application
programs the STUPCNT field to a non-zero value, the core receives SETUP packets
and writes them to the receive FIFO, irrespective of the NAK status and EPENA bit
setting in OTG_FS_DOEPCTLx. The STUPCNT field is decremented every time the
control endpoint receives a SETUP packet. If the STUPCNT field is not programmed to
a proper value before receiving a SETUP packet, the core still receives the SETUP
packet and decrements the STUPCNT field, but the application may not be able to
determine the correct number of SETUP packets received in the Setup stage of a
control transfer.
– STUPCNT = 3 in OTG_FS_DOEPTSIZx
2. The application must always allocate some extra space in the Receive data FIFO, to be
able to receive up to three SETUP packets on a control endpoint.
– The space to be reserved is 10 Words. Three Words are required for the first
SETUP packet, 1 Word is required for the Setup stage done Word and 6 Words
are required to store two extra SETUP packets among all control endpoints.
– 3 Words per SETUP packet are required to store 8 bytes of SETUP data and 4
bytes of SETUP status (Setup packet pattern). The core reserves this space in the
receive data.
– FIFO to write SETUP data only, and never uses this space for data packets.
3. The application must read the 2 Words of the SETUP packet from the receive FIFO.
4. The application must read and discard the Setup stage done Word from the receive
FIFO.
● Internal data flow
5. When a SETUP packet is received, the core writes the received data to the receive
FIFO, without checking for available space in the receive FIFO and irrespective of the
endpoint’s NAK and STALL bit settings.
– The core internally sets the IN NAK and OUT NAK bits for the control IN/OUT
endpoints on which the SETUP packet was received.
6. For every SETUP packet received on the USB, 3 Words of data are written to the
receive FIFO, and the STUPCNT field is decremented by 1.
– The first Word contains control information used internally by the core
– The second Word contains the first 4 bytes of the SETUP command
– The third Word contains the last 4 bytes of the SETUP command
7. When the Setup stage changes to a Data IN/OUT stage, the core writes an entry
(Setup stage done Word) to the receive FIFO, indicating the completion of the Setup
stage.
8. On the AHB side, SETUP packets are emptied by the application.
9. When the application pops the Setup stage done Word from the receive FIFO, the core
interrupts the application with an STUP interrupt (OTG_FS_DOEPINTx), indicating it
can process the received SETUP packet.
– The core clears the endpoint enable bit for control OUT endpoints.
● Application programming sequence
1. Program the OTG_FS_DOEPTSIZx register.
– STUPCNT = 3
2. Wait for the RXFLVL interrupt (OTG_FS_GINTSTS) and empty the data packets from
the receive FIFO.
3. Assertion of the STUP interrupt (OTG_FS_DOEPINTx) marks a successful completion
of the SETUP Data Transfer.
– On this interrupt, the application must read the OTG_FS_DOEPTSIZx register to
determine the number of SETUP packets received and process the last received
SETUP packet.
rem_supcnt =
rd_reg(DOEPTSIZx)
2-stage
ai15678
1. To stop receiving any kind of data in the receive FIFO, the application must set the
Global OUT NAK bit by programming the following field:
– SGONAK = 1 in OTG_FS_DCTL
2. Wait for the assertion of the GONAKEFF interrupt in OTG_FS_GINTSTS. When
asserted, this interrupt indicates that the core has stopped receiving any type of data
except SETUP packets.
3. The application can receive valid OUT packets after it has set SGONAK in
OTG_FS_DCTL and before the core asserts the GONAKEFF interrupt
(OTG_FS_GINTSTS).
4. The application can temporarily mask this interrupt by writing to the GINAKEFFM bit in
the OTG_FS_GINTMSK register.
– GINAKEFFM = 0 in the OTG_FS_GINTMSK register
5. Whenever the application is ready to exit the Global OUT NAK mode, it must clear the
SGONAK bit in OTG_FS_DCTL. This also clears the GONAKEFF interrupt
(OTG_FS_GINTSTS).
– OTG_FS_DCTL = 1 in CGONAK
6. If the application has masked this interrupt earlier, it must be unmasked as follows:
– GINAKEFFM = 1 in GINTMSK
● Disabling an OUT endpoint
The application must use this sequence to disable an OUT endpoint that it has enabled.
Application programming sequence:
1. Before disabling any OUT endpoint, the application must enable Global OUT NAK
mode in the core.
– SGONAK = 1 in OTG_FS_DCTL
2. Wait for the GONAKEFF interrupt (OTG_FS_GINTSTS)
3. Disable the required OUT endpoint by programming the following fields:
– EPDIS = 1 in OTG_FS_DOEPCTLx
– SNAK = 1 in OTG_FS_DOEPCTLx
4. Wait for the EPDISD interrupt (OTG_FS_DOEPINTx), which indicates that the OUT
endpoint is completely disabled. When the EPDISD interrupt is asserted, the core also
clears the following bits:
– EPDIS = 0 in OTG_FS_DOEPCTLx
– EPENA = 0 in OTG_FS_DOEPCTLx
5. The application must clear the Global OUT NAK bit to start receiving data from other
non-disabled OUT endpoints.
– SGONAK = 0 in OTG_FS_DCTL
● Generic non-isochronous OUT data transfers
This section describes a regular non-isochronous OUT data transfer (control, bulk, or
interrupt).
Application requirements:
1. Before setting up an OUT transfer, the application must allocate a buffer in the memory
to accommodate all data to be received as part of the OUT transfer.
2. For OUT transfers, the transfer size field in the endpoint’s transfer size register must be
a multiple of the maximum packet size of the endpoint, adjusted to the Word boundary.
– transfer size[EPNUM] = n × (MPSIZ[EPNUM] + 4 – (MPSIZ[EPNUM] mod 4))
– packet count[EPNUM] = n
– n>0
3. On any OUT endpoint interrupt, the application must read the endpoint’s transfer size
register to calculate the size of the payload in the memory. The received payload size
can be less than the programmed transfer size.
– Payload size in memory = application programmed initial transfer size – core
updated final transfer size
– Number of USB packets in which this payload was received = application
programmed initial packet count – core updated final packet count
Internal data flow:
1. The application must set the transfer size and packet count fields in the endpoint-
specific registers, clear the NAK bit, and enable the endpoint to receive the data.
2. Once the NAK bit is cleared, the core starts receiving data and writes it to the receive
FIFO, as long as there is space in the receive FIFO. For every data packet received on
the USB, the data packet and its status are written to the receive FIFO. Every packet
(maximum packet size or short packet) written to the receive FIFO decrements the
packet count field for that endpoint by 1.
– OUT data packets received with bad data CRC are flushed from the receive FIFO
automatically.
– After sending an ACK for the packet on the USB, the core discards non-
isochronous OUT data packets that the host, which cannot detect the ACK, re-
sends. The application does not detect multiple back-to-back data OUT packets
on the same endpoint with the same data PID. In this case the packet count is not
decremented.
– If there is no space in the receive FIFO, isochronous or non-isochronous data
packets are ignored and not written to the receive FIFO. Additionally, non-
isochronous OUT tokens receive a NAK handshake reply.
– In all the above three cases, the packet count is not decremented because no data
are written to the receive FIFO.
3. When the packet count becomes 0 or when a short packet is received on the endpoint,
the NAK bit for that endpoint is set. Once the NAK bit is set, the isochronous or non-
isochronous data packets are ignored and not written to the receive FIFO, and non-
isochronous OUT tokens receive a NAK handshake reply.
4. After the data are written to the receive FIFO, the application reads the data from the
receive FIFO and writes it to external memory, one packet at a time per endpoint.
5. At the end of every packet write on the AHB to external memory, the transfer size for
the endpoint is decremented by the size of the written packet.
6. The OUT data transfer completed pattern for an OUT endpoint is written to the receive
FIFO on one of the following conditions:
– The transfer size is 0 and the packet count is 0
– The last OUT data packet written to the receive FIFO is a short packet
(0 ≤ packet size < maximum packet size)
7. When either the application pops this entry (OUT data transfer completed), a transfer
completed interrupt is generated for the endpoint and the endpoint enable is cleared.
Application programming sequence:
1. Program the OTG_FS_DOEPTSIZx register for the transfer size and the corresponding
packet count.
2. Program the OTG_FS_DOEPCTLx register with the endpoint characteristics, and set
the EPENA and CNAK bits.
– EPENA = 1 in OTG_FS_DOEPCTLx
– CNAK = 1 in OTG_FS_DOEPCTLx
3. Wait for the RXFLVL interrupt (in OTG_FS_GINTSTS) and empty the data packets from
the receive FIFO.
– This step can be repeated many times, depending on the transfer size.
4. Asserting the XFRC interrupt (OTG_FS_DOEPINTx) marks a successful completion of
the non-isochronous OUT data transfer.
5. Read the OTG_FS_DOEPTSIZx register to determine the size of the received data
payload.
● Generic isochronous OUT data transfer
This section describes a regular isochronous OUT data transfer.
Application requirements:
1. All the application requirements for non-isochronous OUT data transfers also apply to
isochronous OUT data transfers.
2. For isochronous OUT data transfers, the transfer size and packet count fields must
always be set to the number of maximum-packet-size packets that can be received in a
single frame and no more. Isochronous OUT data transfers cannot span more than 1
frame.
3. The application must read all isochronous OUT data packets from the receive FIFO
(data and status) before the end of the periodic frame (EOPF interrupt in
OTG_FS_GINTSTS).
4. To receive data in the following frame, an isochronous OUT endpoint must be enabled
after the EOPF (OTG_FS_GINTSTS) and before the SOF (OTG_FS_GINTSTS).
Internal data flow:
1. The internal data flow for isochronous OUT endpoints is the same as that for non-
isochronous OUT endpoints, but for a few differences.
2. When an isochronous OUT endpoint is enabled by setting the Endpoint Enable and
clearing the NAK bits, the Even/Odd frame bit must also be set appropriately. The core
receives data on an isochronous OUT endpoint in a particular frame only if the
following condition is met:
– EONUM (in OTG_FS_DOEPCTLx) = SOFFN[0] (in OTG_FS_DSTS)
3. When the application completely reads an isochronous OUT data packet (data and
status) from the receive FIFO, the core updates the RXDPID field in
OTG_FS_DOEPTSIZx with the data PID of the last isochronous OUT data packet read
from the receive FIFO.
Application programming sequence:
1. Program the OTG_FS_DOEPTSIZx register for the transfer size and the corresponding
packet count
2. Program the OTG_FS_DOEPCTLx register with the endpoint characteristics and set
the Endpoint Enable, ClearNAK, and Even/Odd frame bits.
– EPENA = 1
– CNAK = 1
– EONUM = (0: Even/1: Odd)
3. Wait for the RXFLVL interrupt (in OTG_FS_GINTSTS) and empty the data packets from
the receive FIFO
– This step can be repeated many times, depending on the transfer size.
4. The assertion of the XFRC interrupt (in OTG_FS_DOEPINTx) marks the completion of
the isochronous OUT data transfer. This interrupt does not necessarily mean that the
data in memory are good.
5. This interrupt cannot always be detected for isochronous OUT transfers. Instead, the
application can detect the IISOOXFRM interrupt in OTG_FS_GINTSTS.
6. Read the OTG_FS_DOEPTSIZx register to determine the size of the received transfer
and to determine the validity of the data received in the frame. The application must
treat the data received in memory as valid only if one of the following conditions is met:
– RXDPID = D0 (in OTG_FS_DOEPTSIZx) and the number of USB packets in
which this payload was received = 1
– RXDPID = D1 (in OTG_FS_DOEPTSIZx) and the number of USB packets in
which this payload was received = 2
– RXDPID = D2 (in OTG_FS_DOEPTSIZx) and the number of USB packets in
which this payload was received = 3
The number of USB packets in which this payload was received =
Application programmed initial packet count – Core updated final packet count
The application can discard invalid data packets.
● Incomplete isochronous OUT data transfers
This section describes the application programming sequence when isochronous OUT data
packets are dropped inside the core.
Internal data flow:
1. For isochronous OUT endpoints, the XFRC interrupt (in OTG_FS_DOEPINTx) may not
always be asserted. If the core drops isochronous OUT data packets, the application
could fail to detect the XFRC interrupt (OTG_FS_DOEPINTx) under the following
circumstances:
– When the receive FIFO cannot accommodate the complete ISO OUT data packet,
the core drops the received ISO OUT data
– When the isochronous OUT data packet is received with CRC errors
– When the isochronous OUT token received by the core is corrupted
– When the application is very slow in reading the data from the receive FIFO
2. When the core detects an end of periodic frame before transfer completion to all
isochronous OUT endpoints, it asserts the incomplete Isochronous OUT data interrupt
Examples
This section describes and depicts some fundamental transfer types and scenarios.
● Bulk OUT transaction
Figure 319 depicts the reception of a single Bulk OUT Data packet from the USB to the AHB
and describes the events involved in the process.
init_ out_ ep
XFRSIZ = 64 bytes
1 PKTCNT = 1
2 wr_reg (DOEPTSIZx)
O UT EPENA= 1
CNAK = 1
3 wr_reg(D OEPCTLx)
64 bytes
4 6
xact _1
AC K RXFLVL iintr
D OE P C idle until intr
T L x.N A
5 PKTCN K =1
T0
XFRSIZ
r =0 rcv_out _pkt()
On new xfer
OU T XF or RxFIFO
int r RC not empty
7
NA K
idle until intr
8
ai15679b
IN data transfers
● Packet write
This section describes how the application writes data packets to the endpoint FIFO when
dedicated transmit FIFOs are enabled.
1. The application can either choose the polling or the interrupt mode.
– In polling mode, the application monitors the status of the endpoint transmit data
FIFO by reading the OTG_FS_DTXFSTSx register, to determine if there is enough
space in the data FIFO.
– In interrupt mode, the application waits for the TXFE interrupt (in
OTG_FS_DIEPINTx) and then reads the OTG_FS_DTXFSTSx register, to
determine if there is enough space in the data FIFO.
– To write a single non-zero length data packet, there must be space to write the
entire packet in the data FIFO.
– To write zero length packet, the application must not look at the FIFO space.
2. Using one of the above mentioned methods, when the application determines that
there is enough space to write a transmit packet, the application must first write into the
endpoint control register, before writing the data into the data FIFO. Typically, the
application, must do a read modify write on the OTG_FS_DIEPCTLx register to avoid
modifying the contents of the register, except for setting the Endpoint Enable bit.
The application can write multiple packets for the same endpoint into the transmit FIFO, if
space is available. For periodic IN endpoints, the application must write packets only for one
microframe. It can write packets for the next periodic transaction only after getting transfer
complete for the previous transaction.
● Setting IN endpoint NAK
Internal data flow:
1. When the application sets the IN NAK for a particular endpoint, the core stops
transmitting data on the endpoint, irrespective of data availability in the endpoint’s
transmit FIFO.
2. Non-isochronous IN tokens receive a NAK handshake reply
– Isochronous IN tokens receive a zero-data-length packet reply
3. The core asserts the INEPNE (IN endpoint NAK effective) interrupt in
OTG_FS_DIEPINTx in response to the SNAK bit in OTG_FS_DIEPCTLx.
4. Once this interrupt is seen by the application, the application can assume that the
endpoint is in IN NAK mode. This interrupt can be cleared by the application by setting
the CNAK bit in OTG_FS_DIEPCTLx.
Application programming sequence:
1. To stop transmitting any data on a particular IN endpoint, the application must set the
IN NAK bit. To set this bit, the following field must be programmed.
– SNAK = 1 in OTG_FS_DIEPCTLx
2. Wait for assertion of the INEPNE interrupt in OTG_FS_DIEPINTx. This interrupt
indicates that the core has stopped transmitting data on the endpoint.
3. The core can transmit valid IN data on the endpoint after the application has set the
NAK bit, but before the assertion of the NAK Effective interrupt.
4. The application can mask this interrupt temporarily by writing to the INEPNEM bit in
DIEPMSK.
– INEPNEM = 0 in DIEPMSK
5. To exit Endpoint NAK mode, the application must clear the NAK status bit (NAKSTS) in
OTG_FS_DIEPCTLx. This also clears the INEPNE interrupt (in OTG_FS_DIEPINTx).
– CNAK = 1 in OTG_FS_DIEPCTLx
6. If the application masked this interrupt earlier, it must be unmasked as follows:
– INEPNEM = 1 in DIEPMSK
● IN endpoint disable
Use the following sequence to disable a specific IN endpoint that has been previously
enabled.
Application programming sequence:
1. The application must stop writing data on the AHB for the IN endpoint to be disabled.
2. The application must set the endpoint in NAK mode.
– SNAK = 1 in OTG_FS_DIEPCTLx
3. Wait for the INEPNE interrupt in OTG_FS_DIEPINTx.
4. Set the following bits in the OTG_FS_DIEPCTLx register for the endpoint that must be
disabled.
– EPDIS = 1 in OTG_FS_DIEPCTLx
– SNAK = 1 in OTG_FS_DIEPCTLx
5. Assertion of the EPDISD interrupt in OTG_FS_DIEPINTx indicates that the core has
completely disabled the specified endpoint. Along with the assertion of the interrupt,
the core also clears the following bits:
– EPENA = 0 in OTG_FS_DIEPCTLx
– EPDIS = 0 in OTG_FS_DIEPCTLx
6. The application must read the OTG_FS_DIEPTSIZx register for the periodic IN EP, to
calculate how much data on the endpoint were transmitted on the USB.
7. The application must flush the data in the Endpoint transmit FIFO, by setting the
following fields in the OTG_FS_GRSTCTL register:
– TXFNUM (in OTG_FS_GRSTCTL) = Endpoint transmit FIFO number
– TXFFLSH in (OTG_FS_GRSTCTL) = 1
The application must poll the OTG_FS_GRSTCTL register, until the TXFFLSH bit is cleared
by the core, which indicates the end of flush operation. To transmit new data on this
endpoint, the application can re-enable the endpoint at a later point.
handshake, the packet count for the endpoint is decremented by one, until the packet
count is zero. The packet count is not decremented on a timeout.
5. For zero length packets (indicated by an internal zero length flag), the core sends out a
zero-length packet for the IN token and decrements the packet count field.
6. If there are no data in the FIFO for a received IN token and the packet count field for
that endpoint is zero, the core generates an “IN token received when TxFIFO is empty”
(ITTXFE) Interrupt for the endpoint, provided that the endpoint NAK bit is not set. The
core responds with a NAK handshake for non-isochronous endpoints on the USB.
7. The core internally rewinds the FIFO pointers and no timeout interrupt is generated.
8. When the transfer size is 0 and the packet count is 0, the transfer complete (XFRC)
interrupt for the endpoint is generated and the endpoint enable is cleared.
Application programming sequence:
1. Program the OTG_FS_DIEPTSIZx register with the transfer size and corresponding
packet count.
2. Program the OTG_FS_DIEPCTLx register with the endpoint characteristics and set the
CNAK and EPENA (Endpoint Enable) bits.
3. When transmitting non-zero length data packet, the application must poll the
OTG_FS_DTXFSTSx register (where x is the FIFO number associated with that
endpoint) to determine whether there is enough space in the data FIFO. The
application can optionally use TXFE (in OTG_FS_DIEPINTx) before writing the data.
● Generic periodic IN data transfers
This section describes a typical periodic IN data transfer.
Application requirements:
1. Application requirements 1, 2, 3, and 4 of Generic non-periodic IN data transfers on
page 924 also apply to periodic IN data transfers, except for a slight modification of
requirement 2.
– The application can only transmit multiples of maximum-packet-size data packets
or multiples of maximum-packet-size packets, plus a short packet at the end. To
transmit a few maximum-packet-size packets and a short packet at the end of the
transfer, the following conditions must be met:
transfer size[EPNUM] = x × MPSIZ[EPNUM] + sp
(where x is an integer ≥ 0, and 0 ≤ sp < MPSIZ[EPNUM])
If (sp > 0), packet count[EPNUM] = x + 1
Otherwise, packet count[EPNUM] = x;
MCNT[EPNUM] = packet count[EPNUM]
– The application cannot transmit a zero-length data packet at the end of a transfer.
It can transmit a single zero-length data packet by itself. To transmit a single zero-
length data packet:
– transfer size[EPNUM] = 0
packet count[EPNUM] = 1
MCNT[EPNUM] = packet count[EPNUM]
2. The application can only schedule data transfers one frame at a time.
– (MCNT – 1) × MPSIZ ≤ XFERSIZ ≤ MCNT × MPSIZ
– PKTCNT = MCNT (in OTG_FS_DIEPTSIZx)
– If XFERSIZ < MCNT × MPSIZ, the last data packet of the transfer is a short
packet.
– Note that: MCNT is in OTG_FS_DIEPTSIZx, MPSIZ is in OTG_FS_DIEPCTLx,
PKTCNT is in OTG_FS_DIEPTSIZx and XFERSIZ is in OTG_FS_DIEPTSIZx
3. The complete data to be transmitted in the frame must be written into the transmit FIFO
by the application, before the IN token is received. Even when 1 Word of the data to be
transmitted per frame is missing in the transmit FIFO when the IN token is received, the
core behaves as when the FIFO is empty. When the transmit FIFO is empty:
– A zero data length packet would be transmitted on the USB for isochronous IN
endpoints
– A NAK handshake would be transmitted on the USB for interrupt IN endpoints
Internal data flow:
1. The application must set the transfer size and packet count fields in the endpoint-
specific registers and enable the endpoint to transmit the data.
2. The application must also write the required data to the associated transmit FIFO for
the endpoint.
3. Every time the application writes a packet to the transmit FIFO, the transfer size for that
endpoint is decremented by the packet size. The data are fetched from application
memory until the transfer size for the endpoint becomes 0.
4. When an IN token is received for a periodic endpoint, the core transmits the data in the
FIFO, if available. If the complete data payload (complete packet, in dedicated FIFO
mode) for the frame is not present in the FIFO, then the core generates an IN token
received when TxFIFO empty interrupt for the endpoint.
– A zero-length data packet is transmitted on the USB for isochronous IN endpoints
– A NAK handshake is transmitted on the USB for interrupt IN endpoints
5. The packet count for the endpoint is decremented by 1 under the following conditions:
– For isochronous endpoints, when a zero- or non-zero-length data packet is
transmitted
– For interrupt endpoints, when an ACK handshake is transmitted
– When the transfer size and packet count are both 0, the transfer completed
interrupt for the endpoint is generated and the endpoint enable is cleared.
6. At the “Periodic frame Interval” (controlled by PFIVL in OTG_FS_DCFG), when the
core finds non-empty any of the isochronous IN endpoint FIFOs scheduled for the
current frame non-empty, the core generates an IISOIXFR interrupt in
OTG_FS_GINTSTS.
application receives this interrupt, it must set the STALL bit in the corresponding endpoint
control register, and clear this interrupt.
1 2 3 4 5 6 7 8
HCLK
PCLK
tkn_rcvd
dsynced_tkn_rcvd
spr_read
spr_addr A1
spr_rdata D1
srcbuf_push
srcbuf_rdata D1
5 Clocks
ai15680
Suspend 6
DRV_VBUS 1
2 5
VBUS_VALID
4 7
D+ 3 Data line pulsing Connect
D- Low
ai15681
B_VALID 2
DISCHRG_VBUS
4
SESS_END
5 8
DP
Data line pulsing Connect
DM
Low
7
VBUS pulsing
CHRG_VBUS
ai15682
discharge time can be obtained from the transceiver vendor and varies from one
transceiver to another.
3. The USB OTG core informs the PHY to speed up VBUS discharge.
4. The application initiates SRP by writing the session request bit in the OTG Control and
status register. The OTG_FS controller perform data-line pulsing followed by VBUS
pulsing.
5. The host detects SRP from either the data-line or VBUS pulsing, and turns on VBUS.
The PHY indicates VBUS power-on to the device.
6. The OTG_FS controller performs VBUS pulsing.
The host starts a new session by turning on VBUS, indicating SRP success. The
OTG_FS controller interrupts the application by setting the session request success
status change bit in the OTG interrupt status register. The application reads the session
request success bit in the OTG control and status register.
7. When the USB is powered, the OTG_FS controller connects, completing the SRP
process.
Suspend 2 4 5 6 8
DM Traffic
DPPULLDOWN
DMPULLDOWN
ai15683
1. DPPULLDOWN = signal from core to PHY to enable/disable the pull-down on the DP line inside the PHY.
DMPULLDOWN = signal from core to PHY to enable/disable the pull-down on the DM line inside the PHY.
1. The OTG_FS controller sends the B-device a SetFeature b_hnp_enable descriptor to
enable HNP support. The B-device’s ACK response indicates that the B-device
supports HNP. The application must set host Set HNP Enable bit in the OTG Control
and status register to indicate to the OTG_FS controller that the B-device supports
HNP.
2. When it has finished using the bus, the application suspends by writing the Port
suspend bit in the host port control and status register.
3. When the B-device observes a USB suspend, it disconnects, indicating the initial
condition for HNP. The B-device initiates HNP only when it must switch to the host role;
otherwise, the bus continues to be suspended.
The OTG_FS controller sets the host negotiation detected interrupt in the OTG
interrupt status register, indicating the start of HNP.
The OTG_FS controller deasserts the DM pull down and DM pull down in the PHY to
indicate a device role. The PHY enables the OTG_FS_DP pull-up resistor to indicate a
connect for B-device.
The application must read the current mode bit in the OTG Control and status register
to determine device mode operation.
4. The B-device detects the connection, issues a USB reset, and enumerates the
OTG_FS controller for data traffic.
5. The B-device continues the host role, initiating traffic, and suspends the bus when
done.
The OTG_FS controller sets the early suspend bit in the Core interrupt register after 3
ms of bus idleness. Following this, the OTG_FS controller sets the USB Suspend bit in
the Core interrupt register.
6. In Negotiated mode, the OTG_FS controller detects the suspend, disconnects, and
switches back to the host role. The OTG_FS controller asserts the DM pull down and
DM pull down in the PHY to indicate its assumption of the host role.
7. The OTG_FS controller sets the Connector ID status change interrupt in the OTG
Interrupt Status register. The application must read the connector ID status in the OTG
Control and Status register to determine the OTG_FS controller operation as an A-
device. This indicates the completion of HNP to the application. The application must
read the Current mode bit in the OTG control and status register to determine host
mode operation.
8. The B-device connects, completing the HNP process.
Suspend 2 4 5 6 8
DM Traffic
DPPULLDOWN
DMPULLDOWN
ai15684
1. DPPULLDOWN = signal from core to PHY to enable/disable the pull-down on the DP line inside the PHY.
DMPULLDOWN = signal from core to PHY to enable/disable the pull-down on the DM line inside the PHY.
1. The A-device sends the SetFeature b_hnp_enable descriptor to enable HNP support.
The OTG_FS controller’s ACK response indicates that it supports HNP. The application
must set the device HNP enable bit in the OTG Control and status register to indicate
HNP support.
The application sets the HNP request bit in the OTG Control and status register to
indicate to the OTG_FS controller to initiate HNP.
2. When it has finished using the bus, the A-device suspends by writing the Port suspend
bit in the host port control and status register.
The OTG_FS controller sets the Early suspend bit in the Core interrupt register after 3
ms of bus idleness. Following this, the OTG_FS controller sets the USB suspend bit in
the Core interrupt register.
The OTG_FS controller disconnects and the A-device detects SE0 on the bus,
indicating HNP. The OTG_FS controller asserts the DP pull down and DM pull down in
the PHY to indicate its assumption of the host role.
The A-device responds by activating its OTG_FS_DP pull-up resistor within 3 ms of
detecting SE0. The OTG_FS controller detects this as a connect.
The OTG_FS controller sets the host negotiation success status change interrupt in the
OTG Interrupt status register, indicating the HNP status. The application must read the
host negotiation success bit in the OTG Control and status register to determine host
negotiation success. The application must read the current Mode bit in the Core
interrupt register (OTG_FS_GINTSTS) to determine host mode operation.
3. The application sets the reset bit (PRST in OTG_FS_HPRT) and the OTG_FS
controller issues a USB reset and enumerates the A-device for data traffic.
4. The OTG_FS controller continues the host role of initiating traffic, and when done,
suspends the bus by writing the Port suspend bit in the host port control and status
register.
5. In Negotiated mode, when the A-device detects a suspend, it disconnects and switches
back to the host role. The OTG_FS controller deasserts the DP pull down and DM pull
down in the PHY to indicate the assumption of the device role.
6. The application must read the current mode bit in the Core interrupt
(OTG_FS_GINTSTS) register to determine the host mode operation.
7. The OTG_FS controller connects, completing the HNP process.
● Option to filter all error frames on reception and not forward them to the application in
Store-and-Forward mode
● Option to forward under-sized good frames
● Supports statistics by generating pulses for frames dropped or corrupted (due to
overflow) in the Receive FIFO
● Supports Store and Forward mechanism for transmission to the MAC core
● Automatic generation of PAUSE frame control or back pressure signal to the MAC core
based on Receive FIFO-fill (threshold configurable) level
● Handles automatic retransmission of Collision frames for transmission
● Discards frames on late collision, excessive collisions, excessive deferral and underrun
conditions
● Software control to flush Tx FIFO
● Calculates and inserts IPv4 header checksum and TCP, UDP, or ICMP checksum in
frames transmitted in Store-and-Forward mode
● Supports internal loopback on the MII for debugging
+BYTE
#HECKSUM 040 -$#
"US MATRIX
28 &)&/
OFFLOAD )%%%
%THERNET
$-!
+BYTE -$)/
48 &)&/ 0-4 --#
AIC
The application can select one of the 32 PHYs and one of the 32 registers within any PHY
and send control data or receive status information. Only one register in one PHY can be
addressed at any given time.
Both the MDC clock line and the MDIO data line are implemented as alternate function I/O
in the microcontroller:
● MDC: a periodic clock that provides the timing reference for the data transfer at the
maximum frequency of 2.5 MHz. The minimum high and low times for MDC must be
160 ns each, and the minimum period for MDC must be 400 ns. In idle state the SMI
management interface drives the MDC clock signal low.
● MDIO: data input/output bitstream to transfer status information to/from the PHY device
synchronously with the MDC clock signal
STM32
802.3 MAC
MDC
External
MDIO PHY
ai15621
Preamble
Start Operation PADDR RADDR TA Data (16 bits) Idle
(32 bits)
drives high-impedance on the MDIO line for the 2 bits of TA. The PHY device must
drive a high-impedance state on the first bit of TA, a zero bit on the second one.
For a write transaction, the MAC controller drives a <10> pattern during the TA field.
The PHY device must drive a high-impedance state for the 2 bits of TA.
● Data: the data field is 16-bit. The first bit transmitted and received must be bit 15 of the
ETH_MIID register.
● Idle: the MDIO line is driven in high-impedance state. All three-state drivers must be
disabled and the PHY’s pull-up resistor keeps the line at logic one.
MDC
Start
Preamble of OP PHY address Register address Turn data
code around
frame
MDC
Start
Preamble of OP PHY address Register address Turn data
code around
frame
48?#,+
34- 48$;=
48?%.
28?#,+
-!#
28$;=
28?%2 %XTERNAL
28?$6 0(9
#23
#/,
-$#
-$)/
AIB
● MII_TX_CLK: continuous clock that provides the timing reference for the TX data
transfer. The nominal frequency is: 2.5 MHz at 10 Mbit/s speed; 25 MHz at 100 Mbit/s
speed.
● MII_RX_CLK: continuous clock that provides the timing reference for the RX data
transfer. The nominal frequency is: 2.5 MHz at 10 Mbit/s speed; 25 MHz at 100 Mbit/s
speed.
● MII_TX_EN: transmission enable indicates that the MAC is presenting nibbles on the
MII for transmission. It must be asserted synchronously (MII_TX_CLK) with the first
nibble of the preamble and must remain asserted while all nibbles to be transmitted are
presented to the MII.
● MII_TXD[3:0]: transmit data is a bundle of 4 data signals driven synchronously by the
MAC sublayer and qualified (valid data) on the assertion of the MII_TX_EN signal.
MII_TXD[0] is the least significant bit, MII_TXD[3] is the most significant bit. While
MII_TX_EN is deasserted the transmit data must have no effect upon the PHY.
● MII_CRS: carrier sense is asserted by the PHY when either the transmit or receive
medium is non idle. It shall be deasserted by the PHY when both the transmit and
receive media are idle. The PHY must ensure that the MII_CS signal remains asserted
throughout the duration of a collision condition. This signal is not required to transition
synchronously with respect to the TX and RX clocks. In full duplex mode the state of
this signal is don’t care for the MAC sublayer.
● MII_COL: collision detection must be asserted by the PHY upon detection of a collision
on the medium and must remain asserted while the collision condition persists. This
signal is not required to transition synchronously with respect to the TX and RX clocks.
In full duplex mode the state of this signal is don’t care for the MAC sublayer.
● MII_RXD[3:0]: reception data is a bundle of 4 data signals driven synchronously by the
PHY and qualified (valid data) on the assertion of the MII_RX_DV signal. MII_RXD[0] is
the least significant bit, MII_RXD[3] is the most significant bit. While MII_RX_EN is
deasserted and MII_RX_ER is asserted, a specific MII_RXD[3:0] value is used to
transfer specific information from the PHY (see Table 210).
● MII_RX_DV: receive data valid indicates that the PHY is presenting recovered and
decoded nibbles on the MII for reception. It must be asserted synchronously
(MII_RX_CLK) with the first recovered nibble of the frame and must remain asserted
through the final recovered nibble. It must be deasserted prior to the first clock cycle
that follows the final nibble. In order to receive the frame correctly, the MII_RX_DV
signal must encompass the frame, starting no later than the SFD field.
● MII_RX_ER: receive error must be asserted for one or more clock periods
(MII_RX_CLK) to indicate to the MAC sublayer that an error was detected somewhere
in the frame. This error condition must be qualified by MII_RX_DV assertion as
described in Table 210.
STM32
802.3 MAC
TX _CLK
External
PHY
25 MHz
RX _CLK
HSE
MCO
25 MHz
ai15623
STM32 TXD[1:0]
TX_EN
802.3 MAC
RXD[1:0]
External
CRS_DV PHY
MDC
MDIO
REF_CLK
Clock source
ai15624
STM32
802.3 MAC
External
PHY
25 MHz
PLL
REF_CLK
MCO
50 MHz
ai15625
MAC
0 MII
50 MHz Sync. divider
/2 for 100 Mb/s 1 RMII(1)
/20 for 10 Mb/s
MII_RX_CLK as AF 0 25 MHz MACRXCLK AHB
(25 MHz or 2.5 MHz) GPIO and AF 25 MHz or 2.5 MHz RX
1 or 2.5 MHz
controller
RMII_REF_CK as AF
(50 MHz)
RMII
HCLK HCLK
must be greater
than 25 MHz
ai15650
1. The MII/RMII selection is controlled through bit 23, MII_RMII_SEL, in the AFIO_MAPR register.
To save a pin, the two input clock signals, RMII_REF_CK and MII_RX_CLK, are multiplexed
on the same GPIO pin.
Figure 335 and Figure 336 describe the frame structure (untagged and tagged) that
includes the following fields:
● Preamble: 7-byte field used for synchronization purposes (PLS circuitry)
Hexadecimal value: 55-55-55-55-55-55-55
Bit pattern: 01010101 01010101 01010101 01010101 01010101 01010101 01010101
(right-to-left bit transmission)
● Start frame delimiter (SFD): 1-byte field used to indicate the start of a frame.
Hexadecimal value: D5
Bit pattern: 11010101 (right-to-left bit transmission)
● Destination and Source Address fields: 6-byte fields to indicate the destination and
source station addresses as follows (see Figure 334):
– Each address is 48 bits in length
– The first LSB bit (I/G) in the destination address field is used to indicate an
individual (I/G = 0) or a group address (I/G = 1). A group address could identify
none, one or more, or all the stations connected to the LAN. In the source address
the first bit is reserved and reset to 0.
– The second bit (U/L) distinguishes between locally (U/L = 1) or globally (U/L = 0)
administered addresses. For broadcast addresses this bit is also 1.
– Each byte of each address field must be transmitted least significant bit first.
The address designation is based on the following types:
● Individual address: this is the physical address associated with a particular station on
the network.
● Group address. A multidestination address associated with one or more stations on a
given network. There are two kinds of multicast address:
– Multicast-group address: an address associated with a group of logically related
stations.
– Broadcast address: a distinguished, predefined multicast address (all 1’s in the
destination address field) that always denotes all the stations on a given LAN.
● QTag Prefix: 4-byte field inserted between the Source address field and the MAC Client
Length/Type field. This field is an extension of the basic frame (untagged) to obtain the
tagged MAC frame. The untagged MAC frames do not include this field. The extensions
for tagging are as follows:
– 2-byte constant Length/Type field value consistent with the Type interpretation
(greater than 0x0600) equal to the value of the 802.1Q Tag Protocol Type (0x8100
hexadecimal). This constant field is used to distinguish tagged and untagged MAC
frames.
– 2-byte field containing the Tag control information field subdivided as follows: a 3-
bit user priority, a canonical format indicator (CFI) bit and a 12-bit VLAN Identifier.
The length of the tagged MAC frame is extended by 4 bytes by the QTag Prefix.
● MAC client length/type: 2-byte field with different meaning (mutually exclusive),
depending on its value:
– If the value is less than or equal to maxValidFrame (0d1500) then this field
indicates the number of MAC client data bytes contained in the subsequent data
field of the 802.3 frame (length interpretation).
– If the value is greater than or equal to MinTypeValue (0d1536 decimal, 0x0600)
then this field indicates the nature of the MAC client protocol (Type interpretation)
related to the Ethernet frame.
Regardless of the interpretation of the length/type field, if the length of the data field is
less than the minimum required for proper operation of the protocol, a PAD field is
added after the data field but prior to the FCS (frame check sequence) field. The
length/type field is transmitted and received with the higher-order byte first.
For length/type field values in the range between maxValidLength and minTypeValue
(boundaries excluded), the behavior of the MAC sublayer is not specified: they may or
may not be passed by the MAC sublayer.
● Data and PAD fields: n-byte data field. Full data transparency is provided, it means that
any arbitrary sequence of byte values may appear in the data field. The size of the PAD,
if any, is determined by the size of the data field. Max and min length of the data and
PAD field are:
– Maximum length = 1500 bytes
– Minimum length for untagged MAC frames = 46 bytes
– Minimum length for tagged MAC frames = 42 bytes
When the data field length is less than the minimum required, the PAD field is added to
match the minimum length (42 bytes for tagged frames, 46 bytes for untagged frames).
● Frame check sequence: 4-byte field that contains the cyclic redundancy check (CRC)
value. The CRC computation is based on the following fields: source address,
destination address, QTag prefix, length/type, LLC data and PAD (that is, all fields
except the preamble, SFD). The generating polynomial is the following:
32 26 23 22 16 12 11 10 8 7 5 4 2
G( x) = x +x +x +x +x +x +x +x +x +x +x +x +x +x+1
7 bytes Preamble
1 byte SFD
MSB LSB
MSB LSB
Bit transmission order (r ight to left)
ai15630
Each byte of the MAC frame, except the FCS field, is transmitted low-order bit first.
An invalid MAC frame is defined by one of the following conditions:
● The frame length is inconsistent with the expected value as specified by the length/type
field. If the length/type field contains a type value, then the frame length is assumed to
be consistent with this field (no invalid frame)
● The frame length is not an integer number of bytes (extra bits)
● The CRC value computed on the incoming frame does not match the included FCS
The CRC generator calculates the 32-bit CRC for the FCS field of the Ethernet frame. The
encoding is defined by the following polynomial.
32 26 23 22 16 12 11 10 8 7 5 4 2
G( x) = x +x +x +x +x +x +x +x +x +x +x +x +x +x+1
Transmit protocol
The MAC controls the operation of Ethernet frame transmission. It performs the following
functions to meet the IEEE 802.3/802.3z specifications. It:
● generates the preamble and SFD
● generates the jam pattern in Half-duplex mode
● controls the Jabber timeout
● controls the flow for Half-duplex mode (back pressure)
● generates the transmit frame status
● contains time stamp snapshot logic in accordance with IEEE 1588
When a new frame transmission is requested, the MAC sends out the preamble and SFD,
followed by the data. The preamble is defined as 7 bytes of 0b10101010 pattern, and the
SFD is defined as 1 byte of 0b10101011 pattern. The collision window is defined as 1 slot
time (512 bit times for 10/100 Mbit/s Ethernet). The jam pattern generation is applicable only
to Half-duplex mode, not to Full-duplex mode.
In MII mode, if a collision occurs at any time from the beginning of the frame to the end of
the CRC field, the MAC sends a 32-bit jam pattern of 0x5555 5555 on the MII to inform all
other stations that a collision has occurred. If the collision is seen during the preamble
transmission phase, the MAC completes the transmission of the preamble and SFD and
then sends the jam pattern.
A jabber timer is maintained to cut off the transmission of Ethernet frames if more than 2048
(default) bytes have to be transferred. The MAC uses the deferral mechanism for flow
control (back pressure) in Half-duplex mode. When the application requests to stop
receiving frames, the MAC sends a JAM pattern of 32 bytes whenever it senses the
reception of a frame, provided that transmit flow control is enabled. This results in a collision
and the remote station backs off. The application requests flow control by setting the BPA bit
(bit 0) in the ETH_MACFCR register. If the application requests a frame to be transmitted,
then it is scheduled and transmitted even when back pressure is activated. Note that if back
pressure is kept activated for a long time (and more than 16 consecutive collision events
occur) then the remote stations abort their transmissions due to excessive collisions. If IEEE
1588 time stamping is enabled for the transmit frame, this block takes a snapshot of the
system time when the SFD is put onto the transmit MII bus.
Transmit scheduler
The MAC is responsible for scheduling the frame transmission on the MII. It maintains the
interframe gap between two transmitted frames and follows the truncated binary exponential
backoff algorithm for Half-duplex mode. The MAC enables transmission after satisfying the
IFG and backoff delays. It maintains an idle period of the configured interframe gap (IFG bits
in the ETH_MACCR register) between any two transmitted frames. If frames to be
transmitted arrive sooner than the configured IFG time, the MII waits for the enable signal
from the MAC before starting the transmission on it. The MAC starts its IFG counter as soon
as the carrier signal of the MII goes inactive. At the end of the programmed IFG value, the
MAC enables transmission in Full-duplex mode. In Half-duplex mode and when IFG is
configured for 96 bit times, the MAC follows the rule of deference specified in Section
4.2.3.2.1 of the IEEE 802.3 specification. The MAC resets its IFG counter if a carrier is
detected during the first two-thirds (64-bit times for all IFG values) of the IFG interval. If the
carrier is detected during the final one third of the IFG interval, the MAC continues the IFG
count and enables the transmitter after the IFG interval. The MAC implements the truncated
binary exponential backoff algorithm when it operates in Half-duplex mode.
frame is being transmitted. As soon as the first frame has been transferred and the
status is received from the MAC, it is pushed to the DMA. If the DMA has already
completed sending the second packet to the FIFO, the second transmission must wait
for the status of the first packet before proceeding to the next frame.
2 You must make sure the Transmit FIFO is deep enough to store a complete frame before
that frame is transferred to the MAC Core transmitter. If the FIFO depth is less than the input
Ethernet frame size, the payload (TCP/UDP/ICMP) checksum insertion function is bypassed
and only the frame’s IPv4 Header checksum is modified, even in Store-and-forward mode.
The transmit checksum offload supports two types of checksum calculation and insertion.
This checksum can be controlled for each frame by setting the CIC bits (Bits 28:27 in
TDES1, described in TDES1: Transmit descriptor Word1 on page 989).
See IETF specifications RFC 791, RFC 793, RFC 768, RFC 792, RFC 2460 and RFC 4443
for IPv4, TCP, UDP, ICMP, IPv6 and ICMPv6 packet header specifications, respectively.
● IP header checksum
In IPv4 datagrams, the integrity of the header fields is indicated by the 16-bit header
checksum field (the eleventh and twelfth bytes of the IPv4 datagram). The checksum
offload detects an IPv4 datagram when the Ethernet frame’s Type field has the value
0x0800 and the IP datagram’s Version field has the value 0x4. The input frame’s
checksum field is ignored during calculation and replaced by the calculated value. IPv6
headers do not have a checksum field; thus, the checksum offload does not modify
IPv6 header fields. The result of this IP header checksum calculation is indicated by the
IP Header Error status bit in the Transmit status (Bit 16). This status bit is set whenever
the values of the Ethernet Type field and the IP header’s Version field are not
consistent, or when the Ethernet frame does not have enough data, as indicated by the
IP header Length field. In other words, this bit is set when an IP header error is
asserted under the following circumstances:
a) For IPv4 datagrams:
– The received Ethernet type is 0x0800, but the IP header’s Version field does not
equal 0x4
– The IPv4 Header Length field indicates a value less than 0x5 (20 bytes)
– The total frame length is less than the value given in the IPv4 Header Length field
b) For IPv6 datagrams:
– The Ethernet type is 0x86DD but the IP header Version field does not equal 0x6
– The frame ends before the IPv6 header (40 bytes) or extension header (as given
in the corresponding Header Length field in an extension header) has been
completely received. Even when the checksum offload detects such an IP header
error, it inserts an IPv4 header checksum if the Ethernet Type field indicates an
IPv4 payload.
● TCP/UDP/ICMP checksum
The TCP/UDP/ICMP checksum processes the IPv4 or IPv6 header (including
extension headers) and determines whether the encapsulated payload is TCP, UDP or
ICMP.
Note that:
a) For non-TCP, -UDP, or -ICMP/ICMPv6 payloads, this checksum is bypassed and
nothing further is modified in the frame.
b) Fragmented IP frames (IPv4 or IPv6), IP frames with security features (such as an
authentication header or encapsulated security payload), and IPv6 frames with
routing headers are bypassed and not processed by the checksum.
The checksum is calculated for the TCP, UDP, or ICMP payload and inserted into its
corresponding field in the header. It can work in the following two modes:
– In the first mode, the TCP, UDP, or ICMPv6 pseudo-header is not included in the
checksum calculation and is assumed to be present in the input frame’s checksum
field. The checksum field is included in the checksum calculation, and then
replaced by the final calculated checksum.
– In the second mode, the checksum field is ignored, the TCP, UDP, or ICMPv6
pseudo-header data are included into the checksum calculation, and the
checksum field is overwritten with the final calculated value.
Note that: for ICMP-over-IPv4 packets, the checksum field in the ICMP packet must
always be 0x0000 in both modes, because pseudo-headers are not defined for such
packets. If it does not equal 0x0000, an incorrect checksum may be inserted into the
packet.
The result of this operation is indicated by the payload checksum error status bit in the
Transmit Status vector (bit 12). The payload checksum error status bit is set when
either of the following is detected:
– the frame has been forwarded to the MAC transmitter in Store-and-forward mode
without the end of frame being written to the FIFO
– the packet ends before the number of bytes indicated by the payload length field in
the IP header is received.
When the packet is longer than the indicated payload length, the bytes are ignored as
stuff bytes, and no error is reported. When the first type of error is detected, the TCP,
UDP or ICMP header is not modified. For the second error type, still, the calculated
checksum is inserted into the corresponding header field.
LSB MSB
D0 D1 Bibit stream
LSB D0
D1
MII_TXD[3:0]
D2
MSB D3
MII_TX_CLK
MII_TX_EN
MII_TXD[3:0] PR EA MB LE
MII_CS
MII_COL
Low
ai15631
MII_TX_CLK
MII_TX_EN
MII_CS
MII_COL
ai15651
MII_RX_CLK
MII_TX_EN
MII_TXD[3:0]
RMII_REF_CLK
RMII_TX_EN
RMII_TXD[1:0]
ai15652
Receive protocol
The received frame preamble and SFD are stripped. Once the SFD has been detected, the
MAC starts sending the Ethernet frame data to the receive FIFO, beginning with the first
byte following the SFD (destination address). If IEEE 1588 time stamping is enabled, a
snapshot of the system time is taken when any frame's SFD is detected on the MII. Unless
the MAC filters out and drops the frame, this time stamp is passed on to the application.
If the received frame length/type field is less than 0x600 and if the MAC is programmed for
the auto CRC/pad stripping option, the MAC sends the data of the frame to RxFIFO up to
the count specified in the length/type field, then starts dropping bytes (including the FCS
field). If the Length/Type field is greater than or equal to 0x600, the MAC sends all received
Ethernet frame data to Rx FIFO, regardless of the value on the programmed auto-CRC strip
option. The MAC watchdog timer is enabled by default, that is, frames above 2048 bytes (DA
+ SA + LT + Data + pad + FCS) are cut off. This feature can be disabled by programming the
watchdog disable (WD) bit in the MAC configuration register. However, even if the watchdog
timer is disabled, frames greater than 16 KB in size are cut off and a watchdog timeout
status is given.
32 26 23 22 16 12 11 10 8 7 5 4 2
G( x) = x +x +x +x +x +x +x +x +x +x +x +x +x +x+1
Regardless of the auto-pad/CRC strip, the MAC receives the entire frame to compute the
CRC check for the received frame.
Meanwhile, if another Pause frame is detected with a zero Pause time value, the MAC
resets the Pause time and manages this new pause request.
If the received control frame matches neither the type field (0x8808), the opcode (0x00001),
nor the byte length (64 bytes), or if there is a CRC error, the MAC does not generate a
Pause.
In the case of a pause frame with a multicast destination address, the MAC filters the frame
based on the address match.
For a pause frame with a unicast destination address, the MAC filtering depends on whether
the DA matched the contents of the MAC address 0 register and whether the UPDF bit in
ETH_MACFCR is set (detecting a pause frame even with a unicast destination address).
The PCF register bits (bits [7:6] in ETH_MACFFR) control filtering for control frames in
addition to address filtering.
Error handling
If the Rx FIFO is full before it receives the EOF data from the MAC, an overflow is declared
and the whole frame is dropped, and the overflow counter in the (ETH_DMAMFBOCR
register) is incremented. The status indicates a partial frame due to overflow. The Rx FIFO
can filter error and undersized frames, if enabled (using the FEF and FUGF bits in
ETH_DMAOMR).
If the Receive FIFO is configured to operate in Store-and-forward mode, all error frames can
be filtered and dropped.
In Cut-through mode, if a frame's status and length are available when that frame's SOF is
read from the Rx FIFO, then the complete erroneous frame can be dropped. The DMA can
flush the error frame being read from the FIFO, by enabling the receive frame flash bit. The
data transfer to the application (DMA) is then stopped and the rest of the frame is internally
read and dropped. The next frame transfer can then be started, if available.
RMII_RXD[1:0]
LSB MSB
D0 D1 Di-bit stream
LSB D0
D1
MII_RXD[3:0]
D2
MSB D3
MII_RX_CLK
MII_RX_DV
MII_RX_ERR
ai15634
MII_RX_CLK
MII_RX_DV
MII_RX_ERR
ai15635
MII_RX_CLK
MII_RX_DV
MII_RXD[3:0] XX XX XX XX 0E XX XX XX XX
MII_RX_ERR
ai15636
TSTS
TSTI
AND
TSTIM
Interrupt
OR
PMTS
PMTI
AND
PMTIM
ai15637
1 X X X X X X Pass
Broadcast 0 X X X X X 0 Pass
0 X X X X X 1 Fail
1 X X X X X X Pass all frames
0 X 0 0 X X X Pass on perfect/group filter match
0 X 0 1 X X X Fail on perfect/Group filter match
0 0 1 0 X X X Pass on hash filter match
Unicast
0 0 1 1 X X X Fail on hash filter match
Pass on hash or perfect/Group filter
0 1 1 0 X X X
match
0 1 1 1 X X X Fail on hash or perfect/Group filter match
Section 29.8: Ethernet register descriptions describes the various counters and lists the
addresses of each of the statistics counters. This address is used for read/write accesses to
the desired transmit/receive counter.
The Receive MMC counters are updated for frames that pass address filtering. Dropped
frames statistics are not updated unless the dropped frames are runt frames of less than 6
bytes (DA bytes are not received fully).
wakeup frame filter register to reach the last register. Each read/write points the wakeup
frame filter register to the next filter register.
Wakeup frame filter reg5 Filter 3 Offset Filter 2 Offset Filter 1 Offset Filter 0 Offset
ai15647
Mask determines which bytes of the frame must be examined. The thirty-first bit of Byte
Mask must be set to zero. The wakeup frame is checked only for length error, FCS error,
dribble bit error, MII error, collision, and to ensure that it is not a runt frame. Even if the
wakeup frame is more than 512 bytes long, if the frame has a valid CRC value, it is
considered valid. Wakeup frame detection is updated in the ETH_MACPMTCSR register for
every remote wakeup frame received. If enabled, a PMT interrupt is generated to indicate
the reception of a remote wakeup frame.
1. Disable the transmit DMA and wait for any previous frame transmissions to complete.
These transmissions can be detected when the transmit interrupt ETH_DMASR
register[0] is received.
2. Disable the MAC transmitter and MAC receiver by clearing the RE and TE bits in the
ETH_MACCR configuration register.
3. Wait for the receive DMA to have emptied all the frames in the Rx FIFO.
4. Disable the receive DMA.
5. Configure and enable the EXTI line 19 to generate either an event or an interrupt.
6. If you configure the EXTI line 19 to generate an interrupt, you also have to correctly
configure the ETH_WKUP_IRQ Handler function, which should clear the pending bit of
the EXTI line 19.
7. Enable Magic packet/Wake-on-LAN frame detection by setting the MFE/ WFE bit in the
ETH_MACPMTCSR register.
8. Enable the MAC power-down mode, by setting the PD bit in the ETH_MACPMTCSR
register.
9. Enable the MAC Receiver by setting the RE bit in the ETH_MACCR register.
10. Enter the system’s Stop mode (for more details refer to Section 5.3.4: Stop mode):
11. On receiving a valid wakeup frame, the Ethernet peripheral exits the power-down
mode.
12. Read the ETH_MACPMTCSR to clear the power management event flag, enable the
MAC transmitter state machine, and the receive and transmit DMA.
13. Configure the system clock: enable the HSE and set the clocks.
t1 Sync message
Data at
slave clock
t2m t2 t2
Follow_up message
containing value of t1
t1, t2
t4
Delay_Resp message
containing value of t4
ai15669
1. The master broadcasts PTP Sync messages to all its nodes. The Sync message
contains the master’s reference time information. The time at which this message
leaves the master’s system is t1. For Ethernet ports, this time has to be captured at the
MII.
2. A slave receives the Sync message and also captures the exact time, t2, using its
timing reference.
3. The master then sends the slave a Follow_up message, which contains the t1
information for later use.
4. The slave sends the master a Delay_Req message, noting the exact time, t3, at which
this frame leaves the MII.
5. The master receives this message and captures the exact time, t4, at which it enters its
system.
6. The master sends the t4 information to the slave in the Delay_Resp message.
7. The slave uses the four values of t1, t2, t3, and t4 to synchronize its local timing
reference to the master’s timing reference.
Most of the protocol implementation occurs in the software, above the UDP layer. As
described above, however, hardware support is required to capture the exact time when
specific PTP packets enter or leave the Ethernet port at the MII. This timing information has
to be captured and returned to the software for a proper, high-accuracy implementation of
PTP.
be greater than or equal to the resolution of time stamp counter. The synchronization
accuracy target between the master node and the slaves is around 100 ns.
The generation, update and modification of the System Time are described in the Section :
System Time correction methods.
The accuracy depends on the PTP reference clock input period, the characteristics of the
oscillator (drift) and the frequency of the synchronization procedure.
Due to the synchronization from the Tx and Rx clock input domain to the PTP reference
clock domain, the uncertainty on the time stamp latched value is 1 reference clock period. If
we add the uncertainty due to resolution, we will add half the period for time stamping.
The accumulator and the addend are 32-bit registers. Here, the accumulator acts as a high-
precision frequency multiplier or divider. Figure 348 shows this algorithm.
Figure 348. System time update using the Fine correction method
Addend register
Addend update
+
Accumulator register
Constant value
Increment Subsecond
register
+
Subsecond register
Second register
ai15670
The system time update logic requires a 50 MHz clock frequency to achieve 20 ns accuracy.
The frequency division is the ratio of the reference clock frequency to the required clock
frequency. Hence, if the reference clock (HCLK) is, let us say, 66 MHz, the ratio is calculated
as 66 MHz/50 MHz = 1.32. Hence, the default addend value to be set in the register is
232/1.32, which is equal to 0xC1F0 7C1F.
If the reference clock drifts lower, to 65 MHz for example, the ratio is 65/50 or 1.3 and the
value to set in the addend register is 232/1.30 equal to 0xC4EC 4EC4. If the clock drifts
higher, to 67 MHz for example, the addend register must be set to 0xBF0 B7672. When the
clock drift is zero, the default addend value of 0xC1F0 7C1F (232/1.32) should be
programmed.
In Figure 348, the constant value used to increment the subsecond register is 0d43. This
makes an accuracy of 20 ns in the system time (in other words, it is incremented by 20 ns
steps).
The software has to calculate the drift in frequency based on the Sync messages, and to
update the Addend register accordingly. Initially, the slave clock is set with
FreqCompensationValue0 in the Addend register. This value is as follows:
FreqCompensationValue0 = 232 / FreqDivisionRatio
If MasterToSlaveDelay is initially assumed to be the same for consecutive Sync messages,
the algorithm described below must be applied. After a few Sync cycles, frequency lock
occurs. The slave clock can then determine a precise MasterToSlaveDelay value and re-
synchronize with the master using the new value.
Programming steps for system time update in the Coarse correction method
To synchronize or update the system time in one process (coarse correction method),
perform the following steps:
1. Write the offset (positive or negative) in the Time stamp update high and low registers.
2. Set bit 3 (TSSTU) in the Time stamp control register.
3. The value in the Time stamp update registers is added to or subtracted from the system
time when the TSSTU bit is cleared.
Programming steps for system time update in the Fine correction method
To synchronize or update the system time to reduce system-time jitter (fine correction
method), perform the following steps:
1. With the help of the algorithm explained in Section : System Time correction methods,
calculate the rate by which you want to speed up or slow down the system time
increments.
2. Update the time stamp.
3. Wait the time you want the new value of the Addend register to be active. You can do
this by activating the Time stamp trigger interrupt after the system time reaches the
target value.
4. Program the required target time in the Target time high and low registers. Unmask the
Time stamp interrupt by clearing bit 9 in the ETH_MACIMR register.
5. Set Time stamp control register bit 4 (TSARU).
6. When this trigger causes an interrupt, read the ETH_MACSR register.
7. Reprogram the Time stamp addend register with the old value and set ETH_TPTSCR
bit 5 again.
ai15671
PPS output
Ethernet MAC
ai15672
Buffer 1 Buffer 1
Descriptor 0 Descriptor 0
Buffer 2
Buffer 1
Descriptor 1
Buffer 2 Buffer 1
Descriptor 1
Buffer 1
Descriptor 2
Buffer 2
Descriptor 2 Buffer 1
Buffer 1
Descriptor n
Buffer 2
Next descriptor
ai15638
INCR4, INCR8, INCR16 and SINGLE transactions. Otherwise (no fixed-length burst), it
transfers data using INCR (undefined length) and SINGLE transactions.
The Receive DMA initiates a data transfer only when sufficient data for the configured burst
is available in Receive FIFO or when the end of frame (when it is less than the configured
burst length) is detected in the Receive FIFO. The DMA indicates the start address and the
number of transfers required to the AHB master interface. When the AHB interface is
configured for fixed-length burst, then it transfers data using the best combination of INCR4,
INCR8, INCR16 and SINGLE transactions. If the end of frame is reached before the fixed-
burst ends on the AHB interface, then dummy transfers are performed in order to complete
the fixed-length burst. Otherwise (FB bit in ETH_DMABMR is reset), it transfers data using
INCR (undefined length) and SINGLE transactions.
When the AHB interface is configured for address-aligned beats, both DMA engines ensure
that the first burst transfer the AHB initiates is less than or equal to the size of the configured
PBL. Thus, all subsequent beats start at an address that is aligned to the configured PBL.
The DMA can only align the address for beats up to size 16 (for PBL > 16), because the
AHB interface does not support more than INCR16.
databus width. If a descriptor is marked as last, then the buffer may not be full (as indicated
by the buffer size in RDES1). To compute the amount of valid data in this final buffer, the
driver must read the frame length (FL bits in RDES0[29:16]) and subtract the sum of the
buffer sizes of the preceding buffers in this frame. The receive DMA always transfers the
start of next frame with a new descriptor.
Note: Even when the start address of a receive buffer is not aligned to the system databus width
the system should allocate a receive buffer of a size aligned to the system bus width. For
example, if the system allocates a 1024 byte (1 KB) receive buffer starting from address
0x1000, the software can program the buffer start address in the receive descriptor to have
a 0x1002 offset. The receive DMA writes the frame to this buffer with dummy data in the first
two locations (0x1000 and 0x1001). The actual frame is written from location 0x1002. Thus,
the actual useful space in this buffer is 1022 bytes, even though the buffer size is
programmed as 1024 bytes, due to the start address offset.
(Re-)fetch next
descriptor
TxDMA suspended No
Own
bit set?
Yes
(AHB) Yes
error?
No
No
Frame xfer
complete?
Yes
Close intermediate
descriptor Wait for Tx status
No
(AHB) Yes
error?
ai15639
1. The DMA operates as described in steps 1–6 of the TxDMA (default mode).
2. Without closing the previous frame’s last descriptor, the DMA fetches the next
descriptor.
3. If the DMA owns the acquired descriptor, the DMA decodes the transmit buffer address
in this descriptor. If the DMA does not own the descriptor, the DMA goes into Suspend
mode and skips to Step 7.
4. The DMA fetches the Transmit frame from the STM32F10xxxSTM32F107xx memory
and transfers the frame until the end of frame data are transferred, closing the
intermediate descriptors if this frame is split across multiple descriptors.
5. The DMA waits for the transmission status and time stamp of the previous frame. When
the status is available, the DMA writes the time stamp to TDES2 and TDES3, if such
time stamp was captured (as indicated by a status bit). The DMA then writes the status,
with a cleared OWN bit, to the corresponding TDES0, thus closing the descriptor. If
time stamping was not enabled for the previous frame, the DMA does not alter the
contents of TDES2 and TDES3.
6. If enabled, the Transmit interrupt is set, the DMA fetches the next descriptor, then
proceeds to Step 3 (when Status is normal). If the previous transmission status shows
an underflow error, the DMA goes into Suspend mode (Step 7).
7. In Suspend mode, if a pending status and time stamp are received by the DMA, it
writes the time stamp (if enabled for the current frame) to TDES2 and TDES3, then
writes the status to the corresponding TDES0. It then sets relevant interrupts and
returns to Suspend mode.
8. The DMA can exit Suspend mode and enter the Run state (go to Step 1 or Step 2
depending on pending status) only after receiving a Transmit Poll demand
(ETH_DMATPDR register).
Figure 353 shows the basic flowchart in OSF mode.
(Re-)fetch next
descriptor
(AHB) Yes
Poll error?
demand
No
Previous frame
status available Transfer data from
buffer(s)
(AHB) Yes
Write time stamp to
error? Time stamp Yes TDES2 & TDES3
present? for previous frame
No
No
(AHB) No (AHB)
No
error? error?
Yes
Yes
ai15640
indicates the last buffer of the frame. After the last buffer of the frame has been transmitted,
the DMA writes back the final status information to the transmit descriptor 0 (TDES0) word
of the descriptor that has the last segment set in transmit descriptor 0 (TDES0[29]). At this
time, if Interrupt on Completion (TDES0[30]) is set, Transmit Interrupt (in ETH_DMASR
register [0]) is set, the next descriptor is fetched, and the process repeats. Actual frame
transmission begins after the Transmit FIFO has reached either a programmable transmit
threshold (ETH_DMAOMR register[16:14]), or a full frame is contained in the FIFO. There is
also an option for the Store and forward mode (ETH_DMAOMR register[21]). Descriptors
are released (OWN bit TDES0[31] is cleared) when the DMA finishes transferring the frame.
Tx DMA descriptors
The descriptor structure consists of four 32-bit words as shown in Figure 354. The bit
descriptions of TDES0, TDES1, TDES2 and TDES3 are given below.
O T T
Ctrl T Res. Ctrl Reserved T
TDES 0 W Status [16:0]
[30:26] S 24 [23:20] [19:18] S
N
E S
TDES 3 Buffer 2 address [31:0] or Next descriptor address [31:0] / Time stamp high [31:0]
ai15642b
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
O
TT TE TC TT IH IP LC LC
W IC LS FS DC DP CIC ES JT FF NC EC VF CC ED UF DB
SE Res R H Res. SS E E A O
N
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
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
TBS2 TBS1
Reserved Reserved
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
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
TBAP1/TBAP/TTSL
rw
Bits 31:0 TBAP1: Transmit buffer 1 address pointer / Transmit frame time stamp low
These bits have two different functions: they indicate to the DMA the location of data in
memory, and after all data are transferred, the DMA can then use these bits to pass back time
stamp data.
TBAP: When the software makes this descriptor available to the DMA (at the moment that the
OWN bit is set to 1 in TDES0), these bits indicate the physical address of Buffer 1. There is no
limitation on the buffer address alignment. See Host data buffer alignment on page 980 for further
details on buffer address alignment.
TTSL: Before it clears the OWN bit in TDES0, the DMA updates this field with the 32 least
significant bits of the time stamp captured for the corresponding transmit frame (overwriting
the value for TBAP1). This field has the time stamp only if time stamping is activated for this
frame (see TTSE, TDES0 bit 25) and if the Last segment control bit (LS) in the descriptor is
set.
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
TBAP2/TBAP2/TTSH
rw
Bits 31:0 TBAP2: Transmit buffer 2 address pointer (Next descriptor address) / Transmit frame time
stamp high
These bits have two different functions: they indicate to the DMA the location of data in
memory, and after all data are transferred, the DMA can then use these bits to pass back
time stamp data.
TBAP2: When the software makes this descriptor available to the DMA (at the moment when
the OWN bit is set to 1 in TDES0), these bits indicate the physical address of Buffer 2 when a
descriptor ring structure is used. If the Second address chained (TDES1 [24]) bit is set, this
address contains the pointer to the physical memory where the next descriptor is present. The
buffer address pointer must be aligned to the bus width only when TDES1 [24] is set. (LSBs are
ignored internally.)
TTSH: Before it clears the OWN bit in TDES0, the DMA updates this field with the 32 most
significant bits of the time stamp captured for the corresponding transmit frame (overwriting
the value for TBAP2). This field has the time stamp only if time stamping is activated for this
frame (see TDES0 bit 25, TTSE) and if the Last segment control bit (LS) in the descriptor is
set.
1. The CPU sets up Receive descriptors (RDES0-RDES3) and sets the OWN bit
(RDES0[31]).
2. Once the SR (ETH_DMAOMR register[1]) bit is set, the DMA enters the Run state.
While in the Run state, the DMA polls the receive descriptor list, attempting to acquire
free descriptors. If the fetched descriptor is not free (is owned by the CPU), the DMA
enters the Suspend state and jumps to Step 9.
3. The DMA decodes the receive data buffer address from the acquired descriptors.
4. Incoming frames are processed and placed in the acquired descriptor’s data buffers.
5. When the buffer is full or the frame transfer is complete, the Receive engine fetches the
next descriptor.
6. If the current frame transfer is complete, the DMA proceeds to step 7. If the DMA does
not own the next fetched descriptor and the frame transfer is not complete (EOF is not
yet transferred), the DMA sets the Descriptor error bit in RDES0 (unless flushing is
disabled). The DMA closes the current descriptor (clears the OWN bit) and marks it as
intermediate by clearing the Last segment (LS) bit in the RDES1 value (marks it as last
descriptor if flushing is not disabled), then proceeds to step 8. If the DMA owns the next
descriptor but the current frame transfer is not complete, the DMA closes the current
descriptor as intermediate and returns to step 4.
7. If IEEE 1588 time stamping is enabled, the DMA writes the time stamp (if available) to
the current descriptor’s RDES2 and RDES3. It then takes the received frame’s status
and writes the status word to the current descriptor’s RDES0, with the OWN bit cleared
and the Last segment bit set.
8. The Receive engine checks the latest descriptor’s OWN bit. If the CPU owns the
descriptor (OWN bit is at 0) the Receive buffer unavailable bit (in ETH_DMASR
register[7]) is set and the DMA Receive engine enters the Suspended state (step 9). If
the DMA owns the descriptor, the engine returns to step 4 and awaits the next frame.
9. Before the Receive engine enters the Suspend state, partial frames are flushed from
the Receive FIFO (you can control flushing using bit 24 in the ETH_DMAOMR register).
10. The Receive DMA exits the Suspend state when a Receive Poll demand is given or the
start of next frame is available from the Receive FIFO. The engine proceeds to step 2
and re-fetches the next descriptor.
The DMA does not acknowledge accepting the status until it has completed the time stamp
write-back and is ready to perform status write-back to the descriptor. If software has
enabled time stamping through CSR, when a valid time stamp value is not available for the
frame (for example, because the receive FIFO was full before the time stamp could be
written to it), the DMA writes all ones to RDES2 and RDES3. Otherwise (that is, if time
stamping is not enabled), RDES2 and RDES3 remain unchanged.
(AHB)
RxDMA suspended Yes
error?
No
Yes
Frame transfer
No Own bit set?
complete?
No Yes
Frame data
Yes Flush disabled ? No
available ?
No Yes
Flush the
Write data to buffer(s) Wait for frame data
remaining frame
(AHB)
Yes
error?
No
(AHB)
Yes
error?
No
No
Yes Yes Yes
No
(AHB)
No
error?
Yes
ai15643
Rx DMA descriptors
The descriptor structure consists of four 32-bit words (16 bytes). These are shown in
Figure 356. The bit descriptions of RDES0, RDES1, RDES2 and RDES3 are given below.
RDES 1 CT Reserved Buffer 2 byte count CTRL Res. Buffer 1 byte count
RL [30:29] [28:16] [15:14] [12:0]
ai15644
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
IPHCE
VLAN
OWN
RWT
AFM
LCO
PCE
SAF
OE
DE
RE
DE
CE
ES
FS
LE
LS
FT
FL
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
Reserved
RCH
RER
DIC
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
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
RBP1 / RTSL
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
Bits 31:0 RBAP1 / RTSL: Receive buffer 1 address pointer / Receive frame time stamp low
These bits take on two different functions: the application uses them to indicate to the DMA
where to store the data in memory, and then after transferring all the data the DMA may use
these bits to pass back time stamp data.
RBAP1: When the software makes this descriptor available to the DMA (at the moment that
the OWN bit is set to 1 in RDES0), these bits indicate the physical address of Buffer 1. There are
no limitations on the buffer address alignment except for the following condition: the DMA uses the
configured value for its address generation when the RDES2 value is used to store the start of
frame. Note that the DMA performs a write operation with the RDES2[3/2/1:0] bits as 0 during the
transfer of the start of frame but the frame data is shifted as per the actual Buffer address pointer.
The DMA ignores RDES2[3/2/1:0] (corresponding to bus width of 128/64/32) if the address pointer
is to a buffer where the middle or last part of the frame is stored.
RTSL: Before it clears the OWN bit in RDES0, the DMA updates this field with the 32 least
significant bits of the time stamp captured for the corresponding receive frame (overwriting
the value for RBAP1). This field has the time stamp only if time stamping is activated for this
frame and if the Last segment control bit (LS) in the descriptor is set.
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
RBP2 / RTSH
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
Bits 31:0 RBAP2 / RTSH: Receive buffer 2 address pointer (next descriptor address) / Receive frame
time stamp high
These bits take on two different functions: the application uses them to indicate to the DMA
the location of where to store the data in memory, and then after transferring all the data the
DMA may use these bits to pass back time stamp data.
RBAP1: When the software makes this descriptor available to the DMA (at the moment that
the OWN bit is set to 1 in RDES0), these bits indicate the physical address of buffer 2 when a
descriptor ring structure is used. If the second address chained (RDES1 [24]) bit is set, this address
contains the pointer to the physical memory where the next descriptor is present. If RDES1 [24] is
set, the buffer (next descriptor) address pointer must be bus width-aligned (RDES3[3, 2, or
1:0] = 0, corresponding to a bus width of 128, 64 or 32. LSBs are ignored internally.)
However, when RDES1 [24] is reset, there are no limitations on the RDES3 value, except for the
following condition: the DMA uses the configured value for its buffer address generation when the
RDES3 value is used to store the start of frame. The DMA ignores RDES3[3, 2, or 1:0]
(corresponding to a bus width of 128, 64 or 32) if the address pointer is to a buffer where the
middle or last part of the frame is stored.
RTSH: Before it clears the OWN bit in RDES0, the DMA updates this field with the 32 most
significant bits of the time stamp captured for the corresponding receive frame (overwriting
the value for RBAP2). This field has the time stamp only if time stamping is activated and if
the Last segment control bit (LS) in the descriptor is set.
interrupt. Even then, a new interrupt is generated, due to the active or pending Receive
buffer unavailable interrupt.
FBES
AND
TPSS FBEIE
AND TJTS AIS
TPSSIE
AND AND
ROS TJTIE
AISE
AND
TUS ROIE
AND
TUIE RBU OR
AND RPSS
RWTS RBUIE
AND
AND RPSSIE
RWTIE
ETS
AND
ETIE
AI15646
ETH_DMAIER register. This timer is disabled before it runs out, when a frame is transferred
to memory and the RS is set because it is enabled for that descriptor.
Note: Reading the PMT control and status register automatically clears the Wakeup Frame
Received and Magic Packet Received PMT interrupt flags. However, since the registers for
these flags are in the CLK_RX domain, there may be a significant delay before this update is
visible by the firmware. The delay is especially long when the RX clock is slow (in 10 Mbit
mode) and when the AHB bus is high-frequency.
Since interrupt requests from the PMT to the CPU are based on the same registers in the
CLK_RX domain, the CPU may spuriously call the interrupt routine a second time even after
reading PMT_CSR. Thus, it may be necessary that the firmware polls the Wakeup Frame
Received and Magic Packet Received bits and exits the interrupt service routine only when
they are found to be at ‘0’.
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
APCS
IPCO
Reserved
Reserved
Reserved
Reserved
ROD
CSD
FES
WD
DM
RD
DC
RE
LM
TE
BL
JD
IFG
Reserved
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
DAIF
SAIF
PAM
HPF
PCF
BFD
SAF
HM
PM
HU
RA
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
The most significant bit determines the register to be used (hash table high/hash table low),
and the other 5 bits determine which bit within the register. A hash value of 0b0 0000 selects
bit 0 in the selected register, and a value of 0b1 1111 selects bit 31 in the selected register.
For example, if the DA of the incoming frame is received as 0x1F52 419C B6AF (0x1F is the
first byte received on the MII interface), then the internally calculated 6-bit Hash value is
0x2C and the HTH register bit[12] is checked for filtering. If the DA of the incoming frame is
received as 0xA00A 9800 0045, then the calculated 6-bit Hash value is 0x07 and the HTL
register bit[7] is checked for filtering.
If the corresponding bit value in the register is 1, the frame is accepted. Otherwise, it is
rejected. If the PAM (pass all multicast) bit is set in the ETH_MACFFR register, then all
multicast frames are accepted regardless of the multicast hash values.
The Hash table high register contains the higher 32 bits of the multicast Hash table.
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
HTH
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
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
HTL
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
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
Reserved
PA MR CR MW MB
Reserved rc_
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
w1
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
MD
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
transferred onto the cable. The Host must make sure that the Busy bit is cleared before
writing to the register.
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
ZQPD
UPFD
RFCE
TFCE
FCB/
Reserved
PT PLT
BPA
Reserved
rc_w1
rw rw rw rw rw rw rw 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
VLANTC
VLANTI
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
This is the address through which the remote wakeup frame filter registers are written/read
by the application. The Wakeup frame filter register is actually a pointer to eight (not
transparent) such wakeup frame filter registers. Eight sequential write operations to this
address with the offset (0x0028) will write all wakeup frame filter registers. Eight sequential
read operations from this address with the offset (0x0028) will read all wakeup frame filter
registers. This register contains the higher 16 bits of the 7th MAC address. Refer to Remote
wakeup frame filter register section for additional information.
Figure 358. Ethernet MAC remote wakeup frame filter register (ETH_MACRWUFFR)
Wakeup frame filter reg5 Filter 3 Offset Filter 2 Offset Filter 1 Offset Filter 0 Offset
ai15648
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
WFFRPR
Reserved
Reserved
WFR
WFE
MPR
MPE
GU
PD
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TSTS MMCTS MMCRS MMCS PMTS
Reserved Reserved Reserved
rc_r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TSTIM PMTIM
Reserved Reserved Reserved
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
MO
MACA0H
Reserved
1 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
MACA0L
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
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
AE SA MBC MACA1H
Reserved
rw rw rw rw rw rw rw rw 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
MACA1L
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
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
AE SA MBC MACA2H
Reserved
rw rw rw rw rw rw rw rw 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
MACA2L
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
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
AE SA MBC MACA3H
Reserved
rw rw rw rw rw rw rw rw 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
MACA3L
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
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
ROR
MCF
CSR
CR
Reserved
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
RGUFS
RFCES
RFAES
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
TGFMSCS
TGFSCS
TGFS
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
RGUFM
RFCEM
RFAEM
Reserved Reserved Reserved
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
TGFMSCM
TGFSCM
TGFM
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
TGFSCC
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
Ethernet MMC transmitted good frames after more than a single collision
counter register (ETH_MMCTGFMSCCR)
Address offset: 0x0150
Reset value: 0x0000 0000
This register contains the number of successfully transmitted frames after more than a
single collision in Half-duplex mode.
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
TGFMSCC
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
Bits 31:0 TGFMSCC: Transmitted good frames more single collision counter
Transmitted good frames after more than a single collision counter
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
TGFC
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RFCEC
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RFAEC
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RGUFC
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TTSARU
TSFCU
TSSTU
TSITE
TSSTI
TSE
Reserved
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
STSSI
Reserved
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
STS
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
STPNS
STSS
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
This register contains the most significant (higher) 32 bits of the time to be written to, added
to, or subtracted from the System Time value. The Time stamp high update register, along
with the Time stamp update low register, initializes or updates the system time maintained
by the MAC. You have to write both of these registers before setting the TSSTI or TSSTU
bits in the Time stamp control register.
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
TSUS
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
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
TSUPNS
TSUSS
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
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
TSA
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
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
TTSH
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
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
TTSL
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
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
Reserved
FPM
USP
AAB
SR
DA
FB
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
TPD
rw_wt
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
RPD
rw_wt
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
SRL
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
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
STL
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
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
MMCS
RWTS
PMTS
RBUS
RPSS
TBUS
FBES
TPSS
TSTS
TJTS
ROS
RPS
ERS
EBS
TUS
TPS
ETS
NIS
AIS
RS
Reserved
Reserved
Reserved
TS
rc- rc- rc- rc- rc- rc- rc- rc- rc- rc- rc- rc- rc- rc- rc-
r r r r r r r r r r r r
w1 w1 w1 w1 w1 w1 w1 w1 w1 w1 w1 w1 w1 w1 w1
The operation mode register establishes the Transmit and Receive operating modes and
commands. The ETH_DMAOMR register should be the last CSR to be written as part of
DMA initialization.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10
DTCEFD 9 8 7 6 5 4 3 2 1 0
FUGF
DFRF
Reserved
Reserved
Reserved
OSF
RTC
RSF
TTC
TSF
FEF
FTF
SR
ST
Reserved Reserved Reserved
rw rw rw rw rs 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
RWTIE
RBUIE
RPSIE
TBUIE
FBEIE
TPSIE
TJTIE
Reserved
ROIE
NISE
ERIE
AISE
TUIE
ETIE
RIE
TIE
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
The Ethernet interrupt is generated only when the TSTS or PMTS bits of the DMA Status
register is asserted with their corresponding interrupt are unmasked, or when the NIS/AIS
Status bit is asserted and the corresponding Interrupt Enable bits (NISE/AISE) are enabled.
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
OMFC
OFOC
MFA
MFC
Reserved
rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_ rc_
r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HTDAP
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HRDAP
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HTBAP
r r r r r r r r 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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HRBAP
r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r r
Offset Register
9
8
7
6
5
4
3
2
1
0
Reserved
Reserved
Reserved
Reserved
APCS
IPCO
ROD
CSD
FES
WD
DM
RD
DC
LM
RE
TE
JD
BL
ETH_MACCR IFG
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
ETH_MACFF
DAIF
PAM
HPF
PCF
BFD
SAF
HM
PM
HU
RA
0x04 R Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ETH_MACHT
HTH[31:0]
0x08 HR
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
ETH_MACHT
HTL[31:0]
0x0C LR
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
ETH_MACMII M M
Reserved
PA MR CR
AR W B
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ETH_MACMII
MD
0x14 DR Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FCB/BPA
Reserved
ZQPD
RFCE
UPFD
TFCE
ETH_MACFC
PT PLT
0x18 R Reserved
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
VLANTC
ETH_MACVL
VLANTI
0x1C ANTR Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ETH_MACRW
Frame filter reg0\Frame filter reg1\Frame filter reg2\Frame filter reg3\Frame filter reg4\...\Frame filter reg7
0x28 UFFR
Reset value 0
WFFRPR
Reserved
Reserved
WFR
ETH_MACPM
WFE
MPR
MPE
GU
PD
0x2C TCSR Reserved
Reset value 0 0 0 0 0 0 0
MMCRS
MMCTS
MMCS
Reserved
PMTS
TSTS
ETH_MACSR
0x38 Not applicable Reserved Reserved
Reset value 0 0 0 0 0
PMTIM
TSTIM
ETH_MACIM
0x3C R Not applicable Reserved Reserved Reserved
Reset value 0 0
ETH_MACA0
MO
Reserved MACA0H
0x40 HR
Reset value 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ETH_MACA0
MACA0L
0x44 LR
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
ETH_MACA1
AE SA MBC[6:0] MACA1H
0x48 HR Reserved
Reset value 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ETH_MACA1
MACA1L
0x4C LR
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
ETH_MACA2
AE SA MBC MACA2H
0x50 HR Reserved
Reset value 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ETH_MACA2
MACA2L
0x54 LR
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
ETH_MACA3
AE SA MBC MACA3H
0x58 HR Reserved
Reset value 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ETH_MACA3
MACA3L
0x5C LR
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
ROR
MCF
CSR
CR
ETH_MMCCR
0x100 Reserved
Reset value 0 0 0 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
RGUFS
RFCES
RFAES
ETH_MMCRI
0x104 R Reserved Reserved Reserved
Reset value 0 0 0
TGFMSCS
TGFSCS
TGFS
ETH_MMCTI
0x108 R Reserved Reserved Reserved
Reset value 0 0 0
RGUFM
RFCEM
RFAEM
ETH_MMCRI
0x10C MR Reserved Reserved Reserved
Reset value 0 0 0
TGFMSCM
TGFSCM
TGFM
ETH_MMCTI
0x110 MR Reserved Reserved Reserved
Reset value 0 0 0
ETH_MMCTG
TGFSCC
0x14C FSCCR
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
ETH_MMCTG
TGFMSCC
0x150 FMSCCR
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
ETH_MMCTG
TGFC
0x168 FCR
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
ETH_MMCRF
RFCEC
0x194 CECR
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
ETH_MMCRF
RFAEC
0x198 AECR
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
ETH_MMCR
RGUFC
0x1C4 GUFCR
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
TTSARU
TSFCU
TSSTU
TSSTI
TSITE
ETH_PTPTS
TSE
0x700 CR Reserved
Reset value 0 0 0 0 0 0
ETH_PTPSSI
STSSI
0x704 R Reserved
Reset value 0 0 0 0 0 0 0 0
ETH_PTPTS
STS[31:0]
0x708 HR
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
STPNS
ETH_PTPTSL
STSS
0x70C R
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
ETH_PTPTS
TSUS
0x710 HUR
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
TSUPNS
ETH_PTPTSL
TSUSS
0x714 UR
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
ETH_PTPTS
TSA
0x718 AR
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
ETH_PTPTT
TTSH
0x71C HR
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
ETH_PTPTTL
TTSL
0x720 R
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
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
10
Offset Register
9
8
7
6
5
4
3
2
1
0
EDFE
ETH_DMABM
FPM
USP
AAB
SR
DA
FB
RDP RTPR PBL DSL
0x1000 R Reserved
Reset value 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1
ETH_DMATP
TPD
0x1004 DR
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
ETH_DMARP
RPD
0x1008 DR
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
ETH_DMARD
SRL
0x100C LAR
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
ETH_DMATD
STL
0x1010 LAR
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
MMCS
Reserved
DTCEFD Reserved
Reserved
RWTS
PMTS
RBUS
RPSS
TBUS
FBES
TPSS
TSTS
TJTS
ROS
RPS
ERS
EBS
TUS
TPS
ETS
NIS
AIS
RS
TS
ETH_DMASR
0x1014
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
Reserved
Reserved
Reserved
FUGF
DFRF
ETH_DMAOM
OSF
RTC
RSF
TTC
TSF
FEF
FTF
SR
ST
0x1018 R Reserved Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RWTIE
RBUIE
RPSIE
Reserved
TBUIE
FBEIE
TPSIE
TJTIE
ROIE
NISE
ERIE
AISE
TUIE
ETH_DMAIE
ETIE
RIE
TIE
0x101C R Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OMFC
OFOC
ETH_DMAMF
MFA
MFC
0x1020 BOCR Reserved
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
ETH_DMACH
HTDAP
0x1048 TDR
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
ETH_DMACH
HRDAP
0x104C RDR
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
ETH_DMACH
HTBAP
0x1050 TBAR
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
ETH_DMACH
HRBAP
0x1054 RBAR
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
F_SIZE
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
U_ID(15:0)
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
U_ID(31:16)
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
U_ID(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
U_ID(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
U_ID(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
U_ID(79:64)
r r r r r r r r r r r r r r r r
31.1 Overview
The STM32F10xxx are built around a Cortex™-M3 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
STM32F10xxx MCUs.
Two interfaces for debug are available:
● Serial wire
● JTAG debug port
Figure 359. Block diagram of STM32 MCU and Cortex™-M3-level debug support
Cortex-M3 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
ai17138
Note: The debug features embedded in the Cortex™-M3 core are a subset of the ARM CoreSight
Design Kit.
The ARM Cortex™-M3 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)
● ETM: Embedded Trace Macrocell (available on larger packages, where the
corresponding pins are mapped)
It also includes debug features dedicated to the STM32F10xxx:
● Flexible debug pinout assignment
● MCU debug box (support for low-power modes, control over peripheral clocks, etc.)
Note: For further information on debug functionality supported by the ARM Cortex™-M3 core,
refer to the Cortex™-M3-r1p1 Technical Reference Manual and to the CoreSight Design Kit-
r1p0 TRM (see Section 31.2: Reference ARM documentation).
SWJ-DP
JTDO TDO
TDO
TDI
JTDI TDI
nTRST
NJTRST nTRST
JTAG-DP
TCK
TMS
nPOTRST
SWD/JTAG From
power-on
select nPOTRST reset
DBGRESETn
SWDITMS
DBGDI
JTMS/SWDIO
SWDO
DBGDO
SW-DP
SWDOEN
DBGDOEN
SWCLKTCK
JTCK/SWCLK DBGCLK
ai17139
Figure 360 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.
If the debugger host wants to switch to the SW-DP, it must provide a dedicated JTAG
sequence on TMS/TCK (respectively mapped to SWDIO and SWCLK) which disables the
JTAG-DP and enables the SW-DP. This way it is possible to activate the SWDP using only
the SWCLK and SWDIO pins.
This sequence is:
1. Send more than 50 TCK cycles with TMS (SWDIO) =1
2. Send the 16-bit sequence on TMS (SWDIO) = 0111100111100111 (MSB transmitted
first)
3. Send more than 50 TCK cycles with TMS (SWDIO) =1
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 set
SWJ_CFG=010 just after reset. 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 will be 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 Cortex-M3 TAP
IR is 5-bit wide IR is 4-bit wide
JTDO
ai14981b
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
DEV_ID
Reserved
r r r r r r r r r r r r
BYPASS
1111
[1 bit]
IDCODE ID CODE
1110
[32 bits] 0x3BA00477 (ARM Cortex™-M3 r1p1-01rel0 ID Code)
Debug port access register
This initiates a debug port and allows access to a debug port register.
– When transferring data IN:
Bits 34:3 = DATA[31:0] = 32-bit data to transfer for a write request
Bits 2:1 = A[3:2] = 2-bit address of a debug port register.
Bit 0 = RnW = Read request (1) or write request (0).
DPACC – When transferring data OUT:
1010
[35 bits] Bits 34:3 = DATA[31:0] = 32-bit data which is read following a read
request
Bits 2:0 = ACK[2:0] = 3-bit Acknowledge:
010 = OK/FAULT
001 = WAIT
OTHER = reserved
Refer to Table 219 for a description of the A(3:2) bits
Table 219. 32-bit debug port registers addressed through the shifted value A[3:2]
Address A(3:2) value Description
Refer to the Cortex™-M3 r1p1 TRM for a detailed description of DPACC and APACC
registers.
The packet request is always followed by the turnaround time (default 1 bit) where neither
the host nor target drive the line.
001: FAULT
0..2 ACK 010: WAIT
100: OK
The ACK Response must be followed by a turnaround time only if it is a READ transaction or
if a WAIT or FAULT acknowledge has been received.
WDATA or
0..31 Write or Read data
RDATA
32 Parity Single parity of the 32 data bits
The DATA transfer must be followed by a turnaround time only if it is a READ transaction.
IDCODE read or CTRL/STAT read or ABORT write which are accepted even if the write
buffer is full.
● Because of the asynchronous clock domains SWCLK and HCLK, two extra SWCLK
cycles are needed after a write transaction (after the parity bit) to make the write
effective internally. These cycles should be applied while driving the line low (IDLE
state)
This is particularly important when writing the CTRL/STAT for a power-up request. If the
next transaction (requiring a power-up) occurs immediately, it will fail.
There are many AP Registers (see AHB-AP) addressed as the combination of:
● The shifted value A[3:2]
● The current value of the DP SELECT register
Note: Important: these registers are not reset by a system reset. They are only reset by a power-
on reset.
Refer to the Cortex™-M3 r1p1 TRM for further details.
To Halt on reset, it is necessary to:
● enable the bit0 (VC_CORRESET) of the Debug and Exception Monitor Control
Register
● enable the bit0 (C_DEBUGEN) of the Debug Halting Control and Status Register.
Note: It is highly recommended for the debugger host to connect (set a breakpoint in the reset
vector) under system reset.
For this, the DWT must be configured to trigger the ITM: the bit CYCCNTENA (bit0) of the
DWT Control Register must be set. In addition, the bit2 (SYNCENA) of the ITM Trace
Control Register must be set.
Note: If the SYNENA bit is not set, the DWT generates Synchronization triggers to the TPIU which
will send only TPIU synchronization packets and not ITM synchronization packets.
An overflow packet consists is a special timestamp packets which indicates that data has
been written but the FIFO was full.
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.17.2: TRACE pin assignment and Section 31.16.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)
The core does not allow FCLK or HCLK to be turned off during a debug session. As these
are required for the debugger connection, during a debug, they must remain active. The
MCU integrates special means to allow the user to debug software in low-power modes.
For this, the debugger host must first set some debug configuration registers to change the
low-power mode behavior:
● In Sleep mode, DBG_SLEEP bit of DBGMCU_CR register must be previously set by
the debugger. This will feed HCLK with the same clock that is provided to FCLK
(system clock previously configured by the software).
● In Stop mode, the bit DBG_STOP must be previously set by the debugger. This will
enable the internal RC oscillator clock to feed FCLK and HCLK in STOP mode.
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
DBG_ DBG_ DBG_ DBG_ DBG_ DBG_ DGB_C DBG_ DBG_ DBG_ DBG_ DBG_I2C2
TIM11_ TIM10_ TIM9_ TIM14_ TIM13_ TIM12_ AN2_ST TIM7_ TIM6_ TIM5_ TIM8_ _SMBUS_
Res. STOP STOP STOP STOP STOP STOP Reserved OP STOP STOP STOP STOP TIMEOUT
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
DBG_I2C1 DBG_ DBG_ DBG_ DBG_ DBG_ DBG_ DBG_ TRACE_ DBG_
TRACE_ DBG_ DBG_
_SMBUS_ CAN1_ TIM4_ TIM3_ TIM2_ TIM1_ WWDG_ IWDG MODE STAND
IOEN Reserved STOP SLEEP
TIMEOUT STOP STOP STOP STOP STOP STOP STOP [1:0] BY
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31.17.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).
TPIU
TRACECLKIN
Asynchronous
ETM
FIFO
TRACECK
TPIU Trace out
formatter (serializer) TRACEDATA
[3:0]
ITM Asynchronous
FIFO
TRACESWO
ai17114
● Synchronous mode
The synchronous mode requires from 2 to 6 extra pins depending on the data trace
size and is only available in the larger packages. In addition it is available in JTAG mode
and in Serial Wire mode and provides better bandwidth output capabilities than
asynchronous trace.
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.
The debugger must then program the Trace Mode by writing the PROTOCOL[1:0] bits in the
SPP_R (Selected Pin Protocol) register of the TPIU.
● PROTOCOL=00: Trace Port Mode (synchronous)
● PROTOCOL=01 or 10: Serial Wire (Manchester or NRZ) Mode (asynchronous mode).
Default state is 01
It then also configures the TRACE port size by writing the bits [3:0] in the CPSPS_R
(Current Sync Port Size Register) of the TPIU:
● 0x1 for 1 pin (default state)
● 0x2 for 2 pins
● 0x8 for 4 pins
TRACE_IOEN bit in the DBGMCU_CFG register is set. In this case, the word
0x7F_FF_FF_FF is not followed by any formatted packet.
● at each DWT trigger (assuming DWT has been previously configured). Two cases
occur:
– If the bit SYNENA of the ITM is reset, only the word 0x7F_FF_FF_FF is emitted
without any formatted stream which follows.
– If the bit SYNENA of the ITM is set, then the ITM synchronization packets will
follow (0x80_00_00_00_00_00), formatted by the TPUI (trace source ID added).
9
8
7
6
5
4
3
2
1
0
0xE0042000
DBGMCU_
REV_ID DEV_ID
IDCODE Reserved
Reset value(1) 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
DBG_I2C2_SMBUS_TIMEOUT
DBG_I2C1_SMBUS_TIMEOUT
DBG_WWDG_STOP
TRACE_MODE[1:0]
DGB_CAN2_STOP
DBG_CAN1_STOP
DBG_TIM7_STOP
DBG_TIM6_STOP
DBG_TIM5_STOP
DBG_TIM8_STOP
DBG_TIM4_STOP
DBG_TIM3_STOP
DBG_TIM2_STOP
DBG_TIM1_STOP
DBG_IWDGSTOP
DBG_STANDBY
TRACE_IOEN
DBG_SLEEP
DBG_STOP
0xE0042004
Reserved
DBGMCU_CR
Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1. The reset value is product dependent. For more information, refer to Section 31.6.1: MCU device ID code.
32 Revision history
Document reference number changed from UM0306 to RM0008. The changes below were
made with reference to revision 1 of 01-Jun-2007 of UM0306.
EXTSEL[2:0] and JEXTSEL[2:0] removed from Table 65: ADC pins on page 209 and
VREF+ range modified in Remarks column.
Notes added to Section 11.3.9 on page 213, Section 11.9.2 on page 221, Section 11.9.7
on page 224 and Section 11.9.9 on page 225.
SPI_CR2 corrected to SPI_CR1 in 1 clock and 1 bidirectional data wire (BIDIMODE=1) on
page 681.
fCPU frequency changed to fPCLK in Section 25.2: SPI and I2S main features on page 673.
Section 25.3.6: CRC calculation on page 688 and Section 25.3.9: SPI communication
using DMA (direct memory addressing) on page 692 modified.
Note added to bit 13 description changed in Section 25.5.1: SPI control register 1
(SPI_CR1) (not used in I2S mode) on page 714. Note for bit 4 modified in Section 25.5.3:
SPI status register (SPI_SR) on page 717.
On 64-pin packages and packages with less pins on page 66 modified.
Section 9.3.2: Using OSC_IN/OSC_OUT pins as GPIO ports PD0/PD1 on page 170
updated.
Description of SRAM at address 0x4000 6000 modified in Figure 2: Memory map on
page 39 and Table 3: Register boundary addresses.
Note added to Section 23.2: USB main features on page 597 and Section 24.2: bxCAN
19-Oct-2007 1 main features on page 628.
Figure 4: Power supply overview and On 100-pin and 144-pin packages modified.
Formula added to Bits 25:24 description in CAN bit timing register (CAN_BTR) on
page 657.
Figure 49: DMA block diagram in low-, medium- high- and XL-density devices on page 267
modified.
Example of configuration on page 1066 modified.
MODEx[1:0] bit definitions corrected in Section 9.2.2: Port configuration register high
(GPIOx_CRH) (x=A..G) on page 167.
Downcounting mode on page 289 modified.
Figure 81: Output stage of capture/compare channel (channel 4) on page 300 and
Figure 83: Output compare mode, toggle on OC1. modified. OCx output enable conditions
modified in Section 14.3.10: PWM mode on page 304.
Section 14.3.19: TIMx and external trigger synchronization on page 319 title changed.
CC1S, CC2S, CC3S and CC4S definitions modified for (1, 1) bit setting modified in
Section 14.4.7: TIM1&TIM8 capture/compare mode register 1 (TIMx_CCMR1) and
Section 14.4.8: TIM1&TIM8 capture/compare mode register 2 (TIMx_CCMR2).
CC1S, CC2S, CC3S and CC4S definitions for (1, 1) bit setting modified in Section 15.4.7:
TIMx capture/compare mode register 1 (TIMx_CCMR1) and Section 15.4.8: TIMx
capture/compare mode register 2 (TIMx_CCMR2).
AFIO_EVCR pins modified in Table 60: AFIO register map and reset values on page 188.
Section 14.3.6: Input capture mode on page 300 modified.
In Section 7: Low-, medium-, high- and XL-density reset and clock control (RCC) on
page 87:
– LSI calibration on page 94 added
– Figure 7: Simplified diagram of the reset circuit on page 88 updated
– APB2 peripheral reset register (RCC_APB2RSTR) on page 103 updated
– APB1 peripheral reset register (RCC_APB1RSTR) on page 106 updated
– AHB peripheral clock enable register (RCC_AHBENR) updated
– APB2 peripheral clock enable register (RCC_APB2ENR) updated
– APB1 peripheral clock enable register (RCC_APB1ENR) on page 111 updated (see
Section Table 18.: RCC register map and reset values).
– LSERDYIE definition modified in Clock interrupt register (RCC_CIR)
– HSITRIM[4:0] definition modified in Clock control register (RCC_CR)
In Section 9: General-purpose and alternate-function I/Os (GPIOs and AFIOs) on
page 154:
– GPIO ports F and G added
– In Section 9.3: Alternate function I/O and debug configuration (AFIO) on page 170
remapping for High-density devices added, note modified under Section 9.3.2,
Section 9.3.3 on page 171 modified
– AF remap and debug I/O configuration register (AFIO_MAPR) updated
Updated in Section 10: Interrupts and events on page 190:
– number of maskable interrupt channels
– number of GPIOs (see Figure 21: External interrupt/event GPIO mapping)
22-May-2008 4 In Section 13: Direct memory access controller (DMA) on page 265:
continued continued – number of DMA controllers and configurable DMA channels updated
– Figure 48: DMA block diagram in connectivity line devices on page 266 updated, notes
added
– Note updated in Section 13.3.2: Arbiter on page 268
– Note updated in Section 13.3.6: Interrupts on page 271
– Figure 50: DMA1 request mapping on page 272 updated
– DMA2 controller on page 273 added
In Section 11: Analog-to-digital converter (ADC) on page 206:
– ADC3 added (Figure 22: Single ADC block diagram on page 208 updated, Table 70:
External trigger for injected channels for ADC3 added, etc.)
Section 12: Digital-to-analog converter (DAC) on page 245 added.
In Section 14: Advanced-control timers (TIM1&TIM8) on page 282:
– Advanced control timer TIM8 added (see Figure 52: Advanced-control timer block
diagram on page 284)
– TS[2:0] modified in Section 14.4.3: TIM1&TIM8 slave mode control register
(TIMx_SMCR) on page 327.
In Section 15: General-purpose timers (TIM2 to TIM5) on page 350:
– TIM5 added
– Figure 100: General-purpose timer block diagram updated. Table 86: TIMx Internal
trigger connection on page 392 modified. Section 17: Basic timers (TIM6&TIM7) added.
RTC clock sources specified in Section 18.2: RTC main features on page 464.
Section 18.1: RTC introduction modified.
Section 21: Flexible static memory controller (FSMC) on page 487 added.
Section 26: Secure digital input/output interface (SDIO) on page 710 added.
Figure 234: CAN frames on page 646 modified. Bits 31:21 and bits 20:3 modified in CAN
TX mailbox identifier register (CAN_TIxR) (x=0..2) on page 659. Bits 31:21 and bits 20:3
modified in CAN receive FIFO mailbox identifier register (CAN_RIxR) (x=0..1) on
page 662.
Section 26.3.7: DMA requests on page 740 modified. DMAEN bit 11 description modified
in Section 26.6.2: I2C Control register 2 (I2C_CR2) on page 746.
Clock phase and clock polarity on page 677 modified. Transmit sequence on page 679
modified. Receive sequence on page 680 added. Reception sequence on page 711
22-May-2008 4 modified. Underrun flag (UDR) on page 712 modified.
continued continued I2S feature added (see Section 25: Serial peripheral interface (SPI) on page 672).
In Section 31: Debug support (DBG) on page 1047:
– DBGMCU_IDCODE on page 1054 and DBGMCU_CR on page 1068 updated
– TMC TAP changed to boundary scan TAP
– Address onto which DBGMCU_CR is mapped modified in Section 31.16.3: Debug MCU
configuration register on page 1068.
Section 30: Device electronic signature on page 1044 added.
REV_ID(15:0) definition modified in Section 31.6.1: MCU device ID code on page 1054.
Developed polynomial form updated in Section 4.2: CRC main features on page 62.
Figure 4: Power supply overview on page 66 modified.
Section 5.1.2: Battery backup domain on page 67 modified.
Section 7.2.5: LSI clock on page 93 specified.
Section 9.1.4: Alternate functions (AF) on page 157 clarified.
Note added to Table 45: TIM2 alternate function remapping on page 174.
Bits are write-only in Section 13.4.2: DMA interrupt flag clear register (DMA_IFCR) on
page 276.
Register name modified in Section 11.3.1: ADC on-off control on page 210.
Recommended sampling time given in Section 11.10: Temperature sensor on page 226.
Bit attributes modified in Section 11.12.1: ADC status register (ADC_SR) on page 228.
Note modified for bits 23:0 in Section 11.12.4: ADC sample time register 1 (ADC_SMPR1)
on page 235.
28-Jul-2008 5
Note added in Section 12.2: DAC main features on page 245.
Formula updated in Section 12.3.5: DAC output voltage on page 249.
DBL[4:0] description modified in Section 14.3.19: TIMx and external trigger
synchronization on page 319.
Figure 82 on page 302 and Figure 128 on page 369 modified.
Section 25.5.3: SPI status register (SPI_SR) on page 717 modified.
Closing the communication on page 732 updated.
Notes added to Section 26.6.8: I2C Clock control register (I2C_CCR) on page 754. TCK
replaced by TPCLK1 in Section 26.6.8 and Section 26.6.9.
OVR changed to ORE in Figure 300: USART interrupt mapping diagram on page 789.
Section 27.6.1: Status register (USART_SR) on page 790 updated.
Slave select (NSS) pin management on page 676 clarified.
Small text changes.
Memory map figure removed from reference manual. Section 3.1: System architecture on
page 47 modified. Section 3.4: Boot configuration on page 60 modified. Exiting Sleep
mode on page 71 modified. Section 6.3.2: RTC calibration on page 80 updated. Wakeup
event management on page 199 updated.
Section 7.3: RCC registers on page 96 updated. Section 13.2: DMA main features on
page 265 updated.
Section 13.3.5: Error management modified. Figure 48: DMA block diagram in
connectivity line devices on page 266 modified. Section 13.3.4: Programmable data width,
data alignment and endians on page 270 added.
Bit definition modified in Section 13.4.5: DMA channel x peripheral address register
(DMA_CPARx) (x = 1..7), where x = channel number) on page 279 and Section 13.4.6:
DMA channel x memory address register (DMA_CMARx) (x = 1..7), where x = channel
number) on page 279.
Note added below Figure 82: PWM input mode timing and Figure 128: PWM input mode
timing.
FSMC_NWAIT signal direction corrected in Figure 185: FSMC block diagram on page 489.
Value to set modified for bit 6 in Table 114: FSMC_BCRx bit fields, Table 117:
FSMC_BCRx bit fields and Table 123: FSMC_BCRx bit fields. Table 130: 8-bit NAND
Flash, Table 131: 16-bit NAND Flash and Table 132: 16-bit PC Card modified. NWAIT and
INTR signals separated in Table 132: 16-bit PC Card. Note added in PWAITEN bit
definition in PC Card/NAND Flash control registers 2..4 (FSMC_PCR2..4) on page 533.
Bit definitions updated in FIFO status and interrupt register 2..4 (FSMC_SR2..4) on
page 534. Note modified in ADDHLD and ADDSET bit definitions in SRAM/NOR-Flash
23-Dec-2008 7 chip-select timing registers 1..4 (FSMC_BTR1..4) on page 521. Bit 8 is reserved in PC
Card/NAND Flash control registers 2..4 (FSMC_PCR2..4) on page 533.
MEMWAIT[15:8] bit definition modified in Common memory space timing register 2..4
(FSMC_PMEM2..4) on page 535.
ATTWAIT[15:8] bit definition modified in Attribute memory space timing registers 2..4
(FSMC_PATT2..4) on page 536.
Section 21.6.5: NAND Flash pre-wait functionality on page 529 modified. Figure 204:
NAND/PC Card controller timing for common memory access modified.
Note added below Table 100: NOR/PSRAM bank selection on page 491.
32-bit external memory access removed from Table 101: External memory address on
page 492 and note added.
Caution: added to Section 21.6.1: External memory interface signals.
NIOS16 description modified in Table 132: 16-bit PC Card on page 526.
Register description modified in Attribute memory space timing registers 2..4
(FSMC_PATT2..4) on page 536.
Resetting the password on page 731 step 2 corrected.
write_data signal modified in Figure 204: NAND/PC Card controller timing for common
memory access.
bxCAN main features on page 628 modified.
Section 26.3.8: Packet error checking on page 742 modified.
Section 31.6.3: Cortex™-M3 TAP modified.
DBG_TIMx_STOP positions modified in DBGMCU_CR on page 1068.
Small text changes.
Updated SPI table in Section 9.1.11: GPIO configurations for device peripherals on
page 161
Updated bit descriptions in Section 7.3.1: Clock control register (RCC_CR) on page 96
and Section 8.3.1: Clock control register (RCC_CR) on page 129
TIMERS:
TIM1&TIM8: Updated example and definition of DBL bits in Section 14.4.19: TIM1&TIM8
DMA control register (TIMx_DCR). Added example related to DMA burst feature and
description of DMAB bits in Section 14.4.20: TIM1&TIM8 DMA address for full transfer
(TIMx_DMAR).
TIM2 to TIM5: added example and updated definition of DBL bits in Section 15.4.17: TIMx
DMA control register (TIMx_DCR). Added example related to DMA burst feature and
description of DMAB bits in Section 15.4.18: TIMx DMA address for full transfer
(TIMx_DMAR). Updated definition of DBL bits in Section 15.4.17: TIMx DMA control
register (TIMx_DCR).
WWDG
Updated Section 20.2: WWDG main features.
Updated Section 20.3: WWDG functional description to remove paragraph related to
counter reload using EWI interrupt.
I2C:
Updated BERR bit description in Section 26.6.6: I2C Status register 1 (I2C_SR1).
17-May-2011 13 Updated Note 1 in Section 26.6.8: I2C Clock control register (I2C_CCR).
Added note 3 below Figure 269: Transfer sequence diagram for slave transmitter on
page 727. Added note below Figure 270: Transfer sequence diagram for slave receiver on
page 728. Modified Section : Closing slave communication on page 728. Modified STOPF,
ADDR, bit description in Section 26.6.6: I2C Status register 1 (I2C_SR1) on page 749.
Modified Section 26.6.7: I2C Status register 2 (I2C_SR2) on page 753.
USART:
Updated Figure 284: Mute mode using address mark detection for Address =1.
ETHERNET:
Removed TX_ETR signal from Figure 329: Media independent interface signals.
SPI:
Modified Slave select (NSS) pin management on page 676 and note on NSS in
Section 25.3.3: Configuring the SPI in master mode
USB OTG FS:
Added caution note related to minimum in Section 28.3.2: Full-speed OTG PHY.
FSMC:
Updated description of DATLAT , DATAST , and ADDSET bits in Section : SRAM/NOR-
Flash chip-select timing registers 1..4 (FSMC_BTR1..4).
Updated description of DATAST and ADDSET bits in Section : SRAM/NOR-Flash write
timing registers 1..4 (FSMC_BWTR1..4).
Index
A CAN_RIxR . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
CAN_TDHxR . . . . . . . . . . . . . . . . . . . . . . . . . 661
ADC_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . . .229
CAN_TDLxR . . . . . . . . . . . . . . . . . . . . . . . . . 661
ADC_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . . .231
CAN_TDTxR . . . . . . . . . . . . . . . . . . . . . . . . . 660
ADC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . .242
CAN_TIxR . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
ADC_HTR . . . . . . . . . . . . . . . . . . . . . . . . . . .237
CAN_TSR . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
ADC_JDRx . . . . . . . . . . . . . . . . . . . . . . . . . . .242
CRC_DR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
ADC_JOFRx . . . . . . . . . . . . . . . . . . . . . . . . .236
CRC_IDR . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
ADC_JSQR . . . . . . . . . . . . . . . . . . . . . . . . . .241
ADC_LTR . . . . . . . . . . . . . . . . . . . . . . . . . . . .237
ADC_SMPR1 . . . . . . . . . . . . . . . . . . . . . . . . .235 D
ADC_SMPR2 . . . . . . . . . . . . . . . . . . . . . . . . .236 DBGMCU_CR . . . . . . . . . . . . . . . . . . . . . . . 1068
ADC_SQR1 . . . . . . . . . . . . . . . . . . . . . . . . . .238 DBGMCU_IDCODE . . . . . . . . . . . . . . . . . . 1054
ADC_SQR2 . . . . . . . . . . . . . . . . . . . . . . . . . .239 DMA_CCRx . . . . . . . . . . . . . . . . . . . . . . . . . . 277
ADC_SQR3 . . . . . . . . . . . . . . . . . . . . . . . . . .240 DMA_CMARx . . . . . . . . . . . . . . . . . . . . . . . . 279
ADC_SR . . . . . . . . . . . . . . . . . . . . . . . . . . . . .228 DMA_CNDTRx . . . . . . . . . . . . . . . . . . . . . . . 278
AFIO_EVCR . . . . . . . . . . . . . . . . . . . . . . . . . .178 DMA_CPARx . . . . . . . . . . . . . . . . . . . . . . . . . 279
AFIO_EXTICR1 . . . . . . . . . . . . . . . . . . . . . . .185 DMA_IFCR . . . . . . . . . . . . . . . . . . . . . . . . . . 276
AFIO_EXTICR2 . . . . . . . . . . . . . . . . . . . . . . .185 DMA_ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
AFIO_EXTICR3 . . . . . . . . . . . . . . . . . . . . . . .186
AFIO_EXTICR4 . . . . . . . . . . . . . . . . . . . . . . .186
AFIO_MAPR . . . . . . . . . . . . . . . . . . . . . . . . .179 E
AFIO_MAPR2 . . . . . . . . . . . . . . . . . . . . . . . .187 ETH_DMABMR . . . . . . . . . . . . . . . . . . . . . . 1027
ETH_DMACHRBAR . . . . . . . . . . . . . . . . . . 1040
B ETH_DMACHRDR . . . . . . . . . . . . . . . . . . . 1039
ETH_DMACHTBAR . . . . . . . . . . . . . . . . . . 1040
BKP_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82 ETH_DMACHTDR . . . . . . . . . . . . . . . . . . . . 1039
BKP_CSR . . . . . . . . . . . . . . . . . . . . . . . . . . . .82 ETH_DMAIER . . . . . . . . . . . . . . . . . . . . . . . 1037
BKP_DRx . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81 ETH_DMAMFBOCR . . . . . . . . . . . . . . . . . . 1039
BKP_RTCCR . . . . . . . . . . . . . . . . . . . . . . . . . .81 ETH_DMAOMR . . . . . . . . . . . . . . . . . . . . . . 1033
ETH_DMARDLAR . . . . . . . . . . . . . . . . . . . . 1030
C ETH_DMARPDR . . . . . . . . . . . . . . . . . . . . . 1029
ETH_DMASR . . . . . . . . . . . . . . . . . . . . . . . 1031
CAN_BTR . . . . . . . . . . . . . . . . . . . . . . . . . . .657
ETH_DMATDLAR . . . . . . . . . . . . . . . . . . . . 1030
CAN_ESR . . . . . . . . . . . . . . . . . . . . . . . . . . .656
ETH_DMATPDR . . . . . . . . . . . . . . . . . . . . . 1029
CAN_FA1R . . . . . . . . . . . . . . . . . . . . . . . . . .667
ETH_MACA0HR . . . . . . . . . . . . . . . . . . . . . 1013
CAN_FFA1R . . . . . . . . . . . . . . . . . . . . . . . . .667
ETH_MACA0LR . . . . . . . . . . . . . . . . . . . . . 1014
CAN_FiRx . . . . . . . . . . . . . . . . . . . . . . . . . . .668
ETH_MACA1HR . . . . . . . . . . . . . . . . . . . . . 1014
CAN_FM1R . . . . . . . . . . . . . . . . . . . . . . . . . .666
ETH_MACA1LR . . . . . . . . . . . . . . . . . . . . . 1015
CAN_FMR . . . . . . . . . . . . . . . . . . . . . . . . . . .665
ETH_MACA2HR . . . . . . . . . . . . . . . . . . . . . 1015
CAN_FS1R . . . . . . . . . . . . . . . . . . . . . . . . . .666
ETH_MACA2LR . . . . . . . . . . . . . . . . . . . . . 1016
CAN_IER . . . . . . . . . . . . . . . . . . . . . . . . . . . .655
ETH_MACA3HR . . . . . . . . . . . . . . . . . . . . . 1016
CAN_MCR . . . . . . . . . . . . . . . . . . . . . . . . . . .648
ETH_MACA3LR . . . . . . . . . . . . . . . . . . . . . 1017
CAN_MSR . . . . . . . . . . . . . . . . . . . . . . . . . . .650
ETH_MACCR . . . . . . . . . . . . . . . . . . . . . . . 1001
CAN_RDHxR . . . . . . . . . . . . . . . . . . . . . . . . .664
ETH_MACFCR . . . . . . . . . . . . . . . . . . . . . . 1007
CAN_RDLxR . . . . . . . . . . . . . . . . . . . . . . . . .664
ETH_MACFFR . . . . . . . . . . . . . . . . . . . . . . 1004
CAN_RDTxR . . . . . . . . . . . . . . . . . . . . . . . . .663
ETH_MACHTHR . . . . . . . . . . . . . . . . . . . . . 1005
CAN_RF0R . . . . . . . . . . . . . . . . . . . . . . . . . .653
ETH_MACHTLR . . . . . . . . . . . . . . . . . . . . . 1006
CAN_RF1R . . . . . . . . . . . . . . . . . . . . . . . . . .654
ETH_MACIMR . . . . . . . . . . . . . . . . . . . . . . . 1013
P T
PWR_CR . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75 TIMx_ARR . . . . . . . . . . . . . . . 403, 439, 448, 461
PWR_CSR . . . . . . . . . . . . . . . . . . . . . . . . . . . .77 TIMx_BDTR . . . . . . . . . . . . . . . . . . . . . . . . . . 344
TIMx_CCER . . . . . . . . . . . . . 338, 401, 438, 447
TIMx_CCMR1 . . . . . . . . . . . . 334, 397, 435, 445
R
TIMx_CCMR2 . . . . . . . . . . . . . . . . . . . . 337, 400
RCC_AHBENR . . . . . . . . . . . . . . 108, 141, 149 TIMx_CCR1 . . . . . . . . . . . . . . 342, 404, 440, 449
RCC_APB1ENR . . . . . . . . . . . . . . . . . . .111, 144 TIMx_CCR2 . . . . . . . . . . . . . . . . . . 343, 404, 440
RCC_APB1RSTR . . . . . . . . . . . . . . . . .106, 138 TIMx_CCR3 . . . . . . . . . . . . . . . . . . . . . . 343, 405
RCC_APB2ENR . . . . . . . . . . . . . . . . . . .109, 142 TIMx_CCR4 . . . . . . . . . . . . . . . . . . . . . . 344, 405
RCC_APB2RSTR . . . . . . . . . . . . . . . . .103, 137 TIMx_CNT . . . . . . . . . . .341, 402, 439, 448, 460
RCC_BDCR . . . . . . . . . . . . . . . . . . . . . .115, 146 TIMx_CR1 . . . . . . . . . . .323, 388, 430, 442, 457
RCC_CFGR . . . . . . . . . . . . . . . . . . 98, 131, 150 TIMx_CR2 . . . . . . . . . . . . . . . . . . . 324, 390, 459
RCC_CIR . . . . . . . . . . . . . . . . . . . . . . . .101, 134 TIMx_DCR . . . . . . . . . . . . . . . . . . . . . . . 346, 406
RCC_CR . . . . . . . . . . . . . . . . . . . . . . . . .96, 129 TIMx_DIER . . . . . . . . . .329, 393, 432, 443, 459
RCC_CSR . . . . . . . . . . . . . . . . . . . . . . .117, 148 TIMx_DMAR . . . . . . . . . . . . . . . . . . . . . 347, 406
RTC_ALRH . . . . . . . . . . . . . . . . . . . . . . . . . .473 TIMx_EGR . . . . . . . . . . .332, 396, 434, 444, 460
RTC_ALRL . . . . . . . . . . . . . . . . . . . . . . . . . . .473 TIMx_PSC . . . . . . . . . . .341, 402, 439, 448, 461
RTC_CNTH . . . . . . . . . . . . . . . . . . . . . . . . . .472 TIMx_RCR . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
RTC_CNTL . . . . . . . . . . . . . . . . . . . . . . . . . .472 TIMx_SMCR . . . . . . . . . . . . . . . . . 327, 391, 431
RTC_CRH . . . . . . . . . . . . . . . . . . . . . . . . . . .468 TIMx_SR . . . . . . . . . . . .331, 394, 433, 443, 460
RTC_CRL . . . . . . . . . . . . . . . . . . . . . . . . . . . .469
RTC_DIVH . . . . . . . . . . . . . . . . . . . . . . . . . . .471
RTC_DIVL . . . . . . . . . . . . . . . . . . . . . . . . . . .471 U
RTC_PRLH . . . . . . . . . . . . . . . . . . . . . . . . . .470 USART_BRR . . . . . . . . . . . . . . . . . . . . . . . . . 792
RTC_PRLL . . . . . . . . . . . . . . . . . . . . . . . . . . .471 USART_CR1 . . . . . . . . . . . . . . . . . . . . . . . . . 793
USART_CR2 . . . . . . . . . . . . . . . . . . . . . . . . . 795
USART_CR3 . . . . . . . . . . . . . . . . . . . . . . . . . 796
S
USART_DR . . . . . . . . . . . . . . . . . . . . . . . . . . 792
SDIO_CLKCR . . . . . . . . . . . . . . . . . . . . . . . .582 USART_GTPR . . . . . . . . . . . . . . . . . . . . . . . 798
SDIO_DCOUNT . . . . . . . . . . . . . . . . . . . . . . .588 USART_SR . . . . . . . . . . . . . . . . . . . . . . . . . . 790
SDIO_DCTRL . . . . . . . . . . . . . . . . . . . . . . . .587 USB_ADDRn_RX . . . . . . . . . . . . . . . . . . . . . 624
SDIO_DLEN . . . . . . . . . . . . . . . . . . . . . . . . . .586 USB_ADDRn_TX . . . . . . . . . . . . . . . . . . . . . 623
SDIO_DTIMER . . . . . . . . . . . . . . . . . . . . . . . .586 USB_BTABLE . . . . . . . . . . . . . . . . . . . . . . . . 618
SDIO_FIFO . . . . . . . . . . . . . . . . . . . . . . . . . .595 USB_CNTR . . . . . . . . . . . . . . . . . . . . . . . . . . 612
SDIO_FIFOCNT . . . . . . . . . . . . . . . . . . . . . . .594 USB_COUNTn_RX . . . . . . . . . . . . . . . . . . . . 625
SDIO_ICR . . . . . . . . . . . . . . . . . . . . . . . . . . .590 USB_COUNTn_TX . . . . . . . . . . . . . . . . . . . . 624
SDIO_MASK . . . . . . . . . . . . . . . . . . . . . . . . .592 USB_DADDR . . . . . . . . . . . . . . . . . . . . . . . . 618
SDIO_POWER . . . . . . . . . . . . . . . . . . . . . . . .582 USB_EPnR . . . . . . . . . . . . . . . . . . . . . . . . . . 619
SDIO_RESPCMD . . . . . . . . . . . . . . . . . . . . .585 USB_FNR . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
SDIO_RESPx . . . . . . . . . . . . . . . . . . . . . . . . .585 USB_ISTR . . . . . . . . . . . . . . . . . . . . . . . . . . . 614
W
WWDG_CFR . . . . . . . . . . . . . . . . . . . . . . . . . 485
WWDG_CR . . . . . . . . . . . . . . . . . . . . . . . . . . 484
WWDG_SR . . . . . . . . . . . . . . . . . . . . . . . . . . 485
Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve the
right to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at any
time, without notice.
All ST products are sold pursuant to ST’s terms and conditions of sale.
Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes no
liability whatsoever relating to the choice, selection or use of the ST products and services described herein.
No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of this
document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products
or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such
third party products or services or any intellectual property contained therein.
UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED
WARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWS
OF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.
UNLESS EXPRESSLY APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES, ST PRODUCTS ARE NOT
RECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAINING
APPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY,
DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVE
GRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.
Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately void
any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, any
liability of ST.
Information in this document supersedes and replaces all information previously supplied.
The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.