HT32F52342-52 UserManualv130 PDF
HT32F52342-52 UserManualv130 PDF
HT32F52342-52 UserManualv130 PDF
HT32F52342/HT32F52352
User Manual
Table of Contents
1 Introduction............................................................................................................ 26
Overview............................................................................................................................... 26
Features................................................................................................................................ 27
Device Information................................................................................................................ 32
Table of Contents
Block Diagram...................................................................................................................... 33
2 Document Conventions........................................................................................ 34
3 System Architecture.............................................................................................. 35
Arm® Cortex®-M0+ Processor............................................................................................... 35
Bus Architecture.................................................................................................................... 36
Memory Organization........................................................................................................... 37
Memory Map.................................................................................................................................... 38
Embedded Flash Memory................................................................................................................ 41
Embedded SRAM Memory.............................................................................................................. 41
AHB Peripherals.............................................................................................................................. 41
APB Peripherals.............................................................................................................................. 41
Table of Contents
5 Power Control Unit (PWRCU)............................................................................... 68
Introduction........................................................................................................................... 68
Features................................................................................................................................ 69
Functional Descriptions........................................................................................................ 69
Backup Domain............................................................................................................................... 69
VDD Power Domain........................................................................................................................... 70
1.5 V Power Domain........................................................................................................................ 72
Operation Modes............................................................................................................................. 72
Register Map........................................................................................................................ 74
Register Descriptions............................................................................................................ 75
Backup Domain Status Register – BAKSR...................................................................................... 75
Backup Domain Control Register – BAKCR.................................................................................... 76
Backup Domain Test Register – BAKTEST..................................................................................... 78
Low Voltage / Brown Out Detect Control and Status Register – LVDCSR...................................... 79
Backup Register n – BAKREGn, n = 0 ~ 9...................................................................................... 81
Table of Contents
APB Peripheral Clock Selection Register 0 – APBPCSR0............................................................ 109
APB Peripheral Clock Selection Register 1 – APBPCSR1.............................................................111
HSI Control Register – HSICR........................................................................................................113
HSI Auto Trimming Counter Register – HSIATCR..........................................................................114
Low Power Control Register – LPCR.............................................................................................115
MCU Debug Control Register – MCUDBGCR................................................................................116
Table of Contents
Port B Open Drain Selection Register – PBODR.......................................................................... 146
Port B Output Current Drive Selection Register – PBDRVR......................................................... 147
Port B Lock Register – PBLOCKR................................................................................................. 148
Port B Data Input Register – PBDINR........................................................................................... 149
Port B Output Data Register – PBDOUTR.................................................................................... 150
Port B Output Set/Reset Control Register – PBSRR..................................................................... 151
Port B Output Reset Register – PBRR.......................................................................................... 152
Port C Data Direction Control Register – PCDIRCR..................................................................... 153
Port C Input Function Enable Control Register – PCINER............................................................ 154
Port C Pull-Up Selection Register – PCPUR................................................................................. 155
Port C Pull-Down Selection Register – PCPDR............................................................................ 156
Port C Open Drain Selection Register – PCODR.......................................................................... 157
Port C Output Current Drive Selection Register – PCDRVR......................................................... 158
Port C Lock Register – PCLOCKR................................................................................................ 159
Port C Data Input Register – PCDINR........................................................................................... 160
Port C Output Data Register – PCDOUTR.................................................................................... 161
Port C Output Set/Reset Control Register – PCSRR.................................................................... 162
Port C Output Reset Register – PCRR.......................................................................................... 163
Port D Data Direction Control Register – PDDIRCR..................................................................... 164
Port D Input Function Enable Control Register – PDINER............................................................ 165
Port D Pull-Up Selection Register – PDPUR................................................................................. 166
Port D Pull-Down Selection Register – PDPDR............................................................................ 167
Port D Open Drain Selection Register – PDODR.......................................................................... 168
Port D Output Current Drive Selection Register – PDDRVR......................................................... 169
Port D Lock Register – PDLOCKR................................................................................................ 170
Port D Data Input Register – PDDINR........................................................................................... 171
Port D Output Data Register – PDDOUTR.................................................................................... 172
Port D Output Set/Reset Control Register – PDSRR.................................................................... 173
Port D Output Reset Register – PDRR.......................................................................................... 174
Table of Contents
Introduction......................................................................................................................... 182
Features.............................................................................................................................. 183
Function Descriptions......................................................................................................... 184
SysTick Calibration........................................................................................................................ 184
Register Map...................................................................................................................... 184
Table of Contents
ADC Trigger Control Register – ADCTCR..................................................................................... 212
ADC Trigger Source Register – ADCTSR...................................................................................... 213
ADC Watchdog Control Register – ADCWCR............................................................................... 214
ADC Watchdog Threshold Register – ADCTR............................................................................... 215
ADC Interrupt Enable Register – ADCIER..................................................................................... 216
ADC Interrupt Raw Status Register – ADCIRAW.......................................................................... 217
ADC Interrupt Status Register – ADCISR...................................................................................... 218
ADC Interrupt Clear Register – ADCICLR..................................................................................... 219
ADC DMA Request Register – ADCDMAR.................................................................................... 220
Table of Contents
PDMA Request.............................................................................................................................. 259
Register Map...................................................................................................................... 260
Register Descriptions.......................................................................................................... 261
Timer Counter Configuration Register – CNTCFR........................................................................ 261
Timer Mode Configuration Register – MDCFR.............................................................................. 263
Timer Trigger Configuration Register – TRCFR............................................................................. 266
Timer Counter Register – CTR...................................................................................................... 267
Channel 0 Input Configuration Register – CH0ICFR..................................................................... 268
Channel 1 Input Configuration Register – CH1ICFR..................................................................... 270
Channel 2 Input Configuration Register – CH2ICFR..................................................................... 272
Channel 3 Input Configuration Register – CH3ICFR..................................................................... 274
Channel 0 Output Configuration Register – CH0OCFR................................................................ 276
Channel 1 Output Configuration Register – CH1OCFR................................................................ 278
Channel 2 Output Configuration Register – CH2OCFR................................................................ 280
Channel 3 Output Configuration Register – CH3OCFR................................................................ 282
Channel Control Register – CHCTR.............................................................................................. 284
Channel Polarity Configuration Register – CHPOLR..................................................................... 285
Timer PDMA/Interrupt Control Register – DICTR.......................................................................... 286
Timer Event Generator Register – EVGR...................................................................................... 288
Timer Interrupt Status Register – INTSR....................................................................................... 290
Timer Counter Register – CNTR................................................................................................... 293
Timer Prescaler Register – PSCR................................................................................................. 294
Timer Counter Reload Register – CRR......................................................................................... 295
Channel 0 Capture/Compare Register – CH0CCR....................................................................... 296
Channel 1 Capture/Compare Register – CH1CCR....................................................................... 297
Channel 2 Capture/Compare Register – CH2CCR....................................................................... 298
Channel 3 Capture/Compare Register – CH3CCR....................................................................... 299
Channel 0 Asymmetric Compare Register – CH0ACR.................................................................. 300
Channel 1 Asymmetric Compare Register – CH1ACR.................................................................. 301
Channel 2 Asymmetric Compare Register – CH2ACR.................................................................. 302
Channel 3 Asymmetric Compare Register – CH3ACR.................................................................. 303
Table of Contents
16 Motor Control Timer (MCTM)............................................................................ 311
Introduction......................................................................................................................... 311
Features.............................................................................................................................. 312
Functional Descriptions...................................................................................................... 313
Counter Mode................................................................................................................................ 313
Clock Controller............................................................................................................................. 317
Trigger Controller........................................................................................................................... 318
Slave Controller............................................................................................................................. 319
Master Controller........................................................................................................................... 321
Channel Controller......................................................................................................................... 322
Input Stage.................................................................................................................................... 325
Output Stage.................................................................................................................................. 327
Update Management..................................................................................................................... 337
Single Pulse Mode......................................................................................................................... 339
Asymmetric PWM Mode................................................................................................................ 341
Timer Interconnection.................................................................................................................... 342
Trigger ADC Start.......................................................................................................................... 346
Lock Level Table............................................................................................................................ 346
PDMA Request.............................................................................................................................. 347
Register Map...................................................................................................................... 348
Register Descriptions.......................................................................................................... 349
Timer Counter Configuration Register – CNTCFR........................................................................ 349
Timer Mode Configuration Register – MDCFR.............................................................................. 351
Timer Trigger Configuration Register – TRCFR............................................................................. 354
Timer Counter Register – CTR...................................................................................................... 355
Channel 0 Input Configuration Register – CH0ICFR..................................................................... 356
Channel 1 Input Configuration Register – CH1ICFR..................................................................... 358
Channel 2 Input Configuration Register – CH2ICFR..................................................................... 360
Channel 3 Input Configuration Register – CH3ICFR..................................................................... 362
Channel 0 Output Configuration Register – CH0OCFR................................................................ 364
Channel 1 Output Configuration Register – CH1OCFR................................................................ 366
Channel 2 Output Configuration Register – CH2OCFR................................................................ 368
Channel 3 Output Configuration Register – CH3OCFR................................................................ 370
Channel Control Register – CHCTR.............................................................................................. 372
Channel Polarity Configuration Register – CHPOLR..................................................................... 374
Channel Break Configuration Register – CHBRKCFR.................................................................. 376
Channel Break Control Register – CHBRKCTR............................................................................ 377
Table of Contents
Channel 0 Capture/Compare Register – CH0CCR....................................................................... 390
Channel 1 Capture/Compare Register – CH1CCR....................................................................... 391
Channel 2 Capture/Compare Register – CH2CCR....................................................................... 392
Channel 3 Capture/Compare Register – CH3CCR....................................................................... 393
Channel 0 Asymmetric Compare Register – CH0ACR.................................................................. 394
Channel 1 Asymmetric Compare Register – CH1ACR.................................................................. 395
Channel 2 Asymmetric Compare Register – CH2ACR.................................................................. 396
Channel 3 Asymmetric Compare Register – CH3ACR.................................................................. 397
Table of Contents
Low Speed Clock Configuration.................................................................................................... 428
RTC Counter Operation................................................................................................................. 429
Interrupt and Wakeup Control........................................................................................................ 429
RTCOUT Output Pin Configuration............................................................................................... 430
Register Map...................................................................................................................... 431
Register Descriptions.......................................................................................................... 431
RTC Counter Register – RTCCNT................................................................................................. 431
RTC Compare Register – RTCCMP.............................................................................................. 432
RTC Control Register – RTCCR.................................................................................................... 433
RTC Status Register – RTCSR..................................................................................................... 435
RTC Interrupt and Wakeup Enable Register – RTCIWEN............................................................. 436
Table of Contents
Register Map...................................................................................................................... 461
Register Descriptions.......................................................................................................... 462
I2C Control Register – I2CCR........................................................................................................ 462
I2C Interrupt Enable Register – I2CIER......................................................................................... 464
I2C Address Register – I2CADDR.................................................................................................. 466
I2C Status Register – I2CSR.......................................................................................................... 467
I2C SCL High Period Generation Register – I2CSHPGR............................................................... 470
I2C SCL Low Period Generation Register – I2CSLPGR................................................................ 471
I2C Data Register – I2CDR............................................................................................................ 472
I2C Target Register – I2CTAR........................................................................................................ 473
I2C Address Mask Register – I2CADDMR..................................................................................... 474
I2C Address Snoop Register – I2CADDSR.................................................................................... 475
I2C Timeout Register – I2CTOUT.................................................................................................. 476
Table of Contents
Interrupts and Status......................................................................................................................511
PDMA Interface...............................................................................................................................511
Register Map...................................................................................................................... 511
Register Descriptions.......................................................................................................... 512
USART Data Register – USRDR................................................................................................... 512
USART Control Register – USRCR............................................................................................... 513
USART FIFO Control Register – USRFCR................................................................................... 515
USART Interrupt Enable Register – USRIER................................................................................ 516
USART Status & Interrupt Flag Register – USRSIFR................................................................... 518
USART Timing Parameter Register – USRTPR............................................................................ 520
USART IrDA Control Register – IrDACR....................................................................................... 521
USART RS485 Control Register – RS485CR............................................................................... 522
USART Synchronous Control Register – SYNCR......................................................................... 523
USART Divider Latch Register – USRDLR................................................................................... 524
USART Test Register – USRTSTR................................................................................................ 525
Table of Contents
PDMA Interface.............................................................................................................................. 547
Register Map...................................................................................................................... 547
Register Descriptions.......................................................................................................... 548
SCI Control Register – CR............................................................................................................. 548
SCI Status Register – SR.............................................................................................................. 550
SCI Contact Control Register – CCR............................................................................................. 552
SCI Elementary Time Unit Register – ETUR................................................................................. 553
SCI Guard Time Register – GTR................................................................................................... 554
SCI Waiting Time Register – WTR................................................................................................ 555
SCI Interrupt Enable Register – IER.............................................................................................. 556
SCI Interrupt Pending Register – IPR............................................................................................ 558
SCI Transmit Buffer – TXB............................................................................................................ 560
SCI Receive Buffer – RXB............................................................................................................. 560
SCI Prescaler Register – PSCR.................................................................................................... 561
Table of Contents
USB Endpoint 4 ~ 7 Interrupt Status Register – USBEPnISR, n = 4 ~ 7....................................... 590
USB Endpoint 4 ~ 7 Transfer Count Register – USBEPnTCR, n = 4 ~ 7...................................... 591
USB Endpoint 4 ~ 7 Configuration Register – USBEPnCFGR, n = 4 ~ 7...................................... 592
Table of Contents
EBI Status Register – EBISR......................................................................................................... 622
EBI Address Timing Register – EBIATR........................................................................................ 623
EBI Read Timing Register – EBIRTR............................................................................................ 624
EBI Write Timing Register – EBIWTR............................................................................................ 625
EBI Parity Register – EBIPR.......................................................................................................... 626
Table of Contents
List of Tables
Table 1. Series Features and Peripheral List........................................................................................... 32
Table 2. Document Conventions.............................................................................................................. 34
Table 3. Register Map.............................................................................................................................. 39
Table 4. Flash Memory and Option Byte.................................................................................................. 44
Table 5. Relationship Between Wait State Cycle and HCLK................................................................... 44
List of Tables
Table 6. Booting Modes........................................................................................................................... 45
Table 7. Option Byte Memory Map.......................................................................................................... 49
Table 8. Access Permission of Protected Main Flash Page..................................................................... 50
Table 9. Access Permission When Security Protection is Enabled.......................................................... 51
Table 10. FMC Register Map................................................................................................................... 52
Table 11. Operation Mode Definitions...................................................................................................... 72
Table 12. Enter/Exit Power Saving Modes............................................................................................... 73
Table 13. Power Status After System Reset............................................................................................ 74
Table 14. PWRCU Register Map............................................................................................................. 74
Table 15. Output Divider2 Value Mapping............................................................................................... 88
Table 16. Feedback Divider2 Value Mapping.......................................................................................... 88
Table 17. CKOUT Clock Source.............................................................................................................. 91
Table 18. CKCU Register Map ................................................................................................................ 92
Table 19. RSTCU Register Map............................................................................................................ 121
Table 20. AFIO, GPIO and IO Pad Control Signal True Table............................................................... 129
Table 21. GPIO Register Map................................................................................................................ 130
Table 22. AFIO Selection for Peripheral Map Example.......................................................................... 177
Table 23. AFIO Register Map................................................................................................................. 177
Table 24. Exception Types..................................................................................................................... 182
Table 25. NVIC Register Map................................................................................................................ 184
Table 26. EXTI Register Map................................................................................................................. 188
Table 27. Data format in ADCDR [15:0]................................................................................................. 203
Table 28. A/D Converter Register Map.................................................................................................. 205
Table 29. CMP Register Map................................................................................................................. 224
Table 30. Counting Direction and Encoding Signals.............................................................................. 247
Table 31. Compare Match Output Setup............................................................................................... 248
Table 32. GPTM Register Map.............................................................................................................. 260
Table 33. GPTM Internal Trigger Connection........................................................................................ 266
Table 34. BFTM Register Map............................................................................................................... 307
Table 35. Compare Match Output Setup............................................................................................... 328
Table 36. Output Control Bits for Complementary Output with a Break Event Occurrence................... 336
Table 37. Lock Level Table.................................................................................................................... 346
Table 38. MCTM Register Map.............................................................................................................. 348
Table 39. MCTM Internal Trigger Connection........................................................................................ 354
List of Tables
Table 46. Conditions of Holding SCL line............................................................................................... 459
Table 47. I2C Register Map.................................................................................................................... 461
Table 48. I2C Clock Setting Example..................................................................................................... 471
Table 49. SPI Interface Format Setup.................................................................................................... 479
Table 50. SPI Mode Fault Trigger Conditions........................................................................................ 484
Table 51. SPI Master Mode SEL Pin Status.......................................................................................... 484
Table 52. SPI Register Map................................................................................................................... 486
Table 53. Baud Rate Deviation Error Calculation – CK_USART = 40 MHz........................................... 501
Table 54. Baud Rate Deviation Error Calculation – CK_USART = 48 MHz........................................... 502
Table 55. USART Register Map..............................................................................................................511
Table 56. Baud Rate Deviation Error Calculation – CK_UART = 40 MHz............................................. 528
Table 57. Baud Rate Deviation Error Calculation – CK_UART = 48 MHz............................................. 529
Table 58. UART Register Map............................................................................................................... 530
Table 59. DI Field Based Di Encoded Decimal Values.......................................................................... 540
Table 60. FI Field Based Fi Encoded Decimal Values........................................................................... 540
Table 61. Possible ETU Values Obtained with the Fi/Di Ratio............................................................... 540
Table 62. SCI Register Map .................................................................................................................. 547
Table 63. Endpoint Characteristics........................................................................................................ 563
Table 64. USB Data Types and Buffer Size........................................................................................... 563
Table 65. USB Register Map................................................................................................................. 566
Table 66. Resume Event Detection....................................................................................................... 569
Table 67. PDMA Channel Assignments................................................................................................. 595
Table 68. PDMA Address Modes........................................................................................................... 597
Table 69. PDMA Register Map............................................................................................................... 598
Table 70. EBI Maps AHB Transactions Width to External Device Transactions.................................... 618
Table 71. EBI Maps AHB Transactions Width to External Device Transactions Width.......................... 618
Table 72. EBI Register Map................................................................................................................... 620
Table 73. Recommend FS List @ 8 MHz PCLK.................................................................................... 630
Table 74. Recommend FS List @ 48 MHz PCLK.................................................................................. 630
Table 75. I2S Register Map ................................................................................................................... 639
Table 76. CRC Register Map................................................................................................................. 651
List of Figures
Figure 1. Block Diagram.......................................................................................................................... 33
Figure 2. Cortex®-M0+ Block Diagram..................................................................................................... 36
Figure 3. Bus Architecture....................................................................................................................... 37
Figure 4. Memory Map............................................................................................................................. 38
Figure 5. Flash Memory Controller Block Diagram.................................................................................. 42
List of Figures
Figure 6. Flash Memory Map................................................................................................................... 43
Figure 7. Vector Remapping.................................................................................................................... 45
Figure 8. Page Erase Operation Flowchart............................................................................................. 46
Figure 9. Mass Erase Operation Flowchart............................................................................................. 47
Figure 10. Word Programming Operation Flowchart............................................................................... 48
Figure 11. PWRCU Block Diagram.......................................................................................................... 68
Figure 12. Power On Reset / Power Down Reset Waveform.................................................................. 71
Figure 13. CKCU Block Diagram............................................................................................................. 83
Figure 14. External Crystal, Ceramic, and Resonators for HSE.............................................................. 84
Figure 15. HSI Auto Trimming Block Diagram ........................................................................................ 86
Figure 16. PLL Block Diagram................................................................................................................. 87
Figure 17. External Crystal, Ceramic, and Resonators for LSE ............................................................. 89
Figure 18. RSTCU Block Diagram..........................................................................................................119
Figure 19. Power On Reset Sequence.................................................................................................. 120
Figure 20. GPIO Block Diagram............................................................................................................ 127
Figure 21. AFIO/GPIO Control Signal.................................................................................................... 129
Figure 22. AFIO Block Diagram............................................................................................................. 175
Figure 23. EXTI Channel Input Selection.............................................................................................. 176
Figure 24. EXTI Block Diagram............................................................................................................. 185
Figure 25. EXTI Wake-up Event Management...................................................................................... 186
Figure 26. EXTI Interrupt Debounce Function....................................................................................... 187
Figure 27. ADC Block Diagram.............................................................................................................. 197
Figure 28. One Shot Conversion Mode................................................................................................. 200
Figure 29. Continuous Conversion Mode.............................................................................................. 200
Figure 30. Discontinuous Conversion Mode.......................................................................................... 202
Figure 31. Comparator Block Diagram.................................................................................................. 221
Figure 32. 6-Bit Scaler for Comparator Voltage Reference Block Diagram........................................... 222
Figure 33. Interrupt Signals of Comparators.......................................................................................... 223
Figure 34. Wakeup Signals of Comparators.......................................................................................... 223
Figure 35. GPTM Block Diagram........................................................................................................... 230
Figure 36. Up-counting Example........................................................................................................... 232
Figure 37. Down-counting Example....................................................................................................... 233
Figure 38. Center-aligned Counting Example........................................................................................ 234
Figure 39. GPTM Clock Selection Source............................................................................................. 235
List of Figures
Figure 46. MTO Selection...................................................................................................................... 240
Figure 47. Capture/Compare Block Diagram......................................................................................... 241
Figure 48. Input Capture Mode.............................................................................................................. 242
Figure 49. PWM Pulse Width Measurement Example........................................................................... 243
Figure 50. Channel 0 and Channel 1 Input Stages................................................................................ 244
Figure 51. Channel 2 and Channel 3 Input Stages................................................................................ 245
Figure 52. TI0 Digital Filter Diagram with N = 2..................................................................................... 245
Figure 53. Input Stage and Quadrature Decoder Block Diagram.......................................................... 246
Figure 54. Both TI0 and TI1 Quadrature Decoder Counting.................................................................. 247
Figure 55. Output Stage Block Diagram................................................................................................ 248
Figure 56. Toggle Mode Channel Output Reference Signal (CHxPRE = 0).......................................... 249
Figure 57. Toggle Mode Channel Output Reference Signal (CHxPRE = 1).......................................... 249
Figure 58. PWM Mode Channel Output Reference Signal and Counter in Up-counting Mode............. 250
Figure 59. PWM Mode Channel Output Reference Signal and Counter in Down-counting Mode........ 250
Figure 60. PWM Mode Channel Output Reference Signal and Counter in Centre-align Mode............. 251
Figure 61. Update Event Setting Diagram............................................................................................. 252
Figure 62. Single Pulse Mode................................................................................................................ 253
Figure 63. Immediate Active Mode Minimum Delay.............................................................................. 254
Figure 64. Asymmetric PWM mode versus center align counting mode............................................... 255
Figure 65. Pausing GPTM1 using the GPTM0 CH0OREF Signal......................................................... 256
Figure 66. Triggering GPTM1 with GPTM0 Update Event..................................................................... 257
Figure 67. Trigger GPTM0 and GPTM1 with the GPTM0 CH0 Input..................................................... 258
Figure 68. GPTM PDMA Mapping Diagram........................................................................................... 259
Figure 69. BFTM Block Diagram........................................................................................................... 304
Figure 70. BFTM – Repetitive Mode...................................................................................................... 305
Figure 71. BFTM – One Shot Mode....................................................................................................... 306
Figure 72. BFTM – One Shot Mode Counter Updating ........................................................................ 306
Figure 73. MCTM Block Diagram...........................................................................................................311
Figure 74. Up-counting Example........................................................................................................... 313
Figure 75. Down-counting Example....................................................................................................... 314
Figure 76. Center-aligned Counting Example........................................................................................ 315
Figure 77. Update Event 1 Dependent Repetition Mechanism Example............................................... 316
Figure 78. MCTM Clock Selection Source............................................................................................. 317
Figure 79. Trigger Controller Block........................................................................................................ 318
Figure 80. Slave Controller Diagram..................................................................................................... 319
List of Figures
Figure 87. Input Capture Mode.............................................................................................................. 323
Figure 88. PWM Pulse Width Measurement Example........................................................................... 324
Figure 89. Channel 0 and Channel 1 Input Stages................................................................................ 325
Figure 90. Channel 2 and Channel 3 Input Stages................................................................................ 325
Figure 91. TI0 Digital Filter Diagram with N = 2..................................................................................... 326
Figure 92. Output Stage Block Diagram................................................................................................ 327
Figure 93. Toggle Mode Channel Output Reference Signal – CHxPRE = 0.......................................... 328
Figure 94. Toggle Mode Channel Output Reference Signal – CHxPRE = 1.......................................... 329
Figure 95. PWM Mode Channel Output Reference Signal and Counter in Up-counting Mode............. 329
Figure 96. PWM Mode Channel Output Reference Signal and Counter in Down-counting Mode........ 330
Figure 97. PWM Mode 1 Channel Output Reference Signal and Counter in Centre-aligned Counting
Mode....................................................................................................................................................... 330
Figure 98. Dead-time Insertion Performed for Complementary Outputs............................................... 331
Figure 99. MCTM Break Signal Bolck Diagram..................................................................................... 332
Figure 100. MT_BRK Pin Digital Filter Diagram with N = 2................................................................... 332
Figure 101. Channel 3 Output with a Break Event Occurrence............................................................. 333
Figure 102. Channel 0 ~ 2 Complementary Outputs with a Break Event Occurrence.......................... 334
Figure 103. Channel 0 ~ 2 Only One Output Enabled when Fault Event Occurs.................................. 334
Figure 104. Hardware Protection When Both CHxO and CHxNO Are in Active Condition.................... 335
Figure 105. Update Event 1 Setup Diagram.......................................................................................... 337
Figure 106. CHxE, CHxNE and CHxOM Updated by Update Event 2.................................................. 338
Figure 107. Update Event 2 Setup Diagram.......................................................................................... 338
Figure 108. Single Pulse Mode.............................................................................................................. 339
Figure 109. Immediate Active Mode Minimum Delay............................................................................ 340
Figure 110. Asymmetric PWM Mode versus Center-aligned Counting Mode........................................ 341
Figure 111. Pausing GPTM using the MCTM CH0OREF Signal........................................................... 342
Figure 112. Triggering GPTM with MCTM Update Event 1................................................................... 343
Figure 113. Trigger MCTM and GPTM with the MCTM CH0 Input........................................................ 344
Figure 114. CH1XOR Input as Hall Sensor Interface............................................................................ 345
Figure 115. MCTM PDMA Mapping Diagram........................................................................................ 347
Figure 116. SCTM Block Diagram......................................................................................................... 398
Figure 117. Up-counting Example......................................................................................................... 399
Figure 118. SCTM Clock Selection Source........................................................................................... 400
Figure 119. Trigger Controller Block...................................................................................................... 401
Figure 120. Slave Controller Diagram................................................................................................... 402
List of Figures
Figure 127. TI Digital Filter Diagram with N = 2..................................................................................... 406
Figure 128. Output Stage Block Diagram.............................................................................................. 407
Figure 129. Toggle Mode Channel Output Reference Signal (CHPRE = 0).......................................... 408
Figure 130. Toggle Mode Channel Output Reference Signal (CHPRE = 1).......................................... 408
Figure 131. PWM Mode Channel Output Reference Signal.................................................................. 409
Figure 132. Update Event Setting Diagram........................................................................................... 410
Figure 133. RTC Block Diagram............................................................................................................ 427
Figure 134. Watchdog Timer Block Diagram ........................................................................................ 437
Figure 135. Watchdog Timer Behavior.................................................................................................. 439
Figure 136. I2C Module Block Diagram.................................................................................................. 446
Figure 137. START and STOP Condition.............................................................................................. 448
Figure 138. Data Validity........................................................................................................................ 448
Figure 139. 7-bit Addressing Mode........................................................................................................ 449
Figure 140. 10-bit Addressing Write Transmit Mode ............................................................................. 450
Figure 141. 10-bit Addressing Read Receive Mode ............................................................................. 450
Figure 142. I2C Bus Acknowledge......................................................................................................... 451
Figure 143. Clock Synchronization during Arbitration............................................................................ 452
Figure 144. Two Master Arbitration Procedure...................................................................................... 452
Figure 145. Master Transmitter Timing Diagram................................................................................... 454
Figure 146. Master Receiver Timing Diagram....................................................................................... 456
Figure 147. Slave Transmitter Timing Diagram..................................................................................... 457
Figure 148. Slave Receiver Timing Diagram......................................................................................... 458
Figure 149. SCL Timing Diagram........................................................................................................... 471
Figure 150. SPI Block Diagram............................................................................................................. 477
Figure 151. SPI Single Byte Transfer Timing Diagram – CPOL = 0, CPHA = 0..................................... 479
Figure 152. SPI Continuous Data Transfer Timing Diagram – CPOL = 0, CPHA = 0............................ 480
Figure 153. SPI Single Byte Transfer Timing Diagram – CPOL = 0, CPHA = 1..................................... 480
Figure 154. SPI Continuous Transfer Timing Diagram – CPOL = 0, CPHA = 1..................................... 481
Figure 155. SPI Single Byte Transfer Timing Diagram – CPOL = 1, CPHA = 0..................................... 481
Figure 156. SPI Continuous Transfer Timing Diagram – CPOL = 1, CPHA = 0..................................... 482
Figure 157. SPI Single Byte Transfer Timing Diagram – CPOL = 1, CPHA = 1..................................... 482
Figure 158. SPI Continuous Transfer Timing Diagram – CPOL = 1, CPHA = 1..................................... 482
Figure 159. SPI Multi-Master Slave Environment.................................................................................. 484
Figure 160. USART Block Diagram....................................................................................................... 498
Figure 161. USART Serial Data Format................................................................................................ 500
Figure 162. USART Clock CK_USART and Data Frame Timing........................................................... 501
Figure 163. Hardware Flow Control between 2 USARTs....................................................................... 502
Figure 164. USART RTS Flow Control.................................................................................................. 503
Figure 165. USART CTS Flow Control.................................................................................................. 503
Figure 166. IrDA Modulation and Demodulation.................................................................................... 504
Figure 167. USART I/O and IrDA Block Diagram.................................................................................. 506
List of Figures
Figure 168. RS485 Interface and Waveform......................................................................................... 507
Figure 169. USART Synchronous Transmission Example.................................................................... 509
Figure 170. 8-bit Format USART Synchronous Waveform.................................................................... 510
Figure 171. UART Block Diagram.......................................................................................................... 526
Figure 172. UART Serial Data Format................................................................................................... 527
Figure 173. UART Clock CK_UART and Data Frame Timing................................................................ 528
Figure 174. SCI Block Diagram............................................................................................................. 538
Figure 175. Character Frame and Compensation Mode....................................................................... 541
Figure 176. Guard Time Duration.......................................................................................................... 542
Figure 177. Character and Block Waiting Time Duration – CWT and BWT........................................... 543
Figure 178. SCI Card Detection Diagram.............................................................................................. 544
Figure 179. SCI Interrupt Structure........................................................................................................ 546
Figure 180. USB Block Diagram............................................................................................................ 562
Figure 181. Endpoint Buffer Allocation Example................................................................................... 564
Figure 182. Double-buffering Operation Example................................................................................. 565
Figure 183. PDMA Block Diagram......................................................................................................... 593
Figure 184. PDMA Request Mapping Architecture................................................................................ 595
Figure 185. PDMA Channel Arbitration and Scheduling Example......................................................... 596
Figure 186. EBI Block Diagram..............................................................................................................611
Figure 187. EBI Non-multiplexed 8-bit Data, 8-bit Address Read Operation......................................... 612
Figure 188. EBI Non-multiplexed 8-bit Data, 8-bit Address Write Operation......................................... 612
Figure 189. EBI Non-multiplexed 16-bit Data, N-bit Address Read Operation...................................... 613
Figure 190. EBI Non-multiplexed 16-bit Data, N-bit Address Write Operation...................................... 613
Figure 191. An EBI Address Latch Setup Diagram................................................................................ 614
Figure 192. EBI Multiplexed 16-bit Data, 16-bit Address Read Operation............................................. 614
Figure 193. EBI Multiplexed 16-bit Data, 16-bit Address Write Operation............................................. 615
Figure 194. EBI Multiplexed 8-bit Data, 20-bit Address Read Operation............................................... 615
Figure 195. EBI Multiplexed 8-bit Data, 20-bit Address Write Operation............................................... 616
Figure 196. EBI Inserts an IDLE Cycle between Transactions in the Same Bank (NOIDLE = 0).......... 617
Figure 197. EBI De-asserts an IDLE Cycle between Transactions in the Same Bank (NOIDLE = 1)... 617
Figure 198. EBI Bank Memory Map....................................................................................................... 619
Figure 199. I2S Block Diagram............................................................................................................... 627
Figure 200. Simple I2S Master/Slave Configuration............................................................................... 628
Figure 201. I2S Clock Generator Diagram............................................................................................. 629
Figure 202. I2S-justified Stereo Mode Waveforms................................................................................. 631
Figure 203. I2S-justified Stereo Mode Waveforms (32-bit Channel Enabled)........................................ 631
Figure 204. Left-justified Stereo Mode Waveforms................................................................................ 632
Figure 205. Left-justified Stereo Mode Waveforms (32-bit Channel Enabled)....................................... 632
Figure 206. Right-justified Stereo Mode Waveforms............................................................................. 633
Figure 207. Right-justified Stereo Mode Waveforms (32-bit Channel Enabled).................................... 633
Figure 208. I2S-justified Mono Mode Waveforms................................................................................... 634
List of Figures
Figure 209. I2S-justified Mono Mode Waveforms (32-bit Channel Enabled).......................................... 634
Figure 210. Left-justified Mono Mode Waveforms................................................................................. 635
Figure 211. Left-justified Mono Mode Waveforms (32-bit Channel Enabled)........................................ 635
Figure 212. Right-justified Mono Mode Waveforms............................................................................... 636
Figure 213. Right-justified Mono Mode Waveforms (32-bit Channel Enabled)...................................... 636
Figure 214. I2S-justified Repeat Mode Waveforms................................................................................ 637
Figure 215. I2S-justified Repeat Mode Waveforms (32-bit Channel Enabled)....................................... 637
Figure 216. FIFO Data Content Arrangement for Various Modes.......................................................... 638
Figure 217. CRC Block Diagram........................................................................................................... 649
Figure 218. CRC Data Bit and Byte Reversal Example......................................................................... 651
1 Introduction
Overview
This user manual provides detailed information including how to use the devices, system and
bus architecture, memory organization and peripheral instructions. The target audiences for this
document are software developers, application developers and hardware developers. For more
Introduction
information regarding pin assignment, package and electrical characteristics, please refer to the
datasheet.
The devices are high performance and low power consumption 32-bit microcontrollers based
around an Arm® Cortex®-M0+ processor core. The Cortex®-M0+ is a next-generation processor
core which is tightly coupled with Nested Vectored Interrupt Controller (NVIC), SysTick timer,
and including advanced debug support.
The devices operate at a frequency of up to 48 MHz with a Flash accelerator to obtain maximum
efficiency. It provides up to 128 KB of embedded Flash memory for code/data storage and 16 KB
of embedded SRAM memory for system operation and application program usage. A variety of
peripherals, such as ADC, I2C, USART, UART, SPI, I2S, GPTM, MCTM, SCI, CRC-16/32, RTC,
WDT, PDMA, EBI, USB2.0 FS, SW-DP (Serial Wire Debug Port), etc., are also implemented in
the device series. Several power saving modes provide the flexibility for maximum optimization
between wakeup latency and power consumption, an especially important consideration in low
power applications.
The above features ensure that the devices are suitable for use in a wide range of applications,
especially in areas such as white goods application control, power monitors, alarm systems,
consumer products, handheld equipment, data logging applications, motor control and so on.
Features
▄▄ Core
●● 32-bit Arm® Cortex®-M0+ processor core
●● Up to 48 MHz operating frequency
●● 0.93 DMIPS/MHz (Dhrystone v2.1)
●● Single-cycle multiplication
●● Integrated Nested Vectored Interrupt Controller (NVIC)
Introduction
●● 24-bit SysTick timer
▄▄ On-chip Memory
●● Up to 128 KB on-chip Flash memory for instruction/data and options storage
●● 16 KB on-chip SRAM
●● Supports multiple boot modes
▄▄ Flash Memory Controller – FMC
●● Flash accelerator for maximum efficiency
●● 32-bit word programming with In System Programming Interface (ISP) and In Application
Programming (IAP)
●● Flash protection capability to prevent illegal access
▄▄ Reset Control Unit – RSTCU
●● Supply supervisor: Power On Reset / Power Down Reset (POR/PDR) and Programmable Low
Voltage Detector (LVD)
▄▄ Clock Control Unit – CKCU
●● External 4 to 16 MHz crystal oscillator
●● External 32,768 Hz crystal oscillator
●● Internal 8MHz RC oscillator trimmed to ±2 % accuracy at 3.3 V operating voltage and 25 ºC
operating temperature
●● Internal 32 kHz RC oscillator
●● Integrated system clock PLL
●● Independent clock divider and gating bits for peripheral clock sources
▄▄ Power management – PWRCU
●● Single VDD power supply: 2.0 V to 3.6 V
●● Integrated 1.5 V LDO regulator for CPU core, peripherals and memories power supply
●● VBAT battery power supply for RTC and backup registers
●● Three power domains: VDD, 1.5 V and Backup
●● Four power saving modes: Sleep, Deep-Sleep1, Deep-Sleep2, Power-Down
▄▄ External Interrupt/Event Controller – EXTI
●● Up to 16 EXTI lines with configurable trigger source and type
●● All GPIO pins can be selected as EXTI trigger source
●● Source trigger type includes high level, low level, negative edge, positive edge, or both edge
●● Individual interrupt enable, wakeup enable and status bits for each EXTI line
●● Software interrupt trigger mode for each EXTI line
●● Integrated deglitch filter for short pulse blocking
Introduction
●● Programmable hysteresis
●● Programming speed and consumption
●● Comparator output can be output to I/O or to timers or ADC trigger inputs
●● 6-bit scaler can be configurable to dedicated I/O for voltage reference.
●● Comparator has interrupt generation capability with wakeup from Sleep or Deep Sleep modes
through the EXTI controller.
▄▄ IO ports – GPIO
●● Up to 51 GPIOs
●● Port A, B, C, D are mapped as 16 external interrupts – EXTI
●● Almost I/O pins are configurable output driving current.
▄▄ Motor Control Timer – MCTM
●● One 16-bit up, down, up/down auto-reload counter
●● Up to 4 independent channels
●● 16-bit programmable prescaler allowing dividing the counter clock frequency by any factor
between 1 and 65536
●● Input Capture function
●● Compare Match Output
●● PWM waveform generation with Edge-aligned and Center-aligned Counting Modes
●● Single Pulse Mode Output
●● Complementary Outputs with programmable dead-time insertion
●● Supports 3-phase motor control and hall sensor interface
●● Break input to force the timer’s output signals into a reset or fixed condition
▄▄ PWM Generation and Capture Timer – GPTM
●● One 16-bit up, down, up/down auto-reload counter
●● Up to 4 independent channels for each timer
●● 16-bit programmable prescaler allowing dividing the counter clock frequency by any factor
between 1 and 65536
●● Input Capture function
●● Compare Match Output
●● PWM waveform generation with Edge-aligned and Center-aligned Counting Modes
●● Single Pulse Mode Output
●● Encoder interface controller with two inputs using quadrature decoder
Introduction
●● Single Pulse Mode Output
▄▄ Basic Function Timer – BFTM
●● One 32-bit compare/match count-up counter – no I/O control features
●● One shot mode – counting stops after a match condition
●● Repetitive mode – restart counter after a match condition
▄▄ Watchdog Timer
●● 12-bit down counter with 3-bit prescaler
●● Reset event for the system
●● Programmable watchdog timer window function
●● Registers write protection function
▄▄ Real Time Clock – RTC
●● 32-bit up-counter with a programmable prescaler
●● Alarm function
●● Interrupt and Wake-up event
▄▄ Inter-integrated Circuit – I2C
●● Supports both master and slave modes with a frequency of up to 1 MHz
●● Provide an arbitration function and clock synchronization
●● Supports 7-bit and 10-bit addressing modes and general call addressing
●● Supports slave multi-addressing mode with maskable address
▄▄ Serial Peripheral Interface – SPI
●● Supports both master and slave mode
●● Frequency of up to (fPCLK/2) MHz for master mode and (fPCLK/3) MHz for slave mode
●● FIFO Depth: 8 levels
●● Multi-master and multi-slave operation
▄▄ Universal Synchronous Asynchronous Receiver Transmitter – USART
●● Supports both asynchronous and clocked synchronous serial communication modes
●● Asynchronous operating baud rate up to (fPCLK/16) MHz and synchronous operating rate up to
(fPCLK/8) MHz
●● Capability of full duplex communication
●● Fully programmable characteristics of serial communication including: word length, parity bit,
stop bit and bit order
●● Error detection: Parity, overrun, and frame error
●● Support Auto hardware flow control mode – RTS, CTS
●● IrDA SIR encoder and decoder
●● RS485 mode with output enable control
●● FIFO Depth: 8 × 9 bits for both receiver and transmitter
Introduction
●● Character mode
●● Single transmit buffer and single receive buffer
●● 11-bit ETU (elementary time unit) counter
●● 9-bit guard time counter
●● 24-bit general purpose waiting time counter
●● Parity generation and checking
●● Automatic character retry on parity error detection in transmission and reception modes
▄▄ Inter-IC Sound – I2S
●● Master or slave mode
●● Mono and stereo
●● I2S-justified, Left-justified, and Right-justified mode
●● 8/16/24/32-bit sample size with 32-bit channel extended
●● 8 × 32-bit TX & RX FIFO with PDMA supported
●● 8-bit Fractional Clock Divider with rate control
▄▄ Cyclic Redundancy Check – CRC
●● Support CRC16 polynomial: 0x8005, X16+X15+X2+1
●● Support CCITT CRC16 polynomial: 0x1021, X16+X12+X5+1
●● Support IEEE-802.3 CRC32 polynomial: 0x04C11DB7, X32+X26+X23+X22+X16+X12+X11+X10+
X8+X7+X5+X4+X2+X+1
●● Support 1’s complement, byte reverse & bit reverse operation on data and checksum
●● Support byte, half-word & word data size
●● Programmable CRC initial seed value
●● CRC computation done in 1 AHB clock cycle for 8-bit data and 4 AHB clock cycles for 32-bit
data
●● Support PDMA to complete a CRC computation of a block of memory
▄▄ Peripheral Direct Memory Access – PDMA
●● 6 channels with trigger source grouping
●● 8/16/32-bit width data transfer
●● Supports Address increment, decrement or fixed mode
●● 4-level programmable channel priority
●● Auto reload mode
●● Supports trigger sources:
ADC, SPI, USART, UART, I2C, I2S, EBI, GPTM, MCTM, SCI and software request
Introduction
●● Support multiplexed and non-multiplexed address and data line configurations
●● Multiplexed address and data line configurations
●● Up to 21 address lines
●● Up to 16-bit data bus width
▄▄ Universal Serial Bus Device Controller – USB
●● Complies with USB 2.0 full-speed (12Mbps) specification
●● On-chip USB full-speed transceiver
●● 1 control endpoint (EP0) for control transfer
●● 3 single-buffered endpoints for bulk and interrupt transfer
●● 4 double-buffered endpoints for bulk, interrupt and isochronous transfer
●● 1KB EP-SRAM used as the endpoint data buffers
▄▄ Debug Support
●● Serial Wire Debug Port – SW-DP
●● 4 comparators for hardware breakpoint or code / literal patch
●● 2 comparators for hardware watchpoints
▄▄ Package and Operation Temperature
●● 33-pin QFN, 48/64-pin LQFP package
●● Operation temperature range: -40 ˚C to +85 ˚C
Device Information
Table 1. Series Features and Peripheral List
Peripherals HT32F52342 HT32F52352
Main Flash (KB) 64 127.5
Option Bytes Flash (KB) 0.5 0.5
SRAM (KB) 8 16
MCTM 1
Introduction
GPTM 2
SCTM 2
Timers
BFTM 2
RTC 1
WDT 1
USB 1
SPI 2
USART 2
Communication UART 2
I2C 2
I2S 1
SCI (ISO7816-3) 2
PDMA 6 channels
EBI 1
CRC-16/32 1
EXTI 16
12-bit ADC 1
Number of channels 12 Channels
Comparator 2
GPIO Up to 51
CPU frequency Up to 48 MHz
Operating voltage 2.0 V ~ 3.6 V
Operating temperature -40 ˚C ~ +85 ˚C
Package 33-pin QFN, 48/64-pin LQFP
Block Diagram
Powered by VDD15
VDD
POR
/PDR VSS
Introduction
Interface Memory HSE XTALIN
AF
IO Port
-16/32 USB
Control/Data
Peripherals CLDO
Registers LDO
SRAM
SRAM
Interrupt request
Controller BOD
LVD
PDMA External Bus Powered by VDD
6 Channels Interafce
PLL
Bridge Device fMax: 48 MHz
AD0~AD15
A0~A20
AF
CS0~CS3
OE, WR, ALE
DP
AF
TX, RX DM
AF
RTS/TXE USART0 ~ 1
CTS/SCK
WDT
MOSI, MISO
AF
AF
TX, RX UART0
UART0~ 1 SPI1
SPI1~~00 SCK, SEL
AF
WS, SDO, SDI
I2S I2C0 ~ 1 SCL
AFIO
AF
GPTM0 ~ 1 CH3 ~ CH0
Power control
EXTI
BFTM0 ~ 1
CH0 ~CH2
APB
AF
SCTM SCTM0 ~ 1
AF
RTC RTCOUT
PWRSW
ADC_IN0 12-bit
AF
VBAK VBAT
SAR ADC ADC
...
WAKEUP
VDDA LSE
BREG 32,768 Hz
VSSA
Powered by VDDA Powered by VDD15 Backup Domain nRST
AF
X32KIN
X32KOUT
Power supply:
Bus:
Control signal:
Alternate function: AF
2 Document Conventions
The conventions used in this document are shown in the following table.
Table 2. Document Conventions
Notation Example Description
The number string with a 0x prefix indicates a hexadecimal
0x 0x5a05
number.
Document Conventions
0xnnnn_nnnn 0x2000_0100 32-bit Hexadecimal address or data.
The number string with a lowercase b prefix indicates a binary
b b0101
number.
Specific bit of NAME. NAME can be a register or field of register.
NAME [n] ADDR [5]
For example, ADDR [5] means bit 5 of ADDR register (field).
Specific bits of NAME. NAME can be a register or field of
NAME [m:n] ADDR [11:5] register. For example, ADDR [11:5] means bit 11 to 5 of ADDR
register (field).
X b10X1 Don’t care notation which means any value is allowed.
19 18
RW SERDYIE PLLRDYIE Software can read and write to this bit.
RW 0 RW 0
3 2
Software can only read this bit. A write operation will have no
RO HSIRDY HSERDY
RO 1 RO 0 effect.
1 0
Software can only read this bit. Read operation will clear it to 0
RC PDF BAK_PORF
RC 0 RC 1 automatically.
3 2
Software can read this bit or clear it by writing 1. Writing a 0 will
WC SERDYF PLLRDYF
WC 0 WC 0 have no effect.
1 0
Software can read this bit or clear it by writing 0. Writing a 1 will
W0C RXCF PARF
RO 0 W0C 0 have no effect.
31 30
Software can only write to this bit. A read operation always
WO DB_CKSRC
WO 0 WO 0 returns 0.
Reserved bit(s) for future use. Data read from these bits is not
1 0
well defined and should be treated as random data. Normally
Reserved LLRDY Reserved
RO 0 these reserved bits should be set to a 0 value. Note that
reserved bit must be kept at reset value.
Word Data length of a word is 32-bit.
Half-word Data length of a half-word is 16-bit.
Byte Data length of a byte is 8-bit.
3 System Architecture
The system architecture of devices that includes the Arm® Cortex®-M0+ processor, bus architecture
and memory organization will be described in the following sections. The Cortex®-M0+ is a next
generation processor core which offers many new features. Integrated and advanced features make
the Cortex®-M0+ processor suitable for market products that require microcontrollers with high
performance and low power consumption. In brief, The Cortex®-M0+ processor includes AHB-Lite
System Architecture
bus interface. All memory accesses of the Cortex®-M0+ processor are executed on the AHB-Lite
bus according to the different purposes and the target memory spaces. The memory organization
uses a Harvard architecture, pre-defined memory map and up to 4 GB of memory space, making
the system flexible and extendable.
Cortex®-M0+
Components Execution Trace Interface
Cortex®-M0+ Processor
Debug
Interrupts Nested ‡ Breakpoint
Cortex®-M0+
Vectored and
Processor
Interrupt Watchpoint
Core
Controller Unit
System Architecture
(NVIC)
‡ Memory ‡ Debug
‡ Wakeup ‡ Debugger
Protection Access Port
Interrupt Interface
Unit (DAP)
Controller (WIC)
Bus Matrix
Bus Architecture
The HT32F52342/52352 series consist of two masters and five slaves in the bus architecture. The
Cortex®-M0+ AHB-Lite bus and Peripheral Direct Memory Access (PDMA) are the masters while
the internal SRAM access bus, the internal Flash memory access bus, the AHB peripherals access
bus, External Bus Interface (EBI) and the AHB to APB bridges are the slaves. The single 32-bit
AHB-Lite system interface provides simple integration to all system regions include the internal
SRAM region and the peripheral region. All of the master buses are based on 32-bit Advanced
High-performance Bus-Lite (AHB-Lite) protocol. The following figure shows the bus architecture
of the HT32F52342/52352 series.
GPIO
Cortex®-M0+
Processor GPIO
System Architecture
PDMA FMC CKCU/RSTCU
Control Control
Registers Registers A~D Control Registers
USB
System
NVIC
SRAM
SRAM
Interrupt request
Controller
AHB to APB
Bridge APB IPs
DMA request
Memory Organization
The Arm ® Cortex ® -M0+ processor accesses and debug accesses share the single external
interface to external AHB peripheral. The processor accesses take priority over debug accesses.
The maximum address range of the Cortex®-M0+ is 4 GB since it has 32-bit bus address width.
Additionally, a pre-defined memory map is provided by the Cortex®-M0+ processor to reduce
the software complexity of repeated implementation of different device vendors. However, some
regions are used by the Arm® Cortex®-M0+ system peripherals. Refer to the Arm® Cortex®-M0+
Technical Reference Manual for more information. The following figure shows the memory map
of HT32F52342/52352 series of devices, including Code, SRAM, peripheral, and other pre-defined
regions.
Memory Map
0x400F_FFFF
Reserved
0x400B_8000
0x400B_0000 GPIO A ~ D
0xFFFF_FFFF 0x400A_C000 Reserved
0x400A_A000 USB SRAM
Reserved
0x400A_8000 USB
0xE010_0000 0x4009_A000 Reserved
System Architecture
0x4009_8000 EBI AHB
Private peripheral bus
0xE000_0000 0x4009_2000 Reserved
0x4009_0000 PDMA
Reserved
0x7000_0000 0x4008_C000 Reserved
0x4008_A000 CRC
EBI Selection Bank 64 MB x 4 0x4008_8000 CKCU/RSTCU
0x6000_0000 0x4008_2000 Reserved
0x4008_0000 FMC
0x4007_8000 Reserved
0x4007_7000 BFTM1
Reserved 0x4007_6000 BFTM0
0x4007_5000 Reserved
0x4007_4000 SCTM1
0x4010_0000 0x4007_0000 Reserved
AHB peripherals 512 KB 0x4006_F000 GPTM1
0x4008_0000 0x4006_E000 GPTM0
Peripheral
APB peripherals 512 KB 0x4006_B000 Reserved
0x4000_0000 0x4006_A000 RTC & PWRCU
0x4006_9000 Reserved
0x4006_8000 WDT
0x4005_9000 Reserved
0x4005_8000 CMP
Reserved
0x4004_A000 Reserved
SRAM
0x4004_9000 I2C1
0x4004_8000 I2C0 APB
0x4004_5000 Reserved
0x2000_4000 0x4004_4000 SPI1
0x4004_3000 SCI0
16 KB on-chip SRAM 16 KB 0x4004_2000 Reserved
0x4004_1000 UART1
0x2000_0000 0x4004_0000 USART1
Reserved 0x4003_B000 Reserved
0x1FF0_0400 0x4003_A000 SCI1
Option byte alias 1 KB 0x4003_5000 Reserved
0x1FF0_0000 0x4003_4000 SCTM0
Reserved 0x4002_D000 Reserved
0x1F00_1000 0x4002_C000 MCTM
Code Boot loader 4 KB 0x4002_7000 Reserved
0x1F00_0000 0x4002_6000 I2S
Reserved 0x4002_5000 Reserved
0x0001_0000 0x4002_4000 EXTI
0x4002_3000 Reserved
0x4002_2000 AFIO
Up to 0x4001_1000 Reserved
128 KB on-chip Flash Up to 0x4001_0000 ADC
128 KB 0x4000_5000 Reserved
0x0000_0000 0x4000_4000 SPI0
0x4000_2000 Reserved
0x4000_1000 UART0
0x4000_0000 USART0
System Architecture
0x4001_1000 0x4002_1FFF Reserved
0x4002_2000 0x4002_2FFF AFIO
0x4002_3000 0x4002_3FFF Reserved
0x4002_4000 0x4002_4FFF EXTI
0x4002_5000 0x4002_5FFF Reserved
0x4002_6000 0x4002_6FFF I2S
0x4002_7000 0x4002_BFFF Reserved
0x4002_C000 0x4002_CFFF MCTM
0x4002_D000 0x4003_3FFF Reserved
0x4003_4000 0x4003_4FFF SCTM0
0x4003_5000 0x4003_9FFF Reserved
0x4003_A000 0x4003_AFFF SCI1
0x4003_B000 0x4003_FFFF Reserved
0x4004_0000 0x4004_0FFF USART1
0x4004_1000 0x4004_1FFF UART1
APB
0x4004_2000 0x4004_2FFF Reserved
0x4004_3000 0x4004_3FFF SCI0
0x4004_4000 0x4004_4FFF SPI1
0x4004_5000 0x4004_7FFF Reserved
0x4004_8000 0x4004_8FFF I2C0
0x4004_9000 0x4004_9FFF I2C1
0x4004_A000 0x4005_7FFF Reserved
0x4005_8000 0x4005_8FFF Comparator
0x4005_9000 0x4006_7FFF Reserved
0x4006_8000 0x4006_8FFF WDT
0x4006_9000 0x4006_9FFF Reserved
0x4006_A000 0x4006_AFFF RTC/PWRCU
0x4006_B000 0x4006_DFFF Reserved
0x4006_E000 0x4006_EFFF GPTM0
0x4006_F000 0x4006_FFFF GPTM1
0x4007_0000 0x4007_3FFF Reserved
0x4007_4000 0x4007_4FFF SCTM1
0x4007_5000 0x4007_5FFF Reserved
0x4007_6000 0x4007_6FFF BFTM0
0x4007_7000 0x4007_7FFF BFTM1
0x4007_8000 0x4007_FFFF Reserved
System Architecture
0x4009_2000 0x4009_7FFF Reserved
0x4009_8000 0x4009_9FFF EBI Control Registers AHB
0x4009_A000 0x400A_7FFF Reserved
0x400A_8000 0x400A_BFFF USB
0x400A_C000 0x400A_FFFF Reserved
0x400B_0000 0x400B_1FFF GPIOA
0x400B_2000 0x400B_3FFF GPIOB
0x400B_4000 0x400B_5FFF GPIOC
0x400B_6000 0x400B_7FFF GPIOD
0x400B_8000 0x400F_FFFF Reserved
System Architecture
Programming (IAP) or In Circuit Programming (ICP). For more information, refer to the Flash
Memory Controller section.
AHB Peripherals
The address of the AHB peripherals ranges from 0x4008_0000 to 0x400F_FFFF. Some peripherals
such as Clock Control Unit, Reset Control Unit and Flash Memory Controller are connected to the
AHB bus directly. The AHB peripherals clocks are always enabled after a system reset. Access to
registers for these peripherals can be achieved directly via the AHB bus. Note that all peripheral
registers in the AHB bus support only word access.
APB Peripherals
The address of APB peripherals ranges from 0x4000_0000 to 0x4007_FFFF. An APB to AHB
Bridge provides access capability between the CPU and the APB peripherals. Additionally, the
APB peripheral clocks are disabled after a system reset. Software must enable the peripheral clock
by setting up the APBCCRn register in the Clock Control Unit before accessing the corresponding
peripheral register. Note that the APB to AHB Bridge will duplicate the half-word or byte data to
word width when a half-word or byte access is performed on the APB peripheral registers. In other
words, the access result of a half-word or byte access on the APB peripheral register will vary
depending on the data bit width of the access operation on the peripheral registers.
Introduction
The Flash Memory Controller (FMC) provides functions of flash operation and pre-fetch buffer
for the embedded on-chip Flash memory. Figure below shows the block diagram of FMC which
includes programming interface, control register, pre-fetch buffer, and access interface. Since the
Flash
Flash Memory Controller
Information
Block
Wait State
AHB Control
Control Register
Peripheral Bus
Addressing
Main Flash
Data Memory
System Bus Pre-fetch Buffer
Programming
Control
Features
▄▄ Up to 128 KB of on-chip Flash memory for storing instruction/data and options
●● 128 KB (instruction/data + Option Byte)
●● 64 KB (instruction/data + Option Byte)
▄▄ Page size of 512 Bytes, totally up to 256 pages depending on the main Flash size
▄▄ Wide access interface with pre-fetch buffer to reduce instruction gaps
▄▄ Page erase and mass erase capability
▄▄ 32-bit word programming
▄▄ Interrupt capability when ready or error occurs
▄▄ Flash read protection to prevent illegal code/data access
▄▄ Page erase/program protection to prevent unexpected operation
Functional Descriptions
Flash Memory Map
The following figure is the Flash memory map of the system. The address ranges from
0x0000_0000 to 0x1FFF_FFFF (0.5 GB). The address from 0x1F00_0000 to 0x1F00_0FFF is
mapped to Boot Loader Block (4 KB). Besides, address 0x1FF0_0000 to 0x1FF0_01FF is the alias
of Option Byte block (0.5 KB) which locates at the last page of main Flash physically. The memory
mapping on system view is shown as below.
Reserved
0x1FF0_0200
Option Byte 0.5 Kbytes
0x1FF0_0000
Reserved
0x1F00_1000
127.5 Kbytes
Main Flash Block
or
User Application
64 Kbytes
0x0000_0000
........
........
........
Main Flash
Block
Page 252 0x0001_F800 ~ 0x0001_F9FF 512 Bytes
OB_PP [126]
Page 253 0x0001_FA00 ~ 0x0001_FBFF 512 Bytes
Page 254 0x0001_FC00 ~ 0x0001_FDFF OB_PP [127] 512 Bytes
Page 255 Physical: 0x0001_FE00 ~ 0x0001_FFFF
OB_CP [1] 512 Bytes
(Option Byte) Alias: 0x1FF0_0000 ~ 0x1FF0_01FF
Information Block Boot Loader 0x1F00_0000 ~ 0x1F00_0FFF NA 4 KB
Notes: 1. Information Block stores boot loader, this block can not be programmed or erased by user.
2. Option Byte is always located at last page of main Flash block.
Booting Configuration
The system provides two kinds of booting mode which can be selected through BOOT pin. The
value of BOOT pin is sampled during the power-on reset or system reset. Once the value is decided,
the first 4 words of vector will be remapped to the corresponding source according to the booting
mode. The booting mode is shown in the following table.
Table 6. Booting Modes
Booting mode selection pin
Mode Descriptions
The Vector Mapping Control Register (VMCR) is provided to change the setting of the vector
remapping temporarily after the chip reset. The reset value of VMCR is determined by the value of
BOOT pin which will be sampled during the reset.
Boot Setting
Page Erase
The FMC provides a page erase function which is used to reset partial content of Flash memory.
Any page can be erased independently without affecting others. The following steps show the
access sequence of the register for page erase.
▄▄ Check the OPCR register to confirm that no Flash memory operation is in progress (OPM [3:0]
equals to 0xE or 0x6). Otherwise, wait until the previous operation has been finished.
▄▄ Write the page address to TADR register
Start
No
Is OPM equal to 0xE or 0x6 ?
Yes
Commit command
by setting OPCR
No
Is OPM equal to 0xE ?
Yes
Finish
Mass Erase
The FMC provides a complete erase function which is used for resetting all the main Flash memory
content. The following steps show the sequence of the register access for mass erase.
▄▄ Check the OPCR register to confirm that no Flash memory operation is in progress (OPM [3:0]
equals to 0xE or 0x6). Otherwise, wait until the previous operation has been finished.
▄▄ Write mass erase command to OCMR register (CMD [3:0] = 0xA).
▄▄ Commit mass erase command to FMC by setting OPCR register (set OPM [3:0] = 0xA).
Start
No
Is OPM equal to 0xE or 0x6 ?
Yes
Commit command
by setting OPCR
No
Is OPM equal to 0xE ?
Yes
Finish
Word Programming
The FMC provides a 32 bits word programming function which is used for modifying the Flash
memory content. The following steps show the sequence of register access for word programming.
▄▄ Check the OPCR register to confirm that no Flash memory operation is in progress (OPM [3:0]
equals to 0xE, or 0x6). Otherwise, wait until the previous operation has been finished.
▄▄ Write word address to TADR register. Write data to WRDR register.
▄▄ Write word program command to OCMR register (CMD [3:0] = 0x4).
Start
No
Is OPM equal to 0xE or 0x6 ?
Yes
Commit command
by setting OPCR
No
Is OPM equal to 0xE ?
Yes
Finish
Security Protection
FMC provides function of Security protection to prevent illegal code/data access of Flash memory.
This function is useful for protecting the software / firmware from the illegal users. The function is
activated by setting the Option Byte OB_CP [0]. Once the function has been enabled, all the main
Flash data access through ICP/Debug mode, programming, and page erase will not be allowed
except the user’s application. But the mass erase operation will still be accepted by FMC in order to
disable this function. The following table shows the access permission of Flash memory when the
security protection is enabled.
Register Map
The following table shows the FMC registers and reset values.
Table 10. FMC Register Map
Register Offset Description Reset Value
FMC Base Address = 0x4008_0000
TADR 0x000 Flash Target Address Register 0x0000_0000
WRDR 0x004 Flash Write Data Register 0x0000_0000
Note: “X” means various reset values which depend on the Device, Flash value, option byte value, or
power on reset setting.
Register Descriptions
Flash Target Address Register – TADR
This register specifies the target address of page erase and word programming operation.
offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
WRDB
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
PPSBn
Type/Reset RO X RO X RO X RO X RO X RO X RO X RO X
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
MFID
31 30 29 28 27 26 25 24
PNSB
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
PSSB
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
CID
Type/Reset RO X RO X RO X RO X RO X RO X RO X RO X
Introduction
The power consumption can be regarded as one of the most important issues for many embedded
system applications. Accordingly the Power Control Unit, PWRCU, provides many types of power
saving modes such as Sleep, Deep-Sleep1, Deep-Sleep2, and Power-Down modes. These modes
VDD
VDD Domain
PLL
LDOOFF
LDO HSI
VDD VBAK LCM
3.3 V
POR/PDR
VBAT DMOSON
DMOS
PWRSW LVD
WKUP1 HSE
1.5 V
nRST POR/PDR
PWR_CTRL
WKUP2
WAKEUP WKUP4 VLDOOUT
VDD15
RTCOUT
WKUP3
RTC
1.5 V Domain
SLEEPDEEP
LSI PORB SLEEPING CPU Memories
APB Digital
LSE BREG INTF Peripheral
Backup Domain
PORB: VBAK Power On Reset LDO: Voltage Regulator LVD: Low Voltage Detector
BREG: Backup Registers DMOS: Depletion MOS POR/PDR: Power On Reset/Power Down Reset
Features
▄▄ Three power domains: Backup, VDD and 1.5 V power domains.
▄▄ Four power saving modes: Sleep, Deep-Sleep1, Deep-Sleep2 and Power-Down modes.
▄▄ Internal Voltage regulator supplies 1.5 V voltage source.
▄▄ Additional Depletion MOS supplies 1.5 V voltage source with low leakage and low operating
current.
Functional Descriptions
Backup Domain
Power Switch
The Backup Domain is powered by the VDD power source or the battery power source, VBAT, which
is selected by the power switch PWRSW. The operating voltage range of the Back Domain is
from 2.0 V to 3.6 V. If VDD is lower than V PDR, then the power source of the Back Domain will be
automatically switched from VDD to VBAT. Therefore, even if VDD is powered down, all the circuitry
in the backup domain can operate normally. This means that the backup register contents will be
retained, the RTC circuitry will operate normally and the low speed oscillators can keep running.
VDD
Hysteresis
VPDR
Time
POR Delay Time
tRSTD
RESET
The Brown Out Detector, BOD, is used to detect if the V DD supply voltage is equal to or lower
than V BOD. When the BODEN bit in the LVDCSR register is set to 1 and the VDD supply voltage
is lower than V BOD then the BODF flag is active. The PWRCU will regard this as a power down
reset situation and then immediately disable the internal LDO regulator when the BODRIS bit is
cleared to 0 or issue an interrupt to notify the CPU to execute a power down procedure when the
BODRIS bit is set to 1. For more details concerning the Brown Out Detector voltage V BOD, refer to
the electrical characteristics of the corresponding datasheet.
Operation Modes
Run Mode
In the Run mode, the system operates with full functions and all power domains are active. There
are two ways to reduce the power consumption in this mode. The first is to slow down the system
clock by setting the AHBPRE field in the CKCU AHBCFGR register, and the second is to turn
off the unused peripherals clock by setting the APBCCR0 and APBCCR1 registers or slow down
peripherals clock by setting the APBPCSR0 and APBPCSR1 registers to meet the application
requirement. Reducing the system clock speed before entering the sleep mode will also help to
minimize power consumption.
Additionally, there are several power saving modes to provide maximum optimization between
device performance and power consumption.
Table 11. Operation Mode Definitions
Mode name Hardware Action
Run After system reset, CPU fetches instructions to execute.
1. CPU clock will be stopped.
Sleep
2. Peripherals, Flash and SRAM clocks can be stopped by setting.
1. Stop all clocks in the 1.5 V power domain.
2. Disable HSI, HSE, and PLL.
Deep-Sleep1 ~ 2
3. Turning on the LDO low current mode or DMOS to reduce the 1.5 V power
domain current.
Power-Down Shut down the 1.5 V power domain
Sleep Mode
By default, only the CPU clock will be stopped in the Sleep mode. Clearing the FMCEN or
SRAMEN bit in the CKCU AHBCCR register to 0 will have the effect of stopping the Flash clock
or SRAM clock after the system enters the Sleep mode. If it is not necessary for the CPU to access
the Flash memory and SRAM in the Sleep mode, it is recommended to clear the FMCEN and
SRAMEN bits in the AHBCCR register to minimize power consumption. To enter the Sleep mode,
it is only necessary to clear the SLEEPDEEP bit to 0 and execute a WFI or WFE instruction. The
system will exit from the Sleep mode via any interrupt or event trigger. The accompanying table
Power-Down Mode
The Power-Down mode is derived from the Deep-Sleep mode of the CPU together with the
additional control bits LDOOFF and DMOSON. To enter the Power-Down mode, users can
configure the registers shown in the preceding Mode-Entering table and execute the WFI or WFE
instruction. A RTC wakeup trigger event, a LVD wakeup, a low to high transition on the external
WAKEUP pin or an external reset (nRST) signal will force the MCU out of the Power-Down mode.
In the Power-Down mode, the 1.5 V power supply will be turned off. The remaining active power
supplies are the 3.3 V power (VDD / VDDA) and the Backup Domain power (VBAK).
Register Map
The following table shows the PWRCU registers and reset values. Note all the registers in this unit
are located in the VBAK backup power domain.
Table 14. PWRCU Register Map
Register Offset Description Reset Value
BAKSR 0x100 Backup Domain Status Register 0x0000_0001
BAKCR 0x104 Backup Domain Control Register 0x0000_0000
BAKTEST 0x108 Backup Domain Test Register 0x0000_0027
LVDCSR 0x110 Low Voltage/Brown Out Detect Control and Status Register 0x0000_0000
BAKREG0 0x200 Backup Register 0 0x0000_0000
BAKREG1 0x204 Backup Register 1 0x0000_0000
BAKREG2 0x208 Backup Register 2 0x0000_0000
BAKREG3 0x20C Backup Register 3 0x0000_0000
BAKREG4 0x210 Backup Register 4 0x0000_0000
BAKREG5 0x214 Backup Register 5 0x0000_0000
BAKREG6 0x218 Backup Register 6 0x0000_0000
BAKREG7 0x21C Backup Register 7 0x0000_0000
BAKREG8 0x220 Backup Register 8 0x0000_0000
BAKREG9 0x224 Backup Register 9 0x0000_0000
Register Descriptions
Backup Domain Status Register – BAKSR
This register indicates backup domain status.
Offset: 0x100
Reset value: 0x0000_0001 (Reset only by Backup Domain reset)
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Low Voltage / Brown Out Detect Control and Status Register – LVDCSR
This register specifies flags, enable bits and option bits for low voltage detector.
Offset: 0x110
Reset value: 0x0000_0000 (Reset only by Backup Domain reset)
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
BAKREGn
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
Introduction
The Clock Control unit (CKCU) provides functions of high speed internal RC oscillator (HSI),
High speed external crystal oscillator (HSE), Low speed internal RC oscillator (LSI), Low speed
external crystal oscillator (LSE), Phase Lock Loop (PLL), HSE clock monitor, clock prescaler,
A variety of internal clocks can also be wired out though CKOUT for debugging purpose. The
clock monitor can be used to get clock failure detection of HSE. Once the clock of HSE does not
function (could be broken down or removed or etc), CKCU will force to switch the system clock
source to HSI clock to prevent system halt.
Prescaler Divider
CK_REF
1 ~ 32 2
HSI Auto CK_LSE CKREFPRE
CKREFEN
Trimming
Controller USB REF Pulse fCK_USB = 48 MHz
CK_USB
USBEN
8 MHz PLLSRC
HSI RC PLLEN f CK_PLL,max = 48 MHz
STCLK
8 (to SysTick)
1 CK_PLL
110
HCLKD
DMAEN ( to PDMA)
Clock CK_EBI
Monitor ( to EBI)
EBIEN
CK_CRC
32.768 kHz CK_LSE CRCEN ( to CRC)
LSE OSC WDTSRC
LSEEN(Note1) HCLKF
1 CK_WDT ( to Flash)
0 CM0PEN
FMCEN
32 kHz CK_LSI
WDTEN
LSI RC
RTCSRC(Note1)
HCLKS
LSIEN(Note1) ( to SRAM)
CM0PEN
1 CK_RTC
0 SRAMEN
RTCEN(Note1) HCLKBM
( to Bus Matrix)
CKOUTSRC[2:0] CM0PEN
BMEN
000 CK_REF
001 HCLKC/16
010 CK_SYS/16 HCLKAPB
CKOUT ( to APB Bridge)
011 CK_HSE/16
CM0PEN
100 CK_HSI/16
101 CK_LSE APBEN
110 CK_LSI
PCLK 00
Legend:
HSE = High Speed External clock Peripherals PCLK/2 PCLK ( CMPx, AFIO,
01
HSI = High Speed Internal clock Clock ADC, SPIx, USARTx,
LSE = Low Speed External clock Prescaler PCLK/4 SPIEN UARTx, I2Cx, I2S,
10
LSI = Low Speed Internal clock 1,2,4,8 GPTMx, MCTMx,
PCLK/8 SCIEN BFTMx, SCTMx, EXTI,
11
RTC, SCI, WDT)
ADC
Prescaler CK_ADC IP
1,2,3,4,8,...
ADCEN
Features
▄▄ 4 ~ 16 MHz external crystal oscillator (HSE)
▄▄ Internal 8 MHz RC oscillator (HSI) with configuration option calibration and custom trimming
capability.
▄
▄ PLL with selectable clock source (from HSE or HSI) for system clock.
▄▄ 32,768 Hz external crystal oscillator (LSE) for Watchdog Timer, RTC or system clock.
Function Descriptions
High Speed External Crystal Oscillator – HSE
The high speed external 4 to 16 MHz crystal oscillator (HSE) produces a highly accurate
clock source to the system clock. The related hardware configuration is shown in the following
figure. The crystal with specific frequency must be placed across the two HSE pins (XTALIN /
XTALOUT) and the external components such as resistors and capacitors are necessary to make it
oscillate properly.
The following guidelines are provided to improve the stability of the crystal circuit PCB layout.
▄▄ The crystal oscillator should be located as close as possible to the MCU so that the trace lengths
are kept as short as possible to reduce any parasitic capacitances.
▄▄ Shield any lines in the vicinity of the crystal by using a ground plane to isolate signals and
reduce noise.
▄▄ Keep frequently switching signal lines away from the crystal area to prevent crosstalk.
OSC_EN
XTALIN XTALOUT
Crystal
4 MHz ~ 16 MHz
CL1 CL2
The HSE crystal oscillator can be switched on or off using the HSEEN bit in the Global Clock
Control Register (GCCR). The HSERDY flag in the Global Clock Status Register (GCSR) will
indicate if the high-speed external crystal oscillator is stable. When switching on the HSE oscillator
the HSE clock will still not be released until this HSERDY bit is set by the hardware. The specific
delay period is well-known as “Start-up time”. As the HSE becomes stable, an interrupt will be
generated if the related interrupt enable bit HSERDYIE in the Global Clock Interrupt Register
(GCIR) is set. The HSE clock can then be used directly as the system clock source or be used as the
PLL input clock.
The accuracy of the frequency of the high speed internal RC oscillator HSI can be calibrated via the
configuration options, but it is still less accurate than the HSE crystal oscillator. The applications,
the environments and the cost will determine the use of the oscillators.
Software could configure PSRCEN bit (Power Saving Wakeup RC Clock Enable) to 1 to force HSI
clock to be system clock when wake-up from Deep-Sleep or Power-Down mode. Subsequently, the
system clock will be switched back to the original clock source (HSE or PLL) if the original clock
source ready flag is asserted. This function can reduce the wakeup time when using the HSE or
PLL clock as the system clock.
After reset, the factory trimming value is loaded in the HSICOARSE[4:0] and HSIFINE[7:0] bits
in the HSI Control Register (HSICR). The HSI frequency accuracy may be affected by the voltage
or temperature variation. If the application has to be driven by more accurate HSI frequency, the
HSI frequency can be manually trimmed using the HSIFINE[7:0] bits in the HSI Control Register
(HSICR) or automatically adjusted via the Auto Trimming Controller together with an external
reference clock in the application. The reference clock can be provided from the low speed external
crystal or ceramic resonator oscillator LSE with a 32,768 Hz frequency or a 1ms USB frame
synchronous signal.
1
ATCEN
AT
0 Counter
Auto Trimming Register
TMSEL
LSE /32 0
AHB Bus
32.768KHz
REFCLKSEL
1
Fine-Trimming
Factory Read Register
Trimming Bits
0
Fine [7:0]
TRIMEN 8MHz HSI 8MHZ
Coarse [4:0] Oscillator
Coarse-Trimming
Read Register
/4
B3~B0
Frequency of the PLL output clock can be determined by the following formula:
NF1* NF 2 4 * NF 2 NF 2
PLLOUT = CK IN * = CK IN * = CK IN *
NR * NO1* NO 2 2 * 2 * NO 2 NO 2
where NR = Ref divider = 2, NF1 = Feedback Divider 1 = 4, NF2 = Feedback Divider 2 = 1 ~ 16,
NO1 = Output Divider 1 = 2, NO2 = Output Divider 2 = 1, 2, 4, or 8
Considering the duty cycle of 50%, both input and output frequencies are divided by 2. If a given
CLK in frequency as the PLL input generates a specific PLL output frequency, it is recommended
to load a larger value into the NF2 field to increase the PLL stability and reduce the jitter with but
the expense of settling time. The output and feedback divider 2 setup values are described in Table
15 and Table 16. All the configuration bits (S1 ~ S0, B3 ~ B0) in Table 15 and Table 16 are defined
in the PLL Configuration Register (PLLCFGR) and PLL Control Register (PLLCR) in the section
of Register Definition. Note that the VCOOUT frequency should be in the range from 48 MHz to
96 MHz. If the selected configuration exceeds this range, the PLL output frequency will not be
guaranteed to match the above PLLOUT formula.
The PLL can be switched on or off by using the PLLEN bit in the Global Clock Control Register
(GCCR). The PLLRDY flag in the Global Clock Status Register (GCSR) will indicate if the PLL
clock is stable. An interrupt can be generated if the related interrupt enable bit PLLRDYIE in the
Global Clock Interrupt Register (GCIR) is set as the PLL becomes stable.
X32KIN X32KOUT
CL1 CL2
32.768KHZ
1. Enable any clock source which will become the system clock or PLL input clock.
2. Configuring the PLLSRC register after the ready flags of both HSI and HSE are asserted,
3. Configuring the SW register to change the system clock source will occur after the corresponding
ready flag of the clock source is asserted. Note that the system clock will be forced to HSI if
the clock monitor is enabled and the PLL output or HSE clock configured as the system clock is
stuck at 0 or 1.
Register Map
The following table shows the CKCU register and reset value.
Table 18. CKCU Register Map
Register Offset Description Reset Value
GCFGR 0x000 Global Clock Configuration Register 0x0000_0102
GCCR 0x004 Global Clock Control Register 0x0000_0803
GCSR 0x008 Global Clock Status Register 0x0000_0028
Register Descriptions
Global Clock Configuration Register – GCFGR
This register specifies the clock source for PLL/USART/Watchdog Timer/CKOUT.
Offset: 0x000
Reset value: 0x0000_0102
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved PFBD
Type/Reset RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
PLLBPS Reserved
Type/Reset RW 0
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved SCI1EN Reserved I2SEN SCI0EN
Type/Reset RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved SCTM1EN SCTM0EN Reserved ADCCEN
Type/Reset RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved HSIST
Type/Reset RO 0 RO 0 RO 1
31 30 29 28 27 26 25 24
UR1PCLK UR0PCLK USR1PCLK USR0PCLK
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved SCTM1PCLK SCTM0PCLK
Type/Reset RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved HSICOARSE
Type/Reset RO X RO X RO X RO X RO X
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The Reset Control Unit, RSTCU, has three kinds of reset, the power on reset, system reset and
APB unit reset. The power on reset, known as a cold reset, resets the full system during a power
up. A system reset resets the processor core and peripheral IP components with the exception of
RSTCU Cortex®-M0+
nRST Filter
WDT_RSTn Delay
SYSRESETREQ SYSRESETn
---- HRESETn System Components
(BusMatrix, PMU)
VBAT
Backup PORB RTC/PWRCU reset
VDD33 Domain Filter
RESET
BAKRST
USART reset
USARTRST Reset
generator
Functional Descriptions
Power On Reset
The Power on reset, POR, is generated by either an external reset or the internal reset generator.
Both types have an internal filter to prevent glitches from causing erroneous reset operations. By
referring to Figure 19, the POR15 active low signal will be de-asserted when the internal LDO
voltage regulator is ready to provide 1.5 V power. In addition to the POR15 signal, the Power
Control Unit, PWRCU, will assert the BODF signal as a Power Down Reset, PDR, when the
VDD33
VDD15
t1
PORESTn
t2
SYSRESTn
t1 = 25us *Typical.
t2 = 100us
t3 t3 = 150us
* This timing is dependent on the internal LDO regulator output capacitor value.
System Reset
A system reset is generated by a power on reset (PORRESETn), a Watchdog Timer reset (WDT_
RSTn), nRST pin or a software reset (SYSRESETREQ) event. For more information about
SYSRESETREQ event, refer to the related chapter in the Cortex®-M0+ reference manual.
Register Map
The following table shows the RSTCU registers and reset values.
Table 19. RSTCU Register Map
Register Offset Description Reset Value
RSTCU Base Address = 0x4008_8000
GRSR 0x100 Global Reset Status Register 0x0000_0008
AHBPRSTR 0x104 AHB Peripheral Reset Register 0x0000_0000
Register Descriptions
Global Reset Status Register – GRSR
This register specifies a variety of reset status conditions.
Offset: 0x100
Reset value: 0x0000_0008
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
Reserved PORSTF WDTRSTF EXTRSTF NVICRSTF
Type/Reset WC 1 WC 0 WC 0 WC 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved PERST PDRST PCRST PBRST PARST
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
CRCRST EBIRST USBRST Reserved DMARST
Type/Reset RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved SCI1RST Reserved I2SRST SCI0RST
Type/Reset RW 0 RW 0 RW 0
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
EXTIRST AFIORST Reserved UR1RST UR0RST USR1RST USR0RST
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
Reserved SPI1RST SPI0RST Reserved I2C1RST I2C0RST
Type/Reset RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved SCTM1RST SCTM0RST Reserved ADCRST
Type/Reset RW 0 RW 0 RW 0
Introduction
There are up to 51 General Purpose I/O port, GPIO, named PA0 ~ PA15, PB0 ~ PB15, PC0 ~
PC15 and PD0 ~ PD3 for the device to implement the logic input/output functions. Each of the
GPIO ports has related control and configuration registers to satisfy the requirement of specific
The GPIO ports are pin-shared with other alternative functions (AFs) to obtain maximum flexibility
on the package pins. The GPIO pins can be used as alternative functional pins by configuring the
corresponding registers regardless of the AF input or output pins.
The external interrupts on the GPIO pins of the device have related control and configuration
registers in the External Interrupt Control Unit (EXTI).
PxRSTn
PxSETn
PxDVn
To IOPAD DS
Bus Interface PxODn
CIOPAD PxDIN
IENAFIO
To IOPAD IEN
PxINENn
PxDIRn
To IOPAD OEN
OENAFIO
Features
▄▄ Input/output direction control
▄▄ Schmitt Trigger Input function enable control
▄▄ Input weak pull-up/pull-down control
▄▄ Output push-pull/open drain enable control
▄▄ Output set/reset control
Functional Descriptions
Default GPIO Pin Configuration
During or just after the reset period, the alternative functions are all inactive and the GPIO ports
are configured into the input disable floating mode, i.e. input disabled without pull-up/pull-down
resistors. Only the boot and Serial-Wired Debug pins which are pin-shared with the I/O pins are
active after a device reset.
▄▄ PA8: Input enable with internal pull-up
▄▄ PA9_BOOT: Input enable with internal pull-up
▄▄ SWCLK: Input enable with internal pull-up
▄▄ SWDIO: Input enable with internal pull-up
The GPIO pins can be configured as output pins where the output data is latched into the data
register PxDOUTR. The output type can be setup to be either push-pull or open-drain by the
open drain selection register PxODR. Only one or several specific bits of the output data will be
set or reset by configuring the port output set and reset control register PxSRR or the port output
reset control register PxRR without affecting the unselected bits. As the port output set and reset
functions are both enabled, the port output set function has the higher priority and the port output
reset function will be blocked. The output driving current of the GPIO pins can be selected by
configuring the drive current selection register PxDRVR.
PxCFGn
PUN
Input
DMUX
PDN
IEN
Output
MUX
AFIO
OENIP Control
IOPAD OEN DS
OENAFIO
ADENAFIO
IENAFIO
ADC
AFIO
ADEN
PxDOn
PxDIn
PxRSTn PxDVn
PxINENn
PxSETn PxODn
PxDIRn
PxPLn
PxPHn
GPIO
PxDIn/PxDOn (x=A ~ D): Data Input/Data Output PxRSTn/PxSETn (x=A ~ D): Reset/Set
PxDVn (x=A ~ D): Output Drive PXODn (x=A ~ D): Open Drain
PxPLn/PxPHn (x=A ~ D): Pull Low/High PxCFGn (x=A ~ D): AFIO Configuration
Table 20. AFIO, GPIO and IO Pad Control Signal True Table
AFIO GPIO PAD
Type
ADENAFIO OENAFIO IENAFIO PxDIRn PxINENn ADEN OEN IEN
GPIO Input (Note) 1 1 1 0 1 1 1 0
GPIO Output (Note)
1 1 1 1 0 (1 if need) 1 0 1 (0)
AFIO Input 1 1 0 0 X 1 1 0
AFIO Output 1 0 1 X 0 (1 if need) 1 0 1 (0)
ADC Input 0 1 1 0 0 (1 if need) 0 1 1 (0)
OSC Output 0 1 1 0 0 (1 if need) 0 1 1 (0)
Note: The signals, IEN and OEN, for I/O pads are derived from the GPIO register bits PxINENn and
PxDIRn respectively when the associated pin is configured in the GPIO input/output mode.
Register Descriptions
Port A Data Direction Control Register – PADIRCR
This register is used to control the direction of the GPIO Port A pin as input or output.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
PADIR
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
PADIR
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
PADV15 PADV14 PADV13 PADV12
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
PALKEY
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
PARST
Type/Reset WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
PBDV15 PBDV14 PBDV13 PBDV12
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
PBLKEY
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
PBRST Reserved
Type/Reset WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
PCDV15 PCDV14 PCDV13 PCDV12
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
PCLKEY
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
PCRST
Type/Reset WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
PDLKEY
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
In order to expand the flexibility of the GPIO or the usage of peripheral functions, each IO pin can
AFIO Configuration
Registers
PxLOCKR
Lock Signal
PxLOCKR
Lock Signal
GPIO Module
Features
▄▄ APB slave interface for register access
▄▄ EXTI source selection
▄▄ Configurable pin function for each GPIO, up to sixteen alternative functions on each pin
▄▄ AFIO lock mechanism
Functional Descriptions
EXTI0PIN
PA0
0000
PB0
0001
PC0 EXTI 0
0010
PD0
0011
EXTI15PIN
PA15
0000
PB15
0001
PC15 EXTI 15
0010
PD15
0011
Alternate Function
Up to sixteen alternative functions can be chosen for each I/O pad by setting the PxCFGn [3:0]
field in the GPxCFGLR or GPxCFGHR (n = 0~15, x = A~ D) registers. If the pin is selected as
an unavailable item which is noted as a “N/A” item in the “Alternate Function Mapping” table in
the device datasheet, this pin will be defined as the default alternate function. Please refer to the
“Alternate Function Mapping” table in the device datasheet for the detailed mapping of the alternate
function I/O pins. 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
Lock Mechanism
The device also offers a lock function to lock the AFIO configuration using the GPIO lock register,
PxLOCKR, until a reset event occurs. Refer to the GPIO Locking Mechanism section in the GPIO
chapter for more details.
Register Map
The following table shows the AFIO registers and reset value.
Table 23. AFIO Register Map
Register Offset Description Reset Value
ESSR0 0x000 EXTI Source Selection Register 0 0x0000_0000
ESSR1 0x004 EXTI Source Selection Register 1 0x0000_0000
GPACFGLR 0x020 GPIO Port A AFIO Configuration Register 0 0x0000_0000
GPACFGHR 0x024 GPIO Port A AFIO Configuration Register 1 0x0000_0000
GPBCFGLR 0x028 GPIO Port B AFIO Configuration Register 0 0x0000_0000
GPBCFGHR 0x02C GPIO Port B AFIO Configuration Register 1 0x0000_0000
GPCCFGLR 0x030 GPIO Port C AFIO Configuration Register 0 0x0000_0000
GPCCFGHR 0x034 GPIO Port C AFIO Configuration Register 1 0x0000_0000
GPDCFGLR 0x038 GPIO Port D AFIO Configuration Register 0 0x0000_0000
GPDCFGHR 0x03C GPIO Port D AFIO Configuration Register 1 0x0000_0000
Register Descriptions
EXTI Source Selection Register 0 – ESSR0
This register specifies the IO selection of EXTI0 ~ EXTI7.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
EXTI15PIN EXTI14PIN
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
PxCFG7 PxCFG6
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
PxCFG15 PxCFG14
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
Introduction
In order to reduce the latency and increase the interrupt processing efficiency, a tightly coupled
integrated section, which is named as Nested Vectored Interrupt Controller (NVIC) is provided
by the Cortex® -M0+. The NVIC controls the system exceptions and the peripheral interrupt
Additionally, an integrated simple, 24-bit down count timer (SysTick) is provided by the
Cortex® -M0+ to be used as a tick timer for the Real Timer Operation System (RTOS) or as a
simple counter. The SysTick counts down from the reloaded value and generates a system interrupt
when it reached zero. The accompanying table lists the 16 system exceptions types and a variety of
peripheral interrupts.
Table 24. Exception Types
Interrupt Exception Exception Vector
Priority Description
Number Number type Address
— 0 — — 0x000 Initial Stack Point value
— 1 Reset -3 (Highest) 0x004 Reset
Non-Maskable Interrupt. The clock stuck
interrupt signal (clock monitor function
-14 2 NMI -2 0x008
provided by Clock Control Unit) is
connected to the NMI input
-13 3 Hard Fault -1 0x00C All fault classes
- 4-10 Reserved — — —
-5 11 SVCall Configurable(1) 0x02C SVC instruction System service call
- 12-13 Reserved — — —
-2 14 PendSV Configurable(1) 0x038 System Service Pendable request
-1 15 SysTick Configurable(1) 0x03C SysTick timer decremented to zero
0 16 LVD Configurable (2)
0x040 Low voltage detection interrupt
1 17 RTC Configurable(2) 0x044 RTC global interrupt
2 18 FMC Configurable(2) 0x048 FMC global interrupt
EXTI event wakeup or external WAKEUP
3 19 WKUP Configurable(2) 0x04C
pin interrupt
4 20 EXTI0 ~ 1 Configurable(2) 0x050 EXTI Line 0 & 1 interrupt
5 21 EXTI2 ~ 3 Configurable(2) 0x054 EXTI Line 2 & 3 interrupt
6 22 EXTI4 ~ 15 Configurable (2)
0x058 EXTI Line 4 ~ 15 interrupt
7 23 CMP Configurable(2) 0x05C Comparator global interrupt
8 24 ADC Configurable(2) 0x060 ADC global interrupt
9 25 Reserved — 0x064 —
10 26 MCTM Configurable(2) 0x068 MCTM global interrupt
11 27 GPTM1 Configurable (2)
0x06C GPTM1 global interrupt
12 28 GPTM0 Configurable(2) 0x070 GPTM0 global interrupt
13 29 SCTM0 Configurable(2) 0x074 SCTM0 global interrupt
14 30 SCTM1 Configurable (2)
0x078 SCTM1 global interrupt
Features
▄▄ 7 system Cortex®-M0+ exceptions
▄▄ Up to 32 Maskable peripheral interrupts
▄▄ 16 programmable priority levels (4 bits for interrupt priority setting)
▄▄ Non-Maskable interrupt
▄▄ Low-latency exception and interrupt handling
▄▄ Vector table remapping capability
●● Integrated simple, 24-bit system timer, SYSTICK
●● 24-bit down counter
●● Auto-reloading capability
●● Maskable system interrupt generation when counter decrements to 0
●● SysTick clock source derived from the HCLK clock divided by 8
Function Descriptions
SysTick Calibration
The SysTick Calibration Value Register (SCALIB) is provided by the NVIC to give a reference time
base of 1ms for the RTOS tick timer or other purpose. The TENMS field in the SCALIB register
has a fixed value of 6000 which is the counter reload value to indicate 1 ms when the clock source
comes from the SysTick reference input clock STCLK with a frequency of 6 MHz (48 MHz divide
by 8).
Note: For more information of the above detail register descriptions, please refer to the “Cortex®-M0+
Devices Generic User Guide” document from Arm®.
Introduction
The External Interrupt/Event Controller, EXTI, comprises 16 edge detectors which can generate
a wake-up event or interrupt requests independently. In interrupt mode there are five trigger types
which can be selected as the external interrupt trigger type, low level, high level, negative edge,
Polarity
Control
(EXTInWPOL)
High or Low level
Features
▄▄ Up to 16 EXTI lines with configurable trigger source and type
All GPIO pins can be selected as EXTI trigger source
Source trigger type includes high level, low level, negative edge, positive edge, or both edge
▄▄ Individual interrupt enable, wakeup enable and status bits for each EXTI line
▄▄ Software interrupt trigger mode for each EXTI line
▄▄ Integrated deglitch filter for short pulse blocking
Function Descriptions
Wakeup Event Management
In order to wakeup the system from the power saving mode, the EXTI controller provides a
function which can monitor external events and send them to the CPU core and the Clock Control
Unit, CKCU. These external events include EXTI events, Low Voltage Detection, WAKEUP input
pin, Comparator, USB and RTC wakeup functions. By configuring the wakeup event enable bit
in the corresponding peripheral, the wakeup signal will be sent to the CPU and the CKCU via the
1
16 EXTInWFL
EXTIn 16 0 16
16 16
EVWUP interrupt
High/Low level (NVIC)
detector 16 16
EXTInWPOL EVWUPIEN
EXTInWEN
16 HSI/HSE/PLL
16 wakeup (CKCU)
CMP 16
CMP_WAKEUP
WDT
WDT_WAKEUP
RTC
RTC_WAKEUP
WUPF
USB
USB_WAKEUP
SLEEPING
(NVIC) EXTI Wakeup Event Management
Low pulse is
shorter than
debounce time
Debounce
time delay
nINT
pin input
nINT
interrupt
request
Register Map
The following table shows the EXTI registers and reset values.
Table 26. EXTI Register Map
Register Offset Description Reset Value
EXTICFGR0 0x000 EXTI Interrupt 0 Configuration Register 0x0000_0000
EXTICFGR1 0x004 EXTI Interrupt 1 Configuration Register 0x0000_0000
EXTICFGR2 0x008 EXTI Interrupt 2 Configuration Register 0x0000_0000
Register Descriptions
EXTI Interrupt Configuration Register n – EXTICFGRn, n = 0 ~ 15
This register is used to specify the debounce function and select the trigger type.
Offset: 0x000 (0) ~ 0x03C (15)
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
EVWUPIEN Reserved
Type/Reset RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
A 12-bit multi-channel Analog to Digital Converter is integrated in the device. There are a total of
14 multiplexed channels including 12 external channels on which the external analog signal can
be supplied and 2 internal channels. If the input voltage is required to remain within a specific
EXTI[15:0]
ADCTSR[31:0]
Start Trigger
ADCTCR[2:0]
. SAR A/D
GPIO ADC Controller
. Converter
ADC_IN12
AVSS
AVDD
DMA Request
Analog Watchdog
Features
▄▄ 12-bit SAR ADC engine
▄▄ Up to 1 MSPS conversion rate
▄▄ 12 external analog input channels
▄▄ 2 internal analog input channels for reference voltage detection
▄▄ Programmable sampling time for conversion channel
Function Descriptions
ADC Clock Setup
The ADC clock, CK_ADC is provided by the Clock Controller which is synchronous and divided
by with the AHB clock known as HCLK. Refer to the Clock Control Unit chapter for more details.
Notes that the ADC requires at least two ADC clock cycles to switch between power-on and power-
off conditions (ADEN bit = ‘0’).
A group is composed of up to 8 conversions. The selected channels of the group conversion can
be specified in the ADCLST0~ADCLST1 registers. The total conversion sequence length is setup
using the ADSEQL[2:0] bits in the ADCCONV register.
Modifying the ADCCONV or ADCHCONV register during a conversion process will reset the
current conversion, after which a new start pulse is required to restart a new conversion.
Conversion Mode
The A/D has three operating conversion modes. The conversion modes are One Shot Conversion
Mode, Continuous Conversion Mode, and Discontinuous Conversion mode. Details are provided
later.
After Conversion:
▄▄ The converted data will be stored in the 16-bit ADCDRy (y = 0~7) registers.
▄▄ The ADC single sample end of conversion event raw status flag, ADIRAWS, in the ADCIRAW
register will be set when the single sample conversion is finished.
▄▄ An interrupt will be generated after a single sample end of conversion if the ADIES bit in the
ADCIER register is enabled.
▄▄ An interrupt will be generated after a group cycle end of conversion if the ADIEC bit in the
ADCIER register is enabled.
CH2 CH4 CH7 CH5 CH6 CH3 CH0 CH1 CH2 CH4 CH7 CH5 CH6
Start of
Conversion
Cycle End of
Conversion
After conversion:
▄▄ The converted data will be stored in the 16-bit ADCDRy (y = 0~7) registers.
▄▄ The ADC group cycle end of conversion event raw status flag, ADIRAWC, in the ADCIRAW
register will be set when the conversion cycle is finished.
▄▄ An interrupt will be generated after a group cycle end of conversion if the ADIEC bit in the
ADCIER register is enabled.
Idle CH2 CH4 CH7 CH5 CH6 CH3 CH0 CH1 CH2 CH4 CH7 CH1
Start of Conversion
In the Discontinuous Conversion Mode, the A/D Converter will start to convert the next n
conversions where the number n is the subgroup length defined by the ADSUBL field. When a
trigger event occurs, the channels to be converted with a specific sequence are specified in the
ADCLSTn registers. After n conversions have completed, the subgroup EOC interrupt raw flag
ADIRAWG in the ADCIRAW register will be asserted. The A/D converter will now not continue
to perform the next n conversions until the next trigger event occurs. The conversion cycle will end
after all the group channels, of which the total number is defined by the ADSEQL[2:0] bits in the
ADCCONV register, have finished their conversion, at which point the cycle EOC interrupt raw
flag ADIRAWC in the ADCIRAW register will be asserted. If a new trigger event occurs after all
the subgroup channels have all been converted, i.e., a complete conversion cycle has been finished,
the conversion will restart from the first subgroup.
Example:
CH2 CH4 CH7 CH5 CH6 CH3 CH0 CH1 CH2 CH4 CH7
Single sample
End of
Conversion
Subgroup End
of Conversion
Cycle End of
Conversion
An A/D converter conversion can be started by setting the software trigger bit, ADSC, in the
ADCTSR register for the group channel when the software trigger enable bit, ADSW, in the
ADCTCR register is set to 1. After the A/D converter starts converting the analog data, the
corresponding enable bit ADSC will be cleared to 0 automatically.
The A/D converter can also be triggered to start a group conversion by a TM event. The TM events
include a GPTM or MCTM master trigger output MTO, four GPTM or MCTM channel outputs
CH0~CH3 and a BFTM trigger output. If the corresponding Timer trigger enable bit is set to 1 and
the trigger output or the TM channel event is selected via the relevant TM event selection bits, the
A/D converter will start a conversion when a rising edge of the selected trigger event occurs.
In addition to the internal trigger sources, the A/D converter can be triggered to start a conversion
by an external trigger event. The external trigger event is derived from the external lines, EXTIn.
If the external trigger enable bit ADEXTI is set to 1 and the corresponding EXTI line is selected by
configuring the ADEXTIS field in the ADCTSR register, the A/D converter will start a conversion
when an EXTI line active edge determined in the EXTI Unit occurs.
The total conversion time (Tconv) is calculated using the following formula:
Where the minimum sampling time TSampling = 1.5 cycles (when ADST[7:0] = 0) and the minimum
channel conversion latency TLatency = 12.5 cycles.
Example:
With the A/D Converter clock CK_ADC = 14 MHz and a sampling time =1.5 cycles:
Data Format
The ADC conversion result can be read in the ADCDRy register and the data format is shown in
the following Table 1.
Table 27. Data format in ADCDR [15:0]
Description ADCDR register Data Format
Right aligned “0_0_0_0_d11_d10_d9_d8_d7_d6_d5_d4_d3_d2_d1_d0”
Analog Watchdog
The A/D converter includes a watchdog function to monitor the converted data. There are two
kinds of thresholds for the watchdog monitor function, known as the watchdog upper threshold
and watchdog lower threshold, which are specified in the Watchdog Upper and Lower Threshold
Registers respectively. The watchdog monitor function is enabled by setting the watchdog upper
and lower threshold monitor function enable bits, ADWUE and ADWLE, in the watchdog control
register ADCWCR. The channel to be monitored can be specified by configuring the ADWCH
and ADWALL bits. When the converted data is less or higher than the lower or upper threshold, as
defined in the ADCLTR or ADCUTR registers respectively, the watchdog lower or upper threshold
interrupt raw flags, ADIRAWL or ADIRAWU in the ADCIRAW register, will be asserted if the
watchdog lower or upper threshold monitor function is enabled. If the lower or upper threshold
interrupt raw flag is asserted and the corresponding interrupt is enabled by setting the ADIML or
ADIMU bit in the ADCIME register, the A/D watchdog lower or upper threshold interrupt will be
generated.
Interrupts
When an A/D conversion is completed, an End of Conversion EOC event will occur. There are
three kinds of EOC events which are known as single sample EOC, subgroup EOC and cycle EOC
for A/D conversion. A single sample EOC event will occur and the single sample EOC interrupt
raw flag, ADIRAWS bits in the ADCIRAW register, will be asserted when a single channel
conversion has completed. A subgroup EOC event will occur and the subgroup EOC interrupt
raw flag, ADIRAWG in the ADCIRAW register, will be asserted when a subgroup conversion has
completed. A cycle EOC event will occur and the cycle EOC interrupt raw flag, ADIRAWC bits in
After a conversion has completed, the 12-bit digital data will be stored in the associated ADCDRy
registers and the value of the data valid flag named as ADVLDy will be changed from low to high.
The converted data should be read by the application program, after which the data valid flag
ADVLDy will be automatically changed from high to low. Otherwise, a data overwrite event will
occur and the data overwrite interrupt raw flag ADIRAWO bit in the ADCIRAW register will be
asserted. When the related data overwrite raw flag is asserted, the data overwrite interrupt will be
generated if the interrupt enable bit ADIEO in the ADCIER register is set to 1.
If the A/D watchdog monitor function is enabled and the data after a channel conversion is less
than the lower threshold or higher than the upper threshold, the watchdog lower or upper threshold
interrupt raw flag ADIRAWL or ADIRAWU in the ADCIRAW register will be asserted. When
the ADIRAWL or ADIRAWU flag is asserted and the corresponding interrupt enable bit, ADIEL
or ADIEU in the ADCIER register, is set a watchdog lower or upper threshold interrupt will be
generated.
The A/D Converter interrupt clear bits are used to clear the associated A/D converter interrupt raw
and interrupt status bits. Writing a 1 into the specific A/D converter interrupt clear bit in the A/D
converter interrupt clear register ADCICLR will clear the corresponding A/D converter interrupt
raw and interrupt status bits. These bits are automatically cleared to 0 by hardware after being set
to 1.
PDMA Request
The converted channel value will be stored in the corresponding data register. The A/D Converter
can inform the MCU using the A/D Converter EOC interrupt if a new conversion data is already
stored in the ADCDRn register. Users also can determine the PDMA request is asserted by setting
the ADDMAC, ADDMAG or ADDMAS bits in the ADCDMAR register. A PDMA request will
be automatically generated at the relevant end of A/D conversion. The detail description will be
introduced in the ADCDMAR register description.
Register Map
The following table shows the A/D Converter registers and reset values.
Table 28. A/D Converter Register Map
Register Offset Description Reset Value
ADCCR 0x000 ADC Conversion Control Register 0x0000_0000
ADCLST0 0x004 ADC Conversion List Register 0 0x0000_0000
ADCLST1 0x008 ADC Conversion List Register 1 0x0000_0000
Register Descriptions
ADC Conversion Control Register – ADCCR
This register specifies the mode setting, sequence length, and subgroup length of the ADC conversion mode.
Note that once the content of ADCCR is changed, the conversion in progress will be aborted and the A/D
converter will return to an idle state. The application program has to wait for at least one CK_ADC clock before
issuing the next command.
Offset: 0x000
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved ADSUBL
Type/Reset RW 0 RW 0 RW 0
15 14 13 12 11 10 9 8
Reserved ADSEQL
Type/Reset RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
ADCEN ADCRST Reserved ADMODE
Type/Reset RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved ADSEQ3
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved ADSEQ7
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
ADVLDy Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved TME
Type/Reset RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved ADUCH
Type/Reset RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
Reserved ADUT
Type/Reset RW 0 RW 0 RW 0 RW 0
23 22 21 20 19 18 17 16
ADUT
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
15 14 13 12 11 10 9 8
Reserved ADLT
Type/Reset RW 0 RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
ADLT
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved ADIEO
Type/Reset RW 0
31 30 29 28 27 26 25 24
Reserved ADIRAWO
Type/Reset RO 0
31 30 29 28 27 26 25 24
Reserved ADISRO
31 30 29 28 27 26 25 24
Reserved ADICLRO
31 30 29 28 27 26 25 24
Reserved
Type/Reset
13 Comparator (CMP)
Introduction
The two general purpose comparators (CMP) are implemented within the device. They can be
configured either as standalone comparators or combined with the different kinds of peripheral IP.
Each comparator is capable of asserting interrupts to the NVIC or wakeup the CPU Deep Sleep
Comparator (CMP)
mode through EXTI wakeup event management unit.
Programmable
Comparator Analog IP Hysteresis
CMPEN
CP
0 AFIO
CMPOUT
Mux 0 GPIO
CN
Mux
1
CMPSTS
Mux
Mux
Sync COUT
Reserved 1
Reserved CMPPOL
Programmable SYNCSEL
Response Time
CVREN CMPINSEL[1:0] HCLK
VDDA
0
CMP Status
Mux
& Interrupt
VREF+ 6-Bit CVREF Control &
1 Reguest
VSSA Scaler Interrupt
ADC
Generator
MCTM
CVRSS GPTM
CVROE
To EXTI
CVRVAL[5:0] Wakeup
Event
VDDA Domain VCORE Domain Management
Features
▄▄ Rail-to-rail comparator
▄▄ Configurable negative inputs used for flexible voltage selection
●● Dedicated I/O pin
●● Internal voltage reference provided by 6-bit scaler
▄▄ Programmable hysteresis
▄▄ Programming response speed and consumption
▄▄ Comparator output used as multiple timers or ADC trigger inputs
▄▄ Programmable internal voltage reference provided by 6-bit scaler.
▄▄ Comparator output transition with interrupt generation and wake-up functions from Sleep or
Deep Sleep modes through the EXTI controller.
Function Descriptions
Comparator Inputs and Output
The I/O pins used as comparator inputs or output must be configured in the AFIO controller
registers. The detail comparator I/Os information will be referred in the pin assignment table
in the datasheet. The output can also be internally connected to a variety of timer or ADC for
trigger purpose. The comparator output can be used for both internal and external functions
simultaneously.
Comparator (CMP)
Comparator Voltage Reference
The comparator voltage reference is a 64-tap resistor ladder network that provides a selectable
reference voltage. It also has a power-down function to conserve the power when the reference
is not used. The comparator voltage reference provides 64 distinct levels. The equation used to
calculate the comparator voltage reference is as follows:
The comparator voltage reference power source, V RP, can come from either the V DDA or external
V REF+ pin. The voltage source is selected by the CVRSS bit in the Comparator Control Register
CMPCR. The primary purpose of the CVREF output is to provide a reference voltage for the
analog comparator. It may also be used independently of them and configured output to CN pin
by setting the CVROE bit in the Comparator Control Register CVRCR. The settling time of the
comparator voltage reference must be considered when changing the CVREF output.
CVRSS = 0 CVRVAL[5:0]
VDDA VRP
VREF+
CVRSS = 1
R
R
CVREN
R
64:1 Mux
R CVREF
R
6-Bit Scaler for Comparator Voltage
Reference
Figure 32. 6-Bit Scaler for Comparator Voltage Reference Block Diagram
For example, when a comparator output rising edge occurs, the comparator rising edge flag bit
CMPRF in the Comparator Transition Flag Register CMPTFR will be set. If the comparator output
rising edge interrupt enable control bit CMPRIEN in the Comparator Interrupt Enable Register
CMPIER is enabled, an interrupt will then be generated and sent to the NVIC unit. Writing “1”
Comparator (CMP)
into the comparator rising edge flag bit CMPRF in the Comparator Transition Flag Register
CMPTFR will clear the CMPRF bit. The comparator output falling edge interrupt also has the
same corresponding interrupt setting. A block diagram of interrupt signal for comparators is shown
in Figure 33.
CMP0RF
CMP0RIEN
CMP0FF
CMP0FIEN
NVIC CMP
Interrupt
CMP1RF
CMP1RIEN
CMP1FF
CMP1FIEN
The comparator outputs are also internally connected to the EXTI Wake-up Event Management
unit. The comparator output rising transition is used to wake up the MCU from the Deep Sleep 1
or 2 modes when the comparator wake-up enable bit CMPWPEN is set in the Comparator Control
Register CMPCR. A block diagram of wakeup signal for comparators is shown in Figure 34.
CMP0WPEN
CMP0OUT
EXTI
CMP_WAKEUP
CMP1WPEN
CMP1OUT
The comparator also has four hysteresis levels to avoid spurious output transitions in case of noisy
signals. The bit CMPHM[1:0] in CMPCR register can be programmed to get the different hysteresis
level for the comparator.
Comparator (CMP)
Comparator Write-Protected mechanism
As the comparator can be used for safety purposes, it is necessary to insure that the comparator
configurations cannot be altered in case of spurious register access or program counter corruption.
For this purpose, the write protection is provided by writing a specific value into the PROTECT
filed in the Comparator Control Register CMPCR. The write protection function is enabled in
default. Before configuring the bits [15:0] in the Comparator Control Register CMPCR, the register
protection bits [31:16] of the CMPCR register has to be written into with the 0x9C3A pattern first.
Then the write protection mode is disabled and the CMPCR register becomes programmable.
As the same reason, the comparator input and output also can be locked with the corresponding
configuration lock bit in the Port n Lock Register PnLOCKR (n = A ~ E) in the GPIO unit.
Register Map
The following table shows the CMP registers and reset values.
Table 29. CMP Register Map
Register Offset Description Reset Value
CMPCR0 0x000 Comparator Control Register 0 0x0001_0000
CVRVALR0 0x004 Comparator Voltage Reference Value Register 0 0x0000_0000
CMPIER0 0x008 Comparator Interrupt Enable Register 0 0x0000_0000
CMPTFR0 0x00C Comparator Transition Flag Register 0 0x0000_0000
CMPCR1 0x100 Comparator Control Register 1 0x0001_0000
CVRVALR1 0x104 Comparator Voltage Reference Value Register 1 0x0000_0000
CMPIER1 0x108 Comparator Interrupt Enable Register 1 0x0000_0000
CMPTFR1 0x10C Comparator Transition Flag Register 1 0x0000_0000
Register Descriptions
Comparator Control Register n – CMPCRn, n = 0 or 1
This register contains the comparator function and comparator voltage reference control bits.
Offset: 0x000 (n = 0), 0x100 (n = 1)
Reset value: 0x0001_0000
31 30 29 28 27 26 25 24
Comparator (CMP)
PROTECT
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
23 22 21 20 19 18 17 16
PROTECT
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 1
15 14 13 12 11 10 9 8
CMPSTS CMPWPEN CMPOSEL CVRSS CVROE CVREN
Type/Reset R 0 RW/R 0 RW/R 0 RW/R 0 RW/R 0 RW/R 0 RW/R 0 RW/R 0
7 6 5 4 3 2 1 0
SYNCSEL CMPPOL CMPINSEL CMPHM CMPSM CMPEN
Type/Reset RW/R 0 RW/R 0 RW/R 0 RW/R 0 RW/R 0 RW/R 0 RW/R 0 RW/R 0
Comparator (CMP)
000: No selection
001: GPTM1 capture channel 3
010: MCTM capture channel 3
011: MCTM break input 1
100: ADC trigger input
Other: Reserved
These bits are used to select the destination for the comparator output after the
polarity selection.
[10] CVRSS Comparator Voltage Reference Source Selection
0: 6-bit scaler reference voltage source comes from VDDA
1: 6-bit scaler reference voltage source comes from VREF+
[9] CVROE Comparator Voltage Reference Output Enable
0: Disable 6-bit scaler output to CN pin
1: Enable 6-bit scaler output to CN pin
[8] CVREN Comparator Voltage Reference Enable
0: Disable 6-bit scaler for comparator voltage reference
1: Enable 6-bit scaler for comparator voltage reference
[7] SYNSEL Synchronization Selection
0: Asynchronous signal of Comparator output is selected
1: Synchronous signal of comparator output is selected
The synchronous comparator output should be selected before being passed to the
AFIO unit.
[6] CMPPOL Comparator Output Polarity Selection
0: Comparator output is not inverted
1: Comparator output is inverted
[5:4] CMPINSEL Comparator Inverted Input Selection
00: Comparator external CN pin is selected
01: Comparator internal 6-bit reference voltage scaler output is selected
1x: Reserved
These bits are used to select the comparator inverted input source.
[3:2] CMPHM Comparator Hysteresis Mode Selection
00: No hysteresis
01: Low hysteresis mode
10: Middle hysteresis mode
11: High hysteresis mode
[1] CMPSM Comparator Speed Mode Selection
0: High speed mode
1: Low speed mode
[0] CMPEN Comparator Enable
0: Disable Comparator (entering the power down mode)
1: Enable Comparator
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Comparator (CMP)
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
Reserved CVRVAL
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Comparator (CMP)
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
Reserved CMPRIEN CMPFIEN
Type/Reset RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Comparator (CMP)
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved CMPRDEN CMPFDEN
Type/Reset RW 0 RW 0
7 6 5 4 3 2 1 0
Reserved CMPRF CMPFF
Type/Reset WC 0 WC 0
Introduction
The General-Purpose Timer consists of one 16-bit up/down-counter, four 16-bit Capture/
Compare Registers (CCRs), one 16-bit Counter-Reload Register (CRR) and several control/status
registers. It can be used for a variety of purposes including general timer, input signal pulse width
fCLKIN UEV1G
TME
ITI0 TEV
Colck Master MTO
TRCED STIED UEV1
ITI1 Controller Controller
Edge
Detector CHxOREF To other Times
ITI2 CLKPULSE (x = 0 ~ 3) To ADC
TI0BED CEVx
MDCFR
Register
TEV : Trigger Event
MEV0
XOR TI0S0ED
TI0 Input Filter CEV0
& Polarity Selection CH0 CH0 Capture/Compare CH0OREF Output
TI0S1ED GT_CH0O
& Edge Detection PRESCALER Register (CH0CCR) Control
GT_CH0
TI1S0ED MEV1
TI1 Input Filter
GT_CH1 & Polarity Selection
CEV1
TI1S1ED CH1 CH1 Capture/Compare CH1OREF Output
& Edge Detection GT_CH1O
PRESCALER Register (CH1CCR) Control
MEV2
Input Filter
TI2S2ED CEV2
TI2 CH2OREF
GT_CH2 & Polarity Selection CH2 CH2 Capture/Compare Output
& Edge Detection
TI2S3ED PRESCALER Register (CH2CCR) Control GT_CH2O
TI3S2ED MEV3
Input Filter
TI3 CEV3
GT_CH3 & Polarity Selection
TI3S3ED CH3 CH3 Capture/Compare CH3OREF Output
& Edge Detection
PRESCALER GT_CH3O
Register (CH3CCR) Control
TRCED
Features
▄▄ 16-bit up/down auto-reload counter
▄▄ 16-bit programmable prescaler that allows division of the counter clock frequency by any factor
between 1 and 65536
▄
▄ Up to 4 independent channels for:
●● Input Capture function
●● Compare Match Output
Functional Descriptions
Counter Mode
Up-Counting
In this mode the counter counts continuously from 0 to the counter-reload value, which is defined
in the CRR register, in a count-up direction. Once the counter reaches the counter-reload value,
the Timer Module generates an overflow event and the counter restarts to count once again from
0. This action will continue repeatedly. The counting direction bit DIR in the CNTCFR register
When the update event is generated by setting the UEVG bit in the EVGR register to 1, the counter
value will also be initialized to 0.
CK_PSC
CNT_EN
CK_CNT
CNTR F2 F3 F4 F5 0 1 2 3
CRR F5 36
CRR Shadow Register F5 36
PSCR 0 1
PSCR Shadow Register 0 1
PSC_CNT 0 0 1 0 1 0 1 0 1
Counter Overflow
Down-Counting
In this mode the counter counts continuously from the counter-reload value, which is defined in
the CRR register, to 0 in a count-down direction. Once the counter reaches 0, the Timer module
generates an underflow event and the counter restarts to count once again from the counter-reload
value. This action will continue repeatedly. The counting direction bit DIR in the CNTCFR register
should be set to 1 for the down-counting mode.
When the update event is set by the UEVG bit in the EVGR register, the counter value will also be
initialized to the counter-reload value.
CNT_EN
CK_CNT
CNTR 3 2 1 0 36 35 34 33
CRR F5 36
CRR Shadow Register F5 36
PSCR 0 1
PSCR Shadow Register 0 1
PSC_CNT 0 0 1 0 1 0 1 0 1
Counter Underflow
Center-Align Counting
In the center-aligned counting mode, the counter counts up from 0 to the counter-reload value
and then counts down to 0 alternatively. The Timer module generates an overflow event when the
counter counts to the counter-reload value in the up-counting mode and generates an underflow
event when the counter counts to 0 in the down-counting mode. The counting direction bit DIR in
the CNTCFR register is read-only and indicates the counting direction when in the center-align
mode. The counting direction is updated by hardware automatically.
Setting the UEVG bit in the EVGR register will initialize the counter value to 0 irrespective of
The UEVIF bit in the INTSR register can be set to 1 when an overflow or underflow event or both
of them occur according to the CMSEL field setting in the CNTCFR register.
CK_PSC
CNT_EN
CK_CNT
CNTR F2 F3 F4 4 3 2 1 0 1 2 3
CRR F5 4
CRR Shadow Register F5 4
Counter Overflow
Counter Underflow
Update Event Flag
Clock Controller
The following describes the Timer Module clock controller which determines the clock source of
the internal prescaler counter.
▄▄ Internal APB clock fCLKIN:
The default internal clock source is the APB clock fCLKIN used to drive the counter prescaler
when the slave mode is disabled. If the slave mode controller is enabled by setting SMSEL field
in the MDCFR register to an available value including 0x1, 0x2, 0x3 and 0x7, the prescaler is
PSCR CRR
TRSEL
SMSEL
ECME
Start/Stop
Overflow / Slave Restart
Underflow UEVG bit mode trigger
Trigger Controller
The trigger controller is used to select the trigger source and setup the trigger level or edge trigger
condition. For the internal trigger input, it can be selected by the Trigger Selection bits TRSEL in
the TRCFR register. For all the trigger sources except the UEVG bit software trigger, the internal
edge detection circuitry will generate a clock pulse at each trigger signal rising edge to stimulate
some GPTM functions which are triggered by a trigger signal rising edge.
ITI2ED
fCLKIN
TRCED
Level Trigger Source = Internal (ITIx) + Channel input (TIn) + Software UEV1G bit
SW Set Level Trigger Mux
UEV1G Bit 000
TI0S0 001
TI1S1 010
Reserved 011
Reserved others
STI_S0
TRSEL[2:0]
0 000
ITI0 001 0
ITI1 010 STI_S1 STI
1
ITI2 011
Reserved others
TRSEL[3]
Slave Controller
The GPTM can be synchronized with an external trigger in several modes including the Restart
mode, the Pause mode and the Trigger mode which is selected by the SMSEL field in the MDCFR
register. The trigger input of these modes comes from the STI signal which is selected by the
TRSEL field in the TRCFR register. The operation modes in the Slave Controller are described in
the accompanying sections.
Restart Mode
The counter and its prescaler can be reinitialized in response to a rising edge of the STI signal.
When a STI rising edge occurs, the update event software generation bit named UEVG will
automatically be asserted by hardware and the trigger event flag will also be set. Then the counter
and prescaler will be reinitialized. Although the UEVG bit is set to 1 by hardware, the update event
does not really occur. It depends upon whether the update event disable control bit UEVDIS is set
to 1 or not. If the UEVDIS is set to 1 to disable the update event to occur, there will no update event
be generated, however the counter and prescaler are still reinitialized when the STI rising edge
occurs. If the UEVDIS bit in the CNTCFR register is cleared to enable the update event to occur,
an update event will be generated together with the STI rising edge, then all the preloaded registers
will be updated.
STI Sync.
CK_CNT
TEVIF
Pause Mode
In the Pause Mode, the selected STI input signal level is used to control the counter start/stop
operation. The counter starts to count when the selected STI signal is at a high level and stops
counting when the STI signal is changed to a low level, here the counter will maintain its present
value and will not be reset. Since the Pause function depends upon the STI level to control the
counter stop/start operation, the selected STI trigger signal can not be derived from the TI0BED
signal.
STI Sync
Sync
CK_ CNT
CNT_ EN
CNTR 27 28 29 30 31
TEVIF
Software clearing
Trigger Mode
After the counter is disabled to count, the counter can resume counting when a STI rising edge
signal occurs. When an STI rising edge occurs, the counter will start to count from the current
value in the counter. Note that if the STI signal is selected to be derived from the UEVG bit
software trigger, the counter will not resume counting. When software triggering using the UEVG
bit is selected as the STI source signal, there will be no clock pulse generated which can be used to
make the counter resume counting. Note that the STI signal is only used to enable the counter to
resume counting and has no effect on controlling the counter to stop counting.
STI
Sync
CK_CNT
CNT_EN
CNTR
27 28 29 30 31 32
(Up-counting)
TEVIF
Software clearing
Master Controller
The GPTMs and MCTMs can be linked together internally for timer synchronization or chaining.
When one GPTM is configured to be in the Master Mode, the GPTM Master Controller will
generate a Master Trigger Output (MTO) signal which includes a reset, a start, a stop signal or
a clock source which is selected by the MMSEL field in the MDCFR register to trigger or drive
another GPTM or MCTM, if exists, which is configured in the Slave Mode.
MMSEL SMSEL
MTO ITI
TSE TRSEL
The Master Mode Selection bits, MMSEL, in the MDCFR register are used to select the MTO
source for synchronizing another slave GPTM or MCTM if exists.
UEVG bit
Counter enable signal
Update Event
Channel 0 Capture/Compare event
MUX
MTO
CH0OREF
CH1OREF
CH2OREF
CH3OREF
MMSEL
For example, setting the MMSEL field to 0x5 is to select the CH1OREF signal as the MTO signal
to synchronize another slave GPTM or MCTM. For a more detailed description, refer to the related
MMSEL field definitions in the MDCFR register.
Channel Controller
The GPTM has four independent channels which can be used as capture inputs or compare match
outputs. Each capture input or compare match output channel is composed of a preload register and
a shadow register. Data access of the APB bus is always through the read/write preload register.
When used in the input capture mode, the counter value is captured into the CHxCCR shadow
register first and then transferred into the CHxCCR preload register when the capture event occurs.
When used in the compare match output mode, the contents of the CHxCCR preload register is
CHxCCR
CHxPSC (Preload Register) Write CHxCCR
CHxCCR
(Shadow Register)
CHxCCS CHxCCS
CHxCCG Capture
CHxPRE
CHxE CHxCCR
TM_CNT
GT_CH0
(TI0)
CNTR 25 26 27 28 29 30 31 32 33 34 35
CHxCCR 0 26 32
CHxCCIF
CHxOCF
GT_CH0
(TI0)
CNTR 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
CH0CCR 7
CH1CCR 4
Input Stage
The input stage consists of a digital filter, a channel polarity selection, edge detection and a
channel prescaler. The channel 0 input signal (TI0) can be chosen to come from the GT_CH0
signal or the Excusive-OR function of the GT_CH0, GT_CH1 and GT_CH2 signals. The channel
input signal (TIx) is sampled by a digital filter to generate a filtered input signal TIxFP. Then the
channel polarity and the edge detection block can generate a TIxS0ED or TIxS1ED signal for the
input capture function. The effective input event number can be set by the channel input prescaler
register (CHxPSC).
GT_CH2 Edge
Detection
fCLKIN CH0CCS
TI0S1
Edge TI0S1ED
Detection
CH1P
CH1PRESCALER CH1PSC
TI1S1 Edge TI1S1ED CH1CAP Event
TI1 TI1FP TI1FN Detection
GT_CH1 Filter
fsampling CH1PSC
TI1F
CH1CCS
TRCED
fCLKIN CH2CCS
TI2
GT_CH2 TI2FP
Filter TI2S2 Edge
fsampling TI2FN Detection
TI2S2ED
TI2F CH2PSC
CH2P CH2PRESCALER
CH2CAP Event
TI3F CH3PSC
CH3CCS
Digital Filter
The digital filters are embedded in the input stage for the GT_CH0 ~ GT_CH3 pins respectively.
The digital filter in the GPTM is an N-event counter where N refers to how many valid transitions
are necessary to output a filtered signal. The N value can be 0, 2, 4, 5, 6 or 8 according to the user
selection for each filter.
TI0
D Q D Q D Q J Q
Filtered
CK
CK CK CK K
fSYSTEM fsampling
Quadrature Decoder
The Quadrature Decoder function uses two quadrantal inputs TI0 and TI1 derived from the GT_
CH0 and GT_CH1 pins respectively to interact to generate the counter value. The DIR bit is
modified by hardware automatically during each input source transition. The input source can be
either TI0 only, TI1 only or both TI0 and TI1, the selection made by setting the SMSEL field to
0x01, 0x02 or 0x03. The mechanism for changing the counter direction is shown in the following
table. The Quadrature decoder can be regarded as an external clock with a directional selection.
This means that the counter counts continuously in the interval between 0 and the counter-reload
TRCED
TI0SRC
fCLKIN
Edge
GT_CH0 Detection
TI0S1 TI0S1ED
Edge
Detection
CH1P CH1PSC
CH1PRESCALER
CH1CAP Event
TI1 TI1S1 Edge TI1S1ED
GT_CH1 TI1FP TI1FN Detection
Filter CH1PSC
fsampling
TI1F CH1CCS
TI1S0
TI1S1
TI0S0ED
Quadrature
TI1S0ED Decoder
TI0S1ED
TI1S1ED
SMSEL
TI0
TI1
Up
Output Stage
The GPTM has four channels for compare match, single pulse or PWM output function. The
channel output GT_CHxO is controlled by the CHxOM, CHxP and CHxE bits in the corresponding
CHxOCFR, CHPOLR and CHCTR registers.
CHxOREF
Output Enable
CNTR GT_CHxO
CHxCMP Event
CHxOM
x: 0 ~ 3
CHxCCR
(New value 2)
CHxCCR
(New value 3)
CHxCCR
Time
Update
CHxCCR value (1) (2) (3)
TME
CHxOREF
UEV
(Update Event)
CHxCCR
(New value 2)
CHxCCR
(New value 3)
CHxCCR
(New value 1)
CHxCCR
Time
Update
CHxCCR value (1) (2) (3)
TME
CHxOREF
UEV
(Update Event)
CHxCCR
CHxCCIF
CHxCCIF CHxCCIF
CHxOM = 0x07
CHxOREF
Figure 58. PWM Mode Channel Output Reference Signal and Counter in Up-counting Mode
CRR CRR
CHxCCR
CHxCCIF CHxCCIF
CHxOM = 0x07
CHxOREF
Figure 59. PWM Mode Channel Output Reference Signal and Counter in Down-counting Mode
0 1 2 3 4 5 4 3 2 1 0 1
CHxCCR = 3
CHxCCR = 4
CHxCCIF
CHxCCIF
CHxCCR = 0 0%
CHxCCIF
Figure 60. PWM Mode Channel Output Reference Signal and Counter in Centre-align Mode
Update Management
The Update event is used to update the CRR, the PSCR, the CHxACR and the CHxCCR values
from the actual registers to the corresponding shadow registers. An update event occurs when the
counter overflows or underflows, the software update control bit is triggered or an update event
from the slave controller is generated.
The UEVDIS bit in the CNTCFR register can determine whether the update event occurs or
not. When the update event occurs, the corresponding update event interrupt will be generated
UEVDIS
UGDIS
CRR
CHxCCR
Counter
reinitialized Counter stopped and
held
Time
TME bit
Trigger by STI
Cleared by Trigger by S/W Cleared by S/W
Update Event
STI
CHxOREF
(PWM1) delay delay
CHxIMAE=0
delay delay
(PWM2)
CHxCCIF
In the Single Pulse mode, the STI active edge which sets the TME bit to 1 will enable the counter.
However, there exist several clock delays to perform the comparison result between the counter
value and the CHxCCR value. In order to reduce the delay to a minimum value, the user can set
the CHxIMAE bit in each CHxOCFR register. After a STI rising edge trigger occurs in the single
pulse mode, the CHxOREF signal will immediately be forced to the state which the CHxOREF
signal will change to as the compare match event occurs without taking the comparison result into
account. The CHxIMAE bit is available only when the output channel is configured to operate in
the PWM1 or PWM2 output mode and the trigger source is derived from the STI signal.
CRR 6
CHxCCR 4
0
Time
CK_CNT
ITIx
STI
TME
Counter Start Time
CHxIMAE
CHxOREF
(PWM1)
Minimum delay
(PWM2)
CNTR 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
CCR = 8
PWM center align mode
CRR = 8
CCR = 3, ACR = X
CCR = 3
CHxOREF
CHxOREF
CHxOREF
CHxOREF
Figure 64. Asymmetric PWM mode versus center align counting mode
Timer Interconnection
The timers can be internally connected together for timer chaining or synchronization. This can
be implemented by configuring one timer to operate in the Master mode while configuring another
timer to be in the Slave mode. The following figures present several examples of trigger selection
for the master and slave modes.
Master GPTM0
fCLKIN
GPTM0
CH0OREF
GPTM0
CNTR 32 33 34 35 36 00 01
Slave GPTM1
GPTM1
CNTR FA FB FC FD
GPTM1
TEVIF
Software cleaning
GPTM0
UEVIF
GPTM0
CNTR 13 14 15 00 01 02 03
GPTM1
CNTR FA FB FC FD
GPTM1
TME bit
GPTM1
TEVIF
Software cleaning
Master GPTM0
fDTS=fCLKIN
TI0
TI0FP
TI0S0ED
GPTM0 (TEVIF)
TSE=1
GPTM0 CK_PSC Delay
GPTM0 CNTR 34 0 1 2 3 4 5
Write UEVG bit
ITI
Slave GPTM1
GPTM1 (TME bit)
GPTM1 (TEVIF)
GPTM1 CK_PSC
GPTM1 CNTR 11 0 0 1 2 3 4 5
Write UEVG bit
Figure 67. Trigger GPTM0 and GPTM1 with the GPTM0 CH0 Input
PDMA Request
The GPTM supports the interface for PDMA data transfer. There are certain events which can
generate the PDMA requests if the corresponding enable control bits are set to 1 to enable the
CHCCDS
CH0CCDE
CH0_EV 0
CH0 PDMA Request
UEV_EV 1
CH1CCDE
CH1_EV 0
CH1 PDMA Request
UEV_EV 1
CH2CCDE
CH2_EV 0
CH2 PDMA Request
UEV_EV 1
CH3CCDE
CH3_EV 0
CH3 PDMA Request
UEV_EV 1
UEV_EV
UEV PDMA Request
UEVDE
TRIG_EV
Trigger PDMA Request
TEVDE
Register Map
The following table shows the GPTM registers and reset values.
Table 32. GPTM Register Map
Register Offset Description Reset Value
CNTCFR 0x000 Timer Counter Configuration Register 0x0000_0000
MDCFR 0x004 Timer Mode Configuration Register 0x0000_0000
TRCFR 0x008 Timer Trigger Configuration Register 0x0000_0000
Register Descriptions
Timer Counter Configuration Register – CNTCFR
This register specifies the GPTM counter configuration.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved SPMSET
Type/Reset RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
TI0SRC Reserved
Type/Reset RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved TEVDE Reserved UEVDE
Type/Reset RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The Basic Function Timer Module, BFTM, is a 32-bit up-counting counter designed to measure
time intervals, generate one shot or generate repetitive interrupts. The BFTM can operate in two
modes which are repetitive and one shot modes. The repetitive mode restarts the counter at each
Counter OSM
Controller To A/D Converter
EN CLR MIF
BFTM APB To NVIC
clock 32-bit Up Counter Comparator
MIEN
BFTMCNTR BFTMCMPR
Features
▄▄ 32-bit up-counting counter
▄▄ Compare Match function
▄▄ Includes debug mode
▄▄ Clock source: BFTM APB clock
▄▄ Counter value can be R/W on the fly
▄▄ One shot mode: counter stops counting when compare match occurs
▄▄ Repetitive mode: counter restarts when compare match occurs
▄▄ Compare Match interrupt enable/disable control
Functional Description
The BFTM is a 32-bit up-counting counter which is driven by the BFTM APB clock, PCLK. The
counter value can be changed or read at any time even when the timer is counting. The BFTM
supports two operating modes known as the repetitive mode and one shot mode allowing the
measurement of time intervals or the generation of periodic time durations.
Repetitive Mode
0xFFFF_FFFF
CMP
MIF
CEN
: Cleared by hardware
CNT
Time
MIF
CEN
0xFFFF_FFFF
CMP
CNT
Time
MIF
CEN
Register Map
The following table shows the BFTM registers and their reset values.
Table 34. BFTM Register Map
Register Offset Description Reset Value
BFTMCR 0x000 BFTM Control Register 0x0000_0000
BFTMSR 0x004 BFTM Status Register 0x0000_0000
BFTMCNTR 0x008 BFTM Counter Value Register 0x0000_0000
Register Descriptions
BFTM Control Register – BFTMCR
This register specifies the overall BFTM control bits.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
Reserved CEN OSM MIEN
Type/Reset RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
CNT
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
CMP
Type/Reset RW 1 RW 1 RW 1 RW 1 RW 1 RW 1 RW 1 RW 1
Introduction
The Motor Control Timer consists of one 16-bit up/down-counter, four 16-bit Capture/Compare
Registers (CCRs), one 16-bit Counter-Reload Register (CRR), one 8-bit Repetition Counter (REPR)
and several control/status registers. It can be used for a variety of purposes which include general
fCLKIN UEV1G
ITI0
TEV TME
TRCED Colck
ITI1 Edge
Colck
Master MTO
Controller
Controller
UEV1 Master
MDCFR
MDCFR
Register
Register
TI0S0 Controller
Controller
BEV : Break Event
REPR
REPR
Restart Reload
Reload
Register
Register
Trigger
Up/Dn Repetition
Down-Counter
Register
Register
Registers
Registers
MEV0
XOR TI0S0ED
TI0 Input Filter CEV0
& Polarity Selection CH0 CH0 Capture/Compare CH0OREF Output MT_CH0O
TI0S1ED DTG
& Edge Detection PRESCALER Register (CH0CCR) Control MT_CH0NO
MT_CH0
TI1S0ED MEV1
TI1 Input Filter
MT_CH1 & Polarity Selection CEV1
TI1S1ED CH1 CH1 Capture/Compare CH1OREF Output MT_CH1O
& Edge Detection DTG
PRESCALER Register (CH1CCR) Control MT_CH1NO
MEV2
Input Filter TI2S2ED CEV2
TI2 CH2OREF MT_CH2O
MT_CH2 & Polarity Selection CH2 CH1 Capture/Compare Output
TI2S3ED DTG
& Edge Detection PRESCALER Register (CH2CCR) Control MT_CH2NO
TI3S2ED MEV3
Input Filter
TI3 CEV3
MT_CH3 & Polarity Selection
TI3S3ED CH3 CH1 Capture/Compare CH3OREF Output
& Edge Detection MT_CH3O
PRESCALER Register (CH3CCR) Control
TRCED
MT_BRK Input Polarity &
MT_BRK Filter
BEV
Clock Failure Event
CMPx Transition
Event
Features
▄▄ 16-bit up/down auto-reload counter.
▄▄ 16-bit programmable prescaler that allows division the counter clock frequency by any factor
between 1 and 65536.
▄
▄ Up to 4 independent channels for:
●● Input Capture function
●● Compare Match Output
Functional Descriptions
Counter Mode
Up-Counting
In this mode the counter counts continuously from 0 to the counter-reload value, which is defined
in the CRR register, in a count-up direction. Once the counter reaches the counter-reload value,
the Timer Module generates an overflow event and the counter restarts to count once again from
0. This action will continue repeatedly. The counting direction bit DIR in the CNTCFR register
When an update event 1 is generated by setting the UEV1G bit in the EVGR register to 1, the
counter value will also be initialised to 0.
CK_PSC
CNT_EN
CK_CNT
CNTR F2 F3 F4 F5 0 1 2 3
CRR F5 36
CRR Shadow Register F5 36
PSCR 0 1
PSCR Shadow Register 0 1
PSC_CNT 0 0 1 0 1 0 1 0 1
Counter Overflow
Down-Counting
In this mode the counter counts continuously from the counter-reload value, which is defined in
the CRR register, to 0 in a count-down direction. Once the counter reaches 0, the Timer module
generates an underflow event and the counter restarts to count once again from the counter-reload
value. This action will continue repeatedly. The counting direction bit DIR in the CNTCFR register
should be set to 1 for the down-counting mode.
When an update event 1 is generated by setting the UEV1G bit in the EVGR register to 1, the
counter value will also be initialised to the counter-reload value.
CNT_EN
CK_CNT
CNTR 3 2 1 0 36 35 34 33
CRR F5 36
CRR Shadow Register F5 36
PSCR 0 1
PSCR Shadow Register 0 1
PSC_CNT 0 0 1 0 1 0 1 0 1
Counter Underflow
Center-aligned Counting
In the center-aligned counting mode, the counter counts up from 0 to the counter-reload value
and then counts down to 0 alternatively. The Timer Module generates an overflow event when the
counter counts to the counter-reload value in the up-counting mode and generates an underflow
event when the counter counts to 0 in the down-counting mode. The counting direction bit DIR
in the CNTCFR register is read-only and indicates the count direction when in the center-aligned
counting mode. The count direction is updated by hardware automatically.
Setting the UEV1G bit in the EVGR register will initialise the counter value to 0 irrespective of
The UEV1IF bit in the INTSR register can be set to 1 according to the CMSEL field setting in
the CNTCFR register. When CMSEL=0x01, an underflow event will set the UEV1IF bit to 1.
When CMSEL=0x10, an overflow event will set the UEV1IF bit to 1. When CMSEL=0x11, either
underflow or overflow event will set the UEV1IF bit to 1.
CK_PSC
CNT_EN
CK_CNT
CNTR F2 F3 F4 4 3 2 1 0 1 2 3
CRR F5 4
CRR Shadow Register F5 4
Counter Overflow
Counter Underflow
CK_CNT
Up-Counting
CNTR 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4
REPR 1
Down-Counting
CNTR 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3
REPR 2
Center-Aligned-Counting
CK_CNT
CNTR 2 3 4 3 2 1 0 1 2 3 4 3 2 1 0 1 2 3 4 3 2 1 0
REPR 1
REPR Counter = 1 REPR Counter = 0 REPR Counter = 1 REPR Counter = 0 REPR Counter = 1 REPR Counter = 0
UEV1
Clock Controller
The following describes the Timer Module clock controller which determines the internal prescaler
counter clock source.
▄▄ Internal APB clock fCLKIN
The default internal clock source is the APB clock fCLKIN which is used to drive the counter pr-
escaler when the slave mode is disabled. When the slave mode selection bits SMSEL are set to
0x4, 0x5 or 0x6, the internal APB clock fCLKIN is the counter prescaler driving clock source.
REPR
PSCR CRR
Repetition Down
Dec
Counter
Update Event 1
fCLKIN
(Slave mode disable) CK_PSC CK_CNT
CLK CLK
STIED PSC Prescaler CNTR
(Trigger events) Reset Reset TM_CNT
TRSEL
SMSEL
ECME
Trigger Controller
The trigger controller is used to select the trigger source and setup the trigger level and edge trigger
conditions. For the internal trigger input (ITIx), it can be selected by the Trigger Selection bits,
TRSEL, in the TRCFR register. For all the trigger sources except the UEV1G bit software trigger,
the internal edge detection circuitry will generate a clock pulse at each trigger signal rising edge to
activate some MCTM functions which are triggered by a trigger signal rising edge.
ITI2ED
fCLKIN
TRSEL[2:0]
TI0BED 000
ITI0ED 001 0
STIED
ITI1ED 010 STIED_S1 1
ITI2ED 011
Reserved others
TRSEL[3]
TRCED
Level Trigger Source = Internal (ITIx) + Channel input (TIn) + Software UEV1G bit
Slave Controller
The MCTM can be synchronised with an internal/external trigger in several modes including the
Restart mode, the Pause mode and the Trigger mode which are selected by the SMSEL field in the
MDCFR register. The trigger input of these modes comes from the STI signal which is selected by
the TRSEL field in the TRCFR register. The operation modes in the Slave Controller are described
in the accompanying sections.
Restart Mode
The counter and its prescaler can be reinitialised in response to an STI signal rising edge. If
the UEV1DIS bit is set to 1 to disable the update event, then no update event will be generated,
however the counter and prescaler are still reinitialized when an STI rising edge occurs. If the
UEV1DIS bit in the CNTCFR register is cleared to enable the update event, then an update event
will be generated together with the STI rising edge and all the preloaded registers will be updated.
STI Sync.
CK_CNT
UEV1G bit
(reset counter) Trigger Event
CNTR
27 28 29 30 31 0 1 2
(Up-counting)
CNTR
27 26 25 24 23 32 31 30
(Down-counting)
TEVIF
Pause Mode
In the Pause Mode, the selected STI input signal level is used to control the counter start/stop
operation. The counter starts to count when the selected STI signal is at a high level and stops
counting when the STI signal is changed to a low level. When the counter stops, it will maintain its
present value and not be reset. Since the Pause function depends upon the STI level to control the
counter stop/start operation, the selected STI trigger signal can not be derived from the TI0BED
signal.
STI Sync
Sync
CK_ CNT
CNT_ EN
CNTR 27 28 29 30 31
TEVIF
Software clearing
Trigger Mode
After the counter is disabled to count, the counter can resume counting when an STI rising edge
signal occurs. When an STI rising edge occurs, the counter will start to count from the current
value in the counter. Note that if the STI signal is selected to be sourced from the UEV1G bit
software trigger, the counter will not resume counting. When software triggering using the UEV1G
bit is selected as the STI source signal, there will be no clock pulse generated which can be used to
make the counter resume counting. Note that the STI signal is only used to enable the counter to
resume counting and has no effect to stop counting.
STI
Sync
CK_CNT
CNT_EN
CNTR
27 28 29 30 31 32
(Up-counting)
TEVIF
Software clearing
Master Controller
The MCTMs and GPTMs can be linked together internally for timer synchronisation or chaining.
When one MCTM is configured to be in the Master Mode, the MCTM Master Controller will
generate a Master Trigger Output (MTO) signal which can reset, restart, stop the Slave counter or
be a clock source of the Slave Counter. This can be selected by the MMSEL field in the MDCFR
register to trigger or drive another MCTM or GPTM which should be configured in the Slave
Mode.
MMSEL SMSEL
MTO ITI
TSE TRSEL
The Master Mode Selection bits, MMSEL, in the MDCFR register are used to select the MTO
source for synchronising another slave MCTM or GPTM.
UEV1G bit
Counter enable signal
Update Event 1
Channel 0 Capture/Compare event
MUX
MTO
CH0OREF
CH1OREF
CH2OREF
CH3OREF
MMSEL
For example, setting the MMSEL field to 0x5 is to select the CH1OREF signal as the MTO signal
to synchronise another slave MCTM or GPTM. For a more detailed description, refer to the related
MMSEL field definitions in the MDCFR register.
Channel Controller
The MCTM has four independent channels which can be used as capture inputs or compare match
outputs. Each capture input or compare match output channel is composed of a preload register
and a shadow register. Data access of the APB bus is always implemented through the read/write
preload register.
When used in the input capture mode, the counter value is captured into the CHxCCR shadow
register first and then transferred into the CHxCCR preload register when the capture event occurs.
CHxCCR
CHxPSC (Preload Register) Write CHxCCR
CHxCCR
(Shadow Register)
CHxCCS CHxCCS
CHxCCG Capture
CHxPRE
CHxE CHxCCR
TM_CNT
CNTR 25 26 27 28 29 30 31 32 33 34 35
CHxCCR 0 26 32
CHxCCIF
CHxOCF
MT_CH0
(TI0)
CNTR 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6
CH0CCR 7
CH1CCR 4
Input Stage
The input stage consists of a digital filter, a channel polarity selection, edge detection and a channel
prescaler. The channel 0 input signal TI0 can be chosen to come from the MT_CH0 signal or the
Excusive-OR function of the MT_CH0, MT_CH1 and MT_CH2 signals. The channel input signal
TIx is sampled by a digital filter to generate a filtered input signal TIxFP. Then the channel polarity
and the edge detection block can generate a TIxSxED signal for the input capture function. The
effective input event number can be set by the channel input prescaler register CHxPSC.
MT_CH2 Edge
Detection
fCLKIN CH0CCS
TI0S1
Edge TI0S1ED
Detection
CH1P
CH1PRESCALER CH1PSC
TI1S1 Edge TI1S1ED CH1CAP Event
TI1 TI1FP TI1FN
MT_CH1 Detection
Filter
fsampling CH1PSC
TI1F
CH1CCS
TRCED
fCLKIN CH2CCS
TI2
MT_CH2 TI2FP
Filter TI2S2 Edge
fsampling TI2FN Detection
TI2S2ED
TI2F CH2PSC
CH2P CH2PRESCALER
CH2CAP Event
TI2S3
Edge TI2S3ED
Detection
CH3P
TI3 CH3PSC
MT_CH3 TI3FP CH3PRESCALER
Filter TI3S3 Edge CH3CAP Event
fsampling TI3FN Detection
TI3S3ED
TI3F CH3PSC
CH3CCS
Digital Filter
The digital filters are embedded in the input stage and clock controller block for the MT_CH0 ~
MT_CH3 pins. The digital filter in the MCTM is an N-event counter where N refers to how many
valid transitions are necessary to output a filtered signal. The N value can be 0, 2, 4, 5, 6 or 8
according to the selection for each filter.
No Filtered
Digital Filter (N=2)
Output Stage
The MCTM supports complementary outputs for channels 0, 1 and 2 with dead time insertion. The
MCTM channel 3 output function is almost the same as that of GPTM channel 3 except for the
break function.
The channel outputs, CHxO and CHxNO, are referenced to the CHxOREF signal. These channel
outputs generate a wide variety of wide waveforms according to the configuration values of
corresponding control bits, as shown by the dashed box in the diagram.
Output Enable
CNTR Controller CH3O
Output Mode
CH3CCR Controller CH3E CHMOE
CH3P
CH3OIS
fCLKIN CH3OCREF
CH3CMP Event
CH3OM
Counter Value
CHxOM=0x03, CHxPRE=0
(Output toggle, preload disable)
CRR
CHxCCR
(New value 2)
CHxCCR
(New value 3)
CHxCCR
(New value 1)
CHxCCR
Time
Update
CHxCCR value (1) (2) (3)
TME
CHxOREF
UEV1
(Update Event 1)
CHxCCR
(New value 2)
CHxCCR
(New value 3)
CHxCCR
CHxCCR
Time
Update
CHxCCR value (1) (2) (3)
TME
CHxOREF
UEV1
(Update Event 1)
CHxCCR
CHxCCR
= 0x00
CHxOM = 0x06
100%
CHxOREF CHxOREF CHxOREF 0%
Figure 95. PWM Mode Channel Output Reference Signal and Counter in Up-counting Mode
CRR CRR
CHxCCR
CHxCCIF CHxCCIF
CHxOM = 0x07
CHxOREF CHxOREF
0%
Figure 96. PWM Mode Channel Output Reference Signal and Counter in Down-counting Mode
0 1 2 3 4 5 4 3 2 1 0 1
CHxCCR = 3
CHxCCIF
CHxCCR = 4
CHxCCIF
CHxCCIF
CHxCCR = 0 0%
CHxCCIF
Figure 97. PWM Mode 1 Channel Output Reference Signal and Counter in Centre-aligned
Counting Mode
CHxOREF
Dead-time
CHxO
CHxNO
Dead-time
CHxNO
CHxOCREF
dead-time
CHxOC
dead-time
CHxNOC
dead-time
CHxNOC
If the delay is greater than the width of the active output of CHxO or CHxNO, then the
corresponding PWM pulses will not be generated.
Break Function
The MCTM includes break function and one input signals for MCTM break. The MT_BRK is default
function and from external MT_BRK pin. The detail block diagram is shown as below figure.
Output
BKP BKF BKE BRKG BRKIF Stage
When the MT_BRK input has an active level or the Clock Monitor Circuitry detects a clock failure
event, a break event will be generated if the break function is enabled. Meanwhile, each channel
output will be forced to a reset state, an inactive or idle state. Moreover, a break event can also be
generated by the software asserting the BRKG bit in the EVGR register even if the break function
is disabled.
The MT_BRK input signal can be enabled by setting the BKE bit in the CHBRKCTR register. The
break input polarity can be selected by setting the BKP bit in CHBRKCTR register. The BKE and
BKP bits can be modified at the same time.
The digital filters are embedded in the input stage and clock controller block for the break
signal. The input filter of the MT_BRK signal can be enabled by by setting the BKF bits in the
CHBRKCTR register. The digital filter is an N-event counter where N refers to how many valid
transitions are necessary to output a filtered signal.
MT_BRK J Q
D Q D Q D Q Filtered
CK
CK CK CK K
fSYSTEM fsampling
When using the break function, the channel output enable signals and output levels are changed
depending on several control bits which include the CHMOE, CHOSSI, CHOSSR, CHxOIS
and CHxOISN bits. Once a break event occurs, the output enable bit CHMOE will be cleared
asynchronously. The break interrupt f lag, BRKIF, will be set and then an interrupt will be
generated if the break function interrupt is enabled by setting the BRKIE bit to 1. The channel
output behavior is as described below:
▄▄ If complementary outputs are used, the channel outputs a level signal first which can be
selected to be either a disable or inactive level, selected by configuring the CHOSSI bit in the
break event
CHMOE
CHxOREF
CH3P = 0, CH3OIS =0
CH3O
CH3P = 0, CH3OIS =1
CH3O
CH3P = 1, CH3OIS =0
CH3O
CH3P = 1, CH3OIS =1
CH3O
The accompanying diagram shows that the complementary output states when a break event occurs
where the complementary outputs are enabled by setting both the CHxE and CHxNE bits to 1.
Break event
CHMOE
CHxP = 0, CHxOIS =0
CHxO
Dead-
time
CHxNP = 0, CHxOISN =1
CHxNO
Dead-time Dead-time
CHxP = 0, CHxOIS =1
CHxO
Dead-time Dead-time
CHxNO CHxNP = 1, CHxOIS =1
Dead-time
The accompanying diagram shows the output states in the case of the output being enabled by
setting the CHxE bit to 1 and the complementary output being disabled by clearing the CHxNE to
0 when a break event occurs.
Break event
CHMOE
CHxOREF
CHxP = 0, CHxOIS =0
CHxO
Dead-time
CHxNP = 0, CHxOISN =1
CHxNO
Dead-time
CHxP = 0, CHxOIS =1
CHxO
CHxNO
0
Figure 103. Channel 0 ~ 2 Only One Output Enabled when Fault Event Occurs
The CHxO and CHxNO complementary outputs should not be set to an active level at the same
time. The hardware will protect the MCTM circuitry to force only one channel output to be in the
active state.
Example: Both CHxOIS and CHxOISN are set to active levels after a break event; only the CHxO
waveform is generated.
Break event
CHxOREF
CHxP = 0, CHxOIS =0
CHxO
CHxNP = 0, CHxOISN =0
CHxNO
0
CHxP = 0, CHxOIS =1
CHxO
CHxNP = 0, CHxOIS =1
CHxNO
0
Figure 104. Hardware Protection When Both CHxO and CHxNO Are in Active Condition
CHMOE can be set automatically by update event 1 if the automatic output enable function is
enabled by setting the CHAOE bit in the CHBRKCTR register to 1.
Table 36. Output Control Bits for Complementary Output with a Break Event Occurrence
Control bit Output status
MT_CHxN Pin output
CHMOE CHOSSI CHOSSR CHxE CHxNE MT_CHx Pin output state
state
Output disabled - floating Output disabled - floating
- not driven by the timer - not driven by the timer
0 0 0
MT_CHx (Note 1) = floating MT_CHxN = floating
MT_CHx_OEN (Note 2) = 1 MT_CHxN_OEN = 1
Update Management
The update events are categorised into two different types which are the update event 1, UEV1, and
update event 2, UEV2. The update event 1 is used to update the CRR, the PSCR, the CHxACR and
the CHxCCR values from the actual registers to the corresponding shadow registers. An update
event 1 occurs when the counter overflows or underflows, the UEV1G bit is set or the slave restart
mode is triggered. The update event 2 is used to update the CHxE, CHxNE and CHxOM control
bits. An update event 2 is generated when a rising edge on the STI occurs or the corresponding
software update control bit is set.
UEV1DIS
UGDIS
Update Event 2
The CHxE, CHxNE, CHxOM control bits for the complementary outputs can be preloaded by
setting the COMPRE bit in the CTR register. Here the shadow bits of the CHxE, CHxNE, and
CHxOM bits will be updated when an update event 2 occurs.
Update Event 2
CHxNE
Shadow CHxE
Shadow CHxNE
CHxO
CHxNO
An update event 2 can be generated by setting the software update bit, UEV2G, in the EVGR
register or by the rising edge of the STI signal if the COMUS bit is set in the CTR register.
UEV2G
Update Event 2
(Update CHxE/CHxNE/CHxOM)
STI Rising Edge
COMUS
Counter Value
CRR
CHxCCR
Counter
reinitialized Counter stopped
and held
Time
TME bit
Trigger by STI
Cleared by Trigger by S/W Cleared by S/W
Update Event
STI
CHxOREF
(PWM1) delay delay
CHxIMAE=0
delay delay
(PWM2)
CHxCCIF
Flag is set by compare match
and cleared by S/W
In the Single Pulse mode, the STI active edge which sets the TME bit to 1 will enable the counter.
However, there exist several clock delays to perform the comparison result between the counter
value and the CHxCCR value. In order to reduce the delay to a minimum value, users can set the
CHxIMAE bit in each CHxOCFR register. After a STI rising edge trigger occurs in the single
pulse mode, the CHxOREF signal will immediately be forced to the state to which the CHxOREF
signal will change to as the compare match event occurs without taking the comparison result into
account. The CHxIMAE bit is available only when the output channel is configured to operate in
the PWM1 or PWM2 output mode and the trigger source is derived from the STI signal.
CRR 6
CHxCCR 4
0
Time
CK_CNT
ITIx
STI
TME
Counter Start Time
CHxIMAE
CHxOREF
(PWM1)
Minimum delay
(PWM2)
CNTR 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
CCR = 8
PWM center align mode
CRR = 8
CCR = 3, ACR = X
CCR = 3
CHxOREF
CHxOREF
CHxOREF
CHxOREF
Timer Interconnection
The timers can be internally connected together for timer chaining or synchronization. This can
be implemented by configuring one timer to operate in the master mode while configuring another
timer to be in the slave mode. The following figures present several examples of trigger selection
for the master and slave modes.
Master MCTM
fCLKIN
MCTM
CH0OREF
MCTM
CNTR 32 33 34 35 36 00 01
Slave GPTM
GPTM
CNTR FA FB FC FD
GPTM
TEVIF
Software cleaning
fCLKIN
MCTM
UEV1IF
MCTM
CNTR 13 14 15 00 01 02 03
GPTM
CNTR FA FB FC FD
GPTM
TME bit
GPTM
TEVIF
Software cleaning
Master MCTM
f =f
DTS CLKIN
TI0
TI0FP
TI0S0ED
MCTM (TEV1IF)
TSE=1
MCTM CK_PSC Delay
MCTM CNTR 34 0 1 2 3 4 5
Write UEV1G bit
ITI
Slave GPTM
GPTM (TME bit)
GPTM (TEVIF)
GPTM CK_PSC
GPTM CNTR 11 0 0 1 2 3 4 5
Write UEV1G bit
Figure 113. Trigger MCTM and GPTM with the MCTM CH0 Input
Using one timer as a hall sensor interface to trigger another timer with update event 2
GPTM:
▄▄ Configure channel 0 to choose an input XOR function (TI0SRC = 1)
▄▄ Configure channel 0 to be in the input capture mode and TRCED as capture source (CH0CCS=
0x03) and Enable channel 0 (CH0E=1)
▄▄ Configure the UEVG bit as the source of MTO (MMSEL= 0x00)
▄▄ Configure TI0BED to be connected to STI (TRSEL = 0x08)
MCTM:
▄▄ Select GPTM MTO to be the STI source of MCTM (TRSEL = 0x0A)
▄▄ Enable the CHxE, CHxNE and CHxOM preload function (COMPRE = 1)
▄▄ Select the rising edge on STI to generate an update event 2 (COMUS = 1)
▄▄ Enable the update event 2 interrupt (UEV2IE = 1)
▄▄ In the update event 2 ISR: write CHxE, CHxNE and CHxOM register for the next step
GPTM
CH1
CH2
CH3
TI0XOR
1000
CNTR
MTO
Reset
MCTM
UEV2
CH1O
CH1NO
CH2O
CH2NO
CH3O
CH3NO
1. The MCTMEN bit of the APBCCR1 register is located in the CKCU unit and use to control the
clock source of the MCTM unit.
2. The CKMEN bit of the GCCR register is located in the CKCU unit and use to monitor the high
speed external clock (HSE) source. If the CKMEN bit is enabled and when hardware detects
HSE clock stuck at low/high state, internal hardware will automatically switch the system clock
to internal high speed RC clock (HSI) to protect the system safety.
3. When the MCTMEN and CKMEN control bits of the CKCU lock protection mode is enabled in
the MCTM unit, the bits will be allowed to enable only and inhibited to disable again.
PDMA Request
The MCTM has a PDMA data transfer interface. There are certain events which can generate
PDMA requests if the corresponding enable control bits are set to 1 to enable the PDMA access.
These events are the MCTM update events, trigger event and channel capture/compare events.
When the PDMA request is generated from the MCTM channel, it can be derived from the channel
capture/compare event or the MCTM update event 1 selected by the channel PDMA selection
bit, CHCCDS, for all channels. For more detailed PDMA configuring information, refer to the
corresponding section in the PDMA chapter.
CH0_EV 0
CH0 PDMA Request
UEV1_EV 1
CH1CCDE
CH1_EV 0
CH1 PDMA Request
UEV1_EV 1
CH2CCDE
CH2_EV 0
CH2 PDMA Request
UEV1_EV 1
CH3CCDE
CH3_EV 0
CH3 PDMA Request
UEV1_EV 1
UEV1_EV
UEV1 PDMA Request
UEV1DE
UEV2_EV
UEV2 PDMA Request
UEV2DE
TRIG_EV
Trigger PDMA Request
TEVDE
Register Map
The following table shows the MCTM registers and reset values.
Table 38. MCTM Register Map
Register Offset Description Reset Value
CNTCFR 0x000 Timer Counter Configuration Register 0x0000_0000
MDCFR 0x004 Timer Mode Configuration Register 0x0000_0000
TRCFR 0x008 Timer Trigger Configuration Register 0x0000_0000
Register Descriptions
Timer Counter Configuration Register – CNTCFR
This register specifies the MCTM counter configuration.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved SPMSET
Type/Reset RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
TI0SRC Reserved
Type/Reset RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
CHDTG
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved TEVDE UEV2DE UEV1DE
Type/Reset RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The Single-Channel Timer consists of one 16-bit up-counter, one 16-bit Capture/Compare Register
(CCR), one 16-bit Counter-Reload Register (CRR) and several control/status registers. It can be
used for a variety of purposes including general timer, input signal pulse width measurement or
fCLKIN
TEV
Colck
TIBED Colck
Controller
Controller
STIED
TISED
MDCFR
MDCFR
Trigger Register
Register
Reload
Reload
Restart Register
Register
(CRR)
Pause (CRR)
Trigger
MEV
Input Filter TISED CEV
TI CH Channel Capture/Compare CHOREF Output
SCTM_CH & Polarity Selection TIBED SCTM_CHO
PRESCALER Register (CHCCR) Control
& Edge Detection
Features
▄▄ 16-bit auto-reload up counter
▄▄ 16-bit programmable prescaler that allows division of the counter clock frequency by any factor
between 1 and 65536
▄
▄ Single channel for:
●● Input Capture function
●● Compare Match Output
Functional Descriptions
Counter Mode
Up-Counting
The counter counts continuously from 0 to the counter-reload value, which is defined in the
CRR register. Once the counter reaches the counter-reload value, the Timer Module generates
an overflow event and the counter restarts to count once again from 0. This action will continue
repeatedly. When the update event is generated by setting the UEVG bit in the EVGR register to 1,
the counter value will also be initialized to 0.
CK_PSC
CNT_EN
CK_CNT
CNTR F2 F3 F4 F5 0 1 2 3
CRR F5 36
CRR Shadow Register F5 36
PSCR 0 1
PSCR Shadow Register 0 1
PSC_CNT 0 0 1 0 1 0 1 0 1
Counter Overflow
Clock Controller
The following describes the Timer Module clock controller which determines the clock source of
the internal prescaler counter.
▄▄ Internal APB clock fCLKIN
The default internal clock source is the APB clock fCLKIN used to drive the counter prescaler
when the slave mode is disabled. If the slave mode controller is enabled by setting SMSEL field
in the MDCFR register to 0x7, the prescaler is clocked by other clock sources selected by the
PSCR CRR
Update Event
fCLKIN
(Internal APB clock) CK_PSC CK_CNT
CLK CLK
STIED PSC Prescaler CNTR TM_CNT
(Trigger events) Reset Reset
TRSEL
SMSEL
ECME
Start/Stop
Overflow / Slave Restart
Underflow UEVG bit mode trigger
Trigger Controller
The trigger controller is used to select the trigger source and setup the trigger level or edge trigger
condition. For the internal trigger input, it can be selected by the Trigger Selection bits TRSEL in
the TRCFR register. For all the trigger sources except the UEVG bit software trigger, the internal
edge detection circuitry will generate a clock pulse at each trigger signal rising edge to stimulate
some SCTM functions which are triggered by a trigger signal rising edge.
Trigger Controller Block = Edge Trigger Mux + Level Trigger Mux
TRSEL[2:0]
TIBED 000
Reserved 001 0
STIED
Reserved 010 STIED_S1 1
Reserved 011
Reserved others
TRSEL[3]
TRCED
Reserved others
TRSEL[3]
Slave Controller
The SCTM can be synchronized with an external trigger in several modes including the Restart
mode, the Pause mode and the Trigger mode which is selected by the SMSEL field in the MDCFR
register. The trigger input of these modes comes from the STI signal which is selected by the
TRSEL field in the TRCFR register. The operation modes in the Slave Controller are described in
the accompanying sections.
Restart Mode
The counter and its prescaler can be reinitialized in response to a rising edge of the STI signal.
When a STI rising edge occurs, the update event software generation bit named UEVG will
automatically be asserted by hardware and the trigger event flag will also be set. Then the counter
and prescaler will be reinitialized. Although the UEVG bit is set to 1 by hardware, the update event
does not really occur. It depends upon whether the update event disable control bit UEVDIS is set
to 1 or not. If the UEVDIS is set to 1 to disable the update event to occur, there will no update event
be generated, however the counter and prescaler are still reinitialized when the STI rising edge
occurs. If the UEVDIS bit in the CNTCFR register is cleared to enable the update event to occur,
an update event will be generated together with the STI rising edge, then all the preloaded registers
will be updated.
STI Sync.
CK_CNT
Trigger Event
UEVG bit
(reset counter)
CNTR
27 28 29 30 31 0 1 2
(Up-counting)
TEVIF
Pause Mode
In the Pause Mode, the selected STI input signal level is used to control the counter start/stop
operation. The counter starts to count when the selected STI signal is at a high level and stops
counting when the STI signal is changed to a low level, here the counter will maintain its present
value and will not be reset. Since the Pause function depends upon the STI level to control the
counter stop/start operation, the selected STI trigger signal can not be derived from the TIBED
signal.
STI Sync
Sync
CK_ CNT
CNT_ EN
CNTR 27 28 29 30 31
TEVIF
Software clearing
Trigger Mode
After the counter is disabled to count, the counter can resume counting when a STI rising edge
signal occurs. When an STI rising edge occurs, the counter will start to count from the current
value in the counter. Note that if the STI signal is selected to be derived from the UEVG bit
software trigger, the counter will not resume counting. When software triggering using the UEVG
bit is selected as the STI source signal, there will be no clock pulse generated which can be used to
make the counter resume counting. Note that the STI signal is only used to enable the counter to
resume counting and has no effect on controlling the counter to stop counting.
STI
Sync
CK_CNT
CNT_EN
CNTR
27 28 29 30 31 32
(Up-counting)
TEVIF
Software clearing
Channel Controller
The SCTM channel can be used as the capture input or compare match output. The capture input or
compare match output channel is composed of a preload register and a shadow register. Data access
of the APB bus is always through the read/write preload register.
When used in the input capture mode, the counter value is captured into the CHCCR shadow
register first and then transferred into the CHCCR preload register when the capture event occurs.
When used in the compare match output mode, the contents of the CHCCR preload register is
CHCCR
CHPSC (Preload Register) Write CHCCR
Cpature Compare
Capture Transfer Compare Transfer
Controller Controller
Read CHCCR Update Event
CHxCCR
(Shadow Register)
CHCCS CHCCS
CHCCG Capture
CHPRE
CHE CHCCR
TM_CNT
SCTM_CH
CNTR 25 26 27 28 29 30 31 32 33 34 35
CHCCR 0 26 32
CHCCIF
CHOCF
Input Stage
The input stage consists of a digital filter, a channel polarity selection, edge detection and a channel
prescaler. The channel input signal (TI) is sampled by a digital filter to generate a filtered input
signal TIFP. Then the channel polarity and the edge detection block can generate a TISED signal
for the input capture function. The effective input event number can be set by the channel input
prescaler register (CHPSC).
fCLKIN CHPSC
CH PRESCALER
CHCAP Event
TI TIS Edge TISED
SCTM_CH TIFP TIFN
Filter Detection
CHPSC
fsampling CHP
TIF
Digital Filter
The digital filters are embedded in the channel input stage. The digital filter in the SCTM is an
N-event counter where N refers to how many valid transitions are necessary to output a filtered
signal. The N value can be 0, 2, 4, 5, 6 or 8 according to the user selection for this digital filter.
No Filtered
Digital Filter (N=2)
TI
D Q D Q D Q J Q Filtered
CK
CK CK CK K
fSYSTEM fsampling
Output Stage
The SCTM output has function for compare match, single pulse or PWM output. The channel
output SCTM_CHO is controlled by the CHOM, CHP and CHE bits in the corresponding
CHOCFR, CHPOLR and CHCTR registers.
CHOREF
Output Enable
CNTR GT_CHO
fCLKIN
CHOREF
CHCMP Event
CHOM
Counter Value
CHOM=0x03, CHPRE=0
(Output toggle, preload disable)
CRR
CHCCR
(New value 2)
CHCCR
(New value 3)
CHCCR
Time
Update
CHCCR value (1) (2) (3)
TME
CHOREF
UEV
(Update Event)
CHCCR
(New value 2)
CHCCR
(New value 3)
CHCCR
(New value 1)
CHCCR
Time
Update
CHCCR value (1) (2) (3)
TME
CHOREF
UEV
(Update Event)
CHCCR
CHCCIF
CHCCIF CHCCIF
CHOM = 0x07
CHOREF
Update Management
The Update event is used to update the CRR, the PSCR and the CHCCR values from the actual
registers to the corresponding shadow registers. An update event will occur when the counter
overflows, the software update control bit is triggered or an update event from the slave controller
is generated.
The UEVDIS bit in the CNTCFR register can determine whether the update event occurs or
not. When the update event occurs, the corresponding update event interrupt will be generated
depending upon whether the update event interrupt generation function is enabled or not by
configuring the UGDIS bit in the CNTCFR register. For more detailed description, refer to the
UEVDIS and UGDIS bit definition in the CNTCFR register.
UEVDIS
UEVG
UGDIS
Register Map
The following table shows the SCTM registers and reset values.
Table 41. SCTM Register Map
Register Offset Description Reset Value
CNTCFR 0x000 Timer Counter Configuration Register 0x0000_0000
MDCFR 0x004 Timer Mode Configuration Register 0x0000_0000
TRCFR 0x008 Timer Trigger Configuration Register 0x0000_0000
CTR 0x010 Timer Control Register 0x0000_0000
CHICFR 0x020 Channel Input Configuration Register 0x0000_0000
CHOCFR 0x040 Channel Output Configuration Register 0x0000_0000
CHCTR 0x050 Channel Control Register 0x0000_0000
CHPOLR 0x054 Channel Polarity Configuration Register 0x0000_0000
DICTR 0x074 Timer Interrupt Control Register 0x0000_0000
EVGR 0x078 Timer Event Generator Register 0x0000_0000
INTSR 0x07C Timer Interrupt Status Register 0x0000_0000
CNTR 0x080 Timer Counter Register 0x0000_0000
PSCR 0x084 Timer Prescaler Register 0x0000_0000
CRR 0x088 Timer Counter Reload Register 0x0000_FFFF
CHCCR 0x090 Channel Capture/Compare Register 0x0000_0000
Register Descriptions
Timer Counter Configuration Register – CNTCFR
This register specifies the SCTM counter configuration.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The Real Time Clock, RTC, circuitry includes the APB interface, a 32-bit up-counter, a control
register, a prescalmer, a compare register and a status register. Most of the RTC circuits are located
in the Backup Domain, as shown shaded in the accompanying figure, except for the APB interface.
LSE CK_LSE
1
OSC
CK_RTC CK_SECOND set CSECIEN
Prescaler CSECFLAG
LSI RC CK_LSI RTCINT
0
OSC OVIEN
( To NVIC )
RTCSRC CMPCLR
CMIEN
set
ISO 32 bits counter OVFLAG
32
match CSECWEN
Features
▄▄ 32-bit up counter for counting elapsed time
▄▄ Programmable clock prescaler
●● Division factor: 1, 2, 4, 8, …, 32768
▄▄ 32-bit compare register for alarm usage
▄▄ RTC clock source
●● LSE oscillator clock
●● LSI oscillator clock
▄▄ Three RTC Interrupt/wakeup settings
●● RTC second clock interrupt/wakeup
●● RTC compare match interrupt/wakeup
●● RTC counter overflow interrupt/wakeup
▄▄ The RTC interrupt/wakeup event can work together with power management to wake up the chip
from power saving mode
Functional Descriptions
RTC Related Register Reset
The RTC registers can only be reset by either a Backup Domain power on reset, PORB, or by a
Backup Domain software reset by setting the BAKRST bit in the BAKCR register. Other reset
events have no effect to clear the RTC registers.
RTCCMP 4
ROLF
0
(Pulse mode)
RTCCMP X
RTCCNT 3 4 5
TR TR TR
1
RTCOUT (ROAP = 0)
Second clock
RTCOUT (ROAP = 1)
ROLF
RTCCMP 4
RTCCNT 3 4 5
0 RTCOUT (ROAP = 0)
Compare match
RTCOUT (ROAP = 1)
ROLF →
1
(Level mode)
RTCCMP X
RTCCNT 3 4 5
1 RTCOUT (ROAP = 0)
Second clock
RTCOUT (ROAP = 1)
ROLF → →
TR: RTCOUT output pulse time = 1 / fCK_RTC
→: Clear by software reading ROLF bit
Register Map
The following table shows the RTC registers and reset values. Note all the registers in this unit are
located at the V BAK backup power domain.
Table 44. RTC Register Map
Register Offset Description Reset Value
RTCCNT 0x000 RTC Counter Register 0x0000_0000
RTCCMP 0x004 RTC Compare Register 0x0000_0000
Register Descriptions
RTC Counter Register – RTCCNT
This register defines a 32-bit up counter which is incremented by the CK_SECOND clock.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
RTCCNTV
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
23 22 21 20 19 18 17 16
RTCCNTV
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
15 14 13 12 11 10 9 8
RTCCNTV
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
7 6 5 4 3 2 1 0
RTCCNTV
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
RTCCMPV
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The Watchdog timer is a hardware timing circuitry that can be used to detect a system lock-up
due to software trapped in a deadlock. The Watchdog timer can be operated in a reset mode. The
Watchdog timer will generate a reset when the counter counts down to a zero value. Therefore, the
WDTV
KEY
WDTRS
RSKEY[15:0]
Reload Underflow
=0
WDTUF
LSI RC Clear
32kHz 0
CK_WDT Prescaler
12-bit Down
LSE OSC 1 /2 /4
1 Counter WDT_RSTn
32.768kHz /8…/128
WDTEN
> WDTD
WDTRSTEN
WDTSRC WDTERR
WPSC[2:0] WDTD
Read WDTSR Register
WDT Error
Features
▄▄ Clock source from either internal 32 kHz RC oscillator (LSI) or 32,768 Hz oscillator (LSE)
▄▄ Can be independently setup to keep running or to stop when entering the sleep or deep sleep
mode 1
▄▄ 12-bit down counter with 3-bit prescaler structure
▄▄ Provides reset to the system
▄▄ Limited reload window setup function for custom Watchdog timer reload times
▄▄ Watchdog Timer may be stopped when the processor is in the debug
▄▄ Reload lock key to prevent unexpected operation
▄▄ Configuration register write protection function for counter value, reset enable, delta value, and
prescaler
Functional Description
The Watchdog timer is formed from a 12-bit count-down counter and a fixed 3-bit prescaler. The
largest time-out period is 16 seconds, using the LSE or LSI clock and a 1/128 maximum prescaler
value.
The Watchdog timer configuration setup includes a programmable counter reload value, reset
enable, window value and prescaler value. These configurations are setup using the WDTMR0
and WDTMR1 registers which must be properly programmed before the Watchdog timer starts
During normal operation, the Watchdog timer counter should be reloaded before it underflows to
prevent the generation of a Watchdog reset. The 12-bit count-down counter can be reloaded with
the required Watchdog Timer Counter Value (WDTV) by first setting the WDTRS bit to1 with the
correct key, which is 0x5FA0 in the WDTCR register.
If a software deadlock occurs during a Watchdog timer reload routine, the reload operation will
still go ahead and therefore the software deadlock cannot be detected. To prevent this situation
from occurring, the reload operation must be executed in such a way that the value of the Watchdog
timer counter is limited within a delta value (WDTD). If the Watchdog timer counter value is
greater than the delta value and a reload operation is executed, a Watchdog Timer error will
occur. The Watchdog timer error will generate a Watchdog reset if the related functional control is
enabled. Additionally, the above features can be disabled by programming a WDTD value greater
than or equal to the WDTV value.
The WDTERR and WDTUF f lags in the WDTSR register will be set respectively when the
Watchdog timer underflows or when a Watchdog timer error occurs. A system reset or write-one
operation on the WDTSR register clears the WDTERR and WDTUF flags.
The watchdog timer uses two clocks: PCLK and CK_WDT. The PCLK clock is used for APB
access to the watchdog registers. The CK_WDT clock is used for the Watchdog timer functionality
and counting. There is some synchronization logic between these two clock domains.
When the system enters the Sleep or Deep sleep mode 1, the Watchdog timer counter will either
continue to count or stop depending on the WDTSHLT bits in the WDTMR0 register. The
Watchdog stops counting when the WDTSHLT bits are set in the Sleep mode. The count value
is retained so that it continues counting after the system is woken up from the Sleep mode. A
Watchdog reset will occur any time when the Watchdog timer is running and when it has an
operating clock source. When the system enters the debug mode, the Watchdog timer counter will
either continue to count or stop depending on the DBWDT bit (in the MCUDBGCR register) in the
Clock Control Unit.
Reset occurred
(If WDTRSTEN = 1)
C ounter value
0xFFF
Reset not occurred
(If WDTRSTEN = 0)
WDTV
WDTD
...
Reload is allowed
0
Time
Start counter Reload counter when Reload counter when counter > WDTD
counter <= WDTD Watchdog Timer error
Normal behavior
Watchdog Timer underflow
Register Map
The following table shows the Watchdog Timer registers and reset values.
Table 45. Watchdog Timer Register Map
Register Offset Description Reset Value
WDTCR 0x000 Watchdog Timer Control Register 0x0000_0000
WDTMR0 0x004 Watchdog Timer Mode Register 0 0x0000_0FFF
WDTMR1 0x008 Watchdog Timer Mode Register 1 0x0000_7FFF
Register Descriptions
Watchdog Timer Control Register – WDTCR
This register is used to reload the Watchdog timer.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
RSKEY
Type/Reset WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0
23 22 21 20 19 18 17 16
RSKEY
Type/Reset WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
Reserved WDTRS
Type/Reset WO 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The I2C Module is an internal circuit allowing communication with an external I2C interface which
is an industry standard two line serial interface used for connection to external hardware. These
two serial lines are known as a serial data line, SDA, and a serial clock line, SCL. The I2C module
The SDA line which is connected to the whole I2C bus is a bi-directional data line between the
master and slave devices used for the transmission and reception of data. The I2C module also has
an arbitration detection function to prevent the situation where more than one master attempts to
transmit data on the I2C bus at the same time.
APB Bus
Bit
Counter
SCL High/Low SCL_out
SCL SCL out
period
Generator control
Generation
Address/Data
Target Register SCL Sync
SDA out
MUX
control SDA_out
SCL Edge
Detect SCL_in
Data Register
Address Address
Register Comparator
Status
Arbitration
Register
Bus Status
Features
▄▄ Two–wire I2C serial interface
●● Serial data line (SDA) and serial clock (SCL)
▄▄ Multiple speed modes
●● Standard mode – 100 kHz
●● Fast mode – 400 kHz
●● Fast mode plus – 1 MHz
Functional Descriptions
Two Wire Serial Interface
The I2C module has two external lines, the serial data SDA and serial clock SCL lines, to carry
information between the interconnected devices connected to the bus. The SCL and SDA lines are
both bidirectional and must be connected to a pull-high resistor. When the I2C bus is in the free or
idle state, both pins are at a high level to perform the required wired-AND function for multiple
connected devices.
A repeated START, which is denoted as the “Sr” bit, is functionally identical to the normal START
condition. A repeated START signal allows the I2C interface to communicate with another slave
device or with the same device but in a different transfer direction without releasing the I2C bus
control.
SDA SDA
SCL SCL
Data Validity
The data on the SDA line must be stable during the high period of the SCL clock. The SDA data
state can only be changed when the clock signal on the SCL line is in a low state.
SDA
SCL
Change of
Stable data line
data allowed
Addressing Format
The I2C interface starts to transfer data after the master device has sent the address to confirm the
targeted slave device. The address frame is sent just after the START signal by master device. The
addressing mode selection bit named ADRM in the I2CCR register should be defined to choose
either the 7-bit or 10-bit addressing mode.
R/W=1 (Read): The master receives data from the addressed slave.
The slave address can be assigned through the ADDR field in the I2CADDR register. The slave
device sends back the acknowledge bit (ACK) if its slave address matches the transmitted address
sent by master.
Note that it is forbidden to own the same address for two slave devices.
Send by master
MSB LSB
S A6 A5 A4 A3 A2 A1 A0 R/W ACK
Slave address
Send by slave
S = START condition
S = START condition
W = Write command
Ack = Acknowledge
A9 ~ A0 = 10-bits Address
MSB LSB
S = START condition
Sr = Repeated-START condition
W = Write command
R = Read command
Ack = Acknowledge
A9 ~ A0 = 10-bits Address
If the slave device returns a Not Acknowledge (NACK) signal to the master device, the master
device can generate a STOP signal to terminate the data transfer or generate a repeated START
signal to restart the transfer.
Data Frame
Acknowledge bit
SCL from
Master 1 2 8 9
Data output
by
Transmitter
Not acknowledge
Data output
by Receiver
acknowledge
Clock Synchronization
Only one master device can generate the SCL clock under normal operation. However when there
is more than one master trying to generate the SCL clock, the clock should be synchronized so
that the data output can be compared. Clock synchronization is performed using the wired-AND
connection of the I2C interface to the SCL line.
SCL from
device 1
SCL from
device 2
SCL on
I2C BUS
Arbitration
A master may start a transfer only if the I2C bus line is in the free or idle mode. If two or more
masters generate a START signal at approximately the same time, an arbitration procedure will
occur.
Arbitration takes place on the SDA line and can continue for many bits. The arbitration procedure
gives a higher priority to the device that transmits serial data with a binary low bit (logic low).
Other master devices which want to transmit binary high bits (logic high) will lose the arbitration.
As soon as a master loses the arbitration, the I2C module will set the ARBLOS bit in the I2CSR
register and generate an interrupt if the interrupt enable bit, ARBLSIEN, in the I2CIER register is
set to 1. Meanwhile, it stops sending data and listens to the bus in order to detect an I2C stop signal.
When the stop signal is detected, the master which has lost the arbitration may try to access the bus
again.
SCL
Data
from 1 0 1
device 1 Device 1 loses arbitration
Data
from 1 0 0 1 1
device 2
SDA line 1 0 0 1 1
The device can support the general call addressing function by setting the corresponding enable
control bit GCEN to 1. If the GCEN bit is set to 1 to support the general call addressing, the AA bit
in the I2CCR register should also be set to 1 to send an acknowledge signal back when the device
Bus Error
If an unpredictable START or STOP condition occurs when the data is being transferred on the I2C
bus, it will be considered as a bus error and the transferring data will be aborted. When a bus error
event occurs, the relevant bus error flag BUSERR in the I2CSR register will set to 1 and both the
SDA and SCL lines are released. The BUSERR flag should be cleared by writing a 1 to it to initiate
the I2C module to an idle state.
For instance, the user sets a data transfer with 7-bit addressing mode together with the I2CADDMR
register value as 0x05h and the I2CADDR register value as 0x55h, this means if an address which
is sent by an I2C master on the bus is equal to 0x50h, 0x51h, 0x54h or 0x55h, the I2C slave address
will all be considered to be matched and the ADRS flag in the I2CSR register will be asserted after
the address frame.
Address Snoop
The Address Snoop register, I2CADDSR, is used to monitor the calling address on the I2C bus
during the whole data transfer operation no matter if the I2C module operates as a master or a slave
device. Note that the I2CADDSR register is a read only register and each calling address on the I2C
bus will be stored in the I2CADDSR register automatically even if the I2C device is not addressed.
Operation Mode
The I2C module can operate in one of the following modes:
▄▄ Master Transmitter
▄▄ Master Receiver
▄▄ Slave Transmitter
▄▄ Slave Receiver
The I2C module operates in the slave mode by default. The interface will switch to the master mode
automatically after generating a START signal.
Address Frame
Data Frame
The data to be transmitted to the slave device must be transferred to the I2CDR register.
The TXDE bit in the I2CSR register is set to indicate that the I2CDR register is empty, which
results in the SCL line being held at a logic low state. New data must then be transferred to the
I2CDR register to continue the data transfer process. Writing a data into the I2CDR register will
clear the TXDE flag.
Address Frame
In the 10-bit addressing mode: The ADRS bit in the I2CSR register will be set twice in the 10-
bit addressing mode. The first time the ADRS bit is set is when the 10-bit address is sent and the
acknowledge signal from the slave device is received. The second time the ADRS bit is set is
when the header byte is sent and the slave acknowledge signal is received. In order to receive the
following data frame, the ADRS bit must be cleared to 0 if it has been set to 1. The ADRS bit is
cleared after reading the I2CSR register. The detailed master receiver mode timing diagram is
shown in the following figure.
Data Frame
In the master receiver mode, data is transmitted from the slave device. Once a data is received by
the master device, the RXDNE flag in the I2CSR register is set but it will not hold the SCL line.
However, if the device receives a complete new data byte and the RXDNE flag has already been set
to 1, the RXBF bit in the I2CSR register will be set to 1 and the SCL line will be held at a logic low
state. When this situation occurs, data from the I2CDR register should be read to continue the data
transfer process. The RXDNE flag can be cleared after reading the I2CDR register.
STA ADRS #1
BEH1 BEH1
BEH4 : cleared by reading I2CDR register, set STOP=1 to send STOP signal
Receive Not-Acknowledge
When the slave device receives a Not-Acknowledge signal, the RXNACK bit in the I2CSR Register
is set but it will not hold the SCL line. Writing “1” to RXNACK will clear the RXNACK flag.
STOP Condition
When the slave device detects a STOP condition, the STO bit in the I2CSR register is set to indicate
that the I2C interface transmission is terminated. Reading the I2CSR register can clear the STO
flag.
ADRS #1
BEH1
BEH3 : cleared by writing 1 clear for RXNACK flag, TXDE is not set when NACK is received.
Data Frame
In the slave receiver mode, the data is transmitted from the master device. Once a data byte is
STOP condition
When the slave device detects a STOP condition, the STO flag bit in the I2CSR register is set to
indicate that the I2C interface transmission is terminated. Reading the I2CSR register can clear the
STO flag bit.
PDMA Interface
The PDMA interface is integrated in the I 2C module. The PDMA function can be enabled by
setting the TXDMAE or RXDMAE bit to 1 in the transmitter or receiver mode respectively. When
the data register is empty in the transmitter mode and the TXDMAE bit is set to 1, the PMDA
function will be activated to move data from a certain memory location into the I2C data register.
Similarly, when the data register is not empty in the receiver mode and the RXDMAE bit is set to
1, the PDMA function will also be activated to move data from the I2C data register to a specific
memory location.
The DMA NACK control bit, DMANACK, is used to determine whether the NACK signal is
sent or not when the I 2C module operates in the master receiver mode and the PDMA function
is enabled. If the DMANACK bit is set to 1 and the data has all been received and moved using
the PDMA interface, a NACK signal will automatically be sent out to properly terminate the data
transfer.
For a mode detailed description on the PDMA configurations, refer to the PDMA chapter.
Register Map
The following table shows the I2C registers and reset values.
Table 47. I2C Register Map
Register Offset Description Reset Value
I2CCR 0x000 I2C Control Register 0x0000_2000
I2CIER 0x004 I2C Interrupt Enable Register 0x0000_0000
I2CADDR 0x008 I2C Address Register 0x0000_0000
Register Descriptions
I2C Control Register – I2CCR
This register specifies the corresponding I2C function enable control.
Offset: 0x000 (0)
Reset value: 0x0000_2000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
SCL
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The Serial Peripheral Interface, SPI, provides an SPI protocol data transmit and receive functions
in both master or slave mode. The SPI interface uses 4 pins, among which are serial data input and
output lines MISO and MOSI, the clock line SCK, and the slave select line SEL. One SPI device
SPIDR
Status
SPISR
SPI_TXFIFO
APB
Bus
MOSI Transmit/Receive SPIFSR
Logic
TX Buffer
MISO
Shift
SEL Register
SCK RX Buffer
Control
SPI_RXFIFO SPICR0
SPICR1
SPIFCR
SPIIER
SPICPR
SPIFTOCR
Features
▄▄ Master or slave mode
▄▄ Master mode speed up to fPCLK/2
▄▄ Slave mode speed up to fPCLK/3
▄▄ Programmable data frame length up to 16 bits
▄▄ FIFO Depth: 8 levels
Function Descriptions
Master Mode
Each data frame can range from 1 to 16 bits in data length. The first bit of the transmitted data can
be either an MSB or LSB determined by the FIRSTBIT bit in the SPICR1 register. The SPI module
is configured as a master or a slave by setting the MODE bit in the SPICR1 register. When the
MODE bit is set, the SPI module is configured as a master and will generate the serial clock on the
SCK pin. The data stream will transmit data in the shift register to the MOSI pin on the serial clock
edge. The SEL pin is active during the full data transmission. When the SELAP bit in the SPICR1
register is set, the SEL pin is active high during the complete data transactions. When the SELM
bit in the SPICR1 register is set, the SEL pin will be driven by the hardware automatically and the
time interval between the active SEL edge and the first edge of SCK is equal to half an SCK period.
Slave Mode
In the slave mode, the SCK pin acts as an input pin and the serial clock will be derived from the
external master device. The SEL pin also acts as an input. When the SELAP bit is cleared to 0, the
SEL signal is active low during the full data stream reception. When the SELAP bit is set to 1, the
SEL signal will be active high during the full data stream byte reception.
Note: For the slave mode, the APB clock, known as f PCLK, must be at least 3 times faster than the
external SCK clock input frequency.
CPOL = 0, CPHA = 0
In this format, the received data is sampled on the SCK line rising edge while the transmitted data
is changed on the SCK line falling edge. In the master mode, the first bit is driven when data is
written into the SPIDR Register. In the slave mode, the first bit is driven when the SEL signal goes
to an active level. Figure 151 shows the single byte data transfer timing of this format.
SEL (SELAP=0)
SEL (SELAP=1)
½ SCK
SCK
data sampled
Figure 151. SPI Single Byte Transfer Timing Diagram – CPOL = 0, CPHA = 0
Figure 152 shows the continuous data transfer timing diagram of this format. Note that the SEL
signal must change to an inactive level between each data frame.
SEL (SELAP=0)
SEL (SELAP=1)
SCK
Figure 152. SPI Continuous Data Transfer Timing Diagram – CPOL = 0, CPHA = 0
CPOL = 0, CPHA = 1
In this format, the received data is sampled on the SCK line falling edge while the transmitted
data is changed on the SCK line rising edge. In the master mode, the first bit is driven when data is
written into the SPIDR register. In the slave mode, the first bit is driven at the first SCK clock rising
edge. Figure 153 shows the single data byte transfer timing.
SEL(SELAP=0)
SEL(SELAP=1)
½ SCK
SCK
Data sampled
Figure 153. SPI Single Byte Transfer Timing Diagram – CPOL = 0, CPHA = 1
Figure 154 shows the continuous data transfer diagram timing. Note that the SEL signal must
remain active until the last data transfer has completed.
SEL (SELAP=0)
SEL (SELAP=1)
SCK
CPOL = 1, CPHA = 0
In this format, the received data is sampled on the SCK line falling edge while the transmitted
data is changed on the SCK line rising edge. In the master mode, the first bit is driven when data
is written into the SPIDR register. In the slave mode, the first bit is driven when the SEL signal
changes to an active level. Figure 155 shows the single byte transfer timing of this format.
SEL (SELAP=0)
SEL (SELAP=1)
SCK
½ SCK
data sampled
Figure 155. SPI Single Byte Transfer Timing Diagram – CPOL = 1, CPHA = 0
Figure 156 shows the continuous data transfer timing of this format. Note that the SEL signal must
change to an inactive level between each data frame.
SEL (SELAP=0)
SCK
CPOL = 1, CPHA = 1
In this format, the received data is sampled on the SCK line rising edge while the transmitted data
is changed on the SCK line falling edge. In the master mode, the first bit is driven when data is
written into the SPIDR register. In the slave mode, the first bit is driven at the first SCK falling
edge. Figure 157 shows the single byte transfer timing of this format.
SEL (SELAP=0)
SEL (SELAP=1)
SCK
½ SCK
data sampled
Figure 157. SPI Single Byte Transfer Timing Diagram – CPOL = 1, CPHA = 1
Figure 158 shows the continuous data transfer timing of this format. Note that the SEL signal must
remain active until the last data transfer has completed.
SEL (SELAP=0)
SEL (SELAP=1)
SCK
Status Flags
TX Buffer Empty – TXBE
This TXBE flag is set when the TX buffer is empty in the non-FIFO mode or when the TX FIFO
data length is equal to or less than the TX FIFO threshold level as defined by the TXFTLS field in
the SPIFCR register in the FIFO mode. The following data to be transmitted can then be loaded
into the buffer again. After this, the TXBE flag will be reset when the TX buffer already contains
new data in the non-FIFO mode or the TX FIFO data length is greater than the TX FIFO threshold
level determined by the TXFTLS bits in FIFO mode.
Mode Fault – MF
The mode fault flag can be used to detect SPI bus usage in the SPI multi-master mode. For the
multi-master mode, the SPI module is configured as a master device and the SEL signal is setup as
an input signal. The mode fault flag is set when the SPI SEL pin is suddenly changed to an active
level by another SPI master. This means that another SPI master is requesting to use the SPI bus.
Therefore, when an SPI mode fault occurs, it will force the SPI module to operate in the slave mode
and also disable all of the SPI interface signals to avoid SPI bus signal collisions. For the same
reason, if the SPI master wants to transfer data, it also needs to inform other SPI masters by driving
its SEL signal to an active state. The detailed configuration diagram for the SPI multi-master mode
is shown in the following figure.
SCK SCK
MOSI MOSI
SPI SPI
Master Master
MISO MISO
SEL SEL
I/O 0 I/O 0
SCK
MOSI
SPI
Slave
MISO
SEL
SCK
MOSI
SPI
Slave
MISO
SEL
Write Collision – WC
The following conditions will assert the Write Collision Flag.
▄▄ The FIFOEN bit in the SPIFCR register is cleared
The write collision flag is asserted when new data is written into the SPIDR register while both
the TX buffer and the shift register are already full. Any new data written into the TX buffer will
be lost.
▄▄ The FIFOEN bit in the SPIFCR register is set
PDMA Interface
The PDMA interface is integrated in the SPI module. The PDMA function can be enabled by
setting the TXDMAE or RXDMAE bit to 1 in the transmitter or receiver mode respectively. When
the transmit buffer empty flag, TXBE, is asserted and the TXDMAE bit is set to 1, the PMDA
function will be activated to move data from the memory location that users designated into the SPI
data register or the TX FIFO until the TXBE flag is cleared to 0. The TXBE flag will be asserted
when the transmit buffer is empty in the non-FIFO mode or the data contained in the TX FIFO is
equal to or less than the level defined by the TXFTLS field in the FIFO mode.
Similarly, when the receive buffer not empty flag, RXBNE, is asserted and the RXDMAE bit is set
to 1, the PDMA function will be activated to move data from the SPI data register or the RX FIFO
to the memory location that users designated until the RXBNE flag is cleared to 0. The RXBNE
flag will be asserted when the receive buffer is not empty in the non-FIFO mode or the data
contained in the RX FIFO is equal to or greater than the level defined by the RXFTLS field in the
FIFO mode.
For a mode detailed description on the PDMA configurations, refer to the PDMA chapter.
Register Map
The following table shows the SPI registers and their reset values.
Table 52. SPI Register Map
Register Offset Description Reset Value
SPICR0 0x000 SPI Control Register 0 0x0000_0000
SPICR1 0x004 SPI Control Register 1 0x0000_0000
SPIIER 0x008 SPI Interrupt Enable Register 0x0000_0000
Register Descriptions
SPI Control Register 0 – SPICR0
This register specifies the SEL control and the SPI enable bits.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
SELHT GUADT
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
GUADTEN DUALEN Reserved SSELC SELOEN RXDMAE TXDMAE SPIEN
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
CP
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
CP
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
Introduction
The Universal Synchronous Asynchronous Receiver Transceiver, USART, provides a flexible
The USART module includes an 8-byte transmit FIFO, TX FIFO, and a 8-byte receive FIFO,
RX FIFO. Software can detect a USART error status by reading USART Status & Interrupt Flag
Register, USRSIFR. The status includes the condition of the transfer operations as well as several
error conditions resulting from Parity, Overrun, Framing and Break events.
The USART includes a programmable baud rate generator which is capable of dividing the USART
clock of the CK_APB (CK_USART) to produce a baud rate clock for the USART transmitter and
receiver.
CK_USART
Transmit FIFO
TXD
Transmit Shift Register
TX
RXD
APB Receive Shift Register
USART Control
Interface RX
and USART I/O and
Configuration IrDA
Registers Receive FIFO
RTS
Reference
Baud Rate
Divisor Clock CTS
Clock
USART Generator
Interrupt
IrDA _EN
Features
▄▄ Supports both asynchronous and clocked synchronous serial communication modes
▄▄ Full Duplex Communication Capability
▄▄ Programming baud rate up to 3 Mbit/s for asynchronous mode and 6 Mbit/s for synchronous
mode
▄▄ IrDA SIR encoder and decoder
Function Descriptions
Serial Data Format
The USART module performs a parallel-to-serial conversion on data that is written to the transmit
FIFO registers and then sends the data with the following format: Start bit, 7 ~ 9 LSB first data
bits, optional Parity bit and finally 1 ~ 2 Stop bits. The Start bit has the opposite polarity of the
data line idle state. The Stop bit is the same as the data line idle state and provides a delay before
the next start situation. The both Start and Stop bits are used for data synchronization during the
The USART module also performs a serial-to-parallel conversion on the data that is read from the
receive FIFO registers. It will first check the Parity bit and will then look for a Stop bit. If the Stop
bit is not found, the USART module will consider the entire word transmission to have failed and
respond with a Framing Error.
(WLS[1:0]=0x00,PBE=1)
Next Start
Start Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Parity Bit Stop Bit
Bit
(WLS[1:0]=0x01,PBE=1)
Next Start
Start Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Parity Bit Stop Bit Bit
Where CK_USART clock is the APB clock connected to the USART while the BRD range is from
16 to 65535 for asynchronous mode and 8 to 65535 for synchronous mode.
BRD =18
Reference
Divisor Clock
Parity Bit
Next Start
Start Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bitn Stop Bit Bit
n=6~8
USART 1 USART 2
TX RX
Transmitter Receiver
CTS RTS
RX TX
Receiver Transmitter
RTS CTS
RXFS[3:0] 3 4 0 1
When the USART CTS pin is forced to a logic high state during a data transmission period, the
current data transmission will be continued until the stop bit is completed. The Figure 165 shows
an example of communication with CTS flow control.
Start Bit Parity Bit Start Bit Parity Bit Start Bit
Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit N Stop Bit Idle Bit 0 Bit 1 Bit 2 Bit 3 Bit 4 Bit N Stop Bit 0
Bit
N=6~8 N=6~8
CTS
TXFS[3:0] 4 3 2
IrDA
The USART IrDA mode is provided half-duplex point-to-point wireless communication.
The USART module includes an integrated modulator and demodulator which allow a wireless
communication using infrared transceivers. The transmitter specifies a logic data ‘0’ as a ‘high’
pulse and a logic data ‘1’ as a ‘low’ level while the Receiver specifies a logic data ‘0’ as a ‘low’
pulse and a logic data ‘1’ as ‘high’ level in the IrDA mode.
TX_Data 1 0 1 0 1 0 1 1 1 0
IrDA TX
Modulation
Signal
IrDA Rx
Demodulation
Signal
Data Frame
START STOP
Rx_Data 1 0 1 0 1 0 1 1 1 0
The IrDA mode provides two operation modes, one is the normal mode, and the other is the low-
power mode.
The IrDAPSC filed is the IrDA prescaler value in the IrDA Control Register IrDACR.
The debounce behavior in the IrDA low-power receiving mode is similar to the IrDA normal mode.
For glitch detection, the low pulse of which the pulse width is shorter than 1 × (IrDAPSC / CK_
USART) should be discarded in the IrDA receiver demodulation. A valid low data is accepted if its
low pulse width is greater than 2 × (IrDAPSC / CK_USART) duration.
The IrDA physical layer specification specifies a minimum delay with a value of 10 ms between the
transmission and reception switch; and this IrDA receiver set-up time also should be managed by
the software.
TX_Data 0
TX
1
Transmitter
Modulation
SEL
0 RX
RX_Data
1
Receiver
Demodulation
SEL
IrDAEN
RS485 Mode
The RS485 mode of the USART provides the data transmission on the interface transmitted over
a 2-wire twisted pair bus. The RS485 transceiver interprets the voltage levels of the differential
signals with respect to a third common voltage. Without this common reference, the transceiver
may interpret the differential signals incorrectly. This enhances the noise rejection capabilities of
the RS485 interface. The USART RTS pin is used to control the external RS485 transceiver whose
polarity can be selected by configuring the TXENP bit in the RS485 Control Register, named
RS485CR, when the USART operates in the RS485 mode.
RS-485 Transceiver
RX
Differential
Bus
TX
RTS
TG = 4
Reference Divisor
Clock
TX
Start D0 D1 D2 D3 D4 D5 D6 D7 ParityStop
Bit Bit
RTS
TXENP =0
RTS
TXENP =1
In the USART synchronous Mode, the USART CTS/SCK clock output pin is only used to transmit
the data to slave device. If the transmission data register USRDR, is written with valid data, the
USART synchronous mode will automatically transmit this data with the corresponding clock
output and the USART receiver will also receive data on the RX pin. Otherwise the receiver will
not obtain synchronous data if no data is transmitted.
TX
Data in
RX
Data out
Device
USART (Master)
(Slave)
CTS/SCK
Clock
Note: The USART supports the synchronous master mode only: it cannot receive or send data
related to an input clock. The USART CTS/SCK clock is always an output.
(CPS=1,WLS[1:0]=0x01,PBE=0)
Clock (CPO=0)
Clock (CPO=1)
USART RX (From
Slave to Master) D0 D1 D2 D3 D4 D5 D6 D7
(CPS=1,WLS[1:0]=0x00,PBE=1)
Clock (CPO=0)
Clock (CPO=1)
USART RX (From
Slave to Master) D0 D1 D2 D3 D4 D5 D6 Parity
(CPS=0,WLS[1:0]=0x01,PBE=0)
Clock (CPO=0)
Clock (CPO=1)
USART RX (From
Slave to Master) D0 D1 D2 D3 D4 D5 D6 D7
(CPS=0,WLS[1:0]=0x00,PBE=1)
Clock (CPO=0)
Clock (CPO=1)
USART TX (From
Master to Slave) Start D0 D1 D2 D3 D4 D5 D6 Parity Stop
USART RX (From
Slave to Master) D0 D1 D2 D3 D4 D5 D6 Parity
PDMA Interface
The PDMA interface is integrated in the USART. The PDMA function can be enabled by setting
the TXDMAEN or RXDMAEN bit in the USRCR register to 1 in the transmit or receive mode
respectively. When the data to be transmitted in the USART Transmit FIFO is less than the TX
FIFO threshold level specified by the TXTL field in the USRFCR register and the TXDMAEN
bit is set to 1, the PDMA function will be activated to move data from a source location into the
USART TX FIFO.
Similarly, when the received data amount in the receive FIFO is equal to the RX FIFO threshold
level specified by the RXTL field in the USRFCR register and the RXDMAEN bit is set to 1, the
PDMA function will be activated to move data from the USART RX FIFO to a specific destination
location. For a mode detailed description on the PDMA configurations, refer to the PDMA chapter.
Register Map
The following table shows the USART registers and reset values.
Table 55. USART Register Map
Register Offset Description Reset Value
USRDR 0x000 USART Data Register 0x0000_0000
USRCR 0x004 USART Control Register 0x0000_0000
USRFCR 0x008 USART FIFO Control Register 0x0000_0000
USRIER 0x00C USART Interrupt Enable Register 0x0000_0000
USRSIFR 0x010 USART Status & Interrupt Flag Register 0x0000_0180
USRTPR 0x014 USART Timing Parameter Register 0x0000_0000
IrDACR 0x018 USART IrDA Control Register 0x0000_0000
RS485CR 0x01C USART RS485 Control Register 0x0000_0000
SYNCR 0x020 USART Synchronous Control Register 0x0000_0000
USRDLR 0x024 USART Divider Latch Register 0x0000_0010
USRTSTR 0x028 USART Test Register 0x0000_0000
Register Descriptions
USART Data Register – USRDR
The register is used to access the USART transmitted and received FIFO data.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved RXFS
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved CTSIE RXTOIE
Type/Reset RW 0 RW 0
7 6 5 4 3 2 1 0
RSADDIE BIE FEIE PEIE OEIE TXCIE TXDEIE RXDRIE
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
ADDMATCH
Type/Reset RW 0
7 6 5 4 3 2 1 0
Reserved RSAAD RSNMM TXENP
Type/Reset RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The Universal Asynchronous Receiver Transceiver, UART, provides a flexible full duplex data
The UART module includes a transmit data register TDR and transmit shift register TSR, and a
receive data register RDR and receive shift register RSR. Software can detect a UART error status
by reading UART Status & Interrupt Flag Register, URSIFR. The status includes the condition of
the transfer operations as well as several error conditions resulting from Parity, Overrun, Framing
and Break events.
The UART includes a programmable baud rate generator which is capable of dividing the UART
clock of the CK_APB (CK_UART) to produce a baud rate clock for the UART transmitter and
receiver.
CK_UART
TXD
Transmit Shift Register (TSR)
RXD
APB Receive Shift Register (RSR) TX
Interface UART Control and
Configuration UART I/O
Registers RX
Receive Data Register (RDR)
Reference
Baud Rate
Divisor Clock
Clock
UART Generator
Interrupt
Features
▄▄ Supports asynchronous serial communication modes
▄▄ Full Duplex Communication Capability
▄▄ Programming baud rate up to 3 Mbit/s.
▄▄ Fully programmable serial communication functions including:
●● Word length: 7, 8, or 9-bit character
Function Descriptions
Serial Data Format
The UART module performs a parallel-to-serial conversion on data that is written to the transmit
data register and then sends the data with the following format: Start bit, 7 ~ 9 LSB first data
bits, optional Parity bit and finally 1 ~ 2 Stop bits. The Start bit has the opposite polarity of the
data line idle state. The Stop bit is the same as the data line idle state and provides a delay before
the next start situation. The both Start and Stop bits are used for data synchronization during the
asynchronous data transmission.
The UART module also performs a serial-to-parallel conversion on the data that is read from the
receive data register. It will first check the Parity bit and will then look for a Stop bit. If the Stop
bit is not found, the UART module will consider the entire word transmission to have failed and
respond with a Framing Error.
(WLS[1:0]=0x00, PBE=1)
Next Start
Start Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Parity Bit Stop Bit Bit
(WLS[1:0]=0x01, PBE=1)
Next Start
Start Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bit5 Bit6 Bit7 Parity Bit Stop Bit Bit
Where CK_UART clock is the APB clock connected to the UART while the BRD range is from 16
to 65535.
BRD =18
Reference
Divisor Clock
Parity Bit
Next Start
Start Bit Bit0 Bit1 Bit2 Bit3 Bit4 Bitn Stop Bit Bit
n=6~8
PDMA Interface
The PDMA interface is integrated in the UART. The PDMA function can be enabled by setting
the TXDMAEN or RXDMAEN bit in the URCR register to 1 in the transmit or receive mode
respectively. When the UART transmit data register TDR is empty and the TXDMAEN bit is set to 1,
the PDMA function will be activated to move data from a source location into the UART transmit
data register TDR.
Similarly, when the received data has been in the UART receive data register RDR and the
RXDMAEN bit is set to 1, the PDMA function will be activated to move data from the UART
receive data register RDR to a specific destination location. For a mode detailed description on the
PDMA configurations, refer to the PDMA chapter.
Register Map
The following table shows the UART registers and reset values.
Table 58. UART Register Map
Register Offset Description Reset Value
URDR 0x000 UART Data Register 0x0000_0000
URCR 0x004 UART Control Register 0x0000_0000
URIER 0x00C UART Interrupt Enable Register 0x0000_0000
Register Descriptions
UART Data Register – URDR
The register is used to access the UART transmitted and received data.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved DB
Type/Reset RW 0
7 6 5 4 3 2 1 0
DB
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved TXC
Type/Reset RO 1
7 6 5 4 3 2 1 0
TXDE Reserved RXDR BII FEI PEI OEI Reserved
Type/Reset RO 1 RO 0 WC 0 WC 0 WC 0 WC 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The Smart Card Interface, SCI, is compatible with the ISO 7816-3 standard. This interface includes
functions for card Insertion/Removal detection, SCI data transfer control logic and data buffers,
internal Timer Counters and corresponding control logic circuits to perform the required Smart
As the complexity of ISO7816-3 standard data protocol does not permit comprehensive specifications
to be provided in this datasheet, the reader should therefore consult other external information for a
detailed understanding of this standard.
fPSC_CK
fPCLK 6-bit Prescaler
fPSC_CK
Features
▄▄ Supports ISO 7816-3 standard
▄▄ Character Transfer Mode
▄▄ 1 transmit buffer and 1 receive buffer
▄▄ 11-bit ETU (elementary time unit) counter
▄▄ 9-bit guard time counter
Functional Descriptions
To communicate with an external Smart Card, the integrated Smart Card Interface has a series
of external pins known as SCI_CLK, SCI_DIO and SCI_DET. The SCI_CLK pin is the clock
output signal used to communicate with the external Smart Card together with the serial data pin
named SCI_DIO. The operation of the SCI_CLK and SCI_DIO pins can be selected to be the SCI
data Transfer Mode which is driven automatically by the SCI control circuits or to be the Manual
mode which is controlled by configuring the internal CLK and DIO register bits respectively by
the application program. The SCI_DET pin is the external card detection input pin. Insertion or
removal of the external Smart Card can be automatically detected and generate an interrupt signal
which is sent to the microcontroller if the corresponding interrupt function is enabled.
For proper data transfer, some timing related procedures must be executed before the Smart
Card Interface can begin to communicate with the external card. There are three counters named
Elementary Time Unit, ETU, Guard Time Counter, GT, and Waiting Time Counter, WT, which are
used for the timing related functions in Smart Card Interface data transfer operations.
where:
▄▄ etu is the nominal duration of the data bit on the signal SCI_DIO provided to the card by the
interface
▄
▄ Di is the bit-rate adjustment factor
▄▄ Fi is the clock rate conversion factor
▄▄ f is the frequency value of the clock signal SCI_CLK provided to the card by the interface
Fi is an encoded decimal value based on a 4-bit field, named FI, as represented in the following
table.
Table 60. FI Field Based Fi Encoded Decimal Values
FI field 0000 0001 0010 0011 0100 0101 0110 1001 1010 1011 1100 1101
Fi (decimal) 372 372 558 744 1116 1488 1860 512 768 1024 1536 2048
The values of FI and DI, as they appear in the preceding tables, will be obtained from the Answer-
to-Reset packet sent from the external Smart Card to the Smart Card Interface the first time the
external Smart Card is inserted. When the SCI receives the FI and DI information, the Fi and
Di values can be obtained by looking up the preceding two tables. After the Fi and Di values are
obtained, the value which should be written into the ETUR register can be calculated by Fi/Di. The
following table shows the possible ETU values obtained by the Fi/Di ratio.
Table 61. Possible ETU Values Obtained with the Fi/Di Ratio
Fi
372 558 774 1116 1488 1860 512 768 1024 1536 2048
Di
1 372 558 744 1116 1488 1860 512 768 1024 1536 2048
2 186 279 372 558 744 930 256 384 512 768 1024
4 93 139.5 186 279 372 465 128 192 256 384 512
8 46.5 69.75 93 139.5 186 232.5 64 96 128 192 256
16 23.25 34.87 46.5 69.75 93 116.2 32 48 64 96 128
32 22.62 17.43 23.25 34.87 46.5 58.13 16 24 32 48 64
12 31 46.5 62 93 124 155 42.66 64 85.33 128 170.6
20 18.6 27.9 37.2 55.8 74.4 93 25.6 38.4 51.2 76.8 102.4
Compensation mode
As the value of the ETUR register is obtained by the above procedure, the calculation results of the
value may not be an integer. If the calculation result is not an integer and is less than the integer
n but greater than the integer (n-1), either the integer n or (n-1) should be written into the ETUR
register depending upon whether the result is closer to integer n or (n-1). The integer n mentioned
here is a decimal.
If the calculation result is close to the value of (n-0.5), the compensation mode should be enabled by
setting the compensation enable control bit, COMP, in the ETUR register to 1 for successful data
SCI_DIO P
tETU
Character
n n n n n n n n n n
SCI_CLK COMP=0
SCI_CLK
n n-1 n n-1 n n-1 n n-1 n n-1 COMP=1
(Average time unit= n-0.5)
SCI_CLK
n-1 n n-1 n n-1 n n-1 n n-1 n
Note: The ETUR register value = n, i.e. 1 tETU=n clocks in this example.
SCIàSmart Card
There is a register for the waiting time counter known as the WTR register which stores the
expected waiting time counter value. The waiting time counter can be used in both the SCI data
Transfer Mode and manual mode and can reload the value for specific conditions. The function
of the waiting time counter is controlled by the WTEN bit in the CR register. When the SCI is
configured to be operated in the SCI data Transfer Mode and the waiting time counter is enabled
by setting the WTEN bit to 1, the updated WTR register value will be loaded into the waiting time
counter when the Start bit is detected. Note that the WTEN bit should not be set to 1 to enable the
waiting time counter in the SCI data Transfer Mode until after the external Smart Card is inserted.
If the SCI is configured to operate in the manual mode, the waiting time counter can be used as a
general purpose timer and this timer is enabled or disabled by setting or clearing the WTEN bit.
The updated WTR register value will not be loaded into the waiting time counter if the waiting
time counter is enabled. When the waiting time counter is disabled by setting the WTEN bit to 0
and an updated value is written into the WTR register, the new value will immediately be loaded
into the waiting time counter and then the counter will start to count after the WTEN bit is again
set to 1.
Software can change the Waiting Time value on-the-fly. For example, in T=1 mode, the value of the
Block Waiting Time, tBWT, should be written into the WTR register before the Start bit of the last
transmitted character occurs. After the transmission of the last character is completed, software
should write the Character Waiting Time value, tCWT, into the WTR register.
Start bit
Program the BWT Program the CWT
Smart CardàSCI
Figure 177. Character and Block Waiting Time Duration – CWT and BWT
The SCI serial data pin, named SCI_DIO, can be controlled by the SCI hardware circuitry or the
software control bits depending upon whether the SCI is operated in the SCI Transfer Mode or in
the Manual Mode. The mode selection is determined by the SCIM bit in the CR register. The SCI_
DIO pin status is controlled by the CDIO bit in the CCR register when the SCI is configured to
operate in the Manual mode by clearing the SCIM bit in the CR register. In the Manual Mode the
SCI_DIO pin status is a copy of the CDIO bit. However, when the SCI is configured to operate in
the SCI Transfer Mode, the SCI_DIO pin status is determined by the SCI transfer circuitry.
The SCI clock output pin named SCI_CLK can be controlled by the 6-bit SCI prescaler or the
software control bits depending upon the condition of the CLKSEL bit in the CCR register. The
SCI_CLK pin status is controlled by the CCLK bit in the CCR register when the CLKSEL bit is
cleared to 0. The SCI_CLK pin status is a copy of the CCLK bit. However, when the CLKSEL bit is
set to 1, the SCI_CLK signal is sourced from the 6-bit prescaler output. The prescaler division ratio
is determined by the PSC field in the PSCR register.
Card Detection
When an external Smart Card is inserted, the internal card detector can detect this insertion
operation and generate a card insertion interrupt if the corresponding interrupt enable control
bit, CARDIRE, in the IER register is set to 1. Similarly, if the card is removed, the internal card
detector can also detect the removal and consequently generate a card removal interrupt when
the corresponding interrupt function is enabled by setting the control bit, CARDIRE, in the IER
register, to 1.
The card detector can support two kinds of card detect switch mechanisms. One is a normally
open switch mechanism when the card is not present and the other is a normally closed switch
mechanism. After noting which card detect switch mechanism type is used, the card switch
selection should be configured by setting the selection bit, DETCNF, in the CR register to correctly
detect the card presence. No matter what type of the card switch is selected, by configuring the
DETCNF bit, the card Insertion/Removal flag, CPREF, in the SR register will be set to 1 when the
card is actually present on the SCI_DET pin. Note that there are no hardware de-bounce circuits in
the card detector. Any change of the SCI_DET pin level will cause the CPREF bit to change. The
required de-bounce time should be handled by the application program.
CPREF
Edge
Detection 0 SCI_DET
Card Insertion / Removal
Interrupt request
There are two data registers related to data transmission and reception, TXB and RXB, which store
the data to be transmitted and received respectively. If a character is written into the TXB register
in the SCI Transfer Mode, the SCI transfer interface will automatically switch to the Transmission
Mode from the reception mode after a reset. When the SCI transmission or reception has finished,
the corresponding request flag, named TXCF or RXCF, in the SR register is set to 1. If the transmit
buffer is empty, the transmit buffer empty flag, TXBEF, in the SR register will be set to 1.
If the data transmitted by the SCI is received by the external Smart Card without a parity error, the
SCI transmission request flag, TXCF, will be set to 1 and the SCI parity error request flag, PARF,
will be cleared to 0. If the data transmitted by the external Smart Card is received by the SCI
without a parity error, the SCI reception request flag, RXCF, will be set to 1 and the parity error
flag, PARF, will be cleared to 0.
Repetition Function
There is a Character Repetition function supported by the SCI transfer circuitry when a parity error
occurs. The Character Repetition function is enabled by setting the CREP bit in the CR register
to 1. A repetition function will then be activated when a parity error occurs during a data transfer.
The repetition time number can be selected to be 4 or 5 by configuring the RETRY bit in the CR
register.
When the CREP bit is set to 1, the character repetition function will be activated. Taking a 4
time repetition as an example, when the CREP bit is set to 1 and the RETRY bit is set to 1, in the
Similarly, when the SCI operates in the reception mode, it will inform the external Smart Card that
there is a parity error for a maximum of 4 times if the character repetition function is enabled. If
the SCI informs the external Smart Card that there is still an error signal for the 4 receptions, the
parity error flag, PARF, will be set to 1 together with the reception request flag, RXCF.
If the CREP bit is cleared to 0, the character repetition function will be disabled. When the SCI
operates in the reception mode, both the PARF and RXCF bits will be set to 1 as data with a parity
error has been received. If the SCI is informed that there is a parity error in the Transmission
Mode, the PARF bit will be set to 1 but the TXCF bit will not be set.
Interrupt Generator
There are several conditions for the SCI to generate an SCI interrupt. When these conditions are
met, an interrupt signal will be generated to obtain the attention of the microcontroller. These
conditions are a Smart Card Insertion/Removal, a Waiting Time Counter Underflow, a Parity
error, an end of a Character Transmission or Reception and an empty Transmit buffer. When a
Smart Card interrupt is generated by any of these conditions, then if the SCI global interrupt and
the corresponding SCI interrupt are together enabled, the program will jump to the corresponding
interrupt vector where it can be serviced before returning to the main program.
For an SCI Interrupt to be serviced, in addition to the bits for the corresponding interrupt enable
control in the SCI being set, the SCI global interrupt enable control bit in the NVIC must also be
set. If this SCI global interrupt control bit is not set, then no SCI interrupt will be serviced.
PDMA Interface
The PDMA interface is integrated in the SCI module. The PDMA function can be enabled by
setting the TXDMA or RXDMA bit to 1 in the transmitter or receiver mode respectively. When the
transmit buffer is empty which results in the transmit buffer empty flag, TXBEF, being asserted
and the TXDMA bit is set to 1, the PDMA function will be activated to move data from a certain
memory location into the SCI Transmit buffer. Similarly, when the SCI receives a character which
results in the character received flag, RXCF, being asserted and the RXDMA bit is set to 1, the
PDMA function will be activated to move data from the SCI Receive buffer to a specific memory
For a mode detailed descriptions on the PDMA configurations, refer to the PDMA chapter.
Register Map
There are several registers associated with the Smart Card function. Some of these registers control
the SCI overall function as well as the interrupts, while some of the registers contain the status
bits which indicate the Smart Card data transfer situation and error conditions. Also there are two
registers for the SCI transmission and reception respectively to store the data received from or to
be transmitted to the external Smart Card. The following table shows the SCI register list and reset
values.
Table 62. SCI Register Map
Register Offset Description Reset Value
CR 0x000 SCI Control Register 0x0000_0000
SR 0x004 SCI Status Register 0x0000_0080
CCR 0x008 SCI Contact Control Register 0x0000_0008
ETUR 0x00C SCI Elementary Time Unit Register 0x0000_0174
GTR 0x010 SCI Guard Time Register 0x0000_000C
WTR 0x014 SCI Waiting Time Register 0x0000_2580
IER 0x018 SCI Interrupt Enable Register 0x0000_0000
IPR 0x01C SCI Interrupt Pending Register 0x0000_0000
TXB 0x020 SCI Transmit Buffer 0x0000_0000
RXB 0x024 SCI Receive Buffer 0x0000_0000
PSCR 0x028 SCI Prescaler Register 0x0000_0000
Register Descriptions
SCI Control Register – CR
This register contains the SCI control bits.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
RB
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The USB device controller is compliant with the USB 2.0 full-speed specification. There is one
control endpoint know as Endpoint 0 and seven configurable endpoints (EP1~EP7). A 1024-
byte EP-SRAM is used for the endpoint buffers. Each endpoint buffer size is programmable
Endpoint 0
Ctrl
IN and OUT
DP
Serial
Endpoint type A On-chip
256 x 32-bit Interface
Int/Bulk USB Full-Speed
EP-SRAM Engine DM
IN or OUT Transceiver
(SIE)
HCLK Endpoint type B
Int/Bulk/Iso
48MHz_CLK IN or OUT
Interrupt
USB Device Controller (USB)
Features
▄▄ Complies with USB 2.0 full-speed (12Mbps) specification
▄▄ Fully integrated USB full-speed transceiver
▄▄ 1 control endpoint (EP0) for control transfer
▄▄ 3 single-buffered endpoint (EP1~EP3) for bulk and interrupt transfer
▄▄ 4 double-buffered endpoint (EP4~EP7) for bulk, interrupt and isochronous transfer
▄▄ 1,024 bytes EP-SRAM used as endpoint data buffers
Functional Descriptions
Endpoints
The USB Endpoint 0 is the only bidirectional endpoint dedicated to USB control transfer. The
device also contains seven unidirectional endpoints for other USB transfer types. There are three
endpoints (EP1~EP3) which supports a single buffering function which is used for Bulk and
Interrupt IN or OUT data transfer. There are four other endpoints (EP4~EP7) which supports
single or double buffering functions for Bulk, Interrupt and Isochronous IN or OUT data transfer.
EP-SRAM
The USB controller contains a dedicated memory space, EP-SRAM, which is used for the USB
endpoint buffers. The EP-SRAM, which is connected to the APB bus, can be accessed by the CPU
and PDMA. The EP-SRAM base address is 0x400A_A000 with an offset which ranges from 0x000
to 0x3FF. The EP-SRAM first two words are reserved for Endpoint 0 to temporarily store the 8-byte
SETUP data. Therefore the valid start address of the endpoint buffer should start from 0x008
and align to a 4-byte boundary. Each endpoint buffer size is programmable. The following table
lists the maximum USB endpoint buffer size which is compliant with USB 2.0 full-speed device
specification.
Table 64. USB Data Types and Buffer Size
Transfer
Direction Supported Buffer Size Bandwidth CRC Retrying
Type
Control Bidirectional 8, 16, 32, 64 Not guaranteed Yes Automatic
Bulk Unidirectional 8, 16, 32, 64 Not guaranteed Yes Yes
Interrupt Unidirectional ≤ 64 Not guaranteed Yes Yes
Isochronous Unidirectional < 512 Guaranteed Yes No
In the following endpoint buffer allocation example, the Endpoint “4” is configured as a double-
buffered Bulk IN endpoint while the Endpoint “5” is configured as a double-buffered Bulk OUT
endpoint. Each endpoint buffer size is set to 64-bytes.
CK_USART
BRD =18
Reference
Divisor Clock
Parity Bit
Double-Buffering
The double buffering function is recommended to be enabled when the corresponding endpoint is
specified to be used for Isochronous transfer or high throughput Bulk transfer. The double buffering
function stores the preceding data packet sent by the USB host in a simple buffer for the CPU to
process and the hardware will ensure that it continues to receive the current data packet in the other
buffer during a OUT transaction, and vice versa. Using a double buffering function can achieve the
highest possible data transfer rate. The details regarding double buffering usage is provided in the
corresponding UDBTG and MDBTG control bit description in the USBEPnCSR register where the
denotation n ranges from 4 to 7.
There are two ways for the USB host to wake up the USB device, one is to send a USB reset signal,
SE0, and the other is to send a USB resume signal known as the K-state, After a wake-up signal,
regardless of whether a SE0 signal or a K-state is detected, the USB device will be woken up.
Remote Wake-up
As the USB device has a remote wake-up function, it can wake up the USB host by sending a
resume request signal by setting the GENRSM bit in the USBCSR register to 1. Once the USB host
receives the remote wake-up signal from the USB device, it will send a resume signal to the USB
device.
Register Map
The following table shows the USB registers and reset values.
Table 65. USB Register Map
Register Offset Description Reset Value
USB Base Address = 0x400A_8000
USBCSR 0x000 USB Control and Status Register 0x0000_00X6
USBIER 0x004 USB Interrupt Enable Register 0x0000_0000
USBISR 0x008 USB Interrupt Status Register 0x0000_0000
USBFCR 0x00C USB Frame Count Register 0x0000_0000
USBDEVAR 0x010 USB Device Address Register 0x0000_0000
USBEP0CSR 0x014 USB Endpoint 0 Control and Status Register 0x0000_0002
USBEP0IER 0x018 USB Endpoint 0 Interrupt Enable Register 0x0000_0000
USBEP0ISR 0x01C USB Endpoint 0 Interrupt Status Register 0x0000_0000
USBEP0TCR 0x020 USB Endpoint 0 Transfer Count Register 0x0000_0000
USBEP0CFGR 0x024 USB Endpoint 0 Configuration Register 0x8000_0002
USBEP1CSR 0x028 USB Endpoint 1 Control and Status Register 0x0000_0002
USBEP1IER 0x02C USB Endpoint 1 Interrupt Enable Register 0x0000_0000
USBEP1ISR 0x030 USB Endpoint 1 Interrupt Status Register 0x0000_0000
USBEP1TCR 0x034 USB Endpoint 1 Transfer Count Register 0x0000_0000
USBEP1CFGR 0x038 USB Endpoint 1 Configuration Register 0x1000_03FF
USBEP2CSR 0x03C USB Endpoint 2 Control and Status Register 0x0000_0002
USBEP2IER 0x040 USB Endpoint 2 Interrupt Enable Register 0x0000_0000
USBEP2ISR 0x044 USB Endpoint 2 Interrupt Status Register 0x0000_0000
USBEP2TCR 0x048 USB Endpoint 2 Transfer Count Register 0x0000_0000
USBEP2CFGR 0x04C USB Endpoint 2 Configuration Register 0x1000_03FF
USBEP3CSR 0x050 USB Endpoint 3 Control and Status Register 0x0000_0002
Register Descriptions
USB Control and Status Register – USBCSR
This register specifies the USB control bits and USB data line status.
Offset: 0x000
Reset value: 0x0000_00X6
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved ZLRXIE SDERIE SDRXIE STRXIE
Type/Reset RW 0 RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
UERIE STLIE NAKIE IDTXIE ITRXIE ODOVIE ODRXIE OTRXIE
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved RXCNT
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
Reserved TXCNT
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
EPEN Reserved EPADR
Type/Reset RO 1 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
UERIE STLIE NAKIE IDTXIE ITRXIE ODOVIE ODRXIE OTRXIE
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved
Type/Reset
7 6 5 4 3 2 1 0
UERIF STLIF NAKIF IDTXIF ITRXIF ODOVIF ODRXIF OTRXIF
Type/Reset WC 0 WC 0 WC 0 WC 0 WC 0 WC 0 WC 0 WC 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
Reserved TCNT
Type/Reset RW 0
7 6 5 4 3 2 1 0
TCNT
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
EPEN Reserved EPTYPE EPDIR EPADR
Type/Reset RW 0 RW 0 RW 1 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved TCNT1
Type/Reset RW 0 RW 0
31 30 29 28 27 26 25 24
EPEN Reserved EPTYPE EPDIR EPADR
Type/Reset RW 0 RW 0 RW 1 RW 0 RW 0 RW 0
Introduction
The Peripheral Direct Memory Access circuitry, PDMA, provides 6 unidirectional channels for
dedicated peripherals to implement the peripheral-to-memory and memory-to-peripheral data
transfer. The memory-to-memory data transfer such as the FLASH-to-SRAM or SRAM-to-
Features
▄▄ 6 unidirectional PDMA channels
▄▄ Memory-to-peripheral, peripheral-to-memory and memory-to-memory data transfer
▄▄ 8-bit, 16-bit and 32-bit width data transfer
▄▄ Software and hardware requested data transfer with configurable channel priority
▄▄ Linear, circular and non-increment address modes
▄▄ 4 transfer event flags – Transfer complete, Half Transfer, Block End and Transfer Error
▄▄ Auto-Reload function
PDMA
Control Logic & Transfer
Req & Ack
Registers Interrupts
Interface
Functional Description
AHB Master
The PDMA is an AHB master connected to other AHB peripherals such as the FLASH memory,
the SRAM memory and the AHB-to-APB bridges through the bus-matrix. The CPU and PDMA
can access different AHB slaves at the same time via the bus-matrix.
PDMA Channel
IP1
CH0 HW REQ High priority
0
Channel 0
IPn
CH0 SW REQ
1
Channel 2
PDMA
Request
IPx
CHn HW REQ
0
Channel n
IPy
CHn SW REQ
1 Low priority
SWTRIG
Enable
Channel transfer
A PDMA channel transfer is split into multiple block transactions with PDMA arbitration occurring
at the end of each block transaction. Although these channel transfers can all be activated, there
is only one block transaction being transferred through the bus at a time. The channel transfer
sequence depends upon the channel priority setting of each PDMA channel. The total transfer size
is calculated from the block transaction count and block size. The block size is equal to the product
of the block length and data bit width. For an efficient transfer, it is recommended that the block
length is set as a multiple of 4.
A PDMA channel total transfer data size = Block transaction count x (Block length x Data width)
Channel Priority
The PDMA provides four priority levels, known as very high, high, medium and low, which can
be configured by the application software. The PDMA also provides two methods to determine
the channel priority. One is determined by application software configuration and the other is
determined by the fixed hardware channel number. The PDMA arbitration processor will first
check the software configuring channel priority level used to request the PDMA to provide the
data transfer services. If more than one channel has the same priority, the channel with a smaller
channel number will have priority over one with a larger channel number after arbitration.
Note that the highest priority channel will not occupy the PDMA service all the time when other
lower priority channel requests are pending. The highest priority channel will be skipped for one
block transaction time duration after one block transaction is complete. Then a block transaction
requested by the second priority channel will be performed. After a block transaction of the second
priority channel is complete, the PDMA arbitration processor will re-check all of the requested
channel priority with the exception of the second priority channel since the second priority
channel will be excluded after the end of a block transaction. Therefore, a block data transaction
of the higher priority channel will be serviced and this channel will be excluded from the priority
arbitration at the end of the block transaction. The PDMA will keep transferring the data using the
method described above until all of the requested channel data transfer is complete. Refer to the
accompanying figure for an example which shows the PDMA channel arbitration and scheduling.
Priority: CH1 > CH2 Priority: CH1 > CH2 Priority: CH1 Priority: CH2
Skip: CH0 Skip: CH0 Skip: CH2 Skip: n/a
Time
Priority: CH0 > CH2 Priority: CH2 Priority: CH2
Skip: CH1 Skip: CH1 Skip: n/a
Transfer Request
For a peripheral-to-memory or memory-to-peripheral transfer, one peripheral hardware request will
trigger one block transaction of the dedicated PDMA channel. However, a complete data transfer
of the relevant dedicated PDMA channel will be triggered when a software request occurs. It is
recommended that the PDMA channel is configured to have a lower priority level and a smaller
block length which is requested by the software for memory-to-memory data copy applications.
Address Mode
Auto-Reload
When the auto-reload control bit, AUTORLn, in the PDMA channel n control register
PDMACHnCR is set, both the channel n current address and the channel n current transfer size
will be automatically reloaded with the corresponding start value after the current PDMA channel
data transfer has totally completed. The channel n will still be activated and the next relative
PDMA request can be serviced without any re-configuration using the application software.
Transfer Interrupt
There are five transfer events during which the interrupts can be asserted for each PDMA channel.
These are the block transaction end (BE), half-transfer (HT), transfer complete (TC), transfer
error (TE) and global transfer event (GE). Setting the corresponding control bits in the PDMA
interrupt enable register PDMAIER will enable the relevant interrupt events. The global interrupt
event, GE, will be generated if any of the four interrupt events including the BE, HT, TC or TE
occurs. Clearing the BE, HT, TC or TE event flags will also clear the GE flag. Clearing the GE
flag will automatically clear all other event flags. The TE interrupt event will occur when the
Register Map
The following table shows the PDMA registers and the reset values.
Table 69. PDMA Register Map
Register Offset Description Reset Value
PDMA Base Address = 0x4009_0000
PDMA Channel 0 Registers
PDMACH0CR 0x000 PDMA Channel 0 Control Register 0x0000_0000
PDMACH0SADR 0x004 PDMA Channel 0 Source Address Register 0x0000_0000
PDMACH0DADR 0x008 PDMA Channel 0 Destination Address Register 0x0000_0000
PDMACH0TSR 0x010 PDMA Channel 0 Transfer Size Register 0x0000_0000
PDMACH0CTSR 0x014 PDMA Channel 0 Current Transfer Size Register 0x0000_0000
PDMA Channel 1 Registers
PDMACH1CR 0x018 PDMA Channel 1 Control Register 0x0000_0000
PDMACH1SADR 0x01C PDMA Channel 1 Source Address Register 0x0000_0000
PDMACH1DADR 0x020 PDMA Channel 1 Destination Address Register 0x0000_0000
PDMACH1TSR 0x028 PDMA Channel 1 Transfer Size Register 0x0000_0000
PDMACH1CTSR 0x02C PDMA Channel 1 Current Transfer Size Register 0x0000_0000
PDMA Channel 2 Registers
PDMACH2CR 0x030 PDMA Channel 2 Control Register 0x0000_0000
PDMACH2SADR 0x034 PDMA Channel 2 Source Address Register 0x0000_0000
PDMACH2DADR 0x038 PDMA Channel 2 Destination Address Register 0x0000_0000
PDMACH2TSR 0x040 PDMA Channel 2 Transfer Size Register 0x0000_0000
PDMACH2CTSR 0x044 PDMA Channel 2 Current Transfer Size Register 0x0000_0000
PDMA Channel 3 Registers
PDMACH3CR 0x048 PDMA Channel 3 Control Register 0x0000_0000
PDMACH3SADR 0x04C PDMA Channel 3 Source Address Register 0x0000_0000
PDMACH3DADR 0x050 PDMA Channel 3 Destination Address Register 0x0000_0000
PDMACH3TSR 0x058 PDMA Channel 3 Transfer Size Register 0x0000_0000
PDMACH3CTSR 0x05C PDMA Channel 3 Current Transfer Size Register 0x0000_0000
PDMA Channel 4 Registers
PDMACH4CR 0x060 PDMA Channel 4 Control Register 0x0000_0000
PDMACH4SADR 0x064 PDMA Channel 4 Source Address Register 0x0000_0000
PDMACH4DADR 0x068 PDMA Channel 4 Destination Address Register 0x0000_0000
PDMACH4TSR 0x070 PDMA Channel 4 Transfer Size Register 0x0000_0000
Register Descriptions
PDMA Channel n Control Register – PDMACHnCR, n = 0 ~ 5
This register is used to specify the PDMA channel n data transfer configuration.
Offset: 0x000 (0), 0x018 (1), 0x030 (2), 0x048 (3), 0x060 (4), 0x078 (5)
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
SADRn
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
DADRn
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
BLKCNTn
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
CBLKCNTn
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
Reserved TEISTA5 TCISTA5 HTISTA5 BEISTA5 GEISTA5 TEISTA4
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
Reserved TEICLR5 TCICLR5 HTICLR5 BEICLR5 GEICLR5 TEICLR4
Type/Reset WC 0 WC 0 WC 0 WC 0 WC 0 WC 0
23 22 21 20 19 18 17 16
TCICLR4 HTICLR4 BEICLR4 GEICLR4 TEICLR3 TCICLR3 HTICLR3 BEICLR3
Type/Reset WC 0 WC 0 WC 0 WC 0 WC 0 WC 0 WC 0 WC 0
15 14 13 12 11 10 9 8
GEICLR3 TEICLR2 TCICLR2 HTICLR2 BEICLR2 GEICLR2 TEICLR1 TCICLR1
Type/Reset WC 0 WC 0 WC 0 WC 0 WC 0 WC 0 WC 0 WC 0
7 6 5 4 3 2 1 0
HTICLR1 BEICLR1 GEICLR1 TEICLR0 TCICLR0 HTICLR0 BEICLR0 GEICLR0
Type/Reset WC 0 WC 0 WC 0 WC 0 WC 0 WC 0 WC 0 WC 0
31 30 29 28 27 26 25 24
Reserved TEIE5 TCIE5 HTIE5 BEIE5 GEIE5 TEIE4
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
Introduction
The external bus interface is able to access external parallel interface devices such as SRAM, Flash
and LCD modules. The interface is memory mapped into the internal address bus of the CPU. The
data and address lines can be multiplexed in order to reduce the number of pins required to connect
Features
▄▄ Programmable interface for various memory types
●● Asynchronous static random access memory – SRAM
●● Read-only memory – ROM
●● NOR Flash memory
●● 8-bit or 16-bit parallel bus CPU interface device
▄▄ Translates AHB transactions into appropriate external device protocol
▄▄ Up to 4 memory bank regions and independent chip select control for each memory bank
▄▄ Programmable timings to support a wide range of devices
●● Programmable wait states
●● Programmable bus turnaround cycles
●● Programmable output enable and write enable cycles extension
●● Programmable active high or low setting of interface control signal
▄▄ Automatic translation when AHB transaction width and external memory interface width is
different
▄▄ Write buffer to decrease stalling of the AHB write burst transactions
▄▄ Supports multiplexed and non-multiplexed address and data line configurations
●● Up to 21 address lines
●● 8-bit or 16-bit data bus width
Function Descriptions
An overview of the EBI module is shown in Figure 186. The EBI enables internal CPU and other
bus matrix master peripherals to access external memories or devices. The EBI automatically
translates the internal AHB transactions into the external device protocol. In particular, if the
selected external memory is 16 or 8 bits width, then 32-bit wide transactions on the AHB are auto
split into consecutive 16 or 8-bit accesses.
AHB
Interface AHB Slave Interface
Register
Block
Control Block
I/O
External Bus
The EBI supports multiplexed and non-multiplexed addressing modes. The non-multiplexed
addressing mode can be operated more efficiently and faster but it requires a higher number of
pins. The multiplexed addressing modes are slower and require an external address latch device
and a lower number of pins. The functionality of the 16 EBI_AD pins depends on what kind of the
multiplexed addressing mode is used. They are used for both address and data in the multiplexed
modes. Also for the non-multiplexed 8-bit address mode, both the address and data fit into these 16
EBI_AD pins. If more address bits or data bits are needed, an external latch can be used to support
up to 20-bit addresses or 16-bit data in the multiplexed addressing modes using only the 16 EBI_
AD pins. Furthermore, independent of the addressing mode, up to 21 non-multiplexed address lines
can be enabled on the EBI_A pin connections. The detailed operation in the supported modes is
presented in the following sections. The AHB clock (HCLK) is the reference clock for the EBI.
EBI_AD[15:8] ADDR[7:0]
EBI_AD[7:0] DATA[7:0]
EBI_CSn
EBI_OE
Figure 187. EBI Non-multiplexed 8-bit Data, 8-bit Address Read Operation
EBI_AD[15:8] ADDR[7:0]
EBI_AD[7:0] DATA[7:0]
EBI_CSn
EBI_WE
Figure 188. EBI Non-multiplexed 8-bit Data, 8-bit Address Write Operation
EBI_A[N:0] ADDR[N+1:1]
EBI_AD[15:0] DATA[15:0]
EBI_CSn
EBI_OE
Figure 189. EBI Non-multiplexed 16-bit Data, N-bit Address Read Operation
EBI_A[N:0] ADDR[N+1:1]
EBI_AD[15:0] DATA[15:0]
EBI_CSn
EBI_WE
Figure 190. EBI Non-multiplexed 16-bit Data, N-bit Address Write Operation
Since the internal AHB address (HADDR) is a byte (8-bit) address whereas the 16-bit width of
external device is addressed in words (16-bit), the address actually issued to the external device
varies according to the data width as shown in the following table.
In case of a 16-bit external device width, the EBI will internally use HADDR[N+1:1] to generate
the address EBI_A[N:0] for external device. Whatever the external memory width (16-bit or 8-bit),
EBI_A[0] should be connected to external device address A[0].
External
EBI Asynchronous
EBI_ALE Device
Data
Control
At the start of the transaction the address is output on the EBI_AD lines. The external address
latch is controlled by the EBI_ALE signal and stores the address. Then the data is read or written
according to operation. Read and write signals are shown in Figure 192 and Figure 193.
EBI_ALE
EBI_CSn
EBI_OE
Figure 192. EBI Multiplexed 16-bit Data, 16-bit Address Read Operation
EBI_ALE
EBI_WE
Figure 193. EBI Multiplexed 16-bit Data, 16-bit Address Write Operation
EBI_ALE
EBI_CSn
EBI_OE
Figure 194. EBI Multiplexed 8-bit Data, 20-bit Address Read Operation
EBI_CSn
EBI_WE
Figure 195. EBI Multiplexed 8-bit Data, 20-bit Address Write Operation
The EBIBUSY status bit in the EBISR register indicates whether an AHB transaction is still active
in the EBI or not. When performing an AHB read or write, the EBIBUSY bit stays 1 until the
required transaction(s) with the external device has finished.
EBI_OE
Figure 196. EBI Inserts an IDLE Cycle between Transactions in the Same Bank (NOIDLE = 0)
EBI_CSn
EBI_OE
Figure 197. EBI De-asserts an IDLE Cycle between Transactions in the Same Bank (NOIDLE = 1)
Table 70. EBI Maps AHB Transactions Width to External Device Transactions.
8-bit External Device 16-bit External Device
AHB Transaction
Transaction Transaction
1 x 16-bit read
8-bit read 1 x 8-bit read
(EBI ignore the superfluous data)
16-bit read 2 x 8-bit read 1 x 16-bit read
32-bit read 4 x 8-bit read 2 x 16-bit read
1 x 16-bit read;
Table 71. EBI Maps AHB Transactions Width to External Device Transactions Width
Access from AHB Master Access to External Bus Interface (EBI)
External Output
Bus Width Access type Address Valid data at
Note Access split value from
HADDR[1:0] EBI_AD[15:0]
EBI_A[1:0]
0b00 No split 0b00
0b01 No split 0b01
Byte (8-bit)
0b10 No split 0b10
0b11 No split 0b11
Half-word 1/2 access 0b00
0b00
(16-bit) 2/2 access 0b01
8-bit EBI_AD[7:0]
Half-word 1/2 access 0b10
0b10
(16-bit) 2/2 access 0b11
1/4 access 0b00
Word 2/4 access 0b01
0b00
(32-bit) 3/4 access 0b10
4/4 access 0b11
0b00 No split 0bx0 EBI_AD[7:0]
0b01 No split 0bx0 EBI_AD[15:8]
Byte (8-bit)
0b10 No split 0bx1 EBI_AD[7:0]
0b11 No split 0bx1 EBI_AD[15:8]
16-bit
Half-word 0b00 No split 0bx0 EBI_AD[15:0]
(16-bit) 0b10 No split 0bx1 EBI_AD[15:0]
Word 1/2 access 0bx0 EBI_AD[15:0]
0b00
(32-bit) 2/2 access 0bx1 EBI_AD[15:0]
0x7000_0000
EBI Selection Bank
0x6000_0000
Reserved
EBI Bank 3 (4MB)
0x6C00_0000
Reserved
0x4000_0000
EBI Bank 2 (4MB) 4 MBytes
0x6800_0000
Reserved x4
EBI Bank 1 (4MB)
0x6400_0000
Reserved
EBI Bank 0 (4MB)
SRAM 0x6000_0000
0x2000_0000
CODE
0x0000_0000
PDMA Request
The EBI only supports a software trigger for activating a PDMA service.
Register Map
The following table shows the EBI register and reset value.
Table 72. EBI Register Map
Register Descriptions
EBI Control Register – EBICR
This register specifies the control setting for EBI bank.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
IDLET Reserved
Type/Reset RW 0 RW 0 RW 0 RW 0
23 22 21 20 19 18 17 16
Reserved
Type/Reset
15 14 13 12 11 10 9 8
NOIDLE3 NOIDLE2 NOIDLE1 NOIDLE0 BANKEN3 BANKEN2 BANKEN1 BANKEN0
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
7 6 5 4 3 2 1 0
Mode3 Mode2 Mode1 Mode0
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
Introduction
The I 2S is a synchronous communication interface that can be used as a master or slave to
exchange data with other audio peripherals, such as ADCs or DACs. The I2S supports a variety of
data formats. In addition to the stereo I2S-justified, Left-justified and Right-justified modes, there
I2SMCLK
I2SWS
MUX
APB I2SBCLK
Interface
MUX
&
Control
Registers
PDMA Ack
Mster/Slave
Features
▄▄ Master or slave mode
▄▄ Mono and stereo
▄▄ I2S-justified, Left-justified, and Right-justified mode
▄▄ 8/16/24/32-bit sample size with 32-bit channel extended
▄▄ 8 × 32-bit TX & RX FIFO with PDMA supported
▄▄ 8-bit Fractional Clock Divider with rate control
Functional Description
I2S Master and Slave Mode
The I2S can operate in slave or master mode. Within the I2S module the difference between these
modes lies in the word select (WS) signal which determines the timing of data transmissions.
▄▄ In the master mode, the word select signal is generated internally by a clock rate generator.
▄▄ In the slave mode, the word select signal is input on the I2S_WS pin.
I2S_BCLK I2S_BCLK
I2S_WS I2S_WS
I2S Master I2S Slave
I2S_DI I2S_DO
I2S_DO I2S_DI
Controller
Master
I2S_BCLK I2S_BCLK
I2S_WS I2S_WS
I2S Slave I2S Slave
I2S_DI I2S_DO
I2S_DO I2S_DI
Because the fractional rate divider is a fully digital implementation function, the divider output
clock transitions are synchronous with the input source clock. Therefore, the fractional rate divider
will generate some jitter with some divider settings. Users should make note of this phenomenon
when choosing the X and Y setup values. It is possible to avoid jitter entirely by choosing fractions
such that X divides evenly into Y. For example, 2/4, 2/6, 3/9, etc.
The tables below show the recommended setup values to reduce clock jitter for different source
clocks and sample rates.
X Y
8-bit Fractional
PCLK Rate Divider
2 (N+1) I2S_BCLK
& Fine-Tuning
Controller
I2S Control
I2S_WS
Logic
BCLK
BCLK
BCLK
BCLK
BCLK
BCLK
INV
WS
BCLK
INV
BCLK
WS
BCLK
INV
WS
BCLK
INV
BCLK
WS
BCLK
INV
WS
BCLK
INV
BCLK
WS
BCLK
BCLK
15 N+1 0 15 N 0 M
31 23 N 0 M
31 N 0 M
15 LEFT 0 15 RIGHT 0 M
31 23 LEFT 0 M
31 23 RIGHT 0 M+1
31 LEFT 0 M
31 RIGHT 0 M+1
The I2S transmitter and receiver have separate PDMA requests and can be assigned to two different
PDMA channels. When a PDMA request is enabled for the I 2S transmitter (TXDMAEN = 1)
then this will automatically request that data is transferred to the assigned I2S TX PDMA channel
whenever TX FIFO space is available and TXFTL is active. When a PDMA request is enabled for
the receiver (RXDMAEN = 1) then this will automatically request the data transfers to the I2S RX
PDMA channel whenever data is present in the receive FIFO and when RXFTL is active.
Register Map
The following table shows the I2S registers and reset values.
Table 75. I2S Register Map
Register Offset Description Reset Value
I2SCR 0x000 I2S Control Register 0x0000_0000
I2SIER 0x004 I2S Interrupt Enable Register 0x0000_0000
I2SCDR 0x008 I2S Clock Divider Register 0x0000_0000
I2STXDR 0x00C I2S TX Data Register 0x0000_0000
I2SRXDR 0x010 I S RX Data Register
2
0x0000_0000
I2SFCR 0x014 I2S FIFO Control Register 0x0000_0000
I2SSR 0x018 I S Status Register
2
0x0000_0809
I2SRCNTR 0x01C I2S Rate Counter Value Register 0x0000_0000
Register Descriptions
I2S Control Register – I2SCR
This register specifies the corresponding I2S function enable control.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
TXDR
Type/Reset WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0
31 30 29 28 27 26 25 24
RXDR
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
23 22 21 20 19 18 17 16
RXDR
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
15 14 13 12 11 10 9 8
RXDR
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
7 6 5 4 3 2 1 0
RXDR
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset
31 30 29 28 27 26 25 24
RXFS TXFS
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
Reserved
Type/Reset RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0 RW 0
Introduction
The CRC (Cyclic Redundancy Check) calculation unit is an error detection technique test algorithm
and uses to verify data transmission or storage data correctness. A CRC calculation takes a data
stream or a block of data as input and generates a 16- or 32-bit output remainder. Ordinarily, a data
CRC Control
Register
CRC Seed
Register
CCITT-16
CRC Data POLY
Register
AHB Bus
B0
CRC-32
POLY
BYTE
CRC FSM
REVERSE
CRC Sum
Register
Features
▄▄ Support CRC16 polynomial: 0x8005, X16+X15+X2+1
▄▄ Support CCITT CRC16 polynomial: 0x1021, X16+X12+X5+1
▄▄ Support IEEE-802.3 CRC32 polynomial: 0x04C11DB7, X32+X26+X23+X22+X16+X12+X11+X10+X8
+X7+X5+X4+X2+X+1
▄▄ Support 1’s complement, byte reverse & bit reverse operation on data and checksum
Function Descriptions
This unit only enables the calculation in the CRC16, CCITT CRC16 and IEEE-802.3 CRC32
polynomial. In this unit, the generator polynomial is fixed to the numeric values for those modes;
therefore, the CRC value based on other generator polynomials cannot be calculated.
CRC Computation
The CRC calculation unit has 32-bit write CRC data register (CRCDR) and read CRC checksum
register (CRCCSR). The CRCDR register is used to input new data (write access), and the
CRCCSR register is used to hold the result of the previous CRC calculation (read access). Each
write operation to the CRCDR register creates a combination of the previous CRC value (stored
in CRCCSR) and the new one. The CRC block diagram is shown as Figure 217. The CRC unit
calculates the CRC data register (CRCDR) value is basic on byte by byte and default byte and bit
order is big-endian. The CRCDR register can be accessed write by word, right-aligned half-word
and right-aligned byte. For the other registers only 32-bit access is allowed. The duration of the
computation depends on data width:
▄▄ 4 AHB clock cycles for 32-bit data input
▄▄ 2 AHB clock cycles for 16-bit data input
▄▄ 1 AHB clock cycles for 8-bit data input
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
Bit7
Bit6
Bit5
Bit4
Bit3
Bit2
Bit1
Bit0
big-endian
Register Map
The following table shows the CRC registers and reset values.
Table 76. CRC Register Map
Register Offset Description Reset Value
CRC Base Address = 0x4008A000
CRCCR 0x000 CRC Control Register 0x0000_0000
CRCSDR 0x004 CRC Seed Register 0x0000_0000
CRCCSR 0x008 CRC Checksum Register 0x0000_0000
CRCDR 0x00C CRC Data Register 0x0000_0000
Register Descriptions
CRC Control Register – CRCCR
This register specifies the corresponding CRC function enable control.
Offset: 0x000
Reset value: 0x0000_0000
31 30 29 28 27 26 25 24
31 30 29 28 27 26 25 24
SEED
Type/Reset WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0
31 30 29 28 27 26 25 24
CHKSUM
Type/Reset RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0 RO 0
31 30 29 28 27 26 25 24
CRCDATA
Type/Reset WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0 WO 0