GD32E10x User Manual Rev1.6
GD32E10x User Manual Rev1.6
GD32E10x
ARM® Cortex®-M4 32-bit MCU
User Manual
Revision 1.6
(Dec. 2021)
1
GD32E10x User Manual
Table of Contents
Table of Contents ........................................................................................................... 2
List of Figures .............................................................................................................. 14
List of Tables ................................................................................................................ 20
1. System and memory architecture ........................................................................ 23
1.1. ARM Cortex-M4 processor ........................................................................................ 23
1.2. System architecture .................................................................................................. 24
1.3. Memory map .............................................................................................................. 26
1.3.1. Bit-banding ............................................................................................................................ 30
1.3.2. On-chip SRAM memory ........................................................................................................ 31
1.3.3. On-chip flash memory overview ........................................................................................... 31
3
GD32E10x User Manual
5.3.2. Clock configuration register 0 (RCU_CFG0) ........................................................................ 78
5.3.3. Clock interrupt register (RCU_INT) ...................................................................................... 81
5.3.4. APB2 reset register (RCU_APB2RST) ................................................................................. 85
5.3.5. APB1 reset register (RCU_APB1RST) ................................................................................. 87
5.3.6. AHB enable register (RCU_AHBEN) .................................................................................... 89
5.3.7. APB2 enable register (RCU_APB2EN) ................................................................................ 91
5.3.8. APB1 enable register (RCU_APB1EN) ................................................................................ 93
5.3.9. Backup domain control register (RCU_BDCTL) ................................................................... 95
5.3.10. Reset source/clock register (RCU_RSTSCK) ...................................................................... 97
5.3.11. AHB reset register (RCU_AHBRST)..................................................................................... 98
5.3.12. Clock configuration register 1 (RCU_CFG1) ........................................................................ 99
5.3.13. Deep-sleep mode voltage register (RCU_DSV) ................................................................. 102
5.3.14. Additional clock control register (RCU_ADDCTL) .............................................................. 102
5.3.15. Additional clock interrupt register (RCU_ADDINT) ............................................................. 103
5.3.16. APB1 additional reset register (RCU_ADDAPB1RST) ....................................................... 104
5.3.17. APB1 additional enable register (RCU_ADDAPB1EN) ...................................................... 104
4
GD32E10x User Manual
7.6.4. Falling edge trigger enable register (EXTI_FTEN) ............................................................. 124
7.6.5. Software interrupt event register (EXTI_SWIEV) ............................................................... 124
7.6.6. Pending register (EXTI_PD) ............................................................................................... 125
6
GD32E10x User Manual
11.2.4. Debug reset ........................................................................................................................ 176
11.2.5. JEDEC-106 ID code ........................................................................................................... 176
8
GD32E10x User Manual
14. Watchdog timer (WDGT) .................................................................................. 231
14.1. Free watchdog timer (FWDGT) ............................................................................ 231
14.1.1. Overview ............................................................................................................................. 231
14.1.2. Characteristics .................................................................................................................... 231
14.1.3. Function overview ............................................................................................................... 231
14.1.4. Register definition ............................................................................................................... 234
16.4. General level2 timer (TIMERx, x=9, 10, 12, 13) ................................................... 377
16.4.1. Overview ............................................................................................................................. 377
16.4.2. Characteristics .................................................................................................................... 377
16.4.3. Block diagram ..................................................................................................................... 377
16.4.4. Function overview ............................................................................................................... 378
16.4.5. TIMERx registers (x=9, 10, 12, 13) ..................................................................................... 386
12
GD32E10x User Manual
20.3. Function overview ................................................................................................ 505
20.3.1. Block diagram ..................................................................................................................... 505
20.3.2. Basic regulation of EXMC access....................................................................................... 506
20.3.3. NOR/PSRAM controller ...................................................................................................... 507
13
GD32E10x User Manual
List of Figures
Figure 1-1. The structure of the Cortex®-M4 processor......................................................................... 24
Figure 1-2. GD32E10x series system architecture ................................................................................. 26
Figure 2-1. Process of page erase operation .......................................................................................... 39
Figure 2-2. Process of mass erase operation ......................................................................................... 40
Figure 2-3. Process of word program operation .................................................................................... 42
Figure 3-1. Power supply overview ......................................................................................................... 54
Figure 3-2. Waveform of the POR / PDR .................................................................................................. 56
Figure 3-3. Waveform of the LVD threshold ........................................................................................... 56
Figure 5-1. The system reset circuit ........................................................................................................ 69
Figure 5-2. Clock tree ................................................................................................................................ 70
Figure 5-3. HXTAL clock source ............................................................................................................... 71
Figure 6-1. Block diagram of CTC .......................................................................................................... 107
Figure 6-2. CTC trim counter .................................................................................................................. 108
Figure 7-1. Block diagram of EXTI ......................................................................................................... 121
Figure 8-1. Basic structure of a standard I/O port bit .......................................................................... 127
Figure 8-2. Input configuration............................................................................................................... 129
Figure 8-3. Output configuration ............................................................................................................ 129
Figure 8-4. Analog configuration ........................................................................................................... 130
Figure 8-5. Alternate function configuration ........................................................................................ 131
Figure 9-1. Block diagram of CRC calculation unit .............................................................................. 157
Figure 10-1. Block diagram of DMA ....................................................................................................... 161
Figure 10-2. Handshake mechanism ..................................................................................................... 163
Figure 10-3. DMA interrupt logic ............................................................................................................ 165
Figure 10-4. DMA0 request mapping ..................................................................................................... 166
Figure 10-5. DMA1 request mapping ..................................................................................................... 167
Figure 12-1. ADC module block diagram .............................................................................................. 184
Figure 12-2. Single conversion mode .................................................................................................... 186
Figure 12-3. Continuous conversion mode .......................................................................................... 187
Figure 12-4. Scan conversion mode, continuous disable ................................................................... 188
Figure 12-5. Scan conversion mode, continuous enable .................................................................... 188
Figure 12-6. Discontinuous conversion mode ..................................................................................... 189
Figure 12-7. Auto-insertion, CNT = 1 ..................................................................................................... 190
Figure 12-8. Triggered insertion............................................................................................................. 190
Figure 12-9. 12-bit data alignment ......................................................................................................... 191
Figure 12-10. 6-bit data alignment ......................................................................................................... 192
Figure 12-11. 20-bit to 16-bit result truncation ..................................................................................... 195
Figure 12-12. A numerical example with 5-bit shifting and rounding ................................................ 195
Figure 12-13. ADC sync block diagram ................................................................................................. 197
Figure 12-14. Regular parallel mode on 16 channels........................................................................... 198
Figure 12-15. Inserted parallel mode on 4 channels ............................................................................ 198
14
GD32E10x User Manual
Figure 12-16. Follow-up fast mode on 1 channel in continuous conversion mode ......................... 199
Figure 12-17. Follow-up slow mode on 1 channel ................................................................................ 200
Figure 12-18. Trigger rotation: inserted channel group ...................................................................... 200
Figure 12-19. Trigger rotation: inserted channels in discontinuous mode ....................................... 201
Figure 12-20. Regular parallel & trigger rotation mode ....................................................................... 201
Figure 12-21. Trigger occurs during inserted conversion .................................................................. 202
Figure 12-22 Follow-up single channel with inserted sequence CH1, CH2 ....................................... 202
Figure 13-1. DAC block diagram ............................................................................................................ 218
Figure 13-2. DAC LFSR algorithm .......................................................................................................... 220
Figure 13-3. DAC triangle noise wave ................................................................................................... 220
Figure 14-1. Free watchdog block diagram .......................................................................................... 232
Figure 14-2. Window watchdog timer block diagram .......................................................................... 238
Figure 14-3. Window watchdog timing diagram ................................................................................... 239
Figure 15-1. Block diagram of RTC ........................................................................................................ 243
Figure 16-1. Advanced timer block diagram ......................................................................................... 252
Figure 16-2. Normal mode, internal clock divided by 1 ....................................................................... 253
Figure 16-3. Counter timing diagram with prescaler division change from 1 to 2 ........................... 254
Figure 16-4. Timing chart of up counting mode, PSC=0/1 .................................................................. 255
Figure 16-5. Timing chart of up counting mode, change TIMERx_CAR ongoing ............................. 256
Figure 16-6. Timing chart of down counting mode, PSC=0/1 ............................................................. 257
Figure 16-7. Timing chart of down counting mode, change TIMERx_CAR ongoing ........................ 258
Figure 16-8. Timing chart of center-aligned counting mode ............................................................... 259
Figure 16-9. Repetition counter timing chart of center-aligned counting mode ............................... 260
Figure 16-10. Repetition counter timing chart of up counting mode ................................................. 260
Figure 16-11. Repetition counter timing chart of down counting mode ............................................ 261
Figure 16-12. Input capture logic ........................................................................................................... 262
Figure 16-13. Output compare logic (with complementary output, x=0,1,2) ..................................... 263
Figure 16-14. Output compare logic (CH3_O) ....................................................................................... 263
Figure 16-15. Output-compare in three modes ..................................................................................... 265
Figure 16-16. Timing chart of EAPWM ................................................................................................... 266
Figure 16-17. Timing chart of CAPWM .................................................................................................. 266
Figure 16-18. Complementary output with dead time insertion ......................................................... 269
Figure 16-19. Output behavior of the channel in response to a break (the break high active) ....... 270
Figure 16-20. Example of counter operation in encoder interface mode .......................................... 271
Figure 16-21. Example of encoder interface mode with CI0FE0 polarity inverted ............................ 271
Figure 16-22. Hall sensor is used for BLDC motor .............................................................................. 272
Figure 16-23. Hall sensor timing between two timers.......................................................................... 273
Figure 16-24. Restart mode .................................................................................................................... 274
Figure 16-25. Pause mode ...................................................................................................................... 274
Figure 16-26. Event mode ....................................................................................................................... 275
Figure 16-27. Single pulse mode TIMERx_CHxCV=0x04, TIMERx_CAR=0x60 ................................. 276
Figure 16-28. TIMER0 master/slave mode example ............................................................................. 276
Figure 16-29. Trigger mode of TIMER0 controlled by enable signal of TIMER2 ............................... 277
Figure 16-30. Trigger mode of TIMER0 controlled by update signal of TIMER2 ............................... 278
15
GD32E10x User Manual
Figure 16-31. Pause mode of TIMER0 controlled by enable signal of TIMER2 ................................. 279
Figure 16-32. Pause mode of TIMER0 controlled by O0CPREF signal of TIMER2 ........................... 279
Figure 16-33. Trigger TIMER0 and TIMER2 by the CI0 signal of TIMER2 ........................................... 280
Figure 16-34. General Level 0 timer block diagram ............................................................................. 310
Figure 16-35. Normal mode, internal clock divided by 1 ...................................................................... 311
Figure 16-36. Counter timing diagram with prescaler division change from 1 to 2 ......................... 312
Figure 16-37. Timing chart of up counting mode, PSC=0/1 ................................................................ 313
Figure 16-38. Timing chart of up counting, change TIMERx_CAR ongoing ...................................... 314
Figure 16-39. Timing chart of down counting mode, PSC=0/1 ........................................................... 314
Figure 16-40. Timing chart of down counting mode, change TIMERx_CAR ongoing ...................... 316
Figure 16-41. Timing chart of center-aligned counting mode ............................................................. 317
Figure 16-42. Input capture logic ........................................................................................................... 318
Figure 16-43. Output compare logic (x=0,1,2,3) ................................................................................... 319
Figure 16-44. Output-compare under three modes .............................................................................. 320
Figure 16-45. Timing chart of EAPWM................................................................................................... 321
Figure 16-46. Timing chart of CAPWM .................................................................................................. 322
Figure 16-47. Example of counter operation in encoder interface mode .......................................... 323
Figure 16-48. Example of encoder interface mode with CI0FE0 polarity inverted ............................ 324
Figure 16-49. Restart mode .................................................................................................................... 325
Figure 16-50. Pause mode ...................................................................................................................... 325
Figure 16-51. Event mode ....................................................................................................................... 326
Figure 16-52. Single pulse mode TIMERx_CHxCV = 0x04, TIMERx_CAR=0x60 ............................... 327
Figure 16-53. General level1 timer block diagram................................................................................ 351
Figure 16-54. Normal mode, internal clock divided by 1 ..................................................................... 352
Figure 16-55. Counter timing diagram with prescaler division change from 1 to 2 ......................... 353
Figure 16-56. Timing chart of up counting mode, PSC=0/1 ................................................................ 354
Figure 16-57. Timing chart of up counting mode, change TIMERx_CAR ongoing ........................... 354
Figure 16-58. Input capture logic ........................................................................................................... 355
Figure 16-59. Output compare logic (x=0,1).......................................................................................... 356
Figure 16-60. Output-compare under three modes .............................................................................. 358
Figure 16-61. Timing chart of EAPWM ................................................................................................... 359
Figure 16-62. Timing chart of CAPWM .................................................................................................. 359
Figure 16-63. Restart mode .................................................................................................................... 361
Figure 16-64. Pause mode ...................................................................................................................... 361
Figure 16-65. Event mode ....................................................................................................................... 362
Figure 16-66. Single pulse mode TIMERx_CHxCV = 0x04, TIMERx_CAR=0x60 ............................... 363
Figure 16-67. General level2 timer block diagram................................................................................ 378
Figure 16-68. Normal mode, internal clock divided by 1 ..................................................................... 379
Figure 16-69. Counter timing diagram with prescaler division change from 1 to 2 ......................... 379
Figure 16-70. Timing chart of up counting mode, PSC=0/1 ................................................................ 380
Figure 16-71. Timing chart of up counting, change TIMERx_CAR ongoing ...................................... 381
Figure 16-72. Input capture logic ........................................................................................................... 382
Figure 16-73. Output compare logic ...................................................................................................... 383
Figure 16-74. Output-compare in three modes ..................................................................................... 384
16
GD32E10x User Manual
Figure 16-75. Basic timer block diagram .............................................................................................. 396
Figure 16-76. Normal mode, internal clock divided by 1 ..................................................................... 396
Figure 16-77. Counter timing diagram with prescaler division change from 1 to 2 ......................... 397
Figure 16-78. Timing chart of up counting mode, PSC=0/1 ................................................................ 398
Figure 16-79. Timing chart of up counting mode, change TIMERx_CAR ongoing ........................... 398
Figure 17-1. USART module block diagram .......................................................................................... 407
Figure 17-2. USART character frame (8 bits data and 1 stop bit) ....................................................... 407
Figure 17-3. USART transmit procedure ............................................................................................... 409
Figure 17-4. Receiving a frame bit by oversampling method ............................................................. 410
Figure 17-5. Configuration steps when using DMA for USART transmission .................................. 412
Figure 17-6. Configuration steps when using DMA for USART reception ......................................... 413
Figure 17-7. Hardware flow control between two USARTs.................................................................. 413
Figure 17-8. Hardware flow control........................................................................................................ 414
Figure 17-9. Break frame occurs during idle state ............................................................................... 415
Figure 17-10. Break frame occurs during a frame ................................................................................ 416
Figure 17-11. Example of USART in synchronous mode .................................................................... 416
Figure 17-12. 8-bit format USART synchronous waveform (CLEN=1) ............................................... 417
Figure 17-13. IrDA SIR ENDEC module ................................................................................................. 417
Figure 17-14. IrDA data modulation ....................................................................................................... 418
Figure 17-15. ISO7816-3 frame format ................................................................................................... 419
Figure 17-16. USART interrupt mapping diagram ................................................................................ 421
Figure 18-1. I2C module block diagram ................................................................................................ 437
Figure 18-2. Data validation .................................................................................................................... 438
Figure 18-3. START and STOP condition .............................................................................................. 438
Figure 18-4. Clock synchronization ....................................................................................................... 439
Figure 18-5. SDA line arbitration ............................................................................................................ 439
Figure 18-6. I2C communication flow with 7-bit address .................................................................... 440
Figure 18-7. I2C communication flow with 10-bit address(Master Transmit) .................................... 440
Figure 18-8. I2C communication flow with 10-bit address(Master Receive) ..................................... 440
Figure 18-9. Programming model for slave transmitting mode .......................................................... 442
Figure 18-10. Programming model for slave receiving mode ............................................................. 443
Figure 18-11. Programming model for master transmitting mode ..................................................... 445
Figure 18-12. Programming model for master receiving mode using Solution A ............................ 447
Figure 18-13. Programming model for master receiving mode using solution B ............................. 449
Figure 19-1. Block diagram of SPI ......................................................................................................... 466
Figure 19-2. SPI timing diagram in normal mode ................................................................................. 467
Figure 19-3. SPI timing diagram in Quad-SPI mode (CKPL=1, CKPH=1, LF=0) ................................ 468
Figure 19-4. A typical full-duplex connection ....................................................................................... 470
Figure 19-5. A typical simplex connection (Master: Receive, Slave: Transmit) ................................ 470
Figure 19-6. A typical simplex connection (Master: Transmit only, Slave: Receive) ....................... 470
Figure 19-7. A typical bidirectional connection .................................................................................... 471
Figure 19-8. Timing diagram of TI master mode with discontinuous transfer .................................. 473
Figure 19-9. Timing diagram of TI master mode with continuous transfer ....................................... 473
Figure 19-10. Timing diagram of TI slave mode ................................................................................... 473
17
GD32E10x User Manual
Figure 19-11. Timing diagram of NSS pulse with continuous transmission ..................................... 474
Figure 19-12. Timing diagram of quad write operation in Quad-SPI mode ....................................... 475
Figure 19-13. Timing diagram of quad read operation in Quad-SPI mode ........................................ 476
Figure 19-14. Block diagram of I2S ........................................................................................................ 479
Figure 19-15. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=0, CKPL=0) ..................... 481
Figure 19-16. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=0, CKPL=1) ..................... 481
Figure 19-17. I2S Phillips standard timing diagram (DTLEN=10, CHLEN=1, CKPL=0) ..................... 481
Figure 19-18. I2S Phillips standard timing diagram (DTLEN=10, CHLEN=1, CKPL=1) ..................... 481
Figure 19-19. I2S Phillips standard timing diagram (DTLEN=01, CHLEN=1, CKPL=0) ..................... 481
Figure 19-20. I2S Phillips standard timing diagram (DTLEN=01, CHLEN=1, CKPL=1) ..................... 482
Figure 19-21. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=1, CKPL=0) ..................... 482
Figure 19-22. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=1, CKPL=1) ..................... 482
Figure 19-23. MSB justified standard timing diagram (DTLEN=00, CHLEN=0, CKPL=0) ................. 482
Figure 19-24. MSB justified standard timing diagram (DTLEN=00, CHLEN=0, CKPL=1) ................. 483
Figure 19-25. MSB justified standard timing diagram (DTLEN=10, CHLEN=1, CKPL=0) ................. 483
Figure 19-26. MSB justified standard timing diagram (DTLEN=10, CHLEN=1, CKPL=1) ................. 483
Figure 19-27. MSB justified standard timing diagram (DTLEN=01, CHLEN=1, CKPL=0) ................. 483
Figure 19-28. MSB justified standard timing diagram (DTLEN=01, CHLEN=1, CKPL=1) ................. 483
Figure 19-29. MSB justified standard timing diagram (DTLEN=00, CHLEN=1, CKPL=0) ................. 483
Figure 19-30. MSB justified standard timing diagram (DTLEN=00, CHLEN=1, CKPL=1) ................. 484
Figure 19-31. LSB justified standard timing diagram (DTLEN=01, CHLEN=1, CKPL=0) .................. 484
Figure 19-32. LSB justified standard timing diagram (DTLEN=01, CHLEN=1, CKPL=1) .................. 484
Figure 19-33. LSB justified standard timing diagram (DTLEN=00, CHLEN=1, CKPL=0) .................. 484
Figure 19-34. LSB justified standard timing diagram (DTLEN=00, CHLEN=1, CKPL=1) .................. 485
Figure 19-35. PCM standard short frame synchronization mode timing diagram (DTLEN=00,
CHLEN=0, CKPL=0) ......................................................................................................................... 485
Figure 19-36. PCM standard short frame synchronization mode timing diagram (DTLEN=00,
CHLEN=0, CKPL=1) ......................................................................................................................... 485
Figure 19-37. PCM standard short frame synchronization mode timing diagram (DTLEN=10,
CHLEN=1, CKPL=0) ......................................................................................................................... 485
Figure 19-38. PCM standard short frame synchronization mode timing diagram (DTLEN=10,
CHLEN=1, CKPL=1) ......................................................................................................................... 485
Figure 19-39. PCM standard short frame synchronization mode timing diagram (DTLEN=01,
CHLEN=1, CKPL=0) ......................................................................................................................... 486
Figure 19-40. PCM standard short frame synchronization mode timing diagram (DTLEN=01,
CHLEN=1, CKPL=1) ......................................................................................................................... 486
Figure 19-41. PCM standard short frame synchronization mode timing diagram (DTLEN=00,
CHLEN=1, CKPL=0) ......................................................................................................................... 486
Figure 19-42. PCM standard short frame synchronization mode timing diagram (DTLEN=00,
CHLEN=1, CKPL=1) ......................................................................................................................... 486
Figure 19-43. PCM standard long frame synchronization mode timing diagram (DTLEN=00,
CHLEN=0, CKPL=0) ......................................................................................................................... 486
Figure 19-44. PCM standard long frame synchronization mode timing diagram (DTLEN=00,
CHLEN=0, CKPL=1) ......................................................................................................................... 487
18
GD32E10x User Manual
Figure 19-45. PCM standard long frame synchronization mode timing diagram (DTLEN=10,
CHLEN=1, CKPL=0) ......................................................................................................................... 487
Figure 19-46. PCM standard long frame synchronization mode timing diagram (DTLEN=10,
CHLEN=1, CKPL=1) ......................................................................................................................... 487
Figure 19-47. PCM standard long frame synchronization mode timing diagram (DTLEN=01,
CHLEN=1, CKPL=0) ......................................................................................................................... 487
Figure 19-48. PCM standard long frame synchronization mode timing diagram (DTLEN=01,
CHLEN=1, CKPL=1) ......................................................................................................................... 487
Figure 19-49. PCM standard long frame synchronization mode timing diagram (DTLEN=00,
CHLEN=1, CKPL=0) ......................................................................................................................... 488
Figure 19-50. PCM standard long frame synchronization mode timing diagram (DTLEN=00,
CHLEN=1, CKPL=1) ......................................................................................................................... 488
Figure 19-51. Block diagram of I2S clock generator ............................................................................ 488
Figure 20-1. The EXMC block diagram .................................................................................................. 506
Figure 20-2. EXMC memory banks......................................................................................................... 507
Figure 20-3. Mode 1 read access ............................................................................................................ 511
Figure 20-4. Mode 1 write access............................................................................................................ 511
Figure 20-5. Mode A read access ........................................................................................................... 512
Figure 20-6. Mode A write access .......................................................................................................... 513
Figure 20-7. Mode 2/B read access ........................................................................................................ 514
Figure 20-8. Mode 2 write access........................................................................................................... 515
Figure 20-9. Mode B write access .......................................................................................................... 515
Figure 20-10. Mode C read access ......................................................................................................... 517
Figure 20-11. Mode C write access ........................................................................................................ 517
Figure 20-12. Mode D read access ......................................................................................................... 519
Figure 20-13. Mode D write access ........................................................................................................ 519
Figure 20-14. Multiplex mode read access ........................................................................................... 521
Figure 20-15. Multiplex mode write access ........................................................................................... 521
Figure 20-16. Read access timing diagram under async-wait signal assertion ............................... 523
Figure 20-17. Write access timing diagram under async-wait signal assertion ............................... 523
Figure 20-18. Read timing of synchronous multiplexed burst mode ................................................. 525
Figure 20-19. Write timing of synchronous multiplexed burst mode................................................. 526
Figure 22-1. USBFS block diagram ........................................................................................................ 534
Figure 22-2. Connection with host or device mode ............................................................................. 535
Figure 22-3. Connection with OTG mode .............................................................................................. 536
Figure 22-4. State transition diagram of host port ............................................................................... 536
Figure 22-5. HOST mode FIFO space in SRAM .................................................................................... 541
Figure 22-6. Host mode FIFO access register mapping ...................................................................... 541
Figure 22-7. Device mode FIFO space in SRAM ................................................................................... 542
Figure 22-8. Device mode FIFO access register mapping .................................................................. 542
19
GD32E10x User Manual
List of Tables
Table 1-1. The interconnection relationship of the AHB interconnect matrix ..................................... 24
Table 1-2. Memory map of GD32E10x devices ....................................................................................... 27
Table 1-3. Boot modes .............................................................................................................................. 31
Table 2-1. GD32E10x base address and size for flash memory ........................................................... 35
Table 2-2. Option bytes ............................................................................................................................. 44
Table 3-1. Power saving mode summary ................................................................................................ 59
Table 5-1. Clock output 0 source select .................................................................................................. 74
Table 5-2. 1.2V domain voltage selected in deep-sleep mode .............................................................. 75
Table 7-1. NVIC exception types in Cortex-M4 ...................................................................................... 117
Table 7-2. Interrupt vector table .............................................................................................................. 118
Table 7-3. EXTI source ............................................................................................................................ 121
Table 8-1. GPIO configuration table....................................................................................................... 126
Table 8-2. Debug interface signals ........................................................................................................ 132
Table 8-3. Debug port mapping .............................................................................................................. 132
Table 8-4. ADC0 external trigger inserted conversion AF remapping ............................................... 133
Table 8-5. ADC0 external trigger regular conversion AF remapping ................................................. 133
Table 8-6. ADC1 external trigger inserted conversion AF remapping ............................................... 133
Table 8-7. ADC1 external trigger regular conversion AF remapping ................................................. 133
Table 8-8. TIMER0 alternate function remapping ................................................................................. 133
Table 8-9. TIMER1 alternate function remapping ................................................................................. 134
Table 8-10. TIMER2 alternate function remapping ............................................................................... 134
Table 8-11. TIMER3 alternate function remapping ............................................................................... 134
Table 8-12. TIMER4 alternate function remapping ............................................................................... 134
Table 8-13. TIMER8 alternate function remapping (1) ........................................................................... 134
Table 8-14. USART0 alternate function remapping .............................................................................. 135
Table 8-15. USART1 alternate function remapping .............................................................................. 135
Table 8-16. USART2 alternate function remapping .............................................................................. 135
Table 8-17. I2C0 alternate function remapping ..................................................................................... 135
Table 8-18. SPI0 alternate function remapping .................................................................................... 135
Table 8-19. SPI2/I2S2 alternate function remapping ............................................................................ 136
Table 8-22. CTC alternate function remapping ..................................................................................... 136
Table 8-23. OSC32 pins configuration ................................................................................................... 136
Table 8-24. OSC pins configuration ....................................................................................................... 136
Table 10-1. DMA transfer operation ....................................................................................................... 162
Table 10-2. Interrupt events .................................................................................................................... 165
Table 10-3. DMA0 requests for each channel ....................................................................................... 166
Table 10-4. DMA1 requests for each channel ....................................................................................... 167
Table 12-1. ADC internal signals ............................................................................................................ 183
Table 12-2. ADC pins definition.............................................................................................................. 183
Table 12-3. External trigger for regular channels for ADC0 and ADC1 .............................................. 192
20
GD32E10x User Manual
Table 12-4. External trigger for inserted channels for ADC0 and ADC1 ............................................ 193
Table 12-5. tCONV timings depending on resolution .............................................................................. 194
Table 12-6. Maximum output results for N and M combinations (grayed values indicate truncation)
........................................................................................................................................................... 195
Table 13-1. DAC pins ............................................................................................................................... 218
Table 13-2. External triggers of DAC ..................................................................................................... 219
Table 14-1. Min/max FWDGT timeout period at 40 kHz (IRC40K) ....................................................... 232
Table 14-2. Min/max timeout value at 60 MHz (fPCLK1) .......................................................................... 239
Table 16-1. Timers (TIMERx) are divided into five sorts ...................................................................... 250
Table 16-2. Complementary outputs controlled by parameters ......................................................... 268
Table 16-3. Counting direction versus encoder signals ...................................................................... 271
Table 16-4. Examples of slave mode ..................................................................................................... 273
Table 16-5. Counting direction versus encoder signals ...................................................................... 323
Table 16-6. Examples of slave mode ..................................................................................................... 324
Table 16-7. Examples of slave mode ..................................................................................................... 360
Table 17-1. Description of USART important pins ............................................................................... 406
Table 17-2. Configuration of stop bits ................................................................................................... 407
Table 17-3. USART interrupt requests ................................................................................................... 421
Table 18-1. Definition of I2C-bus terminology (refer to the I2C specification of Philips
semiconductors) .............................................................................................................................. 437
Table 18-2. Event status flags ................................................................................................................ 452
Table 18-3. I2C error flags ....................................................................................................................... 453
Table 19-1. SPI signal description ......................................................................................................... 466
Table 19-2. Quad-SPI signal description ............................................................................................... 467
Table 19-3. SPI operating modes ........................................................................................................... 469
Table 19-4. SPI interrupt requests ......................................................................................................... 479
Table 19-5. I2S bitrate calculation formulas ......................................................................................... 488
Table 19-6. Audio sampling frequency calculation formulas ............................................................. 489
Table 19-7. Direction of I2S interface signals for each operation mode ............................................ 489
Table 19-8. I2S interrupt .......................................................................................................................... 493
Table 20-1. NOR flash interface signals description............................................................................ 507
Table 20-2. PSRAM non-muxed signal description.............................................................................. 508
Table 20-3. EXMC bank0 supported transactions ................................................................................ 508
Table 20-4. NOR/PSRAM controller timing parameters ....................................................................... 509
Table 20-5. EXMC timing models ........................................................................................................... 510
Table 20-6. Mode 1 related registers configuration .............................................................................. 511
Table 20-7. Mode A related registers configuration ............................................................................. 513
Table 20-8. Mode 2/B related registers configuration .......................................................................... 515
Table 20-9. Mode C related registers configuration ............................................................................. 517
Table 20-10. Mode D related registers configuration ........................................................................... 519
Table 20-11. Related registers configuration of multiplex mode ........................................................ 521
Table 20-12. Timing configurations of synchronous multiplexed read mode .................................. 525
Table 20-13. Timing configurations of synchronous multiplexed write mode .................................. 526
Table 22-1. USBFS signal description ................................................................................................... 534
21
GD32E10x User Manual
Table 22-2. USBFS global interrupt ....................................................................................................... 547
Table 22-1. List of abbreviations used in register ................................................................................ 607
Table 22-2. List of terms .......................................................................................................................... 607
Table 23-1. Revision history ................................................................................................................... 608
22
GD32E10x User Manual
1. System and memory architecture
The devices of GD32E10x series are 32-bit general-purpose microcontrollers based on the
ARM® Cortex®-M4 processor. The ARM® Cortex®-M4 processor includes three AHB buses
which are known as I-Code bus, D-Code bus and System bus. All memory accesses of the
ARM® Cortex®-M4 processor are executed on the three buses 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, makes the system
more flexible and extendable.
The Cortex®-M4 processor is a 32-bit processor that possesses floating point arithmetic
functionality, low interrupt latency and low-cost debug. The characteristics of integrated and
advanced make the Cortex®-M4 processor more suitable for products on the market that
require the microcontrollers to have high performance and low power consumption. The
Cortex®-M4 processor is based on the ARMv7 architecture and supports a powerful and
scalable instruction set that includes general data processing I/O control tasks instructions,
advanced data processing bit field manipulations instructions, DSP and floating point
instructions. Some system peripherals listed below are also provided by Cortex ®-M4:
Internal Bus Matrix connected with I-Code bus, D-Code bus, System bus, Private
Peripheral Bus (PPB) and debug accesses.
Nested Vectored Interrupt Controller (NVIC)
Flash Patch and Breakpoint (FPB)
Data Watchpoint and Trace (DWT)
Instrumentation Trace Macrocell (ITM)
Serial Wire JTAG Debug Port (SWJ-DP)
Trace Port Interface Unit (TPIU)
Floating Point Unit (FPU)
Figure 1-1. The structure of the Cortex®-M4 processor shows the block diagram of the
Cortex®-M4 processor. For more information, refer to the ARM® Cortex®-M4 Technical
Reference Manual.
23
GD32E10x User Manual
Figure 1-1. The structure of the Cortex®-M4 processor
Cortex-M4 processor
Wake-up
Interrupt
Controller
(WIC) Data
Flash Patch
Watchpoint
Breakpoint
And Trace
(FPB)
(WDT)
Serial-Wire
Or JTAG AHB Instrumentation Trace Port
Debug Port Access port Bus Matrix Trace Macrocell Interface Unit
(SWDP or (AHB-AP) (ITM) (TPIU)
SWJ-DP)
A 32-bit multilayer bus is implemented in the GD32E10x devices, which makes the parallel
access paths between multiple masters and slaves in the system possible. The multilayer bus
consists of an AHB interconnect matrix, one AHB bus and two APB buses. The
interconnection relationship of the AHB interconnect matrix is shown below. In the following
table, “1” indicates the corresponding master is able to access the corresponding slave
through the AHB interconnect matrix, the blank indicates the corresponding master cannot
access the corresponding slave through the AHB interconnect matrix.
FMC-I 1
FMC-D 1 1 1
SRAM 1 1 1 1 1
24
GD32E10x User Manual
IBUS DBUS SBUS DMA0 DMA1
EXMC 1 1 1 1 1
AHB 1 1 1
APB1 1 1 1
APB2 1 1 1
As is shown above, there are several masters connected with the AHB interconnect matrix,
including IBUS, DBUS, SBUS, DMA0, DMA1. IBUS is the instruction bus of the Cortex®-M4
core, which is used for fetching instruction/vector from the Code region (0x0000 0000 ~
0x1FFF FFFF). DBUS is the data bus of the Cortex®-M4 core, which is used for
loading/storing data and debugging access of the Code region. Similarly, SBUS is the system
bus of the Cortex®-M4 core, which is used for fetching instruction/vector, loading/storing data
and debugging access of the system regions. The System regions include the internal SRAM
region and the Peripheral region. DMA0 and DMA1 are the buses of DMA0 and DMA1
respectively.
There are also several slaves connected with the AHB interconnect matrix, including FMC-I,
FMC-D, SRAM, EXMC, AHB, APB1 and APB2. FMC-I is the instruction bus of the flash
memory controller, FMC-D is the data bus of the flash memory controller. SRAM is on-chip
static random access memories. EXMC is the external memory controller. AHB is the AHB
bus connected with all AHB slaves, APB1 and APB2 connected with all APB slaves and all
APB peripherals. APB1 is limited to 60 MHz, APB2 can run to full speed (up to 120MHz
depending on the device).
As shown in the following figure, these are interconnected using the multilayer AHB bus
architecture.
25
GD32E10x User Manual
Figure 1-2. GD32E10x series system architecture
LDO
FMC USBFS CRC RCU
1.2V
NVIC Master Slave AHB Peripherals
IRC
AHB Matrix
GP DMA 12 chs SRAM 8MHz
SRAM
Master
Slave
Controller
HXTAL
AHB to APB AHB to APB 3-25MHz
Slave Bridge2 Bridge1
EXMC
Slave
LVD
Interrput request
Powered By VDDA
USART0 WWDGT
Slave Slave
SPI0
TIMER1~3
12-bit
SAR ADC ADC0~1
Powered By V DDA
EXTI SPI1~2
GPIOA USART1~2
GPIOB I2C0
APB2: Fmax = 120MHz
GPIOC I2C1
GPIOD FWDGT
GPIOE RTC
DAC
TIMER4~6
TIMER0
UART3~4
TIMER7
TIMER8~10 TIMER
11~13
CTC
The ARM® Cortex®-M4 processor is structured using a Harvard architecture which uses
separate buses to fetch instructions and load/store data. The instruction code and data are
both located in the same memory address space but in different address ranges. Program
memory, data memory, registers and I/O ports are organized within the same linear 4-Gbyte
26
GD32E10x User Manual
address space. The maximum address range of the Cortex ®-M4 is 4-Gbyte due to its 32-bit
bus address width. Additionally, a pre-defined memory map is provided by the Cortex ®-M4
processor to reduce the software complexity of repeated implementation for different device
vendors. In the map, some regions are used by the ARM ® Cortex®-M4 system peripherals
which can not be modified. However, the other regions are available to the vendors. Table
1-2. Memory map of GD32E10x devices shows the memory map of the GD32E10x series
devices, including Code, SRAM, peripheral, and other pre-defined regions. Almost each
peripheral is allocated 1KB of space. This allows simplifying the address decoding for each
peripheral.
27
GD32E10x User Manual
Pre-defined
Bus Address Peripherals
regions
0x4002 1000 - 0x4002 13FF RCU
0x4002 0C00 - 0x4002 0FFF Reserved
0x4002 0800 - 0x4002 0BFF Reserved
0x4002 0400 - 0x4002 07FF DMA1
0x4002 0000 - 0x4002 03FF DMA0
0x4001 8400 - 0x4001 FFFF Reserved
0x4001 8000 - 0x4001 83FF Reserved
0x4001 7C00 - 0x4001 7FFF Reserved
0x4001 7800 - 0x4001 7BFF Reserved
0x4001 7400 - 0x4001 77FF Reserved
0x4001 7000 - 0x4001 73FF Reserved
0x4001 6C00 - 0x4001 6FFF Reserved
0x4001 6800 - 0x4001 6BFF Reserved
0x4001 5C00 - 0x4001 67FF Reserved
0x4001 5800 - 0x4001 5BFF Reserved
0x4001 5400 - 0x4001 57FF TIMER10
0x4001 5000 - 0x4001 53FF TIMER9
0x4001 4C00 - 0x4001 4FFF TIMER8
0x4001 4800 - 0x4001 4BFF Reserved
0x4001 4400 - 0x4001 47FF Reserved
0x4001 4000 - 0x4001 43FF Reserved
0x4001 3C00 - 0x4001 3FFF Reserved
APB2
0x4001 3800 - 0x4001 3BFF USART0
0x4001 3400 - 0x4001 37FF TIMER7
0x4001 3000 - 0x4001 33FF SPI0
0x4001 2C00 - 0x4001 2FFF TIMER0
0x4001 2800 - 0x4001 2BFF ADC1
0x4001 2400 - 0x4001 27FF ADC0
0x4001 2000 - 0x4001 23FF Reserved
0x4001 1C00 - 0x4001 1FFF Reserved
0x4001 1800 - 0x4001 1BFF GPIOE
0x4001 1400 - 0x4001 17FF GPIOD
0x4001 1000 - 0x4001 13FF GPIOC
0x4001 0C00 - 0x4001 0FFF GPIOB
0x4001 0800 - 0x4001 0BFF GPIOA
0x4001 0400 - 0x4001 07FF EXTI
0x4001 0000 - 0x4001 03FF AFIO
0x4000 CC00 - 0x4000 FFFF Reserved
APB1
0x4000 C800 - 0x4000 CBFF CTC
28
GD32E10x User Manual
Pre-defined
Bus Address Peripherals
regions
0x4000 C400 - 0x4000 C7FF Reserved
0x4000 C000 - 0x4000 C3FF Reserved
0x4000 8000 - 0x4000 BFFF Reserved
0x4000 7C00 - 0x4000 7FFF Reserved
0x4000 7800 - 0x4000 7BFF Reserved
0x4000 7400 - 0x4000 77FF DAC
0x4000 7000 - 0x4000 73FF PMU
0x4000 6C00 - 0x4000 6FFF BKP
0x4000 6800 - 0x4000 6BFF Reserved
0x4000 6400 - 0x4000 67FF Reserved
0x4000 6000 - 0x4000 63FF Reserved
0x4000 5C00 - 0x4000 5FFF Reserved
0x4000 5800 - 0x4000 5BFF I2C1
0x4000 5400 - 0x4000 57FF I2C0
0x4000 5000 - 0x4000 53FF UART4
0x4000 4C00 - 0x4000 4FFF UART3
0x4000 4800 - 0x4000 4BFF USART2
0x4000 4400 - 0x4000 47FF USART1
0x4000 4000 - 0x4000 43FF Reserved
0x4000 3C00 - 0x4000 3FFF SPI2/I2S2
0x4000 3800 - 0x4000 3BFF SPI1/I2S1
0x4000 3400 - 0x4000 37FF Reserved
0x4000 3000 - 0x4000 33FF FWDGT
0x4000 2C00 - 0x4000 2FFF WWDGT
0x4000 2800 - 0x4000 2BFF RTC
0x4000 2400 - 0x4000 27FF Reserved
0x4000 2000 - 0x4000 23FF TIMER13
0x4000 1C00 - 0x4000 1FFF TIMER12
0x4000 1800 - 0x4000 1BFF TIMER11
0x4000 1400 - 0x4000 17FF TIMER6
0x4000 1000 - 0x4000 13FF TIMER5
0x4000 0C00 - 0x4000 0FFF TIMER4
0x4000 0800 - 0x4000 0BFF TIMER3
0x4000 0400 - 0x4000 07FF TIMER2
0x4000 0000 - 0x4000 03FF TIMER1
0x2007 0000 - 0x3FFF FFFF Reserved
0x2006 0000 - 0x2006 FFFF Reserved
SRAM AHB
0x2003 0000 - 0x2005 FFFF Reserved
0x2002 0000 - 0x2002 FFFF Reserved
29
GD32E10x User Manual
Pre-defined
Bus Address Peripherals
regions
0x2001 C000 - 0x2001 FFFF Reserved
0x2001 8000 - 0x2001 BFFF Reserved
0x2000 8000 - 0x2001 7FFF Reserved
0x2000 0000 - 0x2000 7FFF SRAM
0x1FFF F810 - 0x1FFF FFFF Reserved
0x1FFF F800 - 0x1FFF F80F Option Bytes
0x1FFF F000 - 0x1FFF F7FF
0x1FFF C010 - 0x1FFF EFFF
Boot loader
0x1FFF C000 - 0x1FFF C00F
0x1FFF B000 - 0x1FFF BFFF
0x1FFF 7A10 - 0x1FFF AFFF Reserved
0x1FFF 7800 - 0x1FFF 7A0F Reserved
0x1FFF 0000 - 0x1FFF 77FF Reserved
0x1FFE C010 - 0x1FFE FFFF Reserved
0x1FFE C000 - 0x1FFE C00F Reserved
Code AHB
0x1001 0000 - 0x1FFE BFFF Reserved
0x1000 0000 - 0x1000 FFFF Reserved
0x083C 0000 - 0x0FFF FFFF Reserved
0x0830 0000 - 0x083B FFFF Reserved
0x0810 0000 - 0x082F FFFF Reserved
0x0802 0000 - 0x080F FFFF Reserved
0x0800 0000 - 0x0801 FFFF Main Flash
0x0030 0000 - 0x07FF FFFF Reserved
0x0010 0000 - 0x002F FFFF
Aliased to Main
0x0002 0000 - 0x000F FFFF
Flash or Boot loader
0x0000 0000 - 0x0001 FFFF
1.3.1. Bit-banding
In order to reduce the time required for read-modify-write operations, the Cortex®-M4
processor provides a bit-banding function to perform a single atomic bit operation. The
memory map includes two bit-band regions. These occupy the SRAM and Peripherals
respectively. These bit-band regions map each word in an alias region of memory to a bit in
a bit-band region of memory.
A mapping formula shows how to reference each word in the alias region to a corresponding
bit, or target bit, in the bit-band region. The mapping formula is:
where:
30
GD32E10x User Manual
bit_word_addr is the address of the word in the alias memory region that maps to the
targeted bit.
bit_band_base is the starting address of the alias region.
byte_offset is the number of the byte in the bit-band region that contains the targeted bit.
bit_number is the bit position (0-7) of the targeted bit.
For example, the alias word at 0x2000 401C maps to bit [7] of the bit-band byte at 0x2000
0200:
Writing to address 0x2200 401C will cause bit 7 of address 0x2000 0200 change .While a
read to address 0x2200 401C will return 0x01 or 0x00 according to the value of bit 7 at the
SRAM address 0x2000 0200.
The GD32E10x devices series contain up to 32 KB of on-chip SRAM which address starts at
0x2000 0000. It supports byte, half-word (16 bits), and word (32 bits) accesses.
The devices provide high density on-chip flash memory, which is organized as follows:
The GD32E10x devices provide three kinds of boot sources which can be selected by the
BOOT0 and BOOT1 pins. The details are shown in the following table. The value on the two
pins is latched on the 4th rising edge of CK_SYS after a reset. User can select the required
boot source by set the BOOT0 and BOOT1 pins after a power-on reset or a system reset.
Once the two pins have been sampled, they are free and can be used for other purposes.
After power-on sequence or a system reset, the ARM® Cortex™-M4 processor fetches the
31
GD32E10x User Manual
top-of-stack value from address 0x0000 0000 and the base address of boot code from 0x0000
0004 in sequence. Then, starts code execution from the base address of boot code.
Due to the selected boot source, either the main flash memory (original memory space is
beginning at 0x0800 0000) or the system memory (original memory space is beginning at
0x1FFF F000) is aliased in the boot memory space which begins at 0x0000 0000. When the
on-chip SRAM whose memory space is beginning at 0x2000 0000 is selected as the boot
source, in the application initialization code, you have to relocate the vector table in SRAM by
using the NVIC exception table and offset register.
The embedded boot loader is located in the system memory, which is used to reprogram the
Flash memory. In GD32E10x devices, the boot loader can be activated through the USART0
interface.
The device electronic signature contains memory size information and the 96-bit unique
device ID. It is stored in the information block of the Flash memory. The 96-bit unique device
ID is unique for each device. It can be used as serial numbers, or part of security keys, etc.
32
GD32E10x User Manual
1.5.1. Memory density information
Base address: 0x1FFF F7E0
The value is factory programmed and can never be altered by user.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SRAM_DENSITY[15:0]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FLASH_DENSITY[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UNIQUE_ID[31:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UNIQUE_ID[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UNIQUE_ID[63:48]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UNIQUE_ID[47:32]
33
GD32E10x User Manual
Bits Fields Descriptions
31:0 UNIQUE_ID[63:32] Unique device ID
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
UNIQUE_ID[95:80]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
UNIQUE_ID[79:64]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
NOTE:
1. Only bit[7] can be read-modify-write, other bits are not permitted.
34
GD32E10x User Manual
2. Flash memory controller (FMC)
2.1. Overview
The flash memory controller, FMC, provides all the necessary functions for the on-chip flash
memory. A little waiting time is needed while CPU executes instructions stored from the 128K
bytes of the flash. It also provides page erase, mass erase, and program operations for flash
memory.
2.2. Characteristics
Table 2-1. GD32E10x base address and size for flash memory
Block Name Address range size(bytes)
Page 0 0x0800 0000 - 0x0800 03FF 1KB
Page 1 0x0800 0400 - 0x0800 07FF 1KB
Page 2 0x0800 0800 - 0x0800 0BFF 1KB
Main Flash Block . . .
. . .
. . .
Page 127 0x0801 FC00 - 0x0801 FFFF 1KB
35
GD32E10x User Manual
Block Name Address range size(bytes)
Information Block Boot Loader area 0x1FFF B000- 0x1FFF F7FF 18KB
Option bytes
Option bytes 0x1FFF F800 - 0x1FFF F80F 16B
Block
One-time
OTP bytes 0x1FFF_7000~0x1FFF_71FF 512B
program Block
NOTE: The Information Block stores the boot loader. This block cannot be programmed or
erased by user.
The flash can be addressed directly as a common memory space. Any instruction fetch and
the data access from the flash are through the IBUS or DBUS from the CPU.
Must configure the WSCNT bits in the FMC_WS register correctly depend on the AHB clock
frequency. The relation between WSCNT and AHB clock frequency is show as the following
table.
Table 2-2. The relation between WSCNT and AHB clock frequency
AHB clock frequency WSCNT configured
<= 30MHz 0 (0 wait state added)
<= 60MHz 1 (1 wait state added)
<= 90MHz 2 (2 wait state added)
<= 120MHz 3 (3 wait state added)
If system reset occurs, the AHB clock frequency is 8MHz and the WSCNT is 0.
Note:
1. If want to increase the AHB clock frequency. First, refer to the Table 2-2, configure the
WSCNT bits according to the target AHB clock frequency. Then, increase the AHB clock
frequency to the target frequency. It is forbidden to increase the AHB clock frequency before
configure the WSCNT.
2. If want to decrease the AHB clock frequency. First, decrease the target AHB clock
frequency. Then refer to the Table 2-2, configure the WSCNT bits according the target AHB
clock frequency. It is forbidden to configure the WSCNT bits before decrease the AHB clock
frequency.
Because the wait state is added, the read efficiency is very low (such as add 3 wait state
when 120MHz). In order to speed up the read access, there are some functions performed.
Current buffer:
The current buffer is always enabled. Each time read from flash memory, 64-bit data get and
36
GD32E10x User Manual
store in current buffer. The CPU only need 32-bit or 16-bit in each read operation. So in the
case of sequential code, the next data can get from current buffer without repeat fetch from
flash memory.
Pre-fetch buffer:
The pre-fetch buffer is enabled by set the PFEN bit in the FMC_WS register. The pre-fetch
buffer is only performed on IBUS. In the case of sequential code, when CPU execute the
current buffer data (64-bit), 32-bit needs at least 2 clocks and 16-bit needs at least 4 clocks.
In this case, pre-fetch the data of next double-word address from flash memory and store to
Pre-fetch buffer. So when the CPU finish the current buffer and need execute the next data,
the pre-fetch buffer hit.
IBUS Cache:
IBUS cache is enabled by set the ICEN bit in the FMC_WS register. The IBUS cache is only
used when IBUS fetch data. The IBUS cache have 512 bytes which organized as 32 cache
lines, each cache lines is 2 X 64bits.
If the IBUS data is in IBUS cache (IBUS cache hit), the CPU read data from IBUS cache
without any wait state. If the IBUS data is not in IBUS cache (IBUS cache miss) and not in
current buffer/Pre-fetch buffer, the cache line fetch from flash memory and copied to IBUS
cache. If all cache line filled, LRU (least recently used) policy used to replace the cache line.
DBUS Cache:
DBUS cache is enabled by set the DCEN bit in the FMC_WS register. The DBUS cache is
only used when DBUS fetch data by CPU (not by DMA). And the option byte is not cacheable.
The DBUS cache have 256 bytes which organized as 8 cache lines, each cache lines is 4 X
64bits.
If the DBUS data is in DBUS cache (DBUS cache hit), the CPU read data from DBUS cache
without any wait state. If the DBUS data is not in DBUS cache (DBUS cache miss) and not in
current buffer, the cache line fetch from flash memory and copied to DBUS cache. If all cache
line filled, LRU (least recently used) policy used to replace the cache line.
After reset, the FMC_CTL register is not accessible in write mode, and the LK bit in the
FMC_CTL register is reset to 1. An unlocking sequence consists of two write operations to
the FMC_KEY register to open the access to the FMC_CTL register. The two write operations
are writing 0x45670123 and 0xCDEF89AB to the FMC_KEY register. After the two write
operations, the LK bit in the FMC_CTL register is reset to 0 by hardware. The software can
lock the FMC_CTL again by setting the LK bit in the FMC_CTL register to 1. Any wrong
operations to the FMC_KEY, will set the LK bit to 1, and lock the FMC_CTL register, and lead
to a bus error.
37
GD32E10x User Manual
The OBPG bit and OBER bit in the FMC_CTL are still protected even the FMC_CTL is
unlocked. The unlocking sequence consists of two write operations, which are writing
0x45670123 and 0xCDEF89AB to the FMC_OBKEY register. Then the hardware sets the
OBWEN bit in the FMC_CTL register to 1. The software can reset OBWEN bit to 0 to protect
the OBPG bit and OBER bit in the FMC_CTL register again.
The FMC provides a page erase function which is used to initialize the contents of a main
flash memory page to a high state. Each page can be erased independently without affecting
the contents of other pages. The following steps show the access sequence of the registers
for a page erase operation.
When the operation is executed successfully, the ENDF bit in the FMC_STAT register is set,
and an interrupt will be triggered by FMC if the ENDIE bit in the FMC_CTL register is set.
Note that a correct target page address must be confirmed. Otherwise, the software may run
out of control if the target erase page is being used to fetch codes or access data. The FMC
will not provide any notification when that happens. Additionally, the page erase operation will
be ignored on erase/program protected pages. In this condition, a flash operation error
interrupt will be triggered by the FMC if the ERRIE bit in the FMC_CTL register is set. The
software can check the WPERR bit in the FMC_STAT register to detect this condition in the
interrupt handler. The following figure shows the page erase operation flow.
38
GD32E10x User Manual
Figure 2-1. Process of page erase operation
Start
No
Is the LK bit is 0 Unlock the FMC_CTL
Yes
No
Is the BUSY bit is 0
Yes
No
Is the BUSY bit is 0
Yes
Finish
The FMC provides a complete erase function which is used to initialize the main flash block
contents. This erase can affect entire flash block by setting the MER bit to 1 in the FMC_CTL
register. The following steps show the mass erase register access sequence.
When the operation is executed successfully, the ENDF bit in the FMC_STAT register is set,
39
GD32E10x User Manual
and an interrupt will be triggered by FMC if the ENDIE bit in the FMC_CTL register is set.
Since all flash data will be modified to a value of 0xFFFF_FFFF, the mass erase operation
can be implemented using a program that runs in SRAM or using the debugging tool that
accesses the FMC registers directly. Additionally, the mass erase operation will be ignored if
any page is erase/program protected. In this condition, a flash operation error interrupt will be
triggered by the FMC if the ERRIE bit in the FMC_CTL register is set. The software can check
the WPERR bit in the FMC_STAT register to detect this condition in the interrupt handler.
Start
No
Is the LK bit is 0 Unlock the FMC_CTL
Yes
No
Is the BUSY bit is 0
Yes
No
Is the BUSY bit is 0
Yes
Finish
The FMC provides a 32-bit word/16-bit half word programming function by DBUS which is
used to modify the main flash memory contents. While actually, the data program to flash
memory is 32-bits or 64-bits which is defined by the PGW bit in the FMC_WS register.
The following steps show the register access sequence of the programming operation.
40
GD32E10x User Manual
Unlock the FMC_CTL register if necessary.
Check the BUSY bit in the FMC_STAT register to confirm that no flash memory operation
is in progress (BUSY equals to 0). Otherwise, wait until the operation has finished.
Set the PGW bit if needed.
Set the PG bit in the FMC_CTL register.
Write the data to be programed by DBUS with desired absolute address (0x08XX XXXX).
If DBUS program is 32-bit word and the PGW bit is set to 0(32-bit program to flash
memory), the DBUS write once and the data program to flash memory. The data to be
programed must word alignment.
If DBUS program is 32-bit and the PGW bit is set to 1(64-bit program to flash memory),
the DBUS write twice to form a 64-bit data and then the 64-bit data program to flash
memory. The data to be programed must double-word alignment.
If DBUS program is 16-bit and the PGW bit is set to 0(32-bit program to flash memory),
the DBUS write twice to form a 32-bit data and then the 32-bit data program to flash
memory. The data to be programed must word alignment.
If DBUS program is 16-bit and the PGW bit is set to 1(64-bit program to flash memory),
the DBUS write four times to form a 64-bit data and then the 64-bit data program to flash
memory. The data to be programed must double-word alignment.
For less program time, suggest the DBUS program use 32-bit, set the PGW to 1 if the
data to be programed is double-word alignment, or set PGW to 0 if the data to be
programed is word alignment
Wait until all the operations have been finished by checking the value of the BUSY bit in
the FMC_STAT register.
Read and verify the Flash memory if required using a DBUS access.
When the operation is executed successfully, the ENDF bit in the FMC_STAT register is set,
and an interrupt will be triggered by FMC if the ENDIE bit in the FMC_CTL register is set.
Note that there are some program error need caution:
The programming operation checks the address if it has been erased or not. If the address
has not been erased, the PGERR bit in the FMC_STAT register will be set even if
programming 0x0. Each word can be programmed only one time after erase and before next
erase Note that the PG bit must be set before the word/half word programming operation.
Additionally, the program operation will be ignored on erase/program protected pages and
the WPERR bit in the FMC_STAT will be set.
In the following cases, the PGAERR bit in the FMC_STAT register will be set.
- The DBUS program use byte write (not 32-bit or 16-bit write)
- The DBUS program size is not equal previous size. It not allow mix 32-bit with 16-bit write.
- The DBUS write is not alignment. If DBUS program is 32-bit and the PGW bit is set to
1(64-bit program to flash memory), the second DBUS write must double-word alignment
and belong to same double-word address. If DBUS program is 16-bit and the PGW bit is
set to 0(32-bit program to flash memory), the second DBUS write must word alignment
and belong to same word address. If DBUS program is 16-bit and the PGW bit is set to
41
GD32E10x User Manual
1(64-bit program to flash memory), the 2nd/3rd/4th DBUS write must double-word alignment
and belong to same double-word address.
Note: If the program is not write total 64bits/32bits (by set the PGW bit in the FMC_WS
register), the data is not program to the flash memory without any notice.
In these conditions, a flash operation error interrupt will be triggered by the FMC if the ERRIE
bit in the FMC_CTL register is set. The software can check the PGERR bit, PGAERR bit or
WPERR bit in the FMC_STAT register to detect which condition occurred in the interrupt
handler. The following figure shows the word programming operation flow.
Start
No
Is the LK bit is 0 Unlock the FMC_CTL
Yes
No
Is the BUSY bit is 0
Yes
No
Is the BUSY bit is 0
Yes
Finish
Note: Reading the flash should be avoided when a program/erase operation is ongoing in the
same bank. And flash memory accesses will fail if the CPU enters the power saving modes.
The OTP programming method is same as the main flash programming. The OTP block can
only be programed once and cannot be erased.
Note: It must ensure the OTP programming sequence completely without any unexpected
interrupt, such as system reset or power down. If unexpected interrupt occurs, there is very
42
GD32E10x User Manual
little probability of corrupt the data stored in flash memory.
The FMC provides an erase function which is used to initialize the option bytes block in flash.
The following steps show the erase sequence.
When the operation is executed successful, the ENDF bit in the FMC_STAT register is set,
and an interrupt will be triggered by FMC if the ENDIE bit in the FMC_CTL register is set.
The FMC provides an erase / program function which is used to modify the option bytes block
in flash. There are 8 pairs of option bytes. The MSB is the complement of the LSB in each
pair. When the option bytes are modified, the MSB is generated by FMC automatically, not
the value of input data. The following steps show the erase sequence.
When the operation is executed successfully, the ENDF bit in the FMC_STAT register is set,
and an interrupt will be triggered by FMC if the ENDIE bit in the FMC_CTL register is set.
43
GD32E10x User Manual
Note that there programming errors may occur. The PGERR bit and PGAERR bit can be set
which is similar to main flash programming.
The modified option bytes only take effect after a system reset.
The option bytes block is reloaded to the FMC_OBSTAT and FMC_WP registers after each
system reset, then the option bytes take effect. The complement option bytes are the opposite
of the option bytes. When reload the option bytes, if the complement option byte and option
byte do not match, the OBERR bit in the FMC_OBSTAT register will be set, and the option
byte will be set to 0xFF. The OBERR bit will not be set if both the option bytes and its
complement bytes are 0xFF.The following table shows the detail of option bytes.
44
GD32E10x User Manual
Address Name Description
WP[30:24]: Each bit is related to 4KB flash protection.
These bits totally controls the first 124KB flash protection.
WP[31]: Bit 31 controls the protection of the rest flash
memory.
0x1fff f80f WP_N[31:24] WP complement value bit 31 to 24
The FMC provides page erase/program protection functions to prevent inadvertent operations
on the Flash memory. The page erase or program will not be accepted by the FMC on
protected pages. If the page erase or program command is sent to the FMC on a protected
page, the WPERR bit in the FMC_STAT register will be set by the FMC. If the WPERR bit is
set and the ERRIE bit is also set to 1 to enable the corresponding interrupt, then the Flash
operation error interrupt will be triggered by the FMC to draw the attention of the CPU. The
page protection function can be individually enabled by configuring the WP [31:0] bit field to
0 in the option bytes. If a page erase operation is executed on the option bytes block, all the
Flash Memory page protection functions will be disabled. When WP in the option bytes is
modified, then a system reset is necessary.
The FMC provides a security protection function to prevent illegal code/data access to the
Flash memory. This function is useful for protecting the software/firmware from illegal users.
No protection: when setting SPC byte and its complement value to 0x5AA5, no protection
performed. The main flash and option bytes block are accessible by all operations.
Under protection: when setting SPC byte and its complement value to any value except
0x5AA5, the security protection is performed. Note that a power reset should be followed
instead of a system reset if the SPC modification has been performed while the debug module
is still connected to JTAG/SWD device. Under the security protection, the main flash can only
be accessed by user code and the first 4KB flash is under erase/program protection. In debug
mode, boot from SRAM or boot loader mode, all operations to main flash is forbidden. If a
read operation to main flash in debug mode, boot from SRAM or boot loader mode, a bus
error will be generated. If a program/erase operation to main flash in debug mode, boot from
SRAM or boot from boot loader mode, the WPERR bit in the FMC_STAT register will be set.
Option bytes block are accessible by all operations, which can be used to disable the security
protection. Back to no protection level by setting SPC byte and its complement value to
0x5AA5, then a mass erase for main flash will be performed.
45
GD32E10x User Manual
2.4.1. Wait state register (FMC_WS)
Address offset: 0x00
Reset value: 0x0000 0630
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PGW Reserved DCRST ICRST DCEN ICEN Reserved PFEN Reserved WSCNT[2:0]
rw rw rw rw rw rw rw
12 DCRST DBUS cache reset. This bit can be write only when DCEN is set to 0.
0: No effect
1: DBUS cache reset
11 ICRST IBUS cache reset. This bit can be write only when ICEN is set to 0.
0: No effect
1: IBUS cache reset
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
KEY[31:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
KEY[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OBKEY[31:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OBKEY[15:0]
47
GD32E10x User Manual
2.4.4. Status register (FMC_STAT)
Address offset: 0x0C
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
48
GD32E10x User Manual
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved ENDIE Reserved ERRIE OBWEN Reserved LK START OBER OBPG Reserved MER PER PG
rw rw rw rs rs rw rw rw rw rw
49
GD32E10x User Manual
1 PER Main flash page erase for bank0 command bit
This bit is set or clear by software
0: no effect
1: main flash page erase command for bank0
Note: This register should be reset after the corresponding flash operation completed.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADDR[31:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADDR[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved DATA[15:6]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r
50
GD32E10x User Manual
31:26 Reserved Must be kept at reset value.
25:10 DATA[15:0] Store DATA[15:0] of option bytes block after system reset.
9:2 USER[7:0] Store USER of option bytes block after system reset.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
WP[31:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WP[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PID[31:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PID[15:0]
51
GD32E10x User Manual
These bits are read only by software.
These bits are unchanged constant after power on. These bits are one time program
when the chip produced.
52
GD32E10x User Manual
3. Power management unit (PMU)
3.1. Overview
The power consumption is regarded as one of the most important issues for the devices of
GD32E10x series. Power management unit (PMU) provides three types of power saving
modes, including Sleep, Deep-sleep and Standby mode. These modes reduce the power
consumption and allow the application to achieve a best tradeoff among the conflicting
demands of CPU operating time, speed and power consumption. For GD32E10x devices,
there are three power domains, including VDD / VDDA domain, 1.2V domain and backup domain,
as is shown in the Figure 3-1. Power supply overview. The power of the VDD domain is
supplied directly by VDD. An embedded LDO in the VDD / VDDA domain is used to supply the
1.2V domain power. A power switch is implemented for the backup domain. It can be powered
from the VBAT when the main VDD supply is shut down.
3.2. Characteristics
Three power domains: VBAK, VDD / VDDA and 1.2V power domain.
Three power saving modes: Sleep, Deep-sleep and Standby modes.
Internal Voltage regulator (LDO) supplies around 1.2V voltage source for 1.2V domain.
Low Voltage Detector (LVD) can issue an interrupt or event when the power is lower than
a programmed threshold.
Battery power (VBAT) for backup domain when VDD is shut down.
LDO output voltage is selected for power saving.
Figure 3-1. Power supply overview provides details on the internal configuration of the PMU
and the relevant power domains.
53
GD32E10x User Manual
Figure 3-1. Power supply overview
VBAT
VDD
Power Switch
VBAK Backup Domain
3.3V LXTAL BPOR
WKUP WKUPR
PA0 RTC BREG
WKUPN PMU
NRST CTL
WKUPF SLEEPING
FWDGT SLEEPDEEP
Cortex-M4
VDDA Domain
IRC8M IRC40K ADC IRC48M
3.3V
VDDA
LVD PLLs DAC
LVD: Low Voltage Detector LDO: Voltage Regulator BPOR: VBAK Power On Reset
POR: Power On Reset PDR: Power Down Reset BREG: Backup registers
The Backup domain is powered by the VDD or the battery power source (VBAT) selected by the
internal power switch. The VBAK pin which drives backup domain, supplies power for RTC unit,
LXTAL oscillator, BPOR, BREG and three pads, including PC13 to PC15. In order to ensure
the content of the backup domain registers and the RTC supply, when VDD supply is shut
down, VBAT pin can be connected to an optional standby voltage supplied by a battery or by
another source. The power switch is controlled by the Power Down Reset (PDR) circuit in the
VDD / VDDA domain. If no external battery is used in the application, it is recommended to
connect VBAT pin externally to VDD pin with a 100nF external ceramic decoupling capacitor.
The Backup domain reset sources include the Backup domain Power On Reset (BPOR) and
the Backup domain software reset. The BPOR signal forces the device to stay in the reset
mode until VBAK is completely powered up. Also the application software can trigger the
Backup domain software reset by setting the BKPRST bit in the RCU_BDCTL register.
The clock source of the Real Time Clock (RTC) circuit can be derived from the Internal 40KHz
RC oscillator (IRC40K) or the Low Speed Crystal oscillator (LXTAL), or HXTAL clock divided
by 128. When VDD is shut down, only LXTAL is valid for RTC. Before entering the power
saving mode by executing the WFI / WFE instruction, the Cortex®-M4 can setup the RTC
register with an expected alarm time and enable the alarm function to achieve the RTC timer
alarm event. After entering the power saving mode for a certain amount of time, the RTC will
54
GD32E10x User Manual
wake up the device when the time match event occurs. The details of the RTC configuration
and operation will be described in the Real-time Clock (RTC).
When the Backup domain is supplied by VDD (VBAK pin is connected to VDD), the following
functions are available:
PC13 can be used as GPIO or RTC function pin described in the Real-time Clock (RTC).
PC14 and PC15 can be used as either GPIO or LXTAL crystal oscillator pins.
When the Backup domain is supplied by VBAT (VBAK pin is connected to VBAT), the following
functions are available:
PC13 can be used as RTC function pin described in the Real-time Clock (RTC).
PC14 and PC15 can be used as LXTAL crystal oscillator pins only.
Note: Since PC13, PC14 and PC15 are supplied by the Power Switch which can only be
passed by low current, the speed of GPIOs PC13 to PC15 should not exceed 2MHz when
they are in output mode (maximum load: 30pF).
VDD / VDDA domain includes two parts: VDD domain and VDDA domain. VDD domain includes
HXTAL (High Speed Crystal oscillator), LDO (Voltage Regulator), POR / PDR (Power On /
Down Reset), FWDGT (Free Watchdog Timer), all pads except PC13 / PC14 / PC15, etc.
VDDA domain includes ADC / DAC (AD / DA Converter), IRC8M (Internal 8MHz RC oscillator),
IRC48M (Internal 48MHz RC oscillator at 48MHz frequency), IRC40K (Internal 40KHz RC
oscillator), PLLs (Phase Locking Loop), LVD (Low Voltage Detector), etc.
VDD domain
The LDO, which is implemented to supply power for the 1.2V domain, is always enabled after
reset. It can be configured to operate in three different status, including the Sleep mode (full
power on), the Deep-sleep mode (full power on or low power), and the Standby mode (power
off).
The POR / PDR circuit is implemented to detect VDD / VDDA and generate the power reset
signal which resets the whole chip except the Backup domain when the supply voltage is
lower than the specified threshold. Figure 3-2. Waveform of the POR / PDR shows the
relationship between the supply voltage and the power reset signal. V POR, which typical value
is 1.66V, indicates the threshold of power on reset, while VPDR, whose typical value is 1.62V,
means the threshold of power down reset. The hysteresis voltage (V hyst) is around 40mV.
55
GD32E10x User Manual
Figure 3-2. Waveform of the POR / PDR
VDD/VDDA
VPOR
40mV
Vhyst
VPDR
tRSTTEMPO
2ms
VDDA domain
The LVD is used to detect whether the VDD / VDDA supply voltage is lower than a programmed
threshold selected by the LVDT[2:0] bits in the Power control register (PMU_CTL). The LVD
is enabled by setting the LVDEN bit in the PMU_CTL register. And LVDF bit, which is in the
Power control and status register (PMU_CS), indicates if VDD / VDDA is higher or lower than
the LVD threshold. This event is internally connected to the EXTI line 16 and can generate
an interrupt if it is enabled through the EXTI registers. Figure 3-3. Waveform of the LVD
threshold shows the relationship between the LVD threshold and the LVD output (LVD
interrupt signal depends on EXTI line 16 rising or falling edge configuration). The following
figure also shows the relationship between the supply voltage and the LVD signal. The
hysteresis voltage (Vhyst) is 100mV.
VDD/VDDA
LVD
threshold
100mV
Vhyst
LVD output
56
GD32E10x User Manual
Generally, digital circuits are powered by VDD, while most of analog circuits are powered by
VDDA. To improve the conversion accuracy of ADC and DAC, the independent power supply
VDDA is implemented to achieve better performance of analog circuits. VDDA can be externally
connected to VDD through the external filtering circuit to avoid noise on VDDA, and VSSA should
be connected to VSS through the specific circuit independently. Otherwise, if VDDA is different
from VDD, VDDA must always be higher, and the voltage difference should not exceed 0.3V.
To ensure a high accuracy on ADC and DAC, the ADC / DAC independent external reference
voltage should be connected to VREF+ / VREF- pins. According to the different packages, VREF+
pin can be connected to VDDA pin, or external reference voltage which refers to Table 12-2.
ADC pins definition and Table 13-1. DAC pins, VREF- pin must be connected to VSSA pin.
The VREF+ pin is only available on no less than 100-pin packages. On less than 100-pin
packages, the VREF+ pin is not available and it is internally connected to VDDA. The VREF- pin is
internally connected to VSSA.
The main functions that include Cortex®-M4 logic, AHB / APB peripherals, the APB interfaces
for the Backup domain and the VDD / VDDA domain, etc, are located in this power domain. Once
the 1.2V is powered up, the POR will generate a reset sequence on the 1.2V power domain.
If it is needed to enter the specified power saving mode, the associated control bits must be
configured. Then, once a WFI (Wait for Interrupt) or WFE (Wait for Event) instruction is
executed, the device will enter the specified power saving mode which will be discussed in
the following section.
After a system reset or a power reset, the GD32E10x MCU operates at full function state and
all power domains are active. Users can achieve lower power consumption through slowing
down the system clocks (HCLK, PCLK1 and PCLK2), closing the clocks of the unused
peripherals or configuring the LDO output voltage by LDOVS bits in PMU_CTL register. The
LDOVS bits can be configured only when the PLL is off, and the programmed value is selected
to drive 1.2V domain after the PLL is opened. While the PLL is off, LDO output voltage low
mode is selected to drive 1.2V domain. Besides, three power saving modes are provided to
achieve even lower power consumption. They are Sleep mode, Deep-sleep mode and
Standby mode.
Sleep mode
The Sleep mode is corresponding to the SLEEPING mode of the Cortex®-M4. In Sleep mode,
only clock of Cortex®-M4 is off. To enter the Sleep mode, it is only necessary to clear the
SLEEPDEEP bit in the Cortex®-M4 System Control Register, and execute a WFI or WFE
instruction. If the Sleep mode is entered by executing a WFI instruction, any interrupt can
wake up the system. If it is entered by executing a WFE instruction, any wakeup event can
wake up the system (If SEVONPEND is 1, any interrupt can wake up the system, refer to
57
GD32E10x User Manual
Cortex®-M4 Technical Reference Manual). The mode offers the lowest wakeup time as no
time is wasted in interrupt entry or exit.
According to the SLEEPONEXIT bit in the Cortex®-M4 System Control Register, there are
two options to select the Sleep mode entry mechanism.
Sleep-now: if the SLEEPONEXIT bit is cleared, the MCU enters Sleep mode as soon as
a WFI or WFE instruction is executed.
Sleep-on-exit: if the SLEEPONEXIT bit is set, the MCU enters Sleep mode as soon as it
exits from the ISR with the lowest priority.
Deep-sleep mode
The Deep-sleep mode is based on the SLEEPDEEP mode of the Cortex®-M4. In Deep-sleep
mode, all clocks in the 1.2V domain are off, and all of IRC8M, IRC48M, HXTAL and PLLs are
disabled. The contents of SRAM and registers are preserved. The LDO can operate normally
or in low power mode depending on the LDOLP bit in the PMU_CTL register. Before entering
the Deep-sleep mode, it is necessary to set the SLEEPDEEP bit in the Cortex®-M4 System
Control Register, and clear the STBMOD bit in the PMU_CTL register. Then, the device
enters the Deep-sleep mode after a WFI or WFE instruction is executed. If the Deep-sleep
mode is entered by executing a WFI instruction, any interrupt from EXTI lines can wake up
the system. If it is entered by executing a WFE instruction, any wakeup event from EXTI lines
can wake up the system (If SEVONPEND is 1, any interrupt from EXTI lines can wake up the
system, refer to Cortex®-M4 Technical Reference Manual). When exiting the Deep-sleep
mode, the IRC8M is selected as the system clock. Notice that an additional wakeup delay will
be incurred if the LDO operates in low power mode.
Note: In order to enter Deep-sleep mode smoothly, all EXTI line pending status (in the
EXTI_PD register) and related peripheral flags must be reset, refer to Table 7-3. EXTI source.
If not, the program will skip the entry process of Deep-sleep mode to continue to execute the
following procedure.
Standby mode
The Standby mode is also based on the SLEEPDEEP mode of the Cortex®-M4. In Standby
mode, the whole 1.2V domain is powered off, the LDO is shut down, and all of IRC8M,
IRC48M, HXTAL and PLLs are disabled. Before entering the Standby mode, it is necessary
to set the SLEEPDEEP bit in the Cortex®-M4 System Control Register, set the STBMOD bit
in the PMU_CTL register, and clear WUF bit in the PMU_CS register. Then, the device enters
the Standby mode after a WFI or WFE instruction is executed, and the STBF status flag in
the PMU_CS register indicates whether the MCU has been in Standby mode. There are four
wakeup sources for the Standby mode, including the external reset from NRST pin, the RTC
alarm, the FWDGT reset and the rising edge on WKUP pin. The Standby mode achieves the
lowest power consumption, but spends longest time to wake up. Besides, the contents of
SRAM and registers in 1.2V power domain are lost in Standby mode. When exiting from the
Standby mode, a power-on reset of 1.2V domain occurs and the Cortex®-M4 will execute
58
GD32E10x User Manual
instruction code from the 0x0000 0000 address.
59
GD32E10x User Manual
3.4. Register definition
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rs rw rw rw rc_w1 rc_w1 rw rw
60
GD32E10x User Manual
111: 3.1V
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw r r r
61
GD32E10x User Manual
this bit will trigger a wakeup event when the input is already high.
62
GD32E10x User Manual
4. Backup registers (BKP)
4.1. Overview
The Backup registers are located in the Backup domain that remains powered-on by VBAT
even if VDD power is shut down, they are forty two 16-bit (84 bytes) registers for data protection
of user application data, and the wake-up action from Standby mode or system reset will not
affect these registers.
In addition, the Backup registers can be used to implement the tamper detection and RTC
calibration function.
After reset, any writing access to the registers in Backup domain is disabled, that is, the
Backup registers and RTC can not be accessed by writting operation. In order to enable
access to the Backup registers and RTC, the Power and Backup interface clocks should be
enabled firstly by setting the PMUEN and BKPIEN bits in the RCU_APB1EN register, and
writing access to the registers in Backup domain should be enabled by setting the BKPWEN
bit in the PMU_CTL register.
4.2. Characteristics
84 bytes Backup registers which can keep data under power saving mode. If a tamper
event is detected, Backup registers will be reset.
The active level of Tamper source (PC13) can be configured.
RTC Clock Calibration register provides RTC alarm and second output selection, and
the function of setting the calibration value.
Tamper control and status register (BKP_TPCS) can control interrupt or event of tamper
detection.
The calibration value is set by RCCV[6:0] in the BKP_OCTL register, and the calibration
function can slow down the RTC clock by steps of 1000000/2^20 ppm.
Note: When TPAL=0/1, if the TAMPER pin is already high/low before it is enabled(by setting
TPEN bit), an extra tamper event will occur even if there is no rising/falling edge on the
TAMPER pin after TPEN bit is set.
64
GD32E10x User Manual
4.4. Register definition
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATA [15:0]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
65
GD32E10x User Manual
0: RTC alarm pulse is selected as the RTC output
1: RTC second pulse is selected as the RTC output
This bit is reset only by a Backup domain reset.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
66
GD32E10x User Manual
4.4.4. Tamper control and status register (BKP_TPCS)
Address offset: 0x34
Reset value: 0x0000
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r rw w w
67
GD32E10x User Manual
5. Reset and clock unit (RCU)
5.1.1. Overview
Reset control uint includes three kinds of reset: power reset, system reset and backup domain
reset. The power reset, known as a cold reset, resets the full system except the backup
domain. The system reset resets the processor core and peripheral IP components except
for the SW-DP controller and the backup domain. The backup domain reset resets the backup
domain. The resets can be triggered by an external signal, internal events and the reset
generators. More information about these resets will be described in the following sections.
Power reset
The power reset is generated by either an external reset as power on/power down reset
(POR/PDR reset) or the internal reset generator when exiting standby mode. The power reset
sets all registers to their reset values except the backup domain. The power reset whose
active signal is low, it will be de-asserted when the internal LDO voltage regulator is ready to
provide 1.2V power. The RESET service routine vector is fixed at address 0x0000_0004 in
the memory map.
System reset
A system reset pulse generator guarantees low level pulse duration of 20 μs for each reset
source (external or internal reset).
68
GD32E10x User Manual
Figure 5-1. The system reset circuit
NRST Filter
POWER_RSTn
WWDGT_RSTn min 20 us
FWDGT_RSTn pulse System Reset
generator
SW_RSTn
OB_STDBY_RSTn
OB_DPSLP_RSTn
A backup domain reset is generated by setting the BKPRST bit in the backup domain control
register or backup domain power on reset (VDD or VBAT power on in case of both supplies have
been powered off previously).
5.2.1. Overview
The clock control unit provides a range of frequencies and clock functions. These include a
Internal 8M RC oscillator (IRC8M), a Internal 48M RC oscillator (IRC48M), a High speed
crystal oscillator (HXTAL), a Low speed Internal 40K RC oscillator (IRC40K), a Low speed
crystal oscillator (LXTAL), three Phase Lock Loop (PLL), a HXTAL clock monitor, clock
prescalers, clock multiplexers and clock gating circuitry.
The clocks of the AHB, APB and Cortex™-M4 are derived from the system clock (CK_SYS)
which can source from the IRC8M, HXTAL or PLL. The maximum operating frequency of the
system clock (CK_SYS) can be up to 120 MHz. The Free Watchdog Timer has independent
clock source (IRC40K), and Real Time Clock (RTC) uses the IRC40K, LXTAL or HXTAL/128
as its clock source.
69
GD32E10x User Manual
Figure 5-2. Clock tree
CTC
CK_IRC48M
CK_CTC
48 MHz
48 MHz
IRC48M
CK48MSEL
USBFS 1 CK_USBFS
Prescaler
1 1,1.5,2,2.5 0 (to USBFS)
SCS[1:0] 3,3.5,4
CK_IRC8M
00
Peripheral enable
TIMER1,2,3,4,5,6,
×8,9,10…, CK_PLL1 11,12,13 if(APB1
14,16,20 CK_TIMERx
prescale =1)x1 TIMERx
PLL1 else x 2 to TIMER1,2,3,4,
enable
5,6,11,12,13
/1,2,3… PLL1MF
APB2 CK_APB2
15,16 0 CK_I2S
×8,9,10…, Prescaler PCLK2
CK_PLL2
PREDV1 14,16,20 x2 1 ÷1,2,4,8,16 120 MHz max to APB2 peripherals
PLL2
Peripheral enable
I2S1/2SEL
PLL2MF TIMER0,7,8,9,10
/128 11 if(APB2 prescale
=1)x1 CK_TIMERx
TIMERx
CK_RTC else x 2 to
32.768 KHz enable
LXTAL 01 TIMER0,7,8,9,10
(to RTC)
ADC
10 Prescaler ADCPSC[3]
÷2,4,6,8,12,1
6 0 CK_ADCx to ADC0,1
RTCSRC[1:0] CK_FWDGT 40 MHz max
40 KHz 1
IRC40K ADC
(to FWDGT) Prescaler
÷3,5,7,9
00xx NO CLK
0100 CK_SYS
CK_OUT0 0101 CK_IRC8M
0110 CK_HXTAL
0111 /2 CK_PLL
1000 CK_PLL1
1001 /2 CK_PLL2
1010 CK_HXTAL
1011 CK_PLL2
1100 CK_IRC48M
1101 /8 CK_IRC48M
CKOUT0SEL[3:0]
The frequency of AHB, APB2 and the APB1 domains can be configured by each prescaler.
The maximum frequency of the AHB, APB2 and APB1 domains is 120 MHz/120 MHz/60 MHz.
The Cortex System Timer (SysTick) external clock is clocked with the AHB clock (HCLK)
divided by 8. The SysTick can work either with this clock or with the AHB clock (HCLK),
configurable in the SysTick Control and Status Register.
The ADCs are clocked by the clock of APB2 divided by 2, 4, 6, 8, 12, 16 or by the clock of
AHB divided by 3, 5, 7, 9, which defined by ADCPSC in RCU_CFG0 and RCU_CFG1 register.
The TIMERs are clocked by the clock divided from CK_APB2 and CK_APB1. The frequency
of TIMERs clock is equal to CK_APBx(APB prescaler is 1) or twice the CK_APBx(APB
prescaler is not 1).
The USBFS is clocked by the clock of CK48M. The CK48M is selected from the clock of
CK_PLL or the clock of IRC48M by CK48MSEL bit in RCU_ADDCTL register.
The CTC is clocked by the clock of IRC48M. The IRC48M can be trimmed by CTC unit
automatically.
The I2S is clocked by the clock of CK_SYS or PLL2*2 which defined by I2SxSEL bit in
70
GD32E10x User Manual
RCU_CFG1 register.
The RTC is clocked by LXTAL clock, IRC40K clock or HXTAL clock divided by 128 (defined
which clock selected by RTCSRC bit in Backup Domain Control Register (RCU_BDCTL)).
After the RTC select HXTAL clock divided by 128, the clock disappeared when the 1.2V core
domain power off. After the RTC select IRC40K, the clock disappeared when VDD power off.
After the RTC select LXTAL, the clock disappeared when VDD and VBAT power off.
The FWDGT is clocked by IRC40K clock, which is forced on when FWDGT started.
5.2.2. Characteristics
4 to 32 MHz High speed crystal oscillator (HXTAL)
Internal 8 MHz RC oscillator (IRC8M)
Internal 48 MHz RC oscillator (IRC48M)
32,768 Hz Low speed crystal oscillator (LXTAL)
Internal 40KHz RC oscillator (IRC40K)
PLL clock source can be HXTAL, IRC8M or IRC48M
HXTAL clock monitor
The high speed external crystal oscillator (HXTAL), which has a frequency from 4 to 32 MHz,
produces a highly accurate clock source for use as the system clock. A crystal with a specific
frequency must be connected and located close to the two HXTAL pins. The external resistor
and capacitor components connected to the crystal are necessary for proper oscillation.
OSCIN OSCOUT
Crystal
C1 C2
The HXTAL crystal oscillator can be switched on or off using the HXTALEN bit in the control
register RCU_CTL. The HXTALSTB flag in control register RCU_CTL indicates if the high-
speed external crystal oscillator is stable. When the HXTAL is powered up, it will not be
released for use until this HXTALSTB bit is set by the hardware. This specific delay period is
known as the oscillator “Start-up time”. As the HXTAL becomes stable, an interrupt will be
generated if the related interrupt enable bit HXTALSTBIE in the Interrupt register RCU_INT
71
GD32E10x User Manual
is set. At this point the HXTAL clock can be used directly as the system clock source or the
PLL input clock.
Select external clock bypass mode by setting the HXTALBPS and HXTALEN bits in the
Control Register RCU_CTL. The CK_HXTAL is equal to the external clock which drives the
OSCIN pin.
The internal 8M RC oscillator, IRC8M, has a fixed frequency of 8 MHz and is the default clock
source selection for the CPU when the device is powered up. The IRC8M oscillator provides
a lower cost type clock source as no external components are required. The IRC8M RC
oscillator can be switched on or off using the IRC8MEN bit in the control register RCU_CTL.
The IRC8MSTB flag in the control register RCU_CTL is used to indicate if the internal 8M RC
oscillator is stable. The start-up time of the IRC8M oscillator is shorter than the HXTAL crystal
oscillator. An interrupt can be generated if the related interrupt enable bit IRC8MSTBIE in the
clock Interrupt register RCU_INT is set when the IRC8M becomes stable. The IRC8M clock
can also be used as the system clock source or the PLL input clock.
The frequency accuracy of the IRC8M can be calibrated by the manufacturer, but its operating
frequency is still less accurate than HXTAL. The application requirements, environment and
cost will determine which oscillator type is selected.
If the HXTAL or PLL is the system clock source, to minimize the time required for the system
to recover from the Deep-sleep Mode, the hardware forces the IRC8M clock to be the system
clock when the system wakes up initially.
The internal 48M RC oscillator, IRC48M, has a fixed frequency of 48 MHz. The IRC48M
oscillator provides a lower cost type clock source, no need external components when used
for USBFS.The IRC48M RC oscillator can be switched on or off using the IRC48MEN bit in
the RCU_ADDCTL register. The IRC48MSTB flag in the RCU_ADDCTL register is used to
indicate if the internal 48M RC oscillator is stable. An interrupt can be generated if the related
interrupt enable bit IRC48MSTBIE in the RCU_ADDINT register is set when the IRC48M
becomes stable. The IRC48M clock is used for the clocks of USBFS.
The frequency accuracy of the IRC48M can be calibrated by the manufacturer, but its
operating frequency is still not enough accurate, because the USB need the frequency must
between 48MHz with 500ppm accuracy. A hardware automatic dynamic trim performed in
CTC unit adjust the IRC48M to the needed frequency.
There are three internal Phase Locked Loop, the PLL, PLL1 and PLL2.
The PLL can be switched on or off by using the PLLEN bit in the RCU_CTL Register. The
PLLSTB flag in the RCU_CTL register will indicate if the PLL clock is stable. An interrupt can
72
GD32E10x User Manual
be generated if the related interrupt enable bit, PLLSTBIE, in the RCU_INT Register, is set
as the PLL becomes stable.
The PLL1 can be switched on or off by using the PLL1EN bit in the RCU_CTL Register. The
PLL1STB flag in the RCU_CTL register will indicate if the PLL1 clock is stable. An interrupt
can be generated if the related interrupt enable bit, PLL1STBIE, in the RCU_INT Register, is
set as the PLL1 becomes stable.
The PLL2 can be switched on or off by using the PLL2EN bit in the RCU_CTL Register. The
PLL2STB flag in the RCU_CTL register will indicate if the PLL2 clock is stable. An interrupt
can be generated if the related interrupt enable bit, PLL2STBIE, in the RCU_INT Register, is
set as the PLL2 becomes stable.
The three PLLs are closed by hardware when entering the Deepsleep/Standby mode or
HXTAL monitor fail when HXTAL used as the source clock of the PLLs.
The low speed external crystal or ceramic resonator oscillator, which has a frequency of
32,768 Hz, produces a low power but highly accurate clock source for the Real Time Clock
circuit. The LXTAL oscillator can be switched on or off using the LXTALEN bit in the Backup
Domain Control Register (RCU_BDCTL). The LXTALSTB flag in the Backup Domain Control
Register (RCU_BDCTL) will indicate if the LXTAL clock is stable. An interrupt can be
generated if the related interrupt enable bit, LXTALSTBIE, in the Interrupt Register RCU_INT
is set when the LXTAL becomes stable.
Select external clock bypass mode by setting the LXTALBPS and LXTALEN bits in the
Backup Domain Control Register (RCU_BDCTL). The CK_LXTAL is equal to the external
clock which drives the OSC32IN pin.
The internal RC oscillator has a frequency of about 40 kHz and is a low power clock source
for the Real Time Clock circuit or the Free Watchdog Timer. The IRC40K offers a low cost
clock source as no external components are required. The IRC40K RC oscillator can be
switched on or off by using the IRC40KEN bit in the Reset source/clock register
(RCU_RSTSCK). The IRC40KSTB flag in the Reset source/clock register RCU_RSTSCK will
indicate if the IRC40K clock is stable. An interrupt can be generated if the related interrupt
enable bit IRC40KSTBIE in the Clock Interrupt Register (RCU_INT) is set when the IRC40K
becomes stable.
The IRC40K can be trimmed by TIMER4_CH3, user can get the clocks frequency, and adjust
the RTC and FWDGT counter. Please refer to TIMER4CH3_IREMAP in AFIO_PCF0 register.
After the system reset, the default CK_SYS source will be IRC8M and can be switched to
HXTAL or CK_PLL by changing the System Clock Switch bits, SCS, in the Clock configuration
73
GD32E10x User Manual
register 0, RCU_CFG0. When the SCS value is changed, the CK_SYS will continue to
operate using the original clock source until the target clock source is stable. When a clock
source is used as the CK_SYS directly or indirectly (by PLL), it is not possible to stop it.
The HXTAL clock monitor function is enabled by the HXTAL clock monitor enable bit CKMEN
in the control register (RCU_CTL). This function should be enabled after the HXTAL start-up
delay and disabled when the HXTAL is stopped. Once the HXTAL failure is detected, the
HXTAL will be automatically disabled. The HXTAL clock stuck interrupt flag, CKMIF, in the
clock Interrupt register RCU_INT will be set and the HXTAL failure event will be generated.
This failure interrupt is connected to the Non-Maskable Interrupt, NMI, of the Cortex-M4. If
the HXTAL is selected as the clock source of CK_SYS, PLL and CK_RTC, the HXTAL failure
will force the CK_SYS source to IRC8M, the PLL will be disabled automatically. If the HXTAL
is selected as the clock source of PLL, the HXTAL failure will force the PLL closed
automatically. If the HXTAL is selected as the clock source of RTC, the HXTAL failure will
reset the RTC clock selection.
The clock output capability is ranging from 0.09375 MHz to 120 MHz. There are several clock
signals can be selected via the CK_OUT0 Clock Source Selection bits, CKOUT0SEL, in the
Clock Configuration Register 0 (RCU_CFG0). The corresponding GPIO pin should be
configured in the properly Alternate Function I/O (AFIO) mode to output the selected clock
signal.
Voltage control
The 1.2V domain voltage in Deep-sleep mode can be controlled by DSLPVS[1:0] bit in the
Deep-sleep mode voltage register (RCU_DSV).
74
GD32E10x User Manual
Table 5-2. 1.2V domain voltage selected in deep-sleep mode
DSLPVS[1:0] Deep-sleep mode voltage(V)
00 1.0
01 0.9
10 0.8
11 1.2
75
GD32E10x User Manual
5.3. Register definition
This register can be accessed by byte (8-bit), half-word (16-bit) and word (32-bit)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
r rw r rw r rw rw rw r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IRC8M
IRC8MCALIB[7:0] IRC8MADJ[4:0] Reserved IRC8MEN
STB
r rw r rw
76
GD32E10x User Manual
Set by hardware to indicate if the PLL output clock is stable and ready for use.
0: PLL is not stable
1: PLL is stable
18 HXTALBPS High speed crystal oscillator (HXTAL) clock bypass mode enable
The HXTALBPS bit can be written only if the HXTALEN is 0.
0: Disable the HXTAL Bypass mode
1: Enable the HXTAL Bypass mode in which the HXTAL output clock is equal to the
input clock.
77
GD32E10x User Manual
8 MHz ± 1%.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw r rw
78
GD32E10x User Manual
0110: External high speed oscillator clock selected
0111: (CK_PLL / 2) clock selected
1000: CK_PLL1 clock selected
1001: CK_PLL2 clock divided by 2 selected
1010: CK_HXTAL clock selected
1011: CK_PLL2 clock selected
1100: CK_IRC48M clock selected
1101: CK_IRC48M clock divided by 8 selected
81
GD32E10x User Manual
This register can be accessed by byte(8-bit), half-word(16-bit) and word(32-bit)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLL2 PLL1 PLL HXTAL IRC8M LXTAL IRC40K PLL2 PLL1 PLL HXTAL IRC8M LXTAL IRC40K
Reserved CKMIF
STBIE STBIE STBIE STBIE STBIE STBIE STBIE STBIF STBIF STBIF STBIF STBIF STBIF STBIF
rw rw rw rw rw rw rw r r r r r r r r
82
GD32E10x User Manual
1: Reset LXTALSTBIF flag
83
GD32E10x User Manual
1: HXTAL clock stuck
84
GD32E10x User Manual
5.3.4. APB2 reset register (RCU_APB2RST)
Address offset: 0x0C
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw
86
GD32E10x User Manual
0: No reset
1: Reset Alternate Function I/O
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WWDGT TIMER13 TIMER12 TIMER11 TIMER6 TIMER5 TIMER4 TIMER3 TIMER2 TIMER1
SPI2RST SPI1RST Reserved Reserved
RST RST RST RST RST RST RST RST RST RST
rw rw rw rw rw rw rw rw rw rw rw rw
87
GD32E10x User Manual
1: Reset the I2C0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
89
GD32E10x User Manual
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw
91
GD32E10x User Manual
0: Disabled TIMER7 clock
1: Enabled TIMER7 clock
92
GD32E10x User Manual
1: Enabled GPIO port A clock
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
WWDGTE TIMER13E TIMER12E TIMER11E TIMER6 TIMER5 TIMER4 TIMER3 TIMER2 TIMER1
SPI2EN SPI1EN Reserved Reserved
N N N N EN EN EN EN EN EN
rw rw rw rw rw rw rw rw rw rw rw rw
93
GD32E10x User Manual
0: Disabled I2C1 clock
1: Enabled I2C1 clock
Note: The LXTALEN, LXTALBPS, RTCSRC and RTCEN bits of the Backup domain control
register (RCU_BDCTL) are only reset after a Backup domain Reset. These bits can be
modified only when the BKPWEN bit in the Power control register (PMU_CTL) is set.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved BKPRST
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw r rw
96
GD32E10x User Manual
Note: The LXTALDRI can not be used in bypass mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
r r r r r r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IRC40K IRC40KE
Reserved
STB N
r rw
97
GD32E10x User Manual
1: Window watchdog reset generated
98
GD32E10x User Manual
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
USBFSR
Reserved Reserved
ST
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
99
GD32E10x User Manual
28:19 Reserved Must be kept at reset value.
100
GD32E10x User Manual
1111: (PLL1 source clock x 20)
101
GD32E10x User Manual
5.3.13. Deep-sleep mode voltage register (RCU_DSV)
Address offset: 0x34
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DSLPVS[1:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IRC48M IRC48ME
IRC48MCALIB[7:0] Reserved
STB N
r r rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CK48M
Reserved
SEL
rw
102
GD32E10x User Manual
Set by hardware to indicate if the IRC48M oscillator is stable and ready for use.
0: IRC48M is not stable
1: IRC48M is stable
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IRC48M
Reserved Reserved
STBIC
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IRC48M IRC48M
Reserved Reserved Reserved
STBIE STBIF
rw r
103
GD32E10x User Manual
0: Disable the IRC48M stabilization interrupt
1: Enable the IRC48M stabilization interrupt
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
104
GD32E10x User Manual
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
105
GD32E10x User Manual
6. Clock trim controller (CTC)
6.1. Overview
The clock trim controller (CTC) is used to trim internal 48MHz RC oscillator (IRC48M)
automatically by hardware. When using IRC48M as USBFS clock source, the IRC48M must
be 48 MHz with 500ppm accuracy. The internal oscillator cannot meet such high accuracy,
so it is needed to calibrate the IRC48M. The CTC unit trims the frequency of the IRC48M
which is based on an external accurate reference signal source. It can adjust the calibration
value to provide a precise IRC48M clock automatically or manually.
6.2. Characteristics
Three external reference signal sources: GPIO, LXTAL clock, USBFS SOF.
Provide software reference sync pulse.
Trimmed by hardware without any software action automatically.
16 bits trim counter with reference signal source capture and reload function.
8 bits clock trim base value used for frequency evaluation and automatic trim.
Flags or interrupts to indicate whether the clock trim status is OK (CKOKIF), warning
(CKWARNIF) or error (ERRIF).
106
GD32E10x User Manual
6.3. Function overview
CTC
Register
REFSEL REFPSC
SWREFPUL
USBFS_SOF 10
CTC_SYNC 00
Prescaler
(/1,/2,/4,…,/128)
LXTAL 01
1'b0 11
REFCAP
TRIMVALUE
TRIMVALUE
Comparator
adjustment
CKLIM
Firstly, the reference signal source can select GPIO, LXTAL clock output, or USBFS SOF by
setting REFSEL bits in CTC_CTL1 register.
Secondly, the selected reference signal source uses a configurable polarity by setting
REFPOL bit in CTC_CTL1 register, and can be divided to a suitable frequency with a
configurable prescaler by setting REFPSC bits in CTC_CTL1 register.
The CTC trim counter is clocked by CK_IRC48M. After the CNTEN bit in CTC_CTL0 register
107
GD32E10x User Manual
is set, and a first REF sync pulse is detected, the counter starts down-counting from
RLVALUE (defined in CTC_CTL1 register). If any REF sync pulse is detected, the counter
reloads the RLVALUE and starts down-counting again. If no REF sync pulse is detected, the
counter down-counts to zero, and then up-counts to 128 x CKLIM (defined in CTC_CTL1
register), and then stops until next REF sync pulse is detected. If any REF sync pulse is
detected, the current CTC trim counter value is captured to REFCAP in status register
(CTC_STAT), and the counter direction is captured to REFDIR in status register (CTC_STAT).
The detail shows as following figure.
RLVALUE
128 x CKLIM
3 x CKLIM
CKLIM
CLOCK
TRIM VALUE +2 +1 0 -1 -2
CTC STATUS CKERR CKWARN CKOK CKWARN REFMISS
The clock frequency evaluation is performed when a REF sync pulse occurs. If a REF sync
pulse occurs on down-counting, it means the current clock is slower than correct clock (the
frequency of 48M). It needs to increase the TRIMVALUE in CTC_CTL0 register. If a REF sync
pulse occurs on up-counting, it means the current clock is faster than correct clock (the
frequency of 48M). It needs to reduce the TRIMVALUE in CTC_CTL0 register. The CKOKIF,
CKWARNIF, CKERR and REFMISS in CTC_STAT register show the frequency evaluation
scope.
If the AUTOTRIM bit in CTC_CTL0 register is set, the automatic hardware trim mode is
enabled. In this mode, if a REF sync pulse occurs on down-counting, it means the current
clock is slower than correct clock, the TRIMVALUE will be increased to raise the clock
frequency automatically. Vice versa when it occurs on up-counting, the TRIMVALUE will be
decreased to reduce the clock frequency automatically.
108
GD32E10x User Manual
Counter < CKLIM when REF sync pulse is detected.
When the CKOKIF in CTC_STAT register is set, an interrupt will be generated if CKOKIE
bit in CTC_CTL0 register is 1.
If the AUTOTRIM bit in CTC_CTL0 register is set, the TRIMVALUE in CTC_CTL0 register
is not changed.
When the CKOKIF in CTC_STAT register is set, an interrupt will be generated if CKOKIE
bit in CTC_CTL0 register is 1.
3 x CKLIM ≤ Counter < 128 x CKLIM when REF sync pulse is detected.
Counter ≥ 128 x CKLIM when down-counting and a REF sync pulse is detected.
When the CKERR in CTC_STAT register is set, an interrupt will be generated if ERRIE
bit in CTC_CTL0 register is 1.
When the REFMISS in CTC_STAT register is set, an interrupt will be generated if ERRIE
bit in CTC_CTL0 register is 1.
If adjusting the TRIMVALUE in CTC_CTL0 register over 63, the overflow will be occurred,
while adjusting the TRIMVALUE under 0, the underflow will be occurred. The TRIMVALUE
ranges from 0 to 63 (the TRIMVALUE is 63 if overflow, the TRIMVALUE is 0 if underflow).
Then, the TRIMERR in CTC_STAT register will be set, and an interrupt will be generated if
ERRIE bit in CTC_CTL0 register is 1.
The RLVALUE and CKLIM bits in CTC_CTL1 register are critical to evaluate the clock
frequency and automatic hardware trim. The value is calculated by the correct clock frequency
(IRC48M:48 MHz) and the frequency of REF sync pulse. The ideal case is REF sync pulse
occurs when the CTC counter is zero, so the RLVALUE is:
The typical step size is 0.12%. Where the Fclock is the frequency of correct clock (IRC48M),
the FREF is the frequency of reference sync pulse.
110
GD32E10x User Manual
6.4. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw w rw rw rw rw rw rw
111
GD32E10x User Manual
trim counter. When this bit is set, the CTC_CTL1 register cannot be modified.
0: CTC trim counter disabled
1: CTC trim counter enabled.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RLVALUE[15:0]
rw
112
GD32E10x User Manual
These bits are set and cleared by software to select reference signal source.
00: GPIO selected
01: LXTAL clock selected
10: USBFS SOF selected
11: Reserved.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
REFCAP[15:0]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r r r r r r r
113
GD32E10x User Manual
When a reference sync pulse occurs, the CTC trim counter value is captured to
REFCAP bits.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CKWARN CKOK
Reserved EREFIC ERRIC
IC IC
w w w w
115
GD32E10x User Manual
This bit is written by software and read as 0. Write 1 to clear EREFIF bit in
CTC_STAT register. Writing 0 has no effect.
116
GD32E10x User Manual
7. Interrupt/event controller(EXTI)
7.1. Overview
Cortex-M4 integrates the Nested Vectored Interrupt Controller (NVIC) for efficient exceptions
and interrupts processing. NVIC facilitates low-latency exception and interrupt handling, it
also controls power management. It’s tightly coupled to the processer core. For more details
about NVIC, read the Technical Reference Manual of Cortex-M4.
7.2. Characteristics
The ARM Cortex-M4 processor and the Nested Vectored Interrupt Controller (NVIC) prioritize
and handle all exceptions in Handler Mode. The processor state is automatically stored to the
stack on an exception, and automatically restored from the stack at the end of the Interrupt
Service Routine(ISR).
The vector is fetched in parallel to the state saving, enabling efficient interrupt entry. The
processor supports tail-chaining that enables back-to-back interrupts to be performed without
the overhead of state saving and restoration. The following tables list all exception types.
117
GD32E10x User Manual
Exception Vector
Priority (a) Vector Address Description
Type Number
NMI 2 -2 0x0000_0008 Non maskable interrupt.
HardFault 3 -1 0x0000_000C All class of fault
MemManage 4 Programmable 0x0000_0010 Memory management
Prefetch fault, memory access
BusFault 5 Programmable 0x0000_0014
fault
Undefined instruction or illegal
UsageFault 6 Programmable 0x0000_0018
state
0x0000_001C -
- 7-10 - Reserved
0x0000_002B
System service call via SWI
SVCall 11 Programmable 0x0000_002C
instruction
Debug Monitor 12 Programmable 0x0000_0030 Debug Monitor
- 13 - 0x0000_0034 Reserved
Pendable request for system
PendSV 14 Programmable 0x0000_0038
service
SysTick 15 Programmable 0x0000_003C System tick timer
The SysTick calibration value is 15000 and SysTick clock frequency is fixed to HCLK*0.125.
1ms SysTick interrupt will be generated when HCLK is configured to 120MHz.
119
GD32E10x User Manual
Interrupt Vector
Interrupt Description Vector Address
Number Number
TIMER7 update interrupt
IRQ 44 60 and TIMER12 global 0x0000_00F0
interrupt
TIMER7 trigger and Channel
IRQ 45 61 commutation interrupts and 0x0000_00F4
TIMER13 global interrupt
TIMER7 channel capture
IRQ 46 62 0x0000_00F8
compare interrupt
IRQ 47 63 Reserved 0x0000_00FC
IRQ 48 64 EXMC global interrupt 0x0000_0100
IRQ 49 65 Reserved 0x0000_0104
IRQ50 66 TIMER4 global interrupt 0x0000_0108
IRQ51 67 SPI2 global interrupt 0x0000_010C
IRQ52 68 UART3 global interrupt 0x0000_0110
IRQ53 69 UART4 global interrupt 0x0000_0114
IRQ54 70 TIMER5 global interrupt 0x0000_0118
IRQ55 71 TIMER6 global interrupt 0x0000_011C
DMA1 channel0 global
IRQ56 72 0x0000_0120
interrupt
DMA1 channel1 global
IRQ57 73 0x0000_0124
interrupt
DMA1 channel2 global
IRQ58 74 0x0000_0128
interrupt
DMA1 channel3 global
IRQ59 75 0x0000_012C
interrupt
DMA1 channel4 global
IRQ60 76 0x0000_0130
interrupt
0x0000_0134-
IRQ61-66 77-82 Reserved
0x0000_0148
IRQ67 83 USBFS global interrupt 0x0000_014C
120
GD32E10x User Manual
7.4. External interrupt and event (EXTI) block diagram
Polarity Software
Control Trigger
EXTI Line0~18
Edge
detector
To NVIC
Interrupt Mask
Control
To Wakeup Unit
Event Event Mask
Generate Control
The EXTI trigger source includes 16 external lines from GPIO pins and 3 internal lines from
internal modules (including LVD, RTC Alarm, and USBFS wakeup). All GPIO pins can be
selected as an EXTI trigger source by configuring AFIO_EXTISSx registers in GPIO module
(refer to chapter GPIO and section AFIO for detail).
EXTI provides not only interrupts but also events signals to the processor. The Cortex-M4
processor fully supports the wait for interrupt (WFI), wait for event (WFE) and the send event
(SEV) instructions. The wake up interrupt controller (WIC) enables the processor and NVIC
to be put into a very low-power sleep mode, leaving the WIC to identify and prioritize interrupts
and events. EXTI can be used to wake up processor and the whole system when some
expected event occurs, such as a special GPIO pin toggling or RTC alarm.
121
GD32E10x User Manual
EXTI Line
Source
Number
2 PA2/PB2/PC2/PD2/PE2
3 PA3/PB3/PC3/PD3/PE3
4 PA4/PB4/PC4/PD4/PE4
5 PA5/PB5/PC5/PD5/PE5
6 PA6/PB6/PC6/PD6/PE6
7 PA7/PB7/PC7/PD7/PE7
8 PA8/PB8/PC8/PD8/PE8
9 PA9/PB9/PC9/PD9/PE9
10 PA10/PB10/PC10/PD10/PE10
11 PA11/PB11/PC11/PD11/PE1
12 PA12/PB12/PC12/PD12/PE12
13 PA13/PB13/PC13/PD13/PE13
14 PA14/PB14/PC14/PD14/PE14
15 PA15/PB15/PC15/PD15/PE15
16 LVD
17 RTC Alarm
18 USBFS Wakeup
122
GD32E10x User Manual
7.6. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
INTEN15 INTEN14 INTEN13 INTEN12 INTEN11 INTEN10 INTEN9 INTEN8 INTEN7 INTEN6 INTEN5 INTEN4 INTEN3 INTEN2 INTEN1 INTEN0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EVEN15 EVEN14 EVEN13 EVEN12 EVEN11 EVEN10 EVEN9 EVEN8 EVEN7 EVEN6 EVEN5 EVEN4 EVEN3 EVEN2 EVEN1 EVEN0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
123
GD32E10x User Manual
7.6.3. Rising edge trigger enable register (EXTI_RTEN)
Address offset: 0x08
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RTEN15 RTEN14 RTEN13 RTEN12 RTEN11 RTEN10 RTEN9 RTEN8 RTEN7 RTEN6 RTEN5 RTEN4 RTEN3 RTEN2 RTEN1 RTEN0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FTEN15 FTEN14 FTEN13 FTEN12 FTEN11 FTEN10 FTEN9 FTEN8 FTEN7 FTEN6 FTEN5 FTEN4 FTEN3 FTEN2 FTEN1 FTEN0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
124
GD32E10x User Manual
This register has to be accessed by word(32-bit)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SWIEV15 SWIEV14 SWIEV13 SWIEV12 SWIEV11 SWIEV10 SWIEV9 SWIEV8 SWIEV7 SWIEV6 SWIEV5 SWIEV4 SWIEV3 SWIEV2 SWIEV1 SWIEV0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PD15 PD14 PD13 PD12 PD11 PD10 PD9 PD8 PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0
rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1
125
GD32E10x User Manual
8. General-purpose and alternate-function I/Os (GPIO
and AFIO)
8.1. Overview
There are up to 80 general purpose I/O pins (GPIO), named PA0 ~ PA15, PB0 ~ PB15, PC0
~ PC15, PD0 ~ PD15 and PE0 ~ PE15 for the device to implement logic input/output functions.
Each GPIO port has related control and configuration registers to satisfy the requirements of
specific applications. The external interrupts on the GPIO pins of the device have related
control and configuration registers in the Interrupt/Event Controller Unit (EXTI).
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 such as the AF input or output pins.
Each of the GPIO pins can be configured by software as output (push-pull or open-drain),
input, peripheral alternate function or analog mode. Each GPIO pin can be configured as pull-
up, pull-down or floating. All GPIOs are high-current capable except for analog mode.
8.2. Characteristics
Each of the general-purpose I/O ports can be configured as 8 modes, including analog inputs,
input floating, input pull-down/pull-up, GPIO push-pull/open-drain and AFIO push-pull/open-
drain mode by two GPIO configuration registers (GPIOx_CTL0/GPIOx_CTL1), and a 32-bits
registers (GPIOx_OCTL). Table 8-1. GPIO configuration table shows the details.
Figure 8-1. Basic structure of a standard I/O port bit shows the basic structure of an I/O
Port bit.
Output
Control
Alternate Function Output
ESD
protection
Vss
Analog ( Input / Output ) I/O pin
Vdd
Read Input
Status
Register
Schmitt
Input driver trigger
Vss
During or just after the reset period, the alternative functions are all inactive and the GPIO
ports are configured as the input floating mode without pull-up (PU)/pull-down (PD) resistors.
But the JTAG/Serial-Wired Debug pins are configured as input PU/PD mode after the reset.
127
GD32E10x User Manual
PB3: JTDO in floating mode
The GPIO pins can be configured as inputs or outputs. When the GPIO pins are configured
as input pins, all GPIO pins have an internal weak pull-up and weak pull-down which can be
chosen. And the data on the external pins can be captured at every APB2 clock cycle to the
port input status register (GPIOx_ISTAT).
When the GPIO pins are configured as output pins, the user can configure the speed of the
ports and choose the output driver mode, push-pull or open-drain mode. The value of the port
output control register (GPIOx_OCTL) is output on the I/O pin.
There is no need to read-then-write when programming the GPIOx_OCTL at the bit level, the
user can modify only one bit or several bits in a single atomic APB2 write access by
programming ‘1’ to the bit operate register (GPIOx_BOP, or for GPIOx_BC). The other bits
will not be affected.
All ports have external interrupt capability. To use external interrupt lines, the port must be
configured as input mode.
When the port is configured as AFIO (set CTLy bits to “0b10” or “0b11”, and set MDy bits to
“0b01”, “0b10”, or “0b11”, which is in GPIOx_CTL0/GPIOx_CTL1 registers), the port is used
as peripheral alternate functions. The detail alternate function assignments for each port are
described in the device datasheet.
Figure 8-2. Input configuration shows the input configuration of the GPIO pin.
128
GD32E10x User Manual
Figure 8-2. Input configuration
Figure 8-3. Output configuration shows the output configuration of the GPIO pin.
Output
Alternate Function Output Control
ESD
protection
Vss
I/O pin
Vdd
Read Input
Status
Register
Schmitt
Input driver trigger Vss
129
GD32E10x User Manual
8.3.6. Analog configuration
When GPIO pin is used as analog configuration.
Figure 8-4. Analog configuration shows the analog configuration of the GPIO pin.
ESD
protection
To suit for different device packages, the GPIO supports some alternate functions mapped to
some other pins by software.
Figure 8-5. Alternate function configuration shows the alternate function configuration of
the GPIO pin.
130
GD32E10x User Manual
Figure 8-5. Alternate function configuration
Output driver
Vdd
ESD
protection
Vss
I/O pin
Vdd
Schmitt
trigger Vss
Input driver
The protected registers are GPIOx_CTL0, GPIOx_CTL1. It allows the I/O configuration to be
frozen by the 32-bit locking register (GPIOx_LOCK). When the special LOCK sequence has
occurred on LKK bit in GPIOx_LOCK register and the LKy bit is set in GPIOx_LOCK register,
the corresponding port is locked and the corresponding port configuration cannot be modified
until the next reset. It is recommended to be used in the configuration of driving a power
module.
If the I/O port output speed need more than 50MHz, it is recommended to use the
compensation cell for slew rate control to reduce the I/O noise effects on the power supply.
Compensation cell is disabled after reset, it needs to be enabled by the user. After enabling
the compensation cell, the complete flag CPS_RDY is set to indicate that the compensation
cell is ready and can be used. If the supply voltage over 2.4 V~3.6V, must disable the
compensation cell.
8.4.1. Overview
In order to expand the flexibility of the GPIO or the usage of peripheral functions, each I/O pin
can be configured up to four different functions by setting the AFIO port configuration register
131
GD32E10x User Manual
(AFIO_PCF0/AFIO_PCF1). Suitable pinout locations can be selected using the peripheral IO
remapping function. Additionally, various GPIO pins can be selected as the EXTI interrupt
line source by setting the relevant EXTI source selection register (AFIO_EXTISSx) to trigger
an interrupt or event.
8.4.2. Characteristics
EXTI source selection
Each pin has up to four alternative functions for configuration
To reduce the number of GPIOs used for debugging, the user can configure SWJ_CFG[2:0]
bits in the AFIO_PCF0 to a different value. Refer to the table below.
132
GD32E10x User Manual
1. Only released if the asynchronous trace is not used.
133
GD32E10x User Manual
2. Remap not available for the 36-pin package.
2. TIMER1_CH0 and TIMER1_ETI share the same pin but cannot be used at the same time.
134
GD32E10x User Manual
8.4.6. USART AF remapping
Refer to AFIO Port Configuration Register (AFIO_PCF0).
The HXTAL oscillator pins OSC_IN/OSC_OUT can be used as general-purpose I/O PD0/PD1.
PD0/PD1 cannot be used for external interrupt/event generation on 36--pin, 48--pin and 64-
pin packages.
136
GD32E10x User Manual
PD0 OSC_IN PD0
PD1 OSC_OUT PD1
137
GD32E10x User Manual
8.5. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
138
GD32E10x User Manual
Refer to MD0[1:0] description.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
140
GD32E10x User Manual
17:16 MD12[1:0] Port 12 mode bits
These bits are set and cleared by software.
Refer to MD0[1:0] description.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ISTAT15 ISTAT14 ISTAT13 ISTAT12 ISTAT11 ISTAT10 ISTAT 9 ISTAT 8 ISTAT 7 ISTAT 6 ISTAT 5 ISTAT 4 ISTAT 3 ISTAT 2 ISTAT 1 ISTAT 0
141
GD32E10x User Manual
r r r r r r r r r r r r r r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
OCTL15 OCTL14 OCTL13 OCTL12 OCTL11 OCTL10 OCTL9 OCTL8 OCTL7 OCTL6 OCTL5 OCTL4 OCTL3 OCTL2 OCTL1 OCTL0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CR15 CR14 CR13 CR12 CR11 CR10 CR9 CR8 CR7 CR6 CR5 CR4 CR3 CR2 CR1 CR0
w w w w w w w w w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BOP15 BOP14 BOP13 BOP12 BOP11 BOP10 BOP9 BOP8 BOP7 BOP6 BOP5 BOP4 BOP3 BOP2 BOP1 BOP0
w w w w w w w w w w w w w w w w
142
GD32E10x User Manual
Bits Fields Descriptions
31:16 CRy Port clear bit y(y=0..15)
These bits are set and cleared by software.
0: No action on the corresponding OCTLy bit
1: Clear the corresponding OCTLy bit to 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CR15 CR14 CR13 CR12 CR11 CR10 CR9 CR8 CR7 CR6 CR5 CR4 CR3 CR2 CR1 CR0
w w w w w w w w w w w w w w w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved LKK
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
LK15 LK14 LK13 LK12 LK11 LK10 LK9 LK8 LK7 LK6 LK5 LK4 LK3 LK2 LK1 LK0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
143
GD32E10x User Manual
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SPD15 SPD 14 SPD 13 SPD 12 SPD 11 SPD 10 SPD 9 SPD 8 SPD 7 SPD 6 SPD 5 SPD 4 SPD 3 SPD 2 SPD 1 SPD 0
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15:0 SPDy Set very high output speed(120MHz) when MDx is 0b11.
If the port output speed is more than 50MHz, set this bit to 1 and set MDx to
0b11.These bits are set and cleared by software.
0: No effect
1: Max speed more than 50MHz.( MDx required to be set to 0b11 together )
Note: When the port output speed is more than 50 MHz, the user should enable the
I/O compensation cell. Refer to CPS_EN bit in AFIO_CPSCTL register.
144
GD32E10x User Manual
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw w rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
145
GD32E10x User Manual
PD01_RE TIMER3_ TIMER2_REMAP[1:0 TIMER1_REMAP[1:0 TIMER0_REMAP[1:0 USART2_REMAP[1: USART1_ USART0_ I2C0_RE SPI0_RE
Reserved
MAP REMAP ] ] ] 0] REMAP REMAP MAP MAP
rw rw rw rw rw rw rw rw rw rw
146
GD32E10x User Manual
the ADC1 external event inserted conversion is connected to TIMER7_CH3.
147
GD32E10x User Manual
These bits are set and cleared by software.
00: No remap(TIMER1_CH0-TIMER1_ETI/PA0, TIMER1_CH1/PA1,
TIMER1_CH2/PA2, TIMER1_CH3/PA3)
01: Partial remap(TIMER1_CH0-TIMER1_ETI/PA15, TIMER1_CH1/PB3,
TIMER1_CH2/PA2, TIMER1_CH3/PA3)
10: Partial remap(TIMER1_CH0-TIMER1_ETI/PA0, TIMER1_CH1/PA1,
TIMER1_CH2/PB10, TIMER1_CH3/PB11)
11: Full remap(TIMER1_CH0-TIMER1_ETI/PA15, TIMER1_CH1/PB3,
TIMER1_CH2/PB10, TIMER1_CH3/PB11)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
149
GD32E10x User Manual
Other configurations are reserved.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
150
GD32E10x User Manual
0011: PD6 pin
0100: PE6 pin
Other configurations are reserved.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
151
GD32E10x User Manual
0001: PB10 pin
0010: PC10 pin
0011: PD10 pin
0100: PE10 pin
Other configurations are reserved.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
152
GD32E10x User Manual
Other configurations are reserved.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EXMC TIMER8_
Reserved CTC_REMAP[1:0] Reserved Reserved
_NADV REMAP
rw rw rw
153
GD32E10x User Manual
12:11 CTC_REMAP [1:0] CTC remapping
These bits are set and cleared by software, they control the mapping of the
CTC_SYNC alternate function onto the GPIO ports
00: No remap (PA8)
01: Remap0 (PD15)
10/11: Reserved
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r rw
154
GD32E10x User Manual
When the port output speed is more than 50 MHz, the user should enable the I/O
compensation cell.
0: I/O compensation cell is disabled
1: I/O compensation cell is enabled
155
GD32E10x User Manual
9. CRC calculation unit (CRC)
9.1. Overview
This CRC calculation unit can be used to calculate 32 bit CRC code with fixed polynomial.
9.2. Characteristics
32-bit data input and 32-bit data output. Calculation period is 4 AHB clock cycles for 32-
bit input data size from data entered to the calculation result available.
Free 8-bit register is unrelated to calculation and can be used for any other goals by any
other peripheral devices.
Fixed polynomial: 0x4C11DB7
X32 +X26 +X23 +X22 +X16 +X12 +X11 +X10 +X8 +X7 +X5 +X4 +X2 +X+1
156
GD32E10x User Manual
Figure 9-1. Block diagram of CRC calculation unit
Data Input
Input Data Register (32 bit)
AHB
BUS
Interface
Data Output
Output Data Register (32 bit)
Data Access
Free Purpose Register (8 bit)
CRC calculation unit is used to calculate the 32-bit raw data, and CRC_DATA register
will receive the raw data and store the calculation result.
If the CRC_DATA register has not been cleared by software setting the CRC_CTL
register, the new input raw data will be calculated based on the result of previous value
of CRC_DATA.
CRC calculation will spend 4 AHB clock cycles for 32-bit data size, during this period
AHB will not be hanged because of the existence of the 32-bit input buffer.
CRC_FDATA is unrelated to the CRC calculation, any value you write in will be read out
at anytime.
157
GD32E10x User Manual
9.4. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DATA [31:16]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DATA [15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
158
GD32E10x User Manual
These bits are unrelated with CRC calculation. This byte can be used for any goal
by any other peripheral. The CRC_CTL register will take no effect to the byte.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved RST
rs
0 RST Set this bit can reset the CRC_DATA register to the value of 0xFFFFFFFF then
automatically cleared itself to 0 by hardware. This bit will take no effect to
CRC_FDATA.
Software writes and reads.
159
GD32E10x User Manual
10. Direct memory access controller (DMA)
10.1. Overview
The direct memory access (DMA) controller provides a hardware method of transferring data
between peripherals and/or memory without intervention from the CPU, thereby freeing up
bandwidth for other system functions. Data can be quickly moved by DMA between
peripherals and memory as well as memory and memory without any CPU actions. There are
12 channels in the DMA controller (7 for DMA0 and 5 for DMA1). Each channel is dedicated
to manage memory access requests from one or more peripherals. An arbiter is implemented
inside to handle the priority among DMA requests.
The system bus is shared by the DMA controller and the Cortex ®-M4 core. When the DMA
and the CPU are targeting the same destination, the DMA access may stop the CPU access
to the system bus for some bus cycles. Round-robin scheduling is implemented in the bus
matrix to ensure at least half of the system bus bandwidth for the CPU.
10.2. Characteristics
160
GD32E10x User Manual
10.3. Block diagram
Channel 6
peri_req AHB master
AHB interface
Control
Channel 2 Master
peri_req
Port
Channel 1
peri_req
Channel 0
peri_req
Memory control
state & counter
management
…
As shown in Figure 10-1. Block diagram of DMA, a DMA controller consists of four main
parts:
Each DMA transfer consists of two operations, including the loading of data from the source
and the storage of the loaded data to the destination. The source and destination addresses
are computed by the DMA controller based on the programmed values in the
DMA_CHxPADDR, DMA_CHxMADDR, and DMA_CHxCTL registers. The DMA_CHxCNT
register controls how many transfers to be transmitted on the channel. The PWIDTH and
MWIDTH bits in the DMA_CHxCTL register determine how many bytes to be transmitted in a
transfer.
Suppose DMA_CHxCNT is 4, and both PNAGA and MNAGA are set. The DMA transfer
operations for each combination of PWIDTH and MWIDTH are shown in Table 10-1. DMA
161
GD32E10x User Manual
transfer operation.
The CNT bits in the DMA_CHxCNT register control how many data to be transmitted on the
channel and must be configured before enabling the CHEN bit in the register. During the
transmission, the CNT bits indicate the remaining number of data to be transferred.
The DMA transmission is disabled by clearing the CHEN bit in the DMA_CHxCTL register.
If the DMA transmission has not been completed when the CHEN bit is cleared, two
situations may occur when restart this DMA channel:
– If no register configuration operations of the channel occur before restarting the
DMA channel, the DMA will continue to complete the rest of the transmission.
– If any register configuration operations occur, the DMA will restart a new
transmission.
If the DMA transmission has been finished when clearing the CHEN bit, enabling the
DMA channel without any register configuration operation will not launch any DMA
transfer.
162
GD32E10x User Manual
10.4.2. Peripheral handshake
Request signal asserted by peripheral to DMA controller, indicating that the peripheral is
ready to transmit or receive data.
Acknowledge signal responded by DMA to peripheral, indicating that the DMA controller
has initiated an AHB command to access the peripheral.
Figure 10-2. Handshake mechanism shows how the handshake mechanism works between
the DMA controller and peripherals.
Peripheral Peripheral
Peripheral request
request request
Wait the DMA bus to be idle and The DMA controller deasserts
other higher priority channels to the acknowledge signal when
have been processed it receives low request signal
DMA
DMA acknowledge
Acknowledge
10.4.3. Arbitration
When two or more requests are received at the same time, the arbiter determines which
request is served based on the priorities of the channels. There are two-stage priorities,
including the software priority and the hardware priority. The arbiter determines which channel
is selected to respond according to the following priority rules:
Software priority: Four levels, including low, medium, high and ultra high by configuring
the PRIO bits in the DMA_CHxCTL register.
For channels with equal software priority level, priority is given to the channel with lower
channel number.
Two kinds of address generation algorithm are implemented independently for memory and
peripheral, including the fixed mode and the increased mode. The PNAGA and MNAGA bit
in the DMA_CHxCTL register are used to configure the next address generation algorithm of
peripheral and memory.
In the fixed mode, the next address is always equal to the base address configured in the
base address registers (DMA_CHxPADDR, DMA_CHxMADDR).
163
GD32E10x User Manual
In the increasing mode, the next address is equal to the current address plus 1 or 2 or 4,
depending on the transfer data width.
Circular mode is implemented to handle continue peripheral requests (for example, ADC scan
mode). The circular mode is enabled by setting the CMEN bit in the DMA_CHxCTL register.
In circular mode, the CNT bits are automatically reloaded with the pre-programmed value and
the full transfer finish flag is asserted at the end of every DMA transfer. DMA can always
respond the peripheral request until the CHEN bit in the DMA_CHxCTL register is cleared.
The memory to memory mode is enabled by setting the M2M bit in the DMA_CHxCTL register.
In this mode, the DMA channel can also work without being triggered by a request from a
peripheral. The DMA channel starts transferring as soon as it is enabled by setting the CHEN
bit in the DMA_CHxCTL register, and completed when the DMA_CHxCNT register reaches
zero.
When starting a new DMA transfer, it is recommended to respect the following steps:
1. Read the CHEN bit and judge whether the channel is enabled or not. If the channel is
enabled, clear the CHEN bit by software. When the CHEN bit is read as ‘0’, configuring
and starting a new DMA transfer is allowed.
2. Configure the M2M bit and DIR bit in the DMA_CHxCTL register to set the transfer mode.
3. Configure the CMEN bit in the DMA_CHxCTL register to enable/disable the circular mode.
4. Confi gure the PRIO bits in the DMA_CHxCTL register to set the channel software priority.
5. Configure the memory and peripheral transfer width, memory and peripheral address
generation algorithm in the DMA_CHxCTL register.
6. Configure the enable bit for full transfer finish interrupt, half transfer finish interrupt,
transfer error interrupt in the DMA_CHxCTL register.
7. Configure the DMA_CHxPADDR register for setting the peripheral base address.
8. Configure the DMA_CHxMADDR register for setting the memory base address.
9. Configure the DMA_CHxCNT register to set the total transfer data number.
10. Configure the CHEN bit with ‘1’ in the DMA_CHxCTL register to enable the channel.
10.4.8. Interrupt
Each DMA channel has a dedicated interrupt. There are three types of interrupt event,
including full transfer finish, half transfer finish, and transfer error.
Each interrupt event has a dedicated flag bit in the DMA_INTF register, a dedicated clear bit
164
GD32E10x User Manual
in the DMA_INTC register, and a dedicated enable bit in the DMA_CHxCTL register. The
relationship is described in Table 10-2. Interrupt events.
The DMA interrupt logic is shown in Figure 10-3. DMA interrupt logic, an interrupt can be
produced when any type of interrupt event occurs and is enabled on the channel.
HTFIFx
and or CHxINTF
HTFIEx
ERRIFx
and
ERRIEx
Note: “x” indicates channel number (for DMA0, x=0…6, for DMA1, x=0…4).
Several requests from peripherals may be mapped to one DMA channel. They are logically
ORed before entering the DMA. For details, see Figure 10-4. DMA0 request mapping and
Figure 10-5. DMA1 request mapping. The request of each peripheral can be independently
enabled or disabled by programming the registers of the corresponding peripheral. The user
has to ensure that only one request is enabled at a time on one channel. Table 10-3. DMA0
requests for each channel lists the supported request from peripheral for each channel of
DMA0, and Table 10-4. DMA1 requests for each channel lists the supported request from
165
GD32E10x User Manual
peripheral for each channel of DMA1.
SPI0_RX
USART2_TX
Channel 1 or TIMER0_CH0
TIMER1_UP
or TIMER2_CH2
MEMTOMEM1
MEMTOMEM2
SPI0_TX
USART2_RX
Channel 2 or TIMER0_CH1
TIMER2_CH3
or TIMER2_UP
MEMTOMEM2
SPI1/I2S1_RX
USART0_TX
I2C1_TX
Channel 3 or TIMER0_CH3
TIMER0_TG
or TIMER0_CMT
MEMTOMEM3
MEMTOMEM4 TIMER3_CH1
SPI1/I2S1_TX
USART0_RX
I2C1_RX
Channel 4 or TIMER0_UP
or TIMER1_CH0
TIMER3_CH2
MEMTOMEM4
USART1_RX
I2C0_TX
Channel 5 or TIMER0_CH2
TIMER2_CH0
or TIMER2_TG
MEMTOMEM5
MEMTOMEM6
USART1_TX
I2C0_RX
Channel 6 or TIMER1_CH1
TIMER1_CH3
low
or TIMER3_UP
MEMTOMEM6
Hardware
priority SPI2/I2S2_RX
TIMER4_CH3
high Channel 0 or TIMER4_TG
TIMER7_CH2
or TIMER7_UP
MEMTOMEM0
SPI2/I2S2_TX
TIMER4_CH2
TIMER4_UP
Channel 1 or TIMER7_CH3
or TIMER7_TG
TIMER7_CMT
MEMTOMEM1
MEMTOMEM2
UART3_RX
TIMER5_UP
Channel 2 or DAC_CH0
or TIMER7_CH0
MEMTOMEM2
TIMER4_CH1
Channel 3 or TIMER6_UP
DAC_CH1
or
MEMTOMEM3
MEMTOMEM4
UART3_TX
Channel 4 or TIMER4_CH0
TIMER7_CH1
low
or
MEMTOMEM4
167
GD32E10x User Manual
168
GD32E10x User Manual
10.5. Register definition
Note: For DMA1 having 5 channels, all bits related to channel 5 and channel 6 in the following
registers are not suitable for DMA1.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved ERRIF6 HTFIF6 FTFIF6 GIF6 ERRIF5 HTFIF5 FTFIF5 GIF5 ERRIF4 HTFIF4 FTFIF4 GIF4
r r r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ERRIF3 HTFIF3 FTFIF3 GIF3 ERRIF2 HTFIF2 FTFIF2 GIF2 ERRIF1 HTFIF1 FTFIF1 GIF1 ERRIF0 HTFIF0 FTFIF0 GIF0
r r r r r r r r r r r r r r r r
169
GD32E10x User Manual
10.5.2. Interrupt flag clear register (DMA_INTC)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved ERRIFC6 HTFIFC6 FTFIFC6 GIFC6 ERRIFC5 HTFIFC5 FTFIFC5 GIFC5 ERRIFC4 HTFIFC4 FTFIFC4 GIFC4
w w w w w w w w w w w w
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ERRIFC3 HTFIFC3 FTFIFC3 GIFC3 ERRIFC2 HTFIC2 FTFIFC2 GIFC2 ERRIFC1 HTFIFC1 FTFIFC1 GIFC1 ERRIFC0 HTFIFC0 FTFIFC0 GIFC0
w w w w w w w w w w w w w w w w
26/22/18/ HTFIFCx Clear bit for half transfer finish flag of channel x (x=0…6)
14/10/6/2 0: No effect
1: Clear half transfer finish flag
25/21/17/ FTFIFCx Clear bit for full transfer finish flag of channel x (x=0…6)
13/9/5/1 0: No effect
1: Clear full transfer finish flag
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved M2M PRIO[1:0] MWIDTH[1:0] PWIDTH[1:0] MNAGA PNAGA CMEN DIR ERRIE HTFIE FTFIE CHEN
rw rw rw rw rw rw rw rw rw rw rw rw
170
GD32E10x User Manual
31:15 Reserved Must be kept at reset value.
171
GD32E10x User Manual
1: Enable circular mode
This bit can not be written when CHEN is ‘1’.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw
172
GD32E10x User Manual
These bits can not be written when CHEN in the DMA_CHxCTL register is ‘1’.
This register indicates how many transfers remain. Once the channel is enabled, it
is read-only, and it decreases after each DMA transfer. If the register is zero, no
transaction can be issued whether the channel is enabled or not. Once the
transmission of the channel is complete, the register can be reloaded automatically
by the previously programmed value if the channel is configured in circular mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PADDR[31:16]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PADDR[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
MADDR[31:16]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MADDR[15:0]
rw
173
GD32E10x User Manual
31:0 MADDR[31:0] Memory base address
These bits can not be written when CHEN in the DMA_CHxCTL register is ‘1’.
When MWIDTH in the DMA_CHxCTL register is 01 (16-bit), the LSB of these bits is
ignored. Access is automatically aligned to a half word address.
When MWIDTH in the DMA_CHxCTL register is 10 (32-bit), the two LSBs of these
bits are ignored. Access is automatically aligned to a word address.
174
GD32E10x User Manual
11. Debug (DBG)
11.1. Overview
The GD32E10x series provide a large variety of debug, trace and test features. They are
implemented with a standard configuration of the ARM CoreSight ® module together with a
daisy chained standard TAP controller. Debug and trace functions are integrated into the ARM
Cortex-M4. The debug system supports serial wire debug (SWD), trace functions and
standard JTAG debug. The debug and trace functions refer to the following documents.
The DBG hold unit helps debugger to debug in power saving mode, TIMER, I2C, WWDGT,
and FWDGT. When corresponding bit is set, it provides a clock in power saving mode or holds
the state for TIMER, I2C, WWDGT or FWDGT.
Debug capabilities can be accessed by a debug tool via Serial Wire (SW - Debug Port) or
JTAG interface (JTAG - Debug Port).
By default, the JTAG interface is active. The sequence for switching from JTAG to SWD is as
following.
The JTAG interface provides a 5-pin standard JTAG, known as JTAG clock (JTCK), JTAG
mode selection (JTMS), JTAG data input (JTDI), JTAG data output (JTDO) and JTAG reset
(NJTRST, active low). The serial wire debug (SWD) provides a 2-pin SW interface, known as
SW data input/output (SWDIO) and SW clock (SWCLK). The two SW pins are multiplexed
with two of five JTAG pins, which are SWDIO multiplexed with JTMS, SWCLK multiplexed
with JTCK. The JTDO is also used as Trace async data output (TRACESWO) when the async
trace is enabled.
175
GD32E10x User Manual
The pin assignment is as following.
PA15 : JTDI
PA14 : JTCK/SWCLK
PA13 : JTMS/SWDIO
PB4 : NJTRST
PB3 : JTDO
By default, 5-pin standard JTAG debug mode is chosen after reset. User can also use JTAG
function without NJTRST pin, then the PB4 can be used to other GPIO functions. (NJTRST
tied to 1 by hardware). If it is switched to SW debug mode, the PA15/PB4/PB3 are released
to other GPIO functions. If JTAG and SW are not used, all 5-pin can be released to other
GPIO functions. Please refer to GPIO pin configuration.
The Cortex-M4 JTAG TAP is connected to a Boundary-Scan (BSD) JTAG TAP. The BSD JTAG
IR is of 5-bit width, while the Cortex-M4 JTAG IR is of 4-bit width. So when JTAG is in IR shift
step, it first shifts 5-bit BYPASS instruction (5’b11111) for BSD JTAG and then shifts normal
4-bit instruction for Cortex-M4 JTAG. Because of the data shift under BSD JTAG BYPASS
mode, adding 1 extra bit to the data chain is needed.
The JTAG-DP and SW-DP registers are in the Power On Reset domain. The system reset
initializes the majority of the Cortex-M4, excluding NVIC and debug logic, (FPB, DWT, and
ITM). The NJTRST reset can reset JTAG TAP controller only. So, debug feature can be
performed under system reset. Such as halt-after-reset, it is that the debugger sets halt under
system reset, and the core halts immediately after the system reset is released.
The Cortex-M4 integrates JEDEC-106 ID code, which is located in ROM table and mapped
to the address of 0xE00FF000_0xE00FFFFF.
When the STB_HOLD bit in DBG control register (DBG_CTL) is set, and entering the standby
mode, the clock of AHB bus and system clock are provided by CK_IRC8M, and the debugger
can debug in standby mode. When exiting the standby mode, a system reset is generated.
When the DSLP_HOLD bit in DBG control register (DBG_CTL) is set, and entering the Deep-
sleep mode, the clock of AHB bus and system clock are provided by CK_IRC8M, and the
176
GD32E10x User Manual
debugger can debug in Deep-sleep mode.
When the SLP_HOLD bit in DBG control register (DBG_CTL) is set, and entering the sleep
mode, the clock of AHB bus for CPU is not closed, and the debugger can debug in sleep
mode.
When the core is halted and the corresponding bit in DBG control register (DBG_CTL) is set,
the following events occur.
For TIMER, the timer counters are stopped and held for debugging.
177
GD32E10x User Manual
11.4. Register definition
ID_CODE[31:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ID_CODE[15:0]
TIMER10 TIMER9_ TIMER8_ TIMER13 TIMER12 TIMER11 TIMER7_ TIMER6_ TIMER5_ TIMER4_ I2C1_HO
Reserved. Reserved
_HOLD HOLD HOLD _HOLD _HOLD _HOLD HOLD HOLD HOLD HOLD LD
rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
I2C0_HO TIMER3_ TIMER2_ TIMER1_ TIMER0_ WWDGT_ FWDGT_ TRACE STB_ DSLP_ SLP_
Reserved TRACE_MODE[1:0] Reserved
LD HOLD HOLD HOLD HOLD HOLD HOLD _IOEN HOLD HOLD HOLD
rw rw rw rw rw rw rw rw rw rw rw rw
178
GD32E10x User Manual
0: no effect
1: hold the TIMER 9 counter for debugging when the core is halted
179
GD32E10x User Manual
halted
181
GD32E10x User Manual
12. Analog-to-digital converter (ADC)
12.1. Overview
The 12-bit ADC is an analog-to-digital converter using the successive approximation method.
The ADC includes 16 external channels and 2 internal channels that can convert analog
signals. The analog watchdog allows the application to detect whether the input voltage
exceeds the user-defined threshold. The analog signals of the channels can be converted by
the ADC in single, continuous, scan or discontinuous mode. The output of the ADC converter
is left-aligned or right-aligned in the 16-bit data register. An on-chip hardware oversampling
mechanism can reduce the related computational burden of MCU to improve performances.
12.2. Characteristics
High performance
– 12-bit, 10-bit, 8-bit or 6-bit configurable resolution
– Self-calibration
– Programmable sampling time
– Data alignment with built-in data coherency
– DMA support
Analog input channels
– 16 external analog inputs
– 1 channel for internal temperature sensor (VSENSE)
– 1 channel for internal reference voltage (VREFINT)
Start-of-conversion can be initiated
– By software
– By hardware triggers
Conversion modes
– Convert a single channel or scan a sequence of channels
– Single mode converts the selected inputs once for per trigger
– Continuous mode converts selected inputs continuously
– Discontinuous mode
– SYNC mode(the device with two or more ADCs)
Analog watchdog
Interrupt generation
– At the end of regular and inserted group conversions
– Analog watchdog event
Oversampling
– 16-bit data register
– Oversampling ratio adjustable from 2x to 256x
– Programmable data shift up to 8-bit
182
GD32E10x User Manual
ADC supply requirements
– 2.4V to 3.6V, and typical power supply voltage is 3.3V.
ADC input range: VREF- ≤VIN ≤VREF+
Figure 12-1. ADC module block diagram shows the ADC block diagram. Table 12-2. ADC
pins definition gives the ADC pin description.
Note: VDDA and VSSA have to be connected to VDD and VSS respectively.
183
GD32E10x User Manual
12.4. Functional description
EXTI11
EXTI15
TIMER1_TRGO
TIMER1_CH0
TIMER0_TRGO
TIMER0_CH3
TIMER1_CH1
TIMER0_CH2
TIMER0_CH1
TIMER0_CH0
… …
EOC
Regular Inserted
channels channels ADC
EOIC Interrupt
Interrupt
Channel Management generator
watchdog
Analog event
watchdog
ADC_IN0
Channel selector
(16 bits x 4) P
ADC_IN15 Over B
SAR ADC 6~12bit
sampler
Regular data registers
VSENSE (16 bits) B
U
VREFINT S
TOVS
CLB
OVSS[3:0]
self calibration
VREF+ DRES[1:0] OVSR[2:0]
VREF- 12, 10, 8, 6 bits
VDDA OVSE
VSSA
The ADC has a foreground calibration feature. During the procedure, the ADC calculates a
calibration factor which is internally applied to the ADC until the next ADC power-off. The
application can not use the ADC until the calibration is completed. The calibration should be
performed before starting A/D conversion. The calibration is initiated by setting the CLB bit to
1. The CLB bit stays at 1 during the calibration sequence. Then it is cleared by hardware as
soon as the calibration is completed.
When the ADC operating conditions change (such as supply power voltage VDDA, positive
reference voltage VREF+, temperature and so on), it is recommended to re-run a calibration
cycle.
The internal analog calibration can be reset by setting the RSTCLB bit in ADC_CTL1 register.
184
GD32E10x User Manual
2. Delay 14 ADCCLK to wait for ADC stability.
3. Set RSTCLB (optional).
4. Set CLB=1.
5. Wait for CLB=0.
The ADC clock (ADCCLK) is provided by the RCU controller, and it is synchronous with the
AHB and APB2 clock. The RCU controller has a dedicated programmable prescaler for the
ADC clock.
The ADC module is enabled or disabled by configuring the ADCON bit in the ADC_CTL1
register. The ADC module will keep in reset state if this bit is 0. For power saving, when this
bit is 0, the analog sub-module will be enter power-down mode. After ADC is enabled, you
need delay tSU time for sampling, the value of tSU please refer to the device datasheet.
The ADC supports 18 multiplexed channels and organizes the conversion results into two
groups, a regular channel group and an inserted channel group.
This mode can be used in both regular and inserted channel groups. In the single conversion
mode, the ADC performs conversion on the channel specified in the RSQ0[4:0] bits in
ADC_RSQ2 or the channel specified in the ISQ3[4:0] bits in ADC_ISQ. When the ADCON is
1, the ADC samples and converts a single channel, once the corresponding software trigger
or external trigger is active.
185
GD32E10x User Manual
Figure 12-2. Single conversion mode
CH2 CH2 CH2 CH2 CH2
Sample
Regular
trigger
Convert
EOC
After the conversion of a single regular channel, the conversion data will be stored in the
ADC_RDATA register, the EOC will be set. An interrupt will be generated if the EOCIE bit is
set.
After the conversion of a single inserted channel, the conversion data will be stored in the
ADC_IDATA0 register, the EOC and EOIC will be set. An interrupt will be generated if the
EOCIE or EOICIE bit is set.
1. Make sure the DISRC, SM bits in the ADC_CTL0 register and CTN bit in the ADC_CTL1
register are reset.
2. Configure the RSQ0 with the analog channel number
3. Configure the ADC_SAMPTx register
4. Configure the ETERC and ETSRC bits in the ADC_CTL1 register if It is needed.
5. Set the SWRCST bit, or generate an external trigger for the regular group
6. Wait for the EOC flag to be set
7. Read the converted result from the ADC_RDATA register
8. Clear the EOC flag by writing 0
1. Make sure the DISIC, SM bits in the ADC_CTL0 register are reset
2. Configure the ISQ3 with the analog channel number
3. Configure the ADC_SAMPTx register
4. Configure ETEIC and ETSIC bits in the ADC_CTL1 register if it is needed.
5. Set the SWICST bit, or generate an external trigger for the inserted group
6. Wait for the EOC/EOIC flags to be set
7. Read the converted result from the ADC_IDATA0 register
8. Clear the EOC/EOIC flags by writing 0
This mode can be used in the regular channel group. The continuous conversion mode will
be enabled when the CTN bit in the ADC_CTL1 register is set. In this mode, the ADC performs
conversion on the channel specified in the RSQ0[4:0]. When the ADCON has is 1, the ADC
samples and converts specified a channel, once the corresponding software trigger or
external trigger is active. The conversion data will be stored in the ADC_RDATA register.
186
GD32E10x User Manual
Figure 12-3. Continuous conversion mode
CH2 CH2 CH2 CH2 CH2 CH2 CH2
Sample
Regular
trigger
Convert
EOC
The scan conversion mode will be enabled when the SM bit in the ADC_CTL0 register is set.
In this mode, the ADC performs conversion on the channels with a specific sequence
specified in the ADC_RSQ0~ADC_RSQ2 registers or ADC_ISQ register. When the ADCON
is 1, the ADC samples and converts specified channels one by one in the regular or inserted
group till the end of the regular or inserted group, once the corresponding software trigger or
external trigger is active. The conversion data will be stored in the ADC_RDATA or
ADC_IDATAx register. After conversion of the regular or inserted channel group, the EOC or
EOIC will be set. An interrupt will be generated if the EOCIE or EOICIE bit is set. The DMA
bit in ADC_CTL1 register must be set when the regular channel group works in scan mode.
After conversion of a regular channel group, the conversion can be restarted automatically if
the CTN bit in the ADC_CTL1 register is set.
187
GD32E10x User Manual
Figure 12-4. Scan conversion mode, continuous disable
CH2 CH1 CH5 CH7 CH11 CH16 CH12 CH17 CH2 CH1 ···
Regular
trigger
EOC
1. Set the SM bit in the ADC_CTL0 register and the DMA bit in the ADC_CTL1 register
2. Configure the ADC_RSQx and ADC_SAMPTx registers
3. Configure the ETERC and ETSRC bits in the ADC_CTL1 register if it is needed.
4. Prepare the DMA module to transfer data from the ADC_RDATA.
5. Set the SWRCST bit, or generate an external trigger for the regular group
6. Wait for the EOC flag to be set
7. Clear the EOC flag by writing 0
Regular
trigger
EOC
Discontinuous mode
For regular channel group, the discontinuous conversion mode will be enabled when the
DISRC bit in the ADC_CTL0 register is set. In this mode, the ADC performs a short sequence
of n conversions (n<=8) which is part of the sequence of conversions selected in the
188
GD32E10x User Manual
ADC_RSQ0~ADC_RSQ2 registers. The value of n is defined by the DISNUM[2:0] bits in the
ADC_CTL0 register. When the corresponding software trigger or external trigger is active, the
ADC samples and converts the next n channels selected in the ADC_RSQ0~ADC_RSQ2
registers until all the channels in the regular sequence are done. The EOC will be set after
every circle of the regular channel group. An interrupt will be generated if the EOCIE bit is set.
For inserted channel group, the discontinuous conversion mode will be enabled when the
DISIC bit in the ADC_CTL0 register is set. In this mode, the ADC performs one conversion
which is part of the sequence of conversions selected in the ADC_ISQ register. When the
corresponding software trigger or external trigger is active, the ADC samples and converts
the next channel selected in the ADC_ISQ register until all the channels in the inserted
sequence are done. The EOIC will be set after every circle of the inserted channel group. An
interrupt will be generated if the EOICIE bit is set.
The regular and inserted groups cannot both work in discontinuous conversion mode. Only
one group conversion can be set in discontinuous conversion mode at a time.
Regular
trigger
EOC
1. Set the DISRC bit in the ADC_CTL0 register and the DMA bit in the ADC_CTL1 register
2. Configure the DISNUM[2:0] bits in the ADC_CTL0 register
3. Configure the ADC_RSQx and ADC_SAMPTx registers
4. Configure the ETERC and ETSRC bits in the ADC_CTL1 register if it is needed
5. Prepare the DMA module to transfer data from the ADC_RDATA (refer to the spec of the
DMA module).
6. Set the SWRCST bit, or generate an external trigger for the regular group
7. Repeat step 6 if it is needed.
8. Wait for the EOC flag to be set
9. Clear the EOC flag by writing 0
189
GD32E10x User Manual
3. Configure the ETEIC and ETSIC bits in the ADC_CTL1 register if it is needed
4. Set the SWICST bit, or generate an external trigger for the inserted group
5. Repeat step 4 if it is needed
6. Wait for the EOC/EOIC flags to be set
7. Read the converted result from the ADC_IDATAx register
8. Clear the EOC/EOIC flag by writing 0
Auto-insertion
The inserted group channels are automatically converted after the regular group channels
when the ICA bit in ADC_CTL0 register is set. In this mode, the external trigger on inserted
channels cannot be enabled. A sequence of up to 20 conversions programmed in the
ADC_RSQ0~ADC_RSQ2 and ADC_ISQ registers can be used to convert in this mode. In
addition to the ICA bit, if the CNT bit is also set, regular channels are continuously converted
after inserted channels.
Inserted
CH15
group
Sample
EOC
Convert
EOIC
The auto insertion mode cannot be enabled when the discontinuous conversion mode is set.
Triggered insertion
If the ICA bit is cleared, the triggered insertion occurs if a software or external trigger occurs
during the regular channel group conversion. In this situation, the ADC aborts the current
conversion and starts the conversion of inserted channel group. After the inserted channel
group is done, the regular channel group conversion will resume from the last aborted
conversion.
Inserted
CH15 CH15
group
Inserted
trigger
Sample
EOC
Convert
EOIC
190
GD32E10x User Manual
12.4.7. Analog watchdog
The analog watchdog is enabled when the RWDEN and IWDEN bits in the ADC_CTL0
register are set for regular and inserted channel groups respectively. When the analog voltage
converted by the ADC is below the low threshold or above the high threshold, the WDE bit in
ADC_STAT register will be set. An interrupt will be generated if the WDEIE bit is set. The
ADC_WDHT and ADC_WDLT registers are used to specify the high and low threshold. The
comparison is done before the alignment, so the threshold value is independent of the
alignment, which is specified by the DAL bit in the ADC_CTL1 register. One or more channels,
which are selected by the RWDEN, IWDEN, WDSC and WDCHSEL[4:0] bits in ADC_CTL0
register, can be monitored by the analog watchdog.
The alignment of data stored after conversion can be specified by DAL bit in the ADC_CTL1
register.
After being decreased by the user-defined offset written in the ADC_IOFFx registers, the
inserted group data value may be a negative value. The sign value is extended.
DAL=0
DAL=1
6-bit resolution data alignment is different from 12-bit/10-bit/8-bit resolution data alignment,
shown as Figure 12-10. 6-bit data alignment.
191
GD32E10x User Manual
Figure 12-10. 6-bit data alignment
Regular group data
0 0 0 0 0 0 0 0 0 0 D5 D4 D3 D2 D1 D0
DAL=0
DAL=1
The number of ADCCLK cycles which is used to sample the input voltage can be specified
by the SPTn[2:0] bits in the ADC_SAMPT0 and ADC_SAMPT1 registers. Different sampling
time can be specified for each channel. For 12-bit resolution, the total conversion time is
“sampling time + 12.5” ADCCLK cycles.
Example:
ADCCLK = 30MHz and sampling time is 1.5 cycles, the total conversion time is “1.5+12.5”
ADCCLK cycles, that means 0.467us.
The conversion of regular or inserted group can be triggered by rising edge of external trigger
inputs. The external trigger source of regular channel group is controlled by the ETSRC[2:0]
bits in the ADC_CTL1 register, while the external trigger source of inserted channel group is
controlled by the ETSIC[2:0] bits in the ADC_CTL1 register.
ETSRC[2:0] and ETSIC[2:0] control bits are used to specify which out of 8 possible events
can trigger conversion for the regular and inserted groups.
Table 12-3. External trigger for regular channels for ADC0 and ADC1
ETSRC[2:0] Trigger source Trigger type
000 TIMER0_CH0
001 TIMER0_CH1
010 TIMER0_CH2
Internal on-chip signal
011 TIMER1_CH1
100 TIMER2_TRGO
101 TIMER3_CH3
External signal/ internal on-chip
110 EXTI11/TIMER7_TRGO
signal
192
GD32E10x User Manual
ETSRC[2:0] Trigger source Trigger type
111 SWRCST Software trigger
Table 12-4. External trigger for inserted channels for ADC0 and ADC1
ETSIC[2:0] Trigger source Trigger Type
000 TIMER0_TRGO
001 TIMER0_CH3
010 TIMER1_TRGO
Internal on-chip signal
011 TIMER1_CH0
100 TIMER2_CH3
101 TIMER3_TRGO
External signal/ internal on-chip
110 EXTI15/TIMER7_CH3
signal
111 SWICST Software trigger
The DMA request, which is enabled by the DMA bit in ADC_CTL1 register, is used to transfer
data of regular group for conversion of more than one channel. The ADC generates a DMA
request at the end of conversion of a regular channel. When this request is received, the DMA
will transfer the converted data from the ADC_RDATA register to the destination which is
specified by the user.
When the TSVREN bit in ADC_CTL1 register is set, the temperature sensor channel
(ADC0_CH16) and VREFINT channel (ADC0_CH17) are enabled. The temperature sensor can
be used to measure the ambient temperature of the device. The sensor output voltage can
be converted into a digital value by ADC. The sampling time for the temperature sensor is
recommended to be set to at least 17.1 µs. When this sensor is not in use, it can be set in
power down mode by resetting the TSVREN bit.
The output voltage of the temperature sensor changes linearly with temperature. Because
there is an offset, which is up to 45 °C and varies from chip to chip due to process variation,
the internal temperature sensor is more suitable for applications that detect temperature
variations than absolute temperature. When it is used to detect accurate temperature, an
external temperature sensor part should be used to calibrate the offset error.
The internal reference voltage (VREFINT) provides a stable (bandgap) voltage output for the
ADC and comparators. VREFINT is internally connected to the ADC0_CH17 input channel.
It is possible to obtain faster conversion time (tADC) by reducing the ADC resolution.
193
GD32E10x User Manual
The resolution can be configured to be either 12, 10, 8, or 6 bits by programming the
DRES[1:0] bits in the ADC_OVSAMPCTL register. Lower resolution allows faster conversion
time for applications where high data precision is not required. The DRES[1:0] bits must only
be changed when the ADCON bit is reset. Lower resolution reduces the conversion time
needed for the successive approximation steps as shown in Table 12-5. tCONV timings
depending on resolution.
The on-chip hardware oversampling circuit performs data preprocessing to offload the CPU.
It can handle multiple conversions and average them into a single data with increased data
width up to 16-bit. It provides a result with the following form, where N and M can be adjusted,
and Dout(n) is the n-th output digital signal of the ADC:
1
Result= * ∑N-1
n=0 Dout (n) (12-1)
M
The on-chip hardware oversampling circuit performs the following functions: summing and bit
right shifting. The oversampling ratio N is defined by the OVSR[2:0] bits in the
ADC_OVSAMPCTL register. It can range from 2x to 256x. The division coefficient M means
bit right shifting up to 8 bits. It is configured through the OVSS[3:0] bits in the
ADC_OVSAMPCTL register.
The summation unit can yield a result up to 20 bits (256 x 12-bit), which is first shifted right.
The upper bits of the result are then truncated, keeping only the 16 least significant bits
rounded to the nearest value using the least significant bits left apart by the shifting, before
being finally transferred into the data register.
194
GD32E10x User Manual
Figure 12-11. 20-bit to 16-bit result truncation
19 15 11 7 3 0
Shifting
15 11 7 3 0
Truncation and
rounding
Note: If the intermediate result after the shifting exceeds 16 bits, the upper bits of the result
are simply truncated.
Figure 12-12. A numerical example with 5-bit shifting and rounding shows a numerical
example of the processing, from a raw 20-bit accumulated data to the final 16-bit result.
19 15 11 7 3 0
15 11 7 3 0
Table 12-6. Maximum output results for N and M combinations (grayed values indicate
truncation below gives the data format for the various N and M combinations, and the raw
conversion data equals 0xFFF.
Table 12-6. Maximum output results for N and M combinations (grayed values indicate
truncation)
1-bit 2-bit 3-bit 4-bit 5-bit 6-bit 7-bit 8-bit
Oversa Max No-shift
shift shift shift shift shift shift shift shift
mpling Raw OVSS=
OVSS= OVSS= OVSS= OVSS= OVSS= OVSS= OVSS= OVSS=
ratio data 0000
0001 0010 0011 0100 0101 0110 0111 1000
195
GD32E10x User Manual
2x 0x1FFE 0x1FFE 0x0FFF 0x07FF 0x03FF 0x01FF 0x00FF 0x007F 0x003F 0x001F
4x 0x3FFC 0x3FFC 0x1FFE 0x0FFF 0x07FF 0x03FF 0x01FF 0x00FF 0x007F 0x003F
8x 0x7FF8 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x07FF 0x03FF 0x01FF 0x00FF 0x007F
16x 0xFFF0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x07FF 0x03FF 0x01FF 0x00FF
32x 0x1FFE0 0xFFE0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x07FF 0x03FF 0x01FF
64x 0x3FFC0 0xFFC0 0xFFE0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x07FF 0x03FF
128x 0x7FF80 0xFF80 0xFFC0 0xFFE0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF 0x07FF
256x 0xFFF00 0xFF00 0xFF80 0xFFC0 0xFFE0 0xFFF0 0x7FF8 0x3FFC 0x1FFE 0x0FFF
When compared to standard conversion mode, the conversion timings of oversampling mode
do not change, and the sampling time is maintained the same as that of standard conversion
mode during the whole oversampling sequence. New data are provided every N conversion,
with an equivalent delay equal to:
In ADC sync mode, the conversion is alternately or simultaneously triggered by ADC0 (master)
and ADC1 (slave), according to the mode selected by the SYNCM[3:0] bits in ADC0_CTL0
register.
In sync mode, when configure the conversion which is triggered by an external event, the
slave ADC must be configured to be triggered by the software in order to avoid unwanted
conversion started by false triggers. However, the external trigger must be enabled for ADC
master and ADC slave.
The following modes can be configured:
– Free mode
– Regular parallel mode
– Inserted parallel mode
– Follow-up fast mode
– Follow-up slow mode
– Trigger rotation mode
– Inserted parallel mode + regular parallel mode
– Regular parallel mode + trigger rotation mode
– Inserted parallel mode + follow-up fast mode
– Inserted parallel mode + follow-up slow mode
In ADC sync mode, the DMA bit must be set even if it is not used; the converted data of ADC
slave can be read from the master data register.
196
GD32E10x User Manual
Figure 12-13. ADC sync block diagram
ADC1
(slave)
A
ADC_IN0 P
Regular Regular data registers B
ADC_IN1 GPIO channels (16 bits x 4)
··
·
B
ADC_IN15 U
Inserted Inserted data registers S
VSENSE
channels (16 bits)
VREFINT
Sync mode
EXTI11 control
Regular
trigger mux
ADC0
(master)
EXTI15
Inserted
trigger mux
In this mode, the ADC synchronization is bypassed, and each ADC works freely.
This mode converts the regular channel simultaneously. The source of external trigger comes
from the regular group MUX of ADC0 (selected by the ETSRC[2:0] bits in the ADC_CTL1
register). A simultaneous trigger is provided to ADC1.
At the end of conversion on ADC0 or ADC1 an EOC interrupt is generated (if enabled on one
of the two ADC interfaces). The behavior of regular parallel mode shows in the Figure 12-14.
Regular parallel mode on 16 channels.
A 32-bit DMA is used, which transfers ADC_RDATA 32-bit register (the ADC_RDATA 32-bit
register contains the ADC1 converted data in the upper half-word and the ADC0 converted
data in the lower half-word) to SRAM.
Note:
1. Do not convert the same channel on the two ADCs (no overlapping of sampling times for
the two ADCs when converting the same channel).
2. In parallel mode, exactly the same sampling time should be configured for the two channels
197
GD32E10x User Manual
which will be sampled simultaneously by ACD0 and ADC1.
ADC1 CH4 CH5 CH6 CH7 ··· CH2 CH3 CH4 CH5 ···
Regular
Sample
trigger
EOC
Convert
This mode converts the inserted channel simultaneously. The source of external trigger
comes from the inserted group MUX of ADC0 (selected by the ETSIC[2:0] bits in the
ADC_CTL1 register). A simultaneous trigger is provided to ADC1.
At the end of conversion on ADC0 or ADC1, an EOIC interrupt is generated (if enabled on
one of the two ADC interfaces). ADC0/ADC1 inserted channels are all converted, and the
converted data is stored in the ADC_IDATAx registers of each ADC interface. The behavior
of inserted parallel mode shows in the Figure 12-15. Inserted parallel mode on 4 channels.
Note:
1. Do not convert the same channel on the two ADCs (no overlapping of sampling times for
the two ADCs when converting the same channel).
2. In parallel mode, exactly the same sampling time should be configured for the two channels
which will be sampled simultaneously by ADC0 and ADC1.
Inserted Sample
trigger
EOIC Convert
This mode can run on the regular channel group (usually one channel). The source of external
trigger comes from the regular channel MUX of ADC0 (selected by the ETSRC[2:0] bits in the
ADC_CTL1 register). When the trigger occurs, ADC1 runs immediately and ADC0 runs after
7 ADC clock cycles.
If the continuous mode is enabled for both ADC0 and ADC1, the selected regular channels
of both ADCs are continuously converted. The behavior of follow-up fast mode shows in the
198
GD32E10x User Manual
Figure 12-16. Follow-up fast mode on 1 channel in continuous conversion mode.
After an EOC interrupt of ADC0 is generated (in case the EOCIE bit is set), we can use a 32-
bit DMA, which transfers the ADC_RDATA 32-bit register to SRAM. ADC_RDATA register
contains the ADC1 converted data in the upper half word and the ADC0 converted data in the
lower half word.
Note: The maximum sampling time allowed is <7 ADCCLK cycles to avoid the overlapping
between ADC0 and ADC1 sampling phases in the event that they convert the same channel.
ADC1
CH1 CH1 CH1 CH1 ···
Regular
trigger Sample
EOC(ADC0)
Convert
EOC(ADC1 )
This mode can run on the regular channel group (usually one channel). The source of external
trigger comes from the regular channel MUX of ADC0(selected by the ETSRC[2:0] bits in the
ADC_CTL1 register).When the trigger occurs, ADC1 runs immediately, ADC0 runs after 14
ADC clock cycles, after the second 14 ADC clock cycles the ADC1 runs again.
Continuous mode can’t be used in this mode, because it continuously converts the regular
channels. The behavior of follow-up slow mode shows in the Figure 12-17. Follow-up slow
mode on 1 channel.
After an EOC interrupt of ADC0 is generated (if enabled through the EOCIE bit), we can use
a 32-bit DMA, which transfers the ADC_RDATA 32-bit register to SRAM . ADC_RDATA
register contains the ADC1 converted data in the upper half-word and the ADC0 converted
data in the lower half-word.
Note:
1. The maximum sampling time allowed is <14 ADCCLK cycles to avoid the overlapping
between ADC0 and ADC1 sampling phases in the event that they convert the same channel.
2. For both the fast and follow-up slow mode, we must ensure that no external trigger for
inserted channel occurs.
199
GD32E10x User Manual
Figure 12-17. Follow-up slow mode on 1 channel
14 ADCCLK 14 ADCCLK
cycles cycles
ADC1
CH1 CH1 CH1 CH1 ···
Regular
trigger Sample
EOC(ADC0 )
Convert
EOC(ADC1)
This mode can run on the inserted channel group. The source of external trigger comes from
the inserted channel MUX of ADC0 (selected by the ETSIC[2:0] bits in the ADC_CTL1
register).
When the first trigger occurs, all the inserted channels of ADC0 are converted. When the
second trigger occurs, all the inserted channels of ADC1 are converted. The behavior of
trigger rotation mode shows in the Figure 12-18. Trigger rotation: inserted channel group.
If the EOIC interrupt of ADC0 or ADC1 is enabled, when all the channels of ADC0 or ADC1
have been converted, the corresponding interrupt occurs.
If another external trigger occurs after all inserted group channels have been converted, the
trigger rotation process restarts converting ADC0 inserted group channels.
Convert
EOIC(ADC0)
EOIC(ADC1)
If the discontinuous mode is enabled for both ADC0 and ADC1, when the first trigger occurs,
the first inserted channel in ADC0 is converted. When the second trigger occurs, the first
inserted channel in ADC1 is converted. Then the second channel in ADC0, the second
channel in ADC1, and so on.
The behavior of trigger rotation discontinuous mode shows in the Figure 12-19. Trigger
rotation: inserted channels in discontinuous mode.
If the EOIC interrupt of ADC0 or ADC1 is enabled. When all the channels of ADC0 or ADC1
200
GD32E10x User Manual
have been converted, the corresponding interrupt occurs.
If another external trigger occurs after all inserted group channels have been converted then
the trigger rotation process restarts.
Sample
Inserted
trigger
Convert
EOIC(ADC0)
EOIC(ADC1)
In the free mode, the conversion of regular group can be interrupted by the conversion of
inserted group. In the sync mode, it is also possible to interrupt parallel conversion of a regular
group to insert parallel conversion of an inserted group.
Note: In combined regular parallel + inserted parallel mode, the sampling time for the two
ADCs should be configured the same.
It is possible to interrupt regular group parallel conversion to start trigger rotation conversion
of an inserted group. The behavior of an alternate trigger interrupts a regular parallel
conversion shows in the Figure 12-20. Regular parallel & trigger rotation mode.
When the inserted event occurs, the inserted rotation conversion will immediately start. If
regular conversion is already running, in order to ensure synchronization after the inserted
conversion, the regular conversions of both (master/slave) ADCs are stopped and resumed
synchronously at the end of the inserted conversion.
Note: In combined regular parallel + trigger rotation mode, the sampling time for the two ADCs
should be configured the same.
Inserted
Convert
trigger
201
GD32E10x User Manual
If one inserted trigger occurs during an inserted conversion that has interrupted a regular
conversion, it will be ignored. Figure 12-21. Trigger occurs during inserted conversion
shows the case (the second trigger is ignored).
It is possible to interrupt a follow-up conversion (both fast and slow) by an inserted event.
When the inserted trigger occurs, the follow-up conversion is interrupted and the inserted
conversion starts, at the end of the inserted sequence the follow-up conversion is resumed.
Figure 12-22 Follow-up single channel with inserted sequence CH1, CH2 shows the
behavior of this mode.
Figure 12-22 Follow-up single channel with inserted sequence CH1, CH2
ADC0
regular CH0 CH0 CH0
Inserted
trigger
The interrupts of ADC0 and ADC1 are mapped into the same interrupt vector IRQ18.
202
GD32E10x User Manual
12.7. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
203
GD32E10x User Manual
Cleared by software writing 0 to it or by reading the ADC_RDATA register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw
204
GD32E10x User Manual
1001: Trigger rotation mode only
Note: These bits are reserved in ADC1. In sync mode, the change of configuration
will cause unpredictable consequences. We must disable sync mode before any
configuration change.
8 SM Scan mode
0: scan mode disable
1: scan mode enable
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ETEIC ETSIC[2:0] DAL Reserved. DMA Reserved RSTCLB CLB CTN ADCON
rw rw rw rw rw rw rw rw
206
GD32E10x User Manual
20 ETERC External trigger enable for regular channel
0: External trigger for regular channel disable
1: External trigger for regular channel enable
207
GD32E10x User Manual
1: Calibration register initialization starts
0 ADCON ADC ON. The ADC will be waked up when this bit is changed from low to high and
take a stabilization time. When this bit is high and “1” is written to it with other bits
of this register unchanged, the conversion will start.
0: ADC disable and power down
1: ADC enable
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
208
GD32E10x User Manual
001: 7.5 cycles
010: 13.5 cycles
011: 28.5 cycles
100: 41.5 cycles
101: 55.5 cycles
110: 71.5 cycles
111: 239.5 cycles
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
209
GD32E10x User Manual
101: 55.5 cycles
110: 71.5 cycles
111: 239.5 cycles
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved IOFF[11:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved WDHT[11:0]
rw
210
GD32E10x User Manual
12.7.8. Watchdog low threshold register (ADC_WDLT)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved WDLT[11:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
211
GD32E10x User Manual
12.7.10. Regular sequence register 1 (ADC_RSQ1)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
212
GD32E10x User Manual
24:20 RSQ4[4:0] Refer to RSQ0[4:0] description
4:0 RSQ0[4:0] The channel number (0..17) is written to these bits to select a channel as the nth
conversion in the regular channel group.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
4:0 ISQ0[4:0] The channel number (0..17) is written to these bits to select a channel as the nth
conversion in the inserted channel group.
Different from the regular conversion sequence, the inserted channels are
converted starting from (4 - IL[1:0] - 1), if IL[1:0] length is less than 4.
IL Insert channel order
3 ISQ0 >> ISQ1 >> ISQ2 >> ISQ3
2 ISQ1 >> ISQ2 >> ISQ3
1 ISQ2 >> ISQ3
0 ISQ3
213
GD32E10x User Manual
12.7.13. Inserted data register x (ADC_IDATAx) (x= 0..3)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IDATAn[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ADC1RDTR[15:0]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RDATA[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw
215
GD32E10x User Manual
000: 2x
001: 4x
010: 8x
011: 16x
100: 32x
101: 64x
110: 128x
111: 256x
Note: Software is allowed to write this bit only when ADCON =0 (which ensures that
no conversion is ongoing).
216
GD32E10x User Manual
13. Digital-to-analog converter (DAC)
13.1. Overview
The Digital-to-analog converter converts 12-bit digital data to a voltage on the external pins.
The digital data can be configured in 8-bit or 12-bit mode, left-aligned or right-aligned mode.
DMA can be used to update the digital data on external triggers. The output voltage can be
optionally buffered for higher drive capability.
13.2. Characteristics
Figure 13-1. DAC block diagram shows the block diagram of DAC and Table 13-1. DAC
217
GD32E10x User Manual
pins gives the pin description.
DTSELx[2:0]
DMA r equestx
DWBWx[3:0]
DDMA ENx
DBOFFx
DWMx[1:0]
DTENx
TIMER5_TRGO
TIMER2_TRGO
Trigger selectorx
TIMER6_TRGO
TIMER4_TRGO
TIMER1_TRGO
TIMER3_TRGO
EXTI_9
Buff
SWTRx
MUX2X1
DAC_OUTx
Control DOx DAC
logic 12-bit
DHx 12-bit
12-bit
VSSA
VDDA
VREF+
The GPIO pins (PA4 for DAC0, PA5 for DAC1) should be configured to analog mode before
enabling the DAC module.
The DACs can be powered on by setting the DENx bit in the DAC_CTL register. tWAKEUP time
is needed to start up the analog DAC submodule.
For reducing output impedance and driving external loads without an external operational
218
GD32E10x User Manual
amplifier, an output buffer is integrated inside each DAC module.
The output buffer, which is turned on by default, can be turned off by setting the DBOFFx bit
in the DAC_CTL register.
The 12-bit DAC holding data (DACx_DH) can be configured by writing any one of these
registers (DACx_R12DH, DACx_L12DH or DACx_R8DH). When the data is loaded into
DACx_R8DH register, only the MSB 8 bits are configurable, the LSB 4 bits are forced to
4’b0000.
The DAC external trigger is enabled by setting the DTENx bit in the DAC_CTL register. The
DAC external triggers are selected by the DTSELx bits in the DAC_CTL register.
The TIMERx_TRGO signals are generated from the TIMER, and the software trigger can be
generated by setting the SWTRx bit in the DAC_SWT register.
If the external trigger is enabled by setting the DTENx bit in DAC_CTL register, the DAC
holding data is transferred to the DAC output data (DACx_DO) register when the selected
trigger event happened. When the external trigger is disabled, the transfer is performed
automatically.
When the DAC holding data (DACx_DH) is loaded into the DACx_DO register, after the time
tSETTLING, the analog output is valid. The value of tSETTLING is related to the power supply voltage
and the analog output load.
There are two methods to add noise wave to the DAC output signal: LFSR noise wave mode
and Triangle wave mode. The noise wave mode can be selected by the DWMx bits in the
219
GD32E10x User Manual
DAC_CTL register. The amplitude of the noise can be configured by the DAC noise wave bit
width (DWBWx) bits in the DAC_CTL register.
LFSR noise wave mode: there is a Linear Feedback Shift Register (LFSR) in the DAC control
logic, it controls the LFSR noise signal which is added to the DACx_DH value. When the
configured DAC noise wave bit width is less than 12, the noise signal equals to the LSB
DWBWx bits of the LFSR register, while the MSB bits are masked.
XOR
X12 X6 X4 X X0
11 10 9 8 7 6 5 4 3 2 1 0
12
NOR
Triangle noise mode: in this mode, a triangle signal is added to the DACx_DH value. The
minimum value of the triangle signal is 0, while the maximum value of the triangle signal is (2
<< DWBWx) - 1.
(2<<DWBWx)-1 +
DACx_DH value
DACx_DH value
The analog output voltage on the DAC pin is determined by the following equation:
The digital input is linearly converted to analog output voltage whose range is 0 to VREF+.
220
GD32E10x User Manual
13.3.8. DMA request
When the external trigger is enabled, the DMA request can be enabled by setting the
DDMAENx bit of the DAC_CTL register. A DMA request will be generated by DAC when an
external hardware trigger (not a software trigger) occurs.
In order to maximize the utilization of the bus bandwidth, we can make the two DACs work at
the same time using concurrent mode. In this mode, the data transfer (DACx_DH to
DACx_DO) of two DACs is performing at the same time.
There are three concurrent registers that can be used to load the DACx_DH value:
DACC_R8DH, DACC_R12DH and DACC_L12DH. One of the three registers needs to be
configured for driving two DACs at the same time.
When external trigger is enabled, DTENx bit of two DACs must be set both. DTSEL0 and
DTSEL1 bits should be configured with the same value.
When DMA is enabled, only one of the DDMAENx bit should be set.
The noise mode and noise bit width can be configured either the same or different, depending
on the application scenario.
221
GD32E10x User Manual
13.4. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw
222
GD32E10x User Manual
00: wave disabled
01: LFSR noise mode
1x: Triangle noise mode
223
GD32E10x User Manual
1001: The bit width of the wave signal is 10
1010: The bit width of the wave signal is 11
≥1011: The bit width of the wave signal is 12
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
224
GD32E10x User Manual
w w
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DAC0_DH[11:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DAC0_DH[11:0] Reserved
rw
225
GD32E10x User Manual
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DAC0_DH[7:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DAC1_DH[11:0]
rw
226
GD32E10x User Manual
These bits specify the data that is to be converted by DAC1.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DAC1_DH[11:0] Reserved
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DAC1_DH[7:0]
rw
227
GD32E10x User Manual
13.4.9. DAC concurrent mode 12-bit right-aligned data holding register
(DACC_R12DH)
Address offset: 0x20
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved DAC1_DH[11:0]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DAC0_DH[11:0]
rw
(DACC_L12DH)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
DAC1_DH[11:0] Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DAC0_DH[11:0] Reserved
rw
228
GD32E10x User Manual
19:16 Reserved Must be kept at reset value.
(DACC_R8DH)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DAC1_DH[7:0] DAC0_DH[7:0]
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DAC0_DO[11:0]
229
GD32E10x User Manual
Bits Fields Descriptions
31:12 Reserved Must be kept at reset value.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DAC1_DO[11:0]
230
GD32E10x User Manual
14. Watchdog timer (WDGT)
The watchdog timer (WDGT) is a hardware timing circuitry that can be used to detect system
failures due to software malfunctions. There are two watchdog timer peripherals in the chip:
free watchdog timer (FWDGT) and window watchdog timer (WWDGT). They offer a
combination of a high safety level, flexibility of use and high timing accuracy. Both watchdog
timers are offered to resolve malfunctions of software.
The watchdog timer will generate a reset (or an interrupt in window watchdog timer) when the
internal counter reaches a given value. The watchdog timer counter can be stopped while the
processor is in the debug mode.
14.1.1. Overview
The free watchdog timer (FWDGT) has free clock source (IRC40K). Thereupon the FWDGT
can operate even if the main clock fails. It’s suitable for the situation that requires an
independent environment and lower timing accuracy.
The free watchdog timer causes a reset when the internal down counter reaches 0. The
register write protection function in free watchdog can be enabled to prevent it from changing
the configuration unexpectedly.
14.1.2. Characteristics
The free watchdog consists of an 8-stage prescaler and a 12-bit down counter. Figure 14-1.
Free watchdog block diagram shows the functional block of the free watchdog module.
231
GD32E10x User Manual
Figure 14-1. Free watchdog block diagram
Status: PUD
Reload
The free watchdog is enabled by writing the value (0xCCCC) to the control register
(FWDGT_CTL), then the counter starts counting down. When the counter reaches the value
(0x000), there will be a reset.
The counter can be reloaded by writing the value (0xAAAA) to the FWDGT_CTL register at
any time. The reload value comes from the FWDGT_RLD register. The software can prevent
the watchdog reset by reloading the counter before the counter reaches the value (0x000).
The free watchdog can automatically start when power on if the hardware free watchdog bit
in the device option bytes is set. To avoid a reset, the software should reload the counter
before the counter reaches 0x000.
The FWDGT_PSC register and the FWDGT_RLD register are write protected. Before writing
these registers, the software should write the value (0x5555) to the FWDGT_CTL register.
These registers will be protected again by writing any other value to the FWDGT_CTL register.
When an update operation of the prescaler register (FWDGT_PSC) or the reload value
register (FWDGT_RLD) is ongoing, the status bits in the FWDGT_STAT register are set.
If the FWDGT_HOLD bit in DBG module is cleared, the FWDGT continues to work even the
Cortex™-M4 core halted (Debug mode). The FWDGT stops in Debug mode if the
FWDGT_HOLD bit is set.
Note: When after the execution of watchdog reload operation, if the MCU needs enter the
deepsleep/standby mode immediately, (more than 3) IRC40K clock intervals must be inserted
in the middle of reload and deepsleep/standby mode commands by software setting.
233
GD32E10x User Manual
14.1.4. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CMD[15:0]
15:0 CMD[15:0] Write only. Several different functions are realized by writing these bits with different
values.
0x5555: Disable the FWDGT_PSC and FWDGT_RLD write protection
0xCCCC: Start the free watchdog counter. When the counter reduces to 0, the free
watchdog generates a reset.
0xAAAA: Reload the counter
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved PSC[2:0]
rw
2:0 PSC[2:0] Free watchdog timer prescaler selection. Write 0x5555 to the FWDGT_CTL register
234
GD32E10x User Manual
before writing these bits. During a write operation to this register, the PUD bit in the
FWDGT_STAT register is set and the value read from this register is invalid.
000: 1/4
001: 1/8
010: 1/16
011: 1/32
100: 1/64
101: 1/128
110: 1/256
111: 1/256
If several prescaler values are used by the application, it is mandatory to wait until
PUD bit has been reset before changing the prescaler value. If the prescaler value
has been updated, it is not necessary to wait until PUD has been reset before
continuing code execution (Before entering low-power mode, it is necessary to wait
until PUD is reset).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
11:0 RLD[11:0] Free watchdog timer counter reload value. Write 0xAAAA to the FWDGT_CTL
register will reload the FWDGT counter with the RLD value.
These bits are write protected. Write 0x5555 to the FWDGT_CTL register before
writing these bits. During a write operation to this register, the RUD bit in the
FWDGT_STAT register is set and the value read from this register is invalid.
If several reload values are used by the application, it is mandatory to wait until RUD
bit has been reset before changing the reload value. If the reload value has been
updated, it is not necessary to wait until RUD has been reset before continuing code
execution (Before entering low-power mode, it is necessary to wait until PUD is
reset).
235
GD32E10x User Manual
Status register (FWDGT_STAT)
Address offset: 0x0C
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
r r
236
GD32E10x User Manual
14.2. Window watchdog timer (WWDGT)
14.2.1. Overview
The window watchdog timer (WWDGT) is used to detect system failures due to software
malfunctions. After the window watchdog timer starts, the value of down counter reduces
progressively. The watchdog timer causes a reset when the counter reached 0x3F (the CNT
[6] bit has been cleared). The watchdog timer also causes a reset when the counter is
refreshed before the counter reached the window register value. So the software should
refresh the counter in a limited window. The window watchdog timer generates an early
wakeup status flag when the counter reaches 0x40 or refreshes before the counter reaches
the window value. Interrupt occurs if it is enabled.
The window watchdog timer clock is prescaled from the APB1 clock. The window watchdog
timer is suitable for the situation that requires an accurate timing.
14.2.2. Characteristics
If the window watchdog timer is enabled (set the WDGTEN bit in the WWDGT_CTL), the
watchdog timer causes a reset when the counter reaches 0x3F (the CNT [6] bit has been
cleared), or the counter is refreshed before the counter reaches the window register value.
237
GD32E10x User Manual
Figure 14-2. Window watchdog timer block diagram
PCLK1/4096 Prescaler
/1/2/4/8
CNT>WIN
The watchdog is always disabled after power on reset. The software starts the watchdog by
setting the WDGTEN bit in the WWDGT_CTL register. When window watchdog timer is
enabled, the counter counts down all the time, the configured value of the counter should be
greater than 0x3F (it implies that the CNT [6] bit should be set). The CNT [5:0] determine the
maximum time interval between two reloading. The count down speed depends on the APB1
clock and the prescaler (PSC [1:0] bits in the WWDGT_CFG register).
The WIN [6:0] bits in the configuration register (WWDGT_CFG) specify the window value.
The software can prevent the reset event by reloading the down counter. The counter value
is less than the window value and greater than 0x3F, otherwise the watchdog causes a reset.
The early wakeup interrupt (EWI) is enabled by setting the EWIE bit in the WWDGT_CFG
register, and the interrupt will be generated when the counter reaches 0x40 or the counter is
refreshed before it reaches the window value. The software can do something such as
communication or data logging in the interrupt service routine (ISR) in order to analyze the
reason of software malfunctions or save the important data before resetting the device.
Moreover the software can reload the counter in ISR to manage a software system check and
so on. In this case, the WWDGT will never generate a WWDGT reset but can be used for
other things.
The EWI interrupt is cleared by writing '0' to the EWIF bit in the WWDGT_STAT register.
238
GD32E10x User Manual
Figure 14-3. Window watchdog timing diagram
CNT[6:0]
Start Start
0x7F Write CNT
WIN
0x3F
where:
tWWDGT: WWDGT timeout
tPCLK1: APB1 clock period measured in ms
The table below shows the minimum and maximum values of the tWWDGT.
If the WWDGT_HOLD bit in DBG module is cleared, the WWDGT continues to work even the
Cortex™-M4 core halted (Debug mode). While the WWDGT_HOLD bit is set, the WWDGT
stops in Debug mode.
239
GD32E10x User Manual
14.2.4. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rs rw
7 WDGTEN Start the window watchdog timer. Cleared by a hardware reset. Writing 0 has no
effect.
0: Window watchdog timer disabled
1: Window watchdog timer enabled
6:0 CNT[6:0] The value of the watchdog timer counter. A reset occurs when the value of this
counter decreases from 0x40 to 0x3F. When the value of this counter is greater than
the window value, writing this counter also causes a reset.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rs rw rw
240
GD32E10x User Manual
9 EWIE Early wakeup interrupt enable. If the bit is set, an interrupt occurs when the counter
reaches 0x40 or the counter is refreshed before it reaches the window value. It can
be cleared by a hardware reset or a software reset by setting the WWDGTRST bit
in RCU_APB1RST register. A write operation of ‘0’ has no effect.
8:7 PSC[1:0] Prescaler. The time base of the watchdog timer counter.
00: (PCLK1 / 4096) / 1
01: (PCLK1 / 4096) / 2
10: (PCLK1 / 4096) / 4
11: (PCLK1 / 4096) / 8
6:0 WIN[6:0] The Window value. A reset occurs if the watchdog counter (CNT bits in
WWDGT_CTL) is written when the value of the watchdog counter is greater than
the Window value.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved EWIF
rc_w0
0 EWIF Early wakeup interrupt flag. When the counter reaches 0x40 or refreshes before it
reaches the window value, this bit is set by hardware even the interrupt is not
enabled (EWIE in WWDGT_CFG is cleared). This bit is cleared by writing 0. There
is no effect when writing 1.
241
GD32E10x User Manual
15. Real-time Clock (RTC)
15.1. Overview
The RTC is usually used as a clock-calendar. The RTC circuits are located in two power
supply domains. The circuits in the backup domain consist of a 32-bit up-counter, an alarm,
a prescaler, a divider and the RTC clock configuration register. That means the RTC settings
and time are kept when the device resets or wakes up from Standby mode. While the other
circuits in the VDD domain only include the APB interface and a control register. In the following
sections, the details of the RTC function will be described.
15.2. Characteristics
The RTC circuits consist of two major units: APB interface located in PCLK1 clock domain
and RTC core located in RTC clock domain.
APB interface is connected with the APB1 bus. It includes a set of registers, which can be
accessed by APB1 bus.
RTC core includes two major blocks. One is the RTC prescaler block, which generates the
RTC time base clock SC_CLK. RTC prescaler block includes a 20-bit programmable divider
(RTC prescaler) which can generate SC_CLK by dividing the RTC source clock. If second
interrupt is enabled in the RTC_INTEN register, the RTC will generate an interrupt at every
SC_CLK rising edge. Another block is a 32-bit programmable counter, which can be initialized
with the value of current system time. If alarm interrupt is enabled in the RTC_INTEN register,
the RTC will generate an alarm interrupt when the system time equals to the alarm time
242
GD32E10x User Manual
(stored in the RTC_ALRMH/L register).
APB1 BUS
PCLK1
APB interface
RTC_Second
HXTAL/128 SCIF
RTCCLK RTC_Overflow
SCIE RTC Interrupt
LXTAL SC_CLK
RTC_DIV RTC_CNT OVIF NVIC
IRC40K OVIE interrupt
RTC_Alarm
Reload COMPARE ALRMIF controler
RTC_PSC ALRMIE
RTCSRC[1:0] RTC_ALRM
Rising edge EXTI17
The APB interface and the RTC_INTEN register are reset by a system reset. The RTC core
(prescaler, divider, counter and alarm) is reset only by a backup domain reset.
Steps to enable access to the backup registers and the RTC after reset are as follows:
1. Set the PMUEN and BKPIEN bits in the RCU_APB1EN register to enable the power and
backup interface clocks.
2. Enable access to the backup registers and RTC by setting the BKPWEN bit in the
PMU_CTL register.
The APB interface and RTC core are located in two different power supply domains.
In the RTC core, only counter and divider registers are readable registers. And the values in
the two registers and the RTC flags are internally updated at each rising edge of the RTC
clock, which is resynchronized by the APB1 clock.
When the APB interface is enabled from a disabled state, the read operation is not
recommended to be done immediately because the first internal update of the registers has
not finished. That means, when a system reset, a power reset or a wakeup from
standby/Deep-sleep mode occurs, the APB interface is disabled, and the RTC core keeps
running. In these cases, the correct read operation is that clear the RSYNF bit in the
RTC_CTL register first and then wait for it to be set by hardware. WFI and WFE have no
effects on the RTC APB interface.
The RTC_PSC, RTC_CNT and RTC_ALRM registers in the RTC core are writable. The
values of these registers can be configured only when the peripheral has entered
243
GD32E10x User Manual
configuration mode. And the CMF bit in the RTC_CTL register is used to indicate the
configuration mode status. The write operation takes effect only when the peripheral has
exited configuration mode, and it takes at least three RTCCLK cycles. The value of the
LWOFF bit in the RTC_CTL register will be set to ‘1’ after the write operation is finished. The
new write operation should be performed after the previous one is finished.
A) Wait until the value of LWOFF bit in the RTC_CTL register to be set to ‘1’.
B) Enter configuration mode by setting the CMF bit in the RTC_CTL register.
C) Write to the RTC registers.
D) Exit configuration mode by clearing the CMF bit in the RTC_CTL register.
E) Wait until the value of LWOFF bit in the RTC_CTL register to be set to ‘1’.
Before the update of the RTC counter, the RTC second interrupt flag (SCIF) is asserted on
the last RTCCLK cycle.
Before the counter equals to the RTC alarm value which is stored in the alarm register plus
one, the RTC alarm interrupt flag (ALRMIF) is asserted on the last RTCCLK cycle.
Before the counter equals to 0x0, the RTC overflow interrupt flag (OVIF) is asserted on the
last RTCCLK cycle.
The RTC alarm write operation and second interrupt flag must be synchronized by using
either of the following sequences:
Enable the RTC alarm interrupt and update the RTC alarm and/or RTC counter registers
in the RTC interrupt service routine.
Update the RTC alarm and/or the RTC counter registers after the SCIF bit is set in the
RTC_CTL register.
Figure 15-2. RTC second and alarm waveform example (RTC_PSC = 3, RTC_ALRM = 2)
RTCCLK
RTC_ PSC 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1
RTC_Second
RTC_CNT 0 1 2 3 4
RTC_Alarm
ALRMIF
ALRMIF flag can be cleared by software
244
GD32E10x User Manual
Figure 15-3. RTC second and overflow waveform example (RTC_PSC= 3)
RTCCLK
RTC_ PSC 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 3 2 1
RTC_Second
RTC_ Overflow
245
GD32E10x User Manual
15.4. Register definition
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
246
GD32E10x User Manual
4 CMF Configuration mode flag
0: Exit configuration mode
1: Enter configuration mode
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved PSC[19:16]
PSC[15:0]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DIV[19:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DIV[15:0]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
248
GD32E10x User Manual
CNT[31:16]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ALRM[31:16]
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ALRM[15:0]
249
GD32E10x User Manual
16. TIMER
Repetition ● × × × ×
CH Capture/
4 4 2 1 0
Compare
Complementary
● × × × ×
& Dead-time
Break ● × × × ×
Single Pulse ● ● ● × ●
Quadrature
● ● × × ×
Decoder
Slave
● ● ● × ×
Controller
Inter TRGO TO
● (1) ● (2) ● (3) ×
Connection DAC
DMA ● ● × × ● (4)
Debug Mode ● ● ● ● ●
(1) TIMER0 ITI0: TIMER4_TRGO ITI1: TIMER1_TRGO ITI2: TIMER2_TRGO ITI3: TIMER3_TRGO
(3) TIMER8 ITI0: TIMER1_TRGO ITI1: TIMER2_TRGO ITI2: TIMER9_TRGO ITI3: TIMER10_ TRGO
TIMER11 ITI0: TIMER3_TRGO ITI1: TIMER4_TRGO ITI2: TIMER12_TRGO ITI3: TIMER13_ TRGO
(4) Only update events will generate a DMA request. TIMER5/6 do not have DMAS bit (DMA
request source selection).
250
GD32E10x User Manual
16.1. Advanced timer (TIMERx, x=0, 7)
16.1.1. Overview
The advanced timer module (TIMER0, TIMER7) is a four-channel timer that supports both
input capture and output compare. They can generate PWM signals to control motor or be
used for power management applications. The advanced timer has a 16-bit counter that can
be used as an unsigned counter.
In addition, the advanced timers can be programmed and be used for counting, their external
events can be used to drive other timers.
Timer also includes a dead-time insertion module which is suitable for motor control
applications.
Timers are completely independent with each other, but they may be synchronized to provide
a larger timer with their counter value increasing in unison.
16.1.2. Characteristics
251
16.1.3.
CH0_IN
CI0
0 =1
CH1_IN Input Logic
0 0
CH3_IN
ITI0
ITI1
ITI2
ITI3
CK_TIMER TIMERx_CHxCV
Counter
External Trigger Trigger processor
Input logic
PSC_CLK
Trigger Selector&Counter DMA REQ/ACK
Polarity selection Quadrate Decoder TIMER_CK
ETI ETIFP PSC
Edge detector TIMERx_CH0
Slave mode processor TIMERx_CH1
Prescaler TIMERx_CH2
Figure 16-1. Advanced timer block diagram
BRKIN
Figure 16-1. Advanced timer block diagram provides details of the internal configuration of
GD32E10x User Manual
252
GD32E10x User Manual
16.1.4. Function overview
Clock selection
The clock source of the advanced timer can be either the CK_TIMER or an alternate clock
source controlled by SMC bits (TIMERx_SMCFG bit[2:0]).
SMC[2:0] = 3’b000. Internal clock CK_TIMER is selected as timer clock source which is
from module RCU.
The default clock source is the CK_TIMER for driving the counter prescaler when the slave
mode is disabled (SMC[2:0] = 3’b000). When the CEN is set, the CK_TIMER will be divided
by PSC value to generate PSC_CLK.
In this mode, the TIMER_CK which drives counter’s prescaler to count is equal to CK_TIMER
which is from RCU module.
If the slave mode controller is enabled by setting SMC[2:0] in the TIMERx_SMCFG register
to an available value including 0x1, 0x2, 0x3 and 0x7, the prescaler is clocked by other clock
sources selected by the TRGS[2:0] in the TIMERx_SMCFG register, more details will be
introduced later. When the slave mode control bits SMC[2:0] are set to 0x4, 0x5 or 0x6, the
internal clock TIMER_CK is the counter prescaler driving clock source.
CK_TIMER
CEN
update event
generate(UPG)
Reload Pulse
PSC_CLK = TIMER_CK
CNT_REG 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07
SMC[2:0] = 3’b111 (external clock mode 0). External input pin is selected as timer clock
source.
The TIMER_CK, which drives counter’s prescaler to count, can be triggered by the event of
rising or falling edge on the external pin TIMERx_CH0/TIMERx_CH1. This mode can be
selected by setting SMC[2:0] to 0x7 and the TRGS[2:0] to 0x4, 0x5 or 0x6.
253
GD32E10x User Manual
And, the counter prescaler can also be driven by rising edge on the internal trigger input pin
ITI0/1/2/3. This mode can be selected by setting SMC[2:0] to 0x7 and the TRGS[2:0] to 0x0,
0x1, 0x2 or 0x3.
SMC1= 1’b1 (external clock mode 1). External input ETI is selected as timer clock source.
The TIMER_CK, which drives counter’s prescaler to count, can be triggered by the event of
rising or falling edge on the external pin ETI. This mode can be selected by setting the SMC1
bit in the TIMERx_SMCFG register to 1. The other way to select the ETI signal as the clock
source is setting the SMC[2:0] to 0x7 and the TRGS[2:0] to 0x7. Note that the ETI signal is
derived from the ETI pin sampled by a digital filter. When the ETI signal is selected as the
clock source, the trigger controller including the edge detection circuitry will generate a clock
pulse on each ETI signal rising edge to clock the counter prescaler.
Prescaler
The prescaler can divide the timer clock (TIMER_CK) to a counter clock (PSC_CLK) by any
factor ranging from 1 to 65536. It is controlled by prescaler register (TIMERx_PSC) which can
be changed ongoing, but it is adopted at the next update event.
Figure 16-3. Counter timing diagram with prescaler division change from 1 to 2
TIMER_CK
CEN
PSC_CLK
CNT_REG F7 F8 F9 FA FB FC 0 01 02 03 04
UPG
Reload Pulse
PSC value 0 1
Prescaler BUF 0 1
Prescaler CNT 0 0 1 0 1 0 1 0 1
Up counting mode
In this mode, the counter counts up continuously from 0 to the counter reload value, which is
defined in the TIMERx_CAR register, in a count-up direction. Once the counter reaches the
254
GD32E10x User Manual
counter reload value, the counter restarts from 0. If the repetition counter is set, the update
event will be generated after (TIMERx_CREP+1) times of overflow. Otherwise the update
event is generated each time when counter overflows. The counting direction bit DIR in the
TIMERx_CTL0 register should be set to 0 for the up-counting mode.
Whenever, if the update event software trigger is enabled by setting the UPG bit in the
TIMERx_SWEVG register, the counter value will be initialized to 0 and an update event will
be generated.
If the UPDIS bit in TIMERx_CTL0 register is set, the update event is disabled.
When an update event occurs, all the registers (repetition counter register, auto reload
register, prescaler register) are updated.
Figure 16-4. Timing chart of up counting mode, PSC=0/1 and Figure 16-5. Timing chart
of up counting mode, change TIMERx_CAR ongoing show some examples of the counter
behavior for different clock prescaler factors when TIMERx_CAR=0x63.
TIMER_CK
CEN
PSC = 0
CNT_CLK(PSC_CLK)
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07 08
PSC = 1
CNT_CLK(PSC_CLK)
CNT_REG 5F 60 61 62 63 00 01 02 03
255
GD32E10x User Manual
Figure 16-5. Timing chart of up counting mode, change TIMERx_CAR ongoing
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
ARSE = 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07
Auto-reload register 65 63
ARSE = 1
CNT_REG 5E 5F 60 61 62 63 64 65 00 01 02 ... 62 63 00
Auto-reload register 65 63
In this mode, the counter counts down continuously from the counter reload value, which is
defined in the TIMERx_CAR register, in a count-down direction. Once the counter reaches 0,
the counter restarts to count again from the counter reload value. If the repetition counter is
set, the update event will be generated after (TIMERx_CREP+1) times of underflow.
Otherwise, the update event is generated each time when counter underflows. The counting
direction bit DIR in the TIMERx_CTL0 register should be set to 1 for the down counting mode.
When the update event is set by the UPG bit in the TIMERx_SWEVG register, the counter
value will be initialized to the counter reload value and an update event will be generated.
If the UPDIS bit in TIMERx_CTL0 register is set, the update event is disabled.
When an update event occurs, all the registers (repetition counter register, auto reload
register, prescaler register) are updated.
Figure 16-6. Timing chart of down counting mode, PSC=0/1 and Figure 16-7. Timing
chart of down counting mode, change TIMERx_CAR ongoing show some examples of
256
GD32E10x User Manual
the counter behavior in different clock frequencies when TIMERx_CAR = 0x63.
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
TIMERx_PSC PSC == 0
CNT_REG 05 04 03 02 01 00 63 62 61 60 5F 5E 5C 5B 5A
TIMERx_PSC PSC == 1
CNT_CLK(PSC_CLK)
CNT_REG 04 03 02 01 00 63 62 61
257
GD32E10x User Manual
Figure 16-7. Timing chart of down counting mode, change TIMERx_CAR ongoing
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
ARSE = 0
CNT_REG 05 04 03 02 01 00 63 62 61 60 5F 5E 5D 5C
Auto-reload register 65 63
ARSE = 1
CNT_REG 05 04 03 02 01 00 63 62 61 ... 01 00 65 64 63
Auto-reload register 65 63 63 65
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 (TIMERx_CREP-1) in the count-up direction and generates an
underflow event when the counter counts to 1 in the count-down direction. The counting
direction bit DIR in the TIMERx_CTL0 register is read-only and indicates the counting
direction when in the center-aligned counting mode. The counting direction is updated by
hardware automatically.
Setting the UPG bit in the TIMERx_SWEVG register will initialize the counter value to 0 and
generate an update event irrespective of whether the counter is counting up or down in the
center-aligned counting mode.
The UPIF bit in the TIMERx_INTF register will be set to 1 either when an underflow event or
an overflow event occurs. While the CHxIF bit is associated with the value of CAM in
TIMERx_CTL0. The details refer to Figure 16-8. Timing chart of center-aligned counting .
If the UPDIS bit in the TIMERx_CTL0 register is set, the update event is disabled.
When an update event occurs, all the registers (repetition counter register, auto-reload
258
GD32E10x User Manual
register, prescaler register) are updated.
Figure 16-8. Timing chart of center-aligned counting shows some examples of the
counter behavior when TIMERx_CAR=0x63. TIMERx_PSC=0x0.
TIMER_CK
CEN
CNT_CLK
(PSC_CLK)
CNT_REG 03 02 01 00 01 02 …. 62 63 62 61 …. 01 00 01 02 …. 62 63 62 61
Underflow
Overflow
UPIF
CHxIF
CHxIF
CHxIF
Hardware set
Software clear
Repetition counter
Repetition counter is used to generate the update event or update the timer registers only
after a given number (N+1) cycles of the counter, where N is the value of CREP bit in
TIMERx_CREP register. The repetition counter is decremented at each counter overflow in
up counting mode, at each counter underflow in down counting mode or at each counter
overflow and at each counter underflow in center-aligned counting mode.
Setting the UPG bit in the TIMERx_SWEVG register will reload the content of CREP in
TIMERx_CREP register and generate an update event.
For odd values of CREP in center-aligned counting mode, the update event occurs either on
the overflow or on the underflow depending on when the CREP register was written and when
259
GD32E10x User Manual
the counter was started. The update event is generated at overflow when the CREP was
written before starting the counter and generated at underflow when the CREP was written
after starting the counter.
TIMER_CK
CEN
CNT_CLK
03 02 01 00 01 02 …. 62 63 62 61 …. 01 00 01 02 …. 62 63 62 61 …. 01 00 01 02 …. 62 63 62 61
Underflow
Overflow
TIMERx_CREP = 0x0
UPIF
TIMERx_CREP = 0x1
UPIF
TIMERx_CREP = 0x2
UPIF
TIMER_CK
CEN
CNT_CLK
CNT_REG 60 61 62 63 00 01 … 62 63 00 01 … 62 63 00 01 … 62 63 00 01 … 62 63 00 01 … 62 63 00 01
Underflow
Overflow
TIMERx_CREP = 0x0
UPIF
TIMERx_CREP = 0x1
UPIF
TIMERx_CREP = 0x2
UPIF
260
GD32E10x User Manual
Figure 16-11. Repetition counter timing chart of down counting mode
TIMER_CK
CEN
CNT_CLK
CNT_REG 03 02 01 00 63 62 …. 01 00 63 62 …. 01 00 63 62 …. 01 00 63 62 …. 01 00 63 62 …. 01 00 63 62
Underflow
Overflow
TIMERx_CREP = 0x0
UPIF
TIMERx_CREP = 0x1
UPIF
TIMERx_CREP = 0x2
UPIF
Capture/compare channels
The advanced timer has four independent channels which can be used as capture inputs or
compare outputs. Each channel is built around a channel capture compare register including
an input stage, a channel controller and an output stage.
261
GD32E10x User Manual
Figure 16-12. Input capture logic
Edge Detector
Synchronizer Edge selector
&inverter
CI0
D Q D Q D Q
Filter Based on
CH0P&CH0NP
TIMER_CK
CI0FE0 CI0FED
Rising/Falling Rising&Falling
Capture IS0
Clock CI1FE0
Processer Counter Register presclare
(CH0VAL) ITS
CH0IF CH0CAPPSC
CH0_CC_I
CH0IE CH0MS
TIMERx_CC_INT
Capture INT From Other Channal ITI0
ITI1
ITI2
ITI3
CI0FED
The input signals of channelx (CIx) can be the TIMERx_CHx signal or the XOR signal of the
TIMERx_CH0, TIMERx_CH1 and TIMERx_CH2 signals. First, the input signal of channel (CIx)
is synchronized to TIMER_CK signal, and then sampled by a digital filter to generate a filtered
input signal. Then through the edge detector, the rising or falling edge is detected by
configuring CHxP bit. The input capture signal can also be selected from the input signal of
other channel or the internal trigger signal by configuring CHxMS bits. The IC prescaler makes
several input events generate one effective capture event. On the capture event,
TIMERx_CHxCV will store the value of counter.
Result: When the wanted input signal is captured, TIMERx_CHxCV will be set by counter’s
value and CHxIF is asserted. If the CHxIF is 1, the CHxOF will also be asserted. The interrupt
262
GD32E10x User Manual
and DMA request will be asserted or not based on the configuration of CHxIE and CHxDEN
in TIMERx_DMAINTEN.
The input capture mode can be also used for pulse width measurement from signals on the
TIMERx_CHx pins. For example, PWM signal connects to CI0 input. Select CI0 as channel 0
capture signals by setting CH0MS to 2’b01 in the channel control register (TIMERx_CHCTL0)
and set capture on rising edge. Select CI0 as channel 1 capture signal by setting CH1MS to
2’b10 in the channel control register (TIMERx_CHCTL0) and set capture on falling edge. The
counter is set to restart mode and is restarted on channel 0 rising edge. Then the
TIMERX_CH0CV can measure the PWM period and the TIMERx_CH1CV can measure the
PWM duty cycle.
O0CPRE
Capture/
output comparator
O3CPRE
Capture/
output comparator
Figure 16-13. Output compare logic (with complementary output, x=0,1,2) and
Figure 16-14. Output compare logic (CH3_O) show the logic circuit of output compare
mode. The relationship between the channel output signal CHx_O/CHx_ON and the OxCPRE
signal (more details refer to Channel output prepare signal) is described as blew: The active
level of O0CPRE is high, the output level of CH0_O/CH0_ON depends on OxCPRE signal,
CHxP/CHxNP bit and CH0E/CH0NE bit (please refer to the TIMERx_CHCTL2 register for
more details). For examples,
263
GD32E10x User Manual
1) Configure CHxP=0 (the active level of CHx_O is high, the same as OxCPRE), CHxE=1
(the output of CHx_O is enabled),
If the output of OxCPRE is active(high) level, the output of CHx_O is active(high) level;
If the output of OxCPRE is inactive(low) level, the output of CHx_O is active(low) level.
2) Configure CHxNP=0 (the active level of CHx_ON is low, contrary to OxCPRE), CHxNE=1
(the output of CHx_ON is enabled),
If the output of OxCPRE is active(high) level, the output of CHx_O is active(low) level;
If the output of OxCPRE is inactive(low) level, the output of CHx_O is active(high) level.
When CH0_O and CH0_ON are output at the same time, the specific outputs of CH0_O and
CH0_ON are related to the relevant bits (ROS, IOS, POE and DTCFG bits) in the
TIMERx_CCHP register. Please refer to Complementary outputs for more details.
In output compare mode, the TIMERx can generate timed pulses with programmable position,
polarity, duration and frequency. When the counter matches the value in the TIMERx_CHxCV
register of an output compare channel, the channel (n) output can be set, cleared, or toggled
based on CHxCOMCTL. When the counter reaches the value in the TIMERx_CHxCV register,
the CHxIF bit will be set and the channel (n) interrupt is generated if CHxIE = 1. And the DMA
request will be asserted, if CxCDE=1.
Step1: Clock Configuration. Such as clock source, clock prescaler and so on.
Figure 16-15. Output-compare in three modes shows the three compare modes:
toggle/set/clear. CAR=0x63, CHxVAL=0x3.
264
GD32E10x User Manual
Figure 16-15. Output-compare in three modes
CNT_CLK
CEN
CNT_REG 00 01 02 03 04 05 …. 62 63 00 01 02 03 04 05 …. 62 63 00 01 02 03 04 05 ….
Overflow
match toggle
OxCPRE
match set
OxCPRE
match clear
OxCPRE
PWM mode
In the PWM output mode (by setting the CHxCOMCTL bit to 3’b110 (PWM mode 0) or to 3’b
111(PWM mode 1)), the channel can generate PWM waveform according to the
TIMERx_CAR registers and TIMERx_CHxCV registers.
Based on the counter mode, PWM can also be divided into EAPWM (Edge-aligned PWM)
and CAPWM (Center-aligned PWM).
The EAPWM’s period is determined by TIMERx_CAR and the duty cycle is determined by
TIMERx_CHxCV. Figure 16-16. Timing chart of EAPWM shows the EAPWM output and
interrupts waveform.
The CAPWM’s period is determined by 2*TIMERx_CAR, and the duty cycle is determined by
2*TIMERx_CHxCV. Figure 16-17. Timing chart of CAPWM shows the CAPWM output and
interrupts waveform.
265
GD32E10x User Manual
Figure 16-16. Timing chart of EAPWM
CAR
CHxVAL
0
PWM MODE0
Cx OUT
PWM MODE1
Cx OUT
Interrupt signal
CHxIF
CHxOF
CAR
CHxVAL
0
PWM MODE0
Cx OUT
PWM MODE1
Cx OUT
Interrupt signal
CAM=2'b01 down only
CHxIF
CHxOF
CAM=2'b10 up only
CHxIF
CHxOF
CAM=2'b11 up/down
CHxIF
CHxOF
The PWM mode 0/PWM mode 1 output is another output type of OxCPRE which is setup by
configuring the CHxCOMCTL field to 0x06/0x07. In these modes, the OxCPRE signal level is
changed according to the counting direction and the relationship between the counter value
and the TIMERx_CHxCV content. Refer to the definition of relative bit for more details.
Another special function of the OxCPRE signal is a forced output which can be achieved by
configuring the CHxCOMCTL field to 0x04/0x05. The output can be forced to an
inactive/active level irrespective of the comparison condition between the values of the
counter and the TIMERx_CHxCV.
Configure the CHxCOMCEN bit to 1 in the TIMERx_CHCTL0 register, the OxCPRE signal
can be forced to 0 when the ETIFP signal derived from the external ETI pin is set to a high
level. The OxCPRE signal will not return to its active level until the next update event occurs.
Complementary outputs
Function of complementary is for a pair of channels, CHx_O and CHx_ON, the two output
signals cannot be active at the same time. The TIMERx has 4 channels, but only the first
three channels have this function. The complementary signals CHx_O and CHx_ON are
controlled by a group of parameters: the CHxEN and CHxNEN bits in the TIMERx_CHCTL2
register, the POEN, ROS and IOS bits in the TIMERx_CCHP register, ISOx and ISOxN bits
in the TIMERx_CTL1 register. The output polarity is determined by CHxP and CHxNP bits in
the TIMERx_CHCTL2 register.
267
GD32E10x User Manual
Table 16-2. Complementary outputs controlled by parameters
1 CHx_ON=(!OxCPRE)⊕
CHx_O=OxCPRE⊕CHxP
1 CHxNP
CHx_O output enable
CHx_ON output enable
1 0/1 CHx_O = CHxP CHx_ON = CHxNP
0 CHx_O output disable. CHx_ON output disable.
0 CHx_O = CHxP CHx_ON=OxCPRE⊕CHxNP
1 CHx_O output enable CHx_ON output enable
1 CHx_ON=(!OxCPRE)⊕
CHx_O=OxCPRE⊕CHxP
1 CHxNP
CHx_O output enable
CHx_ON output enable.
The dead time insertion is enabled when both CHxEN and CHxNEN are configured to 1’b1,
it is also necessary to configure POEN to 1. The field named DTCFG defines the dead time
delay that can be used for all channels except channel 3. Refer to the TIMERx_CCHP register
for details about the delay time.
268
GD32E10x User Manual
The dead time delay insertion ensures that two complementary signals are not active at the
same time.
When the channelx match event (TIMERx counter = CHxVAL) occurs, OxCPRE will be
toggled in PWM mode 0. At point A in Figure 16-18. Complementary output with dead time
insertion, CHx_O signal remains at the low level until the end of the dead time delay, while
CHx_ON signal will be cleared at once. Similarly, at point B when the channelx match event
(TIMERx counter = CHxVAL) occurs again, OxCPRE is cleared, and CHx_O signal will be
cleared at once, while CHx_ON signal remains at the low level until the end of the dead time
delay.
Sometimes, we can see corner cases about the dead time insertion. For example: the dead
time delay is greater than or equal to the duty cycle of the CHx_O signal, then the CHx_O
signal is always inactive (As shown in Figure 16-18. Complementary output with dead time
insertion).
A B
CAR
CHxVAL
0
CxOPRE
CHx_O
CHx_ON
Deadtime
Corner case Deadtime > pulse width
Pulse width
CHx_O
Deadtime
CHx_ON
Deadtime
Break function
In this function, CHx_O and CHx_ON are controlled by the POEN, IOS and ROS bits in the
TIMERx_CCHP register, ISOx and ISOxN bits in the TIMERx_CTL1 register. In any case,
CHx_O and CHx_ON signals cannot be set to active level at the same time. The break
sources are input break pin and HXTAL stuck event which is generated by Clock Monitor
(CKM) in RCU. The break function is enabled by setting the BRKEN bit in the TIMERx_CCHP
register. The break input polarity is configured by the BRKP bit in TIMERx_CCHP register.
When a break occurs, the POEN bit is cleared asynchronously. As soon as POEN is 0, the
level of the CHx_O and CHx_ON outputs are determined by the ISOx and ISOxN bits in the
TIMERx_CTL1 register. If IOS is 0, the timer releases the enable output, otherwise, the
enable output remains high. The complementary outputs are first in the reset state, and then
269
GD32E10x User Manual
the dead time generator is reactivated to drive the outputs with the level programmed in the
ISOx and ISOxN bits after a dead time.
When a break occurs, the BRKIF bit in the TIMERx_INTF register will be set. If BRKIE is 1,
an interrupt will be generated.
Figure 16-19. Output behavior of the channel in response to a break (the break high
active)
BRKIN
OxCPRE
Quadrature decoder
The quadrature decoder function uses two quadrature inputs CI0 and CI1 derived from the
TIMERx_CH0 and TIMERx_CH1 pins respectively to interact with each other to generate the
counter value. Setting SMC=0x01, 0x02, or 0x03 to select that the counting direction of timer
is determined only by the CI0, only by the CI1, or by the CI0 and the CI1. The DIR bit is
modified by hardware automatically during the voltage level change of each direction
selection source. The mechanism of changing the counter direction is shown in Table 16-3.
Counting direction versus encoder signals. The quadrature decoder can be regarded as
an external clock with a direction selection. This means that the counter counts continuously
from 0 to the counter-reload value. Therefore, users must configure the TIMERx_CAR register
before the counter starts to count.
270
GD32E10x User Manual
Table 16-3. Counting direction versus encoder signals
CI0FE0 CI1FE1
Counting mode Level
Rising Falling Rising Falling
CI0 only CI1FE1=High Down Up - -
counting CI1FE1=Low Up Down - -
CI1 only CI0FE0=High - - Up Down
counting CI0FE0=Low - - Down Up
CI1FE1=High Down Up X X
CI0 and CI1 CI1FE1=Low Up Down X X
counting CI0FE0=High X X Up Down
CI0FE0=Low X X Down Up
CI0
CI1
Counter UP down
Figure 16-21. Example of encoder interface mode with CI0FE0 polarity inverted
CI0
CI1
Counter down UP
Hall sensor is generally used to control BLDC motor, the advanced timer supports this
271
GD32E10x User Manual
function.
Figure 16-22. Hall sensor is used for BLDC motor shows how to connect the timer and the
motor. And two timers are needed. TIMER_in(Advanced/General L0 TIMER)is used to accept
three rotor position signals of motor from hall sensors.
Each of the 3 hall sensors provides a pulse which is applied to an input capture pin, then both
the speed and position of rotor can be calculated by analyzing the hall sensor signals.
Because the advanced/general L0 TIMER has the input XOR function, they can be used as
the TIMER_in timer. And the advanced timer has the functions of complementary output and
dead time, so it can be used as the TIMER_out timer.
In addition, the timers can be selected in pairs based on the internal connection relationship
of the timers. For example:
After appropriate interconnected timers are selected and wires are connected, the timers
need to be configured. Some key settings are as follows:
Enable XOR by setting TI0S, then, the change of each input signal will make the CI0
toggle. CH0VAL will record the current value of counter.
Choose ITIx to trigger commutation by configuring CCUC and CCSE.
Configure PWM parameters based on the requests.
Input capture
BLDC
Motor
Output compare
PWM output
MCU
272
GD32E10x User Manual
Figure 16-23. Hall sensor timing between two timers
CH0_INPUT
CH1_INPUT
CH2_INPUT
CI0(OXR)
Va Vb Vc
Counter
CH0VAL Va Vb Vc
CH0_O
CH0_ON
CH1_O
CH1_ON
CH2_O
CH2_ON
Slave controller
The TIMERx can be synchronized with a trigger in several modes including restart mode,
pause mode and event mode which is selected by the SMC[2:0] bits in the TIMERx_SMCFG
register. The input trigger of these modes can be selected by the TRGS[2:0] bits in the
TIMERx_SMCFG register.
273
GD32E10x User Manual
Mode Selection Source Selection Polarity Selection Filter and Prescaler
TIMER_CK
Exam1
CEN
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 00 01 02
UPIF
ITI0
Pause mode
TI0S=0 (Non-xor)
The counter will be
[CH0NP=0, CH0P=0]
paused when the
TRGS[2:0]=3’b101 CI0FE0 does not Filter is bypassed in
trigger input is low,
CI0FE0 is selected. invert. The capture this example.
and it will start when
event will occur on the
the trigger input is
rising edge only.
high.
Figure 16-25. Pause mode
Exam2
TIMER_CK
CEN
CNT_REG 5E 5F 60 61 62 63
CI0
CI0FE0
TRGIF
274
GD32E10x User Manual
Mode Selection Source Selection Polarity Selection Filter and Prescaler
Event mode
ETPSC = 1, ETI is
The counter will start ETP = 0, the polarity
TRGS[2:0] =3’b111 divided by 2.
to count when a rising of ETI does not
ETIFP is selected. ETFC = 0, ETI does
edge of trigger input change.
not filter.
comes.
Exam3 TIMER_CK
ETI
ETIFP
CNT_REG 5E 5F 60 61
TRGIF
Single pulse mode is enabled by setting SPM in TIMERx_CTL0. If SPM is set, the counter
will be cleared and stopped automatically when the next update event occurs. In order to get
a pulse waveform, the TIMERx is configured to PWM mode or compare mode by
CHxCOMCTL.
Once the timer is set to the single pulse mode, it is not necessary to configure the timer enable
bit CEN in the TIMERx_CTL0 register to 1 to enable the counter. Setting the CEN bit to 1 or
a trigger signal edge can generate a pulse and then keep the CEN bit at a high state until the
update event occurs or the CEN bit is written to 0 by software. If the CEN bit is cleared to 0
by software, the counter will be stopped and its value will be held. If the CEN bit is
automatically cleared to 0 by a hardware update event, the counter will be reinitialized.
In the single pulse mode, the active edge of trigger which sets the CEN bit to 1 will enable the
counter. However, there exists several clock delays to perform the comparison result between
the counter value and the TIMERx_CHxCV value. In order to reduce the delay to a minimum
value, the user can set the CHxCOMFEN bit in TIMERx_CHCTL0/1 register. After a trigger
rising occurs in the single pulse mode, the OxCPRE signal will immediately be forced to the
state which the OxCPRE signal will change to, as the compare match event occurs without
taking the comparison result into account. The CHxCOMFEN bit is available only when the
output channel is configured to the PWM mode 0 or PWM mode 1 and the trigger source is
derived from the trigger signal.
275
GD32E10x User Manual
Figure 16-27. Single pulse mode TIMERx_CHxCV=0x04, TIMERx_CAR=0x60
TIMER_CK(CNT_CLK)
CEN
Under SPM, counter stop
CI3
CNT_REG 00 01 02 03 04 05 …. 5F 60 00
O2CPRE
Timers interconnection
The timers can be internally connected 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 show several examples of trigger
selection for the master mode and slave mode.
Figure 16-28. TIMER0 master/slave mode example shows the TIMER0 trigger selection
when it is configured in slave mode.
TIMER 2
Master TRG O ITI2
Pre scaler Counter mode
control Trigger Slave mode
Pre scaler Counter
selection control
TIMER 3 IT1 Master TRG O ITI3
Pre scaler Counter mode
control
CI0F_ED
CI0FE0
CI1FE1
ETIFP
276
GD32E10x User Manual
TIMER2 is configured as a prescaler for TIMER0. Refer to Figure 16-28. TIMER0
master/slave mode example for connections. Steps are shown as follows:
1. Configure TIMER2 in master mode and select its update event (UPE) as trigger output
(MMC=3’b010 in the TIMER2_CTL1 register). Then TIMER2 drives a periodic signal on
each counter overflow.
First, enable TIMER0 with the enable signal of TIMER2. Refer to Figure 16-29. Trigger mode
of TIMER0 controlled by enable signal of TIMER2. TIMER0 starts counting from its current
value with the divided internal clock after being triggered by TIMER2 enable signal output.
When TIMER0 receives the trigger signal, its CEN bit is set automatically and the counter
counts until TIMER0 is disabled. Both clock frequency of the counters are divided by 3 from
TIMER_CK (fPSC_CLK = fTIMER_CK /3). Steps are shown as follows:
1. Configure TIMER2 in master mode to send its enable signal as trigger output
(MMC=3’b001 in the TIMER2_CTL1 register).
CEN
CNT_REG 61 62 63
TIMER0
TRGIF
11 12 13 14
CNT_REG
277
GD32E10x User Manual
In this example, the update event can also be used as trigger source instead of enable signal.
Refer to Figure 16-30. Trigger mode of TIMER0 controlled by update signal of TIMER2.
Steps are shown as follows:
1. Configure TIMER2 in master mode to send its update event (UPE) as trigger output
(MMC=3’b010 in the TIMER2_CTL1 register).
TIMER2
TIMER_CK
UPE
CNT_REG 62 63 00 01 02
TIMER0
TRGIF
CEN
11 12 13 14
CNT_REG
In this example, TIMER0 is enabled with the enable signal of TIMER2. Refer to Figure 16-31.
Pause mode of TIMER0 controlled by enable signal of TIMER2. TIMER0 counts with the
divided internal clock only when TIMER2 is enabled. Both clock frequency of the counters are
divided by 3 from TIMER_CK (fPSC_CLK = fTIMER_CK/3). Steps are shown as follows:
1. Configure TIMER2 in master mode and output enable signal as trigger output
(MMC=3’b001 in the TIMER2_CTL1 register).
TIMER2
TIMER_CK
CEN
CNT_REG 61 62 63
TIMER0
TRGIF
11 12 13
CNT_REG
In this example, O0CPRE can also be used as trigger source instead of enable signal output.
Steps are shown as follows:
1. Configure TIMER2 in master mode and O0CPRE as trigger output (MMS=3’b100 in the
TIMER2_CTL1 register).
TIMER2
TIMER_CK
CNT_REG 60 61 62 63 00 01
O0CPRE
TIMER0
TRGIF
11 12 13 14
CNT_REG
The start of TIMER0 is triggered by the enable signal of TIMER2, and TIMER2 is triggered by
its CI0 input rising edge. To ensure that two timers start synchronously, TIMER2 must be
configured in master/slave mode. Steps are shown as follows:
279
GD32E10x User Manual
1. Configure TIMER2 in slave mode, and select CI0_ED as the input trigger (TRGS=3’b100
in the TIMER2_SMCFG register).
When the CI0 signal of TIMER2 generates a rising edge, two timer counters start counting
synchronously with the internal clock and both TRGIF flags are set.
Figure 16-33. Trigger TIMER0 and TIMER2 by the CI0 signal of TIMER2
TIMER2
TIMER_CK
CI0
TRGIF
CEN
CNT_REG 00 01 02 03
TIMER0
TRGIF
CEN
CNT_CK
CNT_REG 00 01 02 03
Timer DMA mode is the function that configures timer’s register by DMA module. The relative
registers are TIMERx_DMACFG and TIMERx_DMATB. Corresponding DMA request bit
should be asserted to enable DMA request for internal interrupt event. TIMERx will send a
request to DMA when the interrupt event occurs. DMA is configured to M2P (memory to
peripheral) mode and the address of TIMERx_DMATB is configured to PADDR (peripheral
base address), then DMA will access the TIMERx_DMATB. In fact, TIMERx_DMATB register
is only a buffer, timer will map the TIMERx_DMATB to an internal register, appointed by the
field of DMATA in TIMERx_DMACFG. If the field of DMATC in TIMERx_DMACFG is 0 (1
280
GD32E10x User Manual
transfer), the timer sends only one DMA request. While if TIMERx_DMATC is not 0, such as
3 (4 transfers), then timer will send 3 more requests to DMA, and DMA will access timer’s
registers DMATA+0x4, DMATA+0x8 and DMATA+0xC at the next 3 accesses to
TIMERx_DMATB. In a word, one-time DMA internal interrupt event asserts, (DMATC+1)
times request will be sent by TIMERx.
If one more DMA request event occurs, TIMERx will repeat the process above.
When the Cortex™-M4 is halted, and the TIMERx_HOLD configuration bit in DBG_CTL
register is set to 1, the TIMERx counter stops.
281
GD32E10x User Manual
16.1.5. TIMERx registers (x=0, 7)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
282
GD32E10x User Manual
11: Center-aligned and counting up/down assert mode. The counter counts in
center-aligned mode and channel is configured in output mode (CHxMS=00 in
TIMERx_CHCTL0 register). Both when the counter is counting up and counting
down, compare interrupt flag of channels can be set.
After the counter is enabled, these bits cannot be switched from 0x00 to non 0x00.
4 DIR Direction
0: Count up
1: Count down
This bit is read only when the timer is configured in center-aligned mode or encoder
mode.
283
GD32E10x User Manual
Reset value: 0x0000 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved ISO3 ISO2N ISO2 ISO1N ISO1 ISO0N ISO0 TI0S MMC[2:0] DMAS CCUC Reserved CCSE
rw rw rw rw rw rw rw rw rw rw rw rw
284
GD32E10x User Manual
generated by the slave mode controller, a TRGO pulse occurs. And in the latter
case, the signal on TRGO is delayed compared to the actual reset.
001: Enable. This mode is used to start several timers at the same time or control a
slave timer to be enabled in a period. In this mode, the master mode controller
selects the counter enable signal as TRGO. The counter enable signal is set when
CEN control bit is set or the trigger input in pause mode is high. There is a delay
between the trigger input in pause mode and the TRGO output, except if the master-
slave mode is selected.
010: Update. In this mode, the master mode controller selects the update event as
TRGO.
011: Capture/compare pulse. In this mode, the master mode controller generates a
TRGO pulse when a capture or a compare match occurs in channel 0.
100: Compare. In this mode, the master mode controller selects the O0CPRE signal
as TRGO.
101: Compare. In this mode, the master mode controller selects the O1CPRE signal
as TRGO.
110: Compare. In this mode, the master mode controller selects the O2CPRE signal
as TRGO.
111: Compare. In this mode, the master mode controller selects the O3CPRE signal
as TRGO.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw
286
GD32E10x User Manual
0011: fSAMP= fTIMER_CK, N=8.
0100: fSAMP=fDTS/2, N=6.
0101: fSAMP=fDTS/2, N=8.
0110: fSAMP=fDTS/4, N=6.
0111: fSAMP=fDTS/4, N=8.
1000: fSAMP=fDTS/8, N=6.
1001: fSAMP=fDTS/8, N=8.
1010: fSAMP=fDTS/16, N=5.
1011: fSAMP=fDTS/16, N=6.
1100: fSAMP=fDTS/16, N=8.
1101: fSAMP=fDTS/32, N=5.
1110: fSAMP=fDTS/32, N=6.
1111: fSAMP=fDTS/32, N=8.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved TRGDEN CMTDEN CH3DEN CH2DEN CH1DEN CH0DEN UPDEN BRKIE TRGIE CMTIE CH3IE CH2IE CH1IE CH0IE UPIE
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
288
GD32E10x User Manual
1: Enabled
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
289
GD32E10x User Manual
Reserved CH3OF CH2OF CH1OF CH0OF Reserved BRKIF TRGIF CMTIF CH3IF CH2IF CH1IF CH0IF UPIF
rc_w0 rc_w0 rc_w0 rc_w0 . rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0
290
GD32E10x User Manual
Refer to CH0IF description
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
w w w w w w w w
291
GD32E10x User Manual
1: Generate a trigger event
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
292
GD32E10x User Manual
CH1COM CH1COM CH1COM CH0COM CH0COM CH0COM
CH1COMCTL[2:0] CH0COMCTL[2:0]
CEN SEN FEN CH1MS[1:0] CEN SEN FEN CH0MS[1:0]
rw rw rw rw rw rw
294
GD32E10x User Manual
10: Channel 0 is configured as input, IS0 is connected to CI1FE0.
11: Channel 0 is configured as input, IS0 is connected to ITS, this mode is working
only if an internal trigger input is selected (through TRGS bits in TIMERx_SMCFG
register).
295
GD32E10x User Manual
11: Capture is done every 8 channel input edges.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
296
GD32E10x User Manual
7 CH2COMCEN Channel 2 output compare clear enable.
When this bit is set, the O2CPRE signal is cleared when high level is detected on
ETIFP input.
0: Channel 2 output compare clear disabled
1: Channel 2 output compare clear enabled
297
GD32E10x User Manual
2 CH2COMFEN Channel 2 output compare fast enable
When this bit is set, the responses of the trigger input event to the capture/compare
output will be accelerated if the channel is configured in PWM mode 0 or PWM
mode 1. The output channel will treat an active edge of the trigger input as a
compare match, and CH2_O is set to the compare level regardless of the result of
the comparison.
0: Channel 2 output quickly compare disabled. The minimum delay from an edge of
the trigger input to activate CH2_O output is 5 clock cycles.
1: Channel 2 output quickly compare enable. The minimum delay from an edge of
the trigger input to activate CH2_O output is 3 clock cycles.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved CH3P CH3EN CH2NP CH2NEN CH2P CH2EN CH1NP CH1NEN CH1P CH1EN CH0NP CH0NEN CH0P CH0EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
299
GD32E10x User Manual
10 CH2NEN Channel 2 complementary output enable
Refer to CH0NEN description
300
GD32E10x User Manual
11 or 10.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw
15:0 CNT[15:0] This bit-field indicates the current counter value. Writing to this bit-field can change
the value of the counter.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSC[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CARL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved CREP[7:0]
rw
302
GD32E10x User Manual
Channel 0 capture/compare value register (TIMERx_CH0CV)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH0VAL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH1VAL[15:0]
rw
303
GD32E10x User Manual
shadow register updates by every update event.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH2VAL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH3VAL[15:0]
rw
304
GD32E10x User Manual
When channel 3 is configured in output mode, this bit-field contains value to be
compared to the counter. When the corresponding shadow register is enabled, the
shadow register updates by every update event.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
305
GD32E10x User Manual
This bit can be modified only when PROT[1:0] bit-field in TIMERx_CCHP register is
00.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMATB[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
308
GD32E10x User Manual
16.2. General level0 timer (TIMERx, x=1, 2, 3, 4)
16.2.1. Overview
The general level0 timer module (TIMER1, 2, 3, 4) is a four-channel timer that supports input
capture and output compare. They can generate PWM signals to control motor or be used for
power management applications. The general level0 timer has a 16-bit counter that can be
used as an unsigned counter.
In addition, the general level0 timers can be programmed and be used for counting, their
external events can be used to drive other timers.
Timers are completely independent with each other, but they may be synchronized to provide
a larger timer with their counter value increasing in unison.
16.2.2. Characteristics
Figure 16-34. General Level 0 timer block diagram provides details on the internal
configuration of the general level0 timer.
309
16.2.4.
CH0_IN
CI0
0 =1
CH1_IN 0 0
Input Logic
0
Clock selection
Synchronizer&Filter Edge selector Prescaler
CH2_IN
&Edge Detector
Function overview
CH3_IN
ITI0
ITI1
ITI2
ITI3
CK_TIMER TIMERx_CHxCV
Counter
External Trigger Trigger processor
Input logic
PSC_CLK
Trigger Selector&Counter
Polarity selection TIMER_CK
ETIFP Quadrate Decoder PSC DMA REQ/ACK
ETI Edge detector Slave mode processor
TIMERx_CH0
Prescaler
DMA controller TIMERx_CH1
Filter ……. TIMERx_CH2
TIMERx_CH3
TIMERx_TG
Figure 16-34. General Level 0 timer block diagram
TIMERx_TRGO TIMERx_UP
Register /Interrupt req en/direct req set
Update
Trigger
Cap/Com CH3_O
GD32E10x User Manual
The general level0 TIMER has the capability of being clocked by either the CK_TIMER or an
310
GD32E10x User Manual
SMC[2:0] = 3’b000. Internal clock CK_TIMER is selected as timer clock source which is
from module RCU.
The default clock source is the CK_TIMER for driving the counter prescaler when the slave
mode is disabled (SMC[2:0] = 3’b000). When the CEN is set, the CK_TIMER will be divided
by PSC value to generate PSC_CLK.
In this mode, the TIMER_CK which drives counter’s prescaler to count is equal to CK_TIMER
which is from RCU module.
If the slave mode controller is enabled by setting SMC[2:0] in the TIMERx_SMCFG register
to an available value including 0x1, 0x2, 0x3 and 0x7, the prescaler is clocked by other clock
sources selected by the TRGS[2:0] in the TIMERx_SMCFG register, more details will be
introduced later. When the slave mode control bits SMC[2:0] are set to 0x4, 0x5 or 0x6, the
internal clock TIMER_CK is the counter prescaler driving clock source.
CK_TIMER
CEN
Reload Pulse
PSC_CLK = TIMER_CK
CNT_REG 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07
SMC[2:0] = 3’b111 (external clock mode 0). External input pin is selected as timer clock
source.
The TIMER_CK, which drives counter’s prescaler to count, can be triggered by the event of
rising or falling edge on the external pin TIMERx_CH0/TIMERx_CH1. This mode can be
selected by setting SMC[2:0] to 0x7 and the TRGS[2:0] to 0x4, 0x5 or 0x6.
And, the counter prescaler can also be driven by rising edge on the internal trigger input pin
ITI0/1/2/3. This mode can be selected by setting SMC[2:0] to 0x7 and the TRGS[2:0] to 0x0,
0x1, 0x2 or 0x3.
SMC1= 1’b1 (external clock mode 1). External input ETI is selected as timer clock source.
The TIMER_CK, which drives counter’s prescaler to count, can be triggered by the event of
311
GD32E10x User Manual
rising or falling edge on the external pin ETI. This mode can be selected by setting the SMC1
bit in the TIMERx_SMCFG register to 1. The other way to select the ETI signal as the clock
source is setting the SMC[2:0] to 0x7 and the TRGS[2:0] to 0x7. Note that the ETI signal is
derived from the ETI pin sampled by a digital filter. When the ETI signal is selected as the
clock source, the trigger controller including the edge detection circuitry will generate a clock
pulse on each ETI signal rising edge to clock the counter prescaler.
Prescaler
The prescaler can divide the timer clock (TIMER_CK) to a counter clock (PSC_CLK) by any
factor ranging from 1 to 65536. It is controlled by prescaler register (TIMERx_PSC) which can
be changed ongoing, but it is adopted at the next update event.
Figure 16-36. Counter timing diagram with prescaler division change from 1 to 2
TIMER_CK
CEN
PSC_CLK
CNT_REG F7 F8 F9 FA FB FC 0 01 02 03 04
UPG
Reload Pulse
PSC value 0 1
Prescaler BUF 0 1
Prescaler CNT 0 0 1 0 1 0 1 0 1
Up counting mode
In this mode, the counter counts up continuously from 0 to the counter reload value, which is
defined in the TIMERx_CAR register, in a count-up direction. Once the counter reaches the
counter reload value, the counter restarts from 0. The update event is generated each time
when counter overflows. The counting direction bit DIR in the TIMERx_CTL0 register should
be set to 0 for the up counting mode.
Whenever, if the update event software trigger is enabled by setting the UPG bit in the
TIMERx_SWEVG register, the counter value will be initialized to 0 and an update event will
be generated.
312
GD32E10x User Manual
If the UPDIS bit in TIMERx_CTL0 register is set, the update event is disabled.
When an update event occurs, all the registers (repetition counter register, auto reload
register, prescaler register) are updated.
Figure 16-37. Timing chart of up counting mode, PSC=0/1 and Figure 16-38. Timing
chart of up counting, change TIMERx_CAR ongoing show some examples of the counter
behavior for different clock prescaler factor when TIMERx_CAR=0x63.
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
TIMERx_PSC PSC == 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07 08
Hardware set
Update interrupt flag (UPIF)
TIMERx_PSC PSC == 1
CNT_CLK(PSC_CLK)
CNT_REG 5F 60 61 62 63 00 01 02 03
313
GD32E10x User Manual
Figure 16-38. Timing chart of up counting, change TIMERx_CAR ongoing
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
ARSE = 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07
Hardware set
Update interrupt flag (UPIF)
Auto-reload register 65 63
ARSE = 1
CNT_REG 5E 5F 60 61 62 63 64 65 00 01 02 ... 62 63 00
Auto-reload register 65 63
In this mode, the counter counts down continuously from the counter reload value, which is
defined in the TIMERx_CAR register, in a count-down direction. Once the counter reaches 0,
the counter restarts to count again from the counter reload value. The counting direction bit
DIR in the TIMERx_CTL0 register should be set to 1 for the down counting mode.
When the update event is set by the UPG bit in the TIMERx_SWEVG register, the counter
value will be initialized to the counter reload value and an update event will be generated.
If the UPDIS bit in TIMERx_CTL0 register is set, the update event is disabled.
When an update event occurs, all the registers (repetition counter register, auto reload
register, prescaler register) are updated.
Figure 16-39. Timing chart of down counting mode, PSC=0/1 and Figure 16-40. Timing
chart of down counting mode, change TIMERx_CAR ongoing show some examples of
the counter behavior for different clock frequencies when TIMERx_CAR = 0x63.
314
GD32E10x User Manual
TIMER_CK
CEN
PSC = 0
CNT_CLK(PSC_CLK)
CNT_REG 05 04 03 02 01 00 63 62 61 60 5F 5E 5C 5B 5A
Hardware set
Update interrupt flag (UPIF)
PSC = 1
CNT_CLK(PSC_CLK)
CNT_REG 04 03 02 01 00 63 62 61
315
GD32E10x User Manual
Figure 16-40. Timing chart of down counting mode, change TIMERx_CAR ongoing
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
ARSE = 0
CNT_REG 05 04 03 02 01 00 63 62 61 60 5F 5E 5D 5C
Hardware set
Update interrupt flag (UPIF)
Auto-reload register 65 63
ARSE = 1
CNT_REG 05 04 03 02 01 00 63 62 61 ... 01 00 65 64 63
Auto-reload register 65 63 65
63
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 (TIMERx_CREP-1) in the count-up direction and generates an
underflow event when the counter counts to 1 in the count-down direction. The counting
direction bit DIR in the TIMERx_CTL0 register is read-only and indicates the counting
direction when in the center-aligned counting mode. The counting direction is updated by
hardware automatically.
Setting the UPG bit in the TIMERx_SWEVG register will initialize the counter value to 0 and
generate an update event irrespective of whether the counter is counting up or down in the
center-aligned counting mode.
The UPIF bit in the TIMERx_INTF register will be set to 1 either when an underflow event or
an overflow event occurs. While the CHxIF bit is associated with the value of CAM in
TIMERx_CTL0. The details refer to Figure 16-41. Timing chart of center-aligned counting
mode.
If the UPDIS bit in the TIMERx_CTL0 register is set, the update event is disabled.
316
GD32E10x User Manual
When an update event occurs, all the registers (auto-reload register, prescaler register) are
updated.
Figure 16-41. Timing chart of center-aligned counting mode shows the example of the
counter behavior when TIMERx_CAR=0x63, TIMERx_PSC=0x0
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
CNT_REG 03 02 01 00 01 02 …. 62 63 62 61 …. 01 00 01 02 …. 62 63 62 61
Underflow
Overflow
UPIF
CHxIF
CHxIF
CHxIF
Hardware set
Software clear
Capture/compare channels
The general level0 Timer has four independent channels which can be used as capture inputs
or compare match outputs. Each channel is built around a channel capture compare register
including an input stage, channel controller and an output stage.
Input capture mode allows the channel to perform measurements such as pulse timing,
frequency, period, duty cycle and so on. The input stage consists of a digital filter, a channel
polarity selection, edge detection and a channel prescaler. When a selected edge occurs on
the channel input, the current value of the counter is captured into the TIMERx_CHxCV
register, at the same time the CHxIF bit is set and the channel interrupt is generated if it is
317
GD32E10x User Manual
enabled when CHxIE=1.
Edge Detector
Synchronizer Edge selector
&inverter
CI0
D Q D Q D Q
Filter Based on
CH0P
TIMER_CK
CI0FE0
Rising/Falling
Capture IS0
Clock CI1FE0
Processer Counter Register presclare
(CH0VAL) ITS
CH0IF CH0CAPPSC
CH0_CC_I
CH0IE CH0MS
TIMERx_CC_INT
Capture INT From Other Channal ITI0
ITI1
ITI2
ITI3
The input signals of channelx (CIx) can be the TIMERx_CHx signal or the XOR signal of the
TIMERx_CH0, TIMERx_CH1 and TIMERx_CH2 signals. First, the input signal of channel (CIx)
is synchronized to TIMER_CK signal, and then sampled by a digital filter to generate a filtered
input signal. Then through the edge detector, the rising or falling edge is detected by
configuring CHxP bit. The input capture signal can also be selected from the input signal of
other channel or the internal trigger signal by configuring CHxMS bits. The IC prescaler makes
several input events generate one effective capture event. On the capture event,
TIMERx_CHxCV will store the value of counter.
The input capture mode can be also used for pulse width measurement from signals on the
TIMERx_CHx pins. For example, PWM signal connects to CI0 input. Select CI0 as channel 0
capture signals by setting CH0MS to 2’b01 in the channel control register (TIMERx_CHCTL0)
and set capture on rising edge. Select CI0 as channel 1 capture signal by setting CH1MS to
2’b10 in the channel control register (TIMERx_CHCTL0) and set capture on falling edge. The
counter is set to restart mode and is restarted on channel 0 rising edge. Then the
TIMERX_CH0CV can measure the PWM period and the TIMERx_CH1CV can measure the
PWM duty cycle.
OxCPRE
Capture/
output comparator
Figure 16-43. Output compare logic (x=0,1,2,3) shows the logic circuit of output compare
mode. The relationship between the channel output signal CHx_O and the OxCPRE signal
(more details refer to Channel output prepare signal) is described as blew: The active level
of O0CPRE is high, the output level of CH0_O depends on OxCPRE signal, CHxP bit and
CH0P bit (please refer to the TIMERx_CHCTL2 register for more details).For example,
configure CHxP=0 (the active level of CHx_O is high, the same as OxCPRE), CHxE=1 (the
output of CHx_O is enabled),
If the output of OxCPRE is active(high) level, the output of CHx_O is active(high) level;
If the output of OxCPRE is inactive(low) level, the output of CHx_O is active(low) level.
In output compare mode, the TIMERx can generate timed pulses with programmable position,
polarity, duration and frequency. When the counter matches the value in the TIMERx_CHxCV
register of an output compare channel, the channel (n) output can be set, cleared, or toggled
based on CHxCOMCTL. When the counter reaches the value in the TIMERx_CHxCV register,
the CHxIF bit will be set and the channel (n) interrupt is generated if CHxIE = 1. And the DMA
request will be asserted, if CxCDE=1.
319
GD32E10x User Manual
Step1: Clock configuration. Such as clock source, clock prescaler and so on.
The timing chart below shows the three compare modes toggle/set/clear. CAR=0x63,
CHxVAL=0x3
CNT_CLK
CEN
CNT_REG 00 01 02 03 04 05 …. 62 63 00 01 02 03 04 05 …. 62 63 00 01 02 03 04 05 ….
Overflow
match toggle
OxCPRE
match set
OxCPRE
match clear
OxCPRE
PWM mode
In the PWM output mode (by setting the CHxCOMCTL bit to 3’b110 (PWM mode 0) or to 3’b
111(PWM mode 1)), the channel can generate PWM waveform according to the
TIMERx_CAR registers and TIMERx_CHxCV registers.
Based on the counter mode, PWM can also be divided into EAPWM (Edge-aligned PWM)
and CAPWM (Center-aligned PWM).
320
GD32E10x User Manual
The EAPWM’s period is determined by TIMERx_CAR and the duty cycle is determined
by TIMERx_CHxCV.Figure 16-45. Timing chart of EAPWM shows the EAPWM output and
interrupts waveform.
CAR
CHxVAL
0
PWM MODE0
Cx OUT
PWM MODE1
Cx OUT
Interrupt signal
CHxIF
CHxOF
321
GD32E10x User Manual
Figure 16-46. Timing chart of CAPWM
CAR
CHxVAL
0
PWM MODE0
Cx OUT
PWM MODE1
Cx OUT
Interrupt signal
CAM=2'b01 down only
CHxIF
CHxOF
CAM=2'b10 up only
CHxIF
CHxOF
CAM=2'b11 up/down
CHxIF
CHxOF
As is shown in Figure 16-43. Output compare logic (x=0,1,2,3), when TIMERx is configured
in compare match output mode,a middle signal which is OxCPRE signal (Channel x output
prepare signal) will be generated before the channel outputs signal. The OxCPRE signal type
is defined by configuring the CHxCOMCTL bit. The OxCPRE signal has several types of
output function. These include keeping the original level by configuring the CHxCOMCTL field
to 0x00, setting to high by configuring the CHxCOMCTL field to 0x01, setting to low by
configuring the CHxCOMCTL field to 0x02 or toggling signal by configuring the CHxCOMCTL
field to 0x03 when the counter value matches the content of the TIMERx_CHxCV register.
The PWM mode 0/PWM mode 1 output is another output type of OxCPRE which is setup by
configuring the CHxCOMCTL field to 0x06/0x07. In these modes, the OxCPRE signal level is
changed according to the counting direction and the relationship between the counter value
and the TIMERx_CHxCV content. Refer to the definition of relative bit for more details.
Another special function of the OxCPRE signal is a forced output which can be achieved by
configuring the CHxCOMCTL field to 0x04/0x05. The output can be forced to an
inactive/active level irrespective of the comparison condition between the values of the
counter and the TIMERx_CHxCV.
322
GD32E10x User Manual
Configure the CHxCOMCEN bit to 1 in the TIMERx_CHCTL0 register, the OxCPRE signal
can be forced to 0 when the ETIFP signal derived from the external ETI pin is set to a high
level. The OxCPRE signal will not return to its active level until the next update event occurs.
Quadrature decoder
The quadrature decoder function uses two quadrature inputs CI0 and CI1 derived from the
TIMERx_CH0 and TIMERx_CH1 pins respectively to interact with each other to generate the
counter value. Setting SMC=0x01, 0x02, or 0x03 to select that the counting direction of timer
is determined only by the CI0, only by the CI1, or by the CI0 and the CI1. The DIR bit is
modified by hardware automatically during the voltage level change of each direction
selection source. The mechanism of changing the counter direction is shown in Table 16-5.
Counting direction versus encoder signals. The quadrature decoder can be regarded as
an external clock with a direction selection. This means that the counter counts continuously
from 0 to the counter-reload value. Therefore, users must configure the TIMERx_CAR register
before the counter starts to count.
CI0
CI1
Counter UP down
323
GD32E10x User Manual
Figure 16-48. Example of encoder interface mode with CI0FE0 polarity inverted
CI0
CI1
Counter down UP
Slave controller
The TIMERx can be synchronized with a trigger in several modes including restart mode,
pause mode and event mode which is selected by the SMC[2:0] bits in the TIMERx_SMCFG
register. The input trigger of these modes can be selected by the TRGS[2:0] bits in the
TIMERx_SMCFG register.
324
GD32E10x User Manual
Mode Selection Source Selection Polarity Selection Filter and Prescaler
TIMER_CK
CEN
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 00 01 02
UPIF
ITI0
Pause mode
The counter will be TI0S = 0 (Non-
paused when the xor)[CH0P=0 ] CI0FE0
TRGS[2:0] =3’b101 Filter is bypassed in
trigger input is low, does not invert. The
CI0FE0 is selected. this example.
and it will start when capture event will occur
the trigger input is on the rising edge only.
high.
Exam2
TIMER_CK
CEN
CNT_REG 5E 5F 60 61 62 63
CI0
CI0FE0
TRGIF
Event mode
ETPSC = 1, ETI is
The counter will start
TRGS[2:0] = 3’b111 ETP = 0, the polarity of divided by 2.
Exam3 to count when a rising ETIFP is selected. ETI does not change. ETFC = 0, ETI does not
edge of trigger input
filter.
comes.
325
GD32E10x User Manual
Mode Selection Source Selection Polarity Selection Filter and Prescaler
TIMER_CK
ETI
ETIFP
CNT_REG 5E 5F 60 61
TRGIF
Single pulse mode is enabled by setting SPM in TIMERx_CTL0. If SPM is set, the counter
will be cleared and stopped automatically when the next update event occurs. In order to get
a pulse waveform, the TIMERx is configured to PWM mode or compare mode by
CHxCOMCTL.
Once the timer is set to the single pulse mode, it is not necessary to configure the timer enable
bit CEN in the TIMERx_CTL0 register to 1 to enable the counter. Setting the CEN bit to 1 or
a trigger signal edge can generate a pulse and then keep the CEN bit at a high state until the
update event occurs or the CEN bit is written to 0 by software. If the CEN bit is cleared to 0
by software, the counter will be stopped and its value will be held. If the CEN bit is
automatically cleared to 0 by a hardware update event, the counter will be reinitialized.
In the single pulse mode, the active edge of trigger which sets the CEN bit to 1 will enable the
counter. However, there exists several clock delays to perform the comparison result between
the counter value and the TIMERx_CHxCV value. In order to reduce the delay to a minimum
value, the user can set the CHxCOMFEN bit in TIMERx_CHCTL0/1 register. After a trigger
rising occurs in the single pulse mode, the OxCPRE signal will immediately be forced to the
state which the OxCPRE signal will change to, as the compare match event occurs without
taking the comparison result into account. The CHxCOMFEN bit is available only when the
output channel is configured to the PWM mode 0 or PWM mode 1 and the trigger source is
derived from the trigger signal.
326
GD32E10x User Manual
Figure 16-52. Single pulse mode TIMERx_CHxCV = 0x04, TIMERx_CAR=0x60
TIMER_CK(CNT_CLK)
CEN
CI3
CNT_REG 00 01 02 03 04 05 …. 5F 60 00
O2CPRE
Timers interconnection
Timer DMA mode is the function that configures timer’s register by DMA module. The relative
registers are TIMERx_DMACFG and TIMERx_DMATB. Corresponding DMA request bit
should be asserted to enable DMA request for internal interrupt event. TIMERx will send a
request to DMA when the interrupt event occurs. DMA is configured to M2P (memory to
peripheral) mode and the address of TIMERx_DMATB is configured to PADDR (peripheral
base address), then DMA will access the TIMERx_DMATB. In fact, TIMERx_DMATB register
is only a buffer, timer will map the TIMERx_DMATB to an internal register, appointed by the
field of DMATA in TIMERx_DMACFG. If the field of DMATC in TIMERx_DMACFG is 0 (1
transfer), the timer sends only one DMA request. While if TIMERx_DMATC is not 0, such as
3 (4 transfers), then timer will send 3 more requests to DMA, and DMA will access timer’s
registers DMATA+0x4, DMATA+0x8 and DMATA+0xC at the next 3 accesses to
TIMERx_DMATB. In a word, one-time DMA internal interrupt event asserts, (DMATC+1)
times request will be sent by TIMERx.
If one more DMA request event occurs, TIMERx will repeat the process above.
When the Cortex™-M4 is halted, and the TIMERx_HOLD configuration bit in DBG_CTL
register set to 1, the TIMERx counter stops.
327
GD32E10x User Manual
16.2.5. TIMERx registers(x=1, 2, 3, 4)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
328
GD32E10x User Manual
TIMERx_CHCTL0 register). Only when the counter is counting up, compare
interrupt flag of channels can be set.
11: Center-aligned and counting up/down assert mode. The counter counts in
center-aligned mode and channel is configured in output mode (CHxMS=00 in
TIMERx_CHCTL0 register). Both when the counter is counting up and counting
down, compare interrupt flag of channels can be set.
After the counter is enabled, these bits cannot be switched from 0x00 to non 0x00.
4 DIR Direction
0: Count up
1: Count down
This bit is read only when the timer is configured in Center-aligned mode or Encoder
mode.
329
GD32E10x User Manual
Control register 1 (TIMERx_CTL1)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw
330
GD32E10x User Manual
as TRGO
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw
331
GD32E10x User Manual
10: ETIFP frequency divided by 4
11: ETIFP frequency divided by 8
332
GD32E10x User Manual
2:0 SMC[2:0] Slave mode control
000: Disable slave mode. The slave mode is disabled; The prescaler is clocked
directly by the internal clock (TIMER_CK) when CEN bit is set high.
001: Quadrature decoder mode 0. The counter counts on CI1FE1 edge, while the
direction depends on CI0FE0 level.
010: Quadrature decoder mode 1. The counter counts on CI0FE0 edge, while the
direction depends on CI1FE1 level.
011: Quadrature decoder mode 2. The counter counts on both CI0FE0 and CI1FE1
edges, while the direction depends on the level of the other (CI1FE1 or CI0FE0).
100: Restart mode. The counter is reinitialized and the shadow registers are
updated on the rising edge of the selected trigger input.
101: Pause mode. The trigger input enables the counter clock when it is high and
disables the counter when it is low.
110: Event mode. A rising edge of the trigger input enables the counter. The counter
cannot be disabled by the slave mode controller.
111: External clock mode0. The counter counts on the rising edges of the selected
trigger.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved TRGDEN Reserved CH3DEN CH2DEN CH1DEN CH0DEN UPDEN Reserved TRGIE Reserved CH3IE CH2IE CH1IE CH0IE UPIE
rw rw rw rw rw rw rw rw rw rw rw rw
333
GD32E10x User Manual
0: Disabled
1: Enabled
334
GD32E10x User Manual
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved CH3OF CH2OF CH1OF CH0OF Reserved TRGIF Reserved CH3IF CH2IF CH1IF CH0IF UPIF
rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0
335
GD32E10x User Manual
If channel 0 is in input mode, this flag is set when a capture event occurs. If channel
0 is in output mode, this flag is set when a compare event occurs.
If channel 0 is set to input mode, this bit will be reset by reading TIMERx_CH0CV.
0: No channel 0 interrupt occurred
1: Channel 0 interrupt occurred
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
w w w w w w
336
GD32E10x User Manual
automatically cleared by hardware. When this bit is set, the CH0IF flag will be set,
and the corresponding interrupt or DMA request will be sent if enabled. In addition,
if channel 0 is configured in input mode, the current value of the counter is captured
to TIMERx_CH0CV register, and the CH0OF flag is set if the CH0IF flag has been
set.
0: No generate a channel 0 capture or compare event
1: Generate a channel 0 capture or compare event
0 UPG This bit can be set by software, and automatically cleared by hardware. When this
bit is set, the counter is cleared if the center-aligned or up counting mode is selected,
while in down counting mode it takes the auto-reload value. The prescaler counter
is cleared at the same time.
0: No generate an update event
1: Generate an update event
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
337
GD32E10x User Manual
This bit-field specifies the direction of the channel and the input signal selection.
This bit-field is writable only when the channel is not active (CH1EN bit in
TIMERx_CHCTL2 register is reset).
00: Channel 1 is configured as output.
01: Channel 1 is configured as input, IS1 is connected to CI1FE1.
10: Channel 1 is configured as input, IS1 is connected to CI0FE1.
11: Channel 1 is configured as input, IS1 is connected to ITS. This mode is working
only if an internal trigger input is selected (through TRGS bits in TIMERx_SMCFG
register).
338
GD32E10x User Manual
1: Channel 0 output compare shadow enabled
The PWM mode can be used without validating the shadow register only in single
pulse mode (SPM bit in TIMERx_CTL0 register is set).
339
GD32E10x User Manual
0011: fSAMP= fTIMER_CK, N=8.
0100: fSAMP=fDTS/2, N=6.
0101: fSAMP=fDTS/2, N=8.
0110: fSAMP=fDTS/4, N=6.
0111: fSAMP=fDTS/4, N=8.
1000: fSAMP=fDTS/8, N=6.
1001: fSAMP=fDTS/8, N=8.
1010: fSAMP=fDTS/16, N=5.
1011: fSAMP=fDTS/16, N=6.
1100: fSAMP=fDTS/16, N=8.
1101: fSAMP=fDTS/32, N=5.
1110: fSAMP=fDTS/32, N=6.
1111: fSAMP=fDTS/32, N=8.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
342
GD32E10x User Manual
Refer to CH0CAPPSC description
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
343
GD32E10x User Manual
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved CH3P CH3EN Reserved CH2P CH2EN Reserved CH1P CH1EN Reserved CH0P CH0EN
rw rw rw rw rw rw rw rw
344
GD32E10x User Manual
Counter register (TIMERx_CNT)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw
15:0 CNT[15:0] This bit-field indicates the current counter value. Writing to this bit-field can change
the value of the counter.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSC[15:0]
rw
345
GD32E10x User Manual
This register has to be accessed by word (32-bit).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CARL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH0VAL[15:0]
rw
346
GD32E10x User Manual
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH1VAL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH2VAL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH3VAL[15:0]
rw
348
GD32E10x User Manual
DMA configuration register (TIMERx_DMACFG)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
5’b0_0000: TIMERx_CTL0
5’b0_0001: TIMERx_CTL1
…
In a word: Start Address = TIMERx_CTL0 + DMASAR*4
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DMATB[15:0]
rw
349
GD32E10x User Manual
Bits Fields Descriptions
31:16 Reserved Must be kept at reset value.
16.3.1. Overview
The general level1 timer module (TIMER8,11) is a two-channel timer that supports input
capture and output compare. They can generate PWM signals to control motor or be used for
power management applications. The general level1 timer has a 16-bit counter that can be
used as an unsigned counter.
In addition, the general level1 timers can be programmed and be used for counting, their
external events can be used to drive other timers.
Timers are completely independent with each other, but they may be synchronized to provide
a larger timer with their counter value increasing in unison.
16.3.2. Characteristics
Figure 16-53. General level1 timer block diagram provides details on the internal
configuration of the general level1 timer.
350
GD32E10x User Manual
Figure 16-53. General level1 timer block diagram
CI0
CH0_IN
Input Logic
CH1_IN Synchronizer&Filter Edge selector Prescaler
CI1 &Edge Detector
ITI0
ITI1
ITI2
ITI3
CK_TIMER
Counter TIMERx_CHxCV
Trigger processor
TIMERx_TRGO PSC_CLK
Trigger Selector&Counter TIMER_CK
Quadrate Decoder PSC
Slave mode processor Output Logic
generation of outputs signals in CH0_O
Clock selection
The general level1 TIMER has the capability of being clocked by either the CK_TIMER or an
alternate clock source controlled by SMC (TIMERx_SMCFG bit[2:0]).
SMC[2:0] = 3’b000. Internal clock CK_TIMER is selected as timer clock source which is
from module RCU.
The default clock source is the CK_TIMER for driving the counter prescaler when the slave
mode is disabled (SMC[2:0] = 3’b000). When the CEN is set, the CK_TIMER will be divided
by PSC value to generate PSC_CLK.
In this mode, the TIMER_CK which drives counter’s prescaler to count is equal to CK_TIMER
which is from RCU module.
If the slave mode controller is enabled by setting SMC[2:0] in the TIMERx_SMCFG register
to an available value including 0x1, 0x2, 0x3 and 0x7, the prescaler is clocked by other clock
sources selected by the TRGS[2:0] in the TIMERx_SMCFG register, more details will be
introduced later. When the slave mode control bits SMC[2:0] are set to 0x4, 0x5 or 0x6, the
internal clock TIMER_CK is the counter prescaler driving clock source.
351
GD32E10x User Manual
Figure 16-54. Normal mode, internal clock divided by 1
CK_TIMER
CEN
Reload Pulse
PSC_CLK = TIMER_CK
CNT_REG 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07
SMC[2:0] = 3’b111 (external clock mode 0). External input pin is selected as timer clock
source.
The TIMER_CK, which drives counter’s prescaler to count, can be triggered by the event of
rising or falling edge on the external pin TIMERx_CH0/TIMERx_CH1. This mode can be
selected by setting SMC[2:0] to 0x7 and the TRGS[2:0] to 0x4, 0x5 or 0x6.
And, the counter prescaler can also be driven by rising edge on the internal trigger input pin
ITI0/1/2/3. This mode can be selected by setting SMC[2:0] to 0x7 and the TRGS[2:0] to 0x0,
0x1, 0x2 or 0x3.
Prescaler
The prescaler can divide the timer clock (TIMER_CK) to a counter clock (PSC_CLK) by any
factor ranging from 1 to 65536. It is controlled by prescaler register (TIMERx_PSC) which can
be changed ongoing, but it is adopted at the next update event.
352
GD32E10x User Manual
Figure 16-55. Counter timing diagram with prescaler division change from 1 to 2
TIMER_CK
CEN
PSC_CLK
CNT_REG F7 F8 F9 FA FB FC 0 01 02 03 04
UPG
Reload Pulse
PSC value 0 1
Prescaler BUF 0 1
Prescaler CNT 0 0 1 0 1 0 1 0 1
Up counting mode
In this mode, the counter counts up continuously from 0 to the counter reload value, which is
defined in the TIMERx_CAR register, in a count-up direction. Once the counter reaches the
counter reload value, the counter restarts from 0. The update event is generated each time
when counter overflows. The counting direction bit DIR in the TIMERx_CTL0 register should
be set to 0 for the up counting mode.
Whenever, if the update event software trigger is enabled by setting the UPG bit in the
TIMERx_SWEVG register, the counter value will be initialized to 0 and an update event will
be generated.
If the UPDIS bit in TIMERx_CTL0 register is set, the update event is disabled.
When an update event occurs, all the registers (repetition counter register, auto reload
register, prescaler register) are updated.
The following figures show some examples of the counter behavior for different clock
prescaler factor when TIMERx_CAR=0x63.
353
GD32E10x User Manual
Figure 16-56. Timing chart of up counting mode, PSC=0/1
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
TIMERx_PSC PSC == 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07 08
Hardware set
Update interrupt flag (UPIF)
TIMERx_PSC PSC == 1
CNT_CLK(PSC_CLK)
CNT_REG 5F 60 61 62 63 00 01 02 03
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
ARSE = 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07
Hardware set
Update interrupt flag (UPIF)
Auto-reload register 65 63
ARSE = 1
CNT_REG 5E 5F 60 61 62 63 64 65 00 01 02 ... 62 63 00
Auto-reload register 65 63
354
GD32E10x User Manual
Capture/compare channels
The general level1 timer has two independent channels which can be used as capture inputs
or compare match outputs. Each channel is built around a channel capture compare register
including an input stage, channel controller and an output stage.
Input capture mode allows the channel to perform measurements such as pulse timing,
frequency, period, duty cycle and so on. The input stage consists of a digital filter, a channel
polarity selection, edge detection and a channel prescaler. When a selected edge occurs on
the channel input, the current value of the counter is captured into the TIMERx_CHxCV
register, at the same time the CHxIF bit is set and the channel interrupt is generated if it is
enabled when CHxIE=1.
Edge Detector
Synchronizer Edge selector
&inverter
CI0
D Q D Q D Q
Filter Based on
CH0P&CH0NP
TIMER_CK
CI0FE0 CI0FED
Rising/Falling Rising&Falling
Capture IS0
Clock CI1FE0
Processer Counter Register presclare
(CH0VAL) ITS
CH0IF CH0CAPPSC
CH0_CC_I
CH0IE CH0MS
TIMERx_CC_INT
Capture INT From Other Channal ITI0
ITI1
ITI2
ITI3
CI0FED
First, the input signal of channel (CIx) is synchronized to TIMER_CK signal, and then sampled
by a digital filter to generate a filtered input signal. Then through the edge detector, the rising
or falling edge is detected by configuring CHxP bit. The input capture signal can also be
selected from the input signal of other channel or the internal trigger signal by configuring
CHxMS bits. The IC prescaler makes several input events generate one effective capture
event. On the capture event, TIMERx_CHxCV will store the value of counter.
Result: When the wanted input signal is captured, TIMERx_CHxCV will be set by counter’s
value and CHxIF is asserted. If the CHxIF is 1, the CHxOF will also be asserted. The interrupt
and DMA request will be asserted or not based on the configuration of CHxIE in
TIMERx_DMAINTEN.
The input capture mode can be also used for pulse width measurement from signals on the
TIMERx_CHx pins. For example, PWM signal connects to CI0 input. Select CI0 as channel 0
capture signals by setting CH0MS to 2’b01 in the channel control register (TIMERx_CHCTL0)
and set capture on rising edge. Select CI0 as channel 1 capture signal by setting CH1MS to
2’b10 in the channel control register (TIMERx_CHCTL0) and set capture on falling edge. The
counter is set to restart mode and is restarted on channel 0 rising edge. Then the
TIMERX_CH0CV can measure the PWM period and the TIMERx_CH1CV can measure the
PWM duty cycle.
OxCPRE
Capture/
output comparator
Figure 16-59. Output compare logic (x=0,1) shows the logic circuit of output compare mode.
The relationship between the channel output signal CHx_O and the OxCPRE signal (more
details refer to Channel output prepare signal) is described as blew: The active level of
O0CPRE is high, the output level of CH0_O depends on OxCPRE signal, CHxP bit and CH0P
bit (please refer to theTIMERx_CHCTL2 register for more details).For example, configure
CHxP=0 (the active level of CHx_O is high, the same as OxCPRE), CHxE=1 (the output of
356
GD32E10x User Manual
CHx_O is enabled),
If the output of OxCPRE is active(high) level, the output of CHx_O is active(high) level;
If the output of OxCPRE is inactive(low) level, the output of CHx_O is active(low) level.
In output compare mode, the TIMERx can generate timed pulses with programmable position,
polarity, duration and frequency. When the counter matches the value in the TIMERx_CHxCV
register of an output compare channel, the channel (n) output can be set, cleared, or toggled
based on CHxCOMCTL. When the counter reaches the value in the TIMERx_CHxCV register,
the CHxIF bit will be set and the channel (n) interrupt is generated if CHxIE = 1.
Step1: Clock configuration. Such as clock source, clock prescaler and so on.
The timing chart below show the three compare modes toggle/set/clear. CAR=0x63,
CHxVAL=0x3
357
GD32E10x User Manual
Figure 16-60. Output-compare under three modes
CNT_CLK
CEN
CNT_REG 00 01 02 03 04 05 …. 62 63 00 01 02 03 04 05 …. 62 63 00 01 02 03 04 05 ….
Overflow
match toggle
OxCPRE
match set
OxCPRE
match clear
OxCPRE
PWM mode
In the PWM output mode (by setting the CHxCOMCTL bit to 3’b110 (PWM mode 0) or to 3’b
111(PWM mode 1)), the channel can generate PWM waveform according to the
TIMERx_CAR registers and TIMERx_CHxCV registers.
Based on the counter mode, PWM can also be divided into EAPWM (Edge-aligned PWM)
and CAPWM (Center-aligned PWM).
The EAPWM’s period is determined by TIMERx_CAR and the duty cycle is determined by
TIMERx_CHxCV. Figure 16-61. Timing chart of EAPWM shows the EAPWM output and
interrupts waveform.
The CAPWM’s period is determined by 2*TIMERx_CAR, and the duty cycle is determined by
2*TIMERx_CHxCV. Figure 16-62. Timing chart of CAPWM shows the CAPWM output and
interrupts waveform.
358
GD32E10x User Manual
Figure 16-61. Timing chart of EAPWM
CAR
CHxVAL
0
PWM MODE0
Cx OUT
PWM MODE1
Cx OUT
Interrupt signal
CHxIF
CHxOF
CAR
CHxVAL
0
PWM MODE0
Cx OUT
PWM MODE1
Cx OUT
Interrupt signal
CAM=2'b01 down only
CHxIF
CHxOF
CAM=2'b10 up only
CHxIF
CHxOF
CAM=2'b11 up/down
CHxIF
CHxOF
As is shown in Figure 16-59. Output compare logic (x=0,1), when TIMERx is configured in
compare match output mode,a middle signal which is OxCPRE signal (Channel x output
prepare signal) will be generated before the channel outputs signal. The OxCPRE signal type
is defined by configuring the CHxCOMCTL bit. The OxCPRE signal has several types of
output function. These include keeping the original level by configuring the CHxCOMCTL field
to 0x00, setting to high by configuring the CHxCOMCTL field to 0x01, setting to low by
359
GD32E10x User Manual
configuring the CHxCOMCTL field to 0x02 or toggling signal by configuring the CHxCOMCTL
field to 0x03 when the counter value matches the content of the TIMERx_CHxCV register.
The PWM mode 0/PWM mode 1 output is another output type of OxCPRE which is setup by
configuring the CHxCOMCTL field to 0x06/0x07. In these modes, the OxCPRE signal level is
changed according to the counting direction and the relationship between the counter value
and the TIMERx_CHxCV content. Refer to the definition of relative bit for more details.
Another special function of the OxCPRE signal is a forced output which can be achieved by
configuring the CHxCOMCTL field to 0x04/0x05. The output can be forced to an
inactive/active level irrespective of the comparison condition between the values of the
counter and the TIMERx_CHxCV.
Slave controller
The TIMERx can be synchronized with a trigger in several modes including restart mode,
pause mode and event mode which is selected by the SMC[2:0] bits in the TIMERx_SMCFG
register. The input trigger of these modes can be selected by the TRGS[2:0] bits in the
TIMERx_SMCFG register.
360
GD32E10x User Manual
Mode Selection Source Selection Polarity Selection Filter and Prescaler
TIMER_CK
CEN
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 00 01 02
UPIF
ITI0
Pause mode
TI0S=0 (Non-xor)
The counter will be
[CH0NP=0, CH0P=0]
paused when the
TRGS[2:0] =3’b101 CI0FE0 does not invert. Filter is bypassed in
trigger input is low,
CI0FE0 is selected. The capture event will this example.
and it will start when
occur on the rising edge
the trigger input is
only.
high.
Exam2
TIMER_CK
CEN
CNT_REG 5E 5F 60 61 62 63
CI0
CI0FE0
TRGIF
Event mode
ETPSC = 1, ETI is
The counter will start
TRGS[2:0] =3’b111 ETP = 0, the polarity of divided by 2.
Exam3 to count when a rising
ETIFP is selected. ETI does not change. ETFC = 0, ETI does
edge of trigger input
not filter.
comes.
361
GD32E10x User Manual
Mode Selection Source Selection Polarity Selection Filter and Prescaler
TIMER_CK
CI0FE0
CNT_REG 5E 5F 60 61
TRGIF
Single pulse mode is enabled by setting SPM in TIMERx_CTL0. If SPM is set, the counter
will be cleared and stopped automatically when the next update event occurs. In order to get
a pulse waveform, the TIMERx is configured to PWM mode or compare mode by
CHxCOMCTL.
Once the timer is set to the single pulse mode, it is not necessary to configure the timer enable
bit CEN in the TIMERx_CTL0 register to 1 to enable the counter. Setting the CEN bit to 1 or
a trigger signal edge can generate a pulse and then keep the CEN bit at a high state until the
update event occurs or the CEN bit is written to 0 by software. If the CEN bit is cleared to 0
by software, the counter will be stopped and its value will be held. If the CEN bit is
automatically cleared to 0 by a hardware update event, the counter will be reinitialized.
In the single pulse mode, the active edge of trigger which sets the CEN bit to 1 will enable the
counter. However, there exists several clock delays to perform the comparison result between
the counter value and the TIMERx_CHxCV value. In order to reduce the delay to a minimum
value, the user can set the CHxCOMFEN bit in TIMERx_CHCTL0/1 register. After a trigger
rising occurs in the single pulse mode, the OxCPRE signal will immediately be forced to the
state which the OxCPRE signal will change to, as the compare match event occurs without
taking the comparison result into account. The CHxCOMFEN bit is available only when the
output channel is configured to the PWM mode 0 or PWM mode 1 and the trigger source is
derived from the trigger signal.
362
GD32E10x User Manual
Figure 16-66. Single pulse mode TIMERx_CHxCV = 0x04, TIMERx_CAR=0x60
TIMER_CK(CNT_CLK)
CEN
CI3
CNT_REG 00 01 02 03 04 05 …. 5F 60 00
O2CPRE
Timers interconnection
When the Cortex™-M4 is halted, and the TIMERx_HOLD configuration bit in DBG_CTL
register set to 1, the TIMERx counter stops.
363
GD32E10x User Manual
16.3.5. TIMERx registers (x=8, 11)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
364
GD32E10x User Manual
– The counter generates an overflow or underflow event
– The slave mode controller generates an update event.
1: When enabled, only counter overflow/underflow generates an update interrupt or
a DMA request.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
365
GD32E10x User Manual
1: Master-slave mode enabled
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
366
GD32E10x User Manual
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
367
GD32E10x User Manual
software.
0: No over capture interrupt occurred
1: Over capture interrupt occurred
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
w w w w
368
GD32E10x User Manual
31:7 Reserved Must be kept at reset value.
0 UPG This bit can be set by software, and automatically cleared by hardware. When this
bit is set, the counter is cleared. The prescaler counter is cleared at the same time.
0: No generate an update event
1: Generate an update event
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
369
GD32E10x User Manual
31:15 Reserved Must be kept at reset value.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
372
GD32E10x User Manual
Bits Fields Descriptions
31:8 Reserved Must be kept at reset value.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw
15:0 CNT[15:0] This bit-field indicates the current counter value. Writing to this bit-field can change
the value of the counter.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSC[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
374
GD32E10x User Manual
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CARL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH0VAL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
375
GD32E10x User Manual
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH1VAL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
376
GD32E10x User Manual
16.4. General level2 timer (TIMERx, x=9, 10, 12, 13)
16.4.1. Overview
The general level2 timer module (TIMER9, 10, 12, 13) is a one-channel timer that supports
input capture and output compare. They can generate PWM signals to control motor or be
used for power management applications. The general level2 timer has a 16-bit counter that
can be used as an unsigned counter.
In addition, the general level2 timers can be programmed and be used for counting, their
external events can be used to drive other timers.
16.4.2. Characteristics
Figure 16-67. General level2 timer block diagram provides details on the internal
configuration of the general level2 timer.
377
GD32E10x User Manual
Figure 16-67. General level2 timer block diagram
Trigger Selector&Counter
Counter TIMERx_CHxCV
TIMERx_TRGO TIMER_CK
PSC_CLK
PSC
Clock selection
The general level2 TIMER can only being clocked by the CK_TIMER.
The general level2 TIMER has only one clock source which is the internal CK_TIMER, used
to drive the counter prescaler. When the CEN is set, the CK_TIMER will be divided by PSC
value to generate PSC_CLK.
The TIMER_CK, driven counter’s prescaler to count, is equal to CK_TIMER which is from
RCU
378
GD32E10x User Manual
Figure 16-68. Normal mode, internal clock divided by 1
CK_TIMER
CEN
Reload Pulse
PSC_CLK = TIMER_CK
CNT_REG 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07
Prescaler
The prescaler can divide the timer clock (TIMER_CK) to a counter clock (PSC_CLK) by any
factor ranging from 1 to 65536. It is controlled by prescaler register (TIMERx_PSC) which can
be changed ongoing, but it is adopted at the next update event.
Figure 16-69. Counter timing diagram with prescaler division change from 1 to 2
TIMER_CK
CEN
PSC_CLK
CNT_REG F7 F8 F9 FA FB FC 0 01 02 03 04
UPG
Reload Pulse
PSC value 0 1
Prescaler BUF 0 1
Prescaler CNT 0 0 1 0 1 0 1 0 1
379
GD32E10x User Manual
Up counting mode
In this mode, the counter counts up continuously from 0 to the counter reload value, which is
defined in the TIMERx_CAR register, in a count-up direction. Once the counter reaches the
counter reload value, the counter restarts from 0. The update event is generated each time
when counter overflows. The counting direction bit DIR in the TIMERx_CTL0 register should
be set to 0 for the up counting mode.
Whenever, if the update event software trigger is enabled by setting the UPG bit in the
TIMERx_SWEVG register, the counter value will be initialized to 0 and an update event will
be generated.
If the UPDIS bit in TIMERx_CTL0 register is set, the update event is disabled.
When an update event occurs, all the registers (repetition counter register, auto reload
register, prescaler register) are updated.
The following figures show some examples of the counter behavior for different clock
prescaler factor when TIMERx_CAR=0x63.
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
TIMERx_PSC PSC == 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07 08
Hardware set
Update interrupt flag (UPIF)
TIMERx_PSC PSC == 1
CNT_CLK(PSC_CLK)
CNT_REG 5F 60 61 62 63 00 01 02 03
380
GD32E10x User Manual
Figure 16-71. Timing chart of up counting, change TIMERx_CAR ongoing
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
ARSE = 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07
Hardware set
Update interrupt flag (UPIF)
Auto-reload register 65 63
ARSE = 1
CNT_REG 5E 5F 60 61 62 63 64 65 00 01 02 ... 62 63 00
Auto-reload register 65 63
Capture/compare channels
The general level2 timer has one independent channel which can be used as capture inputs
or compare match outputs. Each channel is built around a channel capture compare register
including an input stage, channel controller and an output stage.
Input capture mode allows the channel to perform measurements such as pulse timing,
frequency, period, duty cycle and so on. The input stage consists of a digital filter, a channel
polarity selection, edge detection and a channel prescaler. When a selected edge occurs on
the channel input, the current value of the counter is captured into the TIMERx_CHxCV
register, at the same time the CHxIF bit is set and the channel interrupt is generated if it is
enabled when CHxIE=1.
381
GD32E10x User Manual
Figure 16-72. Input capture logic
Edge Detector
Synchronizer Edge selector
&inverter
CI0
D Q D Q D Q
Filter Based on
CH0P&CH0NP
TIMER_CK
CI0FE0 CI0FED
Rising/Falling Rising&Falling
Capture IS0
Clock CI1FE0
Processer Counter Register presclare
(CH0VAL) ITS
CH0IF CH0CAPPSC
CH0_CC_I
CH0IE CH0MS
TIMERx_CC_INT
Capture INT From Other Channal ITI0
ITI1
ITI2
ITI3
CI0FED
First, the input signal of channel (CIx) is synchronized to TIMER_CK signal, and then sampled
by a digital filter to generate a filtered input signal. Then through the edge detector, the rising
or falling edge is detected by configuring CHxP bit. The input capture signal can also be
selected from the input signal of other channel or the internal trigger signal by configuring
CHxMS bits. The IC prescaler makes several input events generate one effective capture
event. On the capture event, TIMERx_CHxCV will store the value of counter.
Result: When the wanted input signal is captured, TIMERx_CHxCV will be set by counter’s
value and CHxIF is asserted. If the CHxIF is 1, the CHxOF will also be asserted. The interrupt
382
GD32E10x User Manual
and DMA request will be asserted or not based on the configuration of CHxIE in
TIMERx_DMAINTEN.
The input capture mode can be also used for pulse width measurement from signals on the
TIMERx_CHx pins. For example, PWM signal connects to CI0 input. Select CI0 as channel 0
capture signals by setting CH0MS to 2’b01 in the channel control register (TIMERx_CHCTL0)
and set capture on rising edge. Select CI0 as channel 1 capture signal by setting CH1MS to
2’b10 in the channel control register (TIMERx_CHCTL0) and set capture on falling edge. The
counter is set to restart mode and is restarted on channel 0 rising edge. Then the
TIMERX_CH0CV can measure the PWM period and the TIMERx_CH1CV can measure the
PWM duty cycle.
O0CPRE
Capture/
output comparator
Figure 16-73. Output compare logic shows the logic circuit of output compare mode. The
relationship between the channel output signal CHx_O and the OxCPRE signal (more details
refer to Channel output prepare signal) is described as blew: The active level of O0CPRE
is high, the output level of CH0_O depends on OxCPRE signal, CHxP bit and CH0P bit
(please refer to the TIMERx_CHCTL2 register for more details).For example, configure
CHxP=0 (the active level of CHx_O is high, the same as OxCPRE), CHxE=1 (the output of
CHx_O is enabled),
If the output of OxCPRE is active(high) level, the output of CHx_O is active(high) level;
If the output of OxCPRE is inactive(low) level, the output of CHx_O is active(low) level.
In output compare mode, the TIMERx can generate timed pulses with programmable position,
polarity, duration and frequency. When the counter matches the value in the TIMERx_CHxCV
register of an output compare channel, the channel (n) output can be set, cleared, or toggled
based on CHxCOMCTL. When the counter reaches the value in the TIMERx_CHxCV register,
the CHxIF bit will be set and the channel (n) interrupt is generated if CHxIE = 1.
Step1: Clock configuration. Such as clock source, clock prescaler and so on.
383
GD32E10x User Manual
Set the shadow enable mode by CHxCOMSEN.
Set the output mode (set/clear/toggle) by CHxCOMCTL.
Select the active polarity by CHxP.
Enable the output by CHxEN.
The timing chart below show the three compare modes toggle/set/clear. CAR=0x63,
CHxVAL=0x3
CNT_CLK
CEN
CNT_REG 00 01 02 03 04 05 …. 62 63 00 01 02 03 04 05 …. 62 63 00 01 02 03 04 05 ….
Overflow
match toggle
OxCPRE
match set
OxCPRE
match clear
OxCPRE
As is shown in Figure 16-73. Output compare logic, when TIMERx is configured in compare
match output mode,a middle signal which is OxCPRE signal (Channel x output prepare signal)
will be generated before the channel outputs signal. The OxCPRE signal type is defined by
configuring the CHxCOMCTL bit. The OxCPRE signal has several types of output function.
These include keeping the original level by configuring the CHxCOMCTL field to 0x00, setting
to high by configuring the CHxCOMCTL field to 0x01, setting to low by configuring the
CHxCOMCTL field to 0x02 or toggling signal by configuring the CHxCOMCTL field to 0x03
when the counter value matches the content of the TIMERx_CHxCV register.
The PWM mode 0/PWM mode 1 output is another output type of OxCPRE which is setup by
384
GD32E10x User Manual
configuring the CHxCOMCTL field to 0x06/0x07. In these modes, the OxCPRE signal level is
changed according to the counting direction and the relationship between the counter value
and the TIMERx_CHxCV content. Refer to the definition of relative bit for more details.
Another special function of the OxCPRE signal is a forced output which can be achieved by
configuring the CHxCOMCTL field to 0x04/0x05. The output can be forced to an
inactive/active level irrespective of the comparison condition between the values of the
counter and the TIMERx_CHxCV.
When the Cortex™-M4 is halted, and the TIMERx_HOLD configuration bit in DBG_CTL
register set to 1, the TIMERx counter stops.
385
GD32E10x User Manual
16.4.5. TIMERx registers (x=9, 10, 12, 13)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw
386
GD32E10x User Manual
1: When enabled, only counter overflow/underflow generates an update interrupt or
a DMA request.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
387
GD32E10x User Manual
Interrupt flag register (TIMERx_INTF)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
388
GD32E10x User Manual
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
w w
0 UPG This bit can be set by software, and automatically cleared by hardware. When this
bit is set, the counter is cleared. The prescaler counter is cleared at the same time.
0: No generate an update event
1: Generate an update event
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH0COM CH0COM
Reserved CH0COMCTL[2:0]
Reserved. SEN FEN CH0MS[1:0]
CH0CAPFLT[3:0] CH0CAPPSC[1:0]
rw rw rw
390
GD32E10x User Manual
00: Channel 0 is configured as output.
01: Channel 0 is configured as input, IS0 is connected to CI0FE0.
10: Channel 0 is configured as input, IS0 is connected to CI1FE0.
11: Channel 0 is configured as input, IS0 is connected to ITS. This mode is working
only if an internal trigger input is selected (through TRGS bits in TIMERx_SMCFG
register).
391
GD32E10x User Manual
Channel control register 2 (TIMERx_CHCTL2)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw
15:0 CNT[15:0] This bit-field indicates the current counter value. Writing to this bit-field can change
the value of the counter.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSC[15:0]
rw
393
GD32E10x User Manual
Counter auto reload register (TIMERx_CAR)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CARL[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CH0VAL[15:0]
rw
394
GD32E10x User Manual
Configuration register (TIMERx_CFG)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
16.5.1. Overview
The basic timer module (TIMER5, TIMER 6) has a 16-bit counter that can be used as an
unsigned counter. The basic timer can be configured to generate a DMA request and a TRGO
to connect to DAC.
16.5.2. Characteristics
395
GD32E10x User Manual
16.5.3. Block diagram
Figure 16-75. Basic timer block diagram provides details on the internal configuration of
the basic timer.
Clock selection
The basic TIMER can only be clocked by the internal timer clock CK_TIMER, which is from
the source named CK_TIMER in RCU
The TIMER_CK, driven counter’s prescaler to count, is equal to CK_TIMER used to drive the
counter prescaler. When the CEN is set, the CK_TIMER will be divided by PSC value to
generate PSC_CLK.
CK_TIMER
CEN
Reload Pulse
PSC_CLK = TIMER_CK
CNT_REG 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07
396
GD32E10x User Manual
Prescaler
The prescaler can divide the timer clock (TIMER_CK) to a counter clock (PSC_CLK) by any
factor ranging from 1 to 65536. It is controlled by prescaler register (TIMERx_PSC) which can
be changed ongoing, but it is adopted at the next update event.
Figure 16-77. Counter timing diagram with prescaler division change from 1 to 2
TIMER_CK
CEN
PSC_CLK
CNT_REG F7 F8 F9 FA FB FC 0 01 02 03 04
UPG
Reload Pulse
PSC value 0 1
Prescaler BUF 0 1
Prescaler CNT 0 0 1 0 1 0 1 0 1
Up counting mode
In this mode, the counter counts up continuously from 0 to the counter reload value, which is
defined in the TIMERx_CAR register, in a count-up direction. Once the counter reaches the
counter reload value, the counter restarts from 0. The update event is generated each time
when counter overflows. The counting direction bit DIR in the TIMERx_CTL0 register should
be set to 0 for the up counting mode.
Whenever, if the update event software trigger is enabled by setting the UPG bit in the
TIMERx_SWEVG register, the counter value will be initialized to 0 and an update event will
be generated.
If the UPDIS bit in TIMERx_CTL0 register is set, the update event is disabled.
When an update event occurs, all the registers (repetition counter register, auto reload
register, prescaler register) are updated.
The following figures show some examples of the counter behavior for different clock
prescaler factor when TIMERx_CAR=0x63.
397
GD32E10x User Manual
Figure 16-78. Timing chart of up counting mode, PSC=0/1
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
TIMERx_PSC PSC == 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07 08
Hardware set
Update interrupt flag (UPIF)
TIMERx_PSC PSC == 1
CNT_CLK(PSC_CLK)
CNT_REG 5F 60 61 62 63 00 01 02 03
TIMER_CK
CEN
CNT_CLK(PSC_CLK)
ARSE = 0
CNT_REG 5E 5F 60 61 62 63 00 01 02 03 04 05 06 07
Hardware set
Update interrupt flag (UPIF)
Auto-reload register 65 63
ARSE = 1
CNT_REG 5E 5F 60 61 62 63 64 65 00 01 02 ... 62 63 00
Auto-reload register 65 63
398
GD32E10x User Manual
Timer debug mode
When the Cortex™-M4 is halted, and the TIMERx_HOLD configuration bit in DBG_CTL
register set to 1, the TIMERx counter stops.
399
GD32E10x User Manual
16.5.5. TIMERx registers (x=5, 6)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw
400
GD32E10x User Manual
– The UPG bit is set
– The counter generates an overflow or underflow event
– The slave mode controller generates an update event.
1: Update event disable. The buffered registers keep their value, while the counter
and the prescaler are reinitialized if the UG bit is set or the slave mode controller
generates a hardware reset event.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw
401
GD32E10x User Manual
3:0 Reserved Must be kept at reset value.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved UPIF
rc_w0
402
GD32E10x User Manual
This bit is set by hardware when an update event occurs and cleared by software.
0: No update interrupt occurred
1: Update interrupt occurred
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved UPG
0 UPG This bit can be set by software, and automatically cleared by hardware. When this
bit is set, the counter is cleared. The prescaler counter is cleared at the same time.
0: No generate an update event
1: Generate an update event
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CNT[15:0]
rw
15:0 CNT[15:0] This bit-field indicates the current counter value. Writing to this bit-field can change
the value of the counter.
403
GD32E10x User Manual
Prescaler register (TIMERx_PSC)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PSC[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CARL[15:0]
rw
404
GD32E10x User Manual
17. Universal synchronous/asynchronous receiver
/transmitter (USART)
17.1. Overview
Besides the standard asynchronous receiver and transmitter mode, the USART implements
several other types of serial data exchange modes, such as IrDA (infrared data association)
SIR mode, smartcard mode, LIN (local interconnection network) mode and half-duplex
synchronous mode. It also supports multiprocessor communication mode, and hardware flow
control protocol (CTS/RTS). The data frame can be transferred from LSB or MSB bit. The
polarity of the TX/RX pins can be configured independently and flexibly.
The USART supports DMA function for high-speed data communication, except UART4.
17.2. Characteristics
405
GD32E10x User Manual
– Block mode (T=1)
– Direct and inverse convention
Multiprocessor communication
– Enter into mute mode if address match does not occur
– Wake up from mute mode by idle frame or address match detection
Various status flags:
– Flags for transfer detection: Receive buffer not empty (RBNE), Transmit buffer
empty (TBE), transfer complete (TC), and busy (BSY).
– Flags for error detection: overrun error (ORERR), noise error (NERR), frame error
(FERR) and parity error (PERR)
– Flag for hardware flow control: CTS changes (CTSF)
– Flag for LIN mode: LIN break detected (LBDF)
– Flag for multiprocessor communication: IDLE frame detected ( IDLEF)
– Flags for smartcard block mode: end of block (EBF) and receiver timeout (RTF)
– Interrupt occurs at these events when the corresponding interrupt enable bits are
set
While USART0/1/2 is fully implemented, UART3/4 is only partially implemented with the
following features not supported.
Smartcard mode
Synchronous mode
Hardware flow control protocol (CTS/RTS)
Configurable data polarity
The interface is externally connected to another device by the main pins listed in Table 17-1.
Description of USART important pins.
406
GD32E10x User Manual
Figure 17-1. USART module block diagram
CPU/DMA
W R
Transmit
TX Shift
Register
SW_RX IrDA USART Data
Block Receive Register
RX Shift
Register
USART Control
Registers
USART
Address
Transmitter Transmitter
clock Controller
Receiver Receiver
/16 Wakeup Unit
clock Controller
PCLK
/USARTDIV
The USART frame starts with a start bit and ends up with a number of stop bits. The length
of the data frame is configured by the WL bit in the USART_CTL0 register. The last data bit
can be used as parity check bit by setting the PCEN bit in USART_CTL0 register. When the
WL bit is reset, the parity bit is the 7th bit. When the WL bit is set, the parity bit is the 8th bit.
The method of calculating the parity bit is selected by the PM bit in USART_CTL0 register.
Figure 17-2. USART character frame (8 bits data and 1 stop bit)
CLOCK
Data frame
or parity bit
Start
bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 Stop Start
Stop Start
Break frame
In transmission and reception, the number of stop bits can be configured by the STB[1:0]
bits in the USART_CTL1 register.
The break frame structure is a number of low bits followed by the configured number of stop
bits. The transfer speed of a USART frame depends on the frequency of the PCLK, the
configuration of the baud rate generator and the oversampling mode.
The baud-rate divider is a 16-bit number which consists of a 12-bit integer and a 4-bit
fractional part. The number formed by these two values is used by the baud rate generator to
determine the bit period. Having a fractional baud-rate divider allows the USART to generate
all the standard baud rates.
When oversampled by 16, the baud-rate divider (USARTDIV) has the following relationship
with the peripheral clock:
PCLK
USARTDIV= (17-1)
16×Baud Rate
The peripheral clock is PCLK2 for USART0 and PCLK1 for USART1/2 and UART3/4. The
peripheral clock must be enabled through the clock control unit before enabling the USART.
USARTDIV=33+13/16=33.81.
USART_BUAD=0x1E6.
Note: If the roundness of FRADIV is 16 (overflow), the carry must be added to the
integer part.
If the transmit enable bit (TEN) in USART_CTL0 register is set, when the transmit data buffer
is not empty, the transmitter shifts out the transmit data frame through the TX pin. The polarity
of the TX pin can be configured by the TINV bit in the USART_CTL3 register. Clock pulses
can output through the CK pin.
After the TEN bit is set, an idle frame will be sent. The TEN bit should not be cleared while
the transmission is ongoing.
After power on, the TBE bit is high by default. Data can be written to the USART_DATA when
408
GD32E10x User Manual
the TBE bit in the USART_STAT0 register is asserted. The TBE bit is cleared by writing
USART_DATA register and it is set by hardware after the data is put into the transmit shift
register. If a data is written to the USART_DATA register while a transmission is ongoing, it
will be firstly stored in the transmit buffer, and transferred to the transmit shift register after
the current transmission is done. If a data is written to the USART_DATA register while no
transmission is ongoing, the TBE bit will be cleared and set soon, because the data will be
transferred to the transmit shift register immediately.
If a frame is transmitted and the TBE bit is asserted, the TC bit of the USART_STAT0 register
will be set. An interrupt will be generated if the corresponding interrupt enable bit (TCIE) is
set in the USART_CTL0 register.
The USART transmit procedure is shown in Figure 17-3. USART transmit procedure. The
software operating process is as follows:
3. Set the STB[1:0] bits in USART_CTL1 to configure the number of stop bits.
It is necessary to wait for the TC bit to be asserted before disabling the USART or entering
the power saving mode. This bit can be cleared by a software sequence: reading the
USART_STAT0 register and then writing the USART_DATA register. If the multibuffer
communication is selected (DENT=1), this bit can also be cleared by writing 0 directly.
409
GD32E10x User Manual
17.3.4. USART receiver
After power on, the USART receiver can be enabled by the following procedure:
After being enabled, the receiver receives a bit stream after a valid start pulse has been
detected. Detection on noisy error, parity error, frame error and overrun error is performed
during the reception of a frame.
The software can get the received data by reading the USART_DATA register directly, or
through DMA. The RBNE bit is cleared by a read operation on the USART_DATA register,
whatever it is performed by software directly, or through DMA.
The REN bit should not be disabled when reception is ongoing, or the current frame will be
lost.
By default, the receiver gets three samples to evaluate the value of a frame bit. While in the
oversampling 16 mode, the 7th, 8th, and 9th samples are used. If two or more samples of a
frame bit is 0, the frame bit is confirmed as a 0, else 1. If the value of the three samples of
any bit are not the same, whatever it is a start bit, data bit, parity bit or stop bit, a noisy error
(NERR) will be generated for the frame. An interrupt will be generated if the receive DMA is
enabled and the ERRIE bit in USART_CTL2 register is set.
oversampling
10
11
12
13
14
15
0
16 mode
sample bits
If the parity check function is enabled by setting the PCEN bit in the USART_CTL0 register,
the receiver calculates the expected parity value while receiving a frame. The received parity
bit will be compared with this expected value. If they are not the same, the parity error (PERR)
bit in USART_STAT0 register will be set. An interrupt is generated if the PERRIE bit in
410
GD32E10x User Manual
USART_CTL0 register is set.
If the RX pin is evaluated as 0 during a stop bit, the frame error (FERR) bit in USART_STAT0
register will be set. An interrupt will be generated if the receive DMA is enabled and the ERRIE
bit in USART_CTL2 register is set.
When a frame is received, if the RBNE bit is not cleared yet, the last frame will not be stored
in the receive data buffer. The overrun error (ORERR) bit in USART_STAT0 register will be
set. An interrupt is generated, if the receive DMA is enabled and the ERRIE bit in
USART_CTL2 register is set, or if the RBNEIE is set.
The RBNE, NERR, PERR, FERR and ORERR flags are always set at the same time in a
reception. If the receive DMA is not enabled, software can check NERR, PERR, FERR and
ORERR flags when serving the RBNE interrupt.
To reduce the burden of the processor, DMA can be used to access the transmitting and
receiving data buffer. The DENT bit in USART_CTL2 is used to enable the DMA transmission,
and the DENR bit in USART_CTL2 is used to enable the DMA reception.
When DMA is used for USART transmission, DMA transfers data from internal SRAM to the
transmit data buffer of the USART. The configuration steps are shown in Figure 17-5.
411
GD32E10x User Manual
Configuration steps when using DMA for USART transmission.
Figure 17-5. Configuration steps when using DMA for USART transmission
After all of the data frames are transmitted, the TC bit in USART_STAT0 is set. An interrupt
occurs if the TCIE bit in USART_CTL0 is set.
When DMA is used for USART reception, DMA transfers data from the receive data buffer of
the USART to the internal SRAM. The configuration steps are shown in Figure 17-6.
Configuration steps when using DMA for USART reception. If the ERRIE bit in
USART_CTL2 is set, interrupts can be generated by the Error status bits (FERR, ORERR
412
GD32E10x User Manual
and NERR) in USART_STAT0.
Figure 17-6. Configuration steps when using DMA for USART reception
When the number of the data received by USART reaches the DMA transfer number, an end
of transfer interrupt will be generated in the DMA module.
The hardware flow control function is realized by the nCTS and nRTS pins. The RTS flow
control is enabled by writing ‘1’ to the RTSEN bit in USART_CTL2 and the CTS flow control
is enabled by writing ‘1’ to the CTSEN bit in USART_CTL2.
TX RX
USART 1 USART 2
RX TX
The USART receiver outputs the nRTS, which reflects the status of the receive buffer. When
413
GD32E10x User Manual
data frame is received, the nRTS signal goes high to prevent the transmitter from sending
next frame. The nRTS signal keeps high when the receive buffer is full, and can be cleared
by reading the USART_DATA register.
The USART transmitter monitors the nCTS input pin to decide whether a data frame can be
transmitted. If the TBE bit in USART_STAT0 is ‘0’ and the nCTS signal is low, the transmitter
transmits the data frame. When the nCTS signal goes high during a transmission, the
transmitter stops after the current transmission is accomplished.
RX
start data 1 stop idle start data 2 stop idle
TX data 1 stop start data 2 stop idle start data 3 stop idle
If the CTS flow control is enabled, the CTSF bit in USART_STAT0 is set when the nCTS pin
toggles. An interrupt is generated if the CTSIE bit in USART_CTL2 is set.
If a USART is in mute mode, all of the receive status bits cannot be set. Software can wake
up the USART by clearing the RWU bit.
The USART can also be woken up by hardware by one of the two methods: idle frame method
and address match method.
The idle frame wake up method is selected by default. When an idle frame is detected on the
RX pin, the hardware clears the RWU bit and exits the mute mode. When it is woken up by
an idle frame, the IDLEF bit in USART_STAT0 will not be set.
When the WM bit of in USART_CTL0 register is set, the MSB bit of a frame is detected as the
address flag. If the address flag is high, the frame is treated as an address frame. If the
address flag is low, the frame is treated as a data frame. If the LSB 4 bits of an address frame
are the same as the ADDR[3:0] bits in the USART_CTL1 register, the hardware will clear the
RWU bit and exits the mute mode. The RBNE bit will be set when the frame that wakes up
414
GD32E10x User Manual
the USART. The status bits are available in the USART_STAT0 register. If the LSB 4 bits of
an address frame differ from the ADDR[3:0] bits in the USART_CTL1 register, the hardware
sets the RWU bit and enters mute mode automatically. In this situation, the RBNE bit is not
set.
If the address match method is selected, the receiver does not check the parity value of an
address frame by default. If the PCEN bit in USART_CTL0 is set, the MSB bit will be checked
as the parity bit, and the bit preceding the MSB bit is detected as the address bit.
The local interconnection network mode is enabled by setting the LMEN bit in USART_CTL1.
The CKEN, WL, STB[1:0] bits in USART_CTL1 and the SCEN, HDEN, IREN bits in
USART_CTL2 should be cleared in LIN mode.
When transmitting a normal data frame, the transmission procedure is the same as the normal
USART mode. When the SBKCMD bit in USART_CTL0 is set, the USART transmits 13 ‘0’
bits continuously, followed by 1 stop bit.
The break detection function is totally independent of the normal USART receiver. So a break
frame can be detected during the idle state or during a frame. The expected length of a break
frame can be selected by configuring LBLEN bit in USART_CTL1. When the RX pin is
detected at low state for a time that is equal to or longer than the expected break frame length
(10 bits when LBLEN=0, or 11 bits when LBLEN=1), the LBDF bit in USART_STAT0 is set.
An interrupt occurs if the LBDIE bit in USART_CTL1 is set.
As shown in Figure 17-9. Break frame occurs during idle state, if a break frame occurs
during the idle state on the RX pin, the USART receiver will receive an all ‘0’ frame, with an
asserted FERR status.
RX pin
1 frame time
FERR
LBDF
As shown in Figure 17-10. Break frame occurs during a frame, if a break frame occurs
415
GD32E10x User Manual
during a frame on the RX pin, the FERR status will be asserted for the current frame.
1 frame time
FERR
LBDF
The USART can be used for full-duplex synchronous serial communications only in master
mode, by setting the CKEN bit in USART_CTL1. The LMEN bit in USART_CTL1 and SCEN,
HDEN, IREN bits in USART_CTL2 should be cleared in synchronous mode. The CK pin is
the clock output of the synchronous USART transmitter, and can be only activated when the
TEN bit is enabled. No clock pulse will be sent through the CK pin during the transmission of
the start bit and stop bit. The CLEN bit in USART_CTL1 can be used to determine whether
the clock is output or not during the last (address flag) bit transmission. The CPH bit in
USART_CTL1 can be used to determine whether data is captured on the first or the second
clock edge. The CPL bit in USART_CTL1 can be used to configure the clock polarity in the
USART synchronous idle state.
The CPL, CPH and CLEN bits in USART_CTL1 determine the waveform on the CK pin.
Software can only change them when the USART is disabled (UEN=0).
If the REN bit in USART_CTL0 is set, the receiver works differently from the normal USART
reception method. The receiver samples the data on the capture edge of the CK pin without
any oversampling.
RX Data output
TX Data input
USART Device
(master mode) (slave mode)
CK Clock input
416
GD32E10x User Manual
Figure 17-12. 8-bit format USART synchronous waveform (CLEN=1)
CK pin(CPL=1, CPH=0)
The IrDA mode is enabled by setting the IREN bit in USART_CTL2. The LMEN, STB[1:0],
CKEN bits in USART_CTL1 and HDEN, SCEN bits in USART_CTL2 should be cleared in
IrDA mode.
In IrDA mode, the USART transmission data frame is modulated in the SIR transmit encoder
and transmitted to the infrared LED through the TX pin. The SIR receive decoder receives the
modulated signal from the infrared LED through the RX pin, and puts the demodulated data
frame to the USART receiver. The baud rate should not be larger than 115200 for the encoder.
Receive RX pin
1 Decoder
RX
0
Normal Infrared
USART IREN LED
TX
0 TX pin
Transmit
1
Encoder
SIR MODULE
In IrDA mode, the polarity of the TX pin and RX pin is different. The TX pin is usually at low
state, while the RX pin is usually at high state. The IrDA pins keep stable to represent the
logic ‘1’, while an infrared light pulse on the IrDA pins (a Return to Zero signal) represents the
logic ‘0’. The pulse width should be 3/16 of a bit period. The IrDA could not detect any pulse
417
GD32E10x User Manual
if the pulse width is less than 1 PSC clock. While it can detect a pulse by chance if the pulse
width is greater than 1 but smaller than 2 times of PSC clock.
Because the IrDA is a half-duplex protocol, the transmission and the reception should not be
carried out at the same time in the IrDA SIR ENDEC block.
Normal 0 1 0 1 1 0 0 0 1 0
Start 1 Stop
TX frame
TX pin
RX pin
Normal RX
frame Start 0 1 1 0 0 0 1 0 Stop
1 0 1
The SIR sub module can work in low power mode by setting the IRLP bit in USART_CTL2.
The transmit encoder is driven by a low speed clock, which is divided from the PCLK. The
division ratio is configured by the PSC[7:0] bits in USART_GP register. The pulse width on
the TX pin is 3 cycles of this low speed period. The receiver decoder works in the same
manner as the normal IrDA mode.
The half-duplex communication mode is enabled by setting the HDEN bit in USART_CTL2.
The LMEN, CKEN bits in USART_CTL1 and SCEN, IREN bits in USART_CTL2 should be
cleared in half-duplex communication mode.
In the half-duplex mode the receive line is internally connected to the TX pin, and the RX pin
is no longer used. The TX pin should be configured as output open drain mode. The software
should make sure that the transmission and reception process never conflict with each other.
The smartcard mode is an asynchronous mode, which is designed to support the ISO7816-3
protocol. Both the character (T=0) mode and the block (T=1) mode are supported. The
smartcard mode is enabled by setting the SCEN bit in USART_CTL2. The LMEN bit in
USART_CTL1 and HDEN, IREN bits in USART_CTL2 should be cleared in smartcard mode.
A clock is provided to the external smartcard through the CK pin after the CKEN bit is set.
The clock is divided from the PCLK. The division ratio is configured by the PSC[4:0] bits in
USART_GP register. The CK pin only provides a clock source to the smartcard.
S 0 1 2 3 4 5 6 7 P
S 0 1 2 3 4 5 6 7 P
Compared to the timing in normal operation, the transmission time from transmit shift register
to the TX pin is delayed by half baud clock, and the TC flag assertion time is delayed by a
guard time that is configured by the GUAT[7:0] bits in USART_GP. In Smartcard mode, the
internal guard time counter starts counting up after the stop bits of the last data frame, and
the GUAT[7:0] bits should be configured as the character guard time (CGT) in ISO7816-3
protocol minus 12. The TC status is forced reset while the guard time counter is counting up.
When the counter reaches the programmed value TC is asserted high.
During USART transmission, if a parity error event is detected, the smartcard may NACK the
current frame by pulling down the TX pin during the last 1 bit time of the stop bits. The USART
can automatically resend data according to the protocol for SCRTNUM times. An interframe
gap of 2.5 bits time will be inserted before the start of a resented frame. At the end of the last
repeated character the TC bit is set immediately without guard time. The USART will stop
transmitting and assert the frame error status if it still receives the NACK signal after the
programmed number of retries. The USART will not take the NACK signal as the start bit.
During USART reception, if the parity error is detected in the current frame, the TX pin is
pulled low during the last 1 bit time of the stop bits. This signal is the NACK signal to smartcard.
Then a frame error occurs in smartcard side. The RBNE/receive DMA request is not activated
if the received character is erroneous. According to the protocol, the smartcard can resend
the data. The USART stops transmitting the NACK and the error is regarded as a parity error
if the received character is still erroneous after the maximum number of retries which is
specified in the SCRTNUM bit field. The NACK signal is enabled by setting the NKEN bit in
USART_CTL2.
The idle frame and break frame are not supported in the Smartcard mode.
In block (T=1) mode, the NKEN bit in the USART_CTL2 register should be cleared to
deactivate the NACK transmission.
419
GD32E10x User Manual
When requesting a read from the smartcard, the RT[23:0] bits in USART_RT register should
be programmed with the BWT (block wait time) - 11 value and RBNEIE must be set. This
timeout period is expressed in baud time units. The RTF bit in USART_STAT1 will be asserted,
if no answer is received from the card before the expiration of this period. An interrupt is
generated if the RTIE bit in USART_CTL3 is set. The USART generates a RBNE interrupt if
the first character is received before the expiration of the RT[23:0] period. If DMA is used to
read from the smartcard in block mode, the DMA must be enabled only after the first character
is received.
After the first character is received, the RT[23:0] bits should be configured to the CWT
(character wait time) - 11 to enable the automatic check of the maximum interframe gap
between two consecutive characters. The RTF bit in USART_STAT1 will be asserted, if the
smartcard stops sending characters in the RT[23:0] period.
The USART uses a block length counter, which is reset when the USART is transmitting
(TBE=0), to count the number of received characters. The length of the block, which must be
programmed in the BL[7:0] bits in the USART_RT register, is received from the smartcard in
the third byte of the block (prologue field). The block length counter counts up from 0 to the
maximum value of BL[7:0] +4. The end of the block status (EBF bit in USART_STAT1) is set
after the block length counter reaches the maximum value. An interrupt is generated if the
EBIE bit in USART_CTL3 is set. The RTF bit may be set in case that an error in the block
length.
If DMA is used for reception, this register field must be programmed to the minimum value
(0x0) before the start of the block. With this value, the end of the block interrupt occurs after
the 4th received character. The block length value can be read from the receive buffer at the
third byte.
If DMA is not used for reception, the BL[7:0] bits should be firstly configured with the maximum
value 0xFF to avoid generating an EBF status. The real block length value can be
reconfigured to the BL[7:0] bits after the third byte is received.
When the direct convention is selected, the LSB of the data frame is transferred first, high
state on the TX pin represents logic ‘1’, the parity check mode is even. In this case the MSBF
and DINV bits in USART_CTL3 should be cleared.
When the inverse convention is selected, the MSB of the data frame is transferred first, high
state on the TX pin represents logic ‘0’, the parity check mode is even. In this case the MSBF
and DINV bits in USART_CTL3 should be set.
The USART interrupt events and flags are listed in Table 17-3. USART interrupt requests.
420
GD32E10x User Manual
Table 17-3. USART interrupt requests
Enable
Interrupt event Event flag Control register
Control bit
Transmit data buffer empty TBE USART_CTL0 TBEIE
CTS toggled flag CTSF USART_CTL2 CTSIE
Transmission complete TC USART_CTL0 TCIE
Received buff not empty RBNE
USART_CTL0 RBNEIE
Overrun error ORERR
Idle frame IDLEF USART_CTL0 IDLEIE
Parity error PERR USART_CTL0 PERRIE
Break detected flag in LIN
LBDF USART_CTL1 LBDIE
mode
Receiver timeout RTF USART_CTL3 RTIE
End of Block EBF USART_CTL3 EBIE
Reception Errors (Noise flag,
NERR or ORERR or
overrun error, framing error) in USART_CTL2 ERRIE
FERR
DMA reception
All of the interrupt events are ORed together before being sent to the interrupt controller, so
the USART can only generate a single interrupt request to the controller at any given time.
Software can service multiple interrupt events in a single interrupt service routine.
IDLEF
IDLEIE
ORERR
RBNEIE
PERR
PEIE
FERR
NERR OR
ORERR ERIE
DENR
LBDF
LBDIE
USART_INT
RBNE
RBNEIE
TC
TCIE
TBE
TBEIE
CTSF
CTSIE
RTF
RTIE
EBF
EBIE
421
GD32E10x User Manual
17.4. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved CTSF LBDF TBE TC RBNE IDLEF ORERR NERR FERR PERR
422
GD32E10x User Manual
register.
0: Transmit data buffer is not empty
1: Transmit data buffer is empty
6 TC Transmission complete
This bit is set after power on. If the TBE bit has been set, this bit is set when the
transmission of current data is complete. An interrupt occurs if the TCIE bit in
USART_CTL0 is set.
Software can clear this bit by writing 0 to it.
0: Transmission of current data is not complete
1: Transmission of current data is complete
423
GD32E10x User Manual
1 FERR Frame error flag
This bit is set when the RX pin is detected low during the stop bits of a receive
frame. An interrupt occurs if the ERRIE bit in USART_CTL2 is set.
Software can clear this bit by reading the USART_STAT0 and USART_DATA
registers one by one.
0: The USART does not detect a framing error
1: The USART has detected a framing error
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved DATA[8:0]
rw
The software must not write this register when the USART is enabled (UEN=1).
424
GD32E10x User Manual
This register has to be accessed by word (32-bit)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved UEN WL WM PCEN PM PERRIE TBEIE TCIE RBNEIE IDLEIE TEN REN RWU SBKCMD
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
12 WL Word length
0: 8 data bits
1: 9 data bits
425
GD32E10x User Manual
1: Parity check function is enabled
9 PM Parity mode
0: Even parity
1: Odd parity
5 RBNEIE Read data buffer not empty interrupt and overrun error interrupt enable
If this bit is set, an interrupt occurs when the RBNE bit or the ORERR bit in
USART_STAT0 is set.
0: Read data register not empty interrupt and overrun error interrupt disabled
1: Read data register not empty interrupt and overrun error interrupt enabled
426
GD32E10x User Manual
0: Receiver in active mode
1: Receiver in mute mode
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved LMEN STB[1:0] CKEN CPL CPH CLEN Reserved. LBDIE LBLEN Reserved ADDR[3:0]
rw rw rw rw rw rw rw rw rw
10 CPL CK polarity
This bit specifies the polarity of the CK pin in synchronous mode.
0: The CK pin is in low state when the USART is in idle state
1: The CK pin is in high state when the USART is in idle state
427
GD32E10x User Manual
This bit is reserved for UART3/4.
9 CPH CK phase
This bit specifies the phase of the CK pin in synchronous mode.
0: The capture edge of the LSB bit is the first edge of CK pin
1: The capture edge of the LSB bit is the second edge of CK pin
This bit is reserved for UART3/4.
8 CLEN CK length
This bit specifies the length of the CK signal in synchronous mode.
0: There are 7 CK pulses for an 8-bit frame and 8 CK pulses for a 9-bit frame
1: There are 8 CK pulses for an 8-bit frame and 9 CK pulses for a 9-bit frame
This bit is reserved for UART3/4.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved CTSIE CTSEN RTSEN DENT DENR SCEN NKEN HDEN IRLP IREN ERRIE
rw rw rw rw rw rw rw rw rw rw rw
428
GD32E10x User Manual
31:11 Reserved Must be kept the reset value.
429
GD32E10x User Manual
0: Normal mode
1: Low-power mode
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GUAT[7:0] PSC[7:0]
rw rw
7:0 PSC[7:0] When the USART IrDA low-power mode is enabled, these bits specify the division
factor that is used to divide the peripheral clock (PCLK1/PCLK2) to generate the
low-power frequency.
00000000: Reserved - never program this value
00000001: Divided by 1
00000010: Divided by 2
...
11111111: Divided by 255
When the USART works in IrDA normal mode, these bits must be set to 00000001.
When the USART smartcard mode is enabled, the PSC [4:0] bits specify the division
430
GD32E10x User Manual
factor that is used to divide the peripheral clock (APB1/APB2) to generate the
smartcard clock (CK). The actual division factor is twice as the PSC [4:0] value.
00000: Reserved - never program this value
00001: Divided by 2
00010: Divided by 4
...
11111: Divided by 62
The PSC [7:5] bits are reserved in smartcard mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved MSBF DINV TINV RINV Reserved EBIE RTIE SCRTNUM[2:0] RTEN
rw rw rw rw rw rw rw rw
431
GD32E10x User Manual
This bit specifies the polarity of the RX pin.
0: RX pin signal values are not inverted
1: RX pin signal values are inverted
This bit field cannot be written when the USART is enabled (UEN=1).
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
BL[7:0] RT[23:16]
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RT[15:0]
rw
432
GD32E10x User Manual
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved BSY
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
w0c w0c
433
GD32E10x User Manual
1: USART reception path is working
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
w0c rw
8 EPERR Early parity error flag. This flag will be set as soon as the parity bit has been
detected, which is before RBNE flag. This flag is cleared by writing 0.
0: No parity error is detected
1: Parity error is detected
434
GD32E10x User Manual
0 HCM Hardware flow control coherence mode
0: nRTS signal equals to RBNE bit in USART_STAT0 register
1: nRTS signal is set when the last data bit (parity bit when PCEN is set) has been
sampled
435
GD32E10x User Manual
18. Inter-integrated circuit interface (I2C)
18.1. Overview
The I2C (inter-integrated circuit) module provides an I2C interface which is a two-line serial
interface according with industrial standard for MCU to communicate with external I2C
interface. I2C bus uses two serial lines: a serial data line, SDA (serial data line), and a serial
clock line, SCL (serial clock line).
The I2C interface implements standard I2C protocol with standard mode, fast mode and fast
mode plus as well as CRC calculation and checking, SMBus (system management bus) and
PMBus (power management bus). It also supports multi-master I2C bus. The I2C interface
provides DMA mode for users to reduce CPU overload.
18.2. Characteristics
Figure 18-1. I2C module block diagram below provides details of the internal configuration
of the I2C interface.
436
GD32E10x User Manual
Figure 18-1. I2C module block diagram
PEC register
APB Bus
SCL SCL Controller
Transfer Buffer Register
SMBA/Rxframe
Control Registers
Timing and Control
Logic
Txframe Status Flags
DMA/Interrupts
Table 18-1. Definition of I2C-bus terminology (refer to the I2C specification of Philips
semiconductors)
Term Description
Transmitter The device which sends data to the bus
Receiver The device which receives data from the bus
The device which initiates a transfer, generates clock signals and
Master
terminates a transfer
Slave The device addressed by a master
More than one master can attempt to control the bus at the same
Multi-master
time without corrupting the message
Synchronization Procedure to synchronize the clock signals of two or more devices
Procedure to ensure that if more than one master tries to control the
Arbitration bus simultaneously, only one is allowed to do so and the winning master’s
message is not corrupted
The I2C module has two external lines, the serial data SDA and serial clock SCL lines. The
two wires carry information between the devices connected to the bus. Both SDA and SCL
are bidirectional lines, connected to a positive supply voltage via current-source or pull-up
resistor. When the bus is free, both lines are HIGH. The output stages of devices connected
to the bus must have an open-drain or open-collect to perform the wired-AND function. Data
on the I2C-bus can be transferred at rates of up to 100 Kbit/s in the standard mode, up to 400
437
GD32E10x User Manual
Kbit/s in the fast mode and up to 1Mbit/s in the fast mode plus if the FMPEN bit in
I2C_FMPCFG is set. Due to the variety of different technology devices (CMOS, NMOS,
bipolar) that can be connected to the I2C-bus, the voltage levels of the logical ‘0’ (LOW) and
‘1’ (HIGH) are not fixed, it depends on the associated level of VDD.
The data on the SDA line must be stable during the HIGH period of the clock. The HIGH or
LOW state of the SDA line can only change when the clock signal on the SCL line is LOW
(see Figure 18-2. Data validation). One clock pulse is generated for each data bit to be
transferred.
SDA
SCL
All transmissions begin with a START (S) and are terminated by a STOP (P) (see Figure 18-3.
START and STOP condition_Hlk454893849). A HIGH to LOW transition on the SDA line
while SCL is HIGH defines a START condition. A LOW to HIGH transition on the SDA line
while SCL is HIGH defines a STOP condition.
START
SDA
SCL
STOP
SDA
SCL
Two masters can begin transmitting on a free bus at the same time and there must be a
method for deciding which master takes control of the bus and completes its transmission.
This is done by clock synchronization and bus arbitration. In a single master system, clock
synchronization and bus arbitration are unnecessary.
Clock synchronization is performed using the wired-AND connection of I2C interfaces to the
SCL line. This means that a HIGH to LOW transition on the SCL line causes the masters
concerned to start counting their LOW period, and once a master clock has gone LOW, it
438
GD32E10x User Manual
holds the SCL line in that state until the clock HIGH state is reached (see Figure 18-4. Clock
synchronization_Hlk454893872). However, if another clock is still within its LOW period, the
LOW to HIGH transition of this clock may not change the state of the SCL line. The SCL line
is therefore held LOW by the master with the longest LOW period. Masters with shorter LOW
period enter a HIGH wait-state during this time.
CLK1
CLK2
SCL
18.3.5. Arbitration
Arbitration, like synchronization, is part of the protocol where more than one master is used
in the system. Slaves are not involved in the arbitration procedure.
A master may start a transfer only if the bus is free. Two masters may generate a START
condition within the minimum hold time of the START condition which results in a valid START
condition on the bus. Arbitration is then required to determine which master will complete its
transmission.
Arbitration proceeds bit by bit. During every bit, while SCL is HIGH, each master checks
whether the SDA level matches what it has been sent. This process may take many bits. Two
masters can even complete an entire transmission without error, as long as the transmissions
are identical. The first time a master tries to send a HIGH, but detects that the SDA level is
LOW, then the master knows that it has lost the arbitration and turns off its SDA output driver.
The other master goes on to complete its transmission.
SDA from 1 0 1 0
master2
SDA 1 0 1 0
SCL
Each I2C device is recognized by a unique address (whether it is a microcontroller, LCD driver,
memory or keyboard interface) and can be operated as either a transmitter or receiver
depending on the function of the device.
An I2C slave will continue to detect addresses after a START condition on I2C bus and
439
GD32E10x User Manual
compare the detected address with its slave address which is programmed by software. Once
the two addresses match with each other, the I2C slave will send an ACK to the I2C bus and
response to the following command on I2C bus: transmitting or receiving the desired data.
Additionally, if General Call is enabled by software, the I2C slave always responds to a
General Call Address (0x00). The I2C block supports both 7-bit and 10-bit address modes.
An I2C master always initiates or ends a transfer using START or STOP condition and it’s
also responsible for SCL clock generation.
An I2C device such as LCD driver may only be a receiver, whereas a memory can both
receive and transmit data. In addition to transmitters and receivers, devices can also be
considered as masters or slaves when performing data transfers. A master is the device which
initiates a data transfer on the bus and generates the clock signals to permit the transfer. At
that time, any device addressed is considered as a slave.
An I2C device is able to transmit or receive data whether it’s a master or a slave, thus, there’re
4 operation modes for an I2C device:
Master Transmitter
Master Receiver
Slave Transmitter
Slave Receiver
I2C block supports all of the four I2C modes. After system reset, it works in slave mode. After
sending a START condition on I2C bus, it changes into master mode. The I2C changes back
to slave mode after sending a STOP condition on I2C bus.
440
GD32E10x User Manual
Programming model in slave transmitting mode
As is shown in Figure 18-9. Programming model for slave transmitting, the following
software procedure should be followed if users wish to transmit data in slave transmitter mode:
1. First of all, software should enable I2C peripheral clock as well as configure clock related
registers in I2C_CTL1 to make sure the correct I2C timing. After being enabled and
configured, I2C operates in its default slave state and waits for START condition followed
by an address on I2C bus.
2. After receiving a START condition followed by a matched address, either in 7-bit format
or in 10-bit format, the I2C hardware sets the ADDSEND bit in I2C_STAT0 register, which
should be monitored by software either by polling or interrupt. After that, software should
read I2C_STAT0 and then I2C_STAT1 to clear ADDSEND bit. If 10-bit addressing format
is selected, the I2C master should then send a repeated START(Sr) condition followed
by a header to the I2C bus. The slave sets ADDSEND bit again after it detects the
repeated START(Sr) condition and the following header. Software needs to clear the
ADDSEND bit again by reading I2C_STAT0 and then I2C_STAT1.
3. Now I2C enters data transmission stage and hardware sets TBE bit because both the
shift register and data register I2C_DATA are empty. Once TBE is set, software should
write the first byte of data to I2C_DATA register, TBE is not cleared in this case because
the byte written in I2C_DATA is moved to the internal shift register immediately. I2C
begins to transmit data to I2C bus as soon as the shift register is not empty.
4. During the transmission of the first byte, software can write the second byte to I2C_DATA,
and this time TBE is cleared because neither I2C_DATA nor shift register is empty.
5. Any time TBE is set, software can write a byte to I2C_DATA as long as there is still data
to be transmitted.
6. During the transmission of the second last byte, software writes the last data to
I2C_DATA to clear the TBE flag and doesn’t care TBE anymore. So TBE will be set after
the byte’s transmission and not cleared until a STOP condition.
7. I2C master doesn’t acknowledge to the last byte according to the I2C protocol, so after
sending the last byte, I2C slave will wait for the STOP condition on I2C bus and sets
AERR (Acknowledge Error) bit to notify software that the transmission completes.
Software clears AERR bit by writing 0 to it.
441
GD32E10x User Manual
Figure 18-9. Programming model for slave transmitting mode
I2C Line State Hardware Action Software Flow
IDLE
1) Software initialization
Master generates START
condition
Set TBE
5) Write DATA(3) to I2C_DATA
……(Data transmission)
Set TBE
Write DATA(x) to I2C_DATA
Slave sends DATA(N-2)
Master sends ACK
Set TBE
6)Write DATA(N) to I2C_DATA
Slave sends DATA(N-1)
Master sends ACK
Set TBE
Slave sends DATA(N)
Master doesn't send ACK
Set AERR
Master generates STOP 7) Clear AERR
condition
Clear TBE
As is shown in Figure 18-10. Programming model for slave receiving, the following
software procedure should be followed if users wish to receive data in slave receiver mode:
1. First of all, software should enable I2C peripheral clock as well as configure clock related
registers in I2C_CTL1 to make sure correct I2C timing. After being enabled and
configured, I2C operates in its default slave state and waits for START condition followed
by address on I2C bus.
2. After receiving a START condition followed by a matched 7-bit or 10-bit address, the I2C
hardware sets the ADDSEND bit in I2C status register 0, which should be monitored by
software either by polling or interrupt. After that, software should read I2C_STAT0 and
then I2C_STAT1 to clear ADDSEND bit. The I2C begins to receive data on I2C bus as
442
GD32E10x User Manual
soon as ADDSEND bit is cleared.
3. As soon as the first byte is received, RBNE is set by hardware. Software can now read
the first byte from I2C_DATA and RBNE is cleared as well.
4. Any time RBNE is set, software can read a byte from I2C_DATA.
5. After the last byte is received, RBNE is set. Software reads the last byte.
6. STPDET bit is set when I2C detects a STOP condition on I2C bus and software reads
I2C_STAT0 and then writes I2C_CTL0 to clear the STPDET bit.
IDLE
Master generates START
1) Software initialization
condition
Set RBNE
4) Read DATA(x)
Master sends DATA(N)
Slave sends Acknowledge
Set RBNE
Master generates STOP 5) Read DATA(N)
condition
Set STPDET
6) Clear STPDET
As is shown in Figure 18-11. Programming model for master transmitting, the following
software procedure should be followed if users wish to transmit data in master transmitter
mode:
1. First of all, software should enable I2C peripheral clock as well as configure clock related
registers in I2C_CTL1 to make sure the correct I2C timing. After being enabled and
configured, I2C operates in its default slave state and waits for START condition followed
by address on I2C bus.
443
GD32E10x User Manual
3. After sending a START condition, the I2C hardware sets the SBSEND bit in I2C status
register 0 and enters master mode. Now software should clear the SBSEND bit by
reading I2C_STAT0 and then writing a 7-bit address or header of a 10-bit address to
I2C_DATA. I2C begins to send address or header to I2C bus as soon as SBSEND bit is
cleared. If the address which has been sent is header of a 10-bit address, the hardware
sets ADD10SEND bit after sending the header and software should clear the
ADD10SEND bit by reading I2C_STAT0 and writing 10-bit lower address to I2C_DATA.
4. After the 7-bit or 10-bit address has been sent, the I2C hardware sets the ADDSEND bit
and software should clear the ADDSEND bit by reading I2C_STAT0 and then I2C_STAT1.
5. Now I2C enters data transmission stage and hardware sets TBE bit because both the
shift register and data register I2C_DATA are empty. Software now writes the first byte
data to I2C_DATA register, but the TBE will not be cleared because the byte written in
I2C_DATA is moved to internal shift register immediately. The I2C begins to transmit data
to I2C bus as soon as the shift register is not empty.
6. During the transmission of the first byte, software can write the second byte to I2C_DATA,
and this time TBE is cleared because neither I2C_DATA nor shift register is empty.
7. Any time TBE is set, software can write a byte to I2C_DATA as long as there is still data
to be transmitted.
8. During the transmission of the second last byte, software writes the last data to
I2C_DATA to clear the TBE flag and doesn’t care TBE anymore. So TBE will be asserted
after the byte’s transmission and not be cleared until a STOP condition.
9. After sending the last byte, I2C master sets BTC bit because both the shift register and
I2C_DATA are empty. Software should set the STOP bit to generate a STOP condition,
then the I2C clears both TBE and BTC flags.
444
GD32E10x User Manual
Figure 18-11. Programming model for master transmitting mode
I2C Line State Hardware Action Software Flow
1) Software initialization
Set TBE
7) Write DATA(3) to I2C_DATA
……(Data transmission)
Set TBE
Write DATA(x) to I2C_DATA
Master sends DATA(N-2)
Slave sends ACK
Set TBE
8)Write DATA(N) to I2C_DATA
Master sends DATA(N-1)
Slave sends ACK
Set TBE
Master sends DATA(N)
Slave sends ACK
Set BTC
SCL stretched by master 9) Set STOP
Master generates STOP
condition
In master receiving mode, a master is responsible for generating NACK for the last byte
reception and then sending a STOP condition on I2C bus. So, special attention should be
paid to ensure the correct ending of data reception. Two solutions for master receiving are
provided here for applications: Solution A and B. Solution A requires the software’s quick
response to I2C events, while Solution B doesn’t.
Solution A
1. First of all, software should enable I2C peripheral clock as well as configure clock related
registers in I2C_CTL1 to make sure the correct I2C timing. After being enabled and
configured, I2C operates in its default slave state and waits for START condition followed
by address on I2C bus.
445
GD32E10x User Manual
3. After sending a START condition, the I2C hardware sets the SBSEND bit in I2C status
register 0 and enters master mode. Now software should clear the SBSEND bit by
reading I2C_STAT0 and then writing a 7-bit address or header of a 10-bit address to
I2C_DATA. I2C begins to send address or header to I2C bus as soon as SBSEND bit is
cleared. If the address which has been sent is header of a 10-bit address, the hardware
sets ADD10SEND bit after sending header and software should clear the ADD10SEND
bit by reading I2C_STAT0 and writing 10-bit lower address to I2C_DATA.
4. After the 7-bit or 10-bit address has been sent, the I2C hardware sets the ADDSEND bit
and software should clear the ADDSEND bit by reading I2C_STAT0 and then I2C_STAT1.
If the address is in 10-bit format, software should then set START bit again to generate
a repeated START condition on I2C bus and SBSEND is set after the repeated START
is sent out. Software should clear the SBSEND bit by reading I2C_STAT0 and writing
header to I2C_DATA. Then the header is sent out to I2C bus, and ADDSEND is set again.
Software should again clear ADDSEND by reading I2C_STAT0 and then I2C_STAT1.
5. As soon as the first byte is received, RBNE is set by hardware. Software now can read
the first byte from I2C_DATA and RBNE is cleared as well.
6. Any time RBNE is set, software can read a byte from I2C_DATA.
7. After the second last byte is received, the software should clear ACKEN bit and set STOP
bit. These actions should complete before the end of the last byte’s receiving to ensure
that NACK will be sent for the last byte.
8. After the last byte is received, RBNE is set. Software reads the last byte. I2C doesn’t
send ACK for the last byte and it generates a STOP condition after the transmission of
the last byte.
The above steps require byte number N>1. If N=1, Step 7 should be performed after Step 4
and completed before the end of the single byte’s receiving.
446
GD32E10x User Manual
Figure 18-12. Programming model for master receiving mode using Solution A
I2C Line State Hardware Software Flow
Action
1) Software initialization
Set RBNE
5) Read DATA(1)
……(Data transmission)
Set RBNE
Read DATA(x)
Slave sends DATA(N-1)
Master sends ACK
Set RBNE
6) Read DATA(N-1)
Slave sends DATA(N)
Master doesn't send ACK 7) Clear ACKEN,Set STOP
Solution B
1. First of all, software should enable I2C peripheral clock as well as configure clock related
registers in I2C_CTL1 to make sure the correct I2C timing. After being enabled and
configured, I2C operates in its default slave state and waits for START condition followed
by address on I2C bus.
3. After sending a START condition, the I2C hardware sets the SBSEND bit in I2C status
register 0 and enters master mode. Now software should clear the SBSEND bit by
reading I2C_STAT0 and then writing a 7-bit address or header of a 10-bit address to
I2C_DATA. I2C begins to send address or header to I2C bus as soon as SBSEND bit is
447
GD32E10x User Manual
cleared. If the address which has been sent is a header of 10-bit address, the hardware
sets ADD10SEND bit after sending header and software should clear the ADD10SEND
bit by reading I2C_STAT0 and writing 10-bit lower address toI2C_DATA.
4. After the 7-bit or 10-bit address has been sent, the I2C hardware sets the ADDSEND bit
and software should clear the ADDSEND bit by reading I2C_STAT0 and then I2C_STAT1.
If the address is in 10-bit format, software should then set START bit again to generate
a repeated START condition on I2C bus and SBSEND is set after the repeated START
is sent out. Software should clear the SBSEND bit by reading I2C_STAT0 and writing
header to I2C_DATA. Then the header is sent out to I2C bus, and ADDSEND is set again.
Software should again clear ADDSEND by reading I2C_STAT0 and then I2C_STAT1.
5. As soon as the first byte is received, RBNE is set by hardware. Software now can read
the first byte from I2C_DATA and RBNE is cleared as well.
6. Any time RBNE is set, software can read a byte from I2C_DATA until the master receives
N-3 bytes.
As is shown in Figure 18-13. Programming model for master receiving mode using
solution B, the byte (N-2) is not read out by software, so after the byte (N-1) is received, both
BTC and RBNE are asserted. The bus is stretched by master to prevent the reception of the
last byte. Then software should clear ACKEN bit.
7. Software reads out byte (N-2), clearing BTC. After this, the byte (N-1) is moved from shift
register to I2C_DATA and bus is released and begins to receive the last byte. Master
doesn’t send an ACK for the last byte because ACKEN is already cleared.
8. After the last byte is received, both BTC and RBNE are set again, and SCL is stretched
low. Software sets STOP bit and master sends out a STOP condition on bus.
9. Software reads the byte (N-1), clearing BTC. After this, the last byte is moved from shift
register to I2C_DATA.
The above steps require that byte number N>2. N=1 and N=2 are similar:
N=1
In Step4, software should reset ACKEN bit before clearing ADDSEND bit and set STOP bit
after clearing ADDSEND bit. Step 5 is the last step when N=1.
N=2
In Step 2, software should set POAP bit before setting START bit. In Step 4, software should
reset ACKEN bit before clearing ADDSEND bit. In Step 5, software should wait until BTC is
set and then set STOP bit and read I2C_DATA twice.
448
GD32E10x User Manual
Figure 18-13. Programming model for master receiving mode using solution B
I2C Line State Hardware Action Software Flow
1) Software initialization
Set ADDSEND
4) Clear ADDSEND
SCL stretched by master
4) Set START
Master generates repeated
START condition
SCL stretched by master Set SBSEND
4) Clear SBSEND
Set RBNE
……(Data transmission) 5) Read DATA(1)
Set RBNE
Slave sends DATA(N-2) 6) Read DATA(N-3)
Master sends ACK
Set RBNE
Slave sends DATA(N-1)
Master sends ACK
Set RBNE and BTC
7) Clear ACKEN
SCL stretched by master
8) Read DATA(N-2)
9) Read DATA(N)
The SCL line stretching function is designed to avoid overflow error in reception and underflow
error in transmission. As is shown in Programming Model, when the TBE and BTC bits are
set in transmitting mode, the transmitter stretches the SCL line low until the transfer buffer
register is filled with the next data to be transmitted. When the RBNE and BTC bits are set in
receiving mode, the receiver stretches the SCL line low until the data in the transfer buffer is
read out.
449
GD32E10x User Manual
When works in slave mode, the SCL line stretching function can be disabled by setting the
SS bit in the I2C_CTL0 register. If this bit is set, the software is required to be quick enough
to serve the TBE, RBNE and BTC status, otherwise, overflow or underflow situation might
occur.
The DMA request is enabled by the DMAON bit in the I2C_CTL1 register. This bit should be
set after clearing the ADDSEND status. If the SCL line stretching function is disabled for a
slave device, the DMAON bit should be set before the ADDSEND event.
Refer to the specification of the DMA controller for the configuration method of DMA. The
DMA controller must be configured and enabled before the I2C transfer. When the configured
number of bytes have been transferred, the DMA controller generates End of Transfer (EOT)
interrupt.
When a master receives two or more bytes, the DMALST bit in the I2C_CTL1 register should
be set. The I2C master will not send NACK after the last byte. The software can set the STOP
bit to generate a STOP condition in the ISR of the DMA EOT interrupt.
When a master receives only one byte, the ACKEN bit must be cleared before clearing the
ADDSEND status. Software can set the STOP bit to generate a STOP condition after clearing
the ADDSEND status, or in the ISR of the DMA EOT interrupt.
There is a CRC-8 calculator in I2C block to perform PEC (Packet Error Checking) for I2C data.
The polynomial of the CRC is x8 + x2 + x + 1 which is compatible with the SMBus protocol. If
enabled by setting PECEN bit, the PEC will calculate all the data transmitted through I2C
including address. I2C is able to send out the PEC value after the last data byte or check the
received PEC value with its calculated PEC using the PECTRANS bit. In DMA mode, the I2C
will send or check PEC value automatically if PECEN bit and PECTRANS bit is set.
The System Management Bus (abbreviated to SMBus or SMB) is a single-ended simple two-
wire bus for the purpose of lightweight communication. Most commonly it is found in computer
motherboards for communication with power source for ON/OFF instructions. It is derived
from I2C for communication with low-bandwidth devices on a motherboard, especially power
related chips such as a laptop's rechargeable battery subsystem (see Smart Battery Data).
450
GD32E10x User Manual
SMBus protocol
Each message transmission on SMBus follows the format of one of the defined SMBus
protocols. The SMBus protocols are a subset of the data transfer formats defined in the I2C
specifications. I2C devices that can be accessed through one of the SMBus protocols are
compatible with the SMBus specifications. I2C devices that do not adhere to these protocols
cannot be accessed by standard methods as defined in the SMBus and Advanced
Configuration and Power Management Interface (abbreviated to ACPI) specifications.
The SMBus is realized based on I2C hardware and it uses I2C hardware addressing, but it
adds the second-level software for building special systems. Additionally, its specifications
include an Address Resolution Protocol that can make dynamic address allocations. Dynamic
reconfiguration of the hardware and software allows bus devices to be ‘hot-plugged’ and used
immediately, without restarting the system. The devices are recognized automatically and
assigned unique addresses. This advantage results in a plug-and-play user interface. In those
protocols there is a very useful distinction made between a System Host and all the other
devices in the system that can have the names and functions of masters or slaves.
Time-out feature
SMBus has a time-out feature which resets devices if a communication takes too long. This
explains the minimum clock frequency is 10 kHz to prevent locking up the bus. I2C can be a
‘DC’ bus, which means that a slave device stretches the master clock when performing some
routines while the master is accessing it. This will notify the master that the slave is busy but
does not want to lose the communication. The slave device will continue the communication
after its task is completed. There is no limit in the I2C bus protocol of how long this delay can
be, whereas for a SMBus system, it would be limited to 35ms. SMBus protocol just assumes
that if something takes too long, then it means that there is a problem on the bus and that all
devices must reset in order to solve the problem. Slave devices are not allowed to hold the
clock low too long.
SMBus 2.0 and 1.1 allow Packet Error Checking (PEC). In that mode, a PEC byte is appended
at the end of each transaction. The byte is a CRC-8 checksum of the entire message including
the address and read/write bit. The polynomial used is x8+x2+x+1 (the CRC-8-ATM HEC
algorithm, initialized to zero).
SMBus alert
The SMBus has an extra optional shared interrupt signal called SMBALERT# which can be
used by slaves to tell the host to ask its slaves about events of interest. SMBus also defines
a less common "Host Notify Protocol", providing similar notifications which is based on the
I2C multi-master mode but it can pass more data.
451
GD32E10x User Manual
SMBus communication flow
The programming flow for SMBus is similar to normal I2C. In order to use SMBus mode, the
application should configure several SMBus specific registers, respond to some SMBus
specific flags and implement the upper protocols described in SMBus specification.
1. Before communication, SMBEN bit in I2C_CTL0 should be set and SMBSEL and ARPEN
bits should be configured to desired values.
2. In order to support address resolution protocol (ARP) (ARPEN=1), the software should
respond to HSTSMB flag in SMBus Host Mode (SMBSEL=1) or DEFSMB flag in SMBus
Device Mode, and implement the function of ARP protocol.
3. In order to support SMBus Alert Mode, the software should respond to SMBALT flag and
implement the related function.
To support the SAM_V standard, two additional pins are added to the I2C module: txframe
and rxframe. Txframe is an output pin, in master mode, it indicates the I2C is busy when it is
asserted. Rxframe is an input pin that is supposed to be multiplexed together with the
SMBALERT signal.
The SAM_V mode is enabled by setting the SAMEN bit of the I2C_SAMCS register. The
status of the txframe and rxframe pin can be reflected by the RFR, RFF, TFR, TFF, RXF, and
TXF flags of the I2C_SAMCS register. I2C interrupts will be generated if the corresponding
interrupt enable bits are set.
There are several status and error flags in I2C, and interrupts may be asserted from these
flags by setting some register bits (refer to Register for detail).
453
GD32E10x User Manual
18.4. Register definition
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PECTRA
SRESET Reserved SALT POAP ACKEN STOP START SS GCEN PECEN ARPEN SMBSEL Reserved SMBEN I2CEN
NS
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
454
GD32E10x User Manual
10 ACKEN ACK enable
This bit is set and cleared by software and cleared by hardware when I2CEN=0
0: ACK will not be sent
1: ACK will be sent
7 SS SCL stretching
Whether to stretch SCL low when data is not ready in slave mode.
This bit is set and cleared by software.
0: SCL stretching is enabled
1: SCL stretching is disabled
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
ADDFOR ADDRES
Reserved ADDRESS[9:8] ADDRESS[7:1]
MAT S0
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw
7:1 ADDRESS2[7:1] The second I2C address for the slave in Dual-Address mode
457
GD32E10x User Manual
0: Dual-Address mode is disabled
1: Dual-Address mode is enabled
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved TRB[7:0]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
458
GD32E10x User Manual
This bit is set by hardware and cleared by writing 0.
0: Received PEC matches calculated PEC
1: Received PEC doesn’t match calculated PEC, I2C will send NACK careless of
ACKEN bit.
11 OUERR Over-run or under-run situation occurs in slave mode, when SCL stretching is
disabled. In slave receiving mode, if the last byte in I2C_DATA is not read out while
the following byte is already received, overrun occurs. In slave transmitting mode, if
the current byte is already sent out, while the I2C_DATA is still empty, under-run
occurs.
This bit is set by hardware and cleared by writing 0.
0: No over-run or under-run occurs.
1: Over-run or under-run occurs.
459
GD32E10x User Manual
4 STPDET STOP condition is detected in slave mode
This bit is set by hardware and cleared by reading I2C_STAT0 and then writing
I2C_CTL0
0: STOP condition not detected in slave mode
1: STOP condition detected in slave mode
1 ADDSEND Address is sent in master mode or received and matches in slave mode.
This bit is set by hardware and cleared by reading I2C_STAT0 and reading
I2C_STAT1.
0: No address is sent or received
1: Address is sent out in master mode or a matched address is received in salve
mode
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
460
GD32E10x User Manual
r r r r r r r r
7 DUMODF Dual flag in slave mode indicates which address matches with the address in Dual-
Address mode
This bit is cleared by hardware after a STOP or a START condition or I2CEN=0
0: The address matches with SADDR0 address
1: The address matches with SADDR1 address
461
GD32E10x User Manual
18.4.8. Clock configure register (I2C_CKCFG)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved RISETIME[5:0]
rw
462
GD32E10x User Manual
5:0 RISETIME[5:0] Maximum rise time in master mode
The RISETIME value should be the maximum SCL rise time incremented by 1.
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RFR RFF TFR TFF Reserved RXF TXF RFRIE RFFIE TFRIE TFFIE Reserved STOEN SAMEN
463
GD32E10x User Manual
0 SAMEN SAM_V interface enable
0: SAM_V interface disabled
1: SAM_V interface enabled
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved FMPEN
rw
464
GD32E10x User Manual
19. Serial peripheral interface/Inter-IC sound (SPI/I2S)
19.1. Overview
The SPI/I2S module can communicate with external devices using the SPI protocol or the I2S
audio protocol.
The serial peripheral interface (SPI) provides a SPI protocol of data transmission and
reception function in master or slave mode. Both full-duplex and simplex communication
modes are supported, with hardware CRC calculation and checking. Quad-SPI master mode
is only supported in SPI0.
The inter-IC sound (I2S) supports four audio standards: I2S Phillips standard, MSB justified
standard, LSB justified standard, and PCM standard. I2S works at either master or slave
mode for transmission and reception.
19.2. Characteristics
465
GD32E10x User Manual
19.3. SPI block diagram
SYSCLK
O PAD
SCK
Clock Generator I
Control
Registers
APB
O PAD MOSI
I
TX Buffer
O PAD
MISO
I
Shift Register O PAD IO2
MSB LSB I
RX Buffer O PAD
IO3
I
466
GD32E10x User Manual
19.4.2. Quad-SPI configuration
SPI is in single wire mode by default and enters into Quad-SPI mode after QMOD bit in
SPI_QCTL register is set (only available in SPI0). Quad-SPI mode can only work in master
mode.
The IO2 and IO3 pins can be driven high in normal Non-Quad-SPI mode by configuring
IO23_DRV bit in SPI_QCTL register.
CKPL and CKPH bits in SPI_CTL0 register decide the timing of SPI clock and data signal.
The CKPL bit decides the SCK level when idle and CKPH bit decides either first or second
clock edge is a valid sampling edge. These bits take no effect in TI mode.
NSS
467
GD32E10x User Manual
Figure 19-3. SPI timing diagram in Quad-SPI mode (CKPL=1, CKPH=1, LF=0)
SCK
NSS(slave)
Capture
In normal mode, the length of data is configured by the FF16 bit in the SPI_CTL0 register.
Data length is 16 bits if FF16=1, otherwise is 8 bits. The data frame length is fixed to 8 bits in
Quad-SPI mode.
Data order is configured by the LF bit in SPI_CTL0 register, and SPI will first send the LSB
first if LF=1, or the MSB first if LF=0. The data order is fixed to MSB first in TI mode.
Slave mode
When slave mode is configured (MSTMOD=0), SPI gets NSS level from NSS pin in hardware
NSS mode (SWNSSEN = 0) or from SWNSS bit in software NSS mode (SWNSSEN = 1), and
SPI transmits/receives data only when NSS level is low. In software NSS mode, NSS pin is
not used.
Master mode
In master mode (MSTMOD=1), if the application uses multi-master connection, NSS can be
configured to hardware input mode (SWNSSEN=0, NSSDRV=0) or software mode
(SWNSSEN=1). Then, once the NSS pin (in hardware NSS mode) or the SWNSS bit (in
software NSS mode) goes low, the SPI automatically enters slave mode and triggers a master
fault flag CONFERR.
If the application wants to use NSS line to control the SPI slave, NSS should be configured
to hardware output mode (SWNSSEN=0, NSSDRV=1). NSS stays high after SPI is enabled
and goes low when transmission or reception process begins. When SPI is disabled, the NSS
goes high.
468
GD32E10x User Manual
The application may also use a general purpose IO as NSS pin to realize more flexible NSS.
MSTMOD = 1
RO = 0 MOSI: Transmission
MFD Master full-duplex
BDEN = 0 MISO: Reception
BDOEN: Don’t care
MSTMOD = 1
Master transmission with RO = 0 MOSI: Transmission
MTU
unidirectional connection BDEN = 0 MISO: Not used
BDOEN: Don’t care
MSTMOD = 1
Master reception with RO = 1 MOSI: Not used
MRU
unidirectional connection BDEN = 0 MISO: Reception
BDOEN: Don’t care
MSTMOD = 1
Master transmission with RO = 0 MOSI: Transmission
MTB
bidirectional connection BDEN = 1 MISO: Not used
BDOEN = 1
MSTMOD = 1
Master reception with RO = 0 MOSI: Reception
MRB
bidirectional connection BDEN = 1 MISO: Not used
BDOEN = 0
MSTMOD = 0
RO = 0 MOSI: Reception
SFD Slave full-duplex
BDEN = 0 MISO: Transmission
BDOEN: Don’t care
MSTMOD = 0
Slave transmission with RO = 0 MOSI: Not used
STU
unidirectional connection BDEN = 0 MISO: Transmission
BDOEN: Don’t care
MSTMOD = 0
Slave reception with RO = 1 MOSI: Reception
SRU
unidirectional connection BDEN = 0 MISO: Not used
BDOEN: Don’t care
MSTMOD = 0
Slave transmission with MOSI: Not used
STB RO = 0
bidirectional connection MISO: Transmission
BDEN = 1
469
GD32E10x User Manual
Mode Description Register configuration Data pin usage
BDOEN = 1
MSTMOD = 0
Slave reception with RO = 0 MOSI: Not used
SRB
bidirectional connection BDEN = 1 MISO: Reception
BDOEN = 0
Master Slave
MFD SFD
SCK SCK
MISO MISO
MOSI MOSI
NSS NSS
Master Slave
MRU STU
SCK SCK
MISO MISO
MOSI MOSI
NSS NSS
Figure 19-6. A typical simplex connection (Master: Transmit only, Slave: Receive)
Master Slave
MTU SRU
SCK SCK
MISO MISO
MOSI MOSI
NSS NSS
470
GD32E10x User Manual
Figure 19-7. A typical bidirectional connection
Master Slave
MTB/MRB SRB/STB
SCK SCK
MISO MISO
MOSI MOSI
NSS NSS
Before transmiting or receiving data, application should follow the SPI initialization sequence
described below:
1. If master mode or slave TI mode is used, program the PSC [2:0] bits in SPI_CTL0 register
to generate SCK with desired baud rate or configure the Td time in TI mode, otherwise,
ignore this step.
2. Program data format (FF16 bit in the SPI_CTL0 register).
3. Program the clock timing register (CKPL and CKPH bits in the SPI_CTL0 register).
4. Program the frame format (LF bit in the SPI_CTL0 register).
5. Program the NSS mode (SWNSSEN and NSSDRV bits in the SPI_CTL0 register)
according to the application’s demand as described above in NSS function section.
6. If TI mode is used, set TMOD bit in SPI_CTL1 register, otherwise, ignore this step.
7. Configure MSTMOD, RO, BDEN and BDOEN depending on the operating modes
described in SPI operating modes section.
8. If Quad-SPI mode is used, set the QMOD bit in SPI_QCTL register. Ignore this step if
Quad-SPI mode is not used.
9. Enable the SPI (set the SPIEN bit).
Transmission sequence
After the initialization sequence, the SPI is enabled and stays at idle state. In master mode,
the transmission starts when the application writes a data into the transmit buffer. In slave
mode the transmission starts when SCK clock signal at SCK pin begins to toggle and NSS
level is low, so application should ensure that data is already written into transmit buffer before
the transmission starts in slave mode.
When SPI begins to send a data frame, it first loads this data frame from the data buffer to
the shift register and then begins to transmit the loaded data frame, TBE (transmit buffer
empty) flag is set after the first bit of this frame is transmitted. After TBE flag is set, which
means the transmit buffer is empty, the application should write SPI_DATA register again if it
has more data to transmit.
471
GD32E10x User Manual
In master mode, software should write the next data into SPI_DATA register before the
transmission of current data frame is completed if it desires to generate continuous
transmission.
Reception sequence
After the last valid sample clock, the incoming data will be moved from shift register to the
receive buffer and RBNE (receive buffer not empty) will be set. The application should read
SPI_DATA register to get the received data and this will clear the RBNE flag automatically.
In MRU and MRB modes, hardware continuously sends clock signal to receive the next data
frame, while in full-duplex master mode (MFD), hardware only receives the next data frame
when the transmit buffer is not empty.
In full-duplex mode, either MFD or SFD, the RBNE and TBE flags should be monitored and
then follow the sequences described above.
The transmission mode (MTU, MTB, STU or STB) is similar to the transmission sequence of
full-duplex mode regardless of the RBNE and OVRE bits.
The master reception mode (MRU or MRB) is different from the reception sequence of full-
duplex mode. In MRU or MRB mode, after SPI is enabled, the SPI continuously generates
SCK until the SPI is disabled. So the application should ignore the TBE flag and read out
reception buffer in time after the RBNE flag is set, otherwise a data overrun fault will occur.
The slave reception mode (SRU or SRB) is similar to the reception sequence of full-duplex
mode regardless of the TBE flag.
SPI TI mode
SPI TI mode takes NSS as a special frame header flag signal and its operation sequence is
similar to normal mode described above. The modes described above (MFD, MTU, MRU,
MTB, MRB, SFD, STU, SRU, STB and SRB) are still supported in TI mode. While, in TI mode
the CKPL and CKPH bits in SPI_CTL0 registers take no effect and the SCK sample edge is
falling edge.
472
GD32E10x User Manual
Figure 19-8. Timing diagram of TI master mode with discontinuous transfer
SCK
NSS
MOSI D7 D0 D7
MISO D7 D0 D7
SCK
NSS
MOSI D7 D0 D7
MISO D7
In master TI mode, SPI can perform continuous or non-continuous transfer. If the master
writes SPI_DATA register fast enough, the transfer is continuous, otherwise non-continuous.
In non-continuous transfer, there is an extra header clock cycle before each byte. While in
continuous transfer, the extra header clock cycle only exists before the first byte and the
following bytes’ header clock is overlaid at the last bit of pervious bytes.
SCK
NSS
MOSI D7 D0
MISO D7 D0
Td
In slave TI mode, after the last rising edge of SCK in transfer, the slave begins to transmit the
LSB bit of the last data byte, and after a half-bit time, the master begins to sample the line.
To make sure that the master samples the right value, the slave should continue to drive this
473
GD32E10x User Manual
bit after the falling sample edge of SCK for a period of time before releasing the pin. This time
is called Td . Td is decided by PSC[2:0] bits in SPI_CTL0 register.
Tbit
Td = +5*Tpclk (19-1)
2
In slave mode, the slave also monitors the NSS signal and sets an error flag FERR if it detects
an incorrect NSS behavior, for example, toggles at the middle bit of a byte.
When NSS pulse mode is enabled, a pluse duration of at least 1 SCK clock period is inserted
between two successive data frames depending on the status of internal data transmit buffer.
Multiple SCK clock cycle intervals are possible if the transfer buffer stays empty. This function
is designed for single master-slave configuration for the slave to latch data. The following
diagram depicts its timing diagram.
NSS
SCK
MISO Don’t Care MSB LSB Don’t Care MSB LSB Don’t Care
1 SCK
In order to enter Quad-SPI mode, the software should first verify that the TBE bit is set and
TRANS bit is cleared, then set QMOD bit in SPI_QCTL register. In Quad-SPI mode, BDEN,
BDOEN, CRCEN, CRCNT, FF16, RO and LF bits in SPI_CTL0 register should be kept
cleared and MSTMOD should be set to ensure that SPI is in master mode. SPIEN, PSC,
CKPL and CKPH bits should be configured as desired.
There are two operation modes in Quad-SPI mode: quad write and quad read, decided by
QRD bit in SPI_QCTL register.
SPI works in quad write mode when QMOD is set and QRD is cleared in SPI_QCTL register.
474
GD32E10x User Manual
In this mode, MOSI, MISO, IO2 and IO3 are all used as output pins. SPI begins to generate
clock on SCK line and transmit data on MOSI, MISO, IO2 and IO3 as soon as data is written
into SPI_DATA (TBE is cleared) and SPIEN is set. Once SPI starts transmission, it always
checks TBE status at the end of a frame and stops when condition is not met.
1. Configure clock prescaler, clock polarity, phase, etc. in SPI_CTL0 and SPI_CTL1 based
on application requirements.
2. Set QMOD bit in SPI_QCTL register and then enable SPI by setting SPIEN in SPI_CTL0.
3. Write a byte of data to SPI_DATA register and the TBE will be cleared.
4. Wait until TBE is set by hardware again before writing the next byte.
TBE
SCK
SPI works in quad read mode when QMOD and QRD bits are both set in SPI_QCTL register.
In this mode, MOSI, MISO, IO2 and IO3 are all used as input pins. SPI begins to generate
clock on SCK line as soon as a data is written into SPI_DATA (TBE is cleared) and SPIEN is
set. Writing data into SPI_DATA is only to generate SCK clocks, so the written data can be
any value. Once SPI starts transmission, it always checks SPIEN and TBE status at the end
of a frame and stops when condition is not met. So, dummy data should always be written
into SPI_DATA to generate SCK.
1. Configure clock prescaler, clock polarity, phase, etc. in SPI_CTL0 and SPI_CTL1
register based on application requirements.
2. Set QMOD and QRD bits in SPI_QCTL register and then enable SPI by setting SPIEN
in SPI_CTL0 register.
475
GD32E10x User Manual
3. Write an arbitrary byte (for example, 0xFF) to SPI_DATA register.
4. Wait until the RBNE flag is set and read SPI_DATA to get the received byte.
5. Write an arbitrary byte (for example, 0xFF) to SPI_DATA to receive the next byte.
TBE
SCK
RBNE
Different sequences are used to disable the SPI in different operation modes.
MFD SFD
Wait for the last RBNE flag and then receive the last data. Confirm that TBE=1 and TRANS=0.
At last, disable the SPI by clearing SPIEN bit.
Write the last data into SPI_DATA and wait until the TBE flag is set and then wait until the
TRANS flag is cleared. Disable the SPI by clearing SPIEN bit.
MRU MRB
After getting the second last RBNE flag, read out this data and delay for a SCK clock time
and then, disable the SPI by clearing SPIEN bit. Wait until the last RBNE flag is set and read
out the last data.
476
GD32E10x User Manual
SRU SRB
Application can disable the SPI when it doesn’t want to receive data, and then wait until the
TRANS=0 to ensure the ongoing transfer completes.
TI mode
The disabling sequence of TI mode is the same as the sequences described above.
The disabling sequence of NSSP mode is the same as the sequences described above.
Quad-SPI mode
Before leaving quad wire mode or disabling SPI, software should first check that TBE bit is
set and TRANS bit is cleared, then the QMOD bit in SPI_QCTL register and SPIEN bit in
SPI_CTL0 register are cleared.
The DMA frees the application from data writing and reading process during transfer, to
improve the system efficiency.
DMA function in SPI is enabled by setting DMATEN and DMAREN bits in SPI_CTL1 register.
To use DMA function, application should first correctly configure DMA modules, then
configure SPI module according to the initialization sequence, at last enable SPI.
After being enabled, if DMATEN is set, SPI will generate a DMA request each time when
TBE=1, then DMA will acknowledge to this request and write data into the SPI_DATA register
automatically. If DMAREN is set, SPI will generate a DMA request each time when RBNE=1,
then DMA will acknowledge to this request and read data from the SPI_DATA register
automatically.
There are two CRC calculators in SPI: one for transmission and the other for reception. The
CRC calculation uses the polynomial defined in SPI_CRCPOLY register.
Application can enable the CRC function by setting CRCEN bit in SPI_CTL0 register. The
CRC calculators continuously calculate CRC for each bit transmitted and received on lines,
and the calculated CRC values can be read from SPI_TCRC and SPI_RCRC registers.
To transmit the calculated CRC value, application should set the CRCNT bit in SPI_CTL0
register after the last data is written to the transmit buffer. In full-duplex mode (MFD or SFD),
when the SPI transmits a CRC and prepares to check the received CRC value, the SPI treats
the incoming data as a CRC value. In reception mode (MRB, MRU, SRU and SRB), the
application should set the CRCNT bit after the second last data frame is received. When CRC
checking fails, the CRCERR flag will be set.
477
GD32E10x User Manual
If DMA function is enabled, application doesn’t need to configure CRCNT bit and hardware
will automatically process the CRC transmitting and checking.
This bit is set when the transmit buffer is empty, the software can write the next data to the
transmit buffer by writing the SPI_DATA register.
This bit is set when receive buffer is not empty, which means that one data is received and
stored in the receive buffer, and software can read the data by reading the SPI_DATA register.
TRANS is a status flag to indicate whether the transfer is ongoing or not. It is set and cleared
by hardware and not controlled by software. This flag doesn’t generate any interrupt.
CONFERR is an error flag in master mode. In NSS hardware mode and if the NSSDRV is not
enabled, the CONFERR is set when the NSS pin is pulled low. In NSS software mode, the
CONFERR is set when the SWNSS bit is 0. When the CONFERR is set, the SPIEN bit and
the MSTMOD bit are cleared by hardware, the SPI is disabled and the device is forced into
slave mode.
The SPIEN and MSTMOD bits are write protected until the CONFERR is cleared. The
CONFERR bit of the slave cannot be set. In a multi-master configuration, the device can be
in slave mode with CONFERR bit set, which means there might have been a multi-master
conflict for system control.
The RXORERR bit is set if a data is received when the RBNE is set. That means, the last
data has not been read out and the newly incoming data is received. The receive buffer
contents won’t be covered with the newly incoming data, so the newly incoming data is lost.
In slave TI mode, the slave also monitors the NSS signal and set an error flag if it detects an
incorrect NSS behavior, for example: toggles at the middle bit of a byte.
Interrupt
Flag Description Clear method
enable bit
TBE Transmit buffer empty Write SPI_DATA register. TBEIE
RBNE Receive buffer not empty Read SPI_DATA register. RBNEIE
Read or write SPI_STAT register,
CONFERR Configuration fault error
then write SPI_CTL0 register.
Read SPI_DATA register, then
RXORERR Rx overrun error ERRIE
read SPI_STAT register.
CRCERR CRC error Write 0 to CRCERR bit
FERR TI Mode Format Error Write 0 to FERR bit
16 bits
TX Buffer
O
SPI_MOSI /
PAD
I2S_SD
MSB Shift Register LSB
I
16 bits
RX Buffer
There are five sub modules to support I2S function, including control registers, clock
generator, master control logic, slave control logic and shift register. All the user configuration
registers are implemented in the control registers module, including the TX buffer and RX
buffer. The clock generator is used to produce I2S communication clock in master mode. The
master control logic is implemented to generate the I2S_WS signal and control the
communication in master mode. The slave control logic is implemented to control the
communication in slave mode according to the received I2S_CK and I2S_WS. The shift
register handles the serial data transmission and reception on I2S_SD.
479
GD32E10x User Manual
19.8. I2S signal description
There are four pins on the I2S interface, including I2S_CK, I2S_WS, I2S_SD and I2S_MCK.
I2S_CK is the serial clock signal, which shares the same pin with SPI_SCK. I2S_WS is the
frame control signal, which shares the same pin with SPI_NSS. I2S_SD is the serial data
signal, which shares the same pin with SPI_MOSI. I2S_MCK is the master clock signal. It
produces a frequency rate equals to 256 x Fs, and Fs is the audio sampling frequency.
The I2S audio standard is selected by the I2SSTD bits in the SPI_I2SCTL register. Four audio
standards are supported, including I2S Phillips standard, MSB justified standard, LSB justified
standard, and PCM standard. All standards except PCM handle audio data time-multiplexedly
on two channels (the left channel and the right channel). For these standards, the I2S_WS
signal indicates the channel side. For PCM standard, the I2S_WS signal indicates frame
synchronization information.
The data length and the channel length are configured by the DTLEN bits and CHLEN bit in
the SPI_I2SCTL register. Since the channel length must be greater than or equal to the data
length, four packet types are available. They are 16-bit data packed in 16-bit frame, 16-bit
data packed in 32-bit frame, 24-bit data packed in 32-bit frame, and 32-bit data packed in 32-
bit frame. The data buffer for transmission and reception is 16-bit wide. In the case that the
data length is 24 bits or 32 bits, two write or read operations to or from the SPI_DATA register
are needed to complete the transmission of a frame. In the case that the data length is 16
bits, only one write or read operation to or from the SPI_DATA register is needed to complete
the transmission of a frame. When using 16-bit data packed in 32-bit frame, 16-bit 0 is
inserted by hardware automatically to extend the data to 32-bit format.
For all standards and packet types, the most significant bit (MSB) is always sent first. For all
standards based on two channels time-multiplexed, the channel left is always sent first
followed by the channel right.
For I2S Phillips standard, I2S_WS and I2S_SD are updated on the falling edge of I2S_CK.
The timing diagrams for each configuration are shown below.
480
GD32E10x User Manual
Figure 19-15. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=0, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit data
I2S_SD MSB LSB MSB
Figure 19-16. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=0, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit data
I2S_SD MSB LSB MSB
When the packet type is 16-bit data packed in 16-bit frame, only one write or read operation
to or from the SPI_DATA register is needed to complete the transmission of a frame.
Figure 19-17. I2S Phillips standard timing diagram (DTLEN=10, CHLEN=1, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
32-bit data
I2S_SD MSB LSB MSB
Figure 19-18. I2S Phillips standard timing diagram (DTLEN=10, CHLEN=1, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
32-bit data
I2S_SD MSB LSB MSB
When the packet type is 32-bit data packed in 32-bit frame, two write or read operations to or
from the SPI_DATA register are needed to complete the transmission of a frame. In
transmission mode, if a 32-bit data is going to be sent, the first data written to the SPI_DATA
register should be the higher 16 bits, and the second one should be the lower 16 bits. In
reception mode, if a 32-bit data is received, the first data read from the SPI_DATA register
should be the higher 16 bits, and the second one should be the lower 16 bits.
Figure 19-19. I2S Phillips standard timing diagram (DTLEN=01, CHLEN=1, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
24-bit data 8-bit 0
I2S_SD MSB LSB MSB
481
GD32E10x User Manual
Figure 19-20. I2S Phillips standard timing diagram (DTLEN=01, CHLEN=1, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
24-bit data 8-bit 0
I2S_SD MSB LSB MSB
When the packet type is 24-bit data packed in 32-bit frame, two write or read operations to or
from the SPI_DATA register are needed to complete the transmission of a frame. In
transmission mode, if a 24-bit data D[23:0] is going to be sent, the first data written to the
SPI_DATA register should be the higher 16 bits D[23:8]. And the second one should be a 16-
bit data, the higher 8 bits of this 16-bit data should be D[7:0] and the lower 8 bits can be any
value. In reception mode, if a 24-bit data D[23:0] is received, the first data read from the
SPI_DATA register is D[23:8]. And the second one is a 16-bit data, the higher 8 bits of this
16-bit data are D[7:0] and the lower 8 bits are zeros.
Figure 19-21. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=1, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit data 16-bit 0
I2S_SD MSB LSB MSB
Figure 19-22. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=1, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit data 16-bit 0
I2S_SD MSB LSB MSB
When the packet type is 16-bit data packed in 32-bit frame, only one write or read operation
to or from the SPI_DATA register is needed to complete the transmission of a frame. The
remaining 16 bits are forced by hardware to 0x0000 to extend the data to 32-bit format.
For MSB justified standard, I2S_WS and I2S_SD are updated on the falling edge of I2S_CK.
The SPI_DATA register is handled in the exactly same way as that for I2S Phillips standard.
The timing diagrams for each configuration are shown below.
Figure 19-23. MSB justified standard timing diagram (DTLEN=00, CHLEN=0, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit data
I2S_SD MSB LSB MSB
482
GD32E10x User Manual
Figure 19-24. MSB justified standard timing diagram (DTLEN=00, CHLEN=0, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit data
I2S_SD MSB LSB MSB
Figure 19-25. MSB justified standard timing diagram (DTLEN=10, CHLEN=1, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
32-bit data
I2S_SD MSB LSB MSB
Figure 19-26. MSB justified standard timing diagram (DTLEN=10, CHLEN=1, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
32-bit data
I2S_SD MSB LSB MSB
Figure 19-27. MSB justified standard timing diagram (DTLEN=01, CHLEN=1, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
24-bit data 8-bit 0
I2S_SD MSB LSB MSB
Figure 19-28. MSB justified standard timing diagram (DTLEN=01, CHLEN=1, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
24-bit data 8-bit 0
I2S_SD MSB LSB MSB
Figure 19-29. MSB justified standard timing diagram (DTLEN=00, CHLEN=1, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit data 16-bit 0
I2S_SD MSB LSB MSB
483
GD32E10x User Manual
Figure 19-30. MSB justified standard timing diagram (DTLEN=00, CHLEN=1, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit data 16-bit 0
I2S_SD MSB LSB MSB
For LSB justified standard, I2S_WS and I2S_SD are updated on the falling edge of I2S_CK.
In the case that the channel length is equal to the data length, LSB justified standard and
MSB justified standard are exactly the same. In the case that the channel length is greater
than the data length, the valid data is aligned to LSB for LSB justified standard while the valid
data is aligned to MSB for MSB justified standard. The timing diagrams for the cases that the
channel length is greater than the data length are shown below.
Figure 19-31. LSB justified standard timing diagram (DTLEN=01, CHLEN=1, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
8-bit 0 24-bit data
I2S_SD MSB LSB
Figure 19-32. LSB justified standard timing diagram (DTLEN=01, CHLEN=1, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
8-bit 0 24-bit data
I2S_SD MSB LSB
When the packet type is 24-bit data packed in 32-bit frame, two write or read operations to or
from the SPI_DATA register are needed to complete the transmission of a frame. In
transmission mode, if a 24-bit data D[23:0] is going to be sent, the first data written to the
SPI_DATA register should be a 16-bit data. The higher 8 bits of the 16-bit data can be any
value and the lower 8 bits should be D[23:16]. The second data written to the SPI_DATA
register should be D[15:0]. In reception mode, if a 24-bit data D[23:0] is received, the first data
read from the SPI_DATA register is a 16-bit data. The high 8 bits of this 16-bit data are zeros
and the lower 8 bits are D[23:16]. The second data read from the SPI_DATA register is
D[15:0].
Figure 19-33. LSB justified standard timing diagram (DTLEN=00, CHLEN=1, CKPL=0)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit 0 16-bit data
I2S_SD MSB LSB
484
GD32E10x User Manual
Figure 19-34. LSB justified standard timing diagram (DTLEN=00, CHLEN=1, CKPL=1)
frame 1 (channel left) frame 2 (channel right)
I2S_CK
I2S_WS
16-bit 0 16-bit data
I2S_SD MSB LSB
When the packet type is 16-bit data packed in 32-bit frame, only one write or read operation
to or from the SPI_DATA register is needed to complete the transmission of a frame. The
remaining 16 bits are forced by hardware to 0x0000 to extend the data to 32-bit format.
PCM standard
For PCM standard, I2S_WS and I2S_SD are updated on the rising edge of I2S_CK, and the
I2S_WS signal indicates frame synchronization information. Both the short frame
synchronization mode and the long frame synchronization mode are available and
configurable using the PCMSMOD bit in the SPI_I2SCTL register. The SPI_DATA register is
handled in the exactly same way as that for I2S Phillips standard. The timing diagrams for
each configuration of the short frame synchronization mode are shown below.
Figure 19-35. PCM standard short frame synchronization mode timing diagram
(DTLEN=00, CHLEN=0, CKPL=0)
frame 1 frame 2
I2S_CK
I2S_WS
16-bit data
I2S_SD MSB LSB MSB
Figure 19-36. PCM standard short frame synchronization mode timing diagram
(DTLEN=00, CHLEN=0, CKPL=1)
frame 1 frame 2
I2S_CK
I2S_WS
16-bit data
I2S_SD MSB LSB MSB
Figure 19-37. PCM standard short frame synchronization mode timing diagram
(DTLEN=10, CHLEN=1, CKPL=0)
frame 1 frame 2
I2S_CK
I2S_WS
32-bit data
I2S_SD MSB LSB MSB
Figure 19-38. PCM standard short frame synchronization mode timing diagram
485
GD32E10x User Manual
(DTLEN=10, CHLEN=1, CKPL=1)
frame 1 frame 2
I2S_CK
I2S_WS
32-bit data
I2S_SD MSB LSB MSB
Figure 19-39. PCM standard short frame synchronization mode timing diagram
(DTLEN=01, CHLEN=1, CKPL=0)
frame 1 frame 2
I2S_CK
I2S_WS
24-bit data 8-bit 0
I2S_SD MSB MSB
Figure 19-40. PCM standard short frame synchronization mode timing diagram
(DTLEN=01, CHLEN=1, CKPL=1)
frame 1 frame 2
I2S_CK
I2S_WS
24-bit data 8-bit 0
I2S_SD MSB MSB
Figure 19-41. PCM standard short frame synchronization mode timing diagram
(DTLEN=00, CHLEN=1, CKPL=0)
frame 1 frame 2
I2S_CK
I2S_WS
16-bit data 16-bit 0
I2S_SD MSB MSB
Figure 19-42. PCM standard short frame synchronization mode timing diagram
(DTLEN=00, CHLEN=1, CKPL=1)
frame 1 frame 2
I2S_CK
I2S_WS
16-bit data 16-bit 0
I2S_SD MSB MSB
The timing diagrams for each configuration of the long frame synchronization mode are shown
below.
Figure 19-43. PCM standard long frame synchronization mode timing diagram
486
GD32E10x User Manual
(DTLEN=00, CHLEN=0, CKPL=0)
frame 1 frame 2
I2S_CK
13 bits
I2S_WS
16 bits
I2S_SD MSB LSB MSB
Figure 19-44. PCM standard long frame synchronization mode timing diagram
(DTLEN=00, CHLEN=0, CKPL=1)
frame 1 frame 2
I2S_CK
13 bits
I2S_WS
16 bits
I2S_SD MSB LSB MSB
Figure 19-45. PCM standard long frame synchronization mode timing diagram
(DTLEN=10, CHLEN=1, CKPL=0)
frame 1 frame 2
I2S_CK
13 bits
I2S_WS
32 bits
I2S_SD MSB LSB MSB
Figure 19-46. PCM standard long frame synchronization mode timing diagram
(DTLEN=10, CHLEN=1, CKPL=1)
frame 1 frame 2
I2S_CK
13 bits
I2S_WS
32 bits
I2S_SD MSB LSB MSB
Figure 19-47. PCM standard long frame synchronization mode timing diagram
(DTLEN=01, CHLEN=1, CKPL=0)
frame 1 frame 2
I2S_CK
13 bits
I2S_WS
24-bit data 8-bit 0
I2S_SD MSB MSB
Figure 19-48. PCM standard long frame synchronization mode timing diagram
(DTLEN=01, CHLEN=1, CKPL=1)
frame 1 frame 2
I2S_CK
13 bits
I2S_WS
24-bit data 8-bit 0
I2S_SD MSB MSB
487
GD32E10x User Manual
Figure 19-49. PCM standard long frame synchronization mode timing diagram
(DTLEN=00, CHLEN=1, CKPL=0)
frame 1 frame 2
I2S_CK
13 bits
I2S_WS
16-bit data 16-bit 0
I2S_SD MSB MSB
Figure 19-50. PCM standard long frame synchronization mode timing diagram
(DTLEN=00, CHLEN=1, CKPL=1)
frame 1 frame 2
I2S_CK
13 bits
I2S_WS
16-bit data 16-bit 0
I2S_SD MSB MSB
The block diagram of I2S clock generator is shown as Figure 19-51. Block diagram of I2S
clock generator. The I2S interface clocks are configured by the DIV bits, the OF bit, the
MCKOEN bit in the SPI_I2SPSC register and the CHLEN bit in the SPI_I2SCTL register. The
source clock is the system clock(CK_SYS). The I2S bitrate can be calculated by the formulas
shown in Table 19-5. I2S bitrate calculation formulas.
The relationship between audio sampling frequency (Fs) and I2S bitrate is defined by the
following formula:
488
GD32E10x User Manual
So, in order to get the desired audio sampling frequency, the clock generator needs to be
configured according to the formulas listed in Table 19-6. Audio sampling frequency
calculation formulas.
19.9.3. Operation
Operation modes
The operation mode is selected by the I2SOPMOD bits in the SPI_I2SCTL register. There
are four available operation modes, including master transmission mode, master reception
mode, slave transmission mode, and slave reception mode. The direction of I2S interface
signals for each operation mode is shown in the Table 19-7. Direction of I2S interface
signals for each operation mode.
Table 19-7. Direction of I2S interface signals for each operation mode
1. NU means the pin is not used by I2S and can be used by other functions.
I2S initialization sequence contains five steps shown below. In order to initialize I2S to master
mode, all the five steps should be done. In order to initialize I2S to slave mode, only step 2,
step 3, step 4 and step 5 should be done.
Step 1: Configure the DIV[7:0] bits, the OF bit, and the MCKOEN bit in the SPI_I2SPSC
register to define the I2S bitrate and determine whether I2S_MCK needs to be provided
or not.
Step 2: Configure the CKPL in the SPI_I2SCTL register to define the idle state clock
polarity.
Step 3: Configure the I2SSEL bit, the I2SSTD[1:0] bits, the PCMSMOD bit, the
489
GD32E10x User Manual
I2SOPMOD[1:0] bits, the DTLEN[1:0] bits, and the CHLEN bit in the SPI_I2SCTL register
to define the I2S feature.
Step 4: Configure the TBEIE bit, the RBNEIE bit, the ERRIE bit, the DMATEN bit, and
the DMAREN bit in the SPI_CTL1 register to select the potential interrupt sources and
the DMA capabilities. This step is optional.
Step 5: Set the I2SEN bit in the SPI_I2SCTL register to enable I2S.
The TBE flag is used to control the transmission sequence. As is mentioned before, the TBE
flag indicates that the transmit buffer is empty, and an interrupt will be generated if the TBEIE
bit in the SPI_CTL1 register is set. At the beginning, the transmit buffer is empty (TBE is high)
and no transmission sequence is processing in the shift register. When a half word is written
to the SPI_DATA register (TBE goes low), the data is transferred from the transmit buffer to
the shift register (TBE goes high) immediately. At the moment, the transmission sequence
begins.
The data is parallel loaded into the 16-bit shift register, and shifted out serially to the I2S_SD
pin, MSB first. The next data should be written to the SPI_DATA register, when the TBE flag
is high. After a write operation to the SPI_DATA register, the TBE flag goes low. When the
current transmission finishes, the data in the transmit buffer is loaded into the shift register,
and the TBE flag goes back high. Software should write the next audio data into SPI_DATA
register before the current data finishes, otherwise, the audio data transmission is not
continuous.
For all standards except PCM, the I2SCH flag is used to distinguish which channel side the
data to transfer belongs to. The I2SCH flag is refreshed at the moment when the TBE flag
goes high. At the beginning, the I2SCH flag is low, indicating the left channel data should be
written to the SPI_DATA register.
In order to disable I2S, it is mandatory to clear the I2SEN bit after the TBE flag is high and
the TRANS flag is low.
The RBNE flag is used to control the reception sequence. As is mentioned before, the RBNE
flag indicates the receive buffer is not empty, and an interrupt will be generated if the RBNEIE
bit in the SPI_CTL1 register is set. The reception sequence begins immediately when the
I2SEN bit in the SPI_I2SCTL register is set. At the beginning, the receive buffer is empty
(RBNE is low). When a reception sequence finishes, the received data in the shift register is
loaded into the receive buffer (RBNE goes high). The data should be read from the SPI_DATA
register, when the RBNE flag is high. After a read operation to the SPI_DATA register, the
RBNE flag goes low. It is mandatory to read the SPI_DATA register before the end of the next
reception. Otherwise, reception overrun error occurs. The RXORERR flag is set and an
interrupt may be generated if the ERRIE bit in the SPI_CTL1 register is set. In this case, it is
necessary to disable and then enable I2S before resuming the communication.
490
GD32E10x User Manual
For all standards except PCM, the I2SCH flag is used to distinguish which channel side the
received data belongs to. The I2SCH flag is refreshed at the moment when the RBNE flag
goes high.
Different sequences are used to disable the I2S in different standards, data length and
channel length. The sequences for each case are described below.
16-bit data packed in 32-bit frame in the LSB justified standard (DTLEN = 00, CHLEN =
1, and I2SSTD = 10)
16-bit data packed in 32-bit frame in the audio standards except the LSB justified
standard (DTLEN = 00, CHLEN = 1, and I2SSTD is not equal to 0b10)
The transmission sequence in slave mode is similar to that in master mode. The differences
between them are described below.
In slave mode, the slave has to be enabled before the external master starts the
communication. The transmission sequence begins when the external master sends the clock
and when the I2S_WS signal requests the transfer of data. The data has to be written to the
SPI_DATA register before the master initiates the communication. Software should write the
next audio data into SPI_DATA register before the current data finishes. Otherwise,
transmission underrun error occurs. The TXURERR flag is set and an interrupt may be
generated if the ERRIE bit in the SPI_CTL1 register is set. In this case, it is mandatory to
disable and enable I2S to resume the communication. In slave mode, I2SCH is sensitive to
the I2S_WS signal coming from the external master.
In order to disable I2S, it is mandatory to clear the I2SEN bit after the TBE flag is high and
the TRANS flag is low.
The reception sequence in slave mode is similar to that in master mode. The differences
between them are described below.
491
GD32E10x User Manual
In slave mode, the slave has to be enabled before the external master starts the
communication. The reception sequence begins when the external master sends the clock
and when the I2S_WS signal indicates a start of the data transfer. In slave mode, I2SCH is
sensitive to the I2S_WS signal coming from the external master.
In order to disable I2S, it is mandatory to clear the I2SEN bit immediately after receiving the
last RBNE.
DMA function is the same as SPI mode. The only difference is that the CRC function is not
available in I2S mode.
There are four status flags implemented in the SPI_STAT register, including TBE, RBNE,
TRANS and I2SCH. The user can use them to fully monitor the state of the I2S bus.
This bit is set when the transmit buffer is empty, the software can write the next data to the
transmit buffer by writing the SPI_DATA register.
This bit is set when receive buffer is not empty, which means that one data is received and
stored in the receive buffer, and software can read the data by reading the SPI_DATA register.
TRANS is a status flag to indicate whether the transfer is ongoing or not. It is set and cleared
by hardware and not controlled by software. This flag will not generate any interrupt.
This flag indicates the channel side information of the current transfer and has no meaning in
PCM mode. It is updated when TBE rises in transmission mode or RBNE rises in reception
mode. This flag will not generate any interrupt.
This situation occurs when the transmit buffer is empty if the valid SCK signal starts in slave
492
GD32E10x User Manual
transmission mode.
This situation occurs when the receive buffer is full and a newly incoming data has been
completely received. When overrun occurs, the data in receive buffer is not updated and the
newly incoming data is lost.
In slave I2S mode, the I2S monitors the I2S_WS signal and an error flag will be set if I2S_WS
toggles at an unexpected position.
I2S interrupt events and corresponding enable bits are summed up in the Table 19-8. I2S
interrupt.
Interrupt
Interrupt flag Description Clear method
enable bit
TBE Transmit buffer empty Write SPI_DATA register TBEIE
RBNE Receive buffer not empty Read SPI_DATA register RBNEIE
TXURERR Transmission underrun error Read SPI_STAT register
Read SPI_DATA register and
RXORERR Reception overrun error ERRIE
then read SPI_STAT register.
FERR I2S format error Read SPI_STAT register
493
GD32E10x User Manual
19.11. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SWNSS
BDEN BDOEN CRCEN CRCNT FF16 RO SWNSS LF SPIEN PSC[2:0] MSTMOD CKPL CKPH
EN
rw rw rw rw rw rw rw rw rw rw rw rw rw rw
494
GD32E10x User Manual
register. In receive-only mode, set this bit after the second last data is received.
495
GD32E10x User Manual
0: Capture the first data at the first clock transition
1: Capture the first data at the second clock transition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw
496
GD32E10x User Manual
1 DMATEN Transmit buffer DMA enable
0: Transmit buffer DMA is disabled.
1: Transmit buffer DMA is enabled, when the TBE bit in SPI_STAT is set, there will be a
DMA request on corresponding DMA channel.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved FERR TRANS RXORERR CONFERR CRCERR TXURERR I2SCH TBE RBNE
rc_w0 r r r rc_w0 r r r r
497
GD32E10x User Manual
5 CONFERR SPI Configuration error
0: No configuration fault occurs.
1: Configuration fault occurred. (In master mode, the NSS pin is pulled low in NSS
hardware mode or SWNSS bit is low in NSS software mode.)
This bit is set by hardware and cleared by a read or write operation on the SPI_STAT
register followed by a write access to the SPI_CTL0 register.
This bit is not used in I2S mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SPI_DATA[15:0]
rw
498
GD32E10x User Manual
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CRCPOLY[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
499
GD32E10x User Manual
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RCRC[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TCRC[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PCMSMO
Reserved I2SSEL I2SEN I2SOPMOD[1:0] Reserved I2SSTD[1:0] CKPL DTLEN[1:0] CHLEN
D
rw rw rw rw rw rw rw rw
501
GD32E10x User Manual
5:4 I2SSTD[1:0] I2S standard selection
00: I2S Phillips standard
01: MSB justified standard
10: LSB justified standard
11: PCM standard
These bits should be configured when I2S is disabled.
These bits are not used in SPI mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw
502
GD32E10x User Manual
9 MCKOEN I2S_MCK output enable
0: I2S_MCK output is disabled
1: I2S_MCK output is enabled
This bit should be configured when I2S is disabled.
This bit is not used in SPI mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IO23_DR
Reserved QRD QMOD
V
rw rw rw
504
GD32E10x User Manual
20. External memory controller (EXMC)
20.1. Overview
The external memory controller EXMC, is used as a translator for CPU to access a variety of
external memories. By configuring the related registers, it automatically converts AMBA
memory access protocol into a specific memory access protocol, such as SRAM, PSRAM,
ROM and NOR Flash. Users could also adjust the timing parameters in the configuration
registers to improve memory access efficiency.
20.2. Characteristics
EXMC is the combination of four modules: The AHB bus interface, EXMC configuration
registers, NOR/PSRAM controller and external device interface. AHB clock (HCLK) is the
reference clock.
505
GD32E10x User Manual
Figure 20-1. The EXMC block diagram
HCLK
AHB Bus Interface EXMC
from clock interrupt
controller to NVIC
EXMC Configuration
Register
NOR-Flash/PSRAM
Controller
EXMC_NL(or NADV)
EXMC_NBL[1:0]
EXMC_NWAIT
EXMC_D[15:0]
EXMC_A[25:0]
EXMC_NOE
EXMC_NE
EXMC_NWE
EXMC_CLK
NOR/PSRAM
Pins
EXMC is the conversion interface between AHB bus and external device protocol. 32-bit of
AHB read/write access can split into several consecutive 8-bit or 16-bit read/write operations
respectively. In the process of data transmission, AHB access data width and memory data
width may not be the same. In order to ensure consistency of data transmission, read/write
access of EXMC follows the following basic regulation.
When the width of AHB bus equals to the memory bus width, no conversion is applied.
When the width of AHB bus is greater than memory bus width, the AHB accesses will
automatically split into several continuous memory accesses.
When the width of AHB bus is shorter than memory bus width, if the external memory
devices support the byte selection function, such as SRAM, ROM, PSRAM, the
application can access the corresponding byte through EXMC_NBL[1:0]. Otherwise,
write operation is prohibited, but read operation is allowed unconditionally.
506
GD32E10x User Manual
Figure 20-2. EXMC memory banks
0x6000 0000
Bank0(64M) NOR/PSRAM
0x63FF FFFF
EXMC access space is bank0, which is 64 Mbytes, and is used for NOR and PSRAM device
access.
HADDR[25:0] is the byte address whereas the external memory may not be byte accessed,
this will lead to address inconsistency. EXMC can adjust HADDR to accommodate the data
width of the external memory according to the following rules.
When data bus width of the external memory is 8-bit, in this case the memory address
is byte aligned. HADDR[25:0] is connected to EXMC_A[25:0] and then the EXMC_A[25:0]
is connected to the external memory address lines.
When data bus width of the external memory is 16-bit, in this case the memory address
is half-word aligned. HADDR byte address must be converted into half-word aligned by
connecting HADDR[25:1] with EXMC_A[24:0]. The EXMC_A[24:0] is then connected to
the external memory address lines.
NOR/PSRAM memory controller controls bank0, which is designed to support NOR Flash,
PSRAM, SRAM, ROM and honeycomb RAM external memory.
Note:
In asynchronous mode, all output signals of controller will change on the rising edge of internal
AHB bus clock (HCLK).
In synchronous mode, all output data of controller will change on the falling edge of external
memory device clock (EXMC_CLK).
507
GD32E10x User Manual
EXMC pin Direction Mode Functional description
Async/sync
Input/output Data bus
(non-muxed)
EXMC_NE Output Async/sync Chip selection
Output enable(read
EXMC_NOE Output Async/sync
enable)
EXMC_NWE Output Async/sync Write enable
EXMC_NWAIT Input Async/sync Wait input signal
EXMC_NL(NADV) Output Async/sync Address valid
Table below shows an example of the supported device types, access modes and
transactions when the memory data bus is 16-bit for NOR, PSRAM and SRAM.
508
GD32E10x User Manual
AHB Memory
Memory Access mode R/W transaction transaction Comments
width width
Use byte lanes
Async W 8 16
EXMC_NBL[1:0]
Async R 16 16
Async W 16 16
Split into 2 EXMC
Async R 32 16
accesses
Split into 2 EXMC
Async W 32 16
accesses
Sync R 16 16
Sync R 32 16
Use byte lanes
Sync W 8 16
EXMC_NBL[1:0]
Sync W 16 16
Split into 2 EXMC
Sync W 32 16
accesses
Async R 8 8
Async R 8 16
Split into 2 EXMC
Async R 16 8
accesses
Async R 16 16
Split into 4 EXMC
Async R 32 8
accesses
SRAM and Split into 2 EXMC
Async R 32 16
ROM accesses
Async W 8 8
Use byte lanes
Async W 8 16
EXMC_NBL[1:0]
Async W 16 8
Async W 16 16
Async W 32 8
Async W 32 16
EXMC provides various programmable timing parameters and timing models for SRAM, ROM,
PSRAM, NOR Flash and other external static memories.
As shown in Table 20-5. EXMC timing models, EXMC NOR Flash/PSRAM controller
provides a variety of timing models, users can modify those parameters listed in Table 20-4.
NOR/PSRAM controller timing parameters to adapt to different external memory types and
user’s requirements. When extended mode is enabled via the EXMODEN bit in
EXMC_SNCTL register, different timing patterns for read and write access could be
generated independently according to the configuration of EXMC_SNTCFG and
EXMC_SNWTCFG registers.
Mode 1 - SRAM/CRAM
510
GD32E10x User Manual
Figure 20-3. Mode 1 read access
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
Memory Output
(EXMC_D[15:0])
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
EXMC Output
(EXMC_D[15:0])
511
GD32E10x User Manual
Bit position Bit name Reference setting value
7 Reserved 0x1
6 NREN No effect
5-4 NRW Depends on memory
3-2 NRTP Depends on memory, except 0x2(NOR flash)
1 NRMUX 0x0
0 NRBKEN 0x1
EXMC_SNTCFG
31-30 Reserved 0x0
29-28 ASYNCMOD No effect
27-24 DLAT No effect
23-20 CKDIV No effect
Time between EXMC_NE rising edge to
19-16 BUSLAT
EXMC_NE falling edge
Depends on memory and user (DSET+1 HCLK for
15-8 DSET
write, DSET+3 HCLK for read)
7-4 AHLD No effect
3-0 ASET Depends on memory and user
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
Memory Output
(EXMC_D[15:0])
512
GD32E10x User Manual
Figure 20-6. Mode A write access
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
EXMC Output
(EXMC_D[15:0])
The difference of write timing between mode A and mode 1 is that when read and write timings
are specified by the same set of timing configurations, mode A write timing configuration is
independent of its read configuration.
513
GD32E10x User Manual
Bit position Bit name Reference setting value
Time between EXMC_NE rising edge to EXMC_NE
19-16 BUSLAT
falling edge
Depends on memory and user (DSET+3 HCLK for
15-8 DSET
read)
7-4 AHLD No effect
3-0 ASET Depends on memory and user
EXMC_SNWTCFG(write)
31-30 Reserved 0x0
29-28 WASYNCMOD 0x0
27-20 Reserved 0xFF
Time between EXMC_NE rising edge to EXMC_NE
19-16 WBUSLAT
falling edge
Depends on memory and user (WDSET+1 HCLK for
15-8 WDSET
write)
7-4 WAHLD 0x0
3-0 WASET Depends on memory and user
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
Memory Output
(EXMC_D[15:0])
514
GD32E10x User Manual
Figure 20-8. Mode 2 write access
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
EXMC Output
(EXMC_D[15:0])
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
EXMC Output
(EXMC_D[15:0])
515
GD32E10x User Manual
Bit position Bit name Reference setting value
7 Reserved 0x1
6 NREN 0x1
5-4 NRW Depends on memory
3-2 NRTP 0x2, NOR flash
1 NRMUX 0x0
0 NRBKEN 0x1
EXMC_SNTCFG(read and write in mode 2, read in mode B)
31-30 Reserved 0x0
29-28 ASYNCMOD Mode B:0x1
27-24 DLAT No effect
23-20 CKDIV No effect
Time between EXMC_NE rising edge to EXMC_NE
19-16 BUSLAT
falling edge
Depends on memory and user (DSET+3 HCLK for
15-8 DSET
read)
7-4 AHLD 0x0
3-0 ASET Depends on memory and user
EXMC_SNWTCFG(write in mode B)
31-30 Reserved 0x0
29-28 WASYNCMOD Mode B:0x1
27-20 Reserved 0xFF
Time between EXMC_NE rising edge to EXMC_NE
19-16 WBUSLAT
falling edge
Depends on memory and user (WDSET+1 HCLK for
15-8 WDSET
write)
7-4 WAHLD 0x0
3-0 WASET Depends on memory and user
516
GD32E10x User Manual
Figure 20-10. Mode C read access
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
Memory Output
(EXMC_D[15:0])
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
EXMC Output
(EXMC_D[15:0])
The difference of write timing between mode C and mode 1 is that when read and write timings
are specified by the same set of timing configurations, mode C write timing configuration is
independent of its read configuration.
517
GD32E10x User Manual
Bit position Bit name Reference setting value
10 WRAPEN 0x0
9 NRWTPOL Meaningful only when the bit 15 is set to 1
8 SBRSTEN 0x0
7 Reserved 0x1
6 NREN 0x1
5-4 NRW Depends on memory
3-2 NRTP 0x2, NOR flash
1 NRMUX 0x0
0 NRBKEN 0x1
EXMC_SNTCFG
31-30 Reserved 0x0
29-28 ASYNCMOD Mode C: 0x2
27-24 DLAT 0x0
23-20 CKDIV 0x0
Time between EXMC_NE rising edge to EXMC_NE
19-16 BUSLAT
falling edge
Depends on memory and user (DSET+3 HCLK for
15-8 DSET
read)
7-4 AHLD 0x0
3-0 ASET Depends on memory and user
EXMC_SNWTCFG
31-30 Reserved 0x0
29-28 WASYNCMOD Mode C: 0x2
27-20 Reserved 0xFF
Time between EXMC_NE rising edge to EXMC_NE
19-16 WBUSLAT
falling edge
Depends on memory and user (WDSET+1 HCLK for
15-8 WDSET
write)
7-4 WAHLD 0x0
3-0 WASET Depends on memory and user
518
GD32E10x User Manual
Figure 20-12. Mode D read access
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
Memory Output
(EXMC_D[15:0])
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
EXMC Output
(EXMC_D[15:0])
519
GD32E10x User Manual
Bit position Bit name Reference setting value
7 Reserved 0x1
6 NREN Depends on memory
5-4 NRW Depends on memory
3-2 NRTP Depends on memory
1 NRMUX 0x0
0 NRBKEN 0x1
EXMC_SNTCFG
31-30 Reserved 0x0
29-28 ASYNCMOD Mode D: 0x3
27-24 DLAT Don’t care
23-20 CKDIV No effect
Time between EXMC_NE rising edge to
19-16 BUSLAT
EXMC_NE falling edge
Depends on memory and user (DSET+3 HCLK for
15-8 DSET
read)
7-4 AHLD Depends on memory and user
3-0 ASET Depends on memory and user
EXMC_SNWTCFG
31-30 Reserved 0x0
29-28 WASYNCMOD Mode D: 0x3
27-20 Reserved 0xFF
Time between EXMC_NE rising edge to
19-16 WBUSLAT
EXMC_NE falling edge
Depends on memory and user (WDSET+1 HCLK
15-8 WDSET
for write)
7-4 WAHLD Depends on memory and user
3-0 WASET Depends on memory and user
520
GD32E10x User Manual
Figure 20-14. Multiplex mode read access
Address
Address[25:16]
(EXMC_A[25:16])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
1 HCLK
Data Mux
Address[15:0] Memory Output
(EXMC_D[15:0])
Address
Address[25:16]
(EXMC_A[25:16])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Data
Address[15:0] EXMC output
(EXMC_D[15:0])
521
GD32E10x User Manual
Bit position Bit name Reference setting value
7 Reserved 0x1
6 NREN 0x1
5-4 NRW Depends on memory
3-2 NRTP 0x2: NOR flash
1 NRMUX 0x1
0 NRBKEN 0x1
EXMC_SNTCFG
31-30 Reserved 0x0
29-28 ASYNCMOD 0x0
27-24 DLAT No effect
23-20 CKDIV No effect
Time between EXMC_NE rising edge to
19-16 BUSLAT
EXMC_NE falling edge
Depends on memory and user (DSET+2 HCLK for
15-8 DSET
write, DSET+3 HCLK for read)
7-4 AHLD Depends on memory and user
3-0 ASET Depends on memory and user
Wait function is controlled by the bit ASYNCWAIT in register EXMC_SNCTL. During external
memory access, data setup phase will be automatically extended by the active
EXMC_NWAIT signal if ASYNCWAIT bit is set. The extended time is calculated as follows:
If
be
Otherwise
522
GD32E10x User Manual
Figure 20-16. Read access timing diagram under async-wait signal assertion
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Wait
(EXMC_NWAIT)
NRWTPOL = 0
Wait
(EXMC_NWAIT)
NRWTPOL = 1
Output Enable
(EXMC_NOE)
Data
Memory Output
(EXMC_D[15:0])
Figure 20-17. Write access timing diagram under async-wait signal assertion
Address
(EXMC_A[25:0])
Chip Enable
(EXMC_NE)
Wait
(EXMC_NWAIT)
NRWTPOL = 0
Wait
(EXMC_NWAIT)
NRWTPOL = 1
Write Enable
(EXMC_NWE)
The relationship between memory clock (EXMC_CLK) and system clock (HCLK) is as follows:
HCLK
EXMC_CLK= (20-5)
CKDIV+1
CKDIV is the synchronous clock divider ratio, it is configured through the CKDIV control field
in the EXMC_SNTCFG register.
Data latency (DLAT) is the number of EXMC_CLK cycles to wait before sampling the data.
The relationship between data latency and latency parameter of NOR Flash in specification
is as follows.
For specification of NOR Flash excludes the EXMC_NADV cycle, their relationship should be:
523
GD32E10x User Manual
NOR Flash latency=DLAT+2 (20-6)
For specification of NOR Flash includes the EXMC_NADV cycle, their relationship should be:
2. Data wait
Users should guarantee that EXMC_NWAIT signal matches that of the external device. This
signal is configured through the EXMC_SNCTL registers, it is enabled by the NRWTEN bit,
and the active timing could be one data cycle before the wait state or active during the wait
state by the NRWTCFG bit, and the wait signal polarity is set by the NRWTPOL bit.
In NOR Flash synchronous burst access mode, when NRWTEN bit in EXMC_SNCTL register
is set, EXMC_NWAIT signal will be detected after a period of data latency. If EXMC_NWAIT
signal detected is valid, wait cycles will be inserted until EXMC_NWAIT becomes invalid.
During wait state which is inserted via the EXMC_NWAIT signal, the controller continues to
send clock pulses to the memory, keep the chip select signal and output signals available,
and ignore the invalid data signal.
Crossing page boundary burst access is prohibited in CRAM 1.5, an automatic burst split
functionality is implemented by the EXMC. To guarantee correct burst split operation, users
should specify CRAM page size by configuring the CPS bit in EXMC_SNCTL register to
inform the EXMC when this functionality should be performed.
For synchronous burst transmission, if the needed data of AHB is 16-bit, EXMC will perform
a burst transmission whose length is 1. If the needed data of AHB is 32-bit, EXMC will make
the transmission divided into two 16-bit transmissions, that is, EXMC performs a burst
transmission whose length is 2.
For other configurations please refer to Table 20-3. EXMC bank0 supported transactions.
524
GD32E10x User Manual
Figure 20-18. Read timing of synchronous multiplexed burst mode
HCLK
Clock
(EXMC_CLK)
Address
Address [25:16]
(EXMC_A[25:16])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Wait
(EXMC_NWAIT)
525
GD32E10x User Manual
Bit position Bit name Reference setting value
27-24 DLAT Data latency
23-20 CKDIV The figure above: 0x1, EXMC_CLK=2HCLK
Time between EXMC_NE rising edge to EXMC_NE
19-16 BUSLAT
falling edge
15-8 DSET No effect
7-4 AHLD No effect
3-0 ASET No effect
HCLK
Clock
(EXMC_CLK)
Address
Address [25:16]
(EXMC_A[25:16])
Chip Enable
(EXMC_NE)
Address Valid
(EXMC_NADV)
Output Enable
(EXMC_NOE)
Write Enable
(EXMC_NWE)
Wait
(EXMC_NWAIT)
526
GD32E10x User Manual
Bit position Bit name Reference setting value
8 SBRSTEN No effect
7 Reserved 0x1
6 NREN Depends on memory
5-4 NRW 0x1
3-2 NRTP 0x1
1 NRMUX 0x1, depends on users
0 NRBKEN 0x1
EXMC_SNTCFG(write)
31-30 Reserved 0x0
29-28 ASYNCMOD 0x0
27-24 DLAT Data latency
23-20 CKDIV The figure above: 0x1, EXMC_CLK=2HCLK
Time between EXMC_NE rising edge to
19-16 BUSLAT
EXMC_NE falling edge
15-8 DSET No effect
7-4 AHLD No effect
3-0 ASET No effect
527
GD32E10x User Manual
20.4. Register definition
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw rw rw rw rw rw rw rw rw rw rw
529
GD32E10x User Manual
20.4.2. SRAM/NOR Flash timing configuration registers (EXMC_SNTCFG)
rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw
27:24 DLAT[3:0] Data latency for NOR Flash. Only valid in synchronous access.
0x0: Data latency of first burst access is 2 EXMC_CLK
0x1: Data latency of first burst access is 3 EXMC_CLK
……
0xF: Data latency of first burst access is 17 EXMC_CLK
23:20 CKDIV[3:0] Synchronous clock divide ratio. This filed is only effect in synchronous mode.
0x0: Reserved
0x1: EXMC_CLK period = 2 * HCLK period
……
0xF: EXMC_CLK period = 16 * HCLK period
530
GD32E10x User Manual
This field is meaningful only in asynchronous access.
0x00: Reserved
0x01: Data setup time = 2 * HCLK period
……
0xFF: Data setup time = 256 * HCLK period
(EXMC_SNWTCFG)
This register is meaningful only when the EXMODEN bit in EXMC_SNCTL is set to 1.
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
rw rw rw
531
GD32E10x User Manual
10: Mode C access
11: Mode D access
532
GD32E10x User Manual
21. Universal serial bus full-speed interface (USBFS)
21.1. Overview
USB Full-Speed (USBFS) controller provides a USB-connection solution for portable devices.
USBFS supports host and device modes, as well as OTG mode with HNP (Host Negotiation
Protocol) and SRP (Session Request Protocol). USBFS contains a full-speed internal USB
PHY and the external PHY chip is not contained. USBFS supports all the four types of transfer
(control, bulk, interrupt and isochronous) which are defined in USB 2.0 protocol.
21.2. Characteristics
533
GD32E10x User Manual
21.3. Block diagram
Data DP
FIFO Transcation OTG UTMI USB FS DM
Scheduler Control Mux PHY ID
VBUS
SIE
USB Clock
48MHz
USB Clock Domain
DM Input/Output Differential D-
DP Input/Output Differential D+
The internal PHY supports full-speed and low-speed in host mode, supports full-speed in
device mode, and supports OTG mode with HNP and SRP. The USB clock used by the
USBFS should be 48MHz. The 48MHz USB clock is generated from internal clocks in system,
and its source and divider factors are configurable in RCU.
The pull-up and pull-down resistors have already been integrated into the internal PHY and
534
GD32E10x User Manual
they could be controlled by USBFS automatically according to the current mode (host, device
or OTG mode) and connection status. A typical connection is shown in Figure 21-2.
Connection with host or device mode.
USBFS
5V Power
Supply
GPIO (needed in
host mode)
DM DM
DP DP
GND
When USBFS works in host mode (FHM bit is set and FDM bit is cleared), the VBUS is 5V
power supplied and detecting pin which is used for voltage detection is defined in USB
protocol. The internal PHY cannot supply 5V VBUS power and only has some voltage
comparers, charge and discharge circuits on VBUS line. Thus, if application needs VBUS
power, an external power supply IC is needed. The VBUS connection between USBFS and
the USB connector can be omitted in host mode, so USBFS doesn’t detect the voltage level
on VBUS pin and always assumes that the 5V power is present.
When USBFS works in device mode (FHM bit is cleared and FDM bit is set), the VBUS
detection circuit is configured by VBUSIG bit in USBFS_GCCFG register. So if the device
does not need to detect the voltage on VBUS pin, it could be configured by setting the
VBUSIG bit, then the VBUS pin can be freed for other uses. Otherwise, the VBUS connection
cannot be omitted, and USBFS continuously monitors the VBUS voltage. It will immediately
switch off the pull-up resistor on DP line once that the VBUS voltage falls below the needed
valid value, leading to a disconnection.
The OTG mode connection is described in the Figure 21-3. Connection with OTG mode.
When USBFS works in OTG mode, the FHM, FDM bits in USBFS_GUSBCS and VBUSIG bit
in USBFS_GCCFG should be cleared. In this mode, the USBFS needs all the four pins: DM,
DP, VBUS and ID, and needs to use several voltage comparers to monitor the voltage on
these pins. USBFS also contains VBUS charge and discharge circuits to perform SRP request
which is described in OTG protocol. The OTG A-Device or B-Device is decided by the level
of the ID pin. USBFS controls the pull-up or pull-down resistor during performing the HNP
protocol.
535
GD32E10x User Manual
Figure 21-3. Connection with OTG mode
VDD
USBFS
5V Power
GPIO Supply
VBUS
USB Micro/Mini
VBUS
connector
DM
DM
DP
DP
ID
ID
GND
Host application may control state of the USB port via USBFS_HPCS register. After system
initialization, the USB port stays at power-off state. After PP bit is set by software, the internal
USB PHY is powered on, and the USB port changes into disconnected state. After a
connection is detected, USB port changes into connected state. The USB port changes into
enabled state after a port reset is performed on USB bus.
Power-off
clear PP bit
Enabled
set PP bit
clear PE bit port reset
disconnection event
disconnection event
As a USB host, USBFS will trigger a connection flag for application after a connection is
536
GD32E10x User Manual
detected and will trigger a disconnection flag after a disconnection event.
PRST bit in USBFS_HPCS register is used for USB reset sequence. Application may set this
bit to start a USB reset and clear this bit to finish the USB reset. This bit only takes effect
when port is at connected or enabled state.
The USBFS performs speed identification during connection, and the speed information will
be reported in PS field in USBFS_HPCS register. USBFS identifies the device speed by the
voltage level of DM or DP. As described in USB protocol, full-speed device pulls up DP line,
while low-speed device pulls up DM line.
USBFS supports suspend state and resume operation. When USBFS port is at enabled state,
writing 1 to PSP bit in USBFS_HPCS register will cause USBFS to enter into suspend state.
In suspend state, USBFS stops sending SOFs on USB bus, and it will lead the connected
USB device to enter into suspend state after 3ms. Application can set the PREM bit in
USBFS_HPCS register to start a resume sequence, so as to wake up the suspended device,
and clear this bit to stop the resume sequence. The WKUPIF bit in USBFS_GINTF will be set
and the USBFS wakeup interrupt will be triggered if a host in suspend state detects a remote
wakeup signal.
SOF generate
USBFS sends SOF tokens on USB bus in host mode. As described in USB 2.0 protocol, SOF
packets are generated (by the host controller or hub transaction translator) each 1ms in full-
speed links.
Once that USBFS entered into enabled state, it will send the SOF packet periodically and the
period is defined in USB 2.0 protocol. In addition, application may adjust the length of a frame
by writing FRI field in USBFS_HFT registers. The FRI bits define the number of USB clock
cycles in a frame, so its value should be calculated based on the frequency of USB clock
which is used by USBFS. The FRT field bits show that the remaining clock cycles of the
current frame and it stops changing during suspend state.
USBFS is able to generate a pulse signal for each SOF packet and output it to a pin. The
pulse length is 16 HCLK cycles. If application desires to use this function, it needs to set
SOFOEN bit in USBFS_GCCFG register and configure the related pin registers in GPIO.
USBFS includes 8 independent channels in host mode. Each channel is able to communicate
with an endpoint in USB device. The transfer type, direction, packet length and other
information are all configured in channel related registers such as USBFS_HCHxCTL and
USBFS_HCHxLEN.
USBFS supports all the four types of transfer: control, bulk, interrupt and isochronous. USB
2.0 protocol divides these transfers into 2 kinds: non-periodic transfer (control and bulk) and
periodic transfer (interrupt and isochronous). Based on this, USBFS includes two request
537
GD32E10x User Manual
queues: periodic request queue and non-periodic request queue, to perform efficient
transaction schedule. A request entry in a request queue described above may represent a
USB transaction request or a channel operation request.
Application needs to write packet into data FIFO via AHB bus if it wants to start an OUT
transaction on USB bus. USBFS hardware will automatically generate a transaction request
entry in request queue after the application writes a whole packet.
The request entries in request queue are processed in order by transaction control module.
USBFS always tries to process periodic request queue firstly and secondly process non-
periodic request queue.
After a start of frame, USBFS begins to process periodic queue until the queue is empty or
bus time required by the current periodic request is not enough, and then process the non-
periodic queue. This strategy ensures the bandwidth of periodic transactions in a frame. Each
time the USBFS reads and pops a request entry from request queue. If the request is a
channel disable request, it immediately disables the channel and prepares to process the
next entry.
If the current request is a transaction request and the USB bus time is enough for this
transaction, USBFS will employ SIE to generate this transaction on USB bus.
When the required bus time for the current request is not enough in the current frame, and
this is a periodic request, USBFS stops processing the periodic queue and starts to process
non-periodic request. If this is a non-periodic queue, the USBFS will stop processing any
queue and wait until the end of current frame.
In device mode, USBFS stays at power-off state after initialization. After connecting to a USB
host with a 5V power supply through VBUS pin or setting VBUSIG bit in USBFS_GCCFG
register, USBFS enters into power-on state. In this state, USBFS begins to switch on the pull-
up resistor on DP line and then the host will detect a connection event.
The USB host always starts a USB reset sequence when it detects a device connection, and
USBFS in device mode will trigger a reset interrupt by hardware when it detects the reset
event on USB bus.
After the reset sequence, USBFS will trigger an ENUMF interrupt in USBFS_GINTF register
and report current enumerated device speed by ES bits in USBFS_DSTAT register, the bit
field is always 11(full-speed).
As described in USB 2.0 protocol, USBFS doesn’t support low-speed in device mode.
538
GD32E10x User Manual
A USB device will enter into suspend state if the USB bus stays at IDLE state and there is no
change on data lines for 3ms. When USB device is in suspend state, most of its clocks are
closed to save power. The USB host is able to wake up the suspended device by generating
a resume signal on USB bus. When USBFS detects the resume signal, the WKUPIF flag in
USBFS_GINTF register will be set and the USBFS wakeup interrupt will be triggered.
In suspend mode, USBFS is also able to remotely wake up the USB bus. Software may set
RWKUP bit in USBFS_DCTL register to send a remote wakeup signal, and if remote wakeup
is supported in USB host, the host will begin to send the resume signal on USB bus.
Soft Disconnection
USBFS supports soft disconnection. After the device is powered on, USBFS will switch on
the pull-up resistor on DP line so that the host can detect the connection. It is able to force a
disconnection by setting the SD bit in USBFS_DCTL register. After the SD bit is set, USBFS
will directly switch off the pull-up resistor, so that USB host will detect a disconnection on USB
bus.
SOF tracking
When USBFS receives a SOF packet on USB bus, it will trigger a SOF interrupt and begin to
count the bus time by local USB clock. The frame number of the current frame is reported in
FNRSOF field in USBFS_DSTAT register. When the USB bus time reaches EOF1 or EOF2
point (End of Frame, described in USB 2.0 protocol), USBFS will trigger an EOPFIF interrupt
in USBFS_GINTF register. These flags and registers can be used to get current bus time and
position information.
USBFS supports OTG function described in OTG protocol 1.3, OTG function includes SRP
and HNP protocols.
A-Device is an OTG capable USB device with a Standard-A or Micro-A plug inserted into its
receptacle. The A-Device supplies power to VBUS and it is a host by default at the start of a
session. B-Device is an OTG capable USB device with a Standard-B, Micro-B or Mini-B plug
inserted into its receptacle, or a captive cable ending being a Standard-A plug. The B-Device
is a peripheral by default at the start of a session. USBFS uses the voltage level of ID pin to
identify A-Device or B-Device. The ID status is reported in IDPS bit in USBFS_GOTGCS
register. For the details of transfer states between A-Device and B-Device, please refer to
OTG 1.3 protocol.
HNP
The Host Negotiation Protocol (HNP) allows the host function to be switched between two
directly connected On-The-Go devices and eliminates the necessity of switching the cable
connections for the change about control of communications between the devices. HNP will
539
GD32E10x User Manual
be initialized typically by the user or an application on the On-The-Go B-Device. HNP may
only be implemented through the Micro-AB receptacle on a device.
When USBFS is in OTG A-Device host mode and it wants to give up its host role, it may firstly
set PSP bit in USBFS_HPCS register to make the USB bus enter into suspend status. Then,
the B-Device will enter into suspend state 3ms later. If the B-Device wants to change to be a
host, HNPREQ bit in USBFS_GOTGCS register should be set and the USBFS will begin to
perform HNP protocol on bus, and at last, the result of HNP is reported in HNPS bit in
USBFS_GOTGCS register. In additional, it is always available to get the current role (host or
device) from COPM bit in USBFS_GINTF register by application.
SRP
The Session Request Protocol (SRP) allows a B-Device to request the A-Device to turn on
VBUS and start a session. This protocol allows the A-Device, which may be battery powered,
to save power by turning VBUS off when there is no bus activity, while still providing a means
for the B-Device to initiate bus activity. As is described in OTG protocol, an OTG device must
compare VBUS voltage with several threshold values, and the compared result should be
reported in ASV and BSV bits in USBFS_GOTGCS register.
Set SRPREQ bit in USBFS_GOTGCS register to start a SRP request when USBFS is in OTG
B-Device mode. USBFS will generate a success flag SRPS in USBFS_GOTGCS register if
the SRP requests successfully.
When USBFS is in OTG A-Device mode and it has detected a SRP request from a B-Device,
it sets a SESIF flag in USBFS_GINTF register. The 5V power supply for VBUS pin should be
prepared to switch on after getting this flag.
The USBFS contains a 1.25K bytes data FIFO for packet data storage. The data FIFO is
implemented by using an internal SRAM in USBFS.
Host Mode
In host mode, the data FIFO space is divided into 3 parts: Rx FIFO for received packet, non-
periodic Tx FIFO for non-period transmission packet and periodic Tx FIFO for periodic
transmission packet. All IN channels shares the Rx FIFO for packets reception. All the
periodic OUT channels share the periodic Tx FIFO for packets transmission. All the non-
periodic OUT channels share the non-periodic FIFO for packets transmission. The size and
start offset of these data FIFOs should be configured using these registers: USBFS_GRFLEN,
540
GD32E10x User Manual
USBFS_HNPTFLEN and USBFS_HPTFLEN. Figure 21-5. HOST mode FIFO space in
SRAM describes the structure of these FIFOs in SRAM. The values in the figure are in terms
of 32-bit words.
Start: 0x00
Rx FIFO RXFD
HNPTXRSAR[15:0]
Rx FIFO
Non-Periodic Tx FIFO HNPTXFD
HPTXRSAR[15:0]
End: 0x13F
USBFS provides a special register area for the internal data FIFO reading and writing. Figure
21-6. Host mode FIFO access register mapping describes the register memory area that
the data FIFO can access. The addresses in the figure are addressed in bytes. Each channel
has its own FIFO access register space, although all non-periodic channels share the same
FIFO and all the periodic channels also share the same FIFO. It is important for USBFS to
get which channel the current pushed packet belongs to, and the Rx FIFO which the packet
belongs to is also able to be accessed by using USBFS_GRSTATR/USBFS_GRSTATP
register.
Device mode
541
GD32E10x User Manual
In device mode, the data FIFO is divided into several parts: 1 Rx FIFO, and 4 Tx FIFOs (one
for each IN endpoint). All the OUT endpoints share the Rx FIFO for receiving packets. The
size and start offset of these data FIFOs should be configured by using USBFS_GRFLEN
and USBFS_DIEPxTFLEN (x=0…3) registers. Figure 21-7. Device mode FIFO space in
SRAM describes the structure of these FIFOs in SRAM. The values in the figure are in terms
of 32-bit words.
Rx FIFO RXFD
IEPTX0RSAR[15:0]
Tx FIFO0 IEPTX0FD
IEPTX1RSAR[15:0]
Tx FIFO1 IEPTX1FD
.
.
.
IEPTX3RSAR[15:0]
Tx FIFO3 IEPTX3FD
End: 0x13F
USBFS provides a special register area for the internal data FIFO reading and writing. Figure
21-8. Device mode FIFO access register mapping describes the register memory area
where the data FIFO can access. The addresses in the figure are addressed in bytes. Each
endpoint has its own FIFO access register space. Rx FIFO is also able to be accessed by
using USBFS_GRSTATR/USBFS_GRSTATP register.
542
GD32E10x User Manual
21.5.6. Operation guide
Host mode
5. Program USBFS_GINTEN register to enable mode fault and host port interrupt and set
GINTEN bit in USBFS_GAHBCS register to enable global interrupt.
7. Wait for a device’s connection, and once a device is connected, the connection interrupt
PCD in USBFS_HPCS register will be triggered. Then set PRST bit to perform a port
reset. Wait for at least 10ms and then clear PRST bit.
8. Wait PEDC interrupt in USBFS_HPCS register and then read PE bit to ensure that the
port is successfully enabled. Read PS [1:0] bits to get the connected device’s speed and
then program USBFS_HFT register to change the SOF interval if needed.
1. Program USBFS_HCHxCTL registers with desired transfer type, direction, packet size,
etc. Ensure that CEN and CDIS bits are kept cleared during configuration.
For OUT channel: If PCNT=1, the single packet’s size is equal to TLEN. If PCNT>1, the
former PCNT-1 packets are considered as max-packet-lengthened packets whose size
are defined by MPL field in USBFS_HCHxCTL register, and the last packet’s size is
calculated based on PCNT, TLEN and MPL. If software wants to send out a zero-
lengthened packet, it should program TLEN=0, PCNT=1.
For IN channel: Because the application doesn’t know the actual received data size
before the IN transaction finishes, TLEN could be set to a maximum possible value
supported by Rx FIFO.
543
GD32E10x User Manual
4. Set CEN bit in USBFS_HCHxCTL register to enable the channel.
Software can disable the channel by setting both CEN and CDIS bits at the same time.
USBFS will generate a channel disable request entry in request queue after the register
setting operation. When the request entry reaches the top of request queue, it will be
processed by USBFS immediately:
For OUT channels, the specified channel will be disabled immediately. Then, a CH flag will
be generated and the CEN and CDIS bits will be cleared by USBFS.
For IN channels, USBFS pushes a channel disable status entry into Rx FIFO. Then software
should handle the Rx FIFO not empty event: read and pop this status entry, and then, a CH
flag will be generated and the CEN and CDIS bits will be cleared.
4. After the IN channel is enabled by software, USBFS generates an Rx request entry in the
corresponding request queue.
5. When the Rx request entry reaches the top of the request queue, USBFS begins to
process this request entry. If bus time for the IN transaction indicated by the request entry
is enough, USBFS starts the IN transaction on USB bus.
7. If the IN transaction described in step 5 is successful and PCNT is larger than 1 in step2,
returns to step 3 and continues to receive the remaining packets. If the IN transaction
described in step 5 is not successful, returns to step 3 to re-receive the packet again.
8. After all the transactions in a transfer have been successfully received on USB bus,
USBFS pushes a TF status entry into the Rx FIFO on top of the last packet data. Thus
after reading and popping all the received data packet, the TF status entry is read. USBFS
generates TF flag to indicate that the transfer successfully have been finished.
9. Disable the channel. Now the channel is in IDLE state and is ready for other transfers.
3. Write a packet into the channel’s Tx FIFO (Periodic Tx FIFO or non-periodic Tx FIFO).
544
GD32E10x User Manual
After the whole packet data is written into the FIFO, USBFS generates a Tx request entry
in the corresponding request queue and decreases the TLEN field in USBFS_HCHxLEN
register by the written packet’s size.
4. When the request entry reaches the top of the request queue, USBFS begins to process
this request entry. If bus time for the transaction indicated by the request entry is enough,
USBFS starts the OUT transaction on USB bus.
5. When the OUT transaction indicated by the request entry has been finished on USB bus,
PCNT in USBFS_HCHxLEN register is decreased by 1. If the transaction is finished
successfully (ACK handshake received), the ACK flag is triggered. Otherwise, the status
flag (NAK) reports the transaction result.
6. If the OUT transaction described in step 5 is successful and PCNT is larger than 1 in step
2, returns to step 3 and continues to send the remaining packets. If the OUT transaction
described in step 5 is not successful, return to step 3 to re-send the packet again.
7. After all the transactions in a transfer are successfully sent on USB bus, USBFS
generates TF flag to indicate that the transfer successfully finishes.
8. Disable the channel. Now the channel is in IDLE state and is ready for other transfers.
Device mode
7. After the device is connected to a host, the host will perform port reset on USB bus and
this will trigger the RST interrupt in USBFS_GINTF register.
For IN endpoint:If PCNT=1, the single packet’s size is equal to TLEN. If PCNT>1, the
former PCNT-1 packets are considered as max-packet-length packets whose size are
defined by MPL field in USBFS_DIEPxCTL register, and the last packet’s size is
calculated based on PCNT, TLEN and MPL. If a zero-length packet is required to be sent,
it should program TLEN=0, PCNT=1.
For OUT endpoint:Because the application doesn’t know the actual received data size
before the OUT transaction finishes, TLEN can be set to a maximum possible value
supported by Rx FIFO.
The endpoint could be disabled anytime when the EPEN bit in USBFS_DIEPxCTL or
USBFS_DOEPxCTL registers is cleared.
3. Write packets into the endpoint’s Tx FIFO. At any time, a data packet is written into the
FIFO, USBFS decreases the TLEN field in USBFS_DIEPxLEN register by the written
packet’s size.
4. When an IN token received, USBFS transmits the data packet, and after the transaction
finishes on USB bus, PCNT in USBFS_DIEPxLEN register is decreased by 1. If the
transaction finishes successfully (ACK handshake received), the ACK flag is triggered.
Otherwise, the status flags reports the transaction result.
5. After all the data packets in a transfer have been successfully sent on USB bus, USBFS
generates TF flag to indicate that the transfer successfully is finished and the IN endpoint
is disabled.
546
GD32E10x User Manual
3. When an OUT token is received, USBFS receives the data packet or response with an
NAK handshake based on the status of Rx FIFO and register configuration. If the
transaction is finished successfully (USBFS receives and saves the data packet into Rx
FIFO successfully and sends ACK handshake on USB bus), PCNT in
USBFS_DOEPxLEN register is decreased by 1 and the ACK flag is triggered, otherwise,
the status flags report the transaction result.
4. After all the data packets in a transfer are successfully received on USB bus, USBFS
pushes a TF status entry into the Rx FIFO on top of the last packet data. Thus, after
reading and popping all the received data packet, the TF status entry is read. USBFS
generates TF flag to indicate that the transfer is successfully finished and the IN endpoint
is disabled.
21.6. Interrupts
The source flags of the global interrupt are readable in USBFS_GINTF register and are listed
in Table 21-2. USBFS global interrupt.
547
GD32E10x User Manual
Interrupt flag Description Operation mode
Wakeup interrupt can be triggered when USBFS is in suspend state, even if when the
USBFS’s clocks are stopped. The source of the wakeup interrupt is WKUPIF bit in
USBHS_GINTF register.
548
GD32E10x User Manual
21.7. Register definition
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
IDPS
BSV
ASV
DI
r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
HNPREQ
Reserved
DHNPEN
HHNPEN
SRPREQ
HNPS
SRPS
rw rw rw r rw r
17 DI Debounce interval
Debounce interval of a detected connection
0: Indicates the long debounce interval, when a plug-on and connection occurs on
USB bus.
1: Indicates the short debounce interval, when a soft connection is used in HNP
549
GD32E10x User Manual
protocol.
Note: Only accessible in host mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
Reserved
HNPDET
ADTO
DF
rc_w1 rc_w1 rc_w1
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
Reserved
Reserved
HNPEND
SRPEND
SESEND
rc_w1 rc_w1 rc_w1
19 DF Debounce finish
Set by USBFS when the debounce is done during device connection.
Note: Only accessible in host mode.
551
GD32E10x User Manual
Set by the core when a HNP ends. Read the HNPS in USBFS_GOTGCS register
to get the result of HNP.
Note: Accessible in both device and host modes.
8 SRPEND SRPEND
Set by the core when a SRP ends. Read the SRPS in USBFS_GOTGCS register to
get the result of SRP.
Note: Accessible in both device and host modes.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
Reserved
PTXFTH
GINTEN
TXFTH
rw rw rw
552
GD32E10x User Manual
Host mode:
0: NPTXFEIF will be triggered when the non-periodic Tx FIFO is half empty.
1: NPTXFEIF will be triggered when the non-periodic Tx FIFO is completely empty.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
Reserved
FDM
FHM
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
Reserved
HNPCEN
SRPCEN
TOC[2:0]
UTT[3:0]
rw r/rw r/rw rw
553
GD32E10x User Manual
1: Host mode
The application must wait at least 25ms for the change taking effect after setting the
force bit.
Note: Accessible in both device and host modes.
The application uses this register to reset various hardware features inside the core.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
554
GD32E10x User Manual
TXFNUM[4:0]
Reserved
Reserved
HCSRST
HFCRST
CSRST
RXFF
TXFF
rw rs rs rs rs rs
555
GD32E10x User Manual
Set by the application to reset AHB clock domain circuit.
Hardware automatically clears this bit after the reset process completes. After
setting this bit, application should wait until this bit is cleared before any other
operation on USBFS.
Note: Accessible in both device and host modes.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ISOONCIF
Reserved.
ISOINCIF
Reserved
Reserved
PTXFEIF
PXNCIF/
WKUPIF
DISCIF
IDPSC
OEPIF
SESIF
IEPIF
HCIF
HPIF
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
NPTXFEIF
ISOOPDIF
GNPINAK
Reserved
RXFNEIF
EOPFIF
GONAK
ENUMF
OTGIF
COPM
MFIF
SOF
RST
ESP
SP
556
GD32E10x User Manual
27 Reserved Must be kept at reset value.
557
GD32E10x User Manual
18 IEPIF IN endpoint interrupt flag
Set by USBFS when one of the IN endpoints in device mode has raised an interrupt.
Software should first read USBFS_DAEPINT register to get the endpoint number,
and then read the corresponding USBFS_DIEPxINTF register to get the flags of the
endpoint that cause the interrupt. This bit will be automatically cleared after the
respective endpoint’s flags which cause this interrupt are cleared.
Note: Only accessible in device mode.
11 SP USB suspend
USBFS sets this bit when it detects that the USB bus is idle for 3ms and enters
suspend state.
Note: Only accessible in device mode.
558
GD32E10x User Manual
Note: Only accessible in device mode.
This register works with the global interrupt flag register (USBFS_GINTF) to interrupt the
application. When an interrupt enable bit is disabled, the interrupt associated with that bit is
not generated. However, the global Interrupt flag register bit corresponding to that interrupt is
559
GD32E10x User Manual
still set.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
ISOONCIE
Reserved.
ISOINCIE
Reserved
Reserved
PTXFEIE
IDPSCIE
PXNCIE/
WKUPIE
DISCIE
OEPIE
SESIE
IEPIE
HCIE
HPIE
rw rw rw rw rw rw r rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
GNPINAKIE
NPTXFEIE
ISOOPDIE
GONAKIE
ENUMFIE
RXFNEIE
Reserved
Reserved
EOPFIE
OTGIE
SOFIE
RSTIE
ESPIE
MFIE
SPIE
rw rw rw rw rw rw rw rw rw rw rw rw rw
560
GD32E10x User Manual
Note: Only accessible in host mode.
561
GD32E10x User Manual
Note: Only accessible in device mode.
562
GD32E10x User Manual
1 MFIE Mode fault interrupt enable
0: Disable mode fault interrupt
1: Enable mode fault interrupt
Note: Accessible in both device and host modes.
A read to the receive status read register returns the entry of the top of the Rx FIFO. A read
to the receive status pop register pops the top entry out of the Rx FIFO.
The entries in Rx FIFO have different meanings in host and device modes. Software should
only read this register after when Rx FIFO non-empty interrupt flag bit of the global interrupt
flag register (RXFNEIF bit in USBFS_GINTF) is triggered.
Host mode:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RPCKST[3:0]
Reserved
DPID
r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BCOUNT[10:0]
CNUM[3:0]
DPID
r r r
563
GD32E10x User Manual
00: DATA0
10: DATA1
01: DATA2
11: MDATA
Device mode:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RPCKST[3:0]
Reserved
DPID
r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
BCOUNT[10:0]
EPNUM[3:0]
DPID
r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
15 14 13 12 11 10 9 8 Reserved
RXFD[15:0] 7 6 5 4 3 2 1 0
r/rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IEP0TXFD[15:0]
HNPTXFD/
r/rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
565
GD32E10x User Manual
HNPTXRSAR/
IEP0TXRSAR
[15:0]
r/rw
Host Mode:
Bits Fields Descriptions
31:16 HNPTXFD[15:0] Host non-periodic Tx FIFO depth
In terms of 32-bit words
1≤HNPTXFD≤1024
Device Mode:
Bits Fields Descriptions
31:16 IEP0TXFD[15:0] IN endpoint 0 Tx FIFO depth
In terms of 32-bit words
16≤IEP0TXFD≤140
This register reports the current status of the non-periodic Tx FIFO and request queue. The
request queue includes IN, OUT or other request entries in host mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
NPTXRQS[7:0]
NPTXRQTOP
Reserved
[6:0]
r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
NPTXFS[15:0]
566
GD32E10x User Manual
r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
VBUSBCEN
VBUSACEN
Reserved
Reserved
SOFOEN
PWRON
VBUSIG
567
GD32E10x User Manual
rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
Bits Fields Descriptions
31:22 Reserved Must be kept at reset value.
16 PWRON Power on
This bit is the power switch for the internal embedded full-speed PHY.
0: Embedded full-speed PHY power off
1: Embedded full-speed PHY power on
568
GD32E10x User Manual
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
CID[31:16]
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CID[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
HPTXFD
[15:0]
r/rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HPTXFSAR
[15:0]
r/rw
569
GD32E10x User Manual
Device IN endpoint Tx FIFO length register (USBFS_DIEPxTFLEN) (x = 1…3,
where x is the FIFO_number)
Address offset: 0x0104 + (FIFO_number – 1) × 0x04
Reset value: 0x0200 0400
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
IEPTXFD[15:0]
r/rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IEPTXRSAR
15:0]
r/rw
This register configures the core after power on in host mode. It is not need to modify it after
host initialization.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
570
GD32E10x User Manual
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CLKSEL[1:0]
Reserved
rw
This register sets the frame interval when USBFS controller is enumerating USB device.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FRI[15:0]
rw
571
GD32E10x User Manual
Host frame information remaining register (USBFS_HFINFR)
Address offset: 0x408
Reset value: 0xBB80 0000
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FRT[15:0]
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FRNUM[15:0]
This register reports the current status of the host periodic Tx FIFO and request queue. The
request queue includes IN, OUT or other request entries in host mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PTXREQS[7:0]
PTXREQT[7:0]
r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
572
GD32E10x User Manual
PTXFS[15:0]
r
When a channel interrupt is triggered, USBFS sets a corresponding bit in this register and
software should read this register to know which channel is asserting interrupts.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
573
GD32E10x User Manual
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
HACHINT[7:0]
Reserved
This register can be used by software to enable or disable a channel’s interrupt. Only when
the channel whose corresponding bit in this register is set, so as to cause the channel interrupt
flag HCIF set in USBFS_GINTF register.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CINTEN[7:0]
Reserved
rw
574
GD32E10x User Manual
0: Disable channel n interrupt
1: Enable channel n interrupt
Each bit represents a channel: Bit 0 for channel 0, bit 7 for channel 7.
This register controls the port’s behavior and also has some flags which report the status of
the port. The HPIF flag in USBFS_GINTF register will be triggered if one of these flags (PRST,
PEDC and PCD) in this register is set by USBFS.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
Reserved
PS[1:0]
r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
PLST[1:0]
Reserved
Reserved
Reserved
PREM
PEDC
PRST
PCST
PCD
PSP
PP
PE
rw r rw rs rw rc_w1 rc_w1 rc_w1 r
12 PP Port power
This bit should be set before a port is used. Because USBFS doesn’t have power
supply ability, it only uses this bit to get whether the port is in powered state.
Software should ensure the power supply on VBUS before setting this bit.
0: Port is powered off
1: Port is powered on
575
GD32E10x User Manual
Report the current state of USB data lines.
Bit 10: State of DP line
Bit 11: State of DM line
2 PE Port enable
This bit is automatically set by USBFS after a USB reset signal finishes and cannot
be set by software.
This bit is cleared by the following events:
– A disconnection condition
– Software clears this bit
0: Port disabled
1: Port enabled
576
GD32E10x User Manual
0: Device is not connected to the port
1: Device is connected to the port
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
EPTYPE[1:0]
ODDFRM
Reserved
Reserved
DAR[6:0]
CDIS
CEN
LSD
rs rs rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EPNUM[3:0]
MPL[10:0]
EPDIR
rw rw rw
577
GD32E10x User Manual
The transfer type of the endpoint with which this channel communicates.
00: Control
01: Isochronous
10: Bulk
11: Interrupt
This register contains the status and events of a channel, when a channel interrupt occurs,
application should read this register for the respective channel to get the source of the
interrupt. The flag bits in this register are all set by hardware and cleared by writing 1.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved.
Reserved.
REQOVR
Reserved
USBER
STALL
DTER
BBER
ACK
NAK
CH
TF
5 ACK ACK
An ACK response is received or transmitted.
4 NAK NAK
A NAK response is received.
3 STALL STALL
A STALL response is received.
1 CH Channel halted
This channel is disabled by a request, and it will not respond to other requests during
the request processing.
0 TF Transfer finished
All the transactions of this channel finish successfully, and no error occurs. For IN
channel, this flag will be triggered after PCNT bits in USBFS_HCHxLEN register
reach zero. For OUT channel, this flag will be triggered when software reads and
pops a TF status entry from the Rx FIFO.
579
GD32E10x User Manual
This register contains the interrupt enable bits for the flags in USBFS_HCHxINTF register. If
a bit in this register is set by software, the corresponding bit in USBFS_HCHxINTF register is
able to trigger a channel interrupt. The bits in this register are set and cleared by software.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
REQOVRIE
Reserved.
USBERIE
Reserved
Reserved
STALLIE
DTERIE
BBERIE
ACKIE
NAKIE
CHIE
TFIE
rw rw rw rw rw rw rw rw rw
580
GD32E10x User Manual
3 STALLIE STALL interrupt enable
0: Disable STALL interrupt
1: Enable STALL interrupt
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TLEN[18:16]
PCNT[9:0]
DPID[1:0]
Reserved
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TLEN[15:0]
rw
This register configures the core in device mode after power on, certain control commands or
enumeration. It is not able to change this register after device initialization.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EOPFT[1:0]
Reserved
Reserved
DAR[6:0]
NZLSOH
DS[1:0]
rw rw rw rw
582
GD32E10x User Manual
12:11 EOPFT[1:0] End of periodic frame time
This field defines the percentage time point in a frame that the end of periodic frame
(EOPF) flag should be triggered.
00: 80% of the frame time
01: 85% of the frame time
10: 90% of the frame time
11: 95% of the frame time
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CGONAK
Reserved
SGONAK
Reserved
CGINAK
SGINAK
RWKUP
GONS
GINS
POIF
SD
rw w w w w r r rw rw
583
GD32E10x User Manual
Bits Fields Descriptions
31:12 Reserved Must be kept at reset value.
1 SD Soft disconnect
Software can use this bit to generate a soft disconnection condition on USB bus.
After this bit is set, USBFS switches off the pull-up resistor on DP line. This will
cause the host to detect a device disconnection.
0: No soft disconnection generated
1: Generate a soft disconnection
This register contains status and information of the USBFS in device mode.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
FNRSOF[13:8]
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
FNRSOF[7:0]
Reserved
ES[1:0]
SPST
r r r
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EPTXFUDEN
IEPNEEN
EPDISEN
Reserved
Reserved
Reserved
CITOEN
TFEN
rw rw rw rw rw
586
GD32E10x User Manual
Device OUT endpoint common interrupt enable register (USBFS_DOEPINTEN)
Address offset: 0x0814
Reset value: 0x0000 0000
This register contains the interrupt enable bits for the USBFS_DOEPxINTF register. If a bit in
this register is set by software, the corresponding bit in USBFS_DOEPxINTF register is able
to trigger an endpoint interrupt in USBFS_DAEPINT register. The bits in this register are set
and cleared by software.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EPRXFOVREN
BTBSTPEN
EPDISEN
Reserved
Reserved
Reserved
STPFEN
TFEN
rw rw rw rw rw
6 BTBSTPEN Back-to-back SETUP packets (only for control OUT endpoint) interrupt enable bit
0: Disable back-to-back SETUP packets interrupt
1: Enable back-to-back SETUP packets interrupt
3 STPFEN SETUP phase finished (only for control OUT endpoint) interrupt enable bit
0: Disable SETUP phase finished interrupt
1: Enable SETUP phase finished interrupt
587
GD32E10x User Manual
0: Disable transfer finished interrupt
1: Enable transfer finished interrupt
When an endpoint interrupt is triggered, USBFS sets corresponding bit in this register and
software should read this register to get which endpoint is asserting an interrupt.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OEPITB[3:0]
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IEPITB[3:0]
Reserved
This register can be used by software to enable or disable an endpoint’s interrupt. Only when
the endpoint whose corresponding bit in this register is set, it is able to trigger the endpoint
interrupt flag OEPIF or IEPIF in USBFS_GINTF register.
588
GD32E10x User Manual
This register has to be accessed by word (32-bit)
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
OEPIE[3:0]
Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IEPIE[3:0]
Reserved
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
589
GD32E10x User Manual
DVBUSDT[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
DVBUSPT[11:0]
Reserved
rw
590
GD32E10x User Manual
This register contains the enable bits for the Tx FIFO empty interrupts of IN endpoints.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IEPTXFEIE[3:0]
Reserved
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TXFNUM[3:0]
EPTYPE[1:0]
Reserved
Reserved
Reserved
STALL
CNAK
EPEN
SNAK
NAKS
EPD
rs rs w w rw rs r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
MPL[1:0]
EPACT
r rw
591
GD32E10x User Manual
Bits Fields Descriptions
31 EPEN Endpoint enable
Set by the application and cleared by USBFS.
0: Endpoint disabled
1: Endpoint enabled
Software should follow the operation guide to disable or enable an endpoint.
592
GD32E10x User Manual
1:0 MPL[1:0] Maximum packet length
This field defines the maximum packet length for a control data packet. As described
in USB 2.0 protocol, there are 4 kinds of length for control transfers:
00: 64 bytes
01: 32 bytes
10: 16 bytes
11: 8 bytes
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SODDFRM/SD1
SD0PID/SEVNF
EOFRM/DPID
TXFNUM[3:0]
EPTYPE[1:0]
Reserved
STALL
CNAK
EPEN
SNAK
NAKS
EPD
PID
RM
rs rs w w w w rw rw/rs rw r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MPL[10:0]
Reserved
EPACT
rw rw
593
GD32E10x User Manual
28 SEVENFRM Set even frame (for isochronous IN endpoints)
Software sets this bit to clear EOFRM bit in this register.
594
GD32E10x User Manual
0: Only sends data in even frames
1: Only sends data in odd frames
10:0 MPL[10:0] This field defines the maximum packet length in byte
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
EPTYPE[1:0]
Reserved.
Reserved
Reserved
SNOOP
STALL
CNAK
EPEN
SNAK
NAKS
EPD
rs r w w rs rw r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
MPL[1:0]
EPACT
r r
595
GD32E10x User Manual
29:28 Reserved Must be kept at reset value.
596
GD32E10x User Manual
Device OUT endpoint x control register (USBFS_DOEPxCTL) (x = 1…3, where
x = endpoint_number)
Address offset: 0x0B00 + (endpoint_number × 0x20)
Reset value: 0x0000 0000
The application uses this register to control the operations of each logical OUT endpoint
except OUT endpoint 0.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
SODDFRM/SD1
EOFRM/DPID
EPTYPE[1:0]
SEVNFRM/
Reserved
SD0PID
SNOOP
STALL
CNAK
EPEN
SNAK
NAKS
EPD
PID
rs rs w w w w rw/rs rw rw r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
MPL[10:0]
Reserved
EPACT
rw rw
597
GD32E10x User Manual
27 SNAK Set NAK
Software sets this bit to set NAKS bit in this register.
10:0 MPL[10:0] This field defines the maximum packet length in bytes.
This register contains the status and events of an IN endpoint, when an IN endpoint interrupt
occurs, read this register for the respective endpoint to get the source of the interrupt. The
flag bits in this register are all set by hardware and cleared by writing 1 except the read-only
TXFE bit.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EPTXFUD
Reserved
Reserved
Reserved
IEPNE
EPDIS
TXFE
CITO
TF
0 TF Transfer finished
This flag is triggered when all the IN transactions assigned to this endpoint have
been finished.
This register contains the status and events of an OUT endpoint, when an OUT endpoint
interrupt occurs, read this register for the respective endpoint to get the source of the interrupt.
The flag bits in this register are all set by hardware and cleared by writing 1.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
EPRXFOVR
Reserved
Reserved
Reserved
BTBSTP
EPDIS
STPF
TF
600
GD32E10x User Manual
31:7 Reserved Must be kept at reset value.
0 TF Transfer finished
This flag is triggered when all the OUT transactions assigned to this endpoint have
been finished.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
PCNT[1:0]
Reserved
Reserved
rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TLEN[6:0]
Reserved
rw
601
GD32E10x User Manual
20:19 PCNT[1:0] Packet count
The number of data packets desired to be transmitted in a transfer.
Program this field before the endpoint is enabled. After the transfer starts, this field
is decreased automatically after each successful data packet transmission.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
STPCNT[1:0]
Reserved
Reserved
Reserved
PCNT
rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TLEN[6:0]
Reserved
rw
602
GD32E10x User Manual
11: 3 packets
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TLEN[18:16]
MCPF[1:0]]
PCNT[9:0]
Reserved
rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TLEN[15:0]
rw
603
GD32E10x User Manual
11: 3 packets
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
RXDPID/STPCN
TLEN[18:16]
PCNT[9:0]
Reserved
T[1:0]
r/rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TLEN[15:0]
rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
IEPTFS[15:0]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved
SHCLK
SUCLK
rw rw
606
GD32E10x User Manual
22. Document appendix
For availability of peripherals and their number across all MCU series types,refer to the
corresponding device data datasheet.
607
GD32E10x User Manual
23. Revision history
609
GD32E10x User Manual
Important Notice
This document is the property of GigaDevice Semiconductor Inc. and its subsidiaries (the "Company"). This document, including any
product of the Company described in this document (the “Product”), is owned by the Company under the intellectual property laws and
treaties of the People’s Republic of China and other jurisdictions worldwide. The Company reserves all rights under such laws and
treaties and does not grant any license under its patents, copyrights, trademarks, or other intellectual property rights. The names and
brands of third party referred thereto (if any) are the property of their respective owner and referred to for identification purposes only.
The Company makes no warranty of any kind, express or implied, with regard to this document or any Product, including, but not
limited to, the implied warranties of merchantability and fitness for a particular purpose. The Company does not assume any liability
arising out of the application or use of any Product described in this document. Any information provided in this document is provided
only for reference purposes. It is the responsibility of the user of this document to properly design, program, and test the functionality
and safety of any application made of this information and any resulting product. Except for customized products which has been
expressly identified in the applicable agreement, the Products are designed, developed, and/or manufactured for ordinary business,
industrial, personal, and/or household applications only. The Products are not designed, intended, or authorized for use as components
in systems designed or intended for the operation of weapons, weapons systems, nuclear installations, atomic energy control
instruments, combustion control instruments, airplane or spaceship instruments, transportation instruments, traffic signal instruments,
life-support devices or systems, other medical devices or systems (including resuscitation equipment and surgical implants), pollution
control or hazardous substances management, or other uses where the failure of the device or Product could cause personal injury,
death, property or environmental damage ("Unintended Uses"). Customers shall take any and all actions to ensure using and selling
the Products in accordance with the applicable laws and regulations. The Company is not liable, in whole or in part, and customers
shall and hereby do release the Company as well as it’s suppliers and/or distributors from any claim, damage, or other liability arising
from or related to all Unintended Uses of the Products. Customers shall indemnify and hold the Company as well as it’s suppliers
and/or distributors harmless from and against all claims, costs, damages, and other liabilities, including claims for personal injury or
death, arising from or related to any Unintended Uses of the Products.
Information in this document is provided solely in connection with the Products. The Company reserves the right to make changes,
corrections, modifications or improvements to this document and Products and services described herein at any time, without notice.
610