RM0390
RM0390
RM0390
Reference manual
STM32F446xx advanced Arm®-based 32-bit MCUs
Introduction
This document is addressed to application developers. It provides complete information on
how to use the memory and peripherals of STM32F446xx microcontrollers.
The STM32F446xx constitute a family of microcontrollers with different memory sizes,
packages and peripherals.
For ordering information, mechanical and electrical device characteristics refer to the
corresponding datasheets.
For information on the Arm® Cortex®-M4 with FPU core refer to the Cortex®-M4 Technical
Reference Manual.
STM32F446xx microcontrollers include ST state-of-the-art patented technology.
Related documents
Available from STMicroelectronics web site www.st.com:
STM32F446xx datasheets
For information on the Cortex®-M4 with FPU, refer to STM32 Cortex®-M4 MCUs and MPUs
programming manual (PM0214).
Contents
1 Documentation conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
1.1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
1.2 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
1.3 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
1.4 Availability of peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
List of tables
Table 100. Positioning of captured data bytes in 32-bit words (14-bit width) . . . . . . . . . . . . . . . . . . . 428
Table 101. Data storage in monochrome progressive video format . . . . . . . . . . . . . . . . . . . . . . . . . . 433
Table 102. Data storage in RGB progressive video format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Table 103. Data storage in YCbCr progressive video format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Table 104. Data storage in YCbCr progressive video format - Y extraction mode . . . . . . . . . . . . . . . 435
Table 105. DCMI interrupts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
Table 106. DCMI register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
Table 107. Counting direction versus encoder signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485
Table 108. TIMx Internal trigger connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Table 109. Output control bits for complementary OCx and OCxN channels
with break feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
Table 110. TIM1&TIM8 register map and reset values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
Table 111. Counting direction versus encoder signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
Table 112. TIMx internal trigger connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
Table 113. Output control bit for standard OCx channels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
Table 114. TIM2 to TIM5 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Table 115. TIMx internal trigger connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
Table 116. Output control bit for standard OCx channels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
Table 117. TIM9/12 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
Table 118. Output control bit for standard OCx channels. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
Table 119. TIM10/11/13/14 register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
Table 120. TIM6&TIM7 register map and reset values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
Table 121. Min/max IWDG timeout period at 32 kHz (LSI). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
Table 122. IWDG register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
Table 123. WWDG register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
Table 124. Effect of low power modes on RTC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668
Table 125. Interrupt control bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
Table 126. RTC register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
Table 127. STM32F446xx FMPI2C implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
Table 128. FMPI2C input/output pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
Table 129. FMPI2C internal input/output signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
Table 130. Comparison of analog vs. digital filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697
Table 131. I2C-SMBus specification data setup and hold times . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
Table 132. FMPI2C configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
Table 133. I2C-SMBus specification clock timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
Table 134. Examples of timing settings for fI2CCLK = 8 MHz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
Table 135. Examples of timings settings for fI2CCLK = 16 MHz . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
Table 136. SMBus timeout specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Table 137. SMBus with PEC configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730
Table 138. Examples of TIMEOUTA settings for various FMPI2CCLK frequencies
(max tTIMEOUT = 25 ms) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
Table 139. Examples of TIMEOUTB settings for various FMPI2CCLK frequencies. . . . . . . . . . . . . . 731
Table 140. Examples of TIMEOUTA settings for various FMPI2CCLK frequencies
(max tIDLE = 50 µs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
Table 141. Effect of low-power modes on the FMPI2C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741
Table 142. FMPI2C Interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742
Table 143. FMPI2C register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757
Table 144. Maximum DNF[3:0] value to be compliant with Thd:dat(max) . . . . . . . . . . . . . . . . . . . . . 772
Table 145. SMBus vs. I2C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774
Table 146. I2C Interrupt requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 778
Table 147. I2C register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793
Table 148. USART features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796
Table 243. 32-bit debug port registers addressed through the shifted value A[3:2] . . . . . . . . . . . . . 1310
Table 244. Packet request (8-bits) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1311
Table 245. ACK response (3 bits). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1311
Table 246. DATA transfer (33 bits) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1311
Table 247. SW-DP registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1312
Table 248. Cortex®-M4 with FPU AHB-AP registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1314
Table 249. Core debug registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1315
Table 250. Main ITM registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1318
Table 251. Main ETM registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1320
Table 252. Asynchronous TRACE pin assignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1328
Table 253. Synchronous TRACE pin assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1328
Table 254. Flexible TRACE pin assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1329
Table 255. Important TPIU registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1332
Table 256. DBG register map and reset values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1333
Table 257. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1337
List of figures
Figure 203. Triggering timer 1 and 2 with timer 1 TI1 input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Figure 204. General-purpose timer block diagram (TIM9 and TIM12) . . . . . . . . . . . . . . . . . . . . . . . . 582
Figure 205. General-purpose timer block diagram (TIM10/11/13/14) . . . . . . . . . . . . . . . . . . . . . . . . . 583
Figure 206. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 585
Figure 207. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 585
Figure 208. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 586
Figure 209. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
Figure 210. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
Figure 211. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
Figure 212. Counter timing diagram, update event when ARPE=0
(TIMx_ARR not preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
Figure 213. Counter timing diagram, update event when ARPE=1
(TIMx_ARR preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
Figure 214. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 589
Figure 215. TI2 external clock connection example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
Figure 216. Control circuit in external clock mode 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
Figure 217. Capture/compare channel (example: channel 1 input stage) . . . . . . . . . . . . . . . . . . . . . . 591
Figure 218. Capture/compare channel 1 main circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
Figure 219. Output stage of capture/compare channel (channel 1). . . . . . . . . . . . . . . . . . . . . . . . . . . 592
Figure 220. PWM input mode timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
Figure 221. Output compare mode, toggle on OC1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
Figure 222. Edge-aligned PWM waveforms (ARR=8) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
Figure 223. Example of one pulse mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598
Figure 224. Control circuit in reset mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Figure 225. Control circuit in gated mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
Figure 226. Control circuit in trigger mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
Figure 227. Basic timer block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
Figure 228. Counter timing diagram with prescaler division change from 1 to 2 . . . . . . . . . . . . . . . . . 630
Figure 229. Counter timing diagram with prescaler division change from 1 to 4 . . . . . . . . . . . . . . . . . 630
Figure 230. Counter timing diagram, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Figure 231. Counter timing diagram, internal clock divided by 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
Figure 232. Counter timing diagram, internal clock divided by 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
Figure 233. Counter timing diagram, internal clock divided by N. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
Figure 234. Counter timing diagram, update event when ARPE = 0
(TIMx_ARR not preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
Figure 235. Counter timing diagram, update event when ARPE=1
(TIMx_ARR preloaded) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
Figure 236. Control circuit in normal mode, internal clock divided by 1 . . . . . . . . . . . . . . . . . . . . . . . . 634
Figure 237. Independent watchdog block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
Figure 238. Watchdog block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
Figure 239. Window watchdog timing diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648
Figure 240. RTC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654
Figure 241. FMPI2C block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694
Figure 242. I2C bus protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696
Figure 243. Setup and hold timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698
Figure 244. FMPI2C initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
Figure 245. Data reception . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702
Figure 246. Data transmission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
Figure 247. Slave initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706
Figure 248. Transfer sequence flowchart for FMPI2C slave transmitter,
NOSTRETCH= 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708
Figure 249. Transfer sequence flowchart for FMPI2C slave transmitter,
NOSTRETCH= 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709
Figure 250. Transfer bus diagrams for FMPI2C slave transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
Figure 251. Transfer sequence flowchart for slave receiver with NOSTRETCH=0 . . . . . . . . . . . . . . 711
Figure 252. Transfer sequence flowchart for slave receiver with NOSTRETCH=1 . . . . . . . . . . . . . . 712
Figure 253. Transfer bus diagrams for FMPI2C slave receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 712
Figure 254. Master clock generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
Figure 255. Master initialization flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716
Figure 256. 10-bit address read access with HEAD10R=0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716
Figure 257. 10-bit address read access with HEAD10R=1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717
Figure 258. Transfer sequence flowchart for FMPI2C master transmitter for N≤255 bytes. . . . . . . . . 718
Figure 259. Transfer sequence flowchart for FMPI2C master transmitter for N>255 bytes. . . . . . . . . 719
Figure 260. Transfer bus diagrams for FMPI2C master transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . 720
Figure 261. Transfer sequence flowchart for FMPI2C master receiver for N≤255 bytes . . . . . . . . . . 722
Figure 262. Transfer sequence flowchart for FMPI2C master receiver for N >255 bytes . . . . . . . . . . 723
Figure 263. Transfer bus diagrams for FMPI2C master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724
Figure 264. Timeout intervals for tLOW:SEXT, tLOW:MEXT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Figure 265. Transfer sequence flowchart for SMBus slave transmitter N bytes + PEC. . . . . . . . . . . . 732
Figure 266. Transfer bus diagrams for SMBus slave transmitter (SBC=1) . . . . . . . . . . . . . . . . . . . . . 733
Figure 267. Transfer sequence flowchart for SMBus slave receiver N Bytes + PEC . . . . . . . . . . . . . 734
Figure 268. Bus transfer diagrams for SMBus slave receiver (SBC=1). . . . . . . . . . . . . . . . . . . . . . . . 735
Figure 269. Bus transfer diagrams for SMBus master transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736
Figure 270. Bus transfer diagrams for SMBus master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738
Figure 271. I2C bus protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 761
Figure 272. I2C block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 762
Figure 273. Transfer sequence diagram for slave transmitter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
Figure 274. Transfer sequence diagram for slave receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 765
Figure 275. Transfer sequence diagram for master transmitter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 768
Figure 276. Transfer sequence diagram for master receiver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770
Figure 277. I2C interrupt mapping diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779
Figure 278. USART block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
Figure 279. Word length programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799
Figure 280. Configurable stop bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
Figure 281. TC/TXE behavior when transmitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
Figure 282. Start bit detection when oversampling by 16 or 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
Figure 283. Data sampling when oversampling by 16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
Figure 284. Data sampling when oversampling by 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
Figure 285. Mute mode using Idle line detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819
Figure 286. Mute mode using address mark detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 819
Figure 287. Break detection in LIN mode (11-bit break length - LBDL bit is set) . . . . . . . . . . . . . . . . . 822
Figure 288. Break detection in LIN mode vs. Framing error detection. . . . . . . . . . . . . . . . . . . . . . . . . 823
Figure 289. USART example of synchronous transmission. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824
Figure 290. USART data clock timing diagram (M=0) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 824
Figure 291. USART data clock timing diagram (M=1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825
Figure 292. RX data setup/hold time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825
Figure 293. ISO 7816-3 asynchronous protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826
Figure 294. Parity error detection using the 1.5 stop bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 827
Figure 295. IrDA SIR ENDEC- block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829
Figure 296. IrDA data modulation (3/16) -Normal mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 829
Figure 297. Transmission using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 831
Figure 298. Reception using DMA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832
Figure 299. Hardware flow control between 2 USARTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 832
Figure 300. RTS flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833
1 Documentation conventions
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
b. This is an exhaustive list of all abbreviations applicable to STMicroelectronics microcontrollers, some of
them may not be used in the current document.
1.3 Glossary
This section gives a brief definition of acronyms and abbreviations used in this document:
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, refer to the Cortex®-M4 with FPU
Technical Reference Manual.
Word: data of 32-bit length.
Half-word: data 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 re-program the Flash memory
of a microcontroller while the user program is running.
ICP (in-circuit programming): ICP is the ability to program the Flash memory of a
microcontroller using the JTAG protocol, the SWD protocol or the bootloader while the
device is mounted on the user application board.
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 FPUcore.
D-bus
S-bus
DMA_PI
USB_HS_M
DMA_P2
DMA_MEM1
DMA_MEM2
ICODE
ACCEL
Flash
DCODE memory
SRAM1
112 Kbyte
SRAM2
16 Kbyte
AHB1
peripherals APB1
AHB2
peripherals
APB2
FMC MemCtl/
QuadSPI
Bus matrix-S
MSv36042V1
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 FMC).
2.1.2 D-bus
This bus connects the databus of the Cortex®-M4 with FPU 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 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
fetch on this bus (less efficient than ICode). The targets of this bus are the internal SRAM,
SRAM2, the AHB1 peripherals including the APB peripherals, the AHB2 peripherals and the
external memories through the FMC and QUADSPI.
internal Flash, internal SRAMs (SRAM1, SRAM2) and external memories through the FMC
and QUADSPI.
2.1.7 BusMatrix
The BusMatrix manages the access arbitration between masters. The arbitration uses a
round-robin algorithm.
2.2.1 Introduction
Program memory, data memory, registers and I/O ports are organized within the same linear
4-Gbyte address space.
The bytes are coded in memory in Little Endian format. The lowest numbered byte in a word
is considered the word’s least significant byte and the highest numbered byte the most
significant.
The addressable memory space is divided into eight main blocks, of 512 Mbytes each.
AHB2
0xFFFF FFFF 512-Mbyte
Block 7
Cortex-M4 0x5000 0000
Internal Reserved 0x4008 0000 - 0x4FFF FFFF
peripherals
0x4007 FFFF
0xE000 0000
0xDFFF FFFF
512-Mbyte
Block 6
FMC
0xD000 0000
0xCFFF FFFF AHB1
512-Mbyte
Block 5
FMC/QuadSPI
0xA000 0000
0x9FFF FFFF
512-Mbyte 0x4002 0000
Block 4 Reserved 0x4001 6C00 - 0x4001 FFFF
FMC bank 3
and QuadSPI 0x4001 6BFF
0x8000 0000
0x7FFF FFFF
512-Mbyte
Block 3
FMC bank 1
0x6000 0000
0x5FFF FFFF
APB2
512-Mbyte
Block 2
Peripherals
0x4000 0000
0x3FFF FFFF
512-Mbyte
Block 1
SRAM Reserved 0x2003 0000 - 0x3FFF FFFF
0x4001 0000
0x2000 0000 Reserved 0x2002 0000 - 0x2002 FFFF Reserved 0x4000 8000 - 0x4000 FFFF
0x1FFF FFFF
0x4000 7FFF
512-Mbyte SRAM (16 KB aliased 0x2001 C000 - 0x2001 FFFF
Block 0 By bit-banding
SRAM SRAM (112 KB aliased 0x2000 0000 - 0x2001 BFFF
By bit-banding
0x0000 0000
Reserved 0x1FFF C008 - 0x1FFF FFFF
Option Bytes 0x1FFF C000 - 0x1FFF C00F
Reserved 0x1FFF 7A10 - 0x1FFF 7FFF
System memory 0x1FFF 0000 - 0x1FFF 7A0F APB1
Reserved 0x1FFE C008 - 0x1FFE FFFF
Option bytes 0x1FFE C000 - 0x1FFE C00F
Reserved 0x1001 0000 - 0x1FFE BFFF
Reserved 0x1000 0000 - 0x1000 FFFF
All the memory map areas that are not allocated to on-chip memories and peripherals are
considered “Reserved”. For the detailed mapping of available memory and register areas,
refer to the following table.
The following table gives the boundary addresses of the peripherals available in the
devices.
0xA000 0000 - 0xA000 0FFF FMC control register AHB3 Section 11.8.6: FMC register map on page 323
Section 12.5.14: QUADSPI register map on
0xA000 1000 - 0xA000 1FFF QUADSPI register AHB3
page 354
0x5005 0000 - 0x5005 03FF DCMI AHB2 Section 15.5.12: DCMI register map on page 447
Section 31.15.64: OTG_FS/OTG_HS register map
0x5000 0000 - 0x5003 FFFF USB OTG FS AHB2
on page 1205
Section 31.15.64: OTG_FS/OTG_HS register map
0x4004 0000 - 0x4007 FFFF USB OTG HS
on page 1205
0x4002 6400 - 0x4002 67FF DMA2
Section 9.5.11: DMA register map on page 235
0x4002 6000 - 0x4002 63FF DMA1
0x4002 4000 - 0x4002 4FFF BKPSRAM AHB1 -
Flash interface
0x4002 3C00 - 0x4002 3FFF Section 3.8: Flash interface registers on page 80
register
0x4002 3800 - 0x4002 3BFF RCC Section 6.3.28: RCC register map on page 172
0x4002 3000 - 0x4002 33FF CRC Section 4.4.4: CRC register map on page 91
0x4002 1C00 - 0x4002 1FFF GPIOH
0x4002 1800 - 0x4002 1BFF GPIOG
0x4002 1400 - 0x4002 17FF GPIOF
0x4002 1000 - 0x4002 13FF GPIOE
AHB1 Section 7.4.11: GPIO register map on page 193
0x4002 0C00 - 0x4002 0FFF GPIOD
0x4002 0800 - 0x4002 0BFF GPIOC
0x4002 0400 - 0x4002 07FF GPIOB
0x4002 0000 - 0x4002 03FF GPIOA
0x4001 5C00 - 0x4001 5FFF SAI2
APB2 Section 28.5.18: SAI register map on page 985
0x4001 5800 - 0x4001 5BFF SAI1
0x4001 4800 - 0x4001 4BFF TIM11
Section 18.5.12: TIM10/11/13/14 register map on
0x4001 4400 - 0x4001 47FF TIM10
page 626
0x4001 4000 - 0x4001 43FF TIM9
APB2
0x4001 3C00 - 0x4001 3FFF EXTI Section 10.3.7: EXTI register map on page 250
Section 8.2.9: SYSCFG register maps on
0x4001 3800 - 0x4001 3BFF SYSCFG
page 202
0x4001 3400 - 0x4001 37FF SPI4 APB2 Section 26.7.10: SPI register map on page 896
0x4001 3000 - 0x4001 33FF SPI1 Section 26.7.10: SPI register map on page 896
0x4001 2C00 - 0x4001 2FFF SDMMC Section 29.8.16: SDIO register map on page 1044
0x4001 2000 - 0x4001 23FF ADC1 - ADC2 - ADC3 Section 13.14: ADC register map on page 399
0x4001 1400 - 0x4001 17FF USART6 APB2
Section 25.6.8: USART register map on page 845
0x4001 1000 - 0x4001 13FF USART1
0x4001 0400 - 0x4001 07FF TIM8 Section 16.4.21: TIM1&TIM8 register map on
0x4001 0000 - 0x4001 03FF TIM1 page 518
0x4000 7400 - 0x4000 77FF DAC Section 14.5.15: DAC register map on page 423
0x4000 7000 - 0x4000 73FF PWR Section 5.5: PWR register map on page 115
Section 32.7.7: HDMI-CEC register map on
0x4000 6C00 - 0x4000 6FFF HDMI-CEC
page 1300
0x4000 6800 - 0x4000 6BFF CAN2
Section 30.9.5: bxCAN register map on page 1086
0x4000 6400 - 0x4000 67FF CAN1
0x4000 5C00 - 0x4000 5FFF I2C3
0x4000 5800 - 0x4000 5BFF I2C2 Section 24.6.11: I2C register map on page 793
0x4000 5400 - 0x4000 57FF I2C1
0x4000 5000 - 0x4000 53FF UART5
0x4000 4C00 - 0x4000 4FFF UART4
Section 25.6.8: USART register map on page 845
0x4000 4800 - 0x4000 4BFF USART3
0x4000 4400 - 0x4000 47FF USART2
Section 27.5.10: SPDIFRX interface register map
0x4000 4000 - 0x4000 43FF SPDIF-RX
on page 931
APB1
0x4000 3C00 - 0x4000 3FFF SPI3 / I2S3
Section 26.7.10: SPI register map on page 896
0x4000 3800 - 0x4000 3BFF SPI2 / I2S2
0x4000 3000 - 0x4000 33FF IWDG Section 20.4.5: IWDG register map on page 645
0x4000 2C00 - 0x4000 2FFF WWDG Section 21.6.4: WWDG register map on page 652
0x4000 2800 - 0x4000 2BFF RTC & BKP Registers Section 22.6.21: RTC register map on page 690
0x4000 2000 - 0x4000 23FF TIM14
Section 18.5.12: TIM10/11/13/14 register map on
0x4000 1C00 - 0x4000 1FFF TIM13
page 626
0x4000 1800 - 0x4000 1BFF TIM12
0x4000 1400 - 0x4000 17FF TIM7 Section 19.4.9: TIM6&TIM7 register map on
0x4000 1000 - 0x4000 13FF TIM6 page 639
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, 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 area
0 1 System memory System memory is selected as the boot area
1 1 Embedded SRAM Embedded SRAM is selected as the boot area
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.
Embedded bootloader
The embedded bootloader mode is used to reprogram the Flash memory using one of the
following serial interfaces:
USART
CAN2
I2C
SPI
USB OTG FS 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 - 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 - Flash (512 KB) SRAM1 (112 KB) System memory (128 MB Aliased)
0x001F FFFF(1)(2) Aliased 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 Flash
Cortex-M4 with FPU 32-bit Flash memory
instruction interface bus
I-Code bus I-Code bus 128 bits
D-Code
Flash
Cortex memory
core
Sbus AHB
D-code bus 32-bit FLITF
data bus registers
AHB
AHB periph1
32-bit
DMA1 system bus SRAM and
External
DMA2 memories
AHB
periph2
USB HS
MSv36137V1
3.4.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 5.
Note: On STM32F446xx 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.3: Voltage regulator for details on how to
activate the over-drive mode).
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.
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 4 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 be not 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.5.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 7 sectors 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
3. Set the STRT bit in the FLASH_CR register
4. Wait for the BSY bit to be cleared.
Note: If MER and SER bits are both set in the FLASH_CR register, mass erase is performed.
If both MER 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.5.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.
If an erase operation in Flash memory also concerns data in the data or instruction cache,
you have to make sure that these data are rewritten before they are accessed during code
execution. If this cannot be done safely, it is recommended to flush the caches by setting the
DCRST and ICRST bits in the FLASH_CR register.
Note: The I/D cache should be flushed only when it is disabled (I/DCEN = 0).
3.5.5 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)
In this case, if the error interrupt enable bit (ERRIE) is set in the FLASH_SR 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)
0x1FFF C008 Reserved Write protection nWRP bits for sectors 0 to 7
Flash memory are possible in all boot configurations (Flash user boot, debug or boot
from RAM).
Level 1: read protection enabled
It is the default read protection level after option byte erase. The read protection Level
1 is activated by writing any value (except for 0xAA and 0xCC used to set Level 0 and
Level 2, respectively) into the RDP option byte. When the read protection Level 1 is set:
– No access (read, erase, program) to Flash memory can be performed while the
debug feature is connected or while booting from RAM or system memory
bootloader. A bus error is generated in case of read request.
– When booting from Flash memory, accesses (read, erase, program) to Flash
memory from user code are allowed.
When Level 1 is active, programming the protection option byte (RDP) to Level 0
causes the Flash memory to be mass-erased. As a result the user code area is cleared
before the read protection is removed. The mass erase only erases the user code area.
The other option bytes including write protections remain unchanged from before the
mass-erase operation. The OTP area is not affected by mass erase and remains
unchanged. Mass erase is performed only when Level 1 is active and Level 0
requested. When the protection level is increased (0->1, 1->2, 0->2) there is no mass
erase.
Level 2: debug/chip read protection disabled
The read protection Level 2 is activated by writing 0xCC to the RDP option byte. When
the read protection Level 2 is set:
– All protections provided by Level 1 are active.
– Booting from RAM or system memory bootloader is no more allowed.
– JTAG, SWV (single-wire viewer), ETM, and boundary scan are disabled.
– User option bytes can no longer be changed.
– When booting from Flash memory, accesses (read, erase and program) to Flash
memory from user code are allowed.
Memory read protection Level 2 is an irreversible operation. When Level 2 is activated,
the level of protection cannot be decreased to Level 0 or Level 1.
Note: The JTAG port is permanently disabled when Level 2 is active (acting as a JTAG fuse). As a
consequence, boundary scan cannot be performed. STMicroelectronics is not able to
perform analysis on defective parts on which the Level 2 protection has been set.
--
Level 1
RDP /= AAh
RDP /= CCh
Write options default Write options
including including
RDP = CCh Write optionsincluding RDP = AAh
RDP /= CCh & /= AAh
L ev e l 2 L ev e l 0
RDP = CCh RDP = AA h
Write options
including
RDP = CCh
Options write (RDP level decrease) includes Options write (RDP level identical) includes
- Mass erase - Options erase
- Options erase - New options program
- New options program
ai16045
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 canceled 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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. DCRST ICRST DCEN ICEN PRFTEN Res. Res. Res. Res. LATENCY
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BSY
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. RDERR PGSERR PGPERR PGAERR WRPERR Res. Res. OPERR EOP
rw 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 Res. Res. Res. Res. Res. ERRIE EOPIE Res. Res. Res. Res. Res. Res. Res. STRT
rs rw rw rs
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. PSIZE[1:0] Res. SNB[3:0] MER SER PG
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
nRST_ nRST_ WDG_S OPTST OPTLO
RDP[7:0] Res. BOR_LEV
STDBY STOP W RT CK
rw rw rw rw rw rw rw rw rw rw rw rw rw rs rs
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FLASH_ACR LATENCY
0x00
Reset value 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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
RDERR
OPERR
EOP
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
BSY
FLASH_SR
0x0C
Reset value 0 0 0 0 0 0 0 0
PSIZE[1:0]
ERRIE
EOPIE
LOCK
STRT
MER
SER
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PG
FLASH_CR SNB[3:0]
0x10
Reset value 1 0 0 0 0 0 0 0 0 0 0 0 0
nRST_STOP
nRST_STDB
OPTLOCK
OPTSTRT
WDG_SW
BOR_LEV
SPRMOD
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reset value 0 1 1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1
AHB bus
ai14968
Each write operation into the data register creates a combination of the previous CRC value
and the new one (CRC computation is done on the whole 32-bit data word, and not byte per
byte).
The write operation is stalled until the end of the CRC computation, thus allowing back-to-
back write accesses or consecutive write and read accesses.
The CRC calculator can be reset to 0xFFFF FFFF with the RESET control bit in the
CRC_CR register. This operation does not affect the contents of the CRC_IDR register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DR [31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DR [15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. IDR[7:0]
rw rw rw rw rw rw rw rw
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RESET
Table 13. CRC calculation unit 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
CRC_DR Data register
0x00
RESET
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CRC_CR
0x08
Reset value 0
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/...11/12 Voltage
12 × 100 nF VSS regulator
+ 1 × 4.7 μF 1/2/...11/12
MSv33072V1
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 24: 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
GPIOs PC13 to PC15 in output mode is restricted: the speed has to be limited to 2 MHz with
a maximum load of 30 pF and these I/Os must not be used as a current source (e.g. to drive
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 24: RTC_AF1 pin for more
details about this pin configuration).
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.
The backup SRAM is not mass erased by a tamper event.
When the Flash is read out 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. Refer to the description of Read protection (RDP) option byte.
1.2 V domain
Backup domain
MS30430V1
Table 14. 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,
SAI1 and SAI2 clocks, 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
internally connected to the EXTI line16 and can generate an interrupt if enabled through the
EXTI registers. The PVD output interrupt can be generated when VDD drops below the PVD
threshold and/or when VDD rises above the PVD threshold depending on EXTI line16
rising/falling edge configuration. As an example the service routine could perform
emergency shutdown tasks.
PVD output
MS30432V2
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
If the Over-drive mode was enabled before entering Stop mode, it is automatically disabled
during when the Stop mode is activated.
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 20.3: IWDG functional description.
Real-time clock (RTC): this is configured by the RTCEN bit in the RCC Backup domain
control register (RCC_BDCR).
Internal RC oscillator (LSI RC): this is configured by the LSION bit in the 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.
Exiting Stop mode
The Stop mode is exited according to Exiting low power mode.
Refer to Table 18 for more details on how to exit Stop mode.
When exiting Stop mode by issuing an interrupt or a wakeup event, the HSI RC oscillator is
selected as system clock.
If the Under-drive mode was enabled, it is automatically disabled after exiting Stop mode.
When the voltage regulator operates in low-power or low voltage mode, an additional
startup delay is incurred when waking up from Stop mode. By keeping the internal regulator
ON during Stop mode, the consumption is higher although the startup time is reduced.
When the voltage regulator operates in Under-drive mode, an additional startup delay is
induced when waking up from Stop mode.
Debug mode
By default, the debug connection is lost if the application puts the MCU in Stop or Standby
mode while the debug features are used. This is due to the fact that the Cortex®-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 33.16.1: Debug support for low-power modes.
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FISSR FMSSR UDEN[1:0] ODSWEN ODEN
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
VOS[1:0] ADCDC1 Res. MRUDS LPUDS FPDS DBP PLS[2:0] PVDE CSBF CWUF PDDS LPDS
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. UDRDY[1:0] ODSWRDY ODRDY
rc_w1 rc_w1 r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. VOSRDY Res. Res. Res. Res. BRE EWUP1 EWUP2 Res. Res. Res. BRR PVDO SBF WUF
r rw rw rw r r r r
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
UDEN[1:0]
ODSWEN
ADCDC1
VOS[1:0]
PLS[2:0]
MRUDS
FMSSR
LPUDS
CWUF
FISSR
ODEN
PDDS
PVDE
FPDS
CSBF
LPDS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DBP
PWR_CR
0x000
Reset value 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
UDRDY[1:0]
ODSWRDY
VOSRDY
EWUP2.
ODRDY
EWUP1
PVDO
WUF
BRR
BRE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SBF
PWR_CSR
0x004
Reset value 0 0 0 0 0 0 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 13).
6.2 Clocks
Three different clock sources can be used to drive the system clock (SYSCLK):
HSI oscillator clock
HSE oscillator clock
Two main PLL (PLL) clocks
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.
Enable Peripheral
watchdog IWDGCLK clock enable
LSI RC LSI
32 kHz FMPI2C1
HSI
SYSCLK clock
PCLK1
OSC32_IN RTC / AWU enable Clock
enable HDMI-CEC
LES OSC LSE RTC / AWU LSE
clock
OSC32_OUT 32.768 kHz clock HSI / 488
Clock
enable SDIO
clock
SYSCLK
HSE_RTC
MCO2 PLLI2S
/1→5
1 Power ctrl
clock
MCO1
/1→5 / 2 → 31 not (sleep or deepsleep) CPU
clock
MSv36043V2
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,
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.
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
hardware. An interrupt can be generated if enabled in the RCC clock interrupt register
(RCC_CIR).
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 123.
The PLLI2S and PLLSAI use the same input clock as PLL (PLLSRC bit is common to both
PLLs). However, the PLLI2S and PLLSAI have dedicated enable/disable and division
factors (M, N, P, R and R) configuration bits. Once the PLLI2S and PLLSAI are enabled, the
configuration parameters cannot be changed.
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.
control register (RCC_CR) indicate which clock(s) is (are) ready and which clock is currently
used as the system clock.
The LSE clock is in the Backup domain, whereas the HSE and LSI clocks are not. As a
consequence:
If LSE is selected as the RTC clock:
– The RTC continues to work even if the VDD supply is switched off, provided the
VBAT supply is maintained.
If LSI is selected as the Auto-wakeup unit (AWU) clock:
– The AWU state is not guaranteed if the VDD supply is powered off. Refer to
Section 6.2.5: LSI clock on page 122 for more details on LSI calibration.
If the HSE clock is used as the RTC clock:
– The RTC state is not guaranteed if the VDD supply is powered off or if the internal
voltage regulator is powered off (removing power from the 1.2 V domain).
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 selected clock to output onto MCO must not exceed 100 MHz (the maximum I/O
speed).
TI4_RMP[1:0]
GPIO
RTC_WakeUp_IT
LSE TI4
LSI
ai17741d
TI1_RMP[1:0]
GPIO
HSE_RTC(1 MHz) TI1
SPDIFRX_FRAME_SYNC
MS37331V1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLSAI PLLSAI PLLI2S PLLI2S PLL PLL CSS HSE HSE HSE
Res. Res. Res. Res. Res. Res.
RDY ON RDY ON RDY ON 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 HSI
HSICAL[7:0] HSITRIM[4:0] Res.
RDY ON
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
Res. PLLR[2:0] PLLQ[3:0] Res. PLLSRC Res. Res. Res. Res. PLLP[1:0]
rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. PLLN[8:0] PLLM[5:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MCO2[1:0] MCO2 PRE[2:0] MCO1 PRE[2:0] Res. MCO1 RTCPRE[4:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PPRE2[2:0] PPRE1[2:0] Res. Res. HPRE[3:0] SWS[1:0] SW[1:0}
rw rw rw rw rw rw rw rw rw rw r r rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PLLSAI PLLI2S PLL HSE HSI LSE LSI
Res. Res. Res. Res. Res. Res. Res. Res. CSSC
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
Res. CSSF
RDYIE RDYIE RDYIE RDYIE RDYIE RDYIE RDYIE RDYF RDYF RDYF RDYF RDYF RDYF RDYF
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
OTGHS DMA2 DMA1
Res. Res. Res. Res. Res. Res Res. Res. Res. Res. Res. Res. Res.
RST RST RST
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRC GPIOH GPIOG GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA
Res. Res. Res. Res. Res. Res. Res.
RST RST RST RST RST RST RST 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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OTGFS DCMI
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST RST
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. QSPIRST FMCRST
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DAC PWR CECRS CAN2 CAN1 FMPI2C1 I2C3 I2C2 I2C1 UART5 UART4 UART3 UART2 SPDIFRX
Res. Res.
RST RST T RST RST RST RST RST RST RST RST RST RST RST
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
Res. Res. Res. Res.
RST 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
SAI2 SAI1 TIM11 TIM10 TIM9
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RST RST RST RST RST
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYSCFG SPI4 SPI1 SDIO ADC USART6 USART1 TIM8 TIM1
Res. Res. Res. Res Res Res. Res.
RST RST RST RST RST RST RST 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
OTGHS OTGHS DMA2 DMA1 BKP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
ULPIEN EN EN EN SRAMEN
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRC GPIOH GPIOG GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA
Res. Res. Res. Res. Res. Res. Res.
EN EN EN EN EN EN EN EN EN
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. OTGFSEN Res. Res. Res. Res. Res. Res. DCMIEN
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. QSPIEN FMCEN
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DAC PWR CEC CAN2 CAN1 FMPI2C1 I2C3 I2C2 I2C1 UART5 UART4 USART3 USART2 SPDIFRX
Res. Res.
EN EN EN EN EN EN EN EN EN EN EN EN EN EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SPI3 SPI2 WWDG TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
Res. Res. Res. Res.
EN EN EN 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
SAI2 SAI1 TIM11 TIM10 TIM9
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
EN EN EN EN EN
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYSCFG SPI4 SPI1 SDIO ADC3 ADC2 ADC1 USART6 USART1 TIM8 TIM1
Res. Res. Res. Res. Res.
EN EN EN EN EN EN EN EN EN 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: 0x6067 90FF
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 BKP
OTGHS DMA2 DMA1 SRAM2 SRAM1
Res. ULPI Res. Res. Res. Res. Res. Res. Res. Res. SRAM
LPEN LPEN LPEN LPEN LPEN
LPEN LPEN
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FLITF CRC GPIOH GPIOG GPIOF GPIOE GPIOD GPIOC GPIOB GPIOA
Res. Res. Res. Res. Res. Res.
LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN
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 0081
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OTGFS DCMI
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
LPEN LPEN
rw rw
6.3.17 RCC AHB3 peripheral clock enable in low power mode register
(RCC_AHB3LPENR)
Address offset: 0x58
Reset value: 0x0000 0003
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
QSPI FMC
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
LPEN LPEN
rw rw
6.3.18 RCC APB1 peripheral clock enable in low power mode register
(RCC_APB1LPENR)
Address offset: 0x60
Reset value: 0x3FFF 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
DAC PWR CECLP CAN2 CAN1 FMPI2C1 I2C3 I2C2 I2C1 UART5 UART4 USART3 USART2 SPDIFRX
Res. Res.
LPEN LPEN EN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN
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
SPI3 SPI2 WWDG TIM14 TIM13 TIM12 TIM7 TIM6 TIM5 TIM4 TIM3 TIM2
Res. Res. Res. Res.
LPEN LPEN LPEN 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: 0x0x00C7 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
SAI2 SAI1 TIM11 TIM10 TIM9
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
LPEN LPEN LPEN LPEN LPEN
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYSCFG SPI4 SPI1 SDIO ADC3 ADC2 ADC1 USART6 USART1 TIM8 TIM1
Res. Res. Res. Res. Res.
LPEN LPEN LPEN LPEN LPEN LPEN LPEN LPEN 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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BDRST
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTCEN Res. Res. Res. Res. Res. RTCSEL[1:0] Res. Res. Res. Res. LSEMOD LSEBYP LSERDY LSEON
rw 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 BOR
RMVF Res. Res. Res. Res. Res. Res. Res. Res.
RSTF RSTF RSTF RSTF RSTF RSTF RSTF
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. LSIRDY LSION
r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SSCGEN SPREADSEL Res. Res. INCSTEP
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
Res. PLLI2SR[2:0] PLLI2SQ[3:0] Res. Res. Res. Res. Res. Res. PLLI2SP[1: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
Res. PLLI2SN[8:0] PLLI2SM[5:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. PLLSAIQ[3:0] Res. Res. Res. Res. Res. Res. PLLSAIP[1:0]
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. PLLSAIN[8:0] PLLSAIM[5:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. I2S2SRC I2S1SRC TIMPRE SAI2SRC SAI1SRC Res. Res. Res. Res.
rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. PLLSAIDIVQ Res. Res. Res. PLLIS2DIVQ
rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RCC FLITF SRAM SPARE CM4DBG AHB2APB2 AHB2APB1
Res. Res. Res. Res. Res. Res. Res. Res. Res.
_CKEN _CKEN _CKEN _CKEN _CKEN _CKEN _CKEN
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SPDIFRX SDIO CK48M CEC FMPI2C1SEL
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
SEL SEL SEL SEL [1:0]
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
0x1C
0x0C
Addr.
offset
6.3.28
172/1347
RSTR
RSTR
RSTR
RSTR
CFGR
name
RCC_CR
Reserved
RCC_CIR
RCC_PLL
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
RCC_APB1
RCC_AHB3
RCC_AHB2
RCC_AHB1
RCC_CFGR
0
Res. Res. Res. Res. Res. Res. Res. Res. 31
2
[1:0]
0
0
MCO
Res Res. Res. Res. Res. Res. Res. 30
0
0
0
1
0
DACRST Res. Res. Res. OTGHSRST Res. PLL SAIRDY 29
[2:0]
PLLR
0
0
0
0
PWRRST Res. Res. Res. Res. Res. PLL SAION 28
[2:0]
PRE
MCO2
0
0
0
0
CECRST Res. Res. Res. Res. Res. PLL I2SRDY 27
Reset and clock control (RCC)
0
0
1
0
CAN2RST Res. Res. Res. Res. Res. PLL I2SON 26
RCC register map
0
0
0
0
CAN1RST Res. Res. Res. Res. Res. PLL RDY 25
[2:0]
PRE
PLLQ[3:0]
MCO1
0
0
0
0
FMPI2C1RST Res. Res. Res. Res. Res. PLL ON 24
0
0
I2C3RST Res. Res. Res. Res. CSSC Res. Res. Res. 23
0
0
0
0
0
I2C2RST Res. Res. Res. DMA2RST PLLSAIRDYC PLLSRC Res. 22
1
[1:0]
0
0
0
0
MCO
I2C1RST Res. Res. Res. DMA1RST PLLI2SRDYC Res. Res. 21
0
0
0
UART5RST Res. Res. Res. Res. PLLRDYC Res. Res. 20
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0390 Rev 6
RTCPRE[4:0]
[1:0]
0
0
0
0
0
PLLP
0
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
PPRE1
HSICAL[7:0]
0
0
0
0
0
PLLN[8:0]
0
0
0
0
0
0
0
0
1
0
TIM13RST Res. Res. OTGFSRS GPIOHRST CSSF 7
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
SWS
0
0
0
0
0
1
0
TIM3RST Res. QSPIRST Res. GPIOBRST LSERDYF HSIRDY 1
SW
[1:0]
0
0
0
0
0
1
0
0
TIM2RST Res. FMCRST DCMIRST GPIOARST LSIRDYF HSION 0
RM0390
0x48
0x44
0x40
0x38
0x34
0x30
0x28
0x24
0x4C
0x3C
0x2C
Addr.
offset
RM0390
RCC_
RCC_
RCC_
RCC_
RCC_
RSTR
name
Reserved
Reserved
Reserved
Reserved
Reserved
APB2ENR
APB1ENR
AHB3ENR
AHB2ENR
AHB1ENR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RCC_APB2
Res. 31
0
Res. Res. Res. Res. Res. Res. Res. OTGHSULPIEN Res. Res. Res. 30
0
0
Res. Res. Res. DACEN Res. Res. Res. OTGHSEN Res. Res. Res. 29
0
Res. Res. Res. PWREN Res. Res. Res. Res. Res. Res. Res. 28
0
Res. Res. Res. CECEN Res. Res. Res. Res. Res. Res. Res. 27
0
Res. Res. Res. CAN2EN Res. Res. Res. Res. Res. Res. Res. 26
0
Res. Res. Res. CAN1EN Res. Res. Res. Res. Res. Res. Res. 25
0
Res. Res. Res. FMPI2C1EN Res. Res. Res. Res. Res. Res. Res. 24
0
0
0
Res. Res. SAI2EN I2C3EN Res. Res. Res. Res. Res. Res. SAI2RST 23
0
0
0
0
Res. Res. SAI1EN I2C2EN Res. Res. Res. DMA2EN Res. Res. SAI1RST 22
0
0
Res. Res. Res. I2C1EN Res. Res. Res. DMA1EN Res. Res. Res. 21
0
Res. Res. Res. UART5EN Res. Res. Res. Res. Res. Res. Res. 20
0
Res. Res. Res. UART4EN Res. Res. Res. Res. Res. Res. Res. 19
0
0
0
0
Res. Res. TIM11EN USART3EN Res. Res. Res. BKPSRAMEN Res. Res. TIM11RST 18
0
0
0
Res. Res. TIM10EN USART2EN Res. Res. Res. Res. Res. Res. TIM10RST 17
RM0390 Rev 6
0
0
0
Res. Res. TIM9EN SPDIFRXEN Res. Res. Res. Res. Res. Res. TIM9RST 16
0
Res. Res. Res. SPI3EN Res. Res. Res. Res. Res. Res. Res. 15
0
0
Res. Res. SYSCFGEN SPI2EN Res. Res. Res. Res. Res. Res. SYSCFGRST 14
0
0
Res. Res. SPI4EN Res. Res. Res. Res. Res. Res. Res. SP45RST 13
0
0
0
Res. Res. SPI1EN Res. Res. Res. Res. CRCEN Res. Res. SPI1RST 12
0
0
0
Res. Res. SDIOEN WWDGEN Res. Res. Res. Res. Res. Res. SDIORST 11
0
Res. Res. ADC3EN Res. Res. Res. Res. Res. Res. Res. Res. 10
0
Res. Res. ADC2EN Res. Res. Res. Res. Res. Res. Res. Res. 9
0
0
0
8
Table 21. RCC register map and reset values (continued)
Res. Res. ADC1EN TIM14EN Res. Res. Res. Res. Res. Res. ADCRST
0
0
Res. Res. Res. TIM13EN Res. Res. OTGFSEN GPIOHEN Res. Res. Res. 7
0
0
Res. Res. Res. TIM12EN Res. Res. Res. GPIOGEN Res. Res. Res. 6
0
0
0
0
Res. Res. USART6EN TIM7EN Res. Res. Res. GPIOFEN Res. Res. USART6RST 5
0
0
0
0
Res. Res. USART1EN TIM6EN Res. Res. Res. GPIOEEN Res. Res. USART1RST 4
0
0
Res. Res. Res. TIM5EN Res. Res. Res. GPIODEN Res. Res. Res. 3
0
0
Res. Res. Res. TIM4EN Res. Res. Res. GPIOCEN Res. Res. Res. 2
0
0
0
0
Res. Res. TIM8EN TIM3EN Res. QSPIEN Res. GPIOBEN Res. Res. TIM8RST 1
0
0
0
0
0
0
Res. Res. TIM1EN TIM2EN Res. FMCEN DCMIEN GPIOAEN Res. Res. TIM1RST 0
Reset and clock control (RCC)
173/1347
175
0x74
0x70
0x68
0x64
0x60
0x58
0x54
0x50
0x6C
0x5C
Addr.
offset
174/1347
name
LPENR
LPENR
LPENR
LPENR
LPENR
Reserved
Reserved
Reserved
RCC_CSR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
RCC_APB2
RCC_APB1
RCC_AHB3
RCC_AHB2
RCC_AHB1
RCC_BDCR
0
LPWRRSTF Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
0
1
WWDGRSTF Res. Res. Res. Res. Res. Res. Res. Res. OTGHSULPILPEN 30
0
1
1
WDGRSTF Res. Res. Res. Res. DACLPEN Res. Res. Res. OTGHSLPEN 29
0
1
SFTRSTF Res. Res. Res. Res. PWRLPEN Res. Res. Res. Res. 28
1
1
PORRSTF Res. Res. Res. Res. CECLPEN Res. Res. Res. Res. 27
Reset and clock control (RCC)
1
1
PADRSTF Res. Res. Res. Res. CAN2LPEN Res. Res. Res. Res. 26
1
1
BORRSTF Res. Res. Res. Res. CAN1LPEN Res. Res. Res. Res. 25
0
1
RMVF Res. Res. Res. Res. FMPI2C1LPEN Res. Res. Res. Res. 24
1
1
Res. Res. Res. Res. SAI2LPEN I2C3LPEN Res. Res. Res. Res. 23
1
1
1
Res. Res. Res. Res. SAI1LPEN I2C2LPEN Res. Res. Res. DMA2LPEN 22
1
1
Res. Res. Res. Res. Res. I2C1LPEN Res. Res. Res. DMA1LPEN 21
1
Res. Res. Res. Res. Res. UART5LPEN Res. Res. Res. Res. 20
1
Res. Res. Res. Res. Res. UART4LPEN Res. Res. Res. Res. 19
1
1
1
Res. Res. Res. Res. TIM11LPEN USART3LPEN Res. Res. Res. BKPSRAMLPEN 18
1
1
1
Res. Res. Res. Res. TIM10LPEN USART2LPEN Res. Res. Res. SRAM2LPEN 17
RM0390 Rev 6
0
1
1
1
Res. BDRST Res. Res. TIM9LPEN SPDIFRXLPEN Res. Res. Res. SRAM1LPEN 16
0
1
1
Res. RTCEN Res. Res. Res. SPI3LPEN Res. Res. Res. FLITFLPEN 15
1
Res. Res. Res. Res. SYSCFGLPEN SPI2LPEN Res. Res. Res. Res. 14
1
Res. Res. Res. Res. SPI4LPEN Res. Res. Res. Res. Res. 13
1
1
Res. Res. Res. Res. SPI1LPEN Res. Res. Res. Res. CRCLPEN 12
1
1
Res. Res. Res. Res. SDIOLPEN WWDGLPEN Res. Res. Res. Res. 11
1
Res. Res. Res. Res. ADC3LPEN Res. Res. Res. Res. Res. 10
0
1
Res. RTCSEL 1 Res. Res. ADC2LPEN Res. Res. Res. Res. Res. 9
0
1
1
8
Table 21. RCC register map and reset values (continued)
Res. RTCSEL 0 Res. Res. ADC1LPEN 1 TIM14LPEN Res. Res. Res. Res.
1
Res. Res. Res. Res. Res. TIM13LPEN Res. Res. OTGFSLPEN GPIOHLPEN 7
1
1
Res. Res. Res. Res. Res. TIM12LPEN Res. Res. Res. GPIOGLPEN 6
1
1
1
Res. Res. Res. Res. USART6LPEN TIM7LPEN Res. Res. Res. GPIOFLPEN 5
1
1
1
Res. Res. Res. Res. USART1LPEN TIM6LPEN Res. Res. Res. GPIOELPEN 4
0
1
1
Res. LSEMOD Res. Res. Res. TIM5LPEN Res. Res. Res. GPIODLPEN 3
0
1
1
Res. LSEBYP Res. Res. Res. TIM4LPEN Res. Res. Res. GPIOCLPEN 2
0
1
1
1
0
1
LSIRDY LSERDY Res. Res. TIM8LPEN TIM3LPEN Res. QSPILPEN Res. GPIOBLPEN 1
0
1
1
1
0
1
1
LSION LSEON Res. Res. TIM1LPEN TIM2LPEN Res. FMCLPEN DCMILPEN GPIOALPEN 0
RM0390
0x94
0x90
0x88
0x84
0x80
0x78
0x8C
0x7C
Addr.
offset
RM0390
SAI
CGR
CFGR
CFGR
name
CFGR2
SCFGR
RCC_SS
GATENR
RCC_CK
Reserved
Reserved
RCC_PLL
RCC_DCK
RCC_DCK
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
RCC_PLLI2
0
Res. Res. Res. Res. Res. SSCGEN Res. Res. 31
0
0
0
Res. Res. Res. SPREADSEL Res. Res. 30
0
0
1
SPDIFRXSEL Res. Res. Res. Res. Res. 29
[2:0]
[2:0]
0
0
0
0
PLLI2SR
PLLSAIR
SDIOSEL Res. Res. Res. Res. 28
I2S2SRC[1:0]
0
0
0
0
0
CK48MSEL Res. Res. Res. 27
0
0
1
1
0
CECSEL Res. Res. Res. 26
I2S1SRC[1:0]
[3:0]
[3:0]
0
0
0
0
Res. Res. Res. Res. 25
PLLI2SQ
PLLSAIQ
0
0
0
0
Res. Res. TIMPRE Res. Res. 24
0
0
0
Res. Res. Res. Res. Res. 23
SAI2SCR[1:0]
SEL
[1:0]
I2C1
FMP
0
0
Res. Res. Res. 0 Res. Res. 22
0
0
0
0
0
0
0
RM0390 Rev 6
PLLSAIP[1:0]
2SP
[1:0]
PLLI
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
PLLSAIN[8:0]
8
Table 21. RCC register map and reset values (continued)
0
Res. RCC_CKEN Res. Res. Res. 6
0
0
0
0
MODPER
0
Res. SRAM_CKEN Res. Res. 4
0
0
0
0
0
Res. SPARE_CKEN Res. Res. 3
0
0
0
0
0
Res. CM4DBG_CKEN Res. Res. 2
[4:0]
0
0
0
0
0
PLLI2SM[5:0]
PLLSAIM[5:0]
0
0
0
0
0
Res. AHB2APB1_CKEN Res. Res. 0
Reset and clock control (RCC)
175/1347
175
General-purpose I/Os (GPIO) RM0390
Figure 18 shows the basic structure of a 5 V tolerant I/O port bit, Table 22 gives the possible
port bit configurations.
To on-chip Analog
peripheral
Alternate function input
on/off
TTL Schmitt
Bit set/reset registers
Protection
trigger on/off
Pull diode
up
Input driver I/O pin
Write
Output data register
0 0 0 GP output PP
0 0 1 GP output PP + PU
0 1 0 GP output PP + PD
0 1 1 Reserved
01 SPEED[B:A]
1 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 1 1 Reserved
10 SPEED[B:A]
1 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.
In addition to this flexible I/O multiplexing architecture, each peripheral has alternate
functions mapped onto different I/O pins to optimize the number of peripherals available in
smaller packages.
To use an I/O in a given configuration, proceed as follows:
System function
Connect the I/O to AF0 and configure it depending on the function used:
– JTAG/SWD, after each device reset these pins are assigned as dedicated pins
immediately usable by the debugger host (not controlled by the GPIO controller)
– RTC_REFIN: this pin should be configured in Input floating mode
– MCO1 and MCO2: these pins have to be configured in alternate function mode.
Note: You can disable some or all of the JTAG/SWD pins and so release the associated pins for
GPIO usage.
For more details refer to Section 6.2.10: Clock-out capability.
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_OSPEEDER 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 and PH1.
Refer to the “Alternate function mapping” table in the datasheets for the detailed mapping of
the system and peripherals’ alternate function I/O pins.
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, CEC)
AF4 (I2C1..4, CEC)
AF5 (SPI1/2/3/4)
AF6 (SPI2/3/4, SAI1) Pin x (x = 0..7)
AF7 (SPI2/3, USART1..3, UART5, SPDIF-IN)
1
AF8 (SPI2/3, USART1..3, UART5, SPDIF-IN)
AF9 (CAN1/2, TIM12..14, QUADSPI)
AF10 (SAI2, QUADSPI, OTG_HS, OTG_FS)
AF11
AF12 (FMC, 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, CEC)
AF4 (I2C1..4, CEC)
AF5 (SPI1/2/3/4)
AF6 (SPI2/3/4, SAI1) Pin x (x = 8..15)
AF7 (SPI2/3, USART1..3, UART5, SPDIF-IN)
AF8 (SPI2/3, USART1..3, UART5, SPDIF-IN) 1
AF9 (CAN1/2, TIM12..14, QUADSPI)
AF10 (SAI2, QUADSPI, OTG_HS, OTG_FS)
AF11
AF12 (FMC, SDIO, OTG_HS(1))
AF13 (DCMI)
AF14
AF15 (EVENTOUT)
AFRH[31:0]
MS35850V1
1. Configured in FS.
GPIOx_MODER register is used to select the I/O direction (input, output, AF, analog). The
GPIOx_OTYPER and GPIOx_OSPEEDR registers are used to select the output type (push-
pull or open-drain) and speed (the I/O speed pins are directly connected to the
corresponding GPIOx_OSPEEDR register bits whatever the I/O direction). The
GPIOx_PUPDR register is used to select the pull-up/pull-down whatever the I/O direction.
For more details refer to LCKR register description in Section 7.4.8: GPIO port configuration
lock register (GPIOx_LCKR) (x = A..H).
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OT15 OT14 OT13 OT12 OT11 OT10 OT9 OT8 OT7 OT6 OT5 OT4 OT3 OT2 OT1 OT0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OSPEEDR15 OSPEEDR14 OSPEEDR13 OSPEEDR12 OSPEEDR11 OSPEEDR10 OSPEEDR9 OSPEEDR8
[1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0] [1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OSPEEDR7 OSPEEDR6 OSPEEDR5 OSPEEDR4 OSPEEDR3[ OSPEEDR2 OSPEEDR1 OSPEEDR0
[1:0] [1:0] [1:0] [1:0] 1:0] [1:0] [1:0] 1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PUPDR15[1:0] PUPDR14[1:0] PUPDR13[1:0] PUPDR12[1:0] PUPDR11[1:0] PUPDR10[1:0] PUPDR9[1:0] PUPDR8[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PUPDR7[1:0] PUPDR6[1:0] PUPDR5[1:0] PUPDR4[1:0] PUPDR3[1:0] PUPDR2[1:0] PUPDR1[1:0] PUPDR0[1:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IDR15 IDR14 IDR13 IDR12 IDR11 IDR10 IDR9 IDR8 IDR7 IDR6 IDR5 IDR4 IDR3 IDR2 IDR1 IDR0
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ODR15 ODR14 ODR13 ODR12 ODR11 ODR10 ODR9 ODR8 ODR7 ODR6 ODR5 ODR4 ODR3 ODR2 ODR1 ODR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BR15 BR14 BR13 BR12 BR11 BR10 BR9 BR8 BR7 BR6 BR5 BR4 BR3 BR2 BR1 BR0
w w w w w w w w w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BS15 BS14 BS13 BS12 BS11 BS10 BS9 BS8 BS7 BS6 BS5 BS4 BS3 BS2 BS1 BS0
w w w w w w w w w w w w w w w w
Note: A specific write sequence is used to write to the GPIOx_LCKR register. Only word access
(32-bit long) is allowed during this write sequence.
Each lock bit freezes a specific configuration register (control and alternate function
registers).
Address offset: 0x1C
Reset value: 0x0000 0000
Access: 32-bit word only, read/write register
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LCK
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
K16
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LCK LCK LCK LCK LCK LCK LCK LCK LCK LCK LCK LCK LCK LCK LCK LCK
K15 K14 K13 K12 K11 K10 K9 K8 K7 K6 K5 K4 K3 K2 K1 K0
rw rw rw rw rw rw rw rw 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
7.4.11
RM0390
GPIOx_
GPIOx_
MODER
MODER
GPIOB_
GPIOB_
GPIOA_
OTYPER
except B)
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
OSPEEDER
OSPEEDER
(where x = A..H
(where x = A..H)
GPIOB_PUPDR
GPIOA_PUPDR
(where x = C..H)
GPIOx_MODER
0
0
0
0
0
0
1
Res. 31
PUPDR15[1:0] PUPDR15[1:0] OSPEEDR15[1:0] OSPEEDR15[1:0] MODER15[1:0] MODER15[1:0] MODER15[1:0]
0
1
0
0
0
0
0
Res. 30
0
1
0
0
0
0
1
PUPDR14[1:0] PUPDR14[1:0] OSPEEDR14[1:0] OSPEEDR14[1:0]
Res.
MODER14[1:0] MODER14[1:0] MODER14[1:0]
29
0
0
0
0
0
0
0
Res. 28
0
0
0
0
0
0
1
PUPDR13[1:0] PUPDR13[1:0] OSPEEDR13[1:0] OSPEEDR13[1:0]
Res.
MODER13[1:0] MODER13[1:0] MODER13[1:0]
27
0
1
0
0
0
0
0
GPIO register map
Res. 26
0
0
0
0
0
0
Res. 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
Res. 24
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res. 22
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res. 20
0
0
0
0
0
0
0
Res. 19
PUPDR9[1:0] PUPDR9[1:0] OSPEEDR9[1:0] OSPEEDR9[1:0] MODER9[1:0] MODER9[1:0] MODER9[1:0]
0
0
0
0
0
0
0
Res. 18
RM0390 Rev 6
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res. 16
0
0
0
0
0
0
0
0
PUPDR7[1:0] PUPDR7[1:0] OSPEEDR7[1:0] OSPEEDR7[1:0]
OT15
MODER7[1:0] MODER7[1:0] MODER7[1:0]
15
0
0
0
0
0
0
0
0
OT14 14
0
0
0
0
0
0
0
0
PUPDR6[1:0] PUPDR6[1:0] OSPEEDR6[1:0] OSPEEDR6[1:0]
OT13
MODER6[1:0] MODER6[1:0] MODER6[1:0]
13
0
0
0
0
0
0
0
0
OT12 12
0
0
0
0
0
0
0
0
OT11 11
Table 26. 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
0
OT8 8
0
0
1
0
0
1
0
0
0
1
0
0
0
0
OT6 6
0
0
0
0
0
0
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
0
0
0
0
0
0
0
OT0 0
193/1347
General-purpose I/Os (GPIO)
194
General-purpose I/Os (GPIO) RM0390
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 = C..H)
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
IDR15
IDR14
IDR13
IDR12
IDR10
IDR11
GPIOx_IDR
IDR9
IDR8
IDR7
IDR6
IDR5
IDR4
IDR3
IDR2
IDR1
IDR0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
(where x = A..H)
0x10
Reset value x x x x x x x x x x x x x x x x
ODR15
ODR14
ODR13
ODR12
ODR10
ODR11
ODR9
ODR8
ODR7
ODR6
ODR5
ODR4
ODR3
ODR2
ODR1
ODR0
GPIOx_ODR
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
(where x = A..H)
0x14
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
BR15
BR14
BR13
BR12
BR10
BS15
BS14
BS13
BS12
BS10
BR11
BS11
GPIOx_BSRR
BR9
BR8
BR7
BR6
BR5
BR4
BR3
BR2
BR1
BR0
BS9
BS8
BS7
BS6
BS5
BS4
BS3
BS2
BS1
BS0
(where x = A..H)
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
LCK15
LCK14
LCK13
LCK12
LCK10
LCK11
LCKK
LCK9
LCK8
LCK7
LCK6
LCK5
LCK4
LCK3
LCK2
LCK1
LCK0
GPIOx_LCKR
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
(where x = A..H)
0x1C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
GPIOx_AFRL
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 (where x = A..H)
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The system configuration controller is mainly used to remap the memory accessible in the
code area and to manage the external interrupt line connection to the GPIOs.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. SWP_FMC Res. Res. Res. Res. Res. Res. Res. MEM_MODE[2:0]
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ADCxDC2
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EXTI3[3:0] EXTI2[3:0] EXTI1[3:0] EXTI0[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EXTI7[3:0] EXTI6[3:0] EXTI5[3:0] EXTI4[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EXTI11[3:0] EXTI10[3:0] EXTI9[3:0] EXTI8[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EXTI15[3:0] EXTI14[3:0] EXTI13[3:0] EXTI12[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. READY Res. Res. Res. Res. Res. Res. Res. CMP_PD
r rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FMPI2C1_SDA FMPI2C1_SCL
rw rw
0x2C
0x0C
8.2.9
Offset
202/1347
MEMRMP
SYSCFG_
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
SYSCFG_PMC
SYSCFG_CFGR
SYSCFG_CMPCR
SYSCFG_EXTICR4
SYSCFG_EXTICR3
SYSCFG_EXTICR2
SYSCFG_EXTICR1
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 31
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 30
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 29
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 28
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 27
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 26
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 25
Reserved Reserved Reserved Reserved Reserved Reserved Reserved Reserved 24
SYSCFG register maps
RM0390 Rev 6
0
0
0
0
0
Reserved Reserved Reserved Reserved 15
0
0
0
0
Reserved Reserved Reserved Reserved 14
0
0
0
0
EXTI11[3:0]
EXTI15[3:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
10
0
0
0
0
EXTI14[3:0]
EXTI10[3:0]
0
0
0
0
0
0
0
0
0
Reserved READY Reserved Reserved 7
0
0
0
0
0
0
0
0
EXTI13[3:0]
The following table summarizes the SYSCFG register map and the reset values.
0
0
0
0
0
0
0
0
0
0
0
0
0
FMPI2C1_SDA Reserved Reserved 1
MEM_
MODE
EXTI8[3:0]
EXTI4[3:0]
EXTI0[3:0]
EXTI12[3:0]
x
0
0
0
0
0
0
FMPI2C1_SCL CMP_PD Reserved 0
RM0390
RM0390 Direct memory access controller (DMA)
DMA controller
AHB master
REQ_STR0_CH0
REQ_STR0_CH1 Memory port
REQ_STR0_CH7
STREAM 0
STREAM 1
STREAM 2
STREAM 3
STREAM 4
STREAM 5
STREAM 6
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
ai15945b
REQ_STRx_CH7
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 (such as TIM, ADC, SPI, I2C) are independently
connected to each channel and their connection depends on the product implementation.
Table 28 and Table 29 give examples of DMA request mappings.
TIM3_CH4 TIM3_CH1
Channel 5 - - - TIM3_CH2 - TIM3_CH3
TIM3_UP TIM3_TRIG
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 - - TIM8_TRIG
TIM8_COM
9.3.5 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 26 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
Arbiter level
REQ_STREAMx FIFO
peripheral
DMA_SxPAR source
Memory-to-peripheral mode
Figure 27 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 28.
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 31. 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
Note: Peripheral port may be the source or the destination (it can also be the memory source in
the case of memory-to-memory transfer).
PSIZE, MSIZE and NDT[15:0] must be configured so as to ensure that the last transfer is
not 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
the table below.
The size of the burst is configured by software independently for the two AHB ports by using
the MBURST[1:0] and PBURST[1:0] bits in the DMA_SxCR register.
The burst size indicates the number of beats in the burst, not the number of bytes
transferred.
To ensure data coherence, each group of transfers that form a burst are indivisible: AHB
transfers are locked and the arbiter of the AHB bus matrix does not degrant the DMA master
during the sequence of the burst transfer.
Depending on the single or burst configuration, each DMA request initiates a different
number of transfers on the AHB peripheral port:
When the AHB peripheral port is configured for single transfers, each DMA request
generates a data transfer of a byte, half-word or word depending on the PSIZE[1:0] bits
in the DMA_SxCR register
When the AHB peripheral port is configured for burst transfers, each DMA request
generates 4,8 or 16 beats of byte, half word or word transfers depending on the
PBURST[1:0] and PSIZE[1:0] bits in the DMA_SxCR register.
The same as above has to be considered for the AHB memory port considering the
MBURST and MSIZE bits.
In direct mode, the stream can only generate single transfers and the MBURST[1:0] and
PBURST[1:0] bits are forced by hardware.
The address pointers (DMA_SxPAR or DMA_SxM0AR registers) must be chosen so as to
ensure that all transfers within a burst block are aligned on the address boundary equal to
the size of the transfer.
The burst configuration has to be selected in order to respect the AHB protocol, where
bursts must not cross the 1 Kbyte address boundary because the minimum address space
that can be allocated to a single slave is 1 Kbyte. This means that the 1-Kbyte address
boundary must not be crossed by a burst block transfer, otherwise an AHB error is
generated, that is not reported by the DMA registers.
9.3.13 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 the figure below.
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 is managed in single mode by the DMA,
even if a burst transaction is 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 is 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 is sent with the data width set in the
MSIZE bit in the DMA_SxCR register. This means that memory is 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 are 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 not relevant)
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 non-circular 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
9. Configure the data transfer direction, peripheral and memory incremented/fixed mode,
single or burst transactions, peripheral and memory data widths, circular mode,
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 TEIFx or the FEIFx flag is set due to incompatibility between burst size and FIFO
threshold level, the faulty stream is automatically disabled through a hardware clear of its
EN bit in the corresponding stream configuration register (DMA_SxCR).
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 is 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 EN = 1, the corresponding event flag must be cleared,
otherwise an interrupt is immediately generated.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. TCIF3 HTIF3 TEIF3 DMEIF3 Res. FEIF3 TCIF2 HTIF2 TEIF2 DMEIF2 Res. FEIF2
r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. TCIF1 HTIF1 TEIF1 DMEIF1 Res. FEIF1 TCIF0 HTIF0 TEIF0 DMEIF0 Res. FEIF0
r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. TCIF7 HTIF7 TEIF7 DMEIF7 Res. FEIF7 TCIF6 HTIF6 TEIF6 DMEIF6 Res. FEIF6
r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. TCIF5 HTIF5 TEIF5 DMEIF5 Res. FEIF5 TCIF4 HTIF4 TEIF4 DMEIF4 Res. FEIF4
r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. CTCIF3 CHTIF3 CTEIF3 CDMEIF3 Res. CFEIF3 CTCIF2 CHTIF2 CTEIF2 CDMEIF2 Res. CFEIF2
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
Res. Res. Res. Res. CTCIF1 CHTIF1 CTEIF1 CDMEIF1 Res. CFEIF1 CTCIF0 CHTIF0 CTEIF0 CDMEIF0 Res. CFEIF0
w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. CTCIF7 CHTIF7 CTEIF7 CDMEIF7 Res. CFEIF7 CTCIF6 CHTIF6 CTEIF6 CDMEIF6 Res. CFEIF6
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
Res. Res. Res. Res. CTCIF5 CHTIF5 CTEIF5 CDMEIF5 Res. CFEIF5 CTCIF4 CHTIF4 CTEIF4 CDMEIF4 Res. CFEIF4
w w w w w w w w w w
Bits 24, 18, 8, 2 CDMEIF[7:4]: stream x clear direct mode error interrupt flag (x = 7 to 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 CFEIF[7:4]: stream x clear FIFO error interrupt flag (x = 7 to 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
Res. Res. Res. Res. CHSEL[2:0] MBURST [1:0] PBURST[1:0] Res. CT DBM PL[1:0]
rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
NDT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. FEIE Res. FS[2:0] DMDIS FTH[1:0]
rw r r r rw rw rw
0x02C
0x01C
0x00C
9.5.11
RM0390
DMA_LISR
DMA_HISR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
DMA_S1CR
DMA_S0CR
DMA_LIFCR
DMA_HIFCR
DMA_S1PAR
DMA_S0PAR
DMA_S0FCR
DMA_S1NDTR
DMA_S0NDTR
DMA_S0M1AR
DMA_S0M0AR
Offset Register name
0
0
0
0
Res Res. Res Res Res Res Res Res Res. 31
0
0
0
0
Res Res. Res Res Res Res Res Res Res. 30
0
0
0
0
Res Res. Res Res Res Res Res Res Res. 29
0
0
0
0
Res Res. Res Res Res Res Res Res Res. 28
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res Res Res Res Res Res Res. 23
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res CT Res Res CT CTEIF6 CTEIF2 TEIF6 TEIF2 19
0
0
0
0
0
0
0
0
0
0
Res DBM Res Res DBM CDMEIF6 CDMEIF2 DMEIF6 DMEIF2 18
0
0
0
0
0
RM0390 Rev 6
Res Res Res Res Res Res Res. 17
PL[1:0] PL[1:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
PINCOS Res PINCOS Res Res Res Res. 15
PA[31:0]
PA[31:0]
M1A[31:0]
M0A[31:0]
0
0
0
0
0
0
0
0
Res Res Res Res Res. 14
MSIZE[1:0] MSIZE[1:0]
0
0
0
0
0
0
0
0
Res Res Res Res Res. 13
0
0
0
0
0
0
0
0
Res Res Res Res Res. 12
PSIZE[1:0] PSIZE[1:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
FEIE Res Res Res Res. 7
DIR[1:0] DIR[1:0]
NDT[15:0]
NDT[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
PFCTRL PFCTRL CTCIF4 CTCIF0 TCIF4 TCIF0 5
0
0
0
0
0
0
0
0
0
0
0
0
0
TCIE TCIE CHTIF4 CHTIF0 HTIF4 HTIF0 4
FS[2:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
HTIE HTIE CTEIF4 CTEIF0 TEIF4 TEIF0 3
0
0
0
0
0
0
0
0
0
0
0
0
0
TEIE DMDIS TEIE CDMEIF4 CDMEIF0 DMEIF4 DMEIF0 2
0
0
0
0
0
0
0
0
0
DMEIE DMEIE Res Res Res Res. 1
FTH[1:0]
0
0
0
0
0
0
0
0
0
0
0
0
1
EN EN CFEIF4 CFEIF0 FEIF4 FEIF0
Direct memory access controller (DMA)
235/1347
0
238
Direct memory access controller (DMA) RM0390
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_S1M0AR M0A[31:0]
0x034
Reset value 0 0 0 0 0 0 0 0 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]
0x038
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FTH[1:0]
DMDIS
FEIE
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S1FCR FS[2:0]
0x03C
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
MINC
CIRC
PINC
HTIE
TCIE
DBM
TEIE
[1:0]
Res
Res
Res
Res
Res
DIR
EN
CT
DMA_S2CR
0x040
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S2NDTR NDT[15:0]
0x044
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S2PAR PA[31:0]
0x048
Reset value 0 0 0 0 0 0 0 0 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]
0x04C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S2M1AR M1A[31:0]
0x050
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FTH[1:0]
DMDIS
FEIE
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S2FCR FS[2:0]
0x054
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
HTIE
TCIE
TEIE
DBM
Res
Res
Res
Res
Res
EN
CT
DMA_S3CR
0x058
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S3NDTR NDT[15:0]
0x05C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S3PAR PA[31:0]
0x060
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S3M0AR M0A[31:0]
0x064
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S3M1AR M1A[31:0]
0x068
Reset value 0 0 0 0 0 0 0 0 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
FTH[1:0]
DMDIS
FEIE
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S3FCR FS[2:0]
0x06C
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
MINC
CIRC
PINC
HTIE
TCIE
TEIE
DBM
[1:0]
Res
Res
Res
Res
Res
DIR
EN
CT
DMA_S4CR
0x070
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S4NDTR NDT[15:0]
0x074
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S4PAR PA[31:0]
0x078
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S4M0AR M0A[31:0]
0x07C
Reset value 0 0 0 0 0 0 0 0 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]
0x080
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FTH[1:0]
DMDIS
FEIE
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S4FCR FS[2:0]
0x084
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
HTIE
TCIE
TEIE
DBM
Res
Res
Res
Res
Res
EN
CT
DMA_S5CR
0x088
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S5NDTR NDT[15:0]
0x08C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S5PAR PA[31:0]
0x090
Reset value 0 0 0 0 0 0 0 0 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]
0x094
Reset value 0 0 0 0 0 0 0 0 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]
0x098
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FTH[1:0]
DMDIS
FEIE
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S5FCR FS[2:0]
0x09C
Reset value 0 1 0 0 0 0 1
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
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
TCIE
HTIE
DBM
TEIE
Res
Res
Res
Res
Res
EN
CT
DMA_S6CR
0x0A0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S6NDTR NDT[15:0]
0x0A4
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S6PAR PA[31:0]
0x0A8
Reset value 0 0 0 0 0 0 0 0 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_S6M0AR M0A[31:0]
0x0AC
Reset value 0 0 0 0 0 0 0 0 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]
0x0B0
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FTH[1:0]
DMDIS
FEIE
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S6FCR FS[2:0]
0x0B4
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
TCIE
HTIE
DBM
TEIE
Res
Res
Res
Res
Res
EN
CT
DMA_S7CR
0x0B8
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S7NDTR NDT[15:0]
0x0BC
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DMA_S7PAR PA[31:0]
0x0C0
Reset value 0 0 0 0 0 0 0 0 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]
0x0C4
Reset value 0 0 0 0 0 0 0 0 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]
0x0C8
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FTH[1:0]
DMDIS
FEIE
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
Res
DMA_S7FCR FS[2:0]
0x0CC
Reset value 0 1 0 0 0 0 1
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
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
PD0 EXTI0
PE0
PF0
PG0
PH0
PA1
PB1
PC1
PD1 EXTI1
PE1
PF1
PG1
PH1
...
PA15
PB15
PC15 EXTI15
PD15
PE15
PF15
PG15
MS35851V1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. MR22 MR21 MR20 MR19 MR18 MR17 MR16
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MR15 MR14 MR13 MR12 MR11 MR10 MR9 MR8 MR7 MR6 MR5 MR4 MR3 MR2 MR1 MR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. MR22 MR21 MR20 MR19 MR18 MR17 MR16
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MR15 MR14 MR13 MR12 MR11 MR10 MR9 MR8 MR7 MR6 MR5 MR4 MR3 MR2 MR1 MR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. TR22 TR21 TR20 Res. TR18 TR17 TR16
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TR15 TR14 TR13 TR12 TR11 TR10 TR9 TR8 TR7 TR6 TR5 TR4 TR3 TR2 TR1 TR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The external wakeup lines are edge triggered, no 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
Res. Res. Res. Res. Res. Res. Res. Res. Res. TR22 TR21 TR20 Res. TR18 TR17 TR16
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TR15 TR14 TR13 TR12 TR11 TR10 TR9 TR8 TR7 TR6 TR5 TR4 TR3 TR2 TR1 TR0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: The external wakeup lines are edge triggered, no 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
Res. Res. Res. Res. Res. Res. Res. Res. Res.
22 21 20 19 18 17 16
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER SWIER
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. PR22 PR21 PR20 PR19 PR18 PR17 PR16
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 39. 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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_IMR MR[22:0]
0x00
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_EMR MR[22:0]
0x04
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_SWIER SWIER[22:0]
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
EXTI_PR PR[22:0]
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
11.1 Introduction
The flexible memory controller (FMC) includes three memory controllers:
The NOR/PSRAM memory controller
The NAND memory controller
The Synchronous DRAM (SDRAM/Mobile LPSDR SDRAM) controller
except when crossing a page boundary (for PSRAM and SDRAM). In this case, the
AHB burst is broken into two FIFO entries.
The Write FIFO can be disabled by setting the WFDIS bit in the FMC_BCR1 register.
At startup the FMC pins must be configured by the user application. The FMC I/O pins which
are not used by the application can be used for other purposes.
The FMC registers that define the external device type and associated characteristics are
usually set at boot time and do not change until the next reset or power-up. However, the
settings can be changed at any time.
NOR/PSRAM
FMC_NL (or NADV)
signals
FMC_CLK
From clock NOR/PSRAM
controller NOR / PSRAM / SRAM
memory FMC_NBL[1:0]
HCLK shared signals
controller
FMC_A[25:0]
Shared signals
FMC_D[15:0]
FMC_NE[4:1]
Configuration
FMC_NOE NOR / PSRAM / SRAM
registers
NAND FMC_NWE shared signals
memory FMC_NWAIT
controller
FMC_NCE
NAND signals
FMC_INT
FMC_SDCLK
FMC_SDNWE
SDRAM FMC_SDCKE[1:0]
SDRAM signals
controller FMC_SDNE[1:0]
FMC_NRAS
FMC_NCAS
MS34471V3
Configuration registers
The FMC can be configured through a set of registers. Refer to Section 11.6.6, for a detailed
description of the NOR Flash/PSRAM controller registers. Refer to Section 11.7.7, for a
detailed description of the NAND Flash registers and to Section 11.8.5 for a detailed
description of the SDRAM controller registers.
Supported
Address Bank
memory type
0x6000 0000
NOR/PSRAM/
Bank 1
SRAM
4 x 64 MB
0x6FFF FFFF
0x7000 0000
Bank 2
Not used
0x7FFF FFFF
0x8000 0000
Bank 3 NAND Flash
4 x 64 MB memory
0x8FFF FFFF
0x9000 0000
Bank 4
Not used
0x9FFF FFFF
0xC000 0000
SDRAM Bank 1
4 x 64 MB
0xCFFF FFFF
SDRAM
0xD000 0000
SDRAM Bank 2
4 x 64 MB
0xDFFF FFFF
MSv30444V5
00 Bank 1 - NOR/PSRAM 1
01 Bank 1 - NOR/PSRAM 2
10 Bank 1 - NOR/PSRAM 3
11 Bank 1 - NOR/PSRAM 4
1. HADDR are internal AHB address lines that are translated to external memory.
The HADDR[25:0] bits contain the external memory address. Since HADDR is a byte
address whereas the memory is addressed at word level, the address actually issued to the
memory varies according to the memory data width, as shown in the following table.
For NAND Flash memory, the common and attribute memory spaces are subdivided into
three sections (see in Table 43 below) located in the lower 256 Kbytes:
Data section (first 64 Kbytes in the common/attribute memory space)
Command section (second 64 Kbytes in the common / attribute memory space)
Address section (next 128 Kbytes in the common / attribute memory space)
The application software uses the 3 sections to access the NAND Flash memory:
To sending a command to NAND Flash memory, the software must write the
command value to any memory location in the command section.
To specify the NAND Flash address that must be read or written, the software
must write the address value to any memory location in the address section. Since an
address can be 4 or 5 bytes long (depending on the actual memory size), several
consecutive write operations to the address section are required to specify the full
address.
To read or write data, the software reads or writes the data from/to any memory
location in the data section.
Since the NAND Flash memory automatically increments addresses, there is no need to
increment the address of the data section to access consecutive memory locations.
The following table shows SDRAM mapping for a 13-bit row, a 11-bit column and a 4 internal
bank configuration.
64 Mbytes:
8-bit HADDR[25:24] HADDR[23:11] HADDR[10:0]
4 x 8K x 2K
128 Mbytes:
16-bit HADDR[26:25] HADDR[24:12] HADDR[11:1]
4 x 8K x 2K x 2
1. When interfacing with a 16-bit memory, the FMC internally uses the HADDR[11:1] internal AHB address
lines to generate the external address. Whatever the memory width, FMC_A[0] has to be connected to the
external memory address A[0].
2. The AutoPrecharge is not supported. FMC_A[10] must be connected to the external memory address
A[10] but it will be always driven ‘low’.
The HADDR[27:0] bits are translated to external SDRAM address depending on the
SDRAM controller configuration:
Data size:8 or 16 bits
Row size:11, 12 or 13 bits
Column size: 8, 9, 10 or 11 bits
Number of internal banks: two or four internal banks
The following tables show the SDRAM address mapping versus the SDRAM controller
configuration.
Table 46. SDRAM address mapping with 8-bit data bus width(1)(2)
HADDR(AHB Internal Address Lines)
Row size
configuration
27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Bank
Res. Row[10:0] Column[7:0]
[1:0]
Bank
Res. Row[10:0] Column[8:0]
11-bit row size [1:0]
configuration Bank
Res. Row[10:0] Column[9:0]
[1:0]
Bank
Res. Row[10:0] Column[10:0]
[1:0]
Bank
Res. Row[11:0] Column[7:0]
[1:0]
Bank
Res. Row[11:0] Column[8:0]
12-bit row size [1:0]
configuration Bank
Res. Row[11:0] Column[9:0]
[1:0]
Bank
Res. Row[11:0] Column[10:0]
[1:0]
Bank
Res. Row[12:0] Column[7:0]
[1:0]
Bank
Res. Row[12:0] Column[8:0]
13-bit row size [1:0]
configuration Bank
Res. Row[12:0] Column[9:0]
[1:0]
Bank
Res. Row[12:0] Column[10:0]
[1:0]
1. BANK[1:0] are the Bank Address BA[1:0]. When only 2 internal banks are used, BA1 must always be set to ‘0’.
2. Access to Reserved (Res.) address range generates an AHB error.
Table 47. SDRAM address mapping with 16-bit data bus width(1)(2)
HADDR(AHB address Lines)
Row size
Configuration
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
Bank
Res. Row[10:0] Column[7:0] BM0(3)
[1:0]
Bank
11-bit row size Res. Row[10:0] Column[8:0] BM0
[1:0]
configuration Bank
Res. Row[10:0] Column[9:0] BM0
[1:0]
Bank
Res. Row[10:0] Column[10:0] BM0
[1:0]
Bank
Res. Row[11:0] Column[7:0] BM0
[1:0]
Bank
12-bit row size Res. Row[11:0] Column[8:0] BM0
[1:0]
configuration Bank
Res. Row[11:0] Column[9:0] BM0
[1:0]
Bank
Res. Row[11:0] Column[10:0] BM0
[1:0]
Bank
Res. Row[12:0] Column[7:0] BM0
[1:0]
Bank
13-bit row size Res. Row[12:0] Column[8:0] BM0
[1:0]
configuration Bank
Res. Row[12:0] Column[9:0] BM0
[1:0]
Re Bank
Row[12:0] Column[10:0] BM0
s. [1:0]
1. BANK[1:0] are the Bank Address BA[1:0]. When only 2 internal banks are used, BA1 must always be set to ‘0’.
2. Access to Reserved space (Res.) generates an AHB error.
3. BM0: is the byte mask for 16-bit access.
The FMC supports a wide range of devices through a programmable timings among which:
Programmable wait states (up to 15)
Programmable bus turnaround cycles (up to 15)
Programmable output enable and write enable delays (up to 15)
Independent read and write timings and protocol to support the widest variety of
memories and timings
Programmable continuous clock (FMC_CLK) output.
The FMC Clock (FMC_CLK) is a submultiple of the HCLK clock. It can be delivered to the
selected external device either during synchronous accesses only or during asynchronous
and synchronous accesses depending on the CCKEN bit configuration in the FMC_BCR1
register:
If the CCLKEN bit is reset, the FMC generates the clock (CLK) only during
synchronous accesses (Read/write transactions).
If the CCLKEN bit is set, the FMC generates a continuous clock during asynchronous
and synchronous accesses. To generate the FMC_CLK continuous clock, Bank 1 must
be configured in Synchronous mode (see Section 11.6.6: NOR/PSRAM controller
registers). Since the same clock is used for all synchronous memories, when a
continuous output clock is generated and synchronous accesses are performed, the
AHB data size has to be the same as the memory data width (MWID) otherwise the
FMC_CLK frequency is changed depending on AHB data transaction (refer to
Section 11.6.5: Synchronous transactions for FMC_CLK divider ratio formula).
The size of each bank is fixed and equal to 64 Mbytes. Each bank is configured through
dedicated registers (see Section 11.6.6: NOR/PSRAM controller registers).
The programmable memory parameters include access times (see Table 48) and support
for wait management (for PSRAM and NOR Flash accessed in Burst mode).
Asynchronous R 8 16 Y -
Asynchronous W 8 16 N -
Asynchronous R 16 16 Y -
Asynchronous W 16 16 Y -
NOR Flash Asynchronous R 32 16 Y Split into 2 FMC accesses
(muxed I/Os
and nonmuxed Asynchronous W 32 16 Y Split into 2 FMC accesses
I/Os) Asynchronous
R - 16 N Mode is not supported
page
Synchronous R 8 16 N -
Synchronous R 16 16 Y -
Synchronous R 32 16 Y -
Asynchronous R 8 16 Y -
Asynchronous W 8 16 Y Use of byte lanes NBL[1:0]
Asynchronous R 16 16 Y -
Asynchronous W 16 16 Y -
Asynchronous R 32 16 Y Split into 2 FMC accesses
PSRAM
(multiplexed Asynchronous W 32 16 Y Split into 2 FMC accesses
I/Os and non- Asynchronous
multiplexed R - 16 N Mode is not supported
page
I/Os)
Synchronous R 8 16 N -
Synchronous R 16 16 Y -
Synchronous R 32 16 Y -
Synchronous W 8 16 Y Use of byte lanes NBL[1:0]
Synchronous W 16/32 16 Y -
Asynchronous R 8 / 16 16 Y -
Asynchronous W 8 / 16 16 Y Use of byte lanes NBL[1:0]
SRAM and
ROM Asynchronous R 32 16 Y Split into 2 FMC accesses
Split into 2 FMC accesses
Asynchronous W 32 16 Y
Use of byte lanes NBL[1:0]
Memory transaction
A[25:0]
NBL[1:0]
NEx
NOE
NWE
High
data driven
D[15:0] by memory
ADDSET DATAST
HCLK cycles HCLK cycles
MS34477V1
Memory transaction
A[25:0]
NBL[1:0]
NEx
NOE
1HCLK
NWE
ADDSET (DATAST + 1)
HCLK cycles HCLK cycles
MS34478V1
The one HCLK cycle at the end of the write transaction helps guarantee the address and
data hold time after the NWE rising edge. Due to the presence of this HCLK cycle, the
DATAST value must be greater than zero (DATAST > 0).
A[25:0]
NBL[1:0]
NEx
NOE
NWE
High
ADDSET DATAST
HCLK cycles HCLK cycles
MS34479V1
Memory transaction
A[25:0]
NBL[1:0]
NEx
NOE
1HCLK
NWE
ADDSET (DATAST + 1)
HCLK cycles HCLK cycles
MSv40165V1
The differences compared with Mode 1 are the toggling of NOE and the independent read
and write timings.
A[25:0]
NADV
NEx
NOE
NWE
High
ADDSET DATAST
HCLK cycles HCLK cycles
MS34481V2
Memory transaction
A[25:0]
NADV
NEx
NOE
1HCLK
NWE
ADDSET (DATAST + 1)
HCLK cycles HCLK cycles
MS34482V2
Memory transaction
A[25:0]
NADV
NEx
NOE
1HCLK
NWE
ADDSET (DATAST + 1)
HCLK cycles HCLK cycles
MS34483V1
The differences with mode 1 are the toggling of NWE and the independent read and write
timings when extended mode is set (mode B).
Note: The FMC_BWTRx register is valid only if the Extended mode is set (mode B), otherwise its
content is don’t care.
Memory transaction
A[25:0]
NADV
NEx
NOE
NWE
High
ADDSET DATAST
HCLK cycles HCLK cycles
MS34484V1
Memory transaction
A[25:0]
NADV
NEx
NOE
1HCLK
NWE
ADDSET (DATAST + 1)
HCLK cycles HCLK cycles
MSv40166V1
The differences compared with mode 1 are the toggling of NOE and the independent read
and write timings.
Memory transaction
A[25:0]
NADV
NEx
NOE
NWE
High
ADDSET DATAST
HCLK cycles HCLK cycles
ADDHLD
HCLK cycles MS34486V1
A[25:0]
NADV
NEx
NOE
1HCLK
NWE
ADDSET (DATAST+ 1)
HCLK cycles HCLK cycles
ADDHLD
HCLK cycles
MSv40167V1
The differences with mode 1 are the toggling of NOE that goes on toggling after NADV
changes and the independent read and write timings.
A[25:16]
NADV
NEx
NOE
1HCLK
NWE
The difference with mode D is the drive of the lower address byte(s) on the data bus.
1. The memory asserts the WAIT signal aligned to NOE/NWE which toggles:
DATAST 4 HCLK + max_wait_assertion_time
2. The memory asserts the WAIT signal aligned to NEx (or NOE/NWE not toggling):
if
max_wait_assertion_time address_phase + hold_phase
then:
Memory transaction
A[25:0]
NOE
4HCLK
MS30463V2
Memory transaction
A[25:0]
NEx
1HCLK
NWE
3HCLK
MSv40168V1
Caution: Some NOR Flash memories include the NADV Low cycle in the data latency count, so that
the exact relation between the NOR Flash latency and the FMC DATLAT parameter can be
either:
NOR Flash latency = (DATLAT + 2) CLK clock cycles
or NOR Flash latency = (DATLAT + 3) CLK clock cycles
Some recent memories assert NWAIT during the latency phase. In such cases DATLAT can
be set to its minimum value. As a result, the FMC samples the data and waits long enough
to evaluate if the data are valid. Thus the FMC detects when the memory exits latency and
real data are processed.
Other memories do not assert NWAIT during latency. In this case the latency must be set
correctly for both the FMC and the memory, otherwise invalid data are mistaken for good
data, or valid data are lost in the initial phase of the memory access.
Single-burst transfer
When the selected bank is configured in Burst mode for synchronous accesses, if for
example an AHB single-burst transaction is requested on 16-bit memories, the FMC
performs a burst transaction of length 1 (if the AHB transfer is 16 bits), or length 2 (if the
AHB transfer is 32 bits) and de-assert the chip select signal when the last data is strobed.
Such transfers are not the most efficient in terms of cycles compared to asynchronous read
operations. Nevertheless, a random asynchronous access would first require to re-program
the memory access mode, which would altogether last longer.
Wait management
For synchronous NOR Flash memories, NWAIT is evaluated after the programmed latency
period, which corresponds to (DATLAT+2) CLK clock cycles.
If NWAIT is active (low level when WAITPOL = 0, high level when WAITPOL = 1), wait
states are inserted until NWAIT is inactive (high level when WAITPOL = 0, low level when
WAITPOL = 1).
When NWAIT is inactive, the data is considered valid either immediately (bit WAITCFG = 1)
or on the next clock edge (bit WAITCFG = 0).
During wait-state insertion via the NWAIT signal, the controller continues to send clock
pulses to the memory, keeping the chip select and output enable signals valid. It does not
consider the data as valid.
In Burst mode, there are two timing configurations for the NOR Flash NWAIT signal:
The Flash memory asserts the NWAIT signal one data cycle before the wait state
(default after reset).
The Flash memory asserts the NWAIT signal during the wait state
The FMC supports both NOR Flash wait state configurations, for each chip select, thanks to
the WAITCFG bit in the FMC_BCRx registers (x = 0..3).
HCLK
CLK
A[25:16] addr[25:16]
NADV
NWAIT
(WAITCFG = 0)
NWAIT
(WAITCFG = 1)
inserted wait state
ai15798c
Figure 50. Synchronous multiplexed read mode waveforms - NOR, PSRAM (CRAM)
HCLK
CLK
A[25:16] addr[25:16]
NEx
NOE
High
NWE
NADV
NWAIT
(WAITCFG=
0)
(DATLAT + 2) inserted wait state
CLK cycles
A/D[15:0] Addr[15:0] data data data data
1 clock 1 clock
cycle cycle
Data strobes Data strobes
ai17723f
1. Byte lane outputs (NBL are not shown; for NOR access, they are held high, and, for PSRAM (CRAM)
access, they are held low.
HCLK
CLK
A[25:16] addr[25:16]
NEx
Hi-Z
NOE
NWE
NADV
NWAIT
(WAITCFG = 0)
1. The memory must issue NWAIT signal one cycle in advance, accordingly WAITCFG must be programmed to 0.
2. Byte Lane (NBL) outputs are not shown, they are held low while NEx is active.
12 WREN 0x1
11 WAITCFG 0x0
10 Reserved 0x0
9 WAITPOL to be set according to memory
8 BURSTEN no effect on synchronous write
7 Reserved 0x1
6 FACCEN Set according to memory support
5-4 MWID As needed
3-2 MTYP 0x1
1 MUXEN As needed
0 MBKEN 0x1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CCLK CBURST
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. WFDIS CPSIZE[2:0]
EN RW
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ASYNC EXT WAIT WAIT WAIT BURST FACC MUX MBK
WREN Res. Res. MWID[1:0] MTYP[1:0]
WAIT MOD EN CFG POL EN EN EN EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
configure read accesses (this register) and one to configure write accesses (FMC_BWTRx
registers).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. ACCMOD[1:0] DATLAT[3:0] CLKDIV[3:0] BUSTURN[3:0]
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
DATAST[7:0] ADDHLD[3:0] ADDSET[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: PSRAMs (CRAMs) have a variable latency due to internal refresh. Therefore these
memories issue the NWAIT signal during the whole latency phase to prolong the latency as
needed.
With PSRAMs (CRAMs) the filled DATLAT must be set to 0, so that the FMC exits its latency
phase soon and starts sampling NWAIT from memory, then starts to read or write when the
memory is ready.
This method can be used also with the latest generation of synchronous Flash memories
that issue the NWAIT signal, unlike older Flash memories (check the datasheet of the
specific Flash memory being used).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. ACCMOD[1:0] Res. Res. Res. Res. Res. Res. Res. Res. BUSTURN[3:0]
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATAST[7:0] ADDHLD[3:0] ADDSET[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Theoretically, there is no capacity limitation as the FMC can manage as many address
cycles as needed.
Theoretically, there is no capacity limitation as the FMC can manage as many address
cycles as needed.
Asynchronous R 8 8 Y -
Asynchronous W 8 8 Y -
Asynchronous R 16 8 Y Split into 2 FMC accesses
NAND 8-bit
Asynchronous W 16 8 Y Split into 2 FMC accesses
Asynchronous R 32 8 Y Split into 4 FMC accesses
Asynchronous W 32 8 Y Split into 4 FMC accesses
Asynchronous R 8 16 Y -
Asynchronous W 8 16 N -
Asynchronous R 16 16 Y -
NAND 16-bit
Asynchronous W 16 16 Y -
Asynchronous R 32 16 Y Split into 2 FMC accesses
Asynchronous W 32 16 Y Split into 2 FMC accesses
Figure 52. NAND Flash controller waveforms for common memory access
HCLK
A[25:0]
NCEx
NREG, High
NIOW,
NIOR MEMxSET
+1 MEMxWAIT + 1 MEMxHOLD
NWE,
NOE (1)
MEMxHIZ + 1
write_data
read_data Valid
MS33733V3
1. NOE remains high (inactive) during write accesses. NWE remains high (inactive) during read accesses.
2. For write access, the hold phase delay is (MEMHOLD) HCLK cycles and for read access is
(MEMHOLD + 2) HCLK cycles.
to implement the prewait functionality needed by some NAND Flash memories (see
details in Section 11.7.5: NAND Flash prewait functionality).
4. The controller waits for the NAND Flash memory to be ready (R/NB signal high), before
starting a new access to the same or another memory bank. While waiting, the
controller holds the NCE signal active (low).
5. The CPU can then perform byte read operations from the common memory space to
read the NAND Flash page (data field + Spare field) byte by byte.
6. The next NAND Flash page can be read without any CPU command or address write
operation. This can be done in three different ways:
– by simply performing the operation described in step 5
– a new random address can be accessed by restarting the operation at step 3
– a new command can be sent to the NAND Flash device by restarting at step 2
When this functionality is required, it can be ensured by programming the MEMHOLD value
to meet the tWB timing. However any CPU read access to the NAND Flash memory has a
hold delay of (MEMHOLD + 2) HCLK cycles and CPU write access has a hold delay of
(MEMHOLD) HCLK cycles inserted between the rising edge of the NWE signal and the next
access.
To cope with this timing constraint, the attribute memory space can be used by
programming its timing register with an ATTHOLD value that meets the tWB timing, and by
keeping the MEMHOLD value at its minimum value. The CPU must then use the common
memory space for all NAND Flash read and write accesses, except when writing the last
address byte to the NAND Flash device, where the CPU must write to the attribute memory
space.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ECCPS[2:0] TAR3
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAR[2:0] TCLR[3:0] Res. Res. ECCEN PWID[1:0] PTYP PBKEN PWAITEN Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. FEMPT IFEN ILEN IREN IFS ILS IRS
r rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MEMHIZ[7:0] MEMHOLD[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
MEMWAIT[7:0] MEMSET[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
ATTHIZ[7:0] ATTHOLD[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
ATTWAIT[7:0] ATTSET[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
ECC[31:16]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ECC[15:0]
r r r r r r r r r r r r r r r r
SDRAM initialization
The initialization sequence is managed by software. If the two banks are used, the
initialization sequence must be generated simultaneously to Bank 1and Bank 2 by setting
the Target Bank bits CTB1 and CTB2 in the FMC_SDCMR register:
1. Program the memory device features into the FMC_SDCRx register. The SDRAM
clock frequency, RBURST and RPIPE must be programmed in the FMC_SDCR1
register.
2. Program the memory device timing into the FMC_SDTRx register. The TRP and TRC
timings must be programmed in the FMC_SDTR1 register.
3. Set MODE bits to ‘001’ and configure the Target Bank bits (CTB1 and/or CTB2) in the
FMC_SDCMR register to start delivering the clock to the memory (SDCKE is driven
high).
4. Wait during the prescribed delay period. Typical delay is around 100 μs (refer to the
SDRAM datasheet for the required delay after power-up).
5. Set MODE bits to ‘010’ and configure the Target Bank bits (CTB1 and/or CTB2) in the
FMC_SDCMR register to issue a “Precharge All” command.
6. Set MODE bits to ‘011’, and configure the Target Bank bits (CTB1 and/or CTB2) as well
as the number of consecutive Auto-refresh commands (NRFS) in the FMC_SDCMR
register. Refer to the SDRAM datasheet for the number of Auto-refresh commands that
should be issued. Typical number is 8.
7. Configure the MRD field according to the SDRAM device, set the MODE bits to '100',
and configure the Target Bank bits (CTB1 and/or CTB2) in the FMC_SDCMR register
to issue a "Load Mode Register" command in order to program the SDRAM device.
In particular:
a) the CAS latency must be selected following configured value in FMC_SDCR1/2
registers
b) the Burst Length (BL) of 1 must be selected by configuring the M[2:0] bits to 000 in
the mode register. Refer to SDRAM device datasheet.
If the Mode Register is not the same for both SDRAM banks, this step has to be
repeated twice, once for each bank, and the Target Bank bits set accordingly.
8. Program the refresh rate in the FMC_SDRTR register
The refresh rate corresponds to the delay between refresh cycles. Its value must be
adapted to SDRAM devices.
9. For mobile SDRAM devices, to program the extended mode register it should be done
once the SDRAM device is initialized: First, a dummy read access should be performed
while BA1=1 and BA=0 (refer to SDRAM address mapping section for BA[1:0] address
mapping) in order to select the extended mode register instead of the load mode
register and then program the needed value.
At this stage the SDRAM device is ready to accept commands. If a system reset occurs
during an ongoing SDRAM access, the data bus might still be driven by the SDRAM device.
Therefor the SDRAM device must be first reinitialized after reset before issuing any new
access by the NOR Flash/PSRAM/SRAM or NAND Flash controller.
Note: If two SDRAM devices are connected to the FMC, all the accesses performed at the same
time to both devices by the Command Mode register (Load Mode Register command) are
issued using the timing parameters configured for SDRAM Bank 1 (TMRD andTRAS
timings) in the FMC_SDTR1 register.
TRCD = 3
SDNE
SDCLK
A[12:0] Row n Cola Colb Colc Cold Cole Colf Cog Colh Coli Colj Colk Coll
NRAS
NCAS
SDNWE
DATA[15:0] Dna Dnb Dnc Dnd Dne Dnf Dng Dnh Dni Dnj Dnk Dnl
MS34488V3
SDNE
SDCLK
NRAS
NCAS
NWE
MS34489V2
The FMC SDRAM controller features a Cacheable read FIFO (6 lines x 32 bits). It is used to
store data read in advance during the CAS latency period and the RPIPE delay following the
below formula. The RBURST bit must be set in the FMC_SDCR1 register to anticipate the
next read access.
Number for anticipated data = CAS latency + 1 + (RPIPE delay)/2
Examples:
CAS latency = 3, RPIPE delay = 0: Four data (not committed) are stored in the FIFO.
CAS latency = 3, RPIPE delay = 2: Five data (not committed) are stored in the FIFO.
The read FIFO features a 14-bit address tag to each line to identify its content: 11 bits for the
column address, 2 bits to select the internal bank and the active row, and 1 bit to select the
SDRAM device
When the end of the row is reached in advance during an AHB burst read, the data read in
advance (not committed) are not stored in the read FIFO. For single read access, data are
correctly stored in the FIFO.
Each time a read request occurs, the SDRAM controller checks:
If the address matches one of the address tags, data are directly read from the FIFO
and the corresponding address tag/ line content is cleared and the remaining data in
the FIFO are compacted to avoid empty lines.
Otherwise, a new read command is issued to the memory and the FIFO is updated with
new data. If the FIFO is full, the older data are lost.
Figure 56. Logic diagram of Read access with RBURST bit set (CAS=1, RPIPE=0)
@0x04 Data 2
6 lines FIFO @0x08 Data 3
Data stored in FIFO
... ...
in advance during
Add. Tag read FIFO the CAS latency period
2nd Read access : Requested data was previously stored in the FIFO
@0x04 Data 2
6 lines FIFO @0x08 Data 3
... ...
Data read from FIFO
Add. Tag read FIFO
MS30445V2
During a write access or a Precharge command, the read FIFO is flushed and ready to be
filled with new data.
After the first read request, if the current access was not performed to a row boundary, the
SDRAM controller anticipates the next read access during the CAS latency period and the
RPIPE delay (if configured). This is done by incrementing the memory address. The
following condition must be met:
RBURST control bit should be set to ‘1’ in the FMC_SDCR1 register.
SDNE
SDCLK
Row n
NRAS
NCAS
NWE
TRP = 3 TRCD = 3
SDNE
SDCLK
NRAS
NCAS
NWE
If the next access is sequential and the current access crosses a bank boundary, the
SDRAM controller activates the first row in the next bank and initiates a new read/write
command. Two cases are possible:
If the current bank is not the last one, the active row in the new bank must be
precharged.At a bank boundary, the automatic activation of the next row is supported
for all rows/columns and data bus width configuration.
If the current bank is the last one and the selected SDRAM device is connected to
Bank 1, the automatic activation of the next row in device connected to SDRAM Bank2
is not supported. A PALL software command must be issused on Bank1 before any any
access on Bank2.
SDRAM controller refresh cycle
The Auto-refresh command is used to refresh the SDRAM device content. The SDRAM
controller periodically issues auto-refresh commands. An internal counter is loaded with the
COUNT value in the register FMC_SDRTR. This value defines the number of memory clock
cycles between the refresh cycles (refresh rate). When this counter reaches zero, an
internal pulse is generated.
If a memory access is ongoing, the auto-refresh request is delayed. However, if the memory
access and the auto-refresh requests are generated simultaneously, the auto-refresh
request takes precedence.
If the memory access occurs during an auto-refresh operation, the request is buffered and
processed when the auto-refresh is complete.
If a new auto-refresh request occurs while the previous one was not served, the RE
(Refresh Error) bit is set in the Status register. An Interrupt is generated if it has been
enabled (REIE = ‘1’).
If SDRAM lines are not in idle state (not all row are closed), the SDRAM controller generates
a PALL (Precharge ALL) command before the auto-refresh.
If the Auto-refresh command is generated by the FMC_SDCMR Command Mode register
(Mode bits = ‘011’), a PALL command (Mode bits =’ 010’) must be issued first.
Self-refresh mode
This mode is selected by setting the MODE bits to ‘101’ and by configuring the Target Bank
bits (CTB1 and/or CTB2) in the FMC_SDCMR register.
The SDRAM clock stops running after a TRAS delay and the internal refresh timer stops
counting only if one of the following conditions is met:
A Self-refresh command is issued to both devices
One of the devices is not activated (SDRAM bank is not initialized).
Before entering Self-Refresh mode, the SDRAM controller automatically issues a PALL
command.
If the Write data FIFO is not empty, all data are sent to the memory before activating the
Self-refresh mode and the BUSY status flag remains set.
In Self-refresh mode, all SDRAM device inputs become don’t care except for SDCKE which
remains low.
The SDRAM device must remain in Self-refresh mode for a minimum period of time of
TRAS and can remain in Self-refresh mode for an indefinite period beyond that. To
guarantee this minimum period, the BUSY status flag remains high after the Self-refresh
activation during a TRAS delay.
As soon as an SDRAM device is selected, the SDRAM controller generates a sequence of
commands to exit from Self-refresh mode. After the memory access, the selected device
remains in Normal mode.
To exit from Self-refresh, the MODE bits must be set to ‘000’ (Normal mode) and the Target
Bank bits (CTB1 and/or CTB2) must be configured in the FMC_SDCMR register.
SDCLK
tRAS(min)
SDCKE
DOM/
DOML/DOMU
A0- A9
A11, A12
A10 ALL
BANKS
Data[15:0] Hi-Z
tRP tXSR
Precharge all Exit Self-refresh mode
Enter Self-refresh mode
active banks (restart refresh timebase)
CLK stable prior to existing
Self-refresh mode
MS34492V1
Power-down mode
This mode is selected by setting the MODE bits to ‘110’ and by configuring the Target Bank
bits (CTB1 and/or CTB2) in the FMC_SDCMR register.
SDCLK
SDCKE
tRCD
All banks idle Input buffers gated off
tRAS
Enter Power-down Exit Power-down tRC
MS30451V1
If the Write data FIFO is not empty, all data are sent to the memory before activating the
Power-down mode.
As soon as an SDRAM device is selected, the SDRAM controller exits from the Power-down
mode. After the memory access, the selected SDRAM device remains in Normal mode.
During Power-down mode, all SDRAM device input and output buffers are deactivated
except for the SDCKE which remains low.
The SDRAM device cannot remain in Power-down mode longer than the refresh period and
cannot perform the Auto-refresh cycles by itself. Therefore, the SDRAM controller carries
out the refresh operation by executing the operations below:
1. Exit from Power-down mode and drive the SDCKE high
2. Generate the PALL command only if a row was active during Power-down mode
3. Generate the auto-refresh command
4. Drive SDCKE low again to return to Power-down mode.
To exit from Power-down mode, the MODE bits must be set to ‘000’ (Normal mode) and the
Target Bank bits (CTB1 and/or CTB2) must be configured in the FMC_SDCMR register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. RPIPE[1:0] RBURST SDCLK WP CAS NB MWID NR NC
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Before modifying the RBURST or RPIPE settings or disabling the SDCLK clock, the user
must first send a PALL command to make sure ongoing operations are complete.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. TRCD TRP TWR
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
TRC TRAS TXSR TMRD
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: If two SDRAM devices are connected, all the accesses performed simultaneously to both
devices by the Command Mode register (Load Mode Register command) are issued using
the timing parameters configured for Bank 1 (TMRD and TRAS timings) in the FMC_SDTR1
register.
The TRP and TRC timings are only configured in the FMC_SDTR1 register. If two SDRAM
devices are used, the TRP and TRC timings must be programmed with the timings of the
slowest device.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. MRD
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MRD NRFS CTB1 CTB2 MODE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Example
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. REIE COUNT CRE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw w
Note: The programmed COUNT value must not be equal to the sum of the following timings:
TWR+TRP+TRC+TRCD+4 memory clock cycles.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BUSY MODES2 MODES1 RE
r r r r r r
10
11
9
8
7
6
5
4
3
2
1
0
ASYNCWAIT
CBURSTRW
BURSTEN
WAITCFG
WAITPOL
EXTMOD
CCLKEN
FACCEN
WAITEN
MUXEN
MBKEN
WFDIS
WREN
Res.
Res.
FMC_BCR1
0x00 [2:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 1 1 0 1 1
ASYNCWAIT
CBURSTRW
BURSTEN
WAITCFG
WAITPOL
EXTMOD
FACCEN
WAITEN
MUXEN
MBKEN
WREN
Res.
Res.
FMC_BCR2
0x08 [2:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 1 0
ASYNCWAIT
CBURSTRW
BURSTEN
WAITCFG
WAITPOL
EXTMOD
FACCEN
WAITEN
MUXEN
MBKEN
WREN
Res.
Res.
FMC_BCR3
0x10 [2:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 1 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
ASYNCWAIT
CBURSTRW
BURSTEN
WAITCFG
WAITPOL
EXTMOD
FACCEN
WAITEN
MUXEN
MBKEN
WREN
CPSIZE MWID MTYP
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FMC_BCR4
0x18 [2:0] [1:0] [1:0]
Reset value 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 0 1 0
ACCMOD[1:0]
BUSTURN[3:0
Res.
Res.
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ACCMOD[1:0]
BUSTURN[3:0
Res.
Res.
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ACCMOD[1:0]
BUSTURN[3:0
Res.
Res.
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ACCMOD[1:0]
BUSTURN[3:0
Res.
Res.
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ACCMOD[1:0]
BUSTURN[3:0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ACCMOD[1:0]
BUSTURN[3:0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ACCMOD[1:0]
BUSTURN
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
ACCMOD[1:0]
BUSTURN
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reset value 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
PWAITEN
ECCEN
PBKEN
ECCPS PWID
PTYP
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0
FEMPT
IREN
IFEN
ILEN
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
IRS
FMC_SR
IFS
ILS
0x84
Reset value 1 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
FMC_PMEM MEMHIZx[7:0] MEMHOLDx[7:0] MEMWAITx[7:0] MEMSETx[7:0]
0x88
Reset value 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0
FMC_PATT ATTHIZ[7:0] ATTHOLD[7:0] ATTWAIT[7:0] ATTSET[7:0]
0x8C
Reset value 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0
FMC_ECCR ECCx[31:0]
0x94
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RBURST
RPIPE SDCLK CAS MWID NR
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FMC_SDCR1 WP NB NC
0x140 [1:0] [1:0] [1:0] [1:0] [1:0]
Reset value 0 0 0 1 1 0 1 0 0 1 0 0 0 0 0
RBURST
SDCLK CAS MWID NR
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FMC_SDCR2 WP NB NC
0x144 [1:0] [1:0] [1:0] [1:0]
Reset value 0 1 1 0 1 0 0 1 0 0 0 0 0
Res.
Res.
Res.
Res.
CTB1
CTB2
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CRE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FMC_SDRTR COUNT[12:0]
0x154
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
MODES2[1:0]
MODES1[1:0]
BUSY
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FMC_SDSR
0x158
Reset value 0 0 0 0 0
12.1 Introduction
The QUADSPI is a specialized communication interface targeting single, dual or quad SPI
Flash memories. It can operate in any of the three following modes:
indirect mode: all the operations are performed using the QUADSPI registers
status polling mode: the external Flash memory status register is periodically read and
an interrupt can be generated in case of flag setting
memory-mapped mode: the external Flash memory is mapped to the device address
space and is seen by the system as if it was an internal memory
Both throughput and capacity can be increased two-fold using dual-flash mode, where two
Quad-SPI Flash memories are accessed simultaneously.
nCS
SCLK
IO0 7 6 5 4 3 2 1 0 4 0 4 0 4 0 4 0 4 0 4 0
IO1 5 1 5 1 5 1 5 1 5 1 5 1
IO2 6 2 6 2 6 2 6 2 6 2 6 2
IO3 7 3 7 3 7 3 7 3 7 3 7 3
A23-16 A15-8 A7-0 M7-0 Byte 1 Byte 2
IO switch from
output to input MS35317V1
Instruction phase
During this phase, an 8-bit instruction, configured in INSTRUCTION field of
QUADSPI_CCR[7:0] register, is sent to the Flash memory, specifying the type of operation
to be performed.
Though most Flash memories can receive instructions only one bit at a time from the
IO0/SO signal (single SPI mode), the instruction phase can optionally send 2 bits at a time
(over IO0/IO1 in dual SPI mode) or 4 bits at a time (over IO0/IO1/IO2/IO3 in quad SPI
mode). This can be configured using the IMODE[1:0] field of QUADSPI_CCR[9:8] register.
When IMODE = 00, the instruction phase is skipped, and the command sequence starts
with the address phase, if present.
Address phase
In the address phase, 1-4 bytes are sent to the Flash memory to indicate the address of the
operation. The number of address bytes to be sent is configured in the ADSIZE[1:0] field of
QUADSPI_CCR[13:12] register. In indirect and automatic-polling modes, the address bytes
to be sent are specified in the ADDRESS[31:0] field of QUADSPI_AR register, while in
memory-mapped mode the address is given directly via the AHB (from the Cortex® or from
a DMA).
The address phase can send 1 bit at a time (over SO in single SPI mode), 2 bits at a time
(over IO0/IO1 in dual SPI mode), or 4 bits at a time (over IO0/IO1/IO2/IO3 in quad SPI
mode). This can be configured using the ADMODE[1:0] field of QUADSPI_CCR[11:10]
register.
When ADMODE = 00, the address phase is skipped, and the command sequence proceeds
directly to the next phase, if any.
Alternate-bytes phase
In the alternate-bytes phase, 1-4 bytes are sent to the Flash memory, generally to control
the mode of operation. The number of alternate bytes to be sent is configured in the
ABSIZE[1:0] field of QUADSPI_CCR[17:16] register. The bytes to be sent are specified in
the QUADSPI_ABR register.
The alternate-bytes phase can send 1 bit at a time (over SO in single SPI mode), 2 bits at a
time (over IO0/IO1 in dual SPI mode), or 4 bits at a time (over IO0/IO1/IO2/IO3 in quad SPI
mode). This can be configured using the ABMODE[1:0] field of QUADSPI_CCR[15:14]
register.
When ABMODE = 00, the alternate-bytes phase is skipped, and the command sequence
proceeds directly to the next phase, if any.
There may be times when only a single nibble needs to be sent during the alternate-byte
phase rather than a full byte, such as when dual-mode is used and only two cycles are used
for the alternate bytes. In this case, firmware can use quad-mode (ABMODE = 11) and send
a byte with bits 7 and 3 of ALTERNATE set to ‘1’ (keeping the IO3 line high), and bits 6 and
2 set to ‘0’ (keeping the IO2 line low). In this case the upper two bits of the nibble to be sent
are placed in bits 4:3 of ALTERNATE while the lower two bits are placed in bits 1 and 0. For
example, if the nibble 2 (0010) is to be sent over IO0/IO1, then ALTERNATE should be set
to 0x8A (1000_1010).
Dummy-cycles phase
In the dummy-cycles phase, 1-31 cycles are given without any data being sent or received,
in order to allow the Flash memory the time to prepare for the data phase when higher clock
frequencies are used. The number of cycles given during this phase is specified in the
DCYC[4:0] field of QUADSPI_CCR[22:18] register. In both SDR and DDR modes, the
duration is specified as a number of full CLK cycles.
When DCYC is zero, the dummy-cycles phase is skipped, and the command sequence
proceeds directly to the data phase, if present.
The operating mode of the dummy-cycles phase is determined by DMODE.
In order to assure enough “turn-around” time for changing the data signals from output
mode to input mode, there must be at least one dummy cycle when using dual or quad
mode to receive data from the Flash memory.
Data phase
During the data phase, any number of bytes can be sent to, or received from the Flash
memory.
In indirect and automatic-polling modes, the number of bytes to be sent/received is specified
in the QUADSPI_DLR register.
In indirect write mode the data to be sent to the Flash memory must be written to the
QUADSPI_DR register, while in indirect read mode the data received from the Flash
memory is obtained by reading from the QUADSPI_DR register.
In memory-mapped mode, the data which is read is sent back directly over the AHB to the
Cortex or to a DMA.
The data phase can send/receive 1 bit at a time (over SO/SI in single SPI mode), 2 bits at a
time (over IO0/IO1 in dual SPI mode), or 4 bits at a time (over IO0/IO1/IO2/IO3 in quad SPI
SDR mode
By default, the DDRM bit (QUADSPI_CCR[31]) is 0 and the QUADSPI operates in single
data rate (SDR) mode.
In SDR mode, when the QUADSPI is driving the IO0/SO, IO1, IO2, IO3 signals, these
signals transition only with the falling edge of CLK.
When receiving data in SDR mode, the QUADSPI assumes that the Flash memories also
send the data using CLK’s falling edge. By default (when SSHIFT = 0), the signals are
sampled using the following (rising) edge of CLK.
DDR mode
When the DDRM bit (QUADSPI_CCR[31]) is set to 1, the QUADSPI operates in double data
rate (DDR) mode.
In DDR mode, when the QUADSPI is driving the IO0/SO, IO1, IO2, IO3 signals in the
address/alternate-byte/data phases, a bit is sent on each of the falling and rising edges of
CLK.
The instruction phase is not affected by DDRM. The instruction is always sent using CLK’s
falling edge.
When receiving data in DDR mode, the QUADSPI assumes that the Flash memories also
send the data using both rising and falling CLK edges. When DDRM = 1, firmware must
clear SSHIFT bit (bit 4 of QUADSPI_CR). Thus, the signals are sampled one half of a CLK
cycle later (on the following, opposite edge).
nCS
SCLK
IO0 7 6 5 4 3 2 1 0 4 0 4 0 4 0 4 0 4 0 4 0
IO1 5 4 5 4 5 4 5 4 5 4 5 4
IO2 6 2 6 2 6 2 6 2 6 2 6 2
IO3 7 3 7 3 7 3 7 3 7 3 7 3
A23-16A15-8 A7-0 M7-0 Byte1Byte2
IO switch from
output to input MS35318V1
Dual-flash mode
When the DFM bit (bit 6 of QUADSPI_CR) is 1, the QUADSPI is in dual-flash mode, where
two external quad SPI Flash memories (FLASH 1 and FLASH 2) are used in order to
send/receive 8 bits (or 16 bits in DDR mode) every cycle, effectively doubling the throughput
as well as the capacity.
Each of the Flash memories use the same CLK and optionally the same nCS signals, but
each have separate IO0, IO1, IO2, and IO3 signals.
Dual-flash mode can be used in conjunction with single-bit, dual-bit, and quad-bit modes, as
well as with either SDR or DDR mode.
is set when the limit of the external SPI memory is reached according to the Flash memory
size defined in the QUADSPI_CR.
By default, the QUADSPI never stops its prefetch operation, keeping the previous read
operation active with nCS maintained low, even if no access to the Flash memory occurs for
a long time. Since Flash memories tend to consume more when nCS is held low, the
application might want to activate the timeout counter (TCEN = 1, bit 3 of QUADSPI_CR) so
that nCS is released after a period of TIMEOUT[15:0] (QUADSPI_LPTR) cycles have
elapsed without any access since when the FIFO becomes full with prefetch data.
BUSY goes high as soon as the first memory-mapped access occurs. Because of the
prefetch operations, BUSY does not fall until there is a timeout, there is an abort, or the
peripheral is disabled.
The QUADSPI is configured using the QUADSPI_CR. The user shall configure the clock
prescaler division factor and the sample shifting settings for the incoming data.
DDR mode can be set through the DDRM bit. When setting QUADSPI interface in DDR
mode, the internal divider of kernel clock must be set with a division ratio of 2 or more. Once
enabled, the address and the alternate bytes are sent on both clock edges and the data are
sent/received on both clock edges. Regardless of the DDRM bit setting, instructions are
always sent in SDR mode.
The DMA requests are enabled setting the DMAEN bit. In case of interrupt usage, their
respective enable bit can be also set during this phase.
FIFO level for either DMA request generation or interrupt generation is programmed in the
FTHRES bits.
If timeout counter is needed, the TCEN bit can be set and the timeout value programmed in
the QUADSPI_LPTR register.
Dual-flash mode can be activated by setting DFM to 1.
When writing the control register (QUADSPI_CR) the user specifies the following settings:
The enable bit (EN) set to ‘1’
The DMA enable bit (DMAEN) for transferring data to/from RAM
Timeout counter enable bit (TCEN)
Sample shift setting (SSHIFT)
FIFO threshold level (FTRHES) to indicate when the FTF flag should be set
Interrupt enables
Automatic polling mode parameters: match mode and stop mode (valid when
FMODE = 11)
Clock prescaler
When writing the communication configuration register (QUADSPI_CCR) the user specifies
the following parameters:
The instruction byte through the INSTRUCTION bits
The way the instruction has to be sent through the IMODE bits (1/2/4 lines)
The way the address has to be sent through the ADMODE bits (None/1/2/4 lines)
The address size (8/16/24/32-bit) through the ADSIZE bits
The way the alternate bytes have to be sent through the ABMODE (None/1/2/4 lines)
The alternate bytes number (1/2/3/4) through the ABSIZE bits
The presence or not of dummy bytes through the DBMODE bit
The number of dummy bytes through the DCYC bits
The way the data have to be sent/received (None/1/2/4 lines) through the DMODE bits
If neither the address register (QUADSPI_AR) nor the data register (QUADSPI_DR) need to
be updated for a particular command, then the command sequence starts as soon as
QUADSPI_CCR is written. This is the case when both ADMODE and DMODE are 00, or if
just ADMODE = 00 when in indirect read mode (FMODE = 01).
When an address is required (ADMODE is not 00) and the data register does not need to be
written (when FMODE = 01 or DMODE = 00), the command sequence starts as soon as the
address is updated with a write to QUADSPI_AR.
In case of data transmission (FMODE = 00 and DMODE! = 00), the communication start is
triggered by a write in the FIFO through QUADSPI_DR.
In case of match, the status match flag is set and an interrupt is generated if enabled, and
the QUADSPI can be automatically stopped if the AMPS bit is set.
In any case, the latest retrieved value is available in the QUADSPI_DR.
Memory-mapped mode
In memory-mapped mode, the external Flash memory is seen as internal memory but with
some latency during accesses. Only read operations are allowed to the external Flash
memory in this mode.
Memory-mapped mode is entered by setting the FMODE to 11 in the QUADSPI_CCR
register.
The programmed instruction and frame is sent when a master is accessing the memory
mapped space.
The FIFO is used as a prefetch buffer to anticipate linear reads. Any access to
QUADSPI_DR in this mode returns zero.
The data length register (QUADSPI_DLR) has no meaning in memory-mapped mode.
In indirect mode, the BUSY bit is reset once the QUADSPI has completed the requested
command sequence and the FIFO is empty.
In automatic-polling mode, BUSY goes low only after the last periodic access is complete,
due to a match when APMS = 1, or due to an abort.
After the first access in memory-mapped mode, BUSY goes low only on a timeout event or
on an abort.
Any operation can be aborted by setting the ABORT bit in the QUADSPI_CR. Once the
abort is completed, the BUSY bit and the ABORT bit are automatically reset, and the FIFO
is flushed.
Note: Some Flash memories might misbehave if a write operation to a status registers is aborted.
nCS
SCLK
MS35319V1
When CKMODE=1 (“mode3”, where CLK goes high when no operation is in progress) and
DDRM=0 (SDR mode), nCS still falls one CLK cycle before an operation first rising CLK
edge, and nCS rises one CLK cycle after the operation final rising CLK edge, as shown in
Figure 66.
nCS
SCLK
MS35320V1
When CKMODE = 1 (“mode3”) and DDRM = 1 (DDR mode), nCS falls one CLK cycle
before an operation first rising CLK edge, and nCS rises one CLK cycle after the operation
final active rising CLK edge, as shown in Figure 67. Because DDR operations must finish
with a falling edge, CLK is low when nCS rises, and CLK rises back up one half of a CLK
cycle afterwards.
T T T/2
nCS
SCLK
MS35321V1
When the FIFO stays full in a read operation or if the FIFO stays empty in a write operation,
the operation stalls and CLK stays low until firmware services the FIFO. If an abort occurs
when an operation is stalled, nCS rises just after the abort is requested and then CLK rises
one half of a CLK cycle later, as shown in Figure 68.
nCS
SCLK
Abort
MS35322V1
When not in dual-flash mode (DFM = 0) and FSEL = 0 (default value), only FLASH 1 is
accessed and thus BK2_nCS stays high, if FSEL = 1, only FLASH 2 is accessed and
BK1_nCS stays high. In dual-flash mode, BK2_nCS behaves exactly the same as
BK1_nCS. Thus, if there is a FLASH 2 and if the application is dual-flash mode only, then
BK1_nCS signal can be used for FLASH 2 as well, and the pin devoted to BK2_nCS can be
used for other functions.
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. FTHRES[4:0] FSEL DFM Res. SSHIFT TCEN DMAEN ABORT 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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FSIZE[4:0]
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CK
Res. Res. Res. Res. Res. CSHT[2:0] Res. Res. Res. Res. Res. Res. Res.
MODE
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. FLEVEL[5:0] Res. Res. BUSY TOF SMF FTF TCF TEF
r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. CTOF CSMF Res. CTCF CTEF
w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DL[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
DL[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw 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
ADDRESS[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
ADDRESS[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
ALTERNATE[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
ALTERNATE[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
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MASK[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
MASK[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
MATCH[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
MATCH[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
INTERVAL[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIMEOUT[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
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
name
DMAEN
SSHIFT
ABORT
APMS
FTHRES
TCEN
FSEL
SMIE
PMM
TOIE
TCIE
TEIE
DFM
FTIE
Res.
Res.
Res.
Res.
Res.
QUADSPI_CR PRESCALER[7:0]
EN
[4:0]
0x0000
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CKMODE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
QUADSPI_DCR FSIZE[4:0] CSHT
0x0004
Reset value 0 0 0 0 0 0 0 0 0
SMF
BUS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TOF
TCF
TEF
FTF
QUADSPI_SR FLEVEL[5:0]
0x0008
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
CSMF
CTOF
CTCF
CTEF
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
QUADSPI_FCR
0x000C
Reset value 0 0 0 0
QUADSPI_DLR DL[31:0]
0x0010
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADMODE[1:0]
ABMODE[1:0]
DMODE[1:0]
FMODE[1:0]
ADSIZE[1:0]
ABSIZE[1:0]
IMODE[1:0]
DDRM
DHHC
SIOO
Res.
Res.
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
QUADSPI_AR ADDRESS[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
QUADSPI_ABR ALTERNATE[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
QUADSPI_DR DATA[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
QUADSPI_
MASK[31:0]
0x0024 PSMKR
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
QUADSPI_
MATCH[31:0]
0x0028 PSMAR
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
QUADSPI_PIR INTERVAL[15:0]
0x002C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
QUADSPI_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMEOUT[15:0]
LPTR
0x0030
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
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
ADC1
Channel selection
VIN[0]
ADC123_IN0
VIN[1]
ADC123_IN1
VIN[2]
ADC123_IN2
VIN[3]
ADC123_IN3
VIN[4]
ADC12_IN4
VIN[5]
ADC12_IN5
VIN[6]
ADC12_IN6 VREF+
VIN[7]
ADC12_IN7
VIN[10]
ADC123_IN10 VREF-
VIN[11]
ADC123_IN11
VIN[12]
ADC123_IN12
VIN[13]
ADC123_IN13
VIN[14]
ADC12_IN14
VIN[15]
ADC12_IN15
VIN[16]
N.C.
VIN[17]
VREFINT
VIN[18]
VBAT/4 or VSENSE
MSv35937V1
ADC2
Channel selection
VIN[0]
ADC123_IN0
VIN[1]
ADC123_IN1
VIN[2]
ADC123_IN2
VIN[3]
ADC123_IN3
VIN[4]
ADC12_IN4
VIN[5]
ADC12_IN5
VIN[6]
ADC12_IN6 VREF+
VIN[7]
ADC12_IN7
VIN[10]
ADC123_IN10 VREF-
VIN[11]
ADC123_IN11
VIN[12]
ADC123_IN12
VIN[13]
ADC123_IN13
VIN[14]
ADC12_IN14
VIN[15]
ADC12_IN15
VIN[16]
N.C.
VIN[17]
N.C.
VIN[18]
N.C.
MSv35938V1
ADC3
Channel selection
VIN[0]
ADC123_IN0
VIN[1]
ADC123_IN1
VIN[2]
ADC123_IN2
VIN[3]
ADC123_IN3
VIN[4]
ADC3_IN4
VIN[5]
ADC3_IN5
VIN[6]
ADC3_IN6 VREF+
VIN[7]
ADC3_IN7
VIN[10]
ADC123_IN10 VREF-
VIN[11]
ADC123_IN11
VIN[12]
ADC123_IN12
VIN[13]
ADC123_IN13
VIN[14]
ADC3_IN14
VIN[15]
ADC3_IN15
VIN[16]
N.C.
VIN[17]
N.C.
VIN[18]
N.C.
MSv35939V1
ADC_CLK
ADON
SWSTART/
JSWSTART
Analog voltage
Higher threshold HTR
Guarded area
Lower threshold LTR
ai16048
None x 0 0
All injected channels 0 0 1
Note: When using triggered injection, one must ensure that the interval between trigger events is
longer than the injection sequence. For instance, if the sequence length is 30 ADC clock
cycles (that is two conversions with a sampling time of 3 clock periods), the minimum
interval between triggers must be 31 ADC clock cycles.
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 STM32F446xx datasheets.
Example:
n = 3, channels to be converted = 0, 1, 2, 3, 6, 7, 9, 10
1st trigger: sequence converted 0, 1, 2. An EOC event is generated at each
conversion.
2nd trigger: sequence converted 3, 6, 7. An EOC event is generated at each
conversion
3rd trigger: sequence converted 9, 10.An EOC event is generated at each conversion
4th trigger: sequence converted 0, 1, 2. An EOC event is generated at each conversion
Note: When a regular group is converted in discontinuous mode, no rollover occurs.
When all subgroups are converted, the next trigger starts the conversion of the first
subgroup. In the example above, the 4th trigger reconverts the channels 0, 1 and 2 in the
1st subgroup.
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 78.
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 87 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. Interleaved
dual and triple modes are supported:
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.
The minimum delay which separates 2 conversions in interleaved mode is configured in the
DELAY bits in the ADC_CCR register. However, an ADC cannot start a conversion if the
complementary ADC is still sampling its input (only one ADC can sample the input signal at
a given time). 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 both ADCs,
then 17 clock cycles will separate conversions on ADC1 and ADC2).
If the CONT bit is set on both ADC1 and ADC2, the selected regular channels of both 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.
After an EOC interrupt is generated by ADC2 (if enabled through the EOCIE bit) a 32-bit
DMA transfer request is generated (if the DMA[1:0] bits in ADC_CCR are equal to 0b10).
This request first transfers the ADC2 converted data stored in the upper half-word of the
ADC_CDR 32-bit register into SRAM, then the ADC1 converted data stored in the register’s
lower half-word into SRAM.
Figure 84. Interleaved mode on 1 channel in continuous conversion mode: dual ADC
mode
End of conversion on ADC1 Sampling
Trigger
End of conversion on ADC2
8 ADCCLK
cycles ai16056
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 85. Interleaved mode on 1 channel in continuous conversion mode: triple ADC
mode
End of conversion on ADC1
6 ADCCLK
cycles ai16058
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 by converting the injected ADC1
channels in the group.
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 87. 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
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.
A JEOC interrupt, if enabled, is generated after all injected ADC3 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 by converting the injected ADC1
channels in the group.
ADC1 ...
ADC2
2nd trigger
3rd trigger (n+1)th trigger
Otherwise, the ADC with the shortest sequence may restart while the ADC with the longest
sequence is completing the previous conversions.
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.
CH0
ADC2 inj
synchro not lost
If a trigger occurs during an injected conversion that has interrupted a regular conversion, it
is ignored. Figure 90 shows the behavior in this case (2nd trigger is ignored).
CH0
ADC2 inj
When not in use, the sensor can be put in power down mode.
Note: The TSVREFE bit must be set to enable the conversion of both internal channels: the
ADC1_IN18 (temperature sensor) and the ADC1_IN17 (VREFINT).
Main features
Supported temperature range: –40 to 125 °C
Precision: ±1.5 °C
Temperature V SENSE
sensor ADC1_IN18
Address/data bus
converted data
ADC1
VREFINT
Internal
power block ADC1_IN17
MS35936V1
Note: The sensor has a startup time after waking from power down mode before it can output
VSENSE at the correct level. The ADC also has a startup time after power-on, so to minimize
the delay, the ADON and TSVREFE bits should be set at the same time.
The temperature sensor output voltage changes linearly with temperature. The offset of this
linear function depends on each chip due to process variation (up to 45 °C from one chip to
another).
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. OVR STRT JSTRT JEOC EOC AWD
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
Res. Res. Res. Res. Res. OVRIE RES AWDEN JAWDEN Res. Res. Res. Res. Res. Res.
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DISCNUM[2:0] JDISCEN DISCEN JAUTO AWDSGL SCAN JEOCIE AWDIE EOCIE AWDCH[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
Res. SWSTART EXTEN EXTSEL[3:0] Res. JSWSTART JEXTEN JEXTSEL[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. ALIGN EOCS DDS DMA Res. Res. Res. Res. Res. Res. CONT ADON
rw rw rw rw rw rw
Bit 8 DMA: Direct memory access mode (for single ADC mode)
This bit is set and cleared by software. Refer to the DMA controller chapter for more details.
0: DMA mode disabled
1: DMA mode enabled
Bits 7:2 Reserved, must be kept at reset value.
Bit 1 CONT: Continuous conversion
This bit is set and cleared by software. If it is set, conversion takes place continuously until it
is cleared.
0: Single conversion mode
1: Continuous conversion mode
Bit 0 ADON: A/D Converter ON / OFF
This bit is set and cleared by software.
0: Disable ADC conversion and go to power down mode
1: Enable ADC
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. SMP18[2:0] SMP17[2:0] SMP16[2:0] SMP15[2:1]
rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SMP15_0 SMP14[2:0] SMP13[2:0] SMP12[2:0] SMP11[2:0] SMP10[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. SMP9[2:0] SMP8[2:0] SMP7[2:0] SMP6[2:0] SMP5[2:1]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SMP5_0 SMP4[2:0] SMP3[2:0] SMP2[2:0] SMP1[2:0] SMP0[2:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. JOFFSETx[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. HT[11:0]
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. LT[11:0]
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
Res. Res. Res. Res. Res. Res. Res. Res. L[3:0] SQ16[4:1]
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SQ16_0 SQ15[4:0] SQ14[4:0] SQ13[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
Res. Res. SQ12[4:0] SQ11[4:0] SQ10[4:1]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. JL[1:0] JSQ4[4:1]
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
JDATA[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATA[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OVR3 STRT3 JSTRT3 JEOC 3 EOC3 AWD3
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
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
Res. Res. 2 Res. Res.
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
Res. Res. Res. Res. Res. Res. Res. Res. TSVREFE VBATE Res. Res. Res. Res. ADCPRE
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMA[1:0] DDS Res. DELAY[3:0] Res. Res. Res. MULTI[4:0]
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 91. 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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_SR
0x00
Reset value 0 0 0 0 0 0
Table 91. ADC register map and reset values for each ADC (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
AWD SGL
JDISCEN
JAWDEN
RES[1:0]
DISCEN
AWDEN
JEOCIE
JAUTO
AWDIE
OVRIE
EOCIE
SCAN
DISC
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_CR1 AWDCH[4:0]
0x04 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]
SWSTART
ALIGN
ADON
CONT
EOCS
JEXTSEL
DMA
DDS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_CR2 EXTSEL [3:0]
0x08 [3:0]
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_JOFR1 JOFFSET1[11:0]
0x14
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_JOFR2 JOFFSET2[11:0]
0x18
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_JOFR3 JOFFSET3[11:0]
0x1C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_JOFR4 JOFFSET4[11:0]
0x20
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_HTR HT[11:0]
0x24
Reset value 1 1 1 1 1 1 1 1 1 1 1 1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_LTR LT[11:0]
0x28
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_JDR1 JDATA[15:0]
0x3C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_JDR2 JDATA[15:0]
0x40
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_JDR3 JDATA[15:0]
0x44
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_JDR4 JDATA[15:0]
0x48
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 91. ADC register map and reset values for each ADC (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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_DR Regular DATA[15:0]
0x4C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Table 92. 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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_CSR
0x00
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
DDS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
ADC_CCR DELAY [3:0] MULTI [4:0]
0x04
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
Trigger selectorx
TIM2_T RGO
TIM4_T RGO DMAENx
TIM5_TRGO
TIM6_T RGO
TIM7_T RGO
TIM8_TRGO
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 DAC1_ OU T1/2
VSSA
converterx
VR EF+
ai14708d
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).
Note: The ENx bit enables the analog DAC channelx macrocell only. The DAC channelx digital
interface is enabled even if the ENx bit is reset.
TSEL1[2:0] VREF+
12 Bypass, when
8 off
CH1 DAC Buffer PA4
DAC_CR.BOFF2
MSv35941V1
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 96. Timing diagram for conversion with trigger disabled TEN = 0
APB1_CLK
DHR 0x1AC
Output voltage
DOR 0x1AC available on DAC_OUT pin
tSETTLING ai14711b
Each time a DAC interface detects a rising edge on the selected timer TRGO output, or on
the selected external interrupt line 9, the last data stored into the DAC_DHRx register 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 98. DAC conversion (SW trigger enabled) with LFSR wave generation
APB1_CLK
DHR 0x00
SWTRIG
ai14714b
Note: The DAC trigger must be enabled for noise generation by setting the TENx bit in the
DAC_CR register.
De
n
tio
cr
ta
em
en
en
em
ta
cr
tio
In
n
DAC_DHRx base value
0
ai14715c
Figure 100. 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.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SWTRIG2 SWTRIG1
w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. DACC1DHR[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DACC1DHR[11:0] Res. Res. Res. Res.
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. DACC1DHR[7:0]
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. DACC2DHR[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DACC2DHR[11:0] Res. Res. Res. Res.
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. DACC2DHR[7:0]
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DACC2DHR[7:0] DACC1DHR[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. DACC1DOR[11:0]
r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. DACC2DOR[11:0]
r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. DMAUDR2 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. DMAUDR1 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rc_w1
0x2C
0x1C
0x0C
Offset
RM0390
14.5.15
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DAC_
DOR2
DOR1
name
DHR8R2
DHR8R1
DAC_SR
DAC_CR
DHR8RD
DHR12L2
DHR12L1
DHR12R2
DHR12R1
DHR12LD
DHR12RD
SWTRIGR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
0
0
0
DMAUDR2 Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMAUDRIE2 29
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DMAEN2 28
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
DAC register map
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 0
25
MAMP2[3:0]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
DACC2DHR[11:0]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
WAVE2[2:0]
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TSEL2[2:0] 20
DACC2DHR[11:0]
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Table 95 summarizes the DAC registers.
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. TEN2 18
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BOFF2 17
RM0390 Rev 6
Reserved
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EN2 16
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 15
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
Table 95. DAC register map
14
0
0
0
0
0
0
DMAUDR1 Res. Res. Res. Res. Res. Res. Res. Res. DMAUDRIE1 13
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. DMAEN1 12
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
DACC2DHR[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
DACC1DHR[11:0]
DACC2DHR[11:0]
DACC1DHR[11:0]
0
0
0
0
0
0
0
0
0
0
0
0
Res. Res. 7
WAVE1[2:0]
0
0
0
0
0
0
0
0
0
0
0
0
Res. Res. 6
0
0
0
0
0
0
0
0
0
0
0
0
Res. Res. 5
0
0
0
0
0
0
0
0
0
0
0
0
DACC2DOR[11:0]
DACC1DOR[11:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
DACC1DHR[7:0]
DACC2DHR[7:0]
DACC1DHR[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
423/1347
Digital-to-analog converter (DAC)
423
Digital camera interface (DCMI) RM0390
15.1 Introduction
The digital camera is a synchronous parallel interface able to receive a high-speed data flow
from an external 8-, 10-, 12- or 14-bit CMOS camera module. It supports different data
formats: YCbCr4:2:2/RGB565 progressive video and compressed data (JPEG).
DMA
Control/Statusregister
interface
AHB
interface
FIFO
Data Synchronizer DCMI_PIXCLK
Data
extraction
formatter
DMA_REQ
ai15603c
8 bits DCMI_D[7:0]
10 bits DCMI_D[9:0]
Inputs DCMI data
12 bits DCMI_D[11:0]
14 bits DCMI_D[13:0]
DCMI_PIXCLK Input Pixel clock
DCMI_HSYNC Input Horizontal synchronization / Data valid
DCMI_VSYNC Input Vertical synchronization
from the camera are stable and can be sampled. The maximum DCMI_PIXCLK period must
be higher than 2.5 HCLK periods.
DCMI_PIXCLK
DCMI_D[13:0]
DCMI_HSYNC
DCMI_VSYNC
ai15606c
1. The capture edge of DCMI_PIXCLK is the falling edge, the active state of DCMI_HSYNC and
DCMI_VSYNC is 1.
2. DCMI_HSYNC and DCMI_VSYNC can change states at the same time.
8-bit data
When EDM[1:0] = 00 in DCMI_CR the interface captures 8 LSBs at its input (DCMI_D[7:0])
and stores them as 8-bit data. The DCMI_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. The table below gives
an example of the positioning of captured data bytes in two 32-bit words.
Table 97. 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] = 01 in DCMI_CR, the camera interface captures 10-bit data at its input
DCMI_D[9:0] and stores them as the 10 least significant bits of a 16-bit word. The remaining
most significant bits of 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 the table below.
Table 98. 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] = 10 in DCMI_CR, the camera interface captures the 12-bit data at its input
DCMI_D[11:0] 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 the table below.
Table 99. 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] = 11 in DCMI_CR, the camera interface captures the 14-bit data at its input
DCMI_D[13:0] 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 the table below.
Table 100. 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]
Padding data
at the end of the JPEG stream
Beginning of JPEG stream Programmable
JPEG packet size
JPEG data
DCMI_VSYNC
ai15944b
capture is enabled (CAPTURE bit set in DCMI_CR), data transfer is synchronized with the
deactivation of the DCMI_VSYNC signal (next start of frame).
Transfer can then be continuous, with successive frames transferred by DMA to successive
buffers or the same/circular buffer. To allow the DMA management of successive frames, a
VSIF (Vertical synchronization interrupt flag) is activated at the end of each frame.
detect a frame/line start or frame/line end. This means that there can be different codes for
the frame/line start and frame/line end with the unmasked bit position remaining the same.
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
VST[12:0] in DCMI_CWSTRT
VLINE[13:0] in DCMI_CWSIZE
HOFFCNT[13:0]
in
CAPCNT[13:0] in DCMI_CWSIZE
DCMI_CWSTRT
MS35933V3
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 DCMI_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
Monochrome format
Characteristics:
Raster format
8 bits per pixel
The table below shows how the data are stored.
RGB format
Characteristics:
Raster format
RGB
Interleaved: one buffer: R, G and B interleaved (such as BRGBRGBRG)
Optimized for display output
The RGB planar format is compatible with standard OS frame buffer display formats.
Only 16 BPP (bits per pixel): RGB565 (2 pixels per 32-bit word) is supported.
The 24 BPP (palletized format) and gray-scale formats are not supported. Pixels are stored
in a raster scan order, that is from top to bottom for pixel rows, and from left to right within a
pixel row. Pixel components are R (red), G (green) and B (blue). All components have the
same spatial resolution (4:4:4 format). A frame is stored in a single part, with the
components interleaved on a pixel basis.
The table below shows how the data are stored.
YCbCr format
Characteristics:
Raster format
YCbCr 4:2:2
Interleaved: one buffer: Y, Cb and Cr interleaved (such as CbYCrYCbYCr)
Pixel components are Y (luminance or “luma”), Cb and Cr (chrominance or “chroma” blue
and red). Each component is encoded in 8 bits. Luma and chroma are stored together
(interleaved) as shown in the table below.
0 Yn+1 Cr n Yn Cb n
4 Yn+3 Cr n + 2 Yn+2 Cb n + 2
Table 104. Data storage in YCbCr progressive video format - Y extraction mode
Byte address 31:24 23:16 15:8 7:0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. OELS LSM OEBS BSM[1:0]
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ENABL PCKPO CAPTU
Res. Res. Res. EDM[1:0] FCRC[1:0] VSPOL HSPOL ESS JPEG CROP CM
E L RE
rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FNE VSYNC HSYNC
r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LINE VSYNC ERR OVR FRAME
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
_RIS _RIS _RIS _RIS _RIS
r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LINE VSYNC ERR OVR FRAME
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
_IE _IE _IE _IE _IE
rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LINE VSYNC ERR OVR FRAME
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
_MIS _MIS _MIS _MIS _MIS
r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LINE VSYNC ERR OVR FRAME
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
_ISC _ISC _ISC _ISC _ISC
w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FEC[7:0] LEC[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
LSC[7:0] FSC[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
FEU[7:0] LEU[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
LSU[7:0] FSU[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. VST[12:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. HOFFCNT[13:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. VLINE[13:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. CAPCNT[13:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BYTE3[7:0] BYTE2[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
BYTE1[7:0] BYTE0[7:0]
r r r r r r r r r r r r r r r r
0x1C
0x0C
Offset
RM0390
15.5.12
name
DCMI_SR
DCMI_CR
DCMI_DR
DCMI_RIS
DCMI_IER
DCMI_ICR
DCMI_MIS
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
DCMI_ESUR
DCMI_ESCR
DCMI_CWSIZE
DCMI_CWSTRT
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 31
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 30
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. 29
0
0
0
0
0
Res. Res. Res. Res. Res. Res. 28
0
0
0
0
0
Res. Res. Res. Res. Res. Res. 27
FEU[7:0]
FEC[7:0]
BYTE3[7:0]
0
0
0
0
0
Res. Res. Res. Res. Res. Res. 26
DCMI register map
0
0
0
0
0
Res. Res. Res. Res. Res. Res. 25
0
0
0
0
0
Res. Res. Res. Res. Res. Res. 24
0
0
0
0
0
Res. Res. Res. Res. Res. Res. 23
0
0
0
0
0
Res. Res. Res. Res. Res. Res. 22
VLINE[13:0]
0
0
0
0
0
Res. Res. Res. Res. Res. Res.
VST[12:0]
21
0
0
0
0
0
0
0
0
0
0
0
0
LEU[7:0]
LEC[7:0]
BYTE2[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
RM0390 Rev 6
Res. Res. Res. Res. Res. 17
BSM[1:0]
0
0
0
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 15
0
0
0
0
0
0
0
0
0
Res. Res. Res. Res. Res. Res.
0
0
0
0
0
Res. Res. Res. Res. Res. Res. 12
0
0
0
0
0
0
LSU[7:0]
LSC[7:0]
EDM[1:0]
Table 106. DCMI register map and reset values
BYTE1[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
CAPCNT[13:0]
5
HOFFCNT[13:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
BYTE0[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
447/1347
0
447
Advanced-control timers (TIM1&TIM8) RM0390
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
CC4I CC4I
TI1 TI1FP1
OC2
Input filter & IC1 IC1PS Capture/Compare OC1REF Output
Prescaler DTG
TIMx_CH2N
Edge detector 1 Register control
TI1FP2
U
TRC CC3I CC3I
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 CC2I CC2I
TIMx_CH3
TI3FP3 OC3
TI3 Input filter & IC3 IC3PS Capture/Compare OC3REF
Prescaler DTG Output
Edge detector 3 Register control
TI3FP4 U
OC3N
TRC CC1I CC1I
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
MS39906V2
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 111 and Figure 112 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 111. 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 112. 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
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
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
MS31186V1
CK_PSC
Timerclock = CK_CNT
Counter register 20 1F 00 36
Counter underflow
MS31187V1
Figure 123. Counter timing diagram, update event when repetition counter is not used
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 05 04 03 02 01 00 36 35 34 33 32 31 30 2F
Counter underflow
Auto-reload preload
register FF 36
DMA request is sent). This is to avoid generating both update and capture interrupts when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
The repetition counter is reloaded with the content of TIMx_RCR register
The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register)
The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that if the update source is a counter overflow, the auto-
reload is updated before the counter is reloaded, so that the next period is the expected
one (the counter is loaded with the new value).
The following figures show some examples of the counter behavior for different clock
frequencies.
Figure 124. 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 16.4: TIM1&TIM8 registers).
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter underflow
CK_PSC
CNT_EN
Timerclock = CK_CNT
Counter overflow
Timerclock = CK_CNT
Counter register 20 1F 01 00
Counter underflow
Figure 128. 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
MS31193V2
Figure 129. 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 130. Update rate examples depending on mode and TIMx_RCR register
settings
TIMx_RCR = 0
UEV
TIMx_RCR = 1
UEV
UEV
TIMx_RCR = 2
TIMx_RCR = 3 UEV
TIMx_RCR = 3
and
UEV
re-synchronization
(by SW) (by SW) (by SW)
UEV Update event: Preload registers transferred to active registers and update interrupt generated
Update Event if the repetition counter underflow occurs when the counter is equal to the auto-reload value.
MSv31195V1
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 it does not need to be configured.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF=0
MS31087V2
or TI2F or
TI1F or Encoder
mode
ECE SMS[2:0]
TIMx_SMCR
MS33116V1
For example, to configure the upcounter to count each 2 rising edges on ETR, use the
following procedure:
f CK_INT
CNT_EN
ETR
ETRP
ETRF
Counter clock =
CK_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 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
MS31089V2
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.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
To force an output compare signal (OCXREF/OCx) to its active level, one just needs to write
101 in the OCxM bits in the corresponding TIMx_CCMRx register. Thus OCXREF is 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
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.
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
OCxREF
OCx
delay
OCxN
delay
MS31095V1
Figure 145. Dead-time waveforms with delay greater than the negative pulse.
OCxREF
OCx
delay
OCxN
MS31096V1
Figure 146. Dead-time waveforms with delay greater than the positive pulse.
OCxREF
OCx
OCxN
delay
MS31097V1
The dead-time delay is the same for each of the channels and is programmable with the
DTG bits in the TIMx_BDTR register. Refer to Section 16.4.18: TIM1&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 with 1 again. In this case, it can be used for
security and the break input can be connected to an alarm from power drivers, thermal
sensors or any security components.
Note: The break inputs is acting on level. Thus, the MOE cannot be set while the break input is
active (neither automatically nor by software). In the meantime, the status flag BIF cannot
be cleared.
The break can be generated by the BRK input which has a programmable polarity and an
enable bit BKE in the TIMx_BDTR Register.
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 to freeze the
configuration of several parameters (dead-time duration, OCx/OCxN polarities and state
when disabled, OCxM configurations, break enable and polarity). The protection can be
selected among 3 levels with the LOCK bits in the TIMx_BDTR register. Refer to
Section 16.4.18: TIM1&TIM8 break and dead-time register (TIMx_BDTR). The LOCK bits
can be written only once after an MCU reset.
Figure 147 shows an example of behavior of the outputs in response to a break.
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.
OCxREF
Write COM to 1
COM event
CCxE=1 write OCxM to 100 CCxE=1
CCxNE=0 CCxNE=0
OCxM=100 (forced inactive) OCxM=100
OCx
Example 1
OCxN
Write CCxNE to 1
and OCxM to 101 CCxE=0
CCxE=1 CCxNE=1
CCxNE=0 OCxM=101
OCx OCxM=100 (forced inactive)
Example 2
OCxN
write CCxNE to 0
CCxE=1
and OCxM to 100 CCxE=1
CCxNE=0 CCxNE=0
OCxM=100 (forced inactive) OCxM=100
OCx
Example 3
OCxN
ai14910
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0 t
tDELAY tPULSE
MS31099V2
For example one may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
Let’s use TI2FP2 as trigger 1:
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’s say one want to build a waveform with a transition from ‘0’ to ‘1’ when a compare
match occurs and a transition from ‘1’ to ‘0’ when the counter reaches the auto-reload
value. To do this PWM mode 2 must be enabled by writing OC1M=111 in the
TIMx_CCMR1 register. Optionally the preload registers can be enabled by writing
OC1PE=’1’ in the TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this
case one has to write the compare value in the TIMx_CCR1 register, the auto-reload
value in the TIMx_ARR register, generate an update by setting the UG bit and wait for
external trigger event on TI2. CC1P is written to ‘0’ in this example.
In our example, the DIR and CMS bits in the TIMx_CR1 register should be low.
Since only 1 pulse (Single mode) is needed, a 1 must be written in the OPM bit in the
TIMx_CR1 register to stop the counter at the next update event (when the counter rolls over
from the auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0',
so the Repetitive Mode is selected.
Particular case: OCx fast enable:
In One-pulse mode, the edge detection on TIx input set the CEN bit which enables the
counter. Then the comparison between the counter and the compare value makes the
output toggle. But several clock cycles are needed for these operations and it limits the
minimum delay tDELAY min we can get.
If one wants to output a waveform with the minimum delay, the OCxFE bit can be set in the
TIMx_CCMRx register. Then OCxRef (and OCx) are forced in response to the stimulus,
without taking in account the comparison. Its new level is the same as if a compare match
had occurred. OCxFE acts only if the channel is configured in PWM1 or PWM2 mode.
TIMx_ARR must be configured 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 107 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 151 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 152 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=’1’).
Figure 152. Example of encoder interface mode with TI1FP1 polarity inverted.
forward jitter backward jitter forward
TI1
TI2
Counter
down up down
MS33108V1
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. Dynamic information can be obtained (speed, acceleration, deceleration)
by measuring the period between two encoder events using a second timer configured in
capture mode. The output of the encoder which indicates the mechanical zero can be used
for this purpose. Depending on the time between two events, the counter can also be read
at regular times. This can be done by latching the counter value into a third input capture
register if available (then the capture signal must be periodic and can be generated by
another timer). when available, it is also possible to read its value through a DMA request
generated by a real-time clock.
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
MS31401V1
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
Res. Res. Res. Res. Res. Res. CKD[1:0] ARPE CMS[1:0] DIR OPM URS UDIS CEN
rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. OIS4 OIS3N OIS3 OIS2N OIS2 OIS1N OIS1 TI1S MMS[2:0] CCDS CCUS Res. CCPC
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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 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 109. Output control bits for complementary OCx and OCxN channels
with break feature
Control bits Output states(1)
MOE OSSI OSSR CCxE CCxNE
OCx output state OCxN output state
bit bit bit bit bit
Output Disabled (not driven by
Output Disabled (not driven by the timer)
0 the timer)
OCxN=0, OCxN_EN=0
OCx=0, OCx_EN=0
0
Output Disabled (not driven by
OCxREF + Polarity OCxN=OCxREF xor
1 the timer)
CCxNP, OCxN_EN=1
OCx=0, OCx_EN=0
0 OCxREF + Polarity
Output Disabled (not driven by the timer)
0 OCx=OCxREF xor CCxP,
OCxN=0, OCxN_EN=0
OCx_EN=1
1 Complementary to OCREF (not
OCREF + Polarity + dead-time OCREF)
1
OCx_EN=1 + Polarity + dead-time
1 X OCxN_EN=1
Output Disabled (not driven by
Output Disabled (not driven by the timer)
0 the timer)
OCxN=CCxNP, OCxN_EN=0
OCx=CCxP, OCx_EN=0
0
Off-State (output enabled with OCxREF + Polarity
1 inactive state) OCxN=OCxREF xor CCxNP,
OCx=CCxP, OCx_EN=1 OCxN_EN=1
1
OCxREF + Polarity Off-State (output enabled with inactive
0 OCx=OCxREF xor CCxP, state)
OCx_EN=1 OCxN=CCxNP, OCxN_EN=1
1
Complementary to OCREF (not
OCREF + Polarity + dead-time
1 OCREF) + Polarity + dead-time
OCx_EN=1
OCxN_EN=1
Output Disabled (not driven by
Output Disabled (not driven by the timer)
0 the timer)
0 OCxN=CCxNP, OCxN_EN=0
OCx=CCxP, OCx_EN=0
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.
0x2C
0x1C
0x0C
Offset
518/1347
16.4.21
mode
mode
mode
mode
TIMx_SR
TIMx_CR2
TIMx_CR1
TIMx_PSC
TIMx_CNT
TIMx_RCR
TIMx_ARR
TIMx_EGR
Register
TIMx_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCER
TIMx_SMCR
Input Capture
Input Capture
TIMx_CCMR2
TIMx_CCMR2
TIMx_CCMR1
TIMx_CCMR1
Output Compare
Output Compare
below:
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Advanced-control timers (TIM1&TIM8)
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
TIM1&TIM8 register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
RM0390 Rev 6
17
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
0
0
0
0
Res. Res. O24CE OC2CE Res. Res. Res. ETP Res. Res. 15
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2:0]
[2:0]
IC4F[3:0]
IC2F[3:0]
OC4M
OC2M
[1:0]
0
0
0
0
0
0
0
0
0
0
0
0
12
0
0
0
0
0
0
0
0
0
0
0
0
IC4
IC2
[1:0]
[1:0]
PSC
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
9
ETF[3:0]
[1:0]
[1:0]
[1:0]
[1:0]
[1:0]
CKD
0
0
0
0
0
0
0
0
0
0
0
0
CC4S
CC4S
CC2S
CC2S
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
PSC[15:0]
CNT[15:0]
ARR[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2:0]
[2:0]
IC3F[3:0]
IC1F[3:0]
OC3M
OC1M
TS[2:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
REP[7:0]
IC3
IC1
[1:0]
[1:0]
PSC
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[1:0]
[1:0]
[1:0]
[1:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TIM1&TIM8 registers are mapped as 16-bit addressable registers as described in the table
CC3S
CC3S
CC1S
CC1S
0
RM0390
RM0390 Advanced-control timers (TIM1&TIM8)
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_CCR1 CCR1[15:0]
0x34
Reset value Res. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_CCR2 CCR2[15:0]
0x38
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_CCR3 CCR3[15:0]
0x3C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_CCR4 CCR4[15:0]
0x40
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
OSSR
LOCK
OSSI
MOE
AOE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
BKP
BKE
TIMx_BDTR DT[7:0]
0x44 [1:0]
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_DCR DBL[4:0] DBA[4:0]
0x48
Reset value 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_DMAR DMAB[15:0]
0x4C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
TI1FP1 Encoder
TI2FP2 interface
U
Auto-reload register UI
Stop, clear or up/down
U
CK_PSC PSC CK_CNT +/- CNT counter
prescaler
CC1I U CC1I
XOR TI1FP1 OC1REF
TI1 Input filter & IC1 IC1PS Output OC1 TIMx_CH1
TI1FP2 Prescaler Capture/Compare 1 register
edge detector control
TIMx_CH1 TRC
CC2I
U CC2I
TI2FP1
TI2 Input filter & IC2 Output OC2
TIMx_CH2 TI2FP2 Prescaler
IC2PS Capture/Compare 2 register OC2REF TIMx_CH2
edge detector control
TRC
CC3I CC3I
U
TI3FP3 OC3REF
TI3 Input filter & IC3 IC3PS Output OC3 TIMx_CH3
TI3FP4 Prescaler Capture/Compare 3 register
TIMx_CH3 edge detector control
TRC CC4I
U CC4I
TI4FP3
TI4 Input filter & IC4 Output OC4
TIMx_CH4 TI4FP4 Prescaler
IC4PS Capture/Compare 4 register OC4REF TIMx_CH4
edge detector control
TRC
ETRF
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
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 159 and Figure 160 give some examples of the counter behavior when the prescaler
ratio is changed on the fly:
Figure 159. 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 160. 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
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 165. 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 166. 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
In this mode, the direction bit (DIR from TIMx_CR1 register) cannot be written. It is updated
by hardware and gives the current direction of the counter.
The update event can be generated at each counter overflow and at each counter underflow
or by setting the UG bit in the TIMx_EGR register (by software or by using the slave mode
controller) also generates an update event. In this case, the counter restarts counting from
0, as well as the counter of the prescaler.
The UEV update event can be disabled by software by setting the UDIS bit in TIMx_CR1
register. This is to avoid updating the shadow registers while writing new values in the
preload registers. Then no update event occurs until the UDIS bit has been written to 0.
However, the counter continues counting up and down, based on the current auto-reload
value.
In addition, if the URS bit (update request selection) in TIMx_CR1 register is set, setting the
UG bit generates an update event UEV but without setting the UIF flag (thus no interrupt or
DMA request is sent). This is to avoid generating both update and capture interrupt when
clearing the counter on the capture event.
When an update event occurs, all the registers are updated and the update flag (UIF bit in
TIMx_SR register) is set (depending on the URS bit):
The buffer of the prescaler is reloaded with the preload value (content of the TIMx_PSC
register).
The auto-reload active register is updated with the preload value (content of the
TIMx_ARR register). Note that if the update source is a counter overflow, the auto-
reload is updated before the counter is reloaded, so that the next period is the expected
one (the counter is loaded with the new value).
The following figures show some examples of the counter behavior for different clock
frequencies.
CK_INT
CNT_EN
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.1: TIMx control register 1 (TIMx_CR1)
on page 558).
CK_INT
CNT_EN
Timerclock = CK_CNT
Counter underflow
CK_INT
CNT_EN
Timerclock = CK_CNT
CK_INT
Timerclock = CK_CNT
Counter register 20 1F 01 00
Counter underflow
Figure 176. 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 177. 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
TIMx_SMCR
TS[2:0]
or TI2F or
TI1F or Encoder
ITRx mode
0xx
TI1_ED
100 TRGI External clock
TI1FP1 mode 1 CK_PSC
TI2F_Rising 101
TI2 Edge 0 TI2FP2 ETRF External clock
Filter 110
detector 1 ETRF mode 2
TI2F_Falling 111
CK_INT Internal clock
mode
ICF[3:0] CC2P (internal clock)
TIMx_CCMR1 TIMx_CCER
ECE SMS[2:0]
TIMx_SMCR
MS31196V1
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S= ‘01 in the
TIMx_CCMR1 register.
2. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1
register (if no filter is needed, keep IC2F=0000).
Note: The capture prescaler is not used for triggering, so it does not need to be configured.
3. Select rising edge polarity by writing CC2P=0 and CC2NP=0 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
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
MS33144V1
OCREF_CLR
0
OCREF_CLR_INT
ETRF 1
To the master mode 0
controller Output OC1
OCCS Enable
1 Circuit
TIMx_SMCR
CC1P
CNT > CCR1
Output mode oc1ref TIMx_CCER
CNT = CCR1 controller
CC1E
OC1M[2:0] TIMx_CCER
TIMx_CCMR1 ai17187
The capture/compare block is made of one preload register and one shadow register. Write
and read always access the preload register.
In capture mode, captures are actually done in the shadow register, which is copied into the
preload register.
In compare mode, the content of the preload register is copied into the shadow register
which is compared to the counter.
new level have been detected (sampled at fDTS frequency). Then write IC1F bits to
0011 in the TIMx_CCMR1 register.
Select the edge of the active transition on the TI1 channel by writing the CC1P and
CC1NP bits to 00 in the TIMx_CCER register (rising edge in this case).
Program the input prescaler. In our example, we wish the capture to be performed at
each valid transition, so the prescaler is disabled (write IC1PS bits to 00 in the
TIMx_CCMR1 register).
Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
If needed, enable the related interrupt request by setting the CC1IE bit in the
TIMx_DIER register, and/or the DMA request by setting the CC1DE bit in the
TIMx_DIER register.
When an input capture occurs:
The TIMx_CCR1 register gets the value of the counter on the active transition.
CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures
occurred whereas the flag was not cleared.
An interrupt is generated depending on the CC1IE bit.
A DMA request is generated depending on the CC1DE bit.
In order to handle the overcapture, it is recommended to read the data before the
overcapture flag. This is to avoid missing an overcapture which could happen after reading
the flag and before reading the data.
Note: IC interrupt and/or DMA requests can be generated by software by setting the
corresponding CCxG bit in the TIMx_EGR register.
For example, one can measure the period (in TIMx_CCR1 register) and the duty cycle (in
TIMx_CCR2 register) of the PWM applied on TI1 using the following procedure (depending
on CK_INT frequency and prescaler value):
Select the active input for TIMx_CCR1: write the CC1S bits to 01 in the TIMx_CCMR1
register (TI1 selected).
Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter
clear): write the CC1P to ‘0’ and the CC1NP bit to ‘0’ (active on rising edge).
Select the active input for TIMx_CCR2: write the CC2S bits to 10 in the TIMx_CCMR1
register (TI1 selected).
Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): write the CC2P
bit to ‘1’ and the CC2NP bit to ’0’(active on falling edge).
Select the valid trigger input: write the TS bits to 101 in the TIMx_SMCR register
(TI1FP1 selected).
Configure the slave mode controller in reset mode: write the SMS bits to 100 in the
TIMx_SMCR register.
Enable the captures: write the CC1E and CC2E bits to ‘1 in the TIMx_CCER register.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
Anyway, the comparison between the TIMx_CCRx shadow register and the counter is still
performed and allows the flag to be set. Interrupt and DMA requests can be sent
accordingly. This is described in the Output Compare Mode section.
OC1REF = OC1
Upcounting configuration
Upcounting is active when the DIR bit in the TIMx_CR1 register is low. Refer to Upcounting
mode on page 523.
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 188 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 on page 526.
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) on page 528.
Figure 189 shows some center-aligned PWM waveforms in an example where:
TIMx_ARR=8,
PWM mode is the PWM mode 1,
The flag is set when the counter counts down corresponding to the center-aligned
mode 1 selected for CMS=01 in TIMx_CR1 register.
Counter register 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1
OCxREF
CCRx = 4
CCxIF CMS=01
CMS=10
CMS=11
OCxREF
CCRx=7
CMS=10 or 11
CCxIF
‘1’
OCxREF
CCRx=8
CCxIF CMS=01
CMS=10
CMS=11
‘1’
OCxREF
CCRx>8
CCxIF CMS=01
CMS=10
CMS=11
‘0’
OCxREF
CCRx=0
CCxIF CMS=01
CMS=10
CMS=11
AI14681b
in the TIMx_CR1 register. Moreover, the DIR and CMS bits must not be changed at the
same time by the software.
Writing to the counter while running in center-aligned mode is not recommended as it
can lead to unexpected results. In particular:
– The direction is not updated if a value greater than the auto-reload value is written
in the counter (TIMx_CNT>TIMx_ARR). For example, if the counter was counting
up, it continues to count up.
– The direction is updated if 0 or the TIMx_ARR value is written in the counter but no
Update Event UEV is generated.
The safest way to use center-aligned mode is to generate an update by software
(setting the UG bit in the TIMx_EGR register) just before starting the counter and not to
write the counter while it is running.
TI2
OC1REF
OC1
TIM1_ARR
Counter
TIM1_CCR1
0
tDELAY tPULSE t
MS31099V1
For example one may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
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 191 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 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 192 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 193 gives an example of counter behavior when TI1FP1 polarity is inverted (same
configuration as above except CC1P=1).
Figure 193. Example of encoder interface mode with TI1FP1 polarity inverted
forward jitter backward jitter forward
TI1
TI2
Counter
down up down
MS33108V1
The timer, when configured in Encoder Interface mode provides information on the sensor’s
current position. Dynamic information can be obtained (speed, acceleration, deceleration)
by measuring the period between two encoder events using a second timer configured in
capture mode. The output of the encoder which indicates the mechanical zero can be used
for this purpose. Depending on the time between two events, the counter can also be read
at regular times. This can be done by latching the counter value into a third input capture
register if available (then the capture signal must be periodic and can be generated by
another timer). when available, it is also possible to read its value through a DMA request
generated by a Real-Time clock.
UG
TIF
MS37384V1
TI1
CNT_EN
TIF
Write TIF=0
MS37385V1
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.
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, Timer 1 can be configured to act as a prescaler for Timer 2. Refer to
Figure 198. To do this:
Configure Timer 1 in master mode so that it outputs a periodic trigger signal on each
update event UEV. If MMS=010 is written 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. This is selected through the TS bits in the
TIM2_SMCR register (writing TS=000).
Then the slave mode controller must be put 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 199, 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. Then any value can be written
in the timer counters. The timers can easily be reset by software using the UG bit in the
TIMx_EGR registers.
In the next example, 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
counts until we write ‘0 to the CEN bit in the TIM2_CR1 register. Both counter clock
frequencies are divided by 3 by the prescaler compared to CK_INT (fCK_CNT = fCK_INT/3).
Configure Timer 1 master mode to send its Update Event (UEV) as trigger output
(MMS=010 in the TIM1_CR2 register).
Configure the Timer 1 period (TIM1_ARR registers).
Configure Timer 2 to get the input trigger from Timer 1 (TS=000 in the TIM2_SMCR
register).
Configure Timer 2 in trigger mode (SMS=110 in TIM2_SMCR register).
Start Timer 1 by writing ‘1 in the CEN bit (TIM1_CR1 register).
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, both counters can be initialized before starting counting.
Figure 202 shows the behavior with the same configuration as in Figure 199, 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
counters are aligned, Timer 1 must be configured in Master/Slave mode (slave with respect
to TI1, master with respect to Timer 2):
Configure Timer 1 master mode to send its Enable as trigger output (MMS=001 in the
TIM1_CR2 register).
Configure Timer 1 slave mode to get the input trigger from TI1 (TS=100 in the
TIM1_SMCR register).
Configure Timer 1 in trigger mode (SMS=110 in the TIM1_SMCR register).
Configure the Timer 1 in Master/Slave mode by writing MSM=1 (TIM1_SMCR register).
Configure Timer 2 to get the input trigger from Timer 1 (TS=000 in the TIM2_SMCR
register).
Configure Timer 2 in trigger mode (SMS=110 in the TIM2_SMCR register).
When a rising edge occurs on TI1 (Timer 1), both counters starts counting synchronously on
the internal clock and both TIF flags are set.
Note: In this example both timers are initialized before starting (by setting their respective UG
bits). Both counters starts from 0, but an offset can easily be inserted between them by
writing any of the counter registers (TIMx_CNT). One can see that the master/slave mode
insert a delay between CNT_EN and CK_PSC on timer 1.
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
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 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.
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).
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).
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. ITR1_RMP Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. TI4_RMP Res. Res. Res. Res. Res. Res.
rw rw
0x1C
0x0C
Offset
RM0390
17.4.21
mode
mode
mode
mode
TIMx_SR
TIMx_CR2
TIMx_CR1
TIMx_CNT
TIMx_EGR
Register
TIMx_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCER
TIMx_SMCR
Input Capture
Input Capture
TIMx_CCMR2
TIMx_CCMR2
TIMx_CCMR1
TIMx_CCMR1
Output Compare
Output Compare
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
TIMx register map
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
CNT[31:16]
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
RM0390 Rev 6
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2:0]
[2:0]
IC4F[3:0]
IC2F[3:0]
OC4M
OC2M
[1:0]
0
0
0
0
0
0
0
0
0
ETPS
0
0
0
0
0
0
0
0
0
IC4
IC2
[1:0]
[1:0]
PSC
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[1:0]
[1:0]
[1:0]
[1:0]
[1:0]
CKD
0
0
0
0
0
0
0
0
0
CC4S
CC4S
CC2S
CC2S
CC3E Res. Res. UDE Res. 8
0
0
0
0
0
0
0
0
0
CNT[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[2:0]
[2:0]
IC3F[3:0]
IC1F[3:0]
OC3M
OC1M
TS[2:0]
0
0
0
0
0
0
0
0
0
0
0
0
MMS[2:0]
0
0
0
0
0
0
0
0
0
0
0
IC3
IC1
[1:0]
[1:0]
PSC
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[1:0]
[1:0]
[1:0]
[1:0]
0
0
0
0
0
0
0
0
0
0
0
SMS[2:0]
CC3S
CC3S
CC1S
CC1S
579/1347
General-purpose timers (TIM2 to TIM5)
580
General-purpose timers (TIM2 to TIM5) RM0390
Table 114. 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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_PSC PSC[15:0]
0x28
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ARR[31:16]
TIMx_ARR ARR[15:0]
0x2C (TIM2 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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x44 Reserved
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_DCR DBL[4:0] DBA[4:0]
0x48
Reset value 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_DMAR DMAB[15:0]
0x4C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ITR1_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIM2_OR
RMP
0x50
Reset value 0 0
IT4_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIM5_OR
0x50 RMP
Reset value 0 0
ITR0
Trigger
ITR1 TGI controller
ITR
ITR2 TRC TRGI
ITR3 Slave
Reset, Enable, Count
mode
TI1F_ED controller
TI1FP1
TI2FP2
U Auto-reload register UI
Stop, Clear
U
CK_PSC PSC CK_CNT CNT
+/-
Prescaler COUNTER
CC1I CC1I
TI1 TI1FP1
Input filter &
IC1 IC1PS U OC1REF output OC1
TIMx_CH1 TI1FP2 Prescaler Capture/Compare 1 register TIMx_CH1
Edge detector control
TRC
CC2I
CC2I
TI2FP1 IC2 IC2PS U
TI2 Input filter & OC2REF output OC2
TIMx_CH2
TIMx_CH2 TI2FP2 Prescaler Capture/Compare 2 register
Edge detector control
TRC
Notes:
Reg Preload registers transferred
to active registers on U event
according to control bit
event
interrupt
ai17190
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 206 and Figure 207 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 206. 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 207. 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
CK_PSC
CEN
Timerclock = CK_CNT
Counter register 31 32 33 34 35 36 00 01 02 03 04 05 06 07
Counter overflow
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 it does not need to be configured.
When a rising edge occurs on TI2, the counter counts once and the TIF flag is set.
The delay between the rising edge on TI2 and the actual clock of the counter is due to the
resynchronization circuit on TI2 input.
TI2
CNT_EN
Counter register 34 35 36
TIF
Write TIF = 0
MS31087V3
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
TIM1_CCMR1
Comparator (from time
IC1PS Capture
base unit)
CC1E CNT>CCR1
Counter CNT=CCR1
CC1G
TIM1_EGR
MS31089V2
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 it is written with 0.
The following example shows how to capture the counter value in TIMx_CCR1 when TI1
input rises. To do this, use the following procedure:
1. Select the 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 appropriate input filter duration in relation with the signal connected to the
timer (by programming the ICxF bits in the TIMx_CCMRx register if the input is one of
the TIx inputs). Let’s imagine that, when toggling, the input signal is not stable during at
must 5 internal clock cycles. We must program a filter duration longer than these 5
clock cycles. We can validate a transition on TI1 when 8 consecutive samples with the
new level have been detected (sampled at fDTS frequency). Then write IC1F bits to
‘0011’ in the TIMx_CCMR1 register.
3. Select the edge of the active transition on the TI1 channel by programming CC1P and
CC1NP bits to ‘00’ in the TIMx_CCER register (rising edge in this case).
4. Program the input prescaler. In our example, we wish the capture to be performed at
each valid transition, so the prescaler is disabled (write IC1PS bits to ‘00’ in the
TIMx_CCMR1 register).
5. Enable capture from the counter into the capture register by setting the CC1E bit in the
TIMx_CCER register.
6. If needed, enable the related interrupt request by setting the CC1IE bit in the
TIMx_DIER register.
When an input capture occurs:
The TIMx_CCR1 register gets the value of the counter on the active transition.
CC1IF flag is set (interrupt flag). CC1OF is also set if at least two consecutive captures
occurred whereas the flag was not cleared.
An interrupt is generated depending on the CC1IE bit.
In order to handle the overcapture, it is recommended to read the data before the
overcapture flag. This is to avoid missing an overcapture which could happen after reading
the flag and before reading the data.
Note: IC interrupt requests can be generated by software by setting the corresponding CCxG bit in
the TIMx_EGR register.
1. Select the active input for TIMx_CCR1: write the CC1S bits to ‘01’ in the TIMx_CCMR1
register (TI1 selected).
2. Select the active polarity for TI1FP1 (used both for capture in TIMx_CCR1 and counter
clear): program the CC1P and CC1NP bits to ‘00’ (active on rising edge).
3. Select the active input for TIMx_CCR2: write the CC2S bits to ‘10’ in the TIMx_CCMR1
register (TI1 selected).
4. Select the active polarity for TI1FP2 (used for capture in TIMx_CCR2): program the
CC2P and CC2NP bits to ‘11’ (active on falling edge).
5. Select the valid trigger input: write the TS bits to ‘101’ in the TIMx_SMCR register
(TI1FP1 selected).
6. Configure the slave mode controller in reset mode: write the SMS bits to ‘100’ in the
TIMx_SMCR register.
7. Enable the captures: write the CC1E and CC2E bits to ‘1’ in the TIMx_CCER register.
TI1
TIMx_CCR1 0004
TIMx_CCR2 0002
1. The PWM input mode can be used only with the TIMx_CH1/TIMx_CH2 signals due to the fact that only
TI1FP1 and TI2FP2 are connected to the slave mode controller.
OC1REF= OC1
Counter register 0 1 2 3 4 5 6 7 8 0 1
OCXREF
CCRx=4
CCxIF
OCXREF
CCRx=8
CCxIF
OCXREF ‘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 one may want to generate a positive pulse on OC1 with a length of tPULSE and
after a delay of tDELAY as soon as a positive edge is detected on the TI2 input pin.
Use TI2FP2 as trigger 1:
1. Map TI2FP2 to TI2 by writing CC2S=’01’ in the TIMx_CCMR1 register.
2. TI2FP2 must detect a rising edge, write CC2P=’0’ and CC2NP = ‘0’ in the TIMx_CCER
register.
3. Configure TI2FP2 as trigger for the slave mode controller (TRGI) by writing TS=’110’ in
the TIMx_SMCR register.
4. TI2FP2 is used to start the counter by writing SMS to ‘110’ in the TIMx_SMCR register
(trigger mode).
The OPM waveform is defined by writing the compare registers (taking into account the
clock frequency and the counter prescaler).
The tDELAY is defined by the value written in the TIMx_CCR1 register.
The tPULSE is defined by the difference between the auto-reload value and the compare
value (TIMx_ARR - TIMx_CCR1).
Let’s say one want to build a waveform with a transition from ‘0’ to ‘1’ when a compare
match occurs and a transition from ‘1’ to ‘0’ when the counter reaches the auto-reload
value. To do this PWM mode 2 must be enabled by writing OC1M=’111’ in the
TIMx_CCMR1 register. Optionally the preload registers can be enabled by writing
OC1PE=’1’ in the TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In this
case one has to write the compare value in the TIMx_CCR1 register, the auto-reload
value in the TIMx_ARR register, generate an update by setting the UG bit and wait for
external trigger event on TI2. CC1P is written to ‘0’ in this example.
Since only 1 pulse (Single mode) is needed, a 1 must be written in the OPM bit in the
TIMx_CR1 register to stop the counter at the next update event (when the counter rolls over
from the auto-reload value back to 0). When OPM bit in the TIMx_CR1 register is set to '0',
so the Repetitive Mode is selected.
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
Res. Res. Res. Res. Res. Res. Res. Res. MSM TS[2:0] Res. SMS[2:0]
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.
0x2C
0x1C
0x0C
Offset
RM0390
18.4.13
mode
mode
TIMx_SR
Reserved
Reserved
TIMx_CR1
TIMx_PSC
TIMx_CNT
TIMx_ARR
TIMx_EGR
Register
TIMx_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCER
TIMx_SMCR
Input Capture
TIMx_CCMR1
TIMx_CCMR1
Output Compare
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
TIM9/12 register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
RM0390 Rev 6
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 15
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 14
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 13
[2:0]
IC2F[3:0]
OC2M
0
0
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. 12
0
0
0
0
0
Res. Res. Res. OC2PE Res. Res. Res. Res. Res. 11
IC2
[1:0]
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
[1:0]
[1:0]
[1:0]
CKD
0
0
0
0
0
0
CC2S
CC2S
0
0
0
0
0
0
0
0
PSC[15:0]
CNT[15:0]
ARR[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res. CC2P Res. Res. Res. Res. Res. 5
[2:0]
IC1F[3:0]
OC1M
TS[2:0]
0
0
0
0
0
0
Res. CC2E Res. Res. Res. Res. Res. 4
TIM9/12 registers are mapped as 16-bit addressable registers as described below:
0
0
0
0
0
0
0
[1:0]
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
[1:0]
[1:0]
CC1
CC1
0
0
0
0
0
0
0
0
0
0
0
SMS[2:0]
615/1347
General-purpose timers (TIM9 to TIM14)
627
General-purpose timers (TIM9 to TIM14) RM0390
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_CCR1 CCR1[15:0]
0x34
Reset value Res. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TIMx_CCR2 CCR2[15:0]
0x38
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0x3C to
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Reserved
0x4C
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. OC1M[2:0] OC1PE OC1FE
CC1S[1:0]
Res. Res. Res. Res. Res. Res. Res. Res. IC1F[3:0] IC1PSC[1:0]
rw rw rw rw rw rw rw rw
Note: The state of the external I/O pins connected to the standard OCx channels depends on the
OCx channel state and the GPIO registers.
0x2C
0x1C
0x0C
Offset
626/1347
18.5.12
mode
mode
TIMx_SR
Reserved
Reserved
TIMx_CR1
TIMx_PSC
TIMx_CNT
TIMx_EGR
TIMx_ARR
Register
TIMx_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
TIMx_CCER
TIMx_SMCR
Input capture
TIMx_CCMR1
TIMx_CCMR1
Output compare
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
General-purpose timers (TIM9 to TIM14)
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
TIM10/11/13/14 register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
RM0390 Rev 6
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 15
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 14
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 13
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 12
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 11
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 10
0
0
0
0
0
0
0
0
0
Table 119. TIM10/11/13/14 register map and reset values
0
0
0
0
0
PSC[15:0]
CNT[15:0]
ARR[15:0]
0
0
0
0
0
0
0
0
0
0
IC1F[3:0]
OC1M
0
0
0
0
0
0
0
0
0
0
0
[1:0]
PSC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
CC1S
CC1S
TIMx registers are mapped as 16-bit addressable registers as described in the table below:
0x4C
0x38 to
Offset
RM0390
Reserved
TIMx_OR
Register
Reset value
Reset value
TIMx_CCR1
RM0390 Rev 6
Res. Res. Res. 16
0
Res. Res. 15
0
Res. Res. 14
0
Res. Res. 13
0
Res. Res. 12
0
Res. Res. 11
0
Res. Res. 10
0
Res. Res. 9
0
Res. Res. 8
Refer to Section 2.2.2 on page 50 for the register boundary addresses.
0
Res. Res. 7
0
CCR1[15:0]
Res. Res. 6
Table 119. TIM10/11/13/14 register map and reset values (continued)
Res. Res. 5
0
Res. Res. 4
0
Res. Res. 3
0
Res. Res. 2
0
Res. 1
TI1_RMP
0
Res. 0
627/1347
General-purpose timers (TIM9 to TIM14)
627
Basic timers (TIM6&TIM7) RM0390
Auto-reload register
U
UI
Stop, clear or up
U
CK_PSC PSC CK_CNT
+ CNT counter
prescaler
Notes:
Preload registers transferred
Reg
to active registers on U event
according to control bit
Event
Prescaler description
The prescaler can divide the counter clock frequency by any factor between 1 and 65536. It
is based on a 16-bit counter controlled through a 16-bit register (in the TIMx_PSC register).
It can be changed on the fly as the TIMx_PSC control register is buffered. The new
prescaler ratio is taken into account at the next update event.
Figure 228 and Figure 229 give some examples of the counter behavior when the prescaler
ratio is changed on the fly.
Figure 228. 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 229. 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
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
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
0x2C
0x1C
0x0C
Offset
19.4.9
RM0390
TIMx_SR
Reserved
Reserved
Reserved
Reserved
TIMx_CR2
TIMx_CR1
TIMx_CNT
TIMx_PSC
TIMx_ARR
TIMx_EGR
Register
TIMx_DIER
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
TIM6&TIM7 register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0390 Rev 6
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 15
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 14
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 13
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 12
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 11
0
0
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 10
0
0
0
Table 120. TIM6&TIM7 register map and reset values
0
0
0
0
CNT[15:0]
PSC[15:0]
ARR[15:0]
0
0
0
0
0
0
0
0
0
0
0
0
MMS[2:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
TIMx registers are mapped as 16-bit addressable registers as described in the table below:
639/1347
639
Independent watchdog (IWDG) RM0390
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 that is still functional in
Stop and Standby modes.
/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. Refers
to LSI oscillator characteristics table in device datasheet for from max and min values.
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PR[2:0]
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. RL[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RVU PVU
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)
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
IWDG_KR KEY[15:0]
0x00
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
IWDG_PR PR[2:0]
0x04
Reset value 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
IWDG_RLR RL[11:0]
0x08
Reset value 1 1 1 1 1 1 1 1 1 1 1 1
RVU
PVU
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
IWDG_SR
0x0C
Reset value 0 0
- W6 W5 W4 W3 W2 W1 W0
comparator
=1 when
T6:0 > W6:0
Write WWDG_CR
MSv37226V2
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 the datasheets for the minimum and maximum values of the tWWDG.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. WDGA T[6:0]
rs rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. EWI WDGTB[1:0] W[6:0]
rs rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. EWIF
rc_w0
652/1347
Register
Reset value
Reset value
Reset value
WWDG_SR
WWDG_CR
WWDG_CFR
Res. Res. Res. 31
Res. Res. Res. 30
Res. Res. Res. 29
Window watchdog (WWDG)
RM0390 Rev 6
Res. Res. Res. 17
Res. Res. Res. 16
Res. Res. Res. 15
Res. Res. Res. 14
Res. Res. Res. 13
Res. Res. Res. 12
Res. Res. Res. 11
Table 123. WWDG register map and reset values
Res. 6
1
1
Res. 5
1
1
Res. 4
1
1
Res. 3
T[6:0]
W[6:0]
1
1
Res. 2
1
1
Res. 1
0
1
1
EWIF 0
RM0390
RM0390 Real-time clock (RTC)
22.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).
RTC_TS
Time stamp TSF
512 Hz registe rs
1 Hz
RTC_CALIB
ck_apre Output RTC_OUT
RTCCLK (default 256 Hz) control
RTC_AF1
Alarm A
(RTC_ALRMAR
RTC_PRER Coarse RTC_PRER RTC_ALRMASSR
ck spre registers) = ALRAF
Asyn ch. Calibration Syn chronous (default 1 Hz)
7-bit prescaler RTC_CALIBR 15-bit prescaler
(default = 128) (default = 256) Calendar
RTC_ALARM
Shadow registers
Shadow register
LSE (32.768 Hz) (RTC_TR,
(RTC_SSR)
Smooth RTC_DR)
HSE_RTC calibration
(4 MHz max) RTC_CALR
LSI
Alarm B
= ALRBF
WUCKSEL[1:0] (RTC_ALRMBR RTC_AF2
RTC_ALRMBSSR
Prescaler registers)
/ 2, 4, 8, 16 RTC_WUTR
WUTF
16-bit wakeup
auto-reload timer
Backup and
RTC_TAMP1
RTC tamper
RTC_TAMP2 control registers
TAMPE
TSE
MS19902V3
1. On STM32F446xx devices, the RTC_AF1 and RTC_AF2 additional function are connected to PC13 and PA0, 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 22.3.4 for details).
Every two RTCCLK periods, the current calendar value is copied into the shadow registers,
and the RSF bit of RTC_ISR register is set (see Section 22.6.4). The copy is not performed
in Stop and Standby mode. When exiting these modes, the shadow registers are updated
after up to two RTCCLK periods.
When the application reads the calendar registers, it accesses the content of the shadow
registers.It is possible to make a direct access to the calendar registers by setting the
BYPSHAD control bit in the RTC_CR register. By default, this bit is cleared, and the user
accesses the shadow registers.
When reading the RTC_SSR, RTC_TR or RTC_DR registers in BYPSHAD=0 mode, the
frequency of the APB clock (fAPB) must be at least 7 times the frequency of the RTC clock
(fRTCCLK).
The shadow registers are reset by system reset.
complete (see Programming the wakeup timer), the timer starts counting
down.When the wakeup function is enabled, the down-counting remains active in
low power modes. In addition, when it reaches 0, the WUTF flag is set in the
RTC_ISR register, and the wakeup counter is automatically reloaded with its
reload value (RTC_WUTR register value).
The WUTF flag must then be cleared by software.
When the periodic wakeup interrupt is enabled by setting the WUTIE bit in the RTC_CR2
register, it can exit the device from low power modes.
The periodic wakeup flag can be routed to the RTC_ALARM output provided it has been
enabled through bits OSEL[1:0] of RTC_CR register. RTC_ALARM polarity can be
configured through the POL bit in the RTC_CR register.
System reset, as well as low power modes (Sleep, Stop and Standby) have no influence on
the wakeup timer.
factor. Even if only one of the two fields needs to be changed, 2 separate write
accesses must be performed to the RTC_PRER register.
4. Load the initial time and date values in the shadow registers (RTC_TR and RTC_DR),
and configure the time format (12 or 24 hours) through the FMT bit in the RTC_CR
register.
5. Exit the initialization mode by clearing the INIT bit. The actual calendar counter value is
then automatically loaded and the counting restarts after 4 RTCCLK clock cycles.
When the initialization sequence is complete, the calendar starts counting.
Note: After a system reset, the application can read the INITS flag in the RTC_ISR register to
check if the calendar has been initialized or not. If this flag equals 0, the calendar has not
been initialized since the year field is set at its backup domain reset default value (0x00).
To read the calendar after initialization, the software must first check that the RSF flag is set
in the RTC_ISR register.
When the BYPSHAD control bit is set in the RTC_CR register (bypass shadow
registers)
Reading the calendar registers gives the values from the calendar counters directly, thus
eliminating the need to wait for the RSF bit to be set. This is especially useful after exiting
from low power modes (STOP or Standby), since the shadow registers are not updated
during these modes.
When the BYPSHAD bit is set to 1, the results of the different registers might not be
coherent with each other if an RTCCLK edge occurs between two read accesses to the
registers. Additionally, the value of one of the registers may be incorrect if an RTCCLK edge
occurs during the read operation. The software must read all the registers twice, and then
compare the results to confirm that the data is coherent and correct. Alternatively, the
software can just compare the two results of the least-significant calendar register.
Note: While BYPSHAD=1, instructions which read the calendar registers require one extra APB
cycle to complete.
When positive calibration is enabled (DCS = ‘0’), 2 ck_apre cycles are added every minute
(around 15360 ck_apre cycles) for 2xDC minutes. This causes the calendar to be updated
sooner, thereby adjusting the effective RTC frequency to be a bit higher.
When negative calibration is enabled (DCS = ‘1’), 1 ck_apre cycle is removed every minute
(around 15360 ck_apre cycles) for 2xDC minutes. This causes the calendar to be updated
later, thereby adjusting the effective RTC frequency to be a bit lower.
DC is configured through bits DC[4:0] of RTC_CALIBR register. This number ranges from 0
to 31 corresponding to a time interval (2xDC) ranging from 0 to 62.
The coarse digital calibration can be configured only in initialization mode, and starts when
the INIT bit is cleared. The full calibration cycle lasts 64 minutes. The first 2xDC minutes of
the 64 -minute cycle are modified as just described.
Negative calibration can be performed with a resolution of about 2 ppm while positive
calibration can be performed with a resolution of about 4 ppm. The maximum calibration
ranges from -63 ppm to 126 ppm.
The calibration can be performed either on the LSE or on the HSE clock.
Caution: Digital calibration may not work correctly if PREDIV_A < 6.
The smooth calibration register (RTC_CALR) specifies the number of RTCCLK clock cycles
to be masked during the 32-second cycle:
Setting the bit CALM[0] to 1 causes exactly one pulse to be masked during the 32-
second cycle.
Setting CALM[1] to 1 causes two additional cycles to be masked
Setting CALM[2] to 1 causes four additional cycles to be masked
and so on up to CALM[8] set to 1 which causes 256 clocks to be masked.
Note: CALM[8:0] (RTC_CALRx) specifies the number of RTCCLK pulses to be masked during the
32-second cycle. Setting the bit CALM[0] to ‘1’ causes exactly one pulse to be masked
during the 32-second cycle at the moment when cal_cnt[19:0] is 0x80000; CALM[1]=1
causes two other cycles to be masked (when cal_cnt is 0x40000 and 0xC0000); CALM[2]=1
causes four other cycles to be masked (cal_cnt = 0x20000/0x60000/0xA0000/ 0xE0000);
and so on up to CALM[8]=1 which causes 256 clocks to be masked (cal_cnt = 0xXX800).
While CALM allows the RTC frequency to be reduced by up to 487.1 ppm with fine
resolution, the bit CALP can be used to increase the frequency by 488.5 ppm. Setting CALP
to ‘1’ effectively inserts an extra RTCCLK pulse every 211 RTCCLK cycles, which means
that 512 clocks are added during every 32-second cycle.
Using CALM together with CALP, an offset ranging from -511 to +512 RTCCLK cycles can
be added during the 32-second cycle, which translates to a calibration range of -487.1 ppm
to +488.5 ppm with a resolution of about 0.954 ppm.
The formula to calculate the effective calibrated frequency (FCAL) given the input frequency
(FRTCCLK) is as follows:
FCAL = FRTCCLK x [1 + (CALP x 512 - CALM) / (220 + CALM - CALP x 512)]
Re-calibration on-the-fly
The calibration register (RTC_CALR) can be updated on-the-fly while RTC_ISR/INITF=0, by
using the follow process:
1. Poll the RTC_ISR/RECALPF (re-calibration pending flag).
2. If it is set to 0, write a new value to RTC_CALR, if necessary. RECALPF is then
automatically set to 1
3. Within three ck_apre cycles after the write operation to RTC_CALR, the new calibration
settings take effect.
If a new timestamp event is detected while the timestamp flag (TSF) is already set, the
timestamp overflow flag (TSOVF) flag is set and the timestamp registers (RTC_TSTR and
RTC_TSDR) maintain the results of the previous event.
Note: TSF is set 2 ck_apre cycles after the timestamp event occurs due to synchronization
process.
There is no delay in the setting of TSOVF. This means that if two timestamp events are
close together, TSOVF can be seen as '1' while TSF is still '0'. As a consequence, it is
recommended to poll TSOVF only after TSF has been set.
Caution: If a timestamp event occurs immediately after the TSF bit is supposed to be cleared, then
both TSF and TSOVF bits are set. To avoid masking a timestamp event occurring at the
same moment, the application must not write ‘0’ into TSF bit unless it has already read it to
‘1’.
Optionally, a tamper event can cause a timestamp to be recorded. See the description of the
TAMPTS control bit in Section 22.6.17: RTC tamper and alternate function configuration
register (RTC_TAFCR). If the timestamp event is on the same pin as a tamper event
configured in filtered mode (TAMPFLT set to a non-zero value), the timestamp on tamper
detection event mode must be selected by setting TAMPTS='1' in RTC_TAFCR register.
(see Section 22.6.17). TAMPE bit must be cleared when TAMP1INSEL is modified to avoid
unwanted setting of TAMPF.
The TAMPER 2 alternate function corresponds to RTC_TAMP2 pin.
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.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. PM HT[1:0] HU[3:0]
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. MNT[2:0] MNU[3:0] Res. ST[2:0] SU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register is write protected. The write access procedure is described in RTC register
write protection.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. YT[3:0] YU[3:0]
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WDU[2:0] MT MU[3:0] Res. Res. DT[1:0] DU[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register is write protected. The write access procedure is described in RTC register
write protection.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. COE OSEL[1:0] POL COSEL BKP SUB1H ADD1H
rw rw rw rw rw rw w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TSIE WUTIE ALRBIE ALRAIE TSE WUTE ALRBE ALRAE DCE FMT BYPSHAD REFCKON TSEDGE WUCKSEL[2:0]
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.
This register is write protected. The write access procedure is described in RTC register
write protection.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RECALPF
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. TAMP2F TAMP1F TSOVF TSF WUTF ALRBF ALRAF INIT INITF RSF INITS SHPF WUT WF ALRB WF ALRA 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.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. PREDIV_A[6:0]
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. PREDIV_S[14:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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
This register is write protected. The write access procedure is described in RTC register
write protection.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WUT[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
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.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. DCS Res. Res. DC[4:0]
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.
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.
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.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. KEY
w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADD1S Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. SUBFS[14:0]
w w w w w w w w w w w w w w w
Note: This register is write protected. The write access procedure is described in RTC register
write protection
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. PM HT[1:0] HU[3:0]
r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. MNT[2:0] MNU[3:0] Res. ST[2:0] SU[3:0]
r r r r r r r r r r r r r r
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WDU[1:0] MT MU[3:0] Res. Res. DT[1:0] DU[3:0]
r r r r r r r r r r r r r r
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
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 Res. Res. Res. Res. 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.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ALARMOUT TSIN TAMP1I
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
TYPE SEL NSEL
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TAMP TAMP TAMP TAMP TAMP2
TAMPTS Res. Res. TAMP2E TAMPIE TAMP1TRG TAMP1E
PUDIS PRCH[1:0] FLT[1:0] FREQ[2:0] TRG
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. MASKSS[3:0] Res. Res. Res. Res. Res. Res. Res. Res.
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. SS[14:0]
rw rw rw rw rw rw rw rw rw rw rw rw w rw rw
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 657
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. MASKSS[3:0] Res. Res. Res. Res. Res. Res. Res. Res.
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
Res. 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 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
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
HT
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PM
RTC_TR HU[3:0] MNT[2:0] MNU[3:0] ST[2:0] SU[3:0]
[1:0]
0x00
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DT
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
MT
RTC_DR YT[3:0] YU[3:0] WDU[2:0] MU[3:0] DU[3:0]
[1:0]
0x04
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
POL
BKP
TSE
RTC_CR
0x08 [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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RSF
TSF
INIT
RTC_ISR
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_PRER PREDIV_A[6:0] PREDIV_S[14:0]
0x10
Reset value 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_WUTR WUT[15:0]
0x14
Reset value 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
DCS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_CALIBR DC[4:0]
0x18
Reset value 0 0 0 0 0 0
WDSEL
MSK4
MSK3
MSK2
MSK1
DT HT
PM
Reset value 0 0 0 0 0 0 0 0 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
MSK4
MSK3
MSK2
MSK2
DT HT
PM
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_WPR KEY[7:0]
0x24
Reset value 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_SSR SS[15:0]
0x28
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ADD1S
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_SHIFTR SUBFS[14:0]
0x2C
Reset value 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
MNT[2:0]
HT[1:0]
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
PM
RTC_TSTR HU[3:0] MNU[3:0] ST[2:0] SU[3:0]
0x30
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_TSSSR SS[15:0]
0x38
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
CALW16
CALW8
CALP
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_ CALR CALM[8:0]
0x3C
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
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RTC_TAFCR
0x40
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
MASKSS[3:0] SS[14:0]
0x44 ALRMASSR
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
RTC_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
MASKSS[3:0] SS[14:0]
0x48 ALRMBSSR
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
23.1 Introduction
The I2C (inter-integrated circuit) bus interface handles communications between the
microcontroller and the serial I2C bus. It provides multimaster capability, and controls all I2C
bus-specific sequencing, protocol, arbitration and timing. It supports Standard-mode (Sm),
Fast-mode (Fm) and Fast-mode Plus (Fm+).
It is also SMBus (system management bus) and PMBus (power management bus)
compatible.
DMA can be used to reduce CPU overload.
The following additional features are also available depending on the product
implementation (see Section 23.3: FMPI2C implementation):
SMBus specification rev 3.0 compatibility:
– Hardware PEC (packet error checking) generation and verification with ACK
control
– Command and data acknowledge control
– Address resolution protocol (ARP) support
– Host and Device support
– SMBus alert
– Timeouts and idle condition detection
PMBus rev 1.3 standard compatibility
Independent clock: a choice of independent clock sources allowing the FMPI2C
communication speed to be independent from the PCLK reprogramming
I2CCLK
i2c_ker_ck
Data control
Digital Analog
Shift register noise noise GPIO
filter I2C_SDA
filter logic
SMBUS
PEC
generation/
check
Wakeup
on
address
match Clock control
Master clock
generation Digital Analog
noise noise
Slave clock GPIO I2C_SCL
filter filter
stretching logic
SMBus
Timeout
check
SMBus Alert
control/status I2C_SMBA
PCLK
i2c_pclk Registers
APB bus
MSv46198V2
The FMPI2C is clocked by an independent clock source which allows the FMPI2C to
operate independently from the PCLK frequency.
For I2C I/Os supporting 20mA output current drive for Fast-mode Plus operation, the driving
capability is enabled through control bits in the system configuration controller (SYSCFG).
Refer to Section 23.3: FMPI2C implementation.
Communication flow
In Master mode, the FMPI2C interface initiates a data transfer and generates the clock
signal. A serial data transfer always begins with a START condition and ends with a STOP
condition. Both START and STOP conditions are generated in master mode by software.
In Slave mode, the interface is capable of recognizing its own addresses (7 or 10-bit), and
the general call address. The general call address detection can be enabled or disabled by
software. The reserved SMBus addresses can also be enabled by software.
Data and addresses are transferred as 8-bit bytes, MSB first. The first byte(s) following the
START condition contain the address (one in 7-bit mode, two in 10-bit mode). The address
is always transmitted in Master mode.
A 9th clock pulse follows the 8 clock cycles of a byte transfer, during which the receiver must
send an acknowledge bit to the transmitter. Refer to the following figure.
SDA
MSB ACK
SCL
1 2 8 9
Start Stop
condition condition
MS19854V1
Acknowledge can be enabled or disabled by software. The FMPI2C interface addresses can
be selected by software.
When the FMPI2C is disabled (PE=0), the I2C performs a software reset. Refer to
Section 23.4.6: Software reset for more details.
Noise filters
Before enabling the FMPI2C peripheral by setting the PE bit in FMPI2C_CR1 register, the
user must configure the noise filters, if needed. By default, an analog noise filter is present
on the SDA and SCL inputs. This analog filter is compliant with the I2C specification which
requires the suppression of spikes with a pulse width up to 50 ns in Fast-mode and Fast-
mode Plus. The user can disable this analog filter by setting the ANFOFF bit, and/or select a
digital filter by configuring the DNF[3:0] bit in the FMPI2C_CR1 register.
When the digital filter is enabled, the level of the SCL or the SDA line is internally changed
only if it remains stable for more than DNF x FMPI2CCLK periods. This allows spikes with a
programmable length of 1 to 15 FMPI2CCLK periods to be suppressed.
Caution: Changing the filter configuration is not allowed when the FMPI2C is enabled.
FMPI2C timings
The timings must be configured in order to guarantee a correct data hold and setup time,
used in master and slave modes. This is done by programming the PRESC[3:0],
SCLDEL[3:0] and SDADEL[3:0] bits in the FMPI2C_TIMINGR register.
The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C
configuration window
SDA
tHD;DAT
Data hold time: in case of transmission, the data is sent on SDA output after
the SDADEL delay, if it is already available in I2C_TXDR.
SCLDEL
SCL stretched low by the I2C
SCL
SDA
tSU;DAT
SU;STA
Data setup time: in case of transmission, the SCLDEL counter starts
when the data is sent on SDA output. MSv40108V1
MS49608V1
When the SCL falling edge is internally detected, a delay is inserted before sending
SDA output. This delay is tSDADEL = SDADEL x tPRESC + tI2CCLK where tPRESC = (PRESC+1)
x tI2CCLK.
TSDADEL impacts the hold time tHD;DAT.
In order to bridge the undefined region of the SDA transition (rising edge usually worst
case), the user must program SCLDEL in such a way that:
{[tr (max) + tSU;DAT (min)] / [(PRESC+1)] x tI2CCLK]} - 1 <= SCLDEL
Refer to Table 131: I2C-SMBus specification data setup and hold times for tr and tSU;DAT
standard values.
The SDA and SCL transition time values to be used are the ones in the application. Using
the maximum values from the standard increases the constraints for the SDADEL and
SCLDEL calculation, but ensures the feature whatever the application.
Note: At every clock pulse, after SCL falling edge detection, the I2C master or slave stretches SCL
low during at least [(SDADEL+SCLDEL+1) x (PRESC+1) + 1] x tI2CCLK, in both transmission
and reception modes. In transmission mode, in case the data is not yet written in I2C_TXDR
when SDADEL counter is finished, the I2C keeps on stretching SCL low until the next data
is written. Then new data MSB is sent on SDA output, and SCLDEL counter starts,
continuing stretching SCL low to guarantee the data setup time.
If NOSTRETCH=1 in slave mode, the SCL is not stretched. Consequently the SDADEL
must be programmed in such a way to guarantee also a sufficient setup time.
Additionally, in master mode, the SCL clock high and low levels must be configured by
programming the PRESC[3:0], SCLH[7:0] and SCLL[7:0] bits in the FMPI2C_TIMINGR
register.
When the SCL falling edge is internally detected, a delay is inserted before releasing
the SCL output. This delay is tSCLL = (SCLL+1) x tPRESC where tPRESC = (PRESC+1) x
tI2CCLK.
tSCLL impacts the SCL low time tLOW .
When the SCL rising edge is internally detected, a delay is inserted before forcing the
SCL output to low level. This delay is tSCLH = (SCLH+1) x tPRESC where tPRESC =
(PRESC+1) x tI2CCLK. tSCLH impacts the SCL high time tHIGH .
Initial settings
Configure PRESC[3:0],
End
MSv35962V1
Reception
The SDA input fills the shift register. After the 8th SCL pulse (when the complete data byte is
received), the shift register is copied into FMPI2C_RXDR register if it is empty (RXNE=0). If
RXNE=1, meaning that the previous received data byte has not yet been read, the SCL line
is stretched low until FMPI2C_RXDR is read. The stretch is inserted between the 8th and
9th SCL pulse (before the acknowledge pulse).
RXNE
rd data0 rd data1
MSv35976V1
Transmission
If the FMPI2C_TXDR register is not empty (TXE=0), its content is copied into the shift
register after the 9th SCL pulse (the Acknowledge pulse). Then the shift register content is
shifted out on SDA line. If TXE=1, meaning that no data is written yet in FMPI2C_TXDR,
SCL line is stretched low until FMPI2C_TXDR is written. The stretch is done after the 9th
SCL pulse.
data2
data1
Shift register xx xx xx
TXE
wr data1 wr data2
MSv35977V1
By default, the slave uses its clock stretching capability, which means that it stretches the
SCL signal at low level when needed, in order to perform software actions. If the master
does not support clock stretching, the FMPI2C must be configured with NOSTRETCH=1 in
the FMPI2C_CR1 register.
After receiving an ADDR interrupt, if several addresses are enabled the user must read the
ADDCODE[6:0] bits in the FMPI2C_ISR register in order to check which address matched.
DIR flag must also be checked in order to know the transfer direction.
Slave
initialization
Initial settings
End
MSv35963V1
Slave transmitter
A transmit interrupt status (TXIS) is generated when the FMPI2C_TXDR register becomes
empty. An interrupt is generated if the TXIE bit is set in the FMPI2C_CR1 register.
The TXIS bit is cleared when the FMPI2C_TXDR register is written with the next data byte
to be transmitted.
When a NACK is received, the NACKF bit is set in the FMPI2C_ISR register and an
interrupt is generated if the NACKIE bit is set in the FMPI2C_CR1 register. The slave
automatically releases the SCL and SDA lines in order to let the master perform a STOP or
a RESTART condition. The TXIS bit is not set when a NACK is received.
When a STOP is received and the STOPIE bit is set in the FMPI2C_CR1 register, the
STOPF flag is set in the FMPI2C_ISR register and an interrupt is generated. In most
applications, the SBC bit is usually programmed to ‘0’. In this case, If TXE = 0 when the
slave address is received (ADDR=1), the user can choose either to send the content of the
FMPI2C_TXDR register as the first data byte, or to flush the FMPI2C_TXDR register by
setting the TXE bit in order to program a new data byte.
In Slave byte control mode (SBC=1), the number of bytes to be transmitted must be
programmed in NBYTES in the address match interrupt subroutine (ADDR=1). In this case,
the number of TXIS events during the transfer corresponds to the value programmed in
NBYTES.
Caution: When NOSTRETCH=1, the SCL clock is not stretched while the ADDR flag is set, so the
user cannot flush the FMPI2C_TXDR register content in the ADDR subroutine, in order to
program the first data byte. The first data byte to be sent must be previously programmed in
the FMPI2C_TXDR register:
This data can be the data written in the last TXIS event of the previous transmission
message.
If this data byte is not the one to be sent, the FMPI2C_TXDR register can be flushed by
setting the TXE bit in order to program a new data byte. The STOPF bit must be
cleared only after these actions, in order to guarantee that they are executed before the
first data transmission starts, following the address acknowledge.
If STOPF is still set when the first data transmission starts, an underrun error is
generated (the OVR flag is set).
If a TXIS event is needed, (transmit interrupt or transmit DMA request), the user must
set the TXIS bit in addition to the TXE bit, in order to generate a TXIS event.
Slave
transmission
Slave initialization
No
FMPI2C_ISR.ADDR
=1?
Yes
SCL
stretched
Read ADDCODE and DIR in FMPI2C_ISR
Optional: Set FMPI2C_ISR.TXE = 1
Set FMPI2C_ICR.ADDRCF
No
FMPI2C_ISR.TXIS
=1?
Yes
Write FMPI2C_TXDR.TXDATA
MSv35964V1
Slave
transmission
Slave initialization
No
No
FMPI2C_ISR.TXIS FMPI2C_ISR.STOPF
=1? =1?
Yes Yes
Set FMPI2C_ICR.STOPCF
MSv35965V1
legend:
Example FMPI2C slave transmitter 3 bytes with 1st data flushed
NOSTRETCH=0: transmission
ADDR TXIS TXIS TXIS TXIS reception
S Address A A A data3 NA P
SCL stretch
data1 data2
TXE
EV1: ADDR ISR: check ADDCODE and DIR, set TXE, set ADDRCF
EV2: TXIS ISR: wr data1
EV3: TXIS ISR: wr data2
EV4: TXIS ISR: wr data3
EV5: TXIS ISR: wr data4 (not sent)
legend :
Example FMPI2C slave transmitter 3 bytes without 1st data flush,
NOSTRETCH=0: transmission
ADDR TXIS TXIS TXIS reception
SCL stretch
S Address A data1 A data2 A data3 NA P
TXE
legend:
Example FMPI2C slave transmitter 3 bytes, NOSTRETCH=1:
transmission
TXIS TXIS TXIS STOPF
reception
TXE
EV1: wr data1
EV2: TXIS ISR: wr data2
EV3: TXIS ISR: wr data3
EV4: TXIS ISR: wr data4 (not sent)
EV5: STOPF ISR: (optional: set TXE and TXIS), set STOPCF
MS35975V1
Slave receiver
RXNE is set in FMPI2C_ISR when the FMPI2C_RXDR is full, and generates an interrupt if
RXIE is set in FMPI2C_CR1. RXNE is cleared when FMPI2C_RXDR is read.
When a STOP is received and STOPIE is set in FMPI2C_CR1, STOPF is set in
FMPI2C_ISR and an interrupt is generated.
Figure 251. Transfer sequence flowchart for slave receiver with NOSTRETCH=0
Slave reception
Slave initialization
No
FMPI2C_ISR.ADDR
=1?
Yes
SCL
stretched
Read ADDCODE and DIR in FMPI2C_ISR
Set FMPI2C_ICR.ADDRCF
No
FMPI2C_ISR.RXNE
=1?
Yes
Write FMPI2C_RXDR.RXDATA
MSv35966V1
Figure 252. Transfer sequence flowchart for slave receiver with NOSTRETCH=1
Slave reception
Slave initialization
No
No
FMPI2C_ISR.RXNE FMPI2C_ISR.STOPF
=1? =1?
Yes Yes
MSv35967V1
SCL stretch
S Address A data1 A data2 A data3 A
RXNE
transmission
RXNE RXNE RXNE reception
RXNE
tSYNC2 SCLH
SCLL
tSYNC1
SCL
SCL high level detected SCL high level detected SCL high level detected
SCLH counter starts SCLH counter starts SCLH counter starts
SCLL SCLL
MS19858V1
Caution: In order to be I2C or SMBus compliant, the master clock must respect the timings given the
table below.
Note: SCLL is also used to generate the tBUF and tSU:STA timings.
SCLH is also used to generate the tHD:STA and tSU:STO timings.
Refer to Section 23.4.10: FMPI2C_TIMINGR register configuration examples for examples
of FMPI2C_TIMINGR settings vs. FMPI2CCLK frequency.
master re-launches automatically the slave address transmission until ACK is received. In
this case ADDRCF must be set if a NACK is received from the slave, in order to stop
sending the slave address.
If the FMPI2C is addressed as a slave (ADDR=1) while the START bit is set, the FMPI2C
switches to slave mode and the START bit is cleared, when the ADDRCF bit is set.
Note: The same procedure is applied for a Repeated Start condition. In this case BUSY=1.
Master
initialization
Initial settings
End
MSv35968V1
11110XX 0 11110XX 1
Write Read
MSv41066V1
If the master addresses a 10-bit address slave, transmits data to this slave and then
reads data from the same slave, a master transmission flow must be done first. Then a
repeated start is set with the 10 bit slave address configured with HEAD10R=1. In this
case the master sends this sequence: ReStart + Slave address 10-bit header Read.
11110XX 0
Write
11110XX 1
Slave address
Sr R/W A DATA A DATA A P
1st 7 bits
Read
MS19823V1
Master transmitter
In the case of a write transfer, the TXIS flag is set after each byte transmission, after the 9th
SCL pulse when an ACK is received.
A TXIS event generates an interrupt if the TXIE bit is set in the FMPI2C_CR1 register. The
flag is cleared when the FMPI2C_TXDR register is written with the next data byte to be
transmitted.
The number of TXIS events during the transfer corresponds to the value programmed in
NBYTES[7:0]. If the total number of data bytes to be sent is greater than 255, reload mode
must be selected by setting the RELOAD bit in the FMPI2C_CR2 register. In this case,
when NBYTES data have been transferred, the TCR flag is set and the SCL line is stretched
low until NBYTES[7:0] is written to a non-zero value.
The TXIS flag is not set when a NACK is received.
When RELOAD=0 and NBYTES data have been transferred:
– In automatic end mode (AUTOEND=1), a STOP is automatically sent.
– In software end mode (AUTOEND=0), the TC flag is set and the SCL line is
stretched low in order to perform software actions:
A RESTART condition can be requested by setting the START bit in the
FMPI2C_CR2 register with the proper slave address configuration, and number of
bytes to be transferred. Setting the START bit clears the TC flag and the START
condition is sent on the bus.
A STOP condition can be requested by setting the STOP bit in the FMPI2C_CR2
register. Setting the STOP bit clears the TC flag and the STOP condition is sent on
the bus.
If a NACK is received: the TXIS flag is not set, and a STOP condition is automatically
sent after the NACK reception. the NACKF flag is set in the FMPI2C_ISR register, and
an interrupt is generated if the NACKIE bit is set.
Figure 258. Transfer sequence flowchart for FMPI2C master transmitter for N≤255
bytes
Master
transmission
Master initialization
NBYTES = N
AUTOEND = 0 for RESTART; 1 for STOP
Configure slave address
Set FMPI2C_CR2.START
No
No
FMPI2C_ISR.NACKF FMPI2C_ISR.TXIS
= 1? = 1?
Yes Yes
Write FMPI2C_TXDR
End
NBYTES No
transmitted?
Yes
Yes
FMPI2C_ISR.TC
= 1?
Set FMPI2C_CR2.START
No with slave addess NBYTES
...
End
MSv35969V1
Figure 259. Transfer sequence flowchart for FMPI2C master transmitter for N>255
bytes
Master
transmission
Master initialization
No
No
FMPI2C_ISR.NACKF FMPI2C_ISR.TXIS
= 1? = 1?
Yes Yes
Write FMPI2C_TXDR
End
No
NBYTES
transmitted ?
Yes
Yes
FMPI2C_ISR.TC
= 1?
Set FMPI2C_CR2.START
with slave addess No
NBYTES ...
FMPI2C_ISR.TCR
= 1?
Yes
IF N< 256
NBYTES = N; N = 0; RELOAD = 0
AUTOEND = 0 for RESTART; 1 for STOP
End
ELSE
NBYTES = 0xFF; N = N-255
RELOAD = 1
MSv35970V1
reception
S Address A data1 A data2 A P
SCL stretch
INIT EV1 EV2
TXE
NBYTES xx 2
transmission
S Address A data1 A data2 A ReS Address
reception
NBYTES xx 2
MS35980V1
Master receiver
In the case of a read transfer, the RXNE flag is set after each byte reception, after the 8th
SCL pulse. An RXNE event generates an interrupt if the RXIE bit is set in the FMPI2C_CR1
register. The flag is cleared when FMPI2C_RXDR is read.
If the total number of data bytes to be received is greater than 255, reload mode must be
selected by setting the RELOAD bit in the FMPI2C_CR2 register. In this case, when
NBYTES[7:0] data have been transferred, the TCR flag is set and the SCL line is stretched
low until NBYTES[7:0] is written to a non-zero value.
When RELOAD=0 and NBYTES[7:0] data have been transferred:
– In automatic end mode (AUTOEND=1), a NACK and a STOP are automatically
sent after the last received byte.
– In software end mode (AUTOEND=0), a NACK is automatically sent after the last
received byte, the TC flag is set and the SCL line is stretched low in order to allow
software actions:
A RESTART condition can be requested by setting the START bit in the
FMPI2C_CR2 register with the proper slave address configuration, and number of
bytes to be transferred. Setting the START bit clears the TC flag and the START
condition, followed by slave address, are sent on the bus.
A STOP condition can be requested by setting the STOP bit in the FMPI2C_CR2
register. Setting the STOP bit clears the TC flag and the STOP condition is sent on
the bus.
Figure 261. Transfer sequence flowchart for FMPI2C master receiver for N≤255 bytes
Master reception
Master initialization
NBYTES = N
AUTOEND = 0 for RESTART; 1 for STOP
Configure slave address
Set FMPI2C_CR2.START
No
FMPI2C_ISR.RXNE
=1?
Yes
Read FMPI2C_RXDR
NBYTES No
received?
Yes
Yes
FMPI2C_ISR.TC
= 1?
Set FMPI2C_CR2.START
No with slave addess NBYTES
...
End
MSv35971V1
Figure 262. Transfer sequence flowchart for FMPI2C master receiver for N >255 bytes
Master reception
Master initialization
No
FMPI2C_ISR.RXNE
= 1?
Yes
Read FMPI2C_RXDR
NBYTES No
received?
Yes
Yes
FMPI2C_ISR.TC
= 1?
Set FMPI2C_CR2.START
with slave addess No
NBYTES ...
No
FMPI2C_ISR.TCR
= 1?
Yes
IF N< 256
NBYTES =N; N=0;RELOAD=0
AUTOEND=0 for RESTART; 1 for STOP
ELSE
NBYTES =0xFF;N=N-255
RELOAD=1
End
MSv35972V1
RXNE RXNE
legend:
reception
INIT EV1 EV2
SCL stretch
NBYTES xx 2
transmission
S Address A data1 A data2 NA ReS Address
reception
NBYTES
xx 2 N
MS35979V1
PRESC 1 1 0 0
SCLL 0xC7 0x13 0x9 0x6
tSCLL 200 x 250 ns = 50 µs 20 x 250 ns = 5.0 µs 10 x 125 ns = 1250 ns 7 x 125 ns = 875 ns
SCLH 0xC3 0xF 0x3 0x3
tSCLH 196 x 250 ns = 49 µs 16 x 250 ns = 4.0µs 4 x 125 ns = 500 ns 4 x 125 ns = 500 ns
(1)
tSCL ~100 µs(2) ~10 µs(2) ~2500 ns(3) ~2000 ns(4)
SDADEL 0x2 0x2 0x1 0x0
tSDADEL 2 x 250 ns = 500 ns 2 x 250 ns = 500 ns 1 x 125 ns = 125 ns 0 ns
SCLDEL 0x4 0x4 0x3 0x1
tSCLDEL 5 x 250 ns = 1250 ns 5 x 250 ns = 1250 ns 4 x 125 ns = 500 ns 2 x 125 ns = 250 ns
1. SCL period tSCL is greater than tSCLL + tSCLH due to SCL internal detection delay. Values provided for tSCL are examples
only.
2. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 500 ns. Example with tSYNC1 + tSYNC2 = 1000 ns.
3. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 500 ns. Example with tSYNC1 + tSYNC2 = 750 ns.
4. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 500 ns. Example with tSYNC1 + tSYNC2 = 655 ns.
PRESC 3 3 1 0
SCLL 0xC7 0x13 0x9 0x4
tSCLL 200 x 250 ns = 50 µs 20 x 250 ns = 5.0 µs 10 x 125 ns = 1250 ns 5 x 62.5 ns = 312.5 ns
SCLH 0xC3 0xF 0x3 0x2
tSCLH 196 x 250 ns = 49 µs 16 x 250 ns = 4.0 µs 4 x 125 ns = 500 ns 3 x 62.5 ns = 187.5 ns
(1)
tSCL ~100 µs(2) ~10 µs(2) ~2500 ns(3) ~1000 ns(4)
SDADEL 0x2 0x2 0x2 0x0
tSDADEL 2 x 250 ns = 500 ns 2 x 250 ns = 500 ns 2 x 125 ns = 250 ns 0 ns
SCLDEL 0x4 0x4 0x3 0x2
tSCLDEL 5 x 250 ns = 1250 ns 5 x 250 ns = 1250 ns 4 x 125 ns = 500 ns 3 x 62.5 ns = 187.5 ns
1. SCL period tSCL is greater than tSCLL + tSCLH due to SCL internal detection delay. Values provided for tSCL are examples
only.
2. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 250 ns. Example with tSYNC1 + tSYNC2 = 1000 ns.
3. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 250 ns. Example with tSYNC1 + tSYNC2 = 750 ns.
4. tSYNC1 + tSYNC2 minimum value is 4 x tI2CCLK = 250 ns. Example with tSYNC1 + tSYNC2 = 500 ns.
Introduction
The system management bus (SMBus) is a two-wire interface through which various
devices can communicate with each other and with the rest of the system. It is based on I2C
principles of operation. The SMBus provides a control bus for system and power
management related tasks.
This peripheral is compatible with the SMBus specification (http://smbus.org).
The System Management Bus Specification refers to three types of devices.
A slave is a device that receives or responds to a command.
A master is a device that issues commands, generates the clocks and terminates the
transfer.
A host is a specialized master that provides the main interface to the system’s CPU. A
host must be a master-slave and must support the SMBus host notify protocol. Only
one host is allowed in a system.
This peripheral can be configured as master or slave device, and also as a host.
Bus protocols
There are eleven possible command protocols for any given device. A device may use any
or all of the eleven protocols to communicate. The protocols are Quick Command, Send
Byte, Receive Byte, Write Byte, Write Word, Read Byte, Read Word, Process Call, Block
Read, Block Write and Block Write-Block Read Process Call. These protocols should be
implemented by the user software.
For more details of these protocols, refer to SMBus specification (http://smbus.org).
SMBus alert
The SMBus ALERT optional signal is supported. A slave-only device can signal the host
through the SMBALERT# pin that it wants to talk. The host processes the interrupt and
simultaneously accesses all SMBALERT# devices through the alert response address
(0b0001 100). Only the device(s) which pulled SMBALERT# low acknowledges the alert
response address.
When configured as a slave device(SMBHEN=0), the SMBA pin is pulled low by setting the
ALERTEN bit in the FMPI2C_CR1 register. The Alert Response Address is enabled at the
same time.
When configured as a host (SMBHEN=1), the ALERT flag is set in the FMPI2C_ISR register
when a falling edge is detected on the SMBA pin and ALERTEN=1. An interrupt is
generated if the ERRIE bit is set in the FMPI2C_CR1 register. When ALERTEN=0, the
ALERT line is considered high even if the external SMBA pin is low.
If the SMBus ALERT pin is not needed, the SMBA pin can be used as a standard GPIO if
ALERTEN=0.
Timeouts
This peripheral embeds hardware timers in order to be compliant with the 3 timeouts defined
in SMBus specification.
Start Stop
tLOW:SEXT
ClkAck ClkAck
tLOW:MEXT tLOW:MEXT tLOW:MEXT
SMBCLK
SMBDAT
MS19866V1
Timeout detection
The timeout detection is enabled by setting the TIMOUTEN and TEXTEN bits in the
FMPI2C_TIMEOUTR register. The timers must be programmed in such a way that they
detect a timeout before the maximum time given in the SMBus specification.
tTIMEOUT check
In order to enable the tTIMEOUT check, the 12-bit TIMEOUTA[11:0] bits must be
programmed with the timer reload value in order to check the tTIMEOUT parameter. The
TIDLE bit must be configured to ‘0’ in order to detect the SCL low level timeout.
Then the timer is enabled by setting the TIMOUTEN in the FMPI2C_TIMEOUTR
register.
If SCL is tied low for a time greater than (TIMEOUTA+1) x 2048 x tI2CCLK, the TIMEOUT
flag is set in the FMPI2C_ISR register.
Refer to Table 138: Examples of TIMEOUTA settings for various FMPI2CCLK
frequencies (max tTIMEOUT = 25 ms).
Caution: Changing the TIMEOUTA[11:0] bits and TIDLE bit configuration is not allowed when the
TIMEOUTEN bit is set.
tLOW:SEXT and tLOW:MEXT check
Depending on if the peripheral is configured as a master or as a slave, The 12-bit
TIMEOUTB timer must be configured in order to check tLOW:SEXT for a slave and
tLOW:MEXT for a master. As the standard specifies only a maximum, the user can choose
the same value for the both.
Then the timer is enabled by setting the TEXTEN bit in the FMPI2C_TIMEOUTR
register.
If the SMBus peripheral performs a cumulative SCL stretch for a time greater than
(TIMEOUTB+1) x 2048 x tI2CCLK, and in the timeout interval described in Bus idle
detection on page 729 section, the TIMEOUT flag is set in the FMPI2C_ISR register.
Refer to Table 139: Examples of TIMEOUTB settings for various FMPI2CCLK
frequencies
Caution: Changing the TIMEOUTB configuration is not allowed when the TEXTEN bit is set.
Refer to Table 140: Examples of TIMEOUTA settings for various FMPI2CCLK frequencies
(max tIDLE = 50 µs)
Caution: Changing the TIMEOUTA and TIDLE configuration is not allowed when the TIMEOUTEN is
set.
Figure 265. Transfer sequence flowchart for SMBus slave transmitter N bytes + PEC
SMBus slave
transmission
Slave initialization
No
FMPI2C_ISR.ADDR
= 1?
Yes
No
FMPI2C_ISR.TXIS
=1?
Yes
Write FMPI2C_TXDR.TXDATA
MSv35973V1
Figure 266. Transfer bus diagrams for SMBus slave transmitter (SBC=1)
legend:
Example SMBus slave transmitter 2 bytes + PEC,
transmission
ADDR TXIS TXIS reception
NBYTES 3
EV1: ADDR ISR: check ADDCODE, program NBYTES=3, set PECBYTE, set ADDRCF
EV2: TXIS ISR: wr data1
EV3: TXIS ISR: wr data2
MS19869V2
Figure 267. Transfer sequence flowchart for SMBus slave receiver N Bytes + PEC
SMBus slave
reception
Slave initialization
No
FMPI2C_ISR.ADDR
= 1?
Yes
No
FMPI2C_ISR.RXNE =1?
FMPI2C_ISR.TCR = 1?
Yes
Read FMPI2C_RXDR.RXDATA
Program FMPI2C_CR2.NACK = 0
FMPI2C_CR2.NBYTES = 1
N=N-1
No
N = 1?
Yes
Read FMPI2C_RXDR.RXDATA
Program RELOAD = 0
NACK = 0 and NBYTES = 1
No
FMPI2C_ISR.RXNE
=1?
Yes
Read FMPI2C_RXDR.RXDATA
End
MSv35974V1
Figure 268. Bus transfer diagrams for SMBus slave receiver (SBC=1)
legend:
Example SMBus slave receiver 2 bytes + PEC
transmission
ADDR RXNE RXNE RXNE
reception
NBYTES 3
EV1: ADDR ISR: check ADDCODE and DIR, program NBYTES = 3, PECBYTE=1, RELOAD=0, set ADDRCF
EV2: RXNE ISR: rd data1
EV3: RXNE ISR: rd data2
EV4: RXNE ISR: rd PEC
Example SMBus slave receiver 2 bytes + PEC, with ACK control legend :
(RELOAD=1/0) transmission
ADDR RXNE,TCR RXNE,TCR RXNE
reception
NBYTES 1
EV1: ADDR ISR: check ADDCODE and DIR, program NBYTES = 1, PECBYTE=1, RELOAD=1, set ADDRCF
EV2: RXNE-TCR ISR: rd data1, program NACK=0 and NBYTES = 1
EV3: RXNE-TCR ISR: rd data2, program NACK=0, NBYTES = 1 and RELOAD=0
EV4: RXNE-TCR ISR: rd PEC
MS19870V2
This section is relevant only when the SMBus feature is supported. Refer to Section 23.3:
FMPI2C implementation.
In addition to FMPI2C master transfer management (refer to Section 23.4.9: FMPI2C
master mode) some additional software flowcharts are provided to support the SMBus.
When the SMBus master wants to send a RESTART condition after the PEC, software
mode must be selected (AUTOEND=0). In this case, once NBYTES-1 have been
transmitted, the FMPI2C_PECR register content is transmitted and the TC flag is set after
the PEC transmission, stretching the SCL line low. The RESTART condition must be
programmed in the TC interrupt subroutine.
Caution: The PECBYTE bit has no effect when the RELOAD bit is set.
Example SMBus master transmitter 2 bytes + PEC, automatic end mode (STOP)
TXIS TXIS
legend:
reception
INIT EV1 EV2
SCL stretch
TXE
NBYTES xx 3
INIT: program Slave address, program NBYTES = 3, AUTOEND=1, set PECBYTE, set START
EV1: TXIS ISR: wr data1
EV2: TXIS ISR: wr data2
Example SMBus master transmitter 2 bytes + PEC, software end mode (RESTART)
TC legend:
TXIS TXIS
transmission
S Address A data1 A data2 A PEC A Rstart Address
reception
xx 3 N
NBYTES
INIT: program Slave address, program NBYTES = 3, AUTOEND=0, set PECBYTE, set START
EV1: TXIS ISR: wr data1
EV2: TXIS ISR: wr data2
EV3: TC ISR: program Slave address, program NBYTES = N, set START
MS19871V2
Example SMBus master receiver 2 bytes + PEC, automatic end mode (STOP)
reception
INIT EV1 EV2 EV3
SCL stretch
NBYTES xx 3
INIT: program Slave address, program NBYTES = 3, AUTOEND=1, set PECBYTE, set START
EV1: RXNE ISR: rd data1
EV2: RXNE ISR: rd data2
EV3: RXNE ISR: rd PEC
Example SMBus master receiver 2 bytes + PEC, software end mode (RESTART)
transmission
S Address A data1 A data2 A PEC NA Restart Address
reception
NBYTES
xx 3 N
INIT: program Slave address, program NBYTES = 3, AUTOEND=0, set PECBYTE, set START
EV1: RXNE ISR: rd data1
EV2: RXNE ISR: rd data2
EV3: RXNE ISR: read PEC
EV4: TC ISR: program Slave address, program NBYTES = N, set START
MS19872V2
When a bus error is detected, the BERR flag is set in the FMPI2C_ISR register, and an
interrupt is generated if the ERRIE bit is set in the FMPI2C_CR1 register.
Alert (ALERT)
This section is relevant only when the SMBus feature is supported. Refer to Section 23.3:
FMPI2C implementation.
The ALERT flag is set when the FMPI2C interface is configured as a Host (SMBHEN=1),
the alert pin detection is enabled (ALERTEN=1) and a falling edge is detected on the SMBA
pin. An interrupt is generated if the ERRIE bit is set in the FMPI2C_CR1 register.
initialized before setting the START bit. The end of transfer is managed with the
NBYTES counter. Refer to Master transmitter on page 717.
In slave mode:
– With NOSTRETCH=0, when all data are transferred using DMA, the DMA must be
initialized before the address match event, or in ADDR interrupt subroutine, before
clearing ADDR.
– With NOSTRETCH=1, the DMA must be initialized before the address match
event.
For instances supporting SMBus: the PEC transfer is managed with NBYTES counter.
Refer to SMBus slave transmitter on page 731 and SMBus master transmitter on
page 735.
Note: If DMA is used for transmission, the TXIE bit does not need to be enabled.
No effect
Sleep
FMPI2C interrupts cause the device to exit the Sleep mode.
Stop The contents of FMPI2C registers are kept.
Standby The FMPI2C peripheral is powered down and must be reinitialized after exiting Standby.
Read
Receive buffer
RXNE RXIE FMPI2C_RXDR
not empty
register
Write
Transmit buffer
TXIS TXIE FMPI2C_TXDR
interrupt status
register
Stop detection Write
STOPF STOPIE
interrupt flag STOPCF=1
Write
Transfer No
FMPI2C_CR2
complete TCR
with
FMPI2C reload TCIE Yes
NBYTES[7:0] ≠ 0 No
_EV
Transfer Write START=1
TC
complete or STOP=1
Address Write
ADDR ADDRIE
matched ADDRCF=1
NACK Write
FMP NACKF NACKIE
reception NACKCF=1
I2C
Write
Bus error BERR
BERRCF=1
Write
Arbitration loss ARLO
ARLOCF=1
Overrun/
OVR Write OVRCF=1
FMPI2C Underrun
ERRIE Yes No No
_ER Write
PEC error PECERR
PECERRCF=1
Timeout/ Write
TIMEOUT
tLOW error TIMEOUTCF=1
Write
SMBus alert ALERT
ALERTCF=1
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ALERT SMBD SMBH NOSTR
Res. Res. Res. Res. Res. Res. Res. Res. PECEN GCEN Res. SBC
EN EN EN ETCH
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RXDMA TXDMA ANF STOP NACK ADDR
Res. DNF[3:0] ERRIE TCIE RXIE TXIE PE
EN EN OFF IE IE IE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PEC AUTOE RE
Res. Res. Res. Res. Res. NBYTES[7:0]
BYTE ND LOAD
rs rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HEAD1 RD_
NACK STOP START ADD10 SADD[9:0]
0R WRN
rs rs rs rw rw rw rw rw rw rw rw rw rw rw rw rw
one is completed. The latency of the second write access can be up to 2 x PCLK1 + 6 x
FMPI2CCLK.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OA1
OA1EN Res. Res. Res. Res. OA1[9:0]
MODE
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OA2EN Res. Res. Res. Res. OA2MSK[2:0] OA2[7:1] Res.
rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SCLH[7:0] SCLL[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: This register must be configured when the FMPI2C is disabled (PE = 0).
Note: The STM32CubeMX tool calculates and provides the I2C_TIMINGR content in the I2C
Configuration window.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TEXTEN Res. Res. Res. TIMEOUTB[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIMOUTEN Res. Res. TIDLE TIMEOUTA[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: If the SMBus feature is not supported, this register is reserved and forced by hardware to
“0x00000000”. Refer to Section 23.3: FMPI2C implementation.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. ADDCODE[6:0] DIR
r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TIME PEC
BUSY Res. ALERT OVR ARLO BERR TCR TC STOPF NACKF ADDR RXNE TXIS TXE
OUT ERR
r r r r r r r r r r r r r rs rs
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ALERT TIMOU ARLOC BERRC STOPC NACKC ADDR
Res. Res. PECCF OVRCF Res. Res. Res. Res. Res.
CF TCF F F F F CF
w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r
Note: If the SMBus feature is not supported, this register is reserved and forced by hardware to
“0x00000000”. Refer to Section 23.3: FMPI2C implementation.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. RXDATA[7:0]
r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. TXDATA[7:0]
rw rw rw rw rw rw rw rw
0xC
0x24
0x20
0x18
0x14
0x10
0x1C
Offset
RM0390
23.7.12
name
TIMINGR
FMPI2C_
FMPI2C_
Register
TIMEOUTR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
FMPI2C_ISR
FMPI2C_ICR
FMPI2C_CR2
FMPI2C_CR1
FMPI2C_PECR
FMPI2C_OAR2
FMPI2C_OAR1
FMPI2C_RXDR
0
0
Res. Res. Res. Res. TEXTEN Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
0
PRESC[3:0]
Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
0
Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
0
0
Res. Res. Res. Res. Res. Res. Res. PECBYTE Res. 26
0
0
Res. Res. Res. Res. Res. Res. Res. AUTOEND Res. 25
FMPI2C register map
0
0
Res. Res. Res. Res. Res. Res. Res. RELOAD Res. 24
0
0
0
0
0
0
0
0
0
0
[3:0]
0
0
0
0
0
SCLDEL
0
0
0
0
0
TIMEOUTB[11:0]
0
0
0
0
0
ADDCODE[6:0]
0
0
0
0
NBYTES[7:0]
RM0390 Rev 6
[3:0]
0
0
0
0
0
SDADEL
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res. Res. ALERTCF ALERT Res. Res. Res. START Res. 13
0
0
0
0
0
0
0
0
0
0
0
0
SCLH[7:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
K [2:0]
The table below provides the FMPI2C register map and reset values.
OA2MS
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res. TCR ERRIE 7
0
0
0
0
0
0
0
0
0
Res. TC TCIE 6
0
0
0
0
0
0
0
0
0
0
STOPCF STOPF STOPIE 5
0
0
0
0
0
0
0
0
0
0
NACKCF NACKF NACKIE 4
OA1[9:0]
TIMEOUTA[11:0]
SADD[9:0]
OA2[7:1]
0
0
0
0
0
0
0
0
0
0
ADDRCF ADDR ADDRIE 3
PEC[7:0]
SCLL[7:0]
0
0
0
0
0
0
0
0
0
RXDATA[7:0]
Res. RXNE RXIE 2
0
0
0
0
0
0
0
0
0
Res. TXIS TXIE 1
1
0
0
0
0
0
0
0
0
757/1347
Fast-mode Plus Inter-integrated circuit (FMPI2C) interface
758
Fast-mode Plus Inter-integrated circuit (FMPI2C) interface RM0390
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
name
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
FMPI2C_TXDR TXDATA[7:0]
0x28
Reset value 0 0 0 0 0 0 0 0
Note: Some of the above features may not be available in certain products. The user should refer
to the product data sheet, to identify the specific features supported by the I2C interface
implementation.
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 271.
SDA
MSB ACK
SCL
1 2 8 9
Start Stop
condition condition
Acknowledge may be enabled or disabled by software. The I2C interface addresses (dual
addressing 7-bit/ 10-bit and/or general call address) can be selected by software.
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.
Note: In 10-bit addressing mode, the comparison includes the header sequence (11110xx0),
where xx denotes the two most significant bits of the address.
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 enters 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 273 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.
S Header A Address A
EV1
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 274).
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 275 and Figure 276 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 275 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 275 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.
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 276 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.
24.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 9 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.
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 automatically considers the next byte as a PEC and checks 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 ORed on the same interrupt
channel.
BERR, ARLO, AF, OVR, PECERR, TIMEOUT and SMBALERT are logically ORed on the
same interrupt channel.
STOPF
it_event
BTF
TxE
ITBUFEN
RxNE
ITERREN
BERR
ARLO
it_error
AF
OVR
PECERR
TIMEOUT
SMBALERT
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
SMB GEN
PEC[7:0] DUALF DEFAU Res. TRA BUSY MSL
HOST CALL
LT
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 Res. Res. CCR[11:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. ANOFF DNF[3:0]
rw rw rw rw rw
0x1C
0x0C
Offset
RM0390
24.6.11
I2C_DR
I2C_SR2
I2C_SR1
I2C_CR2
I2C_CR1
I2C_CCR
I2C_FLTR
I2C_OAR2
I2C_OAR1
I2C_TRISE
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 27
I2C register map
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 25
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 24
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 23
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 22
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 21
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 20
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 19
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 18
RM0390 Rev 6
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
0
0
0
0
Res. Res. DUTY TIMEOUT Res. Res. Res. Res. Res. 14
0
0
0
0
0
0
0
0
0
0
0
Table 147. I2C register map and reset values
PEC[7:0]
The table below provides the I2C register map and reset values.
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
ADD[
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
CCR[11:0]
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
ADD[7:1]
Res.
ADD2[7:1]
ADD10 SMBTYPE 3
DR[7:0]
0
0
0
0
0
0
0
0
0
TRISE[5:0]
0
0
0
0
1
0
0
0
0
0
DNF[3:0]
0
0
0
0
0
0
0
0
0
0
793/1347
793
Universal synchronous receiver transmitter (USART) /universal asynchronous receiver transmit-
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 25.6: USART registers for the definition of each bit.
The following pin is required to interface in synchronous mode:
SCLK: 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, SCLK can provide the clock to the
smartcard.
The following pins are required in Hardware flow control mode:
nCTS: Clear To Send blocks the data transmission at the end of the current transfer
when high
nRTS: Request to send indicates that the USART is ready to receive a data (when
low).
PWDATA PRDATA
Write Read (Data register) DR
RX IrDA
SIR
SW_RX Receive Shift Register
ENDEC Transmit Shift Register
block
IRDA_OUT
IRDA_IN GTPR
GT PSC SCLK control SCLK
CR3 CR2
DMAT DMAR SCEN NACK HD IRLP IREN LINE STOP[1:0] CKEN CPOL CPHA LBCL
CR2 CR1
USART Address UE M WAKE PCE PS PEIE
nRTS Hardware
flow
nCTS controller
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
Figure 279.gWord
( length programming
), p
Data frame Next data frame
Possible
parity bit Next
Start Stop Start
Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8
bit bit bit
Clock **
Start
Idle frame bit
Clock **
Start
Idle frame bit
MS37358V1
25.4.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 SCLK 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 278).
Every character is preceded by a start bit that 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 Next data frame
Parity
Data frame
Bit Next
Start start
Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 bit
1 1/2 stop bits
b) 1 1/2 stop Bits
Possible Next data frame
parity
Data frame
bit Next
Start 2 Stop Start
Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bits Bit
Procedure:
1. Enable the USART by writing the UE bit in USART_CR1 register to 1.
2. Program the M bit in USART_CR1 to define the word length.
3. Program the number of stop bits in USART_CR2.
4. Select DMA enable (DMAT) in USART_CR3 if Multi buffer Communication is to take
place. Configure the DMA register as explained in multibuffer communication.
5. Select the desired baud rate using the USART_BRR register.
6. Set the TE bit in USART_CR1 to send an idle frame as first transmission.
7. Write the data to send in the USART_DR register (this clears the TXE bit). Repeat this
for each data to be transmitted in case of single buffer.
8. After writing the last data into the USART_DR register, wait until TC=1. This indicates
that the transmission of the last frame is complete. This is required for instance when
the USART is disabled or enters the Halt mode to avoid corrupting the last
transmission.
When a transmission is taking place, a write instruction to the USART_DR register stores
the data in the TDR register and which is copied in the shift register at the end of the current
transmission.
When no transmission is taking place, a write instruction to the USART_DR register places
the data directly in the shift register, the data transmission starts, and the TXE bit is
immediately set.
If a frame is transmitted (after the stop bit) and the TXE bit is set, the TC bit goes high. An
interrupt is generated if the TCIE bit is set in the USART_CR1 register.
After writing the last data into the USART_DR register, it is mandatory to wait for TC=1
before disabling the USART or causing the microcontroller to enter the low power mode
(see Figure 281: 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.
Break characters
Setting the SBK bit transmits a break character. The break frame length depends on the M
bit (see Figure 279).
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.
25.4.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 that 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 149) 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 tolerance to clock deviations (see Section 25.4.5: USART
receiver tolerance to clock deviation). 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 that 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 that 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.
1. 0.5 stop bit (reception in Smartcard mode): No sampling is done for 0.5 stop bit. As
a consequence, no framing error and no break frame can be detected when 0.5 stop bit
is selected.
2. 1 stop bit: Sampling for 1 stop Bit is done on the 8th, 9th and 10th samples.
3. 1.5 stop bits (Smartcard mode): When transmitting in smartcard mode, the device
must check that the data is correctly sent. Thus the receiver block must be enabled (RE
=1 in the USART_CR1 register) and the stop bit is checked to test if the smartcard has
detected a parity error. In the event of a parity error, the smartcard forces the data
signal low during the sampling - NACK signal-, which is flagged as a framing error.
Then, the FE flag is set with the RXNE at the end of the 1.5 stop bit. Sampling for 1.5
stop bits is done on the 16th, 17th and 18th samples (1 baud clock period after the
beginning of the stop bit). The 1.5 stop bit can be decomposed into two parts: one 0.5
baud clock period during which nothing happens, followed by 1 normal stop bit period
during which sampling occurs halfway through. Refer to Section 25.4.11 for more
details.
4. 2 stop bits: Sampling for 2 stop bits is done on the 8th, 9th and 10th samples of the first
stop bit. If a framing error is detected during the first stop bit the framing error flag will
be set. The second stop bit is not checked for framing error. The RXNE flag will be set
at the end of the first stop bit.
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 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
The nearest real number is 0d8 = 0x8 => overflow of the DIV_frac[2:0] => carry must be
added up to the mantissa
DIV_Mantissa = mantissa (0d50.990 + carry) = 0d51 = 0x33
Then, USART_BRR = 0x0330 => USARTDIV = 0d51.000
Table 150. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 12 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8=0)
Table 151. 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 151. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 12 MHz,
oversampling by 8(1) (continued)
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 152. Error calculation for programmed baud rates at fPCLK = 16 MHz or fPCLK = 24 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8 = 0)
Table 153. Error calculation for programmed baud rates at fPCLK = 16 MHz or fPCLK = 24 MHz,
oversampling by 8(1)
Oversampling by 8 (OVER8=1)
Table 154. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 16(1)
Oversampling by 16 (OVER8=0)
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%
6 230.4 KBps 228.571 KBps 2.1875 0.79% 231.884 KBps 4.3125 0.64%
7 460.8 KBps 470.588 KBps 1.0625 2.12% 457.143 KBps 2.1875 0.79%
Table 154. Error calculation for programmed baud rates at fPCLK = 8 MHz or fPCLK = 16 MHz,
oversampling by 16(1) (continued)
Oversampling by 16 (OVER8=0)
Table 155. 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%
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%
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 156. 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.769 KBps 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%
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%
11 1.8432 MBps 1.8750 MBps 1.0000 1.73% 1.8182 MBps 2.0625 1.52%
12 3.584 MBps NA NA NA 3.2594 MBps 1.0625 1.52%
13 3.6864 MBps NA NA NA 3.7500 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 157. 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%
Table 157. 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)
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%
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 158. 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 158. 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)
10 921.6 KBps 913.043 KBps 2.875 0.93 923.076 KBps 5.6875 0.93
11 1.792 MBps 1.826 MBps 1.4375 1.9 1.787 MBps 2.9375 0.27
12 1.8432 MBps 1.826 MBps 1.4375 0.93 1.826 MBps 2.875 0.93
13 3.584 MBps NA NA NA 3.652 MBps 1.4375 1.9
14 3.6864 MBps NA NA NA 3.652 MBps 1.4375 0.93
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 159. 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 159. 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 160 and Table 161 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
MSv31154V1
RX IDLE Addr=0 Data 1 Data 2 IDLE Addr=1 Data 3 Data 4 Addr=2 Data 5
Non-matching address
MSv31155V1
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 25.4.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 in Figure 287.
Examples of break frames are given on Figure 288, where we suppose that LBDL=1 (11-bit
break length), and M=0 (8-bit data).
Figure 287. Break detection in LIN mode (11-bit break length - LBDL bit is set)
Case 1: break signal not long enough => break discarded, LBDF is not set
Break frame
RX line
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 1
Case 2: break signal just long enough => break detected, LBDF is set
Break frame
RX line
Delimiter is immediate
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 B10 Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 0
LBDF
Case 3: break signal long enough => break detected, LBDF is set
Break frame
RX line
Capture strobe
Break state
Idle Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Bit8 Bit9 Bit10 wait delimiter Idle
machine
Read samples 0 0 0 0 0 0 0 0 0 0 0
LBDF
MSv31156V1
Figure 288. Break detection in LIN mode vs. Framing error detection
Case 1: break occurring after an Idle
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 (SCLK is always an output).
RX Data out
TX Data in
Synchronous device
USART
(e.g. slave SPI)
SCLK Clock
MSv31158V1
Data on TX
0 1 2 3 4 5 6 7
(from master)
Start LSB MSB Stop
Data on RX
0 1 2 3 4 5 6 7
(from slave)
LSB MSB
*
Capture strobe
*LBCL bit controls last data pulse
MSv34709V2
Clock (CPOL=0,
CPHA=0) *
Clock (CPOL=0,
CPHA=1) *
Clock (CPOL=1, *
CPHA=0)
Clock (CPOL=1, *
CPHA=1)
Data on TX
0 1 2 3 4 5 6 7 8
(from master)
Start LSB MSB Stop
Data on RX
0 1 2 3 4 5 6 7 8
(from slave)
LSB MSB
Capture *
strobe
*LBCL bit controls last data pulse
MSv34710V1
SCLK
(capture strobe on SCLK
rising edge in this example)
tSETUP tHOLD
Note: The function of SCLK is different in Smartcard mode. Refer to the Smartcard mode chapter
for more details.
25.4.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 293 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 294 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 294. Parity error detection using the 1.5 stop bits
Bit 7 Parity bit 1.5 Stop bit
Sampling at Sampling at
8th, 9th, 10th 16th, 17th, 18th
0.5 bit
time
Sampling at Sampling at
8th, 9th, 10th 8th, 9th, 10th
MS37359V1
The USART can provide a clock to the smartcard through the SCLK output. In smartcard
mode, SCLK is not associated to the communication but is simply derived from the internal
peripheral input clock through a 5-bit prescaler. The division ratio is configured in the
SIREN
TX
OR USART_TX
SIR
Transmit IrDA_OUT
Encoder
USART
SIR
RX
Receive IrDA_IN
DEcoder
USART_RX
MSv31164V2
IrDA_OUT
Bit period 3/16
IrDA_IN
RX 0 1 0 1 0 0 1 1 0 1
MSv31165V1
USART_TDR F1 F2 F3
TC flag Set by
hardware
DMA writes
USART_TDR
Cleared
DMA TCIF flag by
Set by hardware software
(transfer
complete)
ai17192b
Set by hardware
RXNE flag cleared by DMA read
DMA request
USART_TDR F1 F2 F3
DMA reads
USART_TDR
Cleared
DMA TCIF flag Set by hardware by
(transfer complete) software
USART 1 USART 2
TX RX
TX circuit RX circuit
nCTS nRTS
RX TX
RX circuit TX circuit
nRTS nCTS
MSv31169V1
RTS and CTS flow control can be enabled independently by writing respectively RTSE and
CTSE bits to 1 (in the USART_CR3 register).
nRTS
MSv31168V1
nCTS
Note: Special behavior of break frames: when the CTS flow is enabled, the transmitter does not
check the nCTS input state to send a break.
The USART interrupt events are connected to the same interrupt vector (see Figure 302).
During transmission: Transmission Complete, Clear to Send or Transmit Data Register
empty interrupt.
While receiving: Idle Line detection, Overrun error, Receive Data register not empty,
Parity error, LIN break detection, Noise Flag (only in multi buffer communication) and
Framing Error (only in multi buffer communication).
These events generate an interrupt if the corresponding Enable Control Bit is set.
TC
TCIE
TXE
TXEIE
CTS
CTSIE
IDLE
IDLEIE
RXNEIE
ORE
RXNEIE
RXNE USART
interrupt
PE
PEIE
LBD
LBDIE
FE
NE
ORE EIE
DMAR
MS35853V1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. CTS LBD TXE TC RXNE IDLE ORE NF FE PE
rc_w0 rc_w0 r rc_w0 rc_w0 r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. DR[8: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
DIV_Mantissa[11:0] DIV_Fraction[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
OVER8 Res. UE M WAKE PCE PS PEIE TXEIE TCIE RXNEIE IDLEIE TE RE RWU SBK
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. LINEN STOP[1:0] CLKEN CPOL CPHA LBCL Res. LBDIE LBDL Res. ADD[3:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: These 3 bits (CPOL, CPHA, LBCL) should not be written while the transmitter is enabled.
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
GT[7:0] PSC[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
0x0C
Offset
25.6.8
RM0390
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
USART_SR
USART_DR
USART_CR3
USART_CR2
USART_CR1
USART_BRR
USART_GTPR
Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. 28
Res. Res. Res. Res. Res. Res. Res. 27
Res. Res. Res. Res. Res. Res. Res. 26
Res. Res. Res. Res. Res. Res. Res. 25
USART register map
RM0390 Rev 6
Res. Res. Res. Res. Res. Res. Res. 16
0
0
0
0
0
0
0
0
0
0
0
0
0
0
STOP
0
0
0
0
0
GT[7:0]
ONEBI CLKEN WAKE Res. Res. 11
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
HDSEL TE ORE 3
PSC[7:0]
0
0
0
0
0
0
0
IRLP RE NF 2
[3:0]
0
0
0
0
0
0
0
IREN RWU FE 1
ADD[3:0]
0
0
0
0
0
0
0
DIV_Fraction
Universal synchronous receiver transmitter (USART) /universal asynchronous receiver
845/1347
EIE SBK PE 0
845
Serial peripheral interface/ inter-IC sound (SPI/I2S) RM0390
26.1 Introduction
The SPI/I²S interface can be used to communicate with external devices using the SPI
protocol or the I2S audio protocol. SPI or I2S mode is selectable by software. SPI mode is
selected by default after a device reset.
The serial peripheral interface (SPI) protocol supports half-duplex, full-duplex and simplex
synchronous, serial communication with external devices. The interface can be configured
as master and in this case it provides the communication clock (SCK) to the external slave
device. The interface is also capable of operating in multimaster configuration.
The Inter-IC sound (I2S) protocol is also a synchronous serial communication interface. It
can operate in slave or master mode with half-duplex communication. Full duplex
operations are possible by combining two I2S blocks.
It can address four different audio standards including the Philips I2S standard, the MSB-
and LSB-justified standards and the PCM standard.
Read
Rx
buffer
CRC controller
MOSI
MISO Shift register
LSBFIRST CRCEN
CPOL CRCNEXT
CPHA
DFF
TX
buffer
Write Communication
BIDIOE controller
BIDIMODE
RXOLNY
Baud rate
SCK Internal NSS
generator BR[2:0]
NSS
NSS logic
MSv33711V1
Four I/O pins are dedicated to SPI communication with external devices.
MISO: Master In / Slave Out data. In the general case, this pin is used to transmit data
in slave mode and receive data in master mode.
MOSI: Master Out / Slave In data. In the general case, this pin is used to transmit data
in master mode and receive data in slave mode.
SCK: Serial Clock output pin for SPI masters and input pin for SPI slaves.
NSS: Slave select pin. Depending on the SPI and NSS settings, this pin can be used to
either:
– select an individual slave device for communication
– synchronize the data frame or
– detect a conflict between multiple masters
See Section 26.3.5: Slave select (NSS) pin management for details.
The SPI bus allows the communication between one master device and one or more slave
devices. The bus consists of at least two wires - one for the clock signal and the other for
synchronous data transfer. Other signals can be added depending on the data exchange
between SPI nodes and their slave select signal management.
Full-duplex communication
By default, the SPI is configured for full-duplex communication. In this configuration, the
shift registers of the master and slave are linked using two unidirectional lines between the
MOSI and the MISO pins. During SPI communication, data is shifted synchronously on the
SCK clock edges provided by the master. The master transmits the data to be sent to the
slave via the MOSI line and receives data from the slave via the MISO line. When the data
frame transfer is complete (all the bits are shifted) the information between the master and
slave is exchanged.
MISO MISO
Rx shift register Tx shift register
MOSI MOSI
Tx shift register Rx shift register
MSv39623V1
1. The NSS pins can be used to provide a hardware control flow between master and slave. Optionally, the
pins can be left unused by the peripheral. Then the flow has to be handled internally for both master and
slave. For more details see Section 26.3.5: Slave select (NSS) pin management.
Half-duplex communication
The SPI can communicate in half-duplex mode by setting the BIDIMODE bit in the
SPIx_CR1 register. In this configuration, one single cross connection line is used to link the
shift registers of the master and slave together. During this communication, the data is
synchronously shifted between the shift registers on the SCK clock edge in the transfer
direction selected reciprocally by both master and slave with the BDIOE bit in their
SPIx_CR1 registers. In this configuration, the master’s MISO pin and the slave’s MOSI pin
are free for other application uses and act as GPIOs.
(2)
MISO MISO
Rx shift register Tx shift register
(3)
MOSI 1kΩ (2)
Tx shift register MOSI Rx shift register
MSv39624V1
1. The NSS pins can be used to provide a hardware control flow between master and slave. Optionally, the
pins can be left unused by the peripheral. Then the flow has to be handled internally for both master and
slave. For more details see Section 26.3.5: Slave select (NSS) pin management.
2. In this configuration, the master’s MISO pin and the slave’s MOSI pin can be used as GPIOs.
3. A critical situation can happen when communication direction is changed not synchronously between two
nodes working at bidirectionnal mode and new transmitter accesses the common data line while former
transmitter still keeps an opposite value on the line (the value depends on SPI configuration and
communication data). Both nodes then fight while providing opposite output levels on the common line
temporary till next node changes its direction settings correspondingly, too. It is suggested to insert a serial
resistance between MISO and MOSI pins at this mode to protect the outputs and limit the current blowing
between them at this situation.
Simplex communications
The SPI can communicate in simplex mode by setting the SPI in transmit-only or in receive-
only using the RXONLY bit in the SPIx_CR2 register. In this configuration, only one line is
used for the transfer between the shift registers of the master and slave. The remaining
MISO and MOSI pins pair is not used for communication and can be used as standard
GPIOs.
Transmit-only mode (RXONLY=0): The configuration settings are the same as for full-
duplex. The application has to ignore the information captured on the unused input pin.
This pin can be used as a standard GPIO.
Receive-only mode (RXONLY=1): The application can disable the SPI output function
by setting the RXONLY bit. In slave configuration, the MISO output is disabled and the
pin can be used as a GPIO. The slave continues to receive data from the MOSI pin
while its slave select signal is active (see 26.3.5: Slave select (NSS) pin management).
Received data events appear depending on the data buffer configuration. In the master
configuration, the MOSI output is disabled and the pin can be used as a GPIO. The
clock signal is generated continuously as long as the SPI is enabled. The only way to
stop the clock is to clear the RXONLY bit or the SPE bit and wait until the incoming
pattern from the MISO pin is finished and fills the data buffer structure, depending on its
configuration.
MSv39625V1
1. The NSS pins can be used to provide a hardware control flow between master and slave. Optionally, the
pins can be left unused by the peripheral. Then the flow has to be handled internally for both master and
slave. For more details see Section 26.3.5: Slave select (NSS) pin management.
2. An accidental input information is captured at the input of transmitter Rx shift register. All the events
associated with the transmitter receive flow must be ignored in standard transmit only mode (e.g. OVF
flag).
3. In this configuration, both the MISO pins can be used as GPIOs.
Note: Any simplex communication can be alternatively replaced by a variant of the half-duplex
communication with a constant setting of the transaction direction (bidirectional mode is
enabled while BDIO bit is not changed).
NSS (1)
MISO MISO
Rx shift register Tx shift register
MOSI MOSI
Tx shift register Rx shift register
MISO
Tx shift register
MOSI
Rx shift register
SCK
NSS
Slave 2
MISO
Tx shift register
MOSI
Rx shift register
SCK
NSS
Slave 3
MSv39626V1
1. NSS pin is not used on master side at this configuration. It has to be managed internally (SSM=1, SSI=1) to
prevent any MODF error.
2. As MISO pins of the slaves are connected together, all slaves must have the GPIO configuration of their
MISO pin set as alternate function open-drain (see Section 9.3.7: I/O alternate function input/output on
page 242).
MISO MISO
Rx (Tx) shift register Rx (Tx) shift register
MOSI MOSI
Tx (Rx) shift register Tx (Rx) shift register
MSv39628V1
1. The NSS pin is configured at hardware input mode at both nodes. Its active level enables the MISO line
output control as the passive node is configured as a slave.
– NSS output enable (SSM=0,SSOE = 1): this configuration is only used when the
MCU is set as master. The NSS pin is managed by the hardware. The NSS signal
is driven low as soon as the SPI is enabled in master mode (SPE=1), and is kept
low until the SPI is disabled (SPE =0).
– NSS output disable (SSM=0, SSOE = 0): if the microcontroller is acting as the
master on the bus, this configuration allows multimaster capability. If the NSS pin
is pulled low in this mode, the SPI enters master mode fault state and the device is
automatically reconfigured in slave mode. In slave mode, the NSS pin works as a
standard “chip select” input and the slave is selected while NSS line is at low level.
NSS Master
Slave mode
Inp. mode
Vdd OK Non active
1 Vss Conflict Active
NSS Input
0
NSS GPIO
pin logic
aiv14746e
CPOL = 0
NSS
(to slave)
Capture strobe
CPHA =0
CPOL = 1
CPOL = 0
NSS
(to slave)
Capture strobe
ai17154d
Tx buffer handling
The data frame is loaded from the Tx buffer into the shift register during the first bit
transmission. Bits are then shifted out serially from the shift register to a dedicated output
pin depending on LSBFIRST bit setting.The TXE flag (Tx buffer empty) is set when the data
are transferred from the Tx buffer to the shift register. It indicates that the internal Tx buffer is
ready to be loaded with the next data. An interrupt can be generated if the TXEIE bit of the
SPI_CR2 register is set. Clearing the TXE bit is performed by writing to the SPI_DR register.
A continuous transmit stream can be achieved if the next data to be transmitted are stored
in the Tx buffer while previous frame transmission is still ongoing. When the software writes
to Tx buffer while the TXE flag is not set, the data waiting for transaction is overwritten.
Rx buffer handling
The RXNE flag (Rx buffer not empty) is set on the last sampling clock edge, when the data
are transferred from the shift register to the Rx buffer. It indicates that data are ready to be
read from the SPI_DR register. An interrupt can be generated if the RXNEIE bit in the
SPI_CR2 register is set. Clearing the RXNE bit is performed by reading the SPI_DR
register.
If a device has not cleared the RXNE bit resulting from the previous data byte transmitted,
an overrun condition occurs when the next value is buffered. The OVR bit is set and an
interrupt is generated if the ERRIE bit is set.
Another way to manage the data exchange is to use DMA (see Section 9.2: DMA main
features).
Sequence handling
The BSY bit is set when a current data frame transaction is ongoing. When the clock signal
runs continuously, the BSY flag remains set between data frames on the master side.
However, on the slave side, it becomes low for a minimum duration of one SPI clock cycle
between each data frame transfer.
For some configurations, the BSY flag can be used during the last data transfer to wait until
the completion of the transfer.
When a receive-only mode is configured on the master side, either in half-duplex
(BIDIMODE=1, BIDIOE=0) or simplex configuration (BIDIMODE=0, RXONLY=1), the
master starts the receive sequence as soon as the SPI is enabled. Then the clock signal is
provided by the master and it does not stop until either the SPI or the receive-only mode is
disabled by the master. The master receives data frames continuously up to this moment.
While the master can provide all the transactions in continuous mode (SCK signal is
continuous), it has to respect slave capability to handle data flow and its content at anytime.
When necessary, the master must slow down the communication and provide either a
slower clock or separate frames or data sessions with sufficient delays. Be aware there is no
underflow error signal for slave operating in SPI mode, and that data from the slave are
always transacted and processed by the master even if the slave cannot not prepare them
correctly in time. It is preferable for the slave to use DMA, especially when data frames are
shorter and bus rate is high.
Each sequence must be encased by the NSS pulse in parallel with the multislave system to
select just one of the slaves for communication. In single slave systems, using NSS to
control the slave is not necessary. However, the NSS pulse can be used to synchronize the
slave with the beginning of each data transfer sequence. NSS can be managed either by
software or by hardware (see Section 26.3.4: Multi-master communication).
Refer to Figure 311 and Figure 312 for a description of continuous transfers in master / full-
duplex and slave full-duplex mode.
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
Note: During discontinuous communications, there is a 2 APB clock period delay between the
write operation to the SPI_DR register and BSY bit setting. As a consequence it is
mandatory to wait first until TXE is set and then until BSY is cleared after writing the last
data.
The correct disable procedure for certain receive-only modes is:
1. Interrupt the receive flow by disabling SPI (SPE=0) in the specific time window while
the last data frame is ongoing.
2. Wait until BSY=0 (the last data frame is processed).
3. Read received data.
Note: To stop a continuous receive sequence, a specific time window must be respected during
the reception of the last data frame. It starts when the first bit is sampled and ends before
the last bit transfer starts.
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
The BSY flag is cleared under any one of the following conditions:
When the SPI is correctly disabled
When a fault is detected in Master mode (MODF bit set to 1)
In Master mode, when it finishes a data transmission and no new data is ready to be
sent
In Slave mode, when the BSY flag is set to '0' for at least one SPI clock cycle between
each data transfer.
Note: It is recommended to use always the TXE and RXNE flags (instead of the BSY flags) to
handle data transmission or reception operations.
26.4.1 TI mode
TI protocol in master mode
The SPI interface is compatible with the TI protocol. The FRF bit of the SPIx_CR2 register
can be used to configure the SPI to be compliant with this protocol.
The clock polarity and phase are forced to conform to the TI protocol requirements whatever
the values set in the SPIx_CR1 register. NSS management is also specific to the TI protocol
which makes the configuration of NSS management through the SPIx_CR1 and SPIx_CR2
registers (SSM, SSI, SSOE) impossible in this case.
In slave mode, the SPI baud rate prescaler is used to control the moment when the MISO
pin state changes to HiZ when the current transaction finishes (see Figure 315). Any baud
rate can be used, making it possible to determine this moment with optimal flexibility.
However, the baud rate is generally set to the external master clock baud rate. The delay for
the MISO signal to become HiZ (trelease) depends on internal resynchronization and on the
baud rate value set in through the BR[2:0] bits in the SPIx_CR1 register. It is given by the
formula:
t baud_rate t baud_rate
---------------------- + 4 t pclk t release ---------------------
- + 6 t pclk
2 2
If the slave detects a misplaced NSS pulse during a data frame transaction the TIFRE flag is
set.
This feature is not available for Motorola SPI communications (FRF bit set to 0).
Note: 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 interrupts are always generated, while
when BIDIMODE is set to 1, data are not received and OVR is never set.
Figure 315 shows the SPI communication waveforms when TI mode is selected.
NSS
tri ng
g
t RELEASE
in
in
i
er
er
sa r
pl
pl
pl
e
gg
gg
gg
m
m
sa
sa
tri
tr i
SCK
FRAME 1 FRAME 2
MS19835V2
CRC principle
CRC calculation is enabled by setting the CRCEN bit in the SPIx_CR1 register before the
SPI is enabled (SPE = 1). The CRC value is calculated using an odd programmable
polynomial on each bit. The calculation is processed on the sampling clock edge defined by
the CPHA and CPOL bits in the SPIx_CR1 register. The calculated CRC value is checked
automatically at the end of the data block as well as for transfer managed by CPU or by the
DMA. When a mismatch is detected between the CRC calculated internally on the received
data and the CRC sent by the transmitter, a CRCERR flag is set to indicate a data corruption
error. The right procedure for handling the CRC calculation depends on the SPI
configuration and the chosen transfer management.
Note: The polynomial value should only be odd. No even values are supported.
The received CRC is stored in the Rx buffer like any other data frame.
A CRC-format transaction takes one more data frame to communicate at the end of data
sequence.
When the last CRC data is received, an automatic check is performed comparing the
received value and the value in the SPIx_RXCRC register. Software has to check the
CRCERR flag in the SPIx_SR register to determine if the data transfers were corrupted or
not. Software clears the CRCERR flag by writing '0' to it.
After the CRC reception, the CRC value is stored in the Rx buffer and must be read in the
SPIx_DR register in order to clear the RXNE flag.
Tx buffer
CRC CH
16-bit BSY OVR MODF UDR TxE RxNE FRE
ERR SIDE
MOSI/SD
Shift register
MISO LSB first Communication
16-bit control
Rx buffer
NSS/WS
I2S
I2SE
MOD
SPI LSB
SPE BR2 BR1 BR0 MSTR CPOL CPHA
baud rate generator First
CK
I2SMOD
MCK I2SxCLK
MCKOE ODD I2SDIV[7:0]
MS32126V1
STM32 STM32
MCK (O) MCK (O)
spix_tx_dm SD (O) spix_rx_dm SD (I)
a SPI2Sx a SPI2Sx
(MASTER-TX) CK (O) (MASTER-RX) CK (O)
External External
WS (O) WS (O)
slave slave
device device
WS (I) WS (I)
spix_rx_dm SPI2Sy CK (I) spix_tx_dm SPI2Sy CK (I)
a (SLAVE-RX) a (SLAVE-TX)
SD (I) SD (O)
MSv42093V1
The I2S interface supports four audio standards, configurable using the I2SSTD[1:0] and
PCMSYNC bits in the SPIx_I2SCFGR register.
Figure 318. 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 319. 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 SPIx_DR register.
In transmission mode:
If 0x8EAA33 has to be sent (24-bit):
MS19593V1
In reception mode:
If data 0x8EAA33 is received:
MS19594V1
Figure 322. 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 the SPIx_DR register is required. The 16 remaining
bits are forced by hardware to 0x0000 to extend the data to 32-bit format.
If the data to transmit or the received data are 0x76A3 (0x76A30000 extended to 32-bit), the
operation shown in Figure 323 is required.
Figure 323. Example of 16-bit data frame extended to 32-bit channel frame
0x76A3
MS19595V1
For transmission, each time an MSB is written to SPIx_DR, the TXE flag is set and its
interrupt, if allowed, is generated to load the SPIx_DR register with the new value to send.
This takes place even if 0x0000 have not yet been sent because it is done by hardware.
For reception, the RXNE flag is set and its interrupt, if allowed, is generated when the first
16 MSB half-word is received.
In this way, more time is provided between two write or read operations, which prevents
underrun or overrun conditions (depending on the direction of the data transfer).
Figure 324. 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 326. 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 SPIx_DR register
are required by software or by DMA. The operations are shown below.
0xXX34 0x78AE
In reception mode:
If data 0x3478AE are received, two successive read operations from the SPIx_DR
register are required on each RXNE event.
0xXX34 0x78AE
MS19597V1
Figure 331. 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 the SPIx_DR register is required. The 16 remaining
bits are forced by hardware to 0x0000 to extend the data to 32-bit format. In this case it
corresponds to the half-word MSB.
If the data to transmit or the received data are 0x76A3 (0x0000 76A3 extended to 32-bit),
the operation shown in Figure 332 is required.
Figure 332. Example of 16-bit data frame extended to 32-bit channel frame
Only one access to the SPIx-DR register
0x76A3
MS19598V1
In transmission mode, when a TXE event occurs, the application has to write the data to be
transmitted (in this case 0x76A3). The 0x000 field is transmitted first (extension on 32-bit).
The TXE flag is set again as soon as the effective data (0x76A3) is sent on SD.
In reception mode, RXNE is asserted as soon as the significant half-word is received (and
not the 0x0000 field).
In this way, more time is provided between two write or read operations to prevent underrun
or overrun conditions.
PCM standard
For the PCM standard, there is no need to use channel-side information. The two PCM
modes (short and long frame) are available and configurable using the PCMSYNC bit in
SPIx_I2SCFGR register.
CK
WS
short frame
13-bits
WS
long frame
MS30106V1
For long frame synchronization, the WS signal assertion time is fixed to 13 bits in master
mode.
For short frame synchronization, the WS synchronization signal is only one cycle long.
Figure 334. PCM standard waveforms (16-bit extended to 32-bit packet frame)
CK
WS
short frame
Up to 13-bits
WS
long frame
16 bits
SD MSB LSB
MS30107V1
Note: For both modes (master and slave) and for both synchronizations (short and long), the
number of bits between two consecutive pieces of data (and so two synchronization signals)
needs to be specified (DATLEN and CHLEN bits in the SPIx_I2SCFGR register) even in
slave mode.
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.
Figure 336 presents the communication clock architecture. The I2SxCLK clock is provided
by the RCC block, refer to the RCC section for details.
MCK
MCKOE
I²SMOD
CHLEN
MS30109V1
1. Where x = 2.
The audio sampling frequency may be 192 KHz, 96 kHz, 48 kHz, 44.1 kHz, 32 kHz,
22.05 kHz, 16 kHz, 11.025 kHz or 8 kHz (or any other value within this range). In order to
reach the desired frequency, the linear divider needs to be programmed according to the
formulas below:
When the master clock is generated (MCKOE in the SPIx_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 167 provides example precision values for different clock configurations.
Note: Other configurations are possible that allow optimum clock precision.
Procedure
1. Select the I2SDIV[7:0] bits in the SPIx_I2SPR register to define the serial clock baud
rate to reach the proper audio sample frequency. The ODD bit in the SPIx_I2SPR
register also has to be defined.
2. Select the CKPOL bit to define the steady level for the communication clock. Set the
MCKOE bit in the SPIx_I2SPR register if the master clock MCK needs to be provided
to the external 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 26.6.4: Clock generator).
3. Set the I2SMOD bit in the SPIx_I2SCFGR register to activate the I2S functions and
choose the I2S standard through the I2SSTD[1:0] and PCMSYNC bits, the data length
through the DATLEN[1:0] bits and the number of bits per channel by configuring the
CHLEN bit. Select also the I2S master mode and direction (Transmitter or Receiver)
through the I2SCFG[1:0] bits in the SPIx_I2SCFGR register.
4. If needed, select all the potential interrupt sources and the DMA capabilities by writing
the SPIx_CR2 register.
5. The I2SE bit in SPIx_I2SCFGR register must be set.
WS and CK are configured in output mode. MCK is also an output, if the MCKOE bit in
SPIx_I2SPR is set.
Transmission sequence
The transmission sequence begins when a half-word is written into the Tx buffer.
Lets assume the first data written into the Tx buffer corresponds to the left channel data.
When data are transferred from the Tx buffer to the shift register, TXE is set and data
corresponding to the right channel have to be written into the Tx buffer. The CHSIDE flag
indicates which channel is to be transmitted. It has a meaning when the TXE flag is set
because the CHSIDE flag is updated when TXE goes high.
A full frame has to be considered as a left channel data transmission followed by a right
channel data transmission. It is not possible to have a partial frame where only the left
channel is sent.
The data half-word is parallel loaded into the 16-bit shift register during the first bit
transmission, and then shifted out, serially, to the MOSI/SD pin, MSB first. The TXE flag is
set after each transfer from the Tx buffer to the shift register and an interrupt is generated if
the TXEIE bit in the SPIx_CR2 register is set.
For more details about the write operations depending on the I2S Standard-mode selected,
refer to Section 26.6.3: Supported audio protocols).
To ensure a continuous audio data transmission, it is mandatory to write the SPIx_DR
register with the next data to transmit before the end of the current transmission.
To switch off the I2S, by clearing I2SE, it is mandatory to wait for TXE = 1 and BSY = 0.
Reception sequence
The operating mode is the same as for transmission mode except for the point 3 (refer to the
procedure described in Section 26.6.5: I2S master mode), where the configuration should
set the master reception mode through the I2SCFG[1:0] bits.
Whatever the data or channel length, the audio data are received by 16-bit packets. This
means that each time the Rx buffer is full, the RXNE flag is set and an interrupt is generated
if the RXNEIE bit is set in SPIx_CR2 register. Depending on the data and channel length
configuration, the audio value received for a right or left channel may result from one or two
receptions into the Rx buffer.
Clearing the RXNE bit is performed by reading the SPIx_DR register.
CHSIDE is updated after each reception. It is sensitive to the WS signal generated by the
I2S cell.
For more details about the read operations depending on the I2S Standard-mode selected,
refer to Section 26.6.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 SPIx_CR2 register, an
interrupt is generated to indicate the error.
To switch off the I2S, specific actions are required to ensure that the I2S completes the
transfer cycle properly without initiating a new data transfer. The sequence depends on the
configuration of the data and channel lengths, and on the audio protocol mode selected. In
the case of:
16-bit data length extended on 32-bit channel length (DATLEN = 00 and CHLEN = 1)
using the LSB justified mode (I2SSTD = 10)
a) Wait for the second to last RXNE = 1 (n – 1)
b) Then wait 17 I2S clock cycles (using a software loop)
c) Disable the I2S (I2SE = 0)
16-bit data length extended on 32-bit channel length (DATLEN = 00 and CHLEN = 1) in
MSB justified, I2S or PCM modes (I2SSTD = 00, I2SSTD = 01 or I2SSTD = 11,
respectively)
a) Wait for the last RXNE
Transmission sequence
The transmission sequence begins when the external master device sends the clock and
when the NSS_WS signal requests the transfer of data. The slave has to be enabled before
the external master starts the communication. The I2S data register has to be loaded before
the master initiates the communication.
For the I2S, MSB justified and LSB justified modes, the first data item to be written into the
data register corresponds to the data for the left channel. When the communication starts,
the data are transferred from the Tx buffer to the shift register. The TXE flag is then set in
order to request the right channel data to be written into the I2S data register.
The CHSIDE flag indicates which channel is to be transmitted. Compared to the master
transmission mode, in slave mode, CHSIDE is sensitive to the WS signal coming from the
external master. This means that the slave needs to be ready to transmit the first data
before the clock is generated by the master. WS assertion corresponds to left channel
transmitted first.
Note: The I2SE has to be written at least two PCLK cycles before the first clock of the master
comes on the CK line.
The data half-word is parallel-loaded into the 16-bit shift register (from the internal bus)
during the first bit transmission, and then shifted out serially to the MOSI/SD pin MSB first.
The TXE flag is set after each transfer from the Tx buffer to the shift register and an interrupt
is generated if the TXEIE bit in the SPIx_CR2 register is set.
Note that the TXE flag should be checked to be at 1 before attempting to write the Tx buffer.
For more details about the write operations depending on the I2S Standard-mode selected,
refer to Section 26.6.3: Supported audio protocols.
To secure a continuous audio data transmission, it is mandatory to write the SPIx_DR
register with the next data to transmit before the end of the current transmission. An
underrun flag is set and an interrupt may be generated if the data are not written into the
SPIx_DR register before the first clock edge of the next data communication. This indicates
to the software that the transferred data are wrong. If the ERRIE bit is set into the SPIx_CR2
register, an interrupt is generated when the UDR flag in the SPIx_SR register goes high. In
this case, it is mandatory to switch off the I2S and to restart a data transfer starting from the
left channel.
To switch off the I2S, by clearing the I2SE bit, it is mandatory to wait for TXE = 1 and
BSY = 0.
Reception sequence
The operating mode is the same as for the transmission mode except for the point 1 (refer to
the procedure described in Section 26.6.6: I2S slave mode), where the configuration should
set the master reception mode using the I2SCFG[1:0] bits in the SPIx_I2SCFGR register.
Whatever the data length or the channel length, the audio data are received by 16-bit
packets. This means that each time the RX buffer is full, the RXNE flag in the SPIx_SR
register is set and an interrupt is generated if the RXNEIE bit is set in the SPIx_CR2
register. Depending on the data length and channel length configuration, the audio value
received for a right or left channel may result from one or two receptions into the RX buffer.
The CHSIDE flag is updated each time data are received to be read from the SPIx_DR
register. It is sensitive to the external WS line managed by the external master component.
Clearing the RXNE bit is performed by reading the SPIx_DR register.
For more details about the read operations depending the I2S Standard-mode selected,
refer to Section 26.6.3: Supported audio protocols.
If data are received while the preceding received data have not yet been read, an overrun is
generated and the OVR flag is set. If the bit ERRIE is set in the SPIx_CR2 register, an
interrupt is generated to indicate the error.
To switch off the I2S in reception mode, I2SE has to be cleared immediately after receiving
the last RXNE = 1.
Note: The external master components should have the capability of sending/receiving data in 16-
bit or 32-bit packets via an audio channel.
The BSY flag is useful to detect the end of a transfer if the software needs to disable the I2S.
This avoids corrupting the last transfer. For this, the procedure described below must be
strictly respected.
The BSY flag is set when a transfer starts, except when the I2S is in master receiver mode.
The BSY flag is cleared:
When a transfer completes (except in master transmit mode, in which the
communication is supposed to be continuous)
When the I2S is disabled
When communication is continuous:
In master transmit mode, the BSY flag is kept high during all the transfers
In slave mode, the BSY flag goes low for one I2S 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.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BIDI BIDI CRC CRC RX LSB
DFF SSM SSI SPE BR [2:0] MSTR CPOL CPHA
MODE OE EN NEXT ONLY FIRST
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Res. Res. Res. Res. Res. Res. Res. Res. TXEIE RXNEIE ERRIE FRF Res. SSOE TXDMAEN RXDMAEN
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
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ASTRE PCMSY
Res. Res. Res. I2SMOD I2SE I2SCFG Res. I2SSTD CKPOL DATLEN CHLEN
N NC
rw rw rw rw rw rw rw rw rw rw rw rw
0x1C
0x0C
Offset
896/1347
26.7.10
SPI_SR
SPI_DR
Register
SPI_CR2
SPI_CR1
SPI_I2SPR
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
SPI_CRCPR
SPI_TXCRCR
SPI_RXCRCR
SPI_I2SCFGR
Res. Res. Res. Res. Res. Res. Res. Res. Res. 31
Res. Res. Res. Res. Res. Res. Res. Res. Res. 30
Res. Res. Res. Res. Res. Res. Res. Res. Res. 29
Res. Res. Res. Res. Res. Res. Res. Res. Res. 28
SPI register map
RM0390 Rev 6
Res. Res. Res. Res. Res. Res. Res. Res. Res. 17
Res. Res. Res. Res. Res. Res. Res. Res. Res. 16
Res. Res. Res. Res. BIDIMODE 15
Res. Res. Res. Res. BIDIOE 14
Res. Res. Res. Res. CRCEN 13
Res. ASTREN Res. Res. CRCNEXT 12
Table 169. SPI register map and reset values
0 0 0 0 0 0
PCMSYNC BSY TXEIE LSBFIRST 7
DR[15:0]
TxCRC[15:0]
RxCRC[15:0]
MODF ERRIE
CRCPOLY[15:0]
I2SSTD 5
0 0 0 0
CRCERR FRF
BR
4
[2:0]
I2SDIV
CHSIDE SSOE MSTR 2
DATLEN
TXE TXDMAEN CPOL 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0
0 0 0 0 0 0 0 1 0
0 0 0
RM0390
a. Check the RCC capabilities in order to verify which sampling rates can be supported.
SPDIFRX
SPDIFRX_CLK SPDIFRX_DC
REG_IF
PCLK1
RX_BUF
SPDIFRX_SEQ
SPDIFRX_DEC
SPDIFRX_CR
SPDIFRX_FE
32-bit APB1 bus
SPDIFRX_IN[2]
sequencer
SPDIFRX_IMR
...
SYNC
SPDIFRX_CSR ctrl ch.
SPDIFRX_IN[n] (1)
SPDIFRX_SR
SPDIFRX_IFCR
SPDIFRX_DIR
SPDIFRX_IRQ IRQ_IF
DMA_SPDIFRX_DT
DMA_IF spdifrx_frame_sync
DMA_SPDIFRX_CS SPDIFRX_CLK clock
PCLK1 clock domain
domain
MSv35927V3
1. ‘n’ is fixed to 4.
28 information bits
MSv35981V1
For linear coded audio applications, the first sub-frame (left or “A” channel in stereophonic
operation and primary channel in monophonic operation) normally starts with preamble “M”.
However, the preamble changes to preamble “B” once every 192 frames to identify the start
of the block structure used to organize the channel status and user information. The second
sub-frame (right or “B” channel in stereophonic operation and secondary channel in
monophonic operation) always starts with preamble “W”.
A S/PDIF block contains 192 pairs of sub-frames of 32 bits.
Sub-frame Sub-frame
NOTE
For historical reasons preambles "B", "M" and "W" are, for use in professional applications, referred to as "Z", "X" and "Y", respectively.
MSv35923V1
Synchronization preambles
The preambles patterns are inverted or not according to the previous half-bit value. This
previous half-bit value is the level of the line before enabling a transfer for the first “B”
preamble of the first frame. For the others preambles, this previous half-bit value is the
second half-bit of the parity bit of the previous sub-frame. The preambles patterns B, M and
W are described in the Figure 340.
1 UI 2 UI 3 UI 4 UI 5 UI 6 UI 7 UI 8 UI
Previous half-bit = 0
Preamble “B”
Previous half-bit = 1
Lack of transitions !
Previous half-bit = 0
Preamble “M”
Previous half-bit = 1
Lack of transitions !
Previous half-bit = 0
Preamble “W”
Previous half-bit = 1
Lack of transitions !
Symbol boundary
MSv35982V1
1 2 3 4 5 6 7
Bit Clock
Source coding
1 0 1 1 0 0
Channel coding
(Biphase-Mark)
BitStream Biphase-Mark
Coded
MSv35921V1
SPDIFRX_DC
SPDIFRX_SEQ
transition_pulse SPDIFRX_CLK
TRCNT
transition_width_count 13 (13 bits)
SPDIFRX_DEC
SPDIFRX_FE MAX_CNT Transition preamble_info data_valid
Longest RX_BUF data
SYNC
SPDIFRX_IN[1] coder
& shortest Biphase Data
... Noise filtering &
transition decoder Packing
& MIN_CNT Preamble trans_info data
SPDIFRX_IN[n] detector ctrl_ch.
Edge detection detector
WIDTH24
WIDTH40 FINE
SYNC
transition_pulse
MSv35983V2
SPDIFRX_IN[n:1]
SPDIFRX_CLK
0 1 1 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 1 1 1 1 1
resampled input
filtered input
transition_pulse
MSv35926V2
The search of the longest and shortest transition is stopped when the transition timer
expires. The transition timer is like a watchdog timer that generates a trigger after 70
transitions of the incoming signal. Note that counting 70 transitions insures a delay a bit
longer than a sub-frame.
Note that when the TRCNT overflows due to a too long time interval between two pulses,
the SPDIFRX is stopped and the flag TERR of SPDIFRX_SR register is set to 1.
SPDIFRX Signal
1.5 UI
2.5 UI
THLO THHI
MSv35931V2
Preamble B 11101000 TL TS TS TL
Preamble M 11100010 TL TL TS TS
Preamble W 11100100 TL TM TS TM
Bi-phase decoder
The Bi-phase decoder decodes the input bi-phase marked data stream using the transition
information provided by the transition coder and preamble detector block. It first waits for
the preamble detection information. After the preamble detection, it decodes the following
transition information:
If the incoming transition information is TM then it is decoded as a ‘0’.
Two consecutive TS are decoded as a ‘1’.
Any other transition sequence generates an error signal (FERR set to 1).
After decoding 28 data bits this way, this module looks for the following preamble data. If the
new preamble is not what is expected, then this block generates an error signal (FERR set
to 1). Refer to Section 27.3.8: Reception errors, for additional information on error flags.
Data packing
This block is responsible of the decoding of the IEC-60958 frames and blocks. It also
handles the writing into the RX_BUF or into SPDIFRX_CSR register.
Initial Sync
Process
Parallel flows
preamble Y
N
found within 70
trans. ?
N TRCNT
overflows ? Decode properly the next 40 symbols
Measurement of 24 and 40 symbols duration (WIDTH24, WIDTH40)
Y
N Symb. Y
decoding (1)
OK ?
ATTEMPT ++
Y Set SYNCD to 1
Sync stopped
· (1) - The decoding is considered OK, when the symbols are properly decoded, and preamble occurs at the expected position
MSv35932V1
Refer to Frame structure and synchronization error for additional information concerning
TRCNT overflow.
The FINE SYNC process is re-triggered every frame in order to update thresholds as shown
in Figure 346 in order to continuously track S/PDIF synchronization.
STATE_SYNC STATE_RCV
70
trans.
SPDIFRX_IN M A1 W B1 M A2 W B2 M A3 W B3 B A4 W B4 M A5 W B5 M A6 W B6 M A5 W B5 M A5 W B5
Synchronization T
COARSE FINE FINE FINE FINE FINE FINE FINE
processes S
SYNCD
STATE_IDLE
STATE_SYNC
FERR = 1 (HW) or
TERR = 1 (HW) or
SERR = 1 (HW)
STATE_RCV
FERR = 1 (HW) or
TERR = 1 (HW)
NOTE: SYNCD is an internal event informing that the SPDIFRX is properly synchronized
MSv35985V3.
When SPDIFRXEN is set to 0, the SPDIFRX is disabled, meaning that all the state
machines are reset, and RX_BUF is flushed. Note as well that flags FERR, SERR and
TERR are reset.
Having a 2-word buffer gives more flexibility for the latency constraint.
The maximum latency allowed is TSAMPLE - 2TPCLK - 2TSPDIFRX_CLK
Where TSAMPLE is the audio sampling rate of the received stereo audio samples, TPCLK is
the period of PCLK1 clock, and TSPDIFRX_CLK is the period of SPDIFRX_CLK clock.
The SPDIFRX offers the possibility to use either DMA (spdifrx_dma_req/clr_d) or interrupts
for transferring the audio samples into the memory. The recommended option is DMA, refer
to Section 27.3.10: DMA interface for additional information.
The SPDIFRX offers several way on handling the received data. The user can either have a
separate flow for control information and audio samples, or get them all together.
For each sub-frame, the data reception register SPDIFRX_FMTx_DR contains the 24 data
bits, and optionally the V, U, C, PE status bits, and the PT (see Mixing data and control
flow).
Note that PE bit stands for parity rrror bit, and is set to 1 when a parity error is detected in
the decoded sub-frame.
The PT field carries the preamble type (B, M or W).
V, U and C are a direct copy of the value received from the S/PDIF interface.
The bit DRFMT allows the selection between 3 audio formats as shown in Figure 348.
This document describes 3 data registers: SPDIFRX_FMTx[2:0] (x = 2 to 0), but in reality
there is only one physical data register, having 3 possible formats:
When DRFMT = 0, the format of the data register is the one described by
SPDIFRX_FMT0_DR
When DRFMT = 1, the format of the data register is the one described by
SPDIFRX_FMT1_DR
When DRFMT = 2, the format of the data register is the one described by
SPDIFRX_FMT2_DR"
0 3 4 5 6 7 12 25 26 27 28 29 30 31
LSb MSb
MSb LSb
MSb LSb
MSv35925V4
Setting DRFMT to 00 or 01, offers the possibility to have the data either right or left aligned
into the SPDIFRX_FMTx_DR register. The status information can be enabled or forced to
zero according to the way the software wants to handle them.
The format given by DRFMT= 10 is interesting in non-linear mode, as only 16 bits per sub-
frame are used. By using this format, the data of two consecutive sub-frames are stored into
SPDIFRX_FMTx_DR, dividing by two the amount of memory footprint. Note that when
RXSTEO = 1, there is no misalignment risks (i.e. data from ChA are always stored into
SPDIFRX_FMTx_DR[31:16]). If RXSTEO = 0, then there is a misalignment risk is case of
overrun situation. In that case SPDIFRX_FMTx_DR[31:16] always contain the oldest value
and SPDIFRX_FMTx_DR[15:0] the more recent value (see Figure 350).
In this format the status information cannot be mixed with data, but the user can still get
them through SPDIFRX_CSR register, and use a dedicated DMA channel or interrupt to
transfer them to memory (see Section 27.3.7: Dedicated control flow)
SPDIFRX_IN M A1 W B1 B A2 W B2 M A3 W B3 B A4 W B4 M A5 W B5 M A6 W B6 M A5 W B5 M A5 W B5
0b01 or 0b11
SPDIFRXEN
SYNCD
Start of a new block
spdifrx_dma_req_c
spdifrx_dma_clr_c
SPDIFRX_CSR format
31 25 24 23 16 15 0
reserved SOB CS[7:0] USR[15:0]
MSv35924V2
Note: Once the first start of block is detected (B preamble), the SPDIFRX is checking the
preamble type every 8 frames.
Note: Overrun error on SPDIFRX_FMTx_DR register does not affect this path.
Parity error
For each sub-frame, an even number of zeros and ones is expected inside the 28
information bits. If not, the parity error bit PERR is set in the SPDIFRX_SR register and an
interrupt is generated if the parity interrupt enable PERRIE bit is set in the SPDIFRX_CR
register. The reception of the incoming data is not paused, and the SPDIFRX continue to
deliver data to SPDIFRX_FMTx_DR even if the interrupt is still pending.
The interrupt is acknowledged by clearing the PERR flag through PERRCF bit.
If the software wants to guarantee the coherency between the data read in the
SPDIFRX_FMTx_DR register and the value of the bit PERR, the bit PMSK must be set to 0.
Overrun error
If both SPDIFRX_FMTx_DR and RX_BUF are full, while the SPDIFRX_DC needs to write a
new sample in RX_BUF, this new sample is dropped, and an overrun condition is triggered.
The overrun error flag OVR is set in the SPDIFRX_SR register and an interrupt is generated
if the OVRIE bit of the SPDIFRX_CR register is set.
If the RXSTEO bit is set to 0, then as soon as the RX_BUF is empty, the SPDIFRX stores
the next incoming data, even if the OVR flag is still pending. The main purpose is to reduce
as much as possible the amount of lost samples. Note that the behavior is similar
independently of DRFMT value. See Figure 350.
DRFMT = 0b0x
SPDIFRX_IN M Ch A1 W Ch B1 B Ch A2 W Ch B2 M Ch A3 W Ch B3 M Ch A4 W Ch B4 B Ch A5 W Ch B5
RX_BUF FULL
RX_BUF and - - - Ch A2 Ch A2 - - - - -
SPDIFRX_FMTx_DR content Ch B0 Ch A1 Ch B1 Ch B1 Ch B1 Ch A3 Ch B3 Ch A4 Ch B4 Ch A5
SPDIFRX_DMA_REQ
Ch B1
Ch B3
Ch B4
Ch A1
Ch A2
Ch A3
Ch A4
Ch A5
memory
SPDIFRX_IRQ (OVR)
Acknowledged by SW
DRFMT = 0b10
RX_BUF cannot be emptied because SPDIF_RX is FULL D6 is available and RX_BUF is FULL è Overrun !
ChA ChB ChA ChB ChA ChB ChA ChB ChA ChB ChA ChB
RX_BUF FULL
RXNE
SPDIFRX_DMA_REQ
Acknowledged
SPDIFRX_IRQ (OVR) by SW
If the RXSTEO bit is set to 1, it means that stereo data are transported, then the SPDIFRX
has to avoid misalignment between left and right channels. So the peripheral has to drop a
second sample even if there is room inside the RX_BUF in order to avoid misalignment.
Then the incoming samples can be written normally into the RX_BUF even if the OVR flag is
still pending. Refer to Figure 351.
The OVR flag is cleared by software, by setting the OVRCF bit to 1.
Ch B2 cannot be written into the RX_BUF because Ch A3 cannot be written into the RX_BUF even if the
it is FULL → Overrun ! RX_BUF is not FULL in order to avoid misalignments
SPDIFRX_IN M Ch A1 W Ch B1 B Ch A2 W Ch B2 M Ch A3 W Ch B3 M Ch A4 W Ch B4 B Ch A5 W Ch B5
RX_BUF FULL
RX_BUF and - - - Ch A2 Ch A2 - - - - -
SPDIFRX_FMTx_DR Ch B0 Ch A1 Ch B1 Ch B1 Ch B1 - Ch B3 Ch A4 Ch B4 Ch A5
SPDIFRX_DMA_REQ
Ch B1
Ch B3
Ch B4
Ch A1
Ch A2
Ch A4
Ch A5
memory
SPDIFRX_IRQ
Acknowledged
by SW
MSv35930V4
The DMA mode for the data can be enabled for reception by setting the RXDMAEN bit in the
SPDIFRX_CR register. In this case, as soon as the SPDIFRX_FMTx_DR is not empty, the
SPDIFRX interface sends a transfer request to the DMA. The DMA reads the data received
through the SPDIFRX_FMTx_DR register without CPU intervention.
For the use of DMA for the control data refer to Section 27.3.7: Dedicated control flow.
SYNCD
SYNCDIE
RXNE
RXNEIE
PERR
PERRIE
OVR
SPDIFRX_IRQ
OVRIE OR
CSRNE
CSRNEIE
SBD
SBDIE
SERR
OR
FERR
TERR
IFEIE
MSv35928V2
INSEL rw r r
WFA rw r r
NBTR rw r r
CHSEL rw r r
CBDMAEN rw rw rw
PTMSK rw rw rw
SPDIFRX_CR
CUMSK rw rw rw
VMSK rw rw rw
PMSK rw rw rw
DRFMT rw rw r
RXSTEO rw rw r
RXDMAEN rw rw rw
SPDIFRX_IMR All fields rw rw rw
The table clearly shows that fields such as INSEL must be programmed when the SPDIFRX
is in STATE_IDLE. In the others SPDIFRX states, the hardware prevents writing to this field.
Note: Even if the hardware allows the writing of CBDMAEN and RXDMAEN “on-the-fly”, it is not
recommended to enable the DMA when the SPDIFRX already receives data.
Note: Each of the mask bits (such as PMSK, VMSK) can be changed “on-the-fly” at any SPDIFRX
state, but any change does not affect data which are already hold in SPDIFRX_FMTx_DR.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. INSEL[2:0]
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SPDIFRXEN[1:0]
DRFMT[1:0]
CBDMAEN
RXDMAEN
NBTR[1:0]
RXSTEO
CUMSK
PTMSK
CHSEL
VMSK
PMSK
WFA
Res.
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IFE SYNCD SBLK OVR PERR CSRNE RXNE
Res. Res. Res. Res. Res. Res. Res. Res. Res.
IE IE IE IE IE IE IE
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. WIDTH5[14:0]
r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. TERR SERR FERR SYNCD SBD OVR PERR CSRNE RXNE
r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SYNCD SBD OVR PERR
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
CF CF CF CF
w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. PT[1:0] C U V PE DR[23:16]
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
DR[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
DR[23:8]
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
DR[7:0] Res. Res. PT[1:0] C U V PE
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
DRNL2[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
DRNL1[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. SOB CS[7:0]
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
USR[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. TLO[12:0]
r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. THI[12:0]
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
name
SPDIFRXEN[1:0]
DRFMT[1:0]
CBDMAEN
RXDMAEN
INSEL[2:0]
NBTR[1:0]
RXSTEO
CUMSK
PTMSK
CHSEL
VMSK
PMSK
WFA
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SPDIFRX_CR
0x00
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SYNCDIE
CSRNEIE
PERRIE
RXNEIE
SBLKIE
OVRIE
IFEIE
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SPDIFRX_IMR
0x04
Reset value 0 0 0 0 0 0 0
CSRNE
SYNCD
RXNE
SERR
PERR
TERR
FERR
OVR
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SBD
SPDIFRX_SR WIDTH5[14: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
SYNCDCF
PERRCF
OVRCF
SBDCF
SPDIFRX_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
IFCR
0x0C
Reset value 0 0 0 0
PT[1:0]
SPDIFRX_ P
Res.
Res.
C U V DR[23:0]
0x10 FMT0_DR 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 0 0 0 0
PT[1:0]
SPDIFRX_ P
DR[23:0] Res. C U V
0x10 FMT1_DR 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 0 0 0 0
SPDIFRX_
DRNL2[15:0] DRNL1[15:0]
0x10 FMT2_DR
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SPDIFRX_
SOB
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CS[7:0] USR[15:0]
CSR
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
Res.
Res.
Res.
Res.
Res.
Res.
28.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. SPDIF output is offered when the audio block is configured as a
transmitter.
To bring this level of flexibility and reconfigurability, the SAI contains two independent audio
subblocks. Each block has it own clock generator and I/O line controller.
The SAI works in master or slave configuration. The audio subblocks are either receiver or
transmitter and work synchronously or not (with respect to the other one).
The SAI can be connected with other SAIs to work synchronously.
– FIFO requests.
2-channel DMA interface.
sai_a_gbl_it sai_a_dma
IO Line Management
ker_ck Configuration FSM SCK_A
Audio block A
and status SD_A
registers MCLK_A
32-bit shift register
FS_B
sai_pclk SCK_B
SD_B
Audio block B MCLK_B
FIFO FIFO ctrl
registers
32-bit shift register
in
SAI_BCR1
sai_sync_in_fs
APB Interface
sai_b_gbl_it sai_b_dma
The SAI is mainly composed of two audio subblocks 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 a set of 4 dedicated pins (SD, SCK, FS, MCLK) for a given
audio block in the SAI. Some of these pins can be shared if the two subblocks 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.
If one SAI is configured to operate synchronously with another one, even more I/Os can be
freed (except for pins SD_x).
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 subblock can be a transmitter or receiver, in master or slave mode. The master
mode means the SCK_x bit clock 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 is an SAI output even if the SAI (link controller) is
set-up to consume the SCK clock (and so to be in Slave mode).
Note: For ease of reading of this section, the notation SAI_x refers to SAI_A or SAI_B, where ‘x’
represents the SAI A or B subblock.
sai_a_gbl_it/
Output Audio block A and B global interrupts.
sai_b_gbl_it
sai_a_dma,
Input/output Audio block A and B DMA acknowledges and requests.
sai_b_dma
sai_sync_out_sck, Internal clock and frame synchronization output signals
Output
sai_sync_out_fs exchanged with other SAI blocks.
sai_sync_in_sck, Internal clock and frame synchronization input signals
Input
sai_sync_in_fs exchanged with other SAI blocks.
sai_a_ker_ck/
Input Audio block A/B kernel clock.
sai_b_ker_ck
sai_pclk Input APB clock.
Master mode
In master mode, the SAI delivers the timing signals to the external connected device:
The bit clock and the frame synchronization are output on pin SCK_x and FS_x,
respectively.
If needed, the SAI can also generate a master clock on MCLK_x pin.
Both SCK_x, FS_x and MCLK_x are configured as outputs.
Slave mode
The SAI expects to receive timing signals from an external device.
If the SAI subblock is configured in asynchronous mode, then SCK_x and FS_x pins
are configured as inputs.
If the SAI subblock is configured to operate synchronously with another SAI interface or
with the second audio subblock, the corresponding SCK_x and FS_x pins are left free
to be used as general purpose I/Os.
In slave mode, MCLK_x pin is not used and can be assigned to another function.
It is recommended to enable the slave device before enabling the master.
Internal synchronization
An audio subblock can be configured to operate synchronously with the second audio
subblock in the same SAI. In this case, the bit clock and the frame synchronization signals
are shared to reduce the number of external pins used for the communication. The audio
block configured in synchronous mode sees its own SCK_x, FS_x, and MCLK_x pins
released back as GPIOs while the audio block configured in asynchronous mode is the one
for which FS_x and SCK_x ad MCLK_x I/O pins are relevant (if the audio block is
considered as master).
Typically, the audio block in synchronous mode can be used to configure the SAI in full
duplex mode. One of the two audio blocks can be configured as a master and the other as
slave, or both as slaves with one asynchronous block (corresponding SYNCEN[1:0] bits set
to 00 in SAI_xCR1) and one synchronous block (corresponding SYNCEN[1:0] bits set to 01
in the SAI_xCR1).
Note: Due to internal resynchronization stages, PCLK APB frequency must be higher than twice
the bit rate clock frequency.
External synchronization
The audio subblocks can also be configured to operate synchronously with another SAI.
This can be done as follow:
1. The SAI, which is configured as the source from which the other SAI is synchronized,
has to define which of its audio subblock is supposed to provide the FS and SCK
signals to other SAI. This is done by programming SYNCOUT[1:0] bits.
2. The SAI which receives the synchronization signals, has to select which SAI provides
the synchronization by setting the proper value on SYNCIN[1:0] bits. For each of the
two SAI audio subblocks, the user must then specify if it operates synchronously with
the other SAI via the SYNCEN bit.
Note: SYNCIN[1:0] and SYNCOUT[1:0] bits are located into the SAI_GCR register, and SYNCEN
bits into SAI_xCR1 register.
If both audio subblocks in a given SAI need to be synchronized with another SAI, it is
possible to choose one of the following configurations:
Configure each audio block to be synchronous with another SAI block through the
SYNCEN[1:0] bits.
Configure one audio block to be synchronous with another SAI through the
SYNCEN[1:0] bits. The other audio block is then configured as synchronous with the
second SAI audio block through SYNCEN[1:0] bits.
The following table shows how to select the proper synchronization signal depending on the
SAI block used. For example SAI2 can select the synchronization from SAI1 by setting SAI2
SYNCIN to 0. If SAI1 wants to select the synchronization coming from SAI2, SAI1 SYNCIN
must be set to 1. Positions noted as ‘Reserved’ must not be used.
SCK
SD
Slot 0 Slot 1 Slot 2 Slot 3 Slot 4 …... Slot 0
(FSOFF = 0)
SD
Slot 0 Slot 1 Slot 2 Slot 3 Slot 4 …... Slot 0
(FSOFF = 1)
MSv30037V2
Frame length
Master mode
The audio frame length can be configured to up to 256 bit clock cycles, by setting
FRL[7:0] field in the SAI_xFRCR register.
If the frame length is greater than the number of declared slots for the frame, the
remaining bits to transmit is extended to 0 or the SD line is released to HI-z depending
the state of bit TRIS in the SAI_xCR2 register (refer to FS signal role). In reception
mode, the remaining bit is ignored.
If bit NODIV is cleared, (FRL+1) must be equal to a power of 2, from 8 to 256, to ensure
that an audio frame contains an integer number of MCLK pulses per bit clock cycle.
If bit NODIV is set, the (FRL+1) field can take any value from 8 to 256. Refer to
Section 28.3.8: SAI clock generator”.
Slave mode
The audio frame length is mainly used to specify to the slave the number of bit clock
cycles per audio frame sent by the external master. It is used mainly to detect from the
master any anticipated or late occurrence of the Frame synchronization signal during
an on-going audio frame. In this case an error is generated. For more details refer to
Section 28.3.13: Error flags.
In slave mode, there are no constraints on the FRL[7:0] configuration in the
SAI_xFRCR register.
The number of bits in the frame is equal to FRL[7:0] + 1.
The minimum number of bits to transfer in an audio frame is 8.
FS signal role
The FS signal can have a different meaning depending on the FS function. FSDEF bit in the
SAI_xFRCR register selects which meaning it has:
0: start of frame, like for instance the PCM/DSP, TDM, AC’97, audio protocols,
1: start of frame and channel side identification within the audio frame like for the I2S,
the MSB or LSB-justified protocols.
When the FS signal is considered as a start of frame and channel side identification within
the frame, the number of declared slots must be considered to be half the number for the left
channel and half the number for the right channel. If the number of bit clock cycles on half
audio frame is greater than the number of slots dedicated to a channel side, and TRIS = 0, 0
is sent for transmission for the remaining bit clock cycles in the SAI_xCR2 register.
Otherwise if TRIS = 1, the SD line is released to HI-Z. In reception mode, the remaining bit
clock cycles are not considered until the channel side changes.
Figure 355. FS role is start of frame + channel side identification (FSDEF = TRIS = 1)
Half of frame
FS
sck
Half of frame
FS
sck
MS30038V2
if TRIS = 0 in the SAI_xCR2 register, the remaining bit after the last slot is forced to 0
until the end of frame in case of transmitter,
if TRIS = 1, the line is released to HI-Z during the transfer of these remaining bits. In
reception mode, these bits are discarded.
Audio frame
sck
MS30039V1
The FS signal is not used when the audio block in transmitter mode is configured to get the
SPDIF output on the SD line. The corresponding FS I/O is released and left free for other
purposes.
16-bit 16-bit
32-bit 32-bit
X: don’t care
MSv30033V1
It is possible to choose the position of the first data bit to transfer within the slots. This offset
is configured by FBOFF[4:0] bits in the SAI_xSLOTR register. 0 values are 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
NODIV
MCKDIV[3:0] MCLK_x
0 FRL[7:0]
1 NODIV NODIV
sai_x_ker Master clock 0
_ck divider Bit clock divider 0
0 SCK_x
1 1
MSv30040V2
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_x_ker_ck clock is equivalent to the master clock which can be divided for the external
decoders using bit MCKDIV[3:0]:
MCLK_x = sai_x_ker_ck / (MCKDIV[3:0] * 2), if MCKDIV[3:0] is not equal to 0000.
MCLK_x = sai_x_ker_ck, if MCKDIV[3:0] is equal to 0000.
MCLK_x signal is used only in Free protocol mode.
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 obtain MCLK_x
equal to sai_x_ker_ck.
In the SAI, the single ratio MCLK/FS = 256 is considered. Mostly, three frequency ranges
will be encountered as illustrated in Table 177.
The master clock can 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 cycles- 1 in the audio frame, configured in the
SAI_xFRCR register.
In master mode it is mandatory that (FRL[7:0] +1) is equal to a number with a power of 2
(refer to Section 28.3.6: Frame synchronization) to obtain an even integer number of
MCLK_x pulses by bit clock cycle. The 50% duty cycle is guaranteed on the bit clock
(SCK_x).
The sai_x_ker_ck clock can also be equal to the bit clock frequency. In this case, NODIV bit
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.
Refer to Section 28.3.11: SPDIF output for details on clock generator programming in
SPDIF mode.
cleared by hardware when the FIFO becomes empty (FLVL[2:0] bits in SAI_xSR is equal
to 0b000) i.e no data are stored in FIFO.
When the FIFO threshold bits in SAI_xCR2 register are configured as FIFO quarter fully
(FTH[2:0] set to 001b), an interrupt is generated (FREQ bit is set by hardware to 1 in
SAI_xSR register) if at least one quarter of the FIFO data locations are available
(FLVL[2:0] bits in SAI_xSR is higher or equal to 0b010). This Interrupt (FREQ bit in
SAI_xSR register) is cleared by hardware when less than a quarter of the FIFO data
locations become available (FLVL[2:0] bits in SAI_xSR is less than 0b010).
When the FIFO threshold bits in SAI_xCR2 register are configured as FIFO half fully
(FTH[2:0] set to 0b010 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 (FLVL[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
(FLVL[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
(FLVL[2:0] bits in SAI_xSR is higher or equal to 0b100). 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(FLVL[2:0] bits in SAI_xSR is less than 0b100).
When the FIFO threshold bits in SAI_xCR2 register are configured as FIFO full(FTH[2:0]
set to 0b100), an interrupt is generated (FREQ bit is set by hardware to 1 in SAI_xSR
register) if the FIFO is full (FLVL[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
(FLVL[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 interrupt 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 location whatever the access size. Each FIFO word contains one audio slot.
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 are 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
are 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 bit 2 of the TAG is forced to 0
level whatever the value written in the SAI FIFO.
For more details about tag representation, refer to the AC’97 protocol standard.
One SAI can be used to target an AC’97 point-to-point communication.
Using two SAIs (for devices featuring two embedded SAIs) allows controlling three external
AC’97 decoders as illustrated in Figure 361.
In SAI1, the audio block A must be declared as asynchronous master transmitter whereas
the audio block B is defined to be slave receiver and internally synchronous to the audio
block A.
The SAI2 is configured for audio block A and B both synchronous with the external SAI1 in
slave receiver mode.
SAI1 Sdata_out
Sync
Audio block A Bit_clk
Slave Sdata_in
SDA
SAI2
MSv31173V1
In receiver mode, the SAI acting as an AC’97 link controller requires 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 is set in the SAI_xSR register
and an interrupt is generated. This flag is dedicated to the AC’97 protocol.
Channel
MS30042V1
A SPDIF block contains 192 frames. Each frame is composed of two 32-bit sub-frames,
generally one for the left channel and one for the right channel. Each sub-frame is
composed of a SOPD pattern (4-bit) to specify if the sub-frame is the start of a block (and so
is identifying a channel A) or if it is identifying a channel A somewhere in the block, or if it is
referring to channel B (see Table 178). The next 28 bits of channel information are
composed of 24 bits data + 4 status bits.
SAI_xDR[26:0]
26 0
CS U V D23 D22 D21 D20 D19 D18 D17 D16 D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Status Data[23:0]
bits
MSv31174V1
odd number of 0 0
odd number of 1 1
The underrun is the only error flag available in the SAI_xSR register for SPDIF mode since
the SAI can only operate in transmitter mode. As a result, the following sequence should be
executed to recover from an underrun error detected via the underrun interrupt or the
underrun status bit:
1. Disable the DMA stream (via the DMA peripheral) if the DMA is used.
2. Disable the SAI and check that the peripheral is physically disabled by polling the
SAIEN bit in SAI_xCR1 register.
3. Clear the COVRUNDR flag in the SAI_xCLRFR register.
4. Flush the FIFO by setting the FFLUSH bit in SAI_xCR2.
The software needs to point to the address of the future data corresponding to a start of
new block (data for preamble B). If the DMA is used, the DMA source base address
pointer should be updated accordingly.
5. Enable again the DMA stream (DMA peripheral) if the DMA used to manage data
transfers according to the new source base address.
6. Enable again the SAI by setting SAIEN bit in SAI_xCR1 register.
More generally, the relationship between the audio sampling frequency (FS) and the bit
clock rate (FSCK_X) is given by the formula:
F SCK_x
F S = -----------------------
128
F SCK_x = F sai_x_ker_ck
Note: The above formulas are valid only if NODIV is set to 1 in SAI_ACR1 register.
Mute mode
The mute mode can be used when the audio subblock is a transmitter or a receiver.
Audio subblock in transmission mode
In transmitter mode, the mute mode can be selected at anytime. The mute mode is active
for entire audio frames. The MUTE bit in the SAI_xCR2 register enables the mute mode
when it is set during an ongoing frame.
The mute mode bit is strobed only at the end of the frame. If it is set at this time, the mute
mode is active at the beginning of the new audio frame and for a complete frame, until the
next end of frame. The bit is then strobed to determine if the next frame is still a mute frame.
If the number of slots set through NBSLOT[3:0] bits in the SAI_xSLOTR register is lower
than or equal to 2, it is possible to specify if the value sent in mute mode is 0 or if it is the last
value of each slot. The selection is done via MUTEVAL bit in the SAI_xCR2 register.
If the number of slots set in NBSLOT[3:0] bits in the SAI_xSLOTR register is greater than 2,
MUTEVAL bit in the SAI_xCR2 is meaningless as 0 values are sent on each bit on each
slot.
The FIFO pointers are still incremented in mute mode. This means that data present in the
FIFO and for which the mute mode is requested are discarded.
Audio subblock in reception mode
In reception 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 (MUTECNT[5:0] bits in the SAI_xCR2 register).
When the number of MUTE frames is detected, the MUTEDET flag in the SAI_xSR register
is set and an interrupt can be generated if MUTEDETIE bit is set in SAI_xCR2.
The mute frame counter is cleared when the audio subblock 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 value specified in MUTECNT[5:0] bits. The interrupt event is then
reinitialized when the counter is cleared.
Note: The mute mode is not available for SPDIF audio blocks.
Mono/stereo mode
In transmitter mode, the mono mode can be addressed, without any data preprocessing in
memory, assuming the number of slots is equal to 2 (NBSLOT[3:0] = 0001 in SAI_xSLOTR).
In this case, the access time to and from the FIFO is reduced by 2 since the data for slot 0 is
duplicated into data slot 1.
To enable the mono mode,
1. Set MONO bit to 1 in the SAI_xCR1 register.
2. Set NBSLOT to 1 and SLOTEN to 3 in SAI_xSLOTR.
In reception mode, the MONO bit can be set and is meaningful only if the number of slots is
equal to 2 as in transmitter mode. When it is set, only slot 0 data are stored in the FIFO. The
data belonging to slot 1 are discarded since, in this case, it is supposed to be the same as
the previous slot. If the data flow in reception mode is a real stereo audio flow with a distinct
and different left and right data, the MONO bit is meaningless. The conversion from the
output stereo file to the equivalent mono file is done by software.
Companding mode
Telecommunication applications can require to process the data to be transmitted or
received using a data companding algorithm.
Depending on the COMP[1:0] bits in the SAI_xCR2 register (used only when Free protocol
mode is selected), the application software can choose to process or not the data before
sending it on SD serial output line (compression) or to expand the data after the reception
on SD serial input line (expansion) as illustrated in Figure 364. The two companding modes
supported are the µ-Law and the A-Law log which are a part of the CCITT G.711
recommendation.
The companding standard used in the United States and Japan is the µ-Law. It supports 14
bits of dynamic range (COMP[1:0] = 10 in the SAI_xCR2 register).
The European companding standard is A-Law and supports 13 bits of dynamic range
(COMP[1:0] = 11 in the SAI_xCR2 register).
Both µ-Law or A-Law companding standard can be computed based on 1’s complement or
2’s complement representation depending on the CPL bit setting in the SAI_xCR2 register.
In µ-Law and A-Law standards, data are coded as 8 bits with MSB alignment. Companded
data are always 8-bit wide. For this reason, DS[2:0] bits in the SAI_xCR1 register are forced
to 010 when the SAI audio block is enabled (SAIEN bit = 1 in the SAI_xCR1 register) and
when one of these two companding modes selected through the COMP[1:0] bits.
If no companding processing is required, COMP[1:0] bits should be kept clear.
COMP[1]
1 expand SD
FIFO 32-bit shift register
0
0 SD
FIFO 32-bit shift register
compress 1
COMP[1]
MSv19244V1
Audio frame
sck
Bit TRIS = 1 in the SAI_xCR1 and frame length > number of slots
Audio frame
sck
SD (output) .. Data m
MSv192345V1
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 366 (where bit TRIS in the SAI_xCR1 register = 1, and FSDEF=1, and
half frame length is higher than number of slots/2, and NBSLOT=6).
sck
MSv192346V1
If the TRIS bit in the SAI_xCR2 register is cleared, all the High impedance states on the SD
output line on Figure 365 and Figure 366 are replaced by a drive with a value of 0.
sck
OVRUDR
COVRUDR = 1
MSv192348V2
Underrun
An underrun may occur when the audio block in the SAI is a transmitter and the FIFO is
empty when data need to be transmitted. If an underrun is detected, the slot number for
which the event occurs is stored and MUTE value (00) is sent until the FIFO is ready to
transmit the data corresponding to the slot for which the underrun was detected (refer to
Figure 368). This avoids desynchronization between the memory pointer and the slot in the
audio frame.
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
COVRUDR bit in the SAI_xCLRFR register.
The underrun event can occur when the audio subblock is configured as master or slave.
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
MSv192347V2
Follow the sequence below to configure the SAI interface in DMA mode:
1. Configure SAI and FIFO threshold levels to specify when the DMA request is launched.
2. Configure SAI DMA channel.
3. Enable the DMA.
4. Enable the SAI interface.
Note: Before configuring the SAI block, the SAI DMA channel must be disabled.
Depends on:
– FIFO threshold setting (FLVL bits
Master or slave FREQIE in in SAI_xCR2)
FREQ FREQ Receiver or SAI_xIM – Communication direction
transmitter register (transmitter or receiver)
For more details refer to
Section 28.3.9: Internal FIFOs
Master or slave OVRUDRIE in
COVRUDR = 1 in SAI_xCLRFR
OVRUDR ERROR Receiver or SAI_xIM
register
transmitter register
Slave
AFSDETIE in
(not used in AC’97 CAFSDET = 1 in SAI_xCLRFR
AFSDET ERROR SAI_xIM
mode and SPDIF register
register
SAI mode)
Slave
LFSDETIE in
(not used in AC’97 CLFSDET = 1 in SAI_xCLRFR
LFSDET ERROR SAI_xIM
mode and SPDIF register
register
mode)
CNRDYIE in
Slave CCNRDY = 1 in SAI_xCLRFR
CNRDY ERROR SAI_xIM
(only in AC’97 mode) register
register
MUTEDETIE in
Master or slave CMUTEDET = 1 in SAI_xCLRFR
MUTEDET MUTE SAI_xIM
Receiver mode only register
register
Master with NODIV = WCKCFGIE in
CWCKCFG = 1 in SAI_xCLRFR
WCKCFG ERROR 0 in SAI_xCR1 SAI_xIM
register
register register
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SYNCOUT[1:0] Res. Res. SYNCIN[1:0]
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. MCKDIV[3:0] NODIV Res. DMAEN SAIEN
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OUTD
Res. Res. MONO SYNCEN[1:0] CKSTR LSBFIRST DS[2:0] Res. PRTCFG[1:0] MODE[1:0]
RIV
rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. MCKDIV[3:0] NODIV Res. DMAEN SAIEN
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OUTD
Res. Res. MONO SYNCEN[1:0] CKSTR LSBFIRST DS[2:0] Res. PRTCFG[1:0] MODE[1:0]
RIV
rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MUTE F
COMP[1:0] CPL MUTECNT[5:0] MUTE TRIS FTH[2:0]
VAL FLUSH
rw rw rw rw rw rw rw rw rw rw rw rw w rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MUTE F
COMP[1:0] CPL MUTECNT[5:0] MUTE TRIS FTH[2:0]
VAL FLUSH
rw rw rw rw rw rw rw rw rw rw rw rw w rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FSOFF FSPOL FSDEF
rw rw r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. FSALL[6:0] FRL[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FSOFF FSPOL FSDEF
rw rw r
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
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
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
rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
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
rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LFSDET AFSDETI CNRDY FREQ WCKCFG MUTEDET OVRUDR
Res. Res. Res. Res. Res. Res. Res. Res. Res.
IE E IE IE IE IE IE
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LFSDET AFSDETI CNRDY FREQ WCKCFG MUTEDET OVRUDR
Res. Res. Res. Res. Res. Res. Res. Res. Res.
IE E IE IE IE IE IE
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FLVL[2:0]
r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LFSDE
Res. Res. Res. Res. Res. Res. Res. Res. Res. AFSDET CNRDY FREQ WCKCFG MUTEDET OVRUDR
T
r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FLVL[2:0]
r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LFSDE
Res. Res. Res. Res. Res. Res. Res. Res. Res. AFSDET CNRDY FREQ WCKCFG MUTEDET OVRUDR
T
r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CWCKCF CMUTE COVRUD
Res. Res. Res. Res. Res. Res. Res. Res. Res. CLFSDET CAFSDET CCNRDY Res.
G DET R
w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CWCKCF CMUTE COVRUD
Res. Res. Res. Res. Res. Res. Res. Res. Res. CLFSDET CAFSDET CCNRDY Res.
G DET R
w w w w w w
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
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
10
11
9
8
7
6
5
4
3
2
1
0
name
SYNCOUT[1:0]
SYNCIN[1:0]
Res..
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SAI_GCR
0x0000
Reset value 0 0 0 0
SYNCEN[1:0]
PRTCFG[1:0]
MCKDIV[3:0]
MODE[1:0]
LSBFIRST
OUTDRIV
DMAEN
CKSTR
DS[2:0]
NODIV
MONO
SAIEN
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x0004 SAI_xCR1
or
0x0024
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
COMP[1:0]
MUTE VAL
FTH[2:0]
FFLUS
MUTE
TRIS
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CPL
SAI_xCR2 MUTECN[5:0]
0x0008 or
0x0028
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
FSPOL
FSOFF
FSDEF
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x003C
Offset
986/1347
0x0020 or
0x0018 or
0x0014 or
0x0010 or
0x001C or
name
SAI_xIM
SAI_xSR
SAI_xDR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
SAI_xCLRFR
SAI_xSLOTR
0
0
Res. Res. Res. 31
0
Res. Res. Res. 0
30
Serial audio interface (SAI)
0
0
Res. Res. Res. 29
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Res. Res. 18
RM0390 Rev 6
0
0
0
0
Res. Res. 16
0
Res. Res. Res. Res. 15
DATA[31:0]
0
Res. Res. Res. Res. 14
0
Res. Res. Res. Res. 13
0
0 Res. Res. Res. Res. 12
0
Refer to Section 2.3 on page 129 for the register boundary addresses.
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
SDIO_D
SDIO_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
SDIO
SDIO_CK
Interrupts and
DMA request SDIO_CMD
PCLK2 SDIOCLK
MSv36073V1
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 = 50 MHz)
APB2 bus clock (PCLK2)
PCLK2 and SDIO_CK clock frequencies must respect the following condition:
The signals shown in Table 183 are used on the MultiMediaCard/SD/SD I/O card bus.
SDIO adapter
Card bus
Command
SDIO_CMD
Adapter path
registers
To APB2
Data path SDIO_D[7:0]
interface FIFO
PCLK2 SDIOCLK
MSv36074V1
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 376. 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)
The clock management subunit controls SDIO_CK dephasing. When not in bypass mode
the SDIO command and data output are generated on the SDIOCLK falling edge
succeeding the rising edge of SDIO_CK. (SDIO_CK rising edge occurs on SDIOCLK rising
edge) when SDIO_CLKCR[13] bit is reset (NEGEDGE = 0). When SDIO_CLKCR[13] bit is
set (NEGEDGE = 1) SDIO command and data changed on the SDIO_CK falling edge.
When SDIO_CLKCR[10] is set (BYPASS = 1), SDIO_CK rising edge occurs on SDIOCLK
rising edge. The data and the command change on SDIOCLK falling edge whatever
NEGEDGE value.
The data and command responses are latched using SDIO_CK rising edge.
SDIOCLK
SDIO_CK
CMD / Data
output
NEGEDGE = 0 NEGEDGE = 1
MSv36076V1
Command path
The command path unit sends commands to and receives responses from the cards.
Adapter registers
SDIO_CMDin
CMD
Argument
CRC SDIO_CMDout
Shift
CMD register
Response
To APB2 interface
registers
MSv36078V1
CPSM disabled
or no response
Last data
CPSM disabled or
Send command timeout Receive
When the Wait state is entered, the command timer starts running. If the timeout is reached
before the CPSM moves to the Receive state, the timeout flag is set and the Idle state is
entered.
Note: The command timeout has a fixed value of 64 SDIO_CK clock periods.
If the interrupt bit is set in the command register, the timer is disabled and the CPSM waits
for an interrupt request from one of the cards. If a pending bit is set in the command register,
the CPSM enters the Pend state, and waits for a CmdPend signal from the data path
subunit. When CmdPend is detected, the CPSM moves to the Send state. This enables the
data counter to trigger the stop command transmission.
Note: The CPSM remains in the Idle state for at least eight SDIO_CK periods to meet the NCC and
NRC timing constraints. NCC is the minimum delay between two host commands, and NRC is
the minimum delay between the host command and the card response.
SDIO_CMD Hi-Z Controller drives Hi-Z Card drives Hi-Z Controller drives
MSv36079V1
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 184.
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 380 on page 995. Data
on SDIO_CMD are synchronous with the rising edge of SDIO_CK. Table 184
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 29.8.4 on page 1031). The command path
implements the status flags shown in Table 187:
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 381 shows a block diagram
of the data path.
Data path
Transmit
CRC SDIO_Dout[7:0]
Shift
register
Receive
MSv36080V1
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 382: 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, 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.
DPSM Flags
The status of the data path subunit transfer is reported by several status flags
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
SDIO Clear register.
TXUNDERR Note: In case of TXUNDERR, and DMA is used to fill SDIO FIFO, user software
should disable DMA stream, and then write DMAEN bit in SDIO_DCTRL
with ‘0’ (to disable DMA request generation).
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 191 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
Clear register.
RXOVERR Note: In case of RXOVERR, and DMA is used to read SDIO FIFO, user software
should disable DMA stream, and then write DMAEN bit in SDIO_DCTRL
with ‘0’ (to disable DMA request generation).
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
SDIO APB interface controls all subunit to perform transfers between the host and card
addresses the card. The assigned card changes to the Standby state, it does not react
to further identification cycles, and its output switches from open-drain to push-pull.
8. The SDIO card host repeats steps 5 through 7 until it receives a timeout condition.
For the SD card, the identification process starts at clock rate Fod, and the SDIO_CMD line
output drives are push-pull drivers instead of open-drain. The registration process is
accomplished as follows:
1. The bus is activated.
2. The SDIO card host broadcasts SD_APP_OP_COND (ACMD41).
3. The cards respond with the contents of their operation condition registers.
4. The incompatible cards are placed in the inactive state.
5. The SDIO card host broadcasts ALL_SEND_CID (CMD2) to all active cards.
6. The cards send back their unique card identification numbers (CIDs) and enter the
Identification state.
7. The SDIO card host issues SET_RELATIVE_ADDR (CMD3) to an active card with an
address. This new address is called the relative card address (RCA); it is shorter than
the CID and addresses the card. The assigned card changes to the Standby state. The
SDIO card host can reissue this command to change the RCA. The RCA of the card is
the last assigned value.
8. The SDIO card host repeats steps 5 through 7 with all active cards.
For the SD I/O card, the registration process is accomplished as follows:
1. The bus is activated.
2. The SDIO card host sends IO_SEND_OP_COND (CMD5).
3. The cards respond with the contents of their operation condition registers.
4. The incompatible cards are set to the inactive state.
5. The SDIO card host issues SET_RELATIVE_ADDR (CMD3) to an active card with an
address. This new address is called the relative card address (RCA); it is shorter than
the CID and addresses the card. The assigned card changes to the Standby state. The
SDIO card host can reissue this command to change the RCA. The RCA of the card is
the last assigned value.
Some cards may require long and unpredictable times to write a block of data. After
receiving a block of data and completing the CRC check, the card begins writing and holds
the SDIO_D line low if its write buffer is full and unable to accept new data from a new
WRITE_BLOCK command. The host may poll the status of the card with a SEND_STATUS
command (CMD13) at any time, and the card will respond with its status. The
READY_FOR_DATA status bit indicates whether the card can accept new data or whether
the write process is still in progress. The host may deselect the card by issuing CMD7 (to
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 reselecting the card, 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
8 2 readbllen – 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 205.
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 205), 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 1009), 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 205) is sent.
3. Send LOCK/UNLOCK (CMD42) with the appropriate data byte on the data line
including the 16-bit CRC. The data block indicates the mode (ERASE = 1). All other bits
must be zero.
4. When the ERASE bit is the only bit set in the data field, all card contents are erased,
including the PWD and PWD_LEN fields, and the card is no longer locked. When any
other bits are set, the LOCK_UNLOCK_FAILED error bit is set in the card status
register and the card retains all of its data, and remains locked.
An attempt to use a force erase on an unlocked card fails and the LOCK_UNLOCK_FAILED
error bit is set in the card status register.
SIZE_OF_PROTECTED_AREA
Setting this field differs between standard- and high-capacity cards. In the case of a
standard-capacity card, the capacity of protected area is calculated as follows:
Protected area = SIZE_OF_PROTECTED_AREA_* MULT * BLOCK_LEN.
SIZE_OF_PROTECTED_AREA is specified by the unit in MULT*BLOCK_LEN.
In the case of a high-capacity card, the capacity of protected area is specified in this field:
Protected area = SIZE_OF_PROTECTED_AREA
SIZE_OF_PROTECTED_AREA is specified by the unit in bytes.
SPEED_CLASS
This 8-bit field indicates the speed class and the value can be calculated by PW/2 (where
PW is the write performance).
00h Class 0
01h Class 2
02h Class 4
03h Class 6
04h – FFh Reserved
PERFORMANCE_MOVE
This 8-bit field indicates Pm (performance move) and the value can be set by 1 [MB/sec]
steps. If the card does not move used RUs (recording units), Pm should be considered as
infinity. Setting the field to FFh means infinity.
AU_SIZE
This 4-bit field indicates the AU size and the value can be selected in the power of 2 base
from 16 KB.
The maximum AU size, which depends on the card capacity, is defined in Table 197. 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]
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.
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 184 on page 995 for command formats.
CMD32
Reserved. These command indexes cannot be used in order to maintain backward compatibility with older
...
versions of the MultiMediaCard.
CMD34
Sets the address of the first erase
CMD35 ac [31:0] data address R1 ERASE_GROUP_START group within a range to be selected
for erase.
Sets the address of the last erase
CMD36 ac [31:0] data address R1 ERASE_GROUP_END group within a continuous range to be
selected for erase.
Reserved. This command index cannot be used in order to maintain backward compatibility with older
CMD37
versions of the MultiMediaCards
Erases all previously selected write
CMD38 ac [31:0] stuff bits R1 ERASE
blocks.
CMD40 bcr [31:0] stuff bits R5 GO_IRQ_STATE Places the system in the interrupt mode.
CMD41 Reserved
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 X Command index
[39:8] 32 X Card status
[7:1] 7 X CRC7
0 1 1 End bit
29.5.2 R1b
It is identical to R1 with an optional busy signal transmitted on the data line. The card may
become busy after receiving these commands based on its state prior to the command
reception.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘111111’ Reserved
[39:8] 32 X OCR register
[7:1] 7 ‘1111111’ Reserved
0 1 1 End bit
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘100111’ CMD39
[31:16] 16 X RCA
[39:8] Argument field [15:8] 8 X register address
[7:0] 8 X read register contents
[7:1] 7 X CRC7
0 1 1 End bit
29.5.6 R4b
For SD I/O only: an SDIO card receiving the CMD5 will respond with a unique SDIO
response R4. The format is:
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 X Reserved
39 16 X Card is ready
[38:36] 3 X Number of I/O functions
[39:8] Argument field 35 1 X Present memory
[34:32] 3 X Stuff bits
[31:8] 24 X I/O ORC
[7:1] 7 X Reserved
0 1 1 End bit
Once an SD I/O card has received a CMD5, the I/O portion of that card is enabled to
respond normally to all further commands. This I/O enable of the function within the I/O card
will remain set until a reset, power cycle or CMD52 with write to I/O reset is received by the
card. Note that an SD memory-only card may respond to a CMD5. The proper response for
a memory-only card would be Present memory = 1 and Number of I/O functions = 0. A
memory-only card built to meet the SD Memory Card specification version 1.0 would detect
the CMD5 as an illegal command and not respond. The I/O aware host will send CMD5. If
the card responds with response R4, the host determines the card’s configuration based on
the data contained within the R4 response.
47 1 0 Start bit
46 1 0 Transmission bit
[45:40] 6 ‘101000’ CMD40
RCA [31:16] of winning
[31:16] 16 X
card or of the host
[39:8] Argument field
Not defined. May be used
[15:0] 16 X
for IRQ data
[7:1] 7 X CRC7
0 1 1 End bit
29.5.8 R6
Only for SD I/O. The normal response to CMD3 by a memory device. It is shown in
Table 213.
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
SDIOCLK are frozen, the APB2 interface is still alive. The FIFO can thus be filled or emptied
even if flow control is activated.
To enable HW flow control, the SDIO_CLKCR[14] register bit must be set to 1. After reset
Flow Control is disabled.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PWRCTRL
rw rw
Note: At least seven PCLK2 clock periods are needed between two write accesses to this register.
Note: 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
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HWFC NEGE WID BYPAS PWRS
Res. CLKEN CLKDIV
_EN DGE BUS S AV
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: 1 While the SD/SDIO card or MultiMediaCard is in identification mode, the SDIO_CK
frequency must be less than 400 kHz.
2 The clock frequency can be changed to the maximum card bus frequency when relative
card addresses are assigned to all cards.
3 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
CMDARG[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
CMDARG[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SDIO CPSM WAIT WAIT
Res. Res. Res. Res. WAITRESP CMDINDEX
Suspend EN PEND INT
rw rw rw rw rw rw rw rw rw rw rw rw
Note: 1 After a data write, data cannot be written to this register for three SDIOCLK clock periods
plus two PCLK2 clock periods.
2 MultiMediaCards can send two kinds of response: short responses, 48 bits long, or long
responses,136 bits long. SD card and SD I/O card can send only short responses, the
argument can vary according to the type of response: the software will distinguish the type
of response according to the sent command.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RESPCMD
r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CARDSTATUSx[31:16]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CARDSTATUSx[15:0]
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_RESP4 register LSB is
always 0b.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATATIME[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
DATATIME[15:0]
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
Res. Res. Res. Res. Res. Res. Res. DATALENGTH[24:16]
rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATALENGTH[15:0]
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 SDMMC_DCTRL). Before being written to the data control register a timeout must
be written to the data timer register and the data length register.
In case of IO_RW_EXTENDED (CMD53):
- If the Stream or SDIO multibyte data transfer is selected the value in the data length
register must be between 1 and 512.
- If the Block data transfer is selected the value in the data length register must be between
1*Data block size and 512*Data block size.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SDIO RW RW RW DMA DT
Res. Res. Res. Res. DBLOCKSIZE DTDIR DTEN
EN MOD STOP START EN MODE
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 (48 MHz) 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
Res. Res. Res. Res. Res. Res. Res. DATACOUNT[24:16]
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
DATACOUNT[15:0]
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
RXD TXD RX TX RX TX
Res. Res. Res. Res. Res. Res. Res. Res. Res. SDIOIT
AVL AVL FIFOE FIFOE FIFOF FIFOF
r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RX TX
CMD DBCK DATA CMDS CMDR RX TXUND DTIME CTIME DCRC CCRC
FIFO FIFO RXACT TXACT Res.
ACT END END ENT END OVERR ERR OUT OUT FAIL FAIL
HF HE
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
SDIO
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
ITC
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CMD RX TX
DBCK DATA CMD DTIME CTIME DCRC CCRC
Res. Res. Res. Res. Res. Res. REND OVERR UNDERR
ENDC ENDC SENTC OUTC OUTC FAILC FAILC
C C C
rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RX TX RX TX
SDIO RXD TXD
Res. Res. Res. Res. Res. Res. Res. Res. Res. FIFO FIFO FIFO FIFO
ITIE AVLIE AVLIE
EIE EIE FIE FIE
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RX TX CMD CMD RX TX
RX TX CMD DBCK DATA DTIME CTIME DCRC CCRC
FIFO FIFO Res. SENT REND OVERR UNDERR
ACTIE ACTIE ACTIE ENDIE ENDIE OUTIE OUTIE FAILIE FAILIE
HFIE HEIE IE IE IE IE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. FIFOCOUNT[23:16]
r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FIFOCOUNT[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
FIF0Data[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
FIF0Data[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Offset Register 31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
PWRCTRL
SDIO_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
POWER
0x00
Reset value 0 0
NEGEDGE
HWFC_EN
PWRSAV
WIDBUS
BYPASS
CLKDIV
CLKEN
SDIO_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
CLKCR
0x04
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SDIO_ARG CMDARG
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
SDIOSuspend
CMDINDEX
WAITPEND
WAITRESP
CPSMEN
WAITINT
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
SDIO_CMD
0x0C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
SDIO_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
RESPCMD
RESPCMD
0x10
Reset value 0 0 0 0 0 0
SDIO_
CARDSTATUS1
0x14 RESP1
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SDIO_
CARDSTATUS2
0x18 RESP2
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SDIO_
CARDSTATUS3
0x1C RESP3
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SDIO_
CARDSTATUS4
0x20 RESP4
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SDIO_
DATATIME
0x24 DTIMER
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SDIO_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DATALENGTH
DLEN
0x28
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
DBLOCKSIZE
RWSTART
RWSTOP
DTMODE
RWMOD
SDIOEN
DMAEN
DTDIR
DTEN
SDIO_
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
DCTRL
0x2C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0
0x3C
Offset
RM0390
MASK
SDIO_
SDIO_
SDIO_
DCOUNT
FIFOCNT
SDIO_ICR
SDIO_STA
Register
Reset value
SDIO_FIFO
Reset value
Reset value
Reset value
Reset value
Reset value
0
Res. Res. Res. Res. Res. 31
0
Res. Res. Res. Res. Res. 30
0
Res. Res. Res. Res. Res. 29
0
Res. Res. Res. Res. Res. 28
0
Res. Res. Res. Res. Res. 27
0
Res. Res. Res. Res. Res. 26
0
Res. Res. Res. Res. Res. 25
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
RM0390 Rev 6
0
0
0
0
0
0
0
0
0
0
FIF0Data
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Table 215. SDIO register map (continued)
0
0
0
0
0
FIFOCOUNT
0
0
0
1045/1347
Secure digital input/output interface (SDIO)
1045
Controller area network (bxCAN) RM0390
30.1 Introduction
The Basic Extended CAN peripheral, named bxCAN, interfaces the CAN network. It
supports the CAN protocols version 2.0A and B. It has been designed to manage a high
number of incoming messages efficiently with a minimum CPU load. It also meets the
priority requirements for transmit messages.
For safety-critical applications, the CAN controller provides all hardware functions for
supporting the CAN Time Triggered Communication option.
CAN node 2
CAN node n
MCU
Application
CAN
Controller
CAN CAN
Rx Tx
CAN
Transceiver
CAN CAN
High Low
CAN Bus
MS30392V1
30.3.3 Tx mailboxes
Three transmit mailboxes are provided to the software for setting up messages. The
transmission scheduler decides which mailbox has to be transmitted first.
Receive FIFO
Two receive FIFOs are used by hardware to store the incoming messages. Three complete
messages can be stored in each FIFO. The FIFOs are managed completely by hardware.
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 Note: CAN2 start filter bank number n is configurable by writing
CAN2SB[5:0] bits in the CAN_FMR register
Error Status
Bit Timing
ai16094b
Reset
Sleep
SLAK = 1
INAK = 0
Q SL
R EE
.IN SL P.
IN
C
YN EE R
Q
.S K P. .A
EP . AC IN
R C
K
E
SL EP Q
.A
SLE C
K
Normal INRQ.ACK
Initialization
SLAK = 0 SLAK = 0
INAK = 0
INAK = 1
INRQ.SYNC.SLEEP
ai15902
1. ACK = The wait state during which hardware confirms a request by setting the INAK or SLAK bits in the
CAN_MSR register.
2. SYNC = The state during which bxCAN waits until the CAN bus is idle, meaning 11 consecutive recessive
bits have been monitored on CANRX.
bxCAN
Tx Rx
=1
CANTX CANRX
MS30393V2
bxCAN
Tx Rx
CANTX CANRX
MS30394V2
This mode is provided for self-test functions. To be independent of external events, the CAN
Core ignores acknowledge errors (no dominant bit sampled in the acknowledge slot of a
data / remote frame) in Loop Back Mode. In this mode, the bxCAN performs an internal
feedback from its Tx output to its Rx input. The actual value of the CANRX input pin is
disregarded by the bxCAN. The transmitted messages can be monitored on the CANTX pin.
bxCAN
Tx Rx
=1
CANTX CANRX
MS30395V2
mailbox starts (enter transmit state) when the CAN bus becomes idle. Once the mailbox
has been successfully transmitted, it becomes empty again. The hardware indicates a
successful transmission by setting the RQCP and TXOK bits in the CAN_TSR register.
If the transmission fails, the cause is indicated by the ALST bit in the CAN_TSR register in
case of an Arbitration Lost, and/or the TERR bit, in case of transmission error detection.
Transmit priority
By identifier
When more than one transmit mailbox is pending, the transmission order is given by the
identifier of the message stored in the mailbox. The message with the lowest identifier value
has the highest priority according to the arbitration of the CAN protocol. If the identifier
values are equal, the lower mailbox number is scheduled first.
By transmit request order
The transmit mailboxes can be configured as a transmit FIFO by setting the TXFP bit in the
CAN_MCR register. In this mode the priority order is given by the transmit request order.
This mode is very useful for segmented transmission.
Abort
A transmission request can be aborted by the user setting the ABRQ bit in the CAN_TSR
register. In pending or scheduled state, the mailbox is aborted immediately. An abort
request while the mailbox is in transmit state can have two results. If the mailbox is
transmitted successfully the mailbox becomes empty with the TXOK bit set in the
CAN_TSR register. If the transmission fails, the mailbox becomes scheduled, the
transmission is aborted and becomes empty with TXOK cleared. In all cases the mailbox
becomes empty again at least at the end of the current transmission.
EMPTY
RQCP=X
TXOK=X
TXRQ=1
TME = 1
PENDING
RQCP=0 Mailbox has
TXOK=0 highest priority
ABRQ=1
TME = 0
EMPTY
Transmit succeeded
RQCP=1
TXOK=1
TME = 1
MS30396V2
Valid message
A received message is considered as valid when it has been received correctly according to
the CAN protocol (no error until the last but one bit of the EOF field) and It passed through
the identifier filtering successfully, see Section 30.7.4.
EMPTY
FMP=0x00 Valid Message
FOVR=0 Received
PENDING_1
Release FMP=0x01
Mailbox FOVR=0
PENDING_2
FMP=0x10
FOVR=0
PENDING_3
FMP=0x11 Valid Message
FOVR=0 Received
OVERRUN
Release FMP=0x11
Mailbox FOVR=1
RFOM=1
Valid Message
Received
MS30397V2
FIFO management
Starting from the empty state, the first valid message received is stored in the FIFO which
becomes pending_1. The hardware signals the event setting the FMP[1:0] bits in the
CAN_RFR register to the value 01b. The message is available in the FIFO output mailbox.
The software reads out the mailbox content and releases it by setting the RFOM bit in the
CAN_RFR register. The FIFO becomes empty again. If a new valid message has been
received in the meantime, the FIFO stays in pending_1 state and the new message is
available in the output mailbox.
If the application does not release the mailbox, the next valid message is stored in the FIFO
which enters pending_2 state (FMP[1:0] = 10b). The storage process is repeated for the
next valid message putting the FIFO into pending_3 state (FMP[1:0] = 11b). At this point,
the software must release the output mailbox by setting the RFOM bit, so that a mailbox is
free to store the next valid message. Otherwise the next valid message received causes a
loss of message. Refer also to Section 30.7.5.
Overrun
Once the FIFO is in pending_3 state (i.e. the three mailboxes are full) the next valid
message reception leads to an overrun and a message is lost. The hardware signals the
overrun condition by setting the FOVR bit in the CAN_RFR register. Which message is lost
depends on the configuration of the FIFO:
If the FIFO lock function is disabled (RFLM bit in the CAN_MCR register cleared) the
last message stored in the FIFO is overwritten by the new incoming message. In this
case the latest messages are always available to the application.
If the FIFO lock function is enabled (RFLM bit in the CAN_MCR register set) the most
recent message is discarded and the software has the three oldest messages in the
FIFO available.
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 391.
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”.
identifiers. All bits of the incoming identifier must match the bits specified in the filter
registers.
ID CAN_FxR2[15:8] CAN_FxR2[7:0]
n+1
Mask CAN_FxR2[31:24] CAN_FxR2[23:16]
ID=Identifier
Filter Bank Mode
MSv30398V4
2
1 ID Mask (32-bit) 2 4 ID List (32-bit) 3
3
4 Deactivated 4
3 ID List (16-bit) 5 7
ID Mask (16-bit) 5
6
Deactivated 7 6
5 8 ID Mask (16-bit)
ID List (32-bit) 8 7
8
9 Deactivated 9
6 ID Mask (16-bit) 10 10
10 ID List (16-bit)
11
11 12
9 ID List (32-bit) 11 ID List (32-bit)
12 13
ID=Identifier
MS30399V2
Filter bank
Num Receive FIFO
Identifier 0
0
Identifier 1 Message
Identifier List
Identifier 5
Identifier & Mask
1
Identifier
Mask 2 Filter number stored in the
FMI
Filter Match Index field
within the CAN_RDTxR
Identifier register
4 3
Mask
No Match
Found
Message Discarded
MS31000V2
The example above shows the filtering principle of the bxCAN. On reception of a message,
the identifier is compared first with the filters configured in identifier list mode. If there is a
match, the message is stored in the associated FIFO and the index of the matching filter is
stored in the filter match index. As shown in the example, the identifier matches with
Identifier #2 thus the message content and FMI 2 is stored in the FIFO.
If there is no match, the incoming identifier is then compared with the filters configured in
mask mode.
If the identifier does not match any of the identifiers configured in the filters, the message is
discarded by hardware without disturbing the software.
Transmit mailbox
The software sets up the message to be transmitted in an empty transmit mailbox. The
status of the transmission is indicated by hardware in the CAN_TSR register.
0 CAN_TIxR
4 CAN_TDTxR
8 CAN_TDLxR
12 CAN_TDHxR
Receive mailbox
When a message has been received, it is available to the software in the FIFO output
mailbox. Once the software has handled the message (e.g. read it) the software must
release the FIFO output mailbox by means of the RFOM bit in the CAN_RFR register to
make the next incoming message available. The filter match index is stored in the MFMI
field of the CAN_RDTxR register. The 16-bit time stamp value is stored in the TIME[15:0]
field of CAN_RDTxR.
0 CAN_RIxR
4 CAN_RDTxR
8 CAN_RDLxR
12 CAN_RDHxR
BUS OFF
ai15903
Bus-Off recovery
The Bus-Off state is reached when TEC is greater than 255, this state is indicated by BOFF
bit in CAN_ESR register. In Bus-Off state, the bxCAN is no longer able to transmit and
receive messages.
Depending on the ABOM bit in the CAN_MCR register, bxCAN recovers from Bus-Off
(become error active again) either automatically or on software request. But in both cases
the bxCAN has to wait at least for the recovery sequence specified in the CAN standard
(128 occurrences of 11 consecutive recessive bits monitored on CANRX).
If ABOM is set, the bxCAN starts the recovering sequence automatically after it has entered
Bus-Off state.
If ABOM is cleared, the software must initiate the recovering sequence by requesting
bxCAN to enter and to leave initialization mode.
Note: In initialization mode, bxCAN does not monitor the CANRX signal, therefore it cannot
complete the recovery sequence. To recover, bxCAN must be in normal mode.
Its operation may be explained simply by splitting nominal bit time into three segments as
follows:
Synchronization segment (SYNC_SEG): a bit change is expected to occur within this
time segment. It has a fixed length of one time quantum (1 x tq).
Bit segment 1 (BS1): defines the location of the sample point. It includes the
PROP_SEG and PHASE_SEG1 of the CAN standard. Its duration is programmable
between 1 and 16 time quanta but may be automatically lengthened to compensate for
positive phase drifts due to differences in the frequency of the various nodes of the
network.
Bit segment 2 (BS2): defines the location of the transmit point. It represents the
PHASE_SEG2 of the CAN standard. Its duration is programmable between 1 and 8
time quanta but may also be automatically shortened to compensate for negative
phase drifts.
The resynchronization jump width (SJW) defines an upper bound to the amount of
lengthening or shortening of the bit segments. It is programmable between 1 and 4 time
quanta.
A valid edge is defined as the first transition in a bit time from dominant to recessive bus
level provided the controller itself does not send a recessive bit.
If a valid edge is detected in BS1 instead of SYNC_SEG, BS1 is extended by up to SJW so
that the sample point is delayed.
Conversely, if a valid edge is detected in BS2 instead of SYNC_SEG, BS2 is shortened by
up to SJW so that the transmit point is moved earlier.
As a safeguard against programming errors, the configuration of the Bit timing register
(CAN_BTR) is only possible while the device is in Standby mode.
Note: For a detailed description of the CAN bit timing and resynchronization mechanism, refer to
the ISO 11898 standard.
1 x tq tBS1 tBS2
MS31001V2
IDE
r0
ACK
RTR
Inter-frame space
Inter-frame space Data frame (extended identifier)
or overload frame
64 + 8 *N
Arbitration field Ctrl field Data field CRC field ACK field
2
32 8 *N 16 7
ID DLC CRC EOF
SOF
SRR
IDE
r1
r0
ACK
RTR
Inter-frame space
Inter-frame space Remote frame (standard identifier)
or overload frame
44
Arbitration field Ctrl field CRC field ACK field
2
12 6 16 7
ID DLC CRC EOF
SOF
IDE
r0
ACK
RTR
Inter-frame space
Inter-frame space Remote frame (extended identifier)
or overload frame
64
Arbitration field Ctrl field CRC field ACK field
2
32 6 16 7
ID DLC CRC EOF
SOF
IDE
r0
ACK
RTR
End of frame or
v Suspend transmission: applies to
Error delimiter or Inter-frame space error passive nodes only
Overload delimiter Overload frame or Error frame v EOF: End of frame
Overload Overload Overload v ACK: Acknowledge bit
flag echo delimiter v Ctrl: Control
6 6 8
MS54357V1
FMPIE0
FMP0
& FIFO 0
INTERRUPT
FFIE0
CAN_RF0R FULL0
& +
FOVIE0
FOVR0
&
FMPIE1
FMP1
& FIFO 1
INTERRUPT
FFIE1
CAN_RF1R FULL1
& +
FOVIE1
FOVR1
&
ERRIE
EWGIE
EWGF &
EPVIE
CAN_ESR EPVF & &
BOFIE
+
ERRI
BOFF & CAN_MSR STATUS CHANGE
ERROR
LECIE
1 LEC 6 & INTERRUPT
WKUIE
WKUI
&
CAN_MSR
SLKIE
SLAKI
&
MS31002V2
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DBF
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RESET Res. Res. Res. Res. Res. Res. Res. TTCM ABOM AWUM NART RFLM TXFP SLEEP INRQ
rs rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. RX SAMP RXM TXM Res. Res. Res. SLAKI WKUI ERRI SLAK INAK
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
LOW2 LOW1 LOW0 TME2 TME1 TME0 CODE[1:0] ABRQ2 Res. Res. Res. TERR2 ALST2 TXOK2 RQCP2
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ABRQ1 Res. Res. Res. TERR1 ALST1 TXOK1 RQCP1 ABRQ0 Res. Res. Res. TERR0 ALST0 TXOK0 RQCP0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RFOM0 FOVR0 FULL0 Res. FMP0[1:0]
rs rc_w1 rc_w1 r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. RFOM1 FOVR1 FULL1 Res. FMP1[1:0]
rs rc_w1 rc_w1 r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SLKIE WKUIE
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
REC[7:0] TEC[7:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. LEC[2:0] Res. BOFF EPVF EWGF
rw rw rw r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SILM LBKM Res. Res. Res. Res. SJW[1:0] Res. TS2[2:0] TS1[3:0]
rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
STID[10:0]/EXID[28:18] EXID[17:13]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIME[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. DLC[3:0]
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATA3[7:0] DATA2[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATA1[7:0] DATA0[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATA7[7:0] DATA6[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATA5[7:0] DATA4[7:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
STID[10:0]/EXID[28:18] EXID[17:13]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r r r r r r r r
CAN receive FIFO mailbox data length control and time stamp register
(CAN_RDTxR) (x = 0..1)
Address offsets: 0x1B4, 0x1C4
Reset value: 0xXXXX XXXX
All RX registers are write protected.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TIME[15:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATA3[7:0] DATA2[7:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATA1[7:0] DATA0[7:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATA7[7:0] DATA6[7:0]
r r r r r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATA5[7:0] DATA4[7:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. CANSB[5:0] Res. Res. Res. Res. Res. Res. Res. FINIT
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. FBM27 FBM26 FBM25 FBM24 FBM23 FBM22 FBM21 FBM20 FBM19 FBM18 FBM17 FBM16
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FBM15 FBM14 FBM13 FBM12 FBM11 FBM10 FBM9 FBM8 FBM7 FBM6 FBM5 FBM4 FBM3 FBM2 FBM1 FBM0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Refer to Figure 391: Filter bank scale configuration - Register organization.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. FSC27 FSC26 FSC25 FSC24 FSC23 FSC22 FSC21 FSC20 FSC19 FSC18 FSC17 FSC16
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FSC15 FSC14 FSC13 FSC12 FSC11 FSC10 FSC9 FSC8 FSC7 FSC6 FSC5 FSC4 FSC3 FSC2 FSC1 FSC0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Note: Refer to Figure 391: Filter bank scale configuration - Register organization on page 1057.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. FFA27 FFA26 FFA25 FFA24 FFA23 FFA22 FFA21 FFA20 FFA19 FFA18 FFA17 FFA16
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
FACT FACT FACT FACT FACT FACT FACT FACT FACT FACT FACT FACT
Res. Res. Res. Res.
27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FACT FACT FACT FACT FACT FACT
FACT9 FACT8 FACT7 FACT6 FACT5 FACT4 FACT3 FACT2 FACT1 FACT0
15 14 13 12 11 10
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FB31 FB30 FB29 FB28 FB27 FB26 FB25 FB24 FB23 FB22 FB21 FB20 FB19 FB18 FB17 FB16
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FB15 FB14 FB13 FB12 FB11 FB10 FB9 FB8 FB7 FB6 FB5 FB4 FB3 FB2 FB1 FB0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
In all configurations:
Note: Depending on the scale and mode configuration of the filter the function of each register can
differ. For the filter mapping, functions description and mask registers association, refer to
Section 30.7.4: Identifier filtering.
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 218.
0x17F
0x01C
0x00C
0x020-
Offset
30.9.5
1086/1347
-
CAN_IER
CAN_TSR
CAN_BTR
CAN_ESR
CAN_TI0R
CAN_MSR
CAN_MCR
Register
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
Reset value
CAN_RF1R
CAN_RF0R
x
0
0
0
Res. SILM Res. Res. Res. Res. Res. 31
x
0
0
0
Res. LBKM Res. Res. Res. LOW[2:0] Res. Res. 30
x
0
0
Res. Res. Res. Res. Res. Res. Res. 29
x
0
1
Res. Res. Res. Res. Res. Res. Res. 28
x
0
1
Res. Res. Res. Res. Res. TME[2:0] Res. Res. 27
REC[7:0]
x
0
1
Controller area network (bxCAN)
x
0
0
0
Res. Res. Res. Res. Res. Res. 25
bxCAN register map
SJW[1:0] CODE[1:0]
x
0
0
0
Res. Res. Res. Res. Res. Res. 24
STID[10:0]/EXID[28:18]
x
0
0
Res. Res. Res. Res. Res. ABRQ2 Res. Res. 23
x
0
0
Res. Res. Res. Res. Res. Res. Res. 22
x
1
0
Res. Res. Res. Res. Res. Res. Res. 21
TS2[2:0]
x
0
0
Res. Res. Res. Res. Res. Res. Res. 20
x
0
0
0
Res. Res. Res. Res. TERR2 Res. Res. 19
TEC[7:0]
x
0
0
0
Res. Res. Res. Res. ALST2 Res. Res. 18
x
1
0
0
RM0390 Rev 6
Res. SLKIE Res. Res. TXOK2 Res. Res. 17
TS1[3:0]
x
1
0
0
0
1
offset 0x200 to 0x31C are present only in CAN1.
x
0
0
0
x
Res. Res. Res. Res. Res. Res. Res. Res. Res. 14
x
Res. Res. Res. Res. Res. Res. Res. Res. Res. 13
x
Res. Res. Res. Res. Res. Res. Res. Res. Res. 12
x
0
0
1
EXID[17:0]
x
0
0
1
Table 218. bxCAN register map and reset values
x
0
0
0
0
x
0
0
0
0
x
0
0
0
x
0
0
0
0
x
0
0
0
0
0
0
x
0
0
0
0
0
0
0
BRP[9:0]
x
0
0
0
0
0
0
0
x
0
0
0
0
0
0
x
0
0
0
0
0
0
1
1
Refer to Section 2.2 on page 56 for the register boundary addresses. The registers from
0
0
0
0
0
0
0
0
0
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TGT
CAN_TDT0R TIME[15:0] DLC[3:0]
0x184
Reset value x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
TXRQ
RTR
IDE
CAN_TI1R STID[10:0]/EXID[28:18] EXID[17:0]
0x190
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TGT
CAN_TDT1R TIME[15:0] DLC[3:0]
0x194
Reset value x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
TXRQ
RTR
CAN_TI2R STID[10:0]/EXID[28:18] EXID[17:0] IDE
0x1A0
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
TGT
Reset value x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Res.
RTR
IDE
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
Res.
Res.
Res.
Res.
CAN_RDT0R TIME[15:0] FMI[7:0] DLC[3:0]
0x1B4
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Res.
RTR
IDE
CAN_RI1R STID[10:0]/EXID[28:18] EXID[17:0]
0x1C0
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x -
Res.
Res.
Res.
Res.
CAN_RDT1R TIME[15:0] FMI[7:0] DLC[3:0]
0x1C4
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
0x1D0-
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x1FF
-
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
- Res.
0x208
-
Res.
Res.
Res.
Res.
CAN_FS1R FSC[27:0]
0x20C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x210 -
Res.
Res.
Res.
Res.
CAN_FFA1R FFA[27:0]
0x214
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x218 -
Offset Register
31
30
29
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
10
11
9
8
7
6
5
4
3
2
1
0
Res.
Res.
Res.
Res.
CAN_FA1R FACT[27:0]
0x21C
Reset value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x220 -
0x224-
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
Res.
0x23F
-
CAN_F0R1 FB[31:0]
0x240
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
CAN_F0R2 FB[31:0]
0x244
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
CAN_F1R1 FB[31:0]
0x248
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
CAN_F1R2 FB[31:0]
0x24C
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
. . .
. . .
. . .
. . .
CAN_F27R1 FB[31:0]
0x318
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
CAN_F27R2 FB[31:0]
0x31C
Reset value x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x
31.1 Introduction
Portions Copyright (c) Synopsys, Inc. All rights reserved. Used with permission.
This section presents the architecture and the programming model of the
OTG_FS/OTG_HS controller.
The following acronyms are used throughout the section:
FS Full-speed
LS Low-speed
HS High-speed
MAC Media access controller
OTG On-the-go
PFC Packet FIFO controller
PHY Physical layer
USB Universal serial bus
UTMI USB 2.0 Transceiver Macrocell interface (UTMI)
ULPI UTMI+ Low Pin Interface
LPM Link power management
HNP Host negotiation protocol
SRP Session request protocol
Host mode X X X
Device mode X X -
Host mode - X X
Device mode - X -
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
OTG_HS_DP
OTG FS PHY
transceiver
OTG_HS_DM
serial
OTG_HS_ID
OTG_HS
CPU (USB OTG HS core) OTG detections
OTG_HS_VBUS
AHB (application bus)
AHB
Memory master EXTI
interface
ULPI_CK;
Interrupt: async wakeup ULPI_DIR;
Interrupt: EP1 out ULPI_STP;
NVIC
Interrupt: EP1 in ULPI_NXT;
AHB
Peripheral 1 ULPI_D0-7
slave Interrupt: global
interface USB2.0 (D+/D-)
ULPI interface (12 pins) ULPI PHY
(external
component)
Peripheral 2
RAM interface
Data FIFO
OTG_HS_SOF
Data FIFO
Single-port RAM
(SPRAM)
MSv43325V1
usb_sof Digital output USB OTG start-of-frame event for on chip peripherals
usb_wkup Digital output USB OTG wakeup event output
usb_gbl_it Digital output USB OTG global interrupt
usb_ep1_in_it Digital output USB OTG endpoint 1 in interrupt
usb_ep1_out_it Digital output USB OTG endpoint 1 out interrupt
The USB OTG_HS core includes an ULPI interface to connect an external HS PHY.
Note: In case of multiple OTG_HS instances, ULPI may not be available on each one. Refer to implementation table.
VDD
5 V to VDD
Voltage
regulator(1)
VDD
STM32 EN STMPS2141STR
GPIO
Current-limited 5 V Pwr
Overcurrent power distribution
GPIO + IRQ switch(2)
VBUS
VBUS
USBmicro-AB connector
DM
DM
OSC_IN DP
DP
ID
ID
OSC_OUT
VSS
MSv36917V2
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.
VDD
5 V to VDD
Voltage
regulator
VDD
GPIO EN STMPS2141STR
Current-limited 5 V Pwr
Overcurrent power distribution
GPIO + IRQ switch(1)
VBUS
DM
OSC_OUT
VSS
MSv36916V2
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_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/OTG_HS 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_DCFG). The
OTG_FS/OTG_HS then enters the address state and is ready to answer host transactions
at the configured USB address.
Suspended state
The OTG_FS/OTG_HS peripheral constantly monitors the USB activity. After counting 3 ms
of USB idleness, the early suspend interrupt (ESUSP bit in OTG_GINTSTS) is issued, and
confirmed 3 ms later, if appropriate, by the suspend interrupt (USBSUSP bit in
OTG_GINTSTS). The device suspend bit is then automatically set in the device status
register (SUSPSTS bit in OTG_DSTS) and the OTG_FS/OTG_HS 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_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_GINTSTS) is generated and the device suspend bit is automatically cleared.
which the transfer is not completed in the current frame. This interrupt is asserted
along with the end of periodic frame interrupt (OTG_GINTSTS/EOPF).
5[FS] / 8[HS] 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_DOEPCTLx), transfer configuration
(OTG_DOEPTSIZx) and status-interrupt (OTG_DOEPINTx) register
– Device OUT endpoints common interrupt mask register (OTG_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_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_GINTSTS/EOPF).
Endpoint control
The following endpoint controls are available to the application through the device
endpoint-x IN/OUT control register (OTG_DIEPCTLx/OTG_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 (OTG_DIEPTSIZx/OTG_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/OTG_HS
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 (OTG_DIEPINTx/OTG_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_GINTSTS or IEPINT bit in OTG_GINTSTS,
respectively) is set. Before the application can read these registers, it must first read the
device all endpoints interrupt (OTG_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 OTG_DAINT and OTG_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
VDD
5V
EN STMPS2141STR
GPIO
Current-limited 5 V Pwr
MSv36915V2
VBUS valid
When HNP or SRP is enabled the VBUS sensing 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.4 V) leads
to an OTG interrupt triggered by the session end detected bit (SEDET bit in
OTG_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 does not need to be
connected to VBUS.
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_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_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_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_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_HPRT). The OTG_FS/OTG_HS
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_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_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.
The mask bits for each interrupt source of each channel are also available in the
OTG_HCINTMSKx register.
The host core provides the following status checks and interrupt generation:
– Transfer completed interrupt, indicating that the data transfer is complete on both
the application (AHB) and USB sides
– Channel has stopped due to transfer completed, USB transaction error or disable
command from the application
– Associated transmit FIFO is half or completely empty (IN endpoints)
– ACK response received
– NAK response received
– STALL response received
– USB transaction error due to CRC failure, timeout, bit stuff error, false EOP
– Babble error
– frame overrun
– data toggle error
STM32
D+
TIM SOFgen ID
VSS
MSv36914V1
The OTG_FS/OTG_HS 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.
The end of periodic frame interrupt (OTG_GINTSTS/EOPF) is used to notify the application
when 80%, 85%, 90% or 95% of the time frame interval elapsed depending on the periodic
frame interval field in the device configuration register (PFIVL bit in OTG_DCFG). This
feature can be used to determine if all of the isochronous traffic for that frame is complete.
Table 225. Compatibility of STM32 low power modes with the OTG
Mode Description USB compatibility
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/OTG_HS 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/OTG_HS 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/OTG_HS core.
SOF reload
OTG_HFIR write
400
399
450
449
450
449
Frame timer
1
0
1
0
1
0
1
0
ai18440b
the device’s role. In peripheral mode an additional Tx FIFO is instructed for each active IN
endpoint. Any FIFO size is software configured to better meet the application requirements.
Figure 406. Device-mode FIFO address mapping and AHB FIFO access mapping
Single data
FIFO
IN endpoint Tx FIFO #x Dedicated Tx OTG_DIEPTXFx[31:16]
Tx FIFO #x
DFIFO push access FIFO #x control
packet
from AHB (optional) OTG_DIEPTXFx[15:0]
MAC pop
. . .
. . .
. . .
MAC push
A1=0 (Rx start address fixed
to 0)
MSv36929V1
Peripheral Rx FIFO
The OTG peripheral uses a single receive FIFO that receives the data directed to all OUT
endpoints. Received packets are stacked back-to-back until free space is available in the Rx
FIFO. The status of the received packet (which contains the OUT endpoint destination
number, the byte count, the data PID and the validity of the received data) is also stored by
the core on top of the data payload. When no more space is available, host transactions are
NACKed and an interrupt is received on the addressed endpoint. The size of the receive
FIFO is configured in the receive FIFO size register (OTG_GRXFSIZ).
The single receive FIFO architecture makes it more efficient for the USB peripheral to fill in
the receive RAM buffer:
All OUT endpoints share the same RAM buffer (shared FIFO)
The OTG_FS/OTG_HS core can fill in the receive FIFO up to the limit for any host
sequence of OUT tokens
The application keeps receiving the Rx FIFO non-empty interrupt (RXFLVL bit in
OTG_GINTSTS) as long as there is at least one packet available for download. It reads the
packet information from the receive status read and pop register (OTG_GRXSTSP) and
finally pops data off the receive FIFO by reading from the endpoint-related pop address.
Peripheral Tx FIFOs
The core has a dedicated FIFO for each IN endpoint. The application configures FIFO sizes
by writing the endpoint 0 transmit FIFO size register (OTG_DIEPTXF0) for IN endpoint0 and
the device IN endpoint transmit FIFOx registers (OTG_DIEPTXFx) for IN endpoint-x.
Figure 407. Host-mode FIFO address mapping and AHB FIFO access mapping
Single data
FIFO
Periodic Tx
OTG_HPTXFSIZ[31:16]
Any periodic channel packets
Periodic Tx FIFO
DFIFO push access
control (optional)
from AHB OTG_HPTXFSIZ[15:0]
MAC pop
Non-periodic
OTG_HNPTXFSIZ[31:16]
Any non-periodic Tx packets
Non-periodic Tx
channel DFIFO push
FIFO control
access from AHB OTG_HNPTXFSIZ[15:0]
MAC pop
Rx packets OTG_GRXFSIZ[15:0]
Any channel DFIFO pop
Rx FIFO control
access from AHB
Rx start address fixed to 0
A1=0
MAC push
MSv36930V1
Host Rx FIFO
The host uses one receiver FIFO for all periodic and nonperiodic transactions. The FIFO is
used as a receive buffer to hold the received data (payload of the received packet) from the
USB until it is transferred to the system memory. Packets received from any remote IN
endpoint are stacked back-to-back until free space is available. The status of each received
packet with the host channel destination, byte count, data PID and validity of the received
data are also stored into the FIFO. The size of the receive FIFO is configured in the receive
FIFO size register (OTG_GRXFSIZ).
The single receive FIFO architecture makes it highly efficient for the USB host to fill in the
receive data buffer:
All IN configured host channels share the same RAM buffer (shared FIFO)
The OTG_FS/OTG_HS core can fill in the receive FIFO up to the limit for any sequence
of IN tokens driven by the host software
The application receives the Rx FIFO not-empty interrupt as long as there is at least one
packet available for download. It reads the packet information from the receive status read
and pop register and finally pops the data off the receive FIFO.
Host Tx FIFOs
The host uses one transmit FIFO for all non-periodic (control and bulk) OUT transactions
and one transmit FIFO for all periodic (isochronous and interrupt) OUT transactions. FIFOs
are used as transmit buffers to hold the data (payload of the transmit packet) to be
transmitted over the USB. The size of the periodic (nonperiodic) Tx FIFO is configured in the
host periodic (nonperiodic) transmit FIFO size OTG_HPTXFSIZ / OTG_HNPTXFSIZ)
register.
The two Tx FIFO implementation derives from the higher priority granted to the periodic type
of traffic over the USB frame. At the beginning of each frame, the built-in host scheduler
processes the periodic request queue first, followed by the nonperiodic request queue.
The two transmit FIFO architecture provides the USB host with separate optimization for
periodic and nonperiodic transmit data buffer management:
All host channels configured to support periodic (nonperiodic) transactions in the OUT
direction share the same RAM buffer (shared FIFOs)
The OTG_FS/OTG_HS core can fill in the periodic (nonperiodic) transmit FIFO up to
the limit for any sequence of OUT tokens driven by the host software
The OTG_FS/OTG_HS core issues the periodic Tx FIFO empty interrupt (PTXFE bit in
OTG_GINTSTS) as long as the periodic Tx FIFO is half or completely empty, depending on
the value of the periodic Tx FIFO empty level bit in the AHB configuration register
(PTXFELVL bit in OTG_GAHBCFG). The application can push the transmission data in
advance as long as free space is available in both the periodic Tx FIFO and the periodic
request queue. The host periodic transmit FIFO and queue status register
(OTG_HPTXSTS) can be read to know how much space is available in both.
OTG_FS/OTG_HS core issues the non periodic Tx FIFO empty interrupt (NPTXFE bit in
OTG_GINTSTS) as long as the nonperiodic Tx FIFO is half or completely empty depending
on the non periodic Tx FIFO empty level bit in the AHB configuration register (TXFELVL bit
in OTG_GAHBCFG). The application can push the transmission data as long as free space
is available in both the nonperiodic Tx FIFO and nonperiodic request queue. The host
nonperiodic transmit FIFO and queue status register (OTG_HNPTXSTS) can be read to
know how much space is available in both.
Device RxFIFO =
(5 * number of control endpoints + 8) + ((largest USB packet used / 4) + 1 for status
information) + (2 * number of OUT endpoints) + 1 for Global NAK
Example: The MPS is 1,024 bytes for a periodic USB packet and 512 bytes for a non-
periodic USB packet. There are three OUT endpoints, three IN endpoints, one control
endpoint, and three host channels.
Device RxFIFO = (5 * 1 + 8) + ((1,024 / 4) +1) + (2 * 4) + 1 = 279
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.
Host mode
Receive FIFO RAM allocation:
Status information is written to the FIFO along with each received packet. Therefore, a
minimum space of (largest packet size / 4) + 1 must be allocated to receive packets. If
multiple isochronous channels are enabled, then at least two (largest packet size / 4) + 1
spaces must be allocated to receive back-to-back packets. Typically, two (largest packet
size / 4) + 1 spaces are recommended so that when the previous packet is being transferred
to the CPU, the USB can receive the subsequent packet.
Along with the last packet in the host channel, transfer complete status information is also
pushed to the FIFO. So one location must be allocated for this.
Host RxFIFO = (largest USB packet used / 4) + 1 for status information + 1 transfer
complete
Example: Host RxFIFO = ((1,024 / 4) + 1) + 1 = 258
Transmit FIFO RAM allocation:
The minimum amount of RAM required for the host Non-periodic Transmit FIFO is the
largest maximum packet size among all supported non-periodic OUT channels.
Typically, two largest packet sizes worth of space is recommended, so that when the current
packet is under transfer to the USB, the CPU can get the next packet.
Non-Periodic TxFIFO = largest non-periodic USB packet used / 4
Example: Non-Periodic TxFIFO = (512 / 4) = 128
The minimum amount of RAM required for host periodic Transmit FIFO is the largest
maximum packet size out of all the supported periodic OUT channels. If there is at least one
isochronous OUT endpoint, then the space must be at least two times the maximum packet
size of that channel.
Host Periodic TxFIFO = largest periodic USB packet used / 4
Example: Host Periodic TxFIFO = (1,024 / 4) = 256
Note: More space allocated in the Transmit Non-periodic FIFO results in better performance on
the USB.
Global interrupt
OTG_FS / OTG_HS
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_DIEPEACHMSK1/
OTG_DOEPMSK OTG_DOEPEACHMSK1
Device IN/OUT endpoints common Device each IN/OUT endpoint interrupt
interrupt mask register mask registers
x=0
OTG_DIEPINTx/
...
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
...
MSv47471V3
1. OTG_FS_WKUP / OTG_HS_WKUP become active (high state) when resume condition occurs during L1 SLEEP or L2
SUSPEND states.
OTG_GOTGCTL 0x000 Section 31.15.1: OTG control and status register (OTG_GOTGCTL)
Table 226. Core global control and status registers (CSRs) (continued)
Address
Acronym Register name
offset
OTG_GRXFSIZ 0x024 Section 31.15.12: OTG receive FIFO size register (OTG_GRXFSIZ)
OTG_HNPTXFSIZ/ Section 31.15.13: OTG host non-periodic transmit FIFO size register
0x028
OTG_DIEPTXF0(1) (OTG_HNPTXFSIZ)/Endpoint 0 Transmit FIFO size (OTG_DIEPTXF0)
OTG_GCCFG 0x038 Section 31.15.15: OTG general core configuration register (OTG_GCCFG)
OTG_GLPMCFG 0x54 Section 31.15.17: OTG core LPM configuration register (OTG_GLPMCFG)
OTG_HFIR 0x404 Section 31.15.22: OTG host frame interval register (OTG_HFIR)
OTG_HAINT 0x414 Section 31.15.25: OTG host all channels interrupt register (OTG_HAINT)
OTG_HPRT 0x440 Section 31.15.27: OTG host port control and status register (OTG_HPRT)
0x500
0x520 Section 31.15.28: OTG host channel x characteristics register
OTG_HCCHARx
... (OTG_HCCHARx) for USB_OTG FS
0x660
0x500
0x520 Section 31.15.28: OTG host channel x characteristics register
OTG_HCCHARx
... (OTG_HCCHARx) for USB_OTG HS
0x6E0
0x504
0x524 Section 31.15.29: OTG host channel x split control register
OTG_HCSPLTx
.... (OTG_HCSPLTx)
0x6E4
0x508
0x528 Section 31.15.30: OTG host channel x interrupt register (OTG_HCINTx)
OTG_HCINTx
.... for USB_OTG FS
0x668
0x508
0x528 Section 31.15.30: OTG host channel x interrupt register (OTG_HCINTx)
OTG_HCINTx
.... for USB_OTG HS
0x6E8
0x50C
0x52C Section 31.15.31: OTG host channel x interrupt mask register
OTG_HCINTMSKx
.... (OTG_HCINTMSKx) for USB_OTG FS
0x66C
0x50C
0x52C Section 31.15.31: OTG host channel x interrupt mask register
OTG_HCINTMSKx
.... (OTG_HCINTMSKx) for USB_OTG HS
0x6EC
0x510
0x530 Section 31.15.32: OTG host channel x transfer size register
OTG_HCTSIZx
.... (OTG_HCTSIZx) for USB_OTG FS
0x670
0x510
0x530 Section 31.15.32: OTG host channel x transfer size register
OTG_HCTSIZx
.... (OTG_HCTSIZx) for USB_OTG HS
0x6F0
0x514
0x534 Section 31.15.33: OTG host channel x DMA address register
OTG_HCDMAx
.... (OTG_HCDMAx)
0x6F4
OTG_HS_DOEPEACHM Section 31.15.49: OTG device each OUT endpoint-1 interrupt mask
0x884
SK1 register (OTG_HS_DOEPEACHMSK1)
0x920
0x940 Section 31.15.51: OTG device IN endpoint x control register
OTG_DIEPCTLx
... (OTG_DIEPCTLx) for USB_OTG FS
0x9A0
0x900
0x920 Section 31.15.51: OTG device IN endpoint x control register
OTG_DIEPCTLx
... (OTG_DIEPCTLx) for USB_OTG HS
0xA00
0x908
0x928 Section 31.15.52: OTG device IN endpoint x interrupt register
OTG_DIEPINTx
.... (OTG_DIEPINTx) for USB_OTG FS
0x988
0x908
0x928 Section 31.15.52: OTG device IN endpoint x interrupt register
OTG_DIEPINTx
... (OTG_DIEPINTx) for USB_OTG HS
0x9E8
0x914
0x934 Section 31.15.54: OTG device IN endpoint x DMA address register
OTG_DIEPDMAx
... (OTG_DIEPDMAx)
0x9F4
0x918
0x938 Section 31.15.55: OTG device IN endpoint transmit FIFO status register
OTG_DTXFSTSx
.... (OTG_DTXFSTSx) for USB_OTG FS
0x998
0x918
0x938 Section 31.15.55: OTG device IN endpoint transmit FIFO status register
OTG_DTXFSTSx
..... (OTG_DTXFSTSx) for USB_OTG HS
0x9F8
0x930
0x950 Section 31.15.56: OTG device IN endpoint x transfer size register
OTG_DIEPTSIZx
... (OTG_DIEPTSIZx) for USB_OTG FS
0x9B0
0x930
0x950 Section 31.15.56: OTG device IN endpoint x transfer size register
OTG_DIEPTSIZx
... (OTG_DIEPTSIZx) for USB_OTG HS
0x9F0
0xB08
0xB28 Section 31.15.58: OTG device OUT endpoint x interrupt register
OTG_DOEPINTx
... (OTG_DOEPINTx) for USB_OTG FS
0xBA8
0xB08
0XB28 Section 31.15.58: OTG device OUT endpoint x interrupt register
OTG_DOEPINTx
... (OTG_DOEPINTx) for USB_OTG HS
0xC08
0xB14
0xB34 Section 31.15.60: OTG device OUT endpoint x DMA address register
OTG_DOEPDMAx
... (OTG_DOEPDMAx)
0xC14
0xB20
0xB40 Section 31.15.61: OTG device OUT endpoint x control register
OTG_DOEPCTLx
... (OTG_DOEPCTLx) for USB_OTG FS
0xBA0
0xB20
0xB40 Section 31.15.61: OTG device OUT endpoint x control register
OTG_DOEPCTLx
... (OTG_DOEPCTLx) for USB_OTG HS
0xC00
0xB30
0xB50 Section 31.15.62: OTG device OUT endpoint x transfer size register
OTG_DOEPTSIZx
... (OTG_DOEPTSIZx) for USB_OTG FS
0xBB0
0xB30
0xB50 Section 31.15.62: OTG device OUT endpoint x transfer size register
OTG_DOEPTSIZx
.. (OTG_DOEPTSIZx) for USB_OTG HS
0xBF0
IN, the FIFO can only be read on the channel. Similarly, if a host channel is of type OUT, the
FIFO can only be written on the channel.
Table 230. Power and clock gating control and status registers
Acronym Offset address Register name
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CUR OTG CID
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. BSVLD ASVLD DBCT
MOD VER STS
r rw r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DHNP HSHNP HNP HNG BVALO BVALO AVALO AVALO VBVAL VBVAL SRQ
Res. Res. Res. EHEN SRQ
EN EN RQ SCS VAL EN VAL EN OVAL OEN SCS
rw rw rw rw r rw rw rw rw rw rw rw r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DBC ADTO HNG
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
DNE CHG DET
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HNSS SRSS
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. SEDET Res. Res.
CHG CHG
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PTXFE TXFE GINT
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
LVL LVL MSK
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PTXFE TXFE GINT
Res. Res. Res. Res. Res. Res. Res. Res. DMAEN HBSTLEN[3:0]
LVL LVL MSK
rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FD FH
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
MOD MOD
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HNP SRP PHY
Res. Res. TRDT Res. Res. Res. Res. TOCAL
CAP CAP SEL
rw rw rw rw rw rw r rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FD FH ULPI ULPIE ULPIE ULPI ULPI ULPI
Res. Res. Res. Res. PTCI PCCI TSDPS Res.
MOD MOD IPD VBUSI VBUSD CSM AR FSL
rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PHYL HNP SRP PHY
Res. TRDT[3:0] Res. Res. Res. Res. TOCAL[2:0]
PC CAP CAP SEL
rw rw rw rw rw rw rw rw rw rw 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
30 - 0x9
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AHB
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
IDL
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TXF RXF
Res. Res. Res. Res. Res. TXFNUM Res. FCRST PSRST CSRST
FLSH FLSH
rw rw rw rw rw rs rs rs rs r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
AHB DMAR
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
IDL EQ
r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TXF RXF
Res. Res. Res. Res. Res. TXFNUM[4:0] Res. FCRST PSRST CSRST
FLSH FLSH
rw rw rw rw rw rs rs rs rs rs
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IPXFR/
IN
WKUP SRQ DISC CIDS LPM HPRT RST IISOI OEP
PTXFE HCINT Res. COMP IEPINT Res. Res.
INT INT INT CHG INT INT DET XFR INT
ISO
OUT
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 r r r rc_w1 rc_w1 rc_w1 r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GO GI
ISOO ENUM USB USB NPTXF RXF OTG
EOPF ESUSP Res. Res. NAK NAK SOF MMIS CMOD
DRP DNE RST SUSP E LVL INT
EFF EFF
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 r r r r rc_w1 r rc_w1 r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IPXFR/
IN
WKUP SRQ DISC CIDS LPM HPRT RST DATAF IISOI OEP
PTXFE HCINT COMP IEPINT Res. Res.
INT INT INT CHG INT INT DET SUSP XFR INT
ISO
OUT
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 r r r rc_w1 rc_w1 rc_w1 rc_w1 r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GO GI
ISOO ENUM USB USB NPTXF RXF OTG
EOPF ESUSP Res. Res. NAK NAK SOF MMIS CMOD
DRP DNE RST SUSP E LVL INT
EFF EFF
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 r r r r rc_w1 r rc_w1 r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IPXFR
DISCIN CIDSC LPMIN PTXFE RSTDE M/IISO IISOIX OEPIN
WUIM SRQIM HCIM PRTIM Res. IEPINT Res. Res.
T HGM TM M TM OXFR FRM T
M
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
EOPF ISOOD ENUM USBRS USBSU ESUSP GONA GINAK NPTXF RXFLV OTGIN
Res. Res. SOFM MMISM Res.
M RPM DNEM T SPM M KEFFM EFFM EM LM T
rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IPXFR
DISCIN CIDSC LPMIN PTXFE RSTDE FSUS M/IISO IISOIX OEPIN
WUIM SRQIM HCIM PRTIM IEPINT Res. Res.
T HGM TM M TM PM OXFR FRM T
M
rw rw rw rw rw rw rw r rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EOPF ISOOD ENUM USBRS USBSU ESUSP GONA GINAK NPTXF RXFLV OTGIN
Res. Res. SOFM MMISM Res.
M RPM DNEM T SPM M KEFFM EFFM EM LM T
rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
STSPH
Res. Res. Res. Res. Res. Res. FRMNUM[3:0] PKTSTS[3:0] DPID[1]
ST
r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PKTSTS[3:0] DPID
r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
STSPH
Res. Res. Res. Res. Res. Res. FRMNUM[3:0] PKTSTS[3:0] DPID[1]
ST
r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PKTSTS[3:0] DPID
r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RXFD[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
NPTXFD/TX0FD[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
NPTXFSA/TX0FSA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
Host mode
Device mode
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
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
NPTXFSAV[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
PWR
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. VBDEN Res. Res. Res. Res.
DWN
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PRODUCT_ID[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
PRODUCT_ID[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
EN SND L1RSM
Res. Res. Res. LPMRCNTSTS[2:0] LPMRCNT[2:0] LPMCHIDX[3:0]
BESL LPM OK
rw r r r rs rw rw rw rw rw rw rw r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SLP L1DS L1SS REM LPM LPM
LPMRSP[1:0] BESLTHRS[3:0] BESL[3:0]
STS EN EN WAKE ACK EN
r r r rw rw rw rw rw rw rw/r rw/r rw/r rw/r rw/r rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PTXFSIZ[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
PTXSA[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
INEPTXFD[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
INEPTXSA[15:0]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. FSLSS FSLSPCS[1:0]
r rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RLD
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
CTRL
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FRIVL[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
FTREM[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
FRNUM[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
PTXQTOP[7:0] PTXQSAV[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
PTXFSAVL[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HAINT[15:0]
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HAINTM[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
PTCTL
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. PSPD[1:0]
[3]
r r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
POC PEN
PTCTL[2:0] PPWR PLSTS[1:0] Res. PRST PSUSP PRES POCA PENA PCDET PCSTS
CHNG CHNG
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ODD
CHENA CHDIS DAD[6:0] MCNT[1:0] EPTYP[1:0] LSDEV Res.
FRM
rs rs 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
SPLIT COMP
Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res. Res.
EN LSPLT
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