STM32 RM
STM32 RM
STM32 RM
Reference manual
STM32F405/415, STM32F407/417, STM32F427/437 and
STM32F429/439 advanced Arm®-based 32-bit MCUs
Introduction
This reference manual targets application developers. It provides complete information on
how to use the STM32F405xx/07xx, STM32F415xx/17xx, STM32F42xxx and
STM32F43xxx microcontroller memory and peripherals.
The STM32F405xx/07xx, STM32F415xx/17xx, STM32F42xxx and STM32F43xxx constitute
a family of microcontrollers with different memory sizes, packages and peripherals.
For ordering information, mechanical and electrical device characteristics please refer to the
datasheets.
For information on the Arm® Cortex®-M4 with FPU core, please refer to the Cortex®-M4 with
FPU Technical Reference Manual.
Related documents
Available from STMicroelectronics web site (http://www.st.com):
• STM32F40x and STM32F41x datasheets
• STM32F42x and STM32F43x datasheets
• For information on the Arm® Cortex®-M4 with FPU, refer to the STM32F3xx/F4xxx
Cortex®-M4 with FPU programming manual (PM0214).
Contents
1 Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
1.1 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
1.2 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
1.3 Peripheral availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
6.3.16 RCC AHB2 peripheral clock enable in low power mode register
(RCC_AHB2LPENR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
6.3.17 RCC AHB3 peripheral clock enable in low power mode register
(RCC_AHB3LPENR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
6.3.18 RCC APB1 peripheral clock enable in low power mode register
(RCC_APB1LPENR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
6.3.19 RCC APB2 peripheral clock enabled in low power mode register
(RCC_APB2LPENR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
6.3.20 RCC Backup domain control register (RCC_BDCR) . . . . . . . . . . . . . . 199
6.3.21 RCC clock control & status register (RCC_CSR) . . . . . . . . . . . . . . . . 200
6.3.22 RCC spread spectrum clock generation register (RCC_SSCGR) . . . . 202
6.3.23 RCC PLLI2S configuration register (RCC_PLLI2SCFGR) . . . . . . . . . 203
6.3.24 RCC PLL configuration register (RCC_PLLSAICFGR) . . . . . . . . . . . . 206
6.3.25 RCC Dedicated Clock Configuration Register (RCC_DCKCFGR) . . . 207
6.3.26 RCC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
List of tables
Table 40. SYSCFG register map and reset values (STM32F405xx/07xx and STM32F415xx/17xx) 294
Table 41. SYSCFG register map and reset values (STM32F42xxx and STM32F43xxx) . . . . . . . . . 301
Table 42. DMA1 request mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Table 43. DMA2 request mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
Table 44. Source and destination address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Table 45. Source and destination address registers in Double buffer mode (DBM=1). . . . . . . . . . . 314
Table 46. Packing/unpacking & endian behavior (bit PINC = MINC = 1) . . . . . . . . . . . . . . . . . . . . . 315
Table 47. Restriction on NDT versus PSIZE and MSIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Table 48. FIFO threshold configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Table 49. Possible DMA configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
Table 50. DMA interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Table 51. DMA register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Table 52. Supported color mode in input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342
Table 53. Data order in memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Table 54. Alpha mode configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344
Table 55. Supported CLUT color mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Table 56. CLUT data order in memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Table 57. Supported color mode in output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Table 58. Data order in memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Table 59. DMA2D interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Table 60. DMA2D register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Table 61. Vector table for STM32F405xx/07xx and STM32F415xx/17xx. . . . . . . . . . . . . . . . . . . . . 372
Table 62. Vector table for STM32F42xxx and STM32F43xxx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Table 63. External interrupt/event controller register map and reset values. . . . . . . . . . . . . . . . . . . 387
Table 64. External interrupt/event controller register map and reset values. . . . . . . . . . . . . . . . . . . 387
Table 65. ADC pins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Table 66. Analog watchdog channel selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Table 67. Configuring the trigger polarity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Table 68. External trigger for regular channels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Table 69. External trigger for injected channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Table 70. ADC interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Table 71. ADC global register map. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Table 72. ADC register map and reset values for each ADC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
Table 73. ADC register map and reset values (common ADC registers) . . . . . . . . . . . . . . . . . . . . . 432
Table 74. DAC pins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Table 75. External triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Table 76. DAC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
Table 77. DCMI pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Table 78. DCMI signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
Table 79. Positioning of captured data bytes in 32-bit words (8-bit width) . . . . . . . . . . . . . . . . . . . . 458
Table 80. Positioning of captured data bytes in 32-bit words (10-bit width) . . . . . . . . . . . . . . . . . . . 458
Table 81. Positioning of captured data bytes in 32-bit words (12-bit width) . . . . . . . . . . . . . . . . . . . 459
Table 82. Positioning of captured data bytes in 32-bit words (14-bit width) . . . . . . . . . . . . . . . . . . . 459
Table 83. Data storage in monochrome progressive video format . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Table 84. Data storage in RGB progressive video format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Table 85. Data storage in YCbCr progressive video format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Table 86. DCMI interrupts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467
Table 87. DCMI register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
Table 88. LTDC registers versus clock domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
Table 89. LCD-TFT pins and signal interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
Table 90. Pixel Data mapping versus Color Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Table 91. LTDC interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
oversampling by 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 982
Table 138. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983
Table 139. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983
Table 140. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984
Table 141. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985
Table 142. Error calculation for programmed baud rates at fPCLK = 42 MHz or fPCLK = 84 Hz,
oversampling by 16. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 986
Table 143. Error calculation for programmed baud rates at fPCLK = 42 MHz or fPCLK = 84 MHz,
oversampling by 8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 987
Table 144. USART receiver’s tolerance when DIV fraction is 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 988
Table 145. USART receiver tolerance when DIV_Fraction is different from 0 . . . . . . . . . . . . . . . . . . 989
Table 146. Frame formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 991
Table 147. USART interrupt requests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1006
Table 148. USART mode configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1007
Table 149. USART register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1018
Table 150. SDIO I/O definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023
Table 151. Command format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1027
Table 152. Short response format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028
Table 153. Long response format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028
Table 154. Command path status flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1028
Table 155. Data token format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1031
Table 156. Transmit FIFO status flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1032
Table 157. Receive FIFO status flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033
Table 158. Card status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043
Table 159. SD status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1046
Table 160. Speed class code field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047
Table 161. Performance move field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047
Table 162. AU_SIZE field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048
Table 163. Maximum AU size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048
Table 164. Erase size field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048
Table 165. Erase timeout field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049
Table 166. Erase offset field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049
Table 167. Block-oriented write commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1051
Table 168. Block-oriented write protection commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1052
Table 169. Erase commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1052
Table 170. I/O mode commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
Table 171. Lock card . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
Table 172. Application-specific commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
Table 173. R1 response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1054
Table 174. R2 response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055
Table 175. R3 response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055
Table 176. R4 response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055
Table 177. R4b response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056
Table 178. R5 response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056
Table 179. R6 response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1057
Table 180. Response type and SDIO_RESPx registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1064
Table 181. SDIO register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1074
Table 182. Transmit mailbox mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1091
List of figures
Figure 150. Counter timing diagram, internal clock divided by 4, TIMx_ARR=0x36 . . . . . . . . . . . . . . 600
Figure 151. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Figure 152. Counter timing diagram, Update event with ARPE=1 (counter underflow). . . . . . . . . . . . 601
Figure 153. Counter timing diagram, Update event with ARPE=1 (counter overflow) . . . . . . . . . . . . . 601
Figure 154. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 602
Figure 155. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
Figure 156. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
Figure 157. External trigger input block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
Figure 158. Control circuit in external clock mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
Figure 159. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 605
Figure 160. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
Figure 161. Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 606
Figure 162. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 608
Figure 163. Output compare mode, toggle on OC1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
Figure 164. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
Figure 165. Center-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
Figure 166. Example of one-pulse mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
Figure 167. Clearing TIMx OCxREF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
Figure 168. Example of counter operation in encoder interface mode . . . . . . . . . . . . . . . . . . . . . . . . 617
Figure 169. Example of encoder interface mode with TI1FP1 polarity inverted . . . . . . . . . . . . . . . . . 617
Figure 170. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
Figure 171. Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
Figure 172. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
Figure 173. Control circuit in external clock mode 2 + trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . 621
Figure 174. Master/Slave timer example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
Figure 175. Gating timer 2 with OC1REF of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
Figure 176. Gating timer 2 with Enable of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
Figure 177. Triggering timer 2 with update of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
Figure 178. Triggering timer 2 with Enable of timer 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
Figure 179. Triggering timer 1 and 2 with timer 1 TI1 input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
Figure 180. General-purpose timer block diagram (TIM9 and TIM12) . . . . . . . . . . . . . . . . . . . . . . . . 651
Figure 181. General-purpose timer block diagram (TIM10/11/13/14) . . . . . . . . . . . . . . . . . . . . . . . . 652
Figure 182. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 654
Figure 183. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 654
Figure 184. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
Figure 185. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
Figure 186. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
Figure 187. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
Figure 188. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not preloaded) . . . . . 657
Figure 189. Counter timing diagram, update event when ARPE=1 (TIMx_ARR preloaded) . . . . . . . . 657
Figure 190. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 658
Figure 191. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
Figure 192. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
Figure 193. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 660
Figure 194. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
Figure 195. Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 661
Figure 196. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
Figure 197. Output compare mode, toggle on OC1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
Figure 198. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666
Figure 199. Example of one pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667
Figure 200. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
Figure 201. Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670
Figure 452. Synchronous multiplexed read mode - NOR, PSRAM (CRAM) . . . . . . . . . . . . . . . . . . . 1573
Figure 453. Synchronous multiplexed write mode - PSRAM (CRAM) . . . . . . . . . . . . . . . . . . . . . . . . 1575
Figure 454. NAND/PC Card controller timing for common memory access . . . . . . . . . . . . . . . . . . . 1588
Figure 455. Access to non ‘CE don’t care’ NAND-Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1589
Figure 456. FMC block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1604
Figure 457. FMC memory banks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1607
Figure 458. Mode1 read access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1618
Figure 459. Mode1 write access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1618
Figure 460. ModeA read access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1620
Figure 461. ModeA write access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1621
Figure 462. Mode2 and mode B read access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1623
Figure 463. Mode2 write access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1623
Figure 464. ModeB write access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1624
Figure 465. ModeC read access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1626
Figure 466. ModeC write access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1626
Figure 467. ModeD read access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1628
Figure 468. ModeD write access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1629
Figure 469. Muxed read access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1631
Figure 470. Muxed write access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1631
Figure 471. Asynchronous wait during a read access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . 1633
Figure 472. Asynchronous wait during a write access waveforms. . . . . . . . . . . . . . . . . . . . . . . . . . . 1634
Figure 473. Wait configuration waveforms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1636
Figure 474. Synchronous multiplexed read mode waveforms - NOR, PSRAM (CRAM) . . . . . . . . . . 1636
Figure 475. Synchronous multiplexed write mode waveforms - PSRAM (CRAM). . . . . . . . . . . . . . . 1638
Figure 476. NAND Flash/PC Card controller waveforms for common memory access. . . . . . . . . . . 1651
Figure 477. Access to non ‘CE don’t care’ NAND-Flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1652
Figure 478. Burst write SDRAM access waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1665
Figure 479. Burst read SDRAM access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1666
Figure 480. Logic diagram of Read access with RBURST bit set (CAS=2, RPIPE=0) . . . . . . . . . . . 1667
Figure 481. Read access crossing row boundary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1669
Figure 482. Write access crossing row boundary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1669
Figure 483. Self-refresh mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1672
Figure 484. Power-down mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1673
Figure 485. Block diagram of STM32 MCU and Cortex®-M4 with FPU-level debug support . . . . . . 1683
Figure 486. SWJ debug port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1685
Figure 487. JTAG TAP connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1689
Figure 488. TPIU block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1707
1 Documentation conventions
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
1.2 Glossary
This section gives a brief definition of acronyms and abbreviations used in this document:
• The CPU core integrates two debug ports:
– JTAG debug port (JTAG-DP) provides a 5-pin standard interface based on the
Joint Test Action Group (JTAG) protocol.
– SWD debug port (SWD-DP) provides a 2-pin (clock and data) interface based on
the Serial Wire Debug (SWD) protocol.
For both the JTAG and SWD protocols, please refer to the Cortex®-M4 with FPU
Technical Reference Manual
• Word: data/instruction of 32-bit length.
• Half word: data/instruction of 16-bit length.
• Byte: data of 8-bit length.
• Double word: data of 64-bit length.
• IAP (in-application programming): IAP is the ability to reprogram the Flash memory of a
microcontroller while the user program is running.
• ICP (in-circuit programming): ICP is the ability to program the Flash memory of a
microcontroller using the JTAG protocol, the SWD protocol or the bootloader while the
device is mounted on the user application board.
• I-Code: this bus connects the Instruction bus of the CPU core to the Flash instruction
interface. Prefetch is performed on this bus.
• D-Code: this bus connects the D-Code bus (literal load and debug access) of the CPU
to the Flash data interface.
• Option bytes: product configuration bits stored in the Flash memory.
• OBL: option byte loader.
• AHB: advanced high-performance bus.
• CPU: refers to the Cortex®-M4 with FPU core.
DMA_P1
I-bus
USB_HS_M
DMA_MEM1
DMA_MEM2
D-bus
DMA_P2
ETHERNET_M
S-bus
ICODE
Flash
ACCEL
DCODE memory
SRAM1
112 Kbyte
SRAM2
16 Kbyte
AHB1
peripherals APB1
AHB2
peripherals
APB2
FSMC
Static MemCtl
Bus matrix-S
ai18490e
In the STM32F42xx and STM32F43xx devices, the main system consists of 32-bit multilayer
AHB bus matrix that interconnects:
• Ten masters:
– Cortex®-M4 with FPU core I-bus, D-bus and S-bus
– DMA1 memory bus
– DMA2 memory bus
– DMA2 peripheral bus
– Ethernet DMA bus
– USB OTG HS DMA bus
– LCD Controller DMA-bus
– DMA2D (Chrom-Art Accelerator™) memory bus
• Eight slaves:
– Internal Flash memory ICode bus
– Internal Flash memory DCode bus
– Main internal SRAM1 (112 KB)
– Auxiliary internal SRAM2 (16 KB)
– Auxiliary internal SRAM3 (64 KB)
– AHB1peripherals including AHB to APB bridges and APB peripherals
– AHB2 peripherals
– FMC
The bus matrix provides access from a master to a slave, enabling concurrent access and
efficient operation even when several high-speed peripherals work simultaneously. The 64-
Kbyte CCM (core coupled memory) data RAM is not part of the bus matrix and can be
accessed only through the CPU. This architecture is shown in Figure 2.
DMA_P1
I-bus
D-bus
S-bus
DMA2D
DMA_MEM1
DMA_MEM2
DMA_P2
USB_HS_M
LCD-TFT_M
ETHERNET_M
ICODE
Flash
ACCEL
DCODE memory
SRAM1
112 Kbyte
SRAM2
16 Kbyte
SRAM3
64 Kbyte
AHB2 APB1
peripherals
AHB1
peripherals APB2
FMC external
MemCtl
Bus matrix-S
MS30421V7
2.1.1 I-bus
This bus connects the Instruction bus of the Cortex®-M4 with FPU core to the BusMatrix.
This bus is used by the core to fetch instructions. The target of this bus is a memory
containing code (internal Flash memory/SRAM or external memories through the
FSMC/FMC).
2.1.2 D-bus
This bus connects the databus of the Cortex®-M4 with FPU to the 64-Kbyte CCM data RAM
to the BusMatrix. This bus is used by the core for literal load and debug access. The target
of this bus is a memory containing code or data (internal Flash memory or external
memories through the FSMC/FMC).
2.1.3 S-bus
This bus connects the system bus of the Cortex®-M4 with FPU core to a BusMatrix. This
bus is used to access data located in a peripheral or in SRAM. Instructions may also be
fetched on this bus (less efficient than ICode). The targets of this bus are the internal
SRAM1, SRAM2 and SRAM3, the AHB1 peripherals including the APB peripherals, the
AHB2 peripherals and the external memories through the FSMC/FMC.
2.1.10 BusMatrix
The BusMatrix manages the access arbitration between masters. The arbitration uses a
round-robin algorithm.
0x5006 0800 - 0x5006 0BFF RNG Section 24.4.4: RNG register map on page 771
0x5006 0400 - 0x5006 07FF HASH Section 25.4.9: HASH register map on page 795
0x5006 0000 - 0x5006 03FF CRYP Section 23.6.13: CRYP register map on page 763
AHB2
0x5005 0000 - 0x5005 03FF DCMI Section 15.8.12: DCMI register map on page 478
Section 34.16.6: OTG_FS register map on
0x5000 0000 - 0x5003 FFFF USB OTG FS
page 1326
Section 35.12.6: OTG_HS register map on
0x4004 0000 - 0x4007 FFFF USB OTG HS
page 1472
0x4002 B000 - 0x4002 BBFF DMA2D Section 11.5: DMA2D registers on page 352
Section 33.8.5: Ethernet register maps on
0x4002 8000 - 0x4002 93FF ETHERNET MAC
page 1236
0x4002 6400 - 0x4002 67FF DMA2
Section 10.5.11: DMA register map on page 335
0x4002 6000 - 0x4002 63FF DMA1
0x4002 4000 - 0x4002 4FFF BKPSRAM
Flash interface
0x4002 3C00 - 0x4002 3FFF Section 3.9: Flash interface registers
register
0x4002 3800 - 0x4002 3BFF RCC Section 7.3.24: RCC register map on page 265
0x4002 3000 - 0x4002 33FF CRC Section 4.4.4: CRC register map on page 115
AHB1
0x4002 2800 - 0x4002 2BFF GPIOK
Section 8.4.11: GPIO register map on page 287
0x4002 2400 - 0x4002 27FF GPIOJ
0x4002 2000 - 0x4002 23FF GPIOI
0x4002 1C00 - 0x4002 1FFF GPIOH
0x4002 1800 - 0x4002 1BFF GPIOG
0x4002 1400 - 0x4002 17FF GPIOF
0x4002 1000 - 0x4002 13FF GPIOE Section 8.4.11: GPIO register map on page 287
0x4002 0C00 - 0x4002 0FFF GPIOD
0x4002 0800 - 0x4002 0BFF GPIOC
0x4002 0400 - 0x4002 07FF GPIOB
0x4002 0000 - 0x4002 03FF GPIOA
0x4001 6800 - 0x4001 6BFF LCD-TFT Section 16.7.26: LTDC register map on page 512
APB2
0x4001 5800 - 0x4001 5BFF SAI1 Section 29.17.9: SAI register map on page 963
0x4001 5400 - 0x4001 57FF SPI6
APB2 Section 28.5.10: SPI register map on page 925
0x4001 5000 - 0x4001 53FF SPI5
0x4001 4800 - 0x4001 4BFF TIM11 Section 19.5.12: TIM10/11/13/14 register map on
0x4001 4400 - 0x4001 47FF TIM10 page 694
0x4000 7400 - 0x4000 77FF DAC Section 14.5.15: DAC register map on page 453
0x4000 7000 - 0x4000 73FF PWR Section 5.6: PWR register map on page 149
0x4000 6800 - 0x4000 6BFF CAN2
Section 32.9.5: bxCAN register map on page 1118
0x4000 6400 - 0x4000 67FF CAN1
0x4000 5C00 - 0x4000 5FFF I2C3
0x4000 5800 - 0x4000 5BFF I2C2 Section 27.6.11: I2C register map on page 872
0x4000 5400 - 0x4000 57FF I2C1
0x4000 5000 - 0x4000 53FF UART5
0x4000 4C00 - 0x4000 4FFF UART4
Section 30.6.8: USART register map on page 1018
0x4000 4800 - 0x4000 4BFF USART3
0x4000 4400 - 0x4000 47FF USART2
0x4000 4000 - 0x4000 43FF I2S3ext
0x4000 3C00 - 0x4000 3FFF SPI3 / I2S3
Section 28.5.10: SPI register map on page 925
0x4000 3800 - 0x4000 3BFF SPI2 / I2S2
APB1
0x4000 3400 - 0x4000 37FF I2S2ext
0x4000 3000 - 0x4000 33FF IWDG Section 21.4.5: IWDG register map on page 712
0x4000 2C00 - 0x4000 2FFF WWDG Section 22.6.4: WWDG register map on page 719
0x4000 2800 - 0x4000 2BFF RTC & BKP Registers Section 26.6.21: RTC register map on page 836
0x4000 2000 - 0x4000 23FF TIM14 Section 19.5.12: TIM10/11/13/14 register map on
0x4000 1C00 - 0x4000 1FFF TIM13 page 694
are only available for Cortex®-M4 with FPU accesses, and not from other bus masters (e.g.
DMA).
A mapping formula shows how to reference each word in the alias region to a corresponding
bit in the bit-band region. The mapping formula is:
bit_word_addr = bit_band_base + (byte_offset x 32) + (bit_number × 4)
where:
– bit_word_addr is the address of the word in the alias memory region that maps to
the targeted bit
– bit_band_base is the starting address of the alias region
– byte_offset is the number of the byte in the bit-band region that contains the
targeted bit
– bit_number is the bit position (0-7) of the targeted bit
Example
The following example shows how to map bit 2 of the byte located at SRAM address
0x20000300 to the alias region:
0x22006008 = 0x22000000 + (0x300*32) + (2*4)
Writing to address 0x22006008 has the same effect as a read-modify-write operation on bit
2 of the byte at SRAM address 0x20000300.
Reading address 0x22006008 returns the value (0x01 or 0x00) of bit 2 of the byte at SRAM
address 0x20000300 (0x01: bit set; 0x00: bit reset).
For more information on bit-banding, please refer to the Cortex®-M4 with FPU programming
manual (see Related documents on page 1).
x 0 Main Flash memory Main Flash memory is selected as the boot space
0 1 System memory System memory is selected as the boot space
1 1 Embedded SRAM Embedded SRAM is selected as the boot space
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.
BOOT0 is a dedicated pin while BOOT1 is shared with a GPIO pin. Once BOOT1 has been
sampled, the corresponding GPIO pin is free and can be used for other purposes.
The BOOT pins are also resampled when the device exits the Standby mode. Consequently,
they must be kept in the required Boot mode configuration when the device is in the Standby
mode. After this startup delay is over, the CPU fetches the top-of-stack value from address
0x0000 0000, then starts code execution from the boot memory starting from 0x0000 0004.
Note: When the device boots from SRAM, in the application initialization code, you have to
relocate the vector table in SRAM using the NVIC exception table and the offset register.
In STM32F42xxx and STM32F43xxx devices, when booting from the main Flash memory,
the application software can either boot from bank 1 or from bank 2. By default, boot from
bank 1 is selected.
To select boot from Flash memory bank 2, set the BFB2 bit in the user option bytes. When
this bit is set 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.
Embedded bootloader
The embedded bootloader mode is used to reprogram the Flash memory using one of the
following serial interfaces:
• USART1 (PA9/PA10)
• USART3 (PB10/11 and PC10/11)
• CAN2 (PB5/13)
• USB OTG FS (PA11/12) in Device mode (DFU: device firmware upgrade).
The USART peripherals operate at the internal 16 MHz oscillator (HSI) frequency, while the
CAN and USB OTG FS require an external clock (HSE) multiple of 1 MHz (ranging from 4 to
26 MHz).
The embedded bootloader code is located in system memory. It is programmed by ST
during production. For additional information, refer to application note AN2606.
0x2001 C000 - 0x2001 FFFF SRAM2 (16 KB) SRAM2 (16 KB) SRAM2 (16 KB) SRAM2 (16 KB)
0x2000 0000 - 0x2001 BFFF SRAM1 (112 KB) SRAM1 (112 KB) SRAM1 (112 KB) SRAM1 (112 KB)
0x1FFF 0000 - 0x1FFF 77FF System memory System memory System memory System memory
0x0810 0000 - 0x0FFF FFFF Reserved Reserved Reserved Reserved
0x0800 0000 - 0x080F FFFF Flash memory Flash memory Flash memory Flash memory
FSMC bank 1
0x0400 0000 - 0x07FF FFFF Reserved Reserved Reserved NOR/PSRAM 2
(128 MB Aliased)
FSMC bank 1
0x0000 0000 - SRAM1 (112 KB) System memory
Flash (1 MB) Aliased NOR/PSRAM 1
0x000F FFFF(1)(2) Aliased (30 KB) Aliased
(128 MB Aliased)
1. When the FSMC is remapped at address 0x0000 0000, only the first two regions of bank 1 memory controller (bank 1
NOR/PSRAM 1 and NOR/PSRAM 2) can be remapped. In remap mode, the CPU can access the external memory via
ICode bus instead of System bus which boosts up the performance.
2. Even when aliased in the boot memory space, the related memory is still accessible at its original memory space.
0x2002 0000 - 0x2002 FFFF SRAM3 (64 KB) SRAM3 (64 KB) SRAM3 (64 KB) SRAM3 (64 KB)
0x2001 C000 - 0x2001 FFFF SRAM2 (16 KB) SRAM2 (16 KB) SRAM2 (16 KB) SRAM2 (16 KB)
0x2000 0000 - 0x2001 BFFF SRAM1 (112 KB) SRAM1 (112 KB) SRAM1 (112 KB) SRAM1 (112 KB)
0x1FFF 0000 - 0x1FFF 77FF System memory System memory System memory System memory
0x0810 0000 - 0x0FFF FFFF Reserved Reserved Reserved Reserved
0x0800 0000 - 0x081F FFFF Flash memory Flash memory Flash memory Flash memory
FMC bank 1
0x0400 0000 - 0x07FF FFFF Reserved Reserved Reserved NOR/PSRAM 2
(128 MB Aliased)
FMC bank 1
NOR/PSRAM 1
0x0000 0000 - SRAM1 (112 KB) System memory (128 MB Aliased)
Flash (2 MB) Aliased
0x001F FFFF(1)(2) Aliased (30 KB) Aliased or FMC SDRAM
bank 1 (128 MB
Aliased)
1. When the FMC is remapped at address 0x0000 0000, only the first two regions of bank 1 memory controller (bank 1
NOR/PSRAM 1 and NOR/PSRAM 2) or SDRAM bank 1 can be remapped. In remap mode, the CPU can access the
external memory via ICode bus instead of System bus which boosts up the performance.
2. Even when aliased in the boot memory space, the related memory is still accessible at its original memory space.
3.1 Introduction
The Flash memory interface manages CPU AHB I-Code and D-Code accesses to the Flash
memory. It implements the erase and program Flash memory operations and the read and
write protection mechanisms.
The Flash memory interface accelerates code execution with a system of instruction
prefetch and cache lines.
AHB
USB HS periph2
Ethernet
MS30468V3
AHB
CCM data periph1
AHB
RAM
32-bit
DMA1 system bus SRAM and
external
DMA2
memories
DMA2D AHB
periph2
LCD-TFT
USB HS
Ethernet
Table 6. Flash module - 2 Mbyte dual bank organization (STM32F42xxx and STM32F43xxx)
Block Bank Name Block base addresses Size
DB1M=0 DB1M=1
Main memory Sector number Sector size Main memory Sector number Sector size
Sector 0 16 Kbytes Sector 0 16 Kbytes
Sector 1 16 Kbytes Sector 1 16 Kbytes
Sector 2 16 Kbytes Sector 2 16 Kbytes
Sector 3 16 Kbytes Bank 1 Sector 3 16 Kbytes
Sector 4 64 Kbytes 512KB Sector 4 64 Kbytes
Sector 5 128 Kbytes Sector 5 128 Kbytes
Sector 6 128 Kbytes Sector 6 128 Kbytes
Sector 7 128 Kbytes Sector 7 128 Kbytes
1MB
Sector 8 128 Kbytes Sector 12 16 Kbytes
Sector 9 128 Kbytes Sector 13 16 Kbytes
Sector 10 128 Kbytes Sector 14 16 Kbytes
Sector 11 128 Kbytes Bank 2 Sector 15 16 Kbytes
- - 512KB Sector 16 64 Kbytes
- - Sector 17 128 Kbytes
- - Sector 18 128 Kbytes
- - Sector 19 128 Kbytes
Table 9. 1 Mbyte dual bank Flash memory organization (STM32F42xxx and STM32F43xxx)
Block Name Block base addresses Size
3.5.1 Relation between CPU clock frequency and Flash memory read time
To correctly read data from Flash memory, the number of wait states (LATENCY) must be
correctly programmed in the Flash access control register (FLASH_ACR) according to the
frequency of the CPU clock (HCLK) and the supply voltage of the device.
The prefetch buffer must be disabled when the supply voltage is below 2.1 V. The
correspondence between wait states and CPU clock frequency is given in Table 10 and
Table 11.
Note: On STM32F405xx/07xx and STM32F415xx/17xx devices:
- when VOS = '0', the maximum value of fHCLK = 144 MHz.
- when VOS = '1', the maximum value of fHCLK = 168 MHz.
On STM32F42xxx and STM32F43xxx devices:
- when VOS[1:0] = '0x01', the maximum value of fHCLK is 120 MHz.
- when VOS[1:0] = '0x10', the maximum value of fHCLK is 144 MHz. It can be extended to
168 MHz by activating the over-drive mode.
- when VOS[1:0] = '0x11, the maximum value of fHCLK is 168 MHz. It can be extended to
180 MHz by activating the over-drive mode.
- The over-drive mode is not available when VDD ranges from 1.8 to 2.1 V.
Refer to Section 5.1.4: Voltage regulator for STM32F42xxx and STM32F43xxx for details on
how to activate the over-drive mode.
Table 10. Number of wait states according to CPU clock (HCLK) frequency
(STM32F405xx/07xx and STM32F415xx/17xx)
HCLK (MHz)
Wait states (WS) Voltage range
(LATENCY) Voltage range Voltage range Voltage range
1.8 V - 2.1 V
2.7 V - 3.6 V 2.4 V - 2.7 V 2.1 V - 2.4 V
Prefetch OFF
0 WS (1 CPU cycle) 0 < HCLK ≤ 30 0 < HCLK ≤ 24 0 < HCLK ≤ 22 0 < HCLK ≤ 20
1 WS (2 CPU cycles) 30 < HCLK ≤ 60 24 < HCLK ≤ 48 22 < HCLK ≤ 44 20 <HCLK ≤ 40
2 WS (3 CPU cycles) 60 < HCLK ≤ 90 48 < HCLK ≤ 72 44 < HCLK ≤ 66 40 < HCLK ≤ 60
3 WS (4 CPU cycles) 90 < HCLK ≤ 120 72 < HCLK ≤ 96 66 < HCLK ≤ 88 60 < HCLK ≤ 80
4 WS (5 CPU cycles) 120 < HCLK ≤ 150 96 < HCLK ≤ 120 88 < HCLK ≤ 110 80 < HCLK ≤ 100
5 WS (6 CPU cycles) 150 < HCLK ≤ 168 120 < HCLK ≤ 144 110 < HCLK ≤ 132 100 < HCLK ≤ 120
6 WS (7 CPU cycles) 144 < HCLK ≤ 168 132 < HCLK ≤ 154 120 < HCLK ≤ 140
7 WS (8 CPU cycles) 154 < HCLK ≤ 168 140 < HCLK ≤ 160
Table 11. Number of wait states according to CPU clock (HCLK) frequency
(STM32F42xxx and STM32F43xxx)
HCLK (MHz)
Wait states (WS) Voltage range
(LATENCY) Voltage range Voltage range Voltage range
1.8 V - 2.1 V
2.7 V - 3.6 V 2.4 V - 2.7 V 2.1 V - 2.4 V
Prefetch OFF
After reset, the CPU clock frequency is 16 MHz and 0 wait state (WS) is configured in the
FLASH_ACR register.
It is highly recommended to use the following software sequences to tune the number of
wait states needed to access the Flash memory with the CPU frequency.
Note: A change in CPU clock configuration or wait state (WS) configuration may not be effective
straight away. To make sure that the current CPU clock frequency is the one you have
configured, you can check the AHB prescaler factor and clock source status values. To
make sure that the number of WS you have programmed is effective, you can read the
FLASH_ACR register.
Instruction prefetch
Each Flash memory read operation provides 128 bits from either four instructions of 32 bits
or 8 instructions of 16 bits according to the program launched. So, in case of sequential
code, at least four CPU cycles are needed to execute the previous read instruction line.
Prefetch on the I-Code bus can be used to read the next sequential instruction line from the
Flash memory while the current instruction line is being requested by the CPU. Prefetch is
enabled by setting the PRFTEN bit in the FLASH_ACR register. This feature is useful if at
least one wait state is needed to access the Flash memory.
Figure 5 shows the execution of sequential 32-bit instructions with and without prefetch
when 3 WSs are needed to access the Flash memory.
@ F D E
WAIT
1 1 1 1
Without prefetch
@ F D E
2 2 2 2
@ F D E
3 3 3 3
@ F D E
4 4 4 4
@ F D E
WAIT
5 5 5 5
@ F D E
6 6 6 6
@ F D
7 7 7
@ F
8 8
@ Wait data F D E
1 1 1 1 With prefetch
@ F D E
2 2 2 2
@ F D E
3 3 3 3
@ F D E
4 4 4 4
@ F D E
5 5 5 5
@ F D E
6 6 6
@ F D Cortex-M4 pipeline
7 7 7
@ F
@ F D E
8 8
AHB protocol
ins 1 ins 2 ins 3 ins 4 ins 5 ins 6 ins 7 ins 8
fetch fetch fetch fetch fetch fetch fetch fetch @ : address requested
F: Fetch stage
D: Decode stage
Read ins 1, 2, 3, 4 Gives ins 1, 2, 3, 4 Gives ins 5, 6, 7, 8 E: Execute stage
MS31831V1
When the code is not sequential (branch), the instruction may not be present in the currently
used instruction line or in the prefetched instruction line. In this case (miss), the penalty in
terms of number of cycles is at least equal to the number of wait states.
Data management
Literal pools are fetched from Flash memory through the D-Code bus during the execution
stage of the CPU pipeline. The CPU pipeline is consequently stalled until the requested
literal pool is provided. To limit the time lost due to literal pools, accesses through the AHB
databus D-Code have priority over accesses through the AHB instruction bus I-Code.
If some literal pools are frequently used, the data cache memory can be enabled by setting
the data cache enable (DCEN) bit in the FLASH_ACR register. This feature works like the
instruction cache memory, but the retained data size is limited to 8 rows of 128 bits.
Note: Data in user configuration sector are not cacheable.
Note: The FLASH_CR register is not accessible in write mode when the BSY bit in the FLASH_SR
register is set. Any attempt to write to it with the BSY bit set will cause the AHB bus to stall
until the BSY bit is cleared.
Note: Any program or erase operation started with inconsistent program parallelism/voltage range
settings may lead to unpredicted results. Even if a subsequent read operation indicates that
the logical value was effectively written to the memory, this value may not be retained.
To use VPP, an external high-voltage supply (between 8 and 9 V) must be applied to the VPP
pad. The external supply must be able to sustain this voltage range even if the DC
consumption exceeds 10 mA. It is advised to limit the use of VPP to initial programming on
the factory line. The VPP supply must not be applied for more than an hour, otherwise the
Flash memory might be damaged.
3.6.3 Erase
The Flash memory erase operation can be performed at sector level or on the whole Flash
memory (Mass Erase). Mass Erase does not affect the OTP sector or the configuration
sector.
Sector Erase
To erase a sector, follow the procedure below:
1. Check that no Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register
2. Set the SER bit and select the sector out of the 12 sectors (for STM32F405xx/07xx and
STM32F415xx/17xx) and out of 24 (for STM32F42xxx and STM32F43xxx) in the main
memory block you wish to erase (SNB) in the FLASH_CR register
3. Set the STRT bit in the FLASH_CR register
4. Wait for the BSY bit to be cleared
Mass Erase
To perform Mass Erase, the following sequence is recommended:
1. Check that no Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register
2. Set the MER bit in the FLASH_CR register (on STM32F405xx/07xx and
STM32F415xx/17xx devices)
3. Set both the MER and MER1 bits in the FLASH_CR register (on STM32F42xxx and
STM32F43xxx devices).
4. Set the STRT bit in the FLASH_CR register
5. Wait for the BSY bit to be cleared
Note: If MERx and SER bits are both set in the FLASH_CR register, mass erase is performed.
If both MERx and SER bits are reset and the STRT bit is set, an unpredictable behavior may
occur without generating any error flag. This condition should be forbidden.
3.6.4 Programming
Standard programming
The Flash memory programming sequence is as follows:
1. Check that no main Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register.
2. Set the PG bit in the FLASH_CR register
3. Perform the data write operation(s) to the desired memory address (inside main
memory block or OTP area):
– Byte access in case of x8 parallelism
– Half-word access in case of x16 parallelism
– Word access in case of x32 parallelism
– Double word access in case of x64 parallelism
4. Wait for the BSY bit to be cleared.
Note: Successive write operations are possible without the need of an erase operation when
changing bits from ‘1’ to ‘0’. Writing ‘1’ requires a Flash memory erase operation.
If an erase and a program operation are requested simultaneously, the erase operation is
performed first.
Programming errors
It is not allowed to program data to the Flash memory that would cross the 128-bit row
boundary. In such a case, the write operation is not performed and a program alignment
error flag (PGAERR) is set in the FLASH_SR register.
The write access type (byte, half-word, word or double word) must correspond to the type of
parallelism chosen (x8, x16, x32 or x64). If not, the write operation is not performed and a
program parallelism error flag (PGPERR) is set in the FLASH_SR register.
If the standard programming sequence is not respected (for example, if there is an attempt
to write to a Flash memory address when the PG bit is not set), the operation is aborted and
a program sequence error flag (PGSERR) is set in the FLASH_SR register.
1. Check that no Flash memory operation is ongoing by checking the BSY bit in the
FLASH_SR register (BSY is active when erase/program operation is on going on bank
1 or bank 2)
2. Set the PG bit in the FLASH_CR register
3. Perform the data write operation(s) to the desired memory address inside main
memory block or OTP area
4. Wait for the BSY bit to be reset.
3.6.6 Interrupts
Setting the end of operation interrupt enable bit (EOPIE) in the FLASH_CR register enables
interrupt generation when an erase or program operation ends, that is when the busy bit
(BSY) in the FLASH_SR register is cleared (operation completed, correctly or not). In this
case, the end of operation (EOP) bit in the FLASH_SR register is set.
If an error occurs during a program, an erase, or a read operation request, one of the
following error flags is set in the FLASH_SR register:
• PGAERR, PGPERR, PGSERR (Program error flags)
• WRPERR (Protection error flag)
• RDERR (Read protection error flag) for STM32F42xxx and STM32F43xxx devices
only.
In this case, if the error interrupt enable bit (ERRIE) is set in the FLASH_CR register, an
interrupt is generated and the operation error bit (OPERR) is set in the FLASH_SR register.
Note: If several successive errors are detected (for example, in case of DMA transfer to the Flash
memory), the error flags cannot be cleared until the end of the successive write requests.
0x1FFF C000 Reserved ROP & user option bytes (RDP & USER)
SPRMOD and Write protection nWRP bits for
0x1FFF C008 Reserved
sectors 0 to 11
Bit 15:8 0xCC: Level 2, chip protection (debug and boot from RAM features
disabled)
Others: Level 1, read protection of memories (debug features limited)
USER: User option byte
This byte is used to configure the following features:
Select the watchdog event: Hardware or software
Reset event when entering the Stop mode
Reset event when entering the Standby mode
nRST_STDBY
Bit 7 0: Reset generated when entering the Standby mode
1: No reset generated
nRST_STOP
Bit 6 0: Reset generated when entering the Stop mode
1: No reset generated
WDG_SW
Bit 5 0: Hardware independent watchdog
1: Software independent watchdog
BFB2: Dual bank boot
0: Boot from Flash memory bank 1 or system memory depending on boot pin
Bit 4
state (Default).
1: Boot always from system memory (Dual bank boot mode).
Note: The value of an option byte is automatically modified by first erasing the user configuration
sector (bank 1 and 2) and then programming all the option bytes with the values contained
in the FLASH_OPTCR and FLASH_OPTCR1 registers.
--
Level 1
RDP /= AAh
RDP /= CCh
Write options default Write options
including including
RDP = CCh Write options including RDP = AAh
RDP /= CCh & /= AAh
Level 2 Level 0
RDP = CCh Write options RDP = AAh
including
RDP = CCh
RDP = AAh
Options write (RDP level increase) includes Others option(s) modified
- Options erase
- New options program
Options write (RDP level decrease) includes Options write (RDP level identical) includes
- Mass erase - Options erase
- Options erase - New options program
- New options program
MS47541V1
When a sector is readout protected (PCROP mode activated), it can only be accessed for
code fetch through ICODE Bus on Flash interface:
• Any read access performed through the D-bus triggers a RDERR flag error.
• Any program/erase operation on a PCROPed sector triggers a WRPERR flag error.
Write options
SPMOD = active
and valid nWRPi*
Level 1
RDP /= 0xAA
RDP /= 0xCC
Write options default Write options No restriction on
SPMOD = active SPMOD = active Write options
and valid nWRPi* and valid nWRPi*
Level 2 Level 0
RDP = 0xCC RDP = 0xAA
Write options
SPMOD = active
Write options
and valid nWRPi*
SPMOD = active
User option sector erase and valid nWRPi*
Program new options
The deactivation of the SPRMOD and/or the unprotection of PCROPed user sectors can
only occur when, at the same time, the RDP level changes from 1 to 0. If this condition is not
respected, the user option byte modification is cancelled and the write error WRPERR flag
is set. The modification of the users option bytes (BOR_LEV, RST_STDBY, ..) is allowed
since none of the active nWRPi bits is reset and SPRMOD is kept active.
Note: The active value of nWRPi bits is inverted when PCROP mode is active (SPRMOD =1).
If SPRMOD = 1 and nWRPi =1, then user sector i of bank 1, respectively bank 2 is
read/write protected (PCROP).
The OTP area is divided into 16 OTP data blocks of 32 bytes and one lock OTP block of 16
bytes. The OTP data and lock blocks cannot be erased. The lock block contains 16 bytes
LOCKBi (0 ≤ i ≤ 15) to lock the corresponding OTP data block (blocks 0 to 15). Each OTP
data block can be programmed until the value 0x00 is programmed in the corresponding
OTP lock byte. The lock bytes must only contain 0x00 and 0xFF values, otherwise the OTP
bytes might not be taken into account correctly.
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
DCRST ICRST DCEN ICEN PRFTEN LATENCY[2:0]
Reserved Reserved
rw w 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
DCRST ICRST DCEN ICEN PRFTEN LATENCY[3:0]
Reserved Reserved
rw w rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
KEY[31:16]
w w w w w w w w w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
KEY[15:0]
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OPTKEYR[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
OPTKEYR[15:0]
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BSY
Reserved
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PGSERR PGPERR PGAERR WRPERR OPERR EOP
Reserved Reserved
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BSY
Reserved
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RDERR PGSERR PGPERR PGAERR WRPERR OPERR EOP
Reserved Reserved
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LOCK ERRIE EOPIE STRT
Reserved Reserved
rs rw rw rs
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSIZE[1:0] SNB[3:0] MER SER PG
Reserved Res.
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LOCK ERRIE EOPIE STRT
Reserved Reserved
rs rw rw rs
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MER1 PSIZE[1:0] SNB[4:0] MER SER PG
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
nWRP[11:0]
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
nRST_ nRST_ WDG_ OPTST OPTLO
RDP[7:0] Reserve BOR_LEV
STDBY STOP SW RT CK
d
rw rw rw rw rw rw rw rw rw rw rw rw rw rs rs
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SPR
DB1M nWRP[11:0]
MOD Reserved
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
nRST_ nRST_ WDG_ OPTST OPTLO
RDP[7:0] BFB2 BOR_LEV
STDBY STOP SW RT CK
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rs rs
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
nWRP[11:0]
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
Reserved
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PRFTEN
DCRST
ICRST
DCEN
ICEN
LATENCY
FLASH_ACR
[2:0]
0x00 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0
FLASH_
KEY[31:16] KEY[15:0]
KEYR
0x04
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FLASH_OPT
OPTKEYR[31:16] OPTKEYR[15:0]
KEYR
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
WRPERR
PGSERR
PGPERR
PGAERR
OPERR
Reserved
EOP
BSY
FLASH_SR
0x0C Reserved Reserved
Reset value 0 0 0 0 0 0 0
PSIZE[1:0]
EOPIE
LOCK
STRT
MER
Reserved
SER
PG
FLASH_CR SNB[3:0]
0x10 Reserved Reserved Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0
BOR_LEV[1:0]
nRST_STDBY
nRST_STOP
OPTLOCK
OPTSTRT
WDG_SW
FLASH_
Reserved
nWRP[11:0] RDP[7:0]
0x14 OPTCR Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1
Table 20. Flash register map and reset values (STM32F42xxx and STM32F43xxx)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PRFTEN
DCRST
ICRST
DCEN
ICEN
FLASH_ACR LATENCY[3:0]
0x00 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0
FLASH_
OPTKEYR[31:16] OPTKEYR[15:0]
OPTKEYR
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
WRPERR
PGSERR
PGPERR
PGAERR
OPERR
RDERR
Reserved
EOP
BSY
FLASH_SR
0x0C Reserved Reserved
Reset value 0 0 0 0 0 0 0 0
Table 20. Flash register map and reset values (STM32F42xxx and STM32F43xxx) (continued)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PSIZE[1:0]
EOPIE
MER1
LOCK
STRT
MER
SER
PG
FLASH_CR SNB[4:0]
0x10 Reserved Reserved Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0 0 0 0
BOR_LEV[1:0]
nRST_STDBY
nRST_STOP
OPTLOCK
OPTSTRT
WDG_SW
SPRMOD
DB1M
BFB2
Reserved
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 0 1 1 0 1
FLASH_
Reserved
nWRP[11:0]
OPTCR1
0x18 Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1
This section applies to the whole STM32F4xx family, unless otherwise specified.
AHB bus
ai14968
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
RESET
Reserved
w
Table 21. CRC calculation unit register map and reset values
Offset Register 31-24 23-16 15-8 7 6 5 4 3 2 1 0
This section applies to the whole STM32F4xx family, unless otherwise specified.
VBAT
Backup circuitry
VBAT = Power (OSC32K,RTC,
1.65 to 3.6V switch Wakeup logic
Backup registers,
backup RAM)
Level shifter
OUT
IO
GPIOs
Logic
IN
VCAP_1 Kernel logic
2 × 2.2 μF VCAP_2 (CPU, digital
& RAM)
VDD VDD
1/2/...14/15 Voltage
15 × 100 nF VSS regulator
+ 1 × 4.7 μF 1/2/...14/15
Reset
PDR_ON controller
VDD
VDDA
VREF
VREF+
Analog:
100 nF 100 nF VREF- ADC RCs,
+ 1 μF + 1 μF PLL,..
VSSA
MS19911V2
Backup circuitry
VBAT = Po wer swi tch (OSC32K,RTC,
1.65 to 3.6V Wakeup logic
Backup registers,
backup RAM)
Level shifter
OUT
IO
GP I/Os Logic
IN Kernel logic
(CPU,
VCAP_1
VCAP_2 digital
2 × 2.2 μF & RAM)
VDD
VDD Voltage
1/2/...14/20
regulator
19 × 100 nF VSS
+ 1 × 4.7 μF 1/2/...14/20
VREF
VREF+
100 nF Analog:
100 nF VREF- ADC RCs, PLL,
+ 1 μF + 1 μF
...
VSSA
MS30482V2
If no external battery is used in the application, it is recommended to connect the VBAT pin to
VDD with a 100 nF external decoupling ceramic capacitor in parallel.
When the backup domain is supplied by VDD (analog switch connected to VDD), the
following functions are available:
• PC14 and PC15 can be used as either GPIO or LSE pins
• PC13 can be used as a GPIOas the RTC_AF1 pin (refer to Table 37: RTC_AF1 pin for
more details about this pin configuration)
Note: Due to the fact that the switch only sinks a limited amount of current (3 mA), the use of PI8
and PC13 to PC15 GPIOs in output mode is restricted: the speed has to be limited to 2 MHz
with a maximum load of 30 pF and these I/Os must not be used as a current source (e.g. to
drive an LED).
When the backup domain is supplied by VBAT (analog switch connected to VBAT because
VDD is not present), the following functions are available:
• PC14 and PC15 can be used as LSE pins only
• PC13 can be used as the RTC_AF1 pin (refer to Table 37: RTC_AF1 pin for more
details about this pin configuration)
• PI8 can be used as RTC_AF2
Backup SRAM
The backup domain includes 4 Kbytes of backup SRAM addressed in 32-bit, 16-bit or 8-bit
mode. Its content is retained even in Standby or VBAT mode when the low-power backup
regulator is enabled. It can be considered as an internal EEPROM when VBAT is always
present.
When the backup domain is supplied by VDD (analog switch connected to VDD), the backup
SRAM is powered from VDD which replaces the VBAT power supply to save battery life.
When the backup domain is supplied by VBAT (analog switch connected to VBAT because
VDD is not present), the backup SRAM is powered by a dedicated low-power regulator. This
regulator can be ON or OFF depending whether the application needs the backup SRAM
function in Standby and VBAT modes or not. The power-down of this regulator is controlled
by a dedicated bit, the BRE control bit of the PWR_CSR register (see Section 5.4.2: PWR
power control/status register (PWR_CSR) for STM32F405xx/07xx and
STM32F415xx/17xx).
The backup SRAM is not mass erased by an tamper event. When the Flash memory is read
protected, the backup SRAM is also read protected to prevent confidential data, such as
cryptographic private key, from being accessed. When the protection level change from
level 1 to level 0 is requested, the backup SRAM content is erased.
1.2 V domain
Backup domain
MS30430V1
regulator can be put either in main regulator mode (MR) or in low-power mode (LPR).
The programmed voltage scale remains the same during Stop mode:
The programmed voltage scale remains the same during Stop mode (see
Section 5.4.1: PWR power control register (PWR_CR) for STM32F405xx/07xx
and STM32F415xx/17xx).
• In Standby mode, the regulator is powered down. The content of the registers and
SRAM are lost except for the Standby circuitry and the backup domain.
Note: For more details, refer to the voltage regulator section in the STM32F405xx/07xx and
STM32F415xx/17xx datasheets.
Table 22. Voltage regulator configuration mode versus device operating mode(1)
Voltage regulator
Run mode Sleep mode Stop mode Standby mode
configuration
Example of sequence 2:
1. Select HSI or HSE as system clock source.
2. Disable the peripheral clocks that are not generated by the System PLL (I2S clock,
LCD-TFT clock, SAI1 clock, USB_48MHz clock,....).
3. Reset the ODSW bit in the PWR_CR register to switch back the voltage regulator to
Normal mode. The system clock is stalled during voltage switching.
4. Wait for the ODWRDY flag of PWR_CSR to be reset.
5. Reset the ODEN bit in the PWR_CR register to disable the Over-drive mode.
Note: During step 3, the ODEN bit remains set and the Over-drive mode is still enabled but not
active (ODSW bit is reset). If the ODEN bit is reset instead, the Over-drive mode is disabled
and the voltage regulator is switched back to the initial voltage.
PDR
40 mV
hysteresis PDR
Temporization
tRSTTEMPO
Reset
MS30431V1
Reset
MS30433V1
PVD output
MS30432V2
In addition, the power consumption in Run mode can be reduce by one of the following
means:
• Slowing down the system clocks
• Gating the clocks to the APBx and AHBx peripherals when they are unused.
Only enabled NVIC interrupts with sufficient priority will wakeup and interrupt the MCU.
ON or in low- power
mode (depends on
PWR power control
register (PWR_CR)
for
STM32F405xx/07x
x and
PDDS and LPDS STM32F415xx/17x
bits + Any EXTI line (configured x and PWR power
Stop SLEEPDEEP bit in the EXTI registers, control register
+ WFI, Return internal and external lines) (PWR_CR) for
from ISR or WFE HSI and STM32F405xx/07x
All 1.2 V domain HSE x and
clocks OFF oscillator STM32F415xx/17x
s OFF xPWR power
control register
(PWR_CR) for
STM32F42xxx and
STM32F43xxx
WKUP pin rising edge,
RTC alarm (Alarm A or
PDDS bit +
Alarm B), RTC Wakeup
SLEEPDEEP bit
Standby event, RTC tamper OFF
+ WFI, Return
events, RTC time stamp
from ISR or WFE
event, external reset in
NRST pin, IWDG reset
Peripheral clock gating is controlled by the AHB1 peripheral clock enable register
(RCC_AHB1ENR), AHB2 peripheral clock enable register (RCC_AHB2ENR), AHB3
peripheral clock enable register (RCC_AHB3ENR) (see Section 7.3.10: RCC AHB1
peripheral clock enable register (RCC_AHB1ENR), Section 7.3.11: RCC AHB2 peripheral
clock enable register (RCC_AHB2ENR), Section 7.3.12: RCC AHB3 peripheral clock
enable register (RCC_AHB3ENR) for STM32F405xx/07xx and STM32F415xx/17xx, and
Section 6.3.10: RCC AHB1 peripheral clock register (RCC_AHB1ENR), Section 6.3.11:
RCC AHB2 peripheral clock enable register (RCC_AHB2ENR), and Section 6.3.12: RCC
AHB3 peripheral clock enable register (RCC_AHB3ENR) for STM32F42xxx and
STM32F43xxx).
Disabling the peripherals clocks in Sleep mode can be performed automatically by resetting
the corresponding bit in RCC_AHBxLPENR and RCC_APBxLPENR registers.
STOP MR
0 0 HSI RC startup time
(Main regulator)
Note: If the application needs to disable the external clock before entering Stop mode, the HSEON
bit must first be disabled and the system clock switched to HSI.
Otherwise, if the HSEON bit is kept enabled while the external clock (external oscillator) can
be removed before entering stop mode, the clock security system (CSS) feature must be
enabled to detect any external oscillator failure and avoid a malfunction behavior when
entering stop mode.
Table 27. Stop mode entry and exit (for STM32F405xx/07xx and STM32F415xx/17xx)
Stop mode Description
Table 27. Stop mode entry and exit (for STM32F405xx/07xx and STM32F415xx/17xx)
Stop mode Description
STOP MR
- 0 - 0 0 HSI RC startup time
(Main Regulator)
HSI RC startup time +
STOP MR- FPD - 0 - 0 1 Flash wakeup time from power-
down mode
In Stop mode, the following features can be selected by programming individual control bits:
• Independent watchdog (IWDG): the IWDG is started by writing to its Key register or by
hardware option. Once started it cannot be stopped except by a Reset. See
Section 21.3 in Section 21: Independent watchdog (IWDG).
• Real-time clock (RTC): this is configured by the RTCEN bit in the Section 7.3.20: RCC
Backup domain control register (RCC_BDCR)
• Internal RC oscillator (LSI RC): this is configured by the LSION bit in the
Section 7.3.21: RCC clock control & status register (RCC_CSR).
• External 32.768 kHz oscillator (LSE OSC): this is configured by the LSEON bit in the
RCC Backup domain control register (RCC_BDCR).
The ADC or DAC can also consume power during the Stop mode, unless they are disabled
before entering it. To disable them, the ADON bit in the ADC_CR2 register and the ENx bit
in the DAC_CR register must both be written to 0.
Note: Before entering Stop mode, it is recommended to enable the clock security system (CSS)
feature to prevent external oscillator (HSE) failure from impacting the internal MCU
behavior.
Table 29. Stop mode entry and exit (STM32F42xxx and STM32F43xxx)
Stop mode Description
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®-M4 with
FPU 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 38.16.1: Debug support for low-power modes.
5.3.7 Programming the RTC alternate functions to wake up the device from
the Stop and Standby modes
The MCU can be woken up from a low-power mode by an RTC alternate function.
The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), RTC wakeup, RTC
tamper event detection and RTC time stamp event detection.
These RTC alternate functions can wake up the system from the Stop and Standby low-
power modes.
The system can also wake up from low-power modes without depending on an external
interrupt (Auto-wakeup mode), by using the RTC alarm or the RTC wakeup events.
The RTC provides a programmable time base for waking up from the Stop or Standby mode
at regular intervals.
For this purpose, two of the three alternate RTC clock sources can be selected by
programming the RTCSEL[1:0] bits in the Section 7.3.20: RCC Backup domain control
register (RCC_BDCR):
• Low-power 32.768 kHz external crystal oscillator (LSE OSC)
This clock source provides a precise time base with a very low-power consumption
(additional consumption of less than 1 µA under typical conditions)
• Low-power internal RC oscillator (LSI RC)
This clock source has the advantage of saving the cost of the 32.768 kHz crystal. This
internal RC oscillator is designed to use minimum power.
RTC alternate functions to wake up the device from the Stop mode
• To wake up the device from the Stop mode with an RTC alarm event, it is necessary to:
a) Configure the EXTI Line 17 to be sensitive to rising edges (Interrupt or Event
modes)
b) Enable the RTC Alarm Interrupt in the RTC_CR register
c) Configure the RTC to generate the RTC alarm
• To wake up the device from the Stop mode with an RTC tamper or time stamp event, it
is necessary to:
a) Configure the EXTI Line 21 to be sensitive to rising edges (Interrupt or Event
modes)
b) Enable the RTC time stamp Interrupt in the RTC_CR register or the RTC tamper
interrupt in the RTC_TAFCR register
c) Configure the RTC to detect the tamper or time stamp event
• To wake up the device from the Stop mode with an RTC wakeup event, it is necessary
to:
a) Configure the EXTI Line 22 to be sensitive to rising edges (Interrupt or Event
modes)
b) Enable the RTC wakeup interrupt in the RTC_CR register
c) Configure the RTC to generate the RTC Wakeup event
RTC alternate functions to wake up the device from the Standby mode
• To wake up the device from the Standby mode with an RTC alarm event, it is necessary
to:
a) Enable the RTC alarm interrupt in the RTC_CR register
b) Configure the RTC to generate the RTC alarm
• To wake up the device from the Standby mode with an RTC tamper or time stamp
event, it is necessary to:
a) Enable the RTC time stamp interrupt in the RTC_CR register or the RTC tamper
interrupt in the RTC_TAFCR register
b) Configure the RTC to detect the tamper or time stamp event
• To wake up the device from the Standby mode with an RTC wakeup event, it is
necessary to:
a) Enable the RTC wakeup interrupt in the RTC_CR register
b) Configure the RTC to generate the RTC wakeup event
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
VOS FPDS DBP PLS[2:0] PVDE CSBF CWUF PDDS LPDS
Res. Reserved
rw rw rw rw rw rw rw w w 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
VOS
BRE EWUP BRR PVDO SBF WUF
Res RDY Reserved Reserved
r rw rw r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ODSWE
UDEN[1:0] ODEN
Reserved N
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
VOS[1:0] ADCDC1 MRUDS LPUDS FPDS DBP PLS[2:0] PVDE CSBF CWUF PDDS LPDS
Res.
rw rw rw rw rw rw rw rw rw rw rw rc_w1 rc_w1 rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Table 31. PWR - register map and reset values for STM32F405xx/07xx and STM32F415xx/17xx
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
CWUF
PDDS
PVDE
FPDS
CSBF
LPDS
VOS
DBP
PWR_CR PLS[2:0]
0x000 Reserved Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0
VOSRDY
EWUP
PVDO
WUF
BRR
BRE
SBF
PWR_CSR
0x004 Reserved Reserved Reserved
Reset value 0 0 0 0 0 0 0
Table 32. PWR - register map and reset values for STM32F42xxx and STM32F43xxx
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
UDEN[1:0]
ODSWEN
ADCDC1
VOS[1:0]
MRUDS
LPUDS
Reserved
CWUF
ODEN
PDDS
PVDE
CSBF
FPDS
LPDS
DBP
PWR_CR PLS[2:0]
0x000 Reserved
Reset value 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0
UDRDY[1:0]
ODSWRDY
VOSRDY
ODRDY
EWUP
Reserved
PVDO
WUF
BRR
BRE
SBF
PWR_CSR
0x004 Reserved Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
6.1 Reset
There are three types of reset, defined as system Reset, power Reset and backup domain
Reset.
Software reset
The reset source can be identified by checking the reset flags in the RCC clock control &
status register (RCC_CSR).
The SYSRESETREQ bit in Cortex®-M4 with FPU Application Interrupt and Reset Control
Register must be set to force a software reset on the device. Refer to the Cortex®-M4 with
FPU technical reference manual for more details.
These sources act on the NRST pin and it is always kept low during the delay phase. The
RESET service routine vector is fixed at address 0x0000_0004 in the memory map.
The system reset signal provided to the device is output on the NRST pin. The pulse
generator guarantees a minimum reset pulse duration of 20 µs for each internal reset
source. In case of an external reset, the reset pulse is generated while the NRST pin is
asserted low.
VDD/VDDA
RPU
External System reset
reset Filter
NRST
WWDG reset
Pulse
IWDG reset
generator
Power reset
(min 20 μs)
Software reset
Low-power management reset
ai16095c
The Backup domain has two specific resets that affect only the Backup domain (see
Figure 4).
6.2 Clocks
Three different clock sources can be used to drive the system clock (SYSCLK):
• HSI oscillator clock
• HSE oscillator clock
• Main PLL (PLL) clock
The devices have the two following secondary clock sources:
• 32 kHz low-speed internal RC (LSI RC) which drives the independent watchdog and,
optionally, the RTC used for Auto-wakeup from the Stop/Standby mode.
• 32.768 kHz low-speed external crystal (LSE crystal) which optionally drives the RTC
clock (RTCCLK)
Each clock source can be switched on or off independently when it is not used, to optimize
power consumption.
VCO /P Peripheral
PLL48CK 48 MHz
/Q clock enable
xN clocks
PLL /R
VCO /P
/Q
I2SSRC
xN
PLLI2SCLK Peripheral
/R clock enable I2S clocks
PLLI2S Ext. clock
I2S_CKIN
Peripheral SAI1_A clock
PLLSAICLK clock enable
DIV
Peripheral SAI1_B clock
VCO /P
clock enable
PLLSAICLK
/Q DIV
xN Peripheral LCD-TFT
PLLLCDCLK clock enable clock
/R DIV
PLLSAI
ETH_MII_TX_CLK_MII Peripheral
clock enable MACTXCLK
PHY Ethernet
25 to 50 MHz
/2,20 MII_RMII_SEL in SYSCFG_PMC to Ethernet MAC
Peripheral
clock enable MACRXCLK
ETH_MII_RX_CLK_MI
I Peripheral
clock enable MACRMIICLK
Peripheral
clock enable USBHS
USB2.0 PHY OTG_HS_ULPI_CK
ULPI clock
24 to 60 MHz
MS30434V2
1. For full details about the internal and external clock source characteristics, refer to the Electrical characteristics section in
the device datasheet.
2. When TIMPRE bit of the RCC_DCKCFGR register is reset, if APBx prescaler is 1, then TIMxCLK = PCLKx, otherwise
TIMxCLK = 2x PCLKx.
3. When TIMPRE bit in the RCC_DCKCFGR register is set, if APBx prescaler is 1,2 or 4, then TIMxCLK = HCLK, otherwise
TIMxCLK = 4x PCLKx.
The clock controller provides a high degree of flexibility to the application in the choice of the
external crystal or the oscillator to run the core and peripherals at the highest frequency
and, guarantee the appropriate frequency for peripherals that need a specific clock like
Ethernet, USB OTG FS and HS, I2S, SAI, LTDC, and SDIO.
Several prescalers are used to configure the AHB frequency, the high-speed APB (APB2)
and the low-speed APB (APB1) domains. The maximum frequency of the AHB domain is
180 MHz. The maximum allowed frequency of the high-speed APB2 domain is 90 MHz. The
maximum allowed frequency of the low-speed APB1 domain is 45 MHz
All peripheral clocks are derived from the system clock (SYSCLK) except for:
• The USB OTG FS clock (48 MHz), the random analog generator (RNG) clock
(≤ 48 MHz) and the SDIO clock (≤ 48 MHz) which are coming from a specific output of
PLL (PLL48CLK)
• I2S clock
To achieve high-quality audio performance, the I2S clock can be derived either from a
specific PLL (PLLI2S) or from an external clock mapped on the I2S_CKIN pin. For
more information about I2S clock frequency and precision, refer to Section 28.4.4:
Clock generator.
• SAI1 clock
The SAI1 clock is generated from a specific PLL (PLLSAI or PLLI2S) or from an
external clock mapped on the I2S_CKIN pin.
The PLLSAI can be used as clock source for SAI1 peripheral in case the PLLI2S is
programmed to achieve another audio sampling frequency (49.152 MHz or
11.2896 MHz), and the application requires both frequencies at the same time.
• LTDC clock
The LTDC clock is generated from a specific PLL (PLLSAI).
• The USB OTG HS (60 MHz) clock which is provided from the external PHY
• 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 33.4.4: MII/RMII selection in the Ethernet peripheral description. When the
Ethernet is used, the AHB clock frequency must be at least 25 MHz.
The RCC feeds the external clock of the Cortex System Timer (SysTick) 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 timer clock frequencies for STM32F42xxx and STM32F43xxx are automatically set by
hardware. There are two cases depending on the value of TIMPRE bit in RCC_CFGR
register:
• If TIMPRE bit in RCC_DKCFGR register is reset:
If the APB prescaler is configured to a division factor of 1, the timer clock frequencies
(TIMxCLK) are set to PCLKx. Otherwise, the timer clock frequencies are twice the
frequency of the APB domain to which the timers are connected: TIMxCLK = 2xPCLKx.
• If TIMPRE bit in RCC_DKCFGR register is set:
If the APB prescaler is configured to a division factor of 1, 2 or 4, the timer clock
frequencies (TIMxCLK) are set to HCLK. Otherwise, the timer clock frequencies is four
times the frequency of the APB domain to which the timers are connected: TIMxCLK =
4xPCLKx.
FCLK acts as Cortex®-M4 with FPU free-running clock. For more details, refer to the
Cortex®-M4 with FPU technical reference manual.
OSC_OUT
External clock
(HI-Z)
External
source
OSC_IN OSC_OUT
Crystal/ceramic
resonators
CL1 CL2
Load
capacitors
The HSE Crystal can be switched on and off using the HSEON bit in the RCC clock control
register (RCC_CR).
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 RCC 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 RCC clock control register (RCC_CR).
The HSIRDY flag in the RCC 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 RCC 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 6.2.7: Clock security system (CSS) on page 157.
The three PLLs are disabled by hardware when entering Stop and Standby modes, or when
an HSE failure occurs when HSE or PLL (clocked by HSE) are used as system clock. RCC
PLL configuration register (RCC_PLLCFGR),RCC clock configuration register
(RCC_CFGR), and RCC Dedicated Clock Configuration Register (RCC_DCKCFGR) can be
used to configure PLL, PLLI2S, and PLLSAI.
Note: To read the RTC calendar register when the APB1 clock frequency is less than seven times
the RTC clock frequency (fAPB1 < 7xfRTCLCK), the software must read the calendar time and
date registers twice. The data are correct if the second read access to RTC_TR gives the
same result than the first one. Otherwise a third read access must be performed.
The primary purpose of having the LSE connected to the channel4 input capture is to be
able to precisely measure the HSI (this requires to have the HSI used as the system clock
source). The number of HSI clock counts between consecutive edges of the LSE signal
provides a measurement of the internal clock period. Taking advantage of the high precision
of LSE crystals (typically a few tens of ppm) we can determine the internal clock frequency
with the same resolution, and trim the source to compensate for manufacturing-process
and/or temperature- and voltage-related frequency deviations.
The HSI oscillator has dedicated, user-accessible calibration bits for this purpose.
The basic concept consists in providing a relative measurement (e.g. HSI/LSE ratio): the
precision is therefore tightly linked to the ratio between the two clock sources. The greater
the ratio, the better the measurement.
It is also possible to measure the LSI frequency: this is useful for applications that do not
have a crystal. The ultralow-power LSI oscillator has a large manufacturing process
deviation: by measuring it versus the HSI clock source, it is possible to determine its
frequency with the precision of the HSI. The measured value can be used to have more
accurate RTC time base timeouts (when LSI is used as the RTC clock source) and/or an
IWDG timeout with an acceptable accuracy.
Use the following procedure to measure the LSI frequency:
1. Enable the TIM5 timer and configure channel4 in Input capture mode.
2. This bit is set the TI4_RMP bits in the TIM5_OR register to 0x01 to connect the LSI
clock internally to TIM5 channel4 input capture for calibration purposes.
3. Measure the LSI clock frequency using the TIM5 capture/compare 4 event or interrupt.
4. Use the measured LSI frequency to update the prescaler of the RTC depending on the
desired time base and/or to compute the IWDG timeout.
TIM5
TI4_RMP[1:0]
GPIO
RTC_WakeUp_IT TI4
LSE
LSI
ai17741V2
TIM11
TI1_RMP[1:0]
GPIO
TI1
HSE_RTC(1 MHz)
ai18433
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLSAI PLLSAI PLLI2S PLLI2S PLLRD CSS HSE HSE HSE
PLLON
Reserved RDY ON RDY ON Y Reserved ON BYP RDY ON
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
HSI
HSICAL[7:0] HSITRIM[4:0] HSION
Res. RDY
r r r r r r r r rw rw rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLSR
PLLQ3 PLLQ2 PLLQ1 PLLQ0 Reserv PLLP1 PLLP0
Reserved C Reserved
ed
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Bits 17:16 PLLP: Main PLL (PLL) division factor for main system clock
Set and cleared by software to control the frequency of the general PLL output clock. These
bits can be written only if PLL is disabled.
Caution: The software has to set these bits correctly not to exceed 180 MHz on this domain.
PLL output clock frequency = VCO frequency / PLLP with PLLP = 2, 4, 6, or 8
00: PLLP = 2
01: PLLP = 4
10: PLLP = 6
11: PLLP = 8
Bits 14:6 PLLN: Main PLL (PLL) multiplication factor for VCO
Set and cleared by software to control the multiplication factor of the VCO. These bits can
be written only when PLL is disabled. Only half-word and word accesses are allowed to
write these bits.
Caution: The software has to set these bits correctly to ensure that the VCO output
frequency is between 100 and 432 MHz.
VCO output frequency = VCO input frequency × PLLN with 50 ≤ PLLN ≤ 432
000000000: PLLN = 0, wrong configuration
000000001: PLLN = 1, wrong configuration
...
000110010: PLLN = 50
...
001100011: PLLN = 99
001100100: PLLN = 100
...
110110000: PLLN = 432
110110001: PLLN = 433, wrong configuration
...
111111111: PLLN = 511, wrong configuration
Note: Multiplication factors ranging from 50 and 99 are possible for VCO input frequency
higher than 1 MHz. However care must be taken that the minimum VCO output
frequency respects the value specified above.
Bits 5:0 PLLM: Division factor for the main PLL (PLL) and audio PLL (PLLI2S) input clock
Set and cleared by software to divide the PLL and PLLI2S input clock before the VCO.
These bits can be written only when the PLL and PLLI2S are disabled.
Caution: The software has to set these bits correctly to ensure that the VCO input frequency
ranges from 1 to 2 MHz. It is recommended to select a frequency of 2 MHz to limit
PLL jitter.
VCO input frequency = PLL input clock frequency / PLLM with 2 ≤ PLLM ≤ 63
000000: PLLM = 0, wrong configuration
000001: PLLM = 1, wrong configuration
000010: PLLM = 2
000011: PLLM = 3
000100: PLLM = 4
...
111110: PLLM = 62
111111: PLLM = 63
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
I2SSC
MCO2 MCO2 PRE[2:0] MCO1 PRE[2:0] MCO1 RTCPRE[4:0]
R
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
PPRE2[2:0] PPRE1[2:0] HPRE[3:0] SWS1 SWS0 SW1 SW0
Reserved
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
PLLSAI PLLI2S PLL HSE HSI LSE LSI
CSSC
Reserved RDYC RDYC RDYC RDYC RDYC RDYC RDYC
w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLLSAI PLLI2S PLL HSE HSI LSE LSI PLLSAI PLLI2S PLL HSE HSI LSE LSI
Reserv CSSF
RDYIE RDYIE RDYIE RDYIE RDYIE RDYIE RDYIE RDYF RDYF RDYF RDYF RDYF RDYF RDYF
ed
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
OTGH
ETHMAC DMA2D DMA2 DMA1
S
Reserved Reserved RST Res. RST RST RST Reserved
RST
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRCR GPIOK GPIOJ GPIOI GPIOH GPIOGG GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA
Reserved ST Res. RST RST RST RST RST RST RST RST RST RST RST
rw rw rw rw 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
OTGFS RNG HASH CRYP DCMI
Reserved RST RST RST RST Reserved RST
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
FMCRST
Reserved
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UART8R UART7R PWR CAN2 CAN1 I2C3 I2C2 I2C1 UART5 UART4 UART3 UART2
DACRST
ST ST RST Reser- RST RST Reser- RST RST RST RST RST RST RST Reser-
ved ved ved
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
SPI3 SPI2 WWDG TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
RST RST Reserved RST Reserved RST RST RST RST RST RST RST RST RST
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LTD SAI1 SPI6 SPI5 TIM11 TIM10 TIM9
Reserved CRST Reserved RST RST RST Res. RST RST RST
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART USART
SYSCF SPI4 SPI1 SDIO ADC TIM8 TIM1
Reser- 6 1
G RST RST RST RST Reserved RST Reserved Reserved RST RST
ved RST RST
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OTGH
ETHM ETHM ETHM
S OTGH ETHMA DMA2D DMA2E DMA1E CCMDAT BKPSR
Reser- ULPIE ACPTP ACRXE ACTXE Res.
SEN CEN Res. EN N N ARAMEN AMEN Reserved
ved EN N N
N
rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRCE GPIOK GPIOJ GPIOIE GPIOH GPIOG GPIOFE GPIOD GPIOC GPIO GPIO
GPIOEEN
Reserved N Res. EN EN N EN EN N EN EN BEN AEN
rw rw rw rw 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
OTGFS RNG HASH CRYP DCMI
Reserved EN EN EN EN Reserved EN
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
FMCEN
Reserved
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
USART USART
UART8 UART7 DAC PWR CAN2 CAN1 I2C3 I2C2 I2C1 UART5 UART4
Reser- Reser- 3 2 Reser-
EN EN EN EN EN EN EN EN EN EN EN
ved ved EN EN ved
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
SPI3 SPI2 WWDG TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
EN EN Reserved EN 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
LTDC TIM11 TIM10 TIM9
SAI1EN SPI6EN SPI5EN
Reserved EN Reserved Res. EN EN EN
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART USART
SYSCF SPI4E SPI1 SDIO ADC3 ADC2 ADC1 TIM8 TIM1
Reser- 6 1
G EN N EN EN EN EN EN Reserved Reserved EN EN
ved EN EN
rw rw rw rw rw rw rw rw rw rw rw
6.3.15 RCC AHB1 peripheral clock enable in low power mode register
(RCC_AHB1LPENR)
Address offset: 0x50
Reset value: 0x7EEF 97FF
Access: no wait state, word, half-word and byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OTGHS OTGH ETHPT ETHMA BKPSRA SRAM SRAM
ETHRX ETHTX DMA2D DMA2 DMA1 SRAM3
ULPILPE S P C M 2 1
Res. LPEN LPEN Res. LPEN LPEN LPEN Res. LPEN
N LPEN LPEN LPEN LPEN LPEN LPEN
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
GPIOG GPIO
FLITF CRC GPIOK GPIOIJ GPIOI GPIOH GPIOE GPIOD GPIOC GPIOB GPIOA
G F
LPEN Reserved LPEN Res. LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN
LPEN LPEN
rw rw rw rw rw rw rw rw rw rw rw rw rw
6.3.16 RCC AHB2 peripheral clock enable in low power mode register
(RCC_AHB2LPENR)
Address offset: 0x54
Reset value: 0x0000 00F1
Access: no wait state, word, half-word and byte access.
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
OTGFS RNG HASH CRYP DCMI
Reserved LPEN LPEN LPEN LPEN Reserved LPEN
rw rw rw rw rw
6.3.17 RCC AHB3 peripheral clock enable in low power mode register
(RCC_AHB3LPENR)
Address offset: 0x58
Reset value: 0x0000 0001
Access: no wait state, word, half-word and byte access.
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
FMC
Reserved LPEN
rw
6.3.18 RCC APB1 peripheral clock enable in low power mode register
(RCC_APB1LPENR)
Address offset: 0x60
Reset value: 0xF6FE C9FF
Access: no wait state, word, half-word and byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
USART USART
UART8 UART7 DAC PWR RESER CAN2 CAN1 I2C3 I2C2 I2C1 UART5 UART4
Reser- 3 2 Reser-
LPEN LPEN LPEN LPEN VED LPEN LPEN LPEN LPEN LPEN LPEN LPEN
ved LPEN LPEN ved
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
SPI3 SPI2 WWDG TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
LPEN LPEN Reserved LPEN Reserved LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN
rw rw rw rw rw rw rw rw rw rw rw rw
6.3.19 RCC APB2 peripheral clock enabled in low power mode register
(RCC_APB2LPENR)
Address offset: 0x64
Reset value: 0x0x0477 7F33
Access: no wait state, word, half-word and byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LTDC SAI1 SPI6 SPI5 TIM11 TIM10 TIM9
LPEN LPEN LPEN LPEN Reser- LPEN LPEN LPEN
Reserved Reserved
ved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYSC USART USART
SPI4 SPI1 SDIO ADC3 ADC2 ADC1 TIM8 TIM1
Reser- FG 6 1
LPEN LPEN LPEN LPEN LPEN LPEN Reserved Reserved LPEN LPEN
ved LPEN LPEN LPEN
rw rw rw 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
LSEBY LSERD
RTCEN RTCSEL[1:0] LSEON
Reserved Reserved P Y
rw rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LPWR WWDG IWDG SFT POR PIN BORRS
RMVF
RSTF RSTF RSTF RSTF RSTF RSTF TF Reserved
r r r r r r r rt_w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LSIRDY LSION
Reserved
r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SPR
SSCG
EAD INCSTEP
EN Reserved
SEL
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
INCSTEP MODPER
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
PLLI2S PLLI2S PLLI2S
Reserv PLLI2SQ
R2 R1 R0 Reserved
ed
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN
Reserv 8 7 6 5 4 3 2 1 0 Reserved
ed
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLSAIR PLLSAIQ
Reserved Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLLSAIN
Reserved Reserved
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIMPRE SAI1BSRC SAI1ASRC PLLSAIDIVR
Reserved Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLLSAIDIVQ PLLS2DIVQ
Reserved Reserved
rw rw rw rw rw rw rw rw rw rw
0x38
0x34
0x30
0x28
0x24
0x20
0x18
0x14
0x10
0x08
0x04
0x0C
0x3C
0x2C
0x1C
Addr.
offset
6.3.26
210/1751
R
TR
TR
TR
TR
TR
RCC_
RCC_
RCC_
name
RCC_CR
Reserved
Reserved
Reserved
Reserved
RCC_CIR
AHB3ENR
AHB2ENR
AHB1ENR
Register
RCC_CFGR
RCC_PLLCFG
RCC_APB2RS
RCC_APB1RS
RCC_AHB3RS
RCC_AHB2RS
RCC_AHB1RS
Reserved UART8RST MCO2 1 31
Reserved Reserved
OTGHSULPIEN UART7RST MCO2 0 30
OTGHSEN DACRST OTGHSRST MCO2PRE2 PLL SAIRDY 29
Reserved
ETHMACPTPEN PWRRST MCO2PRE1 PLL SAION
Reserved
28
ETHMACRXEN Reserved Reserved MCO2PRE0 PLLQ 3 PLL I2SRDY 27
Reserved
ETHMACTXEN LTDCRST CAN2RST MCO1PRE2 PLLQ 2 PLL I2SON 26
RCC register map
Reserved
Reserved
Reserved
RM0090 Rev 19
TIM9RST Reserved LSIRDYC RTCPRE 0 PLLP 0 HSEON 16
Reserved
Table 33 gives the register map and reset values.
Reserved
Reserved
15
Reserved
Reserved
Reserved
Reserved
SYSCFGRST SPI2RST PLLSAIRDYIE PPRE2 1 PLLN 8 HSICAL 6 14
SP45RST PLLI2SRDYIE PPRE2 0 PLLN 7 HSICAL 5 13
Reserved
CRCEN SPI1RST CRCRST PLLRDYIE PPRE1 2 PLLN 6 HSICAL 4 12
PPRE1 1
Reset and clock control for STM32F42xxx and STM32F43xxx (RCC)
0x80
0x78
0x68
0x64
0x60
0x58
0x54
0x50
0x48
0x44
0x40
0x7C
0x6C
0x5C
0x4C
Addr.
offset
RM0090
FGR
ENR
ENR
ENR
ENR
ENR
RCC_
RCC_
name
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
APB2ENR
APB1ENR
RCC_CSR
Register
RCC_BDCR
RCC_SSCGR
RCC_APB2LP
RCC_APB1LP
RCC_AHB3LP
RCC_AHB2LP
RCC_AHB1LP
RCC_PLLI2SC
Reserved SSCGEN LPWRRSTF UART8LPEN Reserved UART8EN 31
SPREADSEL WWDGRSTF UART7LPEN OTGHSULPILPEN UART7EN 30
WDGRSTF DACLPEN OTGHSLPEN DACEN 29
Reserved
SFTRSTF PWRLPEN ETHMACPTPLPEN PWREN
Reserved
Reserved
PLLI2SRx
28
PORRSTF Reserved ETHMACRXLPEN Reserved 27
PADRSTF LTDCLPEN CAN2LPEN ETHMACTXLPEN LTDCEN CAN2EN 26
BORRSTF CAN1LPEN ETHMACLPEN CAN1EN 25
PLLI2SQ
RMVF Reserved Reserved Reserved Reserved Reserved 24
I2C3LPEN DMA2DLPEN I2C3EN
Reserved
23
SAI1LPEN I2C2LPEN DMA2LPEN SAI1EN I2C2EN 22
SPI6LPEN I2C1LPEN DMA1LPEN SPI6EN I2C1EN 21
SPI5LPEN UART5LPEN Reserved SPI5EN UART5EN 20
Reserved UART4LPEN SRAM3LPEN Reserved UART4EN
INCSTEP
19
Reserved
TIM11LPEN USART3LPEN BKPSRAMLPEN TIM11EN USART3EN
Reserved
18
TIM10LPEN USART2LPEN SRAM2LPEN TIM10EN USART2EN 17
RM0090 Rev 19
BDRST TIM9LPEN Reserved SRAM1LPEN TIM9EN Reserved 16
RTCEN Reserved SPI3LPEN FLITFLPEN Reserved SPI3EN
Reserved
15
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
SDIOLPEN WWDGLPEN Reserved SDIOEN WWDGEN
Reserved
11
ADC3LPEN GPIOKLPEN ADC3EN 10
Reserved Reserved
RTCSEL 1 ADC2LPEN GPIOJLPEN ADC2EN
PLLI2SNx
9
RTCSEL 0 ADC1LPEN TIM14LPEN GPIOILPEN ADC1EN TIM14EN 8
TIM13LPEN OTGFSLPEN GPIOHLPEN TIM13EN 7
Reserved Reserved
TIM12LPEN RNGLPEN GPIOGLPEN TIM12EN 6
USART6LPEN TIM7LPEN HASHLPEN GPIOFLPEN USART6EN TIM7EN
MODPER
5
USART1LPEN TIM6LPEN CRYPLPEN GPIOELPEN USART1EN TIM6EN
Reserved
4
TIM5LPEN GPIODLPEN TIM5EN 3
Reserved Reserved
LSEBYP TIM4LPEN Reserved GPIOCLPEN TIM4EN 2
Reserved
LSIRDY LSERDY TIM8LPEN TIM3LPEN GPIOBLPEN TIM8EN TIM3EN 1
Table 33. RCC register map and reset values for STM32F42xxx and STM32F43xxx (continued)
211/1751
212
Reset and clock control for STM32F42xxx and STM32F43xxx (RCC) RM0090
Table 33. RCC register map and reset values for STM32F42xxx and STM32F43xxx (continued)
Addr. Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
offset name
Reserved
Reserved
PLLSAIQ
PLLSAIR
PLLSAIN
RCC_PLLSAI
0x88
CFGR
PLLSAIDIVR
SAI1BSCR
SAI1ASCR
Reserved
TIMPRE
RCC_DCKCF
0x8C Reserved Reserved PLLSAIDIVQ Reserved PLLI2SDIVQ
GR
Refer to Section 2.3: Memory map for the register boundary addresses.
7.1 Reset
There are three types of reset, defined as system Reset, power Reset and backup domain
Reset.
Software reset
The reset source can be identified by checking the reset flags in the RCC clock control &
status register (RCC_CSR).
The SYSRESETREQ bit in Cortex®-M4 with FPU Application Interrupt and Reset Control
Register must be set to force a software reset on the device. Refer to the Cortex®-M4 with
FPU technical reference manual for more details.
VDD/VDDA
RPU
External System reset
reset Filter
NRST
WWDG reset
Pulse
IWDG reset
generator
Power reset
(min 20 μs)
Software reset
Low-power management reset
ai16095c
The Backup domain has two specific resets that affect only the Backup domain (see
Figure 4).
A backup domain reset is generated when one of the following events occurs:
1. Software reset, triggered by setting the BDRST bit in the RCC Backup domain control
register (RCC_BDCR).
2. VDD or VBAT power on, if both supplies have previously been powered off.
7.2 Clocks
Three different clock sources can be used to drive the system clock (SYSCLK):
• HSI oscillator clock
• HSE oscillator clock
• Main PLL (PLL) clock
The devices have the two following secondary clock sources:
• 32 kHz low-speed internal RC (LSI RC) which drives the independent watchdog and,
optionally, the RTC used for Auto-wakeup from the Stop/Standby mode.
• 32.768 kHz low-speed external crystal (LSE crystal) which optionally drives the RTC
clock (RTCCLK)
Each clock source can be switched on or off independently when it is not used, to optimize
power consumption.
Watchdog
enable IWDGCLK
LSI RC LSI to independent
32 kHz watchdog
RTC S E L[1:0]
RTC RTCCLK
OSC32_IN enable to RTC
LSE OS C LSE
32.768 kHz
OSC32_OUT
SYSCLK
MCO2 /1 to 5
HSE_RTC
LSE
MCO1 /1 to 5 Peripheral
/2 to 31 clock enable Ethernet
PTP clock
/M
VCO /P
Peripheral 48 MHz
PLL48CK clock enable
/Q clocks
xN
/R
PLL
VCO /P
/Q I2SSRC
xN
PLLI2SCLK Peripheral I2S clocks
/R clock enable
PLLI2S
I2S_CKIN Ext. clock
ETH_MII_TX_CLK_MII Peripheral
PHY Ethernet
clock enable MACTXCLK
25 to 50 MHz
/2,20 MII_RMII_SEL in SYSCFG_PMC to Ethernet MAC
Peripheral
clock enable MACRXCLK
ETH_MII_RX_
CLK_MII Peripheral
clock enable MACRMIICLK Peripheral
OTG_HS_ULPI_CK clock enable USBHS
USB2.0 PHY ULPI clock
24 to 60 MHz
ai16088d
1. For full details about the internal and external clock source characteristics, refer to the Electrical characteristics section in
the device datasheet.
The clock controller provides a high degree of flexibility to the application in the choice of the
external crystal or the oscillator to run the core and peripherals at the highest frequency
and, guarantee the appropriate frequency for peripherals that need a specific clock like
Ethernet, USB OTG FS and HS, I2S and SDIO.
Several prescalers are used to configure the AHB frequency, the high-speed APB (APB2)
and the low-speed APB (APB1) domains. The maximum frequency of the AHB domain is
168 MHz. The maximum allowed frequency of the high-speed APB2 domain is 84 MHz. The
maximum allowed frequency of the low-speed APB1 domain is 42 MHz
All peripheral clocks are derived from the system clock (SYSCLK) except for:
• The USB OTG FS clock (48 MHz), the random analog generator (RNG) clock
(≤ 48 MHz) and the SDIO clock (≤ 48 MHz) which are coming from a specific output of
PLL (PLL48CLK)
• The I2S clock
To achieve high-quality audio performance, the I2S clock can be derived either from a
specific PLL (PLLI2S) or from an external clock mapped on the I2S_CKIN pin. For
more information about I2S clock frequency and precision, refer to Section 28.4.4:
Clock generator.
• The USB OTG HS (60 MHz) clock which is provided from the external PHY
• 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 33.4.4: MII/RMII selection in the Ethernet peripheral description. When the
Ethernet is used, the AHB clock frequency must be at least 25 MHz.
The RCC feeds the external clock of the Cortex System Timer (SysTick) 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 timer clock frequencies are automatically set 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®-M4 with FPU free-running clock. For more details, refer to the
Cortex®-M4 with FPU technical reference manual.
OSC_OUT
External clock
(HI-Z)
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 RCC 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 RCC clock control register (RCC_CR).
The HSIRDY flag in the RCC 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 RCC 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 220.
The LSERDY flag in the RCC Backup domain control register (RCC_BDCR) indicates if the
LSE crystal is stable or not. At startup, the LSE crystal output clock signal is not released
until this bit is set by hardware. An interrupt can be generated if enabled in the RCC clock
interrupt register (RCC_CIR).
If the HSE oscillator is used directly or indirectly as the system clock (indirectly meaning that
it is directly used as PLL input clock, and that PLL clock is the system clock) and a failure is
detected, then the system clock switches to the HSI oscillator and the HSE oscillator is
disabled.
If the HSE oscillator clock was the clock source of PLL used as the system clock when the
failure occurred, PLL is also disabled. In this case, if the PLLI2S was enabled, it is also
disabled when the HSE fails.
The basic concept consists in providing a relative measurement (e.g. HSI/LSE ratio): the
precision is therefore tightly linked to the ratio between the two clock sources. The greater
the ratio, the better the measurement.
It is also possible to measure the LSI frequency: this is useful for applications that do not
have a crystal. The ultralow-power LSI oscillator has a large manufacturing process
deviation: by measuring it versus the HSI clock source, it is possible to determine its
frequency with the precision of the HSI. The measured value can be used to have more
accurate RTC time base timeouts (when LSI is used as the RTC clock source) and/or an
IWDG timeout with an acceptable accuracy.
Use the following procedure to measure the LSI frequency:
1. Enable the TIM5 timer and configure channel4 in Input capture mode.
2. Set the TI4_RMP bits in the TIM5_OR register to 0x01 to connect the LSI clock
internally to TIM5 channel4 input capture for calibration purposes.
3. Measure the LSI clock frequency using the TIM5 capture/compare 4 event or interrupt.
4. Use the measured LSI frequency to update the prescaler of the RTC depending on the
desired time base and/or to compute the IWDG timeout.
TIM5
TI4_RMP[1:0]
GPIO
RTC_WakeUp_IT TI4
LSE
LSI
ai17741V2
TIM11
TI1_RMP[1:0]
GPIO
TI1
HSE_RTC(1 MHz)
ai18433
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLI2S PLLI2S PLLRD CSS HSE HSE HSE
PLLON
Reserved RDY ON Y Reserved ON BYP RDY ON
r rw r rw rw rw r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HSI
HSICAL[7:0] HSITRIM[4:0] HSION
Res. RDY
r r r r r r r r rw rw rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLSR
PLLQ3 PLLQ2 PLLQ1 PLLQ0 Reserv PLLP1 PLLP0
Reserved C Reserved
ed
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Bits 17:16 PLLP: Main PLL (PLL) division factor for main system clock
Set and cleared by software to control the frequency of the general PLL output clock. These
bits can be written only if PLL is disabled.
Caution: The software has to set these bits correctly not to exceed 168 MHz on this domain.
PLL output clock frequency = VCO frequency / PLLP with PLLP = 2, 4, 6, or 8
00: PLLP = 2
01: PLLP = 4
10: PLLP = 6
11: PLLP = 8
Bits 14:6 PLLN: Main PLL (PLL) multiplication factor for VCO
Set and cleared by software to control the multiplication factor of the VCO. These bits can
be written only when PLL is disabled. Only half-word and word accesses are allowed to
write these bits.
Caution: The software has to set these bits correctly to ensure that the VCO output
frequency is between 100 and 432 MHz.
VCO output frequency = VCO input frequency × PLLN with 50 ≤ PLLN ≤ 432
000000000: PLLN = 0, wrong configuration
000000001: PLLN = 1, wrong configuration
...
000110010: PLLN = 50
...
001100011: PLLN = 99
001100100: PLLN = 100
...
110110000: PLLN = 432
110110001: PLLN = 433, wrong configuration
...
111111111: PLLN = 511, wrong configuration
Note: Multiplication factors ranging from 50 and 99 are possible for VCO input frequency
higher than 1 MHz. However care must be taken that the minimum VCO output
frequency respects the value specified above.
Bits 5:0 PLLM: Division factor for the main PLL (PLL) and audio PLL (PLLI2S) input clock
Set and cleared by software to divide the PLL and PLLI2S input clock before the VCO.
These bits can be written only when the PLL and PLLI2S are disabled.
Caution: The software has to set these bits correctly to ensure that the VCO input frequency
ranges from 1 to 2 MHz. It is recommended to select a frequency of 2 MHz to limit
PLL jitter.
VCO input frequency = PLL input clock frequency / PLLM with 2 ≤ PLLM ≤ 63
000000: PLLM = 0, wrong configuration
000001: PLLM = 1, wrong configuration
000010: PLLM = 2
000011: PLLM = 3
000100: PLLM = 4
...
111110: PLLM = 62
111111: PLLM = 63
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
I2SSC
MCO2 MCO2 PRE[2:0] MCO1 PRE[2:0] MCO1 RTCPRE[4:0]
R
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
PPRE2[2:0] PPRE1[2:0] HPRE[3:0] SWS1 SWS0 SW1 SW0
Reserved
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
PLLI2S PLL HSE HSI LSE LSI
CSSC Reserv RDYC
Reserved RDYC RDYC RDYC RDYC RDYC
ed
w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLLI2S PLL HSE HSI LSE LSI PLLI2S PLL HSE HSI LSE LSI
CSSF Reserv
Reserved RDYIE RDYIE RDYIE RDYIE RDYIE RDYIE RDYF RDYF RDYF RDYF RDYF RDYF
ed
rw rw rw rw rw rw r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OTGH
ETHMAC DMA2 DMA1
S
Reserved Reserved RST Reserved RST RST Reserved
RST
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRCR GPIOI GPIOH GPIOGG GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA
Reserved ST Reserved RST RST RST RST RST RST RST RST RST
rw rw 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
OTGFS RNG HASH CRYP DCMI
Reserved RST RST RST RST Reserved RST
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
FSMCRST
Reserved
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PWR CAN2 CAN1 I2C3 I2C2 I2C1 UART5 UART4 UART3 UART2
DACRST
RST Reser- RST RST Reser- RST RST RST RST RST RST RST Reser-
Reserved
ved ved ved
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 WWDG TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
RST RST RST 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
TIM11 TIM10 TIM9
Reserved RST RST RST
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART USART
SYSCF SPI1 SDIO ADC TIM8 TIM1
Reser- 6 1
G RST Reser- RST RST Reserved RST Reserved Reserved RST RST
ved ved RST RST
rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OTGH
ETHM ETHM ETHM
S OTGH ETHMA DMA2E DMA1E CCMDAT BKPSR
Reser- ULPIE ACPTP ACRXE ACTXE Res.
SEN CEN Reserved N N ARAMEN AMEN Reserved
ved EN N N
N
rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRCE GPIOIE GPIOH GPIOG GPIOFE GPIOD GPIOC GPIO GPIO
GPIOEEN
Reserved N Reserved N EN EN N EN EN BEN AEN
rw rw 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
OTGFS RNG HASH CRYP DCMI
Reserved EN EN EN EN Reserved EN
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
FSMCEN
Reserved
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
USART USART
DAC PWR CAN2 CAN1 I2C3 I2C2 I2C1 UART5 UART4
Reser- Reser- 3 2 Reser-
Reserved EN EN EN EN EN EN EN EN EN
ved ved EN EN ved
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 WWDG TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
EN EN Reserved EN 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
TIM11 TIM10 TIM9
Reserved EN EN EN
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USART USART
SYSCF SPI1 SDIO ADC3 ADC2 ADC1 TIM8 TIM1
Reser- 6 1
G EN Reser- EN EN EN EN EN Reserved Reserved EN EN
ved ved EN EN
rw rw rw rw rw rw rw rw rw rw
7.3.15 RCC AHB1 peripheral clock enable in low power mode register
(RCC_AHB1LPENR)
Address offset: 0x50
Reset value: 0x7E67 91FF
Access: no wait state, word, half-word and byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OTGHS OTGH ETHPT ETHMA BKPSRA SRAM SRAM
ETHRX ETHTX DMA2 DMA1
Reser ULPILPE S P C M 2 1
LPEN LPEN Reserved LPEN LPEN Reserved
-ved N LPEN LPEN LPEN LPEN LPEN LPEN
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
GPIOG GPIO
FLITF CRC GPIOI GPIOH GPIOE GPIOD GPIOC GPIOB GPIOA
G F
LPEN Reserved LPEN Reserved LPEN LPEN LPEN LPEN LPEN LPEN LPEN
LPEN LPEN
rw rw rw rw rw rw rw rw rw rw rw
7.3.16 RCC AHB2 peripheral clock enable in low power mode register
(RCC_AHB2LPENR)
Address offset: 0x54
Reset value: 0x0000 00F1
Access: no wait state, word, half-word and byte access.
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
OTGFS RNG HASH CRYP DCMI
Reserved LPEN LPEN LPEN LPEN Reserved LPEN
rw rw rw rw rw
7.3.17 RCC AHB3 peripheral clock enable in low power mode register
(RCC_AHB3LPENR)
Address offset: 0x58
Reset value: 0x0000 0001
Access: no wait state, word, half-word and byte access.
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
FSMC
Reserved LPEN
rw
7.3.18 RCC APB1 peripheral clock enable in low power mode register
(RCC_APB1LPENR)
Address offset: 0x60
Reset value: 0x36FE C9FF
Access: no wait state, word, half-word and byte access.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
USART USART
DAC PWR RESER CAN2 CAN1 I2C3 I2C2 I2C1 UART5 UART4
Reser- 3 2 Reser-
Reserved LPEN LPEN VED LPEN LPEN LPEN LPEN LPEN LPEN LPEN
ved LPEN LPEN ved
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 WWDG TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
LPEN LPEN Reserved LPEN Reserved LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIM11 TIM10 TIM9
Reserved LPEN LPEN LPEN
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYSC USART USART
SPI1 SDIO ADC3 ADC2 ADC1 TIM8 TIM1
Reser- FG Reser- 6 1
LPEN LPEN LPEN LPEN LPEN Reserved Reserved LPEN LPEN
ved LPEN ved LPEN LPEN
rw rw 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
LSEBY LSERD
RTCEN RTCSEL[1:0] LSEON
Reserved Reserved P Y
rw rw rw rw r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LPWR WWDG IWDG SFT POR PIN BORRS
RMVF
RSTF RSTF RSTF RSTF RSTF RSTF TF Reserved
r r r r r r r rt_w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LSIRDY LSION
Reserved
r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SPR
SSCG
EAD INCSTEP
EN Reserved
SEL
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
INCSTEP MODPER
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
PLLI2S PLLI2S PLLI2S
Reserv R2 R1 R0 Reserved
ed
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN PLLI2SN
Reserv 8 7 6 5 4 3 2 1 0 Reserved
ed
rw rw rw rw rw rw rw rw rw
0x38
0x34
0x30
0x28
0x24
0x20
0x18
0x14
0x10
0x08
0x04
0x0C
0x3C
0x2C
0x1C
Addr.
offset
7.3.24
RM0090
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
RCC_
name
RCC_CR
Reserved
Reserved
Reserved
Reserved
RCC_CIR
PLLCFGR
AHB3ENR
AHB2ENR
AHB1ENR
Register
APB2RSTR
APB1RSTR
AHB3RSTR
AHB2RSTR
AHB1RSTR
RCC_CFGR
Reserved MCO2 1 31
Reserved Reserved
OTGHSULPIEN MCO2 0 30
OTGHSEN DACRST OTGHSRST MCO2PRE2 29
Reserved
Reserved
ETHMACPTPEN PWRRST MCO2PRE1 28
ETHMACRXEN Reserved Reserved MCO2PRE0 PLLQ 3 PLL I2SRDY 27
Reserved
ETHMACTXEN CAN2RST MCO1PRE2 PLLQ 2 PLL I2SON 26
RCC register map
Reserved
24
Reserved Reserved
I2C3RST CSSC I2SSRC Reserved 23
DMA2EN I2C2RST DMA2RST Reserved MCO1 1 PLLSRC 22
DMA1EN I2C1RST DMA1RST PLLI2SRDYC MCO1 0 21
Reserved
Reserved
Reserved
Reserved
RM0090 Rev 19
TIM9RST Reserved LSIRDYC RTCPRE 0 PLLP 0 HSEON 16
Reserved
Table 34 gives the register map and reset values.
Reserved
Reserved
15
Reserved
Reserved
Reserved
Reserved
Reserved
SYSCFGRST SPI2RST PPRE2 1 PLLN 8 HSICAL 6 14
Reserved PLLI2SRDYIE PPRE2 0 PLLN 7 HSICAL 5 13
Reserved
CRCEN SPI1RST CRCRST PLLRDYIE PPRE1 2 PLLN 6 HSICAL 4 12
SDIORST WWDGRST HSERDYIE PPRE1 1 PLLN 5 HSICAL 3 11
Table 34. RCC register map and reset values
265/1751
266
0x84
0x74
0x70
0x80
0x78
0x68
0x64
0x60
0x58
0x54
0x50
0x48
0x44
0x40
0x7C
0x6C
0x5C
0x4C
Addr.
offset
266/1751
FGR
ENR
ENR
ENR
ENR
ENR
RCC_
RCC_
name
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
APB2ENR
APB1ENR
RCC_CSR
Register
RCC_BDCR
RCC_SSCGR
RCC_APB2LP
RCC_APB1LP
RCC_AHB3LP
RCC_AHB2LP
RCC_AHB1LP
RCC_PLLI2SC
Reserved SSCGEN LPWRRSTF Reserved 31
Reserved Reserved
SPREADSEL WWDGRSTF OTGHSULPILPEN 30
WDGRSTF DACLPEN OTGHSLPEN DACEN 29
Reserved
SFTRSTF PWRLPEN ETHMACPTPLPEN PWREN
PLLI2SRx
28
PORRSTF Reserved ETHMACRXLPEN Reserved 27
PADRSTF CAN2LPEN ETHMACTXLPEN CAN2EN 26
BORRSTF CAN1LPEN ETHMACLPEN CAN1EN 25
RMVF Reserved Reserved
Reserved
Reserved
24
Reserved
I2C3LPEN I2C3EN
Reserved
23
I2C2LPEN DMA2LPEN I2C2EN 22
I2C1LPEN DMA1LPEN I2C1EN 21
UART5LPEN UART5EN
Reserved
20
Reserved
UART4LPEN UART4EN
INCSTEP
19
Reserved
TIM11LPEN USART3LPEN BKPSRAMLPEN TIM11EN USART3EN 18
TIM10LPEN USART2LPEN SRAM2LPEN TIM10EN USART2EN 17
RM0090 Rev 19
BDRST TIM9LPEN Reserved SRAM1LPEN TIM9EN Reserved 16
RTCEN Reserved SPI3LPEN FLITFLPEN Reserved SPI3EN
Reserved
15
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
SDIOLPEN WWDGLPEN SDIOEN WWDGEN
Reserved
11
ADC3LPEN Reserved ADC3EN 10
Reserved Reserved
RTCSEL 1 ADC2LPEN ADC2EN
PLLI2SNx
9
RTCSEL 0 ADC1LPEN TIM14LPEN GPIOILPEN ADC1EN TIM14EN 8
Table 34. RCC register map and reset values (continued)
Reset and clock control for STM32F405xx/07xx and STM32F415xx/17xx(RCC)
Refer to Section 2.3: Memory map for the register boundary addresses.
TIM13LPEN OTGFSLPEN GPIOHLPEN TIM13EN 7
Reserved Reserved
TIM12LPEN RNGLPEN GPIOGLPEN TIM12EN 6
USART6LPEN TIM7LPEN HASHLPEN GPIOFLPEN USART6EN TIM7EN
MODPER
5
USART1LPEN TIM6LPEN CRYPLPEN GPIOELPEN USART1EN TIM6EN
Reserved
4
TIM5LPEN GPIODLPEN TIM5EN 3
Reserved Reserved
LSEBYP TIM4LPEN Reserved GPIOCLPEN TIM4EN 2
Reserved
LSIRDY LSERDY TIM8LPEN TIM3LPEN GPIOBLPEN TIM8EN TIM3EN 1
LSION LSEON TIM1LPEN TIM2LPEN FSMCLPEN DCMILPEN GPIOALPEN TIM1EN TIM2EN 0
RM0090
RM0090 General-purpose I/Os (GPIO)
This section applies to the whole STM32F4xx family, unless otherwise specified.
Each I/O port bit is freely programmable, however the I/O port registers have to be
accessed as 32-bit words, half-words or bytes. The purpose of the GPIOx_BSRR register is
to allow atomic read/modify accesses to any of the GPIO registers. In this way, there is no
risk of an IRQ occurring between the read and the modify access.
Figure 25 shows the basic structure of a 5 V tolerant I/O port bit. Table 39 gives the possible
port bit configurations.
To on-chip Analog
peripheral
Alternate function input
on/off
Input data register
Read
VDD VDD_FT (1)
TTL Schmitt
Bit set/reset registers
Protection
trigger on/off
Pull diode
up
Input driver I/O pin
Write
Output data register
1. VDD_FT is a potential specific to five-volt tolerant I/Os and different from VDD.
0 0 0 GP output PP
0 0 1 GP output PP + PU
0 1 0 GP output PP + PD
0 SPEED 1 1 Reserved
01
1 [B:A] 0 0 GP output OD
1 0 1 GP output OD + PU
1 1 0 GP output OD + PD
1 1 1 Reserved (GP output OD)
0 0 0 AF PP
0 0 1 AF PP + PU
0 1 0 AF PP + PD
0 SPEED 1 1 Reserved
10
1 [B:A] 0 0 AF OD
1 0 1 AF OD + PU
1 1 0 AF OD + PD
1 1 1 Reserved
x x x 0 0 Input Floating
x x x 0 1 Input PU
00
x x x 1 0 Input PD
x x x 1 1 Reserved (input floating)
x x x 0 0 Input/output Analog
x x x 0 1
11
x x x 1 0 Reserved
x x x 1 1
1. GP = general-purpose, PP = push-pull, PU = pull-up, PD = pull-down, OD = open-drain, AF = alternate
function.
• GPIO
Configure the desired I/O as output or input in the GPIOx_MODER register.
• Peripheral alternate function
For the ADC and DAC, configure the desired I/O as analog in the GPIOx_MODER
register.
For other peripherals:
– Configure the desired I/O as an alternate function in the GPIOx_MODER register
– Select the type, pull-up/pull-down and output speed via the GPIOx_OTYPER,
GPIOx_PUPDR and GPIOx_OSPEEDR registers, respectively
– Connect the I/O to the desired AFx in the GPIOx_AFRL or GPIOx_AFRH register
• EVENTOUT
Configure the I/O pin used to output the Cortex®-M4 with FPU EVENTOUT signal by
connecting it to AF15
Note: EVENTOUT is not mapped onto the following I/O pins: PC13, PC14, PC15, PH0, PH1 and
PI8.
Refer to the “Alternate function mapping” table in the datasheets for the detailed mapping of
the system and peripherals’ alternate function I/O pins.
AF0 (system)
AF1 (TIM1/TIM2)
AF2 (TIM3..5)
AF3 (TIM8..11)
AF4 (I2C1..3)
AF5 (SPI1/SPI2)
AF6 (SPI3) Pin x (x = 0..7)
AF7 (USART1..3)
1
AF8 (USART4..6)
AF9 (CAN1/CAN2, TIM12..14)
AF10 (OTG_FS, OTG_HS)
AF11 (ETH)
AF12 (FSMC, SDIO, OTG_HS(1))
AF13 (DCMI)
AF14
AF15 (EVENTOUT)
AFRL[31:0]
For pins 8 to 15, the GPIOx_AFRH[31:0] register selects the dedicated alternate function
AF0 (system)
AF1 (TIM1/TIM2)
AF2 (TIM3..5)
AF3 (TIM8..11)
AF4 (I2C1..3)
AF5 (SPI1/SPI2)
AF6 (SPI3) Pin x (x = 8..15)
AF7 (USART1..3)
AF8 (USART4..6) 1
AF9 (CAN1/CAN2, TIM12..14)
AF10 (OTG_FS, OTG_HS)
AF11 (ETH)
AF12 (FSMC, SDIO, OTG_HS(1))
AF13 (DCMI)
AF14
AF15 (EVENTOUT)
AFRH[31:0] ai17538
1. Configured in FS.
For pins 0 to 7, the GPIOx_AFRL[31:0] register selects the dedicated alternate function
AF0 (system)
AF1 (TIM1/TIM2)
AF2 (TIM3..5)
AF3 (TIM8..11)
AF4 (I2C1..3)
AF5 (SPI1/2/3/4/5/6)
AF6 (SPI2/3/SAI1) Pin x (x = 0..7)
AF7 (USART1..3)
1
AF8 (USART4..8)
AF9 (CAN1/CAN2, LTDC, TIM12..14)
AF10 (OTG_FS, OTG_HS)
AF11 (ETH)
AF12 (FMC, SDIO, OTG_HS(1))
AF13 (DCMI)
AF14 (LTDC)
AF15 (EVENTOUT)
AFRL[31:0]
For pins 8 to 15, the GPIOx_AFRH[31:0] register selects the dedicated alternate function
AF0 (system)
AF1 (TIM1/TIM2)
AF2 (TIM3..5)
AF3 (TIM8..11)
AF4 (I2C1..3)
AF5 (SPI1/2/4/5/6)
AF6 (SPI2/3/SAI1) Pin x (x = 8..15)
AF7 (USART1..3)
AF8 (USART4..8) 1
AF9 (CAN1/CAN2, TIM12..14)
AF10 (OTG_FS, OTG_HS)
AF11 (ETH)
AF12 (FMC, SDIO, OTG_HS(1))
AF13 (DCMI)
AF14 (LTDC)
AF15 (EVENTOUT)
AFRH[31:0]
MS60208V1
1. Configured in FS.
ai15940b
ai15941b
on
Read
VDD VDD
TTL Schmitt on/off
Bit set/reset registers
trigger protection
Pull diode
Input driver up
Write
Output data register
I/O pin
Output driver VDD on/off
Pull protection
P-MOS down diode
Output
control VSS VSS
N-MOS
Read/write
VSS push-pull or
open-drain
From on-chip
peripheral Alternate function output
ai15942b
Analog
To on-chip
peripheral
Input data register
Read off
0
VDD
Bit set/reset registers
TTL Schmitt
trigger protection
Write diode
Output data register
Input driver
I/O pin
protection
diode
Read/write VSS
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
OT15 OT14 OT13 OT12 OT11 OT10 OT9 OT8 OT7 OT6 OT5 OT4 OT3 OT2 OT1 OT0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OSPEEDR15 OSPEEDR14 OSPEEDR13 OSPEEDR12 OSPEEDR11 OSPEEDR10 OSPEEDR9 OSPEEDR8
[1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OSPEEDR1 OSPEEDR0
OSPEEDR7[1:0] OSPEEDR6[1:0] OSPEEDR5[1:0] OSPEEDR4[1:0] OSPEEDR3[1:0] OSPEEDR2[1:0]
[1:0] 1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PUPDR15[1:0] PUPDR14[1:0] PUPDR13[1:0] PUPDR12[1:0] PUPDR11[1:0] PUPDR10[1:0] PUPDR9[1:0] PUPDR8[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PUPDR7[1:0] PUPDR6[1:0] PUPDR5[1:0] PUPDR4[1:0] PUPDR3[1:0] PUPDR2[1:0] PUPDR1[1:0] PUPDR0[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
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
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AFRL7[3:0] AFRL6[3:0] AFRL5[3:0] AFRL4[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AFRL3[3:0] AFRL2[3:0] AFRL1[3:0] AFRL0[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 AFRLy: Alternate function selection for port x bit y (y = 0..7)
These bits are written by software to configure alternate function I/Os
AFRLy selection:
0000: AF0 1000: AF8
0001: AF1 1001: AF9
0010: AF2 1010: AF10
0011: AF3 1011: AF11
0100: AF4 1100: AF12
0101: AF5 1101: AF13
0110: AF6 1110: AF14
0111: AF7 1111: AF15
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AFRH15[3:0] AFRH14[3:0] AFRH13[3:0] AFRH12[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
AFRH11[3:0] AFRH10[3:0] AFRH9[3:0] AFRH8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 AFRHy: Alternate function selection for port x bit y (y = 8..15)
These bits are written by software to configure alternate function I/Os
AFRHy selection:
0000: AF0 1000: AF8
0001: AF1 1001: AF9
0010: AF2 1010: AF10
0011: AF3 1011: AF11
0100: AF4 1100: AF12
0101: AF5 1101: AF13
0110: AF6 1110: AF14
0111: AF7 1111: AF15
0x0C
0x0C
Offset
8.4.11
RM0090
B)
A..I/J/K)
C..I/J/K)
GPIOx_
GPIOx_
MODER
MODER
GPIOB_
GPIOB_
GPIOA_
OTYPER
(where x =
(where x =
(where x =
OSPEEDR
OSPEEDR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
A..I/J/K except
GPIOB_PUPDR
GPIOA_PUPDR
GPIOx_MODER
0
0
0
0
0
0
1
PUPDR15[1:0] PUPDR15[1:0] OSPEEDR15[1:0] OSPEEDR15[1:0] MODER15[1:0] MODER15[1:0] MODER15[1:0] 31
0
1
0
0
0
0
0
30
0
1
0
0
0
0
1
PUPDR14[1:0] PUPDR14[1:0] OSPEEDR14[1:0] OSPEEDR14[1:0] MODER14[1:0] MODER14[1:0] MODER14[1:0] 29
0
0
0
0
0
0
0
28
0
0
0
0
0
0
1
PUPDR13[1:0] PUPDR13[1:0] OSPEEDR13[1:0] OSPEEDR13[1:0] MODER13[1:0] MODER13[1:0] MODER13[1:0] 27
0
1
0
0
0
0
0
26
GPIO register map
0
0
0
0
0
0
0 25
PUPDR12[1:0] PUPDR12[1:0] OSPEEDR12[1:0] OSPEEDR12[1:0] MODER12[1:0] MODER12[1:0] MODER12[1:0]
0
0
0
0
0
0
0
24
0
0
0
0
0
0
0
Reserved
MODER11[1:0] MODER11[1:0] MODER11[1:0]
0
0
0
0
0
0
0
22
0
0
0
0
0
0
0
0
0
0
0
0
0
0
20
0
0
0
0
0
0
0
0
0
0
0
0
0
0
18
0
0
0
0
0
0
0
RM0090 Rev 19
PUPDR8[1:0] PUPDR8[1:0] OSPEEDR8[1:0] OSPEEDR8[1:0] MODER8[1:0] MODER8[1:0] MODER8[1:0] 17
0
0
0
0
0
0
0
16
0
0
0
0
0
0
0
0
OT15 15
PUPDR7[1:0] PUPDR7[1:0] OSPEEDR7[1:0] OSPEEDR7[1:0] MODER7[1:0] MODER7[1:0] MODER7[1:0]
0
0
0
0
0
0
0
0
OT14 14
0
0
0
0
0
0
0
0
OT13 13
PUPDR6[1:0] PUPDR6[1:0] OSPEEDR6[1:0] OSPEEDR6[1:0] MODER6[1:0] MODER6[1:0] MODER6[1:0]
0
0
0
0
0
0
0
0
OT12 12
0
0
0
0
0
0
0
0
OT11
Table 39. GPIO register map and reset values
0
0
0
0
0
0
0
0 OT10 10
0
0
0
0
0
1
0
0
OT9 9
PUPDR4[1:0] PUPDR4[1:0] OSPEEDR4[1:0] OSPEEDR4[1:0] MODER4[1:0] MODER4[1:0] MODER4[1:0]
The following table gives the GPIO register map and the reset values.
1
0
0
0
0
0
0
OT8 8
0
0
1
0
0
1
0
OT7 7
PUPDR3[1:0] PUPDR3[1:0] OSPEEDR3[1:0] OSPEEDR3[1:0] MODER3[1:0] MODER3[1:0] MODER3[1:0]
0
0
1
0
0
0
0
OT6 6
0
0
0
0
0
0
0
OT5 5
PUPDR2[1:0] PUPDR2[1:0] OSPEEDR2[1:0] OSPEEDR2[1:0] MODER2[1:0] MODER2[1:0] MODER2[1:0]
0
0
0
0
0
0
0
OT4 4
0
0
0
0
0
0
0
OT3 3
PUPDR1[1:0] PUPDR1[1:0] OSPEEDR1[1:0] OSPEEDR1[1:0] MODER1[1:0] MODER1[1:0] MODER1[1:0]
0
0
0
0
0
0
0
OT2 2
0
0
0
0
0
0
0
OT1 1
PUPDR0[1:0] PUPDR0[1:0] OSPEEDR0[1:0] OSPEEDR0[1:0] MODER0[1:0] MODER0[1:0] MODER0[1:0]
0
0
0
0
0
0
0
OT0
287/1751
General-purpose I/Os (GPIO)
288
General-purpose I/Os (GPIO) RM0090
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PUPDR15[1:0]
PUPDR14[1:0]
PUPDR13[1:0]
PUPDR12[1:0]
PUPDR10[1:0]
PUPDR11[1:0]
PUPDR9[1:0]
PUPDR8[1:0]
PUPDR7[1:0]
PUPDR6[1:0]
PUPDR5[1:0]
PUPDR4[1:0]
PUPDR3[1:0]
PUPDR2[1:0]
PUPDR1[1:0]
PUPDR0[1:0]
GPIOx_PUPDR
(where x =
0x0C C..I/J/K)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_IDR
IDR15
IDR14
IDR13
IDR12
IDR10
IDR11
IDR9
IDR8
IDR7
IDR6
IDR5
IDR4
IDR3
IDR2
IDR1
IDR0
(where x =
0x10 A..I/J/K) Reserved
Reset value x x x x x x x x x x x x x x x x
GPIOx_ODR
ODR15
ODR14
ODR13
ODR12
ODR10
ODR11
ODR9
ODR8
ODR7
ODR6
ODR5
ODR4
ODR3
ODR2
ODR1
ODR0
(where x =
0x14 A..I/J/K) Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_BSRR
BR15
BR14
BR13
BR12
BR10
BS15
BS14
BS13
BS12
BS10
BR11
BS11
BR9
BR8
BR7
BR6
BR5
BR4
BR3
BR2
BR1
BR0
BS9
BS8
BS7
BS6
BS5
BS4
BS3
BS2
BS1
BS0
(where x =
0x18 A..I/J/K)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_LCKR
LCK15
LCK14
LCK13
LCK12
LCK10
LCK11
LCKK
LCK9
LCK8
LCK7
LCK6
LCK5
LCK4
LCK3
LCK2
LCK1
LCK0
(where x =
0x1C A..I/J/K) Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_AFRL
(where x = AFRL7[3:0] AFRL6[3:0] AFRL5[3:0] AFRL4[3:0] AFRL3[3:0] AFRL2[3:0] AFRL1[3:0] AFRL0[3:0]
0x20 A..I/J/K)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_AFRH
(where x = AFRH15[3:0] AFRH14[3:0] AFRH13[3:0] AFRH12[3:0] AFRH11[3:0] AFRH10[3:0] AFRH9[3:0] AFRH8[3:0]
0x24 A..I/J)
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
Refer to Section 2.3: Memory map for the register boundary addresses.
The system configuration controller is mainly used to remap the memory accessible in the
code area, select the Ethernet PHY interface and manage the external interrupt line
connection to the GPIOs.
This section applies to the whole STM32F4xx family, unless otherwise specified.
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
MEM_MODE
Reserved
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MII_RMII
Reserved _SEL Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
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
EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
EXTI11[3:0] EXTI10[3:0] EXTI9[3:0] EXTI8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
READY CMP_PD
Reserved Reserved
r rw
Table 40. SYSCFG register map and reset values (STM32F405xx/07xx and STM32F415xx/17xx)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
MEM_MODE
SYSCFG_
0x00 MEMRMP Reserved
Reset value x x
MII_RMII_SEL
SYSCFG_PMC
0x04 Reserved Reserved Reserved
Reset value 0
SYSCFG_EXTICR1 EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[3:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR2 EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR3 EXTI11[3:0] EXTI10[3:0] EXTI9[3:0] EXTI8[3:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR4 EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CMP_PD
READY
SYSCFG_CMPCR
0x20 Reserved Reserved
Reset value 0 0
Refer to Section 2.3: Memory map for the register boundary addresses.
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
FB_
SWP_FMC
MODE
MEM_MODE[2:0]
Reserved Res. Reserved
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MII_RMII
ADCxDC2
Reserved _SEL Reserved
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
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
EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
EXTI11[3:0] EXTI10[3:0] EXTI9[3:0] EXTI8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
READY CMP_PD
Reserved Reserved
r rw
Table 41. SYSCFG register map and reset values (STM32F42xxx and STM32F43xxx)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
SWP_FMC
FB_MODE
Reserved
SYSCFG_ MEM_
0x00 MEMRMP Reserved Reserved MODE
ADC3DC2
ADC2DC2
ADC1DC2
SYSCFG_PMC
0x04 Reserved Reserved Reserved
Reset value 0 0 0 0
SYSCFG_EXTICR1 EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[3:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR2 EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0]
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR3 EXTI11[3:0] EXTI10[3:0] EXTI9[3:0] EXTI8[3:0]
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYSCFG_EXTICR4 EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CMP_PD
READY
SYSCFG_CMPCR
0x20 Reserved Reserved
Reset value 0 0
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
DMA controller
AHB master
REQ_STR0_CH0
REQ_STR0_CH1 Memory port
REQ_STR0_CH7
STREAM 1
STREAM 2
STREAM 3
STREAM 5
STREAM 6
STREAM 0
STREAM 4
STREAM 7
REQ_STR1_CH0
REQ_STR1_CH1
REQ_STREAM0
REQ_STREAM1
REQ_STR1_CH7 REQ_STREAM2
REQ_STREAM3
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
FIFO
REQ_STREAM4 Arbiter
REQ_STREAM5
REQ_STREAM6
STREAM 0
STREAM 1
STREAM 2
STREAM 3
STREAM 4
STREAM 5
STREAM 6
STREAM 7
REQ_STREAM7
REQ_STR7_CH0
REQ_STR7_CH1
AHB master
REQ_STR7_CH7 Peripheral port
Channel
selection
AHB slave
programming Programming port
interface
ai15945
The DMA controller performs direct memory transfer: as an AHB master, it can take the
control of the AHB bus matrix to initiate AHB transactions.
It can carry out the following transactions:
• peripheral-to-memory
• memory-to-peripheral
• memory-to-memory
The DMA controller provides two AHB master ports: the AHB memory port, intended to be
connected to memories and the AHB peripheral port, intended to be connected to
peripherals. However, to allow memory-to-memory transfers, the AHB peripheral port must
also have access to the memories.
The AHB slave port is used to program the DMA controller (it supports only 32-bit
accesses).
See Figure 33 and Figure 34 for the implementation of the system of two DMA controllers.
DCODE
Bus matrix
(AHB Flash
ICODE
multilayer) memory
112 KB SRAM
16 KB SRAM
AHB1 peripherals
DMA controller 2
AHB memory
port
peripherals
AHB-APB APB2
APB2
To AHB2
bridge2
Arbiter
FIFO
AHB slave
peripherals
(dual AHB)
AHB periph
port
AHB-APB APB1
APB1
bridge1
peripherals
(dual AHB)
DMA request
MAPPING
AHB memory
AHB2 peripherals
port
peripherals
Arbiter
To AHB2
AHB slave
FIFO
External memory
AHB periph
controller (FSMC)
port
DMA controller 1
MS19927V2
1. The DMA1 controller AHB peripheral port is not connected to the bus matrix like DMA2 controller. As a result, only DMA2
streams are able to perform memory-to-memory transfers.
Figure 34. System implementation of the two DMA controllers (STM32F42xxx and
STM32F43xxx)
Bus Matrix
(AHB multilayer) DCODE
Flash
ICODE
memory
112 KB SRAM
16 KB SRAM
64 KB SRAM
AHB1 peripherals
DMA controller 2 AHB memory
port
peripherals
AHB-APB APB2
APB2
To AHB2
bridge2
Arbiter
FIFO
AHB slave
peripherals
(dual AHB)
AHB periph
port
AHB-APB APB1
APB1
bridge1
peripherals
(dual AHB)
DMA request
MAPPING
AHB memory
AHB2 peripherals
port
peripherals
Arbiter
To AHB2
AHB slave
FIFO
External memory
AHB periph
controller (FMC)
port
DMA controller 1
MS30438V1
1. The DMA1 controller AHB peripheral port is not connected to the bus matrix like in the case of the DMA2
controller, thus only DMA2 streams are able to perform memory-to-memory transfers.
After an event, the peripheral sends a request signal to the DMA controller. The DMA
controller serves the request depending on the channel priorities. As soon as the DMA
controller accesses the peripheral, an Acknowledge signal is sent to the peripheral by the
DMA controller. The peripheral releases its request as soon as it gets the Acknowledge
signal from the DMA controller. Once the request has been deasserted by the peripheral,
the DMA controller releases the Acknowledge signal. If there are more requests, the
peripheral can initiate the next transaction.
REQ_STRx_CH6
REQ_STRx_CH5
REQ_STREAMx
REQ_STRx_CH4
REQ_STRx_CH3
REQ_STRx_CH2
REQ_STRx_CH1
REQ_STRx_CH0
31 27 25 0
DMA_SxCR CHSEL[2:0]
ai15947b
The 8 requests from the peripherals (TIM, ADC, SPI, I2C, etc.) are independently connected
to each channel and their connection depends on the product implementation.
See the following table(s) for examples of DMA request mappings.
TIM8_CH1 TIM1_CH1
Channel 0 ADC1 SAI1_A(1) TIM8_CH2 SAI1_A(1) ADC1 SAI1_B(1) TIM1_CH2 -
TIM8_CH3 TIM1_CH3
TIM1_CH4
Channel 6 TIM1_TRIG TIM1_CH1 TIM1_CH2 TIM1_CH1 TIM1_TRIG TIM1_UP TIM1_CH3 -
TIM1_COM
TIM8_CH4
Channel 7 - TIM8_UP TIM8_CH1 TIM8_CH2 TIM8_CH3 SPI5_RX(1) SPI5_TX(1) TIM8_TRIG
TIM8_COM
10.3.4 Arbiter
An arbiter manages the 8 DMA stream requests based on their priority for each of the two
AHB master ports (memory and peripheral ports) and launches the peripheral/memory
access sequences.
Priorities are managed in two stages:
• Software: each stream priority can be configured in the DMA_SxCR register. There are
four levels:
– Very high priority
– High priority
– Medium priority
– Low priority
• Hardware: If two requests have the same software priority level, the stream with the
lower number takes priority over the stream with the higher number. For example,
Stream 2 takes priority over Stream 4.
When the data width (programmed in the PSIZE or MSIZE bits in the DMA_SxCR register)
is a half-word or a word, respectively, the peripheral or memory address written into the
DMA_SxPAR or DMA_SxM0AR/M1AR registers has to be aligned on a word or half-word
address boundary, respectively.
Peripheral-to-memory mode
Figure 36 describes this mode.
When this mode is enabled (by setting the bit EN in the DMA_SxCR register), each time a
peripheral request occurs, the stream initiates a transfer from the source to fill the FIFO.
When the threshold level of the FIFO is reached, the contents of the FIFO are drained and
stored into the destination.
The transfer stops once the DMA_SxNDTR register reaches zero, when the peripheral
requests the end of transfers (in case of a peripheral flow controller) or when the EN bit in
the DMA_SxCR register is cleared by software.
In direct mode (when the DMDIS value in the DMA_SxFCR register is ‘0’), the threshold
level of the FIFO is not used: after each single data transfer from the peripheral to the FIFO,
the corresponding data are immediately drained and stored into the destination.
The stream has access to the AHB source or destination port only if the arbitration of the
corresponding stream is won. This arbitration is performed using the priority defined for
each stream using the PL[1:0] bits in the DMA_SxCR register.
DMA_SxM1AR(1)
Memory
destination
FIFO
REQ_STREAMx Arbiter level
FIFO
Peripheral
DMA_SxPAR source
Memory-to-peripheral mode
Figure 37 describes this mode.
When this mode is enabled (by setting the EN bit in the DMA_SxCR register), the stream
immediately initiates transfers from the source to entirely fill the FIFO.
Each time a peripheral request occurs, the contents of the FIFO are drained and stored into
the destination. When the level of the FIFO is lower than or equal to the predefined
threshold level, the FIFO is fully reloaded with data from the memory.
The transfer stops once the DMA_SxNDTR register reaches zero, when the peripheral
requests the end of transfers (in case of a peripheral flow controller) or when the EN bit in
the DMA_SxCR register is cleared by software.
In direct mode (when the DMDIS value in the DMA_SxFCR register is '0'), the threshold
level of the FIFO is not used. Once the stream is enabled, the DMA preloads the first data to
transfer into an internal FIFO. As soon as the peripheral requests a data transfer, the DMA
transfers the preloaded value into the configured destination. It then reloads again the
empty internal FIFO with the next data to be transfer. The preloaded data size corresponds
to the value of the PSIZE bitfield in the DMA_SxCR register.
The stream has access to the AHB source or destination port only if the arbitration of the
corresponding stream is won. This arbitration is performed using the priority defined for
each stream using the PL[1:0] bits in the DMA_SxCR register.
DMA_SxM1AR(1)
Memory bus
AHB memory
port
Memory
source
FIFO
Arbiter
REQ_STREAMx level FIFO
Peripheral
DMA_SxPAR destination
ai15949
Memory-to-memory mode
The DMA channels can also work without being triggered by a request from a peripheral.
This is the memory-to-memory mode, described in Figure 38.
When the stream is enabled by setting the Enable bit (EN) in the DMA_SxCR register, the
stream immediately starts to fill the FIFO up to the threshold level. When the threshold level
is reached, the FIFO contents are drained and stored into the destination.
The transfer stops once the DMA_SxNDTR register reaches zero or when the EN bit in the
DMA_SxCR register is cleared by software.
The stream has access to the AHB source or destination port only if the arbitration of the
corresponding stream is won. This arbitration is performed using the priority defined for
each stream using the PL[1:0] bits in the DMA_SxCR register.
Note: When memory-to-memory mode is used, the Circular and direct modes are not allowed.
Only the DMA2 controller is able to perform memory-to-memory transfers.
DMA_SxM1AR(1)
Memory 2
destination
Arbiter FIFO
Stream enable level FIFO
Memory 1
DMA_SxPAR source
ai15950
Table 45. Source and destination address registers in Double buffer mode (DBM=1)
Bits DIR[1:0] of the
Direction Source address Destination address
DMA_SxCR register
DMA_SxM0AR /
00 Peripheral-to-memory DMA_SxPAR
DMA_SxM1AR
DMA_SxM0AR /
01 Memory-to-peripheral DMA_SxPAR
DMA_SxM1AR
10 Not allowed(1)
11 Reserved - -
1. When the Double buffer mode is enabled, the Circular mode is automatically enabled. Since the memory-
to-memory mode is not compatible with the Circular mode, when the Double buffer mode is enabled, it is
not allowed to configure the memory-to-memory mode.
4 0x3 / B3[7:0]
Note: Peripheral port may be the source or the destination (it could also be the memory source in
the case of memory-to-memory transfer).
PSIZE, MSIZE and NDT[15:0] have to be configured so as to ensure that the last transfer
will not be incomplete. This can occur when the data width of the peripheral port (PSIZE
bits) is lower than the data width of the memory port (MSIZE bits). This constraint is
summarized in Table 47.
10.3.12 FIFO
FIFO structure
The FIFO is used to temporarily store data coming from the source before transmitting them
to the destination.
Each stream has an independent 4-word FIFO and the threshold level is software-
configurable between 1/4, 1/2, 3/4 or full.
To enable the use of the FIFO threshold level, the direct mode must be disabled by setting
the DMDIS bit in the DMA_SxFCR register.
The structure of the FIFO differs depending on the source and destination data widths, and
is described in Figure 39: FIFO structure.
4 words
4 words
4 words
4-words
ai15951
In all cases, the burst size multiplied by the data size must not exceed the FIFO size (data
size can be: 1 (byte), 2 (half-word) or 4 (word)).
Incomplete Burst transfer at the end of a DMA transfer may happen if one of the following
conditions occurs:
• For the AHB peripheral port configuration: the total number of data items (set in the
DMA_SxNDTR register) is not a multiple of the burst size multiplied by the data size
• For the AHB memory port configuration: the number of remaining data items in the
FIFO to be transferred to the memory is not a multiple of the burst size multiplied by the
data size
In such cases, the remaining data to be transferred will be managed in single mode by the
DMA, even if a burst transaction was requested during the DMA stream configuration.
Note: When burst transfers are requested on the peripheral AHB port and the FIFO is used
(DMDIS = 1 in the DMA_SxCR register), it is mandatory to respect the following rule to
avoid permanent underrun or overrun conditions, depending on the DMA stream direction:
If (PBURST × PSIZE) = FIFO_SIZE (4 words), FIFO_Threshold = 3/4 is forbidden with
PSIZE = 1, 2 or 4 and PBURST = 4, 8 or 16.
This rule ensures that enough FIFO space at a time will be free to serve the request from
the peripheral.
FIFO flush
The FIFO can be flushed when the stream is disabled by resetting the EN bit in the
DMA_SxCR register and when the stream is configured to manage peripheral-to-memory or
memory-to-memory transfers: If some data are still present in the FIFO when the stream is
disabled, the DMA controller continues transferring the remaining data to the destination
(even though stream is effectively disabled). When this flush is completed, the transfer
complete status bit (TCIFx) in the DMA_LISR or DMA_HISR register is set.
The remaining data counter DMA_SxNDTR keeps the value in this case to indicate how
many data items are currently available in the destination memory.
Note that during the FIFO flush operation, if the number of remaining data items in the FIFO
to be transferred to memory (in bytes) is less than the memory data width (for example 2
bytes in FIFO while MSIZE is configured to word), data will be sent with the data width set in
the MSIZE bit in the DMA_SxCR register. This means that memory will be written with an
undesired value. The software may read the DMA_SxNDTR register to determine the
memory area that contains the good data (start address and last address).
If the number of remaining data items in the FIFO is lower than a burst size (if the MBURST
bits in DMA_SxCR register are set to configure the stream to manage burst on the AHB
memory port), single transactions will be generated to complete the FIFO flush.
Direct mode
By default, the FIFO operates in direct mode (DMDIS bit in the DMA_SxFCR is reset) and
the FIFO threshold level is not used. This mode is useful when the system requires an
immediate and single transfer to or from the memory after each DMA request.
When the DMA is configured in direct mode (FIFO disabled), to transfer data in memory-to-
peripheral mode, the DMA preloads one data from the memory to the internal FIFO to
ensure an immediate data transfer as soon as a DMA request is triggered by a peripheral.
To avoid saturating the FIFO, it is recommended to configure the corresponding stream with
a high priority.
This mode is restricted to transfers where:
• The source and destination transfer widths are equal and both defined by the
PSIZE[1:0] bits in DMA_SxCR (MSIZE[1:0] bits are don’t care)
• Burst transfers are not possible (PBURST[1:0] and MBURST[1:0] bits in DMA_SxCR
are don’t care)
Direct mode must not be used when implementing memory-to-memory transfers.
to-memory) all the remaining data have been flushed from the FIFO into the
memory
• In Peripheral flow controller mode:
– The last external burst or single request has been generated from the peripheral
and (when the DMA is operating in peripheral-to-memory mode) the remaining
data have been transferred from the FIFO into the memory
– The stream is disabled by software, and (when the DMA is operating in peripheral-
to-memory mode) the remaining data have been transferred from the FIFO into
the memory
Note: The transfer completion is dependent on the remaining data in FIFO to be transferred into
memory only in the case of peripheral-to-memory mode. This condition is not applicable in
memory-to-peripheral mode.
If the stream is configured in noncircular mode, after the end of the transfer (that is when the
number of data to be transferred reaches zero), the DMA is stopped (EN bit in DMA_SxCR
register is cleared by Hardware) and no DMA request is served unless the software
reprograms the stream and re-enables it (by setting the EN bit in the DMA_SxCR register).
single possible
DMA possible possible
Peripheral-to- AHB AHB burst forbidden
memory peripheral port memory port single possible
Peripheral forbidden forbidden
burst forbidden
single possible
DMA possible possible
Memory-to- AHB AHB burst forbidden
peripheral memory port peripheral port single possible
Peripheral forbidden forbidden
burst forbidden
Double buffer mode and interrupts after half and/or full transfer, and/or errors in the
DMA_SxCR register.
10. Activate the stream by setting the EN bit in the DMA_SxCR register.
As soon as the stream is enabled, it can serve any DMA request from the peripheral
connected to the stream.
Once half the data have been transferred on the AHB destination port, the half-transfer flag
(HTIF) is set and an interrupt is generated if the half-transfer interrupt enable bit (HTIE) is
set. At the end of the transfer, the transfer complete flag (TCIF) is set and an interrupt is
generated if the transfer complete interrupt enable bit (TCIE) is set.
If the DMEIFx or the FEIFx flag is set due to an overrun or underrun condition, the faulty
stream is not automatically disabled and it is up to the software to disable or not the stream
by resetting the EN bit in the DMA_SxCR register. This is because there is no data loss
when this kind of errors occur.
When the stream's error interrupt flag (TEIF, FEIF, DMEIF) in the DMA_LISR or DMA_HISR
register is set, an interrupt is generated if the corresponding interrupt enable bit (TEIE,
FEIE, DMIE) in the DMA_SxCR or DMA_SxFCR register is set.
Note: When a FIFO overrun or underrun condition occurs, the data are not lost because the
peripheral request is not acknowledged by the stream until the overrun or underrun
condition is cleared. If this acknowledge takes too much time, the peripheral itself may
detect an overrun or underrun condition of its internal buffer and data might be lost.
Note: Before setting an Enable control bit to ‘1’, the corresponding event flag should be cleared,
otherwise an interrupt is immediately generated.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TCIF7 HTIF7 TEIF7 DMEIF7 Reserv FEIF7 TCIF6 HTIF6 TEIF6 DMEIF6 Reserv FEIF6
Reserved
ed ed
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
TCIF5 HTIF5 TEIF5 DMEIF5 Reserv FEIF5 TCIF4 HTIF4 TEIF4 DMEIF4 Reserv FEIF4
Reserved
ed ed
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
CTCIF3 CHTIF3 CTEIF3 CDMEIF3 CFEIF3 CTCIF2 CHTIF2 CTEIF2 CDMEIF2 CFEIF2
Reserved Reserved Reserved
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
CTCIF1 CHTIF1 CTEIF1 CDMEIF1 CFEIF1 CTCIF0 CHTIF0 CTEIF0 CDMEIF0 CFEIF0
Reserved Reserved Reserved
w w w w w w w w w w
Bits 24, 18, 8, 2 CDMEIFx: Stream x clear direct mode error interrupt flag (x = 7..4)
Writing 1 to this bit clears the corresponding DMEIFx flag in the DMA_HISR register
Bits 23, 17, 7, 1 Reserved, must be kept at reset value.
Bits 22, 16, 6, 0 CFEIFx: Stream x clear FIFO error interrupt flag (x = 7..4)
Writing 1 to this bit clears the corresponding CFEIFx flag in the DMA_HISR register
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CHSEL[2:0] MBURST [1:0] PBURST[1:0] Reser- CT DBM PL[1:0]
Reserved
rw rw rw rw rw rw rw ved rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PINCOS MSIZE[1:0] PSIZE[1:0] MINC PINC CIRC DIR[1:0] PFCTRL TCIE HTIE TEIE DMEIE EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bit 0 EN: Stream enable / flag stream ready when read low
This bit is set and cleared by software.
0: Stream disabled
1: Stream enabled
This bit may be cleared by hardware:
– on a DMA end of transfer (stream ready to be configured)
– if a transfer error occurs on the AHB master buses
– when the FIFO threshold on memory AHB port is not compatible with the size of the
burst
When this bit is read as 0, the software is allowed to program the Configuration and FIFO
bits registers. It is forbidden to write these registers when the EN bit is read as 1.
Note: Before setting EN bit to '1' to start a new transfer, the event flags corresponding to the
stream in DMA_LISR or DMA_HISR register must be cleared.
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[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PAR[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
PAR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
M0A[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
M0A[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
M1A[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
M1A[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:0 M1A[31:0]: Memory 1 address (used in case of Double buffer mode)
Base address of Memory area 1 from/to which the data will be read/written.
This register is used only for the Double buffer mode.
These bits are write-protected. They can be written only if:
– the stream is disabled (bit EN= '0' in the DMA_SxCR register) or
– the stream is enabled (EN=’1’ in DMA_SxCR register) and bit CT = '0' in the
DMA_SxCR register.
10
11
9
8
7
6
5
4
3
2
1
0
DMEIF3
DMEIF2
DMEIF1
DMEIF0
TCIF3
HTIF3
TCIF2
HTIF2
TCIF1
HTIF1
TCIF0
HTIF0
TEIF3
FEIF3
TEIF2
FEIF2
TEIF1
FEIF1
TEIF0
FEIF0
Reserved
Reserved
Reserved
Reserved
DMA_LISR
0x0000 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMEIF7
DMEIF6
DMEIF5
DMEIF4
TCIF7
HTIF7
TCIF6
HTIF6
TCIF5
HTIF5
TCIF4
HTIF4
TEIF7
FEIF7
TEIF6
FEIF6
TEIF5
FEIF5
TEIF4
FEIF4
Reserved
Reserved
Reserved
Reserved
DMA_HISR
0x0004 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CDMEIF3
CDMEIF2
CDMEIF1
CDMEIF0
Reserved Reserved
Reserved Reserved
Reserved Reserved
CTCIF3
CHTIF3
CTCIF2
CHTIF2
CTCIF1
CHTIF1
CTCIF0
CHTIF0
CFEIF3
CTEIF2
CFEIF2
CTEIF1
CFEIF1
CTEIF0
CFEIF0
TEIF3
DMA_LIFCR
Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CDMEIF7
CDMEIF6
CDMEIF5
CDMEIF4
CTCIF7
CHTIF7
CTCIF6
CHTIF6
CTCIF5
CHTIF5
CTCIF4
CHTIF4
CTEIF7
CFEIF7
CTEIF6
CFEIF6
CTEIF5
CFEIF5
CTEIF4
CFEIF4
Reserved
DMA_HIFCR - - -
0x000C Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
Reserved
MINC
CIRC
PINC
HTIE
TCIE
DBM
TEIE
DMA_S0CR
EN
CT
0x0010 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
DMA_S0NDTR NDT[15:.]
0x0014 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S0PAR PA[31:0]
0x0018
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_S0M0AR M0A[31:0]
0x001C
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_S0M1AR M1A[31:0]
0x0020
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
DMDIS
FTH
Reserved
FEIE
DMA_S0FCR FS[2:0]
0x0024 Reserved [1:0]
Reset value 0 1 0 0 0 0 1
PBURST[1:0]
MBURST[1:]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
CHSEL
PL[1:0]
DMEIE
Reserved
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
[2:0]
DMA_S1CR
EN
CT
0x0028 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
DMA_S1NDTR NDT[15:.]
0x002C 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
10
11
9
8
7
6
5
4
3
2
1
0
DMA_S1PAR PA[31:0]
0x0030
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_S1M0AR M0A[31:0]
0x0034
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_S1M1AR M1A[31:0]
0x0038
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
DMDIS
FTH
Reserved
FEIE
DMA_S1FCR FS[2:0]
0x003C Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
CHSEL
PL[1:0]
DMEIE
MINC
Reserved
CIRC
PINC
HTIE
TCIE
TEIE
DBM
[2:0]
[1:0]
DIR
DMA_S2CR
EN
CT
0x0040 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
DMA_S2NDTR NDT[15:.]
0x0044 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S2PAR PA[31:0]
0x0048
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_S2M0AR M0A[31:0]
0x004C
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_S2M1AR M1A[31:0]
0x0050
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
DMDIS
FTH
Reserved
FEIE
DMA_S2FCR FS[2:0]
0x0054 Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
Reserved
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
DMA_S3CR
EN
CT
0x0058 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
DMA_S3NDTR NDT[15:.]
0x005C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S3PAR PA[31:0]
0x0060
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_S3M0AR M0A[31:0]
0x0064
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
10
11
9
8
7
6
5
4
3
2
1
0
DMA_S3M1AR M1A[31:0]
0x0068
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
DMDIS
FTH
Reserved
FEIE
DMA_S3FCR FS[2:0]
0x006C Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
PL[1:0]
DMEIE
Reserved
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
[1:0]
DIR
DMA_S4CR
EN
CT
0x0070 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
DMA_S4NDTR NDT[15:.]
0x0074 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S4PAR PA[31:0]
0x0078
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_S4M0AR M0A[31:0]
0x007C
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_S4M1AR M1A[31:0]
0x0080
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
DMDIS
FTH
Reserved
FEIE
DMA_S4FCR FS[2:0]
0x0084 Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
Reserved
MINC
CIRC
PINC
TCIE
HTIE
DBM
TEIE
DMA_S5CR
EN
CT
0x0088 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
DMA_S5NDTR NDT[15:.]
0x008C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S5PAR PA[31:0]
0x0090
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_S5M0AR M0A[31:0]
0x0094
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_S5M1AR M1A[31:0]
0x0098
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
DMDIS
FTH
Reserved
FEIE
DMA_S5FCR FS[2:0]
0x009C Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
Reserved
MINC
CIRC
PINC
HTIE
TCIE
DBM
TEIE
DMA_S6CR
EN
CT
0x00A0 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
DMA_S6NDTR NDT[15:.]
0x00A4 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S6PAR PA[31:0]
0x00A8
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
10
11
9
8
7
6
5
4
3
2
1
0
DMA_S6M0AR M0A[31:0]
0x00AC
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_S6M1AR M1A[31:0]
0x00B0
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
DMDIS
FTH
Reserved
FEIE
DMA_S6FCR FS[2:0]
0x00B4 Reserved [1:0]
Reset value 0 1 0 0 0 0 1
MBURST[1:0]
PBURST[1:0]
CHSEL[2:0]
MSIZE[1:0]
PSIZE[1:0]
PFCTRL
PINCOS
DIR[1:0]
PL[1:0]
DMEIE
MINC
CIRC
PINC
Reserved
TCIE
HTIE
DBM
TEIE
DMA_S7CR
EN
CT
0x00B8 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
DMA_S7NDTR NDT[15:.]
0x00BC Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S7PAR PA[31:0]
0x00C0
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_S7M0AR M0A[31:0]
0x00C4
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_S7M1AR M1A[31:0]
0x00C8
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
DMDIS
FTH
Reserved
FEIE
DMA_S7FCR FS[2:0]
0x00CC Reserved [1:0]
Reset value 0 1 0 0 0 0 1
Refer to Section 2.3: Memory map for the register boundary addresses.
AHB MASTER
FG PFC
α mode
Blue
BG PFC
α mode
CLUT itf
256x32-bit
RAM AHB SLAVE
MS30439V1
0000 ARGB8888
0001 RGB888
0010 RGB565
0011 ARGB1555
0100 ARGB4444
0101 L8
0110 AL44
0111 AL88
1000 L4
1001 A8
1010 A4
The 24-bit RGB888 aligned on 32-bit is supported through the ARGB8888 mode.
Once the 32-bit value is generated, the alpha channel can be modified according to the
AM[1:0] field of the DMA2D_FGPFCCR/DMA2D_BGPFCCR registers as shown in
Table 54: Alpha mode configuration.
00 No modification
01 Replaced by value in DMA2D_xxPFCCR
10 Replaced by original value multiplied by the value in DMA2D_xxPFCCR / 255
11 Reserved
0 32-bit ARGB8888
1 24-bit RGB888
The way the CLUT data are organized in the system memory is specified in Table 56: CLUT
data order in memory.
αFG . αBG
with αMult =
255
No configuration register is required by the blender. The blender usage depends on the
DMA2D operating mode defined in MODE[1:0] field of the DMA2D_CR register.
000 ARGB8888
001 RGB888
010 RGB565
011 ARGB1555
100 ARGB4444
The timer enabling and the dead time value are configured through the AHB master port
timer configuration register (DMA2D_AMPTCR).
Register-to-memory
The register-to-memory mode is used to fill a user defined area with a predefined color.
The color format is set in the DMA2D_OPFCCR.
The DMA2D does not perform any data fetching from any source. It just writes the color
defined in the DMA2D_OCOLR register to the area located at the address pointed by the
DMA2D_OMAR and defined in the DMA2D_NLR and DMA2D_OOR.
Memory-to-memory
In memory-to-memory mode, the DMA2D does not perform any graphical data
transformation. The foreground input FIFO acts as a buffer and the data are transferred
from the source memory location defined in DMA2D_FGMAR to the destination memory
location pointed by DMA2D_OMAR.
The color mode programmed in the CM[3:0] bits of the DMA2D_FGPFCCR register defines
the number of bits per pixel for both input and output.
The size of the area to be transferred is defined by the DMA2D_NLR and DMA2D_FGOR
registers for the source, and by DMA2D_NLR and DMA2D_OOR registers for the
destination.
The resulting 32-bit pixel value is encoded by the output PFC according to the specified
output format, and the data are written into the destination memory location pointed by
DMA2D_OMAR.
11.3.13 Watermark
A watermark can be programmed to generate an interrupt when the last pixel of a given line
has been written to the destination memory area.
The line number is defined in the LW[15:0] field of the DMA2D_LWR register.
When the last pixel of this line has been transferred, the TWIF flag of the DMA2D_ISR
register is raised and an interrupt is generated if the TWIE bit of the DMA2D_CR is set.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MODE
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
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
MA[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
LO[13:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MA[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
LO[13:0]
Reserved
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
ALPHA[7:0] AM[1: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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RED[7:0]
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
GREEN[7:0] BLUE[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
ALPHA[7:0] AM[1: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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RED[7:0]
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
GREEN[7:0] BLUE[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
MA[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MA[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
CM[2:0]
Reserved
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ALPHA[7:0] RED[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
GREEN[7:0] BLUE[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
MA[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
LO[13:0]
Reserved
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
PL[13:0]
Reserved
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
NL[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LW[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DT[7:0] EN
Reserved
rw rw rw rw rw rw rw rw rw
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
MODE[1:0]
ABORT
START
CTCIE
CAEIE
SUSP
TWIE
CEIE
TCIE
TEIE
DMA2D_CR
0x0000 Reserved Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
CTCIF
CAEIF
TWIF
CEIF
TCIF
TEIF
DMA2D_ISR
0x0004 Reserved
Reset value 0 0 0 0 0 0
CAECIF
CCTCIF
CTWIF
CCEIF
CTCIF
CTEIF
DMA2D_IFCR
0x0008 Reserved
Reset value 0 0 0 0 0 0
DMA2D_FGMAR MA[31:0]
0x000C
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
DMA2D_FGOR LO[13:0]
0x0010 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA2D_BGMAR MA[31:0]
0x0014
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
DMA2D_BGOR LO[13:0]
0x0018 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
AM[1:0]
START
CCM
DMA2D_FGPFCCR ALPHA[7:0] CS[7:0] CM[3:0]
0x001C Reserved Res
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA2D_FGCOLR APLHA[7:0] RED[7:0] GREEN[7:0] BLUE[7:0]
0x0020
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
AM[1:0]
START
CCM
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
DMA2D_OOR LO[13:0]
0x0040 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA2D_NLR PL[13:0] NL[15:0]
0x0044 Res
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA2D_LWR LW[15:0]
0x0048 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA2D_AMTCR DT[7:0]
EN
0x004C Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0
0x0050-
- Reserved
Ox03FF
This Section applies to the whole STM32F4xx family, unless otherwise specified.
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
18 25 settable ADC ADC1, ADC2 and ADC3 global interrupts 0x0000 0088
19 26 settable CAN1_TX CAN1 TX interrupts 0x0000 008C
20 27 settable CAN1_RX0 CAN1 RX0 interrupts 0x0000 0090
21 28 settable CAN1_RX1 CAN1 RX1 interrupt 0x0000 0094
22 29 settable CAN1_SCE CAN1 SCE interrupt 0x0000 0098
23 30 settable EXTI9_5 EXTI Line[9:5] interrupts 0x0000 009C
TIM1 Break interrupt and TIM9 global
24 31 settable TIM1_BRK_TIM9 0x0000 00A0
interrupt
TIM1 Update interrupt and TIM10 global
25 32 settable TIM1_UP_TIM10 0x0000 00A4
interrupt
TIM1 Trigger and Commutation interrupts
26 33 settable TIM1_TRG_COM_TIM11 0x0000 00A8
and TIM11 global interrupt
27 34 settable TIM1_CC TIM1 Capture Compare interrupt 0x0000 00AC
28 35 settable TIM2 TIM2 global interrupt 0x0000 00B0
29 36 settable TIM3 TIM3 global interrupt 0x0000 00B4
30 37 settable TIM4 TIM4 global interrupt 0x0000 00B8
2C1
31 38 settable I2C1_EV I event interrupt 0x0000 00BC
32 39 settable I2C1_ER I2C1 error interrupt 0x0000 00C0
33 40 settable I2C2_EV I2C2 event interrupt 0x0000 00C4
2
34 41 settable I2C2_ER I C2 error interrupt 0x0000 00C8
35 42 settable SPI1 SPI1 global interrupt 0x0000 00CC
36 43 settable SPI2 SPI2 global interrupt 0x0000 00D0
37 44 settable USART1 USART1 global interrupt 0x0000 00D4
38 45 settable USART2 USART2 global interrupt 0x0000 00D8
39 46 settable USART3 USART3 global interrupt 0x0000 00DC
40 47 settable EXTI15_10 EXTI Line[15:10] interrupts 0x0000 00E0
RTC Alarms (A and B) through EXTI line
41 48 settable RTC_Alarm 0x0000 00E4
interrupt
USB On-The-Go FS Wakeup through EXTI
42 49 settable OTG_FS_WKUP 0x0000 00E8
line interrupt
TIM8 Break interrupt and TIM12 global
43 50 settable TIM8_BRK_TIM12 0x0000 00EC
interrupt
Priority
Type of
Acronym Description Address
priority
Priority
Type of
Acronym Description Address
priority
23 23 23 23 23
To NVIC interrupt 23 23 23 23
controller
23
Event
mask
register
MS32662V1
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
PH0
PI0
PA1
PB1
PC1 EXTI1
PD1
PE1
PF1
PG1
PH1
PI1
...
PA15
PB15
PC15
EXTI15
PD15
PE15
PF15
PG15
PH15
ai15897
PA0
PB0
PC0
PD0
PE0 EXTI0
PF0
PG0
PH0
PI0
PJ0
PK0
PA1
PB1
PC1
PD1
PE1 EXTI1
PF1
PG1
PH1
PI1
PJ1
PK1
PA15
PB15
PC15
PD15 EXTI15
PE15
PF15
PG15
PH15
PJ15
MS30440V1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MR22 MR21 MR20 MR19 MR18 MR17 MR16
Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MR15 MR14 MR13 MR12 MR11 MR10 MR9 MR8 MR7 MR6 MR5 MR4 MR3 MR2 MR1 MR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MR22 MR21 MR20 MR19 MR18 MR17 MR16
Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MR15 MR14 MR13 MR12 MR11 MR10 MR9 MR8 MR7 MR6 MR5 MR4 MR3 MR2 MR1 MR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TR22 TR21 TR20 TR19 TR18 TR17 TR16
Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TR15 TR14 TR13 TR12 TR11 TR10 TR9 TR8 TR7 TR6 TR5 TR4 TR3 TR2 TR1 TR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The external wakeup lines are edge triggered, no glitch must be generated on these lines.
If a rising edge occurs on the external interrupt line while writing to the EXTI_RTSR register,
the pending bit is 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
TR22 TR21 TR20 TR19 TR18 TR17 TR16
Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TR15 TR14 TR13 TR12 TR11 TR10 TR9 TR8 TR7 TR6 TR5 TR4 TR3 TR2 TR1 TR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The external wakeup lines are edge triggered, no glitch must be generated on these lines.
If a falling edge occurs on the external interrupt line while writing to the EXTI_FTSR register,
the pending bit is not set.
Rising and falling edge triggers can be set for the same interrupt line. In this 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 SWIER SWIER SWIER
Reserved 22 21 20 19 18 17 16
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
PR22 PR21 PR20 PR19 PR18 PR17 PR16
Reserved
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PR15 PR14 PR13 PR12 PR11 PR10 PR9 PR8 PR7 PR6 PR5 PR4 PR3 PR2 PR1 PR0
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
Table 63. External interrupt/event controller register map and reset values
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
EXTI_IMR MR[22: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 0 0 0
EXTI_EMR MR[22: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 0 0 0
EXTI_RTSR TR[22: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 0 0 0
EXTI_FTSR TR[22: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 0 0 0
EXTI_SWIER SWIER[22: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 0 0 0
EXTI_PR PR[22: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 0 0 0
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
Flags Interrupt
enable bits
DMA overrun
OVR OVRIE
End of conversion
EOC EOCIE
End of injected conversion ADC Interrupt to NVIC
JEOC JEOCIE
Analog watchdog event
AWD AWDIE
Analog watchdog
Compare result
Address/data bus
Injected data registers
V REF+ (4 x 16 bits)
V REF-
Regular data register
V DDA (16 bits)
V SSA
Analog DMA request
mux
ADCx_IN0
ADCx_IN1
GPIO up to 4 ADCCLK
Injected
ports channels Analog to digital
up to 16 Regular converter
ADCx_IN15
channels
Temp. sensor
V REFINT
V BAT
TIM1_CH4 TIM1_CH1
TIM1_TRGO JEXTEN EXTEN TIM1_CH2
TIM2_CH1 [1:0] bits [1:0] bits TIM1_CH3
TIM2_TRGO TIM2_CH2
TIM3_CH2 TIM2_CH3
TIM3_CH4 TIM2_CH4
TIM4_CH1 TIM2_TRGO
TIM4_CH2 TIM3_CH1
TIM4_CH3 TIM3_TRGO
TIM4_TRGO TIM4_CH4
Start trigger Start trigger
TIM5_CH4 TIM5_CH1
(injected group) (regular group)
TIM5_TRGO TIM5_CH2
TIM8_CH2 TIM5_CH3
TIM8_CH3 TIM8_CH1
TIM8_CH4 TIM8_TRGO
EXTI_15
EXTI_11
ai16046
Input, analog reference The higher/positive reference voltage for the ADC,
VREF+
positive 1.8 V ≤ VREF+ ≤ VDDA
Analog power supply equal to VDD and
VDDA Input, analog supply 2.4 V ≤ VDDA ≤ VDD (3.6 V) for full speed
1.8 V ≤ VDDA ≤ VDD (3.6 V) for reduced speed
Input, analog reference The lower/negative reference voltage for the ADC,
VREF–
negative VREF– = VSSA
Input, analog supply
VSSA Ground for analog power supply equal to VSS
ground
ADCx_IN[15:0] Analog input signals 16 analog input channels
The total number of conversions in the injected group must be written in the L[1:0] bits
in the ADC_JSQR register.
If the ADC_SQRx or ADC_JSQR registers are modified during a conversion, the current
conversion is reset and a new start pulse is sent to the ADC to convert the newly chosen
group.
ADC_CLK
ADON
SWSTART/
JSWSTART
Analog voltage
ai16048
None x 0 0
All injected channels 0 0 1
All regular channels 0 1 0
All regular and injected channels 0 1 1
Single(1) injected channel 1 0 1
Single(1) regular channel 1 1 0
(1)
Single regular or injected channel 1 1 1
1. Selected by the AWDCH[4:0] bits
Auto-injection
If the JAUTO bit is set, then the channels in the injected group are automatically converted
after the regular group of channels. This can be used to convert a sequence of up to 20
conversions programmed in the 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.
Note: It is not possible to use both the auto-injected and discontinuous modes simultaneously.
ADCCLK
Injection event
Reset ADC
ai16049
1. The maximum latency value can be found in the electrical characteristics of the STM32F40x and
STM32F41x 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 JEOC event generated
4th trigger: channel 1
Note: 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.
It is not possible to use both the auto-injected and discontinuous modes simultaneously.
Discontinuous mode must not be set for regular and injected groups at the same time.
Discontinuous mode must be enabled only for the conversion of one group.
Injected group
Regular group
0 0 0 0 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
ai16050
Injected group
Regular group
D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 0 0 0 0
ai16051
Special case: when left-aligned, the data are aligned on a half-word basis except when the
resolution is set to 6-bit. in that case, the data are aligned on a byte basis as shown in
Figure 50.
Injected group
Regular group
0 0 0 0 0 0 0 0 D5 D4 D3 D2 D1 D0 0 0
ai16052
Note: The polarity of the external trigger can be changed on the fly.
The EXTSEL[3:0] and JEXTSEL[3:0] control bits are used to select which out of 16 possible
events can trigger conversion for the regular and injected groups.
Table 68 gives the possible external trigger for regular conversion.
Software source trigger events can be generated by setting SWSTART (for regular
conversion) or JSWSTART (for injected conversion) in ADC_CR2.
A regular group conversion can be interrupted by an injected trigger.
Note: The trigger selection can be changed on the fly. However, when the selection changes,
there is a time frame of 1 APB clock cycle during which the trigger detection is disabled.
This is to avoid spurious detection during transitions.
Address/data bus
internal triggers
Dual/Triple
mode control Common part
ADCx_IN1
GPIO
Ports
Regular
channels
ADCx_IN15
Injected
channels
Temp. sensor
VREFINT
VBAT
EXTI_15
Start trigger mux
(injected group)
ai16053
1. Although external triggers are present on ADC2 and ADC3 they are not shown in this diagram.
2. In the Dual ADC mode, the ADC3 slave part is not present.
3. In Triple ADC mode, the ADC common data register (ADC_CDR) contains the ADC1, ADC2 and ADC3’s
regular converted data. All 32 register bits are used according to a selected storage order.
In Dual ADC mode, the ADC common data register (ADC_CDR) contains both the ADC1 and ADC2’s
regular converted data. All 32 register bits are used.
– DMA mode 2: On each DMA request (two data items are available) two half-
words representing two ADC-converted data items are transferred as a word.
In Dual ADC mode, both ADC2 and ADC1 data are transferred on the first request
(ADC2 data take the upper half-word and ADC1 data take the lower half-word) and
so on.
In Triple ADC mode, three DMA requests are generated. On the first request, both
ADC2 and ADC1 data are transferred (ADC2 data take the upper half-word and
ADC1 data take the lower half-word). On the second request, both ADC1 and
ADC3 data are transferred (ADC1 data take the upper half-word and ADC3 data
take the lower half-word).On the third request, both ADC3 and ADC2 data are
transferred (ADC3 data take the upper half-word and ADC2 data take the lower
half-word) and so on.
DMA mode 2 is used in interleaved mode and in regular simultaneous mode (for
Dual ADC mode only).
Example:
a) Interleaved dual mode: a DMA request is generated each time 2 data items are
available:
1st request: ADC_CDR[31:0] = ADC2_DR[15:0] | ADC1_DR[15:0]
2nd request: ADC_CDR[31:0] = ADC2_DR[15:0] | ADC1_DR[15:0]
b) Interleaved triple mode: a DMA request is generated each time 2 data items are
available
1st request: ADC_CDR[31:0] = ADC2_DR[15:0] | ADC1_DR[15:0]
2nd request: ADC_CDR[31:0] = ADC1_DR[15:0] | ADC3_DR[15:0]
3rd request: ADC_CDR[31:0] = ADC3_DR[15:0] | ADC2_DR[15:0]
4th request: ADC_CDR[31:0] = ADC2_DR[15:0] | ADC1_DR[15:0]
– DMA mode 3: This mode is similar to the DMA mode 2. The only differences are
that the on each DMA request (two data items are available) two bytes
representing two ADC converted data items are transferred as a half-word. The
data transfer order is similar to that of the DMA mode 2.
DMA mode 3 is used in interleaved mode in 6-bit and 8-bit resolutions (dual and
triple mode).
Example:
a) Interleaved dual mode: a DMA request is generated each time 2 data items are
available
1st request: ADC_CDR[15:0] = ADC2_DR[7:0] | ADC1_DR[7:0]
2nd request: ADC_CDR[15:0] = ADC2_DR[7:0] | ADC1_DR[7:0]
b) Interleaved triple mode: a DMA request is generated each time 2 data items are
available
1st request: ADC_CDR[15:0] = ADC2_DR[7:0] | ADC1_DR[7:0]
2nd request: ADC_CDR[15:0] = ADC1_DR[7:0] | ADC3_DR[7:0]
3rd request: ADC_CDR[15:0] = ADC3_DR[7:0] | ADC2_DR[7:0]
4th request: ADC_CDR[15:0] = ADC2_DR[7:0] | ADC1_DR[7:0]
Overrun detection: If an overrun is detected on one of the concerned ADCs (ADC1 and
ADC2 in dual and triple modes, ADC3 in triple mode only), the DMA requests are no longer
issued to ensure that all the data transferred to the RAM are valid. It may happen that the
EOC bit corresponding to one ADC remains set because the data register of this ADC
contains valid data.
Figure 56. Interleaved mode on 1 channel in continuous conversion mode: dual ADC
mode
Trigger
End of conversion on ADC2
8 ADCCLK
cycles ai16056
a given time). In this case, the delay becomes the sampling time + 2 ADC clock cycles. For
instance, if DELAY = 5 clock cycles and the sampling takes 15 clock cycles on the three
ADCs, then 17 clock cycles will separate the conversions on ADC1, ADC2 and ADC3).
If the CONT bit is set on ADC1, ADC2 and ADC3, the selected regular channels of all ADCs
are continuously converted.
Note: If the conversion sequence is interrupted (for instance when DMA end of transfer occurs),
the multi-ADC sequencer must be reset by configuring it in independent mode first (bits
DUAL[4:0] = 00000) before reprogramming the interleaved mode.
In this mode a DMA request is generated each time 2 data items are available, (if the
DMA[1:0] bits in the ADC_CCR register are equal to 0b10). The request first transfers the
first converted data stored in the lower half-word of the ADC_CDR 32-bit register to SRAM,
then it transfers the second converted data stored in ADC_CDR’s upper half-word to SRAM.
The sequence is the following:
• 1st request: ADC_CDR[31:0] = ADC2_DR[15:0] | ADC1_DR[15:0]
• 2nd request: ADC_CDR[31:0] = ADC1_DR[15:0] | ADC3_DR[15:0]
• 3rd request: ADC_CDR[31:0] = ADC3_DR[15:0] | ADC2_DR[15:0]
• 4th request: ADC_CDR[31:0] = ADC2_DR[15:0] | ADC1_DR[15:0], ...
Figure 57. Interleaved mode on 1 channel in continuous conversion mode: triple ADC
mode
End of conversion on ADC1
6 ADCCLK
cycles ai16058
ADC has to perform an injected conversion. It is resumed when the injected conversion is
finished.
If the conversion sequence is interrupted (for instance when DMA end of transfer occurs),
the multi-ADC sequencer must be reset by configuring it in independent mode first (bits
DUAL[4:0] = 00000) before reprogramming the interleaved mode.
The time interval between 2 trigger events must be greater than or equal to 1 ADC clock
period. The minimum time interval between 2 trigger events that start conversions on the
same ADC is the same as in the single ADC mode.
ADC1 ...
ADC2
If the injected discontinuous mode is enabled for both ADC1 and ADC2:
• When the 1st trigger occurs, the first injected ADC1 channel is converted.
• When the 2nd trigger occurs, the first injected ADC2 channel are converted
• and so on
A JEOC interrupt, if enabled, is generated after all injected ADC1 channels in the group
have been converted.
A JEOC interrupt, if enabled, is generated after all injected ADC2 channels in the group
have been converted.
If another external trigger occurs after all injected channels in the group have been
converted then the alternate trigger process restarts.
Figure 59. Alternate trigger: 4 injected channels (each ADC) in discontinuous mode
1st trigger 3rd trigger 5th trigger 7th trigger
Sampling
JEOC on ADC1
Conversion
ADC1
ADC2
JEOC on ADC2
ADC1 ...
ADC2
2nd trigger
3rd trigger (n+1)th trigger
ADC with the shortest sequence may restart while the ADC with the longest sequence is
completing the previous conversions.
CH0
ADC2 inj
synchro not lost
If a trigger occurs during an injected conversion that has interrupted a regular conversion, it
is ignored. Figure 62 shows the behavior in this case (2nd trigger is ignored).
CH0
ADC2 inj
Main features
• Supported temperature range: –40 to 125 °C
• Precision: ±1.5 °C
Temperature V SENSE
sensor ADC1_IN16/
ADC1_IN18(1)
Address/data bus
converted data
ADC1
VREFINT
Internal
power block ADC1_IN17
MS31830V1
1. VSENSE is input to ADC1_IN16 for the STM23F40x and STM32F41x devices and to ADC1_IN18 for the
STM32F42x and STM32F43x devices.
The internal temperature sensor is more suited for applications that detect temperature
variations instead of absolute temperatures. If accurate temperature reading is required, an
external temperature sensor should be used.
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
OVR STRT JSTRT JEOC EOC AWD
Reserved
rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OVRIE RES AWDEN JAWDEN
Reserved Reserved
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JDISCE DISC AWDSG
DISCNUM[2:0] JAUTO SCAN JEOCIE AWDIE EOCIE AWDCH[4:0]
N EN L
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
SWST JSWST
EXTEN EXTSEL[3:0] JEXTEN JEXTSEL[3:0]
reserved ART reserved ART
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
ALIGN EOCS DDS DMA CONT ADON
reserved Reserved
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SMP18[2:0] SMP17[2:0] SMP16[2:0] SMP15[2:1]
Reserved
rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SMP15_0 SMP14[2:0] SMP13[2:0] SMP12[2:0] SMP11[2:0] SMP10[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SMP9[2:0] SMP8[2:0] SMP7[2:0] SMP6[2:0] SMP5[2:1]
Reserved
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
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
JOFFSETx[11:0]
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
HT[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
Note: The software can write to these registers when an ADC conversion is ongoing. The
programmed value will be effective when the next conversion is complete. Writing to this
register is performed with a write delay that can create uncertainty on the effective time at
which the new value is programmed.
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
LT[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
Note: The software can write to these registers when an ADC conversion is ongoing. The
programmed value will be effective when the next conversion is complete. Writing to this
register is performed with a write delay that can create uncertainty on the effective time at
which the new value is programmed.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
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
SQ16_0 SQ15[4:0] SQ14[4:0] SQ13[4:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SQ12[4:0] SQ11[4:0] SQ10[4:1]
Reserved
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_0 SQ9[4:0] SQ8[4:0] SQ7[4: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
SQ6[4:0] SQ5[4:0] SQ4[4:1]
Reserved
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
SQ4_0 SQ3[4:0] SQ2[4:0] SQ1[4: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
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
JSQ4[0] JSQ3[4:0] JSQ2[4:0] JSQ1[4:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: When JL[1:0]=3 (4 injected conversions in the sequencer), the ADC converts the channels
in the following order: JSQ1[4:0], JSQ2[4:0], JSQ3[4:0], and JSQ4[4:0].
When JL=2 (3 injected conversions in the sequencer), the ADC converts the channels in the
following order: JSQ2[4:0], JSQ3[4:0], and JSQ4[4:0].
When JL=1 (2 injected conversions in the sequencer), the ADC converts the channels in
starting from JSQ3[4:0], and then JSQ4[4:0].
When JL=0 (1 injected conversion in the sequencer), the ADC converts only JSQ4[4:0]
channel.
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
JDATA[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
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
OVR3 STRT3 JSTRT3 JEOC 3 EOC3 AWD3
Reserved ADC3
r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JSTRT
OVR2 STRT2 JEOC2 EOC2 AWD2 OVR1 STRT1 JSTRT1 JEOC 1 EOC1 AWD1
2
Reserved Reserved
ADC2 ADC1
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
TSVREFE VBATE ADCPRE
Reserved Reserved
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMA[1:0] DDS DELAY[3:0] MULTI[4:0]
Res. Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
13.13.17 ADC common regular data register for dual and triple modes
(ADC_CDR)
Address offset: 0x08 (this offset address is relative to ADC1 base address + 0x300)
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATA2[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
DATA1[15:0]
r r r r r r r r r r r r r r r r
Table 72. ADC register map and reset values for each ADC
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
JSTRT
JEOC
STRT
AWD
OVR
EOC
ADC_SR
0x00 Reserved
Reset value 0 0 0 0 0 0
AWD SGL
JDISCEN
JAWDEN
RES[1:0]
DISCEN
AWDEN
JEOCIE
JAUTO
AWDIE
OVRIE
EOCIE
SCAN
DISC
ADC_CR1 AWDCH[4:0]
0x04 Reserved Reserved 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
JEXTEN[1:0]
JSWSTART
EXTEN[1:0]
Re Re
SWSTART
ALIGN
ADON
CONT
EOCS
se se JEXTSEL
DMA
DDS
ADC_CR2 EXTSEL [3:0]
0x08 rv rv [3:0] Reserved Reserved
ed ed
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_SMPR1 Sample time bits SMPx_x
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_SMPR2 Sample time bits SMPx_x
0x10
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
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 1 1 1 1 1 1 1 1 1 1 1 1
ADC_LTR LT[11:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ADC_SQR1 L[3:0] Regular channel sequence SQx_x bits
0x2C 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
ADC_SQR2 Regular channel sequence SQx_x bits
Reserved Reserved
0x30
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
Table 73. ADC register map and reset values (common ADC registers)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
JSTRT
JSTRT
JSTRT
JEOC
JEOC
JEOC
STRT
STRT
STRT
AWD
AWD
AWD
OVR
EOC
OVR
EOC
OVR
EOC
ADC_CSR
Reserved
Reserved
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC3 ADC2 ADC1
ADCPRE[1:0]
TSVREFE
DMA[1:0]
VBATE
Reserved
DDS
ADC_CCR DELAY [3:0] MULTI [4:0]
0x04 Reserved Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADC_CDR Regular DATA2[15:0] Regular DATA1[15:0]
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
Trigger selectorx
TIM2_T RGO
TIM4_T RGO DMAENx
TIM5_T RGO
TIM6_T RGO
TIM7_T RGO
TIM8_T RGO
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+
ai14708b
Input, analog reference The higher/positive reference voltage for the DAC,
VREF+
positive 1.8 V ≤ VREF+ ≤ VDDA
VDDA Input, analog supply Analog power supply
VSSA Input, analog supply ground Ground for analog power supply
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).
31 24 15 7 0
8-bit right aligned
ai14710b
• Dual DAC channels, there are three possibilities:
– 8-bit right alignment: data for DAC channel1 to be loaded into the DAC_DHR8RD
[7:0] bits (stored into the DHR1[11:4] bits) and data for DAC channel2 to be loaded
into the DAC_DHR8RD [15:8] bits (stored into the DHR2[11:4] bits)
– 12-bit left alignment: data for DAC channel1 to be loaded into the DAC_DHR12LD
[15:4] bits (stored into the DHR1[11:0] bits) and data for DAC channel2 to be
loaded into the DAC_DHR12LD [31:20] bits (stored into the DHR2[11:0] bits)
– 12-bit right alignment: data for DAC channel1 to be loaded into the
DAC_DHR12RD [11:0] bits (stored into the DHR1[11:0] bits) and data for DAC
channel2 to be loaded into the DAC_DHR12LD [27:16] bits (stored into the
DHR2[11:0] bits)
Depending on the loaded DAC_DHRyyyD register, the data written by the user is shifted
and stored into DHR1 and DHR2 (data holding registers, which are internal non-memory-
mapped registers). The DHR1 and DHR2 registers are then loaded into the DOR1 and
DOR2 registers, respectively, either automatically, by software trigger or by an external
event trigger.
ai14709b
When DAC_DORx is loaded with the DAC_DHRx contents, the analog output voltage
becomes available after a time tSETTLING that depends on the power supply voltage and the
analog output load.
Figure 67. Timing diagram for conversion with trigger disabled TEN = 0
APB1_CLK
DHR 0x1AC
Output voltage
DOR 0x1AC available on DAC_OUT pin
tSETTLING
ai14711c
Each time a DAC interface detects a rising edge on the selected timer TRGO output, or on
the selected external interrupt line 9, the last data stored into the DAC_DHRx register are
transferred into the DAC_DORx register. The DAC_DORx register is updated three APB1
cycles after the trigger occurs.
If the software trigger is selected, the conversion starts once the SWTRIG bit is set.
SWTRIG is reset by hardware once the DAC_DORx register has been loaded with the
DAC_DHRx register contents.
Note: TSELx[2:0] bit cannot be changed when the ENx bit is set.
When software trigger is selected, the transfer from the DAC_DHRx register to the
DAC_DORx register takes only one APB1 clock cycle.
DMA underrun
The DAC DMA request is not queued so that if a second external trigger arrives before the
acknowledgement for the first external trigger is received (first request), then no new
request is issued and the DMA channelx underrun flag DMAUDRx in the DAC_SR register
is set, reporting the error condition. DMA data transfers are then disabled and no further
DMA request is treated. The DAC channelx continues to convert old data.
The software should clear the DMAUDRx flag by writing “1”, clear the DMAEN bit of the
used DMA stream and re-initialize both DMA and DAC channelx to restart the transfer
correctly. The software should modify the DAC trigger conversion frequency or lighten the
DMA workload to avoid a new DMA underrun. Finally, the DAC conversion could be
resumed by enabling both DMA data transfer and conversion trigger.
For each DAC channelx, an interrupt is also generated if its corresponding DMAUDRIEx bit
in the DAC_CR register is enabled.
XOR
X6 X4 X X0
X 12
11 10 9 8 7 6 5 4 3 2 1 0
12
NOR
ai14713c
The LFSR value, that may be masked partially or totally by means of the MAMPx[3:0] bits in
the DAC_CR register, is added up to the DAC_DHRx contents without overflow and this
value is then stored into the DAC_DORx register.
If LFSR is 0x0000, a ‘1 is injected into it (antilock-up mechanism).
It is possible to reset LFSR wave generation by resetting the WAVEx[1:0] bits.
Figure 69. DAC conversion (SW trigger enabled) with LFSR wave generation
APB1_CLK
DHR 0x00
SWTRIG
ai14714b
Note: The DAC trigger must be enabled for noise generation by setting the TENx bit in the
DAC_CR register.
De
n
tio
c
re
ta
en
m
en
em
ta
cr
tio
In
n
DAC_DHRx base value
0
ai14715c
Figure 71. DAC conversion (SW trigger enabled) with triangle wave generation
APB1_CLK
DHR 0x00
SWTRIG
ai14714b
Note: The DAC trigger must be enabled for noise generation by setting the TENx bit in the
DAC_CR register.
The MAMPx[3:0] bits must be configured before enabling the DAC, otherwise they cannot
be changed.
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
DACC1DHR[11:0]
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
DACC1DOR[11: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
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DMAUDR2
Reserved Reserved
rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMAUDR1
Reserved Reserved
rc_w1
10
11
9
8
7
6
5
4
3
2
1
0
DMAUDRIE2
DMAUDRIE1
Reserved
Reserved
DMAEN2
DMAEN1
BOFF2
BOFF1
TEN1
EN2
EN1
DAC_
0x04 Reserved
SWTRIGR
DAC_
0x08 Reserved DACC1DHR[11:0]
DHR12R1
DAC_
0x0C Reserved DACC1DHR[11:0] Reserved
DHR12L1
DAC_
0x10 Reserved DACC1DHR[7:0]
DHR8R1
DAC_
0x14 Reserved DACC2DHR[11:0]
DHR12R2
DAC_
0x18 Reserved DACC2DHR[11:0] Reserved
DHR12L2
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
DAC_
0x1C Reserved DACC2DHR[7:0]
DHR8R2
DAC_
0x20 Reserved DACC2DHR[11:0] Reserved DACC1DHR[11:0]
DHR12RD
DAC_
0x24 DACC2DHR[11:0] Reserved DACC1DHR[11:0] Reserved
DHR12LD
DAC_
0x28 Reserved DACC2DHR[7:0] DACC1DHR[7:0]
DHR8RD
DAC_
0x2C Reserved DACC1DOR[11:0]
DOR1
DAC_
0x30 Reserved DACC2DOR[11:0]
DOR2
DMAUDR2
DMAUDR1
Reserved
Refer to Section 2.3: Memory map for the register boundary addresses.
DMA Control/Status
interface register
AHB
interface
ai15604b
DCMI_D[0:13]
DCMI_PIXCLK External
HCLK
DCMI_HSYNC interface
DCMI_VSYNC
DCMI
Interrupt DCMI_IT
controller
DMA_REQ
ai15603b
8 bits D[0..7]
10 bits D[0..9]
Data
12 bits D[0..11]
14 bits D[0..13]
PIXCLK Pixel clock
HSYNC Horizontal synchronization / Data valid
VSYNC Vertical synchronization
The data are synchronous with PIXCLK and change on the rising/falling edge of the pixel
clock depending on the polarity.
The HSYNC signal indicates the start/end of a line.
The VSYNC signal indicates the start/end of a frame
DCMI_PIXCLK
DCMI_DR[0:13]
DCMI_HSYNC
DCMI_VSYNC
ai15606b
1. The capture edge of DCMI_PIXCLK is the falling edge, the active state of DCMI_HSYNC and
DCMI_VSYNC is 1.
1. DCMI_HSYNC and DCMI_VSYNC can change states at the same time.
8-bit data
When EDM[1:0] in DCMI_CR are programmed to “00” the interface captures 8 LSB’s at its
input (D[0:7]) and stores them as 8-bit data. The D[13:8] inputs are ignored. In this case, to
capture a 32-bit word, the camera interface takes four pixel clock cycles.
The first captured data byte is placed in the LSB position in the 32-bit word and the 4th
captured data byte is placed in the MSB position in the 32-bit word. Table 79 gives an
example of the positioning of captured data bytes in two 32-bit words.
Table 79. Positioning of captured data bytes in 32-bit words (8-bit width)
Byte address 31:24 23:16 15:8 7:0
10-bit data
When EDM[1:0] in DCMI_CR are programmed to “01”, the camera interface captures 10-bit
data at its input D[0..9] and stores them as the 10 least significant bits of a 16-bit word. The
remaining most significant bits in the DCMI_DR register (bits 11 to 15) are cleared to zero.
So, in this case, a 32-bit data word is made up every two pixel clock cycles.
The first captured data are placed in the LSB position in the 32-bit word and the 2nd
captured data are placed in the MSB position in the 32-bit word as shown in Table 80.
Table 80. Positioning of captured data bytes in 32-bit words (10-bit width)
Byte address 31:26 25:16 15:10 9:0
0 0 Dn+1[9:0] 0 Dn[9:0]
4 0 Dn+3[9:0] 0 Dn+2[9:0]
12-bit data
When EDM[1:0] in DCMI_CR are programmed to “10”, the camera interface captures the
12-bit data at its input D[0..11] and stores them as the 12 least significant bits of a 16-bit
word. The remaining most significant bits are cleared to zero. So, in this case a 32-bit data
word is made up every two pixel clock cycles.
The first captured data are placed in the LSB position in the 32-bit word and the 2nd
captured data are placed in the MSB position in the 32-bit word as shown in Table 81.
Table 81. Positioning of captured data bytes in 32-bit words (12-bit width)
Byte address 31:28 27:16 15:12 11:0
0 0 Dn+1[11:0] 0 Dn[11:0]
4 0 Dn+3[11:0] 0 Dn+2[11:0]
14-bit data
When EDM[1:0] in DCMI_CR are programmed to “11”, the camera interface captures the
14-bit data at its input D[0..13] and stores them as the 14 least significant bits of a 16-bit
word. The remaining most significant bits are cleared to zero. So, in this case a 32-bit data
word is made up every two pixel clock cycles.
The first captured data are placed in the LSB position in the 32-bit word and the 2nd
captured data are placed in the MSB position in the 32-bit word as shown in Table 82.
Table 82. Positioning of captured data bytes in 32-bit words (14-bit width)
Byte address 31:30 29:16 15:14 13:0
0 0 Dn+1[13:0] 0 Dn[13:0]
4 0 Dn+3[13:0] 0 Dn+2[13:0]
15.5.3 Synchronization
The digital camera interface supports embedded or hardware (HSYNC & VSYNC)
synchronization. When embedded synchronization is used, it is up to the digital camera
module to make sure that the 0x00 and 0xFF values are used ONLY for synchronization
(not in data). Embedded synchronization codes are supported only for the 8-bit parallel data
interface width (that is, in the DCMI_CR register, the EDM[1:0] bits should be cleared to
“00”).
For compressed data, the DCMI supports only the hardware synchronization mode. In this
case, VSYNC is used as a start/end of the image, and HSYNC is used as a Data Valid
signal. Figure 75 shows the corresponding timing diagram.
JPEG data
DCMI_VSYNC
ai15944b
Example
FS = 0xA5
Unmask code for FS = 0x10
In this case the frame start code is embedded in the bit 4 of the frame start code.
DCMI_HSYNC
DCMI_VSYNC
Frame 2
Frame 1 captured not captured
ai15832b
DCMI_HSYNC
DCMI_VSYNC
ai15833b
ai15834
These registers specify the coordinates of the starting point of the capture window as a line
number (in the frame, starting from 0) and a number of pixel clocks (on the line, starting from
0), and the size of the window as a line number and a number of pixel clocks. The CAPCNT
value can only be a multiple of 4 (two least significant bits are forced to 0) to allow the
correct transfer of data through the DMA.
If the VSYNC signal goes active before the number of lines is specified in the
DCMI_CWSIZE register, then the capture stops and an IT_FRAME interrupt is generated
when enabled.
DCMI_HSYNC
DCMI_VSYNC
HOFFCNT
CAPCNT
15.5.7 FIFO
A four-word FIFO is implemented to manage data rate transfers on the AHB. The DCMI
features a simple FIFO controller with a read pointer incremented each time the camera
interface reads from the AHB, and a write pointer incremented each time the camera
interface writes to the FIFO. There is no overrun protection to prevent the data from being
overwritten if the AHB interface does not sustain the data transfer rate.
In case of overrun or errors in the synchronization signals, the FIFO is reset and the DCMI
interface waits for a new start of frame.
Pixel raster
scan order
(increasing
addresses)
Pixel row n – 1
ai15848
0 Yn+1 Cr n Yn Cb n
4 Yn+3 Cr n + 2 Yn+2 Cb n + 2
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
CAPTURE
PCKPOL
ENABLE
HSPOL
VSPOL
CROP
JPEG
Reserved
ESS
CM
EDM FCRC
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
HSYNC
VSYNC
FNE
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
FRAME_RIS
VSYNC_RIS
LINE_RIS
OVR_RIS
ERR_RIS
Reserved
r r r r r
DCMI_RIS gives the raw interrupt status and is accessible in read only. When read, this
register returns the status of the corresponding interrupt before masking with the DCMI_IER
register value.
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
FRAME_IE
VSYNC_IE
LINE_IE
OVR_IE
ERR_IE
Reserved
rw rw rw rw rw
The DCMI_IER register is used to enable interrupts. When one of the DCMI_IER bits is set,
the corresponding interrupt is enabled. This register is accessible in both read and write.
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
FRAME_MIS
VSYNC_MIS
LINE_MIS
OVR_MIS
ERR_MIS
Reserved
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
FRAME_ISC
VSYNC_ISC
LINE_ISC
OVR_ISC
ERR_ISC
Reserved
w w w w w
The DCMI_ICR register is write-only. Writing a ‘1’ into a bit of this register clears the
corresponding bit in the DCMI_RIS and DCMI_MIS registers. Writing a ‘0’ has 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
FEC LEC LSC FSC
rw rw rw rw rw rw rw rw 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
FEU LEU LSU FSU
rw rw rw rw rw rw rw rw 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
VST[12:0 Reserv HOFFCNT[13:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw ed 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
Reserved
VLINE13:0] CAPCNT[13:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
Byte3 Byte2 Byte1 Byte0
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 digital camera Interface packages all the received data in 32-bit format before
requesting a DMA transfer. A 4-word deep FIFO is available to leave enough time for DMA
transfers and avoid DMA overrun conditions.
10
11
9
8
7
6
5
4
3
2
1
0
CAPTURE
PCKPOL
ENABLE
HSPOL
VSPOL
CROP
FCR
JPEG
Reserved
ESS
EDM
CM
DCMI_CR
0x00 Reserved C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
HSYNC
VSYNC
FNE
DCMI_SR
0x04 Reserved
Reset value 0 0 0
FRAME_RIS
VSYNC_RIS
LINE_RIS
OVR_RIS
ERR_RIS
DCMI_RIS
0x08 Reserved
Reset value 0 0 0 0 0
FRAME_IE
VSYNC_IE
LINE_IE
OVR_IE
ERR_IE
DCMI_IER
0x0C Reserved
Reset value 0 0 0 0 0
FRAME_MIS
VSYNC_MIS
LINE_MIS
OVR_MIS
ERR_MIS
DCMI_MIS
0x10 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
10
11
9
8
7
6
5
4
3
2
1
0
FRAME_ISC
VSYNC_ISC
LINE_ISC
OVR_ISC
ERR_ISC
DCMI_ICR
0x14 Reserved
Reset value 0 0 0 0 0
DCMI_CWSTR
Reserved
Reserve VST[12:0 HOFFCNT[13:0]
0x20 T
d
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
DCMI_CWSIZ
Reserved
Reserved
VLINE13:0] CAPCNT[13:0]
0x24 E
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
Refer to Section 2.3: Memory map for the register boundary addresses.
16.1 Introduction
The LCD-TFT (Liquid Crystal Display - Thin Film Transistor) display controller provides a
parallel digital RGB (Red, Green, Blue) and signals for horizontal, vertical synchronisation,
Pixel Clock and Data Enable as output to interface directly to a variety of LCD and TFT
panels.
Layer1
PFC LCD_HSYNC
FIFO
AHB Blending Dithering LCD_VSYNC
interface unit unit LCD_DE
Layer1 LCD-TFT
PFC LCD_CLK
FIFO panel
LCD_R[7:0]
LCD_G[7:0]
APB2 clock domain
Configuration LCD_B[7:0]
Timing
and status
generator
registers
Interrupts
MSv19675V1
LTDC_LxCR
LTDC_LxCFBAR
HCLK
LTDC_LxCFBLR
LTDC_LxCFBLNR
LTDC_SRCR
LTDC_IER
PCLK2
LTDC_ISR
LTDC_ICR
LTDC_SSCR
LTDC_BPCR
LTDC_AWCR
LTDC_TWCR
LTDC_GCR
LTDC_BCCR
LTDC_LIPCR
LTDC_CPSR
LTDC_CDSR Pixel Clock (LCD_CLK)
LTDC_LxWHPCR
LTDC_LxWVPCR
LTDC_LxCKCR
LTDC_LxPFCR
LTDC_LxCACR
LTDC_LxDCCR
LTDC_LxBFCR
LTDC_LxCLUTWR
Care must be taken when accessing the LTDC registers since the APB2 bus is stalling when
the following operations are ongoing:
• Register write access and update for 6 xPCKL2 period + 5x LCD_CLK period (5x
HCLK period for register on AHB clock domain)
• Register read access for 7xPCKL2 period + 5x LCD_CLK period (5x HCLK period for
register on AHB clock domain).
For registers on PCLK2 clock domain, APB2 bus is stalling during the register write access
for 6 xPCKL2 period and 7xPCKL2 period for read access.
The LCD controller can be reset by setting the corresponding bit in the RCC_APB2RSTR
register. It resets the three clock domains.
The LCD-TFT controller pins must be configured by the user application. The unused pins
can be used for other purposes.
For LTDC outputs up to 24-bit (RGB888), if less than 8bpp are used to output for example
RGB565 or RGB666 to interface on 16b-bit or 18-bit displays, the RGB display data lines
must be connected to the MSB of the LCD-TFT controller RGB data lines. As an example, in
the case of an LCD-TFT controller interfacing with a RGB565 16-bit display, the LCD display
R[4:0], G[5:0] and B[4:0] data lines pins must be connected to LCD-TFT controller
LCD_R[7:3], LCD_G[7:2] and LCD_B[7:3].
Total width
HBP HFP
HSYNC
width
Active width
VSYNC width
VBP
Data1, Line1
Total height
Data(n), Line(n)
VFP
MSv19674V1
Note: The HBP and HFP are respectively the Horizontal back porch and front porch period.
The VBP and the VFP are respectively the Vertical back porch and front porch period.
The LCD-TFT programmable synchronous timings are:
– HSYNC and VSYNC Width: Horizontal and Vertical Synchronization width
configured by programming a value of HSYNC Width - 1 and VSYNC Width - 1 in
the LTDC_SSCR register.
– HBP and VBP: Horizontal and Vertical Synchronization back porch width
configured by programming the accumulated value HSYNC Width + HBP - 1 and
the accumulated value VSYNC Width + VBP - 1 in the LTDC_BPCR register.
– Active Width and Active Height: The Active Width and Active Height are
configured by programming the accumulated value HSYNC Width + HBP +
Active Width - 1 and the accumulated value VSYNC Width + VBP + Active
Height - 1 in the LTDC_AWCR register (only up to 1024x768 is supported).
– Total Width: The Total width is configured by programming the accumulated value
HSYNC Width + HBP + Active Width + HFP - 1 in the LTDC_TWCR register. The
HFP is the Horizontal front porch period.
– Total Height: The Total Height is configured by programming the accumulated
value VSYNC Height + VBP + Active Height + VFP - 1 in the LTDC_TWCR
register. The VFP is the Vertical front porch period.
Note: When the LTDC is enabled, the timings generated start with X/Y=0/0 position as the first
horizontal synchronization pixel in the vertical synchronization area and following the back
porch, active data display area and the front porch.
When the LTDC is disabled, the timing generator block is reset to X=Total Width - 1,
Y=Total Height - 1 and held the last pixel before the vertical synchronization phase and the
FIFO are flushed. Therefore only blanking data is output continuously.
Programmable polarity
The Horizontal and Vertical Synchronization, Data Enable and Pixel Clock output signals
polarity can be programmed to active high or active low through the LTDC_GCR register.
Background Color
A constant background color (RGB888) can programmed through the LTDC_BCCR
register. It is used for blending with the bottom layer.
Dithering
The Dithering pseudo-random technique using an LFSR is used to add a small random
value (threshold) to each pixel color channel (R, G or B) value, thus rounding up the MSB in
some cases when displaying a 24-bit data on 18-bit display. Thus the Dithering technique is
used to round data which is different from one frame to the other.
The Dither pseudo-random technique is the same as comparing LSBs against a threshold
value and adding a 1 to the MSB part only, if the LSB part is >= the threshold. The LSBs are
typically dropped once dithering was applied.
The width of the added pseudo-random value is 2 bits for each color channel; 2 bits for Red,
2 bits for Green and 2 bits for Blue.
Once the LCD-TFT controller is enabled, the LFSR starts running with the first active pixel
and it is kept running even during blanking periods and when dithering is switched off. If the
LTDC is disabled, the LFSR is reset.
The Dithering can be switched On and Off on the fly through the LTDC_GCR register.
Windowing
Every layer can be positioned and resized and it must be inside the Active Display area.
The window position and size are configured through the top-left and bottom-right X/Y
positions and the Internal timing generator which includes the synchronous, back porch size
and the active data area. Refer to LTDC_LxWHPCR and LTDC_WVPCR registers.
The programmable layer position and size defines the first/last visible pixel of a line and the
first/last visible line in the window. It allows to display either the full image frame or only a
part of the image frame. Refer to Figure 83
• The first and the last visible pixel in the layer are set by configuring the WHSTPOS[11:0]
and WHSPPOS[11:0] in the LTDC_LxWHPCR register.
• The first and the last visible lines in the layer are set by configuring the WVSTPOS[10:0]
and WVSPPOS[10:0] in the LTDC_LxWVPCR register.
WVSPPOS bits in
WHSTPOS bits in
LTDC_LxWVPCR
LTDC_LxWHPCR Window
WHSPPOS bits in
LTDC_LxWHPCR
MSv19676V3
RGB888
RGB565
ARGB1555
@+3
@+2 @+1 @
Ax+1[0]Rx+1[4:0]
Gx+1[2:0] Bx+1[4:0] Ax[0] Rx[4:0] Gx[4:3] Gx[2:0] Bx[4:0]
Gx+1[4:3]
@+7 @+5
@+6 @+4
Ax+3[0]Rx+3[4:0] Ax+2[0]Rx+2[4:0]Gx+2[4:
Gx+3[2:0] Bx+3[4:0] Gx+2[2:0] Bx+2[4:0]
Gx+3[4:3] 3]
ARGB4444
L8
AL44
AL88
The R, G and B values and their own respective address are programmed through the
LTDC_LxCLUTWR register.
• In case of L8 and AL88 input pixel format, the CLUT has to be loaded by 256 colors. The
address of each color is configured in the CLUTADD bits in the LTDC_LxCLUTWR
register.
• In case of AL44 input pixel format, the CLUT has to be only loaded by 16 colors. The
address of each color must be filled by replicating the 4-bit L channel to 8-bit as follows:
– L0 (indexed color 0), at address 0x00
– L1, at address 0x11
– L2, at address 0x22
– .....
– L15, at address 0xFF
Layer Blending
The blending is always active and the two layers can be blended following the blending
factors configured through the LTDC_LxBFCR register.
The blending order is fixed and it is bottom up. If two layers are enabled, first the Layer1 is
blended with the Background color, then the Layer2 is blended with the result of blended
color of Layer1 and the background. Refer to Figure 84.
Layer 2
Layer 1 Layer 2 Layer 2 +
BG Layer 1 + BG Layer 1 + BG
MS19677V1
Default color
Every layer can have a default color in the format ARGB which is used outside the defined
layer window or when a layer is disabled.
The default color is configured through the LTDC_LxDCCR register.
The blending is always performed between the two layers even when a layer is disabled. To
avoid displaying the default color when a layer is disabled, keep the blending factors of this
layer in the LTDC_LxBFCR register to their reset value.
Color Keying
A color key (RGB) can be configured to be representative for a transparent pixel.
If the Color Keying is enabled, the current pixels (after format conversion and before
blending) are compared to the color key. If they match for the programmed RGB value, all
channels (ARGB) of that pixel are set to 0.
The Color Key value can be configured and used at run-time to replace the pixel RGB value.
The Color Keying is enabled through the LTDC_LxCKCR register.
Line
LTDC global interrupt
Register reload
FIFO underrun
LTDC global error interrupt
Transfer error
MS19678V1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
HSW[11:0]
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
VSH[10:0]
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
AHBP[11:0]
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
AVBP[10:0]
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
AAW[11:0]
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
AAH[10:0]
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
TOTALW[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
16 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TOTALH[10:0]
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
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
VBR IMR
Reserved
rw rw
Note: The shadow registers read back the active values. Until the reload has been done, the 'old'
value will be read.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BCRED[7:0]
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
BCGREEN[7:0] BCBLUE[7:0]
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
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
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
LIPOS[10:0]
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
CXPOS[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
CYPOS{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
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HSYNC VSYNC
HDES VDES
Reserved S S
r r r r
Note: The returned status does not depend on the configured polarity in the LTDC_GCR register,
instead it returns the current active display phase.
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
WHSPPOS[11:0]
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
WHSTPOS[11:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw
Example:
The LTDC_BPCR register is configured to 0x000E0005(AHBP[11:0] is 0xE) and the
LTDC_AWCR register is configured to 0x028E01E5(AAW[11:0] is 0x28E). To configure the
horizontal position of a window size of 630x460, with horizontal start offset of 5 pixels in the
Active data area.
1. Layer window first pixel: WHSTPOS[11:0] should be programmed to 0x14 (0xE+1+0x5)
2. Layer window last pixel: WHSPPOS[11:0] should be programmed to 0x28A
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
WVSPPOS[10:0]
Reserved
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
WVSTPOS[10:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw
Example:
The LTDC_BPCR register is configured to 0x000E0005 (AVBP[10:0] is 0x5) and the
LTDC_AWCR register is configured to 0x028E01E5 (AAH[10:0] is 0x1E5). To configure the
vertical position of a window size of 630x460, with vertical start offset of 8 lines in the Active
data area:
1. Layer window first line: WVSTPOS[10:0] should be programmed to 0xE (0x5 + 1 + 0x8)
2. Layer window last line: WVSPPOS[10:0] should be programmed to 0x1DA
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CKRED[7:0]
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
CKGREEN[7:0] CKBLUE[7:0]
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PF[2:0]
Reserved
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
CONSTA[7:0]
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
DCALPHA[7:0] DCRED[7:0]
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
DCGREEN[7:0] DCBLUE[7:0]
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BF1[2:0] BF2[2:0]
Reserved Reserved
rw rw rw rw rw rw
Note: The Constant Alpha value, is the programmed value in the LxCACR register divided by 255
by hardware.
Example: Only layer1 is enabled, BF1 configured to Constant Alpha
BF2 configured to 1 - Constant Alpha
Constant Alpha: The Constant Alpha programmed in the LxCACR register is 240 (0xF0).
Thus, the Constant Alpha value is 240/255 = 0.94
C: Current Layer Color is 128
Cs: Background color is 48
Layer1 is blended with the background color.
BC = Constant Alpha x C + (1 - Constant Alpha) x Cs = 0.94 x 128 + (1- 0.94) x 48 = 123.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CFBADD[31: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
CFBADD[31: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
CFBP[12:0]
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
CFBLL[12:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw
Example:
• A frame buffer having the format RGB565 (2 bytes per pixel) and a width of 256 pixels
(total number of bytes per line is 256x2=512 bytes), where pitch = line length requires a
value of 0x02000203 to be written into this register.
• A frame buffer having the format RGB888 (3 bytes per pixel) and a width of 320 pixels
(total number of bytes per line is 320x3=960), where pitch = line length requires a value
of 0x03C003C3 to be written into this register.
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
CFBLNBR[10:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw
Note: The number of lines and line length settings define how much data is fetched per frame for
every layer. If it is configured to less bytes than required, a FIFO underrun interrupt will be
generated if enabled.
The start address and pitch settings on the other hand define the correct start of every line in
memory.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CLUTADD[7:0] RED[7:0]
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
GREEN[7:0] BLUE[7:0]
w w w w w w w w w w w w w w w w
Note: The CLUT write register should only be configured during blanking period or if the layer is
disabled. The CLUT can be enabled or disabled in the LTDC_LxCR register.
The CLUT is only meaningful for L8, AL44 and AL88 pixel format.
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
LTDC_SSCR HSW[9:0] VSH[10:0]
0x0008 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
DGW[2:0]
DRW[2:0]
DBW[2:0]
LTDCEN
HSPOL
DEPOL
PCPOL
VSPOL
Reserved
Reserved
Reserved
Reserved
DEN
LTDC_GCR
0x0018 Reserve
Reset value 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0
VBR
IMR
LTDC_SRCR
0x0024 Reserved
Reset value 0 0
LTDC_BCCR BC[23:0]
0x002C 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
TERRIE
RRIE
FUIE
LIE
LTDC_IER
0x0034 Reserved
Reset value 0 0 0 0
TERRIF
RRIF
FUIF
LTDC_ISR
LIF
0x0038 Reserved
Reset value 0 0 0 0
CTERRIF
CRRIF
CFUIF
CLIF
LTDC_ICR
0x003C Reserved
Reset value 0 0 0 0
LTDC_LIPCR LIPOS[10:0]
0x0040 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
LTDC_CDSR
0x0048 Reserved
Reset value 1 1 1 1
COLKEN
CLUTEN
Reserved
LEN
LTDC_L1CR
0x0084 Reserved
Reset value 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
LTDC_L1WVPCR WVSPPOS[10:0] WVSTPOS[10:0]
0x008C 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
LTDC_L1PFCR PF[2:0]
0x0094 Reserved
Reset value 0 0 0
LTDC_L1CACR CONSTA[7:0]
0x0098 Reserved
Reset value 1 1 1 1 1 1 1 1
LTDC_L1CFBAR CFBADD[31:0]
0x00AC
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
LTDC_L1CFBLNR CFBLNBR[10:0]
0x00B4 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
COLKEN
CLUTEN
Reserved
LEN
LTDC_L2CR
0x0104 Reserved
Reset value 0 0 0
LTDC_L2PFCR PF[2:0]
0x0114 Reserved
Reset value 0 0 0
LTDC_L2CACR CONSTA[7:0]
0x0118 Reserved
Reset value 1 1 1 1 1 1 1 1
LTDC_L2CFBAR CFBADD[31:0]
0x012C
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
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
LTDC_L2CFBLNR CFBLNBR[10:0]
0x0134 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0
This section applies to the whole STM32F4xx family, unless otherwise specified.
ETR Trigger
Polarity selection, ETRF controller
Edge detector and Prescaler ETRP
TRGO To other timers
Input filter To DAC and ADC
ITR0
TGI
ITR1
ITR2 TRGI Slave mode
TRC controller
ITR3
TIF_ED
Reset,
UI
Enable,
Up/Down,
TI1FP1 Count REP Register
Encoder
interface U
TIMx_CH1
TI2FP2
OC1
TIMx_CH1N
AutoReload
U
Register
OC1N
Repetition counter
CK_PSC PSC CK_CNT CNT
TIMx_CH2
(prescaler) (counter) DTG[7:0] registers
TIMx_CH1
CC1I CC1I
TI1 TI1FP1
OC2
Input filter & IC1 IC1PS Capture/Compare OC1REF Output
Prescaler DTG
TIMx_CH2N
Edge detector 1 Register control
TI1FP2
U
TRC CC2I CC2I
TIMx_CH2
TI2FP1
TI2 Input filter & IC2 IC2PS Capture/Compare OC2REF
Prescaler DTG Output
Edge detector 2 Register control
TI2FP2 OC2N
U
TIMx_CH3N TIMx_CH3
TRC CC3I CC3I
TIMx_CH3
TI3FP3 OC3
TI3 Input filter & IC3 IC3PS Capture/Compare OC3REF
Prescaler DTG Output
Edge detector 3 Register control
TI3FP4 U
OC3N
TRC CC4I CC4I
TIMx_CH4
TI4FP3
TI4 Input filter & IC4 IC4PS Capture/Compare OC4REF Output
Prescaler control
Edge detector 4 Register
TI4FP4
U
TRC
OC4
TIMx_CH4
TIMx_BKIN
BRK BI
Polarity selection
Event
MS39906V3
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 87 and Figure 88 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 87. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
MS31076V2
Figure 88. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Timerclock = CK_CNT
F7 F8 F9 FA FB FC 00 01
Counter register
0 3
Prescaler control register
0 3
Prescaler buffer
0 0 1 2 3 0 1 2 3
Prescaler counter
MS31077V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_PSC
Timerclock = CK_CNT
Counter register 1F 20 00
Counter overflow
Figure 93. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Figure 94. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload shadow
register F5 36
Downcounting mode
In downcounting mode, the counter counts from the auto-reload value (content of the
TIMx_ARR register) down to 0, then restarts from the auto-reload value and generates a
counter underflow event.
If the repetition counter is used, the update event (UEV) is generated after downcounting is
repeated for the number of times programmed in the repetition counter register plus one
(TIMx_RCR+1). Else the update event is generated at each counter underflow.
Setting the UG bit in the TIMx_EGR register (by software or by using the slave mode
controller) also generates an update event.
The UEV update event can be disabled by software by setting the UDIS bit in TIMx_CR1
register. This is to avoid updating the shadow registers while writing new values in the
preload registers. Then no update event occurs until UDIS bit has been written to 0.
However, the counter restarts from the current auto-reload value, whereas the counter of the
prescaler restarts from 0 (but the prescale rate doesn’t change).
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or
DMA request is sent). This is to avoid generating both update and capture interrupts when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
• The repetition counter is reloaded with the content of TIMx_RCR register
• The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register)
• The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that the auto-reload is updated before the counter is
reloaded, so that the next period is the expected one
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
(cnt_udf)
MS31184V1
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
MS31185V1
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
CK_PSC
Timerclock = CK_CNT
Counter register 20 1F 00 36
Counter underflow
MS31187V1
Figure 99. Counter timing diagram, update event when repetition counter is not used
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
Auto-reload preload
register FF 36
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 100. Counter timing diagram, internal clock divided by 1, TIMx_ARR = 0x6
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 04 03 02 01 00 01 02 03 04 05 06 05 04 03
Counter underflow
Counter overflow
1. Here, center-aligned mode 1 is used (for more details refer to Section 17.4: TIM1 and TIM8 registers).
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_PSC
Timerclock = CK_CNT
Counter register 20 1F 01 00
Counter underflow
Figure 104. 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 overflow
MS31193V3
Figure 105. Counter timing diagram, Update event with ARPE=1 (counter overflow)
CK_PSC
CEN
Timer clock = CK_CNT
Counter register F7 F8 F9 FA FB FC 36 35 34 33 32 31 30 2F
Counter overflow
MS31194V2
Figure 106. Update rate examples depending on mode and TIMx_RCR register
settings
Counter-aligned mode Edge-aligned mode
Counter Upcounting Downcounting
TIMx_CNT
TIMx_RCR = 0
UEV
TIMx_RCR = 1
UEV
UEV
TIMx_RCR = 2
TIMx_RCR = 3 UEV
TIMx_RCR = 3
and
UEV
re-synchronization
(by SW) (by SW) (by SW)
UEV Update event: Preload registers transferred to active registers and update interrupt generated
Update Event if the repetition counter underflow occurs when the counter is equal to the auto-reload value.
MSv31195V1
Internal clock
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MS31085V2
TIMx_SMCR
TS[2:0]
or TI2F or
TI1F or Encoder
ITRx mode
0xx
TI1_ED
100 TRGI External clock
TI1FP1 mode 1 CK_PSC
TI2F_Rising 101
TI2 Edge 0 TI2FP2 ETRF External clock
Filter 110
detector 1 ETRF mode 2
TI2F_Falling 111
CK_INT Internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
ECE SMS[2:0]
TIMx_SMCR
MS31196V1
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = ‘01’ in
the TIMx_CCMR1 register.
2. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1
register (if no filter is needed, keep IC2F=0000).
3. Select rising edge polarity by writing CC2P=0 and CC2NP=0 in the TIMx_CCER
register.
4. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
5. Select TI2 as the trigger input source by writing TS=110 in the TIMx_SMCR register.
6. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
Note: The capture prescaler is not used for triggering, so the user does not need to configure it.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
MS31087V2
or TI2F or
TI1F or Encoder
mode
ECE SMS[2:0]
TIMx_SMCR
MS33116V1
For example, to configure the upcounter to count each 2 rising edges on ETR, use the
following procedure:
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.
f CK_INT
CNT_EN
ETR
ETRP
ETRF
Counter clock =
CK_INT =CK_PSC
Counter register 34 35 36
MS33111V2
TI1F_ED
To the slave mode controller
TI1 TI1F_Rising
Filter TI1F Edge 0 TI1FP1
fDTS downcounter TI1F_Falling 01
detector 1
TI2FP1 IC1 Divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P/CC1NP TRC
11
TIMx_CCMR1 TIMx_CCER (from slave mode
TI2F_Rising controller)
0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_Falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
MS33115V1
The output stage generates an intermediate waveform that 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
S write CCR1H
low
MS35909V1
CC4E TIM1_CCER
MS37370V1
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.
forced high (OCxREF is always active high) and OCx get opposite value to CCxP polarity
bit.
For example: CCxP=0 (OCx active high) => OCx is forced to high level.
The OCxREF signal can be forced low by writing the OCxM bits to 100 in the TIMx_CCMRx
register.
Anyway, the comparison between the TIMx_CCRx shadow register and the counter is still
performed and allows the flag to be set. Interrupt and DMA requests can be sent
accordingly. This is described in the output compare mode section below.
OC1REF= OC1
compare value in TIMx_CCRx is greater than the auto-reload value (in TIMx_ARR)
then OCxREF is held at ‘1’. If the compare value is 0 then OCxRef is held at ‘0’.
Figure 118 shows some edge-aligned PWM waveforms in an example where
TIMx_ARR=8.
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘1’
CCRx>8
CCxIF
OCXREF ‘0’
CCRx=0
CCxIF
MS31093V1
• Downcounting configuration
Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to
Downcounting mode
In PWM mode 1, the reference signal OCxRef is low as long as
TIMx_CNT > TIMx_CCRx else it becomes high. If the compare value in TIMx_CCRx is
greater than the auto-reload value in TIMx_ARR, then OCxREF is held at ‘1’. 0% PWM
is not possible in this mode.
TIMx_CR1 register is updated by hardware and must not be changed by software. Refer to
Center-aligned mode (up/down counting).
Figure 119 shows some center-aligned PWM waveforms in an example where:
• TIMx_ARR=8,
• PWM mode is the PWM mode 1,
• The flag is set when the counter counts down corresponding to the center-aligned
mode 1 selected for CMS=01 in TIMx_CR1 register.
Counter register 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1
OCxREF
CCRx = 4
CCxIF CMS=01
CMS=10
CMS=11
OCxREF
CCRx = 7
CMS=10 or 11
CCxIF
'1'
OCxREF
CCRx = 8
CCxIF CMS=01
CMS=10
CMS=11
'1'
OCxREF
CCRx > 8
CCxIF CMS=01
CMS=10
CMS=11
'0'
OCxREF
CCRx = 0
CCxIF CMS=01
CMS=10
CMS=11
ai14681b
in the TIMx_CR1 register. Moreover, the DIR and CMS bits must not be changed at the
same time by the software.
• Writing to the counter while running in center-aligned mode is not recommended as it
can lead to unexpected results. In particular:
– The direction is not updated if the user writes a value in the counter greater than
the auto-reload value (TIMx_CNT>TIMx_ARR). For example, if the counter was
counting up, it will continue to count up.
– The direction is updated if the user writes 0 or write the TIMx_ARR value in the
counter but no Update Event UEV is generated.
• The safest way to use center-aligned mode is to generate an update by software
(setting the UG bit in the TIMx_EGR register) just before starting the counter and not to
write the counter while it is running.
OCxREF
OCx
delay
OCxN
delay
MS31095V1
Figure 121. Dead-time waveforms with delay greater than the negative pulse.
OCxREF
OCx
delay
OCxN
MS31096V1
Figure 122. Dead-time waveforms with delay greater than the positive pulse.
OCxREF
OCx
OCxN
delay
MS31097V1
The dead-time delay is the same for each of the channels and is programmable with the
DTG bits in the TIMx_BDTR register. Refer to Section 17.4.18: TIM1 and TIM8 break and
dead-time register (TIMx_BDTR) for delay calculation.
have both outputs at inactive level or both outputs active and complementary with
dead-time.
Note: When only OCxN is enabled (CCxE=0, CCxNE=1), it is not complemented and becomes
active as soon as OCxREF is high. For example, if CCxNP=0 then OCxN=OCxRef. On the
other hand, when both OCx and OCxN are enabled (CCxE=CCxNE=1) OCx becomes
active when OCxREF is high whereas OCxN is complemented and becomes active when
OCxREF is low.
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 it is written to ‘1’ again. In this case, it can be used for
security and the break input can be connected to an alarm from power drivers, thermal
sensors or any security components.
Note: The break inputs 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.
There are two solutions to generate a break:
• By using the BRK input which has a programmable polarity and an enable bit BKE in
the TIMx_BDTR register
• By software through the BG bit of the TIMx_EGR 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 freezing the
configuration of several parameters (dead-time duration, OCx/OCxN polarities and state
when disabled, OCxM configurations, break enable and polarity). The user can choose from
three levels of protection selected by the LOCK bits in the TIMx_BDTR register. Refer to
Section 17.4.18: TIM1 and TIM8 break and dead-time register (TIMx_BDTR). The LOCK
bits can be written only once after an MCU reset.
BREAK (MOE )
OCxREF
OCx
(OCxN not implemented, CCxP=0, OISx=1)
OCx
(OCxN not implemented, CCxP=0, OISx=0)
OCx
(OCxN not implemented, CCxP=1, OISx=1)
OCx
(OCxN not implemented, CCxP=1, OISx=0)
OCx
OCx
OCx
OCxN delay
(CCxE=1, CCxP=0, OISx=0, CCxNE=0, CCxNP=0, OISxN=1)
OCx
OCxN delay
(CCxE=1, CCxP=0, OISx=1, CCxNE=0, CCxNP=0, OISxN=0)
OCx
OCxN
(CCxE=1, CCxP=0, CCxNE=0, CCxNP=0, OISx=OISxN=0 or OISx=OISxN=1)
MS31098V1
(CCRx)
Counter (CNT)
ETRF
Note: In case of a PWM with a 100% duty cycle (if CCRx>ARR), then OCxREF is enabled again at
the next counter overflow.
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0 t
tDELAY tPULSE
MS31099V2
For example the user 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’ and CC2NP=’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 us say the user wants 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, enable PWM mode 2 by writing OC1M=111 in the
TIMx_CCMR1 register. The user 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 the compare value must be written 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.
The user only wants one pulse (Single mode), so '1’ must be written in the OPM bit in the
TIMx_CR1 register to stop the counter at the next update event (when the counter rolls over
from the auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0',
so the Repetitive Mode is selected.
Particular case: OCx fast enable:
In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the
counter. Then the comparison between the counter and the compare value makes the
output toggle. But several clock cycles are needed for these operations and it limits the
minimum delay tDELAY min we can get.
If the user wants to output a waveform with the minimum delay, the OCxFE bit in the
TIMx_CCMRx register must be set. 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.
TIMx_ARR register (0 to ARR or ARR down to 0 depending on the direction). So user must
configure TIMx_ARR before starting. in the same way, the capture, compare, prescaler,
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.
Table 93 summarizes the possible combinations, assuming TI1 and TI2 do not 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 127 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’, CC1NP=’0’, and IC1F = ‘0000’ (TIMx_CCER register, TI1FP1 non-inverted,
TI1FP1=TI1).
• CC2P=’0’, CC2NP=’0’, and IC2F = ‘0000’ (TIMx_CCER register, TI1FP2 non-inverted,
TI1FP2= TI2).
• SMS=’011’ (TIMx_SMCR register, both inputs are active on both rising and falling
edges).
• CEN=’1’ (TIMx_CR1 register, Counter enabled).
TI1
TI2
Counter
up down up
MS33107V1
Figure 128 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=’1’).
Figure 128. Example of encoder interface mode with TI1FP1 polarity inverted.
TI1
TI2
Counter
down up down
MS33108V1
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position.The user 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. This can be done by latching the counter value into a third
input capture register if available (then the capture signal must be periodic and can be
generated by another timer). when available, it is also possible to read its value through a
DMA request generated by a real-time clock.
TIH1
TIH2
Interfacing timer
TIH3
Counter (CNT)
(CCR2)
TRGO=OC2REF
COM
OC1
OC1N
Advanced-control timers
OC2
OC2N
OC3
OC3N
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
MS31401V3
TI1
CNT_EN
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
MS31402V3
TI2
CNT_EN
Counter register 34 35 36 37 38
TIF
MS31403V2
TI1
CEN/CNT_EN
ETR
Counter register 34 35 36
TIF
MS33110V1
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 95. Output control bits for complementary OCx and OCxN channels with
break feature
Control bits Output states(1)
Note: The state of the external I/O pins connected to the complementary OCx and OCxN channels
depends on the OCx and OCxN channel state and the GPIO registers.
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.
17.4.20 TIM1 and TIM8 DMA address for full transfer (TIMx_DMAR)
Address offset: 0x4C
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DMAB[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMAB[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Table 96. TIM1 and TIM8 register map and reset values
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
CKD CMS
ARPE
UDIS
OPM
CEN
URS
DIR
TIMx_CR1
0x00 Reserved [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0
OIS3N
OIS2N
OIS1N
CCPC
CCDS
CCUS
Reserved
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
ETP
Reserved
MSM
ECE
ETP
TIMx_SMCR S 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
CC3IE
CC2IE
CC1IE
UDE
TDE
UIE
BIE
TIMx_DIER
TIE
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CC4OF
CC3OF
CC2OF
CC1OF
COMIF
CC4IF
CC3IF
CC2IF
CC1IF
Reserved
TIMx_SR
UIF
BIF
TIF
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
COMG
CC4G
CC3G
CC2G
CC1G
TIMx_EGR
UG
BG
TG
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0
TIMx_CCMR1 CC1
OC2CE
OC1CE
OC2PE
OC1PE
OC2FE
OC1FE
OC2M CC2S OC1M
Output compare S
Reserved [2:0] [1:0] [2:0]
mode [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC2 IC1 CC1
CC2S
Input capture IC2F[3:0] PSC IC1F[3:0] PSC S
Reserved [1:0]
mode [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 CC3
OC4CE
OC3CE
OC4PE
OC3PE
OC4FE
OC3FE
CC3NP
CC3NE
CC2NP
CC2NE
CC1NP
CC1NE
CC4P
CC4E
CC3P
CC3E
CC2P
CC2E
CC1P
CC1E
Reserved
TIMx_CCER
0x20 Reserved
Reset value 0 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
Table 96. TIM1 and TIM8 register map and reset values (continued)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
TIMx_ARR ARR[15:0]
0x2C Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
TIMx_RCR REP[7:0]
0x30 Reserved
Reset value 0 0 0 0 0 0 0 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
LOCK
OSSI
MOE
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[31:0]
0x4C
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
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
TI1FP1 Encoder
TI2FP2 interface
U
Auto-reload register UI
Stop, clear or up/down
U
CK_PSC PSC CK_CNT +/- CNT counter
prescaler
CC1I U CC1I
XOR TI1FP1 OC1REF
TI1 Input filter & IC1 IC1PS Output OC1 TIMx_CH1
TI1FP2 Prescaler Capture/Compare 1 register
edge detector control
TIMx_CH1 TRC
CC2I
U CC2I
TI2FP1
TI2 Input filter & IC2 Output OC2
TIMx_CH2 TI2FP2 Prescaler
IC2PS Capture/Compare 2 register OC2REF TIMx_CH2
edge detector control
TRC
CC3I CC3I
U
TI3FP3 OC3REF
TI3 Input filter & IC3 IC3PS Output OC3 TIMx_CH3
TI3FP4 Prescaler Capture/Compare 3 register
TIMx_CH3 edge detector control
TRC CC4I
U CC4I
TI4FP3
TI4 Input filter & IC4 Output OC4
TIMx_CH4 TI4FP4 Prescaler
IC4PS Capture/Compare 4 register OC4REF TIMx_CH4
edge detector control
TRC
ETRF
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
MS19673V1
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit/32-bit register (in the TIMx_PSC
register). It can be changed on the fly as this control register is buffered. The new prescaler
ratio is taken into account at the next update event.
Figure 135 and Figure 136 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 135. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
MS35833V1
Figure 136. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CNT_EN
Timerclock = CK_CNT
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
MS35834V1
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 buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register)
• The auto-reload shadow register is updated with the preload value (TIMx_ARR)
The following figures show some examples of the counter behavior for different clock
frequencies when TIMx_ARR=0x36.
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_INT
Timerclock = CK_CNT
Counter register 1F 20 00
Counter overflow
Figure 141. Counter timing diagram, Update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
Figure 142. Counter timing diagram, Update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CNT_EN
Timerclock = CK_CNT
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
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
MSv37305V1
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter underflow
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter underflow
CK_INT
Timerclock = CK_CNT
Counter register 20 1F 00 36
Counter overflow
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter overflow
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
Timerclock = CK_CNT
Counter register 04 03 02 01 00 01 02 03 04 05 06 05 04 03
Counter underflow
Counter overflow
1. Here, center-aligned mode 1 is used, for more details refer to Section 18.4.1: TIMx control register 1 (TIMx_CR1).
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter underflow
CK_INT
CNT_EN
Timerclock = CK_CNT
Timerclock = CK_CNT
Counter register 20 1F 01 00
Counter underflow
Figure 152. Counter timing diagram, Update event with ARPE=1 (counter underflow)
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter register 06 05 04 03 02 01 00 01 02 03 04 05 06 07
Counter underflow
Figure 153. 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
MS37361V1
Internal clock
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MS31085V2
or TI2F or
TI1F or Encoder
ITRx mode
0xx
TI1_ED
100 TRGI External clock
TI1FP1 mode 1 CK_PSC
TI2F_Rising 101
TI2 Edge 0 TI2FP2 ETRF External clock
Filter 110
detector 1 ETRF mode 2
TI2F_Falling 111
CK_INT Internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
ECE SMS[2:0]
TIMx_SMCR
MS31196V1
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S= ‘01 in the
TIMx_CCMR1 register.
2. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1
register (if no filter is needed, keep IC2F=0000).
Note: The capture prescaler is not used for triggering, so there’s no need to configure it.
3. Select rising edge polarity by writing CC2P=0 and CC2NP=0 in the TIMx_CCER
register.
4. Configure the timer in external clock mode 1 by writing SMS=111 in the TIMx_SMCR
register.
5. Select TI2 as the input source by writing TS=110 in the TIMx_SMCR register.
6. Enable the counter by writing CEN=1 in the TIMx_CR1 register.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
MS31087V2
or TI2F or
TI1F or Encoder
mode
TRGI External clock
ETR CK_PSC
mode 1
0
ETR pin Divider ETRP Filter ETRF External clock
1 /1, /2, /4, /8 downcounter mode 2
CK_INT CK_INT Internal clock
ETP ETPS[1:0] ETF[3:0] (internal clock) mode
TIMx_SMCR TIMx_SMCR TIMx_SMCR
ECE SMS[2:0]
TIMx_SMCR
MS37365V1
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
MS37362V1
TI1F_ED
to the slave mode controller
TI1F_Rising
TI1 TI1F
filter Edge TI1FP1
01
fDTS downcounter Detector TI1F_Falling
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
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_falling
(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
S write CCR1H
low
Read CCR1H S write_in_progress
read_in_progress write CCR1L
Read CCR1L Capture/compare preload register R
R Output CC1S[1]
capture_transfer compare_transfer mode
CC1S[0]
CC1S[1] Input
mode OC1PE
CC1S[0] Capture/compare shadow register OC1PE
UEV
TIMx_CCMR1
Comparator (from time
IC1PS Capture
base unit)
CC1E CNT>CCR1
Counter CNT=CCR1
CC1G
TIMx_EGR
MS33144V1
CC1P
TIMx_CNT > TIMx_CCR1
Output mode oc1ref TIMx_CCER
TIMx_CNT = TIMx_CCR1 controller
CC1E
TIMx_CCER
OC1M[2:0]
TIMx_CCMR1 ai17187b
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.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
The TIMx_CCRx register can be updated at any time by software to control the output
waveform, provided that the preload register is not enabled (OCxPE=0, else TIMx_CCRx
shadow register is updated only at the next update event UEV). An example is given in
Figure 163.
OC1REF = OC1
Upcounting configuration
Upcounting is active when the DIR bit in the TIMx_CR1 register is low. Refer to Upcounting
mode.
In the following example, we consider PWM mode 1. The reference PWM signal OCxREF is
high as long as TIMx_CNT <TIMx_CCRx else it becomes low. If the compare value in
TIMx_CCRx is greater than the auto-reload value (in TIMx_ARR) then OCxREF is held at ‘1.
If the compare value is 0 then OCxREF is held at ‘0. Figure 164 shows some edge-aligned
PWM waveforms in an example where TIMx_ARR=8.
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘1’
CCRx>8
CCxIF
OCXREF ‘0’
CCRx=0
CCxIF
MS31093V1
Downcounting configuration
Downcounting is active when DIR bit in TIMx_CR1 register is high. Refer to Downcounting
mode.
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.
up and down depending on the CMS bits configuration. The direction bit (DIR) in the
TIMx_CR1 register is updated by hardware and must not be changed by software. Refer to
Center-aligned mode (up/down counting).
Figure 165 shows some center-aligned PWM waveforms in an example where:
• TIMx_ARR=8,
• PWM mode is the PWM mode 1,
• The flag is set when the counter counts down corresponding to the center-aligned
mode 1 selected for CMS=01 in TIMx_CR1 register.
Counter register 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1
OCxREF
CCRx = 4
CCxIF CMS=01
CMS=10
CMS=11
OCxREF
CCRx = 7
CMS=10 or 11
CCxIF
'1'
OCxREF
CCRx = 8
CCxIF CMS=01
CMS=10
CMS=11
'1'
OCxREF
CCRx > 8
CCxIF CMS=01
CMS=10
CMS=11
'0'
OCxREF
CCRx = 0
CCxIF CMS=01
CMS=10
CMS=11
ai14681b
in the TIMx_CR1 register. Moreover, the DIR and CMS bits must not be changed at the
same time by the software.
• Writing to the counter while running in center-aligned mode is not recommended as it
can lead to unexpected results. In particular:
– The direction is not updated if the user writes a value in the counter that is greater
than the auto-reload value (TIMx_CNT>TIMx_ARR). For example, if the counter
was counting up, it continues to count up.
– The direction is updated if the user writes 0 or write the TIMx_ARR value in the
counter but no Update Event UEV is generated.
• The safest way to use center-aligned mode is to generate an update by software
(setting the UG bit in the TIMx_EGR register) just before starting the counter and not to
write the counter while it is running.
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY tPULSE t
MS31099V1
For example the user 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.
1. The external trigger prescaler should be kept off: bits ETPS[1:0] in the TIMx_SMCR
register are cleared to 00.
2. The external clock mode 2 must be disabled: bit ECE in the TIM1_SMCR register is
cleared to 0.
3. The external trigger polarity (ETP) and the external trigger filter (ETF) can be
configured according to the application’s needs.
Figure 167 shows the behavior of the OCxREF signal when the ETRF input becomes high,
for both values of the OCxCE enable bit. In this example, the timer TIMx is programmed in
PWM mode.
(CCRx)
Counter (CNT)
ETRF
1. In case of a PWM with a 100% duty cycle (if CCRx>ARR), OCxREF is enabled again at the next counter
overflow.
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 168 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’, CC1NP = ‘0’, IC1F =’0000’ (TIMx_CCER register, TI1FP1 noninverted,
TI1FP1=TI1)
• CC2P= ‘0’, CC2NP = ‘0’, IC2F =’0000’ (TIMx_CCER register, TI2FP2 noninverted,
TI2FP2=TI2)
• SMS= ‘011’ (TIMx_SMCR register, both inputs are active on both rising and falling
edges)
• CEN = 1 (TIMx_CR1 register, Counter is enabled)
TI1
TI2
Counter
up down up
MS33107V1
Figure 169 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=1).
Figure 169. Example of encoder interface mode with TI1FP1 polarity inverted
TI1
TI2
Counter
down up down
MS33108V1
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. The user 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. The user 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.
TI1
UG
TIF
MS37384V1
TI1
CNT_EN
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
MS40512V1
1. The configuration “CCxP=CCxNP=1” (detection of both rising and falling edges) does not have any effect
in gated mode because gated mode acts on a level and not on an edge.
When a rising edge occurs on TI2, the counter starts counting on the internal clock and the
TIF flag is set.
The delay between the rising edge on TI2 and the actual start of the counter is due to the
resynchronization circuit on TI2 input.
CNT_EN
TIF
MS37386V1
TI1
CEN/CNT_EN
ETR
Counter register 34 35 36
TIF
MS33110V1
UEV
Master Slave
TRGO1 ITR0 CK_PSC
mode mode
Prescaler Counter control control Prescaler Counter
Input trigger
selection
MS37387V1
For example, the user can configure Timer 1 to act as a prescaler for Timer 2 (see
Figure 174). 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 ITR0 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.
CK_INT
TIMER1-OC1REF
TIMER1-CNT FC FD FE FF 00 01
TIMER2-TIF
Write TIF = 0
MS37388V1
In the example in Figure 175, 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
TIMER2-TIF
Write TIF = 0
MS37389V1
CK_INT
TIMER1-UEV
TIMER1-CNT FD FE FF 00 01 02
TIMER2-CNT 45 46 47 48
TIMER2-CEN=CNT_EN
TIMER2-TIF
Write TIF = 0
MS37390V1
As in the previous example, the user can initialize both counters before starting counting.
Figure 178 shows the behavior with the same configuration as in Figure 177 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
TIMER2-TIF
Write TIF = 0
MS37391V1
CK_INT
TIMER1-TI1
TIMER1-CEN=CNT_EN
TIMER1-CK_PSC
TIMER1-CNT 00 01 02 03 04 05 06 07 08 09
TIMER1-TIF
TIMER2-CEN=CNT_EN
TIMER2-CK_PSC
TIMER2-CNT 00 01 02 03 04 05 06 07 08 09
TIMER2-TIF
MS37392V1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OC2CE OC2M[2:0] OC2PE OC2FE OC1CE OC1M[2:0] OC1PE OC1FE
CC2S[1:0] 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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CC4NP CC4P CC4E CC3NP CC3P CC3E CC2NP CC2P CC2E CC1NP CC1P CC1E
Res. Res. Res. Res.
rw rw rw rw rw rw rw rw rw rw rw rw
Note: The state of the external IO pins connected to the standard OCx channels depends on the
OCx channel state and the GPIO registers.
Bits 31:16 CNT[31:16]: High counter value (on TIM2 and TIM5).
Bits 15:0 CNT[15:0]: Counter value
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ARR[31:16] (depending on timers)
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ARR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bits 31:16 ARR[31:16]: High auto-reload value (on TIM2 and TIM5).
Bits 15:0 ARR[15:0]: Auto-reload value
ARR is the value to be loaded in the actual auto-reload register.
Refer to the Section 18.3.1: Time-base unit for more details about ARR update and
behavior.
The counter is blocked while the auto-reload value is null.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR1[15:0]
rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro
Bits 31:16 CCR1[31:16]: High Capture/Compare 1 value (on TIM2 and TIM5).
Bits 15:0 CCR1[15:0]: Low Capture/Compare 1 value
If channel CC1 is configured as output:
CCR1 is the value to be loaded in the actual capture/compare 1 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIMx_CCMR1 register
(bit OC1PE). Else the preload value is copied in the active capture/compare 1 register when
an update event occurs.
The active capture/compare register contains the value to be compared to the counter
TIMx_CNT and signaled on OC1 output.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR2[15:0]
rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro
Bits 31:16 CCR2[31:16]: High Capture/Compare 2 value (on TIM2 and TIM5).
Bits 15:0 CCR2[15:0]: Low Capture/Compare 2 value
If channel CC2 is configured as output:
CCR2 is the value to be loaded in the actual capture/compare 2 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIMx_CCMR register (bit
OC2PE). Else the preload value is copied in the active capture/compare 2 register when an
update event occurs.
The active capture/compare register contains the value to be compared to the counter
TIMx_CNT and signalled on OC2 output.
If channel CC2 is configured as input:
CCR2 is the counter value transferred by the last input capture 2 event (IC2). The
TIMx_CCR2 register is read-only and cannot be programmed.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CCR3[15:0]
rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro rw/ro
Bits 31:16 CCR3[31:16]: High Capture/Compare 3 value (on TIM2 and TIM5).
Bits 15:0 CCR3[15:0]: Low Capture/Compare value
If channel CC3 is configured as output:
CCR3 is the value to be loaded in the actual capture/compare 3 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIMx_CCMR register (bit
OC3PE). Else the preload value is copied in the active capture/compare 3 register when an
update event occurs.
The active capture/compare register contains the value to be compared to the counter
TIMx_CNT and signaled on OC3 output.
If channel CC3 is configured as input:
CCR3 is the counter value transferred by the last input capture 3 event (IC3). The
TIMx_CCR3 register is read-only and cannot be programmed.
Bits 31:16 CCR4[31:16]: High Capture/Compare 4 value (on TIM2 and TIM5).
Bits 15:0 CCR4[15:0]: Low Capture/Compare value
1. if CC4 channel is configured as output (CC4S bits):
CCR4 is the value to be loaded in the actual capture/compare 4 register (preload value).
It is loaded permanently if the preload feature is not selected in the TIMx_CCMR register
(bit OC4PE). Else the preload value is copied in the active capture/compare 4 register
when an update event occurs.
The active capture/compare register contains the value to be compared to the counter
TIMx_CNT and signalled on OC4 output.
2. if CC4 channel is configured as input (CC4S bits in TIMx_CCMR4 register):
CCR4 is the counter value transferred by the last input capture 4 event (IC4). The
TIMx_CCR4 register is read-only and cannot be programmed.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ITR1_RMP
Reserved Reserved
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TI4_RMP
Reserved Reserved
rw rw
10
11
9
8
7
6
5
4
3
2
1
0
CKD CMS
ARPE
UDIS
OPM
CEN
URS
DIR
TIMx_CR1
0x00 Reserved [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0
CCDS
TI1S
TIMx_CR2 MMS[2:0]
0x04 Reserved Reserved
Reset value 0 0 0 0 0
ETPS
Reserved
MSM
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
CC4IE
CC3IE
CC2IE
CC1IE
Reserved
Reserved
UDE
TDE
UIE
TIMx_DIER
TIE
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
TIMx_SR
UIF
TIF
0x10 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
CC4G
CC3G
CC2G
CC1G
Reserved
TIMx_EGR
UG
TG
0x14 Reserved
Reset value 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
OC4CE
OC3CE
OC4PE
OC3PE
OC4FE
OC3FE
OC4M CC4S OC3M CC3S
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
0x1C
TIMx_CCMR2 IC4 IC3
CC4S CC3S
Input Capture IC4F[3:0] PSC IC3F[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
Reserved
Reserved
Reserved
Reserved
CC4NP
CC3NP
CC2NP
CC1NP
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
CNT[31:16]
TIMx_CNT CNT[15:0]
0x24 (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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
Table 100. TIM2 to TIM5 register map and reset values (continued)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ARR[31:16]
TIMx_ARR ARR[15:0]
0x2C (TIM2 and TIM5 only, reserved on the other timers)
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0x30 Reserved
CCR1[31:16]
TIMx_CCR1 CCR1[15:0]
0x34 (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CCR2[31:16]
TIMx_CCR2 CCR2[15:0]
0x38 (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CCR3[31:16]
TIMx_CCR3 CCR3[15:0]
0x3C (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CCR4[31:16]
TIMx_CCR4 CCR4[15:0]
0x40 (TIM2 and TIM5 only, reserved on the other timers)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x44 Reserved
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
ITR1_
TIM2_OR
0x50 Reserved Reserved RMP Reserved
Reset value 0 0
IT4_
TIM5_OR
0x50 Reserved Reserved RMP Reserved
Reset value 0 0
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
ITR0 TGI
ITR1 ITR Slave
ITR2 TRC TRGI controller Reset, enable, up, count
ITR3 mode
TI1F_ED
TI1FP1
TI2FP2
U
Auto-reload register UI
Stop, Clear
U
CK_PSC PSC CK_CNT +/- CNT counter
prescaler
CC1I U CC1I
TI1FP1 OC1REF OC1
TI1 Input filter & TI1FP2 IC1 IC1PS Capture/Compare 1 register Output TIMx_CH1
TIMx_CH1 Prescaler
edge detector control
TRC
CC2I
U CC2I
TI2FP1
TI2 Input filter & IC2 Output OC2
TIMx_CH2 TI2FP2 Prescaler
IC2PS Capture/Compare 2 register OC2REF TIMx_CH2
edge detector control
TRC
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
Interrupt ai17190b
U Autoreload register UI
Stop, Clear
U
CK_PSC PSC CK_CNT CNT
+/-
prescaler counter
CC1I CC1I
TI1 TI1FP1 IC1 U
Input filter & IC1PS OC1REF output OC1
TIMx_CH1 Prescaler Capture/Compare 1 register TIMx_CH1
edge detector control
Notes:
event
ai17725c
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 182 and Figure 183 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 182. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
MS31076V2
Figure 183. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CEN
Timerclock = CK_CNT
F7 F8 F9 FA FB FC 00 01
Counter register
0 3
Prescaler control register
0 3
Prescaler buffer
0 0 1 2 3 0 1 2 3
Prescaler counter
MS31077V2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_PSC
Timerclock = CK_CNT
Counter register 1F 20 00
Counter overflow
Figure 188. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Figure 189. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CEN
Timerclock = CK_CNT
Counter register F0 F1 F2 F3 F4 F5 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload shadow
register F5 36
Internal clock
CEN=CNT_EN
UG
CNT_INIT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
MS31085V2
or TI2F or
TI1F or
ITRx
0xx
TI1_ED
100 TRGI External clock CK_PSC
TI1FP1 mode 1
TI2F_Rising 101
TI2 Edge 0 TI2FP2
Filter 110
detector 1
TI2F_Falling
CK_INT Internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
SMS[2:0]
TIMx_SMCR
MS37337V1
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 no 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
MS31087V3
TI1F_ED
To the slave mode controller
TI1 TI1F_Rising
Filter TI1F Edge 0 TI1FP1
fDTS downcounter TI1F_Falling 01
detector 1
TI2FP1 IC1 Divider IC1PS
10
/1, /2, /4, /8
ICF[3:0] CC1P/CC1NP TRC
11
TIMx_CCMR1 TIMx_CCER (from slave mode
TI2F_Rising controller)
0
(from channel 2)
CC1S[1:0] ICPS[1:0] CC1E
TI2F_Falling
1
(from channel 2) TIMx_CCMR1 TIMx_CCER
MS33115V1
The output stage generates an intermediate waveform which is then used for reference:
OCxRef (active high). The polarity acts at the end of the chain.
APB Bus
MCU-peripheral interface
(if 16-bit)
8 8
high
S write CCR1H
low
Read CCR1H S write_in_progress
read_in_progress write CCR1L
Read CCR1L Capture/compare preload register R
R Output CC1S[1]
capture_transfer compare_transfer mode
CC1S[0]
CC1S[1] Input
mode OC1PE
CC1S[0] Capture/compare shadow register OC1PE
UEV
(from time TIMx_CCMR1
Comparator
IC1PS Capture base unit)
CC1E CNT>CCR1
Counter CNT=CCR1
CC1G
TIMx_EGR
MS31089V3
To the master
mode controller
CC1P
TIMx_CCMR1
ai17720
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 the user writes 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 needed input filter duration with respect to the signal connected to the
timer (by programming the ICxF bits in the TIMx_CCMRx register if the input is one of
the TIx inputs). Let’s imagine that, when toggling, the input signal is not stable during at
must 5 internal clock cycles. We must program a filter duration longer than these 5
clock cycles. We can validate a transition on TI1 when 8 consecutive samples with the
new level have been detected (sampled at fDTS frequency). Then write IC1F bits to
‘0011’ in the TIMx_CCMR1 register.
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.
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.
The TIMx_CCRx register can be updated at any time by software to control the output
waveform, provided that the preload register is not enabled (OCxPE=’0’, else TIMx_CCRx
shadow register is updated only at the next update event UEV). An example is given in
Figure 197.
OC1REF= OC1
TIMx_CCRx is greater than the auto-reload value (in TIMx_ARR) then OCxREF is held at
‘1’. If the compare value is 0 then OCxRef is held at ‘0’. Figure 198 shows some edge-
aligned PWM waveforms in an example where TIMx_ARR=8.
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘1’
CCRx>8
CCxIF
OCXREF ‘0’
CCRx=0
CCxIF
MS31093V1
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY tPULSE t
MS31099V1
For example the user 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 us say the user wants 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 enable PWM mode 2 by writing OC1M=’111’ in the
TIMx_CCMR1 register. The user 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 the user has to write the compare value in the TIMx_CCR1 register, the auto-
reload value in the TIMx_ARR register, generate an update by setting the UG bit and
wait for external trigger event on TI2. CC1P is written to ‘0’ in this example.
The user only wants one pulse (Single mode), so 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.
TI1
UG
Counter register 30 31 32 33 34 35 36 00 01 02 03 00 01 02 03
TIF
MS31401V2
TI1
cnt_en
Counter register 30 31 32 33 34 35 36 37 38
TIF
Write TIF=0
MS31402V1
TI2
cnt_en
Counter register 34 35 36 37 38
TIF
MS31403V1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSM TS[2:0] SMS[2:0]
Reserved Res.
rw 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.
10
11
9
8
7
6
5
4
3
2
1
0
CKD
ARPE
UDIS
OPM
CEN
URS
TIMx_CR1
0x00 Reserved [1:0] Reserved
Reset value 0 0 0 0 0 0 0
Reserved
MSM
TIMx_SMCR TS[2:0] SMS[2:0]
0x08 Reserved
Reset value 0 0 0 0 0 0 0
CC2IE
CC1IE
UIE
TIMx_DIER
TIE
0x0C Reserved Reserved
Reset value 0 0 0 0
CC2OF
CC1OF
CC2IF
CC1IF
Reserved
TIMx_SR
UIF
TIF
0x10 Reserved Reserved
Reset value 0 0 0 0 0 0
CC2G
CC1G
TIMx_EGR
UG
TG
0x14 Reserved Reserved
Reset value 0 0 0 0
TIMx_CCMR1 OC2PE CC1
OC1PE
OC2FE
OC1FE
OC2M CC2S OC1M
Reserved
Output compare S
Reserved [2:0] [1:0] [2:0]
mode [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x18
TIMx_CCMR1 IC2 IC1 CC1
CC2S
Input capture IC2F[3:0] PSC IC1F[3:0] PSC S
Reserved [1:0]
mode [1:0] [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
CC2P
CC2E
CC1P
CC1E
Reserved
0x20
TIMx_CCER
Reserved 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
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
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
Refer to Section 2.3: Memory map for the register boundary addresses.
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.
10
11
9
8
7
6
5
4
3
2
1
0
CKD
ARPE
UDIS
OPM
CEN
URS
TIMx_CR1 Reserve
0x00 Reserved [1:0]
d
Reset value 0 0 0 0 0 0 0
TIMx_SMCR
0x08 Reserved
Reset value
CC1IE
UIE
TIMx_DIER
0x0C Reserved
Reset value 0 0
CC1OF
CC1IF
TIMx_SR
UIF
0x10 Reserved Reserved
Reset value 0 0 0
CC1G
TIMx_EGR
UG
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
CC1P
CC1E
Reserved
TIMx_CCER
0x20 Reserved
Reset value 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
0x38 to
Reserved
0x4C
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
TI1_RMP
TIMx_OR
0x50 Reserved
Reset value 0 0
Refer to Section 3.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
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 204 and Figure 205 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 204. Counter timing diagram with prescaler division change from 1 to 2
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter register F7 F8 F9 FA FB FC 00 01 02 03
Prescaler buffer 0 1
Prescaler counter 0 0 1 0 1 0 1 0 1
MS31076V3
Figure 205. Counter timing diagram with prescaler division change from 1 to 4
CK_PSC
CNT_EN
Timerclock = CK_CNT
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
MS31077V3
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter overflow
CK_INT
Timerclock = CK_CNT
Counter register 1F 20 00
Counter overflow
Figure 210. Counter timing diagram, update event when ARPE=0 (TIMx_ARR not
preloaded)
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
Auto-reload register FF 36
Figure 211. Counter timing diagram, update event when ARPE=1 (TIMx_ARR
preloaded)
CK_PSC
CNT_EN
Timerclock = CK_CNT
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
MS31085V2
Table 106. TIM6 and TIM7 register map and reset values
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
ARPE
Reserved
UDIS
OPM
CEN
URS
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
TIMx_SR
UIF
0x10 Reserved
Reset value 0
TIMx_EGR
UG
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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
different value will break the sequence and register access will be protected again. This
implies that it is the case of the reload operation (writing 0xAAAA).
A status register is available to indicate that an update of the prescaler or the down-counter
reload value is on going.
CORE
Prescaler register Status register Reload register Key register
IWDG_PR IWDG_SR IWDG_RLR IWDG_KR
MS19944V2
Note: The watchdog function is implemented in the VDD voltage domain, still functional in Stop and
Standby modes.
Table 107. Min/max IWDG timeout period (in ms) at 32 kHz (LSI)(1)
Prescaler divider PR[2:0] bits Min timeout RL[11:0]= 0x000 Max timeout RL[11:0]= 0xFFF
/4 0 0.125 512
/8 1 0.25 1024
/16 2 0.5 2048
/32 3 1 4096
/64 4 2 8192
/128 5 4 16384
/256 6 8 32768
1. These timings are given for a 32 kHz clock but the microcontroller internal RC frequency can vary. Refer to
the LSI oscillator characteristics table in the device datasheet for maximum and minimum values.
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)
10
11
9
8
7
6
5
4
3
2
1
0
IWDG_KR KEY[15:0]
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
IWDG_PR PR[2:0]
0x04 Reserved
Reset value 0 0 0
IWDG_RLR RL[11:0]
0x08 Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1
RVU
PVU
IWDG_SR
0x0C Reserved
Reset value 0 0
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
: : : : : : :
FRPSDUDWRU
ZKHQ
7!:
:ULWH::'*B&5
:DWFKGRJFRQWUROUHJLVWHU ::'*B&5
:'*$ 7 7 7 7 7 7 7
ELWGRZQFRXQWHU &17
3&/.
IURP5&&FORFNFRQWUROOHU
:'*SUHVFDOHU
:'*7%
06Y9
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.
In some applications, the EWI interrupt can be used to manage a software system check
and/or system recovery/graceful degradation, without generating a WWDG reset. In this
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.
W[6:0]
0x3F
T6 bit
RESET
ai17101c
where:
tWWDG: WWDG timeout
tPCLK1: APB1 clock period measured in ms
4096: value corresponding to internal divider
Refer to Table 109 for the minimum and maximum values of the tWWDG.
1 0 136.53 8.74
2 1 273.07 17.48
4 2 546.13 34.95
8 3 1092.27 69.91
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
EWI WDGTB[1:0] 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
10
11
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
Refer to Section 2.3: Memory map for the register boundary addresses.
128b 14 14 14
192b 16 16 16
256b 18 18 18
128b 14 14 14 24 10 14 14 12 14 25 14
• DES/TDES
– Direct implementation of simple DES algorithms (a single key, K1, is used)
– Supports the ECB and CBC chaining algorithms
– Supports 64-, 128- and 192-bit keys (including parity)
– 2 × 32-bit initialization vectors (IV) used in the CBC mode
– 16 HCLK cycles to process one 64-bit block in DES
– 48 HCLK cycles to process one 64-bit block in TDES
• Common to DES/TDES and AES
– IN and OUT FIFO (each with an 8-word depth, a 32-bit width, corresponding to 4
DES blocks or 2 AES blocks)
– Automatic data flow control with support of direct memory access (DMA) (using 2
channels, one for incoming data the other for processed data)
– Data swapping logic to support 1-, 8-, 16- or 32-bit data
Status
CRYP_SR CRYP_DIN CRYP_DOUT
DMA control register
CRYP_DMACR
Interrupt registers 8 × 32-bit 8 × 32-bit
CRYP_IMSCR IN FIFO OUT FIFO
CRYP_RIS
CRYP_MISR
Control register
swappi ng swappin g
CRYP_CR
Initialization vectors
IV0...IV127
CRYP_IV0...IV1
DES/TDES/AES
Key Processor core
k255...k0
CRYP_K0. ..K3
ai16068b
Status
CRYP_SR CRYP_DIN CRYP_DOUT
DMA control register
CRYP_DMACR
Interrupt registers 8 × 32-bit 8 × 32-bit
CRYP_IMSCR IN FIFO OUT FIFO
CRYP_RIS
CRYP_MISR
Control register
swappi ng swappin g
CRYP_CR
MS30441V1
IN FIFO
plaintext P
P, 64 bits
DATATYPE
swapping
64
K1 DEA, encrypt
64
K2 DEA, decrypt
64
K3 DEA, encrypt
O, 64 bits
DATATYPE
swapping
C, 64 bits
OUT FIFO
ciphertext C
ai16069b
IN FIFO
ciphertext C
C, 64 bits
DATATYPE
swapping
I, 64 bits
64
K3 DEA, decrypt
64
K2 DEA, encrypt
64
K1 DEA, decrypt
O, 64 bits
DATATYPE
swapping
P, 64 bits
OUT FIFO
plaintext P
MS19021V1
IN FIFO
plaintext P
P, 64 bits
DATATYPE
AHB2 data write swapping
(before CRYP
is enabled) 64 Ps, 64 bits
IV0(L/R) +
I, 64 bits
64
K1 DEA, encrypt
O is written back 64
into IV at the
same time as it K2 DEA, decrypt
is pushed into
the OUT FIFO 64
K3 DEA, encrypt
O, 64 bits
DATATYPE
swapping
C, 64 bits
OUT FIFO
ciphertext C
ai16070b
1. K: key; C: cipher text; I: input block; O: output block; Ps: plain text before swapping (when decoding) or
after swapping (when encoding); P: plain text; IV: initialization vectors.
IN FIFO
ciphertext C
C, 64 bits
DATATYPE
swapping
I, 64 bits
64
I is written back K3 DEA, decrypt
into IV at the
same time as P 64
is pushed into
the OUT FIFO K2 DEA, encrypt
64
K1 DEA, decrypt
MS19022V1
1. K: key; C: cipher text; I: input block; O: output block; Ps: plain text before swapping (when decoding) or
after swapping (when encoding); P: plain text; IV: initialization vectors.
IN FIFO
plaintext P
P, 128 bits
DATATYPE
swapping
I, 128 bits
128/192
or 256
K 0...3(1) AEA, encrypt
DATATYPE
swapping
C, 128 bits
OUT FIFO
ciphertext C
ai16071b
IN FIFO
ciphertext C
C, 128 bits
DATATYPE
swapping
I, 128 bits
128/192
or 256
K 0...3(1) AEA, decrypt
O, 128 bits
DATATYPE
swapping
P, 128 bits
OUT FIFO
plaintext P
MS19023V1
block of data.) The AES-CBC decryption process continues in this manner until the last
complete ciphertext block has been decrypted. Ciphertext representing a partial data
block must be decrypted in a manner specified for the application.
IN FIFO
plaintext P
P, 128 bits
DATATYPE
AHB2 data write swapping
(before CRYP
is enabled) Ps, 128 bits
128
IV=[IV1 IV0](2) +
I, 128 bits
128, 192
or 256
K 0...3(3) AEA, encrypt
O is written
back into IV
at the same time
as it is pushed
into the OUT FIFO
O, 128 bits
DATATYPE
swapping
C, 128 bits
OUT FIFO
ciphertext C
ai16072b
1. K: key; C: cipher text; I: input block; O: output block; Ps: plain text before swapping (when decoding) or
after swapping (when encoding); P: plain text; IV: Initialization vectors.
2. IVx=[IVxR IVxL], R=right, L=left.
3. If Key size = 128 => Key = [K3 K2].
If Key size = 192 => Key = [K3 K2 K1]
If Key size = 256 => Key = [K3 K2 K1 K0].
IN FIFO
ciphertext C
C, 128 bits
DATATYPE
swapping
I, 128 bits
128, 192
or 256
K 0...3(3) AEA, decrypt
I is written
back into IV
at the same time
as P is pushed
into the OUT FIFO
AHB2 data write
(before CRYP O, 128 bits
is enabled) 128
IV=[IV1 IV0](2) +
Ps, 128 bits
DATATYPE
swapping
P, 128 bits
OUT FIFO
plaintext P
MS19024V1
1. K: key; C: cipher text; I: input block; O: output block; Ps: plain text before swapping (when decoding) or
after swapping (when encoding); P: plain text; IV: Initialization vectors.
2. IVx=[IVxR IVxL], R=right, L=left.
3. If Key size = 128 => Key = [K3 K2].
If Key size = 192 => Key = [K3 K2 K1]
If Key size = 256 => Key = [K3 K2 K1 K0].
Figure 226 and Figure 227 illustrate AES-CTR encryption and decryption, respectively.
IN FIFO
plaintext P
P, 128 bits
DATATYPE
AHB2 data write swapping
(before CRYP
is enabled)
IV0...1(L/R)
Ps, 128 bits
+1 I, 128 bits
128, 192
or 256
K0...3 AEA, encrypt
OUT FIFO
ciphertext C
ai16073b
1. K: key; C: cipher text; I: input Block; o: output block; Ps: plain text before swapping (when decoding) or
after swapping (when encoding); Cs: cipher text after swapping (when decoding) or before swapping (when
encoding); P: plain text; IV: Initialization vectors.
IN FIFO
ciphertext P
C, 128 bits
DATATYPE
AHB2 data write swapping
(before CRYP
is enabled)
IV0...1(L/R)
Cs, 128 bits
+1 I, 128 bits
128, 192
or 256
K0...3 AEA, encrypt
OUT FIFO
plaintext C
MS19025V1
1. K: key; C: cipher text; I: input Block; o: output block; Ps: plain text before swapping (when decoding) or
after swapping (when encoding); Cs: cipher text after swapping (when decoding) or before swapping (when
encoding); P: plain text; IV: Initialization vectors.
Figure 228 shows the structure of the IV block as defined by the standard [2]. It is composed
of three distinct fields.
Figure 228. Initial counter block structure for the Counter mode
Nonce 32 bits
Counter 32 bits
ai16074
• Nonce is a 32-bit, single-use value. A new nonce should be assigned to each different
communication.
• The initialization vector (IV) is a 64-bit value and the standard specifies that the
encryptor must choose IV so as to ensure that a given value is used only once for a
given key
• The counter is a 32-bit big-endian integer that is incremented each time a block has
been encrypted. The initial value of the counter should be set to ‘1’.
The block increments the least significant 32 bits, while it leaves the other (most significant)
96 bits unchanged.
Note: The header part must precede the payload and the two parts cannot be mixed together.
In CCM mode, 4 steps are required to perform and encryption or decryption:
1. CCM init phase
In this first step, the B0 packet of the CCM message (1st packet) is programmed into
the CRYP_DIN register. During this phase, the CRYP_DOUT register does not contain
any output data.
The following sequence must be followed:
a) Make sure that the cryptographic processor is disabled by clearing the CRYPEN
bit in the CRYP_CR register.
b) Select the CCM chaining mode by programming the ALGOMODE bits to ‘01001’
in the CRYP_CR register.
c) Configure the GCM_CCMPH bits to ‘00’ in CRYP_CR to start the CCM Init phase.
d) Initialize the key registers (128,192 and 256 bits) in CRYP_KEYRx as well as the
initialization vector (IV).
e) Set the CRYPEN bit to ‘1’ in CRYP_CR.
f) Program the B0 packet into the input data register.
g) Wait for the CRYPEN bit to be cleared before moving on to the next phase.
h) Set CRYPEN to ‘1’.
2. CCM header phase
This step must be performed after the CCM Init phase. The sequence is identical for
encryption and decryption.
During this phase, the CRYP_DOUT register does not contain any output data.
This phase can be skipped if there is no additional authenticated data.
The following sequence must be followed:
i) Set the GCM_CCMPH bit to ’01’ in CRYP_CR to indicate that the header phase
has started.
j) Three methods can be used:
– Program the header data by blocks of 32 bits into the CRYP_DIN register, and use
the IFNF flag to determine if the input FIFO can receive data. The size of the
header must be a multiple of 128 bits (4 words).
– Program the header data into the CRYP_DIN register by blocks of 8 words, and
use the IFEM flag to determine if the input FIFO can receive data (IFEM=’1’). The
size of the header must be a multiple of 128 bits (4 words).
– Use the DMA.
Note: The first block B1 must be formatted with the header length. This task should be handled by
software.
k) Once all header data have been supplied, wait until the BUSY flag is cleared.
3. CCM payload phase (encryption/decryption)
This step must be performed after the CCM header phase. During this phase, the
encrypted/decrypted payload is stored in the CRYP_DOUT register.
The following sequence must be followed:
l) Configure GCM_CCMPH bits to ‘10’ in CRYP_CR.
m) Select the algorithm direction (encryption or decryption) by using the ALGODIR bit
in CRYP_CR.
n) Program the payload message into the CRYP_DIN register, and use the IFNF flag
to determine if the input FIFO can receive data. Alternatively, the data could be
programmed into the CRYP_DIN register by blocks of 8 words and the IFEM flag
used to determine if the input FIFO can receive data (IFEM=’1’). In parallel, the
OFNE/OFFU flag of the CRYP_DOUT register can be monitored to check if the
output FIFO is not empty.
o) Repeat the previous step until all payload blocks have been encrypted or
decrypted. Alternatively, DMA could be used.
4. CCM final phase
This step generates the authentication tag. During this phase, the authentication tag of
the message is generated and stored in the CRYP_DOUT register.
p) Configure GCM_CCMPH[1:0] bits to ‘11’ in CRYP_CR.
q) Load the A0 initialized counter, and program the 128-bit A0 value by writing 4
times 32 bits into the CRYP_DIN register.
r) Wait till the OFNE flag (FIFO output not empty) is set to ‘1’ in the CRYP_SR
register.
s) Read the CRYP_DOUT register 4 times: the output corresponds to the encrypted
authentication tag.
t) Disable the cryptographic processor (CRYPEN bit in CRYP_CR = ‘0’)
Note: The hardware does not perform the formatting of the original B0 and B1 packets and the tag
comparison between encryption and decryption. They have to be handled by software.
The cryptographic processor does not need to be disabled/enabled when moving from the
header phase to the tag phase.
AES cipher message authentication code (CMAC)
The CMAC algorithm allows authenticating the plaintext, and generating the corresponding
tag. The CMAC sequence is identical to the CCM one, except that the payload phase is
skipped.
The system memory organization is little-endian: whatever the data type (bit, byte, 16-bit
half-word, 32-bit word) used, the least-significant data occupy the lowest address locations.
A bit, byte, or half-word swapping operation (depending on the kind of data to be encrypted)
therefore has to be performed on the data read from the IN FIFO before they enter the
CRYP processor. The same swapping operation should be performed on the CRYP data
before they are written into the OUT FIFO. For example, the operation would be byte
swapping for an ASCII text stream.
The kind of data to be processed is configured with the DATATYPE bitfield in the CRYP
control register (CRYP_CR).
0xAB CD 77 20 69 73 FE 01 @+4
0x 01 FE 73 69
@+4
0x2E 04 CE 96
0000 0100 1110 1110 1111 0110 0111 0010 @
0100 1110 0110 1111 0111 0111 0010 0000
0110 1001 0111 0011 0010 0000 0111 0100
0010 1110 0000 0100 1100 1110 1001 0110 @+4
Figure 229 shows how the 64-bit data block M1...64 is constructed from two consecutive 32-
bit words popped off the IN FIFO by the CRYP processor, according to the DATATYPE
value. The same schematic can easily be extended to form the 128-bit block for the AES
cryptographic algorithm (for the AES, the block length is four 32-bit words, but swapping
only takes place at word level, so it is identical to the one described here for the TDES).
Note: The same swapping is performed between the IN FIFO and the CRYP data block, and
between the CRYP data block and the OUT FIFO.
bit 31 bit 30 bit 2 bit 1 bit 0 second word written into the CRYP_DIN register
IN FIFO bit 31 bit 30 bit 2 bit 1 bit 0 first word written into the CRYP_DIN register
bit string M1 M2 M30 M31 M32 M33 M34 M62 M63 M64
bit string Byte 0,0 Byte 0,1 Byte 0,2 Byte 0,3 Byte 1,0 Byte 1,1 Byte 1,2 Byte 1,3
M1...8 M9...16 M17...24 M25...32 M33...40 M41...48 M49...56 M57...64
bit string Half-word 0,0 Half-word 0,1 Half-word 1,0 Half-word 1,1
M1...16 M17...32 M33...48 M49...64
ai16075
bit 31 bit 30 bit 2 bit 1 bit 0 second word written into the CRYP_DIN register
bit 31 bit 30 bit 2 bit 1 bit 0 first word written into the CRYP_DIN register
bit string M1 M2 M30 M31 M32 M33 M34 M62 M63 M64
CRYP_IVL CRYP_IVR
31 30 2 1 0 31 30 2 1 0
IV1 IV2 IV30 IV31 IV32 IV33 IV34 IV62 IV63 IV64
DEA Encrypt, K1
DEA Decrypt, K2
DEA Encrypt, K3
CRYP_IVL CRYP_IVR
31 30 2 1 0 31 30 2 1 0
IV1 IV2 IV30 IV31 IV32 IV33 IV34 IV62 IV63 IV64 CRYP result is copied
back to the CRYP_IVL/R
registers after cyphering
OUT FIFO
First word from the OUT FIFO contains the left part of the cyphertext block (O1...32)
Second word from OUT FIFO contains the right part of cyphertext block (O33...64)
ai16076
the CBC, CTR mode, the initialization vectors CRYP_IVx(L/R)R (x = 0..3) are updated as
well.
A write operation to the key registers (CRYP_Kx(L/R)R, x = 0..3), the initialization registers
(CRYP_IVx(L/R)R, x = 0..3), or to bits [9:2] in the CRYP_CR register are ignored when the
cryptographic processor is busy (bit BUSY = 1b in the CRYP_SR register), and the registers
are not modified. It is thus not possible to modify the configuration of the cryptographic
processor while it is processing a block of data. It is however possible to clear the CRYPEN
bit while BUSY = 1, in which case the ongoing DES, TDES or AES processing is completed
and the two/four word results are written into the output FIFO, and then, only then, the
BUSY bit is cleared.
Note: When a block is being processed in the DES or TDES mode, if the output FIFO becomes full
and if the input FIFO contains at least one new block, then the new block is popped off the
input FIFO and the BUSY bit remains high until there is enough space to store this new
block into the output FIFO.
Processing when the DMA is used to transfer the data from/to the memory
1. Configure the DMA controller to transfer the input data from the memory. The transfer
length is the length of the message. As message padding is not managed by the
peripheral, the message length must be an entire number of blocks. The data are
transferred in burst mode. The burst length is 4 words in the AES and 2 or 4 words in
Processing when the data are transferred by the CPU during interrupts
1. Enable the interrupts by setting the INIM and OUTIM bits in the CRYP_IMSCR register.
2. Enable the cryptographic processor by setting the CRYPEN bit in the CRYP_CR
register.
3. In the interrupt managing the input data: load the input message into the IN FIFO. You
can load 2 or 4 words at a time, or load data until the FIFO is full. When the last word of
the message has been entered into the FIFO, disable the interrupt by clearing the INIM
bit.
4. In the interrupt managing the output data: read the output message from the OUT
FIFO. You can read 1 block (2 or 4 words) at a time or read data until the FIFO is
empty. When the last word has been read, INIM=0, BUSY=0 and both FIFOs are empty
(IFEM=1 and OFNE=0). You can disable the interrupt by clearing the OUTIM bit and,
the peripheral by clearing the CRYPEN bit.
the IN FIFO that have not been processed and save them in the memory until the
FIFO is empty.
Note: In GCM/GMAC or CCM/CMAC mode, bits [17:16] of the CRYP_CR register should also be
saved.
2. Configure and execute the other processing.
3. Context restoration
a) Configure the processor as in Section 23.3.6: Procedure to perform an encryption
or a decryption on page 744, Initialization with the saved configuration. For the
AES-ECB or AES-CBC decryption, the key must be prepared again.
b) Write the data that were saved during context saving into the IN FIFO.
c) If needed, reconfigure the DMA controller to transfer the rest of the message.
d) Enable the processor by setting the CRYPEN bit and, the DMA requests by setting
the DIEN and DOEN bits.
OUTRIS OUTMIS
OUT FIFO Interrupt - OUTMIS
OUTIM ai16077
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
CRYPEN FFLUSH KEYSIZE DATATYPE ALGOMODE[2:0] ALGODIR Res. Res.
Reserved
rw w rw rw rw rw rw rw rw rw
Note: Writing to the KEYSIZE, DATATYPE, ALGOMODE and ALGODIR bits while BUSY=1 has
no effect. These bits can only be configured when BUSY=0.
The FFLUSH bit has to be set only when BUSY=0. If not, the FIFO is flushed, but the block
being processed may be pushed into the output FIFO just after the flush operation, resulting
in a nonempty FIFO condition.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ALGO
MODE GCM_CCMPH
Reserved [3] Res.
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRYPEN FFLUSH KEYSIZE DATATYPE ALGOMODE[2:0] ALGODIR
Reserved Reserved
rw w rw rw rw rw rw rw rw rw
Note: Writing to the KEYSIZE, DATATYPE, ALGOMODE and ALGODIR bits while BUSY=1 has
no effect. These bits can only be configured when BUSY=0.
The FFLUSH bit has to be set only when BUSY=0. If not, the FIFO is flushed, but the block
being processed may be pushed into the output FIFO just after the flush operation, resulting
in a nonempty FIFO condition.
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
BUSY OFFU OFNE IFNF IFEM
Reserved
r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATAIN
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
DATAIN
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
DATAOUT
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
DATAOUT
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
DOEN DIEN
Reserved
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
OUTIM INIM
Reserved
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
OUTRIS INRIS
Reserved
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
OUTMIS INMIS
Reserved
r r
Note: Write accesses to these registers are disregarded when the cryptographic processor is busy
(bit BUSY = 1 in the CRYP_SR register).
Table 114. CRYP register map and reset values for STM32F415/417xx
Register
Offset name and
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
reset value
ALOMODE[2:0]
DATATYPE
ALGODIR
KEYSIZE
CRYPEN
FFLUSH
0x00 CRYP_CR
Res.
Reserved Reserved
0x00
Reset value 0 0 0 0 0 0 0 0 0 0
OFNE
OFFU
BUSY
IFEM
IFNF
CRYP_SR
0x04 Reserved
Reset value 0 0 0 1 1
CRYP_DIN DATAIN
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
CRYP_DOUT DATAOUT
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
DOEN
CRYP_DMAC
DIEN
0x10 R Reserved
Reset value 0 0
OUTIM
CRYP_IMSC
INIM
0x14 R Reserved
Reset value 0 0
OUTRIS
INRIS
CRYP_RISR
0x18 Reserved
Reset value 0 1
OUTMIS
CRYP_MISR IN%IS
0x1C Reserved
Reset value 0 0
CRYP_K0LR CRYP_K0LR
0x20
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
CRYP_K0RR CRYP_K0RR
0x24
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
...
CRYP_K3LR CRYP_K3LR
0x38
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
CRYP_K3RR CRYP_K3RR
0x3C
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
CRYP_IV0LR CRYP_IV0LR
0x40
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 114. CRYP register map and reset values for STM32F415/417xx (continued)
Register
Offset name and
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
reset value
CRYP_IV0RR CRYP_IV0RR
0x44
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
CRYP_IV1LR CRYP_IV1LR
0x48
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
CRYP_IV1RR CRYP_IV1RR
0x4C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 115. CRYP register map and reset values for STM32F43xxx
Register
Offset name
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
reset value
ALOMODE[2:0]
ALGOMODE[3]
GCM_CCMPH
DATATYPE
ALGODIR
KEYSIZE
CRYPEN
FFLUSH
0x00 CRYP_CR
Res..
Res.
Reserved Reserved
0x00
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
OFNE
BUSY
OFFU
IFEM
IFNF
CRYP_SR
0x04 Reserved
Reset value 0 0 0 1 1
CRYP_DIN DATAIN
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
CRYP_DOUT DATAOUT
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 DOEN
CRYP_DMAC DIEN
0x10 R Reserved
Reset value 0 0
OUTIM
CRYP_IMSC
INIM
0x14 R Reserved
Reset value 0 0
OUTRIS
INRIS
CRYP_RISR
0x18 Reserved
Reset value 0 1
Table 115. CRYP register map and reset values for STM32F43xxx (continued)
Register
Offset name
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
reset value
OUTMIS
IN%IS
CRYP_MISR
0x1C Reserved
Reset value 0 0
CRYP_K0LR CRYP_K0LR
0x20
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
CRYP_K0RR CRYP_K0RR
0x24
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
...
...
CRYP_K3LR CRYP_K3LR
0x38
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
CRYP_K3RR CRYP_K3RR
0x3C
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
CRYP_IV0LR CRYP_IV0LR
0x40
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
CRYP_IV0RR CRYP_IV0RR
0x44
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
CRYP_IV1LR CRYP_IV1LR
0x48
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
CRYP_IV1RR CRYP_IV1RR
0x4C
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
CRYP_
CSGCMCCM CRYP_CSGCMCCM0R
0x50 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
CRYP_
CSGCMCCM CRYP_CSGCMCCM1R
0x54 1R
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
CRYP_
CSGCMCCM CRYP_CSGCMCCM2R
0x58 2R
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
CRYP_
CSGCMCCM CRYP_CSGCMCCM3R
0x5C 3R
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 115. CRYP register map and reset values for STM32F43xxx (continued)
Register
Offset name
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
reset value
CRYP_
CSGCMCCM CRYP_CSGCMCCM4R
0x60 4R
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
CRYP_
CSGCMCCM CRYP_CSGCMCCM5R
0x64 5R
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
CRYP_
CSGCMCCM CRYP_CSGCMCCM6R
0x68 6R
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
CRYP_
CSGCMCCM CRYP_CSGCMCCM7R
0x6C 7R
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
CRYP_CSGC
CRYP_CSGCM0R
0x70 M0R
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
CRYP_CSGC
CRYP_CSGCM1R
0x74 M1R
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
CRYP_CSGC
CRYP_CSGCM2R
0x78 M2R
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
CRYP_CSGC
CRYP_CSGCM3R
0x7C M3R
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
CRYP_CSGC
CRYP_CSGCM4R
0x80 M4R
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
CRYP_CSGC
CRYP_CSGCM5R
0x84 M5R
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
CRYP_CSGC
CRYP_CSGCM6R
0x88 M6R
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
CRYP_CSGC
CRYP_CSGCM7R
0x8C M7R
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
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
data register
Control register RNG_DR
RNG _CR
RNG_CLK LFSR
Analog seed
ai16080
1. For more details about RNG Clock (RNG_CLK) source, please refer to Section 6: Reset and clock control
for STM32F42xxx and STM32F43xxx (RCC) and Section 7: Reset and clock control for
STM32F405xx/07xx and STM32F415xx/17xx(RCC).
The random number generator implements an analog circuit. This circuit generates seeds
that feed a linear feedback shift register (RNG_LFSR) in order to produce 32-bit random
numbers.
The analog circuit is made of several ring oscillators whose outputs are XORed to generate
the seeds. The RNG_LFSR is clocked by a dedicated clock (RNG_CLK) at a constant
frequency, so that the quality of the random number is independent of the HCLK frequency.
The contents of the RNG_LFSR are transferred into the data register (RNG_DR) when a
significant number of seeds have been introduced into the RNG_LFSR.
In parallel, the analog seed and the dedicated RNG_CLK clock are monitored. Status bits (in
the RNG_SR register) indicate when an abnormal sequence occurs on the seed or when
the frequency of the RNG_CLK clock is too low. An interrupt can be generated when an
error is detected.
24.3.1 Operation
To run the RNG, follow the steps below:
1. Enable the interrupt if needed (to do so, set the IE bit in the RNG_CR register). An
interrupt is generated when a random number is ready or when an error occurs.
2. Enable the random number generation by setting the RNGEN bit in the RNG_CR
register. This activates the analog part, the RNG_LFSR and the error detector.
3. At each interrupt, check that no error occurred (the SEIS and CEIS bits should be ‘0’ in
the RNG_SR register) and that a random number is ready (the DRDY bit is ‘1’ in the
RNG_SR register). The contents of the RNG_DR register can then be read.
As required by the FIPS PUB (Federal Information Processing Standard Publication) 140-2,
the first random number generated after setting the RNGEN bit should not be used, but
saved for comparison with the next generated random number. Each subsequent generated
random number has to be compared with the previously generated number. The test fails if
any two compared numbers are equal (continuous random number generator test).
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
IE RNGEN
Reserved Reserved
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
SEIS CEIS SECS CECS DRDY
Reserved Reserved
rc_w0 rc_w0 r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RNDATA
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
RNDATA
r r r r r r r r r r r r r r r r
10
11
reset value
9
8
7
6
5
4
3
2
1
0
Reserved
RNGEN
RNG_CR
0x00 Reserved
IE
0x0000000
Reserved
RNG_SR
DRDY
CECS
SECS
CEIS
SEIS
0x04 Reserved
0x0000000
RNG_DR
0x08 RNDATA[31:0]
0x0000000
IN buffer
Data
register
Control and status HASH_DIN
registers
write into HASH_DIN
or write DCAL bit to 1
Interrupt registers or 1 complete block
transferred by the DMA
HASH_IMR
HASH_SR 16 × 32-bit
IN FIFO
Control register
HASH_CR
Start register
HASH_ST R swa ppin g
IN FIFO full
or DCAL written to 1
Context swapping
context
HASH_CSR0..50 SHA -1 / MD5
Hash / HMAC
Message digest
digest processor core
HASH_H0...H4
ai16081
IN buffer
Data
register
Control and status HASH_DIN
registers
write into HASH_DIN
or write DCAL bit to 1
Interrupt registers or 1 complete block
transferred by the DMA
HASH_IMR
HASH_SR 16 × 32-bit
IN FIFO
Control register
HASH_CR
Start register
HASH_ST R swa ppin g
IN FIFO full
or DCAL written to 1
Context swapping
context
HASH_CSR0..53
SHA-1, SHA-224, SHA-256 and MD5
Message digest Hash / HMAC processor core
digest
HASH_H0...H7
MS30442V1
The FIPS PUB 180-2 standard and the IETF RFC 1321 publication specify the SHA-1, SHA-
224 and SHA-256 and MD5 secure hash algorithms, respectively, for computing a
condensed representation of a message or data file. When a message of any length below
264 bits is provided on input, the SHA-1, SHA-224 and SHA-256 and MD5 produce
respective a 160-bit, 224 bit, 256 bit and 128-bit output string, respectively, called a
message digest. The message digest can then be processed with a digital signature
algorithm in order to generate or verify the signature for the message. Signing the message
digest rather than the message often improves the efficiency of the process because the
message digest is usually much smaller in size than the message. The verifier of a digital
signature has to use the same hash algorithm as the one used by the creator of the digital
signature.
The SHA-1, SHA-224 and SHA-256 and MD5 are qualified as “secure” because it is
computationally infeasible to find a message that corresponds to a given message digest, or
to find two different messages that produce the same message digest. Any change to a
message in transit will, with very high probability, result in a different message digest, and
the signature will fail to verify. For more detail on the SHA-1 or SHA-224 and SHA-256
algorithm, please refer to the FIPS PUB 180-2 (Federal Information Processing Standards
Publication 180-2), 2002 august 1.
The current implementation of this standard works with little-endian input data convention.
For example, the C string “abc” must be represented in memory as the 24-bit hexadecimal
value 0x434241.
A message or data file to be processed by the hash processor should be considered a bit
string. The length of the message is the number of bits in the message (the empty message
has length 0). You can consider that 32 bits of this bit string forms a 32-bit word. Note that
the FIPS PUB 180-1 standard uses the convention that bit strings grow from left to right, and
bits can be grouped as bytes (8 bits) or words (32 bits) (but some implementations also use
half-words (16 bits), and implicitly, uses the big-endian byte (half-word) ordering. This
convention is mainly important for padding (see Section 1.3.4: Message padding on
page 12).
A-In case of binary data hash, all bits should be swapped as below
Bit swapping operation DATATYPE =bx 11
HASH_DIN bit 31 bit 30 bit 2 bit 1 bit 0 Bits entred with little-Endian format
padding is performed
on this side of the
bit string.
bit string organization in bit 0 bit 1 bit 29 bit 30 bit 31 “1” “0s”
Hash processor: Big-Endian bit-string grows
in this direction
as defined by
FIPSPUB 180-2 std.
B-In case of byte data hash, all bytes should be swapped as below
Byte swapping operation DATATYPE =bx 10
Half-word 1 Half-word 0
HASH_DIN half word entred with little-Endian format
bits 15...0 bits 15...0
ai16082b
The least significant bit of the message has to be at position 0 (right) in the first word
entered into the hash processor, the 32nd bit of the bit string has to be at position 0 in the
second word entered into the hash processor and so on.
Once this is done, writing into HASH_STR with bit DCAL = 1 starts the processing of the last
entered block of message by the hash processor. This processing consists in:
• Automatically performing the message padding operation: the purpose of this operation
is to make the total length of a padded message a multiple of 512. The HASH
sequentially processes blocks of 512 bits when computing the message digest
• Computing the final message digest
When the DMA is enabled, it provides the information to the hash processor when it is
transferring the last data word. Then the padding and digest computation are performed
automatically as if DCAL had been written to 1.
value 0x0000 0001. Then an all zero word (0x0000 0000) is added and the message
length in a two-word representation, to get a block of 16 x 32-bit words.
4. The HASH computing is performed, and the message digest is then available in the
HASH_Hx registers (x = 0...4) for the SHA-1 algorithm. For example:
H0 = 0xA9993E36
H1 = 0x4706816A
H2 = 0xBA3E2571
H3 = 0x7850C26C
H4 = 0x9CD0D89D
1. The block is initialized by writing the INIT bit to ‘1’ with the MODE bit at ‘1’ and the
ALGO bits set to the value corresponding to the desired algorithm. The LKEY bit must
also be set during this phase if the key being used is longer than 64 bytes (in this case,
the HMAC specifications specify that the hash of the key should be used in place of the
real key).
2. The key (to be used for the inner hash function) is then given to the core. This
operation follows the same mechanism as the one used to send the message in the
hash operation (that is, by writing into HASH_DIN and, finally, into HASH_STR).
3. Once the last word has been entered and computation has started, the hash processor
elaborates the key. It is then ready to accept the message text using the same
mechanism as the one used to send the message in the hash operation.
4. After the first hash round, the hash processor returns “ready” to indicate that it is ready
to receive the key to be used for the outer hash function (normally, this key is the same
as the one used for the inner hash function). When the last word of the key is entered
and computation starts, the HMAC result is made available in the
HASH_H0...HASH_H4 registers on STM32F415/417xx and on HASH_H0...HASH_H7
registers on STM32F43xxx.
Note: 1 The computation latency of the HMAC primitive depends on the lengths of the keys and
message. You could the HMAC as two nested underlying hash functions with the same key
length (long or short).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LKEY
Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DINNE NBW ALGO[0] MODE DATATYPE DMAE INIT
Reserved Reserved
r r r r r rw rw rw rw rw w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
ALGO[1] LKEY
Reserved
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MDMAT DINNE NBW ALGO[0] MODE DATATYPE DMAE INIT
Reserved Reserved
rw r r r r r rw rw rw rw rw w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATAIN
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
DATAIN
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
DCAL NBLW
Reserved Reserved
w rw rw rw rw rw
HASH_HR0
Address offset: 0x0C and 0x310
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
H0
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
H0
r r r r r r r r r r r r r r r r
HASH_HR1
Address offset: 0x10 and 0x314
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
H1
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
H1
r r r r r r r r r r r r r r r r
HASH_HR2
Address offset: 0x14 and 0x318
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
H2
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
H2
r r r r r r r r r r r r r r r r
HASH_HR3
Address offset: 0x18 and 0x31C
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
H3
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
H3
r r r r r r r r r r r r r r r r
HASH_HR4
Address offset: 0x1C and 0x320
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
H4
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
H4
r r r r r r r r r r r r r r r r
HASH_HR5
Address offset: 0x324
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
H5
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
H5
r r r r r r r r r r r r r r r r
HASH_HR6
Address offset: 0x328
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
H6
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
H6
r r r r r r r r r r r r r r r r
HASH_HR7
Address offset: 0x32C
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
H7
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
H7
r r r r r r r r r r r r r r r r
Note: When starting a digest computation for a new bit stream (by writing the INIT bit to 1), these
registers assume their reset values.
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
DCIE DINIE
Reserved
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
BUSY DMAS DCIS DINIS
Reserved
r r rc_w0 rc_w0
HASH_CSRx
Address offset: 0x0F8 to 0x1C0 on STM32F415/417xx
Address offset: 0x0F8 to 0x1CC on STM32F43xxx
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CSx
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
CSx
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
10
11
9
8
7
6
DATATYPE 5
4
3
2
1
0
ALGO[0]
DINNE
MODE
DMAE
Reserved
Reserved
LKEY
INIT
HASH_CR NBW
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
HASH_DIN DATAIN
0x04
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DCAL
Reserved
HASH_STR NBLW
0x08 Reserved
Reset value 0 0 0 0 0 0
HASH_HR0 H0
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
HASH_HR1 H1
0x10
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
HASH_HR2 H2
0x14
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
HASH_HR3 H3
0x18
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
HASH_HR4 H4
0x1C
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
DINIE
DCIE
HASH_IMR Reserved
0x20
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 DMAS
BUSY
DINIS
DCIS
HASH_SR
0x24 Reserved
Reset value 0 0 0 1
HASH_CSR0 CSR0
0xF8
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 1 0
...
...
HASH_CSR50 CSR50
0x1C0
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
Reserved
HASH_HR0 H0
0x310
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
HASH_HR1 H1
0x314
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 117. HASH register map and reset values on STM32F415/417xx (continued)
Register name Register size
Offset
reset value
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
HASH_HR2 H2
0x318
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
HASH_HR3 H3
0x31C
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
HASH_HR4 H4
0x320
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10
11
9
8
7
6
DATATYPE 5
4
3
2
1
0
ALGO[0]
DINNE
MODE
DMAE
LKEY
Reserved
Reserved
INIT
HASH_CR NBW
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
HASH_DIN DATAIN
0x04
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DCAL
Reserved
HASH_STR NBLW
0x08 Reserved
Reset value 0 0 0 0 0 0
HASH_HR0 H0
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
HASH_HR1 H1
0x10
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
HASH_HR2 H2
0x14
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
HASH_HR3 H3
0x18
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
HASH_HR4 H4
0x1C
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
DINIE
DCIE
HASH_IMR Reserved
0x20
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
DMAS
BUSY
DINIS
DCIS
HASH_SR
0x24 Reserved
Reset value 0 0 0 1
Table 118. HASH register map and reset values on STM32F43xxx (continued)
Register name Register size
Offset
reset value
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
HASH_CSR0 CSR0
0xF8
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 1 0
...
...
HASH_CSR53 CSR53
0x1CC
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
Reserved
HASH_HR0 H0
0x310
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
HASH_HR1 H1
0x314
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
HASH_HR2 H2
0x318
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
HASH_HR3 H3
0x31C
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
HASH_HR4 H4
0x320
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
HASH_HR5 H5
0x324
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
HASH_HR6 H6
0x328
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
HASH_HR7 H7
0x32C
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
This section applies to the whole STM32F4xx family, unless otherwise specified.
26.1 Introduction
The real-time clock (RTC) is an independent BCD timer/counter. The RTC provides a time-
of-day clock/calendar, two programmable alarm interrupts, and a periodic programmable
wakeup flag with interrupt capability. The RTC also includes an automatic wakeup unit to
manage low-power modes.
Two 32-bit registers contain the seconds, minutes, hours (12- or 24-hour format), day (day
of week), date (day of month), month, and year, expressed in binary coded decimal format
(BCD). The sub-seconds value is also available in binary format.
Compensations for 28-, 29- (leap year), 30-, and 31-day months are performed
automatically. Daylight saving time compensation can also be performed.
Additional 32-bit registers contain the programmable alarm subseconds, seconds, minutes,
hours, day, and date.
A digital calibration feature is available to compensate for any deviation in crystal oscillator
accuracy.
After backup domain reset, all RTC registers are protected against possible parasitic write
accesses.
As long as the supply voltage remains in the operating range, the RTC never stops,
regardless of the device status (Run mode, low-power mode or under reset).
ck_apre ck_spre
RTC_CALR RTC_PRER (default 256 Hz RTC_PRER (default 1 Hz)
Smooth Asynchronous Synchronous
calibration 7-bit prescaler 15-bit prescaler
(default = 128) (default = 256) Calendar
RTC_CALIB
Output RTC_OUT
RTC_ALARM control
RTC_WUTR
16-bit wakeup WUTF
auto reload timer
OSEL[1:0]
Alarm A
RTC_ALRMAR = ALRAF
RTC_ALRMASSR
Alarm B
= ALRBF
RTC_ALRMBR
RTC_ALRMBSSR
MS30216V6
1. On STM32F4xx devices, the RTC_AF1 and RTC_AF2 alternate functions are connected to PC13 and PI8,
respectively.
The ck_apre clock is used to clock the binary RTC_SSR subseconds downcounter. When it
reaches 0, RTC_SSR is reloaded with the content of PREDIV_S.
fck_spre is given by the following formula:
f RTCCLK
f CK_SPRE = ----------------------------------------------------------------------------------------------
( PREDIV_S + 1 ) × ( PREDIV_A + 1 )
The ck_spre clock can be used either to update the calendar or as timebase for the 16-bit
wakeup auto-reload timer. To obtain short timeout periods, the 16-bit wakeup auto-reload
timer can also run with the RTCCLK divided by the programmable 4-bit asynchronous
prescaler (see Section 26.3.4: Periodic auto-wakeup for details).
When the BYPSHAD control bit is set in the RTC_CR register (bypass shadow
registers)
Reading the calendar registers gives the values from the calendar counters directly, thus
eliminating the need to wait for the RSF bit to be set. This is especially useful after exiting
from low-power modes (STOP or Standby), since the shadow registers are not updated
during these modes.
When the BYPSHAD bit is set to 1, the results of the different registers might not be
coherent with each other if an RTCCLK edge occurs between two read accesses to the
registers. Additionally, the value of one of the registers may be incorrect if an RTCCLK edge
occurs during the read operation. The software must read all the registers twice, and then
compare the results to confirm that the data is coherent and correct. Alternatively, the
software can just compare the two results of the least-significant calendar register.
Note: While BYPSHAD=1, instructions which read the calendar registers require one extra APB
cycle to complete.
When the reference clock detection is enabled, PREDIV_A and PREDIV_S must be set to
their default values:
• PREDIV_A = 0x007F
• PREDIV_S = 0x00FF
Note: The reference clock detection is not available in Standby mode.
Caution: The reference clock detection feature cannot be used in conjunction with the coarse digital
calibration: RTC_CALIBR must be kept at 0x0000 0000 when REFCKON=1.
either shortened by 256 or lengthened by 128 RTCCLK cycles, given that each ck_apre
cycle represents 128 RTCCLK cycles (with PREDIV_A+1=128).
Therefore each calibration step has the effect of adding 512 or subtracting 256 oscillator
cycles for every 125829120 RTCCLK cycles (64min x 60 s/min x 32768 cycles/s). This is
equivalent to +4.069 ppm or -2.035 ppm per calibration step. As a result, the calibration
resolution is +10.5 or -5.27 seconds per month, and the total calibration ranges from +5.45
to -2.72 minutes per month.
In order to measure the clock deviation, a 512 Hz clock is output for calibration.Refer to
Section 26.3.14: Calibration clock output.
set to a value less than 3, CALP is ignored and the calibration operates as if CALP was
equal to 0.
To perform a calibration with PREDIV_A less than 3, the synchronous prescaler value
(PREDIV_S) should be reduced so that each second is accelerated by 8 RTCCLK clock
cycles, which is equivalent to adding 256 clock cycles every 32 seconds. As a result,
between 255 and 256 clock pulses (corresponding to a calibration range from 243.3 to
244.1 ppm) can effectively be added during each 32-second cycle using only the CALM bits.
With a nominal RTCCLK frequency of 32768 Hz, when PREDIV_A equals 1 (division factor
of 2), PREDIV_S should be set to 16379 rather than 16383 (4 less). The only other
interesting case is when PREDIV_A equals 0, PREDIV_S should be set to 32759 rather
than 32767 (8 less).
If PREDIV_S is reduced in this way, the formula given the effective frequency of the
calibrated input clock is as follows:
FCAL = FRTCCLK x [1 + (256 - CALM) / (220 + CALM - 256)]
In this case, CALM[7:0] equals 0x100 (the midpoint of the CALM range) is the correct
setting if RTCCLK is exactly 32768.00 Hz.
Re-calibration on-the-fly
The calibration register (RTC_CALR) can be updated on-the-fly while RTC_ISR/INITF=0, by
using the follow process:
VBAT when the VDD power is switched off. They are not reset by system reset or when the
device wakes up from Standby mode. They are reset by a backup domain reset
The backup registers are reset when a tamper detection event occurs (see Section 26.6.20:
RTC backup registers (RTC_BKPxR) and Tamper detection initialization on page 812.
The polarity of the output is determined by the POL control bit in RTC_CR so that the
opposite of the selected flag bit is output when POL is set to 1.
No effect
Sleep
RTC interrupts cause the device to exit the Sleep mode.
The RTC remains active when the RTC clock source is LSE or LSI. RTC alarm, RTC
Stop tamper event, RTC time stamp event, and RTC Wakeup cause the device to exit the Stop
mode.
The RTC remains active when the RTC clock source is LSE or LSI. RTC alarm, RTC
Standby tamper event, RTC time stamp event, and RTC Wakeup cause the device to exit the
Standby mode.
1. Configure and enable the EXTI Line 21 in interrupt mode and select the rising edge
sensitivity.
2. Configure and Enable the TAMP_STAMP IRQ channel in the NVIC.
3. Configure the RTC to detect the RTC timestamp event.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PM HT[1:0] HU[3:0]
Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
Res. Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register is write protected. The write access procedure is described in RTC register
write protection on page 803.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
YT[3:0] YU[3:0]
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
WDU[2:0] MT MU[3:0] DT[1:0] DU[3:0]
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register is write protected. The write access procedure is described in RTC register
write protection on page 803.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
COE OSEL[1:0] POL COSEL BKP SUB1H ADD1H
Reserved
rw rw rw rw rw rw w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BYPS
TSIE WUTIE ALRBIE ALRAIE TSE WUTE ALRBE ALRAE DCE FMT REFCKON TSEDGE WUCKSEL[2:0]
HAD
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: WUT = Wakeup unit counter value. WUT = (0x0000 to 0xFFFF) + 0x10000 added when
WUCKSEL[2:1 = 11].
Bits 7, 6 and 4 of this register can be written in initialization mode only (RTC_ISR/INITF = 1).
Bits 2 to 0 of this register can be written only when RTC_CR WUTE bit = 0 and RTC_ISR
WUTWF bit = 1.
It is recommended not to change the hour during the calendar hour increment as it could
mask the incrementation of the calendar hour.
ADD1H and SUB1H changes are effective in the next second.
To avoid spuriously setting of TSF, TSE must be reset when TSEDGE is changed.
This register is write protected. The write access procedure is described in RTC register
write protection on page 803.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RECAL
PF
Reserved
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP TAMP WUT ALRB ALRA
Res. TSOVF TSF WUTF ALRBF ALRAF INIT INITF RSF INITS SHPF
2F 1F WF WF WF
rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rw r rc_w0 r r r r r
Note: The ALRAF, ALRBF, WUTF and TSF bits are cleared 2 APB clock cycles after programming
them to 0.
This register is write protected (except for RTC_ISR[13:8] bits). The write access procedure
is described in RTC register write protection on page 803.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PREDIV_A[6:0]
Reserved
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PREDIV_S[14:0]
Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register must be written in initialization mode only. The initialization must be performed
in two separate write accesses. Refer to Calendar initialization and configuration on
page 804
This register is write protected. The write access procedure is described in RTC register
write protection on page 803.
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
WUT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register can be written only when WUTWF is set to 1 in RTC_ISR.
This register is write protected. The write access procedure is described in RTC register
write protection on page 803.
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
DCS DC[4:0]
Reserved Reserved
rw rw rw rw rw rw
Note: This register can be written in initialization mode only (RTC_ISR/INITF = ‘1’).
This register is write protected. The write access procedure is described in RTC register
write protection on page 803.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MSK4 WDSEL DT[1:0] DU[3:0] MSK3 PM HT[1:0] HU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSK2 MNT[2:0] MNU[3:0] MSK1 ST[2:0] SU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register can be written only when ALRAWF is set to 1 in RTC_ISR, or in initialization
mode.
This register is write protected. The write access procedure is described in RTC register
write protection on page 803.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MSK4 WDSEL DT[1:0] DU[3:0] MSK3 PM HT[1:0] HU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MSK2 MNT[2:0] MNU[3:0] MSK1 ST[2:0] SU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register can be written only when ALRBWF is set to 1 in RTC_ISR, or in initialization
mode.
This register is write protected. The write access procedure is described in RTC register
write protection on page 803.
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
KEY
Reserved
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
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
SS[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADD1S Reserved
w r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. SUBFS[14:0]
r w w w w w w w w w w w w w w w
Note: This register is write protected. The write access procedure is described in RTC register
write protection on page 803
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PM HT[1:0] HU[3:0]
Reserved
r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
Res. Res.
r r r r r r r r r r r r r r
Note: The content of this register is valid only when TSF is set to 1 in RTC_ISR. It is cleared when
TSF bit is reset.
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
WDU[1:0] MT MU[3:0] DT[1:0] DU[3:0]
Reserved
r r r r r r r r r r r r r r
Note: The content of this register is valid only when TSF is set to 1 in RTC_ISR. It is cleared when
TSF bit is reset.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
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
SS[15:0]
r r r r r r r r r r r r r r r r
Note: The content of this register is valid only when RTC_ISR/TSF is set. It is cleared when the
RTC_ISR/TSF bit is reset.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
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
CALP CALW8 CALW16 Reserved CALM[8:0]
rw rw rw r r r r rw rw rw rw rw rw rw rw rw
Note: This register is write protected. The write access procedure is described in RTC register
write protection on page 803
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ALARMOUT TSIN TAMP1
Reserved TYPE SEL INSEL
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP- TAMP- TAMPT TAMP2 TAMP2 TAMP1 TAMP1
TAMPFLT[1:0] TAMPFREQ[2:0] TAMPIE
PUDIS PRCH[1:0] S Reserved -TRG E TRG E
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 MASKSS[3:0] Reserved
r r r r rw rw rw rw r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved SS[14:0]
r rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
Note: This register can be written only when ALRAE is reset in RTC_CR register, or in initialization
mode.
This register is write protected. The write access procedure is described in RTC register
write protection on page 803
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved MASKSS[3:0] Reserved
r r r r rw rw rw rw r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved SS[14:0]
r rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
Note: This register can be written only when ALRBIE is reset in RTC_CR register, or in
initialization mode.
This register is write protected.The write access procedure is described in Section : RTC
register write protection
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BKP[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BKP[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
10
11
9
8
7
6
5
4
3
2
1
0
HT
Reserved
Reserved
RTC_TR HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
PM
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DT
Reserved
Reset value 0 0 1 0 0 0 0 1 0 0 0 0 0 1
REFCKON
BYPSHAD
TSEDGE
ALRBIE
ALRAIE
COSEL
ADD1H
SUB1H
ALRBE
ALRAE
WUTIE
WUTE
OSEL WCKSEL
TSIE
COE
DCE
FMT
POL
BKP
TSE
RTC_CR
0x08 Reserved [1: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
ALRBWF
ALRAWF
TAMP2F
TAMP1F
WUTWF
TSOVF
ALRBF
ALRAF
WUTF
SHPF
INITS
INITF
RSF
TSF
INIT
RTC_ISR
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
Reserved
RTC_WUTR WUT[15:0]
0x14 Reserved
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Reserved
DCS
RTC_CALIBR DC[4:0]
0x18 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
10
11
9
8
7
6
5
4
3
2
1
0
WDSEL
DT HT
MSK4
MSK3
MSK2
MSK1
RTC_ALRMAR DU[3:0] HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
PM
0x1C [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
WDSEL
DT HT
MSK4
MSK3
MSK2
MSK2
RTC_ALRMBR DU[3:0] HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
PM
0x20 [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_WPR KEY[7:0]
0x24 Reserved
Reset value 0 0 0 0 0 0 0 0
RTC_SSR SS[15:0]
0x28 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADD1S
RTC_SHIFTR SUBFS[14:0]
0x2C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MNT[2:0]
HT[1:0]
Reserved
Reserved
RTC_TSTR HU[3:0] MNU[3:0] ST[2:0] SU[3:0]
PM
0x30 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_TSSSR SS[15:0]
0x38 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CALW16
CALW8
CALP
Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ALARMOUTTYPE
TAMPPRCH[1:0]
TAMPFREQ[2:0]
TAMPFLT[1:0]
TAMP1INSEL
TAMP1ETRG
TAMPPUDIS
TAMP2TRG
TSINSEL
TAMPTS
TAMP2E
TAMP1E
TAMPIE
Reserved
RTC_TAFCR
0x40 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_
MASKSS[3:0] SS[14:0]
0x44 ALRMASSR Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_
MASKSS[3:0] SS[14:0]
0x48 ALRMBSSR Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_BKP0R BKP[31:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Refer to Section 2.3: Memory map for the register boundary addresses.
Caution: In Table 121, the reset value is the value after a backup domain reset. The majority of the
registers are not affected by a system reset. For more information, please refer to
Section 26.3.7: Resetting the RTC.
This section applies to the whole STM32F4xx family, unless otherwise specified.
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 238.
SDA
MSB ACK
SCL
1 2 8 9
Start Stop
condition condition
MS19854V1
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 239.
Data register
Noise Data
SDA Data shift register
filter control
Clock control
Register (CCR)
Control registers
(CR1&CR2)
Control
Status registers logic
(SR1&SR2)
SMBA
Data register
Noise Data
SDA Data shift register
filter control
Clock control
Register (CCR)
Control registers
(CR1&CR2)
Control
Status registers logic
(SR1&SR2)
SMBA
1. SMBA is an optional signal in SMBus mode. This signal is not applicable if SMBus is disabled.
Header or address not matched: the interface ignores it and waits for another Start
condition.
Header matched (10-bit mode only): the interface generates an acknowledge pulse if the
ACK bit is set and waits for the 8-bit slave address.
Address matched: the interface generates in sequence:
• An acknowledge pulse if the ACK bit is set
• The ADDR bit is set by hardware and an interrupt is generated if the ITEVFEN bit is
set.
• If ENDUAL=1, the software has to read the DUALF bit to check which slave address
has been acknowledged.
In 10-bit mode, after receiving the address sequence the slave is always in Receiver mode.
It will enter Transmitter mode on receiving a repeated Start condition followed by the header
sequence with matching address bits and the least significant bit set (11110xx1).
The TRA bit indicates whether the slave is in Receiver or Transmitter mode.
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 241 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
1. The EV1 and EV3_1 events stretch SCL low until the end of the corresponding software sequence.
2. The EV3 event stretches SCL low if the software sequence is not completed before the end of the next byte
transmission.
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 the
I2C_DR register, stretching SCL low (see Figure 242 Transfer sequencing).
ai18208
1. The EV1 event stretches SCL low until the end of the corresponding software sequence.
2. The EV2 event stretches SCL low if the software sequence is not completed before the end of the next byte
reception.
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.
Start condition
Setting the START bit causes the interface to generate a Start condition and to switch to
Master mode (MSL 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 243 and Figure 244 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 243 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 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 243 Transfer sequencing EV8_2). The interface automatically
goes back to slave mode (MSL 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.
ai18210
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 event stretches SCL low if the software sequence is not complete before the end of the next byte transmission.
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 244 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 DR register, stretching SCL low.
Closing the communication
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. In order to generate the Stop/Restart condition, software must set the STOP/START bit
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 is made during EV6
(before ADDR flag is cleared) and the STOP condition generation is made after EV6.
After the Stop condition generation, the interface goes automatically back to slave mode
(MSL bit cleared).
ai17540d
Note: For each frequency range, the constraint is given based on the worst case which is the
minimum frequency of the range. Greater DNF values can be used if the system can
support maximum hold time violation.
27.3.7 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 version. 2.0 (http://smbus.org/).
Bus protocols
The SMBus specification supports up to nine bus protocols. For more details of these
protocols and SMBus address types, refer to SMBus specification version. 2.0. These
protocols should be implemented by the user software.
For the details on 128-bit UDID and more information on ARP, refer to SMBus specification
version 2.0.
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 version 2.0.
The status flag Timeout or Tlow Error in I2C_SR1 shows the status of this feature.
be set before the ACK of the CRC reception in slave mode. It must be set when
the ACK is set low in master mode.
• A PECERR error flag/interrupt is also available in the I2C_SR1 register.
• If DMA and PEC calculation are both enabled:-
– In transmission: when the I2C interface receives an EOT signal from the DMA
controller, it automatically sends a PEC after the last byte.
– In reception: when the I2C interface receives an EOT_1 signal from the DMA
controller, it will automatically consider the next byte as a PEC and will check it. A
DMA request is generated after PEC reception.
• To allow intermediate PEC transfers, a control bit is available in the I2C_CR2 register
(LAST bit) to determine if it is really the last DMA transfer or not. If it is the last DMA
request for a master receiver, a NACK is automatically sent after the last received byte.
• PEC calculation is corrupted by an arbitration loss.
Note: SB, ADDR, ADD10, STOPF, BTF, RxNE and TxE are logically OR-ed on the same interrupt
channel.
BERR, ARLO, AF, OVR, PECERR, TIMEOUT and SMBALERT are logically OR-ed on the
same interrupt channel.
STOPF
it_event
BTF
TxE
ITBUFEN
RxNE
ITERREN
BERR
ARLO
it_error
AF
OVR
PECERR
TIMEOUT
SMBALERT
MS42082V1
Note: When the STOP, START or PEC bit is set, the software must not perform any write access
to I2C_CR1 before this bit is cleared by hardware. Otherwise there is a risk of setting a
second STOP, START or PEC request.
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ANOFF DNF[3:0]
Reserved
rw rw rw rw rw
10
11
9
8
7
6
5
4
3
2
1
0
NOSTRETCH
SMBTYPE
SWRST
SMBUS
ENPEC
ENARP
ALERT
START
ENGC
STOP
Reserved
Reserved
POS
ACK
PEC
I2C_CR1
PE
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
ADDR
BERR
ARLO
RxNE
Reserved
Reserved
OVR
BTF
TxE
I2C_SR1
SB
AF
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SMBDEFAUL
SMBHOST
GENCALL
DUALF
BUSY
Reserved
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
DUTY
Reserved
I2C_CCR CCR[11:0]
F/S
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
ANOFF
I2C_FLTR DNF[3:0]
0x24 Reserved
Reset value 0 0 0 0 0
Refer to Section 2.3: Memory map for the register boundary addresses table.
This section applies to the whole STM32F4xx family, unless otherwise specified.
Warning: Since some SPI1 and SPI3/I2S3 pins may be mapped onto
some pins used by the JTAG interface (SPI1_NSS onto JTDI,
SPI3_NSS/I2S3_WS onto JTDI and SPI3_SCK/I2S3_CK onto
JTDO), you may either:
– map SPI/I2S onto other pins
– disable the JTAG and use the SWD interface prior to
configuring the pins listed as SPI I/Os (when debugging the
application) or
– disable both JTAG/SWD interfaces (for standalone
applications).
For more information on the configuration of the JTAG/SWD
interface pins, please refer to Section 8.3.2: I/O pin
multiplexer and mapping.
Read
Rx buffer
SPI_CR2
MOSI
TXE RXNE ERR TXDM RXDM
0 0 SSOE
IE IE IE AEN AEN
Write
0
Communication control
1
SCK BR[2:0]
Baud rate generator
LSB
SPE BR2 BR1 BR0 MSTR CPOL CPHA
FIRST
SPI_CR1
Master control logic BIDI BIDI
CRCEN
CRC
DFF
RX
ONLY SSM SSI
MODE OE Next
NSS
MS51604V1
MOSI MOSI
CPHA =1
CPOL = 1
CPOL = 0
NSS
(to slave)
Capture strobe
CPHA =0
CPOL = 1
CPOL = 0
NSS
(to slave)
Capture strobe
ai17154d
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 248). For correct data transfer, the CPOL
and CPHA bits must be configured in the same way in the slave device and the master
device. This step is not required when the TI mode is selected through the FRF bit in
the SPI_CR2 register.
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. This step is not
required when TI mode is selected.
4. In Hardware mode (refer to Slave select (NSS) pin management), 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. This step
is not required when TI mode is selected.
5. Set the FRF bit in the SPI_CR2 register to select the TI mode protocol for serial
communications.
6. 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.
t baud_rate t baud_rate
---------------------------- + 4 × t pclk < t release < ---------------------------- + 6 × t pclk
2 2
Note: This feature is not available for Motorola SPI communications (FRF bit set to 0).
To detect TI frame errors in Slave transmitter only mode by using the Error interrupt (ERRIE
= 1), the SPI must be configured in 2-line unidirectional mode by setting BIDIMODE and
BIDIOE to 1 in the SPI_CR1 register. When BIDIMODE is set to 0, OVR is set to 1 because
the data register is never read and error interrupt are always generated, while when
BIDIMODE is set to 1, data are not received and OVR is never set.
NSS
input trigger sampling trigger sampling trigger sampling
edge edge edge edge edge edge
SCK
input t
Release
MISO
output 1 or 0 MSBOUT LSBOUT
ai18434
NSS
input
trigger sampling trigger sampling trigger sampling
SCK
input
FRAME 1 FRAME 2
ai18435
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 248). This step is not required when the
TI mode is selected.
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. This
step is not required when the TI mode is selected.
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. This step is not required when the TI mode is
selected.
6. Set the FRF bit in SPI_CR2 to select the TI protocol for serial communications.
7. 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.
NSS
output trigger sampling trigger sampling trigger sampling
edge edge edge edge edge edge
SCK
output
MISO
output 1 or 0 MSBOUT LSBOUT
ai18436
NSS
output
trigger sampling trigger sampling trigger sampling
SCK
output
MOSI
DONTCARE MSBOUT LSBOUT MSBOUT LSBOUT
output
FRAME 1 FRAME 2
ai18437
pin. The software must have written the data to be sent before the SPI master
device initiates the transfer.
• In unidirectional receive-only mode (BIDIMODE=0 and RXONLY=1)
– The sequence begins when the slave device receives the clock signal and the first
bit of the data on its MOSI pin. The 7 remaining bits are loaded into the shift
register.
– The transmitter is not activated and no data are shifted out serially to the MISO
pin.
• In bidirectional mode, when transmitting (BIDIMODE=1 and BIDIOE=1)
– The sequence begins when the slave device receives the clock signal and the first
bit in the Tx buffer is transmitted on the MISO pin.
– The data are then parallel loaded from the Tx buffer into the 8-bit shift register
during the first bit transmission and then shifted out serially to the MISO pin. The
software must have written the data to be sent before the SPI master device
initiates the transfer.
– No data are received.
• In bidirectional mode, when receiving (BIDIMODE=1 and BIDIOE=0)
– The sequence begins when the slave device receives the clock signal and the first
bit of the data on its MISO pin.
– The received data on the MISO pin are shifted in serially to the 8-bit shift register
and then parallel loaded into the SPI_DR register (Rx buffer).
– The transmitter is not activated and no data are shifted out serially to the MISO
pin.
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
ai17343
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 255. TXE/BSY behavior in Master transmit-only mode (BIDIMODE=0 and RXONLY=0)
in case of continuous transfers
Example in Master mode with CPOL=1, CPHA=1
SCK
Figure 256. TXE/BSY in Slave transmit-only mode (BIDIMODE=0 and RXONLY=0) in case of
continuous transfers
SCK
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
In slave mode, the continuity of the communication is decided by the SPI master device. In
any case, even if the communication is continuous, the BSY flag goes low between each
transfer for a minimum duration of one SPI clock cycle (see Figure 256).
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
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 devices 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
TXE flag cleared by DMA write clear by DMA write set by hardware
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)
clear
set by hardware
flag DMA TCIF by software
(DMA transfer complete)
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
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.
NSS
output
trigger sampling trigger sampling trigger sampling trigger sampling trigger sampling trigger sampling trigger sampling
SCK
output
MOSI
DONTCARE MSBIN LSBIN DONTCARE MSBIN LSBIN
input
TIFRFE
ai18438
Tx buffer
CH
BSY OVR MODF CRC UDR TxE RxNE FRE
ERR SIDE
16-bit
MOSI/ SD
MISO/
Shift register
I2S2ext_SD/
I2S3ext_SD(1) LSB first Communication
16-bit control
Rx buffer
NSS/WS
I2S
MOD I2SE
SPI LSB
SPE BR2 BR1 BR0 MSTR CPOL CPHA
baud rate generator First
CK
I2SMOD
MCK
MCKOEODD I2SDIV[7:0] I2SxCLK
MS19909V1
1. I2S2ext_SD and I2S3ext_SD are the extended SD pins that control the I2S full duplex mode.
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.
SPI/I2Sx SPIx_MOSI/I2Sx_SD(in/out)
I2Sx_SCK
I2S_ WS
I2Sx_ext I2Sx_extSD(in/out)
MS19910V1
1. Where x can be 2 or 3.
Figure 264. I2S Philips protocol waveforms (16/32-bit full accuracy, CPOL = 0)
CK
WS transmission reception
Channel left
Channel
right
MS19591V1
Data are latched on the falling edge of CK (for the transmitter) and are read on the rising
edge (for the receiver). The WS signal is also latched on the falling edge of CK.
Figure 265. I2S Philips standard waveforms (24-bit frame with CPOL = 0)
CK
WS Transmission Reception
MS19592V1
This mode needs two write or read operations to/from the SPI_DR.
• In transmission mode:
if 0x8EAA33 has to be sent (24-bit):
MS19593V1
• In reception mode:
if data 0x8EAA33 is received:
MS19594V1
Figure 268. I2S Philips standard (16-bit extended to 32-bit packet frame with
CPOL = 0)
CK
WS Transmission Reception
MS19599V1
When 16-bit data frame extended to 32-bit channel frame is selected during the I2S
configuration phase, only one access to 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 269 is required.
0x76A3
MS19595V1
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 270. MSB justified 16-bit or 32-bit full-accuracy length with CPOL = 0
CK
WS Transmission Reception
Channel left
Channel right
MS30100 V1
Data are latched on the falling edge of CK (for transmitter) and are read on the rising edge
(for the receiver).
CK
WS Transmission Reception
Channel right
MS30101V1
Figure 272. MSB justified 16-bit extended to 32-bit packet frame with CPOL = 0
CK
WS Transmission Reception
Channel right
MS30102V1
CK
WS
Transmission Reception
16- or 32-bit data
SD
MSB LSB MSB
Channel left
Channel right
MS30103V1
CK
WS Reception
Transmission
8-bit data 24-bit remaining
SD 0 forced
MSB LSB
MS30104V1
• In transmission mode:
If data 0x3478AE have to be transmitted, two write operations to the SPI_DR register
are required from software or by DMA. The operations are shown below.
0xXX34 0x78AE
• In reception mode:
If data 0x3478AE are received, two successive read operations from SPI_DR are
required on each RXNE event.
0xXX34 0x78AE
MS19597V1
Figure 277. LSB justified 16-bit extended to 32-bit packet frame with CPOL = 0
CK
Reception
WS
Transmission
16-bit data 16-bit remaining
SD 0 forced
MSB LSB
When 16-bit data frame extended to 32-bit channel frame is selected during the I2S
configuration phase, Only one access to 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 278 is required.
Figure 278. Example of LSB justified 16-bit extended to 32-bit packet frame
0x76A3
MS19598V1
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.
CK
WS
short frame
13-bits
WS
long frame
MS30106V1
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 280. PCM standard waveforms (16-bit extended to 32-bit packet frame)
CK
WS
short frame
Up to 13-bits
WS
long frame
16 bits
SD MSB LSB
MS30107V1
Note: For both modes (master and slave) and for both synchronizations (short and long), the
number of bits between two consecutive pieces of data (and so two synchronization signals)
needs to be specified (DATLEN and CHLEN bits in the SPI_I2SCFGR register) even in
slave mode.
32- or 64-bits
FS
sampling point sampling point
MS30108V1
When the master mode is configured, a specific action needs to be taken to properly
program the linear divider in order to communicate with the desired audio frequency.
MCK
MCKOE
I²SMOD
CHLEN
MCKOE ODD I²SDIV[7:0]
MS30109V1
1. Where x could be 2 or 3.
Figure 281 presents the communication clock architecture. To achieve high-quality audio
performance, the I2SxCLK clock source can be either the PLLI2S output (through R division
factor) or an external clock (mapped to I2S_CKIN pin).
The audio sampling frequency can be 192 kHz, 96 kHz, or 48 kHz. 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 127 provides example precision values for different clock configurations.
Note: Other configurations are possible that allow optimum clock precision.
Table 127. Audio frequency precision (for PLLM VCO = 1 MHz or 2 MHz)(1)
Master Target fS Data
PLLI2SN PLLI2SR I2SDIV I2SODD Real fS (Hz) Error
clock (Hz) format
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 28.4.4: 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 28.4.3: 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 28.4.5: I2S master mode), where the configuration
should set the master reception mode through the I2SCFG[1:0] bits.
Whatever the data or channel length, the audio data are received by 16-bit packets. This
means that each time the Rx buffer is full, the RXNE flag is set and an interrupt is generated
if the RXNEIE bit is set in 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 28.4.3: 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.
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 28.4.3: 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 28.4.6: 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 28.4.3: 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.
change. If the synchronization is lost, to recover from this state and resynchronize the
external master device with the I2S slave device, follow the steps below:
1. Disable the I2S
2. Re-enable it when the correct level is detected on the WS line (WS line is high in I2S
mode, or low for MSB- or LSB-justified or PCM modes).
Desynchronization between the master and slave device may be due to noisy environment
on the SCK communication clock or on the WS frame synchronization line. An error interrupt
can be generated if the ERRIE bit is set. The desynchronization flag (FRE) is cleared by
software when the status register is read.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DR[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
10
11
9
8
7
6
5
4
3
2
1
0
BIDIMODE
CRCNEXT
LSBFIRST
RXONLY
CRCEN
BIDIOE
MSTR
CPHA
CPOL
SSM
SPE
DFF
SPI_CR1 BR [2:0]
SSI
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RXDMAEN
TXDMAEN
RXNEIE
ERRIE
TXEIE
SSOE
Reserved
FRF
SPI_CR2
0x04 Reserved
Reset value 0 0 0 0 0 0 0
CRCERR
CHSIDE
MODF
RXNE
OVR
UDR
FRE
BSY
TXE
SPI_SR
0x08 Reserved
Reset value 0 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
DATLEN
I2SMOD
I2SCFG
I2SSTD
CKPOL
CHLEN
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
Refer to Section 2.3: Memory map for the register boundary addresses.
29.1 Introduction
The SAI interface (serial audio interface) offers a wide set of audio protocols due to its
flexibility and wide range of configurations. Many stereo or mono audio applications may be
targeted. I2S standards, LSB or MSB-justified, PCM/DSP, TDM, and AC’97 protocols may
be addressed for example.
To bring this level of flexibility and configurability, the SAI contains two audio sub-blocks that
are fully independent of each other. Each audio sub-block is connected to up to 4 pins (SD,
SCK, FS, MCLK). Some of these pins can be shared if the two sub-blocks are declared as
synchronous to leave some free to be used as general purpose I/Os. The MCLK pin can be
output, or not, depending on the application, the decoder requirement and whether the
audio block is configured as the master.
The SAI can work in master or slave configuration. The audio sub-blocks can be either
receiver or transmitter and can work synchronously or not (with respect to the other one).
APB
FS_A
SAI_CK_A Clock generator FSM
Configuration SCK_A
Audio block A SD_A
Audio block B
FIFO ctrl FS_B
SAI_CK_B Clock generator FIFO
SCK_B
Audio block B SD_B
FSM MCLK_B
Configuration
registers and
Status register 32-bit shift register
SAI_XCR1
APB interface
APB
MS30032V1
The SAI is mainly composed of two audio sub-blocks with their own clock generator. Each
audio block integrates a 32-bit shift register controlled by their own functional state machine.
Data are stored or read from the dedicated FIFO. FIFO may be accessed by the CPU, or by
DMA in order to leave the CPU free during the communication. Each audio block is
independent. They can be synchronous with each other.
An I/O line controller manages each dedicated pins for a given audio block in the SAI. If the
two blocks are synchronized, this controller reduces the number of I/Os used, freeing up an
FS pin, an SCK pin and eventually an MCLK pin, making them general purpose I/Os.
The functional state machine can be configured to address a wide range of audio protocols.
Some registers are present to set-up the desired protocols (audio frame waveform
generator).
The audio block can be a transmitter or receiver, in master or slave mode. The master mode
means the bit clock SCK and the frame synchronization signal are generated from the SAI,
whereas in slave mode, they come from another external or internal master. There is a
particular case for which the FS signal direction is not directly linked to the master or slave
mode definition. In AC’97 protocol, it will be an SAI output even if the SAI (link controller) is
set-up to consume the SCK clock (and so to be in Slave mode).
Fs
sck
MS30037V1
In AC’97 mode (bit PRTCFG[1:0] = 10 in the SAI_xCR1 register), the frame synchronization
shape is forced to be configured to target these protocols. The SAI_xFRCR register value is
ignored.
Each audio block is independent and so each requires a specific configuration.
described in Section 29.13), but there will be no interruption in the audio communication
flow.
Figure 285. FS role is start of frame + channel side identification (FSDEF = TRIS = 1)
Number of slots not aligned with the audio frame
Audio frame
Half of frame
FS
sck
Audio frame
sck
MS30039V1
Each slot can be defined as a valid slot, or not, by setting bit SLOTEN[15:0] in the
SAI_xSLOTR register. In an audio frame, during the transfer of a non-valid slot, 0 value will
be forced on the data line or the SD data line will be released to HI-z (refer to
Section 29.12.4) if the audio block is transmitter, or the received value from the end of this
slot will be ignored. Consequently, there will be no FIFO access and so no request to read
or write the FIFO linked to this inactive slot status.
The slot size is also configurable as shown in the Figure 287. The size of the slots is
selected by setting bit SLOTSZ[1:0] in the SAI_xSLOTR register. The size is applied
identically for each slot in an audio frame.
16-bit 16-bit
32-bit 32-bit
X: don’t care
MS30033V1
It is possible to choose the position of the first data bit to transfer within the slots, this offset
is configured by bit FBOFF[5:0] in the SAI_xSLOTR register. 0 values will be injected in
transmitter mode from the beginning of the slot until this offset position is reached. In
reception, the bit in the offset phase is ignored. This feature targets the LSB justified
protocol (if the offset is equal to the slot size minus the data size).
FBOFF FBOFF
32-bit 32-bit
X: don’t care
MS30034V1
It is mandatory to respect the following conditions in order to avoid bad SAI behavior:
FBOFF ≤ (SLOTSZ - DS),
DS ≤ SLOTSZ,
NBSLOT x SLOTSZ ≤ FRL (frame length),
The number of slots should be even when bit FSDEF in the SAI_xFRCR register is set.
In AC’97 (bit PRTCFG[1:0] = 10), the slot size is automatically set as defined in
Section 29.11.
NODIV
MCLK_x
MCKDIV[3:0]
0
FRL[7:0]
1 NODIV NODIV
SAI_CK_x 0
Master clock
divider Bit clock divider 0 SCK_x
0
1 1
MS30040V1
Note: If NoDiv is set to 1, the MCLK_x signal will be set at 0 level if this pin is configured as the
SAI pin in GPIO peripherals.
The clock source for the clock generator comes from the product clock controller. The
SAI_CK_x clock is equivalent to the master clock which may be divided for the external
decoders using bit MCKDIV[3:0]:
MCLK_x = SAI_CK_x / (MCKDIV[3:0] * 2), if MCKDIV[3:0] is not equal to 0000.
MCLK_x = SAI_CK_x, if MCKDIV[3:0] is equal to 0000.
MCLK_x signal is used only in TDM.
The division must be even in order to keep 50% on the Duty cycle on the MCLK output and
on the SCK_x clock. If bit MCKDIV[3:0] = 0000, division by one is applied to have MCLK_x
= SAI_CK_x.
In the SAI, the single ratio MCLK/FS = 256 is considered. Mostly, three frequency ranges
will be encountered as illustrated in the Table 130.
The master clock may be generated externally on an I/O pad for external decoders if the
corresponding audio block is declared as master with bit NODIV = 0 in the SAI_xCR1
register. In slave, the value set in this last bit is ignored since the clock generator is OFF,
and the MCLK_x I/O pin is released for use as a general purpose I/O.
The bit clock is derived from the master clock. The bit clock divider sets the divider factor
between the bit clock SCK_x and the master clock MCLK_x following the formula:
SCK_x = MCLK x (FRL[7:0] +1) / 256
where:
256 is the fixed ratio between MCLK and the audio frequency sampling.
FRL[7:0] is the number of bit clock - 1 in the audio frame, configured in the SAI_xFRCR
register.
It is mandatory in master mode that (FRL[7:0] +1) should be equal to a number with a power
of 2 (refer to Section 29.7) in order to have an even integer number of MCLK_x pulses by bit
clock. The 50% duty cycle is guaranteed on the bit clock SCK_x.
The SAI_CK_x clock can be also equal to the bit clock frequency. In this case, bit NODIV in
the SAI_xCR1 register should be set and the value inside the MCKDIV divider and the bit
clock divider will be ignored. In this case, the number of bits per frame is fully configurable
without the need to be equal to a power of two.
The bit clock strobing edge on SCK can be configured by bit CKSTR in the SAI_xCR1
register.
An interrupt is generated if FREQIE bit is enabled in the SAI_xIM register. This depends on:
• FIFO threshold setting (FLTH bits in SAI_CR2)
• Communication direction transmitter or receiver (see Section : Interrupt generation in
transmitter mode and Section : Interrupt generation in reception mode)
(FLTH[2:0] bits in SAI_xSR is higher or equal to 010b). This Interrupt (FREQ bit in
SAI_XSR register) is cleared by hardware when less than a quarter of the FIFO data
locations become available (FLTH[2:0] bits in SAI_xSR is less than 010b).
• When the FIFO threshold bits in SAI_XCR2 register are configured as FIFO half fully
(FTH[2:0] set to 010b value), an interrupt is generated (FREQ bit is set by hardware to 1
in SAI_XSR register) if at least half of the FIFO data locations are available (FLTH[2:0]
bits in SAI_xSR is higher or equal to 011b). This Interrupt (FREQ bit in SAI_XSR register)
is cleared by hardware when less than half of the FIFO data locations become available
(FLTH[2:0] bits in SAI_xSR is less than 011b).
• When the FIFO threshold bits in SAI_XCR2 register are configured as FIFO three quarter
full(FTH[2:0] set to 011b value), an interrupt is generated (FREQ bit is set by hardware to
1 in SAI_XSR register) if at least three quarters of the FIFO data locations are available
(FLTH[2:0] bits in SAI_xSR is higher or equal to 100b). This Interrupt (FREQ bit in
SAI_XSR register) is cleared by hardware when the FIFO has less than three quarters of
the FIFO data locations avalable(FLTH[2:0] bits in SAI_xSR is less than 100b).
• When the FIFO threshold bits in SAI_XCR2 register are configured as FIFO full(FTH[2:0]
set to 100b), an interrupt is generated (FREQ bit is set by hardware to 1 in SAI_XSR
register) if the FIFO is full (FLTH[2:0] bits in SAI_xSR is equal to 101b). This Interrupt
(FREQ bit in SAI_XSR register) is cleared by hardware when the FIFO is not full
(FLTH[2:0] bits in SAI_xSR is less than 101b).
Like interrupt generation, the SAI can use the DMA if DMAEN bit in the SAI_xCR1 register is
set. The FREQ bit assertion mechanism is the same as the interruption generation
mechanism described above for FREQIE.
Each FIFO is an 8-word FIFO. Each read or write operation from/to the FIFO targets one
word FIFO allocation whatever the access size. Each FIFO word contains one audio frame.
FIFO pointers are incremented by one word after each access to the SAI_xDR register.
Data should be right aligned when it is written in the SAI_xDR.
Data received will be right aligned in the SAI_xDR.
The FIFO pointers can be reinitialized when the SAI is disabled by setting bit FFLUSH in the
SAI_xCR2 register. If FFLUSH is set when the SAI is enabled the data present in the FIFO
will be lost automatically.
FS
1 2 3 4 5 6 7 8 9 10 11 12
CMD CMD PCM PCM LINE1 PCM PCM PCM PCM LINE2 HSET IO
SDI Tag ADDR DATA LFRONT RFRONT DAC CENTER LSURR RSURR LFE DAC DAC CTRL
STATUS STATUS PCM PCM LINE1 PCM RSR RSR RSR LINE2 IO
Tag HSET
SDO ADDR DATA LEFT RIGHT ADC MIC VD VD LVD ADC STATUS
MS192343V1
Note: In AC’97 protocol, bit 2 of the tag is reserved (always 0), so whatever the value written in the
SAI FIFO, bit 2 of the TAG is forced to 0 level.
For more details about TAG representation, please refer to the AC’97 protocol standard.
One SAI can be used to target an AC’97 point-to-point communication.
In receiver mode, the SAI acting as an AC’97 link controller will require no FIFO request and
so no data storage in the FIFO when the codec ready bit in the slot 0 is decoded low. If bit
CNRDYIE is enabled in the SAI_xIM register, flag CNRDY will be set in the SAI_xSR
register and an interrupt is generated. This flag is dedicated to the AC’97 protocol.
Transmitter
In transmitter mode, Mute mode can be selected at anytime. Mute mode is active for entire
audio frames. The bit MUTE in the SAI_xCR2 register requests Mute mode when it is set
during an on-going frame.
The mute mode bit is strobed only at the end of the frame. If set at this time, the mute mode
is active at the beginning of the new audio frame, for a complete frame, until the next end of
frame, it then strobes the bit to determine if the next frame will still be a mute frame.
If the number of slots set in bit NBSLOT[3:0] in the SAI_xSLOTR register is lower than or
equal to two, it is possible to specify if the value sent during the Mute mode is 0 or if it is the
last value of each slot. The selection is done via bit MUTEVAL in the SAI_xCR2 register.
If the number of slots set in bit NBSLOT[3:0] in the SAI_xSLOTR register is greater than
two, MUTEVAL bit in the SAI_xCR2 has no meaning as 0 values are sent on each bit on
each slot.
During Mute mode, the FIFO pointers are still incremented, meaning that data which was
present in the FIFO and for which the Mute mode is requested is discarded.
Receiver
In receiver mode, it is possible to detect a Mute mode sent from the external transmitter
when all the declared and valid slots of the audio frame receive 0 for a given consecutive
number of audio frames (bit MUTECNT[5:0] in the SAI_xCR2 register).
When the number of MUTE frames is detected, flag MUTEDET in the SAI_xSR register is
set and an interrupt can be generated if bit MUTEDETIE is set in the SAI_xCR2.
The mute frame counter is cleared when the audio block is disabled or when a valid slot
receives at least one data in an audio frame. The interrupt is generated just once, when the
counter reaches the specified value in bit MUTECNT[5:0]. Then the interrupt event is re-
armed when the counter is cleared.
with a distinct and different left and right data, bit MONO has no meaning. The conversion
from the output stereo file to the equivalent mono file is done by software.
Note: To enable Mono mode, NBSLOT and SLOTEN must equal two and MONO bit set to 1.
COMP[1]
1 expand SD
FIFO 32-bit shift register
0
SD
0
FIFO 32-bit shift register
compress 1
COMP[1]
MS19244V1
Audio frame
sck
Bit TRIS = 1 in the SAI_xCR1 and frame length > number of slots
Audio frame
sck
SD (output) .. Data m
MS192345V1
When the selected audio protocol uses the FS signal as a start of frame and a channel side
identification (bit FSDEF = 1 in the SAI_xFRCR register), the tristate mode is managed
according to Figure 293 (where bit TRIS in the SAI_xCR1 register = 1, and FSDEF=1, and
half frame length > number of slots/2, and NBSLOT=6).
sck
MS192346V1
If the TRIS bit in the SAI_xCR2 register is cleared, all the High impedance states on the SD
output line on Figure 292 and Figure 293 are replaced by a drive with a value of 0.
Overrun
When the audio block is configured as receiver, an overrun condition may appear if data is
received in an audio frame when the FIFO is full and is not able to store the received data.
In this case, the received data is lost, the flag OVRUDR in the SAI_xSR register is set and
an interrupt is generated if bit OVRUDRIE is set in the SAI_xIM register. The slot number
from which the overrun occurs, is stored internally. No more data will be stored into the FIFO
until it becomes free to store new data. When the FIFO has at least one data free, the SAI
audio block receiver will store new data (from new audio frame) from the slot number which
was stored internally when the overrun condition was detected, and this, to avoid data slot
de-alignment in the destination memory (refer to Figure 294).
The OVRUDR flag is cleared when bit COVRUDR is set in the SAI_xCLRFR register.
sck
FIFO full
Received data discarded Data stored again in FIFO
OVRUDR
COVRUDR = 1
MS192348V2
Underrun
An underrun may occur when the audio block in the SAI is a transmitter and the FIFO is
empty when data needs to be transmitted (the audio block configuration (Master or Slave) is
not relevant). If an underrun is detected, the software must resynchronize data and slot.
Proceed as follows:
1. Disable the SAI peripheral by resetting the SAIEN bit of the SAI_xCR1 register. Check
that the SAI has been disabled by reading back the SAIEN bit (SAIEN should be equal
to 0).
2. Flush the Tx FIFO through the FFLUS bit of the SAI_xCR2 register.
3. Re-assigned to the correct data to be transferred on the first active slot of the new
frame.
4. Re-enabling the SAI peripheral (SAIEN bit set to 1).
The underrun event sets the OVRUDR flag in the SAI_xSR register and an interrupt is
generated if the OVRUDRIE bit is set in the SAI_xIM register. To clear this flag, set the
COVRUDR bit in the SAI_xCLRFR register.
sck
Slot size = data size
data
SD (output) Slot 0 ON MUTE MUTE MUTE Slot 1 ON ... ON Slot 0 ON
FIFO empty
OVRUND
OVRUND=1
MS192347V2
The late frame synchronisation detection flag is set when the error is detected, SAI needs to
be resynchronized with the master (the four steps described above should be respected).
This detection and flag assertion can detect glitches on the SCK clock in a noisy
environment, detected by the state machine of the audio block. It could incorrectly shift the
SAI audio block state machine from one state in the current audio frame, thus corrupting the
frame.
There is no corruption if the external master is not managing the audio data frame transfer in
a continuous mode, which should not be the case for most application purposes. In this
case, flag LFSDET will be set.
Note: This flag is not asserted in AC’97 mode since the SAI audio block acts as a link controller
and generates the FS signal even when declared as slave.
Depend on:
- FIFO threshold setting
(FLTH bits in SAI_CR2)
Master or Slave FREQIE in
FREQ FREQ - Communication direction
Receiver or transmitter SAI_xIM register
transmitter or receiver
for more details please refer
to Internal FIFOs section
Master or Slave OVRUDRIE in COVRUDR = 1 in
OVRUDR ERROR
Receiver or transmitter SAI_xIM register SAI_xCLRFR register
Slave
AFSDETIE in CAFSDET = 1 in
AFSDET ERROR (Not used in AC’97
SAI_xIM register SAI_xCLRFR register
mode)
Slave
LFSDETIE in CLFSDET = 1 in
LFSDET ERROR (Not used in AC’97
SAI_xIM register SAI_xCLRFR register
mode)
Slave CNRDYIE in CCNRDY = 1 in
CNRDY ERROR
(Only in AC’97 mode) SAI_xIM register SAI_xCLRFR register
Below are the SAI configuration steps to follow when an interrupt occurs:
1. Disable SAI interrupt.
2. Configure SAI.
3. Configure SAI interrupt source.
4. Enable SAI.
If there is an audio block in the SAI synchronous with the other one, the one which is the
master must be disabled first.
Bit 12 MONO: Mono mode. This bit is set and cleared by software.
0: Stereo mode
1: Mono mode.
This bit has a meaning only when the number of slots is equal to 2.
When the Mono mode is selected, the data of the slot 0 data is duplicated on the slot 1 when the
audio block is a transmitter. In reception mode, the slot1 is discarded and only the data received
from the slot 0 will be stored.
Refer to Section 29.12.2 for more details.
Bits 11:10 SYNCEN[1:0]: Synchronization enable. This bit is set and cleared by software.
00: audio block is asynchronous.
01: audio block is synchronous with the other internal audio block. In this case audio block should be
configured in Slave mode
10: Reserved.
11: Not used
These bits have to be configured when the audio block is disabled.
Bit 9 CKSTR: Clock strobing edge. This bit is set and cleared by software.
0: data strobing edge is falling edge of SCK
1: data strobing edge is rising edge of SCK
This bit has to be configured when the audio block is disabled.
Bit 8 LSBFIRST: Least significant bit first. This bit is set and cleared by software.
0: data is transferred with the MSB of the data first
1: data is transferred with the LSB of the data first
This bit has to be configured when the audio block is disabled.
This bit has no meaning in AC’97 audio protocol since in AC’97 data is transferred with the MSB of
the data first.
Bits 7:5 DS[2:0]: Data size. These bits are set and cleared by software.
000: Not used
001: Not used
010: 8-bit
011: 10-bit
100: 16-bit
101: 20-bit
110: 24-bit
111: 32-bit
When the companding mode is selected (bit COMP[1:0]), these DS[1:0] are ignored since the data
size is fixed to 8-bit mode by the algorithm itself.
These bits must be configured when the audio block is disabled.
Note: When AC’97 mode is selected the data sizes that can be used are: 16-bit or 20-bit only, else
SAI behavior is not guaranteed.
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
MUTE
COMP[1:0] CPL MUTECNT[5:0] Mute TRIS FFLUS FTH
VAL
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Bit 6 MUTEVAL: Mute value. This bit is set and cleared by software.This bit has to be written before
enabling the audio block: SAIxEN.
0: Bit value 0 is sent during the MUTE mode.
1: Last values are sent during the MUTE mode.
This bit has a meaning only when the audio block is a transmitter and when the number of slots is
lower or equal to 2 and if the MUTE bit is set.
If more slots are declared, the bit value sent during the transmission in mute mode will be equal to 0,
whatever the value of this MUTEVAL bit.
if the number of slot is lower or equal to 2 and MUTEVAL = 1, the mute value transmitted for each
slot will be the ones sent during the previous frame.
Refer to Section 29.12.1 for more details.
Bit 4 TRIS: Tristate management on data line. This bit is set and cleared by software.
0: SD output line is still driven by the SAI when a slot is inactive.
1: SD output line is released (HI-Z) at the end of the last data bit of the last active slot if the next one
is inactive.
This bit has a meaning only if the audio block is configured to be a transmitter.
This bit should be configured when SAI is disabled.
Refer to Section 29.12.4 for more details.
Bit 3 FFLUSH: FIFO flush. This bit is set by software. It is always read low.
0: No FIFO flush.
1: FIFO flush.
Writing 1 to the bit triggers the FIFO Flush. All the internal FIFO pointers (read and write) are
cleared.
Data still present in the FIFO will be lost in such case (no more transmission or received data lost).
This bit should be configured when SAI is disabled.
Before flushing SAI, DMA stream/interruption must be disabled
Bits 2:0 FTH: FIFO threshold. This bit is set and cleared by software.
000: FIFO empty
001: ¼ FIFO
010: ½ FIFO
011: ¾ FIFO
100: FIFO full
101: Reserved
110: Reserved
111: Reserved
FSALL[6:0] FRL[7:0]
Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
SLOTEN[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
Bits 31:16 SLOTEN[15:0]: Slot enable. These bits are set and cleared by software.
Each bit of the SLOTEN bits identify a slot position from 0 to 15 (maximum 16 slots)
0: Inactive slot.
1: Active slot.
These bits must be set when the audio block is disabled.
They are ignored in AC’97 mode.
Bits 15:12 Reserved, always read as 0.
Bits 11:8 NBSLOT[3:0]: Number of slots in an audio frame. These bits are set and cleared by software.
The value set in these bits register represents the number of slots + 1 in the audio frame (including
the number of inactive slots). The maximum number of slots is 16.
The number of slots should be even if bit FSDEF in the SAI_AFRCR register is set.
If the size is greater than the data size, the remaining bits will be forced to 0 if bit TRIS in the
SAI_xCR1 register is clear, otherwise they will be forced to 0 if the next slot is active or the SD line
will be forced to HI-Z if the next slot is inactive and bit TRIS = 1.
These bits must be set when the audio block is disabled.
They are ignored in AC’97 omode.
Bits 7:6 SLOTSZ[1:0]: Slot size
This bits is set and cleared by software.
00: The slot size is equivalent to the data size (specified in DS[3:0] in the SAI_ACR1 register).
01: 16-bit
10: 32-bit
11: Reserved
The slot size must be greater or equal to the data size. If this condition is not respected, the behavior
of the SAI will be undetermined.
These bits must be set when the audio block is disabled.
They are ignored in AC’97 mode.
Bit 1 Reserved, always read as 0.
Bits 4:0 FBOFF[4:0]: First bit offset
These bits are set and cleared by software.
The value set in these bits represents the position of the first data transfer bit in the slot. It represents
an offset value. During this offset phase 0 value are sent on the data line for transmission mode. For
reception mode, the received bit are discarded during the offset phase.
These bits must be set when the audio block is disabled.
They are ignored in AC’97 mode.
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MUT
LFSDETI AFSDET CNRDY FREQI WCKC OVRU
EDET
Reserved E IE IE E FGIE DRIE
IE
rw rw rw rw rw rw rw
Bit 2 WCKCFGIE: Wrong clock configuration interrupt enable. This bit is set and cleared by software.
0: Interrupt is disabled
1: Interrupt is enabled
This bit is considered only if the audio block is configured as master (MODE[1] = 0 in the SAI_ACR1
register) and bit NODIV = 0 in the SAI_xCR1 register.
It generates an interrupt if the flag WCKCFG in the SAI_ASR register is set.
Note: This bit is used only in TDM mode and has no meaning for other modes.
Bit 1 MUTEDETIE: Mute detection interrupt enable. This bit is set and cleared by software.
0: Interrupt is disabled
1: Interrupt is enabled
When this bit is set, an interrupt will be generated if the MUTEDET bit in the SAI_ASR register is set.
This bit has a meaning only if the audio block is configured in receiver mode.
Bit 0 OVRUDRIE: Overrun/underrun interrupt enable. This bit is set and cleared by software.
0: Interrupt is disabled
1: Interrupt is enabled
When this bit is set, an interrupt will be generated if the OVRUDR bit in the SAI_ASR register is set.
FLTH
Reserved
r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MUTED
LFSDET AFSDET CNRDY FREQ WCKCFG OVRUDR
Reserved ET
r r r r r r r
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CAFSDE CMUTE COVRUD
CLFSDET CCNRDY CWCKCFG
Reserved T Reserved DET R
rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATA[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
DATA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Register
Offset and reset
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
value
MCJDIV[3:0]
LSBFIRST
DMAEN
Reserved.
SAIxEN
CKSTR
Reserved
NODIV
MONO
0x0004
OutDri
Res.
FFLUS
MUTE
COMP[
TRIS
FTH
CPL
FSOFF
Reserved
FSPOL
AFSDETIE Reserved
WCKCFG
LFSDET
FREQIE
Reserved
0x0014 SAI_xIM
or 0x0034
Reset value 0 0 0 0 0 0 0
MUTEDET
WCKCFG
OVRUDR
FLVL[2:0]
AFSDET
LFSDET
CNRDY
Reserved
Reserved
0x0018
FREQ
SAI_xSR
or
0x0038
Reset value 0 0 0 0 0 0 0 1 0 0
Register
Offset and reset
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
value
MUTEDET
CAFSDET
WCKCFG
OVRUDR
LFSDET
CNRDY
Reserved
0x001C SAI_xCLRFR
Res.
or 0x003C
Reset value 0 0 0 0 0 0
0x0020 SAI_xDR DATA[31:0]
or 0x0040 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
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
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 30.6: USART registers on page 1007 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:
• CTS: Clear To Send blocks the data transmission at the end of the current transfer
when high
• RTS: Request to send indicates that the USART is ready to receive a data (when low).
RX IrDA
SIR
SW_RX Receive Shift Register
ENDEC Transmit Shift Register
block
IRDA_OUT
IRDA_IN GTPR
GT PSC SCLK 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
RTS Hardware
flow
CTS controller
Wakeup Receiver
Transmit Receiver clock
control unit
control
CR1 SR
TXEIE TCIE RXNE
IE
IDLE TE RE RWU SBK CTS LBD TXE TC RXNE IDLE ORE NF FE PE
IE
USART
interrupt
control
CR1 USART_BRR
OVER8
TE Transmitter rate
Transmitter control
clock
/ [8 x (2 - OVER8)] /USARTDIV
SAMPLING
DIVIDER DIV_Mantissa DIV_Fraction
15 4 0
fPCLKx(x=1,2)
Receiver rate
RE control
Clock **
Start
Idle frame bit
Clock **
Start
Idle frame bit
30.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 an 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 296).
Every character is preceded by a start bit which is a logic level low for one bit period. The
character is terminated by a configurable number of stop bits.
The following stop bits are supported by USART: 0.5, 1, 1.5 and 2 stop bits.
Note: The TE bit should not be reset during transmission of data. Resetting the TE bit during the
transmission will corrupt the data on the TX pin as the baud rate counters will get frozen.
The current data being transmitted will be lost.
An idle frame will be sent after the TE bit is enabled.
a) 1 Stop Bit
Possible
Parity Next data frame
Data frame Bit Next
Start start
Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 bit
MSv42088V1
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 299: 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.
USART_DR F1 F2 F3
TC flag set
by hardware
Software
enables the Software waits until TXE=1 TC is not set TC is not set TC is not set
USART and writes F2 into DR because TXE=0 because TXE=0 because TXE=1
Software waits until TXE=1 Software waits until TXE=1 Software wait until TC=1
and writes F1 into DR and writes F1 into DR
MS48961V1
Break characters
Setting the SBK bit transmits a break character. The break frame length depends on the M
bit (see Figure 297).
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.
30.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 state
Idle Start bit
RX line
Ideal
sample 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
clock
Sampled values
Real
sample X X X X X X X X 9 10 11 12 13 14 15 16
clock
6/16
7/16 7/16
One-bit time
Conditions
to validate 1 1 1 0 X 0 X 0 X 0 0 0 0 X X X X X X
the start bit
Falling edge At least 2 bits At least 2 bits
detection out of 3 at 0 out of 3 at 0
ai15471b
Note: If the sequence is not complete, the start bit detection aborts and the receiver returns to the
idle state (no flag is set) where it waits for a falling edge.
The start bit is confirmed (RXNE flag set, 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 an 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).
Programming the ONEBIT bit in the USART_CR3 register selects the method used to
evaluate the logic level. There are two options:
• the majority vote of the three samples in the center of the received bit. In this case,
when the 3 samples used for the majority vote are not equal, the NF bit is set
• a single sample in the center of the received bit
Depending on the application:
– select the three samples’ majority vote method (ONEBIT=0) when operating in a
noisy environment and reject the data when a noise is detected (refer to
Figure 133) because this indicates that a glitch occurred during the sampling.
– select the single sample method (ONEBIT=1) when the line is noise-free to
increase the receiver’s tolerance to clock deviations (see Section 30.3.5: USART
receiver tolerance to clock deviation on page 988). In this case the NF bit will
never be set.
When noise is detected in a frame:
• The NF bit is set at the rising edge of the RXNE bit.
• The invalid data is transferred from the Shift register to the USART_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 NF bit is reset by a USART_SR register read operation followed by a USART_DR
register read operation.
Note: Oversampling by 8 is not available in the Smartcard, IrDA and LIN modes. In those modes,
the OVER8 bit is forced to ‘0 by hardware.
RX line
sampled values
Sample clock 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
6/16
7/16 7/16
One bit time
MSv31152V1
RX line
sampled values
Sample
clock (x8) 1 2 3 4 5 6 7 8
2/8
3/8 3/8
One bit time
MSv31153V1
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.
• When OVER8=0, the fractional part is coded on 4 bits and programmed by the
DIV_fraction[3:0] bits in the USART_BRR register
• When OVER8=1, the fractional part is coded on 3 bits and programmed by the
DIV_fraction[2:0] bits in the USART_BRR register, and bit DIV_fraction[3] must be kept
cleared.
Note: The baud counters are updated to the new value in the baud registers after a write operation
to USART_BRR. Hence the baud rate register value should not be changed during
communication.
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
Table 134. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 12 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8=0)
Table 135. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK =12 MHz,
oversampling by 8(1)
Oversampling by 8 (OVER8 = 1)
% Error =
Value (Calculated - Value
programmed Desired) programmed
S.No Desired Actual Actual % Error
in the baud B.rate / in the baud
rate register Desired rate register
B.rate
Table 136. Error calculation for programmed baud rates at fPCLK = 16 MHz or fPCLK = 24 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8 = 0)
Table 136. Error calculation for programmed baud rates at fPCLK = 16 MHz or fPCLK = 24 MHz,
oversampling by 16(1) (continued)
Oversampling by 16 (OVER8 = 0)
Table 137. Error calculation for programmed baud rates at fPCLK = 16 MHz or fPCLK = 24 MHz,
oversampling by 8(1)
Oversampling by 8 (OVER8=1)
Table 138. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8=0)
Value
% Error = Value
programme
(Calculated - programmed
S.No Desired Actual d in the Actual % Error
Desired)B.Rate in the baud
baud rate
/Desired B.Rate rate register
register
1. 2.4 KBps 2.400 KBps 208.3125 0.00% 2.400 KBps 416.6875 0.00%
2. 9.6 KBps 9.604 KBps 52.0625 0.04% 9.598 KBps 104.1875 0.02%
3. 19.2 KBps 19.185 KBps 26.0625 0.08% 19.208 KBps 52.0625 0.04%
4. 57.6 KBps 57.554 KBps 8.6875 0.08% 57.554 KBps 17.3750 0.08%
5. 115.2 KBps 115.942 KBps 4.3125 0.64% 115.108 KBps 8.6875 0.08%
228.571
6. 230.4 KBps 2.1875 0.79% 231.884 KBps 4.3125 0.64%
KBps
470.588
7. 460.8 KBps 1.0625 2.12% 457.143 KBps 2.1875 0.79%
KBps
8. 896 KBps NA NA NA 888.889 KBps 1.1250 0.79%
9. 921.6 KBps NA NA NA 941.176 KBps 1.0625 2.12%
10. 1.792 MBps NA NA NA NA NA NA
11. 1.8432 MBps NA NA NA NA NA NA
12. 3.584 MBps NA NA NA NA NA NA
13. 3.6864 MBps NA NA NA NA NA NA
14. 7.168 MBps NA NA NA NA NA NA
15. 7.3728 MBps NA NA NA NA NA NA
1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can
be fixed with these data.
Table 139. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 8(1)
Oversampling by 8 (OVER8=1)
1. 2.4 KBps 2.400 KBps 416.625 0.01% 2.400 KBps 833.375 0.00%
2. 9.6 KBps 9.604 KBps 104.125 0.04% 9.598 KBps 208.375 0.02%
3. 19.2 KBps 19.185 KBps 52.125 0.08% 19.208 KBps 104.125 0.04%
Table 139. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 8(1) (continued)
Oversampling by 8 (OVER8=1)
4. 57.6 KBps 57.557 KBps 17.375 0.08% 57.554 KBps 34.750 0.08%
5. 115.2 KBps 115.942 KBps 8.625 0.64% 115.108 KBps 17.375 0.08%
6. 230.4 KBps 228.571 KBps 4.375 0.79% 231.884 KBps 8.625 0.64%
7. 460.8 KBps 470.588 KBps 2.125 2.12% 457.143 KBps 4.375 0.79%
8. 896 KBps 888.889 KBps 1.125 0.79% 888.889 KBps 2.250 0.79%
9. 921.6 KBps 888.889 KBps 1.125 3.55% 941.176 KBps 2.125 2.12%
10. 1.792 MBps NA NA NA 1.7777 MBps 1.125 0.79%
11. 1.8432 MBps NA NA NA 1.7777 MBps 1.125 3.55%
12. 3.584 MBps NA NA NA NA NA NA
13. 3.6864 MBps NA NA NA NA NA NA
14. 7.168 MBps NA NA NA NA NA NA
15. 7.3728 MBps NA NA NA NA NA NA
1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can
be fixed with these data.
Table 140. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 16(1)(2)
Oversampling by 16 (OVER8=0)
1. 2.4 KBps 2.400 KBps 781.2500 0.00% 2.400 KBps 1562.5000 0.00%
2. 9.6 KBps 9.600 KBps 195.3125 0.00% 9.600 KBps 390.6250 0.00%
3. 19.2 KBps 19.194 KBps 97.6875 0.03% 19.200 KBps 195.3125 0.00%
4. 57.6 KBps 57.582KBps 32.5625 0.03% 57.582 KBps 65.1250 0.03%
5. 115.2 KBps 115.385 KBps 16.2500 0.16% 115.163 KBps 32.5625 0.03%
6. 230.4 KBps 230.769 KBps 8.1250 0.16% 230.769KBps 16.2500 0.16%
7. 460.8 KBps 461.538 KBps 4.0625 0.16% 461.538 KBps 8.1250 0.16%
8. 896 KBps 909.091 KBps 2.0625 1.46% 895.522 KBps 4.1875 0.05%
Table 140. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 16(1)(2) (continued)
Oversampling by 16 (OVER8=0)
9. 921.6 KBps 909.091 KBps 2.0625 1.36% 923.077 KBps 4.0625 0.16%
10. 1.792 MBps 1.1764 MBps 1.0625 1.52% 1.8182 MBps 2.0625 1.36%
1.8432
11. 1.8750 MBps 1.0000 1.73% 1.8182 MBps 2.0625 1.52%
MBps
12. 3.584 MBps NA NA NA 3.2594 MBps 1.0625 1.52%
3.6864
13. NA NA NA 3.7500 MBps 1.0000 1.73%
MBps
14. 7.168 MBps NA NA NA NA NA NA
7.3728
15. NA NA NA NA NA NA
MBps
1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can
be fixed with these data.
2. Only USART1 and USART6 are clocked with PCLK2. Other USARTs are clocked with PCLK1. Refer to the device
datasheets for the maximum values for PCLK1 and PCLK2.
Table 141. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 8(1) (2)
Oversampling by 8 (OVER8=1)
1. 2.4 KBps 2.400 KBps 1562.5000 0.00% 2.400 KBps 3125.0000 0.00%
2. 9.6 KBps 9.600 KBps 390.6250 0.00% 9.600 KBps 781.2500 0.00%
3. 19.2 KBps 19.194 KBps 195.3750 0.03% 19.200 KBps 390.6250 0.00%
4. 57.6 KBps 57.582 KBps 65.1250 0.16% 57.582 KBps 130.2500 0.03%
5. 115.2 KBps 115.385 KBps 32.5000 0.16% 115.163 KBps 65.1250 0.03%
6. 230.4 KBps 230.769 KBps 16.2500 0.16% 230.769 KBps 32.5000 0.16%
7. 460.8 KBps 461.538 KBps 8.1250 0.16% 461.538 KBps 16.2500 0.16%
8. 896 KBps 909.091 KBps 4.1250 1.46% 895.522 KBps 8.3750 0.05%
9. 921.6 KBps 909.091 KBps 4.1250 1.36% 923.077 KBps 8.1250 0.16%
10. 1.792 MBps 1.7647 MBps 2.1250 1.52% 1.8182 MBps 4.1250 1.46%
Table 141. Error calculation for programmed baud rates at fPCLK = 30 MHz or fPCLK = 60 MHz,
oversampling by 8(1) (2) (continued)
Oversampling by 8 (OVER8=1)
11. 1.8432 MBps 1.8750 MBps 2.0000 1.73% 1.8182 MBps 4.1250 1.36%
12. 3.584 MBps 3.7500 MBps 1.0000 4.63% 3.5294 MBps 2.1250 1.52%
13. 3.6864 MBps 3.7500 MBps 1.0000 1.73% 3.7500 MBps 2.0000 1.73%
14. 7.168 MBps NA NA NA 7.5000 MBps 1.0000 4.63%
15. 7.3728 MBps NA NA NA 7.5000 MBps 1.0000 1.73%
1. The lower the CPU clock the lower the accuracy for a particular baud rate. The upper limit of the achievable baud rate can
be fixed with these data.
2. Only USART1 and USART6 are clocked with PCLK2. Other USARTs are clocked with PCLK1. Refer to the device
datasheets for the maximum values for PCLK1 and PCLK2.
Table 142. Error calculation for programmed baud rates at fPCLK = 42 MHz or fPCLK = 84 Hz,
oversampling by 16(1)(2)
Oversampling by 16 (OVER8=0)
Table 142. Error calculation for programmed baud rates at fPCLK = 42 MHz or fPCLK = 84 Hz,
oversampling by 16(1)(2) (continued)
Oversampling by 16 (OVER8=0)
Table 143. Error calculation for programmed baud rates at fPCLK = 42 MHz or fPCLK = 84 MHz,
oversampling by 8(1)(2)
Oversampling by 8 (OVER8=1)
Table 143. Error calculation for programmed baud rates at fPCLK = 42 MHz or fPCLK = 84 MHz,
oversampling by 8(1)(2) (continued)
Oversampling by 8 (OVER8=1)
Note: The figures specified in Table 144 and Table 145 may slightly 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).
RXNE RXNE
MSv40881V1
RX IDLE Addr=0 Data 1 Data 2 IDLE Addr=1 Data 3 Data 4 Addr=2 Data 5
Non-matching address
MSv40882V1
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.
E.g.: 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.
E.g.: data=00110101; 4 bits set => parity bit will be 1 if odd parity is selected (PS bit in
USART_CR1 = 1).
LIN transmission
The same procedure explained in Section 30.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 on the USART interface. 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 305: Break detection in LIN mode (11-bit break length - LBDL bit is set) on page 993.
Examples of break frames are given on Figure 306: Break detection in LIN mode vs.
Framing error detection on page 994.
Figure 305. 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
Break frame
RX line
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 1
Case 2: break signal just long enough => break detected, LBD is set
Break frame
RX line
Delimiter is immediate
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 B10 Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 0
LBD
Case 3: break signal long enough => break detected, LBD is set
Break frame
RX line
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 wait delimiter Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 0
LBD
MSv40883V1
Figure 306. Break detection in LIN mode vs. Framing error detection
RXNE /FE
LBDF
RXNE /FE
LBDF
MSv31157V1
has been written). This means that it is not possible to receive a synchronous data without
transmitting data.
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.
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.
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
Synchronous device
USART
(e.g. slave SPI)
CK Clock
MSv31158V2
Data on TX
0 1 2 3 4 5 6 7
(from master)
Start LSB MSB Stop
Data on RX
0 1 2 3 4 5 6 7
(from slave)
LSB MSB
*
Capture strobe
*LBCL bit controls last data pulse
MSv31159V1
Idle or
Idle or next
preceding Start M=1 (9 data bits) Stop
transmission
transmission
Clock (CPOL=0,
CPHA=0 *
Clock (CPOL=0,
CPHA=1 *
Clock (CPOL=1, *
CPHA=0
Clock (CPOL=1, *
CPHA=1
Data on TX
0 1 2 3 4 5 6 7 8
(from master)
Start LSB MSB Stop
Data on RX
0 1 2 3 4 5 6 7 8
(from slave)
LSB MSB
Capture *
strobe
*LBCL bit controls last data pulse
MSv31160V1
CK
(capture strobe on CK rising
edge in this example)
tSETUP tHOLD
Note: The function of CK is different in Smartcard mode. Refer to the Smartcard mode chapter for
more details.
30.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 311 shows examples of what can be seen on the data line with and without parity
error.
WithParity error
Guard time
S 0 1 2 3 4 5 6 7 p
Start bit
Line pulled low by receiver
during stop in case of parity error
MSv31162V1
When connected to a Smartcard, the TX output of the USART drives a bidirectional line that
is also driven by the Smartcard. The TX pin must be configured as open-drain.
Smartcard is a single wire half duplex communication protocol.
• Transmission of data from the transmit shift register is guaranteed to be delayed by a
minimum of 1/2 baud clock. In normal operation a full transmit shift register will start
shifting on the next baud clock edge. In Smartcard mode this transmission is further
delayed by a guaranteed 1/2 baud clock.
• If a parity error is detected during reception of a frame programmed with a 0.5 or 1.5
stop bit period, the transmit line is pulled low for a baud clock period after the
completion of the receive frame. This is to indicate to the Smartcard that the data
transmitted to USART has not been correctly received. This NACK signal (pulling
transmit line low for 1 baud clock) will cause a framing error on the transmitter side
(configured with 1.5 stop bits). The application can handle re-sending of data according
to the protocol. A parity error is ‘NACK’ed by the receiver if the NACK control bit is set,
otherwise a NACK is not transmitted.
• The assertion of the TC flag can be delayed by programming the Guard Time register.
In normal operation, TC is asserted when the transmit shift register is empty and no
further transmit requests are outstanding. In Smartcard mode an empty transmit shift
register triggers the guard time counter to count up to the programmed value in the
Guard Time register. TC is forced low during this time. When the guard time counter
reaches the programmed value TC is asserted high.
• The de-assertion of TC flag is unaffected by Smartcard mode.
• If a framing error is detected on the transmitter end (due to a NACK from the receiver),
the NACK will not be detected as a start bit by the receive block of the transmitter.
According to the ISO protocol, the duration of the received NACK can be 1 or 2 baud
clock periods.
• On the receiver side, if a parity error is detected and a NACK is transmitted the receiver
will not detect the NACK as a start bit.
Note: A break character is not significant in Smartcard mode. A 0x00 data with a framing error will
be treated as data and not as a break.
No Idle frame is transmitted when toggling the TE bit. The Idle frame (as defined for the
other configurations) is not defined by the ISO protocol.
Figure 312 details how the NACK signal is sampled by the USART. In this example the
USART is transmitting a data and is configured with 1.5 stop bits. The receiver part of the
USART is enabled in order to check the integrity of the data and the NACK signal.
Figure 312. Parity error detection using the 1.5 stop bits
Sampling at Sampling at
8th, 9th, 10th 8th, 9th, 10th
Sampling at Sampling at
8th, 9th, 10th 8th, 9th, 10th
MSv31163V1
The USART can provide a clock to the smartcard through the CK output. In smartcard
mode, CK is not associated to the communication but is simply derived from the internal
peripheral input clock through a 5-bit prescaler. The division ratio is configured in the
SIREN
TX
OR USART_TX
SIR
Transmit IrDA_OUT
Encoder
USART
SIR
RX
Receive IrDA_IN
DEcoder
USART_RX
MSv31164V2
Start Stop
bit bit
0 1 0 1 0 0 1 1 0 1
TX
IrDA_OUT
Bit period 3/16
IrDA_IN
RX 0 1 0 1 0 0 1 1 0 1
MSv31165V1
TX line
USART_DR F1 F2 F3
set
TC flag by hardware
DMA writes
USART_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)
ai17192b
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)
ai17193b
USART 1 USART 2
TX RX
TX circuit RX circuit
CTS RTS
RX TX
RX circuit TX circuit
RTS CTS
MSv31169V2
RTS and CTS flow control can be enabled independently by writing respectively RTSE and
CTSE bits to 1 (in the USART_CR3 register).
RTS
MSv31168V2
CTS
Note: Special behavior of break frames: when the CTS flow is enabled, the transmitter does not
check the CTS input state to send a break.
The USART interrupt events are connected to the same interrupt vector (see Figure 320).
• 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.
MSv42089V1
Asynchronous mode X X X X X X
Hardware flow control X X X NA NA X
Multibuffer communication (DMA) X X X X X X
Multiprocessor communication X X X X X X
Synchronous X X X NA NA X
Smartcard X X X NA NA X
Half-duplex (single-wire mode) X X X X X X
IrDA X X X X X X
LIN X X X X X X
1. X = supported; NA = not applicable.
Note: These 3 bits (CPOL, CPHA, LBCL) should not be written while the transmitter is enabled.
10
11
9
8
7
6
5
4
3
2
1
0
RXNE
IDLE
ORE
CTS
TXE
LBD
USART_SR
TC
NF
PE
FE
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
OVER8
IDLEIE
WAKE
TXEIE
Reserved
RWU
PEIE
TCIE
PCE
SBK
USART_CR1
UE
RE
PS
TE
M
0x0C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CLKEN
LINEN
LBDIE
CPHA
STOP
CPOL
Reserved
Reserved
LBCL
LBDL
USART_CR2 ADD[3:0]
0x10 Reserved [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0
ONEBIT
HDSEL
DMAR
CTSIE
NACK
SCEN
DMAT
CTSE
RTSE
IREN
IRLP
EIE
USART_CR3
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
SDMMC_D
SDMMC_D Data block crc Data block crc Data block crc
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
Data from card to host stops data transfer
From host to
card(s) From card to host Stop command
stops data transfer
Data from host to card
SDMMC
SDMMC_CK
Interrupts and
DMA request SDMMC_CMD
PCLK2 SDMMCCLK
ai15898b
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 SDIO uses two clock signals:
• SDIO adapter clock SDIOCLK up to 50 MHz (48 MHz when in use with USB)
• APB2 bus clock (PCLK2)
PCLK2 and SDIO_CK clock frequencies must respect the following condition:
The signals shown in Table 150 are used on the MultiMediaCard/SD/SD I/O card bus.
SDMMC adapter
Card bus
Command
SDMMC_CMD
Adapter path
registers
To APB2
Data path SDMMC_D[7:0]
interface FIFO
PCLK2 SDMMCCLK
ai15899b
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 APB2 bus clock domain (PCLK2). 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
The control unit is illustrated in Figure 328. 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
SDMMC_CMDin
CMD
Argument
CRC SDMMC_CMDout
Shift
CMD register
Response
To APB2 interface
registers
ai15900b
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.
at least 8 SDMMC_CK
cycles
SDMMC_CK Command Response Command
SDMMC_CMD Hi-Z Controller drives Hi-Z Card drives Hi-Z Controller drives
ai14807b
• 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 151. 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 331 on page 1027.
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 31.9.4 on page 1062). The command path
implements the status flags shown in Table 154:
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 332 shows a block diagram
of the data path.
Data path
Transmit
CRC SDMMC_Dout[7:0]
Shift
register
Receive
ai14808b
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 333: 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 APB2 clock domain (PCLK2), 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 APB2 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 157 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_Stream3 or DMA2_Stream6 Channel4 source address
register with the memory location’s base address and DMA2_Stream3 or
Cards that store the card identification number (CID) and card specific data (CSD) in the
payload memory are able to communicate this information only under data-transfer VDD
conditions. When the SDIO card host module and the card have incompatible VDD ranges,
the card is not able to complete the identification cycle and cannot send CSD data. For this
purpose, the special commands, SEND_OP_COND (CMD1), SD_APP_OP_COND (ACMD41
for SD Memory), and IO_SEND_OP_COND (CMD5 for SD I/O), are designed to provide a
mechanism to identify and reject cards that do not match the VDD range desired by the
SDIO card host. The SDIO card host sends the required VDD voltage window as the
operand of these commands. Cards that cannot perform data transfer in the specified range
disconnect from the bus and go to the inactive state.
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.
select a different card), which will place the card in the Disconnect state and release the
SDIO_D line(s) without interrupting the write operation. When selecting the card again, it will
reactivate busy indication by pulling SDIO_D to low if programming is still in progress and
the write buffer is unavailable.
The maximum clock frequency for a stream write operation is given by the following
equation fields of the card-specific data register:
8 × 2 writebllen ) ( – NSAC ))
Maximumspeed = MIN (TRANSPEED,(------------------------------------------------------------------------
TAAC × R2WFACTOR
at the specified address) followed by 16 CRC bits. The address field in the write protect
commands is a group address in byte units.
The card ignores all LSBs below the group size.
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 171.
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.
When a password replacement is done, the block size must take into account that both
the old and the new passwords are sent with the command.
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 (SET_PWD = 1), the
length (PWD_LEN), and the password (PWD) itself. When a password replacement is
done, the length value (PWD_LEN) includes the length of both passwords, the old and
the new one, and the PWD field includes the old password (currently used) followed by
the new password.
4. When the password is matched, the new password and its size are saved into the PWD
and PWD_LEN fields, respectively. When the old 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 password is not changed.
The password length field (PWD_LEN) indicates whether a password is currently set. When
this field is nonzero, there is a password set and the card locks itself after power-up. It is
possible to lock the card immediately in the current power session by setting the
LOCK_UNLOCK bit (while setting the password) or sending an additional command for card
locking.
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 171), 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 1040), 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.
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 171) 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.
Type:
• E: error bit
• S: status bit
• R: detected and set for the actual command response
• X: detected and set during command execution. The SDIO card host must poll the card
by issuing the status command to read these bits.
Clear condition:
• A: according to the card current state
• B: always related to the previous command. Reception of a valid command clears it
(with a delay of one command)
• C: clear by read
‘0’ = card
When set, signals that the card is locked
25 CARD_IS_LOCKED SR unlocked A
by the host
‘1’ = card locked
Set when a sequence or password error
LOCK_UNLOCK_ ’0’= no error
24 EX has been detected in lock/unlock card C
FAILED ’1’= error
command
’0’= no error The CRC check of the previous command
23 COM_CRC_ERROR ER B
’1’= error failed.
’0’= no error
22 ILLEGAL_COMMAND ER Command not legal for the card state B
’1’= error
’0’= success Card internal ECC was applied but failed
21 CARD_ECC_FAILED EX C
’1’= failure to correct the data.
(Undefined by the standard) A card error
’0’= no error
20 CC_ERROR ER occurred, which is not related to the host C
’1’= error
command.
(Undefined by the standard) A generic
’0’= no error card error related to the (and detected
19 ERROR EX C
’1’= error during) execution of the last host
command (e.g. read or write failures).
18 Reserved
17 Reserved
Can be either of the following errors:
– The CID register has already been
written and cannot be overwritten
’0’= no error ‘1’= – The read-only section of the CSD does C
16 CID/CSD_OVERWRITE EX
error not match the card contents
– An attempt to reverse the copy (set as
original) or permanent WP
(unprotected) bits was made
0 = Idle
1 = Ready
2 = Ident
The state of the card when receiving the
3 = Stby
command. If the command execution
4 = Tran
causes a state change, it will be visible to
12:9 CURRENT_STATE SR 5 = Data B
the host in the response on the next
6 = Rcv
command. The four bits are interpreted as
7 = Prg
a binary number between 0 and 15.
8 = Dis
9 = Btst
10-15 = reserved
’0’= not ready ‘1’ Corresponds to buffer empty signalling on
8 READY_FOR_DATA SR -
= ready the bus
If set, the card did not switch to the
’0’= no error
7 SWITCH_ERROR EX expected mode as requested by the B
’1’= switch error
SWITCH command
6 Reserved
The card will expect ACMD, or an
‘0’ = Disabled
5 APP_CMD SR indication that the command has been C
‘1’ = Enabled
interpreted as ACMD
4 Reserved for SD I/O Card
’0’= no error Error in the sequence of the
3 AKE_SEQ_ERROR ER C
’1’= error authentication process
2 Reserved for application specific commands
1
Reserved for manufacturer test mode
0
Clear condition:
• A: according to the card current state
• B: always related to the previous command. Reception of a valid command clears it
(with a delay of one command)
• C: clear by read
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.
The maximum AU size, which depends on the card capacity, is defined in Table 163. 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.
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]
The interrupt period is applicable for both memory and I/O operations. The definition of the
interrupt period for operations with single blocks is different from the definition for multiple-
block data transfers.
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.
To use one of the manufacturer-specific ACMDs the SD card Host must perform the
following steps:
1. Send APP_CMD (CMD55)
The card responds to the MultiMediaCard/SD module, indicating that the APP_CMD bit
is set and an ACMD is now expected.
2. Send the required ACMD
The card responds to the MultiMediaCard/SD module, indicating that the APP_CMD bit
is set and that the accepted command is interpreted as an ACMD. When a nonACMD
is sent, it is handled by the card as a normal MultiMediaCard command and the
APP_CMD bit in the card status register stays clear.
When an invalid command is sent (neither ACMD nor CMD) it is handled as a standard
MultiMediaCard illegal command error.
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 151 on page 1027 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.
CMD57
... Reserved.
CMD59
CMD60
... Reserved for manufacturer.
CMD63
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
31.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.
CMD9. Only the bits [127...1] of the CID and CSD are transferred, the reserved bit [0] of
these registers is replaced by the end bit of the response. The card indicates that an erase
is in progress by holding MCDAT low. The actual erase time may be quite long, and the host
may issue CMD7 to deselect the card.
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
31.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
31.5.8 R6
Only for SD I/O. The normal response to CMD3 by a memory device. It is shown in
Table 179.
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
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.
After a data write, data cannot be written to this register for three SDIOCLK clock periods
plus two PCLK2 clock periods.
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: While the SD/SDIO card or MultiMediaCard is in identification mode, the SDIO_CK
frequency must be less than 400 kHz.
The clock frequency can be changed to the maximum card bus frequency when relative
card addresses are assigned to all cards.
After a data write, data cannot be written to this register for three SDIOCLK clock periods
plus two PCLK2 clock periods. 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: After a data write, data cannot be written to this register for three SDIOCLK clock periods
plus two PCLK2 clock periods.
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.
For an SDIO multibyte transfer the value in the data length register must be between 1 and
512.
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
RWSTOP
DTMODE
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
Bit 1 DTDIR: Data transfer direction selection
0: From controller to card.
1: From card to controller.
Bit 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: After a data write, data cannot be written to this register for three SDIOCLK clock periods
plus two PCLK2 clock periods.
The meaning of the DTMODE bit changes according to the value of the SDIOEN bit. When
SDIOEN=0 and DTMODE=1, the MultiMediaCard stream mode is enabled, and when
SDIOEN=1 and DTMODE=1, the peripheral enables an SDIO multibyte transfer.
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
CEATAEND
DTIMEOUT
CTIMEOUT
CMDREND
RXFIFOHF
STBITERR
RXOVERR
CMDSENT
TXFIFOHE
DCRCFAIL
CCRCFAIL
DBCKEND
DATAEND
RXFIFOE
RXFIFOF
CMDACT
TXFIFOE
TXFIFOF
RXDAVL
TXDAVL
RXACT
SDIOIT
TXACT
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
TXUNDERRC
CEATAENDC
DTIMEOUTC
CTIMEOUTC
CMDRENDC
STBITERRC
DCRCFAILC
CCRCFAILC
CMDSENTC
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
CEATAENDIE
DTIMEOUTIE
CTIMEOUTIE
CMDRENDIE
RXFIFOHFIE
STBITERRIE
CMDSENTIE
RXOVERRIE
DCRCFAILIE
CCRCFAILIE
TXFIFOHEIE
DBCKENDIE
DATAENDIE
RXFIFOEIE
RXFIFOFIE
CMDACTIE
TXFIFOEIE
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
10
11
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
CPSMEN
Reserved
WAITINT
nIEN
0x0C SDIO_CMD
DTMODE
Reserved
RWMOD
SDIOEN
DMAEN
DTDIR
DTEN
0x2C SDIO_DCTRL
0x3C
Offset
RM0090
SDIO_ICR
SDIO_STA
Register
SDIO_FIFO
SDIO_MASK
SDIO_FIFOCNT
31
30
29
Reserved Reserved Reserved 28
27
Reserved
26
25
24
CEATAENDIE CEATAENDC CEATAEND 23
SDIOITIE SDIOITC SDIOIT 22
RXDAVLIE RXDAVL 21
TXDAVLIE TXDAVL 20
RXFIFOEIE RXFIFOE 19
TXFIFOEIE TXFIFOE 18
RXFIFOFIE RXFIFOF
RM0090 Rev 19
17
TXFIFOFIE Reserved TXFIFOF 16
RXFIFOHFIE RXFIFOHF 15
FIF0Data
TXFIFOHEIE TXFIFOHE 14
RXACTIE RXACT 13
TXACTIE TXACT 12
Table 181. SDIO register map (continued)
CMDACTIE CMDACT 11
DBCKENDIE DBCKENDC DBCKEND
FIFOCOUNT
10
STBITERRIE STBITERRC STBITERR 9
DATAENDIE DATAENDC DATAEND 8
CMDSENTIE CMDSENTC CMDSENT 7
CMDRENDIE CMDRENDC CMDREND 6
RXOVERRIE RXOVERRC RXOVERR 5
TXUNDERRIE TXUNDERRC TXUNDERR 4
DTIMEOUTIE DTIMEOUTC DTIMEOUT 3
CTIMEOUTIE CTIMEOUTC CTIMEOUT 2
DCRCFAILIE DCRCFAILC DCRCFAIL 1
CCRCFAILIE CCRCFAILC CCRCFAIL
1075/1751
Secure digital input/output interface (SDIO)
1075
Controller area network (bxCAN) RM0090
This section applies to the whole STM32F4xx family, unless otherwise specified.
Transmission
• Three transmit mailboxes
• Configurable transmit priority
• Time Stamp on SOF transmission
Reception
• Two receive FIFOs with three stages
• Scalable filter banks:
– 28 filter banks shared between CAN1 and CAN2
• Identifier list feature
• Configurable FIFO overrun
• Time Stamp on SOF reception
Management
• Maskable interrupts
• Software-efficient mailbox mapping at a unique address space
Dual CAN
• CAN1: Master bxCAN for managing the communication between a Slave bxCAN and
the 512-byte SRAM memory
• CAN2: Slave bxCAN, with no direct access to the SRAM memory.
• The two bxCAN cells share the 512-byte SRAM memory (see Figure 335)
CAN node 2
CAN node n
MCU
Application
CAN
Controller
CAN CAN
Rx Tx
CAN
Transceiver
CAN CAN
High Low
CAN Bus
32.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.
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 FIFOAssign Tx Mailboxes 2 2
Filter Activation 2 1 1
1 Mailbox 0 Mailbox 0
Mailbox 0
CAN2 (Slave)
Master Control
Control/Status/Configuration
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 confi gurable by writing to
Bit Timing the CAN2SB[5:0] bits in the CAN_ FMRregister.
ai16094b
mode. Before entering normal mode bxCAN always has to synchronize on the CAN bus.
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 336. The Sleep mode is exited once the SLAK bit has
been cleared by hardware.
Sleep
SLAK= 1
INAK = 0
Q
NR SL
.I EE
C P
YN .I
NR
.S SL Q
EP CK EE .A
E .A P CK
SL .I
E EP NR
SL Q
.A
CK
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
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 32.7.4.
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 32.7.5
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.
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 342.
Furthermore, the filters can be configured in mask mode or in identifier list mode.
Mask mode
In mask mode the identifier registers are associated with mask registers specifying which
bits of the identifier are handled as “must match” or as “don’t care”.
ID CAN_FxR2[15:8] CAN_FxR2[7:0]
n+1
Mask CAN_FxR2[31:24] CAN_FxR2[23:16]
FSCx = 0
application has to identify the data by means of the identifier. To avoid this, and to ease the
access to the SRAM locations, the CAN controller provides a Filter Match Index.
This index is stored in the mailbox together with the message according to the filter priority
rules. Thus each received message has its associated filter match index.
The Filter Match index can be used in two ways:
• Compare the Filter Match index with a list of expected values.
• Use the Filter Match Index as an index on an array to access the data destination
location.
For nonmasked filters, the software no longer has to compare the identifier.
If the filter is masked the software reduces the comparison to the masked bits only.
The index value of the filter number does not take into account the activation state of the
filter banks. In addition, two independent numbering schemes are used, one for each FIFO.
Refer to Figure 343 for an example.
2
1 ID Mask (32-bit) 2 4 ID List (32-bit) 3
3
4 Deactivated 4
3 ID List (16-bit) 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 ID List (16-bit) 10
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 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
ERROR ACTIVE
ERROR PASSIVE
BUS OFF
ai15903
Bus-Off recovery
The Bus-Off state is reached when TEC is greater than 255, this state is indicated by BOFF
bit in CAN_ESR register. In Bus-Off state, the bxCAN is no longer able to transmit and
receive messages.
Depending on the ABOM bit in the CAN_MCR register bxCAN 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, refer to
the ISO 11898 standard.
1 x tq tBS1 tBS2
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 D LC = Data Length Code
Intermission Transmission Bus Idle
3 C RC = Cyclic Redundancy Code
8
Error flag: 6 dominant bits if node is error
ai15154
FMP0
FMPIE0
& FIFO 0
INTERRUPT
CAN_RF0R FULL0
FFIE0
& +
FOVR0
FOVIE0
&
FMP1
FMPIE1
& FIFO 1
INTERRUPT
CAN_RF1R FULL1
FFIE1
& +
FOVR1
FOVIE1
&
ERRIE
EWGIE
EWGF &
EPVIE
CAN_ESR EPVF & &
BOFIE
+
BOFF & ERRI
CAN_MSR STATUS CHANGE
ERROR
LECIE
1≤LEC≤6 & INTERRUPT
WKUI
WKUIE
&
CAN_MSR
SLAKI
SLKIE
&
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
RESET TTCM ABOM AWUM NART RFLM TXFP SLEEP INRQ
Reserved
rs rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RX SAMP RXM TXM SLAKI WKUI ERRI SLAK INAK
Reserved. Reserved
r r r r rc_w1 rc_w1 rc_w1 r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LOW2 LOW1 LOW0 TME2 TME1 TME0 CODE[1:0] ABRQ2 TERR2 ALST2 TXOK2 RQCP2
Reserved
r r r r r r r r rs rc_w1 rc_w1 rc_w1 rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ABRQ1 Reserved TERR1 ALST1 TXOK1 RQCP1 ABRQ0 TERR0 ALST0 TXOK0 RQCP0
Reserved
rs Res. rc_w1 rc_w1 rc_w1 rc_w1 rs rc_w1 rc_w1 rc_w1 rc_w1
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
RFOM0 FOVR0 FULL0 FMP0[1:0]
Reserved Res.
rs rc_w1 rc_w1 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
RFOM1 FOVR1 FULL1 FMP1[1:0]
Reserved Res.
rs rc_w1 rc_w1 r r
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
LEC BOF EPV EWG FOV FF FMP FOV FF FMP TME
ERRIE
Reserved IE IE IE IE Res. IE1 IE1 IE1 IE0 IE0 IE0 IE
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
REC[7:0] TEC[7:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LEC[2:0] BOFF EPVF EWGF
Reserved Res.
rw rw rw r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SILM LBKM SJW[1:0] Res. TS2[2:0] TS1[3:0]
Reserved
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
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
EXID[12:0] IDE RTR TXRQ
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
EXID[12:0] IDE RTR
Res.
r r r r r r r r r r r r r r r
CAN receive FIFO mailbox data length control and time stamp register
(CAN_RDTxR) (x=0..1)
Address offsets: 0x1B4, 0x1C4
Reset value: 0xXXXX XXXX
All RX registers are write protected.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIME[15:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
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
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
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 32.7.4.
A Mask/Identifier register in mask mode has the same bit mapping as in identifier list
mode.
For the register mapping/addresses of the filter banks refer to Table 184.
10
11
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
CAN_MSR
RX
0x004 Reserved Res.
Reset value 1 1 0 0 0 0 0 1 0
CODE[1:0]
LOW[2:0]
TME[2:0]
RQCP2
RQCP1
RQCP0
ABRQ2
ABRQ1
ABRQ0
TERR2
TXOK2
TERR1
TXOK1
TERR0
TXOK0
ALST2
ALST1
ALST0
CAN_TSR
0x008 Res. Res. Res..
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
BOFIE
EPVIE
LECIE
SLKIE
FFIE1
FFIE0
CAN_IER Reserved
0x014 Reserved Res.
Reset value 0 0 0 0 0 0 0 0 0
LEC[2:0] 0 0 0 0 0
EWGF
BOFF
EPVF
CAN_ESR REC[7:0] TEC[7:0] Reserved
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]
LBKM
Reserved
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
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
CAN_TDH0R DATA7[7:0] DATA6[7:0] DATA5[7:0] DATA4[7:0]
0x18C
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
TXRQ
RTR
IDE
CAN_TI1R STID[10:0]/EXID[28:18] EXID[17:0]
0x190
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x 0
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
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
CAN_RDT1R TIME[15:0] FMI[7:0] DLC[3:0]
0x1C4 Reserved
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
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
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
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
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
PA0-WKUP ETH_MII_CRS
PA1 ETH_MII _RX_CLK / ETH_RMII _REF_CLK
PA2 ETH _MDIO
PA3 ETH _MII_COL
PA7 ETH_MII _RX_DV / ETH_RMII _CRS_DV
PB0 ETH _MII_RXD2
PB1 ETH _MII_RXD3
PB5 ETH _PPS_OUT
PB8 ETH _MII_TXD3
PB10 ETH_ MII_RX_ER
PB11 ETH _MII_TX_EN / ETH _RMII_TX_EN
PB12 ETH _MII_TXD0 / ETH _RMII_TXD0
PB13 ETH _MII_TXD1 / ETH _RMII_TXD1
PC1 ETH _MDC
PC2 ETH _MII_TXD2
PC3 ETH _MII_TX_CLK
PC4 ETH_MII_RXD0 / ETH_RMII_RXD0
PC5 ETH _MII_RXD1/ ETH _RMII_RXD1
PE2 ETH_MII_TXD3
PG8 ETH_PPS_OUT
PG11 ETH _MII_TX_EN / ETH _RMII_TX_EN
PG13 ETH _MII_TXD0 / ETH _RMII_TXD0
PG14 ETH _MII_TXD1 / ETH _RMII_TXD1
PH2 ETH _MII_CRS
PH3 ETH _MII_COL
PH6 ETH _MII_RXD2
PH7 ETH _MII_RXD3
PI10 ETH _MII_RX_ER
2 Kbyte
Checksum PTP MDC
Bus matrix
RX FIFO
offload IEEE1588
Ethernet
DMA
2 Kbyte MDIO
TX FIFO PMT MMC
ai15620c
1. For AHB connections refer to Figure 1: System architecture for STM32F405xx/07xx and
STM32F415xx/17xx devices and Figure 2: System architecture for STM32F42xxx and STM32F43xxx
devices.
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
802.3 MAC
MDC
External
STM32 MCU
MDIO PHY
ai15621b
Preamble
Start Operation PADDR RADDR TA Data (16 bits) Idle
(32 bits)
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
Data to PHY
ai15626
MDC
Start
Preamble of OP PHY address Register address Turn data
code around
frame
TX_CLK
TXD[3:0]
TX_EN
RX_CLK
802.3 MAC
RXD[3:0]
STM32 MCU RX_ER External
RX_DV PHY
CRS
COL
MDC
MDIO
ai15622c
• 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 189).
• 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 189.
STM32 External
TX _CLK
MCU PHY
25 MHz
RX _CLK
HSE
MCO
ai15623b
The RMII is instantiated between the MAC and the PHY. This helps translation of the MAC’s
MII into the RMII. The RMII block has the following characteristics:
• It supports 10-Mbit/s and 100-Mbit/s operating rates
• The clock reference must be doubled to 50 MHz
• The same clock reference must be sourced externally to both MAC and external
Ethernet PHY
• It provides independent 2-bit wide (dibit) transmit and receive data paths
TXD[1:0]
TX_EN
802.3 MAC
RXD[1:0]
STM32 External
MCU CRS_
DV PHY
MDC
MDIO
REF
_ CLK
Clock source
ai15624b
STM32
MCU External
PHY
25 MHz
PLL
REF_CLK
50 MHz
For 10/100 Mbit/s
MS19930V1
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 SYSCFG_PMC register.
To save a pin, the two input clock signals, RMII_REF_CK and MII_RX_CLK, are multiplexed
on the same GPIO pin.
• 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
There are two modes of operation for popping data towards the MAC core:
• In Threshold mode, as soon as the number of bytes in the FIFO crosses the configured
threshold level (or when the end-of-frame is written before the threshold is crossed),
the data is ready to be popped out and forwarded to the MAC core. The threshold level
is configured using the TTC bits of ETH_DMABMR.
• In Store-and-forward mode, only after a complete frame is stored in the FIFO, the frame
is popped towards the MAC core. If the Tx FIFO size is smaller than the Ethernet frame
to be transmitted, then the frame is popped towards the MAC core when the Tx FIFO
becomes almost full.
The application can flush the Transmit FIFO of all contents by setting the FTF
(ETH_DMAOMR register [20]) bit. This bit is self-clearing and initializes the FIFO pointers to
the default state. If the FTF bit is set during a frame transfer to the MAC core, then transfer
is stopped as the FIFO is considered to be empty. Hence an underflow event occurs at the
MAC transmitter and the corresponding Status word is forwarded to the DMA.
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.
the Status words for the frames that were flushed. The Transmit FIFO Flush control register
bit is then cleared. At this point, new frames from the application (DMA) are accepted. All
data presented for transmission after a Flush operation are discarded unless they start with
an SOF marker.
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.
RMII_TXD[1:0]
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
packet has been transferred. Upon completion of the EOF frame transfer, the status word is
popped out and sent to the DMA controller.
In Rx FIFO Store-and-forward mode (configured by the RSF bit in the ETH_DMAOMR
register), a frame is read only after being written completely into the Receive FIFO. In this
mode, all error frames are dropped (if the core is configured to do so) such that only valid
frames are read and forwarded to the application. In Cut-through mode, some error frames
are not dropped, because the error status is received at the end of the frame, by which time
the start of that frame has already been read of the FIFO.
A receive operation is initiated when the MAC detects an SFD on the MII. The core strips the
preamble and SFD before proceeding to process the frame. The header fields are checked
for the filtering and the FCS field used to verify the CRC for the frame. The frame is dropped
in the core if it fails the address filter.
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.
type (Ethernet Type field) and the IP header version, or when the received frame does not
have enough bytes, as indicated by the IPv4 header’s Length field (or when fewer than 20
bytes are available in an IPv4 or IPv6 header). The receive checksum offload also identifies
a TCP, UDP or ICMP payload in the received IP datagrams (IPv4 or IPv6) and calculates the
checksum of such payloads properly, as defined in the TCP, UDP or ICMP specifications. It
includes the TCP/UDP/ICMPv6 pseudo-header bytes for checksum calculation and checks
whether the received checksum field matches the calculated value. The result of this
operation is given as a Payload Checksum Error bit in the receive status word. This status
bit is also set if the length of the TCP, UDP or ICMP payload does not match the expected
payload length given in the IP header. As mentioned in TCP/UDP/ICMP checksum, the
receive checksum offload bypasses the payload of fragmented IP datagrams, IP datagrams
with security features, IPv6 routing headers, and payloads other than TCP, UDP or ICMP.
This information (whether the checksum is bypassed or not) is given in the receive status,
as described in the RDES0: Receive descriptor Word0 section. In this configuration, the
core does not append any payload checksum bytes to the received Ethernet frames.
As mentioned in RDES0: Receive descriptor Word0, the meaning of certain register bits
changes as shown in Table 190.
length, CRC error and Runt Error bits set), indicating the filter fail. In Ethernet power down
mode, all received frames are dropped, and are not forwarded to the application.
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.
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
The interrupt register bits only indicate the block from which the event is reported. You have
to read the corresponding status registers and other registers to clear the interrupt. For
example, bit 3 of the Interrupt register, set high, indicates that the Magic packet or Wake-on-
LAN frame is received in Power-down mode. You must read the ETH_MACPMTCSR
register to clear this interrupt event.
TSTS
TSTI
AND
TSTIM
Interrupt
OR
PMTS
PMTI
AND
PMTIM
ai15637
and Table 192 summarize destination and source address filtering based on the type of
frame received.
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
1 X X X X X X Pass all frames
X X X X X 1 X Pass all frames
Pass on Perfect/Group filter match and
0 X X 0 0 0 X
drop PAUSE control frames if PCF = 0x
Pass on hash filter match and drop
0 0 X 0 1 0 X
PAUSE control frames if PCF = 0x
Pass on hash or perfect/Group filter
Multicast 0 1 X 0 1 0 X match and drop PAUSE control frames if
PCF = 0x
Fail on perfect/Group filter match and
0 X X 1 0 0 X
drop PAUSE control frames if PCF = 0x
Fail on hash filter match and drop PAUSE
0 0 X 1 1 0 X
control frames if PCF = 0x
Fail on hash or perfect/Group filter match
0 1 X 1 1 0 X and drop PAUSE control frames if PCF =
0x
Received frames are considered “good” if none of the following errors exists:
+ CRC error
+ Runt Frame (shorter than 64 bytes)
+ Alignment error (in 10/ 100 Mbit/s only)
+ Length error (non-Type frames only)
+ Out of Range (non-Type frames only, longer than maximum size)
+ MII_RXER Input error
The maximum frame size depends on the frame type, as follows:
+ Untagged frame maxsize = 1518
+ VLAN Frame maxsize = 1522
Wakeup frame filter reg5 Filter 3 Offset Filter 2 Offset Filter 1 Offset Filter 0 Offset
ai15647
the node for a specific Magic Packet pattern. Each received frame is checked for a
0xFFFF FFFF FFFF pattern following the destination and source address field. The PMT
block then checks the frame for 16 repetitions of the MAC address without any breaks or
interruptions. In case of a break in the 16 repetitions of the address, the 0xFFFF FFFF FFFF
pattern is scanned for again in the incoming frame. The 16 repetitions can be anywhere in
the frame, but must be preceded by the synchronization stream (0xFFFF FFFF FFFF). The
device also accepts a multicast frame, as long as the 16 duplications of the MAC address
are detected. If the MAC address of a node is 0x0011 2233 4455, then the MAC scans for
the data sequence:
Destination address source address ……………….. FFFF FFFF FFFF
0011 2233 4455 0011 2233 4455 0011 2233 4455 0011 2233 4455
0011 2233 4455 0011 2233 4455 0011 2233 4455 0011 2233 4455
0011 2233 4455 0011 2233 4455 0011 2233 4455 0011 2233 4455
0011 2233 4455 0011 2233 4455 0011 2233 4455 0011 2233 4455
…CRC
Magic Packet detection is updated in the ETH_MACPMTCSR register for received Magic
Packet. If enabled, a PMT interrupt is generated to indicate the reception of a Magic Packet.
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 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 373 shows this algorithm.
Figure 373. 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 373, 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 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
instead of two contiguous buffers in memory. A data buffer resides in the Host’s physical
memory space, and consists of an entire frame or part of a frame, but cannot exceed a
single frame. Buffers contain only data. The buffer status is maintained in the descriptor.
Data chaining refers to frames that span multiple data buffers. However, a single descriptor
cannot span multiple frames. The DMA skips to the next frame buffer when the end of frame
is detected. Data chaining can be enabled or disabled. The descriptor ring and chain
structure is shown in Figure 376.
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
always accessed in the maximum possible burst size (limited by PBL) for the 16 bytes to be
read.
The Transmit DMA initiates a data transfer only when there is sufficient space in the
Transmit FIFO to accommodate the configured burst or the number of bytes until the end of
frame (when it is less than the configured burst length). 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. 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.
then the DMA marks the first transfer from the buffer as the start of frame. If a descriptor is
marked as last (LS bit in TDES0), then the DMA marks the last transfer from that data buffer
as the end of frame. The receive DMA transfers data to a buffer until the buffer is full or the
end of frame is received. If a descriptor is not marked as last (LS bit in RDES0), then the
buffer(s) that correspond to the descriptor are full and the amount of valid data in a buffer is
accurately indicated by the buffer size field minus the data buffer pointer offset when the
descriptor’s FS bit is set. The offset is zero when the data buffer pointer is aligned to the
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.
3. While in the Run state, the DMA polls the transmit descriptor list for frames requiring
transmission. After polling starts, it continues in either sequential descriptor ring order
or chained order. If the DMA detects a descriptor flagged as owned by the CPU, or if an
error condition occurs, transmission is suspended and both the Transmit buffer
Unavailable (ETH_DMASR register[2]) and Normal Interrupt Summary (ETH_DMASR
register[16]) bits are set. The transmit engine proceeds to Step 9.
4. If the acquired descriptor is flagged as owned by DMA (TDES0[31] is set), the DMA
decodes the transmit data buffer address from the acquired descriptor.
5. The DMA fetches the transmit data from the STM32F4xx memory and transfers the
data.
6. If an Ethernet frame is stored over data buffers in multiple descriptors, the DMA closes
the intermediate descriptor and fetches the next descriptor. Steps 3, 4, and 5 are
repeated until the end of Ethernet frame data is transferred.
7. When frame transmission is complete, if IEEE 1588 time stamping was enabled for the
frame (as indicated in the transmit status) the time stamp value is written to the transmit
descriptor (TDES2 and TDES3) that contains the end-of-frame buffer. The status
information is then written to this transmit descriptor (TDES0). Because the OWN bit is
cleared during this step, the CPU now owns this descriptor. If time stamping was not
enabled for this frame, the DMA does not alter the contents of TDES2 and TDES3.
8. Transmit Interrupt (ETH_DMASR register [0]) is set after completing the transmission
of a frame that has Interrupt on Completion (TDES1[31]) set in its last descriptor. The
DMA engine then returns to Step 3.
9. In the Suspend state, the DMA tries to re-acquire the descriptor (and thereby returns to
Step 3) when it receives a transmit poll demand, and the Underflow Interrupt Status bit
is cleared.
Figure 377 shows the TxDMA transmission flow in default mode.
(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 STM32F4xx 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 378 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.
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
OWN IC LS FS DC DP TTSE CIC TER TCH TTSS IHE
Res Res.
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
ES JT FF IPE LCA NC LCO EC VF CC ED UF DB
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 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 [20]) 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 [20] 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.
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 4 Reserved
TDES 5 Reserved
ai17105b
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
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
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
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/TSV
PCE/ESA
VLAN
OWN
RWT
AFM
LCO
SAF
OE
DE
RE
DE
CE
ES
FS
FT
LE
LS
FL
rw
Table 193. Receive descriptor 0 - encoding for bits 7, 5 and 0 (normal descriptor
format only, EDFE=0)
Bit 5: Bit 7: IPC Bit 0: payload
frame checksum checksum Frame status
type error error
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.
Figure 383. Enhanced receive descriptor field format with IEEE1588 time stamp
enabled
31 0
O
RDES 0 W Status [30:0]
N
RDES 1 CT Reserved Buffer 2 byte count CTRL Res. Buffer 1 byte count
RL [30:29] [28:16] [15:14] [12:0]
RDES 5 Reserved
ai17104
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
IPV6PR 6 5 4 3 2 1 0
IPV4PR
IPCB
IPHE
IPPE
PFT
PV PMT IPPT
Reserved
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
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
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
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
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
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
APCS 6 5 4 3 2 1 0
CSTF
IPCO
Reserved
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 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
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
Figure 385. 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
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
MSFRWCS
MMRPEA
RFWRA
MMTEA
MTFCS
RFRCS
TFWA
TFNE
TFRS
RFFL
Reserved
Reserved
Reserved
Reserved
MTP
TFF
Reserved
ro ro ro ro ro ro ro ro ro ro ro ro ro ro ro ro ro
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
MCFHP
ROR
MCP
MCF
CSR
CR
Reserved
rw rw rw rw rw rw
caused the interrupt is read. The least significant byte lane (bits [7:0]) of the respective
counter must be read in order to clear the interrupt bit.
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
Reserved Reserved 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
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
TSSPTPOEFE
TSPTPPSV2E
TSSIPV4FE
TSSIPV6FE
TSPFFMAE
TSSMRME
TSSARFE
TSSEME
TTSARU
TSCNT
TSSSR
TSFCU
TSSTU
TSITE
TSSTI
Reserved
TSE
Reserved
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
The table below indicates the messages for which a snapshot is taken depending on the
clock, enable master and enable snapshot for event message register settings.
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
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
TSTTR
TSSO
Reserved
ro ro
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
PPSFREQ
Reserved
ro ro
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
FPM
USP
AAB
MB
SR
DA
FB
RDP PM PBL DSL
EDFE
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 rs
transmit DMA. You can issue this command anytime and the TxDMA resets it once it starts
re-fetching the current descriptor from host memory.
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
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
DTCEFD
FUGF
DFRF
Reserved
Reserved
Reserved
OSF
RTC
RSF
TTC
TSF
FEF
FTF
SR
ST
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
ROIE
Reserved
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
RSWTC
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
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
10
11
9
8
7
6
5
4
3
2
1
0
eserved
APCS
CSTF
Reserved
Reserved
Reserved
Reserved
IPCO
ROD
CSD
FES
WD
ETH_MACCR IFG
DM
RD
DC
LM
RE
TE
JD
BL
0x00 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DAIF
SAIF
PAM
HPF
PCF
BFD
SAF
ETH_MACFFR
HM
PM
HU
RA
0x04 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
ETH_MACHTHR HTH[31:0]
0x08
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ETH_MACHTLR HTL[31:0]
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
M M
ETH_MACMIIAR PA MR
CR
0x10 Reserved W B
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ETH_MACMIIDR MD
0x14 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FCB/BPA
ZQPD
UPFD
RFCE
TFCE
Reserved
ETH_MACFCR PT PLT
0x18 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_
VLANTI
0x1C MACVLANTR Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ETH_
Frame filter reg0\Frame filter reg1\Frame filter reg2\Frame filter reg3\Frame filter reg4\...\Frame filter reg7
0x28 MACRWUFFR
Reset value 0
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
WFFRPR
ETH_
Reserved
Reserved
WFR
MPR
WFE
MPE
0x2C
GU
PD
MACPMTCSR Reserved
Reset value 0 0 0 0 0 0 0
MSFRWCS
MMRPEA
TFNEGU
RFWRA
MMTEA
MTFCS
RFRCS
TFWA
ETH_
TFRS
Reserved
Reserved
Reserved
Reserved
RFFL
MTP
TFF
0x34 MACDBGR Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MMCRS
MMCTS
MMCS
PMTS
Reserved
TSTS
ETH_MACSR Reserve
0x38 Reserved
d
Reset value 0 0 0 0 0
PMTIM
TSTIM
ETH_MACIMR Reserve
0x3C Reserved Reserved
d
Reset value 0 0
0x40
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_MACA0LR MACA0L
0x44
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
0x48 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_MACA1LR MACA1L
0x4C
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
0x50 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_MACA2LR MACA2L
0x54
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
0x58 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_MACA3LR MACA3L
0x5C
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
MCFHP
ROR
MCP
MCF
CSR
ETH_MMCCR
CR
0x100 Reserved
Reset value 0 0 0 0 0 0
RGUFS
RFCES
RFAES
ETH_MMCRIR
0x104 Reserved Reserved Reserved
Reset value 0 0 0
TGFMSCS
TGFSCS
TGFS
ETH_MMCTIR
0x108 Reserved Reserved Reserved
Reset value 0 0 0
RGUFM
RFCEM
RFAEM
ETH_MMCRIMR
0x10C Reserved Reserved 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
10
11
9
8
7
6
5
4
3
2
1
0
TGFMSCM
TGFSCM
TGFM
ETH_MMCTIMR
0x110 Reserved Reserved Reserved
Reset value 0 0 0
ETH_MMCTGFS
TGFSCC
0x14C CCR
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_MMCTGF
TGFMSCC
0x150 MSCCR
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_MMCTGF
TGFC
0x168 CR
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_MMCRFC
RFCEC
0x194 ECR
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_MMCRFAE
RFAEC
0x198 CR
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_MMCRGU
RGUFC
0x1C4 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
TSSPTPOEFE
TSPTPPSV2E
TSSIPV4FE
TSSIPV6FE
TSPFFMAE
TSSMRME
TSSARFE
TSSEME
TTSARU
TSCNT
TSSSR
TSFCU
TSSTU
TSITE
TSSTI
Reserved
TSE
ETH_PTPTSCR
0x700 Reserved
Reset value 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
ETH_PTPSSIR STSSI
0x704 Reserved
Reset value 0 0 0 0 0 0 0 0
ETH_PTPTSHR STS[31:0]
0x708
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_PTPTSLR STSS
0x70C
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_PTPTSHU
TSUS
0x710 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
TSUPNS
ETH_PTPTSLU
TSUSS
0x714 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_PTPTSAR TSA
0x718
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_PTPTTHR TTSH
0x71C
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_PTPTTLR TTSL
0x720
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
10
11
9
8
7
6
5
4
3
2
1
0
TSTTR
TSSO
ETH_PTPTSSR
0x728 Reserved
Reset value 0 0
ETH_PTPPPSC PPS
0x72C R Reserved FREQ
Reset value 0 0 0
EDFE
FPM
USP
AAB
ETH_DMABMR MB RDP PM PBL DSL
SR
DA
FB
0x1000 Reserved
Reset value 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 1
ETH_DMATPDR TPD
0x1004
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_DMARPDR RPD
0x1008
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_DMARDLA
SRL
0x100C 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_DMATDLA
STL
0x1010 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
MMCS
RWTS
PMTS
RBUS
RPSS
TBUS
FBES
TPSS
Reserved
TSTS
Reserved
Reserved
TJTS
ROS
RPS
ERS
EBS
TUS
TPS
ETS
NIS
ETH_DMASR
AIS
RS
TS
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
DTCEFD
FUGF
DFRF
Reserved
Reserved
Reserved
OSF
RTC
RSF
TTC
TSF
FEF
FTF
ETH_DMAOMR
SR
ST
Reserve
0x1018 Reserved Reserved
d
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RWTIE
RBUIE
RPSIE
TBUIE
FBEIE
TPSIE
TJTIE
Reserved
ROIE
NISE
ERIE
AISE
TUIE
ETIE
RIE
ETH_DMAIER
TIE
0x101C Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OMFC
OFOC
ETH_DMAMFB
MFA
Reserve MFC
0x1020 OCR
d
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_
RSWTC
0x1024 DMARSWTR Reserved
Reset value 0 0 0 0 0 0 0 0
ETH_
HTDAP
0x1048 DMACHTDR
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_
HRDAP
0x104C DMACHRDR
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_
HTBAP
0x1050 DMACHTBAR
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_
HRBAP
0x1054 DMACHRBAR
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
Refer to Section 2.3: Memory map for the register boundary addresses.
This section applies to the whole STM32F4xx family, unless otherwise specified.
Cortex® core
OTG_FS_DP
Power
USB2.0 OTG OTG_FS_DM
and
OTG FS UTMIFS FS
clock OTG_FS_ID
core PHY
controller USB suspend
USB clock at 48 MHz System clock domain
USB clock OTG_FS_VBUS
domain
RAM bus
OTG_FS_SOF
1.25 Kbyte
USB data
FIFOs
MS19928V4
The CPU submits data over the USB by writing 32-bit words to dedicated OTG_FS locations
(push registers). The data are then automatically stored into Tx-data FIFOs configured
within the USB data RAM. There is one Tx-FIFO push register for each in-endpoint
(peripheral mode) or out-channel (host mode).
The CPU receives the data from the USB by reading 32-bit words from dedicated OTG_FS
addresses (pop registers). The data are then automatically retrieved from a shared Rx-FIFO
configured within the 1.25 KB USB data RAM. There is one Rx-FIFO pop register for each
out-endpoint or in-channel.
The USB protocol layer is driven by the serial interface engine (SIE) and serialized over the
USB by the full-/low-speed transceiver module within the on-chip physical layer (PHY).
VDD
STM32 MCU EN
STMPS2141STR
GPIO
Current-limited 5 V Pwr
Overcurrent power distribution
GPIO+IRQ switch
(2)
USBmicro-AB connector
VBUS
PA9
DM
PA11
OSC_IN DP
PA12
ID
PA10
OSC_OUT
VSS
MS19904V4
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.
STM32 MCU
VBUS
MS19905V4
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 (RWUSIG 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 (WKUPINT bit in
OTG_FS_GINTSTS) is generated and the device suspend bit is automatically cleared.
on which the transfer is not completed in the current frame. This interrupt is
asserted along with the end of periodic frame interrupt
(OTG_FS_GINTSTS/EOPF).
• 3 OUT endpoints
– Each of them can be configured to support the isochronous, bulk or interrupt
transfer type
– Each of them has a proper control (OTG_FS_DOEPCTLx), transfer configuration
(OTG_FS_DOEPTSIZx) and status-interrupt (OTG_FS_DOEPINTx) register
– Device Out endpoints common interrupt mask register (OTG_FS_DOEPMSK) is
available to enable/disable a single kind of endpoint interrupt source on all of the
OUT endpoints (EP0 included)
– Support for incomplete isochronous OUT transfer interrupt (INCOMPISOOUT bit
in OTG_FS_GINTSTS), asserted when there is at least one isochronous OUT
endpoint on which the transfer is not completed in the current frame. This interrupt
is asserted along with the end of periodic frame interrupt
(OTG_FS_GINTSTS/EOPF).
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
the 5 V VBUS line. The external charge pump can be driven by any GPIO output. This is
required for the OTG A-host, A-device and host-only configurations.
The VBUS input ensures that valid VBUS levels are supplied by the charge pump during USB
operations while the charge pump overcurrent output can be input to any GPIO pin
configured to generate port interrupts. The overcurrent ISR must promptly disable the VBUS
generation.
The VBUS pin can be freed by disabling the VBUS sensing option. This is done by setting the
NOVBUSSENS bit in the OTG_FS_GCCFG register. In this case the VBUS is considered
internally to be always at VBUS valid level (5 V).
VDD
5V
EN STMPS2141STR
GPIO
Current-limited 5 V Pwr
MSv36915V2
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.
2. VDD range is between 2 V and 3.6 V.
VBUS valid
When HNP or SRP is enabled the VBUS sensing pin (PA9) pin should be connected to
VBUS. 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.
When HNP and SRP are both disabled, the VBUS sensing pin (PA9) should not be
connected to VBUS. This pin can be can be used as GPIO.
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.
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.
is enabled the packet count field is read-only as the OTG FS core updates it according to
the current transfer status.
• The following transfer parameters can be programmed:
– transfer size in bytes
– number of packets making up the overall transfer size
– initial data PID
responsible for the management of the periodic and nonperiodic request queues.The
periodic transmit FIFO and queue status register (HPTXSTS) and nonperiodic transmit
FIFO and queue status register (HNPTXSTS) are read-only registers which can be used by
the application to read the status of each request queue. They contain:
• The number of free entries currently available in the periodic (nonperiodic) request
queue (8 max)
• Free space currently available in the periodic (nonperiodic) Tx-FIFO (out-transactions)
• IN/OUT token, host channel number and other status information.
As request queues can hold a maximum of 8 entries each, the application can push to
schedule host transactions in advance with respect to the moment they physically reach the
SB for a maximum of 8 pending periodic transactions plus 8 pending nonperiodic
transactions.
To post a transaction request to the host scheduler (queue) the application must check that
there is at least 1 entry available in the periodic (nonperiodic) request queue by reading the
PTXQSAV bits in the OTG_FS_HNPTXSTS register or NPTQXSAV bits in the
OTG_FS_HNPTXSTS register.
STM32 MCU
PA8
SOF pulse output, to
external audio control
PA9 VBUS
VSS
MS19907V3
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.
is generated at any start of frame (SOF bit in OTH_FS_GINTSTS). The current frame
number and the time remaining until the next SOF are tracked in the host frame number
register (HFNUM).
An SOF pulse signal, generated at any SOF starting token and with a width of 20 HCLK
cycles, can be made available externally on the OTG_FS_SOF pin using the SOFOUTEN
bit in the global control and configuration register. The SOF pulse is also internally
connected to the input trigger of timer 2 (TIM2), 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 through the ITR1_RMP bits of TIM2_OR register.
Table 197. Compatibility of STM32 low power modes with the OTG
Mode Description USB compatibility
The power consumption of the OTG PHY is controlled by three bits in the general core
configuration register:
• PHY power down (GCCFG/PWRDWN)
It switches on/off the full-speed transceiver module of the PHY. It must be preliminarily
set to allow any USB operation.
• A-VBUS sensing enable (GCCFG/VBUSASEN)
It switches on/off the VBUS comparators associated with A-device operations. It must
be set when in A-device (USB host) mode and during HNP.
• B-VBUS sensing enable (GCCFG/VBUSASEN)
It switches on/off the VBUS comparators associated with B-device operations. It must
be set when in B-device (USB peripheral) mode and during HNP.
Power reduction techniques are available while in the USB suspended state, when the USB
session is not yet valid or the device is disconnected.
• Stop PHY clock (STPPCLK bit in OTG_FS_PCGCCTL)
When setting the stop PHY clock bit in the clock gating control register, most of the
48 MHz clock domain internal to the OTG full-speed core is switched off by clock
gating. The dynamic power consumption due to the USB clock switching activity is cut
even if the 48 MHz clock input is kept running by the application
Most of the transceiver is also disabled, and only the part in charge of detecting the
asynchronous resume or remote wakeup event is kept alive.
• Gate HCLK (GATEHCLK bit in OTG_FS_PCGCCTL)
When setting the Gate HCLK bit in the clock gating control register, most of the system
clock domain internal to the OTG_FS core is switched off by clock gating. Only the
register read and write interface is kept alive. The dynamic power consumption due to
the USB clock switching activity is cut even if the system clock is kept running by the
application for other purposes.
• USB system stop
When the OTG_FS is in the USB suspended state, the application may decide to
drastically reduce the overall power consumption by a complete shut down of all the
clock sources in the system. USB System Stop is activated by first setting the Stop
PHY clock bit and then configuring the system deep sleep mode in the power control
system module (PWR).
The OTG_FS core automatically reactivates both system and USB clocks by
asynchronous detection of remote wakeup (as an host) or resume (as a device)
signaling on the USB.
To save dynamic power, the USB data FIFO is clocked only when accessed by the OTG_FS
core.
OTG_FS_HFIR
write
OTG_FS_HFIR 400 450
value
Frame
450
449
400
399
400
399
450
449
450
449
… … … …
1
0
1
0
1
0
1
0
timer
ai184
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.
– 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.
Global interrupt
OTG_FS
AND
OR
IEP P
NT
IN
OTG_AHBCFG
T
PIN
T
RT
IN
IN
GI
AND AHB configuration register
HC
OE
HP
OT
OTG_GINTSTS
Core register interrupt
31:26 25 24 23:20 19 18 17:3 2 1:0
OTG_GINTMSK
Core interrupt mask register
OTG_GOTGINT
OTG interrupt register
OTG_DIEPMSK/
OTG_DOEPMSK
Device IN/OUT endpoints common
interrupt mask register
x=0
OTG_DIEPINTx/
...
OTG_DOEPINTx x = #HC-1
Device IN/OUT endpoint interrupt
registers
OTG_HPRT
Host port control and status register
OTG_HAINTMSK
Host all channels interrupt mask register
OTG_HAINT
Host all channels interrupt register
x=0
OTG_HCTINTMSKx
...
MSv36921V3
1. OTG_FS_WKUP become active (high state) when resume condition occurs during L1 SLEEP or L2 SUSPEND states.
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 1271
Table 198. 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 1286
OTG_FS_GRXFSIZ 0x024 OTG_FS Receive FIFO size register (OTG_FS_GRXFSIZ) on page 1287
OTG_FS_HFIR 0x404 OTG_FS Host frame interval register (OTG_FS_HFIR) on page 1292
0x920
OTG device endpoint x control register (OTG_FS_DIEPCTLx) (x = 1..3,
OTG_FS_DIEPCTLx 0x940
where x = Endpoint_number) on page 1311
0x960
0xB20
OTG device endpoint x control register (OTG_FS_DIEPCTLx) (x = 1..3,
OTG_FS_DOEPCTLx 0xB40
where x = Endpoint_number) on page 1311
0xB60
Table 202. 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
Reserved Reserved Reserved
r r r r rw rw rw r rw r
The application reads this register whenever there is an OTG interrupt and clears the bits in
this register to clear the OTG interrupt.
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
HNGDET
DBCDNE
SEDET
Reserved Reserved Reserved Res.
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
SRPCAP
CTXPKT
PHYSEL
FDMOD
FHMOD
HNPCA
TRDT TOCAL
P
Reserved Res. Reserved
rw rw rw rw rw rw r rw
14.2 15 0xF
15 16 0xE
16 17.2 0xD
17.2 18.5 0xC
18.5 20 0xB
20 21.8 0xA
21.8 24 0x9
24 27.5 0x8
27.5 32 0x7
32 - 0x6
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
GONAKEFF
ENUMDNE
GINAKEFF
USBSUSP
ISOODRP
CIDSCHG
HPRTINT
IISOIXFR
Reserved
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
OTGINT
OEPINT
EOPFM
MMISM
SRQIM
IEPINT
PRTIM
SOFM
WUIM
HCIM
Reserved
Reserved
Reserved
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
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
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
rw 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
NOVBUSSENS
SOFOUTEN
VBUSBSEN
VBUSASEN
.PWRDWN
Reserved
Reserved Reserved
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
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
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
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 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
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
ACK
NAK
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
ACKM
NAKM
Reserved
Reserved
Reserved
rw 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
NAKM
EPDM
Reserved
TOM
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 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OUTPKTERRM
STSPHSRXM
OTEPDM
BERRM
XFRCM
STUPM
EPDM
Reserved
Reserved
NAK
Reserved 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
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
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
STALL
CNAK
SNAK
Reserved
TXFNUM MPSIZ
Reserved
rs rs w w w w rw rw rw rw rw rw rw r r rw rw rw rw 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
SNPM
CNAK
SNAK
Reserved
Reserved
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
STALL
SNPM
CNAK
SNAK
MPSIZ
Reserved Reserved
rs rs w w w w rw rw rw rw r r rw rw rw rw 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
PKTDRPSTS
INEPNM
EPDISD
INEPNE
ITTXFE
XFRC
TXFE
TOC
NAK
Reserved
Reserved
Reserved 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
rc_w1 OUTPKTERR
STSPHSRX
OTEPDIS
EPDISD
BERR
XFRC
STUP
NAK
Reserved
Reserved
Reserved Reserved
rc_w1
rc_w1
rc_w1
rc_w1
rc_w1
rc_w1
rc_w1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 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
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
Reserved
STUPCNT XFRSIZ
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
PKTCNT XFRSIZ
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
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
Reserved
RXDPID/S
PKTCNT XFRSIZ
TUPCNT
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
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
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
HSHNPEN
HNGSCS
DHNPEN
SRQSCS
CIDSTS
HNPRQ
BSVLD
ASVLD
DBCT
OTG_FS_GOTG
SRQ
CTL
0x000 Reserved Reserved Reserved
Reset value 0 0 0 1 0 0 0 0 0 0
HNSSCHG
ADTOCHG
SRSSCHG
DBCDNE
HNGDET
SEDET
OTG_FS_GOTG
INT
0x004 Reserved Reserved Reserved Res.
Reset value 0 0 0 0 0 0
PTXFELVL
GINTMSK
TXFELVL
OTG_FS_GAHB
0x008 CFG Reserved Reserved
Reset value 0 0 0
SRPCAP
CTXPKT
PHYSEL
FDMOD
FHMOD
HNPCA
OTG_FS_GUSB
Reserved
Reserved
TRDT TOCAL
CFG
0x00C Reserved
Reset value 0 0 0 0 0 1 0 1 0 0 0 0 0
RXFFLSH
TXFFLSH
AHBIDL
HSRST
CSRST
FCRST
OTG_FS_GRST
Reserved
TXFNUM
CTL
0x010 Reserved
Reset value 1 0 0 0 0 0 0 0 0 0 0
IPXFR/INCOMPISOOUT
GONAKEFF
ENUMDNE
GINAKEFF
USBSUSP
CIDSCHG
ISOODRP
HPRTINT
IISOIXFR
USBRST
DISCINT
WKUINT
NPTXFE
SRQINT
OTGINT
OEPINT
RXFLVL
ESUSP
IEPINT
PTXFE
HCINT
CMOD
EOPF
MMIS
OTG_FS_GINTS
Reserved
Reserved
Reserved
Reserved
SOF
TS
0x014
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
ISOODRPM
CIDSCHGM
IISOIXFRM
NPTXFEM
RXFLVLM
ESUSPM
USBRST
PTXFEM
DISCINT
OTGINT
OEPINT
EOPFM
MMISM
SRQIM
IEPINT
PRTIM
SOFM
WUIM
HCIM
OTG_FS_GINT
Reserved
Reserved
Reserved
Reserved
Reserved
MSK
0x018
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTG_FS_GRXS
TSR (host PKTSTS DPID BCNT CHNUM
mode) Reserved
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
mode) 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
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
OTG_FS_GRXS
TSR (host PKTSTS DPID BCNT CHNUM
mode) Reserved
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
mode) 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
OTG_FS_GRXF
RXFD
SIZ
0x024 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
OTG_FS_HNPT
XFSIZ/
NPTXFD/TX0FD NPTXFSA/TX0FSA
OTG_FS_DIEPT
0x028
XF0
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
XSTS
Res.
0x02C
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
NOVBUSSENS
SOFOUTEN
VBUSBSEN
VBUSASEN
.PWRDWN
OTG_FS_
Reserved
GCCFG
0x038 Reserved Reserved
Reset value 0 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 1 0 0 0 0 0 0 0 0 0
OTG_FS_HPTX
PTXFSIZ PTXSA
0x100 FSIZ
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_DIEPT
INEPTXFD INEPTXSA
XF1
0x104
Reset value 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 0 0 0 0
OTG_FS_DIEPT
INEPTXFD INEPTXSA
XF2
0x108
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_DIEPT
INEPTXFD INEPTXSA
XF3
0x10C
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
M
0x408
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
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
OTG_FS_HPTX
PTXQTOP PTXQSAV PTXFSAVL
STS
0x410
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_HAINT HAINT
0x414 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OTG_FS_HAINT
HAINTM
MSK
0x418 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
POCCHNG
PENCHNG
PSUSP
PCDET
PCSTS
PLSTS
PPWR
POCA
PRES
PENA
PRST
Reserved
OTG_FS_HPRT PSPD PTCTL
0x440 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
OTG_FS_HCCH
Reserved
DAD MCNT EPNUM MPSIZ
AR0
0x500
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
OTG_FS_HCCH EPDIR
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 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
OTG_FS_HCCH
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 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
OTG_FS_HCCH
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 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
OTG_FS_HCCH
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 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
OTG_FS_HCCH
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 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
OTG_FS_HCCH
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 0 0
ODDFRM
CHENA
EPTYP
LSDEV
CHDIS
EPDIR
OTG_FS_HCCH
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 0 0
FRMOR
DTERR
BBERR
TXERR
STALL
XFRC
OTG_FS_HCINT
CHH
Reserved
Reserved
ACK
NAK
0
0x508 Reserved
Reset value 0 0 0 0 0 0 0 0 0
0x5E8
0x5A8
0x58C
0x56C
0x54C
0x52C
0x50C
0x5C8
Offset
RM0090
7
6
5
4
3
2
1
MSK4
MSK3
MSK2
MSK1
MSK0
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
OTG_FS_HCINT
31
30
29
28
27
26
25
24
23
22
21
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
Reserved
20
19
18
RM0090 Rev 19
17
16
15
14
13
12
11
0
0
0
0
0
0
0
0
0
0
0
0
DTERRM DTERRM DTERRM DTERRM DTERRM DTERR DTERR DTERR DTERR DTERR DTERR DTERR 10
0
0
0
0
0
0
0
0
0
0
0
0
FRMORM FRMORM FRMORM FRMORM FRMORM FRMOR FRMOR FRMOR FRMOR FRMOR FRMOR FRMOR 9
0
0
0
0
0
0
0
0
0
0
0
0
BBERRM BBERRM BBERRM BBERRM BBERRM BBERR BBERR BBERR BBERR BBERR BBERR BBERR 8
Table 205. OTG_FS register map and reset values (continued)
0
0
0
0
0
0
0
0
0
0
0
0
TXERRM TXERRM TXERRM TXERRM TXERRM TXERR TXERR TXERR TXERR TXERR TXERR TXERR 7
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 6
0
0
0
0
0
0
0
0
0
0
0
0
ACKM ACKM ACKM ACKM ACKM ACK ACK ACK ACK ACK ACK ACK 5
0
0
0
0
0
0
0
0
0
0
0
0
NAKM NAKM NAKM NAKM NAKM NAK NAK NAK NAK NAK NAK NAK 4
0
0
0
0
0
0
0
0
0
0
0
0
STALLM STALLM STALLM STALLM STALLM STALL STALL STALL STALL STALL STALL STALL 3
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 2
0
0
0
0
0
0
0
0
0
0
0
0
CHHM CHHM CHHM CHHM CHHM CHH CHH CHH CHH CHH CHH CHH 1
0
0
0
0
0
0
0
0
0
0
0
0
XFRCM XFRCM XFRCM XFRCM XFRCM XFRC XFRC XFRC XFRC XFRC XFRC XFRC 0
USB on-the-go full-speed (OTG_FS)
1329/1751
1380
USB on-the-go full-speed (OTG_FS) RM0090
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
CHHM
ACKM
NAKM
OTG_FS_HCINT
Reserved
Reserved
MSK5
0x5AC Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
CHHM
ACKM
NAKM
OTG_FS_HCINT
Reserved
Reserved
MSK6
0x5CC Reserved
Reset value 0 0 0 0 0 0 0 0 0
FRMORM
DTERRM
BBERRM
TXERRM
STALLM
XFRCM
CHHM
ACKM
NAKM
OTG_FS_HCINT
Reserved
Reserved
MSK7
0x5EC Reserved
Reset value 0 0 0 0 0 0 0 0 0
OTG_FS_HCTSI
Reserved
OTG_FS_HCTSI
Reserved
OTG_FS_HCTSI
Reserved
OTG_FS_HCTSI
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 0 0
OTG_FS_HCTSI
Reserved
OTG_FS_HCTSI
Reserved
OTG_FS_HCTSI
Reserved
OTG_FS_HCTSI
Reserved
DSPD
Reserved
DAD
OTG_FS_DCFG
0x800 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 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
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
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
NAKM
EPDM
OTG_FS_DIEPM
TOM
Reserved
SK
0x810 Reserved Reserved
Reset value 0 0 0 0 0 0 0
OUTPKTERRM
STSPHSRXM
OTEPDM
NAKMSK
BERRM
XFRCM
STUPM
EPDM
OTG_FS_DOEP
Reserved
Reserved
Reserved
MSK
0x814 Reserved
Reset value 0 0 0 0 0 0 0 0
OTG_FS_DAINT
OEPM IEPM
0x81C 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 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
SPULSE
0x82C Reserved
Reset value 0 1 0 1 1 0 1 1 1 0 0 0
OTG_FS_DIEPE
INEPTXFEM
MPMSK
0x834 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
USBAEP
NAKSTS
EPENA
EPDIS
STALL
CNAK
SNAK
Reserved
Reserved
TXFNUM
TL0 P Z
0x900 Reserved
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
TG_FS_DTXFST
INEPTFSAV
0x918 S0 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
STALL
CNAK
SNAK
OTG_FS_DIEPC
Reserved
TXFNUM MPSIZ
TL1
0x920 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_DTXFST
INEPTFSAV
S1
0x938 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
STALL
CNAK
SNAK
OTG_FS_DIEPC
Reserved
TXFNUM MPSIZ
TL2
0x940 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_DTXFST
INEPTFSAV
S2
0x958 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
STALL
CNAK
SNAK
OTG_FS_DIEPC
Reserved
TXFNUM MPSIZ
TL3
0x960 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_DTXFST
INEPTFSAV
S3
0x978 Reserved
Reset value 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
USBAEP
NAKSTS
EPENA
EPDIS
STALL
SNPM
CNAK
SNAK
Reserved
Reset value 0 0 0 0 0 0 0 0 0 1 0 0
SD0PID/SEVNFRM
EONUM/DPID
SODDFRM
USBAEP
NAKSTS
EPENA
EPTYP
EPDIS
STALL
SNPM
CNAK
SNAK
OTG_FS_DOEP
MPSIZ
CTL1
0xB20 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
STALL
SNPM
CNAK
SNAK
OTG_FS_DOEP
MPSIZ
CTL2
0xB40 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
STALL
SNPM
CNAK
SNAK
OTG_FS_DOEP
MPSIZ
CTL3
0xB60 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
PKTDRPSTS
INEPNM
EPDISD
INEPNE
ITTXFE
XFRC
TXFE
OTG_FS_DIEPI
Reserved
Reserved
Reserved
TOC
NAK
Reset value 0 0 1 0 0 0 0 0 0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PKTDRPSTS
INEPNM
EPDISD
INEPNE
ITTXFE
XFRC
TXFE
OTG_FS_DIEPI
Reserved
Reserved
Reserved
TOC
NAK
NT1
0x928 Reserved
Reset value 0 0 1 0 0 0 0 0 0
PKTDRPSTS
INEPNM
INEPNE
EPDISD
ITTXFE
XFRC
TXFE
OTG_FS_DIEPI
Reserved
Reserved
Reserved
TOC
NAK
NT2
0x948 Reserved
Reset value 0 0 1 0 0 0 0 0 0
PKTDRPSTS
INEPNM
EPDISD
INEPNE
ITTXFE
XFRC
TXFE
OTG_FS_DIEPI
Reserved
Reserved
Reserved
TOC
NAK
0x968 NT3 Reserved
Reset value 0 0 1 0 0 0 0 0 0
OUTPKTERR
STSPHSRX
OTEPDIS
EPDISD
BERR
XFRC
STUP
OTG_FS_DOEPI
Reserved
Reserved
Reserved
NAK
NT0
0xB08 Reserved
Reset value 0 0 0 0 0 0 0 0
OUTPKTERR
STSPHSRX
OTEPDIS
EPDISD
BERR
XFRC
STUP
OTG_FS_DOEPI
Reserved
Reserved
Reserved
NAK
NT1
0xB28 Reserved
Reset value 0 0 0 0 0 0 0 0
OUTPKTERR
STSPHSRX
OTEPDIS
EPDISD
BERR
XFRC
STUP
OTG_FS_DOEPI
Reserved
Reserved
Reserved
NAK
NT2
0xB48 Reserved
Reset value 0 0 0 0 0 0 0 0
OUTPKTERR
STSPHSRX
OTEPDIS
EPDISD
BERR
XFRC
STUP
OTG_FS_DOEPI
Reserved
Reserved
Reserved
NAK
NT3
0xB68 Reserved
Reset value 0 0 0 0 0 0 0 0
OTG_FS_DIEPT PKTC
XFRSIZ
SIZ0 NT
0x910 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0
OTG_FS_DIEPT
PKTCNT XFRSIZ
SIZ1
0x930 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
OTG_FS_DIEPT
PKTCNT XFRSIZ
SIZ2
0x950 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
OTG_FS_DIEPT
PKTCNT XFRSIZ
SIZ3
0x970 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
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PKTCNT
OTG_FS_DOEP STUP
Reserved
XFRSIZ
TSIZ0 CNT
0xB10 Reserved Reserved
Reset value 0 0 0 0 0 0 0 0 0 0
STUPCNT
RXDPID/
OTG_FS_DOEP
Reserved
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/
OTG_FS_DOEP
Reserved
PKTCNT XFRSIZ
TSIZ2
0xB50
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/
OTG_FS_DOEP
Reserved
PKTCNT XFRSIZ
TSIZ3
0xB70
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
OTG_FS_PCGC
Reserved
CTL
0xE00 Reserved
Reset value
Refer to Section 2.3: Memory map for the register boundary addresses.
register to determine the enumeration speed and perform the steps listed in Endpoint
initialization on enumeration completion on page 1353.
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
The application must ignore all packet statuses other than IN data packet (bx0010).
Start
No
RXFLVL
interrupt ?
Yes
PKTSTS
No
0b0010?
No
Yes
Yes
BCNT > 0?
ai15674
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)
{
Unmask CHH
Disable Channel
Reset Error Count
Mask ACK
}
else if (TXERR or BBERR or STALL)
{
Unmask CHH
Disable Channel
if (TXERR)
{
Increment Error Count
Unmask ACK
}
}
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
}
else if (DTERR)
{
Reset Error Count
}
The application is expected to write the requests as and when the Request queue space is
available and until the XFRC interrupt is received.
• Bulk and control IN transactions
A typical bulk or control IN pipelined transaction-level operation is shown in Figure 399.
See channel 2 (ch_2). The assumptions are:
– The application is attempting to receive two maximum-packet-size packets
(transfer size = 1 024 bytes).
– The receive FIFO can contain at least one maximum-packet-size packet and two
status words per packet (72 bytes for FS).
– The non-periodic request queue depth = 4.
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 400. 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.
• Isochronous OUT transactions
A typical isochronous OUT operation is shown in Figure 401. The assumptions are:
– The application is attempting to send one packet every frame (up to 1 maximum
packet size), starting with an 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 the OUT token in the next frame (odd).
e) The OTG_FS host generates the 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.
g) Handling non-ACK responses
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: 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.
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
1. 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.
2. 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
3. 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.
4. On the AHB side, SETUP packets are emptied by the application.
5. 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
Sequence of operations:
1. Enable all OUT endpoints by setting
– EPENA = 1 in all OTG_FS_DOEPCTLx registers.
2. Flush the RxFIFO as follows
– Poll OTG_FS_GRSTCTL.AHBIDL until it is 1. This indicates that AHB master is
idle.
– Perform read modify write operation on OTG_FS_GRSTCTL.RXFFLSH =1
– Poll OTG_FS_GRSTCTL.RXFFLSH until it is 0, but also using a timeout of less
than 10 milli-seconds (corresponds to minimum reset signaling duration). If 0 is
seen before the timeout, then the RxFIFO flush is successful. If at the moment the
timeout occurs, there is still a 1, (this may be due to a packet on EP0 coming from
the host) then go back (once only) to the previous step (“Perform read modify write
operation”).
3. Before disabling any OUT endpoint, the application must enable Global OUT NAK
mode in the core, according to the instructions in “Setting the global OUT NAK on
page 1358”. This ensures that data in the RxFIFO is sent to the application
successfully. Set SGONAK = 1 in OTG_FS_DCTL
4. Wait for the GONAKEFF interrupt (OTG_FS_GINTSTS)
5. Disable all active OUT endpoints by programming the following register bits:
– EPDIS = 1 in registers OTG_FS_DOEPCTLx
– SNAK = 1 in registers OTG_FS_DOEPCTLx
6. Wait for the EPDIS interrupt in OTG_FS_DOEPINTx for each OUT endpoint
programmed in the previous step. The EPDIS interrupt in OTG_FS_DOEPINTx
indicates that the corresponding OUT endpoint is completely disabled. When the
EPDIS interrupt is asserted, the following bits are cleared:
– EPENA = 0 in registers OTG_FS_DOEPCTLx
– EPDIS = 0 in registers OTG_FS_DOEPCTLx
– SNAK = 0 in registers OTG_FS_DOEPCTLx
• 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
endpoints. At this point, the endpoint with the incomplete transfer remains enabled, but
no active transfers remain in progress on this endpoint on the USB.
Application programming sequence
1. Asserting the IISOOXFRM interrupt (OTG_FS_GINTSTS) indicates that in the current
frame, at least one isochronous OUT endpoint has an incomplete transfer.
2. If this occurs because isochronous OUT data is not completely emptied from the
endpoint, the application must ensure that the application empties all isochronous OUT
data (data and status) from the receive FIFO before proceeding.
– When all data are emptied from the receive FIFO, the application can detect the
XFRC interrupt (OTG_FS_DOEPINTx). In this case, the application must re-
enable the endpoint to receive isochronous OUT data in the next frame.
3. When it receives an IISOOXFRM interrupt (in OTG_FS_GINTSTS), the application
must read the control registers of all isochronous OUT endpoints
(OTG_FS_DOEPCTLx) to determine which endpoints had an incomplete transfer in the
current microframe. An endpoint transfer is incomplete if both the following conditions
are met:
– EONUM bit (in OTG_FS_DOEPCTLx) = SOFFN[0] (in OTG_FS_DSTS)
– EPENA = 1 (in OTG_FS_DOEPCTLx)
4. The previous step must be performed before the SOF interrupt (in OTG_FS_GINTSTS)
is detected, to ensure that the current frame number is not changed.
5. For isochronous OUT endpoints with incomplete transfers, the application must discard
the data in the memory and disable the endpoint by setting the EPDIS bit in
OTG_FS_DOEPCTLx.
6. Wait for the EPDIS interrupt (in OTG_FS_DOEPINTx) and enable the endpoint to
receive new data in the next frame.
– Because the core can take some time to disable the endpoint, the application may
not be able to receive the data in the next frame after receiving bad isochronous
data.
• Stalling a non-isochronous OUT endpoint
This section describes how the application can stall a non-isochronous endpoint.
1. Put the core in the Global OUT NAK mode.
2. Disable the required endpoint
– When disabling the endpoint, instead of setting the SNAK bit in
OTG_FS_DOEPCTL, set STALL = 1 (in OTG_FS_DOEPCTL).
The STALL bit always takes precedence over the NAK bit.
3. When the application is ready to end the STALL handshake for the endpoint, the
STALL bit (in OTG_FS_DOEPCTLx) must be cleared.
4. If the application is setting or clearing a STALL for an endpoint due to a
SetFeature.Endpoint Halt or ClearFeature.Endpoint Halt command, the STALL bit must
be set or cleared before the application sets up the Status stage transfer on the control
endpoint.
Examples
This section describes and depicts some fundamental transfer types and scenarios.
• Bulk OUT transaction
Figure 404 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