0% found this document useful (0 votes)
15 views723 pages

GD32E50x Firmware Library User Guide Rev1.1

Uploaded by

nzy66666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views723 pages

GD32E50x Firmware Library User Guide Rev1.1

Uploaded by

nzy66666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 723

GD32E50x Firmware Library User Guide

GigaDevice Semiconductor Inc.

GD32E50x
Arm® Cortex®-M33 32-bit MCU

Firmware Library
User Guide
Revison 1.1

(Aug. 2020)

1
GD32E50x Firmware Library User Guide

Table of Contents
Table of Contents ........................................................................................................... 2
List of Figures ................................................................................................................ 5
List of Tables .................................................................................................................. 6
1. Introduction ............................................................................................................ 30
1.1. Rules of User Manual and Firmware Library ........................................................... 30
1.1.1. Peripherals ............................................................................................................................ 30
1.1.2. Naming rules ......................................................................................................................... 31

2. Firmware Library Overview ................................................................................... 33


2.1. File Structure of Firmware Library ........................................................................... 33
2.1.1. Examples Folder ................................................................................................................... 34
2.1.2. Firmware Folder .................................................................................................................... 34
2.1.3. Template Folder .................................................................................................................... 35
2.1.4. Utilities Folder ....................................................................................................................... 37

2.2. File descriptions of Firmware Library ...................................................................... 38


3. Firmware Library of Standard Peripherals .......................................................... 39
3.1. Overview of Firmware Library of Standard Peripherals .......................................... 39
3.2. ADC ............................................................................................................................ 39
3.2.1. Descriptions of Peripheral registers ...................................................................................... 39
3.2.2. Descriptions of Peripheral functions ..................................................................................... 40

3.3. BKP............................................................................................................................. 73
3.3.1. Descriptions of Peripheral registers ...................................................................................... 74
3.3.2. Descriptions of Peripheral functions ..................................................................................... 74

3.4. CRC ............................................................................................................................ 86


3.4.1. Descriptions of Peripheral registers ...................................................................................... 86
3.4.2. Descriptions of Peripheral functions ..................................................................................... 87

3.5. CTC ............................................................................................................................. 94


3.5.1. Descriptions of Peripheral registers ...................................................................................... 94
3.5.2. Descriptions of Peripheral functions ..................................................................................... 94

3.6. CMP .......................................................................................................................... 107


3.6.1. Descriptions of Peripheral registers .................................................................................... 107
3.6.2. Descriptions of Peripheral functions ................................................................................... 108

3.7. DAC ...........................................................................................................................114


3.7.1. Descriptions of Peripheral registers ..................................................................................... 114
3.7.2. Descriptions of Peripheral functions .................................................................................... 115

2
GD32E50x Firmware Library User Guide
3.8. DBG .......................................................................................................................... 136
3.8.1. Descriptions of Peripheral registers .................................................................................... 136
3.8.2. Descriptions of Peripheral functions ................................................................................... 136

3.9. DMA .......................................................................................................................... 143


3.9.1. Descriptions of Peripheral registers .................................................................................... 143
3.9.2. Descriptions of Peripheral functions ................................................................................... 143

3.10. ENET ..................................................................................................................... 163


3.10.1. Descriptions of Peripheral registers .................................................................................... 163
3.10.2. Descriptions of Peripheral functions ................................................................................... 165

3.11. EXMC .................................................................................................................... 253


3.11.1. Descriptions of Peripheral registers .................................................................................... 253
3.11.2. Descriptions of Peripheral functions ................................................................................... 254

3.12. EXTI ....................................................................................................................... 273


3.12.1. Descriptions of Peripheral registers .................................................................................... 273
3.12.2. Descriptions of Peripheral functions ................................................................................... 273

3.13. FMC ....................................................................................................................... 281


3.13.1. Descriptions of Peripheral registers .................................................................................... 281
3.13.2. Descriptions of Peripheral functions ................................................................................... 281

3.14. FWDGT .................................................................................................................. 299


3.14.1. Descriptions of Peripheral registers .................................................................................... 300
3.14.2. Descriptions of Peripheral functions ................................................................................... 300

3.15. GPIO ...................................................................................................................... 305


3.15.1. Descriptions of Peripheral registers .................................................................................... 305
3.15.2. Descriptions of Peripheral functions ................................................................................... 306

3.16. SHRTIMER ............................................................................................................ 324


3.16.1. Descriptions of Peripheral registers .................................................................................... 324
3.16.2. Descriptions of Peripheral functions ................................................................................... 326

3.17. I2C ......................................................................................................................... 393


3.17.1. Descriptions of Peripheral registers .................................................................................... 393
3.17.2. Descriptions of Peripheral functions ................................................................................... 394

3.18. MISC ...................................................................................................................... 456


3.18.1. Descriptions of Peripheral registers .................................................................................... 456
3.18.2. Descriptions of Peripheral functions ................................................................................... 457

3.19. PMU ....................................................................................................................... 464


3.19.1. Descriptions of Peripheral registers .................................................................................... 464
3.19.2. Descriptions of Peripheral functions ................................................................................... 464

3.20. RCU ....................................................................................................................... 477


3.20.1. Descriptions of Peripheral registers .................................................................................... 477
3.20.2. Descriptions of Peripheral functions ................................................................................... 478

3
GD32E50x Firmware Library User Guide
3.21. RTC ....................................................................................................................... 520
3.21.1. Descriptions of Peripheral registers .................................................................................... 520
3.21.2. Descriptions of Peripheral functions ................................................................................... 521

3.22. SDIO ...................................................................................................................... 528


3.22.1. Descriptions of Peripheral registers .................................................................................... 528
3.22.2. Descriptions of Peripheral functions ................................................................................... 529

3.23. SPI ......................................................................................................................... 559


3.23.1. Descriptions of Peripheral registers .................................................................................... 559
3.23.2. Descriptions of Peripheral functions ................................................................................... 560

3.24. SQPI ...................................................................................................................... 586


3.24.1. Descriptions of Peripheral registers .................................................................................... 586
3.24.2. Descriptions of Peripheral functions ................................................................................... 587

3.25. TIMER .................................................................................................................... 593


3.25.1. Descriptions of Peripheral registers .................................................................................... 593
3.25.2. Descriptions of Peripheral functions ................................................................................... 593

3.26. TMU ....................................................................................................................... 649


3.26.1. Descriptions of Peripheral registers .................................................................................... 649
3.26.2. Descriptions of Peripheral functions ................................................................................... 649

3.27. USART................................................................................................................... 656


3.27.1. Descriptions of Peripheral registers .................................................................................... 656
3.27.2. Descriptions of Peripheral functions ................................................................................... 657

3.28. WWDGT................................................................................................................. 717


3.28.1. Descriptions of Peripheral registers .................................................................................... 717
3.28.2. Descriptions of Peripheral functions ................................................................................... 717

3.29. USBD ..................................................................................................................... 721


3.30. USBHS .................................................................................................................. 721
4. Revision history ................................................................................................... 722

4
GD32E50x Firmware Library User Guide

List of Figures
Figure 2-1. File structure of firmware library of GD32E50x ...................................................................... 33
Figure 2-2. Select peripheral example files ................................................................................................. 35
Figure 2-3. Copy the peripheral example files ............................................................................................ 36
Figure 2-4. Open the project file .................................................................................................................... 36
Figure 2-5. Configure project files ................................................................................................................ 37
Figure 2-6. Compile-debug-download .......................................................................................................... 37

5
GD32E50x Firmware Library User Guide

List of Tables
Table 1-1. Peripherals ...................................................................................................................................... 30
Table 2-1. Function descriptions of Firmware Library ............................................................................... 38
Table 3-1. Peripheral function format of Firmware Library ....................................................................... 39
Table 3-2. ADC Registers ................................................................................................................................ 39
Table 3-3. ADC firmware function .................................................................................................................. 40
Table 3-4. Function adc_deinit ....................................................................................................................... 41
Table 3-5. Function adc_enable ..................................................................................................................... 42
Table 3-6. Function adc_disable .................................................................................................................... 42
Table 3-7. Function adc_calibration_enable ................................................................................................ 43
Table 3-8. Function adc_calibration_number .............................................................................................. 43
Table 3-9. Function adc_dma_mode_enable ............................................................................................... 44
Table 3-10. Function adc_dma_mode_disable ............................................................................................ 45
Table 3-11. Function adc_tempsensor_vrefint_enable .............................................................................. 45
Table 3-12. Function adc_tempsensor_vrefint_disable............................................................................. 46
Table 3-13. Function adc_discontinuous_mode_config ........................................................................... 46
Table 3-14. Function adc_mode_config ....................................................................................................... 47
Table 3-15. Function adc_special_function_config ................................................................................... 48
Table 3-16. Function adc_data_alignment_config ...................................................................................... 49
Table 3-17. Function adc_channel_length_config ...................................................................................... 49
Table 3-18. Function adc_regular_channel_config .................................................................................... 50
Table 3-19. Function adc_inserted_channel_config .................................................................................. 51
Table 3-20. Function adc_inserted_channel_offset_config ...................................................................... 52
Table 3-21. Function adc_channel_differential_mode_config ................................................................. 53
Table 3-22. Function adc_external_trigger_config ..................................................................................... 54
Table 3-23. Function adc_external_trigger_source_config ...................................................................... 55
Table 3-24. Function adc_software_trigger_enable ................................................................................... 57
Table 3-25. Function adc_regular_data_read .............................................................................................. 58
Table 3-26. Function adc_inserted_data_read ............................................................................................ 58
Table 3-27. Function adc_sync_mode_convert_value_read .................................................................... 59
Table 3-28. Function adc_watchdog0_single_channel_enable ............................................................... 59
Table 3-29. Function adc_watchdog0_group_channel_enable ................................................................ 60
Table 3-30. Function adc_watchdog0_disable ............................................................................................ 61
Table 3-31. Function adc_watchdog1_channel_config ............................................................................. 61
Table 3-32. Function adc_watchdog2_channel_config ............................................................................. 62
Table 3-33. Function adc_watchdog1_disable ............................................................................................ 63
Table 3-34. Function adc_watchdog2_disable ............................................................................................ 63
Table 3-35. Function adc_watchdog0_threshold_config .......................................................................... 64
Table 3-36. Function adc_watchdog1_threshold_config .......................................................................... 64
Table 3-37. Function adc_watchdog2_threshold_config .......................................................................... 65
Table 3-38. Function adc_resolution_config ............................................................................................... 66

6
GD32E50x Firmware Library User Guide
Table 3-39. Function adc_oversample_mode_config ................................................................................ 66
Table 3-40. Function adc_oversample_mode_enable ............................................................................... 68
Table 3-41. Function adc_oversample_mode_disable .............................................................................. 69
Table 3-42. Function adc_flag_get ................................................................................................................ 69
Table 3-43. Function adc_flag_clear ............................................................................................................. 70
Table 3-44. Function adc_interrupt _enable ................................................................................................ 71
Table 3-45. Function adc_interrupt_disable ................................................................................................ 71
Table 3-46. Function adc_interrupt_flag_get ............................................................................................... 72
Table 3-47. Function adc_interrupt_flag_clear ........................................................................................... 73
Table 3-48. BKP Registers .............................................................................................................................. 74
Table 3-49. BKP firmware function ................................................................................................................ 74
Table 3-50. Enum bkp_data_register_enum ................................................................................................ 75
Table 3-51. Function bkp_deinit..................................................................................................................... 76
Table 3-52. Function bkp_write_data ............................................................................................................ 76
Table 3-53. Function bkp_data_read ............................................................................................................. 77
Table 3-54. Function bkp_rtc_calibration_output_enable ......................................................................... 77
Table 3-55. Function bkp_rtc_calibration_output_disable........................................................................ 78
Table 3-56. Function bkp_rtc_signal_output_enable ................................................................................. 78
Table 3-57. Function bkp_rtc_signal_output_disable ................................................................................ 79
Table 3-58. Function bkp_rtc_output_select ............................................................................................... 79
Table 3-59. Function bkp_rtc_clock_output_select ................................................................................... 80
Table 3-60. Function bkp_rtc_clock_calibration_direction ....................................................................... 80
Table 3-61. Function bkp_rtc_calibration_value_set ................................................................................. 81
Table 3-62. Function bkp_tamper_detection_enable ................................................................................. 82
Table 3-63. Function bkp_tamper_detection_disable ................................................................................ 82
Table 3-64. Function bkp_tamper_active_level_set ................................................................................... 82
Table 3-65. Function bkp_tamper_interrupt_enable .................................................................................. 83
Table 3-66. Function bkp_tamper_interrupt_disable ................................................................................. 84
Table 3-67. Function bkp_flag_get ................................................................................................................ 84
Table 3-68. Function bkp_flag_clear ............................................................................................................. 85
Table 3-69. Function bkp_interrupt_flag_get .............................................................................................. 85
Table 3-70. Function bkp_interrupt_flag_clear ........................................................................................... 86
Table 3-118. CRC Registers ............................................................................................................................ 86
Table 3-119. CRC firmware function .............................................................................................................. 87
Table 3-120. Function crc_deinit ................................................................................................................... 87
Table 3-121. Function crc_data_register_reset ........................................................................................... 88
Table 3-122. Function crc_reverse_output_data_enable .......................................................................... 88
Table 3-123. Function crc_reverse_output_data_disable ......................................................................... 88
Table 3-124. Function crc_input_data_reverse_config ............................................................................. 89
Table 3-125. Function crc_data_register_read ............................................................................................ 90
Table 3-126. Function crc_free_data_register_read ................................................................................... 90
Table 3-127. Function crc_free_data_register_write .................................................................................. 91
Table 3-128. Function crc_init_data_register_write ................................................................................... 91
Table 3-129. Function crc_polynomial_size_set ......................................................................................... 92
7
GD32E50x Firmware Library User Guide
Table 3-130. Function crc_polynomial_set .................................................................................................. 92
Table 3-131. Function crc_single_data_calculate ...................................................................................... 93
Table 3-132. Function crc_block_data_calculate ....................................................................................... 93
Table 3-133. CTC Registers ............................................................................................................................ 94
Table 3-134. CTC firmware function .............................................................................................................. 94
Table 3-135. Function ctc_deinit .................................................................................................................... 95
Table 3-136. Function ctc_counter_enable .................................................................................................. 96
Table 3-137. Function ctc_counter_disable ................................................................................................. 96
Table 3-138. Function ctc_irc48m_trim_value_config ............................................................................... 97
Table 3-139. Function ctc_software_refsource_pulse_generate ............................................................. 97
Table 3-140. Function ctc_hardware_trim_mode_config .......................................................................... 98
Table 3-141. Function ctc_refsource_polarity_config ............................................................................... 98
Table 3-142. Function ctc_refsource_signal_select ................................................................................... 99
Table 3-143. Function ctc_refsource_prescaler_config ............................................................................ 99
Table 3-144. Function ctc_clock_limit_value_config ............................................................................... 100
Table 3-145. Function ctc_counter_reload_value_config ....................................................................... 101
Table 3-146. Function ctc_counter_capture_value_read ........................................................................ 101
Table 3-147. Function ctc_counter_direction_read .................................................................................. 102
Table 3-148. Function ctc_counter_reload_value_read........................................................................... 102
Table 3-149. Function ctc_irc48m_trim_value_read ................................................................................ 103
Table 3-150. Function ctc_flag_get ............................................................................................................. 103
Table 3-151. Function ctc_flag_clear .......................................................................................................... 104
Table 3-152. Functionctc_interrupt_enable ............................................................................................... 105
Table 3-153. Functionctc_interrupt_disable .............................................................................................. 105
Table 3-154. Function ctc_interrupt_flag_get ............................................................................................ 106
Table 3-155. Function ctc_interrupt_flag_clear ........................................................................................ 106
Table 3-156. CMP Registers .......................................................................................................................... 107
Table 3-157. CMP firmware function ........................................................................................................... 108
Table 3-158. Enum cmp_enum ..................................................................................................................... 108
Table 3-159. Enum inverting_input_enum ................................................................................................. 108
Table 3-160. Enum cmp_output_enum ....................................................................................................... 108
Table 3-161. Enum cmp_outputblank_enum ............................................................................................. 109
Table 3-162. Function cmp_deinit ............................................................................................................... 109
Table 3-163. Function cmp_input_init ........................................................................................................ 109
Table 3-164. Function cmp_input_init ........................................................................................................ 110
Table 3-165. Function cmp_outputblank_init ............................................................................................ 111
Table 3-166. Function cmp_enable.............................................................................................................. 112
Table 3-167. Function cmp_disable ............................................................................................................ 113
Table 3-168. Function cmp_lock_enable .................................................................................................... 113
Table 3-169. Function cmp_output_level_get ........................................................................................... 114
Table 3-170. DAC Registers .......................................................................................................................... 114
Table 3-171. DAC firmware function ........................................................................................................... 115
Table 3-172. Function dac_deinit ................................................................................................................. 116
Table 3-173. Function dac_enable ............................................................................................................... 116
8
GD32E50x Firmware Library User Guide
Table 3-174. Function dac_disable .............................................................................................................. 117
Table 3-175. Function dac_dma_enable ..................................................................................................... 117
Table 3-176. Function dac_dma_disable .................................................................................................... 118
Table 3-177. Function dac_output_buffer_enable .................................................................................... 118
Table 3-178. Function dac_output_buffer_disable ................................................................................... 119
Table 3-179. Function dac_output_value_get ........................................................................................... 119
Table 3-180. Function dac_data_set ........................................................................................................... 120
Table 3-181. Function dac_output_buffer_enable .................................................................................... 120
Table 3-182. Function dac_output_fifo_disable ........................................................................................ 121
Table 3-183. Function dac_output_fifo_number_get ............................................................................... 121
Table 3-184. Function dac_trigger_enable ................................................................................................. 122
Table 3-185. Function dac_trigger_disable ................................................................................................ 122
Table 3-186. Function dac_trigger_source_config ................................................................................... 123
Table 3-187. Function dac_software_trigger_enable ............................................................................... 124
Table 3-188. Function dac_software_trigger_disable .............................................................................. 125
Table 3-189. Function dac_wave_mode_config ........................................................................................ 125
Table 3-190. Function dac_wave_bit_width_config ................................................................................. 126
Table 3-191. Function dac_lfsr_noise_config ........................................................................................... 126
Table 3-192. Function dac_triangle_noise_config .................................................................................... 127
Table 3-193. Function dac_concurrent_enable ......................................................................................... 128
Table 3-194. Function dac_concurrent_disable ........................................................................................ 128
Table 3-195. Function dac_concurrent_software_trigger_enable ......................................................... 129
Table 3-196. Function dac_concurrent_software_trigger_disable ........................................................ 129
Table 3-197. Function dac_concurrent_output_buffer_enable .............................................................. 130
Table 3-198. Function dac_concurrent_output_buffer_disable ............................................................. 130
Table 3-199. Function dac_concurrent_data_set ..................................................................................... 131
Table 3-200. Function dac_flag_get ............................................................................................................ 131
Table 3-201. Function dac_flag_clear ......................................................................................................... 132
Table 3-202. Function dac_interrupt_enable ............................................................................................. 133
Table 3-203. Function dac_interrupt_enable ............................................................................................. 134
Table 3-204. Function dac_interrupt_flag_get........................................................................................... 135
Table 3-205. Function dac_interrupt_flag_clear ....................................................................................... 135
Table 3-206. DBG Registers .......................................................................................................................... 136
Table 3-207. DBG firmware function ........................................................................................................... 137
Table 3-208. Enum dbg_periph_enum ........................................................................................................ 137
Table 3-209. Function dbg_deinit ................................................................................................................ 137
Table 3-210. Function dbg_id_get ............................................................................................................... 138
Table 3-211. Function dbg_low_power_enable ......................................................................................... 138
Table 3-212. Function dbg_low_power_disable ........................................................................................ 139
Table 3-213. Function dbg_periph_enable ................................................................................................. 140
Table 3-214. Function dbg_periph_disable ................................................................................................ 140
Table 3-215. Function dbg_trace_pin_enable ........................................................................................... 141
Table 3-216. Function dbg_trace_pin_disable .......................................................................................... 141
Table 3-217. Function dbg_trace_pin_mode_set ...................................................................................... 142
9
GD32E50x Firmware Library User Guide
Table 3-218. DMA Registers .......................................................................................................................... 143
Table 3-219. DMA firmware function ........................................................................................................... 143
Table 3-220. Enum dma_channel_enum .................................................................................................... 144
Table 3-221. Structure dma_parameter_struct .......................................................................................... 144
Table 3-222. Function dma_deinit ............................................................................................................... 145
Table 3-223. Function dma_struct_para_init ............................................................................................. 145
Table 3-224. Function dma_init .................................................................................................................... 146
Table 3-225. Function dma_circulation_enable ........................................................................................ 147
Table 3-226. Function dma_circulation_disable ....................................................................................... 147
Table 3-227. Function dma_memory_to_memory_enable ...................................................................... 148
Table 3-228. Function dma_memory_to_memory_disable ..................................................................... 149
Table 3-229. Function dma_channel_enable ............................................................................................. 149
Table 3-230. Function dma_channel_disable ............................................................................................ 150
Table 3-231. Function dma_periph_address_config ................................................................................ 150
Table 3-232. Function dma_memory_address_config ............................................................................. 151
Table 3-233. Function dma_transfer_number_config .............................................................................. 152
Table 3-234. Function dma_transfer_number_get .................................................................................... 152
Table 3-235. Function dma_priority_config ............................................................................................... 153
Table 3-236. Function dma_memory_width_config ................................................................................. 154
Table 3-237. Function dma_periph_width_config .................................................................................... 155
Table 3-238. Function dma_memory_increase_enable ........................................................................... 155
Table 3-239. Function dma_memory_increase_disable .......................................................................... 156
Table 3-240. Function dma_periph_increase_enable .............................................................................. 156
Table 3-241. Function dma_periph_increase_disable ............................................................................. 157
Table 3-242. Function dma_transfer_direction_config ............................................................................ 158
Table 3-243. Function dma_flag_get ........................................................................................................... 158
Table 3-244. Function dma_flag_clear ........................................................................................................ 159
Table 3-245. Function dma_interrupt_enable ............................................................................................ 160
Table 3-246. Function dma_interrupt_disable ........................................................................................... 161
Table 3-247. Function dma_interrupt_flag_get ......................................................................................... 161
Table 3-248. Function dma_interrupt_flag_clear ...................................................................................... 162
Table 3-249. ENET Registers ........................................................................................................................ 163
Table 3-250. ENET firmware function ......................................................................................................... 165
Table 3-251. Structure enet_initpara_struct .............................................................................................. 169
Table 3-252. Structure enet_descriptors_struct ....................................................................................... 169
Table 3-253. Structure enet_ptp_systime_struct ...................................................................................... 169
Table 3-254. Enum enet_flag_enum ............................................................................................................ 170
Table 3-255. Enum enet_flag_clear_enum ................................................................................................. 172
Table 3-256. Enum enet_int_enum .............................................................................................................. 172
Table 3-257. Enum enet_int_flag_enum ..................................................................................................... 174
Table 3-258. Enum enet_int_flag_clear_enum .......................................................................................... 175
Table 3-259. Enum enet_desc_reg_enum .................................................................................................. 176
Table 3-260. Enum enet_msc_counter_enum ........................................................................................... 176
Table 3-261. Enum enet_option_enum ....................................................................................................... 177
10
GD32E50x Firmware Library User Guide
Table 3-262. Enum enet_mediamode_enum .............................................................................................. 177
Table 3-263. Enum enet_chksumconf_enum ............................................................................................ 178
Table 3-264. Enum enet_frmrecept_enum ................................................................................................. 178
Table 3-265. Enum enet_registers_type_enum ......................................................................................... 178
Table 3-266. Enum enet_dmadirection_enum ........................................................................................... 178
Table 3-267. Enum enet_phydirection_enum ............................................................................................ 179
Table 3-268. Enum enet_regdirection_enum ............................................................................................. 179
Table 3-269. Enum enet_macaddress_enum ............................................................................................. 179
Table 3-270. Enum enet_descstate_enum ................................................................................................. 179
Table 3-271. Enum enet_msc_preset_enum .............................................................................................. 180
Table 3-272. Function enet_deinit ............................................................................................................... 180
Table 3-273. Function enet_initpara_config .............................................................................................. 180
Table 3-274. Function enet_init .................................................................................................................... 184
Table 3-275. Function enet_software_reset ............................................................................................... 185
Table 3-276. Function enet_rxframe_size_get........................................................................................... 186
Table 3-277. Function enet_descriptors_chain_init ................................................................................. 186
Table 3-278. Function enet_descriptors_ring_init .................................................................................... 187
Table 3-279. Function enet_frame_receive ................................................................................................ 187
Table 3-280. Function enet_frame_transmit .............................................................................................. 188
Table 3-281. Function enet_transmit_checksum_config ........................................................................ 189
Table 3-282. Function enet_enable ............................................................................................................. 189
Table 3-283. Function enet_disable ............................................................................................................ 190
Table 3-284. Function enet_mac_address_set .......................................................................................... 190
Table 3-285. Function enet_mac_address_get ......................................................................................... 191
Table 3-286. Function enet_flag_get ........................................................................................................... 192
Table 3-287. Function enet_flag_clear ........................................................................................................ 194
Table 3-288. Function enet_interrupt_enable ............................................................................................ 196
Table 3-289. Function enet_interrupt_disable ........................................................................................... 197
Table 3-290. Function enet_interrupt_flag_get ......................................................................................... 198
Table 3-291. Function enet_interrupt_flag_clear ...................................................................................... 200
Table 3-292. Function enet_tx_enable ........................................................................................................ 201
Table 3-293. Function enet_tx_disable ....................................................................................................... 202
Table 3-294. Function enet_rx_enable ........................................................................................................ 202
Table 3-295. Function enet_rx_disable ....................................................................................................... 203
Table 3-296. Function enet_registers_get .................................................................................................. 203
Table 3-297. Function enet_debug_status_get ......................................................................................... 204
Table 3-298. Function enet_address_filter_enable................................................................................... 205
Table 3-299. Function enet_address_filter_disable ................................................................................. 206
Table 3-300. Function enet_address_filter_config ................................................................................... 206
Table 3-301. Function enet_phy_config ..................................................................................................... 208
Table 3-302. Function enet_phy_write_read .............................................................................................. 208
Table 3-303. Function enet_phyloopback_enable .................................................................................... 209
Table 3-304. Function enet_phyloopback_disable ................................................................................... 209
Table 3-305. Function enet_forward_feature_enable ............................................................................... 210
11
GD32E50x Firmware Library User Guide
Table 3-306. Function enet_forward_feature_disable .............................................................................. 211
Table 3-307. Function enet_fliter_feature_enable .................................................................................... 211
Table 3-308. Function enet_fliter_feature_disable ................................................................................... 212
Table 3-309. Function enet_pauseframe_generate .................................................................................. 213
Table 3-310. Function enet_pauseframe_detect_config ......................................................................... 214
Table 3-311. Function enet_pauseframe_config ....................................................................................... 214
Table 3-312. Function enet_flowcontrol_threshold_config .................................................................... 215
Table 3-313. Function enet_flowcontrol_feature_enable ........................................................................ 216
Table 3-314. Function enet_flowcontrol_feature_disable ....................................................................... 217
Table 3-315. Function enet_dmaprocess_state_get ................................................................................ 218
Table 3-316. Function enet_dmaprocess_resume .................................................................................... 219
Table 3-317. Function enet_rxprocess_check_recovery ......................................................................... 219
Table 3-318. Function enet_txfifo_flush ..................................................................................................... 220
Table 3-319. Function enet_current_desc_address_get ......................................................................... 220
Table 3-320. Function enet_desc_information_get .................................................................................. 221
Table 3-321. Function enet_missed_frame_counter_get ........................................................................ 222
Table 3-322. Function enet_desc_flag_get ................................................................................................ 223
Table 3-323. Function enet_desc_flag_set ................................................................................................ 224
Table 3-324. Function enet_desc_flag_clear ............................................................................................. 225
Table 3-325. Function enet_rx_desc_immediate_receive_complete_interrupt ................................... 226
Table 3-326. Function enet_rx_desc_delay_receive_complete_interrupt ............................................ 227
Table 3-327. Function enet_rxframe_drop ................................................................................................. 227
Table 3-328. Function enet_dma_feature_enable ..................................................................................... 228
Table 3-329. Function enet_dma_feature_disable .................................................................................... 228
Table 3-330. Function enet_rx_desc_enhanced_status_get .................................................................. 229
Table 3-331. Function enet_desc_select_enhanced_mode .................................................................... 230
Table 3-332. Function enet_ptp_enhanced_descriptors_chain_init ..................................................... 230
Table 3-333. Function enet_ptp_enhanced_descriptors_ring_init ........................................................ 231
Table 3-334. Function enet_ptpframe_receive_enhanced_mode .......................................................... 232
Table 3-335. Function enet_ptpframe_transmit_enhanced_mode ........................................................ 232
Table 3-336. Function enet_desc_select_normal_mode ......................................................................... 233
Table 3-337. Function enet_ptp_normal_descriptors_chain_init .......................................................... 234
Table 3-338. Function enet_ptp_normal_descriptors_ring_init ............................................................. 234
Table 3-339. Function enet_ptpframe_receive_normal_mode ............................................................... 235
Table 3-340. Function enet_ptpframe_transmit_normal_mode ............................................................. 236
Table 3-341. Function enet_wum_filter_register_pointer_reset ............................................................ 236
Table 3-342. Function enet_wum_filter_config ......................................................................................... 237
Table 3-343. Function enet_wum_feature_enable .................................................................................... 237
Table 3-344. Function enet_wum_feature_disable ................................................................................... 238
Table 3-345. Function enet_msc_counters_reset ..................................................................................... 239
Table 3-346. Function enet_msc_feature_enable ..................................................................................... 239
Table 3-347. Function enet_msc_feature_disable .................................................................................... 240
Table 3-348. Function enet_msc_counters_preset_config ..................................................................... 240
Table 3-349. Function enet_msc_counters_get ........................................................................................ 241
12
GD32E50x Firmware Library User Guide
Table 3-350. Function enet_ptp_subsecond_2_nanosecond ................................................................. 242
Table 3-351. Function enet_ptp_nanosecond_2_subsecond ................................................................. 242
Table 3-352. Function enet_ptp_feature_enable ....................................................................................... 243
Table 3-353. Function enet_ptp_feature_disable ...................................................................................... 244
Table 3-354. Function enet_ptp_timestamp_function_config ................................................................ 245
Table 3-355. Function enet_ptp_subsecond_increment_config ............................................................ 246
Table 3-356. Function enet_ptp_timestamp_addend_config ................................................................. 247
Table 3-357. Function enet_ptp_timestamp_update_config ................................................................... 247
Table 3-358. Function enet_ptp_expected_time_config .......................................................................... 248
Table 3-359. Function enet_ptp_system_time_get ................................................................................... 248
Table 3-360. enet_ptp_pps_output_frequency_config ............................................................................ 249
Table 3-361. enet_ptp_start .......................................................................................................................... 250
Table 3-362. enet_ptp_finecorrection_adjfreq........................................................................................... 251
Table 3-363. enet_ptp_coarsecorrection_systime_update ..................................................................... 251
Table 3-364. enet_ptp_finecorrection_settime .......................................................................................... 252
Table 3-365. enet_ptp_flag_get .................................................................................................................... 252
Table 3-366. Function enet_initpara_reset ................................................................................................. 253
Table 3-367. EXMC Registers ....................................................................................................................... 254
Table 3-368. EXMC firmware function ......................................................................................................... 254
Table 3-369. Structure exmc_norsram_timing_parameter_struct ......................................................... 255
Table 3-370. Structure exmc_norsram_parameter_struct....................................................................... 255
Table 3-371. Structure exmc_nand_pccard_timing_parameter_struct ................................................. 256
Table 3-372. Structure exmc_nand_parameter_struct ............................................................................. 256
Table 3-373. Structure exmc_pccard_parameter_struct ......................................................................... 256
Table 3-374. Function exmc_norsram_deinit ............................................................................................ 256
Table 3-375. Function exmc_norsram_struct_para_init .......................................................................... 257
Table 3-376. Function exmc_norsram_init ................................................................................................. 258
Table 3-377. Function exmc_norsram_enable .......................................................................................... 259
Table 3-378. Function exmc_norsram_disable ......................................................................................... 260
Table 3-379. Function exmc_norsram_page_size_config ....................................................................... 260
Table 3-380. Function exmc_nand_deinit .................................................................................................. 261
Table 3-381. Function exmc_nand_struct_para_init ................................................................................ 261
Table 3-382. Function exmc_nand_init ....................................................................................................... 262
Table 3-383. Function exmc_nand_enable ................................................................................................ 263
Table 3-384. Function exmc_nand_disable ............................................................................................... 263
Table 3-385. Function exmc_nand_ecc_config ......................................................................................... 264
Table 3-386. Function exmc_ecc_get ......................................................................................................... 265
Table 3-387. Function exmc_pccard_deinit ............................................................................................... 265
Table 3-388. Function exmc_pccard_struct_para_init ............................................................................. 266
Table 3-389. Function exmc_pccard_init ................................................................................................... 266
Table 3-390. Function exmc_pccard_enable ............................................................................................. 267
Table 3-391. Function exmc_pccard_disable ............................................................................................ 268
Table 3-392. Function exmc_interrupt_enable .......................................................................................... 268
Table 3-393. Function exmc_interrupt_disable ......................................................................................... 269
13
GD32E50x Firmware Library User Guide
Table 3-394. Function exmc_flag_get ......................................................................................................... 270
Table 3-395. Function exmc_flag_clear ...................................................................................................... 270
Table 3-396. Function exmc_interrupt_flag_get ....................................................................................... 271
Table 3-397. Function exmc_interrupt_flag_clear .................................................................................... 272
Table 3-398. EXTI Registers .......................................................................................................................... 273
Table 3-399. EXTI firmware function ........................................................................................................... 273
Table 3-400. Enum exti_line_enum ............................................................................................................. 274
Table 3-401. Enum exti_mode_enum .......................................................................................................... 274
Table 3-402. Enum exti_trig_type_enum .................................................................................................... 274
Table 3-403. Function exti_deinit ................................................................................................................. 275
Table 3-404. Function exti_init ..................................................................................................................... 275
Table 3-405. Function exti_interrupt_enable ............................................................................................. 276
Table 3-406. Function exti_interrupt_disable ............................................................................................ 276
Table 3-407. Function exti_event_enable ................................................................................................... 277
Table 3-408. Function exti_event_disable .................................................................................................. 277
Table 3-409. Function exti_software_interrupt_enable ........................................................................... 278
Table 3-410. Function exti_software_interrupt_disable .......................................................................... 278
Table 3-411. Function exti_flag_get ............................................................................................................ 279
Table 3-412. Function exti_flag_clear ......................................................................................................... 279
Table 3-413. Function exti_interrupt_flag_get........................................................................................... 280
Table 3-414. Function exti_interrupt_flag_clear ....................................................................................... 280
Table 3-415. FMC Registers .......................................................................................................................... 281
Table 3-416. FMC firmware function ........................................................................................................... 281
Table 3-417. fmc_state_enum....................................................................................................................... 282
Table 3-418. Function fmc_unlock .............................................................................................................. 283
Table 3-419. Function fmc_lock ................................................................................................................... 283
Table 3-420. Function fmc_wscnt_set ........................................................................................................ 284
Table 3-421. Function fmc_prefetch_enable ............................................................................................. 284
Table 3-422. Function fmc_prefetch_disable ............................................................................................ 285
Table 3-423. Function fmc_ibus_enable ..................................................................................................... 285
Table 3-424. Function fmc_ibus_disable .................................................................................................... 286
Table 3-425. Function fmc_ibus_reset ........................................................................................................ 286
Table 3-426. Function fmc_dbus_enable ................................................................................................... 287
Table 3-427. Function fmc_dbus_disable .................................................................................................. 287
Table 3-428. Function fmc_dbus_reset ...................................................................................................... 288
Table 3-429. Function fmc_page_erase ...................................................................................................... 288
Table 3-430. Function fmc_mass_erase ..................................................................................................... 289
Table 3-431. Function fmc_word_program ................................................................................................ 289
Table 3-432. Function ob_unlock ................................................................................................................ 290
Table 3-433. Function ob_lock ..................................................................................................................... 290
Table 3-434. Function ob_erase ................................................................................................................... 291
Table 3-435. Function ob_write_protection_enable ................................................................................. 291
Table 3-436. Function ob_security_protection_config ............................................................................ 292
Table 3-437. Function ob_user_write .......................................................................................................... 293
14
GD32E50x Firmware Library User Guide
Table 3-438. Function ob_data_program ................................................................................................... 293
Table 3-439. Function ob_user_get ............................................................................................................. 294
Table 3-440. Function ob_data_program ................................................................................................... 294
Table 3-441. Function ob_write_protection_get ....................................................................................... 295
Table 3-442. Function ob_security_protection_flag_get ......................................................................... 295
Table 3-443. Function fmc_flag_get ............................................................................................................ 296
Table 3-444. Function fmc_flag_clear ......................................................................................................... 296
Table 3-445. Function fmc_interrupt_enable ............................................................................................. 297
Table 3-446. Function fmc_interrupt_disable ............................................................................................ 298
Table 3-447. Function fmc_interrupt_flag_get .......................................................................................... 298
Table 3-448. Function fmc_interrupt_flag_clear ....................................................................................... 299
Table 3-449. FWDGT Registers .................................................................................................................... 300
Table 3-450. FWDGT firmware function ...................................................................................................... 300
Table 3-451. Function fwdgt_write_enable ................................................................................................ 300
Table 3-452. Function fwdgt_write_disable ............................................................................................... 301
Table 3-453. Function fwdgt_enable ........................................................................................................... 301
Table 3-454. Function fwdgt_prescaler_value_config ............................................................................. 302
Table 3-455. Function fwdgt_reload_value_config................................................................................... 302
Table 3-456. Function fwdgt_config ............................................................................................................ 303
Table 3-457. Function fwdgt_counter_reload ............................................................................................ 304
Table 3-458. Function fwdgt_flag_get ......................................................................................................... 304
Table 3-459. GPIO Registers ......................................................................................................................... 305
Table 3-460. GPIO firmware function .......................................................................................................... 306
Table 3-461. Function gpio_deinit ............................................................................................................... 306
Table 3-462. Function gpio_afio_deinit ...................................................................................................... 307
Table 3-463. Function gpio_init .................................................................................................................... 307
Table 3-464. Function gpio_bit_set ............................................................................................................. 308
Table 3-465. Function gpio_bit_reset ......................................................................................................... 309
Table 3-466. Function gpio_bit_write .......................................................................................................... 310
Table 3-467. Function gpio_port_write ....................................................................................................... 310
Table 3-468. Function gpio_input_bit_get.................................................................................................. 311
Table 3-469. Function gpio_input_port_get ............................................................................................... 311
Table 3-470. Function gpio_output_bit_get ............................................................................................... 312
Table 3-471. Function gpio_output_port_get ............................................................................................ 313
Table 3-472. Function gpio_pin_remap_config ......................................................................................... 313
Table 3-473. Function gpio_afio_port_config ............................................................................................ 315
Table 3-474. Function gpio_ethernet_phy_select ..................................................................................... 320
Table 3-475. Function gpio_exti_source_select ....................................................................................... 320
Table 3-476. Function gpio_event_output_config .................................................................................... 321
Table 3-477. Function gpio_event_output_enable ................................................................................... 321
Table 3-478. Function gpio_event_output_disable .................................................................................. 322
Table 3-479. Function gpio_pin_lock .......................................................................................................... 322
Table 3-480. Function gpio_compensation_config .................................................................................. 323
Table 3-481. Function gpio_compensation_flag_get ............................................................................... 323
15
GD32E50x Firmware Library User Guide
Table 3-482. SHRTIMER Register ................................................................................................................ 324
Table 3-483. SHRTIMER firmware function ................................................................................................ 326
Table 3-484. Structure shrtimer_baseinit_parameter_struct .................................................................. 329
Table 3-485. Structure shrtimer_timerinit_parameter_struct ................................................................. 329
Table 3-486. Structure shrtimer_timercfg_parameter_struct ................................................................. 330
Table 3-487. Structure shrtimer_comparecfg_parameter_struct ........................................................... 330
Table 3-488. Structure shrtimer_exevfilter_parameter_struct ................................................................ 330
Table 3-489. Structure shrtimer_deadtimecfg_parameter_struct .......................................................... 331
Table 3-490. Structure shrtimer_carriersignalcfg_parameter_struct .................................................... 331
Table 3-491. Structure shrtimer_synccfg_parameter_struct .................................................................. 331
Table 3-492. Structure shrtimer_bunchmode_parameter_struct ........................................................... 331
Table 3-493. Structure shrtimer_exeventcfg_parameter_struct ............................................................ 332
Table 3-494. Structure shrtimer_faultcfg_parameter_struct ................................................................... 332
Table 3-495. Structure shrtimer_adctrigcfg_parameter_struct .............................................................. 332
Table 3-496. Structure shrtimer_channel_outputcfg_parameter_struct .............................................. 332
Table 3-497. Function shrtimer_deinit ........................................................................................................ 333
Table 3-498. Function shrtimer_dll_calibration_start .............................................................................. 333
Table 3-499. Function shrtimer_baseinit_struct_para_init ..................................................................... 334
Table 3-500. Function shrtimer_timers_base_init .................................................................................... 335
Table 3-501. Function shrtimer_timers_counter_enable ......................................................................... 336
Table 3-502. Function shrtimer_timers_counter_enable ......................................................................... 336
Table 3-503. Function shrtimer_timers_update_event_enable .............................................................. 337
Table 3-504. Function shrtimer_timers_update_event_enable .............................................................. 338
Table 3-505. Function shrtimer_software_update .................................................................................... 338
Table 3-506. Function shrtimer_software_counter_reset ....................................................................... 339
Table 3-507. Function shrtimer_timerinit_struct_para_init ..................................................................... 340
Table 3-508. Function shrtimer_timers_waveform_init ........................................................................... 340
Table 3-509. Function shrtimer_timercfg_struct_para_init ..................................................................... 341
Table 3-510. Function shrtimer_slavetimer_waveform_config .............................................................. 342
Table 3-511. Function shrtimer_comparecfg_struct_para_init .............................................................. 343
Table 3-512. Function shrtimer_slavetimer_waveform_compare_config ............................................ 344
Table 3-513. Function shrtimer_channel_outputcfg_struct_para_init .................................................. 345
Table 3-514. Function shrtimer_slavetimer_waveform_channel_config .............................................. 345
Table 3-515. Function shrtimer_slavetimer_waveform_channel_software_request .......................... 347
Table 3-516. Function shrtimer_slavetimer_waveform_channel_output_level_get ........................... 348
Table 3-517. Function shrtimer_slavetimer_waveform_channel_state_get ........................................ 348
Table 3-518. Function shrtimer_channel_outputcfg_struct_para_init .................................................. 349
Table 3-519. Function shrtimer_slavetimer_waveform_channel_software_request .......................... 350
Table 3-520. Function shrtimer_channel_outputcfg_struct_para_init .................................................. 351
Table 3-521. Function shrtimer_slavetimer_carriersignal_config ......................................................... 352
Table 3-522. Function shrtimer_output_channel_enable ........................................................................ 352
Table 3-523. Function shrtimer_output_channel_disable ....................................................................... 353
Table 3-524. Function shrtimer_slavetimer_waveform_compare_config ............................................ 354
Table 3-525. Function shrtimer_slavetimer_compare_value_get .......................................................... 354
16
GD32E50x Firmware Library User Guide
Table 3-526. Function shrtimer_mastertimer_compare_value_config ................................................. 355
Table 3-527. Function shrtimer_slavetimer_compare_value_get .......................................................... 356
Table 3-528. Function shrtimer_timers_counter_value_config ............................................................. 357
Table 3-529. Function shrtimer_timers_counter_value_get ................................................................... 357
Table 3-530. Function shrtimer_timers_autoreload_value_config ........................................................ 358
Table 3-531. Function shrtimer_timers_autoreload_value_get .............................................................. 359
Table 3-532. Function shrtimer_timers_repetition_value_config .......................................................... 359
Table 3-533. Function shrtimer_timers_repetition_value_get ................................................................ 360
Table 3-534. Function shrtimer_exevfilter_struct_para_init ................................................................... 361
Table 3-535. Function shrtimer_slavetimer_exevent_filtering_config .................................................. 361
Table 3-536. Function shrtimer_exeventcfg_struct_para_init ................................................................ 362
Table 3-537. Function shrtimer_exevent_config....................................................................................... 363
Table 3-538. Function shrtimer_exevent_prescaler ................................................................................. 364
Table 3-539. Function shrtimer_synccfg_struct_para_init ..................................................................... 365
Table 3-540. Function shrtimer_synchronization_config ........................................................................ 365
Table 3-541. Function shrtimer_faultcfg_struct_para_init ...................................................................... 366
Table 3-542. Function shrtimer_fault_config ............................................................................................. 366
Table 3-543. Function shrtimer_fault_prescaler_config .......................................................................... 367
Table 3-544. Function shrtimer_fault_input_enable ................................................................................. 368
Table 3-545. Function shrtimer_fault_input_disable ................................................................................ 369
Table 3-546. Function shrtimer_timers_dma_enable ............................................................................... 369
Table 3-547. Function shrtimer_timers_dma_enable ............................................................................... 370
Table 3-548. Function shrtimer_dmamode_config ................................................................................... 372
Table 3-549. Function shrtimer_bunchmode_struct_para_init .............................................................. 373
Table 3-550. Function shrtimer_bunchmode_config ............................................................................... 374
Table 3-551. Function shrtimer_bunchmode_enable ............................................................................... 375
Table 3-552. Function shrtimer_bunchmode_disable ............................................................................. 375
Table 3-553. Function shrtimer_bunchmode_flag_get ............................................................................ 376
Table 3-554. Function shrtimer_bunchmode_software_start ................................................................. 376
Table 3-555. Function shrtimer_slavetimer_capture_config .................................................................. 377
Table 3-556. Function shrtimer_slavetimer_capture_software .............................................................. 378
Table 3-557. Function shrtimer_slavetimer_capture_value_read .......................................................... 379
Table 3-558. Function shrtimer_adctrigcfg_struct_para_init ................................................................. 379
Table 3-559. Function shrtimer_adc_trigger_config ................................................................................ 380
Table 3-560. Function shrtimer_timers_flag_get ...................................................................................... 381
Table 3-561. Function shrtimer_timers_flag_clear ................................................................................... 382
Table 3-562. Function shrtimer_common_flag_get .................................................................................. 383
Table 3-563. Function shrtimer_common_flag_clear ............................................................................... 384
Table 3-564. Function shrtimer_timers_interrupt_enable ....................................................................... 385
Table 3-565. Function shrtimer_timers_interrupt_disable ...................................................................... 386
Table 3-566. Function shrtimer_timers_interrupt_flag_get .................................................................... 387
Table 3-567. Function shrtimer_timers_interrupt_flag_clear ................................................................. 388
Table 3-568. Function shrtimer_common_interrupt_enable ................................................................... 390
Table 3-569. Function shrtimer_common_interrupt_disable ................................................................. 390
17
GD32E50x Firmware Library User Guide
Table 3-570. Function shrtimer_common_interrupt_flag_get ................................................................ 391
Table 3-571. Function shrtimer_common_interrupt_flag_clear ............................................................. 392
Table 3-572. I2C Registers ............................................................................................................................ 393
Table 3-573. I2C firmware function .............................................................................................................. 394
Table 3-574. i2c_flag_enum .......................................................................................................................... 396
Table 3-575. i2c_interrupt_enum ................................................................................................................. 397
Table 3-576. i2c_interrupt_flag_enum ........................................................................................................ 397
Table 3-577. i2c2_interrupt_flag_enum ...................................................................................................... 398
Table 3-578. Function i2c_deinit .................................................................................................................. 399
Table 3-579. Function i2c_enable ................................................................................................................ 399
Table 3-580. Function i2c_disable ............................................................................................................... 400
Table 3-581. Function i2c_start_on_bus .................................................................................................... 400
Table 3-582. Function i2c_stop_on_bus .................................................................................................... 401
Table 3-583. Function i2c_slave_response_to_gcall_enable ................................................................. 401
Table 3-584. Function i2c_slave_response_to_gcall_disable ................................................................ 402
Table 3-585. Function i2c_stretch_scl_low_enable ................................................................................. 402
Table 3-586. Function i2c_stretch_scl_low_disable ................................................................................ 403
Table 3-587. Function i2c_data_transmit ................................................................................................... 403
Table 3-588. Function i2c_data_receive ..................................................................................................... 404
Table 3-589. Function i2c_pec_transfer ..................................................................................................... 404
Table 3-590. Function i2c_pec_enable ....................................................................................................... 405
Table 3-591. Function i2c_pec_disable ...................................................................................................... 405
Table 3-592. Function i2c_pec_value_get .................................................................................................. 406
Table 3-593. Function i2c_clock_config ..................................................................................................... 406
Table 3-594. Function i2c_mode_addr_config .......................................................................................... 407
Table 3-595. Function i2c_smbus_type_config ........................................................................................ 408
Table 3-596. Function i2c_ack_config ........................................................................................................ 408
Table 3-597. Function i2c_ackpos_config ................................................................................................. 409
Table 3-598. Function i2c_master_addressing ......................................................................................... 410
Table 3-599. Function i2c_dualaddr_enable .............................................................................................. 410
Table 3-600. Function i2c_dualaddr_disable ............................................................................................. 411
Table 3-601. Function i2c_dma_enable ...................................................................................................... 411
Table 3-602. Function i2c_dma_last_transfer_config .............................................................................. 412
Table 3-603. Function i2c_software_reset_config .................................................................................... 413
Table 3-604. Function i2c_smbus_issue_alert .......................................................................................... 413
Table 3-605. Function i2c_smbus_arp_enable .......................................................................................... 414
Table 3-606. Function i2c_sam_enable ...................................................................................................... 414
Table 3-607. Function i2c_sam_disable ..................................................................................................... 415
Table 3-608. Function i2c_sam_timeout_enable....................................................................................... 415
Table 3-609. Function i2c_sam_timeout_disable ..................................................................................... 416
Table 3-610. Function i2c_start_early_termination_mode_config ........................................................ 416
Table 3-611. Function i2c_timeout_calculation_enable ........................................................................... 417
Table 3-612. Function i2c_timeout_calculation_disable ......................................................................... 418
Table 3-613. Function i2c_record_received_slave_address_enable .................................................... 418
18
GD32E50x Firmware Library User Guide
Table 3-614. Function i2c_record_received_slave_address_disable ................................................... 419
Table 3-615. Function i2c_address_bit_compare_config ....................................................................... 419
Table 3-616. Function i2c_status_clear_enable ........................................................................................ 420
Table 3-617. Function i2c_status_clear_disable ....................................................................................... 421
Table 3-618. Function i2c_start_early_termination_mode_config ........................................................ 421
Table 3-619. Function i2c_flag_get ............................................................................................................. 422
Table 3-620. Function i2c_flag_clear .......................................................................................................... 423
Table 3-621. Function i2c_interrupt_enable .............................................................................................. 424
Table 3-622. Function i2c_interrupt_disable ............................................................................................. 425
Table 3-623. Function i2c_interrupt_flag_get ............................................................................................ 425
Table 3-624. Function i2c_interrupt_flag_clear ......................................................................................... 427
Table 3-625. Function i2c_timing_config ................................................................................................... 428
Table 3-626. Function i2c_digital_noise_filter_config ............................................................................. 428
Table 3-627. Function i2c_analog_noise_filter_enable ........................................................................... 429
Table 3-628. Function i2c_analog_noise_filter_disable .......................................................................... 430
Table 3-629. Function i2c_wakeup_from_deepsleep_enable ................................................................. 430
Table 3-630. Function i2c_wakeup_from_deepsleep_disable ................................................................ 431
Table 3-631. Function i2c_master_clock_config ...................................................................................... 431
Table 3-632. Function i2c2_master_transfer_direction_config .............................................................. 432
Table 3-633. Function i2c_address10_header_enable ............................................................................. 433
Table 3-634. Function i2c_address10_header_disable ............................................................................ 433
Table 3-635. Function i2c_address10_enable ........................................................................................... 434
Table 3-636. Function i2c_address10_disable .......................................................................................... 434
Table 3-637. Function i2c_automatic_end_enable ................................................................................... 435
Table 3-638. Function i2c_automatic_end_disable .................................................................................. 435
Table 3-639. Function i2c_address_config ................................................................................................ 436
Table 3-640. Function i2c_address_disable .............................................................................................. 436
Table 3-641. Function i2c_second_address_config ................................................................................. 437
Table 3-642. Function i2c_second_address_disable ............................................................................... 438
Table 3-643. Function i2c_recevied_address_get .................................................................................... 438
Table 3-644. Function i2c_slave_byte_control_enable ............................................................................ 439
Table 3-645. Function i2c_slave_byte_control_disable ........................................................................... 440
Table 3-646. Function i2c_nack_enable ..................................................................................................... 440
Table 3-647. Function i2c_nack_disable .................................................................................................... 441
Table 3-648. Function i2c_reload_enable................................................................................................... 441
Table 3-649. Function i2c_reload_disable ................................................................................................. 442
Table 3-650. Function i2c_transfer_byte_number_config....................................................................... 442
Table 3-651. Function i2c2_dma_enable .................................................................................................... 443
Table 3-652. Function i2c2_dma_disable ................................................................................................... 443
Table 3-653. Function i2c_smbus_alert_enable ........................................................................................ 444
Table 3-654. Function i2c_smbus_alert_disable....................................................................................... 444
Table 3-655. Function i2c_smbus_default_addr_enable ......................................................................... 445
Table 3-656. Function i2c_smbus_default_addr_disable ........................................................................ 445
Table 3-657. Function i2c_smbus_host_addr_enable ............................................................................. 446
19
GD32E50x Firmware Library User Guide
Table 3-658. Function i2c_smbus_host_addr_disable ............................................................................ 446
Table 3-659. Function i2c_extented_clock_timeout_enable ................................................................... 447
Table 3-660. Function i2c_extented_clock_timeout_disable .................................................................. 447
Table 3-661. Function i2c_clock_timeout_enable .................................................................................... 448
Table 3-662. Function i2c_clock_timeout_disable ................................................................................... 448
Table 3-663. Function i2c_bus_timeout_b_config .................................................................................... 449
Table 3-664. Function i2c_bus_timeout_a_config .................................................................................... 449
Table 3-665. Function i2c_idle_clock_timeout_config ............................................................................ 450
Table 3-666. Function i2c2_flag_get ........................................................................................................... 451
Table 3-667. Function i2c2_flag_clear ........................................................................................................ 451
Table 3-668. Function i2c2_interrupt_enable ............................................................................................ 452
Table 3-669. Function i2c2_interrupt_disable ........................................................................................... 453
Table 3-670. Function i2c2_interrupt_flag_get .......................................................................................... 454
Table 3-671. Function i2c2_interrupt_flag_clear....................................................................................... 455
Table 3-672. NVIC Registers ......................................................................................................................... 456
Table 3-673. SysTick Registers .................................................................................................................... 456
Table 3-674. MISC firmware function .......................................................................................................... 457
Table 3-675. IRQn_Type ................................................................................................................................. 457
Table 3-676. Function nvic_priority_group_set ........................................................................................ 459
Table 3-677. Function nvic_irq_enable ....................................................................................................... 460
Table 3-678. Function nvic_irq_disable ...................................................................................................... 461
Table 3-679. Function nvic_system_reset ................................................................................................. 461
Table 3-680. Function nvic_vector_table_set ............................................................................................ 462
Table 3-681. Function system_lowpower_set ........................................................................................... 462
Table 3-682. Function system_lowpower_reset ........................................................................................ 463
Table 3-683. Function systick_clksource_set ........................................................................................... 463
Table 3-684. PMU Registers .......................................................................................................................... 464
Table 3-685. PMU firmware function ........................................................................................................... 464
Table 3-686. Function pmu_deinit ............................................................................................................... 465
Table 3-687. Function pmu_lvd_select ....................................................................................................... 466
Table 3-688. Function pmu_lvd_disable ..................................................................................................... 466
Table 3-689. Function pmu_highdriver_mode_enable ............................................................................ 467
Table 3-690. Function pmu_highdriver_mode_disable ........................................................................... 467
Table 3-691. Function pmu_highdriver_switch_select ............................................................................ 468
Table 3-692. Function pmu_lowdriver_mode_enable .............................................................................. 468
Table 3-693. Function pmu_lowdriver_mode_disable ............................................................................. 469
Table 3-694. Function pmu_lowpower_driver_config .............................................................................. 469
Table 3-695. Function pmu_normalpower_driver_config ....................................................................... 470
Table 3-696. Function pmu_to_sleepmode ................................................................................................ 470
Table 3-697. Function pmu_to_deepsleepmode ....................................................................................... 471
Table 3-698. Function pmu_to_deepsleepmode_1 ................................................................................... 472
Table 3-699. Function pmu_to_deepsleepmode_2 ................................................................................... 472
Table 3-700. Function pmu_to_standbymode ........................................................................................... 473
Table 3-701. Function pmu_backup_write_enable ................................................................................... 473
20
GD32E50x Firmware Library User Guide
Table 3-702. Function pmu_backup_write_disable .................................................................................. 474
Table 3-703. Function pmu_wakeup_pin_enable ..................................................................................... 474
Table 3-704. Function pmu_wakeup_pin_disable .................................................................................... 475
Table 3-705. Function pmu_flag_get ........................................................................................................... 476
Table 3-706. Function pmu_flag_clear ........................................................................................................ 476
Table 3-707. RCU Registers .......................................................................................................................... 477
Table 3-708. RCU firmware function ........................................................................................................... 478
Table 3-709. Enum rcu_periph_enum ......................................................................................................... 479
Table 3-710. Enum rcu_periph_sleep_enum ............................................................................................. 481
Table 3-711. Enum rcu_periph_reset_enum .............................................................................................. 481
Table 3-712. Enum rcu_flag_enum .............................................................................................................. 482
Table 3-713. Enum rcu_int_flag_enum ....................................................................................................... 483
Table 3-714. Enum rcu_int_flag_clear_enum ............................................................................................ 484
Table 3-715. Enum rcu_int_enum ................................................................................................................ 484
Table 3-716. Enum rcu_osci_type_enum ................................................................................................... 484
Table 3-717. Enum rcu_clock_freq_enum .................................................................................................. 485
Table 3-718. Function rcu_deinit ................................................................................................................. 485
Table 3-719. Function rcu_periph_clock_enable ...................................................................................... 486
Table 3-720. Function rcu_periph_clock_disable ..................................................................................... 487
Table 3-721. Function rcu_periph_clock_sleep_enable .......................................................................... 488
Table 3-722. Function rcu_periph_clock_sleep_disable ......................................................................... 488
Table 3-723. Function rcu_periph_reset_enable....................................................................................... 489
Table 3-724. Function rcu_periph_reset_disable ..................................................................................... 490
Table 3-725. Function rcu_bkp_reset_enable ........................................................................................... 491
Table 3-726. Function rcu_bkp_reset_disable .......................................................................................... 491
Table 3-727. Function rcu_system_clock_source_config....................................................................... 492
Table 3-728. Function rcu_system_clock_source_get ............................................................................ 492
Table 3-729. Function rcu_ahb_clock_config ........................................................................................... 493
Table 3-730. Function rcu_apb1_clock_config ......................................................................................... 493
Table 3-731. Function rcu_apb2_clock_config ......................................................................................... 494
Table 3-732. Function rcu_ckout0_config .................................................................................................. 495
Table 3-733. Function rcu_pll_config ......................................................................................................... 496
Table 3-734. Function rcu_pllpresel_config .............................................................................................. 496
Table 3-735. Function rcu_predv0_config ................................................................................................. 497
Table 3-736. Function rcu_predv0_config ................................................................................................. 498
Table 3-737. Function rcu_predv1_config ................................................................................................. 498
Table 3-738. Function rcu_pll1_config ....................................................................................................... 499
Table 3-739. Function rcu_pll2_config ....................................................................................................... 499
Table 3-740. Function rcu_pllusbpresel_config ........................................................................................ 500
Table 3-741. Function rcu_pllusbpredv_config ........................................................................................ 500
Table 3-742. Function rcu_pllusb_config ................................................................................................... 501
Table 3-743. Function rcu_adc_clock_config ............................................................................................ 501
Table 3-744. Function rcu_usb_clock_config ........................................................................................... 502
Table 3-745. Function rcu_rtc_clock_config ............................................................................................. 503
21
GD32E50x Firmware Library User Guide
Table 3-746. Function rcu_shrtimer_clock_config ................................................................................... 504
Table 3-747. Function rcu_usart5_clock_config ....................................................................................... 504
Table 3-748. Function rcu_i2c2_clock_config ........................................................................................... 505
Table 3-749. Function rcu_i2s1_clock_config ........................................................................................... 506
Table 3-750. Function rcu_i2s2_clock_config ........................................................................................... 506
Table 3-751. Function rcu_ck48m_clock_config ...................................................................................... 507
Table 3-752. Function rcu_usbhssel_config ............................................................................................. 508
Table 3-753. Function rcu_usbdv_config ................................................................................................... 508
Table 3-754. Function rcu_flag_get ............................................................................................................. 509
Table 3-755. Function rcu_all_reset_flag_clear ........................................................................................ 510
Table 3-756. Function rcu_interrupt_flag_get ........................................................................................... 510
Table 3-757. Function rcu_interrupt_flag_clear ........................................................................................ 511
Table 3-758. Function rcu_interrupt_enable .............................................................................................. 512
Table 3-759. Function rcu_interrupt_disable ............................................................................................. 513
Table 3-760. Function rcu_lxtal_drive_capability_config ........................................................................ 514
Table 3-761. Function rcu_osci_stab_wait ................................................................................................ 514
Table 3-762. Function rcu_osci_on ............................................................................................................. 515
Table 3-763. Function rcu_osci_off ............................................................................................................. 516
Table 3-764. Function rcu_osci_bypass_mode_enable .......................................................................... 516
Table 3-765. Function rcu_osci_bypass_mode_disable ......................................................................... 517
Table 3-766. Function rcu_hxtal_clock_monitor_enable ........................................................................ 517
Table 3-767. Function rcu_hxtal_clock_monitor_disable ....................................................................... 518
Table 3-768. Function rcu_irc8m_adjust_value_set ................................................................................. 518
Table 3-769. Function rcu_deepsleep_voltage_set .................................................................................. 519
Table 3-770. Function rcu_clock_freq_get ................................................................................................. 519
Table 3-771. RTC Registers .......................................................................................................................... 520
Table 3-772. RTC firmware function ............................................................................................................ 521
Table 3-773. Function rtc_configuration_mode_enter ............................................................................. 521
Table 3-774. Function rtc_configuration_mode_exit ............................................................................... 522
Table 3-775. Function rtc_lwoff_wait .......................................................................................................... 522
Table 3-776. Function rtc_register_sync_wait .......................................................................................... 523
Table 3-777. Function rtc_counter_get ....................................................................................................... 523
Table 3-778. Function rtc_counter_set ....................................................................................................... 524
Table 3-779. Function rtc_prescaler_set .................................................................................................... 524
Table 3-780. Function rtc_alarm_config ..................................................................................................... 525
Table 3-781. Function rtc_divider_get ........................................................................................................ 525
Table 3-782. Function rtc_interrupt_enable ............................................................................................... 526
Table 3-783. Function rtc_interrupt_disable .............................................................................................. 526
Table 3-784. Function rtc_flag_get .............................................................................................................. 527
Table 3-785. Function rtc_flag_clear ........................................................................................................... 528
Table 3-786. SDIO Registers ......................................................................................................................... 529
Table 3-787. SDIO firmware function .......................................................................................................... 529
Table 3-788. Function sdio_deinit ............................................................................................................... 530
Table 3-789. Function sdio_clock_config .................................................................................................. 531
22
GD32E50x Firmware Library User Guide
Table 3-790. Function sdio_hardware_clock_enable ............................................................................... 532
Table 3-791. Function sdio_hardware_clock_disable .............................................................................. 532
Table 3-792. Function sdio_bus_mode_set ............................................................................................... 533
Table 3-793. Function sdio_power_state_set ............................................................................................ 533
Table 3-794. Function sdio_power_state_get ............................................................................................ 534
Table 3-795. Function sdio_clock_enable .................................................................................................. 534
Table 3-796. Function sdio_clock_disable ................................................................................................. 535
Table 3-797. Function sdio_command_response_config ....................................................................... 535
Table 3-798. Function sdio_wait_type_set ................................................................................................. 536
Table 3-799. Function sdio_csm_enable .................................................................................................... 537
Table 3-800. Function sdio_csm_disable ................................................................................................... 537
Table 3-801. Function sdio_command_index_get .................................................................................... 538
Table 3-802. Function sdio_response_get ................................................................................................. 538
Table 3-803. Function sdio_data_config .................................................................................................... 539
Table 3-804. Function sdio_data_transfer_config .................................................................................... 540
Table 3-805. Function sdio_dsm_enable .................................................................................................... 541
Table 3-806. Function sdio_dsm_disable ................................................................................................... 541
Table 3-807. Function sdio_data_write ....................................................................................................... 542
Table 3-808. Function sdio_data_read ........................................................................................................ 542
Table 3-809. Function sdio_data_counter_get .......................................................................................... 543
Table 3-810. Function sdio_data_counter_get .......................................................................................... 543
Table 3-811. Function sdio_dma_enable .................................................................................................... 544
Table 3-812. Function sdio_dma_disable ................................................................................................... 544
Table 3-813. Function sdio_flag_get ........................................................................................................... 545
Table 3-814. Function sdio_flag_clear ........................................................................................................ 546
Table 3-815. Function sdio_interrupt_enable ............................................................................................ 547
Table 3-816. Function sdio_interrupt_disable ........................................................................................... 548
Table 3-817. Function sdio_interrupt_flag_get ......................................................................................... 549
Table 3-818. Function sdio_interrupt_flag_clear ...................................................................................... 551
Table 3-819. Function sdio_readwait_enable ............................................................................................ 552
Table 3-820. Function sdio_readwait_disable ........................................................................................... 552
Table 3-821. Function sdio_stop_readwait_enable .................................................................................. 553
Table 3-822. Function sdio_stop_readwait_disable ................................................................................. 553
Table 3-823. Function sdio_readwait_type_set ......................................................................................... 554
Table 3-824. Function sdio_operation_enable .......................................................................................... 554
Table 3-825. Function sdio_operation_disable ......................................................................................... 555
Table 3-826. Function sdio_suspend_enable ............................................................................................ 555
Table 3-827. Function sdio_suspend_disable ........................................................................................... 556
Table 3-828. Function sdio_ceata_command_enable .............................................................................. 556
Table 3-829. Function sdio_ceata_command_disable ............................................................................. 557
Table 3-830. Function sdio_ceata_interrupt_enable ................................................................................ 557
Table 3-831. Function sdio_ceata_interrupt_disable ............................................................................... 558
Table 3-832. Function sdio_ceata_command_completion_enable ....................................................... 558
Table 3-833. Function sdio_ceata_command_completion_disable ...................................................... 559
23
GD32E50x Firmware Library User Guide
Table 3-834. SPI/I2S Registers ..................................................................................................................... 559
Table 3-835. SPI/I2S firmware function ....................................................................................................... 560
Table 3-836. spi_parameter_struct .............................................................................................................. 561
Table 3-837. Function spi_i2s_deinit .......................................................................................................... 561
Table 3-838. Function spi_struct_para_init ............................................................................................... 562
Table 3-839. Function spi_init ...................................................................................................................... 562
Table 3-840. Function spi_enable ................................................................................................................ 563
Table 3-841. Function spi_disable ............................................................................................................... 564
Table 3-842. Function i2s_init ...................................................................................................................... 564
Table 3-843. Function i2s_psc_config ........................................................................................................ 565
Table 3-844. Function i2s_enable ................................................................................................................ 567
Table 3-845. Function i2s_disable ............................................................................................................... 567
Table 3-846. Function spi_nss_output_enable ......................................................................................... 568
Table 3-847. Function spi_nss_output_disable ........................................................................................ 568
Table 3-848. Function spi_nss_internal_high ........................................................................................... 569
Table 3-849. Function spi_nss_internal_low ............................................................................................. 569
Table 3-850. Function spi_dma_enable ...................................................................................................... 570
Table 3-851. Function spi_dma_disable ..................................................................................................... 570
Table 3-852. Function spi_i2s_data_frame_format_config ..................................................................... 571
Table 3-853. Function spi_i2s_data_transmit ............................................................................................ 571
Table 3-854. Function spi_i2s_data_receive ............................................................................................. 572
Table 3-855. Function spi_bidirectional_transfer_config ........................................................................ 572
Table 3-856. Function spi_crc_polynomial_set ........................................................................................ 573
Table 3-857. Function spi_crc_polynomial_get ........................................................................................ 574
Table 3-858. Function spi_crc_on ............................................................................................................... 574
Table 3-859. Function spi_crc_off ............................................................................................................... 575
Table 3-860. Function spi_crc_next ............................................................................................................ 575
Table 3-861. Function spi_crc_get .............................................................................................................. 576
Table 3-862. Function spi_ti_mode_enable ............................................................................................... 576
Table 3-863. Function spi_ti_mode_disable .............................................................................................. 577
Table 3-864. Function spi_nssp_mode_enable ......................................................................................... 577
Table 3-865. Function spi_nssp_mode_disable ........................................................................................ 578
Table 3-866. Function i2s_init ...................................................................................................................... 578
Table 3-867. Function qspi_enable ............................................................................................................. 580
Table 3-868. Function qspi_disable ............................................................................................................ 580
Table 3-869. Function qspi_write_enable ................................................................................................... 581
Table 3-870. Function qspi_read_enable ................................................................................................... 581
Table 3-871. Function qspi_io23_output_enable ...................................................................................... 582
Table 3-872. Function qspi_io23_output_disable ..................................................................................... 582
Table 3-873. Function spi_i2s_interrupt_enable ....................................................................................... 583
Table 3-874. Function spi_i2s_interrupt_disable ...................................................................................... 583
Table 3-875. Function spi_i2s_interrupt_flag_get .................................................................................... 584
Table 3-876. Function spi_i2s_flag_get ...................................................................................................... 585
Table 3-877. Function spi_crc_error_clear ................................................................................................ 586
24
GD32E50x Firmware Library User Guide
Table 3-878. SQPI Registers ......................................................................................................................... 587
Table 3-879. SQPI firmware function........................................................................................................... 587
Table 3-880. sqpi_parameter_struct ............................................................................................................ 587
Table 3-881. Function sqpi_deinit ............................................................................................................... 587
Table 3-882. Function sqpi_struct_para_init ............................................................................................. 588
Table 3-883. Function sqpi_init .................................................................................................................... 588
Table 3-884. Function sqpi_read_id_command ........................................................................................ 589
Table 3-885. Function sqpi_special_command ......................................................................................... 590
Table 3-886. Function sqpi_read_command_config ................................................................................ 590
Table 3-887. Function sqpi_write_command_config ............................................................................... 591
Table 3-888. Function sqpi_low_id_receive............................................................................................... 592
Table 3-889. Function sqpi_low_id_receive............................................................................................... 592
Table 3-890. TIMERx Registers .................................................................................................................... 593
Table 3-891. TIMERx firmware function ...................................................................................................... 594
Table 3-892. Structure timer_parameter_struct ........................................................................................ 596
Table 3-893. Structure timer_break_parameter_struct ............................................................................ 596
Table 3-894. Structure timer_oc_parameter_struct .................................................................................. 597
Table 3-895. Structure timer_ic_parameter_struct ................................................................................... 597
Table 3-896. Function timer_deinit .............................................................................................................. 597
Table 3-897. Function timer_struct_para_init ............................................................................................ 598
Table 3-898. Function timer_init .................................................................................................................. 598
Table 3-899. Function timer_enable ............................................................................................................ 599
Table 3-900. Function timer_disable ........................................................................................................... 600
Table 3-901. Function timer_auto_reload_shadow_enable .................................................................... 600
Table 3-902. Function timer_auto_reload_shadow_disable ................................................................... 601
Table 3-903. Function timer_update_event_enable ................................................................................. 601
Table 3-904. Function timer_update_event_disable ................................................................................ 602
Table 3-905. Function timer_counter_alignment ...................................................................................... 602
Table 3-906. Function timer_counter_up_direction ................................................................................. 603
Table 3-907. timer_counter_down_direction ............................................................................................. 603
Table 3-908. Function timer_prescaler_config .......................................................................................... 604
Table 3-909. Function timer_repetition_value_config ............................................................................. 605
Table 3-910. Function timer_autoreload_value_config ........................................................................... 605
Table 3-911. Function timer_counter_value_config ................................................................................. 606
Table 3-912. Function timer_counter_read ................................................................................................ 606
Table 3-913. Function timer_prescaler_read ............................................................................................. 607
Table 3-914. Function timer_single_pulse_mode_config ....................................................................... 607
Table 3-915. Function timer_update_source_config ................................................................................ 608
Table 3-916. Function timer_dma_enable .................................................................................................. 609
Table 3-917. Function timer_dma_disable ................................................................................................. 610
Table 3-918. Function timer_channel_dma_request_source_select ..................................................... 610
Table 3-919. Function timer_dma_transfer_config ................................................................................... 611
Table 3-920. Function timer_event_software_generate ........................................................................... 613
Table 3-921. Function timer_break_struct_para_init ............................................................................... 614
25
GD32E50x Firmware Library User Guide
Table 3-922. Function timer_break_config ................................................................................................ 614
Table 3-923. Function timer_break_enable ................................................................................................ 615
Table 3-924. Function timer_break_disable ............................................................................................... 616
Table 3-925. Function timer_automatic_output_enable .......................................................................... 616
Table 3-926. Function timer_automatic_output_disable ......................................................................... 617
Table 3-927. Function timer_primary_output_config ............................................................................... 617
Table 3-928. Function timer_channel_control_shadow_config ............................................................. 618
Table 3-929. Function timer_channel_control_shadow_update_config............................................... 618
Table 3-930. Function timer_channel_output_struct_para_init ............................................................. 619
Table 3-931. Function timer_channel_output_config .............................................................................. 620
Table 3-932. Function timer_channel_output_mode_config .................................................................. 621
Table 3-933. Function timer_channel_output_pulse_value_config....................................................... 622
Table 3-934. Function timer_channel_output_shadow_config .............................................................. 622
Table 3-935. Function timer_channel_output_fast_config...................................................................... 623
Table 3-936. Function timer_channel_output_clear_config ................................................................... 624
Table 3-937. Function timer_channel_output_polarity_config ............................................................... 625
Table 3-938. Function timer_channel_complementary_output_polarity_config ................................ 626
Table 3-939. Function timer_channel_output_state_config ................................................................... 627
Table 3-940. Function timer_channel_complementary_output_state_config ..................................... 627
Table 3-941. Function timer_channel_input_struct_para_init ................................................................ 628
Table 3-942. Function timer_input_capture_config.................................................................................. 629
Table 3-943. Function timer_channel_input_capture_prescaler_config .............................................. 630
Table 3-944. Function timer_channel_capture_value_register_read .................................................... 630
Table 3-945. Function timer_input_pwm_capture_config ....................................................................... 631
Table 3-946. Function timer_hall_mode_config ........................................................................................ 632
Table 3-947. Function timer_input_trigger_source_select ..................................................................... 633
Table 3-948. Function timer_master_output_trigger_source_select .................................................... 634
Table 3-949. Function timer_slave_mode_select ..................................................................................... 635
Table 3-950. Function timer_master_slave_mode_config ...................................................................... 636
Table 3-951. Function timer_external_trigger_config .............................................................................. 636
Table 3-952. Function timer_quadrature_decoder_mode_config .......................................................... 637
Table 3-953. Function timer_internal_clock_config ................................................................................. 638
Table 3-954. Function timer_internal_trigger_as_external_clock_config ............................................ 639
Table 3-955. Function timer_external_trigger_as_external_clock_config ........................................... 640
Table 3-956. Function timer_external_clock_mode0_config .................................................................. 641
Table 3-957. Function timer_external_clock_mode1_config .................................................................. 641
Table 3-958. Function timer_external_clock_mode1_disable ................................................................ 642
Table 3-959. Function timer_write_chxval_register_config .................................................................... 643
Table 3-960. Function timer_output_value_selection_config ................................................................ 644
Table 3-965. Function timer_flag_get ......................................................................................................... 644
Table 3-966. Function timer_flag_clear ...................................................................................................... 645
Table 3-961. Function timer_interrupt_enable .......................................................................................... 646
Table 3-962. Function timer_interrupt_disable ......................................................................................... 647
Table 3-963. Function timer_interrupt_flag_get ........................................................................................ 647
26
GD32E50x Firmware Library User Guide
Table 3-964. Function timer_interrupt_flag_clear ..................................................................................... 648
Table 3-967. TMU Registers .......................................................................................................................... 649
Table 3-968. TMU firmware function ........................................................................................................... 650
Table 3-969. Function tmu_deinit ................................................................................................................ 650
Table 3-970. Function tmu_enable .............................................................................................................. 650
Table 3-971. Function tmu_mode_set ......................................................................................................... 651
Table 3-972. Function tmu_idata0_write .................................................................................................... 652
Table 3-973. Function tmu_idata1_write .................................................................................................... 652
Table 3-974. Function tmu_data0_read ...................................................................................................... 653
Table 3-975. Function tmu_data1_read ...................................................................................................... 653
Table 3-976. Function tmu_interrupt_enable ............................................................................................. 654
Table 3-977. Function tmu_interrupt_disable ............................................................................................ 654
Table 3-978. Function tmu_flag_get ............................................................................................................ 655
Table 3-979. Function tmu_interrupt_flag_get .......................................................................................... 655
Table 3-980. USART Registers ..................................................................................................................... 656
Table 3-981. USART firmware function....................................................................................................... 657
Table 3-982. Enum usart_flag_enum........................................................................................................... 659
Table 3-983. Enum usart5_flag_enum ........................................................................................................ 660
Table 3-984. Enum usart_interrupt_flag_enum ......................................................................................... 660
Table 3-985. Enum usart5_interrupt_flag_enum ....................................................................................... 661
Table 3-986. Enum usart_interrupt_enum .................................................................................................. 662
Table 3-987. Enum usart5_interrupt_enum ................................................................................................ 662
Table 3-988. Enum usart_invert_enum ....................................................................................................... 662
Table 3-989. Enum usart5_invert_enum ..................................................................................................... 663
Table 3-990. Function usart_deinit .............................................................................................................. 663
Table 3-991. Function usart_baudrate_set ................................................................................................ 663
Table 3-992. Function usart_parity_config ................................................................................................ 664
Table 3-993. Function usart_word_length_set .......................................................................................... 665
Table 3-994. Function usart_stop_bit_set .................................................................................................. 665
Table 3-995. Function usart_enable ............................................................................................................ 666
Table 3-996. Function usart_disable ........................................................................................................... 666
Table 3-997. Function usart_transmit_config ............................................................................................ 667
Table 3-998. Function usart_receive_config ............................................................................................. 668
Table 3-999. Function usart_oversample_config ..................................................................................... 668
Table 3-1000. Function usart_sample_bit_config ..................................................................................... 669
Table 3-1001. Function usart_receiver_timeout_enable ......................................................................... 670
Table 3-1002. Function usart_receiver_timeout_disable ........................................................................ 670
Table 3-1003. Function usart_receiver_timeout_threshold_config ....................................................... 671
Table 3-1004. Function usart_data_transmit ............................................................................................. 671
Table 3-1005. Function usart_data_receive ............................................................................................... 672
Table 3-1006. Function usart_mute_mode_enable................................................................................... 672
Table 3-1007. Function usart_mute_mode_disable ................................................................................. 673
Table 3-1008. Function usart_mute_mode_wakeup_config ................................................................... 673
Table 3-1009. Function usart_lin_mode_enable ....................................................................................... 674
27
GD32E50x Firmware Library User Guide
Table 3-1010. Function usart_lin_mode_disable ...................................................................................... 675
Table 3-1011. Function usart_lin_break_dection_length_config ........................................................... 675
Table 3-1012. Function usart_halfduplex_enable ..................................................................................... 676
Table 3-1013. Function usart_halfduplex_disable .................................................................................... 676
Table 3-1014. Function usart_synchronous_clock_enable .................................................................... 677
Table 3-1015. Function usart_synchronous_clock_disable ................................................................... 677
Table 3-1016. Function usart_synchronous_clock_config ..................................................................... 678
Table 3-1017. Function usart_guard_time_config .................................................................................... 679
Table 3-1018. Function usart_smartcard_mode_enable ......................................................................... 679
Table 3-1019. Function usart_smartcard_mode_disable ........................................................................ 680
Table 3-1020. Function usart_smartcard_mode_nack_enable............................................................... 680
Table 3-1021. Function usart_smartcard_mode_nack_disable ............................................................. 681
Table 3-1022. Function usart_smartcard_autoretry_config .................................................................... 681
Table 3-1023. Function usart_block_length_config ................................................................................. 682
Table 3-1024. Function usart_irda_mode_enable ..................................................................................... 682
Table 3-1025. Function usart_irda_mode_disable .................................................................................... 683
Table 3-1026. Function usart_prescaler_config ........................................................................................ 683
Table 3-1027. Function usart_irda_lowpower_config .............................................................................. 684
Table 3-1028. Function usart_hardware_flow_rts_config ....................................................................... 685
Table 3-1029. Function usart_hardware_flow_cts_config ...................................................................... 685
Table 3-1030. Function usart_dma_receive_config ................................................................................. 686
Table 3-1031. Function usart_dma_transmit_config ................................................................................ 687
Table 3-1032. Function usart_data_first_config ....................................................................................... 687
Table 3-1033. Function usart_invert_config .............................................................................................. 688
Table 3-1034. Function usart_address_config .......................................................................................... 689
Table 3-1035. Function usart_send_break ................................................................................................. 689
Table 3-1036. Function usart_flag_get ....................................................................................................... 690
Table 3-1037. Function usart_flag_clear .................................................................................................... 691
Table 3-1038. Function usart_interrupt_enable ........................................................................................ 692
Table 3-1039. Function usart_interrupt_disable ....................................................................................... 692
Table 3-1040. Function usart_interrupt_flag_get ...................................................................................... 693
Table 3-1041. Function usart_interrupt_flag_clear................................................................................... 694
Table 3-1042. Function usart5_ data_first_config .................................................................................... 695
Table 3-1043. Function usart5_invert_config ............................................................................................ 696
Table 3-1044. Function usart5_overrun_enable ........................................................................................ 697
Table 3-1045. Function usart5_overrun_disable....................................................................................... 697
Table 3-1046. Function usart5_autobaud_detection_enable .................................................................. 698
Table 3-1047. Function usart5_autobaud_detection_disable ................................................................. 698
Table 3-1048. Function usart5_autobaud_detection_mode_config ...................................................... 699
Table 3-1049. Function usart5_address_config ........................................................................................ 699
Table 3-1050. Function usart5_address_detection_mode_config ......................................................... 700
Table 3-1051. Function usart5_smartcard_mode_early_nack_enable ................................................. 701
Table 3-1052. Function usart5_smartcard_mode_early_nack_disable ................................................ 701
Table 3-1053. Function usart5_hardware_flow_coherence_config ....................................................... 702
28
GD32E50x Firmware Library User Guide
Table 3-1054. Function usart5_rs485_driver_enable ............................................................................... 702
Table 3-1055. Function usart5_rs485_driver_disable .............................................................................. 703
Table 3-1056. Function usart5_driver_assertime_config ........................................................................ 703
Table 3-1057. Function usart5_driver_deassertime_config .................................................................... 704
Table 3-1058. Function usart5_depolarity_config .................................................................................... 704
Table 3-1059. Function usart5_reception_error_dma_enable ................................................................ 705
Table 3-1060. Function usart5_reception_error_dma_disable ............................................................... 706
Table 3-1061. Function usart5_wakeup_enable ........................................................................................ 706
Table 3-1062. Function usart5_wakeup_disable ....................................................................................... 707
Table 3-1063. Function usart5_wakeup_mode_config ............................................................................ 707
Table 3-1064. Function usart5_receive_fifo_enable ................................................................................. 708
Table 3-1065. Function usart5_receive_fifo_disable ................................................................................ 708
Table 3-1066. Function usart5_receive_fifo_counter_number ............................................................... 709
Table 3-1067. Function usart5_flag_get ..................................................................................................... 709
Table 3-1068. Function usart5_flag_clear .................................................................................................. 711
Table 3-1069. Function usart5_interrupt_enable ...................................................................................... 711
Table 3-1070. Function usart5_interrupt_disable ..................................................................................... 712
Table 3-1071. Function usart5_command_enable .................................................................................... 713
Table 3-1072. Function usart5_interrupt_flag_get .................................................................................... 714
Table 3-1073. Function usart5_interrupt_flag_clear ................................................................................ 715
Table 3-1074. WWDGT Registers ................................................................................................................. 717
Table 3-1075. WWDGT firmware function .................................................................................................. 717
Table 3-1076. Function wwdgt_deinit ......................................................................................................... 717
Table 3-1077. Function wwdgt_enable ....................................................................................................... 718
Table 3-1078. Function wwdgt_counter_update ....................................................................................... 718
Table 3-1079. Function wwdgt_config ........................................................................................................ 719
Table 3-1080. Function wwdgt_interrupt_enable ...................................................................................... 720
Table 3-1081. Function wwdgt_flag_get ..................................................................................................... 720
Table 3-1082. Function wwdgt_flag_clear .................................................................................................. 721
Table 4-1. Revision history ........................................................................................................................... 722

29
GD32E50x Firmware Library User Guide
1. Introduction

This manual introduces firmware library of GD32E50x devices which are 32-bit
microcontrollers based on the ARM processor.

The firmware library is a firmware function package, including program, data structure and
macro definitions, all the performance features of peripherals of GD32E50x devices are
involved in the package. The peripheral driving code and firmware examples on evaluation
board are also included in firmware library. Users need not learn each peripherals in details
and it’s easy to apply a peripheral by using the firmware library. Using firmware library can
greatly reduce programming time, thereby reducing development costs.

The driving code of each peripheral is concluded by a group of functions, which describes all
the performance features of the peripheral. Users can drive a peripheral by a group of APIs
(application programming interface), all the APIs are standardized about the code structure,
function name and parameter names.

All the driving source code accord with MISRA-C:2004 standard (example files accord with
extended ANSI-C standard), and will not be influenced by differences of IDEs, except the
startup files which are written differently according to the IDEs.

The commonly used firmware library includes all the functions of all the peripherals, so the
code size and the execution speed may not be the optimal. For most applications, users can
use the library functions directly, while for the applications which are strict with the code size
and execution speed, the firmware library can be used as the reference resource of how to
configure a peripheral, and users adjust the code according to actual needs.

The overall structure of the firmware library user manual is shown as below:

 Rules of user manual and firmware library;

 Firmware library overview;

 Functions and registers descriptions of firmware library.

1.1. Rules of User Manual and Firmware Library

1.1.1. Peripherals

Table 1-1. Peripherals


Peripherals Descriptions
ADC Analog-to-digital converter
BKP Backup registers
CRC CRC calculation unit
CTC Clock trim controller
CMP Comparator
30
GD32E50x Firmware Library User Guide
Peripherals Descriptions
DAC Digital-to-analog converter
DBG Debug
DMA Direct memory access controller
ENET Ethernet
EXMC External memory controller
EXTI Interrupt/event controller
FMC Flash memory controller
FWDGT Free watchdog timer
GPIO/AFIO General-purpose and alternate-function I/Os
SHRTIMER High-Precision Timer
I2C Inter-integrated circuit interface
MISC Nested Vectored Interrupt Controller
PMU Power management unit
RCU Reset and clock unit
RTC Real-time Clock
SDIO Secure digital input/output interface
SPI/I2S Serial peripheral interface/Inter-IC sound
SQPI Serial/Quad Parallel Interface
TIMER TIMER
TMU Trigonometric Math Unit
USART Universal synchronous/asynchronous receiver /transmitter
WWDGT Window watchdog timer
USBD Universal Serial Bus full-speed device interface
USBHS Universal serial bus High-Speed interface

1.1.2. Naming rules

The firmware library naming rules are shown as below:

 The peripherals are shortened in XXX format, such as: ADC. More shorten information
of peripherals refer to Peripherals;

 The name of sourcefile and header file are started with “gd32e50x_”, such as:
gd32e50x_adc.h;

 The constants used only in one file should be defined in the used file; the constants used
in many files should be defined in corresponding header file. All the constants are written
in uppercase of English letters;

 Registers are handled as constants. The naming of them are written in uppercase of
English letters. In most cases, register names are shortened accord with the user manual;

 Variables are written in lowercase, when concluded by several words, underlines should
be adapted among words;

31
GD32E50x Firmware Library User Guide
 The naming of peripheral functions are started with the peripheral abbreviation added
with an underline, when the function name is concluded by several words, underlines
should be adapted among words, and all the peripheral functions are written in lowercase.

32
GD32E50x Firmware Library User Guide
2. Firmware Library Overview

2.1. File Structure of Firmware Library

GD32E50x_Firmware_Library, the file structure is shown as below:

Figure 2-1. File structure of firmware library of GD32E50x

33
GD32E50x Firmware Library User Guide
2.1.1. Examples Folder

Examples folder, each of GD32 peripheral has a subfolder. Each subfolder contains one or
more examples of the peripheral, to show how to use the peripheral correctly. Each of the
example subfolder includes the files shown as below:
 readme.txt: the description and using guide of the example;
 gd32e50x_libopt.h: the header file configures all the peripherals used in the example,
included by different “DEFINE” sentences (all the peripherals are enabled by default);
 gd32e50x_it.c: the source file include all the interrupt service routines (if no interrupt is
used, then all the function bodies are empty);
 gd32e50x.it.h: the header file include all the prototypes of the interrupt service routines;
 systick.c: the source file include the precise time delay functions by using systick;
 systick.h: the header file include the prototype of the precise time delay functions by
using systick;
 main.c: example code. Note: all the examples are not influenced by software IDEs.

2.1.2. Firmware Folder

Firmware folder includes all the subfolder and files which are the core part of the firmware:

 CMSIS subfolder includes the Cortex M33 kernel support files, the startup file based on
the Cortex M33 kernel processor, the global header file of GD32E50x and system
configuration file;

 GD32E50x_standard_peripheral subfolder:

– Include subfolder includes all the header files of firmware libray, users need not modify
this folder;

– Source subfolder includes all the source files of firmware library, users need not modify
this folder;

 GD32E50x_usbd_library subfolder includes all the related files about USBD peripheral:

– Include subfolder includes the header files of USBD peripheral, users need not modify
this folder;

– Source subfolder includes the source files of USBD peripheral, users need not modify
this folder;

 GD32E50x_usbhs_library subfolder includes all the related files about USBHS


peripheral:

– Include subfolder includes the header files of USBHS peripheral, users need not modify
this folder;

– Source subfolder includes the source files of USBHS peripheral, users need not modify
this folder;

34
GD32E50x Firmware Library User Guide
Note:All the codes accord with MISRA-C:2004 standard, and will not be influenced by
different software IDEs.

2.1.3. Template Folder

Template folder includes a simple demo of how to use LED, how to print by USART and use
key to control, (IAR_project is run in IAR, and Keil_project is run in Keil5). User can use the
project template to compile the formware examples, the steps are shown as below:

Select files

Open “Examples” folder, select the module to be tested, such as SPI, open ”SPI” folder, select
an example of SPI, such as ”SPI_master_transmit_slave_receive_interrupt”, shown as below:

Figure 2-2. Select peripheral example files

35
GD32E50x Firmware Library User Guide
Copy files

Open “Template” folder, keep the folders of ” IAR_project” and ” Keil_project”, and delete the
other files, then copy all the files in “SPI_master_transmit_slave_receive_interrupt” folder to
the “Template” subfolder, shown as below:

Figure 2-3. Copy the peripheral example files

Open a project

GD provides project in Keil and IAR, users can open project in different IDEs according to
their need, such as ”Keil_project”, open \Template\Keil_project\Project.uvprojx, shown as
below:

Figure 2-4. Open the project file

Because different module and different functions adopt different files, users should add or
delete the files in project according to the copied files, shown as below:

36
GD32E50x Firmware Library User Guide
Figure 2-5. Configure project files

Compile-Debug-Download

First compile the project, if there is no error, then select the right jumper cap according to the
description of readme, download the project to the target board, and there will be the
phenomenon showed accord with the description of readme. The usage of IDE can refer to
corresponding software user guide. If users are using Keil, the figure is shown as below:

Figure 2-6. Compile-debug-download

2.1.4. Utilities Folder

Utilities folder includes files about the firmware examples on evaluation board:

 LCD_Commom subfolders include files for USB tests;

 gd32e50x_eval.h and gd32e50x_lcd_eval.h are related header files of the evaluation


board about running the firmware examples;

 gd32e50x_eval.c and gd32e50x_lcd_eval.c are related source files of the evaluation


board about running the firmware examples.

Note:All the codes accord with MISRA-C:2004 standard, and will not be influenced by
different software IDEs.
37
GD32E50x Firmware Library User Guide
2.2. File descriptions of Firmware Library

The major files about the firmware library are listed and described in the table below.

Table 2-1. Function descriptions of Firmware Library

Files Descriptions

The header file about all the header files of peripherals. It is the only one file
gd32e50x_libopt.h which is necessity to be included in the user’s application, to connect the
firmware library and the application.

main.c Example of main function.

gd32e50x_it.h Header file, including all the prototypes of interrupt service routines.

Source files about interruput service routines of peripherals. User can written
his own interrupt functions in this file. For the different interrupt service
gd32e50x_it.c requests to the same interrupt vector, users can confirm the interrupt source
by functions of judging interrupt flags of peripherals. The functions are
included in the firmware library.

The header file of peripheral PPP, including functions about peripheral PPP,
gd32e50x_xxx.h
and the variables used for functions.

gd32e50x_xxx.c The C source file for driving peripheral PPP.

The header file of systick.c, including prototypes of systick configuration


systick.h
function and delay function.

systick.c The source file about systick configuration function and delay function.

Description document about how to configure and how to use the firmware
readme.txt
example.

38
GD32E50x Firmware Library User Guide
3. Firmware Library of Standard Peripherals

3.1. Overview of Firmware Library of Standard Peripherals

The description format of firmware functions are shown as below:

Table 3-1. Peripheral function format of Firmware Library


Function name Name of peripheral function
Function prototype Declaration prototype
Function descriptions Explain the function how to work
Precondition Requirements should meet before calling this function
The called functions Other firmware functions called in this functin
Input parameter{in}
Input parameter name Description
xxxx Description of input parameters
Output parameter{out}
Output parameter
Description
name
xxxx Description of output parameters
Return value
Return value type The range of return value

3.2. ADC

The 12-bit ADC is an analog-to-digital converter using the successive approximation method.
The ADC registers are listed in chapter 3.2.1, the ADC firmware functions are introduced in
chapter 3.2.2.

3.2.1. Descriptions of Peripheral registers

ADC registers are listed in the table shown as below:

Table 3-2. ADC Registers


Registers Descriptions
ADC_STAT Status register
ADC_CTL0 Control register 0
ADC_CTL1 Control register 1
ADC_SAMPT0 Sample time register 0
ADC_SAMPT1 Sample time register 1
ADC_IOFFx
Inserted channel data offset register x(x=0..3)
(x=0..3)
ADC_WDHT0 Watchdog 0 high threshold register
39
GD32E50x Firmware Library User Guide
Registers Descriptions
ADC_WDLT0 Watchdog 0 low threshold register
ADC_RSQ0 Regular sequence register 0
ADC_RSQ1 Regular sequence register 1
ADC_RSQ2 Regular sequence register 2
ADC_ISQ Inserted sequence register
ADC_IDATAx
Inserted data register x(x=0..3)
(x=0..3)
ADC_RDATA Regular data register
ADC_OVSAMPCTL Oversample control register
ADC_WD1SR ADC watchdog 1 channel selection register
ADC_WD2SR ADC watchdog 2 channel selection register
ADC_WDT1 ADC watchdog threshold register 1
ADC_WDT2 ADC watchdog threshold register 2
ADC_DIFCTL ADC differential mode control register

3.2.2. Descriptions of Peripheral functions

ADC firmware functions are listed in the table shown as below:

Table 3-3. ADC firmware function


Function name Function description
adc_deinit reset ADC peripheral
adc_enable enable ADC interface
adc_disable disable ADC interface
adc_calibration_enable ADC calibration and reset calibration
adc_calibration_number configure ADC calibration number
adc_dma_mode_enable enable DMA request
adc_dma_mode_disable disable DMA request
adc_tempsensor_vrefint_enable enable the temperature sensor and vrefint channel
adc_tempsensor_vrefint_disable disable the temperature sensor and vrefint channel
adc_discontinuous_mode_config configure ADC discontinuous mode
adc_mode_config configure the ADC sync mode
adc_special_function_config enable or disable ADC special function
adc_data_alignment_config configure ADCx data alignment
configure the length of regular channel group or inserted
adc_channel_length_config
channel group
adc_regular_channel_config configure ADC regular channel
adc_inserted_channel_config configure ADC inserted channel
adc_inserted_channel_offset_config configure ADC inserted channel offset
adc_channel_differential_mode_
configure differential mode for ADC channel
config
adc_external_trigger_config enable ADC external trigger

40
GD32E50x Firmware Library User Guide
Function name Function description
adc_external_trigger_source_config configure ADC external trigger source
adc_software_trigger_enable enable ADC software trigger
adc_regular_data_read read ADC regular group data register
adc_inserted_data_read read ADC inserted group data register
read the last ADC0 and ADC1 conversion result data in sync
adc_sync_mode_convert_value_read
mode
adc_watchdog0_single_channel_
configure ADC analog watchdog 0 single channel
enable
adc_watchdog0_group_channel_
configure ADC analog watchdog 0 group channel
enable
adc_watchdog0_disable disable ADC analog watchdog 0
adc_watchdog1_channel_config configure ADC analog watchdog 1 channel
adc_watchdog2_channel_config configure ADC analog watchdog 2 channel
adc_watchdog1_disable disable ADC analog watchdog 1
adc_watchdog2_disable disable ADC analog watchdog 2
adc_watchdog0_threshold_config configure ADC analog watchdog 0 threshold
adc_watchdog1_threshold_config configure ADC analog watchdog 1 threshold
adc_watchdog2_threshold_config configure ADC analog watchdog 2 threshold
adc_resolution_config configure ADC resolution
adc_oversample_mode_config configure ADC oversample mode
adc_oversample_mode_enable enable ADC oversample mode
adc_oversample_mode_disable disable ADC oversample mode
adc_flag_get get the ADC flag bits
adc_flag_clear clear the ADC flag bits
adc_interrupt_enable enable ADC interrupt
adc_interrupt_disable disable ADC interrupt
adc_interrupt_flag_get get the ADC interrupt bits
adc_interrupt_flag_clear clear the ADC flag

adc_deinit

The description of adc_deinit is shown as below:

Table 3-4. Function adc_deinit


Function name adc_deinit
Function prototype void adc_deinit(uint32_t adc_periph);
Function descriptions reset ADC peripheral
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection

41
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* reset ADC0 */

adc_deinit(ADC0);

adc_enable

The description of adc_enable is shown as below:

Table 3-5. Function adc_enable


Function name adc_enable
Function prototype void adc_enable(uint32_t adc_periph);
Function descriptions enable ADC interface
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable ADC0 */

adc_enable(ADC0);

adc_disable

The description of adc_disable is shown as below:

Table 3-6. Function adc_disable


Function name adc_disable
Function prototype void adc_disable(uint32_t adc_periph);
Function descriptions disable ADC interface
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
42
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* disable ADC0 */

adc_disable(ADC0);

adc_calibration_enable

The description of adc_calibration_enable is shown as below:

Table 3-7. Function adc_calibration_enable


Function name adc_calibration_enable
Function prototype void adc_calibration_enable(uint32_t adc_periph);
Function descriptions ADC calibration and reset calibration
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* ADC0 calibration and reset calibration */

adc_calibration_enable(ADC0);

adc_calibration_number

The description of adc_calibration_number is shown as below:

Table 3-8. Function adc_calibration_number


Function name adc_calibration_number
Function prototype void adc_calibration_number(uint32_t adc_periph, uint32_t clb_num);
Function descriptions configure ADC calibration number
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
43
GD32E50x Firmware Library User Guide
Input parameter{in}
clb_num calibration number
ADC_CALIBRATION_
calibrate once
NUM1
ADC_CALIBRATION_
calibrate twice
NUM2
ADC_CALIBRATION_
calibrate 4 times
NUM4
ADC_CALIBRATION_
calibrate 8 times
NUM8
ADC_CALIBRATION_
calibrate 16 times
NUM16
ADC_CALIBRATION_
calibrate 32 times
NUM32
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC calibration number */

adc_calibration_number(ADC0, ADC_CALIBRATION_NUM16);

adc_dma_mode_enable

The description of adc_dma_mode_enable is shown as below:

Table 3-9. Function adc_dma_mode_enable


Function name adc_dma_mode_enable
Function prototype void adc_dma_mode_enable(uint32_t adc_periph);
Function descriptions enable ADC DMA request
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable ADC0 DMA request */

44
GD32E50x Firmware Library User Guide
adc_dma_mode_enable(ADC0);

adc_dma_mode_disable

The description of adc_dma_mode_disable is shown as below:

Table 3-10. Function adc_dma_mode_disable


Function name adc_dma_mode_disable
Function prototype void adc_dma_mode_disable(uint32_t adc_periph);
Function descriptions disable ADC DMA request
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable ADC0 DMA request */

adc_dma_mode_disable(ADC0);

adc_tempsensor_vrefint_enable

The description of adc_tempsensor_vrefint_enable is shown as below:

Table 3-11. Function adc_tempsensor_vrefint_enable


Function name adc_tempsensor_vrefint_enable
Function prototype void adc_tempsensor_vrefint_enable(void);
Function descriptions enable the temperature sensor and vrefint channel
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the temperature sensor and vrefint channel */

adc_tempsensor_vrefint_enable();
45
GD32E50x Firmware Library User Guide
adc_tempsensor_vrefint_disable

The description of adc_tempsensor_vrefint_disable is shown as below:

Table 3-12. Function adc_tempsensor_vrefint_disable


Function name adc_tempsensor_vrefint_disable
Function prototype void adc_tempsensor_vrefint_disable(void);
Function descriptions disable the temperature sensor and vrefint channel
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the temperature sensor and vrefint channel */

adc_tempsensor_vrefint_disable();

adc_discontinuous_mode_config

The description of adc_discontinuous_mode_config is shown as below:

Table 3-13. Function adc_discontinuous_mode_config


Function name adc_discontinuous_mode_config
void adc_discontinuous_mode_config(uint32_t adc_periph, uint8_t
Function prototype
adc_channel_group, uint8_t length);
Function descriptions configure ADC discontinuous mode
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel_group select the channel group
ADC_REGULAR_
regular channel group
CHANNEL
ADC_INSERTED_
inserted channel group
CHANNEL
ADC_CHANNEL_
disable discontinuous mode of regular and inserted channel
DISCON_DISABLE
Input parameter{in}

46
GD32E50x Firmware Library User Guide
number of conversions in discontinuous mode, the number can be 1..8 for
length
regular channel, the number has no effect for inserted channel
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 regular channel group discontinuous mode */

adc_discontinuous_mode_config(ADC0, ADC_REGULAR_CHANNEL, 6);

adc_mode_config

The description of adc_mode_config is shown as below:

Table 3-14. Function adc_mode_config


Function name adc_mode_config
Function prototype void adc_mode_config(uint32_t mode);
Function descriptions configure the ADCs sync mode
Precondition -
The called functions -
Input parameter{in}
mode ADC mode
ADC_MODE_FREE all the ADCs work independently
ADC_DAUL_REGULAL
_PARALLEL_INSERTE ADC0 and ADC1 work in combined regular parallel + inserted parallel mode
D_PARALLEL
ADC_DAUL_REGULAL
_PARALLEL_INSERTE ADC0 and ADC1 work in combined regular parallel + trigger rotation mode
D_ROTATION
ADC_DAUL_INSERTE
D_PARALLEL_REGUL ADC0 and ADC1 work in combined inserted parallel + follow-up fast mode
AL_FOLLOWUP_FAST
ADC_DAUL_INSERTE
D_PARALLEL_REGUL
ADC0 and ADC1 work in combined inserted parallel + follow-up slow mode
AL_FOLLOWUP_SLO
W
ADC_DAUL_INSERTE
ADC0 and ADC1 work in inserted parallel mode only
D_PARALLEL
ADC_DAUL_REGULAL
ADC0 and ADC1 work in regular parallel mode only
_PARALLEL
ADC_DAUL_REGULAL
ADC0 and ADC1 work in follow-up fast mode only
_FOLLOWUP_FAST

47
GD32E50x Firmware Library User Guide
ADC_DAUL_REGULAL
ADC0 and ADC1 work in follow-up slow mode only
_FOLLOWUP_SLOW
ADC_DAUL_
INSERTED_TRRIGGE ADC0 and ADC1 work in trigger rotation mode only
R_ROTATION
Output parameter{out}
- -
Return value
- -

Example:

/* configure the ADC sync mode */

adc_mode_config(ADC_MODE_FREE);

adc_special_function_config

The description of adc_special_function_config is shown as below:

Table 3-15. Function adc_special_function_config


Function name adc_special_function_config
void adc_special_function_config(uint32_t adc_periph, uint32_t function,
Function prototype
ControlStatus newvalue);
Function descriptions enable or disable ADC special function
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
function the function to config
ADC_SCAN_MODE scan mode select
ADC_INSERTED_
inserted channel group convert automatically
CHANNEL_AUTO
ADC_CONTINUOUS_
continuous mode select
MODE
Input parameter{in}
newvalue control value
ENABLE enable function
DISABLE disable function
Output parameter{out}
- -
Return value
- -

48
GD32E50x Firmware Library User Guide
Example:

/* enable ADC0 scan mode */

adc_special_function_config(ADC0, ADC_SCAN_MODE, ENABLE);

adc_data_alignment_config

The description of adc_data_alignment_config is shown as below:

Table 3-16. Function adc_data_alignment_config


Function name adc_data_alignment_config
void adc_data_alignment_config(uint32_t adc_periph, uint32_t
Function prototype
data_alignment);
Function descriptions configure ADCx data alignment
Precondition -

The called functions -

Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
data_alignment data alignment select
ADC_DATAALIGN_
right alignment
RIGHT
ADC_DATAALIGN_
left alignment
LEFT
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 data alignment */

adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);

adc_channel_length_config

The description of adc_channel_length_config is shown as below:

Table 3-17. Function adc_channel_length_config


Function name adc_channel_length_config
void adc_channel_length_config(uint32_t adc_periph, uint8_t
Function prototype
adc_channel_group, uint32_t length);
Function descriptions configure the length of regular channel group or inserted channel group
Precondition -

49
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel_group select the channel group
ADC_REGULAR_
regular channel group
CHANNEL
ADC_INSERTED_
inserted channel group
CHANNEL
Input parameter{in}
length the length of the channel, regular channel 1-16, inserted channel 1-4
Output parameter{out}
- -
Return value
- -

Example:

/* configure the length of ADC0 regular channel */

adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 4);

adc_regular_channel_config

The description of adc_regular_channel_config is shown as below:

Table 3-18. Function adc_regular_channel_config


Function name adc_regular_channel_config
void adc_regular_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t
Function prototype
adc_channel, uint32_t sample_time);
Function descriptions configure ADC regular channel
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
rank the regular group sequence rank, this parameter must be between 0 to 15
Input parameter{in}
adc_channel the selected ADC channel
ADC_CHANNEL_x
ADC Channelx (x=0..17) (x=16 and x=17 are only for ADC0)
(x=0..17)
Input parameter{in}
sample_time the sample time value

50
GD32E50x Firmware Library User Guide
ADC_SAMPLETIME_
1.5 cycles
1POINT5
ADC_SAMPLETIME_
7.5 cycles
7POINT5
ADC_SAMPLETIME_
13.5 cycles
13POINT5
ADC_SAMPLETIME_
28.5 cycles
28POINT5
ADC_SAMPLETIME_
41.5 cycles
41POINT5
ADC_SAMPLETIME_
55.5 cycles
55POINT5
ADC_SAMPLETIME_
71.5 cycles
71POINT5
ADC_SAMPLETIME_
239.5 cycles
239POINT5
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 regular channel */

adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_0, ADC_SAMPLETIME_7POINT5);

adc_inserted_channel_config

The description of adc_inserted_channel_config is shown as below:

Table 3-19. Function adc_inserted_channel_config


Function name adc_inserted_channel_config
void adc_inserted_channel_config(uint32_t adc_periph, uint8_t rank, uint8_t
Function prototype
adc_channel, uint32_t sample_time);
Function descriptions configure ADC inserted channel
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
rank the inserted group sequencer rank, this parameter must be between 0 to 3
Input parameter{in}
adc_channel the selected ADC channel

51
GD32E50x Firmware Library User Guide
ADC_CHANNEL_x
ADC Channelx (x=0..17)(x=16 and x=17 are only for ADC0)
(x=0..17)
Input parameter{in}
sample_time the sample time value
ADC_SAMPLETIME_
1.5 cycles
1POINT5
ADC_SAMPLETIME_
7.5 cycles
7POINT5
ADC_SAMPLETIME_
13.5 cycles
13POINT5
ADC_SAMPLETIME_
28.5 cycles
28POINT5
ADC_SAMPLETIME_
41.5 cycles
41POINT5
ADC_SAMPLETIME_
55.5 cycles
55POINT5
ADC_SAMPLETIME_
71.5 cycles
71POINT5
ADC_SAMPLETIME_
239.5 cycles
239POINT5
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 inserted channel */

adc_inserted_channel_config(ADC0, 1, ADC_CHANNEL_0, ADC_SAMPLETIME_7POINT5);

adc_inserted_channel_offset_config

The description of adc_inserted_channel_offset_config is shown as below:

Table 3-20. Function adc_inserted_channel_offset_config


Function name adc_inserted_channel_offset_config
void adc_inserted_channel_offset_config(uint32_t adc_periph, uint8_t
Function prototype
inserted_channel, uint16_t offset);
Function descriptions configure ADC inserted channel offset
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection

52
GD32E50x Firmware Library User Guide
Input parameter{in}
inserted_channel insert channel select
ADC_INSERTED_
inserted channel, x=0,1,2,3
CHANNEL_x(x=0..3)
Input parameter{in}
offset the offset data, this parameter must be between 0 to 4095
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 inserted channel offset */

adc_inserted_channel_offset_config(ADC0, ADC_INSERTED_CHANNEL_0, 100);

adc_channel_differential_mode_config

The description of adc_channel_differential_mode_config is shown as below:

Table 3-21. Function adc_channel_differential_mode_config


Function name adc_channel_differential_mode_config
void adc_channel_differential_mode_config(uint32_t adc_periph, uint32_t
Function prototype
adc_channel, ControlStatus newvalue);
Function descriptions configure differential mode for ADC channel
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
inserted_channel the channel use differential mode
ADC_DIFFERENTIAL_
MODE_CHANNEL_x
(x=0..14), ADC channel for differential mode (just for channel0~channel14)
ADC_DIFFERENTIAL_
MODE_CHANNEL_ALL
Input parameter{in}
newvalue control value
ENABLE enable function
DISABLE disable function
Output parameter{out}
- -
Return value

53
GD32E50x Firmware Library User Guide
- -

Example:

/* configure differential mode for ADC channel */

adc_channel_differential_mode_config(ADC0,
ADC_DIFFERENTIAL_MODE_CHANNEL_ALL, ENABLE);

adc_external_trigger_config

The description of adc_external_trigger_config is shown as below:

Table 3-22. Function adc_external_trigger_config


Function name adc_external_trigger_config
void adc_external_trigger_config(uint32_t adc_periph, uint8_t
Function prototype
adc_channel_group, ControlStatus newvalue);
Function descriptions configure ADC external trigger
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel_group select the channel group
ADC_REGULAR_
regular channel group
CHANNEL
ADC_INSERTED_
inserted channel group
CHANNEL
Input parameter{in}
newvalue control value
ENABLE enable function
DISABLE disable function
Output parameter{out}
- -
Return value
- -

Example:

/* enable ADC0 inserted channel group external trigger */

adc_external_trigger_config(ADC0, ADC_INSERTED_CHANNEL_0, ENABLE);

adc_external_trigger_source_config

The description of adc_external_trigger_source_config is shown as below:

54
GD32E50x Firmware Library User Guide
Table 3-23. Function adc_external_trigger_source_config
Function name adc_external_trigger_ source_config
void adc_external_trigger_source_config(uint32_t adc_periph, uint8_t
Function prototype
adc_channel_group, uint32_t external_trigger_source);
Function descriptions configure ADC external trigger source
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel_group select the channel group
ADC_REGULAR_
regular channel group
CHANNEL
ADC_INSERTED_
inserted channel group
CHANNEL
Input parameter{in}
external_trigger_
regular or inserted group trigger source
source
ADC0_1_EXTTRIG_
TIMER0 CH0 event select for regular channel
REGULAR_T0_CH0
ADC0_1_EXTTRIG_
TIMER0 CH1 event select for regular channel
REGULAR_T0_CH1
ADC0_1_EXTTRIG_
TIMER0 CH2 event select for regular channel
REGULAR_T0_CH2
ADC0_1_EXTTRIG_
TIMER1 CH1 event select for regular channel
REGULAR_T1_CH1
ADC0_1_EXTTRIG_
TIMER2 TRGO event select for regular channel
REGULAR_T2_TRGO
ADC0_1_EXTTRIG_RE
TIMER3 CH3 event select for regular channel
GULAR_T3_CH3
ADC0_1_EXTTRIG_
TIMER7 TRGO event select for regular channel
REGULAR_T7_TRGO
ADC0_1_EXTTRIG_
external interrupt line 11 for regular channel
REGULAR_EXTI_11
ADC0_1_EXTTRIG_
REGULAR_SHRTIMER SHRTIMER_ADCTRG0 output select for regular channel
_ADCTRG0
ADC0_1_EXTTRIG_
REGULAR_SHRTIMER SHRTIMER_ADCTRG2 output select for regular channel
_ADCTRG2
ADC2_EXTTRIG_
TIMER2 CH0 event select for regular channel
REGULAR_T2_CH0

55
GD32E50x Firmware Library User Guide
ADC2_EXTTRIG_
TIMER1 CH2 event select for regular channel
REGULAR_T1_CH2
ADC2_EXTTRIG_
TIMER0 CH2 event select for regular channel
REGULAR_T0_CH2
ADC2_EXTTRIG_
TIMER7 CH0 event select for regular channel
REGULAR_T7_CH0
ADC2_EXTTRIG_
TIMER7 TRGO event select for regular channel
REGULAR_T7_TRGO
ADC2_EXTTRIG_
TIMER4 CH0 event select for regular channel
REGULAR_T4_CH0
ADC2_EXTTRIG_
TIMER4 CH2 event select for regular channel
REGULAR_T4_CH2
ADC0_1_2_EXTTRIG_
software trigger for regular channel
REGULAR_NONE
ADC0_1_EXTTRIG_
TIMER0 TRGO event select for inserted channel
INSERTED_T0_TRGO
ADC0_1_EXTTRIG_
TIMER0 CH3 event select for inserted channel
INSERTED_T0_CH3
ADC0_1_EXTTRIG_
TIMER1 TRGO event select for inserted channel
INSERTED_T1_TRGO
ADC0_1_EXTTRIG_
TIMER1 CH0 event select for inserted channel
INSERTED_T1_CH0
ADC0_1_EXTTRIG_
TIMER2 CH3 event select for inserted channel
INSERTED_T2_CH3
ADC0_1_EXTTRIG_
TIMER3 TRGO event select for inserted channel
INSERTED_T3_TRGO
ADC0_1_EXTTRIG_
TIMER7 CH3 event select for inserted channel
INSERTED_T7_CH3
ADC0_1_EXTTRIG_
external interrupt line 15 for inserted channel
INSERTED_EXTI_15
ADC0_1_EXTTRIG_
INSERTED_SHRTIME SHRTIMER_ADCTRG1 output select for inserted channel
R_ADCTRG1
ADC0_1_EXTTRIG_
INSERTED_SHRTIME SHRTIMER_ADCTRG3 output select for inserted channel
R_ADCTRG3
ADC2_EXTTRIG_
TIMER0 TRGO event select for inserted channel
INSERTED_T0_TRGO
ADC2_EXTTRIG_
TIMER0 CH3 event select for inserted channel
INSERTED_T0_CH3
ADC2_EXTTRIG_
TIMER3 CH2 event select for inserted channel
INSERTED_T3_CH2
ADC2_EXTTRIG_ TIMER7 CH1 event select for inserted channel

56
GD32E50x Firmware Library User Guide
INSERTED_T7_CH1
ADC2_EXTTRIG_
TIMER7 CH3 event select for inserted channel
INSERTED_T7_CH3
ADC2_EXTTRIG_
TIMER4 TRGO event select for inserted channel
INSERTED_T4_TRGO
ADC2_EXTTRIG_
TIMER4 CH3 event select for inserted channel
INSERTED_T4_CH3
ADC0_1_2_EXTTRIG_
software trigger for inserted channel
INSERTED_NONE
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 regular channel external trigger source */

adc_external_trigger_source_config(ADC0,ADC_REGULAR_CHANNEL,
ADC0_1_EXTTRIG_REGULAR_T0_CH0);

adc_software_trigger_enable

The description of adc_software_trigger_enable is shown as below:

Table 3-24. Function adc_software_trigger_enable


Function name adc_software_trigger_enable
void adc_software_trigger_enable(uint32_t adc_periph, uint8_t
Function prototype
adc_channel_group);
Function descriptions enable ADC software trigger
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel_group select the channel group
ADC_REGULAR_
regular channel group
CHANNEL
ADC_INSERTED_
inserted channel group
CHANNEL
Output parameter{out}
- -
Return value
- -

57
GD32E50x Firmware Library User Guide
Example:

/* enable ADC0 regular channel group software trigger */

adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);

adc_regular_data_read

The description of adc_regular_data_read is shown as below:

Table 3-25. Function adc_regular_data_read


Function name adc_regular_data_read
Function prototype uint16_t adc_regular_data_read(uint32_t adc_periph);
Function descriptions read ADC regular group data register
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
uint16_t ADC conversion value (0~0xFFFF)

Example:

/* read ADC0 regular group data register */

uint16_t adc_value = 0;

adc_value = adc_regular_data_read(ADC0);

adc_inserted_data_read

The description of adc_inserted_data_read is shown as below:

Table 3-26. Function adc_inserted_data_read


Function name adc_inserted_data_read
uint16_t adc_inserted_data_read(uint32_t adc_periph, uint8_t
Function prototype
inserted_channel);
Function descriptions read ADC inserted group data register
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
inserted_channel insert channel select
58
GD32E50x Firmware Library User Guide
ADC_INSERTED_
inserted Channelx, x=0,1,2,3
CHANNEL_x(x=0..3)
Output parameter{out}
- -
Return value
uint16_t ADC conversion value (0~0xFFFF)

Example:

/* read ADC0 inserted group data register */

uint16_t adc_value = 0;

adc_value = adc_inserted_data_read (ADC0, ADC_INSERTED_CHANNEL_0);

adc_sync_mode_convert_value_read

The description of adc_sync_mode_convert_value_read is shown as below:

Table 3-27. Function adc_sync_mode_convert_value_read


Function name adc_sync_mode_convert_value_read
Function prototype uint32_t adc_sync_mode_convert_value_read(void);
Function descriptions read the last ADC0 and ADC1 conversion result data in sync mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t ADC conversion value (0-0xFFFFFFFF)

Example:

/* read the last ADC0 and ADC1 conversion result data in sync mode */

uint32_t adc_value = 0;

adc_value = adc_sync_mode_convert_value_read ();

adc_watchdog0_single_channel_enable

The description of adc_watchdog0_single_channel_enable is shown as below:

Table 3-28. Function adc_watchdog0_single_channel_enable


Function name adc_watchdog0_single_channel_enable
void adc_watchdog0_single_channel_enable(uint32_t adc_periph, uint8_t
Function prototype
adc_channel);
Function descriptions configure ADC analog watchdog 0 single channel

59
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel the selected ADC channel
ADC_CHANNEL_x
ADC channelx(x=0..17) (x=16 and x=17 are only for ADC0)
(x=0..17)
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 analog watchdog 0 single channel */

adc_watchdog0_single_channel_enable(ADC0, ADC_CHANNEL_1);

adc_watchdog0_group_channel_enable

The description of adc_watchdog0_group_channel_enable is shown as below:

Table 3-29. Function adc_watchdog0_group_channel_enable


Function name adc_watchdog0_group_channel_enable
void adc_watchdog0_group_channel_enable(uint32_t adc_periph, uint8_t
Function prototype
adc_channel_group);
Function descriptions configure ADC analog watchdog 0 group channel
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel_group the channel group use analog watchdog
ADC_REGULAR_
regular channel group
CHANNEL
ADC_INSERTED_
inserted channel group
CHANNEL
ADC_REGULAR_
both regular and inserted group
INSERTED_CHANNEL
Output parameter{out}
- -
Return value

60
GD32E50x Firmware Library User Guide
- -

Example:

/* configure ADC0 analog watchdog 0 group channel */

adc_watchdog0_group_channel_enable(ADC0, ADC_REGULAR_CHANNEL);

adc_watchdog0_disable

The description of adc_watchdog0_disable is shown as below:

Table 3-30. Function adc_watchdog0_disable


Function name adc_watchdog0_disable
Function prototype void adc_watchdog0_disable(uint32_t adc_periph);
Function descriptions disable ADC analog watchdog 0
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable ADC0 analog watchdog 0 */

adc_watchdog0_disable(ADC0);

adc_watchdog1_channel_config

The description of adc_watchdog1_channel_config is shown as below:

Table 3-31. Function adc_watchdog1_channel_config


Function name adc_watchdog1_channel_config
void adc_watchdog1_channel_config(uint32_t adc_periph, uint32_t
Function prototype
adc_channel, ControlStatus newvalue);
Function descriptions configure ADC analog watchdog 1 channel
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel the selected ADC channel
61
GD32E50x Firmware Library User Guide
ADC_AWD1_2_SELEC
TION_CHANNEL_x
ADC channel analog watchdog 1/2 selection
(x=0..17),
(x=0..17, x=16 and x=17 are only for ADC0)
ADC_AWD1_2_SELEC
TION_CHANNEL_ALL
Input parameter{in}
newvalue control value
ENABLE enable function
DISABLE disable function
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC analog watchdog 1 channel */

adc_watchdog1_channel_config(ADC0, ADC_AWD1_2_SELECTION_CHANNEL_1,
ENABLE);

adc_watchdog2_channel_config

The description of adc_watchdog2_channel_config is shown as below:

Table 3-32. Function adc_watchdog2_channel_config


Function name adc_watchdog2_channel_config
void adc_watchdog2_channel_config(uint32_t adc_periph, uint32_t
Function prototype
adc_channel, ControlStatus newvalue);
Function descriptions configure ADC analog watchdog 2 channel
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
adc_channel the selected ADC channel
ADC_AWD1_2_SELEC
TION_CHANNEL_x
ADC channel analog watchdog 1/2 selection
(x=0..17),
(x=0..17, x=16 and x=17 are only for ADC0)
ADC_AWD1_2_SELEC
TION_CHANNEL_ALL
Input parameter{in}
newvalue control value
ENABLE enable function

62
GD32E50x Firmware Library User Guide
DISABLE disable function
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC analog watchdog 2 channel */

adc_watchdog2_channel_config(ADC0, ADC_AWD1_2_SELECTION_CHANNEL_1,
ENABLE);

adc_watchdog1_disable

The description of adc_watchdog1_disable is shown as below:

Table 3-33. Function adc_watchdog1_disable


Function name adc_watchdog1_disable
Function prototype void adc_watchdog1_disable(uint32_t adc_periph);
Function descriptions disable ADC analog watchdog 1
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable ADC0 analog watchdog 1 */

adc_watchdog1_disable(ADC0);

adc_watchdog2_disable

The description of adc_watchdog2_disable is shown as below:

Table 3-34. Function adc_watchdog2_disable


Function name adc_watchdog2_disable
Function prototype void adc_watchdog2_disable(uint32_t adc_periph);
Function descriptions disable ADC analog watchdog 2
Precondition -
The called functions -
Input parameter{in}
63
GD32E50x Firmware Library User Guide
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable ADC0 analog watchdog 2 */

adc_watchdog2_disable(ADC0);

adc_watchdog0_threshold_config

The description of adc_watchdog0_threshold_config is shown as below:

Table 3-35. Function adc_watchdog0_threshold_config


Function name adc_watchdog0_threshold_config
void adc_watchdog0_threshold_config(uint32_t adc_periph , uint16_t
Function prototype
low_threshold , uint16_t high_threshold);
Function descriptions configure ADC analog watchdog 0 threshold
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
low_threshold analog watchdog low threshold, 0..4095
Input parameter{in}
high_threshold analog watchdog high threshold, 0..4095
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 analog watchdog 0 threshold */

adc_watchdog0_threshold_config(ADC0, 0x0400, 0x0A00);

adc_watchdog1_threshold_config

The description of adc_watchdog1_threshold_config is shown as below:

Table 3-36. Function adc_watchdog1_threshold_config


Function name adc_watchdog1_threshold_config
64
GD32E50x Firmware Library User Guide
void adc_watchdog1_threshold_config(uint32_t adc_periph , uint8_t
Function prototype
low_threshold , uint8_t high_threshold);
Function descriptions configure ADC analog watchdog 1 threshold
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
low_threshold analog watchdog low threshold, 0..255
Input parameter{in}
high_threshold analog watchdog high threshold, 0..255
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 analog watchdog 1 threshold */

adc_watchdog1_threshold_config(ADC0, 0x40, 0xA0);

adc_watchdog2_threshold_config

The description of adc_watchdog2_threshold_config is shown as below:

Table 3-37. Function adc_watchdog2_threshold_config


Function name adc_watchdog2_threshold_config
void adc_watchdog2_threshold_config(uint32_t adc_periph , uint8_t
Function prototype
low_threshold , uint8_t high_threshold);
Function descriptions configure ADC analog watchdog 2 threshold
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
low_threshold analog watchdog low threshold, 0..255
Input parameter{in}
high_threshold analog watchdog high threshold, 0..255
Output parameter{out}
- -
Return value
- -

65
GD32E50x Firmware Library User Guide
Example:

/* configure ADC0 analog watchdog 2 threshold */

adc_watchdog2_threshold_config(ADC0, 0x40, 0xA0);

adc_resolution_config

The description of adc_resolution_config is shown as below:

Table 3-38. Function adc_resolution_config


Function name adc_resolution_config
Function prototype void adc_resolution_config(uint32_t adc_periph , uint32_t resolution);
Function descriptions configure ADC resolution
Precondition -

The called functions -

Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
resolution ADC resolution
ADC_RESOLUTION_
12-bit ADC resolution
12B
ADC_RESOLUTION_
10-bit ADC resolution
10B
ADC_RESOLUTION_
8-bit ADC resolution
8B
ADC_RESOLUTION_
6-bit ADC resolution
6B
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC0 data alignment */

adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);

adc_oversample_mode_config

The description of adc_oversample_mode_config is shown as below:

Table 3-39. Function adc_oversample_mode_config


Function name adc_oversample_mode_config
Function prototype void adc_oversample_mode_config(uint32_t adc_periph, uint32_t mode,

66
GD32E50x Firmware Library User Guide
uint16_t shift, uint8_t ratio);
Function descriptions configure ADC oversample mode
Precondition -

The called functions -

Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
mode ADC oversampling mode
ADC_OVERSAMPLING all oversampled conversions for a channel are done consecutively after a
_ALL_CONVERT trigger
ADC_OVERSAMPLING
each oversampled conversion for a channel needs a trigger
_ONE_CONVERT
Input parameter{in}
shift ADC oversampling shift
ADC_OVERSAMPLING
no oversampling shift
_SHIFT_NONE
ADC_OVERSAMPLING
1-bit oversampling shift
_SHIFT_1B
ADC_OVERSAMPLING
2-bit oversampling shift
_SHIFT_2B
ADC_OVERSAMPLING
3-bit oversampling shift
_SHIFT_3B
ADC_OVERSAMPLING
4-bit oversampling shift
_SHIFT_4B
ADC_OVERSAMPLING
5-bit oversampling shift
_SHIFT_5B
ADC_OVERSAMPLING
6-bit oversampling shift
_SHIFT_6B
ADC_OVERSAMPLING
7-bit oversampling shift
_SHIFT_7B
ADC_OVERSAMPLING
8-bit oversampling shift
_SHIFT_8B
Input parameter{in}
ratio ADC oversampling ratio
ADC_OVERSAMPLING
oversampling ratio multiple 2
_RATIO_MUL2
ADC_OVERSAMPLING
oversampling ratio multiple 4
_RATIO_MUL4
ADC_OVERSAMPLING
oversampling ratio multiple 8
_RATIO_MUL8
ADC_OVERSAMPLING oversampling ratio multiple 16

67
GD32E50x Firmware Library User Guide
_RATIO_MUL16
ADC_OVERSAMPLING
oversampling ratio multiple 32
_RATIO_MUL32
ADC_OVERSAMPLING
oversampling ratio multiple 64
_RATIO_MUL64
ADC_OVERSAMPLING
oversampling ratio multiple 128
_RATIO_MUL128
ADC_OVERSAMPLING
oversampling ratio multiple 256
_RATIO_MUL256
Output parameter{out}
- -
Return value
- -

Example:

/* configure ADC1 oversample mode: 16 times sample, 4 bits shift */

adc_oversample_mode_config(ADC1, ADC_OVERSAMPLING_ALL_CONVERT,
ADC_OVERSAMPLING_SHIFT_4B, ADC_OVERSAMPLING_RATIO_MUL16);

adc_oversample_mode_enable

The description of adc_oversample_mode_enable is shown as below:

Table 3-40. Function adc_oversample_mode_enable


Function name adc_oversample_mode_enable
Function prototype void adc_oversample_mode_enable(uint32_t adc_periph);
Function descriptions enable ADC oversample mode
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable ADC0 oversample mode */

adc_oversample_mode_enable (ADC0);

68
GD32E50x Firmware Library User Guide
adc_oversample_mode_disable

The description of adc_oversample_mode_disable is shown as below:

Table 3-41. Function adc_oversample_mode_disable


Function name adc_oversample_mode_disable
Function prototype void adc_oversample_mode_disable(uint32_t adc_periph);
Function descriptions disable ADC oversample mode
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable ADC0 oversample mode */

adc_oversample_mode_disable (ADC0);

adc_flag_get

The description of adc_flag_get is shown as below:

Table 3-42. Function adc_flag_get


Function name adc_flag_get
Function prototype FlagStatus adc_flag_get(uint32_t adc_periph, uint32_t flag);
Function descriptions get the ADC flag
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
flag the adc flag bits
ADC_FLAG_WDE0 analog watchdog 0 event flag
ADC_FLAG_EOC end of group conversion flag
ADC_FLAG_EOIC end of inserted group conversion flag
ADC_FLAG_STIC start flag of inserted channel group
ADC_FLAG_STRC start flag of regular channel group
ADC_FLAG_WDE1 analog watchdog 1 event flag
ADC_FLAG_WDE2 analog watchdog 2 event flag

69
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the ADC0 analog watchdog 0 flag bits */

FlagStatus flag_value;

flag_value = adc_flag_get(ADC0, ADC_FLAG_WDE0);

adc_flag_clear

The description of adc_flag_clear is shown as below:

Table 3-43. Function adc_flag_clear


Function name adc_flag_clear
Function prototype void adc_flag_clear(uint32_t adc_periph, uint32_t flag);
Function descriptions clear the ADC flag bits
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
flag the adc flag bits
ADC_FLAG_WDE0 analog watchdog 0 event flag
ADC_FLAG_EOC end of group conversion flag
ADC_FLAG_EOIC end of inserted group conversion flag
ADC_FLAG_STIC start flag of inserted channel group
ADC_FLAG_STRC start flag of regular channel group
ADC_FLAG_WDE1 analog watchdog 1 event flag
ADC_FLAG_WDE2 analog watchdog 2 event flag
Output parameter{out}
- -
Return value
- -

Example:

/* clear the ADC0 analog watchdog 0 flag bits */

adc_flag_clear(ADC0, ADC_FLAG_WDE0);

70
GD32E50x Firmware Library User Guide
adc_interrupt_enable

The description of adc_interrupt_enable is shown as below:

Table 3-44. Function adc_interrupt _enable


Function name adc_interrupt_enable
Function prototype void adc_interrupt_enable(uint32_t adc_periph, uint32_t interrupt);
Function descriptions enable ADC interrupt
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
interrupt the adc interrupt
ADC_INT_WDE0 analog watchdog 0 interrupt
ADC_INT_EOC end of group conversion interrupt
ADC_INT_EOIC end of inserted group conversion interrupt
ADC_INT_WDE1 analog watchdog 1 interrupt
ADC_INT_WDE2 analog watchdog 2 interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* enable ADC0 analog watchdog 0 interrupt */

adc_interrupt_enable(ADC0, ADC_INT_WDE0);

adc_interrupt_disable

The description of adc_interrupt_disable is shown as below:

Table 3-45. Function adc_interrupt_disable


Function name adc_interrupt_disable
Function prototype void adc_interrupt_disable(uint32_t adc_periph , uint32_t interrupt);
Function descriptions disable ADC interrupt
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
interrupt the adc interrupt

71
GD32E50x Firmware Library User Guide
ADC_INT_WDE0 analog watchdog 0 interrupt
ADC_INT_EOC end of group conversion interrupt
ADC_INT_EOIC end of inserted group conversion interrupt
ADC_INT_WDE1 analog watchdog 1 interrupt
ADC_INT_WDE2 analog watchdog 2 interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* disable ADC0 analog watchdog 0 interrupt */

adc_interrupt_disable(ADC0, ADC_INT_WDE0);

adc_interrupt_flag_get

The description of adc_interrupt_flag_get is shown as below:

Table 3-46. Function adc_interrupt_flag_get


Function name adc_interrupt_flag_get
Function prototype FlagStatus adc_interrupt_flag_get(uint32_t adc_periph, uint32_t int_flag);
Function descriptions get the ADC interrupt bits
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
int_flag the adc interrupt bits
ADC_INT_FLAG_
analog watchdog 0 interrupt
WDE0
ADC_INT_FLAG_EOC end of group conversion interrupt
ADC_INT_FLAG_EOIC end of inserted group conversion interrupt
ADC_INT_FLAG_
analog watchdog 1 interrupt
WDE1
ADC_INT_FLAG_
analog watchdog 2 interrupt
WDE2
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

72
GD32E50x Firmware Library User Guide
/* get the ADC0 analog watchdog 0 interrupt bits*/

FlagStatus flag_value;

flag_value = adc_interrupt_flag_get(ADC0, ADC_INT_WDE0);

adc_interrupt_flag_clear

The description of adc_interrupt_flag_clear is shown as below:

Table 3-47. Function adc_interrupt_flag_clear


Function name adc_interrupt_flag_clear
Function prototype void adc_interrupt_flag_clear(uint32_t adc_periph, uint32_t int_flag);
Function descriptions clear the ADC interrupt bits
Precondition -
The called functions -
Input parameter{in}
adc_periph ADC peripheral
ADCx(x=0..2) ADC peripheral selection
Input parameter{in}
int_flag the adc interrupt bits
ADC_INT_FLAG_
analog watchdog 0 interrupt
WDE0
ADC_INT_FLAG_EOC end of group conversion interrupt
ADC_INT_FLAG_EOIC end of inserted group conversion interrupt
ADC_INT_FLAG_
analog watchdog 1 interrupt
WDE1
ADC_INT_FLAG_
analog watchdog 2 interrupt
WDE2
Output parameter{out}
- -
Return value
- -

Example:

/* clear the ADC0 analog watchdog 0 interrupt bits*/

adc_interrupt_flag_clear(ADC0, ADC_INT_WDE0);

3.3. BKP

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 do not
affect these registers. The BKP registers are listed in chapter 3.3.1, the BKP firmware
73
GD32E50x Firmware Library User Guide
functions are introduced in chapter 3.3.2.

3.3.1. Descriptions of Peripheral registers

BKP registers are listed in the table shown as below:

Table 3-48. BKP Registers


Registers Descriptions
BKP_DATAx (x=
Backup data register
0..41)
BKP_OCTL RTC signal output control register
BKP_TPCTL Tamper pin control register
BKP_TPCS Tamper control and status register

3.3.2. Descriptions of Peripheral functions

BKP firmware functions are listed in the table shown as below:

Table 3-49. BKP firmware function


Function name Function description
bkp_deinit reset data registers
bkp_write_data write BKP data register
bkp_read_data read BKP data register
bkp_rtc_calibration_output_enable enable RTC clock calibration output
bkp_rtc_calibration_output_disable disable RTC clock calibration output
bkp_rtc_signal_output_enable enable RTC alarm or second signal output
bkp_rtc_signal_output_disable disable RTC alarm or second signal output
select RTC output, the RTC output can be select as alarm
bkp_rtc_output_select
pulse or second pulse
bkp_rtc_clock_output_select select RTC clock output
bkp_rtc_clock_calibration_direction select RTC clock calibration direction
bkp_rtc_calibration_value_set set RTC clock calibration value
bkp_tamper_detection_enable enable tamper detection
bkp_tamper_detection_disable disable tamper detection
bkp_tamper_active_level_set set tamper pin active level
bkp_tamper_interrupt_enable enable tamper interrupt
bkp_tamper_interrupt_disable disable tamper interrupt
bkp_flag_get get bkp flag state
bkp_flag_clear clear bkp flag state
bkp_interrupt_flag_get get bkp interrupt flag state
bkp_interrupt_flag_clear clear bkp interrupt flag state

74
GD32E50x Firmware Library User Guide
Enum bkp_data_register_enum

Table 3-50. Enum bkp_data_register_enum


Member name Function description
BKP_DATA_0 bkp data register number 0
BKP_DATA_1 bkp data register number 1
BKP_DATA_2 bkp data register number 2
BKP_DATA_3 bkp data register number 3
BKP_DATA_4 bkp data register number 4
BKP_DATA_5 bkp data register number 5
BKP_DATA_6 bkp data register number 6
BKP_DATA_7 bkp data register number 7
BKP_DATA_8 bkp data register number 8
BKP_DATA_9 bkp data register number 9
BKP_DATA_10 bkp data register number 10
BKP_DATA_11 bkp data register number 11
BKP_DATA_12 bkp data register number 12
BKP_DATA_13 bkp data register number 13
BKP_DATA_14 bkp data register number 14
BKP_DATA_15 bkp data register number 15
BKP_DATA_16 bkp data register number 16
BKP_DATA_17 bkp data register number 17
BKP_DATA_18 bkp data register number 18
BKP_DATA_19 bkp data register number 19
BKP_DATA_20 bkp data register number 20
BKP_DATA_21 bkp data register number 21
BKP_DATA_22 bkp data register number 22
BKP_DATA_23 bkp data register number 23
BKP_DATA_24 bkp data register number 24
BKP_DATA_25 bkp data register number 25
BKP_DATA_26 bkp data register number 26
BKP_DATA_27 bkp data register number 27
BKP_DATA_28 bkp data register number 28
BKP_DATA_29 bkp data register number 29
BKP_DATA_30 bkp data register number 30
BKP_DATA_31 bkp data register number 31
BKP_DATA_32 bkp data register number 32
BKP_DATA_33 bkp data register number 33
BKP_DATA_34 bkp data register number 34
BKP_DATA_35 bkp data register number 35
BKP_DATA_36 bkp data register number 36
BKP_DATA_37 bkp data register number 37
BKP_DATA_38 bkp data register number 38
75
GD32E50x Firmware Library User Guide
Member name Function description
BKP_DATA_39 bkp data register number 39
BKP_DATA_40 bkp data register number 40
BKP_DATA_41 bkp data register number 41

bkp_deinit

The description of bkp_deinit is shown as below:

Table 3-51. Function bkp_deinit


Function name bkp_deinit
Function prototype void bkp_deinit(void);
Function descriptions reset data registers
Precondition -
The called functions rcu_bkp_reset_enable / rcu_bkp_reset_disable
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset BKP registers */

bkp_deinit ();

bkp_write_data

The description of bkp_write_data is shown as below:

Table 3-52. Function bkp_write_data


Function name bkp_write_data
void bkp_write_data(bkp_data_register_enum register_number, uint16_t
Function prototype
data);
Function descriptions write BKP data register
Precondition -
The called functions -
Input parameter{in}
register_number refer to Enum bkp_data_register_enum
BKP_DATA_x(x =
bkp data register number x
0..41)
Input parameter{in}
data the data to be write in BKP data register
0-0xffff data value

76
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* write BKP data register */

bkp _write_data (BKP_DATA_0, 0x1226);

bkp_read_data

The description of bkp_read_data is shown as below:

Table 3-53. Function bkp_data_read


Function name bkp_read_data
Function prototype uint16_t bkp_read_data(bkp_data_register_enum register_number);
Function descriptions read BKP data register
Precondition -
The called functions -
Input parameter{in}
register_number refer to bkp_data_register_enum
BKP_DATA_x(x =
bkp data register number x
0..41)
Output parameter{out}
- -
Return value
uint16_t 0-0xffff

Example:

/* read BKP data register */

uint16_t data;

data = bkp _read_data (BKP_DATA_0);

bkp_rtc_calibration_output_enable

The description of bkp_rtc_calibration_output_enable is shown as below:

Table 3-54. Function bkp_rtc_calibration_output_enable


Function name bkp_rtc_calibration_output_enable
Function prototype void bkp_rtc_calibration_output_enable(void);
Function descriptions enable RTC clock calibration output
Precondition -
The called functions -

77
GD32E50x Firmware Library User Guide
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable RTC clock calibration output */

bkp_rtc_calibration_output_enable();

bkp_rtc_calibration_output_disable

The description of bkp_rtc_calibration_output_disable is shown as below:

Table 3-55. Function bkp_rtc_calibration_output_disable


Function name bkp_rtc_calibration_output_disable
Function prototype void bkp_rtc_calibration_output_disable(void);
Function descriptions disable RTC clock calibration output
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable RTC clock calibration output */

bkp_rtc_calibration_output_disable();

bkp_rtc_signal_output_enable

The description of bkp_rtc_signal_output_enable is shown as below:

Table 3-56. Function bkp_rtc_signal_output_enable


Function name bkp_rtc_signal_output_enable
Function prototype void bkp_rtc_signal_output_enable (void);
Function descriptions enable RTC alarm or second signal output
Precondition -
The called functions -
Input parameter{in}
- -
78
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* enable RTC alarm or second signal output */

bkp_rtc_signal_output_enable();

bkp_rtc_signal_output_disable

The description of bkp_rtc_signal_output_disable is shown as below:

Table 3-57. Function bkp_rtc_signal_output_disable


Function name bkp_rtc_signal_output_disable
Function prototype void bkp_rtc_signal_output_disable (void);
Function descriptions disable RTC alarm or second signal output
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable RTC alarm or second signal output */

bkp_rtc_signal_output_disable();

bkp_rtc_output_select

The description of bkp_rtc_output_select is shown as below:

Table 3-58. Function bkp_rtc_output_select


Function name bkp_rtc_output_select
Function prototype void bkp_rtc_output_select (uint16_t outputsel);
select RTC output, the RTC output can be select as alarm pulse or second
Function descriptions
pulse
Precondition -
The called functions -
Input parameter{in}
outputsel RTC output selection
RTC_OUTPUT_ALAR RTC alarm pulse is selected as the RTC output
79
GD32E50x Firmware Library User Guide
M_PULSE
RTC_OUTPUT_SECO
RTC second pulse is selected as the RTC output
ND_PULSE
Output parameter{out}
- -
Return value
- -

Example:

/* select RTC output alarm signal output */

bkp_rtc_output_select (RTC_OUTPUT_ALARM_PULSE);

bkp_rtc_clock_output_select

The description of bkp_rtc_clock_output_select is shown as below:

Table 3-59. Function bkp_rtc_clock_output_select


Function name bkp_rtc_clock_output_select
Function prototype void bkp_rtc_clock_output_select(uint16_t clocksel);
select RTC clock output, the RTC clock output can be select as divided 64
Function descriptions
or no division
Precondition -
The called functions -
Input parameter{in}
clocksel RTC clock output selection
RTC_CLOCK_DIV_64 RTC clock divided 64 is selected as the RTC clock output
RTC_CLOCK_DIV_1 RTC clock is selected as the RTC clock output
Output parameter{out}
- -
Return value
- -

Example:

/* select RTC clock devided 64 to output */

bkp_rtc_clock_output_select (RTC_CLOCK_DIV_64);

bkp_rtc_clock_calibration_direction

The description of bkp_rtc_clock_calibration_direction is shown as below:

Table 3-60. Function bkp_rtc_clock_calibration_direction


Function name bkp_rtc_clock_calibration_direction
Function prototype void bkp_rtc_clock_calibration_direction(uint16_t direction);
Function descriptions select RTC clock calibration direction, the RTC clock calibration direction
80
GD32E50x Firmware Library User Guide
can be select as slowed down or speed up
Precondition -
The called functions -
Input parameter{in}
direction RTC clock calibration direction
RTC_CLOCK_SLOWE
RTC clock slowed down
D_DOWN
RTC_CLOCK_SPEED_
RTC clock speed up
UP
Output parameter{out}
- -
Return value
- -

Example:

/* set RTC clock slowed down */

bkp_rtc_clock_calibration_direction (RTC_CLOCK_SLOWED_DOWN);

bkp_rtc_calibration_value_set

The description of bkp_rtc_calibration_value_set is shown as below:

Table 3-61. Function bkp_rtc_calibration_value_set


Function name bkp_rtc_calibration_value_set
Function prototype void bkp_rtc_calibration_value_set(uint8_t value);
Function descriptions set RTC clock calibration value
Precondition -
The called functions -
Input parameter{in}
value RTC clock calibration value
0x00 - 0x7F value
Output parameter{out}
- -
Return value
- -

Example:

/* set RTC clock calibration value */

bkp_rtc_calibration_value_set (0x7f);

bkp_tamper_detection_enable

The description of bkp_tamper_detection_enable is shown as below:

81
GD32E50x Firmware Library User Guide
Table 3-62. Function bkp_tamper_detection_enable
Function name bkp_tamper_detection_enable
Function prototype void bkp_tamper_detection_enable (void);
Function descriptions enable tamper detection
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable tamper pin detection */

bkp_tamper_detection_enable();

bkp_tamper_detection_disable

The description of bkp_tamper_detection_disable is shown as below:

Table 3-63. Function bkp_tamper_detection_disable


Function name bkp_tamper_detection_disable
Function prototype void bkp_tamper_detection_disable (void);
Function descriptions disable tamper detection
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable tamper pin detection */

bkp_tamper_detection_disable();

bkp_tamper_active_level_set

The description of bkp_tamper_active_level_set is shown as below:

Table 3-64. Function bkp_tamper_active_level_set


Function name bkp_tamper_active_level_set
82
GD32E50x Firmware Library User Guide
Function prototype void bkp_tamper_active_level_set (uint16_t level);
Function descriptions set tamper pin active level
Precondition -
The called functions -
Input parameter{in}
level tamper pin active level
TAMPER_PIN_ACTIVE
the tamper pin is active high
_HIGH
TAMPER_PIN_ACTIVE
the tamper pin is active low
_LOW
Output parameter{out}
- -
Return value
- -

Example:

/* set tamper pin active level high */

bkp_tamper_active_level_set (TAMPER_PIN_ACTIVE_HIGH);

bkp_tamper_interrupt_enable

The description of bkp_tamper_interrupt_enable is shown as below:

Table 3-65. Function bkp_tamper_interrupt_enable


Function name bkp_tamper_interrupt_enable
Function prototype void bkp_tamper_interrupt_enable (void);
Function descriptions enable tamper interrupt
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable tamper pin interrupt */

bkp_tamper_interrupt_enable ();

bkp_tamper_interrupt_disable

The description of bkp_tamper_interrupt_disable is shown as below:

83
GD32E50x Firmware Library User Guide
Table 3-66. Function bkp_tamper_interrupt_disable
Function name bkp_tamper_interrupt_disable
Function prototype void bkp_tamper_interrupt_disable (void);
Function descriptions disable tamper interrupt
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable tamper pin interrupt */

bkp_tamper_interrupt_disable ();

bkp_flag_get

The description of bkp_flag_get is shown as below:

Table 3-67. Function bkp_flag_get


Function name bkp_flag_get
Function prototype FlagStatus bkp_flag_get(uint16_t flag);
Function descriptions get bkp flag state
Precondition -
The called functions -
Input parameter{in}
flag bkp flag state
BKP_FLAG_TAMPER tamper event flag
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get BKP flag state */

FlagStatus status;

status = bkp_flag_get (BKP_FLAG_TAMPER);

bkp_flag_clear

The description of bkp_flag_clear is shown as below:


84
GD32E50x Firmware Library User Guide
Table 3-68. Function bkp_flag_clear
Function name bkp_flag_clear
Function prototype void bkp_flag_clear(uint16_t flag);
Function descriptions clear bkp flag state
Precondition -
The called functions -
Input parameter{in}
flag bkp flag state
BKP_FLAG_TAMPER tamper event flag
Output parameter{out}
- -
Return value
- -

Example:

/* clear BKP flag state */

bkp_flag_clear (BKP_FLAG_TAMPER);

bkp_interrupt_flag_get

The description of bkp_interrupt_flag_get is shown as below:

Table 3-69. Function bkp_interrupt_flag_get


Function name bkp_interrupt_flag_get
Function prototype FlagStatus bkp_interrupt_flag_get(uint16_t flag);
Function descriptions get bkp interrupt flag state
Precondition -
The called functions -
Input parameter{in}
flag bkp interrupt flag state
BKP_INT_FLAG_TAMP
tamper interrupt flag
ER
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get BKP interrupt flag state */

bkp_interrupt_flag_get (BKP_INT_FLAG_TAMPER);

85
GD32E50x Firmware Library User Guide
bkp_interrupt_flag_clear

The description of bkp_interrupt_flag_clear is shown as below:

Table 3-70. Function bkp_interrupt_flag_clear


Function name bkp_interrupt_flag_clear
Function prototype void bkp_interrupt_flag_clear(uint16_t flag);
Function descriptions clear bkp interrupt flag state
Precondition -
The called functions -
Input parameter{in}
flag bkp interrupt flag state
BKP_INT_FLAG_TAMP
tamper interrupt flag
ER
Output parameter{out}
- -
Return value
- -

Example:

/* clear BKP interrupt flag state */

bkp_interrupt_flag_clear (BKP_INT_FLAG_TAMPER);

3.4. CRC

A cycle redundancy check (CRC) is an error-detecting code commonly used in digital


networks and storage devices to detect accidental changes to raw data. The CRC registers
are listed in chapter 3.4.1, the CRC firmware functions are introduced in chapter 3.4.2.

3.4.1. Descriptions of Peripheral registers

CRC registers are listed in the table shown as below:

Table 3-71. CRC Registers


Registers Descriptions
CRC_DATA CRC data register
CRC_FDATA CRC free data register
CRC_CTL CRC control register
CRC_IDATA CRC initialization data register
CRC_POLY CRC polynomial register

86
GD32E50x Firmware Library User Guide
3.4.2. Descriptions of Peripheral functions

CRC firmware functions are listed in the table shown as below:

Table 3-72. CRC firmware function


Function name Function description
crc_deinit deinitialize CRC calculation unit
crc_data_register_reset reset data register to the value of initializaiton data register
crc_reverse_output_data_enable enable the reverse operation of output data
crc_reverse_output_data_disable disable the reverse operation of output data
crc_input_data_reverse_config configure the CRC input data function
crc_data_register_read read the data register
crc_free_data_register_read read the free data register
crc_free_data_register_write write the free data register
crc_init_data_register_write write the initialization value register
crc_polynomial_size_set configure the CRC size of polynomial function
crc_polynomial_set configure the CRC polynomial value function
crc_single_data_calculate CRC calculate a 32-bit data
crc_block_data_calculate CRC calculate a 32-bit data array

crc_deinit

The description of crc_deinit is shown as below:

Table 3-73. Function crc_deinit


Function name crc_deinit
Function prototype void crc_deinit(void);
Function descriptions deinitialize CRC unit
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize CRC */

crc_deinit();

crc_data_register_reset

The description of crc_data_register_reset is shown as below:


87
GD32E50x Firmware Library User Guide
Table 3-74. Function crc_data_register_reset
Function name crc_data_register_reset
Function prototype void crc_data_register_reset(void);
Function descriptions reset data register to the value of initializaiton data register
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset crc data register */

crc_data_register_reset ();

crc_reverse_output_data_enable

The description of crc_reverse_output_data_enable is shown as below:

Table 3-75. Function crc_reverse_output_data_enable


Function name crc_reverse_output_data_enable
Function prototype void crc_reverse_output_data_enable (void);
Function descriptions enable the reverse operation of output data
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable CRC reverse operation of output data */

crc_reverse_output_data_enable ();

crc_reverse_output_data_disable

The description of crc_reverse_output_data_disable is shown as below:

Table 3-76. Function crc_reverse_output_data_disable


Function name crc_reverse_output_data_disable
88
GD32E50x Firmware Library User Guide
Function prototype void crc_reverse_output_data_disable (void);
Function descriptions disable the reverse operation of output data
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable crc reverse operation of output data */

crc_reverse_output_data_disable ();

crc_input_data_reverse_config

The description of crc_input_data_reverse_config is shown as below:

Table 3-77. Function crc_input_data_reverse_config


Function name crc_input_data_reverse_config
Function prototype void crc_input_data_reverse_config(uint32_t data_reverse)
Function descriptions configure the crc input data function
Precondition -
The called functions -
Input parameter{in}
data_reverse specify input data reverse function
CRC_INPUT_DATA_N
input data is not reversed
OT
CRC_INPUT_DATA_B
input data is reversed on 8 bits
YTE
CRC_INPUT_DATA_H
input data is reversed on 16 bits
ALFWORD
CRC_INPUT_DATA_W
input data is reversed on 32 bits
ORD
Output parameter{out}
- -
Return value
- -

Example:

/* configure the crc input data */

crc_input_data_reverse_config (CRC_INPUT_DATA_WORD);
89
GD32E50x Firmware Library User Guide
crc_data_register_read

The description of crc_data_register_read is shown as below:

Table 3-78. Function crc_data_register_read


Function name crc_data_register_read
Function prototype uint32_t crc_data_register_read(void);
Function descriptions read the data register
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t 32-bit value of the data register (0-0xFFFFFFFF)

Example:

/* read crc data register */

uint32_t crc_value = 0;

crc_value = crc_data_register_read();

crc_free_data_register_read

The description of crc_free_data_register_read is shown as below:

Table 3-79. Function crc_free_data_register_read


Function name crc_free_data_register_read
Function prototype uint8_t crc_free_data_register_read(void);
Function descriptions read the free data register
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint8_t 8-bit value of the free data register (0-0xFF)

Example:

/* read crc free data register */

uint8_t crc_value = 0;

crc_value = crc_free_data_register_read();
90
GD32E50x Firmware Library User Guide
crc_free_data_register_write

The description of crc_free_data_register_write is shown as below:

Table 3-80. Function crc_free_data_register_write


Function name crc_free_data_register_write
Function prototype void crc_free_data_register_write(uint8_t free_data);
Function descriptions write the free data register
Precondition -
The called functions -
Input parameter{in}
free_data specify 8-bit data
Output parameter{out}
- -
Return value
- -

Example:

/* write the free data register */

crc_free_data_register_write(0x11);

crc_init_data_register_write

The description of crc_init_data_register_write is shown as below:

Table 3-81. Function crc_init_data_register_write


Function name crc_init_data_register_write
Function prototype void crc_init_data_register_write(uint32_t init_data)
Function descriptions write the initializaiton data register
Precondition -
The called functions -
Input parameter{in}
init_data specify 32-bit data
Output parameter{out}
- -
Return value
- -

Example:

/* write crc initializaiton data register */

crc_init_data_register_write (0x11223344);

91
GD32E50x Firmware Library User Guide
crc_polynomial_size_set

The description of crc_polynomial_size_set is shown as below:

Table 3-82. Function crc_polynomial_size_set


Function name crc_polynomial_size_set
Function prototype void crc_polynomial_size_set(uint32_t poly_size)
Function descriptions configure the CRC size of polynomial function
Precondition -
The called functions -
Input parameter{in}
poly_size size of polynomial
CRC_CTL_PS_32 32-bit polynomial for CRC calculation
CRC_CTL_PS_16 16-bit polynomial for CRC calculation
CRC_CTL_PS_8 8-bit polynomial for CRC calculation
CRC_CTL_PS_7 7-bit polynomial for CRC calculation
Output parameter{out}
- -
Return value
- -

Example:

/* configure the CRC polynomial size*/

crc_polynomial_size_set (CRC_CTL_PS_7);

crc_polynomial_set

The description of crc_polynomial_set is shown as below:

Table 3-83. Function crc_polynomial_set


Function name crc_polynomial_set
Function prototype void crc_polynomial_set(uint32_t poly)
Function descriptions configure the CRC polynomial value function
Precondition -
The called functions -
Input parameter{in}
poly configurable polynomial value
Output parameter{out}
- -
Return value
- -

Example:

/* configure the CRC polynomial value */


92
GD32E50x Firmware Library User Guide
crc_polynomial_set (0x11223344);

crc_single_data_calculate

The description of crc_single_data_calculate is shown as below:

Table 3-84. Function crc_single_data_calculate


Function name crc_single_data_calculate
Function prototype uint32_t crc_single_data_calculate(uint32_t sdata);
Function descriptions CRC calculate a 32-bit data
Precondition -
The called functions -
Input parameter{in}
sdata specify 32-bit data
Output parameter{out}
- -
Return value
uint32_t 32-bit CRC calculate value (0-0xFFFFFFFF)

Example:

/* CRC calculate a 32-bit data */

uint32_t val = 0, valcrc = 0;

val = (uint32_t)0xabcd1234;

rcu_periph_clock_enable(RCU_CRC);

valcrc = crc_single_data_calculate(val);

crc_block_data_calculate

The description of crc_block_data_calculate is shown as below:

Table 3-85. Function crc_block_data_calculate


Function name crc_block_data_calculate
Function prototype uint32_t crc_block_data_calculate(uint32_t array[], uint32_t size);
Function descriptions calculate the CRC value of an array of 32-bit values
Precondition -
The called functions -
Input parameter{in}
array pointer to an array of 32 bit data words
Input parameter{in}
size size of the array
Output parameter{out}
- -
Return value
93
GD32E50x Firmware Library User Guide
uint32_t 32-bit CRC calculate value (0-0xFFFFFFFF)

Example:

/* CRC calculate a 32-bit data array */

#define BUFFER_SIZE 6

uint32_t valcrc = 0;

static const uint32_t data_buffer[BUFFER_SIZE] = {

0x00001111, 0x00002222, 0x00003333, 0x00004444, 0x00005555, 0x00006666};

valcrc = crc_block_data_calculate((uint32_t *) data_buffer, BUFFER_SIZE);

3.5. CTC

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.The CTC registers are listed in chapter 3.5.1, the CTC firmware
functions are introduced in chapter 3.5.2.

3.5.1. Descriptions of Peripheral registers

CTC registers are listed in the table shown as below:

Table 3-86. CTC Registers


Registers Descriptions
CTC_CTL0 CTC control register 0
CTC_CTL1 CTC control register 1
CTC_STAT CTC status register
CTC_INTC CTC Interrupt clear register

3.5.2. Descriptions of Peripheral functions

CTC registers are listed in the table shown as below:

Table 3-87. CTC firmware function


Function name Function description
ctc_deinit reset CTC clock trim controller
ctc_counter_enable enable CTC trim counter
ctc_counter_disable disable CTC trim counter
ctc_irc48m_trim_value_config configure the IRC48M trim value
ctc_software_refsource_pulse_genera
generate software reference source sync pulse
te

94
GD32E50x Firmware Library User Guide
Function name Function description
ctc_hardware_trim_mode_config configure hardware automatically trim mode
ctc_refsource_polarity_config configure reference signal source polarity
ctc_refsource_signal_select select reference signal source
ctc_refsource_prescaler_config configure reference signal source prescaler
ctc_clock_limit_value_config configure clock trim base limit value
ctc_counter_reload_value_config configure CTC counter reload value
read CTC counter capture value when reference sync pulse
ctc_counter_capture_value_read
occurred
read CTC trim counter direction when reference sync pulse
ctc_counter_direction_read
occurred
ctc_counter_reload_value_read read CTC counter reload value
ctc_irc48m_trim_value_read read the IRC48M trim value
ctc_flag_get get CTC flag
ctc_flag_clear clear CTC flag
ctc_interrupt_enable enable the CTC interrupt
ctc_interrupt_disable disable the CTC interrupt
ctc_interrupt_flag_get get CTC interrupt flag
ctc_interrupt_flag_clear clear CTC interrupt flag

ctc_deinit

The description of ctc_deinit is shown as below:

Table 3-88. Function ctc_deinit


Function name ctc_deinit
Function prototype void ctc_deinit (void)
Function descriptions Reset CTC peripheral
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset CTC */

ctc_deinit();

95
GD32E50x Firmware Library User Guide
ctc_counter_enable

The description of ctc_counter_enable is shown as below:

Table 3-89. Function ctc_counter_enable


Function name ctc_counter_enable
Function prototype void ctc_counter_enable (void);
Function descriptions enable CTC counter
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable CTC trim counter*/

ctc_counter_enable ();

ctc_counter_disable

The description of ctc_counter_disable is shown as below:

Table 3-90. Function ctc_counter_disable


Function name ctc_counter_disable
Function prototype void ctc_counter_disable (void);
Function descriptions disable CTC counter
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable CTC trim counter */

ctc_counter_disable ();

96
GD32E50x Firmware Library User Guide
ctc_irc48m_trim_value_config

The description of ctc_irc48m_trim_value_config is shown as below:

Table 3-91. Function ctc_irc48m_trim_value_config


Function name ctc_irc48m_trim_value_config
Function prototype void ctc_irc48m_trim_value_config(uint8_t trim_value);
Function descriptions configure the IRC48M trim value
Precondition -
The called functions -
Input parameter{in}
trim_value 0~63
Output parameter{out}
- -
Return value
- -

Example:

/* IRC48M trim value configuration */

ctc_irc48m_trim_value_config (0x01);

ctc_software_refsource_pulse_generate

The description of ctc_software_refsource_pulse_generate is shown as below:

Table 3-92. Function ctc_software_refsource_pulse_generate


Function name ctc_software_refsource_pulse_generate
Function prototype void ctc_software_refsource_pulse_generate (void);
Function descriptions generate software reference source sync pulse
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* generate reference source sync pulse */

ctc_software_refsource_pulse_generate ();

97
GD32E50x Firmware Library User Guide
ctc_hardware_trim_mode_config

The description of ctc_hardware_trim_mode_config is shown as below:

Table 3-93. Function ctc_hardware_trim_mode_config


Function name ctc_hardware_trim_mode_config
Function prototype void ctc_hardware_trim_mode_config(uint32_t hardmode);
Function descriptions configure hardware automatically trim mode
Precondition -
The called functions -
Input parameter{in}
hardmode hardware automatically trim mode enable or disable
CTC_HARDWARE_TRI
hardware automatically trim mode enable
M_MODE_ENABLE
CTC_HARDWARE_TRI
hardware automatically trim mode disable
M_MODE_DISABLE
Output parameter{out}
- -
Return value
- -

Example:

/* enable CTC hardware trim */

ctc_hardware_trim_mode_config (CTC_HARDWARE_TRIM_MODE_ENABLE);

ctc_refsource_polarity_config

The description of ctc_refsource_polarity_config is shown as below:

Table 3-94. Function ctc_refsource_polarity_config


Function name ctc_refsource_polarity_config
Function prototype void ctc_refsource_polarity_config(uint32_t polarity);
Function descriptions configure reference signal source polarity
Precondition -
The called functions -
Input parameter{in}
polarity reference signal source polarity
CTC_REFSOURCE_P
reference signal source polarity is falling edge
OLARITY_FALLING
CTC_REFSOURCE_P
reference signal source polarity is rising edge
OLARITY_RISING
Output parameter{out}
- -
Return value

98
GD32E50x Firmware Library User Guide
- -

Example:

/* set reference source polarity */

ctc_refsource_polarity_config (CTC_REFSOURCE_POLARITY_RISING);

ctc_refsource_signal_select

The description of ctc_refsource_signal_select is shown as below:

Table 3-95. Function ctc_refsource_signal_select


Function name ctc_refsource_signal_select
Function prototype void ctc_refsource_signal_select(uint32_t refs);
Function descriptions select reference signal source
Precondition -
The called functions -
Input parameter{in}
refs reference signal source
CTC_REFSOURCE_G
GPIO is selected
PIO
CTC_REFSOURCE_LX
LXTAL is selected
TAL
CTC_REFSOURCE_U
USBHS_SOF or USBD_SOF is selected
SBSOF
Output parameter{out}
- -
Return value
- -

Example:

/* reference signal selection */

ctc_refsource_signal_select (CTC_REFSOURCE_LXTAL);

ctc_refsource_prescaler_config

The description of ctc_refsource_prescaler_config is shown as below:

Table 3-96. Function ctc_refsource_prescaler_config


Function name ctc_refsource_prescaler_config
Function prototype void ctc_refsource_prescaler_config(uint32_t prescaler);
Function descriptions configure reference signal source prescaler
Precondition -
The called functions -
Input parameter{in}
99
GD32E50x Firmware Library User Guide
prescaler Prescaler factor
CTC_REFSOURCE_P
reference signal not divided
SC_OFF
CTC_REFSOURCE_P
reference signal divided by 2
SC_DIV2
CTC_REFSOURCE_P
reference signal divided by 4
SC_DIV4
CTC_REFSOURCE_P
reference signal divided by 8
SC_DIV8
CTC_REFSOURCE_P
reference signal divided by 16
SC_DIV16
CTC_REFSOURCE_P
reference signal divided by 32
SC_DIV32
CTC_REFSOURCE_P
reference signal divided by 64
SC_DIV64
CTC_REFSOURCE_P
reference signal divided by 128
SC_DIV128
Output parameter{out}
- -
Return value
- -

Example:

/* configure reference signal source prescaler */

ctc_refsource_prescaler_config(CTC_REFSOURCE_PSC_DIV2);

ctc_clock_limit_value_config

The description of ctc_clock_limit_value_config is shown as below:

Table 3-97. Function ctc_clock_limit_value_config


Function name ctc_clock_limit_value_config
Function prototype void ctc_clock_limit_value_config(uint8_t limit_value);
Function descriptions configure clock trim base limit value
Precondition -
The called functions -
Input parameter{in}
limit_value 0x00 - 0xFF
Output parameter{out}
- -
Return value
- -

Example:
100
GD32E50x Firmware Library User Guide
/* configure clock trim base limit value */

ctc_clock_limit_value_config (0x1F);

ctc_counter_reload_value_config

The description of ctc_counter_reload_value_config is shown as below:

Table 3-98. Function ctc_counter_reload_value_config


Function name ctc_counter_reload_value_config
Function prototype void ctc_counter_reload_value_config(uint16_t reload_value);
Function descriptions configure CTC counter reload value
Precondition -
The called functions -
Input parameter{in}
reload_value 0x0000 - 0xFFFF
Output parameter{out}
- -
Return value
- -

Example:

/* configure CTC counter reload value */

ctc_counter_reload_value_config (0x00FF);

ctc_counter_capture_value_read

The description of ctc_counter_capture_value_read is shown as below:

Table 3-99. Function ctc_counter_capture_value_read


Function name ctc_counter_capture_value_read
Function prototype uint16_t ctc_counter_capture_value_read(void);
Function descriptions read CTC counter capture value
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint16_t the 16-bit CTC counter capture value (0x0000 - 0xFFFF)

Example:

/* read CTC counter capture value */

101
GD32E50x Firmware Library User Guide
uint16_t ctc_value = 0;

ctc_value = ctc_counter_capture_value_read ();

ctc_counter_direction_read

The description of ctc_counter_direction_read is shown as below:

Table 3-100. Function ctc_counter_direction_read


Function name ctc_counter_direction_read
Function prototype FlagStatus ctc_counter_direction_read(void);
Function descriptions read CTC trim counter direction
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
FlagStatus SET / RESET

Example:

/* read ctc counter direction */

FlagStatus ctc_direction = SET;

ctc_direction = ctc_counter_direction_read ();

ctc_counter_reload_value_read

The description of ctc_counter_reload_value_read is shown as below:

Table 3-101. Function ctc_counter_reload_value_read


Function name ctc_counter_reload_value_read
Function prototype uint16_t ctc_counter_reload_value_read(void);
Function descriptions read CTC counter reload value
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint16_t Read 16-bit data of counter reload value (0x0000 - 0xFFFF)

Example:

102
GD32E50x Firmware Library User Guide
/* read CTC counter reload value */

uint16_t ctc_reload_value = 0;

ctc_reload_value = ctc_counter_reload_value_read ();

ctc_irc48m_trim_value_read

The description of ctc_irc48m_trim_value_read is shown as below:

Table 3-102. Function ctc_irc48m_trim_value_read


Function name ctc_irc48m_trim_value_read
Function prototype uint8_t ctc_irc48m_trim_value_read(void);
Function descriptions read the IRC48M trim value
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint8_t the 8-bit IRC48M trim value (0-63)

Example:

/* read the IRC48M trim value */

uint8_t ctc_trim_value = 0;

ctc_trim_value = ctc_irc48m_trim_value_read ();

ctc_flag_get

The description of ctc_flag_get is shown as below:

Table 3-103. Function ctc_flag_get


Function name ctc_flag_get
Function prototype FlagStatus ctc_flag_get(uint32_t flag);
Function descriptions get CTC status flag
Precondition -
The called functions -
Input parameter{in}
flag CTC status flag
CTC_FLAG_CKOK clock trim OK interrupt flag
CTC_FLAG_CKWARN clock trim warning interrupt flag
CTC_FLAG_ERR error interrupt flag
CTC_FLAG_EREF expect reference interrupt flag
CTC_FLAG_CKERR clock trim error bit
103
GD32E50x Firmware Library User Guide
CTC_FLAG_REFMISS reference sync pulse miss flag
CTC_FLAG_TRIMERR trim value error flag
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get CTC flag status */

FlagStatus state = ctc_flag_get (CTC_FLAG_CKOK);

ctc_flag_clear

The description of ctc_flag_clear is shown as below:

Table 3-104. Function ctc_flag_clear


Function name ctc_flag_clear
Function prototype void ctc_flag_clear (uint32_t flag);
Function descriptions clear CTC status flag
Precondition -
The called functions -
Input parameter{in}
flag CTC status flag
CTC_FLAG_CKOK clock trim OK interrupt flag
CTC_FLAG_CKWARN clock trim warning interrupt flag
CTC_FLAG_ERR error interrupt flag
CTC_FLAG_EREF expect reference interrupt flag
CTC_FLAG_CKERR clock trim error bit
CTC_FLAG_REFMISS reference sync pulse miss flag
CTC_FLAG_TRIMERR trim value error flag
Output parameter{out}
- -
Return value
- -

Example:

/* clear CTC flag status */

ctc_flag_clear (CTC_FLAG_CKOK);

ctc_interrupt_enable

The description of ctc_interrupt_enable is shown as below:

104
GD32E50x Firmware Library User Guide
Table 3-105. Functionctc_interrupt_enable
Function name ctc_interrupt_enable
Function prototype void ctc_interrupt_enable(uint32_t interrupt);
Function descriptions enable the CTC interrupt
Precondition -
The called functions -
Input parameter{in}
interrupt CTC interrupt
CTC_INT_CKOK clock trim OK interrupt
CTC_INT_CKWARN clock trim warning interrupt
CTC_INT_ERR error interrupt
CTC_INT_EREF expect reference interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* enable CTC clock trim OK interrupt */

ctc_interrupt_enable (CTC_INT_CKOK);

ctc_interrupt_disable

The description of ctc_interrupt_disable is shown as below:

Table 3-106. Functionctc_interrupt_disable


Function name ctc_interrupt_disable
Function prototype void ctc_interrupt_disable(uint32_t interrupt);
Function descriptions disable the CTC interrupt
Precondition -
The called functions -
Input parameter{in}
interrupt CTC interrupt
CTC_INT_CKOK clock trim OK interrupt
CTC_INT_CKWARN clock trim warning interrupt
CTC_INT_ERR error interrupt
CTC_INT_EREF expect reference interrupt
Output parameter{out}
- -
Return value
- -

Example:

105
GD32E50x Firmware Library User Guide
/* disable CTC clock trim OK interrupt */

ctc_interrupt_disable (CTC_INT_CKOK);

ctc_interrupt_flag_get

The description of ctc_interrupt_flag_get is shown as below:

Table 3-107. Function ctc_interrupt_flag_get


Function name ctc_interrupt_flag_get
Function prototype FlagStatus ctc_interrupt_flag_get(uint32_t int_flag);
Function descriptions get CTC interrupt flag
Precondition -
The called functions -
Input parameter{in}
int_flag CTC interrupt flag
CTC_INT_FLAG_CKO
clock trim OK interrupt
K
CTC_INT_FLAG_CKW
clock trim warning interrupt
ARN
CTC_INT_FLAG_ERR error interrupt
CTC_INT_FLAG_EREF expect reference interrupt
CTC_INT_FLAG_CKE
clock trim error bit interrupt
RR
CTC_INT_FLAG_REF
reference sync pulse miss interrupt
MISS
CTC_INT_FLAG_TRIM
trim value error interrupt
ERR
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get CTC interrupt flag status */

FlagStatus state = ctc_interrupt_flag_get (CTC_INT_FLAG_CKOK);

ctc_interrupt_flag_clear

The description of ctc_interrupt_flag_clear is shown as below:

Table 3-108. Function ctc_interrupt_flag_clear


Function name ctc_interrupt_flag_clear
Function prototype void ctc_interrupt_flag_clear(uint32_t int_flag);
Function descriptions clear CTC interrupt flag

106
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
int_flag CTC interrupt flag
CTC_INT_FLAG_CKO
clock trim OK interrupt
K
CTC_INT_FLAG_CKW
clock trim warning interrupt
ARN
CTC_INT_FLAG_ERR error interrupt
CTC_INT_FLAG_EREF expect reference interrupt
CTC_INT_FLAG_CKE
clock trim error bit interrupt
RR
CTC_INT_FLAG_REF
reference sync pulse miss interrupt
MISS
CTC_INT_FLAG_TRIM
trim value error interrupt
ERR
Output parameter{out}
- -
Return value
- -

Example:

/* clear CTC interrupt flag status */

ctc_interrupt_flag_clear (CTC_INT_FLAG_CKOK);

3.6. CMP

The general purpose comparatorscan work either standalone (all terminal are available on
I/Os) or together with the timers. It blanking function can be used for false overcurrent
detection in motor control applications.The CMP registers are listed in chapter 3.6.1, the CMP
firmware functions are introduced in chapter 3.6.2.

3.6.1. Descriptions of Peripheral registers

CMP registers are listed in the table shown as below:

Table 3-109. CMP Registers


Registers Descriptions
CMP1_CS CMP1 Control/status register
CMP3_CS CMP3 Control/status register
CMP5_CS CMP5 Control/status register

107
GD32E50x Firmware Library User Guide
3.6.2. Descriptions of Peripheral functions

CMP registers are listed in the table shown as below:

Table 3-110. CMP firmware function


Function name Function description
cmp_deinit Deinit CMP unit
cmp_input_init CMP input init
cmp_output_init CMP output init
cmp_outputblank_init CMP output blank init
cmp_enable enable CMP
cmp_disable disable CMP
cmp_lock_enable lock the CMP
cmp_output_level_get get output level

Enum cmp_enum

Table 3-111. Enum cmp_enum


Member name Function description
CMP1 Cmoparator 1
CMP3 Cmoparator 3
CMP5 Cmoparator 5

Enum inverting_input_enum

Table 3-112. Enum inverting_input_enum


Member name Function description
CMP_1_4VREFINT VREFINT /4 input
CMP_1_2VREFINT VREFINT /2 input
CMP_3_4VREFINT VREFINT *3/4 input
CMP_VREFINT VREFINT input
CMP_PA4 PA4 (DAC0) input
CMP_PA5 PA5 input
CMP_PA2 PA2 input
CMP_PB_2_15 PB2 or PB15 input

Enum cmp_output_enum

Table 3-113. Enum cmp_output_enum


Member name Function description
CMP_OUTPUT_NONE output no selection
CMP_OUTPUT_TIMER0_BKIN TIMER 0 break input
CMP_OUTPUT_TIMER2IC2_TIM
TIMER 2 channel2 or TIMER 1 channel1 input
ER1IC1

108
GD32E50x Firmware Library User Guide
Member name Function description
CMP_OUTPUT_TIMER0IC0 TIMER 0 channel0 input
CMP_OUTPUT_TIMER1IC3 TIMER 1 channel3 input
CMP_OUTPUT_TIMER2IC0 TIMER 2 channel0 input

Enum cmp_outputblank_enum

Table 3-114. Enum cmp_outputblank_enum


Member name Function description
CMP_OUTPUTBLANK_NONE output no blanking
CMP_OUTPUTBLANK_TIMER2_I
select TIMER2_CH3 as blanking source
C3
CMP_OUTPUTBLANK_TIMER1IC
select TIMER1_CH2 as blanking source
2
CMP_OUTPUTBLANK_TIMER2IC select TIMER2_CH2 or TIMER1_CH3 as blanking source
2_TIMER1IC3

cmp_deinit

The description of cmp_deinit is shown as below:

Table 3-115. Function cmp_deinit


Function name cmp_deinit
Function prototype void cmp_deinit (void);
Function descriptions deinitialize comparator
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize comparator */

cmp_deinit();

cmp_input_init

The description of cmp_input_init is shown as below:

Table 3-116. Function cmp_input_init


Function name cmp_input_init
Function prototype void cmp_input_init(cmp_enum cmp_periph,inverting_input_enum
109
GD32E50x Firmware Library User Guide
inverting_input);
Function descriptions initialize comparator input
Precondition -
The called functions -
Input parameter{in}
cmp_periph CMP peripherals, refer to Enum cmp_enum
CMPx Peripheral CMPx, (x=1,3,5)
Input parameter{in}
inverting_input CMP inverting input select, refer to Enum inverting_input_enum
CMP_1_4VREFINT VREFINT *1/4 input
CMP_1_2VREFINT VREFINT *1/2 input
CMP_3_4VREFINT VREFINT *3/4 input
CMP_VREFINT VREFINT input
CMP_PA4 PA4 input
CMP_PA5 PA5 input
CMP_PA2 PA2 input(only CMP1)
CMP_PB_2_15 PB2 input(only CMP1),PB15 input(only CMP3)
Output parameter{out}
- -
Return value
- -

Example:

/* initialize comparator 1 input */

cmp_input_init (CMP1, CMP_1_4VREFINT);

cmp_output_init

The description of cmp_output_init is shown as below:

Table 3-117. Function cmp_input_init


Function name cmp_output_init
cmp_output_init(cmp_enum cmp_periph,cmp_output_enum output_slection,
Function prototype
uint32_t output_polarity);
Function descriptions initialize comparator output
Precondition -
The called functions -
Input parameter{in}
cmp_periph CMP peripherals, refer to Enum cmp_enum
CMPx Peripheral CMPx, (x=1,3,5)
Input parameter{in}
output_slection CMP output select, refer to Enum cmp_output_enum
CMP_OUTPUT_NONE output no selection

110
GD32E50x Firmware Library User Guide
CMP_OUTPUT_TIMER
TIMER0 break input
0_BKIN
CMP_OUTPUT_TIMER TIMER2 channel2 input capture(CMP3),TIMER1 channel1 input
2IC2_TIMER1IC1 capture(CMP5)
CMP_OUTPUT_TIMER
TIMER0 channel0 input capture(CMP1)
0IC0
CMP_OUTPUT_TIMER
TIMER1 channel3 input capture(CMP1)
1IC3
CMP_OUTPUT_TIMER
TIMER2 channel0 input capture(CMP1)
2IC0
Input parameter{in}
output_polarity CMP output polarity select
CMP_OUTPUT_POLA
output is inverted
RITY_INVERTED
CMP_OUTPUT_POLA
output is not inverted
RITY_NOINVERTED
Output parameter{out}
- -
Return value
- -

Example:

/* initialize comparator 1 output */

cmp_output_init (CMP1,CMP_OUTPUT_NONE,
CMP_OUTPUT_POLARITY_NOINVERTED);

cmp_outputblank_init

The description of cmp_outputblank_init is shown as below:

Table 3-118. Function cmp_outputblank_init


Function name cmp_outputblank_init
void cmp_outputblank_init(cmp_enum cmp_periph,cmp_outputblank_enum
Function prototype
output_blank);
Function descriptions initialize CMP output blanking
Precondition -
The called functions -
Input parameter{in}
cmp_periph CMP peripherals, refer to Enum cmp_enum
CMPx Peripheral CMPx, (x=1,3,5)
Input parameter{in}
output_blank CMP output blank select, refer to Enum cmp_outputblank_enum
CMP_OUTPUTBLANK no blanking

111
GD32E50x Firmware Library User Guide
_NONE
CMP_OUTPUTBLANK
select TIMER2_CH3 as blanking source(CMP3)
_TIMER2_IC3
CMP_OUTPUTBLANK
select TIMER1_CH2 as blanking source(CMP1)
_TIMER1IC2
CMP_OUTPUTBLANK
Select TIMER2_CH2 as blanking source(CMP1), select TIMER1_CH3 as
_TIMER2IC2_TIMER1I
blanking source(CMP5)
C3
Output parameter{out}
- -
Return value
- -

Example:

/* initialize CMP1 output blanking */

cmp_outputblank_init (CMP1, CMP_OUTPUTBLANK_TIMER1IC2);

cmp_enable

The description of cmp_enable is shown as below:

Table 3-119. Function cmp_enable


Function name cmp_enable
Function prototype void cmp_enable(cmp_enum cmp_periph);
Function descriptions enable comparator
Precondition -
The called functions -
Input parameter{in}
cmp_periph CMP peripherals, refer to Enum cmp_enum
CMPx Peripheral CMPx, (x=1,3,5)
Output parameter{out}
- -
Return value
- -

Example:

/* enable comparator1 */

cmp_enable (CMP1);

cmp_disable

The description of cmp_disable is shown as below:

112
GD32E50x Firmware Library User Guide
Table 3-120. Function cmp_disable
Function name cmp_disable
Function prototype void cmp_disable(cmp_enum cmp_periph);
Function descriptions disable comparator
Precondition -
The called functions -
Input parameter{in}
cmp_periph CMP peripherals, refer to Enum cmp_enum
CMPx Peripheral CMPx, (x=1,3,5)
Output parameter{out}
- -
Return value
- -

Example:

/* disable comparator1 */

cmp_disable (CMP1);

cmp_lock_enable

The description of cmp_lock_enable is shown as below:

Table 3-121. Function cmp_lock_enable


Function name cmp_lock_enable
Function prototype void cmp_lock_enable(cmp_enum cmp_periph);
Function descriptions lock the comparator
Precondition -
The called functions -
Input parameter{in}
cmp_periph CMP peripherals, refer to Enum cmp_enum
CMPx Peripheral CMPx, (x=1,3,5)
Output parameter{out}
- -
Return value
- -

Example:

/* lock the comparator1 */

cmp_lock_enable (CMP1);

cmp_output_level_get

The description of cmp_output_level_get is shown as below:

113
GD32E50x Firmware Library User Guide
Table 3-122. Function cmp_output_level_get
Function name cmp_output_level_get
Function prototype uint32_t cmp_output_level_get(cmp_enum cmp_periph);
Function descriptions get output level
Precondition -
The called functions -
Input parameter{in}
cmp_periph CMP peripherals, refer to Enum cmp_enum
CMPx Peripheral CMPx, (x=1,3,5)
Output parameter{out}
- -
Return value
uint32_t CMP_OUTPUTLEVEL_HIGH or CMP_OUTPUTLEVEL_LOW

Example:

/* get CMP1 output level*/

cmp_output_level_get(CMP1);

3.7. DAC

The Digital-to-analog converter converts 12-bit digital data to a voltage on the external pins.
The DAC registers are listed in chapter 3.7.1, the DAC firmware functions are introduced in
chapter 3.7.2.

3.7.1. Descriptions of Peripheral registers

DAC registers are listed in the table shown as below:

Table 3-123. DAC Registers


Registers Descriptions
DAC_CTL0 DAC control register 0
DAC_SWT DAC software trigger register
OUT0_R12DH DAC_OUT0 12-bit right-aligned data holding register
OUT0_L12DH DAC_OUT0 12-bit left-aligned data holding register
OUT0_R8DH DAC_OUT0 8-bit right-aligned data holding register
OUT1_R12DH DAC_OUT1 12-bit right-aligned data holding register
OUT1_L12DH DAC_OUT1 12-bit left-aligned data holding register
OUT1_R8DH DAC_OUT1 8-bit right-aligned data holding register
DACC_R12DH DAC concurrent mode 12-bit right-aligned data holding register
DACC_L12DH DAC concurrent mode 12-bit left-aligned data holding register
DACC_R8DH DAC concurrent mode 8-bit right-aligned data holding register
OUT0_DO DAC_OUT0 data output register

114
GD32E50x Firmware Library User Guide
Registers Descriptions
OUT1_DO DAC_OUT1 data output register
DAC_STAT0 DAC status register 0
DAC_CTL1 DAC control register 1
DAC_STAT1 DAC status register 1

3.7.2. Descriptions of Peripheral functions

DAC registers are listed in the table shown as below:

Table 3-124. DAC firmware function


Function name Function description
dac_deinit deinitialize DAC
dac_enable enable DAC
dac_disable disable DAC
dac_dma_enable enable DAC DMA
dac_dma_disable disable DAC DMA
dac_output_buffer_enable enable DAC output buffer
dac_output_buffer_disable disable DAC output buffer
dac_output_value_get get DAC output value
dac_data_set set DAC data holding register value
dac_output_fifo_enable enable DAC output FIFO
dac_output_fifo_disable disable DAC output FIFO
dac_output_fifo_number_get get DAC output FIFO number
dac_trigger_enable enable DAC trigger
dac_trigger_disable disable DAC trigger
dac_trigger_source_config configure DAC trigger source
dac_software_trigger_enable enable DAC software trigger
dac_software_trigger_disable disable DAC software trigger
dac_wave_mode_config configure DAC wave mode
dac_wave_bit_width_config configure DAC wave bit width
dac_lfsr_noise_config configure DAC LFSR noise mode
dac_triangle_noise_config configure DAC triangle noise mode
dac_concurrent_enable enable DAC concurrent mode
dac_concurrent_disable disable DAC concurrent mode
dac_concurrent_software_trigger
enable DAC concurrent software trigger
_enable
dac_concurrent_software_trigger
disable DAC concurrent software trigger
_disable
dac_concurrent_output_buffer_enable enable DAC concurrent buffer function
dac_concurrent_output_buffer
disable DAC concurrent buffer function
_disable
dac_concurrent_data_set set DAC concurrent mode data holding register value

115
GD32E50x Firmware Library User Guide
Function name Function description
dac_flag_get get the DAC flag
dac_flag_clear clear the DAC flag
dac_interrupt_enable enable DAC interrupt
dac_interrupt_disable disable DAC interrupt
dac_interrupt_flag_get get DAC interrupt flag
dac_interrupt_flag_clear clear DAC interrupt flag

dac_deinit

The description of dac_deinit is shown as below:

Table 3-125. Function dac_deinit


Function name dac_deinit
Function prototype void dac_deinit(void);
Function descriptions deinitialize DAC
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize DAC */

dac_deinit();

dac_enable

The description of dac_enable is shown as below:

Table 3-126. Function dac_enable


Function name dac_enable
Function prototype void dac_enable(uint8_t dac_out);
Function descriptions enable DAC
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -

116
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* enable DAC_OUT0 */

dac_enable(DAC_OUT_0);

dac_disable

The description of dac_disable is shown as below:

Table 3-127. Function dac_disable


Function name dac_disable
Function prototype void dac_disable(uint8_t dac_out);
Function descriptions disable DAC
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC_OUT0 */

dac_disable(DAC_OUT_0);

dac_dma_enable

The description of dac_dma_enable is shown as below:

Table 3-128. Function dac_dma_enable


Function name dac_dma_enable
Function prototype void dac_dma_enable(uint8_t dac_out);
Function descriptions enable DAC DMA function
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
117
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* enable DAC_OUT0 DMA function */

dac_dma_enable(DAC_OUT_0);

dac_dma_disable

The description of dac_dma_disable is shown as below:

Table 3-129. Function dac_dma_disable


Function name dac_dma_disable
Function prototype void dac_dma_disable(uint8_t dac_out);
Function descriptions disable DAC DMA function
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC_OUT0 DMA function */

dac_dma_disable(DAC_OUT_0);

dac_output_buffer_enable

The description of dac_output_buffer_enable is shown as below:

Table 3-130. Function dac_output_buffer_enable


Function name dac_output_buffer_enable
Function prototype void dac_output_buffer_enable(uint8_t dac_out);
Function descriptions enable DAC output buffer
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x = 0,1)
Output parameter{out}
- -
118
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* enable DAC_OUT0 output buffer */

dac_output_buffer_enable(DAC_OUT_0);

dac_output_buffer_disable

The description of dac_output_buffer_disable is shown as below:

Table 3-131. Function dac_output_buffer_disable


Function name dac_output_buffer_disable
Function prototype void dac_output_buffer_disable(uint8_t dac_out);
Function descriptions disable DAC output buffer
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x = 0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC_OUT0 output buffer */

dac_output_buffer_disable(DAC_OUT_0);

dac_output_value_get

The description of dac_output_value_get is shown as below:

Table 3-132. Function dac_output_value_get


Function name dac_output_value_get
Function prototype uint16_t dac_output_value_get(uint8_t dac_out);
Function descriptions get DAC output value
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection (x = 0,1)
Output parameter{out}
- -
119
GD32E50x Firmware Library User Guide
Return value
uint16_t DAC output data (0~4095)

Example:

/* get DAC_OUT0 output value */

data = dac_output_value_get(DAC_OUT_0);

dac_data_set

The description of dac_data_set is shown as below:

Table 3-133. Function dac_data_set


Function name dac_data_set
Function prototype void dac_data_set(uint8_t dac_out, uint32_t dac_align, uint16_t data);
Function descriptions set the DAC specified data holding register value
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x = 0,1)
Input parameter{in}
dac_align DAC align mode
DAC_ALIGN_12B_R data left 12 bit alignment
DAC_ALIGN_12B_L data right 12 bit alignment
DAC_ALIGN_8B_R data right 8 bit alignment
Input parameter{in}
data the data sending to holding register (0~4095)
Output parameter{out}
- -
Return value
- -

Example:

/* set the DAC_OUT0 specified data holding register value */

dac_data_set(DAC_OUT_0, DAC_ALIGN_8B_R, 0xff);

dac_output_fifo_enable

The description of dac_output_fifo_enable is shown as below:

Table 3-134. Function dac_output_buffer_enable


Function name dac_output_fifo_enable
Function prototype void dac_output_fifo_enable(uint8_t dac_out);
Function descriptions enable DAC output FIFO
120
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable DAC_OUT0 output FIFO */

dac_output_fifo_enable(DAC_OUT_0);

dac_output_fifo_disable

The description of dac_output_fifo_disable is shown as below:

Table 3-135. Function dac_output_fifo_disable


Function name dac_output_fifo_disable
Function prototype void dac_output_fifo_disable(uint8_t dac_out);
Function descriptions disable DAC output FIFO
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC_OUT0 output FIFO */

dac_output_fifo_disable(DAC_OUT_0);

dac_output_fifo_number_get

The description of dac_output_fifo_number_get is shown as below:

Table 3-136. Function dac_output_fifo_number_get


Function name dac_output_fifo_number_get
Function prototype uint16_t dac_output_fifo_number_get(uint8_t dac_out);
Function descriptions get DAC output FIFO number
121
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection (x = 0,1)
Output parameter{out}
- -
Return value
uint16_t DAC output FIFO number (0~4)

Example:

/* get DAC_OUT0 output FIFO number */

data = dac_output_fifo_number_get (DAC_OUT_0);

dac_trigger_enable

The description of dac_trigger_enable is shown as below:

Table 3-137. Function dac_trigger_enable


Function name dac_trigger_enable
Function prototype void dac_trigger_enable(uint8_t dac_out);
Function descriptions enable DAC trigger
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable DAC_OUT0 trigger */

dac_trigger_enable(DAC_OUT_0);

dac_trigger_disable

The description of dac_trigger_disable is shown as below:

Table 3-138. Function dac_trigger_disable


Function name dac_trigger_disable
Function prototype void dac_trigger_disable(uint8_t dac_out);
Function descriptions disable DAC trigger
122
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC_OUT0 trigger */

dac_trigger_disable(DAC_OUT_0);

dac_trigger_source_config

The description of dac_trigger_source_config is shown as below:

Table 3-139. Function dac_trigger_source_config


Function name dac_trigger_source_config
Function prototype void dac_trigger_source_config(uint8_t dac_out,uint32_t triggersource);
Function descriptions set DAC trigger source
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
triggersource external triggers of DAC
DAC_TRIGGER_T5_
TIMER5 TRGO
TRGO
DAC_TRIGGER_T7_
TIMER7 TRGO (for GD32E50X_HD and GD32E50X_XD)
TRGO
DAC_TRIGGER_T2_
TIMER2 TRGO (for GD32E50X_CL)
TRGO
DAC_TRIGGER_T6_
TIMER6 TRGO
TRGO
DAC_TRIGGER_T4_
TIMER4 TRGO
TRGO
DAC_TRIGGER_T1_
TIMER1 TRGO
TRGO
DAC_TRIGGER_T3_
TIMER3 TRGO
TRGO

123
GD32E50x Firmware Library User Guide
DAC_TRIGGER_
EXTI interrupt line 9 event
EXTI_9
DAC_TRIGGER_
software trigger
SOFTWARE
DAC_TRIGGER_
SHRTIMER SHRTIMER_DACTRIG0 trigger
_DACTRIG0
DAC_TRIGGER_
SHRTIMER SHRTIMER_DACTRIG1 trigger
_DACTRIG1
DAC_TRIGGER_
SHRTIMER SHRTIMER_DACTRIG2 trigger
_DACTRIG2
Output parameter{out}
- -
Return value
- -

Example:

/* configure DAC_OUT0 trigger source*/

dac_trigger_source_config(DAC_OUT_0, DAC_TRIGGER_T1_TRGO);

dac_software_trigger_enable

The description of dac_software_trigger_enable is shown as below:

Table 3-140. Function dac_software_trigger_enable


Function name dac_software_trigger_enable
Function prototype void dac_software_trigger_enable(uint8_t dac_out);
Function descriptions enable DAC software trigger
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable DAC_OUT0 software trigger */

dac_software_trigger_enable(DAC_OUT_0);
124
GD32E50x Firmware Library User Guide
dac_software_trigger_disable

The description of dac_software_trigger_disable is shown as below:

Table 3-141. Function dac_software_trigger_disable


Function name dac_software_trigger_disable
Function prototype void dac_software_trigger_disable(uint8_t dac_out);
Function descriptions disable DAC software trigger
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC_OUT0 software trigger */

dac_software_trigger_disable(DAC_OUT_0);

dac_wave_mode_config

The description of dac_wave_mode_config is shown as below:

Table 3-142. Function dac_wave_mode_config


Function name dac_wave_mode_config
Function prototype void dac_wave_mode_config(uint8_t dac_out, uint32_t wave_mode);
Function descriptions configure DAC wave mode
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
wave_mode wave mode
DAC_WAVE_DISABLE wave disable
DAC_WAVE_MODE
LFSR noise mode
_LFSR
DAC_WAVE_MODE
triangle noise mode
_TRIANGLE
Output parameter{out}
- -

125
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* configure DAC_OUT0 wave mode */

dac_wave_mode_config(DAC_OUT_0, DAC_WAVE_DISABLE);

dac_wave_bit_width_config

The description of dac_wave_bit_width_config is shown as below:

Table 3-143. Function dac_wave_bit_width_config


Function name dac_wave_bit_width_config
Function prototype void dac_wave_bit_width_config(uint8_t dac_out, uint32_t bit_width);
Function descriptions configure DAC wave bit width
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
bit_width noise wave bit width
DAC_WAVE_BIT_
noise wave bit width (x = 1..12)
WIDTH_x
Output parameter{out}
- -
Return value
- -

Example:

/* configure DAC_OUT0 wave bit width */

dac_wave_bit_width_config(DAC_OUT_0, DAC_WAVE_BIT_WIDTH_1);

dac_lfsr_noise_config

The description of dac_lfsr_noise_config is shown as below:

Table 3-144. Function dac_lfsr_noise_config


Function name dac_lfsr_noise_config
Function prototype void dac_lfsr_noise_config(uint8_t dac_out, uint32_t unmask_bits);
Function descriptions configure DAC LFSR noise mode
Precondition -
The called functions -
Input parameter{in}
126
GD32E50x Firmware Library User Guide
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
unmask_bits noise wave unmask bit width
DAC_LFSR_BIT0 unmask the LFSR bit 0
DAC_LFSR_BITSx_0 unmask the LFSR bits[x:0]
Output parameter{out}
- -
Return value
- -

Example:

/* configure DAC_OUT0 LFSR noise mode */

dac_lfsr_noise_config(DAC_OUT_0, DAC_LFSR_BIT0);

dac_triangle_noise_config

The description of dac_triangle_noise_config is shown as below:

Table 3-145. Function dac_triangle_noise_config


Function name dac_triangle_noise_config
Function prototype void dac_triangle_noise_config(uint8_t dac_out, uint32_t amplitude);
Function descriptions configure DAC triangle noise mode
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
amplitude the amplitude of triangle noise
DAC_TRIANGLE_
x = 2n-1 (n = 1..12)
AMPLITUDE_x
Output parameter{out}
- -
Return value
- -

Example:

/* configure DAC_OUT0 triangle noise mode */

dac_triangle_noise_config(DAC_OUT_0, DAC_TRIANGLE_AMPLITUDE_1);

127
GD32E50x Firmware Library User Guide
dac_concurrent_enable

The description of dac_concurrent_enable is shown as below:

Table 3-146. Function dac_concurrent_enable


Function name dac_concurrent_enable
Function prototype void dac_concurrent_enable(void);
Function descriptions enable DAC concurrent mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable DAC concurrent mode */

dac_concurrent_enable();

dac_concurrent_disable

The description of dac_concurrent_disable is shown as below:

Table 3-147. Function dac_concurrent_disable


Function name dac_concurrent_disable
Function prototype void dac_concurrent_disable(void);
Function descriptions disable DAC concurrent mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC concurrent mode */

dac_concurrent_disable();

128
GD32E50x Firmware Library User Guide
dac_concurrent_software_trigger_enable

The description of dac_concurrent_software_trigger_enable is shown as below:

Table 3-148. Function dac_concurrent_software_trigger_enable


Function name dac_concurrent_software_trigger_enable
Function prototype void dac_concurrent_software_trigger_enable(void);
Function descriptions enable DAC concurrent software trigger function
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable DAC concurrent software trigger function */

dac_concurrent_software_trigger_enable();

dac_concurrent_software_trigger_disable

The description of dac_concurrent_software_trigger_disable is shown as below:

Table 3-149. Function dac_concurrent_software_trigger_disable


Function name dac_concurrent_software_trigger_disable
Function prototype void dac_concurrent_software_trigger_disable(void);
Function descriptions disable DAC concurrent software trigger function
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC concurrent software trigger function */

dac_concurrent_software_trigger_disable();

129
GD32E50x Firmware Library User Guide
dac_concurrent_output_buffer_enable

The description of dac_concurrent_output_buffer_enable is shown as below:

Table 3-150. Function dac_concurrent_output_buffer_enable


Function name dac_concurrent_output_buffer_enable
Function prototype void dac_concurrent_output_buffer_enable(void);
Function descriptions enable DAC concurrent buffer function
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable DAC concurrent buffer function */

dac_concurrent_output_buffer_enable();

dac_concurrent_output_buffer_disable

The description of dac_concurrent_output_buffer_disable is shown as below:

Table 3-151. Function dac_concurrent_output_buffer_disable


Function name dac_concurrent_output_buffer_disable
Function prototype void dac_concurrent_output_buffer_disable(void);
Function descriptions disable DAC concurrent buffer function
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC concurrent buffer function */

dac_concurrent_output_buffer_disable();

130
GD32E50x Firmware Library User Guide
dac_concurrent_data_set

The description of dac_concurrent_data_set is shown as below:

Table 3-152. Function dac_concurrent_data_set


Function name dac_concurrent_data_set
void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t
Function prototype
data1);
Function descriptions set DAC concurrent mode data holding register value
Precondition -
The called functions -
Input parameter{in}
dac_align DAC align mode
DAC_ALIGN_12B_R data left 12 bit alignment
DAC_ALIGN_12B_L data right 12 bit alignment
DAC_ALIGN_8B_R data right 8 bit alignment
Input parameter{in}
data0 the data sending to holding register of DAC_OUT0(0~4095)
Input parameter{in}
data1 the data sending to holding register of DAC_OUT1(0~4095)
Output parameter{out}
- -
Return value
- -

Example:

/* set DAC concurrent mode data holding register value */

dac_concurrent_data_set(DAC_ALIGN_8B_R, 0xff, 0xff);

dac_flag_get

The description of dac_flag_get is shown as below:

Table 3-153. Function dac_flag_get


Function name dac_flag_get
Function prototype FlagStatus dac_flag_get(uint8_t dac_out, uint32_t flag);
Function descriptions get DAC flag
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
flag DAC flag

131
GD32E50x Firmware Library User Guide
DAC_FLAG_DDUDR0 DAC_OUT0 DMA underrun flag
DAC_FLAG_FF0 DAC_OUT0 FIFO full flag
DAC_FLAG_FE0 DAC_OUT0 FIFO empty flag
DAC_FLAG_
DAC_OUT0 FIFO overflow flag
FIFOOVR0
DAC_FLAG_
DAC_OUT0 FIFO underflow flag
FIFOUDR0
DAC_FLAG_DDUDR1 DAC_OUT1 DMA underrun flag
DAC_FLAG_FF1 DAC_OUT1 FIFO full flag
DAC_FLAG_FE1 DAC_OUT1 FIFO empty flag
DAC_FLAG_
DAC_OUT1 FIFO overflow flag
FIFOOVR1
DAC_FLAG_
DAC_OUT1 FIFO underflow flag
FIFOUDR1
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the DAC flag */

FlagStatus flag_value;

flag_value = dac_flag_get(DAC_OUT_0, DAC_FLAG_FIFOOVR0);

dac_flag_clear

The description of dac_flag_clear is shown as below:

Table 3-154. Function dac_flag_clear


Function name dac_flag_clear
Function prototype void dac_flag_clear(uint8_t dac_out, uint32_t flag);
Function descriptions clear DAC flag
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
flag DAC flag
DAC_FLAG_DDUDR0 DAC_OUT0 DMA underrun flag
DAC_FLAG_
DAC_OUT0 FIFO overflow flag
FIFOOVR0
DAC_FLAG_ DAC_OUT0 FIFO underflow flag
132
GD32E50x Firmware Library User Guide
FIFOUDR0
DAC_FLAG_DDUDR1 DAC_OUT1 DMA underrun flag
DAC_FLAG_
DAC_OUT1 FIFO overflow flag
FIFOOVR1
DAC_FLAG_
DAC_OUT1 FIFO underflow flag
FIFOUDR1
Output parameter{out}
- -
Return value
- -

Example:

/* clear the DAC flag */

dac_flag_clear(DAC_OUT_0, DAC_FLAG_FIFOOVR0);

dac_interrupt_enable

The description of dac_interrupt_enable is shown as below:

Table 3-155. Function dac_interrupt_enable


Function name dac_interrupt_enable
Function prototype void dac_interrupt_enable(uint8_t dac_out, uint32_t interrupt);
Function descriptions enable DAC interrupt
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
interrupt DAC interrupt
DAC_INT_DDUDRIE0 DAC_OUT0 DMA underrun interrupt enable
DAC_INT_
DAC_OUT0 FIFO overflow interrupt enable
FIFOOVRIE0
DAC_INT_
DAC_OUT0 FIFO underflow interrupt enable
FIFOUDRIE0
DAC_INT_DDUDRIE1 DAC_OUT1 DMA underrun interrupt enable
DAC_INT_
DAC_OUT1 FIFO overflow interrupt enable
FIFOOVRIE1
DAC_INT_
DAC_OUT1 FIFO underflow interrupt enable
FIFOUDRIE1
Output parameter{out}
- -
Return value

133
GD32E50x Firmware Library User Guide
- -

Example:

/* enable DAC interrupt */

dac_interrupt_enable(DAC_OUT_0, DAC_INT_DDUDRIE0);

dac_interrupt_disable

The description of dac_interrupt_disable is shown as below:

Table 3-156. Function dac_interrupt_enable


Function name dac_interrupt_enable
Function prototype void dac_interrupt_disable(uint8_t dac_out, uint32_t interrupt);
Function descriptions disable DAC interrupt
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
interrupt DAC interrupt
DAC_INT_DDUDRIE0 DAC_OUT0 DMA underrun interrupt disable
DAC_INT_
DAC_OUT0 FIFO overflow interrupt disable
FIFOOVRIE0
DAC_INT_
DAC_OUT0 FIFO underflow interrupt disable
FIFOUDRIE0
DAC_INT_DDUDRIE1 DAC_OUT1 DMA underrun interrupt disable
DAC_INT_
DAC_OUT1 FIFO overflow interrupt disable
FIFOOVRIE1
DAC_INT_
DAC_OUT1 FIFO underflow interrupt disable
FIFOUDRIE1
Output parameter{out}
- -
Return value
- -

Example:

/* disable DAC interrupt */

dac_interrupt_disable(DAC_OUT_0, DAC_INT_DDUDRIE0);

dac_interrupt_flag_get

The description of dac_interrupt_flag_get is shown as below:

134
GD32E50x Firmware Library User Guide
Table 3-157. Function dac_interrupt_flag_get
Function name dac_interrupt_flag_get
Function prototype FlagStatus dac_interrupt_flag_get(uint8_t dac_out, uint32_t int_flag);
Function descriptions get DAC interrupt flag
Precondition -
The called functions -
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
int_flag DAC interrupt flag
DAC_INT_FLAG_
DAC_OUT0 DMA underrun interrupt flag
DDUDR0
DAC_INT_FLAG_
DAC_OUT0 FIFO overflow interrupt flag
FIFOOVR0
DAC_INT_FLAG_
DAC_OUT0 FIFO underflow interrupt flag
FIFOUDR0
DAC_INT_FLAG_
DAC_OUT1 DMA underrun interrupt flag
DDUDR1
DAC_INT_FLAG_
DAC_OUT1 FIFO overflow interrupt flag
FIFOOVR1
DAC_INT_FLAG_
DAC_OUT1 FIFO underflow interrupt flag
FIFOUDR1
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the DAC interrupt flag */

FlagStatus flag_value;

flag_value = dac_interrupt_flag_get(DAC_OUT_0, DAC_INT_FLAG_FIFOOVR0);

dac_interrupt_flag_clear

The description of dac_interrupt_flag_clear is shown as below:

Table 3-158. Function dac_interrupt_flag_clear


Function name dac_interrupt_flag_clear
Function prototype void dac_interrupt_flag_clear(uint8_t dac_out, uint32_t int_flag);
Function descriptions clear DAC interrupt flag
Precondition -
The called functions -
135
GD32E50x Firmware Library User Guide
Input parameter{in}
dac_out DAC output
DAC_OUT_x DAC output selection(x =0,1)
Input parameter{in}
int_flag DAC interrupt flag
DAC_INT_FLAG_
DAC_OUT0 DMA underrun interrupt flag
DDUDR0
DAC_INT_FLAG_
DAC_OUT0 FIFO overflow interrupt flag
FIFOOVR0
DAC_INT_FLAG_
DAC_OUT0 FIFO underflow interrupt flag
FIFOUDR0
DAC_INT_FLAG_
DAC_OUT1 DMA underrun interrupt flag
DDUDR1
DAC_INT_FLAG_
DAC_OUT1 FIFO overflow interrupt flag
FIFOOVR1
DAC_INT_FLAG_
DAC_OUT1 FIFO underflow interrupt flag
FIFOUDR1
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* clear DAC interrupt flag */

dac_interrupt_flag_clear (DAC_OUT_0, DAC_INT_FLAG_FIFOOVR0);

3.8. DBG

The DBG hold unit helps debugger to debug power saving mode. The DBG registers are
listed in chapter 3.8.1. the DBG firmware functions are introduced in chapter 3.8.2.

3.8.1. Descriptions of Peripheral registers

DBG registers are listed in the table shown as below:

Table 3-159. DBG Registers


Registers Descriptions
DBG_ID DBG ID code register
DBG_CTL DBG control register

3.8.2. Descriptions of Peripheral functions

DBG firmware functions are listed in the table shown as below:


136
GD32E50x Firmware Library User Guide
Table 3-160. DBG firmware function
Function name Function description
dbg_deinit deinitialize the DBG
dbg_id_get read DBG_ID code register
dbg_low_power_enable enable low power behavior when the MCU is in debug mode
dbg_low_power_disable disable low power behavior when the MCU is in debug mode
dbg_periph_enable enable peripheral behavior when the MCU is in debug mode
dbg_periph_disable disable peripheral behavior when the MCU is in debug mode
dbg_trace_pin_enable enable trace pin assignment
dbg_trace_pin_disable disable trace pin assignment
dbg_trace_pin_mode_set set trace pin mode

Enum dbg_periph_enum

Table 3-161. Enum dbg_periph_enum


Member name Function description
DBG_FWDGT_HOLD hold FWDGT counter when core is halted
DBG_WWDGT_HOLD hold WWDGT counter when core is halted
DBG_TIMER0_HOLD hold TIMER0 counter when core is halted
DBG_TIMER1_HOLD hold TIMER1 counter when core is halted
DBG_TIMER2_HOLD hold TIMER2 counter when core is halted
DBG_TIMER3_HOLD hold TIMER3 counter when core is halted
DBG_I2C0_HOLD hold I2C0 smbus when core is halted
DBG_I2C1_HOLD hold I2C1 smbus when core is halted
DBG_TIMER7_HOLD hold TIMER7 counter when core is halted
DBG_TIMER4_HOLD hold TIMER4 counter when core is halted
DBG_TIMER5_HOLD hold TIMER5 counter when core is halted
DBG_TIMER6_HOLD hold TIMER6 counter when core is halted
DBG_I2C2_HOLD hold I2C2 smbus timeout when core is halted
DBG_TIMER11_HOLD hold TIMER11 counter when core is halted
DBG_TIMER12_HOLD hold TIMER12 counter when core is halted
DBG_TIMER13_HOLD hold TIMER13 counter when core is halted
DBG_TIMER8_HOLD hold TIMER8 counter when core is halted
DBG_TIMER9_HOLD hold TIMER9 counter when core is halted
DBG_TIMER10_HOLD hold TIMER10 counter when core is halted
hold SHRTIMER counter when core is halted, except for
DBG_SHRTIMER_HOLD
GD32EPRT series

dbg_deinit

The description of dbg_deinit is shown as below:

Table 3-162. Function dbg_deinit


Function name dbg_deinit

137
GD32E50x Firmware Library User Guide
Function prototype void dbg_deinit(void);
Function descriptions deinitialize the DBG
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize the DBG */

dbg_deinit();

dbg_id_get

The description of dbg_id_get is shown as below:

Table 3-163. Function dbg_id_get


Function name dbg_id_get
Function prototype uint32_t dbg_id_get(void);
Function descriptions Read DBG_ID code register
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t DBG_ID code (0-0xFFFFFFFF)

Example:

/* read DBG_ID code register */

uint32_t id_value = 0;

id_value = dbg_id_get();

dbg_low_power_enable

The description of dbg_low_power_enable is shown as below:

Table 3-164. Function dbg_low_power_enable


Function name dbg_low_power_enable

138
GD32E50x Firmware Library User Guide
Function prototype void dbg_low_power_enable(uint32_t dbg_low_power);
Function descriptions Enable low power behavior when the mcu is in debug mode
Precondition -
The called functions -
Input parameter{in}
dbg_low_power low power mode
DBG_LOW_POWER_S
keep debugger connection during sleep mode
LEEP
DBG_LOW_POWER_D
keep debugger connection during deepsleep mode
EEPSLEEP
DBG_LOW_POWER_S
keep debugger connection during standby mode
TANDBY
Output parameter{out}
- -
Return value
- -

Example:

/* keep debugger connection during sleep mode */

dbg_low_power_enable(DBG_LOW_POWER_SLEEP);

dbg_low_power_disable

The description of dbg_low_power_disable is shown as below:

Table 3-165. Function dbg_low_power_disable


Function name dbg_low_power_disable
Function prototype void dbg_low_power_disable(uint32_t dbg_low_power);
Function descriptions Disable low power behavior when the mcu is in debug mode
Precondition -
The called functions -
Input parameter{in}
dbg_low_power low power mode
DBG_LOW_POWER_S
keep debugger connection during sleep mode
LEEP
DBG_LOW_POWER_D
keep debugger connection during deepsleep mode
EEPSLEEP
DBG_LOW_POWER_S
keep debugger connection during standby mode
TANDBY
Output parameter{out}
- -
Return value
- -

139
GD32E50x Firmware Library User Guide
Example:

/* do not keep debugger connection during sleep mode */

dbg_low_power_disable(DBG_LOW_POWER_SLEEP);

dbg_periph_enable

The description of dbg_periph_enable is shown as below:

Table 3-166. Function dbg_periph_enable


Function name dbg_periph_enable
Function prototype void dbg_periph_enable(dbg_periph_enum dbg_periph);
Function descriptions Enable peripheral behavior when the mcu is in debug mode
Precondition -
The called functions -
Input parameter{in}
dbg_periph Peripheral refer to Enum dbg_periph_enum
DBG_FWDGT_HOLD debug FWDGT kept when core is halted
DBG_WWDGT_HOLD debug WWDGT kept when core is halted
DBG_I2Cx_HOLD x=0,1,2 hold I2Cx smbus when core is halted
DBG_TIMERx_HOLD x=0,1,2,3,4,5,6,7,8,9,10,11,12,13, hold TIMERx counter when core is halted
DBG_SHRTIMER_HOL
hold SHRTIMER counter when core is halted, except for GD32EPRT series
D
Output parameter{out}
- -
Return value
- -

Example:

/* hold TIMER0 counter when core is halted */

dbg_periph_enable(DBG_TIMER0_HOLD);

dbg_periph_disable

The description of dbg_periph_disable is shown as below:

Table 3-167. Function dbg_periph_disable


Function name dbg_periph_disable
Function prototype void dbg_periph_disable(dbg_periph_enum dbg_periph);
Function descriptions Disable peripheral behavior when the mcu is in debug mode
Precondition -
The called functions -
Input parameter{in}
dbg_periph peripheral refer to Enum dbg_periph_enum

140
GD32E50x Firmware Library User Guide
DBG_FWDGT_HOLD debug FWDGT kept when core is halted
DBG_WWDGT_HOLD debug WWDGT kept when core is halted
DBG_I2Cx_HOLD x=0,1,2hold I2Cx smbus when core is halted
DBG_TIMERx_HOLD x=0,1,2,3,4,5,6,7,8,9,10,11,12,13, hold TIMERx counter when core is halted
DBG_SHRTIMER_HOL
hold SHRTIMER counter when core is halted, except for GD32EPRT series
D
Output parameter{out}
- -
Return value
- -

Example:

/* do not hold TIMER0 counter when core is halted */

dbg_periph_disable(DBG_TIMER0_HOLD);

dbg_trace_pin_enable

The description of dbg_trace_pin_enable is shown as below:

Table 3-168. Function dbg_trace_pin_enable


Function name dbg_trace_pin_enable
Function prototype void dbg_trace_pin_enable(void);
Function descriptions Enable trace pin assignment
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable trace pin assignment */

dbg_trace_pin_enable();

dbg_trace_pin_disable

The description of dbg_trace_pin_disable is shown as below:

Table 3-169. Function dbg_trace_pin_disable


Function name dbg_trace_pin_disable
Function prototype void dbg_trace_pin_disable(void);
Function descriptions Disable trace pin assignment
141
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable trace pin assignment */

dbg_trace_pin_disable();

dbg_trace_pin_mode_set

The description of dbg_trace_pin_mode_set is shown as below:

Table 3-170. Function dbg_trace_pin_mode_set


Function name dbg_trace_pin_mode_set
Function prototype void dbg_trace_pin_mode_set(uint32_t trace_mode);
Function descriptions Trace pin mode selection
Precondition -
The called functions -
Input parameter{in}
trace_mode trace pin mode selection
TRACE_MODE_ASYN
trace pin used for async mode
C
TRACE_MODE_SYNC
trace pin used for sync mode and data size is 1
_DATASIZE_1
TRACE_MODE_SYNC
trace pin used for sync mode and data size is 2
_DATASIZE_2
TRACE_MODE_SYNC
trace pin used for sync mode and data size is 4
_DATASIZE_4
Output parameter{out}
- -
Return value
- -

Example:

/* trace pin used for async mode */

dbg_trace_pin_mode_set(TRACE_MODE_ASYNC);

142
GD32E50x Firmware Library User Guide
3.9. DMA

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. The DMA registers are listed in chapter 3.9.1, the DMA
firmware functions are introduced in chapter 3.9.2.

3.9.1. Descriptions of Peripheral registers

DMA registers are listed in the table shown as below:

Table 3-171. DMA Registers


Registers Descriptions
DMA_INTF Interrupt flag register
DMA_INTC Interrupt flag clear register
DMA_CHxCTL
Channel x control register
(x=0..6)
DMA_CHxCNT
Channel x counter register
(x=0..6)
DMA_CHxPADDR
Channel x peripheral base address register
(x=0..6)
DMA_CHxMADDR
Channel x memory base address register
(x=0..6)

3.9.2. Descriptions of Peripheral functions

DMA firmware functions are listed in the table shown as below:

Table 3-172. DMA firmware function


Function name Function description
dma_deinit deinitialize DMA a channel registers
dma_struct_para_init initialize the parameters of DMA struct with the default values
dma_init initialize DMA channel
dma_circulation_enable enable DMA circulation mode
dma_circulation_disable disable DMA circulation mode
dma_memory_to_memory_enable enable memory to memory mode
dma_memory_to_memory_disable disable memory to memory mode
dma_channel_enable enable DMA channel
dma_channel_disable disable DMA channel
dma_periph_address_config set DMA peripheral base address
dma_memory_address_config set DMA memory base address
dma_transfer_number_config set the number of remaining data to be transferred by the

143
GD32E50x Firmware Library User Guide
Function name Function description
DMA
get the number of remaining data to be transferred by the
dma_transfer_number_get
DMA
dma_priority_config configure priority level of DMA channel
dma_memory_width_config configure transfer data size of memory
dma_periph_width_config configure transfer data size of peripheral
dma_memory_increase_enable enable next address increasement algorithm of memory
dma_memory_increase_disable disable next address increasement algorithm of memory
dma_periph_increase_enable enable next address increasement algorithm of peripheral
dma_periph_increase_disable disable next address increasement algorithm of peripheral
dma_transfer_direction_config configure the direction of data transfer on the channel
dma_flag_get check DMA flag is set or not
dma_flag_clear clear a DMA channel flag
dma_interrupt_enable enable DMA interrupt
dma_interrupt_disable disable DMA interrupt
dma_interrupt_flag_get check DMA flag and interrupt enable bit is set or not
dma_interrupt_flag_clear clear a DMA channel flag

Enum dma_channel_enum

Table 3-173. Enum dma_channel_enum


Member name Function description
DMA_CH0 DMA Channel0
DMA_CH1 DMA Channel1
DMA_CH2 DMA Channel2
DMA_CH3 DMA Channel3
DMA_CH4 DMA Channel4
DMA_CH5 DMA Channel5
DMA_CH6 DMA Channel6

Structure dma_parameter_struct

Table 3-174. Structure dma_parameter_struct


Member name Function description
periph_addr peripheral base address
periph_width transfer data size of peripheral
memory_addr memory base address
memory_width transfer data size of memory
number channel transfer number
priority channel priority level
periph_inc peripheral increasing mode
memory_inc memory increasing mode

144
GD32E50x Firmware Library User Guide
direction channel data transfer direction

dma_deinit

The description of dma_deinit is shown as below:

Table 3-175. Function dma_deinit


Function name dma_deinit
Function prototype void dma_deinit(uint32_t dma_periph, dma_channel_enum channelx);
Function descriptions deinitialize DMA a channel registers
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel, refer to Enum dma_channel_enum
DMA_CHx(DMA0:x=0..
DMA channel selection
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* DMA0 channel0 deinitialize*/


dma_deinit(DMA0, DMA_CH0);

dma_struct_para_init

The description of dma_struct_para_init is shown as below:

Table 3-176. Function dma_struct_para_init


Function name dma_struct_para_init
Function prototype void dma_struct_para_init(dma_parameter_struct* init_struct);
Function descriptions initialize the parameters of DMA struct with the default values
Precondition -
The called functions -
Input parameter{in}
A dma_parameter_struct address, refer to Structure
*init_struct
dma_parameter_struct
Output parameter{out}
- -
Return value
- -
145
GD32E50x Firmware Library User Guide
Example:

/* initialize the parameters of DMA */


dma_parameter_struct dma_init_struct;
dma_struct_para_init(&dma_init_struct);

dma_init

The description of dma_init is shown as below:

Table 3-177. Function dma_init


Function name dma_init
void dma_init(uint32_t dma_periph, dma_channel_enum channelx,
Function prototype
dma_parameter_struct* init_struct);
Function descriptions initialize DMA channel
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel, refer to Enum dma_channel_enum
DMA_CHx(DMA0:x=0..
DMA channel selection
6; DMA1: x=0..4)
Input parameter{in}
Structure for initialization, the structure members can refer to Structure
init_struct
dma_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* DMA0 channel0 initialize */


dma_parameter_struct dma_init_struct;
dma_deinit(DMA0, DMA_CH0);
dma_struct_para_init(&dma_init_struct);

dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY;
dma_init_struct.memory_addr = (uint32_t)g_destbuf;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_32BIT;
dma_init_struct.number = TRANSFER_NUM/4;
dma_init_struct.periph_addr = (uint32_t)FLASH_WRITE_START_ADDR;
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_ENABLE;
146
GD32E50x Firmware Library User Guide
dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_32BIT;
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_init(DMA0, DMA_CH0, &dma_init_struct);

dma_circulation_enable

The description of dma_circulation_enable is shown as below:

Table 3-178. Function dma_circulation_enable


Function name dma_circulation_enable
void dma_circulation_enable(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx);
Function descriptions enable DMA circulation mode
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* enable DMA0 channel0 circulation mode */


dma_circulation_enable(DMA0, DMA_CH0);

dma_circulation_disable

The description of dma_circulation_disable is shown as below:

Table 3-179. Function dma_circulation_disable


Function name dma_circulation_disable
void dma_circulation_disable(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx);
Function descriptions disable DMA circulation mode
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
147
GD32E50x Firmware Library User Guide
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DMA0 channel0 circulation mode */


dma_circulation_disable(DMA0, DMA_CH0);

dma_memory_to_memory_enable

The description of dma_memory_to_memory_enable is shown as below:

Table 3-180. Function dma_memory_to_memory_enable


Function name dma_memory_to_memory_enable
void dma_memory_to_memory_enable(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx);
Function descriptions enable memory to memory mode
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* enable DMA0 channel0 memory to memory mode */


dma_memory_to_memory_enable(DMA0, DMA_CH0);

dma_memory_to_memory_disable

The description of dma_memory_to_memory_disable is shown as below:

148
GD32E50x Firmware Library User Guide
Table 3-181. Function dma_memory_to_memory_disable
Function name dma_memory_to_memory_disable
void dma_memory_to_memory_disable(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx);
Function descriptions disable memory to memory mode
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DMA0 channel0 memory to memory mode */


dma_memory_to_memory_enable(DMA0, DMA_CH0);

dma_channel_enable

The description of dma_channel_enable is shown as below:

Table 3-182. Function dma_channel_enable


Function name dma_channel_enable
void dma_channel_enable(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx);
Function descriptions enable DMA channel
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
149
GD32E50x Firmware Library User Guide
- -

Example:

/* enable DMA0 channel0 */


dma_channel_enable(DMA0, DMA_CH0);

dma_channel_disable

The description of dma_channel_disable is shown as below:

Table 3-183. Function dma_channel_disable


Function name dma_channel_disable
void dma_channel_disable(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx);
Function descriptions disable DMA channel
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* disable DMA0 channel0 */


dma_channel_disable(DMA0, DMA_CH0);

dma_periph_address_config

The description of dma_periph_address_config is shown as below:

Table 3-184. Function dma_periph_address_config


Function name dma_periph_address_config
void dma_periph_address_config(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx, uint32_t address);
Function descriptions set DMA peripheral base address
Precondition -
The called functions -
Input parameter{in}
150
GD32E50x Firmware Library User Guide
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
address peripheral base address
Output parameter{out}
- -
Return value
- -

Example:

#define FLASH_WRITE_START_ADDR ((uint32_t)0x08004000)

dma_periph_address_config(DMA0, DMA_CH0, FLASH_WRITE_START_ADDR);

dma_memory_address_config

The description of dma_memory_address_config is shown as below:

Table 3-185. Function dma_memory_address_config


Function name dma_memory_address_config
void dma_memory_address_config(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx, uint32_t address);
Function descriptions set DMA memory base address
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
address memory base address
Output parameter{out}
- -
Return value
- -

Example:

151
GD32E50x Firmware Library User Guide
uint8_t g_destbuf[TRANSFER_NUM];

dma_memory_address_config(DMA0, DMA_CH0, (uint32_t) g_destbuf);

dma_transfer_number_config

The description of dma_transfer_number_config is shown as below:

Table 3-186. Function dma_transfer_number_config


Function name dma_transfer_number_config
void dma_transfer_number_config(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx, uint32_t number);
Function descriptions set the number of remaining data to be transferred by the DMA
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
number data transfer number (0x00000000 – 0x0000FFFF)
Output parameter{out}
- -
Return value
- -

Example:

#define TRANSFER_NUM 0x400

dma_transfer_number_config(DMA0, DMA_CH0, TRANSFER_NUM);

dma_transfer_number_get

The description of dma_transfer_number_get is shown as below:

Table 3-187. Function dma_transfer_number_get


Function name dma_transfer_number_get
uint32_t dma_transfer_number_get(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx);
Function descriptions get the number of remaining data to be transferred by the DMA
Precondition -
The called functions -
Input parameter{in}
152
GD32E50x Firmware Library User Guide
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
uint32_t 0x00000000 – 0x0000FFFF

Example:

uint32_t number = 0;

number = dma_transfer_number_get(DMA0, DMA_CH0);

dma_priority_config

The description of dma_priority_config is shown as below:

Table 3-188. Function dma_priority_config


Function name dma_priority_config
void dma_priority_config(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx, uint32_t priority);
Function descriptions configure priority level of DMA channel
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
priority priority Level of this channel
DMA_PRIORITY_LOW low priority
DMA_PRIORITY_MEDI
medium priority
UM
DMA_PRIORITY_HIGH high priority
DMA_PRIORITY_ULTR
ultra high priority
A_HIGH
Output parameter{out}
- -

153
GD32E50x Firmware Library User Guide
Return value
- -

Example:

dma_priority_config(DMA0, DMA_CH0, DMA_PRIORITY_ULTRA_HIGH);

dma_memory_width_config

The description of dma_memory_width_config is shown as below:

Table 3-189. Function dma_memory_width_config


Function name dma_memory_width_config
void dma_memory_width_config (uint32_t dma_periph, dma_channel_enum
Function prototype
channelx, uint32_t mwidth);
Function descriptions configure transfer data size of memory
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
mwidth transfer data width of memory
DMA_MEMORY_WIDT
transfer data width of memory is 8-bit
H_8BIT
DMA_MEMORY_WIDT
transfer data width of memory is 16-bit
H_16BIT
DMA_MEMORY_WIDT
transfer data width of memory is 32-bit
H_32BIT
Output parameter{out}
- -
Return value
- -

Example:

dma_memory_width_config(DMA0, DMA_CH0, DMA_MEMORY_WIDTH_8BIT);

dma_periph_width_config

The description of dma_periph_width_config is shown as below:

154
GD32E50x Firmware Library User Guide
Table 3-190. Function dma_periph_width_config
Function name dma_periph_width_config
void dma_periph_width_config (uint32_t dma_periph, dma_channel_enum
Function prototype
channelx, uint32_t pwidth);
Function descriptions configure transfer data size of peripheral
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
pwidth transfer data width of peripheral
DMA_PERIPHERAL_W
transfer data width of peripheral is 8-bit
IDTH_8BIT
DMA_PERIPHERAL_W
transfer data width of peripheral is 16-bit
IDTH_16BIT
DMA_PERIPHERAL_W
transfer data width of peripheral is 32-bit
IDTH_32BIT
Output parameter{out}
- -
Return value
- -

Example:

dma_periph_width_config(DMA0, DMA_CH0, DMA_PERIPHERAL_WIDTH_8BIT);

dma_memory_increase_enable

The description of dma_memory_increase_enable is shown as below:

Table 3-191. Function dma_memory_increase_enable


Function name dma_memory_increase_enable
void dma_memory_increase_enable(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx);
Function descriptions enable next address increasement algorithm of memory
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
155
GD32E50x Firmware Library User Guide
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

dma_memory_increase_enable(DMA0, DMA_CH0);

dma_memory_increase_disable

The description of dma_memory_increase_disable is shown as below:

Table 3-192. Function dma_memory_increase_disable


Function name dma_memory_increase_disable
void dma_memory_increase_disable(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx);
Function descriptions disable next address increasement algorithm of memory
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

dma_memory_increase_disable(DMA0, DMA_CH0);

dma_periph_increase_enable

The description of dma_periph_increase_enable is shown as below:

Table 3-193. Function dma_periph_increase_enable


Function name dma_periph_increase_enable
Function prototype void dma_periph_increase_enable(uint32_t dma_periph,
156
GD32E50x Firmware Library User Guide
dma_channel_enum channelx);
Function descriptions enable next address increasement algorithm of peripheral
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

dma_periph_increase_enable(DMA0, DMA_CH0);

dma_periph_increase_disable

The description of dma_periph_increase_disable is shown as below:

Table 3-194. Function dma_periph_increase_disable


Function name dma_periph_increase_disable
void dma_periph_increase_disable(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx);
Function descriptions disable next address increasement algorithm of peripheral
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

dma_periph_increase_disable(DMA0, DMA_CH0);
157
GD32E50x Firmware Library User Guide
dma_transfer_direction_config

The description of dma_transfer_direction_config is shown as below:

Table 3-195. Function dma_transfer_direction_config


Function name dma_transfer_direction_config
void dma_transfer_direction_config(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx, uint32_t direction);
Function descriptions configure the direction of data transfer on the channel
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
direction specify the direction of data transfer
DMA_PERIPHERAL_T
read from peripheral and write to memory
O_MEMORY
DMA_MEMORY_TO_P
read from memory and write to peripheral
ERIPHERAL
Output parameter{out}
- -
Return value
- -

Example:

dma_transfer_direction_config(DMA0, DMA_CH0, DMA_PERIPHERAL_TO_MEMORY);

dma_flag_get

The description of dma_flag_get is shown as below:

Table 3-196. Function dma_flag_get


Function name dma_flag_get
FlagStatus dma_flag_get(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx, uint32_t flag);
Function descriptions check DMA flag is set or not
Precondition -
The called functions -
Input parameter{in}

158
GD32E50x Firmware Library User Guide
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
flag specify get which flag
DMA_FLAG_G global interrupt flag of channel
DMA_FLAG_FTF full transfer finish flag of channel
DMA_FLAG_HTF half transfer finish flag of channel
DMA_FLAG_ERR error flag of channel
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

FlagStatus flag = RESET;

flag = dma_flag_get(DMA0, DMA_CH0, DMA_FLAG_FTF);

dma_flag_clear

The description of dma_flag_clear is shown as below:

Table 3-197. Function dma_flag_clear


Function name dma_flag_clear
void dma_flag_clear(uint32_t dma_periph, dma_channel_enum channelx,
Function prototype
uint32_t flag);
Function descriptions clear the flag of a DMA channel
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
flag specify get which flag
DMA_FLAG_G global interrupt flag of channel
DMA_FLAG_FTF full transfer finish flag of channel

159
GD32E50x Firmware Library User Guide
DMA_FLAG_HTF half transfer finish flag of channel
DMA_FLAG_ERR error flag of channel
Output parameter{out}
- -
Return value
- -

Example:

dma_flag_clear(DMA0, DMA_CH0, DMA_FLAG_FTF);

dma_interrupt_enable

The description of dma_interrupt_enable is shown as below:

Table 3-198. Function dma_interrupt_enable


Function name dma_interrupt_enable
void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx, uint32_t source);
Function descriptions enable DMA interrupt
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
source DMA interrupt source
DMA_INT_FTF full transfer finish interrupt of channel
DMA_INT_HTF half transfer finish interrupt of channel
DMA_INT_ERR error interrupt of channel
Output parameter{out}
- -
Return value
- -

Example:

/* DMA0 channel0 interrupt configuration */

dma_interrupt_enable(DMA0, DMA_CH0, DMA_INT_FTF);

160
GD32E50x Firmware Library User Guide
dma_interrupt_disable

The description of dma_interrupt_disable is shown as below:

Table 3-199. Function dma_interrupt_disable


Function name dma_interrupt_disable
void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx, uint32_t source);
Function descriptions disable DMA interrupt
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
source DMA interrupt source
DMA_INT_FTF full transfer finish interrupt of channel
DMA_INT_HTF half transfer finish interrupt of channel
DMA_INT_ERR error interrupt of channel
Output parameter{out}
- -
Return value
- -

Example:

/* DMA0 channel0 interrupt configuration */

dma_interrupt_ disable(DMA0, DMA_CH0, DMA_INT_FTF);

dma_interrupt_flag_get

The description of dma_interrupt_flag_get is shown as below:

Table 3-200. Function dma_interrupt_flag_get


Function name dma_interrupt_flag_get
FlagStatus dma_interrupt_flag_get(uint32_t dma_periph,
Function prototype
dma_channel_enum channelx, uint32_t flag);
Function descriptions check DMA flag and interrupt enable bit is set or not
Precondition -
The called functions -
Input parameter{in}

161
GD32E50x Firmware Library User Guide
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
flag specify get which flag
DMA_INT_FLAG_FTF full transfer finish interrupt flag of channel
DMA_INT_FLAG_HTF half transfer finish interrupt flag of channel
DMA_INT_FLAG_ERR error interrupt flag of channel
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

if(dma_interrupt_flag_get(DMA0, DMA_CH3, DMA_INT_FLAG_FTF)){


dma_interrupt_flag_clear(DMA0, DMA_CH3, DMA_INT_FLAG_G);
}

dma_interrupt_flag_clear

The description of dma_interrupt_flag_clear is shown as below:

Table 3-201. Function dma_interrupt_flag_clear


Function name dma_interrupt_flag_clear
void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum
Function prototype
channelx, uint32_t flag);
Function descriptions clear the interrupt flag of a DMA channel
Precondition -
The called functions -
Input parameter{in}
dma_periph DMA peripheral
DMAx(x=0,1) DMA peripheral selection
Input parameter{in}
channelx DMA channel
DMA_CHx(DMA0:x=0..
DMA channel selection, refer to Enum dma_channel_enum
6; DMA1: x=0..4)
Input parameter{in}
flag specify get which flag
DMA_INT_FLAG_G global interrupt flag of channel
DMA_INT_FLAG_FTF full transfer finish interrupt flag of channel
DMA_INT_FLAG_HTF half transfer finish interrupt flag of channel
162
GD32E50x Firmware Library User Guide
DMA_INT_FLAG_ERR error interrupt flag of channel
Output parameter{out}
- -
Return value
- -

Example:

if(dma_interrupt_flag_get(DMA0, DMA_CH3, DMA_INT_FLAG_FTF)){


dma_interrupt_flag_clear(DMA0, DMA_CH3, DMA_INT_FLAG_G);
}

3.10. ENET

There is a media access controller (MAC) designed in Ethernet module to support


10/100Mbps interface speed. For more efficient data transfer between Ethernet and memory,
a DMA controller is designed in this module. The support interface protocol for Ethernet is
media independent interface (MII) and reduced media independent interface (RMII). The
ENET registers are listed in chapter 3.10.1, the ENET firmware functions are introduced in
chapter 3.10.2.

3.10.1. Descriptions of Peripheral registers

ENET registers are listed in the table shown as below:

Table 3-202. ENET Registers


Registers Descriptions
ENET_MAC_CFG MAC configuration register
ENET_MAC_FRMF MAC frame filter register
ENET_MAC_HLH MAC hash list high register
ENET_MAC_HLL MAC hash list low register
ENET_MAC_PHY_
MAC PHY control register
CTL
ENET_MAC_PHY_
MAC MII data register
DATA
ENET_MAC_FCTL MAC flow control register
ENET_MAC_VLT MAC VLAN tag register
ENET_MAC_RWFF MAC remote wakeup frame filter register
ENET_MAC_WUM MAC wakeup management register
ENET_MAC_DBG MAC debug register
ENET_MAC_INTF MAC interrupt flag register
ENET_MAC_INTMS
MAC interrupt mask register
K
ENET_MAC_ADDR MAC address 0 high register

163
GD32E50x Firmware Library User Guide
Registers Descriptions
0H
ENET_MAC_ADDR
MAC address 0 low register
0L
ENET_MAC_ADDR
MAC address 1 high register
1H
ENET_MAC_ADDR
MAC address 1 low register
1L
ENET_MAC_ADDT
MAC address 2 high register
2H
ENET_MAC_ADDR
MAC address 2 low register
2L
ENET_MAC_ADDR
MAC address 3 high register
3H
ENET_MAC_ADDR
MAC address 3 low register
3L
ENET_MAC_FCTH MAC flow control threshold register
ENET_MSC_CTL MSC control register
ENET_MSC_RINTF MSC receive interrupt flag register
ENET_MSC_TINTF MSC transmit interrupt flag register
ENET_MSC_RINT
MSC receive interrupt mask register
MSK
ENET_MSC_TINTM
MSC transmit interrupt mask register
SK
ENET_MSC_SCCN
MSC transmitted good frames after a single collision counter register
T
ENET_MSC_MSCC
MSC transmitted good frames after more than a single collision counter register
NT
ENET_MSC_TGFC
MSC transmitted good frames counter register
NT
ENET_MSC_RFCE
MSC received frames with CRC error counter register
CNT
ENET_MSC_RFAE
MSC received frames with alignment error counter register
CNT
ENET_MSC_RGUF
MSC received good unicast frames counter register
CNT
ENET_PTP_TSCTL PTP time stamp control register
ENET_PTP_SSINC PTP subsecond increment register
ENET_PTP_TSH PTP time stamp high register
ENET_PTP_TSL PTP time stamp low register
ENET_PTP_TSUH PTP time stamp update high register
ENET_PTP_TSUL PTP time stamp update low register
ENET_PTP_TSADD PTP time stamp addend register

164
GD32E50x Firmware Library User Guide
Registers Descriptions
END
ENET_PTP_ETH PTP expected time high register
ENET_PTP_ETL PTP expected time low register
ENET_PTP_TSF PTP time stamp flag register
ENET_PTP_PPSCT
PTP PPS control register
L
ENET_DMA_BCTL DMA bus control register
ENET_DMA_TPEN DMA transmit poll enable register
ENET_DMA_RPEN DMA receive poll enable register
ENET_DMA_RDTA
DMA receive descriptor table address register
DDR
ENET_DMA_TDTA
DMA transmit descriptor table address register
DDR
ENET_DMA_STAT DMA status register
ENET_DMA_CTL DMA control register
ENET_DMA_INTEN DMA interrupt enable register
ENET_DMA_MFBO
DMA missed frame and buffer overflow counter register
CNT
ENET_DMA_RSWD
DMA receive state watchdog counter redister
C
ENET_DMA_CTDA
DMA current transmit descriptor address register
DDR
ENET_DMA_CRDA
DMA current receive descriptor address register
DDR
ENET_DMA_CTBA
DMA current transmit buffer address register
DDR
ENET_DMA_CRBA
DMA current receive buffer address register
DDR

3.10.2. Descriptions of Peripheral functions

ENET firmware functions are listed in the table shown as below:

Table 3-203. ENET firmware function


Function name Function description
main function
deinitialize the ENET, and reset structure parameters for
enet_deinit
ENET initialization
configure the parameters which are usually less cared for
enet_initpara_config
initialization
initialize ENET peripheral with generally concerned
enet_init
parameters and the less cared parameters

165
GD32E50x Firmware Library User Guide
Function name Function description
reset all core internal registers located in CLK_TX and
enet_software_reset
CLK_RX
enet_rxframe_size_get check receive frame valid and return frame size
enet_descriptors_chain_init initialize the dma tx/rx descriptors's parameters in chain mode
enet_descriptors_ring_init initialize the dma tx/rx descriptors's parameters in ring mode
enet_frame_receive handle current received frame data to application buffer
enet_frame_transmit handle application buffer data to transmit it
configure the transmit IP frame checksum offload calculation
enet_transmit_checksum_config
and insertion
ENET Tx and Rx function enable (include MAC and DMA
enet_enable
module)
ENET Tx and Rx function disable (include MAC and DMA
enet_disable
module)
enet_mac_address_set configure MAC address
enet_mac_address_get get MAC address
enet_flag_get get the ENET MAC/MSC/PTP/DMA status flag
enet_flag_clear clear the ENET DMA status flag
enet_interrupt_enable enable ENET MAC/MSC/DMA interrupt
enet_interrupt_disable disable ENET MAC/MSC/DMA interrupt
enet_interrupt_flag_get get ENET MAC/MSC/DMA interrupt flag
enet_interrupt_flag_clear clear ENET DMA interrupt flag
MAC function
enet_tx_enable ENET Tx function enable (include MAC and DMA module)
enet_tx_disable ENET Tx function disable (include MAC and DMA module)
enet_rx_enable ENET Rx function enable (include MAC and DMA module)
enet_rx_disable ENET Rx function disable (include MAC and DMA module)
enet_registers_get put registers value into the application buffer
enet_debug_status_get get the enet debug status from the debug register
enet_address_filter_enable enable the MAC address filter
enet_address_filter_disable disable the MAC address filter
enet_address_filter_config configure the MAC address filter
PHY interface configuration (configure SMI clock and reset
enet_phy_config
PHY chip)
enet_phy_write_read write to/read from a PHY register
enet_phyloopback_enable enable the loopback function of phy chip
enet_phyloopback_disable disable the loopback function of phy chip
enet_forward_feature_enable enable ENET forward feature
enet_forward_feature_disable disable ENET forward feature
enet_fliter_feature_enable enable ENET fliter feature
enet_fliter_feature_disable disable ENET fliter feature
flow control function

166
GD32E50x Firmware Library User Guide
Function name Function description
generate the pause frame, ENET will send pause frame after
enet_pauseframe_generate
enable transmit flow control
enet_pauseframe_detect_config configure the pause frame detect type
enet_pauseframe_config configure the pause frame parameters
configure the threshold of the flow control(deactive and active
enet_flowcontrol_threshold_config
threshold)
enet_flowcontrol_feature_enable enable ENET flow control feature
enet_flowcontrol_feature_disable disable ENET flow control feature
DMA function
enet_dmaprocess_state_get get the dma transmit/receive process state
enet_dmaprocess_resume poll the dma transmission/reception enable
enet_rxprocess_check_recovery check and recover the Rx process
flush the ENET transmit fifo, and wait until the flush operation
enet_txfifo_flush
completes
get the transmit/receive address of current descriptor, or
enet_current_desc_address_get
current buffer, or descriptor table
enet_desc_information_get get the Tx or Rx descriptor information
enet_missed_frame_counter_get get the number of missed frames during receiving
descriptor function
enet_desc_flag_get get the bit flag of ENET dma descriptor
enet_desc_flag_set set the bit flag of ENET dma tx descriptor
enet_desc_flag_clear clear the bit flag of ENET dma tx descriptor
enet_rx_desc_immediate_receive_co when receiving the completed, set RS bit in
mplete_interrupt ENET_DMA_STAT register will immediately set
when receiving the completed, set RS bit in
enet_rx_desc_delay_receive_complet
ENET_DMA_STAT register will is set after a configurable
e_interrupt
delay time
enet_rxframe_drop drop current receive frame
enet_dma_feature_enable enable DMA feature
enet_dma_feature_disable disable DMA feature
enhanced descriptor
enet_rx_desc_enhanced_status_get get the bit of extended status flag in ENET DMA descriptor
enet_desc_select_enhanced_mode configure descriptor to work in enhanced mode
enet_ptp_enhanced_descriptors_chai initialize the dma Tx/Rx descriptors's parameters in enhanced
n_init chain mode with ptp function
enet_ptp_enhanced_descriptors_ring initialize the dma Tx/Rx descriptors's parameters in enhanced
_init ring mode with ptp function
enet_ptpframe_receive_enhanced_m receive a packet data with timestamp values to application
ode buffer, when the DMA is in enhanced mode
enet_ptpframe_transmit_enhanced_m send data with timestamp values in application buffer as a
ode transmit packet, when the DMA is in enhanced mode
normal descriptor
167
GD32E50x Firmware Library User Guide
Function name Function description
enet_desc_select_normal_mode configure descriptor to work in normal mode
enet_ptp_normal_descriptors_chain_i initialize the dma Tx/Rx descriptors's parameters in normal
nit chain mode with ptp function
initialize the dma Tx/Rx descriptors's parameters in normal
enet_ptp_normal_descriptors_ring_init
ring mode with ptp function
receive a packet data with timestamp values to application
enet_ptpframe_receive_normal_mode
buffer, when the DMA is in normal mode
enet_ptpframe_transmit_normal_mod send data with timestamp values in application buffer as a
e transmit packet, when the DMA is in normal mode
WUM function
enet_wum_filter_register_pointer_res
wakeup frame filter register pointer reset
et
enet_wum_filter_config set the remote wakeup frame registers
enet_wum_feature_enable enable wakeup management features
enet_wum_feature_disable disable wakeup management features
MSC function
enet_msc_counters_reset reset the MAC statistics counters
enet_msc_feature_enable enable the MAC statistics counter features
enet_msc_feature_disable disable the MAC statistics counter features
enet_msc_counters_preset_config configure MAC statistics counters preset mode
enet_msc_counters_get get MAC statistics counter
PTP function
enet_ptp_subsecond_2_nanosecond change subsecond to nanosecond
enet_ptp_nanosecond_2_subsecond change nanosecond to subsecond
enet_ptp_feature_enable enable the PTP features
enet_ptp_feature_disable disable the PTP features
enet_ptp_timestamp_function_config configure the PTP timestamp function
enet_ptp_subsecond_increment_confi
configure the PTP system time subsecond increment value
g
enet_ptp_timestamp_addend_config adjusting the PTP clock frequency only in fine update mode
initializing or adding/subtracting to second of the PTP system
enet_ptp_timestamp_update_config
time
enet_ptp_expected_time_config configure the PTP expected target time
enet_ptp_system_time_get get the PTP current system time
enet_ptp_pps_output_frequency_confi
configure the PPS output frequency
g
enet_ptp_start configure and start PTP timestamp counter
enet_ptp_finecorrection_adjfreq adjust frequency in fine method by configure addend register
enet_ptp_coarsecorrection_systime_u
update system time in coarse method
pdate
enet_ptp_finecorrection_settime set system time in fine method
enet_ptp_flag_get get the ptp flag status
168
GD32E50x Firmware Library User Guide
Function name Function description
internal function
reset the ENET initpara struct, call it before using
enet_initpara_reset
enet_initpara_config()

Structure enet_initpara_struct

Table 3-204. Structure enet_initpara_struct


member name Function description
option_enable select which function to configure
forward_frame frame forward related parameters
dmabus_mode DMA bus mode related parameters
dma_maxburst DMA max burst related parameters
dma_arbitration DMA Tx and Rx arbitration related parameters
store_forward_mode store forward mode related parameters
dma_function DMA control related parameters
vlan_config VLAN tag related parameters
flow_control flow control related parameters
hashtable_high hash list high 32-bit related parameters
hashtable_low hash list low 32-bit related parameters
framesfilter_mode frame filter control related parameters
halfduplex_param halfduplex related parameters
timer_config frame timer related parameters
interframegap inter frame gap related parameters

Structure enet_descriptors_struct

Table 3-205. Structure enet_descriptors_struct


member name Function description
status status
control_buffer_size control and buffer1, buffer2 lengths
buffer1_addr buffer1 address pointer/timestamp low
buffer2_next_desc_
buffer2 or next descriptor address pointer/timestamp high
addr
extended_status extended status
reserved reserved
timestamp_low timestamp low
timestamp_high timestamp high

Structure enet_ptp_systime_struct

Table 3-206. Structure enet_ptp_systime_struct


member name Function description
second second of system time

169
GD32E50x Firmware Library User Guide
nanosecond nanosecond of system time
sign sign of system time

Enum enet_flag_enum

Table 3-207. Enum enet_flag_enum


member name Function description
ENET_MAC_FLAG_
magic packet received flag
MPKR
ENET_MAC_FLAG_
wakeup frame received flag
WUFR
ENET_MAC_FLAG_
flow control status flag
FLOWCONTROL
ENET_MAC_FLAG_
WUM status flag
WUM
ENET_MAC_FLAG_
MSC status flag
MSC
ENET_MAC_FLAG_
MSC receive status flag
MSCR
ENET_MAC_FLAG_
MSC transmit status flag
MSCT
ENET_MAC_FLAG_
timestamp trigger status flag
TMST
ENET_PTP_FLAG_
timestamp second counter overflow flag
TSSCO
ENET_PTP_FLAG_
target time match flag
TTM
ENET_MSC_FLAG_
received frames CRC error flag
RFCE
ENET_MSC_FLAG_
received frames alignment error flag
RFAE
ENET_MSC_FLAG_
received good unicast frames flag
RGUF
ENET_MSC_FLAG_
transmitted good frames single collision flag
TGFSC
ENET_MSC_FLAG_
transmitted good frames more single collision flag
TGFMSC
ENET_MSC_FLAG_
transmitted good frames flag
TGF
ENET_DMA_FLAG_
transmit status flag
TS
ENET_DMA_FLAG_
transmit process stopped status flag
TPS

170
GD32E50x Firmware Library User Guide
ENET_DMA_FLAG_
transmit buffer unavailable status flag
TBU
ENET_DMA_FLAG_
transmit jabber timeout status flag
TJT
ENET_DMA_FLAG_
receive overflow status flag
RO
ENET_DMA_FLAG_
transmit underflow status flag
TU
ENET_DMA_FLAG_
receive status flag
RS
ENET_DMA_FLAG_
receive buffer unavailable status flag
RBU
ENET_DMA_FLAG_
receive process stopped status flag
RPS
ENET_DMA_FLAG_
receive watchdog timeout status flag
RWT
ENET_DMA_FLAG_
early transmit status flag
ET
ENET_DMA_FLAG_
fatal bus error status flag
FBE
ENET_DMA_FLAG_
early receive status flag
ER
ENET_DMA_FLAG_
abnormal interrupt summary flag
AI
ENET_DMA_FLAG_
normal interrupt summary flag
NI
ENET_DMA_FLAG_
error during data transfer by RxDMA/TxDMA flag
EB_DMA_ERROR
ENET_DMA_FLAG_
EB_TRANSFER_E error during write/read transfer flag
RROR
ENET_DMA_FLAG_
EB_ACCESS_ERR error during data buffer/descriptor access flag
OR
ENET_DMA_FLAG_
MSC status flag
MSC
ENET_DMA_FLAG_
WUM status flag
WUM
ENET_DMA_FLAG_
timestamp trigger status flag
TST

171
GD32E50x Firmware Library User Guide
Enum enet_flag_clear_enum

Table 3-208. Enum enet_flag_clear_enum


member name Function description
ENET_DMA_FLAG_
transmit status flag clear
TS_CLR
ENET_DMA_FLAG_
transmit process stopped status flag clear
TPS_CLR
ENET_DMA_FLAG_
transmit buffer unavailable status flag clear
TBU_CLR
ENET_DMA_FLAG_
transmit jabber timeout status flag clear
TJT_CLR
ENET_DMA_FLAG_
receive overflow status flag clear
RO_CLR
ENET_DMA_FLAG_
transmit underflow status flag clear
TU_CLR
ENET_DMA_FLAG_
receive status flag clear
RS_CLR
ENET_DMA_FLAG_
receive buffer unavailable status flag clear
RBU_CLR
ENET_DMA_FLAG_
receive process stopped status flag clear
RPS_CLR
ENET_DMA_FLAG_
receive watchdog timeout status flag clear
RWT_CLR
ENET_DMA_FLAG_
early transmit status flag clear
ET_CLR
ENET_DMA_FLAG_
fatal bus error status flag clear
FBE_CLR
ENET_DMA_FLAG_
early receive status flag clear
ER_CLR
ENET_DMA_FLAG_
abnormal interrupt summary flag clear
AI_CLR
ENET_DMA_FLAG_
normal interrupt summary flag clear
NI_CLR

Enum enet_int_enum

Table 3-209. Enum enet_int_enum


member name Function description
ENET_MAC_INT_W
WUM interrupt mask
UMIM
ENET_MAC_INT_T
timestamp trigger interrupt mask
MSTIM
ENET_MSC_INT_R received frame CRC error interrupt mask
172
GD32E50x Firmware Library User Guide
FCEIM
ENET_MSC_INT_R
received frames alignment error interrupt mask
FAEIM
ENET_MSC_INT_R
received good unicast frames interrupt mask
GUFIM
ENET_MSC_INT_T
transmitted good frames single collision interrupt mask
GFSCIM
ENET_MSC_INT_T
transmitted good frames more single collision interrupt mask
GFMSCIM
ENET_MSC_INT_T
transmitted good frames interrupt mask
GFIM
ENET_DMA_INT_TI
transmit interrupt enable
E
ENET_DMA_INT_T
transmit process stopped interrupt enable
PSIE
ENET_DMA_INT_T
transmit buffer unavailable interrupt enable
BUIE
ENET_DMA_INT_T
transmit jabber timeout interrupt enable
JTIE
ENET_DMA_INT_R
receive overflow interrupt enable
OIE
ENET_DMA_INT_T
transmit underflow interrupt enable
UIE
ENET_DMA_INT_RI
receive interrupt enable
E
ENET_DMA_INT_R
receive buffer unavailable interrupt enable
BUIE
ENET_DMA_INT_R
receive process stopped interrupt enable
PSIE
ENET_DMA_INT_R
receive watchdog timeout interrupt enable
WTIE
ENET_DMA_INT_E
early transmit interrupt enable
TIE
ENET_DMA_INT_F
fatal bus error interrupt enable
BEIE
ENET_DMA_INT_E
early receive interrupt enable
RIE
ENET_DMA_INT_AI
abnormal interrupt summary enable
E
ENET_DMA_INT_NI
normal interrupt summary enable
E

173
GD32E50x Firmware Library User Guide
Enum enet_int_flag_enum

Table 3-210. Enum enet_int_flag_enum


member name Function description
ENET_MAC_INT_F
WUM status flag
LAG_WUM
ENET_MAC_INT_F
MSC status flag
LAG_MSC
ENET_MAC_INT_F
MSC receive status flag
LAG_MSCR
ENET_MAC_INT_F
MSC transmit status flag
LAG_MSCT
ENET_MAC_INT_F
time stamp trigger status flag
LAG_TMST
ENET_MSC_INT_F
received frames CRC error flag
LAG_RFCE
ENET_MSC_INT_F
received frames alignment error flag
LAG_RFAE
ENET_MSC_INT_F
received good unicast frames flag
LAG_RGUF
ENET_MSC_INT_F
transmitted good frames single collision flag
LAG_TGFSC
ENET_MSC_INT_F
transmitted good frames more single collision flag
LAG_TGFMSC
ENET_MSC_INT_F
transmitted good frames flag
LAG_TGF
ENET_DMA_INT_F
transmit status flag
LAG_TS
ENET_DMA_INT_F
transmit process stopped status flag
LAG_TPS
ENET_DMA_INT_F
transmit buffer unavailable status flag
LAG_TBU
ENET_DMA_INT_F
transmit jabber timeout status flag
LAG_TJT
ENET_DMA_INT_F
receive overflow status flag
LAG_RO
ENET_DMA_INT_F
transmit underflow status flag
LAG_TU
ENET_DMA_INT_F
receive status flag
LAG_RS
ENET_DMA_INT_F
receive buffer unavailable status flag
LAG_RBU
ENET_DMA_INT_F receive process stopped status flag

174
GD32E50x Firmware Library User Guide
LAG_RPS
ENET_DMA_INT_F
receive watchdog timeout status flag
LAG_RWT
ENET_DMA_INT_F
early transmit status flag
LAG_ET
ENET_DMA_INT_F
fatal bus error status flag
LAG_FBE
ENET_DMA_INT_F
early receive status flag
LAG_ER
ENET_DMA_INT_F
abnormal interrupt summary flag
LAG_AI
ENET_DMA_INT_F
normal interrupt summary flag
LAG_NI
ENET_DMA_INT_F
MSC status flag
LAG_MSC
ENET_DMA_INT_F
WUM status flag
LAG_WUM
ENET_DMA_INT_F
timestamp trigger status flag
LAG_TST

Enum enet_int_flag_clear_enum

Table 3-211. Enum enet_int_flag_clear_enum


member name Function description
ENET_DMA_INT_F
transmit status flag
LAG_TS_CLR
ENET_DMA_INT_F
transmit process stopped status flag
LAG_TPS_CLR
ENET_DMA_INT_F
transmit buffer unavailable status flag
LAG_TBU_CLR
ENET_DMA_INT_F
transmit jabber timeout status flag
LAG_TJT_CLR
ENET_DMA_INT_F
receive overflow status flag
LAG_RO_CLR
ENET_DMA_INT_F
transmit underflow status flag
LAG_TU_CLR
ENET_DMA_INT_F
receive status flag
LAG_RS_CLR
ENET_DMA_INT_F
receive buffer unavailable status flag
LAG_RBU_CLR
ENET_DMA_INT_F
receive process stopped status flag
LAG_RPS_CLR
ENET_DMA_INT_F receive watchdog timeout status flag

175
GD32E50x Firmware Library User Guide
LAG_RWT_CLR
ENET_DMA_INT_F
early transmit status flag
LAG_ET_CLR
ENET_DMA_INT_F
fatal bus error status flag
LAG_FBE_CLR
ENET_DMA_INT_F
early receive status flag
LAG_ER_CLR
ENET_DMA_INT_F
abnormal interrupt summary flag
LAG_AI_CLR
ENET_DMA_INT_F
normal interrupt summary flag
LAG_NI_CLR

Enum enet_desc_reg_enum

Table 3-212. Enum enet_desc_reg_enum


member name Function description
ENET_RX_DESC_T
the start address of the receive descriptor table
ABLE
ENET_RX_CURRE the start descriptor address of the current receive descriptor read by the
NT_DESC RxDMA controller
ENET_RX_CURRE
the current receive buffer address being read by the RxDMA controller
NT_BUFFER
ENET_TX_DESC_T
the start address of the transmit descriptor table
ABLE
ENET_TX_CURRE the start descriptor address of the current transmit descriptor read by the
NT_DESC TxDMA controller
ENET_TX_CURRE
the current transmit buffer address being read by the TxDMA controller
NT_BUFFER

Enum enet_msc_counter_enum

Table 3-213. Enum enet_msc_counter_enum


member name Function description
ENET_MSC_TX_S
MSC transmitted good frames after a single collision counter
CCNT
ENET_MSC_TX_M
MSC transmitted good frames after more than a single collision counter
SCCNT
ENET_MSC_TX_T
MSC transmitted good frames counter
GFCNT
ENET_MSC_RX_R
MSC received frames with CRC error counter
FCECNT
ENET_MSC_RX_R
MSC received frames with alignment error counter
FAECNT
ENET_MSC_RX_R MSC received good unicast frames counter

176
GD32E50x Firmware Library User Guide
GUFCNT

Enum enet_option_enum

Table 3-214. Enum enet_option_enum


member name Function description
FORWARD_OPTIO
choose to configure the frame forward related parameters
N
DMABUS_OPTION choose to configure the DMA bus mode related parameters
DMA_MAXBURST_
choose to configure the DMA max burst related parameters
OPTION
DMA_ARBITRATIO
choose to configure the DMA arbitration related parameters
N_OPTION
STORE_OPTION choose to configure the store forward mode related parameters
DMA_OPTION choose to configure the DMA related parameters
VLAN_OPTION choose to configure vlan related parameters
FLOWCTL_OPTION choose to configure flow control related parameters
HASHH_OPTION choose to configure hash high
HASHL_OPTION choose to configure hash low
FILTER_OPTION choose to configure frame filter related parameters
HALFDUPLEX_OPT
choose to configure halfduplex mode related parameters
ION
TIMER_OPTION choose to configure time counter related parameters
INTERFRAMEGAP_
choose to configure the inter frame gap related parameters
OPTION

Enum enet_mediamode_enum

Table 3-215. Enum enet_mediamode_enum


member name Function description
ENET_AUTO_NEG
PHY auto negotiation
OTIATION
ENET_100M_FULL
100Mbit/s, full-duplex
DUPLEX
ENET_100M_HALF
100Mbit/s, half-duplex
DUPLEX
ENET_10M_FULLD
10Mbit/s, full-duplex
UPLEX
ENET_10M_HALFD
10Mbit/s, half-duplex
UPLEX
ENET_LOOPBACK
MAC in loopback mode at the MII
MODE

177
GD32E50x Firmware Library User Guide
Enum enet_chksumconf_enum

Table 3-216. Enum enet_chksumconf_enum


member name Function description
ENET_NO_AUTOC
disable IP frame checksum function
HECKSUM
ENET_AUTOCHEC
KSUM_DROP_FAIL enable IP frame checksum function
FRAMES
ENET_AUTOCHEC
enable IP frame checksum function, and the received frame with only payload
KSUM_ACCEPT_F
error but no other errors will not be dropped
AILFRAMES

Enum enet_frmrecept_enum

Table 3-217. Enum enet_frmrecept_enum


member name Function description
ENET_PROMISCU
promiscuous mode enabled
OUS_MODE
ENET_RECEIVEAL
all received frame are forwarded to application
L
ENET_BROADCAS
the address filters pass all received broadcast frames
T_FRAMES_PASS
ENET_BROADCAS
the address filters filter all incoming broadcast frames
T_FRAMES_DROP

Enum enet_registers_type_enum

Table 3-218. Enum enet_registers_type_enum


member name Function description
ALL_MAC_REG get the registers within the offset scope range ENET_MAC_CFG to
ENET_MAC_FCTH
ALL_MSC_REG get the registers within the offset scope range ENET_MSC_CTL to
ENET_MSC_RGUFCNT
ALL_PTP_REG get the registers within the offset scope range ENET_PTP_TSCTL to
ENET_PTP_PPSCTL
ALL_DMA_REG get the registers within the offset scope range ENET_DMA_BCTL to
ENET_DMA_CRBADDR

Enum enet_dmadirection_enum

Table 3-219. Enum enet_dmadirection_enum


member name Function description
ENET_DMA_TX DMA Tx descriptors

178
GD32E50x Firmware Library User Guide
ENET_DMA_RX DMA Rx descriptors

Enum enet_phydirection_enum

Table 3-220. Enum enet_phydirection_enum


member name Function description
ENET_PHY_WRITE write data to phy register
ENET_PHY_READ read data from phy register

Enum enet_regdirection_enum

Table 3-221. Enum enet_regdirection_enum


member name Function description
ENET_REG_READ read register
ENET_REG_WRITE write register

Enum enet_macaddress_enum

Table 3-222. Enum enet_macaddress_enum


member name Function description
ENET_MAC_ADDR
set MAC address 0 filter
ESS0
ENET_MAC_ADDR
set MAC address 1 filter
ESS1
ENET_MAC_ADDR
set MAC address 2 filter
ESS2
ENET_MAC_ADDR
set MAC address 3 filter
ESS3

Enum enet_descstate_enum

Table 3-223. Enum enet_descstate_enum


member name Function description
TXDESC_COLLISI
the number of collisions occurred before the frame was transmitted
ON_COUNT
TXDESC_BUFFER_
the buffer1 address of the Tx frame
1_ADDR
RXDESC_FRAME_
the byte length of the received frame that was transferred to the buffer
LENGTH
RXDESC_BUFFER
receive buffer 1 size
_1_SIZE
RXDESC_BUFFER
receive buffer 2 size
_2_SIZE
RXDESC_BUFFER
the buffer1 address of the Rx frame
_1_ADDR
179
GD32E50x Firmware Library User Guide
Enum enet_msc_preset_enum

Table 3-224. Enum enet_msc_preset_enum


member name Function description
ENET_MSC_PRES
do not preset MSC counter
ET_NONE
ENET_MSC_PRES
preset all MSC counters to almost-half(0x7FFF FFF0) value
ET_HALF
ENET_MSC_PRES
preset all MSC counters to almost-full(0xFFFF FFF0) value
ET_FULL

enet_deinit

The description of enet_deinit is shown as below:

Table 3-225. Function enet_deinit


Function name enet_deinit
Function prototype void enet_deinit(void);
Function descriptions deinitialize the ENET, and reset structure parameters for ENET initialization
Precondition -
The called functions rcu_periph_reset_enable() /rcu_periph_reset_disable()/enet_initpara_reset()
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize the ENET */

enet_deinit( );

enet_initpara_config

The description of enet_initpara_config is shown as below:

Table 3-226. Function enet_initpara_config


Function name enet_initpara_config
Function prototype void enet_initpara_config(enet_option_enum option, uint32_t para)
configure the parameters which are usually less cared for initialization, this
Function descriptions function must be called before enet_init(), otherwise configuration will be no
effect
Precondition enet_initpara_reset(void)
The called functions -

180
GD32E50x Firmware Library User Guide
Input parameter{in}
different function option, which is related to several parameters, refer to
option Enum enet_option_enum
only one parameter can be selected which is shown as below
FORWARD_OPTION choose to configure the frame forward related parameters
DMABUS_OPTION choose to configure the DMA bus mode related parameters
DMA_MAXBURST_OP
choose to configure the DMA max burst related parameters
TION
DMA_ARBITRATION_
choose to configure the DMA arbitration related parameters
OPTION
STORE_OPTION choose to configure the store forward mode related parameters
DMA_OPTION choose to configure the DMA related parameters
VLAN_OPTION choose to configure vlan related parameters
FLOWCTL_OPTION choose to configure flow control related parameters
HASHH_OPTION choose to configure hash high
HASHL_OPTION choose to configure hash low
FILTER_OPTION choose to configure frame filter related parameters
HALFDUPLEX_OPTIO
choose to configure halfduplex mode related parameters
N
TIMER_OPTION choose to configure time counter related parameters
INTERFRAMEGAP_OP
choose to configure the inter frame gap related parameters
TION
Input parameter{in}
para
all the related values should be configured which are shown as below
(the value according to
example: para = (value1 | value2 | value3…)
the parameter option)
When value of parameter option is FORWARD_OPTION
ENET_AUTO_PADCRC_DROP_ENABLE /
value1
ENET_AUTO_PADCRC_DROP_DISABLE
ENET_FORWARD_ERRFRAMES_ENABLE /
value2
ENET_FORWARD_ERRFRAMES_DISABLE
ENET_FORWARD_UNDERSZ_GOODFRAMES_ENABLE /
value3
ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE
ENET_FORWARD_UNDERSZ_GOODFRAMES_ENABLE /
value4
ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE
When value of parameter option is DMABUS_OPTION
value1 ENET_ADDRESS_ALIGN_ENABLE / ENET_ADDRESS_ALIGN_DISABLE
value2 ENET_FIXED_BURST_ENABLE / ENET_FIXED_BURST_DISABLE
value3 ENET_MIXED_BURST_ENABLE/ ENET_MIXED_BURST_DISABLE
When value of parameter option is DMA_MAXBURST_OPTION
ENET_RXDP_1BEAT / ENET_RXDP_2BEAT/ ENET_RXDP_4BEAT /
value1 ENET_RXDP_8BEAT / ENET_RXDP_16BEAT / ENET_RXDP_32BEAT /
ENET_RXDP_4xPGBL_4BEAT / ENET_RXDP_4xPGBL_8BEAT /
181
GD32E50x Firmware Library User Guide
ENET_RXDP_4xPGBL_16BEAT / ENET_RXDP_4xPGBL_32BEAT /
ENET_RXDP_4xPGBL_64BEAT / ENET_RXDP_4xPGBL_128BEAT
ENET_PGBL_1BEAT / ENET_PGBL_2BEAT / ENET_PGBL_4BEAT /
ENET_PGBL_8BEAT / ENET_PGBL_16BEAT / ENET_PGBL_32BEAT /
value2 ENET_PGBL_4xPGBL_4BEAT / ENET_PGBL_4xPGBL_8BEAT /
ENET_PGBL_4xPGBL_16BEAT / ENET_PGBL_4xPGBL_32BEAT /
ENET_PGBL_4xPGBL_64BEAT / ENET_PGBL_4xPGBL_128BEAT
value3 ENET_RXTX_DIFFERENT_PGBL / ENET_RXTX_SAME_PGBL
When value of parameter option is DMA_ARBITRATION_OPTION
value1 ENET_ARBITRATION_RXPRIORTX
ENET_ARBITRATION_RXTX_1_1 / ENET_ARBITRATION_RXTX_2_1 /
value2
ENET_ARBITRATION_RXTX_3_1 / ENET_ARBITRATION_RXTX_4_1
When value of parameter option is STORE_OPTION
ENET_RX_MODE_STOREFORWARD /
value1
ENET_RX_MODE_CUTTHROUGH
value2 ENET_TX_MODE_STOREFORWARD / ENET_TX_MODE_CUTTHROUGH
ENET_RX_THRESHOLD_64BYTES / ENET_RX_THRESHOLD_32BYTES /
value3
ENET_RX_THRESHOLD_96BYTES / ENET_RX_THRESHOLD_128BYTES
ENET_TX_THRESHOLD_64BYTES / ENET_TX_THRESHOLD_128BYTES
/ ENET_TX_THRESHOLD_192BYTES /
value4 ENET_TX_THRESHOLD_256BYTES / ENET_TX_THRESHOLD_40BYTES
/ ENET_TX_THRESHOLD_32BYTES / ENET_TX_THRESHOLD_24BYTES
/ ENET_TX_THRESHOLD_16BYTES
When value of parameter option is DMA_OPTION
ENET_FLUSH_RXFRAME_ENABLE /
value1
ENET_FLUSH_RXFRAME_DISABLE
ENET_SECONDFRAME_OPT_ENABLE /
value2
ENET_SECONDFRAME_OPT_DISABLE
value3 ENET_ENHANCED_DESCRIPTOR/ ENET_NORMAL_DESCRIPTOR
When value of parameter option is VLAN_OPTION
ENET_VLANTAGCOMPARISON_12BIT/
value1
ENET_VLANTAGCOMPARISON_16BIT
value2 MAC_VLT_VLTI(regval)
When value of parameter option is FLOWCTL_OPTION
value1 MAC_FCTL_PTM(regval)
ENET_ZERO_QUANTA_PAUSE_ENABLE /
value2
ENET_ZERO_QUANTA_PAUSE_DISABLE
ENET_PAUSETIME_MINUS4 / ENET_PAUSETIME_MINUS28 /
value3
ENET_PAUSETIME_MINUS144/ENET_PAUSETIME_MINUS256
ENET_MAC0_AND_UNIQUE_ADDRESS_PAUSEDETECT /
value4
ENET_UNIQUE_PAUSEDETECT
ENET_RX_FLOWCONTROL_ENABLE /
value5
ENET_RX_FLOWCONTROL_DISABLE

182
GD32E50x Firmware Library User Guide
ENET_TX_FLOWCONTROL_ENABLE /
value6
ENET_TX_FLOWCONTROL_DISABLE
When value of parameter option is HASHH_OPTION
value1 0x0~0xFFFF FFFFU
When value of parameter option is HASHL_OPTION
value1 0x0~0xFFFF FFFFU
When value of parameter option is FILTER_OPTION
ENET_SRC_FILTER_NORMAL_ENABLE /
value1
ENET_SRC_FILTER_INVERSE_ENABLE / ENET_SRC_FILTER_DISABLE
ENET_DEST_FILTER_INVERSE_ENABLE /
value2
ENET_DEST_FILTER_INVERSE_DISABLE
ENET_MULTICAST_FILTER_HASH_OR_PERFECT /
ENET_MULTICAST_FILTER_HASH /
value3
ENET_MULTICAST_FILTER_PERFECT /
ENET_MULTICAST_FILTER_NONE
ENET_UNICAST_FILTER_EITHER / ENET_UNICAST_FILTER_HASH /
value4
ENET_UNICAST_FILTER_PERFECT
ENET_PCFRM_PREVENT_ALL /
value5 ENET_PCFRM_PREVENT_PAUSEFRAME /
ENET_PCFRM_FORWARD_ALL / ENET_PCFRM_FORWARD_FILTERED
When value of parameter option is HALFDUPLEX_OPTION
value1 ENET_CARRIERSENSE_ENABLE / ENET_CARRIERSENSE_DISABLE
value2 ENET_RECEIVEOWN_ENABLE / ENET_RECEIVEOWN_DISABLE
ENET_RETRYTRANSMISSION_ENABLE /
value3
ENET_RETRYTRANSMISSION_DISABLE
ENET_BACKOFFLIMIT_10 / ENET_BACKOFFLIMIT_8 /
value4
ENET_BACKOFFLIMIT_4 / ENET_BACKOFFLIMIT_1
ENET_DEFERRALCHECK_ENABLE /
value5
ENET_DEFERRALCHECK_DISABLE
When value of parameter option is TIMER_OPTION
value1 ENET_WATCHDOG_ENABLE / ENET_WATCHDOG_DISABLE
value2 ENET_JABBER_ENABLE / ENET_JABBER_DISABLE
When value of parameter option is INTERFRAMEGAP_OPTION
ENET_INTERFRAMEGAP_96BIT / ENET_INTERFRAMEGAP_88BIT /
ENET_INTERFRAMEGAP_80BIT / ENET_INTERFRAMEGAP_72BIT /
value1
ENET_INTERFRAMEGAP_64BIT / ENET_INTERFRAMEGAP_56BIT /
ENET_INTERFRAMEGAP_48BIT / ENET_INTERFRAMEGAP_40BIT
Output parameter{out}
- -
Return value
- -

Example:

183
GD32E50x Firmware Library User Guide
/* config DMA option of the ENET */

enet_initpara_reset();

enet_initpara_config(DMA_OPTION, ENET_FLUSH_RXFRAME_ENABLE | ENET_SECO


NDFRAME_OPT_ENABLE | ENET_NORMAL_DESCRIPTOR);

enet_init

The description of enet_init is shown as below:

Table 3-227. Function enet_init


Function name enet_init
ErrStatus enet_init(enet_mediamode_enum mediamode,
Function prototype
enet_chksumconf_enum checksum, enet_frmrecept_enum recept);
initialize ENET peripheral with generally concerned parameters and the less
Function descriptions
cared parameters
Precondition enet_deinit ()
The called functions enet_phy_config /enet_phy_write_read
Input parameter{in}
PHY mode and mac loopback configurations, refer to Enum
mediamode
enet_mediamode_enum, only one parameter can be selected
ENET_AUTO_NEGOTI
PHY auto negotiation
ATION
ENET_100M_FULLDU
100Mbit/s, full-duplex
PLEX
ENET_100M_HALFDU
100Mbit/s, half-duplex
PLEX
ENET_10M_FULLDUP
10Mbit/s, full-duplex
LEX
ENET_10M_HALFDUP
10Mbit/s, half-duplex
LEX
ENET_LOOPBACKMO
MAC in loopback mode at the MII
DE
Input parameter{in}
IP frame checksum offload function, refer to Enum
checksum
enet_chksumconf_enum, only one parameter can be selected
ENET_NO_AUTOCHE
disable IP frame checksum function
CKSUM
ENET_AUTOCHECKS
UM_DROP_FAILFRAM enable IP frame checksum function
ES
ENET_AUTOCHECKS
enable IP frame checksum function, and the received frame with only
UM_ACCEPT_FAILFR
payload error but no other errors will not be dropped
AMES

184
GD32E50x Firmware Library User Guide
Input parameter{in}
frame filter function, refer to Enum enet_frmrecept_enum, only one
recept
parameter can be selected
ENET_PROMISCUOU
promiscuous mode enabled
S_MODE
ENET_RECEIVEALL all received frame are forwarded to application
ENET_BROADCAST_F
the address filters pass all received broadcast frames
RAMES_PASS
ENET_BROADCAST_F
the address filters filter all incoming broadcast frames
RAMES_DROP
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* initialize ENET peripheral */

ErrStatus enet_init_status;

enet_init_status = enet_init(ENET_AUTO_NEGOTIATION, ENET_AUTOCHECKSUM_DR


OP_FAILFRAMES, ENET_BROADCAST_FRAMES_PASS);

enet_software_reset

The description of enet_software_reset is shown as below:

Table 3-228. Function enet_software_reset


Function name enet_software_reset
Function prototype ErrStatus enet_software_reset(void);
Function descriptions reset all core internal registers located in CLK_TX and CLK_RX
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* reset all core internal registers located in CLK_TX and CLK_RX */

ErrStatus reval_state = ERROR;

reval_state = enet_software_reset();
185
GD32E50x Firmware Library User Guide
enet_rxframe_size_get

The description of enet_rxframe_size_get is shown as below:

Table 3-229. Function enet_rxframe_size_get

Function name enet_rxframe_size_get

Function prototype uint32_t enet_rxframe_size_get(void);

Function descriptions check receive frame valid and return frame size

Precondition -

The called functions enet_rxframe_drop()

Input parameter{in}

- -

Output parameter{out}

- -

Return value

uint32_t size of received frame 0x0 - 0x3FFF

Example:

/* check receive frame valid */

uint32_t reval;

reval = enet_rxframe_size_get();

enet_descriptors_chain_init

The description of enet_descriptors_chain_init is shown as below:

Table 3-230. Function enet_descriptors_chain_init


Function name enet_descriptors_chain_init
Function prototype void enet_descriptors_chain_init(enet_dmadirection_enum direction);
Function descriptions initialize the DMA Tx/Rx descriptors's parameters in chain mode
Precondition -
The called functions -
Input parameter{in}
the descriptors which users want to init, refer to Enum
direction enet_dmadirection_enum
only one parameter can be selected which is shown as below
ENET_DMA_TX DMA Tx descriptors
ENET_DMA_RX DMA Rx descriptors

186
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the DMA Tx/Rx descriptors's parameters in chain mode */

enet_descriptors_chain_init(ENET_DMA_TX);

enet_descriptors_ring_init

The description of enet_descriptors_ring_init is shown as below:

Table 3-231. Function enet_descriptors_ring_init


Function name enet_descriptors_ring_init
Function prototype void enet_descriptors_ring_init(enet_dmadirection_enum direction);
Function descriptions initialize the DMA Tx/Rx descriptors's parameters in ring mode
Precondition -
The called functions -
Input parameter{in}
the descriptors which users want to init, refer to Enum
direction enet_dmadirection_enum
only one parameter can be selected which is shown as below
ENET_DMA_TX DMA Tx descriptors
ENET_DMA_RX DMA Rx descriptors
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the DMA Tx/Rx descriptors's parameters in ring mode */

enet_descriptors_ring_init(ENET_DMA_TX);

enet_frame_receive

The description of enet_frame_receive is shown as below:

Table 3-232. Function enet_frame_receive


Function name enet_frame_receive
Function prototype ErrStatus enet_frame_receive(uint8_t *buffer, uint32_t bufsize);
Function descriptions handle current received frame data to application buffer
Precondition -
The called functions -
187
GD32E50x Firmware Library User Guide
Input parameter{in}
bufsize the size of buffer which is the parameter in function, (0 -- 1524)
Output parameter{out}
pointer to the received frame data
buffer
if the input is NULL, user should copy data in application by himself
Return value
ErrStatus ERROR or SUCCESS

Example:

/* transfer received frame data to application buffer */

uint8_t data_buffer[1500];

uint32_t data_size;

enet_frame_receive(data_buffer, &data_size);

enet_frame_transmit

The description of enet_frame_transmit is shown as below:

Table 3-233. Function enet_frame_transmit


Function name enet_frame_transmit
Function prototype ErrStatus enet_frame_transmit(uint8_t *buffer, uint32_t length);
Function descriptions handle application buffer data to transmit it
Precondition -
The called functions -
Input parameter{in}
pointer to the frame data to be transmitted
buffer
if the input is NULL, user should handle the data in application by himself
Input parameter{in}
length the length of frame data to be transmitted, (0 -- 1524)
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* transfer buffer data of application */

uint8_t data_buffer[1500];

uint32_t data_size = 800;

enet_frame_transmit (data_buffer, data_size);

188
GD32E50x Firmware Library User Guide
enet_transmit_checksum_config

The description of enet_transmit_checksum_config is shown as below:

Table 3-234. Function enet_transmit_checksum_config


Function name enet_transmit_checksum_config
ErrStatus enet_transmit_checksum_config(enet_descriptors_struct *desc,
Function prototype
uint32_t checksum);
Function descriptions configure the transmit IP frame checksum offload calculation and insertion
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to configure, the structure members
desc
can refer to Structure enet_descriptors_struct
Input parameter{in}
IP frame checksum configuration
checksum
only one parameter can be selected which is shown as below
ENET_CHECKSUM_DI
checksum insertion disabled
SABLE
ENET_CHECKSUM_IP
only IP header checksum calculation and insertion are enabled
V4HEADER
ENET_CHECKSUM_T
CPUDPICMP_SEGME TCP/UDP/ICMP checksum insertion calculated but pseudo-header
NT
ENET_CHECKSUM_T
TCP/UDP/ICMP checksum insertion fully calculated
CPUDPICMP_FULL
Output parameter{out}

Return value
ErrStatus ERROR or SUCCESS

Example:

/* configure the transmit IP frame checksum offload calculation and insertion */

enet_descriptors_struct rx_desc;

enet_transmit_checksum_config(rx_desc, ENET_CHECKSUM_TCPUDPICMP_FULL);

enet_enable

The description of enet_enable is shown as below:

Table 3-235. Function enet_enable


Function name enet_enable
Function prototype void enet_enable(void);
Function descriptions ENET Tx and Rx function enable (include MAC and DMA module)
189
GD32E50x Firmware Library User Guide
Precondition -
The called functions enet_tx_enable() /enet_rx_enable()
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the ENET */

enet_enable();

enet_disable

The description of enet_disable is shown as below:

Table 3-236. Function enet_disable


Function name enet_disable
Function prototype void enet_disable(void);
Function descriptions ENET Tx and Rx function disable (include MAC and DMA module)
Precondition -
The called functions enet_tx_disable() /enet_rx_disable()
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the ENET */

enet_disable();

enet_mac_address_set

The description of enet_mac_address_set is shown as below:

Table 3-237. Function enet_mac_address_set


Function name enet_mac_address_set
void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t
Function prototype
paddr[]);
Function descriptions configure MAC address
Precondition -
190
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
select which MAC address will be set, refer to Enum
mac_addr enet_macaddress_enum only one parameter can be selected which is
shown as below
ENET_MAC_ADDRES
set MAC address 0 filter
S0
ENET_MAC_ADDRES
set MAC address 1 filter
S1
ENET_MAC_ADDRES
set MAC address 2 filter
S2
ENET_MAC_ADDRES
set MAC address 3 filter
S3
Input parameter{in}
the buffer pointer which stores the MAC address
paddr little-ending store, such as MAC address is aa:bb:cc:dd:ee:22, the buffer is
{22, ee, dd, cc, bb, aa}
Output parameter{out}
- -
Return value
- -

Example:

/* config mac address */

netif->hwaddr[0] = 0x02;

netif->hwaddr[1] = 0xaa;

netif->hwaddr[2] = 0xbb;

netif->hwaddr[3] = 0xcc;

netif->hwaddr[4] = 0xdd;

netif->hwaddr[5] = 0xee;

enet_mac_address_set(ENET_MAC_ADDRESS0, netif->hwaddr);

enet_mac_address_get

The description of enet_mac_address_get is shown as below:

Table 3-238. Function enet_mac_address_get


Function name enet_mac_address_get
ErrStatus enet_mac_address_get(enet_macaddress_enum mac_addr,
Function prototype
uint8_t paddr[], uint8_t bufsize);
Function descriptions get MAC address
191
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
select which MAC address will be set, refer to Enum
mac_addr enet_macaddress_enum only one parameter can be selected which is
shown as below
ENET_MAC_ADDRES
set MAC address 0 filter
S0
ENET_MAC_ADDRES
set MAC address 1 filter
S1
ENET_MAC_ADDRES
set MAC address 2 filter
S2
ENET_MAC_ADDRES
set MAC address 3 filter
S3
Output parameter{out}
the buffer pointer which stores the MAC address
paddr little-ending store, such as MAC address is aa:bb:cc:dd:ee:22, the buffer is
{22, ee, dd, cc, bb, aa}
Input parameter{in}
bufsize refer to the size of the buffer which stores the MAC address
Return value
- -

Example:

/* get mac address */

enet_mac_address_get (ENET_MAC_ADDRESS0, netif->hwaddr, 0x100);

enet_flag_get

The description of enet_flag_get is shown as below:

Table 3-239. Function enet_flag_get


Function name enet_flag_get
Function prototype FlagStatus enet_flag_get(enet_flag_enum enet_flag);
Function descriptions get the ENET MAC/MSC/PTP/DMA status flag
Precondition -
The called functions -
Input parameter{in}
ENET status flag, refer to Enum enet_flag_enum
enet_flag
only one parameter can be selected which is shown as below
ENET_MAC_FLAG_MP
magic packet received flag
KR
ENET_MAC_FLAG_W wakeup frame received flag

192
GD32E50x Firmware Library User Guide
UFR
ENET_MAC_FLAG_FL
flow control status flag
OWCONTROL
ENET_MAC_FLAG_W
WUM status flag
UM
ENET_MAC_FLAG_MS
MSC status flag
C
ENET_MAC_FLAG_MS
MSC receive status flag
CR
ENET_MAC_FLAG_MS
MSC transmit status flag
CT
ENET_MAC_FLAG_TM
time stamp trigger status flag
ST
ENET_PTP_FLAG_TS
timestamp second counter overflow flag
SCO
ENET_PTP_FLAG_TT
target time match flag
M
ENET_MSC_FLAG_RF
received frames CRC error flag
CE
ENET_MSC_FLAG_RF
received frames alignment error flag
AE
ENET_MSC_FLAG_RG
received good unicast frames flag
UF
ENET_MSC_FLAG_TG
transmitted good frames single collision flag
FSC
ENET_MSC_FLAG_TG
transmitted good frames more single collision flag
FMSC
ENET_MSC_FLAG_TG
transmitted good frames flag
F
ENET_DMA_FLAG_TS transmit status flag
ENET_DMA_FLAG_TP
transmit process stopped status flag
S
ENET_DMA_FLAG_TB
transmit buffer unavailable status flag
U
ENET_DMA_FLAG_TJ
transmit jabber timeout status flag
T
ENET_DMA_FLAG_RO receive overflow status flag
ENET_DMA_FLAG_TU transmit underflow status flag
ENET_DMA_FLAG_RS receive status flag
ENET_DMA_FLAG_RB
receive buffer unavailable status flag
U
ENET_DMA_FLAG_RP
receive process stopped status flag
S

193
GD32E50x Firmware Library User Guide
ENET_DMA_FLAG_R
receive watchdog timeout status flag
WT
ENET_DMA_FLAG_ET early transmit status flag
ENET_DMA_FLAG_FB
fatal bus error status flag
E
ENET_DMA_FLAG_ER early receive status flag
ENET_DMA_FLAG_AI abnormal interrupt summary flag
ENET_DMA_FLAG_NI normal interrupt summary flag
ENET_DMA_FLAG_EB
DMA error flag
_DMA_ERROR
ENET_DMA_FLAG_EB
transfer error flag
_TRANSFER_ERROR
ENET_DMA_FLAG_EB
access error flag
_ACCESS_ERROR
ENET_DMA_FLAG_MS
MSC status flag
C
ENET_DMA_FLAG_W
WUM status flag
UM
ENET_DMA_FLAG_TS
timestamp trigger status flag
T
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* check whether the specified flag bit is set */

enet_flag_get (ENET_DMA_FLAG_RS);

enet_flag_clear

The description of enet_flag_clear is shown as below:

Table 3-240. Function enet_flag_clear


Function name enet_flag_clear
Function prototype void enet_flag_clear(enet_flag_clear_enum enet_flag);
Function descriptions clear the ENET DMA status flag
Precondition -
The called functions -
Input parameter{in}
ENET DMA flag clear, refer to Enum enet_flag_clear_enum
enet_flag
only one parameter can be selected which is shown as below
ENET_DMA_FLAG_TS transmit status flag clear

194
GD32E50x Firmware Library User Guide
_CLR
ENET_DMA_FLAG_TP
transmit process stopped status flag clear
S_CLR
ENET_DMA_FLAG_TB
transmit buffer unavailable status flag clear
U_CLR
ENET_DMA_FLAG_TJ
transmit jabber timeout status flag clear
T_CLR
ENET_DMA_FLAG_RO
receive overflow status flag clear
_CLR
ENET_DMA_FLAG_TU
transmit underflow status flag clear
_CLR
ENET_DMA_FLAG_RS
receive status flag clear
_CLR
ENET_DMA_FLAG_RB
receive buffer unavailable status flag clear
U_CLR
ENET_DMA_FLAG_RP
receive process stopped status flag clear
S_CLR
ENET_DMA_FLAG_R
receive watchdog timeout status flag clear
WT_CLR
ENET_DMA_FLAG_ET
early transmit status flag clear
_CLR
ENET_DMA_FLAG_FB
fatal bus error status flag clear
E_CLR
ENET_DMA_FLAG_ER
early receive status flag clear
_CLR
ENET_DMA_FLAG_AI_
abnormal interrupt summary flag clear
CLR
ENET_DMA_FLAG_NI
normal interrupt summary flag clear
_CLR
Output parameter{out}
- -
Return value
- -

Example:

/* clear the specified flag bit */

enet_flag_clear(ENET_DMA_FLAG_RS_CLR);

enet_interrupt_enable

The description of enet_interrupt_enable is shown as below:

195
GD32E50x Firmware Library User Guide
Table 3-241. Function enet_interrupt_enable
Function name enet_interrupt_enable
Function prototype void enet_interrupt_enable(enet_int_enum enet_int);
Function descriptions enable ENET MAC/MSC/DMA interrupt
Precondition -
The called functions -
Input parameter{in}
ENET interrupt, refer to Enum enet_int_enum
enet_int
only one parameter can be selected which is shown as below
ENET_MAC_INT_WUM
WUM interrupt mask
IM
ENET_MAC_INT_TMS
timestamp trigger interrupt mask
TIM
ENET_MSC_INT_RFC
received frame CRC error interrupt mask
EIM
ENET_MSC_INT_RFA
received frames alignment error interrupt mask
EIM
ENET_MSC_INT_RGU
received good unicast frames interrupt mask
FIM
ENET_MSC_INT_TGF
transmitted good frames single collision interrupt mask
SCIM
ENET_MSC_INT_TGF
transmitted good frames more single collision interrupt mask
MSCIM
ENET_MSC_INT_TGFI
transmitted good frames interrupt mask
M
ENET_DMA_INT_TIE transmit interrupt enable
ENET_DMA_INT_TPSI
transmit process stopped interrupt enable
E
ENET_DMA_INT_TBUI
transmit buffer unavailable interrupt enable
E
ENET_DMA_INT_TJTI
transmit jabber timeout interrupt enable
E
ENET_DMA_INT_ROIE receive overflow interrupt enable
ENET_DMA_INT_TUIE transmit underflow interrupt enable
ENET_DMA_INT_RIE receive interrupt enable
ENET_DMA_INT_RBUI
receive buffer unavailable interrupt enable
E
ENET_DMA_INT_RPSI
receive process stopped interrupt enable
E
ENET_DMA_INT_RWT
receive watchdog timeout interrupt enable
IE
ENET_DMA_INT_ETIE early transmit interrupt enable
ENET_DMA_INT_FBEI fatal bus error interrupt enable

196
GD32E50x Firmware Library User Guide
E
ENET_DMA_INT_ERIE early receive interrupt enable
ENET_DMA_INT_AIE abnormal interrupt summary enable
ENET_DMA_INT_NIE normal interrupt summary enable
Output parameter{out}
- -
Return value
- -

Example:

/* enable normal interrupt summary */

enet_interrupt_enable(ENET_DMA_INT_NIE);

enet_interrupt_disable

The description of enet_interrupt_disable is shown as below:

Table 3-242. Function enet_interrupt_disable


Function name enet_interrupt_disable
Function prototype void enet_interrupt_disable(enet_int_enum enet_int);
Function descriptions disable ENET MAC/MSC/DMA interrupt
Precondition -
The called functions -
Input parameter{in}
ENET interrupt, refer to Enum enet_int_enum
enet_int
only one parameter can be selected which is shown as below
ENET_MAC_INT_WUM
WUM interrupt mask
IM
ENET_MAC_INT_TMS
timestamp trigger interrupt mask
TIM
ENET_MSC_INT_RFC
received frame CRC error interrupt mask
EIM
ENET_MSC_INT_RFA
received frames alignment error interrupt mask
EIM
ENET_MSC_INT_RGU
received good unicast frames interrupt mask
FIM
ENET_MSC_INT_TGF
transmitted good frames single collision interrupt mask
SCIM
ENET_MSC_INT_TGF
transmitted good frames more single collision interrupt mask
MSCIM
ENET_MSC_INT_TGFI
transmitted good frames interrupt mask
M
ENET_DMA_INT_TIE transmit interrupt enable

197
GD32E50x Firmware Library User Guide
ENET_DMA_INT_TPSI
transmit process stopped interrupt enable
E
ENET_DMA_INT_TBUI
transmit buffer unavailable interrupt enable
E
ENET_DMA_INT_TJTI
transmit jabber timeout interrupt enable
E
ENET_DMA_INT_ROIE receive overflow interrupt enable
ENET_DMA_INT_TUIE transmit underflow interrupt enable
ENET_DMA_INT_RIE receive interrupt enable
ENET_DMA_INT_RBUI
receive buffer unavailable interrupt enable
E
ENET_DMA_INT_RPSI
receive process stopped interrupt enable
E
ENET_DMA_INT_RWT
receive watchdog timeout interrupt enable
IE
ENET_DMA_INT_ETIE early transmit interrupt enable
ENET_DMA_INT_FBEI
fatal bus error interrupt enable
E
ENET_DMA_INT_ERIE early receive interrupt enable
ENET_DMA_INT_AIE abnormal interrupt summary enable
ENET_DMA_INT_NIE normal interrupt summary enable
Output parameter{out}
- -
Return value
- -

Example:

/* disable normal interrupt summary */

enet_interrupt_disable(ENET_DMA_INT_NIE);

enet_interrupt_flag_get

The description of enet_interrupt_flag_get is shown as below:

Table 3-243. Function enet_interrupt_flag_get


Function name enet_interrupt_flag_get
Function prototype FlagStatus enet_interrupt_flag_get(enet_int_flag_enum int_flag);
Function descriptions get ENET MAC/MSC/DMA interrupt flag
Precondition -
The called functions -
Input parameter{in}
ENET interrupt flag, refer to Enum enet_int_flag_enum
int_flag
only one parameter can be selected which is shown as below

198
GD32E50x Firmware Library User Guide
ENET_MAC_INT_FLA
WUM status flag
G_WUM
ENET_MAC_INT_FLA
MSC status flag
G_MSC
ENET_MAC_INT_FLA
MSC receive status flag
G_MSCR
ENET_MAC_INT_FLA
MSC transmit status flag
G_MSCT
ENET_MAC_INT_FLA
time stamp trigger status flag
G_TMST
ENET_MSC_INT_FLA
received frames CRC error flag
G_RFCE
ENET_MSC_INT_FLA
received frames alignment error flag
G_RFAE
ENET_MSC_INT_FLA
received good unicast frames flag
G_RGUF
ENET_MSC_INT_FLA
transmitted good frames single collision flag
G_TGFSC
ENET_MSC_INT_FLA
transmitted good frames more single collision flag
G_TGFMSC
ENET_MSC_INT_FLA
transmitted good frames flag
G_TGF
ENET_DMA_INT_FLA
transmit status flag
G_TS
ENET_DMA_INT_FLA
transmit process stopped status flag
G_TPS
ENET_DMA_INT_FLA
transmit buffer unavailable status flag
G_TBU
ENET_DMA_INT_FLA
transmit jabber timeout status flag
G_TJT
ENET_DMA_INT_FLA
receive overflow status flag
G_RO
ENET_DMA_INT_FLA
transmit underflow status flag
G_TU
ENET_DMA_INT_FLA
receive status flag
G_RS
ENET_DMA_INT_FLA
receive buffer unavailable status flag
G_RBU
ENET_DMA_INT_FLA
receive process stopped status flag
G_RPS
ENET_DMA_INT_FLA
receive watchdog timeout status flag
G_RWT
ENET_DMA_INT_FLA early transmit status flag

199
GD32E50x Firmware Library User Guide
G_ET
ENET_DMA_INT_FLA
fatal bus error status flag
G_FBE
ENET_DMA_INT_FLA
early receive status flag
G_ER
ENET_DMA_INT_FLA
abnormal interrupt summary flag
G_AI
ENET_DMA_INT_FLA
normal interrupt summary flag
G_NI
ENET_DMA_INT_FLA
MSC status flag
G_MSC
ENET_DMA_INT_FLA
WUM status flag
G_WUM
ENET_DMA_INT_FLA
timestamp trigger status flag
G_TST
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* check whether the specified flag bit is set or not */

enet_interrupt_flag_get(ENET_DMA_INT_FLAG_RS);

enet_interrupt_flag_clear

The description of enet_interrupt_flag_clear is shown as below:

Table 3-244. Function enet_interrupt_flag_clear


Function name enet_interrupt_flag_clear
Function prototype void enet_interrupt_flag_clear(enet_int_flag_clear_enum int_flag_clear);
Function descriptions clear ENET DMA interrupt flag
Precondition -
The called functions -
Input parameter{in}
clear ENET interrupt flag, refer to Enum enet_flag_clear_enum. only one
int_flag_clear
parameter can be selected which is shown as below
ENET_DMA_INT_FLA
transmit status flag
G_TS_CLR
ENET_DMA_INT_FLA
transmit process stopped status flag
G_TPS_CLR
ENET_DMA_INT_FLA
transmit buffer unavailable status flag
G_TBU_CLR

200
GD32E50x Firmware Library User Guide
ENET_DMA_INT_FLA
transmit jabber timeout status flag
G_TJT_CLR
ENET_DMA_INT_FLA
receive overflow status flag
G_RO_CLR
ENET_DMA_INT_FLA
transmit underflow status flag
G_TU_CLR
ENET_DMA_INT_FLA
receive status flag
G_RS_CLR
ENET_DMA_INT_FLA
receive buffer unavailable status flag
G_RBU_CLR
ENET_DMA_INT_FLA
receive process stopped status flag
G_RPS_CLR
ENET_DMA_INT_FLA
receive watchdog timeout status flag
G_RWT_CLR
ENET_DMA_INT_FLA
early transmit status flag
G_ET_CLR
ENET_DMA_INT_FLA
fatal bus error status flag
G_FBE_CLR
ENET_DMA_INT_FLA
early receive status flag
G_ER_CLR
ENET_DMA_INT_FLA
abnormal interrupt summary flag
G_AI_CLR
ENET_DMA_INT_FLA
normal interrupt summary flag
G_NI_CLR
Output parameter{out}
- -
Return value
- -

Example:

/* clear receive status flag bit */

enet_interrupt_flag_clear(ENET_DMA_INT_FLAG_RS);

enet_tx_enable

The description of enet_tx_enable is shown as below:

Table 3-245. Function enet_tx_enable


Function name enet_tx_enable
Function prototype void enet_tx_enable(void);
Function descriptions ENET Tx function enable (include MAC and DMA module)
Precondition -
The called functions enet_txfifo_flush()

201
GD32E50x Firmware Library User Guide
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable transport function of MAC and DMA */

enet_tx_enable();

enet_tx_disable

The description of enet_tx_disable is shown as below:

Table 3-246. Function enet_tx_disable


Function name enet_tx_disable
Function prototype void enet_tx_disable(void);
Function descriptions ENET Tx function disable (include MAC and DMA module)
Precondition -
The called functions enet_txfifo_flush()
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable transport function of MAC and DMA */

enet_tx_disable();

enet_rx_enable

The description of enet_rx_enable is shown as below:

Table 3-247. Function enet_rx_enable


Function name enet_rx_enable
Function prototype void enet_rx_enable(void);
Function descriptions ENET Rx function enable (include MAC and DMA module)
Precondition -
The called functions -
Input parameter{in}
- -
202
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* enable reception function of MAC and DMA */

enet_rx_enable();

enet_rx_disable

The description of enet_rx_disable is shown as below:

Table 3-248. Function enet_rx_disable


Function name enet_rx_disable
Function prototype void enet_rx_disable(void);
Function descriptions ENET Rx function disable (include MAC and DMA module)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable reception function of MAC and DMA */

enet_rx_disable();

enet_registers_get

The description of enet_registers_get is shown as below:

Table 3-249. Function enet_registers_get


Function name enet_registers_get
void enet_registers_get(enet_registers_type_enum type, uint32_t *preg,
Function prototype
uint32_t num);
Function descriptions put registers value into the application buffer
Precondition -
The called functions -
Input parameter{in}
type register type which will be get, refer to Enum enet_registers_type_enum
only one parameter can be selected which is shown as below
203
GD32E50x Firmware Library User Guide
ALL_MAC_REG get the registers within the offset scope range ENET_MAC_CFG to
ENET_MAC_FCTH
ALL_MSC_REG get the registers within the offset scope range ENET_MSC_CTL to
ENET_MSC_RGUFCNT
ALL_PTP_REG get the registers within the offset scope range ENET_PTP_TSCTL to
ENET_PTP_PPSCTL
ALL_DMA_REG get the registers within the offset scope range ENET_DMA_BCTL to
ENET_DMA_CRBADDR
Input parameter{in}
num the number of registers that the user want to get, (0 -- 54)
Output parameter{out}
preg the application buffer pointer for storing the register value
Return value
- -

Example:

/* get all mac registers value */

uint32_t register_buffer[5];

enet_registers_get(ALL_MAC_REG, 5, register_buffer);

enet_debug_status_get

The description of enet_debug_status_get is shown as below:

Table 3-250. Function enet_debug_status_get


Function name enet_debug_status_get
Function prototype uint32_t enet_debug_status_get(uint32_t mac_debug);
Function descriptions get the enet debug status from the debug register
Precondition -
The called functions --
Input parameter{in}
enet debug status
mac_debug
only one parameter can be selected which is shown as below
ENET_MAC_RECEIVE
MAC receiver is not in idle state
R_NOT_IDLE
ENET_RX_ASYNCHR
Rx asynchronous FIFO status
ONOUS_FIFO_STATE
ENET_RXFIFO_WRITI
RxFIFO is doing write operation
NG
ENET_RXFIFO_READ
RxFIFO read operation status
_STATUS
ENET_RXFIFO_STATE RxFIFO state
ENET_MAC_TRANSMI MAC transmitter is not in idle state

204
GD32E50x Firmware Library User Guide
TTER_NOT_IDLE
ENET_MAC_TRANSMI
status of MAC transmitter
TTER_STATUS
ENET_PAUSE_CONDI
pause condition status
TION_STATUS
ENET_TXFIFO_READ_
TxFIFO read operation status
STATUS
ENET_TXFIFO_WRITI
TxFIFO is doing write operation
NG
ENET_TXFIFO_NOT_E
TxFIFO is not empty
MPTY
ENET_TXFIFO_FULL TxFIFO is full
Output parameter{out}
- -
Return value
uint32_t value of the status users want to get

Example:

/* get debug message of RxFIFO state */

uint32_t debug_value;

debug_value = enet_debug_status_get (ENET_RXFIFO_STATE);

enet_address_filter_enable

The description of enet_address_filter_enable is shown as below:

Table 3-251. Function enet_address_filter_enable


Function name enet_address_filter_enable
Function prototype void enet_address_filter_enable(enet_macaddress_enum mac_addr);
Function descriptions enable the MAC address filter
Precondition -
The called functions --
Input parameter{in}
select which MAC address will be enable refer to Enum
mac_addr enet_macaddress_enum. only one parameter can be selected which is
shown as below
ENET_MAC_ADDRES
enable MAC address 1 filter
S1
ENET_MAC_ADDRES
enable MAC address 2 filter
S2
ENET_MAC_ADDRES
enable MAC address 3 filter
S3
Output parameter{out}

205
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* enable the MAC address 1 filter */

enet_address_filter_enable(ENET_MAC_ADDRESS1);

enet_address_filter_disable

The description of enet_address_filter_disable is shown as below:

Table 3-252. Function enet_address_filter_disable


Function name enet_address_filter_disable
Function prototype void enet_address_filter_disable(enet_macaddress_enum mac_addr);
Function descriptions disable the MAC address filter
Precondition -
The called functions -
Input parameter{in}
select which MAC address will be enable, refer to Enum
mac_addr enet_macaddress_enum. only one parameter can be selected which is
shown as below
ENET_MAC_ADDRES
enable MAC address 1 filter
S1
ENET_MAC_ADDRES
enable MAC address 2 filter
S2
ENET_MAC_ADDRES
enable MAC address 3 filter
S3
Output parameter{out}
- -
Return value
- -

Example:

/* disable the MAC address 1 filter */

enet_address_filter_disable(ENET_MAC_ADDRESS1);

enet_address_filter_config

The description of enet_address_filter_config is shown as below:

Table 3-253. Function enet_address_filter_config


Function name enet_address_filter_config
Function prototype void enet_address_filter_config(enet_macaddress_enum mac_addr,

206
GD32E50x Firmware Library User Guide
uint32_t addr_mask, uint32_t filter_type);
Function descriptions configure the MAC address filter
Precondition -
The called functions -
Input parameter{in}
select which MAC address will be enable, refer to Enum
mac_addr enet_macaddress_enum. only one parameter can be selected which is
shown as below
ENET_MAC_ADDRES
enable MAC address 1 filter
S1
ENET_MAC_ADDRES
enable MAC address 2 filter
S2
ENET_MAC_ADDRES
enable MAC address 3 filter
S3
Input parameter{in}
select which MAC address bytes will be mask
addr_mask
one or more parameters can be selected which are shown as below
ENET_ADDRESS_MA
mask ENET_MAC_ADDR1L[7:0] bits
SK_BYTE0
ENET_ADDRESS_MA
mask ENET_MAC_ADDR1L[15:8] bits
SK_BYTE1
ENET_ADDRESS_MA
mask ENET_MAC_ADDR1L[23:16] bits
SK_BYTE2
ENET_ADDRESS_MA
mask ENET_MAC_ADDR1L [31:24] bits
SK_BYTE3
ENET_ADDRESS_MA
mask ENET_MAC_ADDR1H [7:0] bits
SK_BYTE4
ENET_ADDRESS_MA
mask ENET_MAC_ADDR1H [15:8] bits
SK_BYTE5
Input parameter{in}
select which MAC address filter type will be selected
filter_type
only one parameter can be selected which is shown as below
ENET_ADDRESS_FILT The MAC address is used to compared with the SA field of the received
ER_SA frame
ENET_ADDRESS_FILT The MAC address is used to compared with the DA field of the received
ER_DA frame
Output parameter{out}
- -
Return value
- -

Example:

/* config the MAC address 1 filter */


207
GD32E50x Firmware Library User Guide
enet_address_filter_config(ENET_MAC_ADDRESS1, ENET_ADDRESS_MASK_BYTE0 |
ENET_ADDRESS_MASK_BYTE1 | ENET_ADDRESS_MASK_BYTE2, ENET_ADDRESS
_FILTER_DA);

enet_phy_config

The description of enet_phy_config is shown as below:

Table 3-254. Function enet_phy_config


Function name enet_phy_config
Function prototype ErrStatus enet_phy_config(void);
Function descriptions PHY interface configuration (configure SMI clock and reset PHY chip)
Precondition -
The called functions rcu_clock_freq_get()/enet_phy_write_read()
Input parameter{in}
- -
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* config PHY interface */

enet_phy_config();

enet_phy_write_read

The description of enet_phy_write_read is shown as below:

Table 3-255. Function enet_phy_write_read


Function name enet_phy_write_read
ErrStatus enet_phy_write_read(enet_phydirection_enum direction, uint16_t
Function prototype
phy_address, uint16_t phy_reg, uint16_t *pvalue);
Function descriptions write to / read from a PHY register
Precondition -
The called functions -
Input parameter{in}
refer to Enum enet_phydirection_enum, only one parameter can be
direction
selected which is shown as below
ENET_PHY_WRITE write data to phy register
ENET_PHY_READ read data from phy register
Input parameter{in}
phy_address 0x0 - 0x1F
Input parameter{in}

208
GD32E50x Firmware Library User Guide
phy_reg 0x0 - 0x1F
Input parameter{in}
pvalue the value will be written to the PHY register in ENET_PHY_WRITE direction
Output parameter{out}
pvalue the value will be read from the PHY register in ENET_PHY_READ direction
Return value
ErrStatus ERROR or SUCCESS

Example:

/* write 0 to PHY BCR register */

uint16_t temp_phy = 0U;

phy_state = enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR,


&temp_phy);

enet_phyloopback_enable

The description of enet_phyloopback_enable is shown as below:

Table 3-256. Function enet_phyloopback_enable


Function name enet_phyloopback_enable
Function prototype ErrStatus enet_phyloopback_enable(void);
Function descriptions enable the loopback function of PHY chip
Precondition -
The called functions enet_phy_write_read()
Input parameter{in}
- -
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* enable the loopback function of PHY chip */

ErrStatus phy_state = ERROR;

phy_state = enet_phyloopback_enable();

enet_phyloopback_disable

The description of enet_phyloopback_disable is shown as below:

Table 3-257. Function enet_phyloopback_disable


Function name enet_phyloopback_disable
Function prototype ErrStatus enet_phyloopback_disable(void);

209
GD32E50x Firmware Library User Guide
Function descriptions disable the loopback function of PHY chip
Precondition -
The called functions enet_phy_write_read
Input parameter{in}
- -
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* disable the loopback function of PHY chip */

ErrStatus phy_state = ERROR;

phy_state = enet_phyloopback_disable();

enet_forward_feature_enable

The description of enet_forward_feature_enable is shown as below:

Table 3-258. Function enet_forward_feature_enable


Function name enet_forward_feature_enable
Function prototype void enet_forward_feature_enable(uint32_t feature);
Function descriptions enable ENET forward feature
Precondition -
The called functions -
Input parameter{in}
the feature of ENET forward mode
feature
one or more parameters can be selected which are shown as below
ENET_AUTO_PADCR
the function of the MAC strips the Pad/FCS field on received frames
C_DROP
ENET_TYPEFRAME_C the function that FCS field(last 4 bytes) of frame will be dropped before
RC_DROP forwarding
ENET_FORWARD_ER the function that all frame received with error except runt error are
RFRAMES forwarded to memory
ENET_FORWARD_UN
DERSZ_GOODFRAME the function that forwarding undersized good frames
S
Output parameter{out}
- -
Return value
- -

Example:

210
GD32E50x Firmware Library User Guide
/* enable the function that forwarding undersized good frames */

enet_forward_feature_enable(ENET_FORWARD_UNDERSZ_GOODFRAMES);

enet_forward_feature_disable

The description of enet_forward_feature_disable is shown as below:

Table 3-259. Function enet_forward_feature_disable


Function name enet_forward_feature_disable
Function prototype void enet_forward_feature_disable(uint32_t feature);
Function descriptions disable ENET forward feature
Precondition -
The called functions -
Input parameter{in}
the feature of ENET forward mode
feature
one or more parameters can be selected which are shown as below
ENET_AUTO_PADCR
the function of the MAC strips the Pad/FCS field on received frames
C_DROP
ENET_TYPEFRAME_C the function that FCS field(last 4 bytes) of frame will be dropped before
RC_DROP forwarding
ENET_FORWARD_ER the function that all frame received with error except runt error are
RFRAMES forwarded to memory
ENET_FORWARD_UN
DERSZ_GOODFRAME the function that forwarding undersized good frames
S
Output parameter{out}
- -
Return value
- -

Example:

/* enable the function that forwarding undersized good frames */

enet_forward_feature_enable(ENET_FORWARD_UNDERSZ_GOODFRAMES);

enet_fliter_feature_enable

The description of enet_fliter_feature_enable is shown as below:

Table 3-260. Function enet_fliter_feature_enable


Function name enet_fliter_feature_enable
Function prototype void enet_fliter_feature_enable(uint32_t feature);
Function descriptions enable ENET fliter feature
Precondition -
The called functions -

211
GD32E50x Firmware Library User Guide
Input parameter{in}
the feature of ENET fliter mode
feature
one or more parameters can be selected which are shown as below
ENET_SRC_FILTER filter source address function
ENET_SRC_FILTER_I
inverse source address filtering result function
NVERSE
ENET_DEST_FILTER_
inverse DA filtering result function
INVERSE
ENET_MULTICAST_FI
pass all multicast frames function
LTER_PASS
ENET_MULTICAST_FI
HASH multicast filter function
LTER_HASH_MODE
ENET_UNICAST_FILT
HASH unicast filter function
ER_HASH_MODE
ENET_FILTER_MODE
HASH or perfect filter function
_EITHER
Output parameter{out}
- -
Return value
- -

Example:

/* enable filter source address function */

enet_fliter_feature_enable(ENET_SRC_FILTER);

enet_fliter_feature_disable

The description of enet_fliter_feature_disable is shown as below:

Table 3-261. Function enet_fliter_feature_disable


Function name enet_fliter_feature_disable
Function prototype void enet_fliter_feature_disable(uint32_t feature);
Function descriptions disable ENET fliter feature
Precondition -
The called functions -
Input parameter{in}
the feature of ENET fliter mode
feature
one or more parameters can be selected which are shown as below
ENET_SRC_FILTER filter source address function
ENET_SRC_FILTER_I
inverse source address filtering result function
NVERSE
ENET_DEST_FILTER_
inverse DA filtering result function
INVERSE

212
GD32E50x Firmware Library User Guide
ENET_MULTICAST_FI
pass all multicast frames function
LTER_PASS
ENET_MULTICAST_FI
HASH multicast filter function
LTER_HASH_MODE
ENET_UNICAST_FILT
HASH unicast filter function
ER_HASH_MODE
ENET_FILTER_MODE
HASH or perfect filter function
_EITHER
Output parameter{out}
- -
Return value
- -

Example:

/* enable filter source address function */

enet_fliter_feature_enable(ENET_SRC_FILTER);

enet_pauseframe_generate

The description of enet_pauseframe_generate is shown as below:

Table 3-262. Function enet_pauseframe_generate


Function name enet_pauseframe_generate
Function prototype ErrStatus enet_pauseframe_generate(void);
generate the pause frame, ENET will send pause frame after enable
Function descriptions
transmit flow control this function only use in full-dulex mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* generate the pause frame */

ErrStatus reval;

reval = enet_pauseframe_generate();

enet_pauseframe_detect_config

The description of enet_pauseframe_detect_config is shown as below:


213
GD32E50x Firmware Library User Guide
Table 3-263. Function enet_pauseframe_detect_config
Function name enet_pauseframe_detect_config
Function prototype void enet_pauseframe_detect_config(uint32_t detect);
Function descriptions configure the pause frame detect type
Precondition -
The called functions -
Input parameter{in}
pause frame detect type
detect
only one parameter can be selected which is shown as below
ENET_MAC0_AND_UN
besides the unique multicast address, MAC can also use the MAC0 address
IQUE_ADDRESS_PAU
to detecting pause frame
SEDETECT
ENET_UNIQUE_PAUS only the unique multicast address for pause frame which is specified in
EDETECT IEEE802.3 can be detected
Output parameter{out}
- -
Return value
- -

Example:

/* config the pause frame detect type as ENET_UNIQUE_PAUSEDETECT */

enet_pauseframe_detect_config(ENET_UNIQUE_PAUSEDETECT);

enet_pauseframe_config

The description of enet_pauseframe_config is shown as below:

Table 3-264. Function enet_pauseframe_config


Function name enet_pauseframe_config
void enet_pauseframe_config(uint32_t pausetime, uint32_t
Function prototype
pause_threshold);
Function descriptions configure the pause frame parameters
Precondition -
The called functions -
Input parameter{in}
pausetime pause time in transmit pause control frame, (0 – 0xFFFF)
Input parameter{in}
the threshold of the pause timer for retransmitting frames automatically, this
pause_threshold value must make sure to be less than configured pause time, only one
parameter can be selected which is shown as below
ENET_PAUSETIME_MI
pause time minus 4 slot times
NUS4
ENET_PAUSETIME_MI pause time minus 28 slot times

214
GD32E50x Firmware Library User Guide
NUS28
ENET_PAUSETIME_MI
pause time minus 144 slot times
NUS144
ENET_PAUSETIME_MI
pause time minus 256 slot times
NUS256
Output parameter{out}
- -
Return value
- -

Example:

/* config pause time minus 4 slot times */

enet_pauseframe_config(30, ENET_PAUSETIME_MINUS4);

enet_flowcontrol_threshold_config

The description of enet_flowcontrol_threshold_config is shown as below:

Table 3-265. Function enet_flowcontrol_threshold_config


Function name enet_flowcontrol_threshold_config
Function prototype void enet_flowcontrol_threshold_config(uint32_t deactive, uint32_t active);
Function descriptions configure the threshold of the flow control(deactive and active threshold)
Precondition -
The called functions -
Input parameter{in}
the threshold of the deactive flow control, this value should always be less
deactive than active flow control value, only one parameter can be selected which is
shown as below
ENET_DEACTIVE_TH
threshold level is 256 bytes
RESHOLD_256BYTES
ENET_DEACTIVE_TH
threshold level is 512 bytes
RESHOLD_512BYTES
ENET_DEACTIVE_TH
threshold level is 768 bytes
RESHOLD_768BYTES
ENET_DEACTIVE_TH
RESHOLD_1024BYTE threshold level is 1024 bytes
S
ENET_DEACTIVE_TH
RESHOLD_1280BYTE threshold level is 1280 bytes
S
ENET_DEACTIVE_TH
RESHOLD_1536BYTE threshold level is 1536 bytes
S

215
GD32E50x Firmware Library User Guide
ENET_DEACTIVE_TH
RESHOLD_1792BYTE threshold level is 1792 bytes
S
Input parameter{in}
the threshold of the active flow control, only one parameter can be selected
active
which is shown as below
ENET_ACTIVE_THRE
threshold level is 256 bytes
SHOLD_256BYTES
ENET_ACTIVE_THRE
threshold level is 512 bytes
SHOLD_512BYTES
ENET_ACTIVE_THRE
threshold level is 768 bytes
SHOLD_768BYTES
ENET_ACTIVE_THRE
threshold level is 1024 bytes
SHOLD_1024BYTES
ENET_ACTIVE_THRE
threshold level is 1280 bytes
SHOLD_1280BYTES
ENET_ACTIVE_THRE
threshold level is 1536 bytes
SHOLD_1536BYTES
ENET_ACTIVE_THRE
threshold level is 1792 bytes
SHOLD_1792BYTES
Output parameter{out}
- -
Return value
- -

Example:

/* configure the threshold of the flow control */

enet_flowcontrol_threshold_config(ENET_DEACTIVE_THRESHOLD_256BYTES, ENET_A
CTIVE_THRESHOLD_256BYTES);

enet_flowcontrol_feature_enable

The description of enet_flowcontrol_feature_enable is shown as below:

Table 3-266. Function enet_flowcontrol_feature_enable


Function name enet_flowcontrol_feature_enable
Function prototype void enet_flowcontrol_feature_enable(uint32_t feature);
Function descriptions enable ENET flow control feature
Precondition -
The called functions -
Input parameter{in}
the feature of ENET flow control mode
feature
one or more parameters can be selected which are shown as below

216
GD32E50x Firmware Library User Guide
ENET_ZERO_QUANT
the automatic zero-quanta generation function
A_PAUSE
ENET_TX_FLOWCON
the flow control operation in the MAC
TROL
ENET_RX_FLOWCON
decoding function for the received pause frame and process it
TROL
ENET_BACK_PRESSU
back pressure operation in the MAC(only use in half-dulex mode)
RE
Output parameter{out}
- -
Return value
- -

Example:

/* enable the flow control operation in the MAC */

enet_flowcontrol_feature_enable(ENET_ZERO_QUANTA_PAUSE);

enet_flowcontrol_feature_disable

The description of enet_flowcontrol_feature_disable is shown as below:

Table 3-267. Function enet_flowcontrol_feature_disable


Function name enet_flowcontrol_feature_disable
Function prototype void enet_flowcontrol_feature_disable(uint32_t feature);
Function descriptions disable ENET flow control feature
Precondition -
The called functions -
Input parameter{in}
the feature of ENET flow control mode
feature
one or more parameters can be selected which are shown as below
ENET_ZERO_QUANT
the automatic zero-quanta generation function
A_PAUSE
ENET_TX_FLOWCON
the flow control operation in the MAC
TROL
ENET_RX_FLOWCON
decoding function for the received pause frame and process it
TROL
ENET_BACK_PRESSU
back pressure operation in the MAC(only use in half-dulex mode)
RE
Output parameter{out}
- -
Return value
- -

Example:
217
GD32E50x Firmware Library User Guide
/* disable the automatic zero-quanta generation function */

enet_flowcontrol_feature_disable(ENET_ZERO_QUANTA_PAUSE);

enet_dmaprocess_state_get

The description of enet_dmaprocess_state_get is shown as below:

Table 3-268. Function enet_dmaprocess_state_get


Function name enet_dmaprocess_state_get
Function prototype uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction);
Function descriptions get the dma transmit/receive process state
Precondition -
The called functions -
Input parameter{in}
choose the direction of DMA process which users want to resume
direction
only one parameter can be selected which is shown as below
ENET_DMA_TX DMA transmit process
ENET_DMA_RX DMA receive process
Output parameter{out}
- -
Return value
state of dma process, the value range shows below:
ENET_RX_STATE_STOPPED / ENET_RX_STATE_FETCHING /
ENET_RX_STATE_WAITING / ENET_RX_STATE_SUSPENDED /
uint32_t ENET_RX_STATE_CLOSING / ENET_RX_STATE_QUEUING /
ENET_TX_STATE_STOPPED / ENET_TX_STATE_FETCHING /
ENET_TX_STATE_WAITING / ENET_TX_STATE_READING /
ENET_TX_STATE_SUSPENDED / ENET_TX_STATE_CLOSING

Example:

/* get the dma receive process state */

uint32_t reval;

reval = enet_dmaprocess_state_get(ENET_DMA_RX);

if(ENET_RX_STATE_SUSPENDED == reval){

do…

enet_dmaprocess_resume

The description of enet_dmaprocess_resume is shown as below:

218
GD32E50x Firmware Library User Guide
Table 3-269. Function enet_dmaprocess_resume
Function name enet_dmaprocess_resume
Function prototype void enet_dmaprocess_resume(enet_dmadirection_enum direction);
poll the DMA transmission/reception enable by writing any value to the
Function descriptions ENET_DMA_TPEN/ENET_DMA_RPEN register, this will make the DMA to
resume transmission/reception
Precondition -
The called functions -
Input parameter{in}
choose the direction of DMA process which users want to resume
direction
only one parameter can be selected which is shown as below
ENET_DMA_TX DMA transmit process
ENET_DMA_RX DMA receive process
Output parameter{out}
- -
Return value
- -

Example:

/* enable DMA receive process */

enet_dmaprocess_resume(ENET_DMA_RX);

enet_rxprocess_check_recovery

The description of enet_rxprocess_check_recovery is shown as below:

Table 3-270. Function enet_rxprocess_check_recovery


Function name enet_rxprocess_check_recovery
Function prototype void enet_rxprocess_check_recovery(void);
Function descriptions check and recover the Rx process
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* check and recover the Rx process */

enet_rxprocess_check_recovery();

219
GD32E50x Firmware Library User Guide
enet_txfifo_flush

The description of enet_txfifo_flush is shown as below:

Table 3-271. Function enet_txfifo_flush


Function name enet_txfifo_flush
Function prototype ErrStatus enet_txfifo_flush(void);
Function descriptions flush the ENET transmit FIFO, and wait until the flush operation completes
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* flush the ENET transmit FIFO */

ErrStatus reval = ERROR;

reval = enet_txfifo_flush();

enet_current_desc_address_get

The description of enet_current_desc_address_get is shown as below:

Table 3-272. Function enet_current_desc_address_get


Function name enet_current_desc_address_get
Function prototype uint32_t enet_current_desc_address_get(enet_desc_reg_enum addr_get);
get the transmit/receive address of current descriptor, or current buffer, or
Function descriptions
descriptor table
Precondition -
The called functions -
Input parameter{in}
choose the address which users want to get, refer to Enum
addr_get enet_desc_reg_enum
only one parameter can be selected which is shown as below
ENET_RX_DESC_TAB
the start address of the receive descriptor table
LE
ENET_RX_CURRENT_ the start descriptor address of the current receive descriptor read by the
DESC RxDMA controller
ENET_RX_CURRENT_
the current receive buffer address being read by the RxDMA controller
BUFFER

220
GD32E50x Firmware Library User Guide
ENET_TX_DESC_TAB
the start address of the transmit descriptor table
LE
ENET_TX_CURRENT_ the start descriptor address of the current transmit descriptor read by the
DESC TxDMA controller
ENET_TX_CURRENT_
the current transmit buffer address being read by the TxDMA controller
BUFFER
Output parameter{out}
- -
Return value
uint32_t 0- 0xFFFFFFFF

Example:

/* get the start address of the receive descriptor table */

uint32_t reval;

reval = enet_current_desc_address_get(ENET_RX_DESC_TABLE);

enet_desc_information_get

The description of enet_desc_information_get is shown as below:

Table 3-273. Function enet_desc_information_get


Function name enet_desc_information_get
uint32_t enet_desc_information_get(enet_descriptors_struct *desc,
Function prototype
enet_descstate_enum info_get);
Function descriptions get the Tx or Rx descriptor information
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to get information, the structure
desc
members can refer to Structure enet_descriptors_struct
Input parameter{in}
the descriptor information type which is selected, refer to Enum
info_get enet_descstate_enum
only one parameter can be selected which is shown as below
TXDESC_COLLISION_
the number of collisions occurred before the frame was transmitted
COUNT
TXDESC_BUFFER_1_
the buffer1 address of the Tx frame
ADDR
RXDESC_FRAME_LE
the byte length of the received frame that was transferred to the buffer
NGTH
RXDESC_BUFFER_1_
receive buffer 1 size
SIZE
RXDESC_BUFFER_2_ receive buffer 2 size

221
GD32E50x Firmware Library User Guide
SIZE
RXDESC_BUFFER_1_
the buffer1 address of the Rx frame
ADDR
Output parameter{out}
- -
Return value
descriptor information if value is 0xFFFFFFFFU, means the false input
uint32_t
parameter

Example:

/* get the reception buffer 1 size */

uint32_t reval;

reval = enet_desc_information_get(rx_desc, RXDESC_BUFFER_1_SIZE);

enet_missed_frame_counter_get

The description of enet_missed_frame_counter_get is shown as below:

Table 3-274. Function enet_missed_frame_counter_get


Function name enet_missed_frame_counter_get
void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t
Function prototype
*rxdma_drop);
Function descriptions get the number of missed frames during receiving
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
rxfifo_drop pointer to the number of frames dropped by RxFIFO
Output parameter{out}
rxdma_drop pointer to the number of frames missed by the RxDMA controller
Return value
- -

Example:

/* get the number of missed frames during receiving */

uint32_t rxcnt, txcnt;

enet_missed_frame_counter_get(&rxcnt, &txcnt);

enet_desc_flag_get

The description of enet_desc_flag_get is shown as below:

222
GD32E50x Firmware Library User Guide
Table 3-275. Function enet_desc_flag_get
Function name enet_desc_flag_get
FlagStatus enet_desc_flag_get(enet_descriptors_struct *desc, uint32_t
Function prototype
desc_flag);
Function descriptions get the bit flag of ENET DMA descriptor
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to get flag, the structure members
desc
can refer to Structure enet_descriptors_struct
Input parameter{in}
desc_flag
the bit flag of ENET DMA descriptor
(the value according to
only one parameter can be selected which is shown as below
the parameter desc)
When type of parameter desc is TX
ENET_TDES0_DB deferred
ENET_TDES0_UFE underflow error
ENET_TDES0_EXD excessive deferral
ENET_TDES0_VFRM VLAN frame
ENET_TDES0_ECO excessive collision
ENET_TDES0_LCO late collision
ENET_TDES0_NCA no carrier
ENET_TDES0_LCA loss of carrier
ENET_TDES0_IPPE IP payload error
ENET_TDES0_FRMF frame flushed
ENET_TDES0_JT jabber timeout
ENET_TDES0_ES error summary
ENET_TDES0_IPHE IP header error
ENET_TDES0_TTMSS transmit timestamp status
ENET_TDES0_TCHM the second address chained mode
ENET_TDES0_TERM transmit end of ring mode
ENET_TDES0_TTSEN transmit timestamp function enable
ENET_TDES0_DPAD disable adding pad
ENET_TDES0_DCRC disable CRC
ENET_TDES0_FSG first segment
ENET_TDES0_LSG last segment
ENET_TDES0_INTC interrupt on completion
ENET_TDES0_DAV DAV bit
When type of parameter desc is RX
ENET_RDES0_PCERR payload checksum error
ENET_RDES0_CERR CRC error
ENET_RDES0_DBERR dribble bit error

223
GD32E50x Firmware Library User Guide
ENET_RDES0_RERR receive error
ENET_RDES0_RWDT receive watchdog timeout
ENET_RDES0_FRMT frame type
ENET_RDES0_LCO late collision
ENET_RDES0_IPHER
IP frame header error
R
ENET_RDES0_LDES last descriptor
ENET_RDES0_FDES first descriptor
ENET_RDES0_VTAG VLAN tag
ENET_RDES0_OERR overflow error
ENET_RDES0_LERR length error
ENET_RDES0_SAFF SA filter fail
ENET_RDES0_DERR descriptor error
ENET_RDES0_ERRS error summary
ENET_RDES0_DAFF destination address filter fail
ENET_RDES0_DAV descriptor available
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the bit flag of ENET DMA descriptor */

FlagStatus reval;

reval = enet_desc_flag_get(p_txdesc, ENET_TDES0_TCHM);

enet_desc_flag_set

The description of enet_desc_flag_set is shown as below:

Table 3-276. Function enet_desc_flag_set


Function name enet_desc_flag_set
Function prototype void enet_desc_flag_set(enet_descriptors_struct *desc, uint32_t desc_flag);
Function descriptions set the bit flag of ENET DMA descriptor
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to set flag, the structure members
desc
can refer to Structure enet_descriptors_struct
Input parameter{in}
desc_flag
the bit flag of ENET DMA descriptor
(the value according to
only one parameter can be selected which is shown as below
the parameter desc)
224
GD32E50x Firmware Library User Guide
When type of parameter desc is TX
ENET_TDES0_VFRM VLAN frame
ENET_TDES0_FRMF frame flushed
ENET_TDES0_TCHM the second address chained mode
ENET_TDES0_TERM transmit end of ring mode
ENET_TDES0_TTSEN transmit timestamp function enable
ENET_TDES0_DPAD disable adding pad
ENET_TDES0_DCRC disable CRC
ENET_TDES0_FSG first segment
ENET_TDES0_LSG last segment
ENET_TDES0_INTC interrupt on completion
ENET_TDES0_DAV DAV bit
When type of parameter desc is RX
ENET_RDES0_DAV descriptor available
Output parameter{out}
- -
Return value
- -

Example:

/* set VLAN frame bit flag of ENET DMA descriptor */

enet_desc_flag_set(p_txdesc, ENET_TDES0_VFRM);

enet_desc_flag_clear

The description of enet_desc_flag_clear is shown as below:

Table 3-277. Function enet_desc_flag_clear


Function name enet_desc_flag_clear
void enet_desc_flag_clear(enet_descriptors_struct *desc, uint32_t
Function prototype
desc_flag);
Function descriptions clear the bit flag of ENET DMA descriptor
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to set flag, the structure members
desc
can refer to Structure enet_descriptors_struct
Input parameter{in}
desc_flag
the bit flag of ENET DMA descriptor
(the value according to
only one parameter can be selected which is shown as below
the parameter desc)
When type of parameter desc is TX
ENET_TDES0_VFRM VLAN frame

225
GD32E50x Firmware Library User Guide
ENET_TDES0_FRMF frame flushed
ENET_TDES0_TCHM the second address chained mode
ENET_TDES0_TERM transmit end of ring mode
ENET_TDES0_TTSEN transmit timestamp function enable
ENET_TDES0_DPAD disable adding pad
ENET_TDES0_DCRC disable CRC
ENET_TDES0_FSG first segment
ENET_TDES0_LSG last segment
ENET_TDES0_INTC interrupt on completion
ENET_TDES0_DAV DAV bit
When type of parameter desc is RX
ENET_RDES0_DAV descriptor available
Output parameter{out}
- -
Return value
- -

Example:

/* clear VLAN frame bit flag of ENET DMA descriptor */

enet_desc_flag_clear(p_txdesc, ENET_TDES0_VFRM);

enet_rx_desc_immediate_receive_complete_interrupt

The description of enet_rx_desc_immediate_receive_complete_interrupt is shown as below:

Table 3-278. Function enet_rx_desc_immediate_receive_complete_interrupt


Function name enet_rx_desc_immediate_receive_complete_interrupt
void
Function prototype enet_rx_desc_immediate_receive_complete_interrupt(enet_descriptors_str
uct *desc);
when receiving completed, set RS bit in ENET_DMA_STAT register will
Function descriptions
immediately set
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to get flag, the structure members
desc
can refer to Structure enet_descriptors_struct
Output parameter{out}
- -
Return value
- -

Example:

226
GD32E50x Firmware Library User Guide
/* set RS bit in ENET_DMA_STAT register immediately when receving completed */

enet_rx_desc_immediate_receive_complete_interrupt(p_rxdesc);

enet_rx_desc_delay_receive_complete_interrupt

The description of enet_rx_desc_delay_receive_complete_interrupt is shown as below:

Table 3-279. Function enet_rx_desc_delay_receive_complete_interrupt


Function name enet_rx_desc_delay_receive_complete_interrupt
void
Function prototype enet_rx_desc_delay_receive_complete_interrupt(enet_descriptors_struct
*desc, uint32_t delay_time);
when receiving completed, set RS bit in ENET_DMA_STAT register will is
Function descriptions
set after a configurable delay time
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to get flag, the structure members
desc
can refer to Structure enet_descriptors_struct
Input parameter{in}
delay_time delay a time of 256*delay_time HCLK(0x00000000 - 0x000000FF)
Output parameter{out}
- -
Return value
- -

Example:

/* when receiving completed, RS bit in ENET_DMA_STAT register will be set after 256*16
HCLK */

enet_rx_desc_delay_receive_complete_interrupt(p_rxdesc, 0x00000010);

enet_rxframe_drop

The description of enet_rxframe_drop is shown as below:

Table 3-280. Function enet_rxframe_drop


Function name enet_rxframe_drop
Function prototype void enet_rxframe_drop(void);
Function descriptions drop current receive frame
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}

227
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* drop current receive frame */

enet_rxframe_drop( );

enet_dma_feature_enable

The description of enet_dma_feature_enable is shown as below:

Table 3-281. Function enet_dma_feature_enable


Function name enet_dma_feature_enable
Function prototype void enet_dma_feature_enable(uint32_t feature);
Function descriptions enable DMA feature
Precondition -
The called functions -
Input parameter{in}
the feature of DMA mode
feature
one or more parameters can be selected which are shown as below
ENET_NO_FLUSH_RX
RxDMA does not flushes frames function
FRAME
ENET_SECONDFRAM
TxDMA controller operate on second frame function
E_OPT
Output parameter{out}
- -
Return value
- -

Example:

/* enable RxDMA does not flushes frames function */

enet_dma_feature_enable(ENET_NO_FLUSH_RXFRAME);

enet_dma_feature_disable

The description of enet_dma_feature_disable is shown as below:

Table 3-282. Function enet_dma_feature_disable


Function name enet_dma_feature_disable
Function prototype void enet_dma_feature_disable(uint32_t feature);
Function descriptions disable DMA feature
Precondition -
The called functions -
228
GD32E50x Firmware Library User Guide
Input parameter{in}
the feature of DMA mode
feature
one or more parameters can be selected which are shown as below
ENET_NO_FLUSH_RX
RxDMA does not flushes frames function
FRAME
ENET_SECONDFRAM
TxDMA controller operate on second frame function
E_OPT
Output parameter{out}
- -
Return value
- -

Example:

/* disable RxDMA does not flushes frames function */

enet_dma_feature_disable(ENET_NO_FLUSH_RXFRAME);

enet_rx_desc_enhanced_status_get

The description of enet_rx_desc_enhanced_status_get is shown as below:

Table 3-283. Function enet_rx_desc_enhanced_status_get


Function name enet_rx_desc_enhanced_status_get
uint32_t enet_rx_desc_enhanced_status_get(enet_descriptors_struct
Function prototype
*desc, uint32_t desc_status);
Function descriptions get the bit of extended status flag in ENET DMA descriptor
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to get the extended status flag,the
desc
structure members can refer to Structure enet_descriptors_struct
Input parameter{in}
desc_status: the extended status want to get
desc_status
only one parameter can be selected which is shown as below
ENET_RDES4_IPPLDT IP frame payload type
ENET_RDES4_IPHER
IP frame header error
R
ENET_RDES4_IPPLDE
IP frame payload error
RR
ENET_RDES4_IPCKS
IP frame checksum bypassed
B
ENET_RDES4_IPF4 IP frame in version 4
ENET_RDES4_IPF6 IP frame in version 6
ENET_RDES4_PTPMT PTP message type

229
GD32E50x Firmware Library User Guide
ENET_RDES4_PTPOE
PTP on ethernet frame
F
ENET_RDES4_PTPVF PTP version format
Output parameter{out}
- -
Return value
- -

Example:

/* get the IP frame payload type in ENET DMA descriptor */

uint32_t status;

status = enet_rx_desc_enhanced_status_get(p_rxdesc, ENET_RDES4_IPPLDT);

enet_desc_select_enhanced_mode

The description of enet_desc_select_enhanced_mode is shown as below:

Table 3-284. Function enet_desc_select_enhanced_mode


Function name enet_desc_select_enhanced_mode
Function prototype void enet_desc_select_enhanced_mode(void);
Function descriptions configure descriptor to work in enhanced mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* configure descriptor to work in enhanced mode */

enet_desc_select_enhanced_mode();

enet_ptp_enhanced_descriptors_chain_init

The description of enet_ptp_enhanced_descriptors_chain_init is shown as below:

Table 3-285. Function enet_ptp_enhanced_descriptors_chain_init


Function name enet_ptp_enhanced_descriptors_chain_init
void enet_ptp_enhanced_descriptors_chain_init(enet_dmadirection_enum
Function prototype
direction);
Function descriptions initialize the DMA Tx/Rx descriptors's parameters in enhanced chain mode

230
GD32E50x Firmware Library User Guide
with ptp function
Precondition -
The called functions -
Input parameter{in}
the descriptors which users want to init,
direction
only one parameter can be selected which is shown as below
ENET_DMA_TX DMA Tx descriptors
ENET_DMA_RX DMA Rx descriptors
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the DMA Tx descriptors's parameters in enhanced chain mode with ptp function */

enet_ptp_enhanced_descriptors_chain_init(ENET_DMA_TX);

enet_ptp_enhanced_descriptors_ring_init

The description of enet_ptp_enhanced_descriptors_ring_init is shown as below:

Table 3-286. Function enet_ptp_enhanced_descriptors_ring_init


Function name enet_ptp_enhanced_descriptors_ring_init
void enet_ptp_enhanced_descriptors_ring_init(enet_dmadirection_enum
Function prototype
direction);
initialize the DMA Tx/Rx descriptors's parameters in enhanced ring mode
Function descriptions
with ptp function
Precondition -
The called functions -
Input parameter{in}
the descriptors which users want to init,
direction
only one parameter can be selected which is shown as below
ENET_DMA_TX DMA Tx descriptors
ENET_DMA_RX DMA Rx descriptors
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the DMA Rx descriptors's parameters in enhanced ring mode with ptp function */

enet_ptp_enhanced_descriptors_ring_init(ENET_DMA_RX);

231
GD32E50x Firmware Library User Guide
enet_ptpframe_receive_enhanced_mode

The description of enet_ptpframe_receive_enhanced_mode is shown as below:

Table 3-287. Function enet_ptpframe_receive_enhanced_mode


Function name enet_ptpframe_receive_enhanced_mode
ErrStatus enet_ptpframe_receive_enhanced_mode(uint8_t *buffer, uint32_t
Function prototype
bufsize, uint32_t timestamp[]);
receive a packet data with timestamp values to application buffer, when the
Function descriptions
DMA is in enhanced mode
Precondition -
The called functions -
Input parameter{in}
bufsize the size of buffer which is the parameter in function
Output parameter{out}
buffer pointer to the application buffer
Output parameter{out}
timestamp pointer to the table which stores the timestamp high and low
Return value
ErrStatus SUCCESS or ERROR

Example:

/* receive a packet data with timestamp values to application buffer in DMA enhanced mode
*/

uint32_t rx_buffer[500];

uint32_t time_stamp[2];

ErrStatus status;

status = enet_ptpframe_receive_enhanced_mode (rx_buffer, 500, time_stamp);

enet_ptpframe_transmit_enhanced_mode

The description of enet_ptpframe_transmit_enhanced_mode is shown as below:

Table 3-288. Function enet_ptpframe_transmit_enhanced_mode


Function name enet_ptpframe_transmit_enhanced_mode
ErrStatus enet_ptpframe_transmit_enhanced_mode(uint8_t *buffer, uint32_t
Function prototype
length, uint32_t timestamp[]);
send data with timestamp values in application buffer as a transmit packet,
Function descriptions
when the DMA is in enhanced mode
Precondition -
The called functions -
Input parameter{in}
buffer pointer on the application buffer
232
GD32E50x Firmware Library User Guide
note -- if the input is NULL, user should copy data in application by himself
Input parameter{in}
length the length of frame data to be transmitted
Output parameter{out}
pointer to the table which stores the timestamp high and low
timestamp
note -- if the input is NULL, timestamp is ignored
Return value
ErrStatus SUCCESS or ERROR

Example:

/* send data and timestamp values in application buffer as a transmit packet with DMA
enhanced mode */

uint32_t tx_buffer[500];

uint32_t time_stamp[2];

ErrStatus status;

status = enet_ptpframe_transmit_enhanced_mode(tx_buffer, 500, time_stamp);

enet_desc_select_normal_mode

The description of enet_desc_select_normal_mode is shown as below:

Table 3-289. Function enet_desc_select_normal_mode


Function name enet_desc_select_normal_mode
Function prototype void enet_desc_select_normal_mode(void);
Function descriptions configure descriptor to work in normal mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* configure descriptor to work in normal mode */

enet_desc_select_normal_mode( );

enet_ptp_normal_descriptors_chain_init

The description of enet_ptp_normal_descriptors_chain_init is shown as below:

233
GD32E50x Firmware Library User Guide
Table 3-290. Function enet_ptp_normal_descriptors_chain_init
Function name enet_ptp_normal_descriptors_chain_init
void enet_ptp_normal_descriptors_chain_init(enet_dmadirection_enum
Function prototype
direction, enet_descriptors_struct *desc_ptptab);
initialize the DMA Tx/Rx descriptors's parameters in normal chain mode
Function descriptions
with PTP function
Precondition -
The called functions -
Input parameter{in}
the descriptors which users want to init
direction
only one parameter can be selected which is shown as below
ENET_DMA_TX DMA Tx descriptors
ENET_DMA_RX DMA Rx descriptors
Input parameter{in}
pointer to the first descriptor address of PTP Rx descriptor table, the
desc_ptptab
structure members can refer to Structure enet_descriptors_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the DMA Rx descriptors's parameters in normal chain mode with PTP function */

enet_descriptors_struct ptp_rxdesc_tab[ENET_RXBUF_NUM];

enet_ptp_normal_descriptors_chain_init(ENET_DMA_RX, ptp_rxdesc_tab);

enet_ptp_normal_descriptors_ring_init

The description of enet_ptp_normal_descriptors_ring_init is shown as below:

Table 3-291. Function enet_ptp_normal_descriptors_ring_init


Function name enet_ptp_normal_descriptors_ring_init
void enet_ptp_normal_descriptors_ring_init(enet_dmadirection_enum
Function prototype
direction, enet_descriptors_struct *desc_ptptab);
initialize the DMA Tx/Rx descriptors's parameters in normal ring mode with
Function descriptions
PTP function
Precondition -
The called functions -
Input parameter{in}
the descriptors which users want to init
direction
only one parameter can be selected which is shown as below
ENET_DMA_TX DMA Tx descriptors
ENET_DMA_RX DMA Rx descriptors

234
GD32E50x Firmware Library User Guide
Input parameter{in}
pointer to the first descriptor address of PTP Rx descriptor table, the
desc_ptptab
structure members can refer to Structure enet_descriptors_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the DMA Rx descriptors's parameters in normal ring mode with PTP function */

enet_descriptors_struct ptp_rxdesc_tab[ENET_RXBUF_NUM];

enet_ptp_normal_descriptors_ring_init(ENET_DMA_RX, ptp_rxdesc_tab);

enet_ptpframe_receive_normal_mode

The description of enet_ptpframe_receive_normal_mode is shown as below:

Table 3-292. Function enet_ptpframe_receive_normal_mode


Function name enet_ptpframe_receive_normal_mode
ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t
Function prototype
bufsize, uint32_t timestamp[]);
receive a packet data with timestamp values to application buffer, when the
Function descriptions
DMA is in normal mode
Precondition -
The called functions -
Input parameter{in}
bufsize the size of buffer which is the parameter in function
Output parameter{out}
timestamp pointer to the table which stores the timestamp high and low
Output parameter{out}
pointer to the application buffer
buffer
if the input is NULL, user should copy data in application by himself
Return value
ErrStatus ERROR or SUCCESS

Example:

/* receive a packet data with timestamp values to application buffer in DMA normal mode */

uint32_t rx_buffer[500];

uint32_t time_stamp[2];

ErrStatus status;

status = enet_ptpframe_receive_normal_mode(rx_buffer, 500, time_stamp);


235
GD32E50x Firmware Library User Guide
enet_ptpframe_transmit_normal_mode

The description of enet_ptpframe_transmit_normal_mode is shown as below:

Table 3-293. Function enet_ptpframe_transmit_normal_mode


Function name enet_ptpframe_transmit_normal_mode
ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t
Function prototype
length, uint32_t timestamp[]);
send data with timestamp values in application buffer as a transmit packet,
Function descriptions
when the DMA is in normal mode
Precondition -
The called functions --
Input parameter{in}
pointer on the application buffer
buffer
if the input is NULL, user should copy data in application by himself
Input parameter{in}
length the length of frame data to be transmitted
Output parameter{out}
pointer to the table which stores the timestamp high and low
timestamp
if the input is NULL, timestamp is ignored
Return value
ErrStatus ERROR or SUCCESS

Example:

/* send data and timestamp values in application buffer as a transmit packet with DMA normal
mode */

uint32_t tx_buffer[500];

uint32_t time_stamp[2];

ErrStatus status;

status = enet_ptpframe_transmit_normal_mode(tx_buffer, 500, time_stamp);

enet_wum_filter_register_pointer_reset

The description of enet_wum_filter_register_pointer_reset is shown as below:

Table 3-294. Function enet_wum_filter_register_pointer_reset


Function name enet_wum_filter_register_pointer_reset
Function prototype void enet_wum_filter_register_pointer_reset(void);
Function descriptions wakeup frame filter register pointer reset
Precondition -
The called functions -
Input parameter{in}
- -
236
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* reset wakeup frame filter register pointer */

enet_wum_filter_register_pointer_reset ();

enet_wum_filter_config

The description of enet_wum_filter_config is shown as below:

Table 3-295. Function enet_wum_filter_config


Function name enet_wum_filter_config
Function prototype void enet_wum_filter_config(uint32_t pdata[]);
Function descriptions set the remote wakeup frame registers
Precondition -
The called functions -
Input parameter{in}
pointer to buffer data which is written to remote wakeup frame registers (8
pdata
words total)
Output parameter{out}
- -
Return value
- -

Example:

/* set the remote wakeup frame registers */

uint32_t wum_data[8];

enet_wum_filter_config (wum_data);

enet_wum_feature_enable

The description of enet_wum_feature_enable is shown as below:

Table 3-296. Function enet_wum_feature_enable


Function name enet_wum_feature_enable
Function prototype void enet_wum_feature_enable(uint32_t feature);
Function descriptions enable wakeup management features
Precondition -
The called functions -
Input parameter{in}

237
GD32E50x Firmware Library User Guide
feature one or more parameters can be selected which are shown as below
ENET_WUM_POWER_
power down mode
DOWN
ENET_WUM_MAGIC_
enable a wakeup event due to magic packet reception
PACKET_FRAME
ENET_WUM_WAKE_U
enable a wakeup event due to wakeup frame reception
P_FRAME
ENET_WUM_GLOBAL
any received unicast frame passed filter is considered to be a wakeup frame
_UNICAST
Output parameter{out}
- -
Return value
- -

Example:

/* enable power down mode */

enet_wum_feature_enable(ENET_WUM_POWER_DOWN);

enet_wum_feature_disable

The description of enet_wum_feature_disable is shown as below:

Table 3-297. Function enet_wum_feature_disable


Function name enet_wum_feature_disable
Function prototype void enet_wum_feature_disable(uint32_t feature)
Function descriptions disable wakeup management features
Precondition -
The called functions -
Input parameter{in}
feature one or more parameters can be selected which are shown as below
ENET_WUM_MAGIC_
enable a wakeup event due to magic packet reception
PACKET_FRAME
ENET_WUM_WAKE_U
enable a wakeup event due to wakeup frame reception
P_FRAME
ENET_WUM_GLOBAL
any received unicast frame passed filter is considered to be a wakeup frame
_UNICAST
Output parameter{out}
- -
Return value
- -

Example:

/* disable power down mode */

238
GD32E50x Firmware Library User Guide
enet_wum_feature_disable(ENET_WUM_POWER_DOWN);

enet_msc_counters_reset

The description of enet_msc_counters_reset is shown as below:

Table 3-298. Function enet_msc_counters_reset


Function name enet_msc_counters_reset
Function prototype void enet_msc_counters_reset(void);
Function descriptions reset the MAC statistics counters
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset the MAC statistics counters */

enet_msc_counters_reset();

enet_msc_feature_enable

The description of enet_msc_feature_enable is shown as below:

Table 3-299. Function enet_msc_feature_enable


Function name enet_msc_feature_enable
Function prototype void enet_msc_feature_enable(uint32_t feature);
Function descriptions enable the MAC statistics counter features
Precondition -
The called functions -
Input parameter{in}
feature one or more parameters can be selected which are shown as below
ENET_MSC_COUNTE
counter stop rollover
R_STOP_ROLLOVER
ENET_MSC_RESET_O
reset on read
N_READ
ENET_MSC_COUNTE
MSC counter freeze
RS_FREEZE
Output parameter{out}
- -
Return value

239
GD32E50x Firmware Library User Guide
- -

Example:

/* enable counter stop rollover function */

enet_msc_feature_enable(ENET_MSC_COUNTER_STOP_ROLLOVER);

enet_msc_feature_disable

The description of enet_msc_feature_disable is shown as below:

Table 3-300. Function enet_msc_feature_disable


Function name enet_msc_feature_disable
Function prototype void enet_msc_feature_disable(uint32_t feature);
Function descriptions disable the MAC statistics counter features
Precondition -
The called functions -
Input parameter{in}
feature one or more parameters can be selected which are shown as below
ENET_MSC_COUNTE
counter stop rollover
R_STOP_ROLLOVER
ENET_MSC_RESET_O
reset on read
N_READ
ENET_MSC_COUNTE
MSC counter freeze
RS_FREEZE
Output parameter{out}
- -
Return value
- -

Example:

/* disable counter stop rollover function */

enet_msc_feature_disable(ENET_MSC_COUNTER_STOP_ROLLOVER);

enet_msc_counters_preset_config

The description of enet_msc_counters_preset_config is shown as below:

Table 3-301. Function enet_msc_counters_preset_config


Function name enet_msc_counters_preset_config
Function prototype void enet_msc_counters_preset_config(enet_msc_preset_enum mode);
Function descriptions configure MAC statistics counters preset mode
Precondition -
The called functions -
Input parameter{in}
240
GD32E50x Firmware Library User Guide
MSC counters preset mode, refer to Enum enet_msc_preset_enum
mode
only one parameter can be selected which is shown as below
ENET_MSC_PRESET_
do not preset MSC counter
NONE
ENET_MSC_PRESET_
preset all MSC counters to almost-half(0x7FFF FFF0) value
HALF
ENET_MSC_PRESET_
preset all MSC counters to almost-full(0xFFFF FFF0) value
FULL
Output parameter{out}
- -
Return value
- -

Example:

/* preset all MSC counters to almost-half */

enet_msc_counters_preset_config (ENET_MSC_PRESET_HALF);

enet_msc_counters_get

The description of enet_msc_counters_get is shown as below:

Table 3-302. Function enet_msc_counters_get


Function name enet_msc_counters_get
Function prototype uint32_t enet_msc_counters_get(enet_msc_counter_enum counter);
Function descriptions get MAC statistics counter
Precondition -
The called functions -
Input parameter{in}
MSC counters which is selected, refer to Enum enet_msc_counter_enum
counter
only one parameter can be selected which is shown as below
ENET_MSC_TX_SCCN
MSC transmitted good frames after a single collision counter
T
ENET_MSC_TX_MSC
MSC transmitted good frames after more than a single collision counter
CNT
ENET_MSC_TX_TGFC
MSC transmitted good frames counter
NT
ENET_MSC_RX_RFCE
MSC received frames with CRC error counter
CNT
ENET_MSC_RX_RFAE
MSC received frames with alignment error counter
CNT
ENET_MSC_RX_RGU
MSC received good unicast frames counter
FCNT
Output parameter{out}

241
GD32E50x Firmware Library User Guide
- -
Return value
uint32_t the MSC counter value

Example:

/* get MSC transmitted good frames after a single collision counter value*/

uin32_t reval;

reval = enet_msc_counters_get(ENET_MSC_TX_SCCNT);

enet_ptp_subsecond_2_nanosecond

The description of enet_ptp_subsecond_2_nanosecond is shown as below:

Table 3-303. Function enet_ptp_subsecond_2_nanosecond


Function name enet_ptp_subsecond_2_nanosecond
Function prototype uint32_t enet_ptp_subsecond_2_nanosecond(uint32_t subsecond);
Function descriptions change subsecond to nanosecond
Precondition -
The called functions -
Input parameter{in}
subsecond subsecond value
Output parameter{out}
- -
Return value
uint32_t the nanosecond value

Example:

/* change subsecond to nanosecond */

uin32_t reval;

reval = enet_ptp_subsecond_2_nanosecond (2);

enet_ptp_nanosecond_2_subsecond

The description of enet_ptp_nanosecond_2_subsecond is shown as below:

Table 3-304. Function enet_ptp_nanosecond_2_subsecond


Function name enet_ptp_nanosecond_2_subsecond
Function prototype uint32_t enet_ptp_nanosecond_2_subsecond(uint32_t nanosecond);
Function descriptions change nanosecond to subsecond
Precondition -
The called functions -
Input parameter{in}
nanosecond Nanosecond value
242
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
uint32_t the subsecond value

Example:

/* change nanosecond to subsecond */

uin32_t reval;

reval = enet_ptp_nanosecond_2_subsecond (2);

enet_ptp_feature_enable

The description of enet_ptp_feature_enable is shown as below:

Table 3-305. Function enet_ptp_feature_enable


Function name enet_ptp_feature_enable
Function prototype void enet_ptp_feature_enable(uint32_t feature);
Function descriptions enable the PTP features
Precondition -
The called functions -
Input parameter{in}
the feature of ENET PTP mode
feature
one or more parameters can be selected which are shown as below
ENET_RXTX_TIMEST
timestamp function for transmit and receive frames
AMP
ENET_PTP_TIMESTA
timestamp interrupt trigger
MP_INT
ENET_ALL_RX_TIMES
all received frames are taken snapshot
TAMP
ENET_NONTYPE_FRA
take snapshot when received non type frame
ME_SNAPSHOT
ENET_IPV6_FRAME_S
take snapshot for IPv6 frame
NAPSHOT
ENET_IPV4_FRAME_S
take snapshot for IPv4 frame
NAPSHOT
ENET_PTP_FRAME_U
SE_MACADDRESS_FI use MAC address1-3 to filter the PTP frame
LTER
Output parameter{out}
- -
Return value
- -

243
GD32E50x Firmware Library User Guide
Example:

/* enable PTP function for all received frames */

enet_ptp_feature_enable(ENET_ALL_RX_TIMESTAMP);

enet_ptp_feature_disable

The description of enet_ptp_feature_disable is shown as below:

Table 3-306. Function enet_ptp_feature_disable


Function name enet_ptp_feature_disable
Function prototype void enet_ptp_feature_disable(uint32_t feature);
Function descriptions disable the PTP features
Precondition -
The called functions -
Input parameter{in}
the feature of ENET PTP mode
feature
one or more parameters can be selected which are shown as below
ENET_RXTX_TIMEST
timestamp function for transmit and receive frames
AMP
ENET_PTP_TIMESTA
timestamp interrupt trigger
MP_INT
ENET_ALL_RX_TIMES
all received frames are taken snapshot
TAMP
ENET_NONTYPE_FRA
take snapshot when received non type frame
ME_SNAPSHOT
ENET_IPV6_FRAME_S
take snapshot for IPv6 frame
NAPSHOT
ENET_IPV4_FRAME_S
take snapshot for IPv4 frame
NAPSHOT
ENET_PTP_FRAME_U
SE_MACADDRESS_FI use MAC address1-3 to filter the PTP frame
LTER
Output parameter{out}
- -
Return value
- -

Example:

/* disable PTP function for all received frames */

enet_ptp_feature_disable(ENET_ALL_RX_TIMESTAMP);

244
GD32E50x Firmware Library User Guide
enet_ptp_timestamp_function_config

The description of enet_ptp_timestamp_function_config is shown as below:

Table 3-307. Function enet_ptp_timestamp_function_config


Function name enet_ptp_timestamp_function_config
ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum
Function prototype
func);
Function descriptions configure the PTP timestamp function
Precondition -
The called functions -
Input parameter{in}
func only one parameter can be selected which is shown as below
ENET_CKNT_ORDINA
type of ordinary clock node type for timestamp
RY
ENET_CKNT_BOUND
type of boundary clock node type for timestamp
ARY
ENET_CKNT_END_TO
type of end-to-end transparent clock node type for timestamp
_END
ENET_CKNT_PEER_T
type of peer-to-peer transparent clock node type for timestamp
O_PEER
ENET_PTP_ADDEND_
addend register update
UPDATE
ENET_PTP_SYSTIME_
timestamp update
UPDATE
ENET_PTP_SYSTIME_
timestamp initialize
INIT
ENET_PTP_FINEMOD
the system timestamp uses the fine method for updating
E
ENET_PTP_COARSE
the system timestamp uses the coarse method for updating
MODE
ENET_SUBSECOND_
digital rollover mode
DIGITAL_ROLLOVER
ENET_SUBSECOND_
digital rollover mode
BINARY_ROLLOVER
ENET_SNOOPING_PT
version 2
P_VERSION_2
ENET_SNOOPING_PT
version 1
P_VERSION_1
ENET_EVENT_TYPE_
MESSAGES_SNAPSH only event type messages are taken snapshot
OT
ENET_ALL_TYPE_ME all type messages are taken snapshot except announce,
SSAGES_SNAPSHOT management and signaling message
245
GD32E50x Firmware Library User Guide
ENET_MASTER_NOD
E_MESSAGE_SNAPS snapshot is only take for master node message
HOT
ENET_SLAVE_NODE_
MESSAGE_SNAPSHO snapshot is only taken for slave node message
T
Output parameter{out}
- -
Return value
ErrStatus SUCCESS or ERROR

Example:

/* config addend register update function */

ErrStatus reval = ERROR;

reval = enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);

enet_ptp_subsecond_increment_config

The description of enet_ptp_subsecond_increment_config is shown as below:

Table 3-308. Function enet_ptp_subsecond_increment_config


Function name enet_ptp_subsecond_increment_config
Function prototype void enet_ptp_subsecond_increment_config(uint32_t subsecond);
Function descriptions configure system time subsecond increment value
Precondition -
The called functions -
Input parameter{in}
the value will be added to the subsecond value of system time, this value
subsecond
must be between 0 and 0xFF
Output parameter{out}
- -
Return value
- -

Example:

/* configure 0x1F as system time subsecond increment value */

enet_ptp_subsecond_increment_config(0x1F);

enet_ptp_timestamp_addend_config

The description of enet_ptp_timestamp_addend_config is shown as below:

246
GD32E50x Firmware Library User Guide
Table 3-309. Function enet_ptp_timestamp_addend_config
Function name enet_ptp_timestamp_addend_config
Function prototype void enet_ptp_timestamp_addend_config(uint32_t add);
Function descriptions adjusting the clock frequency only in fine update mode
Precondition -
The called functions -
Input parameter{in}
the value will be added to the accumulator register to achieve time
add
synchronization (0 – 0xFFFF FFFF)
Output parameter{out}
- -
Return value
- -

/* added 0x1FFF to the accumulator register */

enet_ptp_timestamp_addend_config(0x1FFF);

enet_ptp_timestamp_update_config

The description of enet_ptp_timestamp_update_config is shown as below:

Table 3-310. Function enet_ptp_timestamp_update_config


Function name enet_ptp_timestamp_update_config
void enet_ptp_timestamp_update_config(uint32_t sign, uint32_t second,
Function prototype
uint32_t subsecond);
Function descriptions initialize or add/subtract to second of the system time
Precondition -
The called functions -
Input parameter{in}
timestamp update positive or negative sign,
sign
only one parameter can be selected which is shown as below
ENET_PTP_ADD_TO_
update value is added to system time
TIME
ENET_PTP_SUBSTRA
timestamp update value is subtracted from system time
CT_FROM_TIME
Input parameter{in}
initializing or adding/subtracting to second of the system time (0 – 0xFFFF
second
FFFF)
Input parameter{in}
the current subsecond of the system time with 0.46 ns accuracy (0 –
subsecond
0x7FFF FFFF)
Output parameter{out}
- -
Return value
247
GD32E50x Firmware Library User Guide
- -

Example:

/* initialize system time with timestamp update value */

enet_ptp_timestamp_update_config(ENET_PTP_ADD_TO_TIME, 0, 0);

enet_ptp_expected_time_config

The description of enet_ptp_expected_time_config is shown as below:

Table 3-311. Function enet_ptp_expected_time_config


Function name enet_ptp_expected_time_config
void enet_ptp_expected_time_config(uint32_t second, uint32_t
Function prototype
nanosecond);
Function descriptions configure the expected target time
Precondition -
The called functions -
Input parameter{in}
second the expected target second time (0 – 0xFFFF FFFF)
Input parameter{in}
nanosecond the expected target nanosecond time (signed) (0 – 0xFFFF FFFF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the expected target time */

enet_ptp_expected_time_config(2000, 0);

enet_ptp_system_time_get

The description of enet_ptp_system_time_get is shown as below:

Table 3-312. Function enet_ptp_system_time_get


Function name enet_ptp_system_time_get
Function prototype void enet_ptp_system_time_get(enet_ptp_systime_struct *systime_struct);
Function descriptions get the current system time
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
systime_struct pointer to a enet_ptp_systime_struct structure which contains parameters of
248
GD32E50x Firmware Library User Guide
PTP system time, the structure members can refer to Structure
enet_ptp_systime_struct
Return value
- -

Example:

/* get the current system time */

enet_ptp_systime_struct systime;

enet_ptp_system_time_get(&systime);

enet_ptp_pps_output_frequency_config

The description of enet_ptp_pps_output_frequency_config is shown as below:

Table 3-313. enet_ptp_pps_output_frequency_config


Function name enet_ptp_pps_output_frequency_config
Function prototype void enet_ptp_pps_output_frequency_config(uint32_t freq);
Function descriptions configure the PPS output frequency
Precondition -
The called functions -
Input parameter{in}
freq
ENET_PPSOFC_1HZ PPS output 1Hz frequency
ENET_PPSOFC_2HZ PPS output 2Hz frequency
ENET_PPSOFC_4HZ PPS output 4Hz frequency
ENET_PPSOFC_8HZ PPS output 8Hz frequency
ENET_PPSOFC_16HZ PPS output 16Hz frequency
ENET_PPSOFC_32HZ PPS output 32Hz frequency
ENET_PPSOFC_64HZ PPS output 64Hz frequency
ENET_PPSOFC_128H
PPS output 128Hz frequency
Z
ENET_PPSOFC_256H
PPS output 256Hz frequency
Z
ENET_PPSOFC_512H
PPS output 512Hz frequency
Z
ENET_PPSOFC_1024
PPS output 1024Hz frequency
HZ
ENET_PPSOFC_2048
PPS output 2048Hz frequency
HZ
ENET_PPSOFC_4096
PPS output 4096Hz frequency
HZ
ENET_PPSOFC_8192
PPS output 8192Hz frequency
HZ

249
GD32E50x Firmware Library User Guide
ENET_PPSOFC_16384
PPS output 16384Hz frequency
HZ
ENET_PPSOFC_32768
PPS output 32768Hz frequency
HZ
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PPS output frequency as 1Hz */

enet_ptp_pps_output_frequency_config(ENET_PPSOFC_1HZ);

enet_ptp_start

The enet_ptp_start is shown as below:

Table 3-314. enet_ptp_start


Function name enet_ptp_start
void enet_ptp_start(int32_t updatemethod, uint32_t init_sec, uint32_t
Function prototype
init_subsec, uint32_t carry_cfg, uint32_t accuracy_cfg);
Function descriptions configure and start PTP timestamp counter
Precondition -
The called functions -
Input parameter{in}
updatemethod method for updating
ENET_PTP_FINEMOD
fine correction method
E
ENET_PTP_COARSE
coarse correction method
MODE
Input parameter{in}
init_sec second value for initializing system time
Input parameter{in}
init_subsec subsecond value for initializing system time
Input parameter{in}
carry_cfg the value to be added to the accumulator register (in fine method is used)
Input parameter{in}
accuracy_cfg the value to be added to the subsecond value of system time
Output parameter{out}
- -
Return value
- -

Example:
250
GD32E50x Firmware Library User Guide
/* gconfigure and start PTP timestamp counter*/

enet_ptp_start(ENET_PTP_FINEMODE, 10, 10, 10, 10);

enet_ptp_finecorrection_adjfreq

The enet_ptp_finecorrection_adjfreq is shown as below:

Table 3-315. enet_ptp_finecorrection_adjfreq


Function name enet_ptp_finecorrection_adjfreq
Function prototype void enet_ptp_finecorrection_adjfreq(int32_t carry_cfg);
Function descriptions adjust frequency in fine method by configure addend register
Precondition -
The called functions -
Input parameter{in}
carry_cfg the value to be added to the accumulator register
Output parameter{out}
- -
Return value
- -

Example:

/* adjust frequency in fine method by configure addend register */

enet_ptp_finecorrection_adjfreq(10);

enet_ptp_coarsecorrection_systime_update

The enet_ptp_coarsecorrection_systime_update is shown as below:

Table 3-316. enet_ptp_coarsecorrection_systime_update


Function name enet_ptp_coarsecorrection_systime_update
void enet_ptp_coarsecorrection_systime_update(enet_ptp_systime_struct
Function prototype
*systime_struct);
Function descriptions update system time in coarse method
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to configure, the structure members
systime_struct
can refer to Structure enet_ptp_systime_struct
Output parameter{out}
- -
Return value
- -

Example:

251
GD32E50x Firmware Library User Guide
/* update system time in coarse method */

enet_ptp_systime_struct systime_struct;

enet_ptp_coarsecorrection_systime_update (&systime_struct);

enet_ptp_finecorrection_settime

The enet_ptp_finecorrection_settime is shown as below:

Table 3-317. enet_ptp_finecorrection_settime


Function name enet_ptp_finecorrection_settime
void enet_ptp_finecorrection_settime(enet_ptp_systime_struct *
Function prototype
systime_struct);
Function descriptions set system time in fine method
Precondition -
The called functions -
Input parameter{in}
the descriptor pointer which users want to configure, the structure members
systime_struct
can refer to Structure enet_ptp_systime_struct
Output parameter{out}
- -
Return value
- -

Example:

/* set system time in fine method */

enet_ptp_systime_struct systime_struct;

enet_ptp_finecorrection_settime (&systime_struct);

enet_ptp_flag_get

The enet_ptp_flag_get is shown as below:

Table 3-318. enet_ptp_flag_get


Function name enet_ptp_flag_get
Function prototype FlagStatus enet_ptp_flag_get(uint32_t flag);
Function descriptions get the ptp flag status
Precondition -
The called functions -
Input parameter{in}
flag ptp flag status to be checked
ENET_PTP_ADDEND_
addend register update
UPDATE
ENET_PTP_SYSTIME_ timestamp update

252
GD32E50x Firmware Library User Guide
UPDATE
ENET_PTP_SYSTIME_
timestamp initialize
INIT
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the ptp flag status */

FlagStatus status = enet_ptp_flag_get(ENET_PTP_ADDEND_UPDATE);

enet_initpara_reset

The description of enet_initpara_reset is shown as below:

Table 3-319. Function enet_initpara_reset


Function name enet_initpara_reset
Function prototype void enet_initpara_reset(void);
Function descriptions reset the ENET initpara struct, call it before using enet_initpara_config()
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset the ENET initpara struct */

enet_initpara_reset();

3.11. EXMC

The external memory controller EXMC, is used as a translator for MCU to access a variety of
external memory. The EXMC registers are listed in chapter 3.11.1, the EXMC firmware
functions are introduced in chapter 3.11.2.

3.11.1. Descriptions of Peripheral registers

EXMC registers are listed in the table shown as below:

253
GD32E50x Firmware Library User Guide
Table 3-320. EXMC Registers
Registers Descriptions
EXMC_SNCTL SRAM/NOR Flash control registers
EXMC_SNTCFG SRAM/NOR Flash timing configuration registers
EXMC_SNWTCFG SRAM/NOR Flash write timing configuration registers
EXMC_NPCTL NAND flash/PC card control registers
EXMC_NPINTEN NAND flash/PC card interrupt enable registers
EXMC_NPCTCFG NAND flash/PC card common space timing configuration registers
EXMC_NPATCFG NAND flash/PC card attribute space timing configuration registers
EXMC_PIOTCFG3 PC card I/O space timing configuration register
EXMC_NECC NAND flash ECC registers

3.11.2. Descriptions of Peripheral functions

EXMC firmware functions are listed in the table shown as below:

Table 3-321. EXMC firmware function


Function name Function description
exmc_norsram_deinit deinitialize EXMC NOR/SRAM region x
initialize exmc_norsram_parameter_struct with the default
exmc_norsram_struct_para_init
values
exmc_norsram_init initialize EXMC NOR/SRAM region x
exmc_norsram_enable enable EXMC NOR/PSRAM region x
exmc_norsram_disable disable EXMC NOR/PSRAM region x
exmc_norsram_page_size_config configure CRAM page size
exmc_nand_deinit deinitialize EXMC NAND bank x
initialize exmc_norsram_parameter_struct with the default
exmc_nand_struct_para_init
values
exmc_nand_init initialize EXMC NAND bank x
exmc_nand_enable enable EXMC NAND bank x
exmc_nand_disable disable EXMC NAND bank x
exmc_nand_ecc_config enable or disable the EXMC NAND ECC function
exmc_ecc_get get the EXMC ECC value
exmc_pccard_deinit deinitialize EXMC PC card bank
initialize exmc_pccard_parameter_struct with the default
exmc_pccard_struct_para_init
values
exmc_pccard_init initialize EXMC PC card bank
exmc_pccard_enable enable EXMC PC card bank
exmc_pccard_disable disable EXMC PC card bank
exmc_interrupt_enable enable EXMC interrupt
exmc_interrupt_disable disable EXMC interrupt
exmc_flag_get get EXMC flag status
exmc_flag_clear clear EXMC flag status

254
GD32E50x Firmware Library User Guide
Function name Function description
exmc_interrupt_flag_get get EXMC interrupt flag
exmc_interrupt_flag_clear clear EXMC interrupt flag

Structure exmc_norsram_timing_parameter_struct

Table 3-322. Structure exmc_norsram_timing_parameter_struct


Member name Function description
asyn_access_mode asynchronous access mode
syn_data_latency configure the data latency, synchronous access mode valid
syn_clk_division configure the clock divide ratio, synchronous access mode valid
bus_latency configure the bus latency
asyn_data_setuptim
configure the data setup time, asynchronous access mode valid
e
asyn_address_holdti
configure the address hold time, asynchronous access mode valid
me
asyn_address_setu
configure the data setup time, asynchronous access mode valid
ptime

Structure exmc_norsram_parameter_struct

Table 3-323. Structure exmc_norsram_parameter_struct


Member name Function description
norsram_region select the region of EXMC NOR/SRAM
write_mode the write mode, synchronous mode or asynchronous mode
extended_mode enable or disable the extended mode
asyn_wait enable or disable the asynchronous wait function
nwait_signal enable or disable the NWAIT signal while in synchronous bust mode
memory_write enable or disable the write operation
nwait_config NWAIT signal configuration, only work in synchronous mode
wrap_burst_mode enable or disable the wrap burst mode
nwait_polarity specifies the polarity of NWAIT signal from memory
burst_mode enable or disable the burst mode
databus_width specifies the databus width of external memory
memory_type specifies the type of external memory
address_data_mux specifies whether the data bus and address bus are multiplexed
timing parameters for read and write if the extended mode is not used or the
read_write_timing timing parameters for read if the extended mode is used, the structure
members can refer to Structure exmc_norsram_timing_parameter_struct
timing parameters for write when the extended mode is used, the structure
write_timing
members can refer to Structure exmc_norsram_timing_parameter_struct

255
GD32E50x Firmware Library User Guide
Structure exmc_nand_pccard_timing_parameter_struct

Table 3-324. Structure exmc_nand_pccard_timing_parameter_struct


Member name Function description
databus_hiztime configure the dadtabus HiZ time for write operation
holdtime configure the address hold time(or the data hold time for write operation)
waittime configure the minimum wait time
setuptime configure the address setup time

Structure exmc_nand_parameter_struct

Table 3-325. Structure exmc_nand_parameter_struct


Member name Function description
nand_bank select the bank of NAND
ecc_size the page size for the ECC calculation
atr_latency configure the latency of ALE low to RB low
ctr_latency configure the latency of CLE low to RB low
ecc_logic enable or disable the ECC calculation logic
databus_width the NAND flash databus width
wait_feature enable or disable the wait feature
common_space_timi the timing parameters for NAND flash common space, the structure members
ng can refer to Structure exmc_nand_pccard_timing_parameter_struct
attribute_space_timi the timing parameters for NAND flash attribute space, the structure members
ng can refer to Structure exmc_nand_pccard_timing_parameter_struct

Structure exmc_pccard_parameter_struct

Table 3-326. Structure exmc_pccard_parameter_struct


Member name Function description
atr_latency configure the latency of ALE low to RB low
ctr_latency configure the latency of CLE low to RB low
wait_feature enable or disable the wait feature
common_space_timi the timing parameters for PC card common space, the structure members can
ng refer to Structure exmc_nand_pccard_timing_parameter_struct
attribute_space_timi the timing parameters for PC card attribute space, the structure members can
ng refer to Structure exmc_nand_pccard_timing_parameter_struct
the timing parameters for PC card IO space, the structure members can refer to
io_space_timing
Structure exmc_nand_pccard_timing_parameter_struct

exmc_norsram_deinit

The description of exmc_norsram_deinit is shown as below:

Table 3-327. Function exmc_norsram_deinit


Function name exmc_norsram_deinit
256
GD32E50x Firmware Library User Guide
Function prototype void exmc_norsram_deinit(uint32_t exmc_norsram_region);
Function descriptions deinitialize EXMC NOR/SRAM region
Precondition -
The called functions -
Input parameter{in}
exmc_norsram_regio
EXMC NOR/SRAM region
n
EXMC_BANK0_NORS
x=0,1,2,3
RAM_REGIONx
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize the EXMC NOR/SRAM region1 of bank0 */

exmc_norsram_deinit(EXMC_BANK0_NORSRAM_REGION1);

exmc_norsram_struct_para_init

The description of exmc_norsram_struct_para_init is shown as below:

Table 3-328. Function exmc_norsram_struct_para_init


Function name exmc_norsram_struct_para_init
void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct*
Function prototype
exmc_norsram_init_struct);
Function descriptions initialize the struct exmc_norsram_parameter_struct
Precondition -
The called functions -
Input parameter{in}
exmc_norsram_init_st Structure for initialization, the structure members can refer to Structure
ruct exmc_norsram_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the struct nor_init_struct */

exmc_norsram_parameter_struct nor_init_struct;

exmc_norsram_struct_para_init (&nor_init_struct);

257
GD32E50x Firmware Library User Guide
exmc_norsram_init

The description of exmc_norsram_init is shown as below:

Table 3-329. Function exmc_norsram_init


Function name exmc_norsram_init
void exmc_norsram_init(exmc_norsram_parameter_struct*
Function prototype
exmc_norsram_init_struct);
Function descriptions initialize EXMC NOR/SRAM region
Precondition -
The called functions -
Input parameter{in}
exmc_norsram_init_st Structure for initialization, the structure members can refer to Structure
ruct exmc_norsram_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize EXMC NOR/SRAM bank */

exmc_norsram_parameter_struct lcd_init_struct;

exmc_norsram_timing_parameter_struct lcd_timing_init_struct;

/* configure timing parameter */

lcd_timing_init_struct.asyn_access_mode = EXMC_ACCESS_MODE_A;

lcd_timing_init_struct.syn_data_latency = EXMC_DATALAT_2_CLK;

lcd_timing_init_struct.syn_clk_division = EXMC_SYN_CLOCK_RATIO_DISABLE;

lcd_timing_init_struct.bus_latency = 1;

lcd_timing_init_struct.asyn_data_setuptime = 5;

lcd_timing_init_struct.asyn_address_holdtime = 2;

lcd_timing_init_struct.asyn_address_setuptime = 2;

/* configure EXMC bus parameters */

lcd_init_struct.norsram_region = EXMC_BANK0_NORSRAM_REGION1;

lcd_init_struct.write_mode = EXMC_ASYN_WRITE;

lcd_init_struct.extended_mode = DISABLE;

lcd_init_struct.asyn_wait = DISABLE;

258
GD32E50x Firmware Library User Guide
lcd_init_struct.nwait_signal = DISABLE;

lcd_init_struct.memory_write = ENABLE;

lcd_init_struct.nwait_config = EXMC_NWAIT_CONFIG_BEFORE;

lcd_init_struct.wrap_burst_mode = DISABLE;

lcd_init_struct.nwait_polarity = EXMC_NWAIT_POLARITY_LOW;

lcd_init_struct.burst_mode = DISABLE;

lcd_init_struct.databus_width = EXMC_NOR_DATABUS_WIDTH_16B;

lcd_init_struct.memory_type = EXMC_MEMORY_TYPE_SRAM;

lcd_init_struct.address_data_mux = DISABLE;

lcd_init_struct.read_write_timing = &lcd_timing_init_struct;

lcd_init_struct.write_timing = &lcd_timing_init_struct;

exmc_norsram_init(&lcd_init_struct);

exmc_norsram_enable

The description of exmc_norsram_enable is shown as below:

Table 3-330. Function exmc_norsram_enable


Function name exmc_norsram_enable
Function prototype void exmc_norsram_enable(uint32_t exmc_norsram_region);
Function descriptions enable EXMC NOR/PSRAM region
Precondition -
The called functions -
Input parameter{in}
exmc_norsram_regio
EXMC NOR/SRAM region
n
EXMC_BANK0_NORS
x=0,1,2,3
RAM_REGIONx
Output parameter{out}
- -
Return value
- -

Example:

/* enable the EXMC NOR/SRAM region1 of bank0 */

exmc_norsram_enable(EXMC_BANK0_NORSRAM_REGION1);

259
GD32E50x Firmware Library User Guide
exmc_norsram_disable

The description of exmc_norsram_disable is shown as below:

Table 3-331. Function exmc_norsram_disable


Function name exmc_norsram_disable
Function prototype void exmc_norsram_disable(uint32_t exmc_norsram_region);
Function descriptions disable EXMC NOR/PSRAM region
Precondition -
The called functions -
Input parameter{in}
exmc_norsram_regio
EXMC NOR/SRAM region
n
EXMC_BANK0_NORS
x=0,1,2,3
RAM_REGIONx
Output parameter{out}
- -
Return value
- -

Example:

/* disable the EXMC NOR/SRAM region1 of bank0 */

exmc_norsram_disable(EXMC_BANK0_NORSRAM_REGION1);

exmc_norsram_page_size_config

The description of exmc_norsram_page_size_config is shown as below:

Table 3-332. Function exmc_norsram_page_size_config


Function name exmc_norsram_page_size_config
Function prototype void exmc_norsram_page_size_config(uint32_t page_size);
Function descriptions configure CRAM page size
Precondition -
The called functions -
Input parameter{in}
page_size CRAM page size
EXMC_CRAM_AUTO_
the clock is generated only during synchronous access
SPLIT
EXMC_CRAM_PAGE_
page size is 128 bytes
SIZE_128_BYTES
EXMC_CRAM_PAGE_
page size is 256 bytes
SIZE_256_BYTES
EXMC_CRAM_PAGE_
page size is 512 bytes
SIZE_512_BYTES

260
GD32E50x Firmware Library User Guide
EXMC_CRAM_PAGE_
page size is 1024 bytes
SIZE_1024_BYTES
Output parameter{out}
- -
Return value
- -

Example:

/* configure CRAM page size */

exmc_norsram_page_size_config (EXMC_CRAM_PAGE_SIZE_128_BYTES);

exmc_nand_deinit

The description of exmc_nand_deinit is shown as below:

Table 3-333. Function exmc_nand_deinit


Function name exmc_nand_deinit
Function prototype void exmc_nand_deinit(uint32_t exmc_nand_bank);
Function descriptions deinitialize EXMC NAND bank
Precondition -
The called functions -
Input parameter{in}
exmc_nand_bank the bank of NAND
EXMC_BANKx_NAND x=1,2
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize EXMC NOR/SRAM bank1 */

exmc_norsram_deinit(EXMC_BANK1_NAND);

exmc_nand_struct_para_init

The description of exmc_nand_struct_para_init is shown as below:

Table 3-334. Function exmc_nand_struct_para_init


Function name exmc_nand_struct_para_init
void exmc_nand_struct_para_init(exmc_nand_parameter_struct*
Function prototype
exmc_nand_init_struct);
Function descriptions initialize the struct exmc_nand_parameter_struct
Precondition -
The called functions -
261
GD32E50x Firmware Library User Guide
Input parameter{in}
exmc_nand_init_struc Structure for initialization, the structure members can refer to Structure
t exmc_nand_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the struct nand_init_struct */

exmc_nand_parameter_struct nand_init_struct;

exmc_nand_struct_para_init (&nand_init_struct);

exmc_nand_init

The description of exmc_nand_init is shown as below:

Table 3-335. Function exmc_nand_init


Function name exmc_nand_init
void exmc_nand_init(exmc_nand_parameter_struct*
Function prototype
exmc_nand_init_struct);
Function descriptions initialize EXMC NAND bank
Precondition -
The called functions -
Input parameter{in}
exmc_nand_init_struc Structure for initialization, the structure members can refer to Structure
t exmc_nand_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

exmc_nand_parameter_struct nand_init_struct;

exmc_nand_pccard_timing_parameter_struct nand_timing_init_struct;

/* EXMC configuration */

nand_timing_init_struct.setuptime = 5;

nand_timing_init_struct.waittime = 4;

nand_timing_init_struct.holdtime = 2;

nand_timing_init_struct.databus_hiztime = 2;

262
GD32E50x Firmware Library User Guide
nand_init_struct.nand_bank = EXMC_BANK1_NAND;

nand_init_struct.ecc_size = EXMC_ECC_SIZE_2048BYTES;

nand_init_struct.atr_latency = EXMC_ALE_RE_DELAY_1_HCLK;

nand_init_struct.ctr_latency = EXMC_CLE_RE_DELAY_1_HCLK;

nand_init_struct.ecc_logic = ENABLE;

nand_init_struct.databus_width = EXMC_NAND_DATABUS_WIDTH_8B;

nand_init_struct.wait_feature = ENABLE;

nand_init_struct.common_space_timing = &nand_timing_init_struct;

nand_init_struct.attribute_space_timing = &nand_timing_init_struct;

exmc_nand_init(&nand_init_struct);

exmc_nand_enable

The description of exmc_nand_enable is shown as below:

Table 3-336. Function exmc_nand_enable


Function name exmc_nand_enable
Function prototype void exmc_nand_enable(uint32_t exmc_nand_bank);
Function descriptions enable EXMC NAND bank
Precondition -
The called functions -
Input parameter{in}
exmc_nand_bank the bank of NAND
EXMC_BANKx_NAND x=1,2
Output parameter{out}
- -
Return value
- -

Example:

/* enable EXMC NAND bank1 */

exmc_nand_enable(EXMC_BANK1_NAND);

exmc_nand_disable

The description of exmc_nand_disable is shown as below:

Table 3-337. Function exmc_nand_disable


Function name exmc_nand_disable
Function prototype exmc_nand_disable(uint32_t exmc_nand_bank);

263
GD32E50x Firmware Library User Guide
Function descriptions disable EXMC NAND bank
Precondition -
The called functions -
Input parameter{in}
exmc_nand_bank the bank of NAND
EXMC_BANKx_NAND x=1,2
Output parameter{out}
- -
Return value
- -

Example:

/* disable EXMC NAND bank1 */

exmc_nand_disable(EXMC_BANK1_NAND);

exmc_nand_ecc_config

The description of exmc_nand_ecc_config is shown as below:

Table 3-338. Function exmc_nand_ecc_config


Function name exmc_nand_ecc_config
void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus
Function prototype
newvalue);
Function descriptions enable or disable the EXMC NAND ECC function
Precondition -
The called functions -
Input parameter{in}
exmc_nand_bank specifie the NAND bank
EXMC_BANKx_NAND x=1,2
Input parameter{in}
newvalue ENABLE or DISABLE
Output parameter{out}
- -
Return value
- -

Example:

/* enable the EXMC NAND ECC function */

exmc_nand_ecc_config(EXMC_BANK1_NAND, ENABLE);

exmc_ecc_get

The description of exmc_ecc_get is shown as below:

264
GD32E50x Firmware Library User Guide
Table 3-339. Function exmc_ecc_get
Function name exmc_ecc_get
Function prototype uint32_t exmc_ecc_get(uint32_t exmc_nand_bank);
Function descriptions get the EXMC ECC value
Precondition -
The called functions -
Input parameter{in}
exmc_nand_bank specifie the NAND bank
EXMC_BANKx_NAND x=1,2
Output parameter{out}
- -
Return value
uint32_t the error correction code(ECC) value

Example:

/* get the EXMC ECC value */

uint32_t ecc_value;

ecc_value = exmc_ecc_get(EXMC_BANK1_NAND);

exmc_pccard_deinit

The description of exmc_pccard_deinit is shown as below:

Table 3-340. Function exmc_pccard_deinit


Function name exmc_pccard_deinit
Function prototype void exmc_pccard_deinit(void);
Function descriptions deinitialize EXMC PC card bank
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize EXMC PC card bank */

exmc_pccard_deinit();

exmc_pccard_struct_para_init

The description of exmc_pccard_struct_para_init is shown as below:


265
GD32E50x Firmware Library User Guide
Table 3-341. Function exmc_pccard_struct_para_init
Function name exmc_pccard_struct_para_init
void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct*
Function prototype
exmc_pccard_init_struct);
Function descriptions initialize the struct exmc_pccard_parameter_struct
Precondition -
The called functions -
Input parameter{in}
exmc_pccard_init_str Structure for initialization, the structure members can refer to Structure
uct exmc_pccard_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the struct pccard_init_struct */

exmc_pccard_parameter_struct pccard_init_struct;

exmc_pccard_struct_para_init (&pccard_init_struct);

exmc_pccard_init

The description of exmc_pccard_init is shown as below:

Table 3-342. Function exmc_pccard_init


Function name exmc_pccard_init
void exmc_pccard_init(exmc_pccard_parameter_struct*
Function prototype
exmc_pccard_init_struct);
Function descriptions initialize EXMC PC card bank
Precondition -
The called functions -
Input parameter{in}
exmc_pccard_init_str Structure for initialization, the structure members can refer to Structure
uct exmc_pccard_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

exmc_pccard_parameter_struct pccard_init_struct;

exmc_nand_pccard_timing_parameter_struct pccard_timing_init_struct;

266
GD32E50x Firmware Library User Guide
/* EXMC configuration */

pccard_timing_init_struct.setuptime = 5;

pccard_timing_init_struct.waittime = 4;

pccard_timing_init_struct.holdtime = 2;

pccard_timing_init_struct.databus_hiztime = 2;

pccard_init_struct.atr_latency = EXMC_ALE_RE_DELAY_1_HCLK;

pccard_init_struct.ctr_latency = EXMC_CLE_RE_DELAY_1_HCLK;

pccard_init_struct.wait_feature = ENABLE;

pccard_init_struct.common_space_timing = & pccard_timing_init_struct;

pccard_init_struct.attribute_space_timing = & pccard_timing_init_struct;

pccard_init_struct. io_space_timing = & pccard_timing_init_struct;

exmc_pccard_init(&pccard_init_struct);

exmc_pccard_enable

The description of exmc_pccard_enable is shown as below:

Table 3-343. Function exmc_pccard_enable


Function name exmc_pccard_enable
Function prototype void exmc_pccard_enable(void);
Function descriptions enable EXMC PC card bank
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable EXMC PC card bank */

exmc_pccard_enable();

exmc_pccard_disable

The description of exmc_pccard_disable is shown as below:

267
GD32E50x Firmware Library User Guide
Table 3-344. Function exmc_pccard_disable
Function name exmc_pccard_disable
Function prototype void exmc_pccard_disable(void);
Function descriptions disable EXMC PC card bank
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable EXMC PC card bank */

exmc_pccard_disable();

exmc_interrupt_enable

The description of exmc_interrupt_enable is shown as below:

Table 3-345. Function exmc_interrupt_enable


Function name exmc_interrupt_enable
Function prototype void exmc_interrupt_enable(uint32_t exmc_bank,uint32_t interrupt);
Function descriptions enable EXMC interrupt
Precondition -
The called functions -
Input parameter{in}
exmc_bank specifies the NAND bank , PC card bank
EXMC_BANK1_NAND the NAND bank1
EXMC_BANK2_NAND the NAND bank2
EXMC_BANK3_PCCA
the PC Card bank
RD
Input parameter{in}
interrupt specify get which interrupt flag
EXMC_NAND_PCCAR
rising edge interrupt and corresponding flag
D_INT_FLAG_RISE
EXMC_NAND_PCCAR
high-level interrupt and corresponding flag
D_INT_FLAG_LEVEL
EXMC_NAND_PCCAR
falling edge interrupt and corresponding flag
D_INT_FLAG_FALL
Output parameter{out}
- -

268
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* enable EXMC rising edge interrupt*/

exmc_interrupt_enable(EXMC_BANK1_NAND, EXMC_NAND_PCCARD_INT_FLAG_RISE);

exmc_interrupt_disable

The description of exmc_interrupt_disable is shown as below:

Table 3-346. Function exmc_interrupt_disable


Function name exmc_interrupt_disable
Function prototype void exmc_interrupt_disable(uint32_t exmc_bank,uint32_t interrupt);
Function descriptions disable EXMC interrupt
Precondition -
The called functions -
Input parameter{in}
exmc_bank specifies the NAND bank , PC card bank
EXMC_BANK1_NAND the NAND bank1
EXMC_BANK2_NAND the NAND bank2
EXMC_BANK3_PCCA
the PC Card bank
RD
Input parameter{in}
interrupt specify get which interrupt flag
EXMC_NAND_PCCAR
rising edge interrupt and corresponding flag
D_INT_FLAG_RISE
EXMC_NAND_PCCAR
high-level interrupt and corresponding flag
D_INT_FLAG_LEVEL
EXMC_NAND_PCCAR
falling edge interrupt and corresponding flag
D_INT_FLAG_FALL
Output parameter{out}
- -
Return value
- -

Example:

/* disable EXMC rising edge interrupt */

exmc_interrupt_disable(EXMC_BANK1_NAND,
EXMC_NAND_PCCARD_INT_FLAG_RISE);

269
GD32E50x Firmware Library User Guide
exmc_flag_get

The description of exmc_flag_get is shown as below:

Table 3-347. Function exmc_flag_get


Function name exmc_flag_get
Function prototype FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag);
Function descriptions get EXMC flag status
Precondition -
The called functions -
Input parameter{in}
exmc_bank specifies the NAND bank , PC card bank
EXMC_BANK1_NAND the NAND bank1
EXMC_BANK2_NAND the NAND bank2
EXMC_BANK3_PCCA
the PC Card bank
RD
Input parameter{in}
flag specify get which flag
EXMC_NAND_PCCAR
interrupt rising edge status
D_FLAG_RISE
EXMC_NAND_PCCAR
interrupt high-level status
D_FLAG_LEVEL
EXMC_NAND_PCCAR
interrupt falling edge status
D_FLAG_FALL
EXMC_NAND_PCCAR
FIFO empty status
D_FLAG_FIFOE
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* check rising edge status is set or not*/

if(RESET != exmc_flag_get(EXMC_BANK1_NAND, EXMC_NAND_PCCARD_FLAG_RISE));

exmc_flag_clear

The description of exmc_flag_clear is shown as below:

Table 3-348. Function exmc_flag_clear


Function name exmc_flag_clear
Function prototype FlagStatus exmc_flag_clear (uint32_t exmc_bank,uint32_t flag);
Function descriptions clear EXMC flag status
Precondition -

270
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
exmc_bank specifies the NAND bank , PC card bank
EXMC_BANK1_NAND the NAND bank1
EXMC_BANK2_NAND the NAND bank2
EXMC_BANK3_PCCA
the PC Card bank
RD
Input parameter{in}
flag specify get which flag
EXMC_NAND_PCCAR
interrupt rising edge status
D_FLAG_RISE
EXMC_NAND_PCCAR
interrupt high-level status
D_FLAG_LEVEL
EXMC_NAND_PCCAR
interrupt falling edge status
D_FLAG_FALL
EXMC_NAND_PCCAR
FIFO empty status
D_FLAG_FIFOE
Output parameter{out}
- -
Return value
- -

Example:

/* clear rising edge status */

exmc_flag_clear(EXMC_BANK1_NAND, EXMC_NAND_PCCARD_FLAG_RISE);

exmc_interrupt_flag_get

The description of exmc_interrupt_flag_get is shown as below:

Table 3-349. Function exmc_interrupt_flag_get


Function name exmc_interrupt_flag_get
Function prototype FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank,uint32_t interrupt);
Function descriptions get EXMC interrupt flag
Precondition -
The called functions -
Input parameter{in}
exmc_bank specifies the NAND bank , PC card bank
EXMC_BANK1_NAND the NAND bank1
EXMC_BANK2_NAND the NAND bank2
EXMC_BANK3_PCCA
the PC Card bank
RD
Input parameter{in}

271
GD32E50x Firmware Library User Guide
interrupt specify get which interrupt flag
EXMC_NAND_PCCAR
rising edge interrupt and corresponding flag
D_INT_FLAG_RISE
EXMC_NAND_PCCAR
high-level interrupt and corresponding flag
D_INT_FLAG_LEVEL
EXMC_NAND_PCCAR
falling edge interrupt and corresponding flag
D_INT_FLAG_FALL
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* check rising edge interrup flag is set or not*/

if(RESET!=exmc_interrupt_flag_get(EXMC_BANK1_NAND,EXMC_NAND_PCCARD_INT_
FLAG_RISE));

exmc_interrupt_flag_clear

The description of exmc_interrupt_flag_clear is shown as below:

Table 3-350. Function exmc_interrupt_flag_clear


Function name exmc_interrupt_flag_clear
Function prototype void exmc_interrupt_flag_clear(uint32_t exmc_bank,uint32_t interrupt);
Function descriptions clear EXMC interrupt flag
Precondition -
The called functions -
Input parameter{in}
exmc_bank specifies the NAND bank , PC card bank
EXMC_BANK1_NAND the NAND bank1
EXMC_BANK2_NAND the NAND bank2
EXMC_BANK3_PCCA
the PC Card bank
RD
Input parameter{in}
interrupt specify get which interrupt flag
EXMC_NAND_PCCAR
rising edge interrupt and corresponding flag
D_INT_FLAG_RISE
EXMC_NAND_PCCAR
high-level interrupt and corresponding flag
D_INT_FLAG_LEVEL
EXMC_NAND_PCCAR
falling edge interrupt and corresponding flag
D_INT_FLAG_FALL
Output parameter{out}
- -

272
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* clear rising edge interrupt flag */

exmc_interrupt_flag_clear(EXMC_BANK1_NAND,EXMC_NAND_PCCARD_INT_FLAG_RI
SE);

3.12. EXTI

EXTI is the interrupt / event controller in the MCU. It contains up to 22 independent edge
detectors and generates interrupt requests or events to the processer. The EXTI registers are
listed in chapter 3.12.1, the EXTI firmware functions are introduced in chapter 3.12.2.

3.12.1. Descriptions of Peripheral registers

EXTI registers are listed in the table shown as below:

Table 3-351. EXTI Registers


Registers Descriptions
EXTI_INTEN Interrupt enable register
EXTI_EVEN Event enable register
EXTI_RTEN Rising edge trigger enable register
EXTI_FTEN Falling edge trigger enable register
EXTI_SWIEV Software interrupt event register
EXTI_PD Pending register

3.12.2. Descriptions of Peripheral functions

EXTI firmware functions are listed in the table shown as below:

Table 3-352. EXTI firmware function


Function name Function description
exti_deinit deinitialize the EXTI
exti_init initialize the EXTI
exti_interrupt_enable enable the interrupts from EXTI line x
exti_interrupt_disable disable the interrupts from EXTI line x
exti_event_enable enable the events from EXTI line x
exti_event_disable disable the events from EXTI line x
exti_software_interrupt_enable enable the EXTI software interrupt event
exti_software_interrupt_disable disable the EXTI software interrupt event
exti_flag_get get EXTI linex pending flag
exti_flag_clear clear EXTI linex pending flag

273
GD32E50x Firmware Library User Guide
Function name Function description
exti_interrupt_flag_get get EXTI linex flag when the interrupt flag is set
exti_interrupt_flag_clear clear EXTI line x pending flag

Enum exti_line_enum

Table 3-353. Enum exti_line_enum


Member name Function description
EXTI_0 EXTI line 0
EXTI_1 EXTI line 1
EXTI_2 EXTI line 2
EXTI_3 EXTI line 3
EXTI_4 EXTI line 4
EXTI_5 EXTI line 5
EXTI_6 EXTI line 6
EXTI_7 EXTI line 7
EXTI_8 EXTI line 8
EXTI_9 EXTI line 9
EXTI_10 EXTI line 10
EXTI_11 EXTI line 11
EXTI_12 EXTI line 12
EXTI_13 EXTI line 13
EXTI_14 EXTI line 14
EXTI_15 EXTI line 15
EXTI_16 EXTI line 16
EXTI_17 EXTI line 17
EXTI_18 EXTI line 18
EXTI_19 EXTI line 19
EXTI_20 EXTI line 20
EXTI_21 EXTI line 21

Enum exti_mode_enum

Table 3-354. Enum exti_mode_enum


Member name Function description
EXTI_INTERRUPT EXTI interrupt mode
EXTI_EVENT EXTI event mode

Enum exti_trig_type_enum

Table 3-355. Enum exti_trig_type_enum


Member name Function description
EXTI_TRIG_RISING EXTI rising edge trigger
EXTI_TRIG_FALLING EXTI falling edge trigger
274
GD32E50x Firmware Library User Guide
EXTI_TRIG_BOTH EXTI rising and falling edge trigger
EXTI_TRIG_NONE EXTI without rising or falling edge trigger

exti_deinit

The description of exti_deinit is shown as below:

Table 3-356. Function exti_deinit


Function name exti_deinit
Function prototype void exti_deinit(void);
Function descriptions deinitialize the EXTI. reset the value of all EXTI registers into initial values
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize the EXTI */

exti_deinit();

exti_init

The description of exti_init is shown as below:

Table 3-357. Function exti_init


Function name exti_init
void exti_init(exti_line_enum linex, exti_mode_enum mode,
Function prototype
exti_trig_type_enum trig_type);
Function descriptions initialize the EXTI
Precondition -
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Input parameter{in}
mode EXTI mode, refer to Enum exti_mode_enum
EXTI_INTERRUPT interrupt mode
EXTI_EVENT event mode
Input parameter{in}
trig_type trigger type, refer to Enum exti_trig_type_enum

275
GD32E50x Firmware Library User Guide
EXTI_TRIG_RISING rising edge trigger
EXTI_TRIG_FALLING falling edge trigger
EXTI_TRIG_BOTH rising edge and falling edge trigger
EXTI_TRIG_NONE without rising edge or falling edge trigger
Output parameter{out}
- -
Return value
- -

Example:

/* configure EXTI_0 */

exti_init(EXTI_0, EXTI_INTERRUPT, EXTI_TRIG_BOTH);

exti_interrupt_enable

The description of exti_interrupt_enable is shown as below:

Table 3-358. Function exti_interrupt_enable


Function name enable the interrupts from EXTI line x
Function prototype void exti_interrupt_enable(exti_line_enum linex);
Function descriptions enable the interrupts from EXTI line x
Precondition -
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
- -

Example:

/* enable the interrupts from EXTI line 0 */

exti_interrupt_enable(EXTI_0);

exti_interrupt_disable

The description of exti_interrupt_disable is shown as below:

Table 3-359. Function exti_interrupt_disable


Function name exti_interrupt_disable
Function prototype void exti_interrupt_disable(exti_line_enum linex);
Function descriptions disable the interrupts from EXTI line x
Precondition -
276
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
- -

Example:

/* disable the interrupts from EXTI line 0 */

exti_interrupt_disable(EXTI_0);

exti_event_enable

The description of exti_event_enable is shown as below:

Table 3-360. Function exti_event_enable


Function name exti_event_enable
Function prototype void exti_event_enable(exti_line_enum linex);
Function descriptions enable the events from EXTI line x
Precondition -
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
- -

Example:

/* enable the events from EXTI line 0 */

exti_event_enable(EXTI_0);

exti_event_disable

The description of exti_event_disable is shown as below:

Table 3-361. Function exti_event_disable


Function name exti_event_disable
Function prototype void exti_event_disable(exti_line_enum linex);
Function descriptions disable the events from EXTI line x
Precondition -
277
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
- -

Example:

/* disable the events from EXTI line 0 */

exti_event_disable(EXTI_0);

exti_software_interrupt_enable

The description of exti_software_interrupt_enable is shown as below:

Table 3-362. Function exti_software_interrupt_enable


Function name exti_software_interrupt_enable
Function prototype void exti_software_interrupt_enable(exti_line_enum linex);
Function descriptions enable the EXTI software interrupt event
Precondition -
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
- -

Example:

/* enable EXTI line 0 software interrupt event */

exti_software_interrupt_enable(EXTI_0);

exti_software_interrupt_disable

The description of exti_software_interrupt_disable is shown as below:

Table 3-363. Function exti_software_interrupt_disable


Function name exti_software_interrupt_disable
Function prototype void exti_software_interrupt_disable(exti_line_enum linex);
Function descriptions disable the EXTI software interrupt event
Precondition -
278
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
- -

Example:

/* disable EXTI line 0 software interrupt event */

exti_software_interrupt_disable(EXTI_0);

exti_flag_get

The description of exti_flag_get is shown as below:

Table 3-364. Function exti_flag_get


Function name exti_flag_get
Function prototype FlagStatus exti_flag_get(exti_line_enum linex);
Function descriptions get EXTI linex pending flag
Precondition -
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get EXTI line 0 flag status */

FlagStatus state = exti_flag_get(EXTI_0);

exti_flag_clear

The description of exti_flag_clear is shown as below:

Table 3-365. Function exti_flag_clear


Function name exti_flag_clear
Function prototype void exti_flag_clear(exti_line_enum linex);
Function descriptions clear EXTI linex pending flag
Precondition -
279
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
- -

Example:

/* clear EXTI line 0 flag status */

exti_flag_clear(EXTI_0);

exti_interrupt_flag_get

The description of exti_interrupt_flag_get is shown as below:

Table 3-366. Function exti_interrupt_flag_get


Function name exti_interrupt_flag_get
Function prototype FlagStatus exti_interrupt_flag_get(exti_line_enum linex);
Function descriptions get EXTI linex flag when the interrupt flag is set
Precondition -
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get EXTI line 0 interrupt flag status */

FlagStatus state = exti_interrupt_flag_get(EXTI_0);

exti_interrupt_flag_clear

The description of exti_interrupt_flag_clear is shown as below:

Table 3-367. Function exti_interrupt_flag_clear


Function name exti_interrupt_flag_clear
Function prototype void exti_interrupt_flag_clear(exti_line_enum linex);
Function descriptions clear EXTI linex pending flag
Precondition -
280
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
linex EXTI line x, refer to Enum exti_line_enum
EXTI_x x=0,1,2..21
Output parameter{out}
- -
Return value
- -

Example:

/* clear EXTI line 0 interrupt flag status */

exti_interrupt_flag_clear(EXTI_0);

3.13. FMC

There is flash controller and option byte for GD32E50x series. The FMC registers are listed
in chapter 3.13.1 the FMC firmware functions are introduced in chapter 3.13.2.

3.13.1. Descriptions of Peripheral registers

FMC registers are listed in the table shown as below: :

Table 3-368. FMC Registers


Registers Descriptions
FMC_WS FMC wait state register
FMC_KEY FMC unlock key register
FMC_OBKEY FMC option bytes unlock key register
FMC_STAT FMC status register
FMC_CTL FMC control register
FMC_ADDR FMC address register
FMC_OBSTAT FMC option bytes status register
FMC_WP FMC erase/program protection register
FMC_PID FMC product ID register

3.13.2. Descriptions of Peripheral functions

FMC firmware functions are listed in the table shown as below:

Table 3-369. FMC firmware function


Function name Function description
fmc_unlock unlock the main FMC operation
fmc_lock lock the main FMC operation
fmc_wscnt_set set the FMC wait state

281
GD32E50x Firmware Library User Guide
Function name Function description
fmc_prefetch_enable enable pre-fetch
fmc_prefetch_disable disable pre-fetch
fmc_ibus_enable enable IBUS cache
fmc_ibus_disable disable IBUS cache
fmc_ibus_reset reset IBUS cache
fmc_dbus_enable enable DBUS cache
fmc_dbus_disable disable DBUS cache
fmc_dbus_reset reset DBUS cache
fmc_page_erase FMC erase page
fmc_mass_erase FMC erase whole chip
fmc_word_program FMC program a word at the corresponding address
ob_unlock unlock the option bytes operation
ob_lock lock the option bytes operation
ob_erase erase the option bytes
ob_write_protection_enable enable write protection
ob_security_protection_config configure the option bytes security protection
ob_user_write program option bytes USER
ob_data_program program option bytes DATA
ob_user_get get the value of option bytes USER
ob_data_get get the value of option bytes DATA
ob_write_protection_get get the value of option bytes write protection
ob_security_protection_flag_get get option bytes security protection state
fmc_flag_get get FMC flag status
fmc_flag_clear clear the FMC flag
fmc_interrupt_enable enable FMC interrupt
fmc_interrupt_disable disable FMC interrupt
fmc_interrupt_flag_get get FMC interrupt flag state
fmc_interrupt_flag_clear clear FMC interrupt flag

Enum fmc_state_enum

Table 3-370. fmc_state_enum


enum name enum description
FMC_READY the operation has been completed
FMC_BUSY the operation is in progress
FMC_PGERR program error
FMC_PGAERR program alignment error
FMC_WPERR erase/program protection error
FMC_TOERR timeout error
FMC_OB_HSPC high security protection

282
GD32E50x Firmware Library User Guide
fmc_unlock

The description of fmc_unlock is shown as below:

Table 3-371. Function fmc_unlock


Function name fmc_unlock
Function prototype void fmc_unlock (void);
Function descriptions unlock the main FMC operation
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* unlock the main FMC operation */

fmc_unlock ( );

fmc_lock

The description of fmc_lock is shown as below:

Table 3-372. Function fmc_lock


Function name fmc_lock
Function prototype void fmc_lock(void);
Function descriptions lock the main FMC operation
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* lock the main FMC operation */

fmc_lock( );

283
GD32E50x Firmware Library User Guide
fmc_wscnt_set

The description of fmc_wscnt_set is shown as below:

Table 3-373. Function fmc_wscnt_set


Function name fmc_wscnt_set
Function prototype void fmc_wscnt_set(uint32_t wscnt);
Function descriptions set the wait state counter value
Precondition -
The called functions -
Input parameter{in}
wscnt wait state counter value
FMC_WAIT_STATE_0 0 wait state added
FMC_WAIT_STATE_1 1 wait state added
FMC_WAIT_STATE_2 2 wait state added
FMC_WAIT_STATE_3 3 wait state added
FMC_WAIT_STATE_4 4 wait state added
Output parameter{out}
- -
Return value
- -

Example:

/* set 1wait state */

fmc_wscnt_set (WS_WSCNT_1);

fmc_prefetch_enable

The description of fmc_prefetch_enable is shown as below:

Table 3-374. Function fmc_prefetch_enable


Function name fmc_prefetch_enable
Function prototype void fmc_prefetch_enable(void);
Function descriptions enable pre-fetch
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

284
GD32E50x Firmware Library User Guide
/* enable pre-fetch */

fmc_prefetch_enable( );

fmc_prefetch_disable

The description of fmc_prefetch_disable is shown as below:

Table 3-375. Function fmc_prefetch_disable


Function name fmc_prefetch_disable
Function prototype void fmc_prefetch_disable (void);
Function descriptions disable pre-fetch
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable pre-fetch */

fmc_prefetch_disable( );

fmc_ibus_enable

The description of fmc_ibus_enable is shown as below:

Table 3-376. Function fmc_ibus_enable


Function name fmc_ibus_enable
Function prototype void fmc_ibus_enable(void);
Function descriptions enable IBUS cache
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable IBUS cache */

285
GD32E50x Firmware Library User Guide
fmc_ibus_enable( );

fmc_ibus_disable

The description of fmc_ibus_disable is shown as below:

Table 3-377. Function fmc_ibus_disable


Function name fmc_ibus_disable
Function prototype void fmc_ibus_disable(void);
Function descriptions disable IBUS cache
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable IBUS cache */

fmc_ibus_disable( );

fmc_ibus_reset

The description of fmc_ibus_reset is shown as below:

Table 3-378. Function fmc_ibus_reset


Function name fmc_ibus_reset
Function prototype void fmc_ibus_reset(void);
Function descriptions reset IBUS cache
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset IBUS cache */

fmc_ibus_reset();

286
GD32E50x Firmware Library User Guide
fmc_dbus_enable

The description of fmc_dbus_enable is shown as below:

Table 3-379. Function fmc_dbus_enable


Function name fmc_dbus_enable
Function prototype void fmc_dbus_enable(void);
Function descriptions enable DBUS cache
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable DBUS cache */

fmc_dbus_enable( );

fmc_dbus_disable

The description of fmc_dbus_disable is shown as below:

Table 3-380. Function fmc_dbus_disable


Function name fmc_dbus_disable
Function prototype void fmc_dbus_disable(void);
Function descriptions disable DBUS cache
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable DBUS cache */

fmc_dbus_disable( );

287
GD32E50x Firmware Library User Guide
fmc_dbus_reset

The description of fmc_dbus_reset is shown as below:

Table 3-381. Function fmc_dbus_reset


Function name fmc_dbus_reset
Function prototype void fmc_dbus_reset(void);
Function descriptions reset DBUS cache
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset DBUS cache */

fmc_dbus_reset( );

fmc_page_erase

The description of fmc_page_erase is shown as below:

Table 3-382. Function fmc_page_erase


Function name fmc_page_erase
Function prototype fmc_state_enum fmc_page_erase(uint32_t page_address);
Function descriptions FMC erase page
Precondition fmc_unlock
The called functions -
Input parameter{in}
page_address the page address to be erased
Output parameter{out}
- -
Return value
fmc_state_enum state of FMC, refer to Enum fmc_state_enum

Example:

/* erase page */

fmc_unlock();

fmc_state_enum state = fmc_page_erase ( 0x08004000);

288
GD32E50x Firmware Library User Guide
fmc_mass_erase

The description of fmc_mass_erase is shown as below:

Table 3-383. Function fmc_mass_erase


Function name fmc_mass_erase
Function prototype fmc_state_enum fmc_mass_erase(void );
Function descriptions FMC erase whole chip
Precondition fmc_unlock
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
fmc_state_enum state of FMC, refer to Enum fmc_state_enum

Example:

/* erase whole chip */

fmc_unlock();

fmc_state_enum state = fmc_mass_erase ( );

fmc_word_program

The description of fmc_word_program is shown as below:

Table 3-384. Function fmc_word_program


Function name fmc_word_program
Function prototype fmc_state_enum fmc_word_program(uint32_t address, uint32_t data);
Function descriptions program a word at the corresponding address
Precondition fmc_unlock, fmc_page_erase / fmc_mass_erase
The called functions -
Input parameter{in}
address the address to program
Input parameter{in}
data the data to program
Output parameter{out}
- -
Return value
fmc_state_enum state of FMC, refer to Enum fmc_state_enum

Example:

/* program a word at the corresponding address */

289
GD32E50x Firmware Library User Guide
fmc_unlock();

fmc_page_erase(0x08004000);

fmc_state_enum state = fmc_word_program (0x08004000, 0xaabbccdd);

ob_unlock

The description of ob_unlock is shown as below:

Table 3-385. Function ob_unlock


Function name ob_unlock
Function prototype void ob_unlock(void);
Function descriptions unlock the option bytes operation
Precondition fmc_unlock
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* unlock the option bytes operation */

fmc_unlock( );

ob_unlock ( );

ob_lock

The description of ob_lock is shown as below:

Table 3-386. Function ob_lock


Function name ob_lock
Function prototype void ob_lock(void);
Function descriptions lock the option byts operation
Precondition fmc_unlock
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

290
GD32E50x Firmware Library User Guide
Example:

/* lock the option bytes operation */

fmc_unlock( );

ob_lock( );

ob_erase

The description of ob_erase is shown as below:

Table 3-387. Function ob_erase


Function name ob_erase
Function prototype fmc_state_enum ob_erase(void);
Function descriptions erase the FMC option bytes
Precondition ob_unlock
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
fmc_state_enum state of FMC, refer to Enum fmc_state_enum

Example:

/* erase the FMC option bytes */

fmc_unlock( );

ob_unlock( );

fmc_state enum state = ob_erase ( );

ob_write_protection_enable

The description of ob_write_protection_enable is shown as below:

Table 3-388. Function ob_write_protection_enable


Function name ob_write_protection_enable
Function prototype fmc_state_enum ob_write_protection_enable(uint32_t ob_wp);
Function descriptions enable write protection
Precondition ob_unlock
The called functions -
Input parameter{in}
ob_wp enable write protection
OB_WP_NONE disable all write protection
OB_WPx write protect specify sector x

291
GD32E50x Firmware Library User Guide
OB_WP_ALL write protect all sector
Output parameter{out}
- -
Return value
fmc_state_enum state of FMC, refer to Enum fmc_state_enum

Example:

/* enable write protection */

fmc_unlock( );

ob_unlock( );

fmc_state_enum state = ob_write_protection_enable (OB_WP7);

ob_security_protection_config

The description of ob_security_protection_config is shown as below:

Table 3-389. Function ob_security_protection_config

Function name ob_security_protection_config

Function prototype fmc_state_enum ob_security_protection_config (uint8_t ob_spc);


Function descriptions configure security protection
Precondition ob_unlock
The called functions -
Input parameter{in}
ob_spc specify security protection
FMC_NSPC no security protection
FMC_LSPC low security protection
FMC_HSPC high security protection
Output parameter{out}
- -
Return value
fmc_state_enum state of FMC, refer to Enum fmc_state_enum

Example:

/* enable security protection */

ob_unlock( );

fmc_state_enum state = ob_security_protection_config (FMC_LSPC);

ob_user_write

The description of ob_user_write is shown as below:

292
GD32E50x Firmware Library User Guide
Table 3-390. Function ob_user_write
Function name ob_user_write
fmc_state_enum ob_user_write(uint8_t ob_fwdgt, uint8_t ob_deepsleep,
Function prototype
uint8_t ob_stdby, uint8_t ob_boot);
Function descriptions program option bytes USER
Precondition ob_unlock
The called functions -
Input parameter{in}
ob_fwdgt option bytes watchdog value
OB_FWDGT_SW software free watchdog
OB_FWDGT_HW hardware free watchdog
Input parameter{in}
ob_deepsleep option bytes deepsleep reset value
OB_DEEPSLEEP_NRS
no reset when entering deepsleep mode
T
OB_DEEPSLEEP_RST generate a reset instead of entering deepsleep mode
Input parameter{in}
ob_stdby option bytes standby reset value
OB_STDBY_NRST no reset when entering standby mode
OB_STDBY_RST generate a reset instead of entering standby mode
Output parameter{out}
- -
Return value
fmc_state_enum state of FMC, refer to Enum fmc_state_enum

Example:

/* configure user option byte */

fmc_unlock( );

ob_unlock( );

fmc_state_enum state = ob_user_write(OB_FWDGT_HW,OB_DEEPSLEEP_RST,

OB_STDBY_RST);

ob_data_program

The description of ob_data_program is shown as below:

Table 3-391. Function ob_data_program


Function name ob_data_program
Function prototype fmc_state_enum ob_data_program(uint16_t ob_data);
Function descriptions program option bytes DATA
Precondition ob_unlock
The called functions -
293
GD32E50x Firmware Library User Guide
Input parameter{in}
data the byte to be programmed
Output parameter{out}
- -
Return value
fmc_state_enum state of FMC, refer to Enum fmc_state_enum

Example:

/* program option bytes data */

fmc_unlock( );

ob_unlock( );

fmc_state_enum state = ob_data_program (0x1ffff804, 0x56);

ob_user_get

The description of ob_user_get is shown as below:

Table 3-392. Function ob_user_get


Function name ob_user_get
Function prototype uint8_t ob_user_get(void);
Function descriptions get the value of option bytes USER
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint8_t the FMC user option bytes values(0x0 – 0xFF)

Example:

/* get the FMC user option bytes */

uint8_t user = ob_user_get ( );

ob_data_get

The description of ob_data_get is shown as below:

Table 3-393. Function ob_data_program


Function name ob_data_get
Function prototype uint16_t ob_data_get(void);
Function descriptions get the value of option bytes DATA
Precondition -

294
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
Uint16_t the FMC data option bytes values(0x0 – 0xFFFF)

Example:

/* get the FMC data option bytes */

uint16_t data = ob_data_get ( );

ob_write_protection_get

The description of ob_ write_protection_get is shown as below:

Table 3-394. Function ob_write_protection_get


Function name ob_ write_protection_get
Function prototype uint32_t ob_write_protection_get(void);
Function descriptions get the value of option bytes write protection
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t the FMC write protection option bytes value(0x0– 0XFFFFFFFF)

Example:

/* get the FMC option bytes write protection */

uint32_t wp = ob_write_protection_get ( );

ob_security_protection_flag_get

The description of ob_security_protection_flag_get is shown as below:

Table 3-395. Function ob_security_protection_flag_get


Function name ob_security_protection_flag_get
Function prototype FlagStatus ob_security_protection_flag_get(void);
Function descriptions get the FMC option bytes security protection state
Precondition -
The called functions -
Input parameter{in}
295
GD32E50x Firmware Library User Guide
- -
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the FMC option bytes security protection */

FlagStatus spc = ob_security_protection_flag_get( );

fmc_flag_get

The description of fmc_flag_get is shown as below:

Table 3-396. Function fmc_flag_get


Function name fmc_flag_get
Function prototype FlagStatus fmc_flag_get(uint32_t flag);
Function descriptions get FMC flag status
Precondition -
The called functions -
Input parameter{in}
flag FMC flag
FMC_FLAG_BUSY FMC busy flag
FMC_FLAG_PGERR FMC program error flag
FMC_FLAG_PGAERR FMC program alignment error flag
FMC_FLAG_WPERR FMC erase/program protection error flag
FMC_FLAG_END FMC end of operation flag
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get FMC end of operation flag */

FlagStatus flag = fmc_flag_get(FMC_FLAG_END);

fmc_flag_clear

The description of fmc_flag_clear is shown as below:

Table 3-397. Function fmc_flag_clear


Function name fmc_flag_clear
Function prototype void fmc_flag_clear(uint32_t flag);
Function descriptions clear the FMC flag
296
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
flag FMC flag
FMC_FLAG_PGERR FMC program error flag
FMC_FLAG_PGAERR FMC program alignment error flag
FMC_FLAG_WPERR FMC erase/program protection error flag
FMC_FLAG_END FMC end of operation flag
Output parameter{out}
- -
Return value
- -

Example:

/* clear FMC program error flag */

FlagStatus flag = fmc_flag_clear(FMC_FLAG_PGERR);

fmc_interrupt_enable

The description of fmc_interrupt_enable is shown as below:

Table 3-398. Function fmc_interrupt_enable


Function name fmc_interrupt_enable
Function prototype void fmc_interrupt_enable(uint32_t interrupt);
Function descriptions enable FMC interrupt
Precondition fmc_unlock
The called functions -
Input parameter{in}
interrupt FMC interrupt source
FMC_INT_END FMC end of operation interrupt
FMC_INT_ERR FMC error interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* enable FMC end of operation interrupt */

fmc_unlock( );

fmc_interrupt_enable(FMC_INT_END);

297
GD32E50x Firmware Library User Guide
fmc_interrupt_disable

The description of fmc_interrupt_disable is shown as below:

Table 3-399. Function fmc_interrupt_disable


Function name fmc_interrupt_disable
Function prototype void fmc_interrupt_disable(uint32_t interrupt);
Function descriptions disable FMC interrupt
Precondition fmc_unlock
The called functions -
Input parameter{in}
interrupt FMC interrupt source
FMC_INT_END FMC end of operation interrupt
FMC_INT_ERR FMC error interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* disable FMC end of operation interrupt */

fmc_unlock( );

fmc_interrupt_disable(FMC_INT_END);

fmc_interrupt_flag_get

The description of fmc_interrupt_flag_get is shown as below:

Table 3-400. Function fmc_interrupt_flag_get


Function name fmc_interrupt_flag_get
Function prototype FlagStatus fmc_interrupt_flag_get(fmc_interrupt_flag_enum flag);
Function descriptions get FMC interrupt flag
Precondition -
The called functions -
Input parameter{in}
flag FMC interrupt flag
FMC_INT_FLAG_PGE
FMC operation error interrupt flag
RR
FMC_INT_FLAG_PGA
FMC program alignment error interrupt flag
ERR
FMC_INT_FLAG_WPE
FMC erase/program protection error interrupt flag
RR
FMC_INT_FLAG_END FMC end of operation interrupt flag

298
GD32E50x Firmware Library User Guide
K0_PGERR
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get FMC operation error interrupt flag bit */

FlagStatus flag = fmc_interrupt_flag_get (FMC_INT_FLAG_PGERR);

fmc_interrupt_flag_clear

The description of fmc_interrupt_flag_get is shown as below:

Table 3-401. Function fmc_interrupt_flag_clear


Function name fmc_interrupt_flag_ clear
Function prototype FlagStatus fmc_interrupt_flag_clear (fmc_interrupt_flag_enum flag);
Function descriptions clear FMC interrupt flag
Precondition -
The called functions -
Input parameter{in}
flag FMC flag
FMC_INT_FLAG_PGE
FMC operation error interrupt flag
RR
FMC_INT_FLAG_PGA
FMC program alignment error interrupt flag
ERR
FMC_INT_FLAG_WPE
FMC erase/program protection error interrupt flag
RR
FMC_INT_FLAG_END
FMC end of operation interrupt flag
K0_PGERR
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* clear FMC operation error interrupt flag */

FlagStatus flag = fmc_interrupt_flag_clear (FMC_INT_FLAG_PGERR);

3.14. FWDGT

The free watchdog timer (FWDGT) is a hardware timing circuitry that can be used to detect

299
GD32E50x Firmware Library User Guide
system failures due to software malfunctions. It’s suitable for the situation that requires an
independent environment and lower timing accuracy.The FWDGT registers are listed in
chapter 3.14.1 the FWDGT firmware functions are introduced in chapter 3.14.2.

3.14.1. Descriptions of Peripheral registers

FWDGT registers are listed in the table shown as below:

Table 3-402. FWDGT Registers


Registers Descriptions
FWDGT_CTL Control register
FWDGT_PSC Prescaler register
FWDGT_RLD Reload register
FWDGT_STAT Status register

3.14.2. Descriptions of Peripheral functions

FWDGT firmware functions are listed in the table shown as below:

Table 3-403. FWDGT firmware function


Function name Function description
fwdgt_write_enable enable write access to FWDGT_PSC and FWDGT_RLD
fwdgt_write_disable disable write access to FWDGT_PSC and FWDGT_RLD
fwdgt_enable start the free watchdog timer counter
fwdgt_prescaler_value_config configure the FWDGT counter prescaler value
fwdgt_reload_value_config configure the FWDGT counter reload value
fwdgt_config configure counter reload value, and prescaler divider value
fwdgt_counter_reload reload the counter of FWDGT
fwdgt_flag_get get flag state of FWDGT

fwdgt_write_enable

The description of fwdgt_write_enable is shown as below:

Table 3-404. Function fwdgt_write_enable


Function name fwdgt_write_enable
Function prototype void fwdgt_write_enable(void);
Function descriptions enable write access to FWDGT_PSC and FWDGT_RLD
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
300
GD32E50x Firmware Library User Guide
- -

Example:

/* enable write access to FWDGT_PSC and FWDGT_RLD */

fwdgt_write_enable ( );

fwdgt_write_disable

The description of fwdgt_write_disable is shown as below:

Table 3-405. Function fwdgt_write_disable


Function name fwdgt_write_disable
Function prototype void fwdgt_write_disable(void);
Function descriptions disable write access to FWDGT_PSC and FWDGT_RLD
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable write access to FWDGT_PSC and FWDGT_RLD */

fwdgt_write_disable ( );

fwdgt_enable

The description of fwdgt_enable is shown as below:

Table 3-406. Function fwdgt_enable


Function name fwdgt_enable
Function prototype void fwdgt_enable(void);
Function descriptions start the free watchdog timer counter
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

301
GD32E50x Firmware Library User Guide
Example:

/* start the free watchdog timer counter */

fwdgt_enable ( );

fwdgt_prescaler_value_config

The description of fwdgt_prescaler_value_config is shown as below:

Table 3-407. Function fwdgt_prescaler_value_config


Function name fwdgt_prescaler_value_config
Function prototype ErrStatus fwdgt_prescaler_value_config(uint16_t prescaler_value);
Function descriptions configure the FWDGT counter prescaler value
Precondition -
The called functions -
Input parameter{in}
prescaler_value specify prescaler value
FWDGT_PSC_DIV4 FWDGT prescaler set to 4
FWDGT_PSC_DIV8 FWDGT prescaler set to 8
FWDGT_PSC_DIV16 FWDGT prescaler set to 16
FWDGT_PSC_DIV32 FWDGT prescaler set to 32
FWDGT_PSC_DIV64 FWDGT prescaler set to 64
FWDGT_PSC_DIV128 FWDGT prescaler set to 128
FWDGT_PSC_DIV256 FWDGT prescaler set to 256
Output parameter{out}
- -
Return value
- -

Example:

/* configure the FWDGT counter prescaler value */

fwdgt_prescaler_value_config (FWDGT_PSC_DIV8);

fwdgt_reload_value_config

The description of fwdgt_reload_value_config is shown as below:

Table 3-408. Function fwdgt_reload_value_config


Function name fwdgt_reload_value_config
Function prototype ErrStatus fwdgt_reload_value_config(uint16_t reload_value);
Function descriptions configure the FWDGT counter reload value
Precondition -
The called functions -
Input parameter{in}

302
GD32E50x Firmware Library User Guide
reload_value specify reload value(0x0000 - 0x0FFF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the FWDGT counter reload value */

fwdgt_reload_value_config(625);

fwdgt_config

The description of fwdgt_config is shown as below:

Table 3-409. Function fwdgt_config


Function name fwdgt_config
Function prototype ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div);
Function descriptions configure counter reload value, and prescaler divider value
Precondition -
The called functions -
Input parameter{in}
reload_value specify reload value(0x0000 - 0x0FFF)
Input parameter{in}
prescaler_div FWDGT prescaler value-
FWDGT_PSC_DIV4 FWDGT prescaler set to 4
FWDGT_PSC_DIV8 FWDGT prescaler set to 8
FWDGT_PSC_DIV16 FWDGT prescaler set to 16
FWDGT_PSC_DIV32 FWDGT prescaler set to 32
FWDGT_PSC_DIV64 FWDGT prescaler set to 64
FWDGT_PSC_DIV128 FWDGT prescaler set to 128
FWDGT_PSC_DIV256 FWDGT prescaler set to 256
Output parameter{out}
- -
Return value
ErrStatus ERROR or SUCCESS

Example:

/* confiure FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */

fwdgt_config(2*500, FWDGT_PSC_DIV64);

fwdgt_counter_reload

The description of fwdgt_counter_reload is shown as below:

303
GD32E50x Firmware Library User Guide
Table 3-410. Function fwdgt_counter_reload
Function name fwdgt_counter_reload
Function prototype void fwdgt_counter_reload(void);
Function descriptions reload the counter of FWDGT
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reload FWDGT counter */

fwdgt_counter_reload ( );

fwdgt_flag_get

The description of fwdgt_flag_get is shown as below:

Table 3-411. Function fwdgt_flag_get


Function name fwdgt_flag_get
Function prototype FlagStatus fwdgt_flag_get(uint16_t flag);
Function descriptions get flag state of FWDGT
Precondition -
The called functions -
Input parameter{in}
flag flag to get
FWDGT_FLAG_PUD a write operation to FWDGT_PSC register is on going
FWDGT_FLAG_RUD a write operation to FWDGT_RLD register is on going
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* test if a prescaler value update is on going */

FlagStatus status;

status = fwdgt_flag_get (FWDGT_FLAG_PUD);

if(status == RESET)

304
GD32E50x Firmware Library User Guide
{

...

}else

...
}

3.15. GPIO

GPIO is used to implement logic input/output functions for the devices. The GPIO registers
are listed in chapter 3.15.1, the GPIO firmware functions are introduced in chapter 3.15.2.

3.15.1. Descriptions of Peripheral registers

GPIO registers are listed in the table shown as below:

Table 3-412. GPIO Registers


Registers Descriptions
GPIOx_CTL0 GPIO port control register 0
GPIOx_CTL1 GPIO port control register 1
GPIOx_ISTAT GPIO port input status register
GPIOx_OCTL GPIO port output control register
GPIOx_BOP GPIO port bit operate register
GPIOx_BC GPIO port bit clear register
GPIOx_LOCK GPIO port configuration lock register
GPIOx_SPD GPIO port bit speed register
AFIO_EC AFIO event control register
AFIO_PCF0 AFIO port configuration register 0
AFIO_EXTISS0 AFIO port EXTI sources selection register 0
AFIO_EXTISS1 AFIO port EXTI sources selection register 1
AFIO_EXTISS2 AFIO port EXTI sources selection register 2
AFIO_EXTISS3 AFIO port EXTI sources selection register 3
AFIO_PCF1 AFIO port AFIO port configuration register 1
AFIO_CPSCTL IO compensation control register
AFIO_PCFA AFIO port configuration register A
AFIO_PCFB AFIO port configuration register B
AFIO_PCFC AFIO port configuration register C
AFIO_PCFD AFIO port configuration register D
AFIO_PCFE AFIO port configuration register E
AFIO_PCFG AFIO port configuration register G

305
GD32E50x Firmware Library User Guide
3.15.2. Descriptions of Peripheral functions

GPIO firmware functions are listed in the table shown as below:

Table 3-413. GPIO firmware function


Function name Function description
gpio_deinit reset GPIO port
gpio_afio_deinit reset alternate function I/O(AFIO)
gpio_init GPIO parameter initialization
gpio_bit_set set GPIO pin
gpio_bit_reset reset GPIO pin
gpio_bit_write write data to the specified GPIO pin
gpio_port_write write data to the specified GPIO port
gpio_input_bit_get get GPIO pin input status
gpio_input_port_get get GPIO port input status
gpio_output_bit_get get GPIO pin output status
gpio_output_port_get get GPIO port output status
gpio_pin_remap_config configure GPIO pin remap
gpio_afio_port_config configure AFIO port alternate function
gpio_ethernet_phy_select select ethernet MII or RMII PHY (for GD32E50X_CL devices)
gpio_exti_source_select select GPIO pin exti sources
gpio_event_output_config configure GPIO pin event output
gpio_event_output_enable enable GPIO pin event output
gpio_event_output_disable disable GPIO pin event output
gpio_pin_lock lock GPIO pin
gpio_compensation_config configure the I/O compensation cell
gpio_compensation_flag_get check the I/O compensation cell is ready or not

gpio_deinit

The description of gpio_deinit is shown as below:

Table 3-414. Function gpio_deinit


Function name gpio_deinit
Function prototype void gpio_deinit(uint32_t gpio_periph);
Function descriptions reset GPIO port
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Output parameter{out}
- -
Return value

306
GD32E50x Firmware Library User Guide
- -

Example:

/* reset GPIOA */

gpio_deinit (GPIOA);

gpio_afio_deinit

The description of gpio_afio_deinit is shown as below:

Table 3-415. Function gpio_afio_deinit


Function name gpio_afio_deinit
Function prototype void gpio_afio_deinit(void);
Function descriptions reset alternate function I/O(AFIO)
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset alternate function */

gpio_afio_deinit();

gpio_init

The description of gpio_init is shown as below:

Table 3-416. Function gpio_init


Function name gpio_init
void gpio_init(uint32_t gpio_periph, uint32_t mode, uint32_t speed, uint32_t
Function prototype
pin);
Function descriptions GPIO parameter initialization
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Input parameter{in}
gpio_mode gpio pin mode
GPIO_MODE_AIN analog input mode
307
GD32E50x Firmware Library User Guide
GPIO_MODE_IN
floating input mode
_FLOATING
GPIO_MODE_IPD pull-down input mode
GPIO_MODE_IPU pull-up input mode
GPIO_MODE_OUT
GPIO output with open-drain
_OD
GPIO_MODE_OUT_PP GPIO output with push-pull
GPIO_MODE_AF_OD AFIO output with open-drain
GPIO_MODE_AF_PP AFIO output with push-pull
Input parameter{in}
speed gpio output max speed value
GPIO_OSPEED_
output max speed 10MHz
10MHZ
GPIO_OSPEED_
output max speed 2MHz
2MHZ
GPIO_OSPEED_
output max speed 50MHz
50MHZ
GPIO_OSPEED_MAX output max speed more than 50MHz
Input parameter{in}
pin GPIO pin
GPIO_PIN_x GPIO_PIN_x(x=0..15)
GPIO_PIN_ALL All pins
Output parameter{out}
- -
Return value
- -

Example:

/* config PA0 as analog input mode*/

gpio_init (GPIOA, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_0);

gpio_bit_set

The description of gpio_bit_set is shown as below:

Table 3-417. Function gpio_bit_set


Function name gpio_bit_set
Function prototype void gpio_bit_set(uint32_t gpio_periph,uint32_t pin);
Function descriptions set GPIO pin
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port

308
GD32E50x Firmware Library User Guide
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Input parameter{in}
pin GPIO pin
GPIO_PIN_x GPIO_PIN_x(x=0..15)
GPIO_PIN_ALL All pins
Output parameter{out}
- -
Return value
- -

Example:

/* set PA0*/

gpio_bit_set (GPIOA, GPIO_PIN_0);

gpio_bit_reset

The description of gpio_bit_reset is shown as below:

Table 3-418. Function gpio_bit_reset


Function name gpio_bit_reset
Function prototype void gpio_bit_reset(uint32_t gpio_periph,uint32_t pin);
Function descriptions reset GPIO pin
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Input parameter{in}
pin GPIO pin
GPIO_PIN_x GPIO_PIN_x (x=0..15)
GPIO_PIN_ALL All pins
Output parameter{out}
- -
Return value
- -

Example:

/* reset PA0*/

gpio_bit_reset (GPIOA, GPIO_PIN_0);

gpio_bit_write

The description of gpio_bit_write is shown as below:

309
GD32E50x Firmware Library User Guide
Table 3-419. Function gpio_bit_write
Function name gpio_bit_write
Function prototype void gpio_bit_write(uint32_t gpio_periph,uint32_t pin,bit_status bit_value);
Function descriptions write data to the specified GPIO pin
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Input parameter{in}
pin GPIO pin
GPIO_PIN_x GPIO_PIN_x(x=0..15)
GPIO_PIN_ALL All pins
Input parameter{in}
bit_value SET or RESET
RESET clear the port pin
SET set the port pin
Output parameter{out}
- -
Return value
- -

Example:

/* write 1 to PA0 */

gpio_bit_write (GPIOA, GPIO_PIN_0, SET);

gpio_port_write

The description of gpio_port_write is shown as below:

Table 3-420. Function gpio_port_write


Function name gpio_port_write
Function prototype void gpio_port_write(uint32_t gpio_periph,uint16_t data);
Function descriptions write data to the specified GPIO port
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Input parameter{in}
data specify the value to be written to the port output data register
Output parameter{out}
- -

310
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/*write 1010 0101 1010 0101 to Port A */

gpio_port_write (GPIOA, 0xA5A5);

gpio_input_bit_get

The description of gpio_input_bit_get is shown as below:

Table 3-421. Function gpio_input_bit_get


Function name gpio_input_bit_get
Function prototype FlagStatus gpio_input_bit_get(uint32_t gpio_periph,uint32_t pin);
Function descriptions get GPIO pin input status
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Input parameter{in}
pin GPIO pin
GPIO_PIN_x GPIO_PIN_x (x=0..15)
GPIO_PIN_ALL All pins
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get status of PA0 */

FlagStatus bit_state;

bit_state = gpio_input_bit_get(GPIOA, GPIO_PIN_0);

gpio_input_port_get

The description of gpio_input_port_get is shown as below:

Table 3-422. Function gpio_input_port_get


Function name gpio_input_port_get
Function prototype uint16_t gpio_input_port_get(uint32_t gpio_periph);
Function descriptions get GPIO port input status
Precondition -

311
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Output parameter{out}
- -
Return value
uint16_t 0x0000-0xFFFF

Example:

/* get input value of Port A */

uint16_t port_state;

port_state = gpio_input_port_get(GPIOA);

gpio_output_bit_get

The description of gpio_output_bit_get is shown as below:

Table 3-423. Function gpio_output_bit_get


Function name gpio_output_bit_get
Function prototype FlagStatus gpio_output_bit_get(uint32_t gpio_periph,uint32_t pin);
Function descriptions get GPIO pin output status
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Input parameter{in}
pin GPIO pin
GPIO_PIN_x GPIO_PIN_x (x=0..15)
GPIO_PIN_ALL All pins
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get output status of PA0 */

FlagStatus bit_state;

bit_state = gpio_output_bit_get (GPIOA, GPIO_PIN_0);

312
GD32E50x Firmware Library User Guide
gpio_output_port_get

The description of gpio_output_port_get is shown as below:

Table 3-424. Function gpio_output_port_get


Function name gpio_output_port_get
Function prototype uint16_t gpio_output_port_get(uint32_t gpio_periph);
Function descriptions get GPIO port output status
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Output parameter{out}
- -
Return value
Uint16_t 0x0000-0xFFFF

Example:

/* get output value of Port A */

uint16_t port_state;

port_state = gpio_output_port_get (GPIOA);

gpio_pin_remap_config

The description of gpio_pin_remap_config is shown as below:

Table 3-425. Function gpio_pin_remap_config


Function name gpio_pin_remap_config
Function prototype void gpio_pin_remap_config(uint32_t remap, ControlStatus newvalue);
Function descriptions configure GPIO pin remap
Precondition -
The called functions -
Input parameter{in}
gpio_remap select the pin to remap
GPIO_SPI0_REMAP SPI0 remapping
GPIO_I2C0_REMAP I2C0 remapping
GPIO_USART0_REMA
USART0 remapping
P
GPIO_USART1_REMA
USART1 remapping
P
GPIO_USART2_PARTI
USART2 partial remapping
AL_REMAP

313
GD32E50x Firmware Library User Guide
GPIO_USART2_FULL_
USART2 full remapping
REMAP
GPIO_TIMER0_PARTI
TIMER0 partial remapping
AL_REMAP
GPIO_TIMER0_FULL_
TIMER0 full remapping
REMAP
GPIO_TIMER1_PARTI
TIMER1 partial remapping
AL_REMAP0
GPIO_TIMER1_PARTI
TIMER1 partial remapping
AL_REMAP1
GPIO_TIMER1_FULL_
TIMER1 full remapping
REMAP
GPIO_TIMER2_PARTI
TIMER2 partial remapping
AL_REMAP
GPIO_TIMER2_FULL_
TIMER2 full remapping
REMAP
GPIO_TIMER3_REMA
TIMER3 remapping
P
GPIO_PD01_REMAP PD01 remapping
GPIO_TIMER4CH3_IR
TIMER4 channel3 internal remapping
EMAP
GPIO_ADC0_ETRGINS ADC0 external trigger inserted conversion remapping(only for
_REMAP GD32E50X_HD devices and GD32E50X_XD devices)
GPIO_ADC0_ETRGRE ADC0 external trigger regular conversion remapping(only for
G_REMAP GD32E50X_HD devices and GD32E50X_XD devices)
GPIO_ADC1_ETRGINS ADC1 external trigger inserted conversion remapping(only for
_REMAP GD32E50X_HD devices and GD32E50X_XD devices)
GPIO_ADC1_ETRGRE ADC1 external trigger regular conversion remapping(only for
G_REMAP GD32E50X_HD devices and GD32E50X_XD devices)
GPIO_ENET_REMAP ENET remapping(only for GD32E50X_CL devices)
GPIO_SWJ_NONJTRS
full SWJ(JTAG-DP + SW-DP),but without NJTRST
T_REMAP
GPIO_SWJ_SWDPEN
JTAG-DP disabled and SW-DP enabled
ABLE_REMAP
GPIO_SWJ_DISABLE_
JTAG-DP disabled and SW-DP disabled
REMAP
GPIO_SPI2_REMAP SPI2 remapping
GPIO_TIMER1ITR0_R
TIMER1 internal trigger 0 remapping(only for GD32E50X_CL devices)
EMAP
GPIO_PTP_PPS_REM
ethernet PTP PPS remapping(only for GD32E50X_CL devices)
AP
GPIO_TIMER8_REMA
TIMER8 remapping
P

314
GD32E50x Firmware Library User Guide
GPIO_TIMER9_REMA
TIMER9 remapping
P
GPIO_TIMER10_REMA
TIMER10 remapping
P
GPIO_TIMER12_REMA
TIMER12 remapping
P
GPIO_TIMER13_REMA
TIMER13 remapping
P
GPIO_EXMC_NADV_R
EXMC_NADV connect/disconnect
EMAP
GPIO_CTC_REMAP0 CTC remapping(PD15)
GPIO_CTC_REMAP1 CTC remapping(PF0)
Input parameter{in}
newvalue control value
ENABLE enable function
DISABLE disable function
Output parameter{out}
- -
Return value
- -

Example:

/*enable SPI0 remapping*/

gpio_pin_remap_config (GPIO_SPI0_REMAP, ENABLE);

gpio_afio_port_config

The description of gpio_afio_port_config is shown as below:

Table 3-426. Function gpio_afio_port_config


Function name gpio_afio_port_config
Function prototype void gpio_afio_port_config(uint32_t afio_function, ControlStatus newvalue);
Function descriptions configure AFIO port alternate function
Precondition -
The called functions -
Input parameter{in}
configure the port alternate function(SHRTIMER not support on
afio_function
GD32E50X_EPRT devices)
AFIO_PA2_CMP1_C
configure PA2 alternate function to CMP1
FG
AFIO_PA3_USBHS_
configure PA3 alternate function to USBHS
CFG
AFIO_PA5_USBHS_ configure PA5 alternate function to USBHS

315
GD32E50x Firmware Library User Guide
CFG
AFIO_PA8_I2C2_CF
configure PA8 alternate function to I2C2
G
AFIO_PA8_SHRTIM
configure PA8 alternate function to SHRTIMER
ER_CFG
AFIO_PA9_I2C2_CF
configure PA9 alternate function to I2C2
G
AFIO_PA9_SHRTIM
configure PA9 alternate function to SHRTIMER
ER_CFG
AFIO_PA10_CMP5_
configure PA10 alternate function to CMP5
CFG
AFIO_PA10_SHRTI
configure PA10 alternate function to SHRTIMER
MER_CFG
AFIO_PA11_USART
configure PA11 alternate function to USART5
5_CFG
AFIO_PA11_SHRTI
configure PA11 alternate function to SHRTIMER
MER_CFG
AFIO_PA12_CMP1_
configure PA12 alternate function to CMP1
CFG
AFIO_PA12_USART
configure PA12 alternate function to USART5
5_CFG
AFIO_PA12_SHRTI
configure PA12 alternate function to SHRTIMER
MER_CFG
AFIO_PA15_SHRTI
configure PA15 alternate function to SHRTIMER
MER_CFG
AFIO_PB0_USBHS_
configure PB0 alternate function to USBHS
CFG
AFIO_PB1_CMP3_C
configure PB1 alternate function to CMP3
FG
AFIO_PB1_USBHS_
configure PB1 alternate function to USBHS
CFG
AFIO_PB1_SHRTIM
configure PB1 alternate function to SHRTIMER
ER_CFG
AFIO_PB2_USBHS_
configure PB2 alternate function to USBHS
CFG
AFIO_PB2_SHRTIM
configure PB2 alternate function to SHRTIMER
ER_CFG
AFIO_PB3_SHRTIM
configure PB3 alternate function to SHRTIMER
ER_CFG
AFIO_PB4_I2S2_CF
configure PB4 alternate function to I2S2
G
AFIO_PB4_I2C2_CF
configure PB4 alternate function to I2C2
G

316
GD32E50x Firmware Library User Guide
AFIO_PB4_SHRTIM
configure PB4 alternate function to SHRTIMER
ER_CFG
AFIO_PB5_I2C2_CF
configure PB5 alternate function to I2C2
G
AFIO_PB5_USBHS_
configure PB5 alternate function to USBHS
CFG
AFIO_PB5_SHRTIM
configure PB5 alternate function to SHRTIMER
ER_CFG
AFIO_PB6_SHRTIM
configure PB6 alternate function to SHRTIMER
ER_CFG
AFIO_PB7_SHRTIM
configure PB7 alternate function to SHRTIMER
ER_CFG
AFIO_PB8_I2C2_CF
configure PB8 alternate function to I2C2
G
AFIO_PB8_SHRTIM
configure PB8 alternate function to SHRTIMER
ER_CFG
AFIO_PB9_CMP1_C
configure PB9 alternate function to CMP1
FG
AFIO_PB9_SHRTIM
configure PB9 alternate function to SHRTIMER
ER_CFG
AFIO_PB10_USBHS
configure PB10 alternate function to USBHS
_CFG
AFIO_PB10_SHRTI
configure PB10 alternate function to SHRTIMER
MER_CFG
AFIO_PB11_USBHS
configure PB11 alternate function to USBHS
_CFG
AFIO_PB11_SHRTI
configure PB11 alternate function to SHRTIMER
MER_CFG
AFIO_PB12_USBHS
configure PB12 alternate function to USBHS
_CFG
AFIO_PB12_SHRTI
configure PB12 alternate function to SHRTIMER
MER_CFG
AFIO_PB13_USBHS
configure PB13 alternate function to USBHS
_CFG
AFIO_PB13_SHRTI
configure PB13 alternate function to SHRTIMER
MER_CFG
AFIO_PB14_I2S1_C
configure PB14 alternate function to I2S1
FG
AFIO_PB14_SHRTI
configure PB14 alternate function to SHRTIMER
MER_CFG
AFIO_PB15_SHRTI
configure PB15 alternate function to SHRTIMER
MER_CFG
AFIO_PC0_USBHS_ configure PC0 alternate function to USBHS

317
GD32E50x Firmware Library User Guide
CFG
AFIO_PC2_I2S1_CF
configure PC2 alternate function to I2S1
G
AFIO_PC2_USBHS_
configure PC2 alternate function to USBHS
CFG
AFIO_PC3_USBHS_
configure PC3 alternate function to USBHS
CFG
AFIO_PC6_CMP5_C
configure PC6 alternate function to CMP5
FG
AFIO_PC6_USART5
configure PC6 alternate function to USART5
_CFG
AFIO_PC6_SHRTIM
configure PC6 alternate function to SHRTIMER
ER_CFG
AFIO_PC7_USART5
configure PC7 alternate function to USART5
_CFG
AFIO_PC7_SHRTIM
configure PC7 alternate function to SHRTIMER
ER_CFG
AFIO_PC8_USART5
configure PC8 alternate function to USART5
_CFG
AFIO_PC8_SHRTIM
configure PC8 alternate function to SHRTIMER
ER_CFG
AFIO_PC9_I2C2_CF
configure PC9 alternate function to I2C2
G
AFIO_PC9_SHRTIM
configure PC9 alternate function to SHRTIMER
ER_CFG
AFIO_PC10_I2C2_C
configure PC10 alternate function to I2C2
FG
AFIO_PC11_I2S2_C
configure PC11 alternate function to I2S2
FG
AFIO_PC11_SHRTI
configure PC11 alternate function to SHRTIMER
MER_CFG
AFIO_PC12_SHRTI
configure PC12 alternate function to SHRTIMER
MER_CFG
AFIO_PD4_SHRTIM
configure PD4 alternate function to SHRTIMER
ER_CFG
AFIO_PD5_SHRTIM
configure PD5 alternate function to SHRTIMER
ER_CFG
AFIO_PE0_SHRTIM
configure PE0 alternate function to SHRTIMER
ER_CFG
AFIO_PE1_SHRTIM
configure PE1 alternate function to SHRTIMER
ER_CFG
AFIO_PE8_CMP1_C
configure PE8 alternate function to CMP1
FG

318
GD32E50x Firmware Library User Guide
AFIO_PE9_CMP3_C
configure PE9 alternate function to CMP3
FG
AFIO_PE10_CMP5_
configure PE10 alternate function to CMP5
CFG
AFIO_PE11_CMP5_
configure PE11 alternate function to CMP5
CFG
AFIO_PE12_CMP3_
configure PE12 alternate function to CMP3
CFG
AFIO_PE13_CMP1_
configure PE13 alternate function to CMP1
CFG
AFIO_PG6_SHRTIM
configure PG6 alternate function to SHRTIMER_C
ER_CFG
AFIO_PG7_USART5
configure PG7 alternate function to USART5
_CFG
AFIO_PG7_SHRTIM
configure PG7 alternate function to SHRTIMER
ER_CFG
AFIO_PG9_USART5
configure PG9 alternate function to USART5
_CFG
AFIO_PG10_SHRTI
configure PG10 alternate function to SHRTIMER
MER_CFG
AFIO_PG11_SHRTI
configure PG11 alternate function to SHRTIMER
MER_CFG
AFIO_PG12_SHRTI
configure PG12 alternate function to SHRTIMER
MER_CFG
AFIO_PG13_SHRTI
configure PG13 alternate function to SHRTIMER
MER_CFG
AFIO_PG14_USART
configure PG14 alternate function to USART5
5_CFG
Input parameter{in}
newvalue control value
ENABLE enable function
DISABLE disable function
Output parameter{out}
- -
Return value
- -

Example:

/* configure PG14 alternate function to USART5*/

gpio_afio_port_config (AFIO_PG14_USART5_CFG, ENABLE);

319
GD32E50x Firmware Library User Guide
gpio_ethernet_phy_select

The description of gpio_ethernet_phy_select is shown as below:

Table 3-427. Function gpio_ethernet_phy_select


Function name gpio_ethernet_phy_select
Function prototype void gpio_ethernet_phy_select(uint32_t enet_sel);
Function descriptions select ethernet MII or RMII PHY (for GD32E50X_CL devices)
Precondition -
The called functions -
Input parameter{in}
enet_sel ethernet MII or RMII PHY selection
GPIO_ENET_PHY_MII configure ethernet MAC for connection with an MII PHY
GPIO_ENET_PHY_
configure ethernet MAC for connection with an RMII PHY
RMII
Output parameter{out}
- -
Return value
- -

Example:

/* configure ethernet MAC for connection with an RMII PHY */

gpio_ethernet_phy_select (GPIO_ENET_PHY_RMII);

gpio_exti_source_select

The description of gpio_exti_source_select is shown as below:

Table 3-428. Function gpio_exti_source_select


Function name gpio_exti_source_select
Function prototype void gpio_exti_source_select(uint8_t output_port, uint8_t output_pin);
Function descriptions select GPIO pin exti sources
Precondition -
The called functions -
Input parameter{in}
output_port gpio event output port
GPIO_PORT_SOURCE
output port source (x= A,B,C,D,E)
_GPIOx
Input parameter{in}
output_pin gpio event output pin
GPIO_PIN_SOURCE_x pin number (x=0..15)
Output parameter{out}
- -
Return value

320
GD32E50x Firmware Library User Guide
- -

Example:

/* config PA0 as EXTI source*/

gpio_exti_source_select (GPIO_PORT_SOURCE_GPIOA, GPIO_PIN_SOURCE_0);

gpio_event_output_config

The description of gpio_event_output_config is shown as below:

Table 3-429. Function gpio_event_output_config


Function name gpio_event_output_config
Function prototype void gpio_event_output_config(uint8_t output_port, uint8_t output_pin);
Function descriptions configure GPIO pin event output
Precondition -
The called functions -
Input parameter{in}
output_port gpio event output port
GPIO_EVENT_PORT_
event output port x (x= A,B,C,D,E)
GPIOx
Input parameter{in}
output_pin gpio event output pin
GPIO_EVENT_PIN_x pin number (x=0..15)
Output parameter{out}
- -
Return value
- -

Example:

/* Config PA0 as the output of event */

gpio_event_output_config (GPIO_EVENT_PORT_GPIOA, GPIO_EVENT_PIN_0);

gpio_event_output_enable

The description of gpio_event_output_enable is shown as below:

Table 3-430. Function gpio_event_output_enable


Function name gpio_event_output_enable
Function prototype void gpio_event_output_enable(void);
Function descriptions enable GPIO pin event output
Precondition -
The called functions -
Input parameter{in}
- -
321
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* enable GPIO pin event output */

gpio_event_output_enable(void);

gpio_event_output_disable

The description of gpio_event_output_disable is shown as below:

Table 3-431. Function gpio_event_output_disable


Function name gpio_event_output_disable
Function prototype void gpio_event_output_disable(void);
Function descriptions disable GPIO pin event output
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable GPIO pin event output */

gpio_event_output_disable(void);

gpio_pin_lock

The description of gpio_pin_lock is shown as below:

Table 3-432. Function gpio_pin_lock


Function name gpio_pin_lock
Function prototype void gpio_pin_lock(uint32_t gpio_periph,uint32_t pin);
Function descriptions lock GPIO pin
Precondition -
The called functions -
Input parameter{in}
gpio_periph GPIO port
GPIOx GPIOx (x=A,B,C,D,E,F,G)
Input parameter{in}
322
GD32E50x Firmware Library User Guide
pin GPIO pin
GPIO_PIN_x GPIO_PIN_x(x=0..15)
GPIO_PIN_ALL All pins
Output parameter{out}
- -
Return value
- -

Example:

/* lock PA0 */

gpio_pin_lock (GPIOA, GPIO_PIN_0);

gpio_compensation_config

The description of gpio_compensation_config is shown as below:

Table 3-433. Function gpio_compensation_config


Function name gpio_compensation_config
Function prototype void gpio_compensation_config(uint32_t compensation);
Function descriptions configure the I/O compensation cell
Precondition -
The called functions -
Input parameter{in}
compensation specifies the I/O compensation cell mode
GPIO_COMPENSATIO
I/O compensation cell is enabled
N_ENABLE
GPIO_COMPENSATIO
I/O compensation cell is disabled
N_DISABLE
Output parameter{out}
- -
Return value
- -

Example:

/* enabled I/O compensation cell */

gpio_compensation_config (GPIO_COMPENSATION_ENABLE);

gpio_compensation_flag_get

The description of gpio_compensation_flag_get is shown as below:

Table 3-434. Function gpio_compensation_flag_get


Function name gpio_compensation_flag_get
Function prototype FlagStatus gpio_compensation_flag_get(void);
323
GD32E50x Firmware Library User Guide
Function descriptions check the I/O compensation cell is ready or not
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* check the I/O compensation cell state */

FlagStatus cell_state;

cell_state = gpio_compensation_flag_get (void);

3.16. SHRTIMER

SHRTIMER has a high-precision counting clock and can be used for high-precision timing. It
can generate 10 high precision and flexible digital signals to control motor or be used for
power management applications. The 10 digital signals can be output independently or
coupled into 5 pairs of complementary signals. The SHRTIMER registers are listed in chapter
3.16.1, the SHRTIMER firmware functions are introduced in chapter 3.16.2. The GD32EPRT
series does not have SHRTIMER module.

3.16.1. Descriptions of Peripheral registers

SHRTIMER registers are listed in the table shown as below:

Table 3-435. SHRTIMER Register


Registers Descriptions
Master Timer Registers
SHRTIMER_MTCTL0 Master_TIMER control register 0
SHRTIMER_MTINTF Master_TIMER interrupt flag register
SHRTIMER_MTINTC Master_TIMER interrupt flag clear register
SHRTIMER_MTDMAINTEN Master_TIMER DMA and interrupt enable register
SHRTIMER_MTCNT Master_TIMER counter register
SHRTIMER_MTCAR Master_TIMER counter auto reload register
SHRTIMER_MTCREP Master_TIMER counter repetition register
SHRTIMER_MTCMP0V Master_TIMER compare 0 value register
SHRTIMER_MTCMP1V Master_TIMER compare 1 value register
SHRTIMER_MTCMP2V Master_TIMER compare 2 value register
SHRTIMER_MTCMP3V Master_TIMER compare 3 value register

324
GD32E50x Firmware Library User Guide
Registers Descriptions
SHRTIMER_MTACTL Master_TIMER additional control register
Slave Timer Registers
SHRTIMER_STXCTL0 Slave_TIMERx control register 0
SHRTIMER_STXINTF Slave_TIMERx interrupt flag register
SHRTIMER_STXINTC Slave_TIMERx interrupt flag clear register
SHRTIMER_STXDMAINTEN Slave_TIMERx DMA and interrupt enable register
SHRTIMER_STXCNT Slave_TIMERx counter register
SHRTIMER_STXCAR Slave_TIMERx counter auto reload register
SHRTIMER_STXCREP Slave_TIMERx counter repetition register
SHRTIMER_STXCMP0V Slave_TIMERx compare 0 value register
SHRTIMER_STXCMP0CP Slave_TIMERx compare 0 composite register
SHRTIMER_STXCMP1V Slave_TIMERx compare 1 value register
SHRTIMER_STXCMP2V Slave_TIMERx compare 2 value register
SHRTIMER_STXCMP3V Slave_TIMERx compare 3 value register
SHRTIMER_STXCAP0V Slave_TIMERx capture 0 value register
SHRTIMER_STXCAP1V Slave_TIMERx capture 1 value register
SHRTIMER_STXDTCTL Slave_TIMERx dead-time control register
SHRTIMER_STXCH0SET Slave_TIMERx channel 0 set request register
SHRTIMER_STXCH0RST Slave_TIMERx channel 0 reset request register
SHRTIMER_STXCH1SET Slave_TIMERx channel 1 set request register
SHRTIMER_STXCH1RST Slave_TIMERx channel 1 reset request register
SHRTIMER_STXEXEVFCFG
Slave_TIMERx external event filter configuration register 0
0
SHRTIMER_STXEXEVFCFG
Slave_TIMERx external event filter configuration register 1
1
SHRTIMER_STXCNTRST Slave_TIMERx counter reset register
SHRTIMER_STXCSCTL Slave_TIMERx carrier-signal control register
SHRTIMER_STXCAP0TRG Slave_TIMERx capture 0 trigger register
SHRTIMER_STXCAP1TRG Slave_TIMERx capture 1 trigger register
SHRTIMER_STXCHOCTL Slave_TIMERx channel output control register
SHRTIMER_STXFLTCTL Slave_TIMERx fault control register
SHRTIMER_STXACTL Slave_TIMERx additional control register
Common Registers
SHRTIMER_CTL0 SHRTIMER control register 0
SHRTIMER_CTL1 SHRTIMER control register 1
SHRTIMER_INTF SHRTIMER interrupt flag register
SHRTIMER_INTC SHRTIMER interrupt flag clear register
SHRTIMER_INTEN SHRTIMER interrupt enable register
SHRTIMER_CHOUTEN SHRTIMER channel output enable register
SHRTIMER_CHOUTDIS SHRTIMER channel output disable register
SHRTIMER_CHOUTDISF SHRTIMER channel output disable flag register

325
GD32E50x Firmware Library User Guide
Registers Descriptions
SHRTIMER_BMCTL SHRTIMER bunch mode control register
SHRTIMER_BMSTRG SHRTIMER bunch mode start trigger register
SHRTIMER_BMCMPV SHRTIMER bunch mode compare value register
SHRTIMER_BMCAR SHRTIMER bunch mode counter auto reload register
SHRTIMER_EXEVCFG0 SHRTIMER external event configuration register 0
SHRTIMER_EXEVCFG1 SHRTIMER external event configuration register 1
SHRTIMER_EXEVDFCTL SHRTIMER external event digital filter control register
SHRTIMER_ADCTRIGS0 SHRTIMER trigger source 0 to ADC register
SHRTIMER_ADCTRIGS1 SHRTIMER trigger source 1 to ADC register
SHRTIMER_ADCTRIGS2 SHRTIMER trigger source 2 to ADC register
SHRTIMER_ADCTRIGS3 SHRTIMER trigger source 3 to ADC register
SHRTIMER_DLLCCTL SHRTIMER DLL calibration control register
SHRTIMER_FLTINCFG0 SHRTIMER fault input configuration register 0
SHRTIMER_FLTINCFG1 SHRTIMER fault input configuration register 1
SHRTIMER_DMAUPMTR SHRTIMER DMA update Master_TIMER register
SHRTIMER_DMAUPST0R SHRTIMER DMA update Slave_TIMER0 register
SHRTIMER_DMAUPST1R SHRTIMER DMA update Slave_TIMER1 register
SHRTIMER_DMAUPST2R SHRTIMER DMA update Slave_TIMER2 register
SHRTIMER_DMAUPST3R SHRTIMER DMA update Slave_TIMER3 register
SHRTIMER_DMAUPST4R SHRTIMER DMA update Slave_TIMER4 register
SHRTIMER_DMATB SHRTIMER DMA transfer buffer register

3.16.2. Descriptions of Peripheral functions

SHRTIMER firmware functions are listed in the table shown as below:

Table 3-436. SHRTIMER firmware function


Function name Function description
shrtimer_deinit deinit a SHRTIMER
shrtimer_dll_calibration_start configure and start DLL calibration
initialize SHRTIMER time base parameters struct with a
shrtimer_baseinit_struct_para_init
default value
shrtimer_timers_base_init initialize Master_TIMER and Slave_TIMER timerbase
shrtimer_timers_counter_enable enable a counter
shrtimer_timers_counter_disable disable a counter
shrtimer_timers_update_event_enabl
enable the Master_TIMER or Slave_TIMER update event
e
shrtimer_timers_update_event_disabl
disable the Master_TIMER or Slave_TIMER update event
e
trigger the Master_TIMER and Slave_TIMER registers update
shrtimer_software_update
by software
shrtimer_software_counter_reset the Master_TIMER and Slave_TIMER counter reset by

326
GD32E50x Firmware Library User Guide
Function name Function description
software
initialize waveform mode initialization parameters struct with a
shrtimer_timerinit_struct_para_init
default value
shrtimer_timers_waveform_init initialize a timer to work in waveform mode
initialize Slave_TIMER general behavior configuration struct
shrtimer_timercfg_struct_para_init
with a default value
configure the general behavior of a Slave_TIMER which work
shrtimer_slavetimer_waveform_config
in waveform mode
shrtimer_comparecfg_struct_para_init initialize compare unit configuration struct with a default value
shrtimer_slavetimer_waveform_ configure the compare unit of a Slave_TIMER which work in
compare_config waveform mode
shrtimer_channel_outputcfg_struct_ initialize channel output configuration struct with a default
para_init value
shrtimer_slavetimer_waveform_ configure the channel output of a Slave_TIMER work in
channel_config waveform mode
shrtimer_slavetimer_waveform_
software generates channel "set request" or "reset request"
channel_software_request
shrtimer_slavetimer_waveform_
get Slave_TIMER channel output level
channel_output_level_get
shrtimer_slavetimer_waveform_
get Slave_TIMER channel run state
channel_state_get
shrtimer_deadtimercfg_struct_para_
initialize dead time configuration struct with a default value
init
shrtimer_slavetimer_deadtime_config configure the dead time for Slave_TIMER
shrtimer_carriersignalcfg_struct_para
_ initialize carrier signal configuration struct with a default value
init
shrtimer_slavetimer_carriersignal_
configure the carrier signal mode for Slave_TIMER
config
shrtimer_output_channel_enable enable a output channel
shrtimer_output_channel_disable disable a output channel
shrtimer_mastertimer_compare_value
configure the compare value in Master_TIMER
_config
shrtimer_mastertimer_compare_value
get the compare value in Master_TIMER
_get
shrtimer_slavetimer_compare_value_
configure the compare value in Slave_TIMER
config
shrtimer_slavetimer_compare_value_
get the compare value in Slave_TIMER
get
configure the counter value in Master_TIMER and
shrtimer_timers_counter_value_config
Slave_TIMER
shrtimer_timers_counter_value_get get the counter value in Master_TIMER and Slave_TIMER

327
GD32E50x Firmware Library User Guide
Function name Function description
shrtimer_timers_autoreload_value_ configure the counter auto reload value in Master_TIMER and
config Slave_TIMER
shrtimer_timers_autoreload_value_ge get the counter auto reload value in Master_TIMER and
t Slave_TIMER
shrtimer_timers_repetition_value_ configure the counter repetition value in Master_TIMER and
config Slave_TIMER
get the counter repetition value in Master_TIMER and
shrtimer_timers_repetition_value_get
Slave_TIMER
initialize external event filtering for Slave_TIMER
shrtimer_exevfilter_struct_para_init
configuration struct with a default value
shrtimer_slavetimer_exevent_filtering configure the external event filtering for Slave_TIMER
_config (blanking, windowing)
initialize external event configuration struct with a default
shrtimer_exeventcfg_struct_para_init
value
shrtimer_exevent_config configure the an external event
shrtimer_exevent_prescaler configure external event digital filter clock division
initialize synchronization configuration struct with a default
shrtimer_synccfg_struct_para_init
value
shrtimer_synchronization_config configure the synchronization input/output of the SHRTIMER
shrtimer_faultcfg_struct_para_init configure the synchronization input/output of the SHRTIMER
shrtimer_fault_config configure the fault input
shrtimer_fault_prescaler_config configure the fault input digital filter clock division
shrtimer_fault_input_enable fault input enable
shrtimer_fault_input_disable fault input disable
shrtimer_timers_dma_enable enable the Master_TIMER and Slave_TIMER DMA request
shrtimer_timers_dma_disable disable the Master_TIMER and Slave_TIMER DMA request
shrtimer_dmamode_config configure the DMA mode for Master_TIMER or Slave_TIMER
shrtimer_bunchmode_struct_para_init initialize bunch mode configuration struct with a default value
shrtimer_bunchmode_config configure bunch mode for the SHRTIMER
shrtimer_bunchmode_enable enable the bunch mode
shrtimer_bunchmode_disable disable the bunch mode
shrtimer_bunchmode_flag_get get bunch mode operating flag
shrtimer_bunchmode_software_start bunch mode started by software
shrtimer_slavetimer_capture_config configure the capture source in Slave_TIMER
shrtimer_slavetimer_capture_software capture triggered by software in Slave_TIMER
shrtimer_slavetimer_capture_value_
read the capture value
read
shrtimer_adctrigcfg_struct_para_init initialize ADC trigger configuration struct with a default value
shrtimer_adc_trigger_config configure the trigger source to ADC and the update source
shrtimer_timers_flag_get get the Master_TIMER and Slave_TIMER flag
shrtimer_timers_flag_clear clear the Master_TIMER and Slave_TIMER flag
shrtimer_common_flag_get get the common flag
328
GD32E50x Firmware Library User Guide
Function name Function description
shrtimer_common_flag_clear clear the common flag
shrtimer_timers_interrupt_enable enable the Master_TIMER and Slave_TIMER interrupt
shrtimer_timers_interrupt_disable disable the Master_TIMER and Slave_TIMER interrupt
shrtimer_timers_interrupt_flag_get clear the Master_TIMER and Slave_TIMER interrupt flag
shrtimer_timers_interrupt_flag_clear clear the Master_TIMER and Slave_TIMER interrupt flag
shrtimer_common_interrupt_enable enable the common interrupt
shrtimer_common_interrupt_disable disable common interrupt
shrtimer_common_interrupt_flag_get clear the common interrupt flag
shrtimer_common_interrupt_flag_clea
clear the common interrupt flag
r

Structure shrtimer_baseinit_parameter_struct

Table 3-437. Structure shrtimer_baseinit_parameter_struct


member name Function description
period value, min value: 3 tSHRTIMER_CK clock, max value: 0xFFFF - (1
period
tSHRTIMER_CK)
repetitioncounter the counter repetition value, 0x00~0xFF
prescaler prescaler value, refer to: counter clock division
counter_mode counter operating mode, refer to: counter operating mode

Structure shrtimer_timerinit_parameter_struct

Table 3-438. Structure shrtimer_timerinit_parameter_struct


member name Function description
specifies whether or not half mode is enabled, refer to: half mode enabling
half_mode
status
specifies whether or not timer is started by a rising edge on the synchronization
start_sync
input, refer to: synchronous input start timer
specifies whether or not timer is reset by a rising edge on the synchronization
reset_sync
input, refer to: synchronous input reset timer
indicates whether or not the a DAC synchronization event is generated, refer
dac_trigger
to: trigger source to DAC
Indicates whether or not the a DAC synchronization event is generated, refer
shadow
to: trigger source to DAC
the update occurs with respect to DMA mode or STxUPINy (Slave_TIMERx
update_selection
only), refer to: update event selection
the timer behaves during a bunch mode operation, refer to: timer behaves
cnt_bunch
during a bunch mode operation
the timer behaves during a bunch mode operation, refer to: timer behaves
repetition_update
during a bunch mode operation

329
GD32E50x Firmware Library User Guide
Structure shrtimer_timercfg_parameter_struct

Table 3-439. Structure shrtimer_timercfg_parameter_struct


member name Function description
specifies whether or not the balanced mode is enabled, refer to: set balanced
balanced_mode
mode
specifies whether or not the fault channels are enabled for the Slave_TIMER,
fault_enable
refer to: faut channel enabled for a Slave_TIMER
specifies whether the write protection function is enable or not, refer to: protect
fault_protect
fault enable
specifies whether or not dead time insertion is enabled for the timer, refer to:
deadtime_enable
dead time enable
delayed_idle the delayed IDLE mode, refer to: set delayed IDLE state mode
the source triggering the Slave_TIMER registers update, refer to: update is
update_source
done synchronously with any other Slave_TIMER or Master_TIMER update
the source triggering the Slave_TIMER counter reset, refer to: Slave_TIMER
cnt_reset
counter reset
specifies whether or not registers update is triggered when the timer counter is
reset_update
reset, refer to: update event generated by reset event

Structure shrtimer_comparecfg_parameter_struct

Table 3-440. Structure shrtimer_comparecfg_parameter_struct


member name Function description
compare value, min value: 3 tSHRTIMER_CK clock, max value: 0xFFFF - (1
compare_value
tSHRTIMER_CK)
defining whether the compare register is behaving in regular mode or in
delayed_mode
delayed mode, refer to: compare 3 or 1 delayed mode
compare value for compare 0 or 2 when compare 3 or 1 is delayed mode with
timeout_value time out is selected , timeout_value + compare_value must be less than
0xFFFF

Structure shrtimer_exevfilter_parameter_struct

Table 3-441. Structure shrtimer_exevfilter_parameter_struct


member name Function description
the external event filter mode for Slave_TIMER, refer to: external event filter
filter_mode
mode
specifies whether or not the signal is memorized, refer to: external event
memorized
memorized enable

330
GD32E50x Firmware Library User Guide
Structure shrtimer_deadtimecfg_parameter_struct

Table 3-442. Structure shrtimer_deadtimecfg_parameter_struct


member name Function description
prescaler dead time generator clock division, refer to: dead time prescaler
rising_value rising edge dead-time value, 0x0000~0xFFFF
rising_sign the sign of rising edge dead-time value, refer to: dead time rising sign
dead time rising edge protection for value and sign, refer to: dead time rising
rising_protect
edge protection for value and sign
dead time rising edge protection for sign, refer to: dead time rising edge
risingsign_protect
protection only for sign
falling_value falling edge dead-time value, 0x0000~0xFFFF
falling_sign the sign of falling edge dead-time value, refer to: dead time falling sign
dead time falling edge protection for value and sign, refer to: dead time falling
falling_protect
edge protection for value and sign
dead time falling edge protection for sign, refer to: dead time falling edge
fallingsign_protect
protection only for sign

Structure shrtimer_carriersignalcfg_parameter_struct

Table 3-443. Structure shrtimer_carriersignalcfg_parameter_struct


member name Function description
carrier signal period: tCSPRD, 0x0~0xF. tCSPRD = (period + 1) * 16 *
period
tSHRTIMER_CK
duty_cycle carrier signal duty cycle, 0x0~0x7, duty cycle = duty_cycle/8
first carrier-signal pulse width: tCSFSTPW, 0x0~0xF. tCSFSTPW =
first_pulse
(first_pulse+1) * 16 * tSHRTIMER_CK

Structure shrtimer_synccfg_parameter_struct

Table 3-444. Structure shrtimer_synccfg_parameter_struct


member name Function description
the external synchronization input source, refer to: the synchronization input
input_source
source
the source and event to be sent on the external synchronization outputs, refer
output_source
to: the synchronization output source
the polarity and length of the pulse to be sent on the external synchronization
output_polarity outputs, refer to: the pulse on the synchronization output pad
SHRTIMER_SCOUT

Structure shrtimer_bunchmode_parameter_struct

Table 3-445. Structure shrtimer_bunchmode_parameter_struct


member name Function description

331
GD32E50x Firmware Library User Guide
mode the bunch mode operating mode, refer to: continuous mode in bunch mode
clock_source specifies the burst mode clock source, refer to: bunch mode clock source
prescaler the bunch mode prescaler, refer to: bunch mode clock division
specifies whether or not preload is enabled for SHRTIMER_BMCMPV and
shadow
SHRTIMER_BMCAR registers, refer to: bunch mode shadow enable
the event triggering the bunch operation, refer to: the event triggers bunch
trigger
mode operation
idle_duration the duration of the IDLE, 0x0000~0xFFFF
the bunch mode period which is the sum of the IDLE and RUN duration,
period
0x0001~0xFFFF

Structure shrtimer_exeventcfg_parameter_struct

Table 3-446. Structure shrtimer_exeventcfg_parameter_struct


member name Function description
source the source of the external event,refer to: external event source
the active level of external event 0 when EXEVyEG[1:0] = 2’b00, refer to:
polarity
external event polarity
edge the sensitivity of the external event, external event edge sensitivity
digital_filter external event filter control, 0x0~0xF

Structure shrtimer_faultcfg_parameter_struct

Table 3-447. Structure shrtimer_faultcfg_parameter_struct


member name Function description
source the source of the fault input, refer to: fault input source
polarity the polarity of the fault input, refer to: fault input polarity
filter fault input filter control, 0x0~0xF
control fault input enable or disable, refer to: enable or disable fault
protect protect fault input configuration, refer to: protect fault input configuration

Structure shrtimer_adctrigcfg_parameter_struct

Table 3-448. Structure shrtimer_adctrigcfg_parameter_struct


member name Function description
the source triggering the update of the SHRTIMER_ADCTRIGSy register, refer
update_source
to: SHRTIMER_ADCTRIG update source
trigger the event triggering the ADC conversion, refer to: ADC trigger event

Structure shrtimer_channel_outputcfg_parameter_struct

Table 3-449. Structure shrtimer_channel_outputcfg_parameter_struct


member name Function description

332
GD32E50x Firmware Library User Guide
polarity configure channel output polarity, refer to: channel output polarity
configure the event generates channel ‘set request’, refer to channel set
set_request
request
configure the event generates channel ‘reset request’, refer to: channel reset
reset_request
request
specifies whether channel output can be IDLE state in bunch mode, refer to:
idle_bunch
channel IDLE state enable in bunch mode
idle_state specifies channel output idle state, refer to channel output idle state
specifies the output level when in FAULT state, refer to: channel output in fault
fault_state
state
specifies whether or not the carrier-signal mode is enabled, refer to: channel
carrier_mode
carrier-signal mode enable
specifies whether or not deadtime is inserted before output entering the IDLE
deadtime_bunch
state in bunch mode, refer to: channel dead-time insert in bunch mode

shrtimer_deinit

The description of shrtimer_deinit is shown as below:

Table 3-450. Function shrtimer_deinit


Function name shrtimer_deinit
Function prototype void shrtimer_deinit(uint32_t shrtimer_periph);
Function descriptions deinit SHRTIMER
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Output parameter{out}
- -
Return value
- -

Example:

/* reset SHRTIMER */

shrtimer_deinit(SHRTIMER0);

shrtimer_dll_calibration_start

The description of shrtimer_dll_calibration_start is shown as below:

Table 3-451. Function shrtimer_dll_calibration_start


Function name shrtimer_dll_calibration_start
Function prototype void shrtimer_dll_calibration_start(uint32_t shrtimer_periph);

333
GD32E50x Firmware Library User Guide
Function descriptions configure and start DLL calibration
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
calform specify the calibration form
SHRTIMER_CALIBRAT
DLL calibration start once
ION_ONCE
SHRTIMER_CALIBRAT DLL periodic calibration, the length of the DLL calibration cycle is 1048576 *
ION_1048576_PERIOD tSHRTIMER_CK
SHRTIMER_CALIBRAT DLL periodic calibration, the length of the DLL calibration cycle is 131072 *
ION_131072_PERIOD tSHRTIMER_CK
SHRTIMER_CALIBRAT DLL periodic calibration, the length of the DLL calibration cycle is 16384 *
ION_16384_PERIOD tSHRTIMER_CK
SHRTIMER_CALIBRAT DLL periodic calibration, the length of the DLL calibration cycle is 2048 *
ION_2048_PERIOD tSHRTIMER_CK
Output parameter{out}
- -
Return value
- -

Example:

/* configure and start DLL calibration */

shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_ONCE);

shrtimer_baseinit_struct_para_init

The description of shrtimer_baseinit_struct_para_init is shown as below:

Table 3-452. Function shrtimer_baseinit_struct_para_init


Function name shrtimer_baseinit_struct_para_init
void shrtimer_baseinit_struct_para_init(shrtimer_baseinit_parameter_struct*
Function prototype
baseinit);
Function descriptions initialize SHRTIMER time base parameters struct with the default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_baseinit_parameter_struct, the structure members can refer to
baseinit
Structure shrtimer_baseinit_parameter_struct
Output parameter{out}
- -

334
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* initialize SHRTIMER time base parameters struct with the default value */

shrtimer_baseinit_parameter_struct baseinit;

shrtimer_baseinit_struct_para_init(&baseinit);

shrtimer_timers_base_init

The description of shrtimer_timers_base_init is shown as below:

Table 3-453. Function shrtimer_timers_base_init


Function name shrtimer_timers_base_init
Function prototype void shrtimer_timers_base_init(uint32_t shrtimer_periph);
Function descriptions initialize Master_TIMER and Slave_TIMER timerbase
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_
the slave timer selection(x=0..4)
TIMERx
Input parameter{in}
shrtimer_baseinit_parameter_struct, the structure members can refer to
baseinit
Structure shrtimer_baseinit_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize Master_TIMER and Slave_TIMER timerbase */

shrtimer_baseinit_parameter_struct baseinit_para;

shrtimer_baseinit_struct_para_init(&baseinit_para);

baseinit_para.period = 384;

baseinit_para.prescaler = SHRTIMER_PRESCALER_MUL64;
335
GD32E50x Firmware Library User Guide
baseinit_para.repetitioncounter = 0;

baseinit_para.counter_mode = SHRTIMER_COUNTER_MODE_CONTINOUS;

shrtimer_timers_base_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER0, &baseinit_para);

shrtimer_timers_counter_enable

The description of shrtimer_timers_counter_enable is shown as below:

Table 3-454. Function shrtimer_timers_counter_enable


Function name shrtimer_timers_counter_enable
void shrtimer_timers_counter_enable(uint32_t shrtimer_periph, uint32_t
Function prototype
cntid);
Function descriptions enable a counter
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
cntid specify the counter to configure
SHRTIMER_MT_COUN
the counter of Master_TIMER
TER
SHRTIMER_STx_COU
the counter of Slave_TIMERx(x=0..4)
NTER(x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* enable a counter */

void shrtimer_timers_counter_enable(SHRTIMER0, SHRTIMER_MT_COUNTER);

shrtimer_timers_counter_disable

The description of shrtimer_timers_counter_disable is shown as below:

Table 3-455. Function shrtimer_timers_counter_enable


Function name shrtimer_timers_counter_disable
void shrtimer_timers_counter_disable(uint32_t shrtimer_periph, uint32_t
Function prototype
cntid);
Function descriptions disable a counter
Precondition -

336
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
cntid specify the counter to configure
SHRTIMER_MT_COUN
the counter of Master_TIMER
TER
SHRTIMER_STx_COU
the counter of Slave_TIMERx(x=0..4)
NTER(x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* disable a counter */

shrtimer_timers_counter_disable(SHRTIMER0, SHRTIMER_MT_COUNTER);

shrtimer_timers_update_event_enable

The description of shrtimer_timers_update_event_enable is shown as below:

Table 3-456. Function shrtimer_timers_update_event_enable


Function name shrtimer_timers_update_event_enable
void shrtimer_timers_update_event_enable(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id);
Function descriptions enable the Master_TIMER or Slave_TIMER update event
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Output parameter{out}
- -
Return value
- -

337
GD32E50x Firmware Library User Guide
Example:

/* enable the Master_TIMER or Slave_TIMER update event */

shrtimer_timers_update_event_enable(SHRTIMER0, SHRTIMER_MASTER_TIMER);

shrtimer_timers_update_event_disable

The description of shrtimer_timers_update_event_disable is shown as below:

Table 3-457. Function shrtimer_timers_update_event_enable


Function name shrtimer_timers_update_event_disable
void shrtimer_timers_update_event_disable(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id);
Function descriptions disable the Master_TIMER or Slave_TIMER update event
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* disable the Master_TIMER or Slave_TIMER update event */

shrtimer_timers_update_event_disable(SHRTIMER0, SHRTIMER_MASTER_TIMER);

shrtimer_software_update

The description of shrtimer_software_update is shown as below:

Table 3-458. Function shrtimer_software_update


Function name shrtimer_software_update
Function prototype void shrtimer_software_update(uint32_t shrtimer_periph, uint32_t timersrc);
Function descriptions update the Master_TIMER or Slave_TIMER by software
Precondition -
The called functions -

338
GD32E50x Firmware Library User Guide
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timersrc software update timer selection
SHRTIMER_UPDATE_
Master_TIMER software update
SW_MT
SHRTIMER_UPDATE_
Slave_TIMERx software update (x=0..4)
SW_STx(x=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* update the Master_TIMER or Slave_TIMER by software */

void shrtimer_software_update(SHRTIMER0, SHRTIMER_UPDATE_SW_MT);

shrtimer_software_counter_reset

The description of shrtimer_software_counter_reset is shown as below:

Table 3-459. Function shrtimer_software_counter_reset


Function name shrtimer_software_counter_reset
void shrtimer_software_counter_reset(uint32_t shrtimer_periph, uint32_t
Function prototype
timerrst);
Function descriptions reset the Master_TIMER or Slave_TIMER counter by software
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timersrc software reset timer selection
SHRTIMER_COUNTER
Master_TIMER software reset
_RESET_SW_MT
SHRTIMER_COUNTER
_RESET_SW_STx Slave_TIMERx software reset(x=0..4)
(x=0..4)
Output parameter{out}
- -
Return value
- -

339
GD32E50x Firmware Library User Guide
Example:

/* triggers the Master_TIMER or Slave_TIMER registers update by software */

void shrtimer_software_counter_reset(SHRTIMER0,
SHRTIMER_COUNTER_RESET_SW_MT);

shrtimer_timerinit_struct_para_init

The description of shrtimer_timerinit_struct_para_init is shown as below:

Table 3-460. Function shrtimer_timerinit_struct_para_init


Function name shrtimer_timerinit_struct_para_init
void shrtimer_timerinit_struct_para_init(shrtimer_timerinit_parameter_struct*
Function prototype
timerinit);
Function descriptions initialize waveform mode initialization parameters struct with a default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_timerinit_parameter_struct, the structure members can refer to
timerinit
Structure shrtimer_timerinit_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize waveform mode initialization parameters struct with a default value */

shrtimer_timerinit_parameter_struct timerinit_para;

shrtimer_timerinit_struct_para_init(&timerinit_para);

shrtimer_timers_waveform_init

The description of shrtimer_timers_waveform_init is shown as below:

Table 3-461. Function shrtimer_timers_waveform_init


Function name shrtimer_timers_waveform_init
void shrtimer_timers_waveform_init(uint32_t shrtimer_periph, uint32_t
Function prototype
timer_id, shrtimer_timerinit_parameter_struct* timerinitpara);
Function descriptions initialize a timer to work in waveform mode
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection

340
GD32E50x Firmware Library User Guide
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
shrtimer_timerinit_parameter_struct, the structure members can refer to
timerinit
Structure shrtimer_timerinit_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize a timer to work in waveform mode */

shrtimer_timerinit_parameter_struct timerinit_para;

shrtimer_timerinit_struct_para_init(&timerinit_para);

timerinit_para.cnt_bunch = SHRTIMER_TIMERBUNCHNMODE_MAINTAINCLOCK;

timerinit_para.DAC_trigger = SHRTIMER_DAC_TRIGGER_NONE;

timerinit_para.half_mode = SHRTIMER_HALFMODE_DISABLED;

timerinit_para.repetition_update = SHRTIMER_UPDATEONREPETITION_DISABLED;

timerinit_para.reset_sync = SHRTIMER_SYNCRESET_DISABLED;

timerinit_para.shadow = SHRTIMER_SHADOW_DISABLED;

timerinit_para.start_sync = SHRTIMER_SYNISTART_DISABLED;

timerinit_para.update_selection =
SHRTIMER_MT_ST_UPDATE_SELECTION_INDEPENDENT;

shrtimer_timers_waveform_init(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
&timerinit_para);

shrtimer_timercfg_struct_para_init

The description of shrtimer_timercfg_struct_para_init is shown as below:

Table 3-462. Function shrtimer_timercfg_struct_para_init


Function name shrtimer_timercfg_struct_para_init
void
Function prototype shrtimer_timercfg_struct_para_init(shrtimer_timercfg_parameter_struct*
timercgf);
341
GD32E50x Firmware Library User Guide
initialize Slave_TIMER general behavior configuration struct with a default
Function descriptions
value
Precondition -
The called functions -
Input parameter{in}
shrtimer_timercfg_parameter_struct, the structure members can refer to
timercfg
Structure shrtimer_timercfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize Slave_TIMER general behavior configuration struct with a default value */

shrtimer_timercfg_parameter_struct timercfg_para;

shrtimer_timercfg_struct_para_init(timercfg_para);

shrtimer_slavetimer_waveform_config

The description of shrtimer_slavetimer_waveform_config is shown as below:

Table 3-463. Function shrtimer_slavetimer_waveform_config


Function name shrtimer_slavetimer_waveform_config
void shrtimer_slavetimer_waveform_config(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, shrtimer_timercfg_parameter_struct * timercfg);
initialize Slave_TIMER general behavior configuration struct with a default
Function descriptions
value
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
shrtimer_timercfg_parameter_struct, the structure members can refer to
timercfg
Structure shrtimer_timercfg_parameter_struct
Output parameter{out}
- -
342
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* initialize Slave_TIMER general behavior configuration struct with a default value */

shrtimer_timercfg_parameter_struct timercfg_para;

shrtimer_timercfg_struct_para_init(&timercfg_para);

timercfg_para.balanced_mode = SHRTIMER_STXBALANCEDMODE_DISABLED;

timercfg_para.cnt_reset = SHRTIMER_STXCNT_RESET_NONE;

timercfg_para.deadtime_enable = SHRTIMER_STXDEADTIME_DISABLED;

timercfg_para.delayed_idle = SHRTIMER_STXDELAYED_IDLE_DISABLED;

timercfg_para.fault_enable = SHRTIMER_STXFAULTENABLE_NONE;

timercfg_para.fault_protect = SHRTIMER_STXFAULT_PROTECT_READWRITE;

timercfg_para.reset_update = SHRTIMER_STXUPDATEONRESET_DISABLED;

timercfg_para.update_source = SHRTIMER_STXUPDATETRIGGER_NONE;

shrtimer_slavetimer_waveform_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
&timercfg_para);

shrtimer_comparecfg_struct_para_init

The description of shrtimer_comparecfg_struct_para_init is shown as below:

Table 3-464. Function shrtimer_comparecfg_struct_para_init


Function name shrtimer_comparecfg_struct_para_init
void
Function prototype shrtimer_comparecfg_struct_para_init(shrtimer_comparecfg_parameter_str
uct* comparecfg);
Function descriptions initialize compare unit configuration struct with a default value
Precondition -
The called functions -
Input parameter{in}
timer parameter initialization struct, the structure members can refer to
comparecfg
Structure shrtimer_comparecfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

343
GD32E50x Firmware Library User Guide
/* initialize compare unit configuration struct with a default value */

shrtimer_comparecfg_parameter_struct comparecfg_para;

shrtimer_comparecfg_struct_para_init(comparecfg_para);

shrtimer_slavetimer_waveform_compare_config

The description of shrtimer_slavetimer_waveform_compare_config is shown as below:

Table 3-465. Function shrtimer_slavetimer_waveform_compare_config


Function name shrtimer_slavetimer_waveform_compare_config
void shrtimer_slavetimer_waveform_compare_config(uint32_t
Function prototype shrtimer_periph, uint32_t timer_id, uint32_t comparex,
shrtimer_comparecfg_parameter_struct* cmpcfg);
configure the compare unit of a Slave_TIMER which work in waveform
Function descriptions
mode
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
comparex compare unit selection
SHRTIMER_COMPAR
the compare unit y(y=0..4)
Ey (y=0..4)
Input parameter{in}
timer parameter initialization struct, the structure members can refer to
comparecfg
Structure shrtimer_comparecfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* configure the compare unit of a Slave_TIMER which work in waveform mode */

shrtimer_comparecfg_parameter_struct comparecfg_para;

shrtimer_comparecfg_struct_para_init(&comparecfg_para);
344
GD32E50x Firmware Library User Guide
comparecfg_para.compare_value = 192;

shrtimer_slavetimer_waveform_compare_config(SHRTIMER0,
SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE0, &comparecfg_para);

shrtimer_channel_outputcfg_struct_para_init

The description of shrtimer_channel_outputcfg_struct_para_init is shown as below:

Table 3-466. Function shrtimer_channel_outputcfg_struct_para_init


Function name shrtimer_channel_outputcfg_struct_para_init
void
Function prototype shrtimer_channel_outputcfg_struct_para_init(shrtimer_channel_outputcfg_p
arameter_struct * channelcfg);
Function descriptions initialize channel output configuration struct with a default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_channel_outputcfg_parameter_struct, the structure members can
channelcfg
refer to Structure shrtimer_channel_outputcfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize channel output configuration struct with a default value */

shrtimer_channel_outputcfg_parameter_struct outcfg_para;

shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);

shrtimer_slavetimer_waveform_channel_config

The description of shrtimer_slavetimer_waveform_channel_config is shown as below:

Table 3-467. Function shrtimer_slavetimer_waveform_channel_config


Function name shrtimer_slavetimer_waveform_channel_config
void shrtimer_slavetimer_waveform_channel_config(uint32_t
Function prototype shrtimer_periph, uint32_t timer_id, uint32_t channel,
shrtimer_channel_outputcfg_parameter_struct * channelcfg);
Function descriptions configure the channel of a Slave_TIMER work in waveform mode
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral

345
GD32E50x Firmware Library User Guide
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER timer index
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
channel SHRTIMER timer channel index
SHRTIMER_STx_CHy(
SHRTIMER timer channel selection
x=0..4,y=0,1)
Input parameter{in}
shrtimer_channel_outputcfg_parameter_struct, the structure members can
channelcfg
refer to Structure shrtimer_channel_outputcfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* configure the channel of a Slave_TIMER work in waveform mode */

shrtimer_channel_outputcfg_parameter_struct outcfg_para;

shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);

outcfg_para.carrier_mode = SHRTIMER_CHANNEL_CARRIER_DISABLED;

outcfg_para.deadtime_bunch = SHRTIMER_CHANNEL_BUNCH_ENTRY_REGULAR;

outcfg_para.fault_state = SHRTIMER_CHANNEL_FAULTSTATE_NONE;

outcfg_para.idle_bunch = SHRTIMER_CHANNEL_BUNCH_IDLE_DISABLE;

outcfg_para.idle_state = SHRTIMER_CHANNEL_IDLESTATE_INACTIVE;

outcfg_para.polarity = SHRTIMER_CHANNEL_POLARITY_HIGH;

outcfg_para.reset_request = SHRTIMER_CHANNEL_RESET_CMP1;

outcfg_para.set_request = SHRTIMER_CHANNEL_SET_CMP0;

shrtimer_slavetimer_waveform_channel_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
SHRTIMER_ST0_CH0, &outcfg_para);

shrtimer_slavetimer_waveform_channel_software_request

The description of shrtimer_slavetimer_waveform_channel_software_request is shown as


below:

346
GD32E50x Firmware Library User Guide
Table 3-468. Function shrtimer_slavetimer_waveform_channel_software_request
Function name shrtimer_slavetimer_waveform_channel_software_request
void shrtimer_slavetimer_waveform_channel_software_request(uint32_t
Function prototype
shrtimer_periph, uint32_t timer_id, uint32_t channel, uint32_t request)
Function descriptions software generates channel "set request" or "reset request"
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER timer index
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
channel SHRTIMER timer channel index
SHRTIMER_STx_CHy(
SHRTIMER timer channel selection
x=0..4,y=0,1)
Input parameter{in}
request request type selection
SHRTIMER_CHANNEL
software event cannot generate request
_SOFTWARE_SET
SHRTIMER_CHANNEL
software event can generate request
_SOFTWARE_RESET
Output parameter{out}
- -
Return value
- -

Example:

/* software generates channel "set request" or "reset request" */

shrtimer_slavetimer_waveform_channel_software_request (SHRTIMER0,
SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST0_CH0,
SHRTIMER_CHANNEL_SOFTWARE_SET);

shrtimer_slavetimer_waveform_channel_output_level_get

The description of shrtimer_slavetimer_waveform_channel_output_level_get is shown as


below:

347
GD32E50x Firmware Library User Guide
Table 3-469. Function shrtimer_slavetimer_waveform_channel_output_level_get
Function name shrtimer_slavetimer_waveform_channel_output_level_get
uint32_t shrtimer_slavetimer_waveform_channel_output_level_get(uint32_t
Function prototype
shrtimer_periph, uint32_t timer_id, uint32_t channel);
Function descriptions get Slave_TIMER channel output level
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER timer index
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
channel SHRTIMER timer channel index
SHRTIMER_STx_CHy(
SHRTIMER timer channel selection
x=0..4,y=0,1)
Output parameter{out}
- -
Return value
uint32_t channel output level

Example:

/* get Slave_TIMER channel output level */

uint32_t output_level;

output_level = shrtimer_slavetimer_waveform_channel_output_level_get(uint32_t
shrtimer_periph, uint32_t timer_id, uint32_t channel)

shrtimer_slavetimer_waveform_channel_state_get

The description of shrtimer_slavetimer_waveform_channel_state_get is shown as below:

Table 3-470. Function shrtimer_slavetimer_waveform_channel_state_get


Function name shrtimer_slavetimer_waveform_channel_state_get
uint32_t shrtimer_slavetimer_waveform_channel_state_get(uint32_t
Function prototype
shrtimer_periph, uint32_t timer_id, uint32_t channel)
Function descriptions get Slave_TIMER channel run state
Precondition -
The called functions -
Input parameter{in}
348
GD32E50x Firmware Library User Guide
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER timer index
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
channel SHRTIMER timer channel index
SHRTIMER_STx_CHy(
SHRTIMER timer channel selection
x=0..4,y=0,1)
Output parameter{out}
- -
Return value
SHRTIMER_CHANNEL_STATE_IDLE or
uint32_t SHRTIMER_CHANNEL_STATE_RUN or
SHRTIMER_CHANNEL_STATE_FAULT

Example:

/* get Slave_TIMER channel run state */

uint32_t output_state;

output_state = shrtimer_slavetimer_waveform_channel_state_get (SHRTIMER0,


SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST0_CH0);

shrtimer_deadtimercfg_struct_para_init

The description of shrtimer_deadtimercfg_struct_para_init is shown as below:

Table 3-471. Function shrtimer_channel_outputcfg_struct_para_init


Function name shrtimer_deadtimercfg_struct_para_init
void
Function prototype shrtimer_deadtimercfg_struct_para_init(shrtimer_deadtimecfg_parameter_s
truct * dtcfg);
Function descriptions initialize dead time configuration struct with a default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_deadtimecfg_parameter_struct, the structure members can refer to
dtcfg
Structure shrtimer_deadtimecfg_parameter_struct
Output parameter{out}
- -
Return value

349
GD32E50x Firmware Library User Guide
- -

Example:

/* initialize dead time configuration struct with a default value */

shrtimer_deadtimecfg_parameter_struct deadtimecfg_para;

shrtimer_deadtimercfg_struct_para_init(&deadtimecfg_para);

shrtimer_slavetimer_deadtime_config

The description of shrtimer_slavetimer_deadtime_config is shown as below:

Table 3-472. Function shrtimer_slavetimer_waveform_channel_software_request


Function name shrtimer_slavetimer_deadtime_config
void shrtimer_slavetimer_deadtime_config(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, shrtimer_deadtimecfg_parameter_struct* dtcfg)
Function descriptions configure the dead time for Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER timer index
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
shrtimer_deadtimecfg_parameter_struct, the structure members can refer to
dtcfg
Structure shrtimer_deadtimecfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* configure the dead time for Slave_TIMER */

shrtimer_deadtimecfg_parameter_struct deadtimecfg_para;

shrtimer_deadtimercfg_struct_para_init(&deadtimecfg_para);

deadtimecfg_para.fallingsign_protect =
SHRTIMER_DEADTIME_FALLINGSIGN_PROTECT_DISABLE;

deadtimecfg_para.falling_protect =
SHRTIMER_DEADTIME_FALLING_PROTECT_DISABLE;

350
GD32E50x Firmware Library User Guide
deadtimecfg_para.falling_sign = SHRTIMER_DEADTIME_FALLINGSIGN_POSITIVE;

deadtimecfg_para.falling_value = 0x0040;

deadtimecfg_para.prescaler = SHRTIMER_DEADTIME_PRESCALER_MUL8;

deadtimecfg_para.risingsign_protect =
SHRTIMER_DEADTIME_RISINGSIGN_PROTECT_DISABLE;

deadtimecfg_para.rising_protect = SHRTIMER_DEADTIME_RISING_PROTECT_DISABLE;

deadtimecfg_para.rising_sign = SHRTIMER_DEADTIME_RISINGSIGN_POSITIVE;

deadtimecfg_para.rising_value = 0x0040;

shrtimer_slavetimer_deadtime_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
&deadtimecfg_para);

shrtimer_carriersignalcfg_struct_para_init

The description of shrtimer_carriersignalcfg_struct_para_init is shown as below:

Table 3-473. Function shrtimer_channel_outputcfg_struct_para_init


Function name shrtimer_carriersignalcfg_struct_para_init
void
Function prototype shrtimer_carriersignalcfg_struct_para_init(shrtimer_carriersignalcfg_parame
ter_struct* carriercfg);
Function descriptions initialize carrier signal configuration struct with a default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_carriersignalcfg_parameter_struct, the structure members can
carriercfg
refer to shrtimer_carriersignalcfg_struct_para_init
Output parameter{out}
- -
Return value
- -

Example:

/* initialize carrier signal configuration struct with a default value */

shrtimer_carriersignalcfg_parameter_struct carriercfg;

shrtimer_carriersignalcfg_struct_para_init(&carriercfg);

shrtimer_slavetimer_carriersignal_config

The description of shrtimer_slavetimer_carriersignal_config is shown as below:

351
GD32E50x Firmware Library User Guide
Table 3-474. Function shrtimer_slavetimer_carriersignal_config
Function name shrtimer_slavetimer_carriersignal_config
void shrtimer_slavetimer_carriersignal_config(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, shrtimer_carriersignalcfg_parameter_struct* carriercfg);
Function descriptions configure the carrier signal mode for Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER timer index
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
shrtimer_carriersignalcfg_parameter_struct, the structure members can
carriercfg
refer to shrtimer_carriersignalcfg_struct_para_init
Output parameter{out}
- -
Return value
- -

Example:

/* configure the carrier signal mode for Slave_TIMER */

shrtimer_carriersignalcfg_parameter_struct carriercfg;

shrtimer_carriersignalcfg_struct_para_init(&carriercfg);

shrtimer_slavetimer_carriersignal_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
&carriercfg);

shrtimer_output_channel_enable

The description of shrtimer_output_channel_enable is shown as below:

Table 3-475. Function shrtimer_output_channel_enable


Function name shrtimer_output_channel_enable
void shrtimer_output_channel_enable(uint32_t shrtimer_periph, uint32_t
Function prototype
chid);
Function descriptions enable a output channel
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral

352
GD32E50x Firmware Library User Guide
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
ch_id SHRTIMER timer channel index
SHRTIMER_STx_CHy(
timer channel selection
x=0..4;y=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable a output channel */

void shrtimer_output_channel_enable(SHRTIMER0, SHRTIMER_ST0_CH0);

shrtimer_output_channel_disable

The description of shrtimer_output_channel_disable is shown as below:

Table 3-476. Function shrtimer_output_channel_disable


Function name shrtimer_output_channel_disable
void shrtimer_output_channel_disable(uint32_t shrtimer_periph, uint32_t
Function prototype
chid);
Function descriptions disable a output channel
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
ch_id SHRTIMER timer channel index
SHRTIMER_STx_CHy(
timer channel selection
x=0..4;y=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable a output channel */

void shrtimer_output_channel_disable(SHRTIMER0, SHRTIMER_ST0_CH0);

353
GD32E50x Firmware Library User Guide
shrtimer_slavetimer_compare_value_config

The description of shrtimer_slavetimer_compare_value_config is shown as below:

Table 3-477. Function shrtimer_slavetimer_waveform_compare_config


Function name shrtimer_slavetimer_compare_value_config
void shrtimer_slavetimer_compare_value_config(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, uint32_t comparex, uint32_t cmpvalue);
Function descriptions configure the compare value in Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
comparex compare unit selection
SHRTIMER_COMPAR
the compare unit y(y=0..4)
Ey (y=0..4)
Input parameter{in}
the compare value from 3 tSHRTIMER_CK clock to 0xFFFF - (1
cmpvalue
tSHRTIMER_CK)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the compare value in Slave_TIMER */

shrtimer_slavetimer_compare_value_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
SHRTIMER_COMPARE0, 3);

shrtimer_slavetimer_compare_value_get

The description of shrtimer_slavetimer_compare_value_get is shown as below:

Table 3-478. Function shrtimer_slavetimer_compare_value_get


Function name shrtimer_slavetimer_compare_value_get
uint32_t shrtimer_slavetimer_compare_value_get(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, uint32_t comparex)
Function descriptions get the compare value in Slave_TIMER

354
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
comparex compare unit selection
SHRTIMER_COMPAR
the compare unit y(y=0..4)
Ey (y=0..4)
Output parameter{out}
- -
Return value
uint32_t the compare value

Example:

/* get the compare value in Slave_TIMER */

uint32_t cmpvalue;

cmpvalue = shrtimer_slavetimer_compare_value_get (SHRTIMER0,


SHRTIMER_SLAVE_TIMER0, SHRTIMER_COMPARE0);

shrtimer_mastertimer_compare_value_config

The description of shrtimer_mastertimer_compare_value_config is shown as below:

Table 3-479. Function shrtimer_mastertimer_compare_value_config


Function name shrtimer_mastertimer_compare_value_config
void shrtimer_mastertimer_compare_value_config(uint32_t shrtimer_periph,
Function prototype
uint32_t comparex, uint32_t cmpvalue);
Function descriptions configure the compare value in Master_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
comparex compare unit selection
SHRTIMER_COMPAR
the compare unit y(y=0..4)
Ey (y=0..4)
Input parameter{in}
355
GD32E50x Firmware Library User Guide
the compare value from 3 tSHRTIMER_CK clock to 0xFFFF - (1
cmpvalue
tSHRTIMER_CK)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the compare value in Master_TIMER */

shrtimer_mastertimer_compare_value_config(SHRTIMER0, SHRTIMER_COMPARE0, 3);

shrtimer_mastertimer_compare_value_get

The description of shrtimer_mastertimer_compare_value_get is shown as below:

Table 3-480. Function shrtimer_slavetimer_compare_value_get


Function name shrtimer_mastertimer_compare_value_get
uint32_t shrtimer_mastertimer_compare_value_get(uint32_t
Function prototype
shrtimer_periph, uint32_t comparex);
Function descriptions get the compare value in Master_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
comparex compare unit selection
SHRTIMER_COMPAR
the compare unit y(y=0..4)
Ey (y=0..4)
Output parameter{out}
- -
Return value
uint32_t the compare value

Example:

/* get the compare value in Master_TIMER */

uint32_t cmpvalue;

cmpvalue = shrtimer_mastertimer_compare_value_get(SHRTIMER0,
SHRTIMER_COMPARE0)

shrtimer_timers_counter_value_config

The description of shrtimer_timers_counter_value_config is shown as below:


356
GD32E50x Firmware Library User Guide
Table 3-481. Function shrtimer_timers_counter_value_config
Function name shrtimer_timers_counter_value_config
void shrtimer_timers_counter_value_config(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, uint32_t cntvalue);
Function descriptions configure the counter value in Master_TIMER and Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
cntvalue the value ranges from 0 to 0xffff
Output parameter{out}
- -
Return value
- -

Example:

/* configure the counter value in Master_TIMER and Slave_TIMER */

shrtimer_timers_counter_value_config(SHRTIMER0, SHRTIMER_MASTER_TIMER, 100);

shrtimer_timers_counter_value_get

The description of shrtimer_timers_counter_value_get is shown as below:

Table 3-482. Function shrtimer_timers_counter_value_get


Function name shrtimer_timers_counter_value_get
uint32_t shrtimer_timers_counter_value_get(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id);
Function descriptions get the counter value in Master_TIMER and Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral

357
GD32E50x Firmware Library User Guide
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Output parameter{out}
- -
Return value
uint32_t the counter value

Example:

/* get the counter value in Master_TIMER and Slave_TIMER */

uint32_t value;

value = shrtimer_timers_counter_value_get(SHRTIMER0, SHRTIMER_MASTER_TIMER);

shrtimer_timers_autoreload_value_config

The description of shrtimer_timers_autoreload_value_config is shown as below:

Table 3-483. Function shrtimer_timers_autoreload_value_config


Function name shrtimer_timers_autoreload_value_config
void shrtimer_timers_autoreload_value_config(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, uint32_t carlvalue);
configure the counter auto reload value in Master_TIMER and
Function descriptions
Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
carlvalue the value ranges from 0 to 0xffff
Output parameter{out}
- -
Return value
- -

Example:

358
GD32E50x Firmware Library User Guide
/* configure the counter auto reload value in Master_TIMER and Slave_TIMER */

shrtimer_timers_autoreload_value_config(SHRTIMER0, SHRTIMER_MASTER_TIMER,
100);

shrtimer_timers_autoreload_value_get

The description of shrtimer_timers_autoreload_value_get is shown as below:

Table 3-484. Function shrtimer_timers_autoreload_value_get


Function name shrtimer_timers_autoreload_value_get
uint32_t shrtimer_timers_autoreload_value_get(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id)
Function descriptions get the counter auto reload value in Master_TIMER and Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Output parameter{out}
- -
Return value
uint32_t the counter value

Example:

/* get the counter auto reload value in Master_TIMER and Slave_TIMER */

uint32_t value;

value = shrtimer_timers_autoreload_value_get(SHRTIMER0,
SHRTIMER_MASTER_TIMER);

shrtimer_timers_repetition_value_config

The description of shrtimer_timers_repetition_value_config is shown as below:

Table 3-485. Function shrtimer_timers_repetition_value_config


Function name shrtimer_timers_repetition_value_config
void shrtimer_timers_repetition_value_config(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, uint32_t replvalue);

359
GD32E50x Firmware Library User Guide
Function descriptions configure the counter repetition value in Master_TIMER and Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
replvalue the value ranges from 0 to 0xffff
Output parameter{out}
- -
Return value
- -

Example:

/* configure the counter repetition value in Master_TIMER and Slave_TIMER */

shrtimer_timers_repetition_value_config(SHRTIMER0, SHRTIMER_MASTER_TIMER, 100);

shrtimer_timers_repetition_value_get

The description of shrtimer_timers_repetition_value_get is shown as below:

Table 3-486. Function shrtimer_timers_repetition_value_get


Function name shrtimer_timers_repetition_value_get
uint32_t shrtimer_timers_repetition_value_get(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id);
Function descriptions get the counter repetition value in Master_TIMER and Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER peripheral
SHRTIMER_MASTER_
the counter of Master_TIMER
TIMER
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)

360
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
uint32_t the counter value

Example:

/* get the counter repetition value in Master_TIMER and Slave_TIMER */

uint32_t value;

value = shrtimer_timers_repetition_value_get (SHRTIMER0, SHRTIMER_MASTER_TIMER);

shrtimer_exevfilter_struct_para_init

The description of shrtimer_exevfilter_struct_para_init is shown as below:

Table 3-487. Function shrtimer_exevfilter_struct_para_init


Function name shrtimer_exevfilter_struct_para_init
void
Function prototype shrtimer_exevfilter_struct_para_init(shrtimer_exevfilter_parameter_struct *
exevfilter);
initialize external event filtering for Slave_TIMER configuration struct with a
Function descriptions
default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_exevfilter_parameter_struct * exevfilter, the structure members can
exevfilter
refer to Structure shrtimer_exevfilter_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize external event filtering for Slave_TIMER configuration struct with a default value */

shrtimer_exevfilter_parameter_struct exevfilter;

shrtimer_exevfilter_struct_para_init(&exevfilter);

shrtimer_slavetimer_exevent_filtering_config

The description of shrtimer_slavetimer_exevent_filtering_config is shown as below:

Table 3-488. Function shrtimer_slavetimer_exevent_filtering_config


Function name shrtimer_slavetimer_exevent_filtering_config
Function prototype void shrtimer_slavetimer_exevent_filtering_config(uint32_t shrtimer_periph,

361
GD32E50x Firmware Library User Guide
uint32_t timer_id, uint32_t event_id, shrtimer_exevfilter_parameter_struct
*exevfilter);
Function descriptions configure the external event filtering for Slave_TIMER (blanking, windowing)
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id SHRTIMER timer index
SHRTIMER_SLAVE_TI
the counter of Slave_TIMERx(x=0..4)
MERx(x=0..4)
Input parameter{in}
event_id SHRTIMER event index
SHRTIMER_EXEVENT
the counter of Slave_TIMERx undefined event channel
_NONE
SHRTIMER_EXEVENT
extern event y(y=0..9)
_y(y=0..9)
Input parameter{in}
shrtimer_exevfilter_parameter_struct * exevfilter, the structure members can
exevfilter
refer to Structure shrtimer_exevfilter_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* configure the external event filtering for Slave_TIMER (blanking, windowing) */

shrtimer_exevfilter_parameter_struct exevfilter;

shrtimer_exevfilter_struct_para_init(&exevfilter);

exevfilter.filter_mode = SHRTIMER_EXEVFILTER_BLANKINGCMP1;

exevfilter.memorized = SHRTIMER_EXEVMEMORIZED_DISABLE;

shrtimer_slavetimer_exevent_filtering_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
SHRTIMER_EXEVENT_5, &exevfilter);

shrtimer_exeventcfg_struct_para_init

The description of shrtimer_exeventcfg_struct_para_init is shown as below:

Table 3-489. Function shrtimer_exeventcfg_struct_para_init


Function name shrtimer_exeventcfg_struct_para_init

362
GD32E50x Firmware Library User Guide
void
Function prototype shrtimer_exeventcfg_struct_para_init(shrtimer_exeventcfg_parameter_struc
t * exevcfg);
Function descriptions initialize external event configuration struct with a default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_exeventcfg_parameter_struct, the structure members can refer to
exevcfg
Structure shrtimer_exeventcfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize external event configuration struct with a default value */

shrtimer_exeventcfg_parameter_struct exevcfg;

shrtimer_exeventcfg_struct_para_init(&exevcfg);

shrtimer_exevent_config

The description of shrtimer_exevent_config is shown as below:

Table 3-490. Function shrtimer_exevent_config


Function name shrtimer_exevent_config
void shrtimer_exevent_config(uint32_t shrtimer_periph, uint32_t event_id,
Function prototype
shrtimer_exeventcfg_parameter_struct* exevcfg);
Function descriptions configure the an external event
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
event_id SHRTIMER event index
SHRTIMER_EXEVENT
the counter of Slave_TIMERx undefined event channel
_NONE
SHRTIMER_EXEVENT
extern event y(y=0..9)
_y(y=0..9)
Input parameter{in}
shrtimer_exeventcfg_parameter_struct, the structure members can refer to
exevcfg
Structure shrtimer_exeventcfg_parameter_struct
Output parameter{out}
363
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* configure the an external event */

shrtimer_exeventcfg_parameter_struct exevcfg;

shrtimer_exeventcfg_struct_para_init(&exevcfg);

exevcfg.digital_filter = 0x5;

exevcfg.edge = SHRTIMER_EXEV_EDGE_RISING;

exevcfg.polarity = SHRTIMER_EXEV_EDGE_LEVEL;

exevcfg.source = SHRTIMER_EXEV_SRC0;

shrtimer_exevent_config(SHRTIMER0, SHRTIMER_EXEVENT_5, &exevcfg);

shrtimer_exevent_prescaler

The description of shrtimer_exevent_prescaler is shown as below:

Table 3-491. Function shrtimer_exevent_prescaler


Function name shrtimer_exevent_prescaler
void shrtimer_exevent_prescaler(uint32_t shrtimer_periph, uint32_t
Function prototype
prescaler);
Function descriptions configure external event digital filter clock division
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
prescaler clock division value
SHRTIMER_EXEV_PR
ESCALER_DIVx(x=1,2, fSHRTIMER_EXEVFCK = fSHRTIMER_CK/x (x=1,2,4,8)
4,8)
Output parameter{out}
- -
Return value
- -

Example:

/* configure external event digital filter clock division */

364
GD32E50x Firmware Library User Guide
shrtimer_exevent_prescaler(SHRTIMER0, SHRTIMER_EXEV_PRESCALER_DIV1);

shrtimer_synccfg_struct_para_init

The description of shrtimer_synccfg_struct_para_init is shown as below:

Table 3-492. Function shrtimer_synccfg_struct_para_init


Function name shrtimer_synccfg_struct_para_init
void shrtimer_synccfg_struct_para_init(shrtimer_synccfg_parameter_struct*
Function prototype
synccfg);
Function descriptions initialize synchronization configuration struct with a default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_synccfg_parameter_struct, the structure members can refer to
synccfg
Structure shrtimer_synccfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize synchronization configuration struct with a default value */

shrtimer_synccfg_parameter_struct synccfg;

shrtimer_synccfg_struct_para_init (&synccfg);

shrtimer_synchronization_config

The description of shrtimer_synchronization_config is shown as below:

Table 3-493. Function shrtimer_synchronization_config


Function name shrtimer_synchronization_config
void shrtimer_synchronization_config(uint32_t shrtimer_periph,
Function prototype
shrtimer_synccfg_parameter_struct* synccfg);
Function descriptions configure the synchronization input/output of the SHRTIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
shrtimer_synccfg_parameter_struct, the structure members can refer to
synccfg
Structure shrtimer_synccfg_parameter_struct
Output parameter{out}
365
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* configure the synchronization input/output of the SHRTIMER */

shrtimer_synccfg_parameter_struct synccfg;

shrtimer_synccfg_struct_para_init (&synccfg);

synccfg.input_source = SHRTIMER_SYNCINPUTSOURCE_EXTERNAL;

shrtimer_synchronization_config(SHRTIMER0, &synccfg);

shrtimer_faultcfg_struct_para_init

The description of shrtimer_faultcfg_struct_para_init is shown as below:

Table 3-494. Function shrtimer_faultcfg_struct_para_init


Function name shrtimer_faultcfg_struct_para_init
void shrtimer_faultcfg_struct_para_init(shrtimer_faultcfg_parameter_struct *
Function prototype
faultcfg);
Function descriptions initialize fault input configuration struct with a default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_faultcfg_parameter_struct, the structure members can refer to
faultcfg
Structure shrtimer_faultcfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize fault input configuration struct with a default value */

shrtimer_faultcfg_parameter_struct faultcfg;

shrtimer_synccfg_struct_para_init (&faultcfg);

shrtimer_fault_config

The description of shrtimer_fault_config is shown as below:

Table 3-495. Function shrtimer_fault_config


Function name shrtimer_fault_config
Function prototype void shrtimer_fault_config(uint32_t shrtimer_periph, uint32_t fault_id,

366
GD32E50x Firmware Library User Guide
shrtimer_faultcfg_parameter_struct* faultcfg);
Function descriptions configure the fault input
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
fault_id SHRTIMER fault index
SHRTIMER_FAULT_y(
SHRTIMER fault selection
y=0..4)
Input parameter{in}
shrtimer_faultcfg_parameter_struct, the structure members can refer to
faultcfg
Structure shrtimer_faultcfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* configure the fault input */

shrtimer_faultcfg_parameter_struct faultcfg;

shrtimer_synccfg_struct_para_init (&faultcfg);

faultcfg_para.control = SHRTIMER_FAULT_CHANNEL_ENABLE;

faultcfg_para.filter = 0x0;

faultcfg_para.polarity = SHRTIMER_FAULT_POLARITY_HIGH;

faultcfg_para.protect = SHRTIMER_FAULT_PROTECT_ENABLE;

faultcfg_para.source = SHRTIMER_FAULT_SOURCE_PIN;

shrtimer_fault_config(SHRTIMER0, SHRTIMER_FAULT_0, &faultcfg);

shrtimer_fault_prescaler_config

The description of shrtimer_fault_prescaler_config is shown as below:

Table 3-496. Function shrtimer_fault_prescaler_config


Function name shrtimer_fault_prescaler_config
void shrtimer_fault_prescaler_config(uint32_t shrtimer_periph, uint32_t
Function prototype
prescaler);
Function descriptions configure the fault input digital filter clock division
Precondition -

367
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
prescaler clock division value
SHRTIMER_FAULT_P
RESCALER_DIVy(y=1, fSHRTIMER_FLTFCK = fSHRTIMER_CK/y (y=1,2,4,8)
2,4,8)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the fault input digital filter clock division */

void shrtimer_fault_prescaler_config(SHRTIMER0,
SHRTIMER_FAULT_PRESCALER_DIV1);

shrtimer_fault_input_enable

The description of shrtimer_fault_input_enable is shown as below:

Table 3-497. Function shrtimer_fault_input_enable


Function name shrtimer_fault_input_enable
void shrtimer_fault_input_enable(uint32_t shrtimer_periph, uint32_t
Function prototype
fault_id);
Function descriptions fault input enable
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
fault_id SHRTIMER fault index
SHRTIMER_FAULT_y(
SHRTIMER fault selection
y=0..4)
Output parameter{out}
- -
Return value
- -

Example:

368
GD32E50x Firmware Library User Guide
/* fault input enable */

shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_0);

shrtimer_fault_input_disable

The description of shrtimer_fault_input_disable is shown as below:

Table 3-498. Function shrtimer_fault_input_disable


Function name shrtimer_fault_input_disable
void shrtimer_fault_input_disable(uint32_t shrtimer_periph, uint32_t
Function prototype
fault_id);
Function descriptions fault input disable
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
fault_id SHRTIMER fault index
SHRTIMER_FAULT_y(
SHRTIMER fault selection
y=0..4)
Output parameter{out}
- -
Return value
- -

Example:

/* fault input disable */

shrtimer_fault_input_disable(SHRTIMER0, SHRTIMER_FAULT_0);

shrtimer_timers_dma_enable

The description of shrtimer_timers_dma_enable is shown as below:

Table 3-499. Function shrtimer_timers_dma_enable


Function name shrtimer_timers_dma_enable
void shrtimer_timers_dma_enable(uint32_t shrtimer_periph, uint32_t
Function prototype
timer_id, uint32_t dmareq);
Function descriptions enable the Master_TIMER and Slave_TIMER DMA request
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
369
GD32E50x Firmware Library User Guide
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
dmareq DMA request source
SHRTIMER_MT_ST_D
compare y DMA request, for Master_TIMER and Slave_TIMER (y=0..3)
MA_CMPy(y=0..3)
SHRTIMER_MT_ST_D
repetition DMA request, for Master_TIMER and Slave_TIMER
MA_REP
SHRTIMER_MT_DMA_
synchronization input DMA request, for Master_TIMER
SYNID
SHRTIMER_MT_ST_D
update DMA request, for Master_TIMER and Slave_TIMER
MA_UPD
SHRTIMER_ST_DMA_
capture y DMA request, for Slave_TIMER(y=0,1)
CAPy(y=0,1)
SHRTIMER_ST_DMA_
channel y output active DMA request, for Slave_TIMER(y=0,1)
CHyOA(y=0,1)
SHRTIMER_ST_DMA_
channel y output inactive DMA request, for Slave_TIMER(y=0,1)
CHyONA(y=0,1)
SHRTIMER_ST_DMA_
counter reset DMA request, for Slave_TIMER
CNTRST
SHRTIMER_ST_DMA_
delayed IDLE mode entry DMA request, for Slave_TIMER
DLYIDLE
Output parameter{out}
- -
Return value
- -

Example:

/* enable the Master_TIMER and Slave_TIMER DMA request */

shrtimer_timers_dma_enable(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_DMA_CMP0);

shrtimer_timers_dma_disable

The description of shrtimer_timers_dma_disable is shown as below:

Table 3-500. Function shrtimer_timers_dma_enable


Function name shrtimer_timers_dma_disable
Function prototype void shrtimer_timers_dma_disable(uint32_t shrtimer_periph, uint32_t

370
GD32E50x Firmware Library User Guide
timer_id, uint32_t dmareq);
Function descriptions disable the Master_TIMER and Slave_TIMER DMA request
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
dmareq DMA request source
SHRTIMER_MT_ST_D
compare y DMA request, for Master_TIMER and Slave_TIMER (y=0..3)
MA_CMPy(y=0..3)
SHRTIMER_MT_ST_D
repetition DMA request, for Master_TIMER and Slave_TIMER
MA_REP
SHRTIMER_MT_DMA_
synchronization input DMA request, for Master_TIMER
SYNID
SHRTIMER_MT_ST_D
update DMA request, for Master_TIMER and Slave_TIMER
MA_UPD
SHRTIMER_ST_DMA_
capture y DMA request, for Slave_TIMER(y=0,1)
CAPy(y=0,1)
SHRTIMER_ST_DMA_
channel y output active DMA request, for Slave_TIMER(y=0,1)
CHyOA(y=0,1)
SHRTIMER_ST_DMA_
channel y output inactive DMA request, for Slave_TIMER(y=0,1)
CHyONA(y=0,1)
SHRTIMER_ST_DMA_
counter reset DMA request, for Slave_TIMER
CNTRST
SHRTIMER_ST_DMA_
delayed IDLE mode entry DMA request, for Slave_TIMER
DLYIDLE
Output parameter{out}
- -
Return value
- -

Example:

/* disable the Master_TIMER and Slave_TIMER DMA request */

shrtimer_timers_dma_disable(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_DMA_CMP0);

371
GD32E50x Firmware Library User Guide
shrtimer_dmamode_config

The description of shrtimer_dmamode_config is shown as below:

Table 3-501. Function shrtimer_dmamode_config


Function name shrtimer_dmamode_config
void shrtimer_dmamode_config(uint32_t shrtimer_periph, uint32_t timer_id,
Function prototype
uint32_t regupdate);
Function descriptions configure the DMA mode for Master_TIMER or Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
regupdate registers to be updated
SHRTIMER_DMAMOD
No register is updated by DMA mode, for Master_TIMER and Slave_TIMER
E_NONE
SHRTIMER_DMAMOD MTCTL0 or STxCTL0 register is updated by DMA mode, for Master_TIMER
E_CTL0 and Slave_TIMER
SHRTIMER_DMAMOD MT or STx register is updated by DMA mode, for Master_TIMER and
E_INTC Slave_TIMER
SHRTIMER_DMAMOD MTINTC or STxINTC register is updated by DMA mode, for Master_TIMER
E_DMAINTEN and Slave_TIMER
SHRTIMER_DMAMOD MTCNT or STxCNT register is updated by DMA mode, for Master_TIMER
E_CNT and Slave_TIMER
SHRTIMER_DMAMOD MTCAR or STxCAR register is updated by DMA mode, for Master_TIMER
E_CAR and Slave_TIMER
SHRTIMER_DMAMOD MTCREP or STxCREP register is updated by DMA mode, for
E_CREP Master_TIMER and Slave_TIMER
SHRTIMER_DMAMOD MTCMPyV or STxCMPyV register is updated by DMA mode, for
E_CMPyV(y=0..3) Master_TIMER and Slave_TIMER(y=0..3)
SHRTIMER_DMAMOD
STxDTCTL register is updated by DMA mode, only for Slave_TIMER
E_DTCTL
SHRTIMER_DMAMOD STxCHySET register is updated by DMA mode, only for
E_CHySET(y=0,1) Slave_TIMER(y=0,1)
SHRTIMER_DMAMOD STxCHyRST register is updated by DMA mode, only for
E_CHyRST(y=0,1) Slave_TIMER(y=0,1)
372
GD32E50x Firmware Library User Guide
SHRTIMER_DMAMOD STxEXEVFCFGy register is updated by DMA mode, only for Slave_TIMER
E_EXEVFCFGy(y=0,1) (y=0,1)
SHRTIMER_DMAMOD
STxCNTRST register is updated by DMA mode, only for Slave_TIMER
E_CNTRST
SHRTIMER_DMAMOD
STxCSCTL register is updated by DMA mode, only for Slave_TIMER
E_CSCTL
SHRTIMER_DMAMOD
STxCHOCTL register is updated by DMA mode, only for Slave_TIMER
E_CHOCTL
SHRTIMER_DMAMOD
STxFLTCTL register is updated by DMA mode, only for Slave_TIMER
E_FLTCTL
SHRTIMER_DMAMOD
STxACTL register is updated by DMA mode, only for Slave_TIMER
E_ACTL
Output parameter{out}
- -
Return value
- -

Example:

/* enable the Master_TIMER and Slave_TIMER DMA request */

shrtimer_dmamode_config(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_DMAMODE_NONE);

shrtimer_bunchmode_struct_para_init

The description of shrtimer_bunchmode_struct_para_init is shown as below:

Table 3-502. Function shrtimer_bunchmode_struct_para_init


Function name shrtimer_bunchmode_struct_para_init
void
Function prototype shrtimer_bunchmode_struct_para_init(shrtimer_bunchmode_parameter_str
uct* bmcfg);
Function descriptions initialize bunch mode configuration struct with a default value
Precondition -
The called functions -
Input parameter{in}
shrtimer_bunchmode_parameter_struct, the structure members can refer to
bmcfg
Structure shrtimer_bunchmode_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize bunch mode configuration struct with a default value */


373
GD32E50x Firmware Library User Guide
shrtimer_bunchmode_parameter_struct bmcfg;

shrtimer_bunchmode_struct_para_init(&bmcfg);

shrtimer_bunchmode_config

The description of shrtimer_bunchmode_config is shown as below:

Table 3-503. Function shrtimer_bunchmode_config


Function name shrtimer_bunchmode_config
void shrtimer_bunchmode_config(uint32_t shrtimer_periph,
Function prototype
shrtimer_bunchmode_parameter_struct* bmcfg);
Function descriptions configure bunch mode for the SHRTIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_bunchmode_parameter_struct, the structure members can refer to
bmcfg
Structure shrtimer_bunchmode_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* configure bunch mode for the SHRTIMER */

shrtimer_bunchmode_parameter_struct bmcfg;

shrtimer_bunchmode_struct_para_init(&bmcfg);

bmcfg.clock_source = SHRTIMER_BUNCHMODE_CLOCKSOURCE_ST0;

bmcfg.idle_duration = 3;

bmcfg.mode = SHRTIMER_BUNCHMODE_CONTINOUS;

bmcfg.period = 6;

bmcfg.prescaler = SHRTIMER_BUNCHMODE_PRESCALER_DIV1;

bmcfg.shadow = SHRTIMER_BUNCHMODEPRELOAD_DISABLED;

bmcfg.trigger = SHRTIMER_BUNCHMODE_TRIGGER_SOFTWARE;

shrtimer_bunchmode_config(SHRTIMER0, &bmcfg);

shrtimer_bunchmode_enable

The description of shrtimer_bunchmode_enable is shown as below:

374
GD32E50x Firmware Library User Guide
Table 3-504. Function shrtimer_bunchmode_enable
Function name shrtimer_bunchmode_enable
Function prototype void shrtimer_bunchmode_enable(uint32_t shrtimer_periph);
Function descriptions enable bunch mode for the SHRTIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable bunch mode for the SHRTIMER */

shrtimer_bunchmode_enable(SHRTIMER0);

shrtimer_bunchmode_disable

The description of shrtimer_bunchmode_disable is shown as below:

Table 3-505. Function shrtimer_bunchmode_disable


Function name shrtimer_bunchmode_disable
Function prototype void shrtimer_bunchmode_disable(uint32_t shrtimer_periph);
Function descriptions disable bunch mode for the SHRTIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable bunch mode for the SHRTIMER */

shrtimer_bunchmode_disable(SHRTIMER0);

shrtimer_bunchmode_flag_get

The description of shrtimer_bunchmode_flag_get is shown as below:

375
GD32E50x Firmware Library User Guide
Table 3-506. Function shrtimer_bunchmode_flag_get
Function name shrtimer_bunchmode_flag_get
Function prototype uint32_t shrtimer_bunchmode_flag_get(uint32_t shrtimer_periph);
Function descriptions get bunch mode operating flag
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Output parameter{out}
- -
Return value
SHRTIMER_BUNCHMODE_OPERATION_OFF or
uint32_t
SHRTIMER_BUNCHMODE_OPERATION_ON

Example:

/* get bunch mode operating flag */

uint32_t flag;

flag = shrtimer_bunchmode_flag_get(SHRTIMER0);

shrtimer_bunchmode_software_start

The description of shrtimer_bunchmode_software_start is shown as below:

Table 3-507. Function shrtimer_bunchmode_software_start


Function name shrtimer_bunchmode_software_start
Function prototype void shrtimer_bunchmode_software_start(uint32_t shrtimer_periph);
Function descriptions bunch mode started by software
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Output parameter{out}
- -
Return value
- -

Example:

/* bunch mode started by software */

shrtimer_bunchmode_software_start(SHRTIMER0);

376
GD32E50x Firmware Library User Guide
shrtimer_slavetimer_capture_config

The description of shrtimer_slavetimer_capture_config is shown as below:

Table 3-508. Function shrtimer_slavetimer_capture_config


Function name shrtimer_slavetimer_capture_config
void shrtimer_slavetimer_capture_config(uint32_t shrtimer_periph, uint32_t
Function prototype
timer_id, uint32_t capturex, uint32_t trgsource);
Function descriptions configure the capture source in Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
capturex capture unit index
SHRTIMER_CAPTURE
capture unit selection(y=0,1)
_y(y=0,1)
Input parameter{in}
trgsource capture trigger source
SHRTIMER_CAPTURE
Capture trigger is disabled
TRIGGER_NONE
SHRTIMER_CAPTURE
capture triggered by update event
TRIGGER_UPDATE
SHRTIMER_CAPTURE
TRIGGER_EXEV_y(y= capture triggered by external event 0(y=0..9)
0..9)
SHRTIMER_CAPTURE
TRIGGER_STy_ACTIV capture triggered by STyCH0_O output inactive to active transition(y=0..4)
E(y=0..4)
SHRTIMER_CAPTURE
TRIGGER_STy_INACTI capture triggered by STyCH0_O output active to inactive transition(y=0..4)
VE(y=0..4)
SHRTIMER_CAPTURE
TRIGGER_STy_CMP0( capture triggered by compare 0 event of Slave_TIMERy(y=0..4)
y=0..4)
SHRTIMER_CAPTURE
TRIGGER_STy_CMP1( capture triggered by compare 1 event of Slave_TIMERy(y=0..4)
y=0..4)
Output parameter{out}
377
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* configure the capture source in Slave_TIMER */

shrtimer_slavetimer_capture_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
SHRTIMER_CAPTURE_0, SHRTIMER_CAPTURETRIGGER_NONE);

shrtimer_slavetimer_capture_software

The description of shrtimer_slavetimer_capture_software is shown as below:

Table 3-509. Function shrtimer_slavetimer_capture_software


Function name shrtimer_slavetimer_capture_software
void shrtimer_slavetimer_capture_software(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, uint32_t capturex);
Function descriptions configure the capture source in Slave_TIMER
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
capturex capture unit index
SHRTIMER_CAPTURE
capture unit selection(y=0,1)
_y(y=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the capture source in Slave_TIMER */

shrtimer_slavetimer_capture_software(SHRTIMER0, SHRTIMER_SLAVE
SHRTIMER_CAPTURE_0);

378
GD32E50x Firmware Library User Guide
shrtimer_slavetimer_capture_value_read

The description of shrtimer_slavetimer_capture_value_read is shown as below:

Table 3-510. Function shrtimer_slavetimer_capture_value_read


Function name shrtimer_slavetimer_capture_value_read
uint32_t shrtimer_slavetimer_capture_value_read(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, uint32_t capturex);
Function descriptions read the capture value
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
capturex capture unit index
SHRTIMER_CAPTURE
capture unit selection(y=0,1)
_y(y=0,1)
Output parameter{out}
- -
Return value
uint32_t capture value

Example:

/* read the capture value */

uint32_t capture_value;

capture_value = shrtimer_slavetimer_capture_value_read (SHRTIMER0,


SHRTIMER_SLAVE SHRTIMER_CAPTURE_0);

shrtimer_adctrigcfg_struct_para_init

The description of shrtimer_adctrigcfg_struct_para_init is shown as below:

Table 3-511. Function shrtimer_adctrigcfg_struct_para_init


Function name shrtimer_adctrigcfg_struct_para_init
void
Function prototype shrtimer_adctrigcfg_struct_para_init(shrtimer_adctrigcfg_parameter_struct*
triggercfg);
Function descriptions initialize ADC trigger configuration struct with a default value
Precondition -
379
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
shrtimer_adctrigcfg_parameter_struct, the structure members can refer to
triggercfg
Structure shrtimer_adctrigcfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize ADC trigger configuration struct with a default value */

shrtimer_adctrigcfg_parameter_struct triggercfg;

shrtimer_adctrigcfg_struct_para_init(&triggercfg);

shrtimer_adc_trigger_config

The description of shrtimer_adc_trigger_config is shown as below:

Table 3-512. Function shrtimer_adc_trigger_config


Function name shrtimer_adc_trigger_config
void shrtimer_adc_trigger_config(uint32_t shrtimer_periph, uint32_t
Function prototype
trigger_id, shrtimer_adctrigcfg_parameter_struct* triggercfg);
Function descriptions configure the trigger source to ADC and the update source
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
trigger_id ADC trigger event
SHRTIMER_ADCTRIG
the slave timer selection(x=0..4)
_y(y=0..3)
Input parameter{in}
shrtimer_adctrigcfg_parameter_struct, the structure members can refer to
triggercfg
Structure shrtimer_adctrigcfg_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* configure the trigger source to ADC and the update source */

380
GD32E50x Firmware Library User Guide
shrtimer_adctrigcfg_parameter_struct triggercfg;

shrtimer_adctrigcfg_struct_para_init(&triggercfg);

triggercfg.update_source = SHRTIMER_ADCTRGI_UPDATE_MT;

triggercfg. trigger = SHRTIMER_ADCTRGI02_EVENT_NONE;

shrtimer_adc_trigger_config(SHRTIMER0, SHRTIMER_ADCTRIG_0, &triggercfg);

shrtimer_timers_flag_get

The description of shrtimer_timers_flag_get is shown as below:

Table 3-513. Function shrtimer_timers_flag_get


Function name shrtimer_timers_flag_get
FlagStatus shrtimer_timers_flag_get(uint32_t shrtimer_periph, uint32_t
Function prototype
timer_id, uint32_t flag);
Function descriptions get the Master_TIMER and Slave_TIMER flag
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
flag the flag source
SHRTIMER_MT_ST_F
compare y flag, for Master_TIMER and Slave_TIMER (y=0..3)
LAG_CMPy(y=0..3)
SHRTIMER_MT_ST_F
repetition flag, for Master_TIMER and Slave_TIMER
LAG_REP
SHRTIMER_MT_INT_F
synchronization input flag, for Master_TIMER
LAG_SYNI
SHRTIMER_MT_ST_F
update flag, for Master_TIMER and Slave_TIMER
LAG_UPD
SHRTIMER_ST_FLAG
capture y flag, for Slave_TIMER(y=0,1)
_CAPy(y=0,1)
SHRTIMER_ST_FLAG
channel y output active flag, for Slave_TIMER(y=0,1)
_CHyOA(y=0,1)
SHRTIMER_ST_FLAG
channel y output inactive flag, for Slave_TIMER(y=0,1)
_CHyONA(y=0,1)

381
GD32E50x Firmware Library User Guide
SHRTIMER_ST_FLAG
counter reset flag, for Slave_TIMER
_CNTRST
SHRTIMER_ST_FLAG
delayed IDLE mode entry flag, for Slave_TIMER
_DLYIDLE
SHRTIMER_ST_FLAG
current balanced flag, for Slave_TIMER
_CBLN
SHRTIMER_ST_FLAG
balanced IDLE flag, for Slave_TIMER
_BLNIDLE
SHRTIMER_ST_FLAG
channel y output flag, for Slave_TIMER(y=0,1)
_CHyOUT(y=0,1)
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the Master_TIMER and Slave_TIMER flag */

FlagStatus flag = RESET;

flag = shrtimer_timers_flag_get(SHRTIMER0, SHRTIMER_MASTER_TIMER,


SHRTIMER_MT_ST_FLAG_CMP0);

shrtimer_timers_flag_clear

The description of shrtimer_timers_flag_clear is shown as below:

Table 3-514. Function shrtimer_timers_flag_clear


Function name shrtimer_timers_flag_clear
void shrtimer_timers_flag_clear(uint32_t shrtimer_periph, uint32_t timer_id,
Function prototype
uint32_t flag);
Function descriptions clear the Master_TIMER and Slave_TIMER flag
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
flag the flag source

382
GD32E50x Firmware Library User Guide
SHRTIMER_MT_ST_F
compare y flag, for Master_TIMER and Slave_TIMER (y=0..3)
LAG_CMPy(y=0..3)
SHRTIMER_MT_ST_F
repetition flag, for Master_TIMER and Slave_TIMER
LAG_REP
SHRTIMER_MT_INT_F
synchronization input flag, for Master_TIMER
LAG_SYNI
SHRTIMER_MT_ST_F
update flag, for Master_TIMER and Slave_TIMER
LAG_UPD
SHRTIMER_ST_FLAG
capture y flag, for Slave_TIMER(y=0,1)
_CAPy(y=0,1)
SHRTIMER_ST_FLAG
channel y output active flag, for Slave_TIMER(y=0,1)
_CHyOA(y=0,1)
SHRTIMER_ST_FLAG
channel y output inactive flag, for Slave_TIMER(y=0,1)
_CHyONA(y=0,1)
SHRTIMER_ST_FLAG
counter reset flag, for Slave_TIMER
_CNTRST
SHRTIMER_ST_FLAG
delayed IDLE mode entry flag, for Slave_TIMER
_DLYIDLE
SHRTIMER_ST_FLAG
current balanced flag, for Slave_TIMER
_CBLN
SHRTIMER_ST_FLAG
balanced IDLE flag, for Slave_TIMER
_BLNIDLE
SHRTIMER_ST_FLAG
channel y output flag, for Slave_TIMER(y=0,1)
_CHyOUT(y=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* clear the Master_TIMER and Slave_TIMER flag */

shrtimer_timers_flag_clear(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_FLAG_CMP0);

shrtimer_common_flag_get

The description of shrtimer_common_flag_get is shown as below:

Table 3-515. Function shrtimer_common_flag_get


Function name shrtimer_common_flag_get
FlagStatus shrtimer_common_flag_get(uint32_t shrtimer_periph, uint32_t
Function prototype
flag);
Function descriptions get the common flag

383
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
flag the flag source
SHRTIMER_FLAG_FLT
fault y interrupt flag (y=0..3)
y(y=0..3)
SHRTIMER_FLAG_SY
system fault interrupt flag
SFLT
SHRTIMER_FLAG_DL
DLL calibration completed interrupt flag
LCAL
SHRTIMER_FLAG_BM
bunch mode period interrupt flag
PER
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the common flag */

FlagStatus flag = RESET;

flag = shrtimer_common_flag_get(SHRTIMER0, SHRTIMER_FLAG_FLT0);

shrtimer_common_flag_clear

The description of shrtimer_common_flag_clear is shown as below:

Table 3-516. Function shrtimer_common_flag_clear


Function name shrtimer_common_flag_clear
Function prototype void shrtimer_common_flag_clear(uint32_t shrtimer_periph, uint32_t flag);
Function descriptions clear the common flag
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
flag the flag source
SHRTIMER_FLAG_FLT
fault y interrupt flag (y=0..3)
y(y=0..3)
SHRTIMER_FLAG_SY system fault interrupt flag
384
GD32E50x Firmware Library User Guide
SFLT
SHRTIMER_FLAG_DL
DLL calibration completed interrupt flag
LCAL
SHRTIMER_FLAG_BM
bunch mode period interrupt flag
PER
Output parameter{out}
- -
Return value
- -

Example:

/* clear the common flag */

shrtimer_common_flag_clear(SHRTIMER0, SHRTIMER_FLAG_FLT0);

shrtimer_timers_interrupt_enable

The description of shrtimer_timers_interrupt_enable is shown as below:

Table 3-517. Function shrtimer_timers_interrupt_enable


Function name shrtimer_timers_interrupt_enable
void shrtimer_timers_interrupt_enable(uint32_t shrtimer_periph, uint32_t
Function prototype
timer_id, uint32_t interrupt);
Function descriptions enable the Master_TIMER and Slave_TIMER interrupt
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
interrupt the interrupt source
SHRTIMER_MT_ST_IN
compare y interrupt, for Master_TIMER and Slave_TIMER (y=0..3)
T_CMPy(y=0..3)
SHRTIMER_MT_ST_IN
repetition interrupt, for Master_TIMER and Slave_TIMER
T_REP
SHRTIMER_MT_INT_S
synchronization input interrupt, for Master_TIMER
YNI
SHRTIMER_MT_ST_IN update interrupt, for Master_TIMER and Slave_TIMER

385
GD32E50x Firmware Library User Guide
T_UPD
SHRTIMER_ST_INT_C
capture y interrupt, for Slave_TIMER(y=0,1)
APy(y=0,1)
SHRTIMER_ST_INT_C
channel y output active interrupt, for Slave_TIMER(y=0,1)
HyOA(y=0,1)
SHRTIMER_ST_INT_C
channel y output inactive interrupt, for Slave_TIMER(y=0,1)
HyONA(y=0,1)
SHRTIMER_ST_INT_C
counter reset interrupt, for Slave_TIMER
NTRST
SHRTIMER_ST_INT_D
delayed IDLE mode entry interrupt, for Slave_TIMER
LYIDLE
Output parameter{out}
- -
Return value
- -

Example:

/* enable the Master_TIMER and Slave_TIMER interrupt */

shrtimer_timers_interrupt_enable(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_INT_CMP0);

shrtimer_timers_interrupt_disable

The description of shrtimer_timers_interrupt_disable is shown as below:

Table 3-518. Function shrtimer_timers_interrupt_disable


Function name shrtimer_timers_interrupt_disable
void shrtimer_timers_interrupt_disable(uint32_t shrtimer_periph, uint32_t
Function prototype
timer_id, uint32_t interrupt);
Function descriptions disable the Master_TIMER and Slave_TIMER interrupt
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
interrupt the interrupt source

386
GD32E50x Firmware Library User Guide
SHRTIMER_MT_ST_IN
compare y interrupt, for Master_TIMER and Slave_TIMER (y=0..3)
T_CMPy(y=0..3)
SHRTIMER_MT_ST_IN
repetition interrupt, for Master_TIMER and Slave_TIMER
T_REP
SHRTIMER_MT_INT_S
synchronization input interrupt, for Master_TIMER
YNI
SHRTIMER_MT_ST_IN
update interrupt, for Master_TIMER and Slave_TIMER
T_UPD
SHRTIMER_ST_INT_C
capture y interrupt, for Slave_TIMER(y=0,1)
APy(y=0,1)
SHRTIMER_ST_INT_C
channel y output active interrupt, for Slave_TIMER(y=0,1)
HyOA(y=0,1)
SHRTIMER_ST_INT_C
channel y output inactive interrupt, for Slave_TIMER(y=0,1)
HyONA(y=0,1)
SHRTIMER_ST_INT_C
counter reset interrupt, for Slave_TIMER
NTRST
SHRTIMER_ST_INT_D
delayed IDLE mode entry interrupt, for Slave_TIMER
LYIDLE
Output parameter{out}
- -
Return value
- -

Example:

/* disable the Master_TIMER and Slave_TIMER interrupt */

shrtimer_timers_interrupt_disable(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_INT_CMP0);

shrtimer_timers_interrupt_flag_get

The description of shrtimer_timers_interrupt_flag_get is shown as below:

Table 3-519. Function shrtimer_timers_interrupt_flag_get


Function name shrtimer_timers_interrupt_flag_get
FlagStatus shrtimer_timers_interrupt_flag_get(uint32_t shrtimer_periph,
Function prototype
uint32_t timer_id, uint32_t interrupt);
Function descriptions get the Master_TIMER and Slave_TIMER interrupt flag
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}

387
GD32E50x Firmware Library User Guide
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
interrupt the interrupt source
SHRTIMER_MT_ST_IN
T compare y interrupt flag, for Master_TIMER and Slave_TIMER (y=0..3)
_FLAG_CMPy(y=0..3)
SHRTIMER_MT_ST_IN
repetition interrupt flag, for Master_TIMER and Slave_TIMER
T _FLAG_REP
SHRTIMER_MT_INT_F
synchronization input interrupt flag, for Master_TIMER
LAG_SYNI
SHRTIMER_MT_ST_IN
update interrupt flag, for Master_TIMER and Slave_TIMER
T_FLAG_UPD
SHRTIMER_ST_INT_F
capture y interrupt flag, for Slave_TIMER(y=0,1)
LAG_CAPy(y=0,1)
SHRTIMER_ST_INT_F
channel y output active interrupt flag, for Slave_TIMER(y=0,1)
LAG_CHyOA(y=0,1)
SHRTIMER_ST_INT_F
channel y output inactive interrupt flag, for Slave_TIMER(y=0,1)
LAG_CHyONA(y=0,1)
SHRTIMER_ST_INT_F
counter reset interrupt flag, for Slave_TIMER
LAG_CNTRST
SHRTIMER_ST_INT_F
delayed IDLE mode entry interrupt flag, for Slave_TIMER
LAG_DLYIDLE
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the Master_TIMER and Slave_TIMER interrupt flag */

FlagStatus flag = RESET;

flag = shrtimer_timers_interrupt_flag_get(SHRTIMER0, SHRTIMER_MASTER_TIMER,


SHRTIMER_MT_ST_INT_FLAG_CMP0);

shrtimer_timers_interrupt_flag_clear

The description of shrtimer_timers_interrupt_flag_clear is shown as below:

Table 3-520. Function shrtimer_timers_interrupt_flag_clear


Function name shrtimer_timers_interrupt_flag_clear

388
GD32E50x Firmware Library User Guide
void shrtimer_timers_interrupt_flag_clear(uint32_t shrtimer_periph, uint32_t
Function prototype
timer_id, uint32_t interrupt);
Function descriptions clear the Master_TIMER and Slave_TIMER interrupt flag
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
timer_id master timer and slave timer index
SHRTIMER_MASTER_
the master timer
TIMER
SHRTIMER_SLAVE_TI
the slave timer selection(x=0..4)
MERx
Input parameter{in}
interrupt the interrupt source
SHRTIMER_MT_ST_IN
T compare y interrupt flag, for Master_TIMER and Slave_TIMER (y=0..3)
_FLAG_CMPy(y=0..3)
SHRTIMER_MT_ST_IN
repetition interrupt flag, for Master_TIMER and Slave_TIMER
T _FLAG_REP
SHRTIMER_MT_INT_F
synchronization input interrupt flag, for Master_TIMER
LAG_SYNI
SHRTIMER_MT_ST_IN
update interrupt flag, for Master_TIMER and Slave_TIMER
T_FLAG_UPD
SHRTIMER_ST_INT_F
capture y interrupt flag, for Slave_TIMER(y=0,1)
LAG_CAPy(y=0,1)
SHRTIMER_ST_INT_F
channel y output active interrupt flag, for Slave_TIMER(y=0,1)
LAG_CHyOA(y=0,1)
SHRTIMER_ST_INT_F
channel y output inactive interrupt flag, for Slave_TIMER(y=0,1)
LAG_CHyONA(y=0,1)
SHRTIMER_ST_INT_F
counter reset interrupt flag, for Slave_TIMER
LAG_CNTRST
SHRTIMER_ST_INT_F
delayed IDLE mode entry interrupt flag, for Slave_TIMER
LAG_DLYIDLE
Output parameter{out}
- -
Return value
- -

Example:

/* clear the Master_TIMER and Slave_TIMER interrupt flag */

389
GD32E50x Firmware Library User Guide
shrtimer_timers_interrupt_flag_clear(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_INT_FLAG_CMP0);

shrtimer_common_interrupt_enable

The description of shrtimer_common_interrupt_enable is shown as below:

Table 3-521. Function shrtimer_common_interrupt_enable


Function name shrtimer_common_interrupt_enable
void shrtimer_common_interrupt_enable(uint32_t shrtimer_periph, uint32_t
Function prototype
interrupt);
Function descriptions enable SHRTIMER common interrupt
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
interrupt the interrupt source
SHRTIMER_INT_FLTy(
fault y interrupt (y=0..3)
y=0..3)
SHRTIMER_INT_SYSF
system fault interrupt
LT
SHRTIMER_INT_DLLC
DLL calibration completed interrupt
AL
SHRTIMER_INT_BMP
bunch mode period interrupt
ER
Output parameter{out}
- -
Return value
- -

Example:

/* enable SHRTIMER common interrupt */

shrtimer_common_interrupt_enable(SHRTIMER0, SHRTIMER_INT_FLT0);

shrtimer_common_interrupt_disable

The description of shrtimer_common_interrupt_disable is shown as below:

Table 3-522. Function shrtimer_common_interrupt_disable


Function name shrtimer_common_interrupt_disable
void shrtimer_common_interrupt_disable(uint32_t shrtimer_periph, uint32_t
Function prototype
interrupt);

390
GD32E50x Firmware Library User Guide
Function descriptions disable SHRTIMER common interrupt
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
interrupt the interrupt source
SHRTIMER_INT_FLTy(
fault y interrupt (y=0..3)
y=0..3)
SHRTIMER_INT_SYSF
system fault interrupt
LT
SHRTIMER_INT_DLLC
DLL calibration completed interrupt
AL
SHRTIMER_INT_BMP
bunch mode period interrupt
ER
Output parameter{out}
- -
Return value
- -

Example:

/* disable SHRTIMER common interrupt */

shrtimer_common_interrupt_disable(SHRTIMER0, SHRTIMER_INT_FLT0);

shrtimer_common_interrupt_flag_get

The description of shrtimer_common_interrupt_flag_get is shown as below:

Table 3-523. Function shrtimer_common_interrupt_flag_get


Function name shrtimer_common_interrupt_flag_get
FlagStatus shrtimer_common_interrupt_flag_get(uint32_t shrtimer_periph,
Function prototype
uint32_t interrupt);
Function descriptions get the common interrupt flag
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
interrupt the interrupt source
SHRTIMER_INT
fault y interrupt flag (y=0..3)
_FLAG_FLTy(y=0..3)

391
GD32E50x Firmware Library User Guide
SHRTIMER_INT
system fault interrupt flag
_FLAG_SYSFLT
SHRTIMER_INT
DLL calibration completed interrupt flag
_FLAG_DLLCAL
SHRTIMER_INT
bunch mode period interrupt flag
_FLAG_BMPER
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the common interrupt flag */

FlagStatus flag = RESET;

flag = shrtimer_common_interrupt_flag_get(SHRTIMER0, SHRTIMER_INT_FLAG_FLT0);

shrtimer_common_interrupt_flag_clear

The description of shrtimer_common_interrupt_flag_clear is shown as below:

Table 3-524. Function shrtimer_common_interrupt_flag_clear


Function name shrtimer_common_interrupt_flag_clear
void shrtimer_common_interrupt_flag_clear(uint32_t shrtimer_periph,
Function prototype
uint32_t interrupt);
Function descriptions clear the common interrupt flag
Precondition -
The called functions -
Input parameter{in}
shrtimer_periph SHRTIMER peripheral
SHRTIMERx(x=0) SHRTIMER selection
Input parameter{in}
interrupt the interrupt source
SHRTIMER_INT
fault y interrupt flag (y=0..3)
_FLAG_FLTy(y=0..3)
SHRTIMER_INT
system fault interrupt flag
_FLAG_SYSFLT
SHRTIMER_INT
DLL calibration completed interrupt flag
_FLAG_DLLCAL
SHRTIMER_INT
bunch mode period interrupt flag
_FLAG_BMPER
Output parameter{out}
- -
Return value

392
GD32E50x Firmware Library User Guide
- -

Example:

/* clear the common interrupt flag */

shrtimer_common_interrupt_flag_clear(SHRTIMER0, SHRTIMER_INT_FLAG_FLT0);

3.17. I2C

The I2C (inter-integrated circuit) module provides an I2C interface which is an industry
standard two-line serial interface for MCU to communicate with external I2C interface. The
I2C registers are listed in chapter 3.17.1, the I2C firmware functions are introduced in chapter
3.17.2.

3.17.1. Descriptions of Peripheral registers

I2C registers are listed in the table shown as below:

Table 3-525. I2C Registers


Registers Descriptions
I2C_CTL0 Control register 0
I2C_CTL1 Control register 1
I2C_SADDR0 Slave address register 0
I2C_SADDR1 Slave address register 1
I2C_DATA Transfer buffer register
I2C_STAT0 Transfer status register 0
I2C_STAT1 Transfer status register 1
I2C_CKCFG Clock configure register
I2C_RT Rise time register
I2C_SAMCS SAM control and status register
I2C_CTL2 Control register 2
I2C_CS Control and status register
I2C_STATC Status clear register
I2C2_CTL0 Control register 0
I2C2_CTL1 Control register 1
I2C2_SADDR0 Slave address register 0
I2C2_SADDR1 Slave address register 1
I2C2_TIMING Timing register
I2C2_TIMEOUT Timeout register
I2C2_STAT Status register
I2C2_STATC Status clear register
I2C2_PEC PEC register
I2C2_RDATA Receive data register

393
GD32E50x Firmware Library User Guide
Registers Descriptions
I2C2_TDATA Transmit data register

3.17.2. Descriptions of Peripheral functions

I2C firmware functions are listed in the table shown as below:

Table 3-526. I2C firmware function


Function name Function description
i2c_deinit reset I2C
i2c_enable enable I2C
i2c_disable disable I2C
i2c_start_on_bus generate a START condition on I2C bus
i2c_stop_on_bus generate a STOP condition on I2C bus
i2c_slave_response_to_gcall_enable enable the response to a general call
i2c_slave_response_to_gcall_disable disable the response to a general call
enable to stretch SCL low when data is not ready in slave
i2c_stretch_scl_low_enable
mode
disable to stretch SCL low when data is not ready in slave
i2c_stretch_scl_low_disable
mode
i2c_data_transmit I2C transmit data function
i2c_data_receive I2C receive data function
i2c_pec_transfer I2C transfers PEC value
i2c_pec_enable enable I2C PEC calculation
i2c_pec_disable disable I2C PEC calculation
i2c_pec_value_get get packet error checking value
i2c_clock_config configure I2C clock
i2c_mode_addr_config configure I2C address
i2c_smbus_type_config SMBus type selection
i2c_ack_config whether or not to send an ACK
i2c_ackpos_config configure I2C POAP position
i2c_master_addressing master send slave address
i2c_dualaddr_enable dual-address mode switch
i2c_dualaddr_disable disable dual-address mode
i2c_dma_enable I2C DMA mode enable
i2c_dma_last_transfer_config configure whether next DMA EOT is DMA last transfer or not
i2c_software_reset_config software reset I2C
i2c_smbus_issue_alert I2C issue alert through SMBA pin
i2c_smbus_arp_enable I2C ARP protocol in SMBus switch
i2c_sam_enable enable SAM_V interface
i2c_sam_disable disable SAM_V interface
i2c_sam_timeout_enable enable SAM_V interface timeout detect
i2c_sam_timeout_disable disable SAM_V interface timeout detect

394
GD32E50x Firmware Library User Guide
Function name Function description
i2c_start_early_termination_mode_co
configure I2C start early termination mode
nfig
i2c_timeout_calculation_enable enable i2c timeout calculation
i2c_timeout_calculation_disable disable i2c timeout calculation
i2c_record_received_slave_address_ enable i2c record the received slave address to the transfer
enable buffer register
i2c_record_received_slave_address_ disable i2c record the received slave address to the transfer
disable buffer register
define which bits of ADDRESS[7:1] need to compare with the
i2c_address_bit_compare_config
incoming address byte
i2c_status_clear_enable enable i2c status register clear
i2c_status_clear_disable disable i2c status register clear
i2c_status_bit_clear clear i2c status register bit
i2c_flag_get check I2C flag is set or not
i2c_flag_clear clear I2C flag
i2c_interrupt_enable enable I2C interrupt
i2c_interrupt_disable disable I2C interrupt
i2c_interrupt_flag_get check I2C interrupt flag
i2c_interrupt_flag_clear clear I2C interrupt flag
i2c_timing_config configure the timing parameters
i2c_digital_noise_filter_config configure digital noise filter
i2c_analog_noise_filter_enable enable analog noise filter
i2c_analog_noise_filter_disable disable analog noise filter
i2c_wakeup_from_deepsleep_enable enable wakeup from Deep-sleep mode
i2c_wakeup_from_deepsleep_disable disable wakeup from Deep-sleep mode
configure the SCL high and low period of clock in master
i2c_master_clock_config
mode
configure i2c slave addresss and transfer direction in master
i2c2_master_addressing
mode
10-bit address header executes read direction only in master
i2c_address10_header_enable
receive mode
10-bit address header executes complete sequence in master
i2c_address10_header_disable
receive mode
i2c_address10_enable enable 10-bit addressing mode in master mode
i2c_address10_disable disable 10-bit addressing mode in master mode
i2c_automatic_end_enable enable I2C automatic end mode in master mode
i2c_automatic_end_disable disable I2C automatic end mode in master mode
i2c_address_config configure i2c slave address
i2c_address_disable disable i2c address in slave mode
i2c_second_address_config configure i2c second slave address
i2c_second_address_disable disable i2c second address in slave mode
i2c_recevied_address_get get received match address in slave mode
395
GD32E50x Firmware Library User Guide
Function name Function description
i2c_slave_byte_control_enable enable slave byte control
i2c_slave_byte_control_disable disable slave byte control
i2c_nack_enable generate a NACK in slave mode
i2c_nack_disable generate an ACK in slave mode
i2c_reload_enable enable I2C reload mode
i2c_reload_disable disable I2C reload mode
i2c_transfer_byte_number_config configure number of bytes to be transferred
i2c2_dma_enable enable I2C DMA for transmission or reception
i2c2_dma_disable disable I2C DMA for transmission or reception
i2c_smbus_alert_enable enable SMBus Alert
i2c_smbus_alert_disable disable SMBus Alert
i2c_smbus_default_addr_enable enable SMBus device default address
i2c_smbus_default_addr_disable disable SMBus device default address
i2c_smbus_host_addr_enable enable SMBus Host address
i2c_smbus_host_addr_disable disable SMBus Host address
i2c_extented_clock_timeout_enable enable extended clock timeout detection
i2c_extented_clock_timeout_disable disable extended clock timeout detection
i2c_clock_timeout_enable enable clock timeout detection
i2c_clock_timeout_disable disable clock timeout detection
i2c_bus_timeout_b_config configure bus timeout B
i2c_bus_timeout_a_config configure bus timeout A
i2c_idle_clock_timeout_config configure idle clock timeout detection
i2c2_flag_get get I2C flag status
i2c2_flag_clear clear I2C flag status
i2c2_interrupt_enable enable I2C interrupt
i2c2_interrupt_disable disable I2C interrupt
i2c2_interrupt_flag_get get I2C interrupt flag status
i2c2_interrupt_flag_clear clear I2C interrupt flag status

Enum i2c_flag_enum

Table 3-527. i2c_flag_enum


Member name Function description
I2C_FLAG_SBSEND start condition send out
address is sent in master mode or received and matches in slave
I2C_FLAG_ADDSEND
mode
I2C_FLAG_BTC byte transmission finishes
I2C_FLAG_ADD10SEND header of 10-bit address is sent in master mode
I2C_FLAG_STPDET stop condition detected in slave mode
I2C_FLAG_RBNE I2C_DATA is not Empty during receiving
I2C_FLAG_TBE I2C_DATA is empty during transmitting
I2C_FLAG_BERR a bus error occurs indication a unexpected start or stop condition

396
GD32E50x Firmware Library User Guide
Member name Function description
on I2C bus
I2C_FLAG_LOSTARB arbitration lost in master mode
I2C_FLAG_AERR acknowledge error
I2C_FLAG_OUERR overrun or underrun situation occurs in slave mode
I2C_FLAG_PECERR PEC error when receiving data
I2C_FLAG_SMBTO timeout signal in SMBus mode
I2C_FLAG_SMBALT SMBus alert status
I2C_FLAG_MASTER a flag indicating whether I2C block is in master or slave mode
I2C_FLAG_I2CBSY busy flag
I2C_FLAG_TR whether the I2C is a transmitter or a receiver
I2C_FLAG_RXGC general call address (00h) received
I2C_FLAG_DEFSMB default address of SMBus device
I2C_FLAG_HSTSMB SMBus host header detected in slave mode
dual flag in slave mode indicating which address is matched in
I2C_FLAG_DUMOD
dual-address mode
I2C_FLAG_TFF txframe fall flag
I2C_FLAG_TFR txframe rise flag
I2C_FLAG_RFF rxframe fall flag
I2C_FLAG_RFR rxframe rise flag
I2C_FLAG_STLO start lost flag
I2C_FLAG_STPSEND stop condition sent flag

Enum i2c_interrupt_enum

Table 3-528. i2c_interrupt_enum


Member name Function description
I2C_INT_ERR error interrupt disable
I2C_INT_EV event interrupt disable
I2C_INT_BUF buffer interrupt disable
I2C_INT_TFF txframe fall interrupt enable
I2C_INT_TFR txframe rise interrupt enable
I2C_INT_RFF rxframe fall interrupt enable
I2C_INT_RFR rxframe rise interrupt enable
I2C_INT_STLO start lost interrupt enable
I2C_INT_STPSEND stop condition sent interrupt enable

Enum i2c_interrupt_flag_enum

Table 3-529. i2c_interrupt_flag_enum


Member name Function description
I2C_INT_FLAG_SBSEND start condition sent out in master mode interrupt flag
I2C_INT_FLAG_ADDSEND address is sent in master mode or received and matches in slave

397
GD32E50x Firmware Library User Guide
Member name Function description
mode interrupt flag
I2C_INT_FLAG_BTC byte transmission finishes
I2C_INT_FLAG_ADD10SEND header of 10-bit address is sent in master mode interrupt flag
I2C_INT_FLAG_STPDET stop condition detected in slave mode interrupt flag
I2C_INT_FLAG_RBNE I2C_DATA is not Empty during receiving interrupt flag
I2C_INT_FLAG_TBE I2C_DATA is empty during transmitting interrupt flag
a bus error occurs indication a unexpected start or stop condition
I2C_INT_FLAG_BERR
on I2C bus interrupt flag
I2C_INT_FLAG_LOSTARB arbitration lost in master mode interrupt flag
I2C_INT_FLAG_AERR acknowledge error interrupt flag
I2C_INT_FLAG_OUERR over-run or under-run situation occurs in slave mode interrupt flag
I2C_INT_FLAG_PECERR PEC error when receiving data interrupt flag
I2C_INT_FLAG_SMBTO timeout signal in SMBus mode interrupt flag
I2C_INT_FLAG_SMBALT SMBus Alert status interrupt flag
I2C_INT_FLAG_TFF txframe fall interrupt flag
I2C_INT_FLAG_TFR txframe rise interrupt flag
I2C_INT_FLAG_RFF rxframe fall interrupt flag
I2C_INT_FLAG_RFR rxframe rise interrupt flag
I2C_INT_FLAG_STLO start lost interrupt flag
I2C_INT_FLAG_STPSEND stop condition sent interrupt flag

Enum i2c2_interrupt_flag_enum

Table 3-530. i2c2_interrupt_flag_enum


Member name Function description
I2C2_INT_FLAG_TI transmit interrupt flag
I2C2_INT_FLAG_RBNE I2C_RDATA is not empty during receiving interrupt flag
I2C2_INT_FLAG_ADDSEND address received matches in slave mode interrupt flag
I2C2_INT_FLAG_NACK not acknowledge interrupt flag
I2C2_INT_FLAG_STPDET stop condition detected in slave mode interrupt flag
I2C2_INT_FLAG_TC transfer complete in master mode interrupt flag
I2C2_INT_FLAG_TCR transfer complete reload interrupt flag
I2C2_INT_FLAG_BERR bus error interrupt flag
I2C2_INT_FLAG_LOSTARB arbitration lost interrupt flag
I2C2_INT_FLAG_OUERR overrun/underrun error in slave mode interrupt flag
I2C2_INT_FLAG_PECERR PEC error interrupt flag
I2C2_INT_FLAG_TIMEOUT timeout interrupt flag
I2C2_INT_FLAG_SMBALT SMBus Alert interrupt flag

i2c_deinit

The description of i2c_deinit is shown as below:

398
GD32E50x Firmware Library User Guide
Table 3-531. Function i2c_deinit
Function name i2c_deinit
Function prototype void i2c_deinit(uint32_t i2c_periph);
Function descriptions reset I2C
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* reset I2C0 */

i2c_deinit (I2C0);

i2c_enable

The description of i2c_enable is shown as below:

Table 3-532. Function i2c_enable


Function name i2c_enable
Function prototype void i2c_enable(uint32_t i2c_periph);
Function descriptions enable I2C
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C0 */

i2c_enable (I2C0);

i2c_disable

The description of i2c_disable is shown as below:

399
GD32E50x Firmware Library User Guide
Table 3-533. Function i2c_disable
Function name i2c_disable
Function prototype void i2c_disable(uint32_t i2c_periph);
Function descriptions disable I2C
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable I2C0 */

i2c_disable (I2C0);

i2c_start_on_bus

The description of i2c_start_on_bus is shown as below:

Table 3-534. Function i2c_start_on_bus


Function name i2c_start_on_bus
Function prototype void i2c_start_on_bus(uint32_t i2c_periph);
Function descriptions generate a START condition on I2C bus
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* I2C0 send a start condition to I2C bus */

i2c_start_on_bus (I2C0);

i2c_stop_on_bus

The description of i2c_stop_on_bus is shown as below:

400
GD32E50x Firmware Library User Guide
Table 3-535. Function i2c_stop_on_bus
Function name i2c_stop_on_bus
Function prototype void i2c_stop_on_bus(uint32_t i2c_periph);
Function descriptions generate a STOP condition on I2C bus
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* I2C0 generate a STOP condition to I2C bus */

i2c_stop_on_bus (I2C0);

i2c_slave_response_to_gcall_enable

The description of i2c_slave_response_to_gcall_enable is shown as below:

Table 3-536. Function i2c_slave_response_to_gcall_enable


Function name i2c_slave_response_to_gcall_enable
Function prototype void i2c_slave_response_to_gcall_enable(uint32_t i2c_periph);
Function descriptions enable the response to a general call
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable the response to a general call */

i2c_slave_response_to_gcall_enable (I2C0);

i2c_slave_response_to_gcall_disable

The description of i2c_slave_response_to_gcall_disable is shown as below:

401
GD32E50x Firmware Library User Guide
Table 3-537. Function i2c_slave_response_to_gcall_disable
Function name i2c_slave_response_to_gcall_disable
Function prototype void i2c_slave_response_to_gcall_disable(uint32_t i2c_periph);
Function descriptions disable the response to a general call
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable the response to a general call */

i2c_slave_response_to_gcall_disable (I2C0);

i2c_stretch_scl_low_enable

The description of i2c_stretch_scl_low_enable is shown as below:

Table 3-538. Function i2c_stretch_scl_low_enable


Function name i2c_stretch_scl_low_enable
Function prototype void i2c_stretch_scl_low_enable(uint32_t i2c_periph);
Function descriptions enable to stretch SCL low when data is not ready in slave mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable to stretch SCL low when data is not ready in slave mode */

i2c_stretch_scl_low_enable (I2C0);

i2c_stretch_scl_low_disable

The description of i2c_stretch_scl_low_disable is shown as below:

402
GD32E50x Firmware Library User Guide
Table 3-539. Function i2c_stretch_scl_low_disable
Function name i2c_stretch_scl_low_disable
Function prototype void i2c_stretch_scl_low_disable(uint32_t i2c_periph);
Function descriptions disable to stretch SCL low when data is not ready in slave mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable to stretch SCL low when data is not ready in slave mode */

i2c_stretch_scl_low_disable (I2C0);

i2c_data_transmit

The description of i2c_data_transmit is shown as below:

Table 3-540. Function i2c_data_transmit


Function name i2c_data_transmit
Function prototype void i2c_data_transmit(uint32_t i2c_periph, uint32_t data);
Function descriptions I2C transmit data function
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Input parameter{in}
data transmit data
Output parameter{out}
- -
Return value
- -

Example:

/* I2C0 transmit data */

i2c_data_transmit (I2C0, 0x55);

403
GD32E50x Firmware Library User Guide
i2c_data_receive

The description of i2c_data_receive is shown as below:

Table 3-541. Function i2c_data_receive


Function name i2c_data_receive
Function prototype uint8_t i2c_data_receive(uint32_t i2c_periph);
Function descriptions I2C receive data function
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
uint32_t 0x00..0xFF

Example:

/* I2C0 receive data */

uint32_t i2c_receiver;

i2c_receiver = i2c_data_receive(I2C0);

i2c_pec_transfer

The description of i2c_pec_transfer is shown as below:

Table 3-542. Function i2c_pec_transfer


Function name i2c_pec_transfer
Function prototype void i2c_pec_transfer(uint32_t i2c_periph);
Function descriptions I2C transfers PEC value
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* I2C transfers PEC value */

404
GD32E50x Firmware Library User Guide
i2c_pec_transfer (I2C0);

i2c_pec_enable

The description of i2c_pec_enable is shown as below:

Table 3-543. Function i2c_pec_enable


Function name i2c_pec_enable
Function prototype void i2c_pec_enable(uint32_t i2c_periph);
Function descriptions enable I2C PEC calculation
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C PEC calculation */

i2c_pec_enable (I2C0);

i2c_pec_disable

The description of i2c_pec_disable is shown as below:

Table 3-544. Function i2c_pec_disable


Function name i2c_pec_disable
Function prototype void i2c_pec_disable(uint32_t i2c_periph);
Function descriptions disable I2C PEC calculation
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable I2C PEC calculation */

405
GD32E50x Firmware Library User Guide
i2c_pec_disable (I2C0);

i2c_pec_value_get

The description of i2c_pec_value_get is shown as below:

Table 3-545. Function i2c_pec_value_get


Function name i2c_pec_value_get
Function prototype uint32_t i2c_pec_value_get(uint32_t i2c_periph);
Function descriptions get packet error checking value
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1,2)
Output parameter{out}
- -
Return value
uint32_t PEC value

Example:

/* I2C0 get packet error checking value */

uint32_t pec_value;

pec_value = i2c_pec_value_get (I2C0);

i2c_clock_config

The description of i2c_clock_config is shown as below:

Table 3-546. Function i2c_clock_config


Function name i2c_clock_config

Function prototype void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t


dutycyc);

Function descriptions I2C clock configure

Precondition -

The called functions rcu_clock_freq_get


Input parameter{in}

i2c_periph I2C peripheral

I2Cx (x=0,1)
Input parameter{in}

406
GD32E50x Firmware Library User Guide
clkspeed i2c clock speed
Input parameter{in}

dutycyc duty cycle in fast mode

I2C_DTCY_2 T_low/T_high=2

I2C_DTCY_16_9 T_low/T_high=16/9
Output parameter{out}

- -
Return value

- -

Example:

/* configure I2C0 clock speed as 100KHz*/

i2c_clock_config(I2C0, 100000, I2C_DTCY_2);

i2c_mode_addr_config

The description of i2c_mode_addr_config is shown as below:

Table 3-547. Function i2c_mode_addr_config


Function name i2c_mode_addr_config
void i2c_mode_addr_config(uint32_t i2c_periph, uint32_t mode, uint32_t
Function prototype
addformat, uint32_t addr);
Function descriptions configure I2C address
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
mode I2C mode select
I2C_I2CMODE_ENABL
I2C mode
E
I2C_SMBUSMODE_EN
SMBus mode
ABLE
Input parameter{in}
addformat 7bits or 10bits
I2C_ADDFORMAT_7BI
7bits
TS
I2C_ADDFORMAT_10
10bits
BITS

407
GD32E50x Firmware Library User Guide
Input parameter{in}
addr I2C address
Output parameter{out}
- -
Return value
- -

Example:

/* configure I2C0 address as 0x82, using 7 bits */

i2c_mode_addr_config(I2C0, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, 0x82);

i2c_smbus_type_config

The description of i2c_smbus_type_config is shown as below:

Table 3-548. Function i2c_smbus_type_config


Function name i2c_smbus_type_config
Function prototype void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type);
Function descriptions SMBus type selection
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
type Device or host
I2C_SMBUS_DEVICE device
I2C_SMBUS_HOST host
Output parameter{out}
- -
Return value
- -

Example:

/* config I2C0 as SMBUS host type*/

i2c_smbus_type_config (I2C0, I2C_SMBUS_HOST);

i2c_ack_config

The description of i2c_ack_config is shown as below:

Table 3-549. Function i2c_ack_config


Function name i2c_ack_config
Function prototype void i2c_ack_config(uint32_t i2c_periph, uint32_t ack);
408
GD32E50x Firmware Library User Guide
Function descriptions whether or not to send an ACK
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
ack I2C peripheral
I2C_ACK_ENABLE ACK will be sent
I2C_ACK_DISABLE ACK will not be sent
Output parameter{out}
- -
Return value
- -

Example:

/* I2C0 will send ACK */

i2c_ack_config (I2C0, I2C_ACK_ENABLE);

i2c_ackpos_config

The description of i2c_ackpos_config is shown as below:

Table 3-550. Function i2c_ackpos_config


Function name i2c_ackpos_config
Function prototype void i2c_ackpos_config(uint32_t i2c_periph, uint32_t pos);
Function descriptions I2C POAP position configure
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
pos ACK position
I2C_ACKPOS_CURRE
whether to send ACK or not for the current
NT
I2C_ACKPOS_NEXT whether to send ACK or not for the next byte
Output parameter{out}
- -
Return value
- -

Example:

409
GD32E50x Firmware Library User Guide
/* The ACK of I2C0 is send for the current frame*/

i2c_ackpos_config (I2C0, I2C_ACKPOS_CURRENT);

i2c_master_addressing

The description of i2c_master_addressing is shown as below:

Table 3-551. Function i2c_master_addressing


Function name i2c_master_addressing
void i2c_master_addressing(uint32_t i2c_periph, uint32_t addr, uint32_t
Function prototype
trandirection);
Function descriptions master sends slave address
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
addr slave address
Input parameter{in}
trandirection transmitter or receiver
I2C_TRANSMITTER transmitter
I2C_RECEIVER receiver
Output parameter{out}
- -
Return value
- -

Example:

/* send slave address to I2C bus and I2C0 act as receiver */

i2c_master_addressing(I2C0, 0x82, I2C_RECEIVER);

i2c_dualaddr_enable

The description of i2c_dualaddr_enable is shown as below:

Table 3-552. Function i2c_dualaddr_enable


Function name i2c_dualaddr_enable
Function prototype void i2c_dualaddr_enable(uint32_t i2c_periph, uint32_t dualaddr);
Function descriptions enable dual-address mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
410
GD32E50x Firmware Library User Guide
I2Cx (x=0,1)
Input parameter{in}
addr the second address in dual-address mode
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C0 dual-address */

i2c_dualaddr_enable (I2C0, 0x82);

i2c_dualaddr_disable

The description of i2c_dualaddr_disable is shown as below:

Table 3-553. Function i2c_dualaddr_disable


Function name i2c_dualaddr_disable
Function prototype void i2c_dualaddr_disable(uint32_t i2c_periph);
Function descriptions disable dual-address mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable dual-address mode */

i2c_dualaddr_disable (I2C0);

i2c_dma_enable

The description of i2c_dma_enable is shown as below:

Table 3-554. Function i2c_dma_enable


Function name i2c_dma_enable
Function prototype void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate);
Function descriptions enable I2C DMA mode
Precondition -
The called functions -
411
GD32E50x Firmware Library User Guide
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
dmastate On or off
I2C_DMA_ON DMA mode enable
I2C_DMA_OFF DMA mode disable
Output parameter{out}
- -
Return value
- -

Example:

/* I2C0 DMA mode enable */

i2c_dma_enable (I2C0, I2C_DMA_ON);

i2c_dma_last_transfer_config

The description of i2c_dma_last_transfer_config is shown as below:

Table 3-555. Function i2c_dma_last_transfer_config


Function name i2c_dma_last_transfer_config
Function prototype void i2c_dma_last_transfer_config (uint32_t i2c_periph, uint32_t dmalast);
Function descriptions flag indicating DMA last transfer
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
dmalast next DMA EOT is the last transfer or not
I2C_DMALST_ON next DMA EOT is the last transfer
I2C_DMALST_OFF next DMA EOT is not the last transfer
Output parameter{out}
- -
Return value
- -

Example:

/* next DMA EOT is the last transfer */

i2c_dma_last_transfer_enable (I2C0, I2C_DMALST_ON);

412
GD32E50x Firmware Library User Guide
i2c_software_reset_config

The description of i2c_software_reset_config is shown as below:

Table 3-556. Function i2c_software_reset_config


Function name i2c_software_reset_config
Function prototype void i2c_software_reset_config(uint32_t i2c_periph, uint32_t sreset);
Function descriptions software reset I2C
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
sreset under reset or not
I2C_SRESET_SET I2C is under reset
I2C_SRESET_RESET I2C is not under reset
Output parameter{out}
- -
Return value
- -

Example:

/* software reset I2C0 */

i2c_software_reset_config (I2C0, I2C_SRESET_SET);

i2c_smbus_issue_alert

The description of i2c_smbus_issue_alert is shown as below:

Table 3-557. Function i2c_smbus_issue_alert


Function name i2c_smbus_issue_alert
Function prototype void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara);
Function descriptions I2C issue alert through SMBA pin
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
smbuspara issue alert through SMBA pin or not
I2C_SALTSEND_ENAB
issue alert through SMBA pin
LE
I2C_SALTSEND_DISA not issue alert through SMBA pin

413
GD32E50x Firmware Library User Guide
BLE
Output parameter{out}
- -
Return value
- -

Example:

/* I2C0 issue alert through SMBA pin enable*/

i2c_smbus_issue_alert (I2C0, I2C_SALTSEND_ENABLE);

i2c_smbus_arp_enable

The description of i2c_smbus_arp_enable is shown as below:

Table 3-558. Function i2c_smbus_arp_enable


Function name i2c_smbus_arp_enable
Function prototype void i2c_smbus_arp_enable(uint32_t i2c_periph, uint32_t arpstate);
Function descriptions enable or disable I2C ARP protocol in SMBus switch
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
arpstate ARP protocol in SMBus switch
I2C_ARP_ENABLE enable ARP
I2C_ARP_DISABLE disable ARP
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C0 ARP protocol in SMBus switch */

i2c_smbus_arp_enable (I2C0, I2C_ARP_ENABLE);

i2c_sam_enable

The description of i2c_sam_enable is shown as below:

Table 3-559. Function i2c_sam_enable


Function name i2c_sam_enable
Function prototype void i2c_sam_enable(uint32_t i2c_periph);
Function descriptions enable SAM_V interface
414
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable SAM_V interface */

i2c_sam_enable (I2C0);

i2c_sam_disable

The description of i2c_sam_disable is shown as below:

Table 3-560. Function i2c_sam_disable


Function name i2c_sam_disable
Function prototype void i2c_sam_disable(uint32_t i2c_periph);
Function descriptions disable SAM_V interface
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable SAM_V interface */

i2c_sam_disable (I2C0);

i2c_sam_timeout_enable

The description of i2c_sam_timeout_enable is shown as below:

Table 3-561. Function i2c_sam_timeout_enable


Function name i2c_sam_timeout_enable
Function prototype void i2c_sam_timeout_enable(uint32_t i2c_periph);
Function descriptions enable SAM_V interface timeout detect
415
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable SAM_V interface timeout detect */

i2c_sam_timeout_enable (I2C0);

i2c_sam_timeout_disable

The description of i2c_sam_timeout_disable is shown as below:

Table 3-562. Function i2c_sam_timeout_disable


Function name i2c_sam_timeout_disable
Function prototype void i2c_sam_timeout_disable(uint32_t i2c_periph);
Function descriptions disable SAM_V interface timeout detect
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable SAM_V interface timeout detect */

i2c_sam_timeout_disable (I2C0);

i2c_start_early_termination_mode_config

The description of i2c_start_early_termination_mode_config is shown as below:

Table 3-563. Function i2c_start_early_termination_mode_config


Function name i2c_start_early_termination_mode_config
void i2c_start_early_termination_mode_config(uint32_t i2c_periph, uint32_t
Function prototype
mode);
416
GD32E50x Firmware Library User Guide
Function descriptions configure I2C start early termination mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
mode I2C start early termination mode
STANDARD_I2C_PRO
do as the standard i2c protocol
TOCOL_MODE
ARBITRATION_LOST_
do the same thing as arbitration lost
MODE
Output parameter{out}
- -
Return value
- -

Example:

/* configure I2C start early termination mode */

i2c_start_early_termination_mode_config (I2C0, ARBITRATION_LOST_MODE);

i2c_timeout_calculation_enable

The description of i2c_timeout_calculation_enable is shown as below:

Table 3-564. Function i2c_timeout_calculation_enable


Function name i2c_timeout_calculation_enable
Function prototype void i2c_timeout_calculation_enable(uint32_t i2c_periph);
Function descriptions enable i2c timeout calculation
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable i2c timeout calculation */

i2c_timeout_calculation_enable (I2C0);

417
GD32E50x Firmware Library User Guide
i2c_timeout_calculation_disable

The description of i2c_timeout_calculation_disable is shown as below:

Table 3-565. Function i2c_timeout_calculation_disable


Function name i2c_timeout_calculation_disable
Function prototype void i2c_timeout_calculation_disable(uint32_t i2c_periph);
Function descriptions disable i2c timeout calculation
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable i2c timeout calculation */

i2c_timeout_calculation_disable (I2C0);

i2c_record_received_slave_address_enable

The description of i2c_record_received_slave_address_enable is shown as below:

Table 3-566. Function i2c_record_received_slave_address_enable


Function name i2c_record_received_slave_address_enable
Function prototype void i2c_record_received_slave_address_enable(uint32_t i2c_periph);
Function descriptions enable i2c record the received slave address to the transfer buffer register
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable i2c record the received slave address to the transfer buffer register */

i2c_record_received_slave_address_enable (I2C0);

418
GD32E50x Firmware Library User Guide
i2c_record_received_slave_address_disable

The description of i2c_record_received_slave_address_disable is shown as below:

Table 3-567. Function i2c_record_received_slave_address_disable


Function name i2c_record_received_slave_address_disable
Function prototype void i2c_record_received_slave_address_disable(uint32_t i2c_periph);
Function descriptions disable i2c record the received slave address to the transfer buffer register
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable i2c record the received slave address to the transfer buffer register */

i2c_record_received_slave_address_disable (I2C0);

i2c_address_bit_compare_config

The description of i2c_address_bit_compare_config is shown as below:

Table 3-568. Function i2c_address_bit_compare_config


Function name i2c_address_bit_compare_config
void i2c_address_bit_compare_config(uint32_t i2c_periph, uint16_t
Function prototype
compare_bits);
define which bits of ADDRESS[7:1] need to compare with the incoming
Function descriptions
address byte
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
mode the bits need to compare
ADDRESS_BIT1_COM
address bit1 needs compare
PARE
ADDRESS_BIT2_COM
address bit2 needs compare
PARE
ADDRESS_BIT3_COM address bit3 needs compare

419
GD32E50x Firmware Library User Guide
PARE
ADDRESS_BIT4_COM
address bit4 needs compare
PARE
ADDRESS_BIT5_COM
address bit5 needs compare
PARE
ADDRESS_BIT6_COM
address bit6 needs compare
PARE
ADDRESS_BIT7_COM
address bit7 needs compare
PARE
Output parameter{out}
- -
Return value
- -

Example:

/* define which bits of ADDRESS[7:1] need to compare with the incoming address byte */

i2c_address_bit_compare_config (I2C0, ADDRESS_BIT7_COMPARE);

i2c_status_clear_enable

The description of i2c_status_clear_enable is shown as below:

Table 3-569. Function i2c_status_clear_enable


Function name i2c_status_clear_enable
Function prototype void i2c_status_clear_enable(uint32_t i2c_periph);
Function descriptions enable i2c status register clear
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* enable i2c status register clear */

i2c_status_clear_enable (I2C0);

i2c_status_clear_disable

The description of i2c_status_clear_disable is shown as below:

420
GD32E50x Firmware Library User Guide
Table 3-570. Function i2c_status_clear_disable
Function name i2c_status_clear_disable
Function prototype void i2c_status_clear_disable(uint32_t i2c_periph);
Function descriptions disable i2c status register clear
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Output parameter{out}
- -
Return value
- -

Example:

/* disable i2c status register clear */

i2c_status_clear_disable (I2C0);

i2c_status_bit_clear

The description of i2c_status_bit_clear is shown as below:

Table 3-571. Function i2c_start_early_termination_mode_config


Function name i2c_status_bit_clear
Function prototype void i2c_status_bit_clear(uint32_t i2c_periph, uint32_t clear_bit);
Function descriptions clear i2c status register bit
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
clear_bit which bit needs to clear
CLEAR_STPDET clear STPDET bit in I2C_STAT0
CLEAR_ADD10SEND clear ADD10SEND bit in I2C_STAT0
CLEAR_BTC clear BTC bit in I2C_STAT0
CLEAR_ADDSEND clear ADDSEND bit in I2C_STAT0
CLEAR_SBSEND clear SBSEND bit in I2C_STAT0
Output parameter{out}
- -
Return value
- -

Example:
421
GD32E50x Firmware Library User Guide
/* clear i2c status register bit */

i2c_status_bit_clear (I2C0, CLEAR_ADDSEND);

i2c_flag_get

The description of i2c_flag_get is shown as below:

Table 3-572. Function i2c_flag_get


Function name i2c_flag_get
Function prototype FlagStatus i2c_flag_get(uint32_t i2c_periph, i2c_flag_enum flag);
Function descriptions check I2C flag is set or not
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
flag specify get which flag, refer to Enum i2c_flag_enum.
I2C_FLAG_SBSEND start condition send out
I2C_FLAG_ADDSEND address is sent in master mode or received and matches in slave mode
I2C_FLAG_BTC byte transmission finishes
I2C_FLAG_ADD10SEN
header of 10-bit address is sent in master mode
D
I2C_FLAG_STPDET stop condition detected in slave mode
I2C_FLAG_RBNE I2C_DATA is not Empty during receiving
I2C_FLAG_TBE I2C_DATA is empty during transmitting
a bus error occurs indication a unexpected start or stop condition on I2C
I2C_FLAG_BERR
bus
I2C_FLAG_LOSTARB arbitration lost in master mode
I2C_FLAG_AERR acknowledge error
I2C_FLAG_OUERR overrun or underrun situation occurs in slave mode
I2C_FLAG_PECERR PEC error when receiving data
I2C_FLAG_SMBTO timeout signal in SMBus mode
I2C_FLAG_SMBALT SMBus alert status
I2C_FLAG_MASTER a flag indicating whether I2C block is in master or slave mode
I2C_FLAG_I2CBSY busy flag
I2C_FLAG_TR whether the I2C is a transmitter or a receiver
I2C_FLAG_RXGC general call address (00h) received
I2C_FLAG_DEFSMB default address of SMBus device
I2C_FLAG_HSTSMB SMBus host header detected in slave mode
dual flag in slave mode indicating which address is matched in dual-address
I2C_FLAG_DUMOD
mode
I2C_FLAG_TFF txframe fall flag

422
GD32E50x Firmware Library User Guide
I2C_FLAG_TFR txframe rise flag
I2C_FLAG_RFF rxframe fall flag
I2C_FLAG_RFR rxframe rise flag
I2C_FLAG_STLO start lost flag
I2C_FLAG_STPSEND stop condition sent flag
Output parameter{out}
- -
Return value
FlagStatus SET / RESET

Example:

/* check whether start condition send out */

FlagStatus flag_state = RESET;

flag_state = i2c_flag_get (I2C0, I2C_FLAG_SBSEND);

i2c_flag_clear

The description of i2c_flag_clear is shown as below:

Table 3-573. Function i2c_flag_clear


Function name i2c_flag_clear
Function prototype void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag);
Function descriptions clear I2C flag
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
flag flag type, refer to Enum i2c_flag_enum.
I2C_FLAG_SMBALT SMBus Alert status
I2C_FLAG_SMBTO timeout signal in SMBus mode
I2C_FLAG_PECERR PEC error when receiving data
I2C_FLAG_OUERR over-run or under-run situation occurs in slave mode
I2C_FLAG_AERR acknowledge error
I2C_FLAG_LOSTARB arbitration lost in master mode
I2C_FLAG_BERR a bus error
I2C_FLAG_ADDSEND cleared by reading I2C_STAT0 and reading I2C_STAT1
I2C_FLAG_TFF txframe fall flag
I2C_FLAG_TFR txframe rise flag
I2C_FLAG_RFF rxframe fall flag
I2C_FLAG_RFR rxframe rise flag
I2C_FLAG_STLO start lost flag
423
GD32E50x Firmware Library User Guide
I2C_FLAG_STPSEND stop condition sent flag
Output parameter{out}
- -
Return value
- -

Example:

/* clear a bus error flag*/

i2c_flag_clear (I2C0, I2C_FLAG_BERR);

i2c_interrupt_enable

The description of i2c_interrupt_enable is shown as below:

Table 3-574. Function i2c_interrupt_enable


Function name i2c_interrupt_enable
Function prototype void i2c_interrupt_enable(uint32_t i2c_periph, i2c_interrupt_enum interrupt);
Function descriptions enable I2C interrupt
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
interrupt interrupt type, refer to Enum i2c_interrupt_enum.
I2C_INT_ERR error interrupt enable
I2C_INT_EV event interrupt enable
I2C_INT_BUF buffer interrupt enable
I2C_INT_TFF txframe fall interrupt enable
I2C_INT_TFR txframe rise interrupt enable
I2C_INT_RFF rxframe fall interrupt enable
I2C_INT_RFR rxframe rise interrupt enable
I2C_INT_STLO start lost interrupt enable
I2C_INT_STPSEND stop condition sent interrupt enable
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C0 error interrupt */

i2c_interrupt_enable (I2C0, I2C_INT_EV);

424
GD32E50x Firmware Library User Guide
i2c_interrupt_disable

The description of i2c_interrupt_disable is shown as below:

Table 3-575. Function i2c_interrupt_disable


Function name i2c_interrupt_disable
void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum
Function prototype
interrupt);
Function descriptions disable I2C interrupt
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
interrupt interrupt type, refer to Enum i2c_interrupt_enum.
I2C_INT_ERR error interrupt disable
I2C_INT_EV event interrupt disable
I2C_INT_BUF buffer interrupt disable
I2C_INT_TFF txframe fall interrupt enable
I2C_INT_TFR txframe rise interrupt enable
I2C_INT_RFF rxframe fall interrupt enable
I2C_INT_RFR rxframe rise interrupt enable
I2C_INT_STLO start lost interrupt enable
I2C_INT_STPSEND stop condition sent interrupt enable
Output parameter{out}
- -
Return value
- -

Example:

/* disable I2C0 error interrupt */

i2c_interrupt_disable (I2C0, I2C_INT_EV);

i2c_interrupt_flag_get

The description of i2c_interrupt_flag_get is shown as below:

Table 3-576. Function i2c_interrupt_flag_get


Function name i2c_interrupt_flag_get
FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph,
Function prototype
i2c_interrupt_flag_enum int_flag);
Function descriptions check I2C interrupt flag
Precondition -

425
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
int_flag interrupt flag, refer to Enum i2c_interrupt_flag_enum.
I2C_INT_FLAG_SBSE
start condition sent out in master mode interrupt flag
ND
I2C_INT_FLAG_ADDS address is sent in master mode or received and matches in slave mode
END interrupt flag
I2C_INT_FLAG_BTC byte transmission finishes
I2C_INT_FLAG_ADD10
header of 10-bit address is sent in master mode interrupt flag
SEND
I2C_INT_FLAG_STPD
stop condition detected in slave mode interrupt flag
ET
I2C_INT_FLAG_RBNE I2C_DATA is not Empty during receiving interrupt flag
I2C_INT_FLAG_TBE I2C_DATA is empty during transmitting interrupt flag
a bus error occurs indication a unexpected start or stop condition on I2C
I2C_INT_FLAG_BERR
bus interrupt flag
I2C_INT_FLAG_LOSTA
arbitration lost in master mode interrupt flag
RB
I2C_INT_FLAG_AERR acknowledge error interrupt flag
I2C_INT_FLAG_OUER
over-run or under-run situation occurs in slave mode interrupt flag
R
I2C_INT_FLAG_PECE
PEC error when receiving data interrupt flag
RR
I2C_INT_FLAG_SMBT
timeout signal in SMBus mode interrupt flag
O
I2C_INT_FLAG_SMBA
SMBus Alert status interrupt flag
LT
I2C_INT_FLAG_TFF txframe fall interrupt flag
I2C_INT_FLAG_TFR txframe rise interrupt flag
I2C_INT_FLAG_RFF rxframe fall interrupt flag
I2C_INT_FLAG_RFR rxframe rise interrupt flag
I2C_INT_FLAG_STLO start lost interrupt flag
I2C_INT_FLAG_STPSE
stop condition sent interrupt flag
ND
Output parameter{out}
- -
Return value
FlagStatus SET / RESET

Example:

426
GD32E50x Firmware Library User Guide
/* check the byte transmission finishes interrupt flag is set or not*/

FlagStatus flag_state = RESET;

flag_state = i2c_interrupt_flag_get (I2C0, I2C_INT_FLAG_BTC);

i2c_interrupt_flag_clear

The description of i2c_interrupt_flag_clear is shown as below:

Table 3-577. Function i2c_interrupt_flag_clear


Function name i2c_interrupt_flag_clear
void i2c_interrupt_flag_clear(uint32_t i2c_periph, i2c_interrupt_flag_enum
Function prototype
int_flag);
Function descriptions clear I2C interrupt flag
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=0,1)
Input parameter{in}
int_flag interrupt flag, refer to Enum i2c_interrupt_flag_enum.
I2C_INT_FLAG_ADDS address is sent in master mode or received and matches in slave mode
END interrupt flag
a bus error occurs indication a unexpected start or stop condition on I2C
I2C_INT_FLAG_BERR
bus interrupt flag
I2C_INT_FLAG_LOSTA
arbitration lost in master mode interrupt flag
RB
I2C_INT_FLAG_AERR acknowledge error interrupt flag
I2C_INT_FLAG_OUER
over-run or under-run situation occurs in slave mode interrupt flag
R
I2C_INT_FLAG_PECE
PEC error when receiving data interrupt flag
RR
I2C_INT_FLAG_SMBT
timeout signal in SMBus mode interrupt flag
O
I2C_INT_FLAG_SMBA
SMBus Alert status interrupt flag
LT
I2C_INT_FLAG_TFF txframe fall interrupt flag
I2C_INT_FLAG_TFR txframe rise interrupt flag
I2C_INT_FLAG_RFF rxframe fall interrupt flag
I2C_INT_FLAG_RFR rxframe rise interrupt flag
I2C_INT_FLAG_STLO start lost interrupt flag
I2C_INT_FLAG_STPSE
stop condition sent interrupt flag
ND
Output parameter{out}

427
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* clear the acknowledge error interrupt flag */

i2c_interrupt_flag_clear (I2C0, I2C_INT_FLAG_AERR);

i2c_timing_config

The description of i2c_timing_config is shown as below:

Table 3-578. Function i2c_timing_config


Function name i2c_timing_config
void i2c_timing_config(uint32_t i2c_periph, uint32_t psc, uint32_t scl_dely,
Function prototype
uint32_t sda_dely);
Function descriptions configure the timing parameters
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
psc 0-0xf, timing prescaler
Input parameter{in}
scl_dely 0-0xf,data setup time
Input parameter{in}
sda_dely 0-0xf,data hold time
Output parameter{out}
- -
Return value
- -

Example:

/* configure the timing parameters */

i2c_timing_config (I2C2, 0x1, 0x2, 0x1);

i2c_digital_noise_filter_config

The description of i2c_digital_noise_filter_config is shown as below:

Table 3-579. Function i2c_digital_noise_filter_config


Function name i2c_digital_noise_filter_config
Function prototype void i2c_digital_noise_filter_config(uint32_t i2c_periph, uint32_t
428
GD32E50x Firmware Library User Guide
filter_length);
Function descriptions configure digital noise filter
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
filter_length filter_length
FILTER_DISABLE digital filter is disabled
FILTER_LENGTH_1 digital filter is enabled and filter spikes with a length of up to 1 tI2CCLK
FILTER_LENGTH_2 digital filter is enabled and filter spikes with a length of up to 2 tI2CCLK
FILTER_LENGTH_3 digital filter is enabled and filter spikes with a length of up to 3 tI2CCLK
FILTER_LENGTH_4 digital filter is enabled and filter spikes with a length of up to 4 tI2CCLK
FILTER_LENGTH_5 digital filter is enabled and filter spikes with a length of up to 5 tI2CCLK
FILTER_LENGTH_6 digital filter is enabled and filter spikes with a length of up to 6 tI2CCLK
FILTER_LENGTH_7 digital filter is enabled and filter spikes with a length of up to 7 tI2CCLK
FILTER_LENGTH_8 digital filter is enabled and filter spikes with a length of up to 8 tI2CCLK
FILTER_LENGTH_9 digital filter is enabled and filter spikes with a length of up to 9 tI2CCLK
FILTER_LENGTH_10 digital filter is enabled and filter spikes with a length of up to 10 tI2CCLK
FILTER_LENGTH_11 digital filter is enabled and filter spikes with a length of up to 11 tI2CCLK
FILTER_LENGTH_12 digital filter is enabled and filter spikes with a length of up to 12 tI2CCLK
FILTER_LENGTH_13 digital filter is enabled and filter spikes with a length of up to 13 tI2CCLK
FILTER_LENGTH_14 digital filter is enabled and filter spikes with a length of up to 14 tI2CCLK
FILTER_LENGTH_15 digital filter is enabled and filter spikes with a length of up to 15 tI2CCLK
Output parameter{out}
- -
Return value
- -

Example:

/* I2C2 digital filter filters spikes with a length of up to 1 tI2CCLK */

i2c_digital_noise_filter_config (I2C2, FILTER_LENGTH_1);

i2c_analog_noise_filter_enable

The description of i2c_analog_noise_filter_enable is shown as below:

Table 3-580. Function i2c_analog_noise_filter_enable


Function name i2c_analog_noise_filter_enable
Function prototype void i2c_analog_noise_filter_enable(uint32_t i2c_periph);
Function descriptions enable analog noise filter
Precondition -

429
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable analog noise filter */

i2c_analog_noise_filter_enable (I2C2);

i2c_analog_noise_filter_disable

The description of i2c_analog_noise_filter_disable is shown as below:

Table 3-581. Function i2c_analog_noise_filter_disable


Function name i2c_analog_noise_filter_disable
Function prototype void i2c_analog_noise_filter_disable(uint32_t i2c_periph);
Function descriptions disable analog noise filter
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable analog noise filter */

i2c_analog_noise_filter_disable (I2C2);

i2c_wakeup_from_deepsleep_enable

The description of i2c_wakeup_from_deepsleep_enable is shown as below:

Table 3-582. Function i2c_wakeup_from_deepsleep_enable


Function name i2c_wakeup_from_deepsleep_enable
Function prototype void i2c_wakeup_from_deepsleep_enable(uint32_t i2c_periph);
Function descriptions enable wakeup from Deep-sleep mode
Precondition -
430
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable wakeup from Deep-sleep mode */

i2c_wakeup_from_deepsleep_enable (I2C2);

i2c_wakeup_from_deepsleep_disable

The description of i2c_wakeup_from_deepsleep_disable is shown as below:

Table 3-583. Function i2c_wakeup_from_deepsleep_disable


Function name i2c_wakeup_from_deepsleep_disable
Function prototype void i2c_wakeup_from_deepsleep_disable(uint32_t i2c_periph);
Function descriptions disable wakeup from Deep-sleep mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable wakeup from Deep-sleep mode */

i2c_wakeup_from_deepsleep_disable (I2C2);

i2c_master_clock_config

The description of i2c_master_clock_config is shown as below:

Table 3-584. Function i2c_master_clock_config


Function name i2c_master_clock_config
void i2c_master_clock_config(uint32_t i2c_periph, uint32_t sclh, uint32_t
Function prototype
scll);
Function descriptions configure the SCL high and low period of clock in master mode
431
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
sclh 0-0xff, SCL high period
Input parameter{in}
scll 0-0xff, SCL low period
Output parameter{out}
- -
Return value
- -

Example:

/* configure the SCL and SDA period of clock in master mode */

i2c_master_clock_config (I2C2, 0x0f, 0x0f);

i2c2_master_addressing

The description of i2c2_master_addressing is shown as below:

Table 3-585. Function i2c2_master_transfer_direction_config


Function name i2c2_master_addressing
void i2c2_master_addressing(uint32_t i2c_periph, uint32_t address,
Function prototype
uint32_t trans_direction);
Function descriptions configure i2c slave addresss and transfer direction in master mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
address 0-0x3FF except reserved address, I2C slave address to be sent
Input parameter{in}
trans_direction I2C transfer direction in master mode
I2C2_MASTER_TRAN
master transmit
SMIT
I2C2_MASTER_RECEI
master receive
VE
Output parameter{out}
- -
Return value

432
GD32E50x Firmware Library User Guide
- -

Example:

/* send slave address to I2C bus */

i2c2_master_addressing (I2C2, 0x82, I2C2_MASTER_TRANSMIT);

i2c_address10_header_enable

The description of i2c_address10_header_enable is shown as below:

Table 3-586. Function i2c_address10_header_enable


Function name i2c_address10_header_enable
Function prototype void i2c_address10_header_enable(uint32_t i2c_periph);
Function descriptions 10-bit address header executes read direction only in master receive mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* 10-bit address header executes read direction only in master receive mode */

i2c_address10_header_enable (I2C2);

i2c_address10_header_disable

The description of i2c_address10_header_disable is shown as below:

Table 3-587. Function i2c_address10_header_disable


Function name i2c_address10_header_disable
Function prototype void i2c_address10_header_disable(uint32_t i2c_periph);
Function descriptions 10-bit address header executes complete sequence in master receive mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
433
GD32E50x Firmware Library User Guide
- -

Example:

/* 10-bit address header executes complete sequence in master receive mode */

i2c_address10_header_disable (I2C2);

i2c_address10_enable

The description of i2c_address10_enable is shown as below:

Table 3-588. Function i2c_address10_enable


Function name i2c_address10_enable
Function prototype void i2c_address10_enable(uint32_t i2c_periph);
Function descriptions enable 10-bit addressing mode in master mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable 10-bit addressing mode in master mode */

i2c_address10_enable (I2C2);

i2c_address10_disable

The description of i2c_address10_disable is shown as below:

Table 3-589. Function i2c_address10_disable


Function name i2c_address10_disable
Function prototype void i2c_address10_disable(uint32_t i2c_periph);
Function descriptions disable 10-bit addressing mode in master mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
434
GD32E50x Firmware Library User Guide
- -

Example:

/* disable 10-bit addressing mode in master mode */

i2c_address10_disable (I2C2);

i2c_automatic_end_enable

The description of i2c_automatic_end_enable is shown as below:

Table 3-590. Function i2c_automatic_end_enable


Function name i2c_automatic_end_enable
Function prototype void i2c_automatic_end_enable(uint32_t i2c_periph);
Function descriptions enable I2C automatic end mode in master mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C automatic end mode in master mode */

i2c_automatic_end_enable (I2C2);

i2c_automatic_end_disable

The description of i2c_automatic_end_disable is shown as below:

Table 3-591. Function i2c_automatic_end_disable


Function name i2c_automatic_end_disable
Function prototype void i2c_automatic_end_disable(uint32_t i2c_periph);
Function descriptions disable I2C automatic end mode in master mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
435
GD32E50x Firmware Library User Guide
- -

Example:

/* disable I2C automatic end mode in master mode */

i2c_automatic_end_disable (I2C2);

i2c_address_config

The description of i2c_address_config is shown as below:

Table 3-592. Function i2c_address_config


Function name i2c_address_config
void i2c_address_config(uint32_t i2c_periph, uint32_t address, uint32_t
Function prototype
addr_format);
Function descriptions configure i2c slave address
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
address I2C address
Input parameter{in}
addr_format 7bits or 10bits
I2C_ADDFORMAT_7BI
7bits
TS
I2C_ADDFORMAT_10
10bits
BITS
Output parameter{out}
- -
Return value
- -

Example:

/* configure i2c slave address */

i2c_address_config (I2C2, 0x82, I2C_ADDFORMAT_7BITS);

i2c_address_disable

The description of i2c_address_disable is shown as below:

Table 3-593. Function i2c_address_disable


Function name i2c_address_disable
Function prototype void i2c_address_disable(uint32_t i2c_periph);

436
GD32E50x Firmware Library User Guide
Function descriptions disable i2c address in slave mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable i2c address in slave mode */

i2c_address_disable (I2C2);

i2c_second_address_config

The description of i2c_second_address_config is shown as below:

Table 3-594. Function i2c_second_address_config


Function name i2c_second_address_config
void i2c_second_address_config(uint32_t i2c_periph, uint32_t address,
Function prototype
uint32_t addr_mask);
Function descriptions configure i2c second slave address
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
address I2C address
Input parameter{in}
addr_mask the bits not need to compare
ADDRESS2_NO_MAS
no mask, all the bits must be compared
K
ADDRESS2_MASK_BI
ADDRESS2[1] is masked, only ADDRESS2[7:2] are compared
T1
ADDRESS2_MASK_BI
ADDRESS2[2:1] is masked, only ADDRESS2[7:3] are compared
T1_2
ADDRESS2_MASK_BI
ADDRESS2[3:1] is masked, only ADDRESS2[7:4] are compared
T1_3
ADDRESS2_MASK_BI
ADDRESS2[4:1] is masked, only ADDRESS2[7:5] are compared
T1_4

437
GD32E50x Firmware Library User Guide
ADDRESS2_MASK_BI
ADDRESS2[5:1] is masked, only ADDRESS2[7:6] are compared
T1_5
ADDRESS2_MASK_BI
ADDRESS2[6:1] is masked, only ADDRESS2[7] are compared
T1_6
ADDRESS2_MASK_AL
all the ADDRESS2[7:1] bits are masked
L
Output parameter{out}
- -
Return value
- -

Example:

/* configure i2c second slave address */

i2c_second_address_config (I2C2, 0x82, ADDRESS2_MASK_BIT1_2);

i2c_second_address_disable

The description of i2c_second_address_disable is shown as below:

Table 3-595. Function i2c_second_address_disable


Function name i2c_second_address_disable
Function prototype void i2c_second_address_disable(uint32_t i2c_periph);
Function descriptions disable i2c second address in slave mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable i2c second address in slave mode */

i2c_second_address_disable (I2C2);

i2c_recevied_address_get

The description of i2c_recevied_address_get is shown as below:

Table 3-596. Function i2c_recevied_address_get


Function name i2c_recevied_address_get
Function prototype uint32_t i2c_recevied_address_get(uint32_t i2c_periph);

438
GD32E50x Firmware Library User Guide
Function descriptions get received match address in slave mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
uint32_t 0x00..0x7F

Example:

/* get received match address in slave mode */

uint32_t address;

address = i2c_recevied_address_get (I2C2);

i2c_slave_byte_control_enable

The description of i2c_slave_byte_control_enable is shown as below:

Table 3-597. Function i2c_slave_byte_control_enable


Function name i2c_slave_byte_control_enable
Function prototype void i2c_slave_byte_control_enable(uint32_t i2c_periph);
Function descriptions enable slave byte control
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable slave byte control */

i2c_slave_byte_control_enable (I2C2);

i2c_slave_byte_control_disable

The description of i2c_slave_byte_control_disable is shown as below:

439
GD32E50x Firmware Library User Guide
Table 3-598. Function i2c_slave_byte_control_disable
Function name i2c_slave_byte_control_disable
Function prototype void i2c_slave_byte_control_disable(uint32_t i2c_periph);
Function descriptions disable slave byte control
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable slave byte control */

i2c_slave_byte_control_disable (I2C2);

i2c_nack_enable

The description of i2c_nack_enable is shown as below:

Table 3-599. Function i2c_nack_enable


Function name i2c_nack_enable
Function prototype void i2c_nack_enable(uint32_t i2c_periph);
Function descriptions generate a NACK in slave mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* generate a NACK in slave mode */

i2c_nack_enable (I2C2);

i2c_nack_disable

The description of i2c_nack_disable is shown as below:

440
GD32E50x Firmware Library User Guide
Table 3-600. Function i2c_nack_disable
Function name i2c_nack_disable
Function prototype void i2c_nack_disable(uint32_t i2c_periph);
Function descriptions generate a ACK in slave mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* generate a ACK in slave mode */

i2c_nack_disable (I2C2);

i2c_reload_enable

The description of i2c_reload_enable is shown as below:

Table 3-601. Function i2c_reload_enable


Function name i2c_reload_enable
Function prototype void i2c_reload_enable(uint32_t i2c_periph);
Function descriptions enable I2C reload mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C reload mode */

i2c_reload_enable (I2C2);

i2c_reload_disable

The description of i2c_reload_disable is shown as below:

441
GD32E50x Firmware Library User Guide
Table 3-602. Function i2c_reload_disable
Function name i2c_reload_disable
Function prototype void i2c_reload_disable(uint32_t i2c_periph);
Function descriptions disable I2C reload mode
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* disable I2C reload mode */

i2c_reload_disable (I2C2);

i2c_transfer_byte_number_config

The description of i2c_transfer_byte_number_config is shown as below:

Table 3-603. Function i2c_transfer_byte_number_config


Function name i2c_transfer_byte_number_config
void i2c_transfer_byte_number_config(uint32_t i2c_periph, uint32_t
Function prototype
byte_number);
Function descriptions configure number of bytes to be transferred
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
byte_number 0x0-0xFF, number of bytes to be transferred
Output parameter{out}
- -
Return value
- -

Example:

/* configure number of bytes to be transferred */

i2c_transfer_byte_number_config (I2C2, 0xFF);

442
GD32E50x Firmware Library User Guide
i2c2_dma_enable

The description of i2c2_dma_enable is shown as below:

Table 3-604. Function i2c2_dma_enable


Function name i2c2_dma_enable
Function prototype void i2c2_dma_enable(uint32_t i2c_periph, uint8_t dma);
Function descriptions enable I2C DMA for transmission or reception
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
dma I2C DMA
I2C2_DMA_TRANSMIT transmit data using DMA
I2C2_DMA_RECEIVE receive data using DMA
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C DMA for transmission or reception */

i2c2_dma_enable (I2C2, I2C2_DMA_RECEIVE);

i2c2_dma_disable

The description of i2c2_dma_disable is shown as below:

Table 3-605. Function i2c2_dma_disable


Function name i2c2_dma_disable
Function prototype void i2c2_dma_disable(uint32_t i2c_periph, uint8_t dma);
Function descriptions disable I2C DMA for transmission or reception
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
dma I2C DMA
I2C2_DMA_TRANSMIT transmit data using DMA
I2C2_DMA_RECEIVE receive data using DMA
Output parameter{out}

443
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* disable I2C DMA for transmission or reception */

i2c2_dma_disable (I2C2, I2C2_DMA_RECEIVE);

i2c_smbus_alert_enable

The description of i2c_smbus_alert_enable is shown as below:

Table 3-606. Function i2c_smbus_alert_enable


Function name i2c_smbus_alert_enable
Function prototype void i2c_smbus_alert_enable(uint32_t i2c_periph);
Function descriptions enable SMBus Alert
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable SMBus Alert */

i2c_smbus_alert_enable (I2C2);

i2c_smbus_alert_disable

The description of i2c_smbus_alert_disable is shown as below:

Table 3-607. Function i2c_smbus_alert_disable


Function name i2c_smbus_alert_disable
Function prototype void i2c_smbus_alert_disable(uint32_t i2c_periph);
Function descriptions disable SMBus Alert
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
444
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* disable SMBus Alert */

i2c_smbus_alert_disable (I2C2);

i2c_smbus_default_addr_enable

The description of i2c_smbus_default_addr_enable is shown as below:

Table 3-608. Function i2c_smbus_default_addr_enable


Function name i2c_smbus_default_addr_enable
Function prototype void i2c_smbus_default_addr_enable(uint32_t i2c_periph);
Function descriptions enable SMBus device default address
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable SMBus device default address */

i2c_smbus_default_addr_enable (I2C2);

i2c_smbus_default_addr_disable

The description of i2c_smbus_default_addr_disable is shown as below:

Table 3-609. Function i2c_smbus_default_addr_disable


Function name i2c_smbus_default_addr_disable
Function prototype void i2c_smbus_default_addr_disable(uint32_t i2c_periph);
Function descriptions disable SMBus device default address
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
445
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* disable SMBus device default address */

i2c_smbus_default_addr_disable (I2C2);

i2c_smbus_host_addr_enable

The description of i2c_smbus_host_addr_enable is shown as below:

Table 3-610. Function i2c_smbus_host_addr_enable


Function name i2c_smbus_host_addr_enable
Function prototype void i2c_smbus_host_addr_enable(uint32_t i2c_periph);
Function descriptions enable SMBus Host address
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable SMBus Host address */

i2c_smbus_host_addr_enable (I2C2);

i2c_smbus_host_addr_disable

The description of i2c_smbus_host_addr_disable is shown as below:

Table 3-611. Function i2c_smbus_host_addr_disable


Function name i2c_smbus_host_addr_disable
Function prototype void i2c_smbus_host_addr_disable(uint32_t i2c_periph);
Function descriptions disable SMBus Host address
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
446
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* disable SMBus Host address */

i2c_smbus_host_addr_disable (I2C2);

i2c_extented_clock_timeout_enable

The description of i2c_extented_clock_timeout_enable is shown as below:

Table 3-612. Function i2c_extented_clock_timeout_enable


Function name i2c_extented_clock_timeout_enable
Function prototype void i2c_extented_clock_timeout_enable(uint32_t i2c_periph);
Function descriptions enable extended clock timeout detection
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable extended clock timeout detection */

i2c_extented_clock_timeout_enable (I2C2);

i2c_extented_clock_timeout_disable

The description of i2c_extented_clock_timeout_disable is shown as below:

Table 3-613. Function i2c_extented_clock_timeout_disable


Function name i2c_extented_clock_timeout_disable
Function prototype void i2c_extented_clock_timeout_disable(uint32_t i2c_periph);
Function descriptions disable extended clock timeout detection
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
447
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* disable extended clock timeout detection */

i2c_extented_clock_timeout_disable (I2C2);

i2c_clock_timeout_enable

The description of i2c_clock_timeout_enable is shown as below:

Table 3-614. Function i2c_clock_timeout_enable


Function name i2c_clock_timeout_enable
Function prototype void i2c_clock_timeout_enable(uint32_t i2c_periph);
Function descriptions enable clock timeout detection
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
- -
Return value
- -

Example:

/* enable clock timeout detection */

i2c_clock_timeout_enable (I2C2);

i2c_clock_timeout_disable

The description of i2c_clock_timeout_disable is shown as below:

Table 3-615. Function i2c_clock_timeout_disable


Function name i2c_clock_timeout_disable
Function prototype void i2c_clock_timeout_disable(uint32_t i2c_periph);
Function descriptions disable clock timeout detection
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Output parameter{out}
448
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* disable clock timeout detection */

i2c_clock_timeout_disable (I2C2);

i2c_bus_timeout_b_config

The description of i2c_bus_timeout_b_config is shown as below:

Table 3-616. Function i2c_bus_timeout_b_config


Function name i2c_bus_timeout_b_config
Function prototype void i2c_bus_timeout_b_config(uint32_t i2c_periph, uint32_t timeout);
Function descriptions configure bus timeout B
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
timeout 0-0xfff, bus timeout B
Output parameter{out}
- -
Return value
- -

Example:

/* configure bus timeout B */

i2c_bus_timeout_b_config (I2C2, 0xff);

i2c_bus_timeout_a_config

The description of i2c_bus_timeout_a_config is shown as below:

Table 3-617. Function i2c_bus_timeout_a_config


Function name i2c_bus_timeout_a_config
Function prototype void i2c_bus_timeout_a_config(uint32_t i2c_periph, uint32_t timeout);
Function descriptions configure bus timeout A
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
449
GD32E50x Firmware Library User Guide
I2Cx (x=2)
Input parameter{in}
timeout 0-0xfff, bus timeout A
Output parameter{out}
- -
Return value
- -

Example:

/* configure bus timeout A */

i2c_bus_timeout_a_config (I2C2, 0xff);

i2c_idle_clock_timeout_config

The description of i2c_idle_clock_timeout_config is shown as below:

Table 3-618. Function i2c_idle_clock_timeout_config


Function name i2c_idle_clock_timeout_config
Function prototype void i2c_idle_clock_timeout_config(uint32_t i2c_periph, uint32_t timeout);
Function descriptions configure idle clock timeout detection
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
timeout bus timeout A
BUSTOA_DETECT_SC
BUSTOA is used to detect SCL low timeout
L_LOW
BUSTOA_DETECT_ID BUSTOA is used to detect both SCL and SDA high timeout when the bus is
LE idle
Output parameter{out}
- -
Return value
- -

Example:

/* configure idle clock timeout detection */

i2c_idle_clock_timeout_config (I2C2, BUSTOA_DETECT_SCL_LOW);

i2c2_flag_get

The description of i2c2_flag_get is shown as below:

450
GD32E50x Firmware Library User Guide
Table 3-619. Function i2c2_flag_get
Function name i2c2_flag_get
Function prototype FlagStatus i2c2_flag_get(uint32_t i2c_periph, uint32_t flag);
Function descriptions get I2C flag status
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
flag I2C flags
I2C2_FLAG_TBE I2C2_TDATA is empty during transmitting
I2C2_FLAG_TI transmit interrupt
I2C2_FLAG_RBNE I2C2_RDATA is not empty during receiving
I2C2_FLAG_ADDSEND address received matches in slave mode
I2C2_FLAG_NACK not acknowledge flag
I2C2_FLAG_STPDET STOP condition detected in slave mode
I2C2_FLAG_TC transfer complete in master mode
I2C2_FLAG_TCR transfer complete reload
I2C2_FLAG_BERR bus error
I2C2_FLAG_LOSTARB arbitration Lost
I2C2_FLAG_OUERR overrun/underrun error in slave mode
I2C2_FLAG_PECERR PEC error
I2C2_FLAG_TIMEOUT timeout flag
I2C2_FLAG_SMBALT SMBus Alert
I2C2_FLAG_I2CBSY busy flag
I2C2_FLAG_TR whether the I2C is a transmitter or a receiver in slave mode
Output parameter{out}
- -
Return value
FlagStatus SET / RESET

Example:

/* get I2C flag status */

FlagStatus flag_state = RESET;

flag_state = i2c2_flag_get (I2C2, I2C2_FLAG_TBE);

i2c2_flag_clear

The description of i2c2_flag_clear is shown as below:

Table 3-620. Function i2c2_flag_clear


Function name i2c2_flag_clear
451
GD32E50x Firmware Library User Guide
Function prototype void i2c2_flag_clear(uint32_t i2c_periph, uint32_t flag);
Function descriptions clear I2C flag status
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
flag I2C flags
I2C2_FLAG_ADDSEND address received matches in slave mode
I2C2_FLAG_NACK not acknowledge flag
I2C2_FLAG_STPDET STOP condition detected in slave mode
I2C2_FLAG_BERR bus error
I2C2_FLAG_LOSTARB arbitration Lost
I2C2_FLAG_OUERR overrun/underrun error in slave mode
I2C2_FLAG_PECERR PEC error
I2C2_FLAG_TIMEOUT timeout flag
I2C2_FLAG_SMBALT SMBus Alert
Output parameter{out}
- -
Return value
- -

Example:

/* clear a bus error flag*/

i2c2_flag_clear (I2C2, I2C2_FLAG_BERR);

i2c2_interrupt_enable

The description of i2c2_interrupt_enable is shown as below:

Table 3-621. Function i2c2_interrupt_enable


Function name i2c2_interrupt_enable
Function prototype void i2c2_interrupt_enable(uint32_t i2c_periph, uint32_t interrupt);
Function descriptions enable I2C interrupt
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
interrupt I2C interrupts
I2C2_INT_ERR error interrupt

452
GD32E50x Firmware Library User Guide
I2C2_INT_TC transfer complete interrupt
I2C2_INT_STPDET stop detection interrupt
I2C2_INT_NACK not acknowledge received interrupt
I2C2_INT_ADDM address match interrupt
I2C2_INT_RBNE receive interrupt
I2C2_INT_TI transmit interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2C2 transmit interrupt */

i2c2_interrupt_enable (I2C2, I2C2_INT_TI);

i2c2_interrupt_disable

The description of i2c2_interrupt_disable is shown as below:

Table 3-622. Function i2c2_interrupt_disable


Function name i2c2_interrupt_disable
Function prototype void i2c2_interrupt_disable(uint32_t i2c_periph, uint32_t interrupt);
Function descriptions disable I2C interrupt
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
interrupt I2C interrupts
I2C2_INT_ERR error interrupt
I2C2_INT_TC transfer complete interrupt
I2C2_INT_STPDET stop detection interrupt
I2C2_INT_NACK not acknowledge received interrupt
I2C2_INT_ADDM address match interrupt
I2C2_INT_RBNE receive interrupt
I2C2_INT_TI transmit interrupt
Output parameter{out}
- -
Return value
- -

Example:

453
GD32E50x Firmware Library User Guide
/* disable I2C2 transmit interrupt */

i2c2_interrupt_disable (I2C2, I2C2_INT_TI);

i2c2_interrupt_flag_get

The description of i2c2_interrupt_flag_get is shown as below:

Table 3-623. Function i2c2_interrupt_flag_get


Function name i2c2_interrupt_flag_get
FlagStatus i2c2_interrupt_flag_get(uint32_t i2c_periph,
Function prototype
i2c_interrupt_flag_enum int_flag);
Function descriptions get I2C interrupt flag status
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
int_flag I2C interrupt flags, refer to Enum i2c2_interrupt_flag_enum.
I2C2_INT_FLAG_TI transmit interrupt flag
I2C2_INT_FLAG_RBN
I2C2_RDATA is not empty during receiving interrupt flag
E
I2C2_INT_FLAG_ADD
address received matches in slave mode interrupt flag
SEND
I2C2_INT_FLAG_NAC
not acknowledge interrupt flag
K
I2C2_INT_FLAG_STPD
stop condition detected in slave mode interrupt flag
ET
I2C2_INT_FLAG_TC transfer complete in master mode interrupt flag
I2C2_INT_FLAG_TCR transfer complete reload interrupt flag
I2C2_INT_FLAG_BER
bus error interrupt flag
R
I2C2_INT_FLAG_LOST
arbitration lost interrupt flag
ARB
I2C2_INT_FLAG_OUE
overrun/underrun error in slave mode interrupt flag
RR
I2C2_INT_FLAG_PECE
PEC error interrupt flag
RR
I2C2_INT_FLAG_TIME
timeout interrupt flag
OUT
I2C2_INT_FLAG_SMB
SMBus Alert interrupt flag
ALT
Output parameter{out}

454
GD32E50x Firmware Library User Guide
- -
Return value
FlagStatus SET / RESET

Example:

/* get I2C interrupt flag status */

FlagStatus flag_state = RESET;

flag_state = i2c2_interrupt_flag_get (I2C2, I2C2_INT_FLAG_TI);

i2c2_interrupt_flag_clear

The description of i2c2_interrupt_flag_clear is shown as below:

Table 3-624. Function i2c2_interrupt_flag_clear


Function name i2c2_interrupt_flag_clear
void i2c2_interrupt_flag_clear(uint32_t i2c_periph, i2c_interrupt_flag_enum
Function prototype
int_flag);
Function descriptions clear I2C interrupt flag status
Precondition -
The called functions -
Input parameter{in}
i2c_periph I2C peripheral
I2Cx (x=2)
Input parameter{in}
int_flag I2C interrupt flags, refer to Enum i2c2_interrupt_flag_enum.
I2C2_INT_FLAG_ADD
address received matches in slave mode interrupt flag
SEND
I2C2_INT_FLAG_NAC
not acknowledge interrupt flag
K
I2C2_INT_FLAG_STPD
stop condition detected in slave mode interrupt flag
ET
I2C2_INT_FLAG_BER
bus error interrupt flag
R
I2C2_INT_FLAG_LOST
arbitration lost interrupt flag
ARB
I2C2_INT_FLAG_OUE
overrun/underrun error in slave mode interrupt flag
RR
I2C2_INT_FLAG_PECE
PEC error interrupt flag
RR
I2C2_INT_FLAG_TIME
timeout interrupt flag
OUT
I2C2_INT_FLAG_SMB
SMBus Alert interrupt flag
ALT

455
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* clear a bus error flag */

i2c2_interrupt_flag_clear (I2C2, I2C2_INT_FLAG_BERR);

3.18. MISC

MISC is a software package that provide the interfaces for NVIC and SysTick.The NVIC and
SysTick registers are listed in chapter 3.18.1, the MISC firmware functions are introduced in
chapter 3.18.2.

3.18.1. Descriptions of Peripheral registers

Table 3-625. NVIC Registers


Registers Descriptions
ISER(1) Interrupt Set Enable Register
ICER(1) Interrupt Clear Enable Register
(1)
ISPR Interrupt Set Pending Register
ICPR(1) Interrupt Clear Pending Register
IABR(1) Interrupt Active bit Register
ITNS(1) Interrupt Non-Secure State Register
IPR(1) Interrupt Priority Register
STIR(1) Software Trigger Interrupt Register
CPUID(2) CPUID Base Register
ICSR(2) Interrupt Control and State Register
VTOR(2) Vector Table Offset Register
AIRCR(2) Application Interrupt and Reset Control Register
SCR(2) System Control Register
(2)
CCR Configuration Control Register
SHPR(2) System Handlers Priority Registers
SHCSR(2) System Handler Control and State Register
1. refer to the structure NVIC_Type, is defined in the core_cm33.h file
2. refer to the structure SCB_Type, is defined in the core_cm33.h file

Table 3-626. SysTick Registers


Registers Descriptions
CTRL(1) SysTick Control and Status Register
LOAD(1) SysTick Reload Value Register

456
GD32E50x Firmware Library User Guide
Registers Descriptions
VAL(1) SysTick Current Value Register
CALIB(1) SysTick Calibration Register
1. refer to the structure SysTick_Type, is defined in the core_cm33.h file

3.18.2. Descriptions of Peripheral functions


MISC firmware functions are listed in the table shown as below:

Table 3-627. MISC firmware function


Function name Function description
nvic_priority_group_set set the priority group
nvic_irq_enable enable NVIC interrupt request
nvic_irq_disable disable NVIC interrupt request
nvic_system_reset initiates a system reset request to reset the MCU
nvic_vector_table_set set the NVIC vector table address
system_lowpower_set set the state of the low power mode
system_lowpower_reset reset the state of the low power mode
systick_clksource_set set the systick clock source

Enum IRQn_Type

Table 3-628. IRQn_Type


Member name Function description
WWDGT_IRQn window watchDog timer interrupt
LVD_IRQn LVD through EXTI line detect interrupt
TAMPER_IRQn tamper through EXTI line detect
RTC_IRQn RTC through EXTI line interrupt
FMC_IRQn FMC interrupt
RCU_CTC_IRQn RCU and CTC interrupt
EXTI0_IRQn EXTI line 0 interrupts
EXTI1_IRQn EXTI line 1 interrupts
EXTI2_IRQn EXTI line 2 interrupts
EXTI3_IRQn EXTI line 3 interrupts
EXTI4_IRQn EXTI line 4 interrupts
DMA0_Channel0_IRQn DMA0 channel0 interrupt
DMA0_Channel1_IRQn DMA0 channel1 interrupt
DMA0_Channel2_IRQn DMA0 channel2 interrupt
DMA0_Channel3_IRQn DMA0 channel3 interrupt
DMA0_Channel4_IRQn DMA0 channel4 interrupt
DMA0_Channel5_IRQn DMA0 channel5 interrupt
DMA0_Channe6_IRQn DMA0 channel6 interrupt
ADC0_1_IRQn ADC0 and ADC1 interrupt
USBD_HP_IRQn USBD High Priority interrupt
457
GD32E50x Firmware Library User Guide
Member name Function description
USBD_LP_IRQn USBD Low Priority interrupt
EXTI5_9_IRQn EXTI[9:5] interrupts
TIMER0_BRK_TIMER8_IRQn TIMER0 break and TIMER8 interrupts
TIMER0_UP_TIMER9_IRQn TIMER0 update and TIMER9 interrupts
TIMER0_TRG_CMT_TIMER10_IRQn TIMER0 trigger and commutation and TIMER10 interrupts
TIMER0_Channel_IRQn TIMER0 channel capture compare interrupt
TIMER1_IRQn TIMER1 interrupt
TIMER2_IRQn TIMER2 interrupt
TIMER3_IRQn TIMER3 interrupt
I2C0_EV_IRQn I2C0 event interrupt
I2C0_ER_IRQn I2C0 error interrupt
I2C1_EV_IRQn I2C1 event interrupt
I2C1_ER_IRQn I2C1 error interrupt
SPI0_IRQn SPI0 interrupt
SPI1_I2S1ADD_IRQn SPI1 or I2S1ADD interrupt
USART0_IRQn USART0 interrupt
USART1_IRQn USART1 interrupt
USART2_IRQn USART2 interrupt
EXTI10_15_IRQn EXTI[15:10] interrupts
RTC_Alarm_IRQn RTC alarm interrupt
USBD_WKUP_IRQn /
USBD / USBHS wakeup interrupt
USBHS_WKUP_IRQn
TIMER7_BRK_TIMER11_IRQn TIMER7 break and TIMER11 interrupts
TIMER7_UP_TIMER12_IRQn TIMER7 update and TIMER12 interrupts
TIMER7_TRG_CMT_TIMER13_IRQn TIMER7 trigger and commutation and TIMER13 interrupts
TIMER7_Channel_IRQn TIMER7 channel capture compare interrupt
EXMC_IRQn EXMC global interrupt
SDIO_IRQn SDIO global interrupt
TIMER4_IRQn TIMER4 global interrupt
SPI2_I2S2ADD_IRQn SPI2 or I2S2ADD global interrupt
UART3_IRQn UART3 global interrupt
UART4_IRQn UART4 global interrupt
TIMER5_DAC_IRQn TIMER5 or DAC global interrupt
TIMER6_IRQn TIMER6 global interrupt
DMA1_Channel0_IRQn DMA1 channel0 global interrupt
DMA1_Channel1_IRQn DMA1 channel1 global interrupt
DMA1_Channel2_IRQn DMA1 channel2 global interrupt
DMA1_Channel3_Channel4_IRQn / DMA1 channel3 and channel4 global interrupt /
DMA1_Channel3_IRQn DMA1 channel3 global interrupt
DMA1_Channel4_IRQn DMA1 channel4 global interrupt
ENET_IRQn ENET global interrupt

458
GD32E50x Firmware Library User Guide
Member name Function description
ENET_WKUP_IRQn ENET wakeup interrupt
USBHS_IRQn USBHS global interrupt
SHRTIMER_IRQ2_IRQn SHRTIMER_IRQ2 interrupt
SHRTIMER_IRQ3_IRQn SHRTIMER_IRQ3 interrupt
SHRTIMER_IRQ4_IRQn SHRTIMER_IRQ4 interrupt
SHRTIMER_IRQ5_IRQn SHRTIMER_IRQ5 interrupt
SHRTIMER_IRQ6_IRQn SHRTIMER_IRQ6 interrupt
USBHS_EP1_OUT_IRQn USBHS end point 1 out interrupt
USBHS_EP1_IN_IRQn USBHS end point 1 in interrupt
SHRTIMER_IRQ0_IRQn SHRTIMER_IRQ0 interrupt
SHRTIMER_IRQ1_IRQn SHRTIMER_IRQ1 interrupt
I2C2_EV_IRQn I2C2 EV interrupt
I2C2_ER_IRQn I2C2 ER interrupt
USART5_IRQn USART5 global interrupt
I2C2_WKUP_IRQn I2C2 Wakeup interrupt
USART5_WKUP_IRQn USART5 Wakeup interrupt
TMU_IRQn TMU interrupt

nvic_priority_group_set

The description of nvic_priority_group_set is shown as below:

Table 3-629. Function nvic_priority_group_set


Function name nvic_priority_group_set
Function prototype void nvic_priority_group_set(uint32_t nvic_prigroup);
Function descriptions configure bits length of the priority group
Precondition -
The called functions -
Input parameter{in}
nvic_prigroup priority group
NVIC_PRIGROUP_PR
0 bits for pre-emption priority 4 bits for subpriority
E0_SUB4
NVIC_PRIGROUP_PR
1 bits for pre-emption priority 3 bits for subpriority
E1_SUB3
NVIC_PRIGROUP_PR
2 bits for pre-emption priority 2 bits for subpriority
E2_SUB2
NVIC_PRIGROUP_PR
3 bits for pre-emption priority 1 bits for subpriority
E3_SUB1
NVIC_PRIGROUP_PR
4 bits for pre-emption priority 0 bits for subpriority
E4_SUB0
Output parameter{out}
- -

459
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* priority group configuration, 0 bits for pre-emption priority 4 bits for subpriority */

nvic_priority_group_set(NVIC_PRIGROUP_PRE0_SUB4);

nvic_irq_enable

The description of nvic_irq_enable is shown as below:

Table 3-630. Function nvic_irq_enable


Function name nvic_irq_enable
void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_pre_priority, uint8_t
Function prototype
nvic_irq_sub_priority);
Function descriptions enable NVIC request, configure the priority of interrupt
Precondition -
The called functions nvic_priority_group_set
Input parameter{in}
NVIC interrupt, refer to MISC firmware functions are listed in the table
shown as below:
Table 3-627. MISC firmware function
Function name Function descrip
nvic_priority_group_set set the priority gr
nvic_irq_enable enable NVIC interrupt
nvic_irq nvic_irq_disable disable NVIC interrup
nvic_system_reset initiates a system reset request
nvic_vector_table_set set the NVIC vector tab
system_lowpower_set set the state of the low p
system_lowpower_reset reset the state of the low
systick_clksource_set set the systick clock
Enum IRQn_Type
Input parameter{in}
nvic_irq_pre_priority the pre-emption priority needed to set (0~4)
Input parameter{in}
nvic_irq_sub_priority the subpriority needed to set (0~4)
Output parameter{out}
- -
Return value
- -

Example:

/* enable window watchDog timer interrupt , pre-emption priority is 1, subpriority is 1 */

460
GD32E50x Firmware Library User Guide
nvic_irq_enable(WWDGT_IRQn, 1, 1);

nvic_irq_disable

The description of nvic_irq_disable is shown as below:

Table 3-631. Function nvic_irq_disable


Function name nvic_irq_disable
Function prototype void nvic_irq_disable(uint8_t nvic_irq);
Function descriptions disable NVIC request
Precondition -
The called functions -
Input parameter{in}
NVIC interrupt, refer to Enum IRQn_Type.
nvic_irq

Output parameter{out}
- -
Return value
- -

Example:

/* disable window watchDog timer interrupt */


nvic_irq_disable(WWDGT_IRQn);

nvic_system_reset

The description of nvic_system_reset is shown as below:

Table 3-632. Function nvic_system_reset


Function name nvic_system_reset
Function prototype void nvic_system_reset(void);
Function descriptions initiates a system reset request to reset the MCU
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* initiates a system reset request to reset the MCU */


nvic_system_reset();

461
GD32E50x Firmware Library User Guide
nvic_vector_table_set

The description of nvic_vector_table_set is shown as below:

Table 3-633. Function nvic_vector_table_set


Function name nvic_vector_table_set
Function prototype void nvic_vector_table_set(uint32_t nvic_vict_tab, uint32_t offset);
Function descriptions set the NVIC vector table address
Precondition -
The called functions -
Input parameter{in}
nvic_vict_tab the RAM or FLASH base address
NVIC_VECTTAB_RAM RAM base address
NVIC_VECTTAB_FLAS
Flash base address
H
Input parameter{in}
offset Vector Table offset (vector table start address= base address+offset)
Output parameter{out}
- -
Return value
- -

Example:

/* set vector table address = NVIC_VECTTAB_FLASH +0x200 */


nvic_vector_table_set (NVIC_VECTTAB_FLASH,0x200);

system_lowpower_set

The description of system_lowpower_set is shown as below:

Table 3-634. Function system_lowpower_set


Function name system_lowpower_set
Function prototype void system_lowpower_set(uint8_t lowpower_mode);
Function descriptions the state of the low power mode management
Precondition -
The called functions -
Input parameter{in}
lowpower_mode the low power mode state
SCB_LPM_SLEEP_EXI if chose this para, the system always enter low power mode by exiting from
T_ISR ISR
SCB_LPM_DEEPSLEE if chose this para, the system will enter the DEEPSLEEP mode
P
SCB_LPM_WAKE_BY_ if chose this para, the lowpower mode can be woke up by all the enable and
ALL_INT disable interrupts

462
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* the system always enter low power mode by exiting from ISR */
system_lowpower_set (SCB_LPM_SLEEP_EXIT_ISR);

system_lowpower_reset

The description of system_lowpower_reset is shown as below:

Table 3-635. Function system_lowpower_reset


Function name system_lowpower_reset
Function prototype void system_lowpower_reset(uint8_t lowpower_mode);
Function descriptions the state of the low power mode management
Precondition -
The called functions -
Input parameter{in}
lowpower_mode the low power mode state
SCB_LPM_SLEEP_EXI if chose this para, the system will exit low power mode by exiting from ISR
T_ISR
SCB_LPM_DEEPSLEE if chose this para, the system will enter the SLEEP mode
P
SCB_LPM_WAKE_BY_ if chose this para, the lowpower mode only can be woke up by the enable
ALL_INT interrupts
Output parameter{out}
- -
Return value
- -

Example:

/* the system will exit low power mode by exiting from ISR */
system_lowpower_reset (SCB_LPM_SLEEP_EXIT_ISR);

systick_clksource_set

The description of systick_clksource_set is shown as below:

Table 3-636. Function systick_clksource_set


Function name systick_clksource_set
Function prototype void systick_clksource_set(uint32_t systick_clksource);
Function descriptions set the systick clock source
Precondition -
463
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
systick_clksource the systick clock source needed to choose
SYSTICK_CLKSOURC systick clock source is from HCLK
E_HCLK
SYSTICK_CLKSOURC systick clock source is from HCLK/8
E_HCLK_DIV8
Output parameter{out}
- -
Return value
- -

Example:

/* systick clock source is HCLK/8 */

systick_clksource_set (SYSTICK_CLKSOURCE_HCLK_DIV8);

3.19. PMU

According to the Power management unit (PMU), provides five types of power saving modes,
including Sleep, Deep-sleep, Deep-sleep 1, Deep-sleep 2 and Standby mode. The PMU
registers are listed in chapter 3.19.1, the PMU firmware functions are introduced in chapter
3.19.2.

3.19.1. Descriptions of Peripheral registers


PMU registers are listed in the table shown as below:

Table 3-637. PMU Registers


Registers Descriptions
PMU_CTL0 Control register 0
PMU_CS0 Control and status register 0
PMU_CTL1 Control register 1
PMU_CS1 Control and status register 1

3.19.2. Descriptions of Peripheral functions


PMU firmware functions are listed in the table shown as below:

Table 3-638. PMU firmware function


Function name Function description
pmu_deinit deinitialize the PMU
pmu_lvd_select select low voltage detector threshold
pmu_lvd_disable disable PMU lvd

464
GD32E50x Firmware Library User Guide
Function name Function description
pmu_highdriver_mode_enable enable high-driver mode
pmu_highdriver_mode_disable disable high-driver mode
pmu_highdriver_switch_select switch high-driver mode
pmu_lowdriver_mode_enable enable low-driver mode in deep-sleep mode
pmu_lowdriver_mode_disable disable low-driver mode in deep-sleep mode
pmu_lowpower_driver_config in deep-sleep mode, driver mode when use low power LDO
in deep-sleep mode, driver mode when use normal power
pmu_normalpower_driver_config
LDO
pmu_to_sleepmode PMU work at sleep mode
pmu_to_deepsleepmode PMU work at deepsleep mode
pmu_to_deepsleepmode_1 PMU work at deepsleep mode 1
pmu_to_deepsleepmode_2 PMU work at deepsleep mode 2
pmu_to_standbymode pmu work at standby mode
pmu_wakeup_pin_enable enable wakeup pin
pmu_wakeup_pin_disable disable wakeup pin
pmu_backup_write_enable enable backup domain write
pmu_backup_write_disable disable backup domain write
pmu_flag_clear clear flag bit
pmu_flag_get get flag state

pmu_deinit

The description of pmu_deinit is shown as below:

Table 3-639. Function pmu_deinit


Function name pmu_deinit
Function prototype void pmu_deinit(void);
Function descriptions deinitialize the PMU
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset PMU */

pmu_deinit ();

465
GD32E50x Firmware Library User Guide
pmu_lvd_select

The description of pmu_lvd_select is shown as below:

Table 3-640. Function pmu_lvd_select


Function name pmu_lvd_select
Function prototype void pmu_lvd_select(uint32_t lvdt_n);
Function descriptions select low voltage detector threshold
Precondition -
The called functions -
Input parameter{in}
lvdt_n voltage threshold value
PMU_LVDT_0 voltage threshold is 2.1V
PMU_LVDT_1 voltage threshold is 2.3V
PMU_LVDT_2 voltage threshold is 2.4V
PMU_LVDT_3 voltage threshold is 2.6V
PMU_LVDT_4 voltage threshold is 2.7V
PMU_LVDT_5 voltage threshold is 2.9V
PMU_LVDT_6 voltage threshold is 3.0V
PMU_LVDT_7 voltage threshold is 3.1V
Output parameter{out}
- -
Return value
- -

Example:

/* select low voltage detector threshold as 3.1V */

pmu_lvd_select (PMU_LVDT_7);

pmu_lvd_disable

The description of pmu_lvd_disable is shown as below:

Table 3-641. Function pmu_lvd_disable


Function name pmu_lvd_disable
Function prototype void pmu_lvd_disable (void);
Function descriptions disable PMU lvd
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value

466
GD32E50x Firmware Library User Guide
- -

Example:

/* disable PMU lvd */

pmu_lvd_disable ();

pmu_highdriver_mode_enable

The description of pmu_highdriver_mode_enable is shown as below:

Table 3-642. Function pmu_highdriver_mode_enable


Function name pmu_highdriver_mode_enable
Function prototype void pmu_highdriver_mode_enable (void);
Function descriptions enable high-driver mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable high-driver mode */

pmu_highdriver_mode_enable ();

pmu_highdriver_mode_disable

The description of pmu_highdriver_mode_disable is shown as below:

Table 3-643. Function pmu_highdriver_mode_disable


Function name pmu_highdriver_mode_disable
Function prototype void pmu_highdriver_mode_disable (void);
Function descriptions disable high-driver mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

467
GD32E50x Firmware Library User Guide
Example:

/* disable high-driver mode */

pmu_highdriver_mode_disable ();

pmu_highdriver_switch_select

The description of pmu_highdriver_switch_select is shown as below:

Table 3-644. Function pmu_highdriver_switch_select


Function name pmu_highdriver_switch_select
Function prototype void pmu_highdriver_switch_select(uint32_t highdr_switch);
Function descriptions switch high-driver mode
Precondition -
The called functions pmu_flag_get()
Input parameter{in}
highdr_switch enable or disable high-driver mode switch
PMU_HIGHDR_SWITC
disable high-driver mode switch
H_NONE
PMU_HIGHDR_SWITC
enable high-driver mode switch
H_EN
Output parameter{out}
- -
Return value
- -

Example:

/* enable high-driver mode switch */

pmu_highdriver_switch_select (PMU_HIGHDR_SWITCH_EN);

pmu_lowdriver_mode_enable

The description of pmu_lowdriver_mode_enable is shown as below:

Table 3-645. Function pmu_lowdriver_mode_enable


Function name pmu_lowdriver_mode_enable
Function prototype void pmu_lowdriver_mode_enable(void);
Function descriptions enable low-driver mode in deep-sleep mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -

468
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* enable low-driver mode in deep-sleep mode */

pmu_lowdriver_mode_enable ();

pmu_lowdriver_mode_disable

The description of pmu_lowdriver_mode_disable is shown as below:

Table 3-646. Function pmu_lowdriver_mode_disable


Function name pmu_lowdriver_mode_disable
Function prototype void pmu_lowdriver_mode_disable (void);
Function descriptions e disable low-driver mode in deep-sleep mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable low-driver mode in deep-sleep mode */

pmu_lowdriver_mode_disable ();

pmu_lowpower_driver_config

The description of pmu_lowpower_driver_config is shown as below:

Table 3-647. Function pmu_lowpower_driver_config


Function name pmu_lowpower_driver_config
Function prototype void pmu_lowpower_driver_config(uint32_t mode);
Function descriptions driver mode when use low power LDO
Precondition -
The called functions -
Input parameter{in}
mode driver mode
PMU_NORMALDR_LO
normal driver when use low power LDO
WPWR
PMU_LOWDR_LOWP
low-driver mode enabled when LDEN is 11 and use low power LDO
WR
469
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* normal driver when use low power LDO */

pmu_lowpower_driver_config (PMU_NORMALDR_LOWPWR);

pmu_normalpower_driver_config

The description of pmu_normalpower_driver_config is shown as below:

Table 3-648. Function pmu_normalpower_driver_config


Function name pmu_normalpower_driver_config
Function prototype void pmu_normalpower_driver_config (uint32_t mode);
Function descriptions driver mode when use normal power LDO
Precondition -
The called functions -
Input parameter{in}
mode driver mode
PMU_NORMALDR_LO
normal driver when use normal power LDO
WPWR
PMU_LOWDR_LOWP
low-driver mode enabled when LDEN is 11 and use normal power LDO
WR
Output parameter{out}
- -
Return value
- -

Example:

/* normal driver when use normal power LDO */

pmu_normalpower_driver_config (PMU_NORMALDR_LOWPWR);

pmu_to_sleepmode

The description of pmu_to_sleepmode is shown as below:

Table 3-649. Function pmu_to_sleepmode


Function name pmu_to_sleepmode
Function prototype void pmu_to_sleepmode(uint8_t sleepmodecmd);
Function descriptions PMU work at sleep mode
Precondition -
The called functions -
470
GD32E50x Firmware Library User Guide
Input parameter{in}
sleepmodecmd command to enter sleep mode
WFI_CMD use WFI command
WFE_CMD use WFE command
Output parameter{out}
- -
Return value
- -

Example:

/* PMU work at sleep mode */

pmu_to_sleepmode (WFI_CMD);

pmu_to_deepsleepmode

The description of pmu_to_deepsleepmode is shown as below:

Table 3-650. Function pmu_to_deepsleepmode


Function name pmu_to_deepsleepmode
Function prototype void pmu_to_deepsleepmode(uint32_t ldo,uint8_t deepsleepmodecmd);
Function descriptions PMU work at deepsleep mode
Precondition -
The called functions -
Input parameter{in}
ldo ldo work mode
PMU_LDO_NORMAL LDO normal work when pmu enter deepsleep mode
PMU_LDO_LOWPOW
LDO work at low power mode when pmu enter deepsleep mode
ER
Input parameter{in}
deepsleepmodecmd command to enter deepsleep mode
WFI_CMD use WFI command
WFE_CMD use WFE command
Output parameter{out}
- -
Return value
- -

Example:

/* PMU work at deepsleep mode */

pmu_to_deepsleepmode (PMU_LDO_NORMAL, WFI_CMD);

471
GD32E50x Firmware Library User Guide
pmu_to_deepsleepmode_1

The description of pmu_to_deepsleepmode_1 is shown as below:

Table 3-651. Function pmu_to_deepsleepmode_1


Function name pmu_to_deepsleepmode_1
Function prototype void pmu_to_deepsleepmode_1(uint32_t ldo,uint8_t deepsleepmode1cmd);
Function descriptions PMU work at deepsleep mode 1
Precondition -
The called functions -
Input parameter{in}
ldo ldo work mode
PMU_LDO_NORMAL LDO normal work when pmu enter deepsleep mode 1
PMU_LDO_LOWPOW
LDO work at low power mode when pmu enter deepsleep mode 1
ER
Input parameter{in}
deepsleepmode1cmd command to enter deepsleep mode 1
WFI_CMD use WFI command
WFE_CMD use WFE command
Output parameter{out}
- -
Return value
- -

Example:

/* PMU work at deepsleep mode 1 */

pmu_to_deepsleepmode_1 (PMU_LDO_NORMAL, WFI_CMD);

pmu_to_deepsleepmode_2

The description of pmu_to_deepsleepmode_2 is shown as below:

Table 3-652. Function pmu_to_deepsleepmode_2


Function name pmu_to_deepsleepmode_2
Function prototype void pmu_to_deepsleepmode_2(uint32_t ldo,uint8_t deepsleepmode2cmd);
Function descriptions PMU work at deepsleep mode 2
Precondition -
The called functions -
Input parameter{in}
ldo ldo work mode
PMU_LDO_NORMAL LDO normal work when pmu enter deepsleep mode 2
PMU_LDO_LOWPOW
LDO work at low power mode when pmu enter deepsleep mode 2
ER
Input parameter{in}

472
GD32E50x Firmware Library User Guide
deepsleepmode2cmd command to enter deepsleep mode 2
WFI_CMD use WFI command
WFE_CMD use WFE command
Output parameter{out}
- -
Return value
- -

Example:

/* PMU work at deepsleep mode 2 */

pmu_to_deepsleepmode_2 (PMU_LDO_NORMAL, WFI_CMD);

pmu_to_standbymode

The description of pmu_to_standbymode is shown as below:

Table 3-653. Function pmu_to_standbymode


Function name pmu_to_standbymode
Function prototype void pmu_to_standbymode(uint8_t standbymodecmd);
Function descriptions pmu work at standby mode
Precondition -
The called functions -
Input parameter{in}
standbymodecmd command to enter standby mode
WFI_CMD use WFI command
WFE_CMD use WFE command
Output parameter{out}
- -
Return value
- -

Example:

/* PMU work at standby mode */

pmu_to_standby (WFI_CMD);

pmu_backup_write_enable

The description of pmu_backup_write_enable is shown as below:

Table 3-654. Function pmu_backup_write_enable


Function name pmu_backup_write_enable
Function prototype void pmu_backup_write_enable (void);
Function descriptions enable backup domain write
Precondition -
473
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable backup domain write */

pmu_backup_write_enable ();

pmu_backup_write_disable

The description of pmu_backup_write_disable is shown as below:

Table 3-655. Function pmu_backup_write_disable


Function name pmu_backup_write_disable
Function prototype void pmu_backup_write_disable (void);
Function descriptions disable backup domain write
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable backup domain write */

pmu_backup_write_disable ();

pmu_wakeup_pin_enable

The description of pmu_wakeup_pin_enable is shown as below:

Table 3-656. Function pmu_wakeup_pin_enable


Function name pmu_wakeup_pin_enable
Function prototype void pmu_wakeup_pin_enable(uint32_t wakeup_pin);
Function descriptions enable wakeup pin
Precondition -
The called functions -
Input parameter{in}
474
GD32E50x Firmware Library User Guide
wakeup_pin the pin to wakeup system
PMU_WAKEUP_PIN0 WKUP Pin 0 (PA0)
PMU_WAKEUP_PIN1 WKUP Pin 1 (PC13)
PMU_WAKEUP_PIN2 WKUP Pin 2 (PE6)
PMU_WAKEUP_PIN3 WKUP Pin 3 (PA2)
PMU_WAKEUP_PIN4 WKUP Pin 4 (PC5)
PMU_WAKEUP_PIN5 WKUP Pin 5 (PB5)
PMU_WAKEUP_PIN6 WKUP Pin 6 (PB15)
PMU_WAKEUP_PIN7 WKUP Pin 7 (PF8)
Output parameter{out}
- -
Return value
- -

Example:

/* enable wakeup pin 0 */

pmu_wakeup_pin_enable (PMU_WAKEUP_PIN0);

pmu_wakeup_pin_disable

The description of pmu_wakeup_pin_disable is shown as below:

Table 3-657. Function pmu_wakeup_pin_disable


Function name pmu_wakeup_pin_disable
Function prototype void pmu_wakeup_pin_disable (uint32_t wakeup_pin);
Function descriptions disable wakeup pin
Precondition -
The called functions -
Input parameter{in}
wakeup_pin the pin to wakeup system
PMU_WAKEUP_PIN0 WKUP Pin 0 (PA0)
PMU_WAKEUP_PIN1 WKUP Pin 1 (PC13)
PMU_WAKEUP_PIN2 WKUP Pin 2 (PE6)
PMU_WAKEUP_PIN3 WKUP Pin 3 (PA2)
PMU_WAKEUP_PIN4 WKUP Pin 4 (PC5)
PMU_WAKEUP_PIN5 WKUP Pin 5 (PB5)
PMU_WAKEUP_PIN6 WKUP Pin 6 (PB15)
PMU_WAKEUP_PIN7 WKUP Pin 7 (PF8)
Output parameter{out}
- -
Return value
- -

Example:
475
GD32E50x Firmware Library User Guide
/* disable wakeup pin 0 */

pmu_wakeup_pin_disable (PMU_WAKEUP_PIN0);

pmu_flag_get

The description of pmu_flag_get is shown as below:

Table 3-658. Function pmu_flag_get


Function name pmu_flag_get
Function prototype FlagStatus pmu_flag_get(uint32_t flag);
Function descriptions get flag state
Precondition -
The called functions -
Input parameter{in}
flag flag
PMU_FLAG_WAKEUP wakeup flag
PMU_FLAG_STANDBY standby flag
PMU_FLAG_LVD low voltage detector status flag
PMU_FLAG_HDRF high-driver ready flag
PMU_FLAG_HDSRF high-driver switch ready flag
PMU_FLAG_LDRF ow-driver mode ready flag
PMU_FLAG_DEEPSLE
deep-sleep 1 mode status flag
EP_1
PMU_FLAG_DEEPSLE
deep-sleep 2 mode status flag
EP_2
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get flag state */

FlagStatus status;

status = pmu_flag_get (PMU_FLAG_WAKEUP);

pmu_flag_clear

The description of pmu_flag_clear is shown as below:

Table 3-659. Function pmu_flag_clear


Function name pmu_flag_clear
Function prototype void pmu_flag_clear(uint32_t flag_reset);
Function descriptions clear flag bit

476
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
flag_reset flag
PMU_FLAG_RESET_
reset wakeup flag
WAKEUP
PMU_FLAG_RESET_S
reset standby flag
TANDBY
PMU_FLAG_RESET_D
reset deep-sleep 1 mode status flag
EEPSLEEP_1
PMU_FLAG_RESET_D
reset deep-sleep 2 mode status flag
EEPSLEEP_2
Output parameter{out}
- -
Return value
- -

Example:

/* clear flag bit */

pmu_flag_clear (PMU_FLAG_RESET_WAKEUP);

3.20. RCU

RCU is the reset and clock unit. Reset Control includes the control of three kinds of reset:
power reset, system reset and backup domain reset. The Clock Control unit provides a range
of frequencies and clock functions. The RCU registers are listed in chapter 3.20.1, the RCU
firmware functions are introduced in chapter 3.20.2.

3.20.1. Descriptions of Peripheral registers

Table 3-660. RCU Registers


Registers Descriptions
RCU_CTL Control register
RCU_CFG0 Clock configuration register 0
RCU_INT Clock interrupt register
RCU_APB2RST APB2 reset register
RCU_APB1RST APB1 reset register
RCU_AHBEN AHB enable register
RCU_APB2EN APB2 enable register
RCU_APB1EN APB1 enable register
RCU_BDCTL Backup domain control register
RCU_RSTSCK Reset source/clock register
477
GD32E50x Firmware Library User Guide
Registers Descriptions
RCU_AHBRST AHB reset register(CL series)
RCU_CFG1 Clock configuration register 1
RCU_DSV Deep-sleep mode voltage register
RCU_ADDCTL Additional clock control register
RCU_ADDCFG Additional clock configuration register
RCU_ADDINT Additional clock interrupt register
RCU_PLLSSCTL PLL clock spread spectrum control register
RCU_CFG2 Clock configuration register 2
RCU_ADDAPB1RST APB1 additional reset register
RCU_ADDAPB1EN APB1 additional enable register

3.20.2. Descriptions of Peripheral functions

Table 3-661. RCU firmware function


Function name Function description
rcu_deinit deinitialize the RCU
rcu_periph_clock_enable enable the peripherals clock
rcu_periph_clock_disable disable the peripherals clock
rcu_periph_clock_sleep_enable enable the peripherals clock when in sleep mode
rcu_periph_clock_sleep_disable disable the peripherals clock when in sleep mode
rcu_periph_reset_enable enable the peripherals reset
rcu_periph_reset_disable disable the peripheral reset
rcu_bkp_reset_enable enable the BKP domain reset
rcu_bkp_reset_disable disable the BKP domain reset
rcu_system_clock_source_config configure the system clock source
rcu_system_clock_source_get get the system clock source
rcu_ahb_clock_config configure the AHB clock prescaler selection
rcu_apb1_clock_config configure the APB1 clock prescaler selection
rcu_apb2_clock_config configure the APB2 clock prescaler selection
rcu_ckout0_config configure the CK_OUT0 clock source
rcu_pll_config configure the main PLL clock
rcu_pllpresel_config configure the PLL clock source preselection
rcu_predv0_config configure the PREDV0 division factor
rcu_predv1_config configure the PREDV1 division factor
rcu_pll1_config configure the PLL1 clock
rcu_pll2_config configure the PLL2 clock
rcu_pllusbpresel_config configure the PLLUSB clock source preselection
configure the PLLUSBPREDV division factor and clock
rcu_pllusbpredv_config
source
rcu_pllusb_config configure the PLLUSB clock
rcu_adc_clock_config configure the ADC prescaler factor

478
GD32E50x Firmware Library User Guide
Function name Function description
rcu_usb_clock_config configure the USB prescaler factor
rcu_rtc_clock_config configure the RTC clock source selection
rcu_shrtimer_clock_config configure the SHRTIMER clock source selection
rcu_usart5_clock_config configure the usart5 clock source selection
rcu_i2c2_clock_config configure the I2C2 clock source selection
rcu_i2s1_clock_config configure the I2S1 clock source selection
rcu_i2s2_clock_config configure the I2S2 clock source selection
rcu_ck48m_clock_config configure the CK48M clock selection
rcu_usbhssel_config configure the USBHSSEL source clock selection
rcu_usbdv_config configure the USBHSDV division factor
rcu_flag_get get the clock stabilization and periphral reset flags
rcu_all_reset_flag_clear clear all the reset flag
rcu_interrupt_flag_get get the clock stabilization interrupt and ckm flags
rcu_interrupt_flag_clear clear the interrupt flags
rcu_interrupt_enable enable the stabilization interrupt
rcu_interrupt_disable disable the stabilization interrupt
rcu_lxtal_drive_capability_config configure the LXTAL drive capability
wait for oscillator stabilization flags is SET or oscillator startup
rcu_osci_stab_wait
is timeout
rcu_osci_on turn on the oscillator
rcu_osci_off turn off the oscillator
rcu_osci_bypass_mode_enable enable the oscillator bypass mode
rcu_osci_bypass_mode_disable disable the oscillator bypass mode
rcu_hxtal_clock_monitor_enable enable the HXTAL clock monitor
rcu_hxtal_clock_monitor_disable disable the HXTAL clock monitor
rcu_irc8m_adjust_value_set set the IRC8M adjust value
rcu_deepsleep_voltage_set set the deep-sleep mode voltage value
rcu_clock_freq_get get the system clock, bus clock frequency

Enum rcu_periph_enum

Table 3-662. Enum rcu_periph_enum


enum name Function description
RCU_DMA0 DMA0 clock
RCU_DMA1 DMA1 clock
RCU_CRC CRC clock
RCU_EXMC EXMC clock
RCU_SDIO SDIO clock(HD、XD series)
RCU_USBHS USBHS clock(only for CL series)
RCU_ULPI ULPI clock(only for CL series)
RCU_ENET ENET clock(only for CL series)
RCU_ENETTX ENETTX clock(only for CL series)

479
GD32E50x Firmware Library User Guide
enum name Function description
RCU_ENETRX ENETRX clock(only for CL series)
RCU_TMU TMU clock(only for CL series)
RCU_SQPI SQPI clock
RCU_TIMER1 TIMER1 clock
RCU_TIMER2 TIMER2 clock
RCU_TIMER3 TIMER3 clock
RCU_TIMER4 TIMER4 clock
RCU_TIMER5 TIMER5 clock
RCU_TIMER6 TIMER6 clock
RCU_TIMER11 TIMER11 clock(XD、CL series)
RCU_TIMER12 TIMER12 clock(XD、CL series)
RCU_TIMER13 TIMER13 clock(XD、CL series)
RCU_WWDGT WWDGT clock
RCU_SPI1 SPI1 clock
RCU_SPI2 SPI2 clock
RCU_USART1 USART1 clock
RCU_USART2 USART2 clock
RCU_UART3 UART3 clock
RCU_UART4 UART4 clock
RCU_I2C0 I2C0 clock
RCU_I2C1 I2C1 clock
RCU_USBD USBD clock(XD、HD series)
RCU_I2C2 I2C2 clock
RCU_BKPI BKPI clock
RCU_PMU PMU clock
RCU_DAC DAC clock
RCU_RTC RTC clock
RCU_CTC CTC clock
RCU_AF alternate function clock
RCU_GPIOA GPIOA clock
RCU_GPIOB GPIOB clock
RCU_GPIOC GPIOC clock
RCU_GPIOD GPIOD clock
RCU_GPIOE GPIOE clock
RCU_GPIOF GPIOF clock
RCU_GPIOG GPIOG clock
RCU_ADC0 ADC0 clock
RCU_ADC1 ADC1 clock
RCU_TIMER0 TIMER0 clock
RCU_SPI0 SPI0 clock
RCU_TIMER7 TIMER7 clock

480
GD32E50x Firmware Library User Guide
enum name Function description
RCU_USART0 USART0 clock
RCU_ADC2 ADC2 clock(XD、HD series)
RCU_TIMER8 TIMER8 clock(XD、CL series)
RCU_TIMER9 TIMER9 clock(XD、CL series)
RCU_TIMER10 TIMER10 clock(XD、CL series)
RCU_SHRTIMER SHRTIMER clock
RCU_USART5 USART5 clock
RCU_CMP CMP clock(only for CL series)

Enum rcu_periph_sleep_enum

Table 3-663. Enum rcu_periph_sleep_enum


enum name Function description
RCU_SRAM_SLP SRAM clock when sleep mode
RCU_FMC_SLP FMC clock when sleep mode

Enum rcu_periph_reset_enum

Table 3-664. Enum rcu_periph_reset_enum


enum name Function description
RCU_USBHSRST USBHS clock reset(only for CL series)
RCU_ENETRST ENET clock reset(only for CL series)
RCU_TMURST TMU clock reset(only for CL series)
RCU_SQPIRST SQPI clock reset
RCU_TIMER1RST TIMER1 clock reset
RCU_TIMER2RST TIMER2 clock reset
RCU_TIMER3RST TIMER3 clock reset
RCU_TIMER4RST TIMER4 clock reset
RCU_TIMER5RST TIMER5 clock reset
RCU_TIMER6RST TIMER6 clock reset
RCU_TIMER11RST TIMER11 clock reset(XD、CL series)
RCU_TIMER12RST TIMER12 clock reset(XD、CL series)
RCU_TIMER13RST TIMER13 clock reset(XD、CL series)
RCU_WWDGTRST WWDGT clock reset
RCU_SPI1RST SPI1 clock reset
RCU_SPI2RST SPI2 clock reset
RCU_USART1RST USART1 clock reset
RCU_USART2RST USART2 clock reset
RCU_UART3RST UART3 clock reset
RCU_USART4RST UART4 clock reset
RCU_I2C0RST I2C0 clock reset
RCU_I2C1RST I2C1 clock reset

481
GD32E50x Firmware Library User Guide
enum name Function description
RCU_USBDRST USBD clock reset(XD、HD series)
RCU_I2C2RST I2C2 clock reset
RCU_BKPIRST BKPI clock reset
RCU_PMURST PMU clock reset
RCU_DACRST DAC clock reset
RCU_CTCRST CTC clock reset
RCU_AFRST alternate function clock reset
RCU_GPIOARST GPIOA clock reset
RCU_GPIOBRST GPIOB clock reset
RCU_GPIOCRST GPIOC clock reset
RCU_GPIODRST GPIOD clock reset
RCU_GPIOERST GPIOE clock reset
RCU_GPIOFRST GPIOF clock reset
RCU_GPIOGRST GPIOG clock reset
RCU_ADC0RST ADC0 clock reset
RCU_ADC1RST ADC1 clock reset
RCU_TIMER0RST TIMER0 clock reset
RCU_SPI0RST SPI0 clock reset
RCU_TIMER7RST TIMER7 clock reset
RCU_USART0RST USART0 clock reset
RCU_ADC2RST ADC2 clock reset(XD、HD series)
RCU_TIMER8RST TIMER8 clock reset(XD、CL series)
RCU_TIMER9RST TIMER9 clock reset(XD、CL series)
RCU_TIMER10RST TIMER10 clock reset(XD、CL series)
RCU_USART5RST USART5 clock reset
RCU_SHRTIMERRST HPTIEMR clock reset
RCU_CMPRST CMP clock reset(only for CL series)

Enum rcu_flag_enum

Table 3-665. Enum rcu_flag_enum


enum name Function description
RCU_FLAG_IRC8MST IRC8M stabilization flags
B
RCU_FLAG_HXTALST HXTAL stabilization flags
B
RCU_FLAG_PLLSTB PLL stabilization flags
RCU_FLAG_PLLUSBS PLLUSB stabilization flags(only for CL series)
TB
RCU_FLAG_PLL1STB PLL1 stabilization flags(only for CL series)
RCU_FLAG_PLL2STB PLL2 stabilization flags(only for CL series)
RCU_FLAG_LXTALST LXTAL stabilization flags

482
GD32E50x Firmware Library User Guide
enum name Function description
B
RCU_FLAG_IRC40KST IRC40K stabilization flags
B
RCU_FLAG_IRC48MS IRC48M stabilization flags
TB
RCU_FLAG_BORRST BOR reset flag
RCU_FLAG_EPRST external PIN reset flags
RCU_FLAG_PORRST power reset flags
RCU_FLAG_SWRST software reset flags
RCU_FLAG_FWDGTR FWDGT reset flags
ST
RCU_FLAG_WWDGTR WWDGT reset flags
ST
RCU_FLAG_LPRST low-power reset flags

Enum rcu_int_flag_enum

Table 3-666. Enum rcu_int_flag_enum


enum name Function description
RCU_INT_FLAG_IRC4 IRC40K stabilization interrupt flag
0KSTB
RCU_INT_FLAG_LXTA LXTAL stabilization interrupt flag
LSTB
RCU_INT_FLAG_IRC8 IRC8M stabilization interrupt flag
MSTB
RCU_INT_FLAG_HXTA HXTAL stabilization interrupt flag
LSTB
RCU_INT_FLAG_PLLS PLL stabilization interrupt flag
TB
RCU_INT_FLAG_PLL1 PLL1 stabilization interrupt flag(only for CL series)
STB
RCU_INT_FLAG_PLL2 PLL2 stabilization interrupt flag(only for CL series)
STB
RCU_INT_FLAG_PLLU PLLUSB stabilization interrupt flag(only for CL series)
SBSTB
RCU_INT_FLAG_CKM HXTAL clock stuck interrupt flag
RCU_INT_FLAG_IRC4 IRC48M stabilization interrupt flag
8MSTB

483
GD32E50x Firmware Library User Guide
Enum rcu_int_flag_clear_enum

Table 3-667. Enum rcu_int_flag_clear_enum


enum name Function description
RCU_INT_FLAG_IRC4 IRC40K stabilization interrupt flags clear
0KSTB_CLR
RCU_INT_FLAG_LXTA LXTAL stabilization interrupt flags clear
LSTB_CLR
RCU_INT_FLAG_IRC8 IRC8M stabilization interrupt flags clear
MSTB_CLR
RCU_INT_FLAG_HXTA HXTAL stabilization interrupt flags clear
LSTB_CLR
RCU_INT_FLAG_PLLS PLL stabilization interrupt flags clear
TB_CLR
RCU_INT_FLAG_PLL1 PLL1 stabilization interrupt flags clear(only for CL series)
STB_CLR
RCU_INT_FLAG_PLL2 PLL2 stabilization interrupt flags clear(only for CL series)
STB_CLR
RCU_INT_FLAG_PLLU PLLUSB stabilization interrupt flags clear(only for CL series)
SBSTB_CLR
RCU_INT_FLAG_CKM CKM interrupt flags clear
_CLR
RCU_INT_FLAG_IRC4 internal 48 MHz RC oscillator stabilization interrupt clear
8MSTB_CLR

Enum rcu_int_enum

Table 3-668. Enum rcu_int_enum


enum name Function description
RCU_INT_IRC40KSTB IRC40K stabilization interrupt
RCU_INT_LXTALSTB LXTAL stabilization interrupt
RCU_INT_IRC8MSTB IRC8M stabilization interrupt
RCU_INT_HXTALSTB HXTAL stabilization interrupt
RCU_INT_PLLSTB PLL stabilization interrupt
RCU_INT_PLL1STB PLL1 stabilization interrupt
RCU_INT_PLL2STB PLL2 stabilization interrupt
RCU_INT_PLLUSBSTB PLLUSB stabilization interrupt
RCU_INT_IRC48MSTB internal 48 MHz RC oscillator stabilization interrupt

Enum rcu_osci_type_enum

Table 3-669. Enum rcu_osci_type_enum


enum name Function description
RCU_HXTAL HXTAL

484
GD32E50x Firmware Library User Guide
enum name Function description
RCU_LXTAL LXTAL
RCU_IRC8M IRC8M
RCU_IRC48M IRC48M
RCU_IRC40K IRC40K
RCU_PLL_CK PLL
RCU_PLL1_CK PLL1
RCU_PLL2_CK PLL2
RCU_PLLUSB_CK PLLUSB

Enum rcu_clock_freq_enum

Table 3-670. Enum rcu_clock_freq_enum


enum name Function description
CK_SYS system clock
CK_AHB AHB clock
CK_APB1 APB1 clock
CK_APB2 APB2 clock
CK_USART USART5 clock

rcu_deinit

The description of rcu_deinit is shown as below:

Table 3-671. Function rcu_deinit


Function name rcu_deinit
Function prototype void rcu_deinit(void);
Function descriptions deinitialize the RCU, reset the value of all RCU registers into initial values
Precondition -
The called functions rcu_osci_stab_wait
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset RCU */

rcu_deinit();

rcu_periph_clock_enable

The description of rcu_periph_clock_enable is shown as below:

485
GD32E50x Firmware Library User Guide
Table 3-672. Function rcu_periph_clock_enable
Function name rcu_periph_clock_enable
Function prototype void rcu_periph_clock_enable(rcu_periph_enum periph);
Function descriptions enable the peripherals clock
Precondition -
The called functions -
Input parameter{in}
periph RCU peripherals, refer to Enum rcu_periph_enum
RCU_GPIOx GPIO ports clock (x=A,B,C,D,E,F,G)
RCU_AF alternate function clock
RCU_CRC CRC clock
RCU_DMAx DMAx clock (x=0,1)
RCU_ENET ENET clock(CL series)
RCU_ENETTX ENETTX clock(CL series)
RCU_ENETRX ENETRX clock(CL series)
RCU_USBD USBD clock(HD、XD series)
RCU_USBHS USBHS clock(CL series)
RCU_EXMC EXMC clock
RCU_TMU TMU clock(CL series)
RCU_SQPI SQPI clock
RCU_TIMERx TIMERx clock (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13)
RCU_WWDGT WWDGT clock
RCU_SPIx SPIx clock (x=0,1,2)
RCU_USARTx USARTx clock (x=0,1,2,5)
RCU_UARTx UARTx clock (x=3,4)
RCU_I2Cx I2Cx clock (x=0,1,2)
RCU_PMU PMU clock
RCU_DAC DAC clock
RCU_RTC RTC clock
RCU_ADCx ADCx clock (x=0,1,2) ADC2 is not available for CL series
RCU_SDIO SDIO clock (HD、XD series)
RCU_CTC CTC clock
RCU_BKPI BKP interface clock
RCU_SHRTIMER SHRTIMER clock
RCU_CMP CMP clock(CL series)
Output parameter{out}
- -
Return value
- -

Example:

/* enable the USART0 clock */

486
GD32E50x Firmware Library User Guide
rcu_periph_clock_enable(RCU_USART0);

rcu_periph_clock_disable

The description of rcu_periph_clock_disable is shown as below:

Table 3-673. Function rcu_periph_clock_disable


Function name rcu_periph_clock_disable
Function prototype void rcu_periph_clock_disable(rcu_periph_enum periph);
Function descriptions disable the peripherals clock
Precondition -
The called functions -
Input parameter{in}
periph RCU peripherals, refer to Enum rcu_periph_enum
RCU_GPIOx GPIO ports clock (x=A,B,C,D,E,F,G)
RCU_AF alternate function clock
RCU_CRC CRC clock
RCU_DMAx DMAx clock (x=0,1)
RCU_ENET ENET clock(CL series)
RCU_ENETTX ENETTX clock(CL series)
RCU_ENETRX ENETRX clock(CL series)
RCU_USBD USBD clock(HD、XD series)
RCU_USBHS USBHS clock(CL series)
RCU_EXMC EXMC clock
RCU_TMU TMU clock(CL series)
RCU_SQPI SQPI clock
RCU_TIMERx TIMERx clock (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13)
RCU_WWDGT WWDGT clock
RCU_SPIx SPIx clock (x=0,1,2)
RCU_USARTx USARTx clock (x=0,1,2,5)
RCU_UARTx UARTx clock (x=3,4)
RCU_I2Cx I2Cx clock (x=0,1,2)
RCU_PMU PMU clock
RCU_DAC DAC clock
RCU_RTC RTC clock
RCU_ADCx ADCx clock (x=0,1,2) ADC2 is not available for CL series
RCU_SDIO SDIO clock (HD、XD series)
RCU_CTC CTC clock
RCU_BKPI BKP interface clock
RCU_SHRTIMER SHRTIMER clock
RCU_CMP CMP clock(CL series)
Output parameter{out}
- -

487
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* disable the USART0 clock */

rcu_periph_clock_disable(RCU_USART0);

rcu_periph_clock_sleep_enable

The description of rcu_periph_clock_sleep_enable is shown as below:

Table 3-674. Function rcu_periph_clock_sleep_enable


Function name rcu_periph_clock_sleep_enable
Function prototype void rcu_periph_clock_sleep_enable(rcu_periph_sleep_enum periph);
Function descriptions enable the peripherals clock when in sleep mode
Precondition -
The called functions -
Input parameter{in}
periph RCU peripherals, refer to Enum rcu_periph_sleep_enum
RCU_FMC_SLP FMC clock
RCU_SRAM_SLP SRAM clock
Output parameter{out}
- -
Return value
- -

Example:

/* enable the FMC clock when in sleep mode */

rcu_periph_clock_sleep_enable(RCU_FMC_SLP);

rcu_periph_clock_sleep_disable

The description of rcu_periph_clock_sleep_disable is shown as below:

Table 3-675. Function rcu_periph_clock_sleep_disable


Function name rcu_periph_clock_sleep_disable
Function prototype void rcu_periph_clock_sleep_disable(rcu_periph_sleep_enum periph);
Function descriptions disable the peripherals clock when in sleep mode
Precondition -
The called functions -
Input parameter{in}
periph RCU peripherals, refer to Enum rcu_periph_sleep_enum
RCU_FMC_SLP FMC clock
RCU_SRAM_SLP SRAM clock
488
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* disable the FMC clock when in sleep mode */

rcu_periph_clock_sleep_disable(RCU_FMC_SLP);

rcu_periph_reset_enable

The description of rcu_periph_reset_enable is shown as below:

Table 3-676. Function rcu_periph_reset_enable


Function name rcu_periph_reset_enable
Function prototype void rcu_periph_reset_enable(rcu_periph_reset_enum periph_reset);
Function descriptions enable the peripherals reset
Precondition -
The called functions -
Input parameter{in}
periph_reset RCU peripherals reset, refer to Enum rcu_periph_reset_enum
RCU_GPIOxRST reset GPIO ports clock (x=A,B,C,D,E,F,G)
RCU_AFRST reset alternate function clock
RCU_ENETRST reset ENET clock(CL series)
RCU_USBDRST reset USBD clock(HD、XD series)
RCU_USBHSRST reset USBHS clock(CL series)
RCU_TMURST reset TMU
RCU_SQPIRST reset SQPI
RCU_TIMERxRST reset TIMERx clock (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13)
RCU_WWDGTRST reset WWDGT clock
RCU_SPIxRST reset SPIx clock (x=0,1,2)
RCU_USARTxRST reset USARTx clock (x=0,1,2,5)
RCU_UARTxRST reset UARTx clock (x=3,4)
RCU_I2CxRST reset I2Cx clock (x=0,1,2)
RCU_PMURST reset PMU clock
RCU_DACRST reset DAC clock
RCU_ADCxRST reset ADCx clock (x=0,1,2) ADC2 is not available for CL series
RCU_CTCRST reset CTC clock
RCU_BKPIRST reset BKPI clock
RCU_SHRTIMERRST reset SHRTIMERRST
RCU_CMPRST reset CMP(CL series)
Output parameter{out}
- -

489
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* enable SPI0 reset */

rcu_periph_reset_enable(RCU_SPI0RST);

rcu_periph_reset_disable

The description of rcu_periph_reset_disable is shown as below:

Table 3-677. Function rcu_periph_reset_disable


Function name rcu_periph_reset_disable
Function prototype void rcu_periph_reset_disable(rcu_periph_reset_enum periph_reset);
Function descriptions disable the peripheral reset
Precondition -
The called functions -
Input parameter{in}
periph_reset RCU peripherals reset, refer to Enum rcu_periph_reset_enum
RCU_GPIOxRST reset GPIO ports clock (x=A,B,C,D,E,F,G)
RCU_AFRST reset alternate function clock
RCU_ENETRST reset ENET clock(CL series)
RCU_USBDRST reset USBD clock(HD、XD series)
RCU_USBHSRST reset USBHS clock(CL series)
RCU_TMURST reset TMU
RCU_SQPIRST reset SQPI
RCU_TIMERxRST reset TIMERx clock (x=0,1,2,3,4,5,6,7,8,9,10,11,12,13)
RCU_WWDGTRST reset WWDGT clock
RCU_SPIxRST reset SPIx clock (x=0,1,2)
RCU_USARTxRST reset USARTx clock (x=0,1,2,5)
RCU_UARTxRST reset UARTx clock (x=3,4)
RCU_I2CxRST reset I2Cx clock (x=0,1,2)
RCU_PMURST reset PMU clock
RCU_DACRST reset DAC clock
RCU_ADCxRST reset ADCx clock (x=0,1,2) ADC2 is not available for CL series
RCU_CTCRST reset CTC clock
RCU_BKPIRST reset BKPI clock
RCU_SHRTIMERRST reset SHRTIMERRST
RCU_CMPRST reset CMP
Output parameter{out}
- -
Return value
- -

490
GD32E50x Firmware Library User Guide
Example:

/* disable SPI0 reset */

rcu_periph_reset_disable(RCU_SPI0RST);

rcu_bkp_reset_enable

The description of rcu_bkp_reset_enable is shown as below:

Table 3-678. Function rcu_bkp_reset_enable


Function name rcu_bkp_reset_enable
Function prototype void rcu_bkp_reset_enable(void);
Function descriptions enable the BKP domain reset
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset the BKP domain */

rcu_bkp_reset_enable();

rcu_bkp_reset_disable

The description of rcu_bkp_reset_disable is shown as below:

Table 3-679. Function rcu_bkp_reset_disable


Function name rcu_bkp_reset_disable
Function prototype void rcu_bkp_reset_disable(void);
Function descriptions disable the BKP domain reset
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

491
GD32E50x Firmware Library User Guide
/* disable the BKP domain reset */

rcu_bkp_reset_disable();

rcu_system_clock_source_config

The description of rcu_system_clock_source_config is shown as below:

Table 3-680. Function rcu_system_clock_source_config


Function name rcu_system_clock_source_config
Function prototype void rcu_system_clock_source_config(uint32_t ck_sys);
Function descriptions configure the system clock source
Precondition -
The called functions -
Input parameter{in}
ck_sys system clock source select
RCU_CKSYSSRC_IRC
select CK_IRC8M as the CK_SYS source
8M
RCU_CKSYSSRC_HX
select CK_HXTAL as the CK_SYS source
TAL
RCU_CKSYSSRC_PLL select CK_PLL as the CK_SYS source
Output parameter{out}
- -
Return value
- -

Example:

/* configure the CK_HXTAL as the CK_SYS source */

rcu_system_clock_source_config(RCU_CKSYSSRC_HXTAL);

rcu_system_clock_source_get

The description of rcu_system_clock_source_get is shown as below:

Table 3-681. Function rcu_system_clock_source_get


Function name rcu_system_clock_source_get
Function prototype uint32_t rcu_system_clock_source_get(void);
Function descriptions get the system clock source
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
492
GD32E50x Firmware Library User Guide
uint32_t RCU_SCSS_IRC8M/RCU_SCSS_HXTAL/RCU_SCSS_PLL

Example:

uint32_t temp_cksys_status;

/* get the CK_SYS source */

temp_cksys_status = rcu_system_clock_source_get();

rcu_ahb_clock_config

The description of rcu_ahb_clock_config is shown as below:

Table 3-682. Function rcu_ahb_clock_config


Function name rcu_ahb_clock_config
Function prototype void rcu_ahb_clock_config(uint32_t ck_ahb);
Function descriptions configure the AHB clock prescaler selection
Precondition -
The called functions -
Input parameter{in}
ck_ahb AHB clock prescaler selection
RCU_AHB_CKSYS_DI
select CK_SYS / x, (x=1, 2, 4, 8, 16, 64, 128, 256, 512)
Vx
Output parameter{out}
- -
Return value
- -

Example:

/* configure CK_SYS/128 */

rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV128);

rcu_apb1_clock_config

The description of rcu_apb1_clock_config is shown as below:

Table 3-683. Function rcu_apb1_clock_config


Function name rcu_apb1_clock_config
Function prototype void rcu_apb1_clock_config(uint32_t ck_apb1);
Function descriptions configure the APB1 clock prescaler selection
Precondition -
The called functions -
Input parameter{in}
ck_apb1 APB1 clock prescaler selection
RCU_APB1_CKAHB_D select CK_AHB as CK_APB1

493
GD32E50x Firmware Library User Guide
IV1
RCU_APB1_CKAHB_D
select CK_AHB/2 as CK_APB1
IV2
RCU_APB1_CKAHB_D
select CK_AHB/4 as CK_APB1
IV4
RCU_APB1_CKAHB_D
select CK_AHB/8 as CK_APB1
IV8
RCU_APB1_CKAHB_D
select CK_AHB/16 as CK_APB1
IV16
Output parameter{out}
- -
Return value
- -

Example:

/* configure CK_AHB/16 as CK_APB1 */

rcu_apb1_clock_config(RCU_APB1_CKAHB_DIV16);

rcu_apb2_clock_config

The description of rcu_apb2_clock_config is shown as below:

Table 3-684. Function rcu_apb2_clock_config


Function name rcu_apb2_clock_config
Function prototype void rcu_apb2_clock_config(uint32_t ck_apb2);
Function descriptions configure the APB2 clock prescaler selection
Precondition -
The called functions -
Input parameter{in}
ck_apb2 APB2 clock prescaler selection
RCU_APB2_CKAHB_D
select CK_AHB as CK_APB2
IV1
RCU_APB2_CKAHB_D
select CK_AHB/2 as CK_APB2
IV2
RCU_APB2_CKAHB_D
select CK_AHB/4 as CK_APB2
IV4
RCU_APB2_CKAHB_D
select CK_AHB/8 as CK_APB2
IV8
RCU_APB2_CKAHB_D
select CK_AHB/16 as CK_APB2
IV16
Output parameter{out}
- -
Return value

494
GD32E50x Firmware Library User Guide
- -

Example:

/* configure CK_AHB/8 as CK_APB2 */

rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV8);

rcu_ckout0_config

The description of rcu_ckout0_config is shown as below:

Table 3-685. Function rcu_ckout0_config


Function name rcu_ckout0_config
Function prototype void rcu_ckout0_config(uint32_t ckout0_src);
Function descriptions configure the CK_OUT0 clock source
Precondition -
The called functions -
Input parameter{in}
ckout0_src CK_OUT0 clock source selection
RCU_CKOUT0SRC_N
no clock selected
ONE
RCU_CKOUT0SRC_C
select system clock CK_SYS
KSYS
RCU_CKOUT0SRC_IR
select high speed 8M internal oscillator clock
C8M
RCU_CKOUT0SRC_H
select HXTAL
XTAL
RCU_CKOUT0SRC_C
select (CK_PLL / 2) clock
KPLL_DIV2
RCU_CKOUT0SRC_C
select CK_PLL1 clock
KPLL1
RCU_CKOUT0SRC_C
select (CK_PLL2 / 2) clock
KPLL2_DIV2
RCU_CKOUT0SRC_C
select CK_PLL2 clock
KPLL2
RCU_CKOUT0SRC_E
select EXT1 clock
XT1
RCU_CKOUT0SRC_C
CK_IRC48M clock selected
KIRC48M
RCU_CKOUT0SRC_C
CK_IRC48M/8 clock selected
KIRC48M_DIV8
RCU_CKOUT0SRC_C
CK_PLLUSB/32 clock selected
KPLLUSB_DIV32
Output parameter{out}

495
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* configure the HXTAL as CK_OUT0 clock source */

rcu_ckout0_config(RCU_CKOUT0SRC_HXTAL);

rcu_pll_config

The description of rcu_pll_config is shown as below:

Table 3-686. Function rcu_pll_config


Function name rcu_pll_config
Function prototype void rcu_pll_config(uint32_t pll_src, uint32_t pll_mul);
Function descriptions configure the main PLL clock
Precondition -
The called functions -
Input parameter{in}
pll_src PLL clock source selection
RCU_PLLSRC_IRC8M
IRC8M/2 clock is selected as source clock of PLL
_DIV2
RCU_PLLSRC_HXTAL
HXTAL or IRC48M is selected as source clock of PLL
_IRC48M
Input parameter{in}
pll_mul PLL clock multiplication factor
RCU_PLL_MULx PLL clock * x (XD series x = 2..63, CL series x = 2..14, 16..64, 6.5)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PLL */

rcu_pll_config(RCU_PLLSRC_HXTAL, RCU_PLL_MUL10);

rcu_pllpresel_config

The description of rcu_pllpresel_config is shown as below:

Table 3-687. Function rcu_pllpresel_config


Function name rcu_pllpresel_config
Function prototype void rcu_pllpresel_config(uint32_t pll_presel);
Function descriptions configure the PLL clock source preselection
496
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
pll_presel PLL clock source preselection
RCU_PLLPRESRC_HX
HXTAL selected as PREDV0 source clock
TAL
RCU_PLLPRESRC_IR
CK_PLL selected as PREDV0 input source clock
C48M
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PLL clock source preselection */

rcu_pllpresel_config (RCU_PLLPRESRC_HXTAL);

rcu_predv0_config(HD、XD series)

The description of rcu_predv0_config is shown as below:

Table 3-688. Function rcu_predv0_config


Function name rcu_predv0_config
Function prototype void rcu_predv0_config(uint32_t predv0_div);
Function descriptions configure the PREDV0 division factor
Precondition -
The called functions -
Input parameter{in}
predv0_div PREDV0 division factor
RCU_PREDV0_DIVx PREDV0 input source clock is divided x (x=1,2)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PREDV0 division factor */

rcu_predv0_config(RCU_PREDV0_DIV1);

rcu_predv0_config(CL series)

The description of rcu_predv0_config is shown as below:

497
GD32E50x Firmware Library User Guide
Table 3-689. Function rcu_predv0_config
Function name rcu_predv0_config
Function prototype void rcu_predv0_config(uint32_t predv0_source, uint32_t predv0_div);
Function descriptions configure the PREDV0 division factor
Precondition -
The called functions -
Input parameter{in}
predv0_source PREDV0 input clock source selection
RCU_PREDV0SRC_H
select HXTAL or IRC48M as PREDV0 input source clock
XTAL_IRC48M
RCU_PREDV0SRC_C
select CK_PLL1 as PREDV0 input source clock
KPLL1
Input parameter{in}
predv0_div PREDV0 division factor
RCU_PREDV0_DIVx PREDV0 input source clock is divided x (x=1..16)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PREDV0 division factor */

rcu_predv0_config(RCU_PREDV0SRC_HXTAL_IRC48M, RCU_PREDV0_DIV4);

rcu_predv1_config(CL series)

The description of rcu_predv1_config is shown as below:

Table 3-690. Function rcu_predv1_config


Function name rcu_predv1_config
Function prototype void rcu_predv1_config(uint32_t predv1_div);
Function descriptions configure the PREDV1 division factor
Precondition -
The called functions -
Input parameter{in}
predv1_div PREDV1 division factor
RCU_PREDV1_DIVx PREDV1 input source clock is divided x (x=1..16)
Output parameter{out}
- -
Return value
- -

Example:

498
GD32E50x Firmware Library User Guide
/* configure the PREDV1 division factor */

rcu_predv1_config(RCU_PREDV1_DIV8);

rcu_pll1_config(CL series)

The description of rcu_pll1_config is shown as below:

Table 3-691. Function rcu_pll1_config


Function name rcu_pll1_config
Function prototype void rcu_pll1_config(uint32_t pll_mul);
Function descriptions configure the PLL1 clock
Precondition -
The called functions -
Input parameter{in}
pll_mul PLL clock multiplication factor
RCU_PLL1_MULx PLL1 clock * x,(x = 8..14,16,20)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PLL1 clock */

rcu_pll1_config(RCU_PLL1_MUL8);

rcu_pll2_config(CL series)

The description of rcu_pll2_config is shown as below:

Table 3-692. Function rcu_pll2_config


Function name rcu_pll2_config
Function prototype void rcu_pll2_config(uint32_t pll_mul);
Function descriptions configure the PLL2 clock
Precondition -
The called functions -
Input parameter{in}
pll_mul PLL clock multiplication factor
RCU_PLL2_MULx PLL2 clock * x, (x = 8..14,16,20,18..32,40,34..64,80)
Output parameter{out}
- -
Return value
- -

Example:

499
GD32E50x Firmware Library User Guide
/* configure the PLL2 clock */

rcu_pll2_config(RCU_PLL2_MUL8);

rcu_pllusbpresel_config(CL series)

The description of rcu_pllusbpresel_config is shown as below:

Table 3-693. Function rcu_pllusbpresel_config


Function name rcu_pllusbpresel_config
Function prototype void rcu_pllusbpresel_config(uint32_t pllusb_presel);
Function descriptions configure the PLLUSB clock source preselection
Precondition -
The called functions -
Input parameter{in}
pllusb_presel PLLUSB clock source preselection
RCU_PLLUSBPRESR
HXTAL selected as PLLUSB source clock
C_HXTAL
RCU_PLLUSBPRESR
IRC48M clock selected as PLLUSB source clock
C_IRC48M
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PLLUSB clock source preselection */

rcu_pllusbpresel_config(RCU_PLLUSBPRESRC_HXTAL);

rcu_pllusbpredv_config (CL series)

The description of rcu_pllusbpredv_config is shown as below:

Table 3-694. Function rcu_pllusbpredv_config


Function name rcu_pllusbpredv_config
void rcu_pllusbpredv_config(uint32_t pllusbpredv_source, uint32_t
Function prototype
pllusbpredv_div);
Function descriptions configure the PLLUSBPREDV division factor and clock source
Precondition -
The called functions -
Input parameter{in}
pllusbpredv_source PLLUSBPREDV input clock source selection
RCU_PLLUSBPREDVS
HXTAL or IRC48M selected as PLLUSBPREDV input source clock
RC_HXTAL_IRC48M
RCU_PLLUSBPREDVS CK_PLL1 selected as PLLUSBPREDV input source clock
500
GD32E50x Firmware Library User Guide
RC_CKPLL1
Input parameter{in}
pllusbpredv_div PLLUSBPREDV division factor
RCU_PLLUSBPREDV_
PLLUSBPREDV input source clock divided by x,( x = 1..15)
DIVx
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PLLUSBPREDV division factor and clock source */

rcu_pllusbpredv_config(RCU_PLLUSBPREDVSRC_HXTAL_IRC48M, RCU_PLLUSBPREDV_DIV15) ;

rcu_pllusb_config (CL series)

The description of rcu_pllusb_config is shown as below:

Table 3-695. Function rcu_pllusb_config


Function name rcu_pllusb_config
Function prototype void rcu_pllusb_config(uint32_t pllusb_mul);
Function descriptions configure the PLLUSB clock
Precondition -
The called functions -
Input parameter{in}
pllusb_mul PLLUSB clock multiplication factor
RCU_PLLUSB_MULx PLLUSB source clock multiply by x, (x = 16,17..127)
Output parameter{out}
- -
Return value
- -

Example:

/* configure the PLLUSB clock */

rcu_pllusb_config(RCU_PLLUSB_MUL16);

rcu_adc_clock_config

The description of rcu_adc_clock_config is shown as below:

Table 3-696. Function rcu_adc_clock_config


Function name rcu_adc_clock_config

501
GD32E50x Firmware Library User Guide
Function prototype void rcu_adc_clock_config(uint32_t adc_psc);
Function descriptions configure the ADC prescaler factor
Precondition -
The called functions -
Input parameter{in}
adc_psc ADC prescaler factor
RCU_CKADC_CKAPB
CK_ADC = CK_APB2 / 2
2_DIV2
RCU_CKADC_CKAPB
CK_ADC = CK_APB2 / 4
2_DIV4
RCU_CKADC_CKAPB
CK_ADC = CK_APB2 / 6
2_DIV6
RCU_CKADC_CKAPB
CK_ADC = CK_APB2 / 8
2_DIV8
RCU_CKADC_CKAPB
CK_ADC = CK_APB2 / 12
2_DIV12
RCU_CKADC_CKAPB
CK_ADC = CK_APB2 / 16
2_DIV16
RCU_CKADC_CKAHB
CK_ADC = CK_AHB/ 5
_DIV5
RCU_CKADC_CKAHB
CK_ADC = CK_AHB/ 6
_DIV6
RCU_CKADC_CKAHB
CK_ADC = CK_AHB/ 10
_DIV10
RCU_CKADC_CKAHB
CK_ADC = CK_AHB/ 20
_DIV20
Output parameter{out}
- -
Return value
- -

Example:

/* configure the ADC prescaler factor */

rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV8);

rcu_usb_clock_config

The description of rcu_usb_clock_config is shown as below:

Table 3-697. Function rcu_usb_clock_config


Function name rcu_usb_clock_config
Function prototype void rcu_usb_clock_config(uint32_t usb_psc);
Function descriptions configure the USB prescaler factor

502
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
usb_psc USB prescaler factor
RCU_CKUSB_CKPLL_
CK_USBD/USBHS = CK_PLL / 1.5
DIV1_5
RCU_CKUSB_CKPLL_
CK_USBD/USBHS = CK_PLL / 1
DIV1
RCU_CKUSB_CKPLL_
CK_USBD/USBHS = CK_PLL / 2.5
DIV2_5
RCU_CKUSB_CKPLL_
CK_USBD/USBHS = CK_PLL / 2
DIV2
RCU_CKUSB_CKPLL_
CK_USBD/USBHS = CK_PLL / 3
DIV3
RCU_CKUSB_CKPLL_
CK_USBD/USBHS = CK_PLL / 3.5
DIV3_5
RCU_CKUSB_CKPLL_
CK_USBD/USBHS = CK_PLL / 4
DIV4
Output parameter{out}
- -
Return value
- -

Example:

/* configure the USB prescaler factor */

rcu_usb_clock_config(RCU_CKUSB_CKPLL_DIV2_5);

rcu_rtc_clock_config

The description of rcu_rtc_clock_config is shown as below:

Table 3-698. Function rcu_rtc_clock_config


Function name rcu_rtc_clock_config
Function prototype void rcu_rtc_clock_config(uint32_t rtc_clock_source);
Function descriptions configure the RTC clock source selection
Precondition -
The called functions -
Input parameter{in}
rtc_clock_source RTC clock source selection
RCU_RTCSRC_NONE no clock selected
RCU_RTCSRC_LXTAL select CK_LXTAL as RTC source clock
RCU_RTCSRC_IRC40
select CK_IRC40K as RTC source clock
K

503
GD32E50x Firmware Library User Guide
RCU_RTCSRC_HXTAL
select CK_HXTAL/128 as RTC source clock
_DIV_128
Output parameter{out}
- -
Return value
- -

Example:

/* configure the RTC clock source selection */

rcu_rtc_clock_config(RCU_RTCSRC_IRC40K);

rcu_shrtimer_clock_config

The description of rcu_shrtimer_clock_config is shown as below:

Table 3-699. Function rcu_shrtimer_clock_config


Function name rcu_shrtimer_clock_config
Function prototype void rcu_shrtimer_clock_config (uint32_t shrtimer_clock_source);
Function descriptions configure the SHRTIMER clock source selection
Precondition -
The called functions -
Input parameter{in}
shrtimer_clock_sourc
SHRTIMER clock source selection
e
RCU_SHRTIMERSRC_
APB2 clock selected as SHRTIMER source clock
CKAPB2
RCU_SHRTIMERSRC_
system clock selected as SHRTIMER source clock
CKSYS
Output parameter{out}
- -
Return value
- -

Example:

/* configure the SHRTIMER clock source selection */

rcu_shrtimer_clock_config (RCU_SHRTIMERSRC_CKAPB2);

rcu_usart5_clock_config

The description of rcu_usart5_clock_config is shown as below:

Table 3-700. Function rcu_usart5_clock_config


Function name rcu_usart5_clock_config
Function prototype void rcu_usart5_clock_config(uint32_t usart5_clock_source);

504
GD32E50x Firmware Library User Guide
Function descriptions configure the USART5 clock source selection
Precondition -
The called functions -
Input parameter{in}
usart5_clock_source USART5 clock source selection
RCU_USART5SRC_C
APB2 clock selected as USART5 source clock
KAPB2
RCU_USART5SRC_C
system clock selected as USART5 source clock
KSYS
RCU_USART5SRC_LX
LXTAL clock selected as USART5 source clock
TAL
RCU_USART5SRC_IR
IRC8M clock selected as USART5 source clock
C8M
Output parameter{out}
- -
Return value
- -

Example:

/* configure the USART5 clock source selection */

rcu_usart5_clock_config(RCU_USART5SRC_CKAPB2);

rcu_i2c2_clock_config

The description of rcu_i2c2_clock_config is shown as below:

Table 3-701. Function rcu_i2c2_clock_config


Function name rcu_i2c2_clock_config
Function prototype void rcu_i2c2_clock_config(uint32_t i2c2_clock_source);
Function descriptions configure the I2C2 clock source selection
Precondition -
The called functions -
Input parameter{in}
i2c2_clock_source I2C2 clock source selection
RCU_I2C2SRC_CKAP
APB1 clock selected as I2C2 source clock
B1
RCU_I2C2SRC_CKSY
System clock selected as I2C2 source clock
S
RCU_I2C2SRCSRC_C
CK_IRC8M clock selected as I2C2 source clock
KIRC8M
Output parameter{out}
- -
Return value

505
GD32E50x Firmware Library User Guide
- -

Example:

/* configure the I2C2 clock source selection */

rcu_i2c2_clock_config(RCU_I2C2SRC_CKAPB1);

rcu_i2s1_clock_config(CL series)

The description of rcu_i2s1_clock_config is shown as below:

Table 3-702. Function rcu_i2s1_clock_config


Function name rcu_i2s1_clock_config
Function prototype void rcu_i2s1_clock_config(uint32_t i2s_clock_source);
Function descriptions configure the I2S1 clock source selection
Precondition -
The called functions -
Input parameter{in}
i2s_clock_source I2S clock source selection
RCU_I2S1SRC_CKSY
select system clock as I2S1 source clock
S
RCU_I2S1SRC_CKPLL
select CK_PLL2 * 2 as I2S1 source clock
2_MUL2
Output parameter{out}
- -
Return value
- -

Example:

/* configure the I2S1 clock source selection */

rcu_i2s1_clock_config(RCU_I2S1SRC_CKPLL2_MUL2);

rcu_i2s2_clock_config(CL series)

The description of rcu_i2s2_clock_config is shown as below:

Table 3-703. Function rcu_i2s2_clock_config


Function name rcu_i2s2_clock_config
Function prototype void rcu_i2s2_clock_config(uint32_t i2s_clock_source);
Function descriptions configure the I2S2 clock source selection
Precondition -
The called functions -
Input parameter{in}
i2s_clock_source I2S clock source selection
RCU_I2S2SRC_CKSY select system clock as I2S2 source clock
506
GD32E50x Firmware Library User Guide
S
RCU_I2S2SRC_CKPLL
select CK_PLL2 * 2 as I2S2 source clock
2_MUL2
Output parameter{out}
- -
Return value
- -

Example:

/* configure the I2S2 clock source selection */

rcu_i2s2_clock_config(RCU_I2S2SRC_CKPLL2_MUL2);

rcu_ck48m_clock_config

The description of rcu_ck48m_clock_config is shown as below:

Table 3-704. Function rcu_ck48m_clock_config


Function name rcu_ck48m_clock_config
Function prototype void rcu_ck48m_clock_config(uint32_t ck48m_clock_source);
Function descriptions configure the CK48M clock source selection
Precondition -
The called functions -
Input parameter{in}
ck48m_clock_source CK48M clock source selection
RCU_CK48MSRC_CK
CK_PLL selected as CK48M source clock
PLL
RCU_CK48MSRC_IRC
CK_IRC48M selected as CK48M source clock
48M
RCU_CK48MSRC_CK
CKPLLUSB selected as CK48M source clock
PLLUSB
RCU_CK48MSRC_CK
CKPLL2 selected as CK48M source clock
PLL2
Output parameter{out}
- -
Return value
- -

Example:

/* configure the CK48M clock source selection */

rcu_ck48m_clock_config (RCU_CK48MSRC_IRC48M);

507
GD32E50x Firmware Library User Guide
rcu_usbhssel_config (CL series)

The description of rcu_usbhssel_config is shown as below:

Table 3-705. Function rcu_usbhssel_config


Function name rcu_usbhssel_config
Function prototype void rcu_usbhssel_config(uint32_t usbhssel_clock_source);
Function descriptions configure the USBHSSEL source clock selection
Precondition -
The called functions -
Input parameter{in}
usbhssel_clock_sour
USBHSSEL clock source selection
ce
RCU_USBHSSRC_48
48M clock selected as USBHS source clock
M
RCU_CK48MSRC_60M 60M clock selected as USBHS source clock
Output parameter{out}
- -
Return value
- -

Example:

/* configure the USBHSSEL source clock selection */

rcu_usbhssel_config(RCU_USBHSSRC_48M);

rcu_usbdv_config (CL series)

The description of rcu_usbdv_config is shown as below:

Table 3-706. Function rcu_usbdv_config


Function name rcu_usbdv_config
Function prototype void rcu_usbdv_config(uint32_t usbhs_dv);
Function descriptions configure the USBHSDV division factor
Precondition -
The called functions -
Input parameter{in}
usbhs_dv USBHSDV division factor
RCU_USBHSDV_DIVx USBHSDV input source clock divided by x,(x=2,4,…,16)
Output parameter{out}
- -
Return value
- -

Example:

508
GD32E50x Firmware Library User Guide
/* configure the USBHSDV division factor */

rcu_usbdv_config(RCU_USBHSDV_DIV16);

rcu_flag_get

The description of rcu_flag_get is shown as below:

Table 3-707. Function rcu_flag_get


Function name rcu_flag_get
Function prototype FlagStatus rcu_flag_get(rcu_flag_enum flag);
Function descriptions get the clock stabilization and periphral reset flags
Precondition -
The called functions -
Input parameter{in}
the clock stabilization and periphral reset flags, refer to Enum
flag
rcu_flag_enum
RCU_FLAG_IRC8MST
IRC8M stabilization flag
B
RCU_FLAG_HXTALST
HXTAL stabilization flag
B
RCU_FLAG_PLLSTB PLL stabilization flag
RCU_FLAG_PLL1STB PLL1 stabilization flag(CL series only)
RCU_FLAG_PLL2STB PLL2 stabilization flag(CL series only)
RCU_FLAG_LXTALST
LXTAL stabilization flag
B
RCU_FLAG_IRC40KST
IRC40K stabilization flag
B
RCU_FLAG_IRC48MS
IRC48M stabilization flag
TB
RCU_FLAG_BORRST BOR reset flag
RCU_FLAG_EPRST external PIN reset flag
RCU_FLAG_PORRST power reset flag
RCU_FLAG_SWRST software reset flag
RCU_FLAG_FWDGTR
free watchdog timer reset flag
ST
RCU_FLAG_WWDGTR
window watchdog timer reset flag
ST
RCU_FLAG_LPRST low-power reset flag
Output parameter{out}
- -
Return value
FlagStatus SET or RESET
509
GD32E50x Firmware Library User Guide
Example:

/* get the clock stabilization flag */

if(RESET != rcu_flag_get(RCU_FLAG_LXTALSTB)){

rcu_all_reset_flag_clear

The description of rcu_all_reset_flag_clear is shown as below:

Table 3-708. Function rcu_all_reset_flag_clear


Function name rcu_all_reset_flag_clear
Function prototype void rcu_all_reset_flag_clear(void);
Function descriptions clear all the reset flag
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* clear all the reset flag */

rcu_all_reset_flag_clear();

rcu_interrupt_flag_get

The description of rcu_interrupt_flag_get is shown as below:

Table 3-709. Function rcu_interrupt_flag_get


Function name rcu_interrupt_flag_get
Function prototype FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag);
Function descriptions get the clock stabilization interrupt and ckm flags
Precondition -
The called functions -
Input parameter{in}
int_flag interrupt and ckm flags, refer to Enum rcu_int_flag_enum
RCU_INT_FLAG_IRC4
IRC40K stabilization interrupt flag
0KSTB
RCU_INT_FLAG_LXTA
LXTAL stabilization interrupt flag
LSTB
RCU_INT_FLAG_IRC8 IRC8M stabilization interrupt flag

510
GD32E50x Firmware Library User Guide
MSTB
RCU_INT_FLAG_HXT
HXTAL stabilization interrupt flag
ALSTB
RCU_INT_FLAG_PLLS
PLL stabilization interrupt flag
TB
RCU_INT_FLAG_PLL1
PLL1 stabilization interrupt flag(CL series only)
STB
RCU_INT_FLAG_PLL2
PLL2 stabilization interrupt flag(CL series only)
STB
RCU_INT_FLAG_PLLU
PLLUSB stabilization interrupt flag(CL series only)
SBSTB
RCU_INT_FLAG_CKM HXTAL clock stuck interrupt flag
RCU_INT_FLAG_IRC4
IRC48M stabilization interrupt flag
8MSTB
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the clock stabilization interrupt flag */

if(SET == rcu_interrupt_flag_get(RCU_INT_FLAG_HXTALSTB)){

rcu_interrupt_flag_clear

The description of rcu_interrupt_flag_clear is shown as below:

Table 3-710. Function rcu_interrupt_flag_clear


Function name rcu_interrupt_flag_clear
Function prototype void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag);
Function descriptions clear the interrupt flags
Precondition -
The called functions -
Input parameter{in}
clock stabilization and stuck interrupt flags clear, refer to Enum
int_flag
rcu_int_flag_clear_enum
RCU_INT_FLAG_IRC4
IRC40K stabilization interrupt flag clear
0KSTB_CLR
RCU_INT_FLAG_LXTA
LXTAL stabilization interrupt flag clear
LSTB_CLR
RCU_INT_FLAG_IRC8
IRC8M stabilization interrupt flag clear
MSTB_CLR

511
GD32E50x Firmware Library User Guide
RCU_INT_FLAG_HXT
HXTAL stabilization interrupt flag clear
ALSTB_CLR
RCU_INT_FLAG_PLLS
PLL stabilization interrupt flag clear
TB_CLR
RCU_INT_FLAG_PLL1
PLL1 stabilization interrupt flag clear(CL series only)
STB_CLR
RCU_INT_FLAG_PLL2
PLL2 stabilization interrupt flag clear(CL series only)
STB_CLR
RCU_INT_FLAG_PLLU
PLLUSB stabilization interrupt flag clear(CL series only)
SBSTB_CLR
RCU_INT_FLAG_CKM
clock stuck interrupt flag clear
_CLR
RCU_INT_FLAG_IRC4
IRC48M stabilization interrupt flag clear
8MSTB_CLR
Output parameter{out}
- -
Return value
- -

Example:

/* clear the interrupt HXTAL stabilization interrupt flag */

rcu_interrupt_flag_clear(RCU_INT_FLAG_HXTALSTB_CLR);

rcu_interrupt_enable

The description of rcu_interrupt_enable is shown as below:

Table 3-711. Function rcu_interrupt_enable


Function name rcu_interrupt_enable
Function prototype void rcu_interrupt_enable(rcu_int_enum interrupt);
Function descriptions enable the stabilization interrupt
Precondition -
The called functions -
Input parameter{in}
interrupt clock stabilization interrupt, refer to Enum rcu_int_enum
RCU_INT_IRC40KSTB IRC40K stabilization interrupt enable
RCU_INT_LXTALSTB LXTAL stabilization interrupt enable
RCU_INT_IRC8MSTB IRC8M stabilization interrupt enable
RCU_INT_HXTALSTB HXTAL stabilization interrupt enable
RCU_INT_PLLSTB PLL stabilization interrupt enable
RCU_INT_PLL1STB PLL1 stabilization interrupt enable(CL series only)
RCU_INT_PLL2STB PLL2 stabilization interrupt enable(CL series only)
RCU_INT_PLLUSBSTB PLLUSB stabilization interrupt enable(CL series only)

512
GD32E50x Firmware Library User Guide
RCU_INT_IRC48MSTB IRC48M stabilization interrupt enable
Output parameter{out}
- -
Return value
- -

Example:

/* enable the HXTAL stabilization interrupt */

rcu_interrupt_enable(RCU_INT_HXTALSTB);

rcu_interrupt_disable

The description of rcu_interrupt_disable is shown as below:

Table 3-712. Function rcu_interrupt_disable


Function name rcu_interrupt_disable
Function prototype void rcu_interrupt_disable(rcu_int_enum interrupt);
Function descriptions disable the stabilization interrupt
Precondition -
The called functions -
Input parameter{in}
interrupt clock stabilization interrupt, refer to Enum rcu_int_enum
RCU_INT_IRC40KSTB IRC40K stabilization interrupt enable
RCU_INT_LXTALSTB LXTAL stabilization interrupt enable
RCU_INT_IRC8MSTB IRC8M stabilization interrupt enable
RCU_INT_HXTALSTB HXTAL stabilization interrupt enable
RCU_INT_PLLSTB PLL stabilization interrupt enable
RCU_INT_PLL1STB PLL1 stabilization interrupt enable(CL series only)
RCU_INT_PLL2STB PLL2 stabilization interrupt enable(CL series only)
RCU_INT_PLLUSBSTB PLLUSB stabilization interrupt enable(CL series only)
RCU_INT_IRC48MSTB IRC48M stabilization interrupt enable
Output parameter{out}
- -
Return value
- -

Example:

/* disable the HXTAL stabilization interrupt */

rcu_interrupt_disable(RCU_INT_HXTALSTB);

rcu_lxtal_drive_capability_config

The description of rcu_lxtal_drive_capability_config is shown as below:

513
GD32E50x Firmware Library User Guide
Table 3-713. Function rcu_lxtal_drive_capability_config
Function name rcu_lxtal_drive_capability_config
Function prototype void rcu_lxtal_drive_capability_config(uint32_t lxtal_dricap);
Function descriptions configure the LXTAL drive capability
Precondition -
The called functions -
Input parameter{in}
lxtal_dricap drive capability of LXTAL
RCU_LXTAL_LOWDRI lower driving capability
RCU_LXTAL_MED_LO
medium low driving capability
WDRI
RCU_LXTAL_MED_HI
medium high driving capability
GHDRI
RCU_LXTAL_HIGHDRI higher driving capability
Output parameter{out}
- -
Return value
- -

Example:

/* configure the LXTAL drive capability */

rcu_lxtal_drive_capability_config (RCU_LXTAL_LOWDRI);

rcu_osci_stab_wait

The description of rcu_osci_stab_wait is shown as below:

Table 3-714. Function rcu_osci_stab_wait


Function name rcu_osci_stab_wait
Function prototype ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci);
Function descriptions wait for oscillator stabilization flags is SET or oscillator startup is timeout
Precondition -
The called functions -
Input parameter{in}
osci oscillator types, refer to Enum rcu_osci_type_enum
RCU_HXTAL high speed crystal oscillator(HXTAL)
RCU_LXTAL low speed crystal oscillator(LXTAL)
RCU_IRC8M internal 8M RC oscillators(IRC8M)
RCU_IRC48M internal 48M RC oscillators(IRC48M)
RCU_IRC40K internal 40K RC oscillator(IRC40K)
RCU_PLL_CK phase locked loop(PLL)
RCU_PLL1_CK phase locked loop 1(CL series only)
RCU_PLL2_CK phase locked loop 2(CL series only)

514
GD32E50x Firmware Library User Guide
RCU_PLLUSB_CK phase locked loop USB(CL series only)
Output parameter{out}
- -
Return value
ErrStatus SUCCESS or ERROR

Example:

/* wait for oscillator stabilization flag */

if(SUCCESS == rcu_osci_stab_wait(RCU_HXTAL)){

rcu_osci_on

The description of rcu_osci_on is shown as below:

Table 3-715. Function rcu_osci_on


Function name rcu_osci_on
Function prototype void rcu_osci_on(rcu_osci_type_enum osci);
Function descriptions turn on the oscillator
Precondition -
The called functions -
Input parameter{in}
osci oscillator types, refer to Enum rcu_osci_type_enum
RCU_HXTAL high speed crystal oscillator(HXTAL)
RCU_LXTAL low speed crystal oscillator(LXTAL)
RCU_IRC8M internal 8M RC oscillators(IRC8M)
RCU_IRC48M internal 48M RC oscillators(IRC48M)
RCU_IRC40K internal 40K RC oscillator(IRC40K)
RCU_PLL_CK phase locked loop(PLL)
RCU_PLL1_CK phase locked loop 1(CL series only)
RCU_PLL2_CK phase locked loop 2(CL series only)
RCU_PLLUSB_CK phase locked loop USB(CL series only)
Output parameter{out}
- -
Return value
- -

Example:

/* turn on the high speed crystal oscillator */

rcu_osci_on(RCU_HXTAL);

515
GD32E50x Firmware Library User Guide
rcu_osci_off

The description of rcu_osci_off is shown as below:

Table 3-716. Function rcu_osci_off


Function name rcu_osci_off
Function prototype void rcu_osci_off(rcu_osci_type_enum osci);
Function descriptions turn off the oscillator
Precondition -
The called functions -
Input parameter{in}
osci oscillator types, refer to Enum rcu_osci_type_enum
RCU_HXTAL high speed crystal oscillator(HXTAL)
RCU_LXTAL low speed crystal oscillator(LXTAL)
RCU_IRC8M internal 8M RC oscillators(IRC8M)
RCU_IRC48M internal 48M RC oscillators(IRC48M)
RCU_IRC40K internal 40K RC oscillator(IRC40K)
RCU_PLL_CK phase locked loop(PLL)
RCU_PLL1_CK phase locked loop 1(CL series only)
RCU_PLL2_CK phase locked loop 2(CL series only)
RCU_PLLUSB_CK phase locked loop USB(CL series only)
Output parameter{out}
- -
Return value
- -

Example:

/* turn off the high speed crystal oscillator */

rcu_osci_off(RCU_HXTAL);

rcu_osci_bypass_mode_enable

The description of rcu_osci_bypass_mode_enable is shown as below:

Table 3-717. Function rcu_osci_bypass_mode_enable


Function name rcu_osci_bypass_mode_enable
Function prototype void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci);
Function descriptions enable the oscillator bypass mode
Precondition HXTALEN or LXTALEN must be reset before it
The called functions -
Input parameter{in}
osci oscillator types, refer to Enum rcu_osci_type_enum
RCU_HXTAL high speed crystal oscillator(HXTAL)
RCU_LXTAL low speed crystal oscillator(LXTAL)

516
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* enable the high speed crystal oscillator bypass mode */

rcu_osci_bypass_mode_enable(RCU_HXTAL);

rcu_osci_bypass_mode_disable

The description of rcu_osci_bypass_mode_disable is shown as below:

Table 3-718. Function rcu_osci_bypass_mode_disable


Function name rcu_osci_bypass_mode_disable
Function prototype void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci);
Function descriptions disable the oscillator bypass mode
Precondition HXTALEN or LXTALEN must be reset before it
The called functions -
Input parameter{in}
osci oscillator types, refer to Enum rcu_osci_type_enum
RCU_HXTAL high speed crystal oscillator(HXTAL)
RCU_LXTAL low speed crystal oscillator(LXTAL)
Output parameter{out}
- -
Return value
- -

Example:

/* disable the high speed crystal oscillator bypass mode */

rcu_osci_bypass_mode_disable(RCU_HXTAL);

rcu_hxtal_clock_monitor_enable

The description of rcu_hxtal_clock_monitor_enable is shown as below:

Table 3-719. Function rcu_hxtal_clock_monitor_enable


Function name rcu_hxtal_clock_monitor_enable
Function prototype void rcu_hxtal_clock_monitor_enable(void);
Function descriptions enable the HXTAL clock monitor
Precondition -
The called functions -
Input parameter{in}
- -
517
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* enable the HXTAL clock monitor */

rcu_hxtal_clock_monitor_enable();

rcu_hxtal_clock_monitor_disable

The description of rcu_hxtal_clock_monitor_disable is shown as below:

Table 3-720. Function rcu_hxtal_clock_monitor_disable


Function name rcu_hxtal_clock_monitor_disable
Function prototype void rcu_hxtal_clock_monitor_disable(void);
Function descriptions disable the HXTAL clock monitor
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the HXTAL clock monitor */

rcu_hxtal_clock_monitor_disable();

rcu_irc8m_adjust_value_set

The description of rcu_irc8m_adjust_value_set is shown as below:

Table 3-721. Function rcu_irc8m_adjust_value_set


Function name rcu_irc8m_adjust_value_set
Function prototype void rcu_irc8m_adjust_value_set(uint32_t irc8m_adjval);
Function descriptions set the IRC8M adjust value
Precondition -
The called functions -
Input parameter{in}
irc8m_adjval IRC8M adjust value, must be between 0 and 0x1F
Output parameter{out}
- -
518
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* set the IRC8M adjust value */

rcu_irc8m_adjust_value_set(0x10);

rcu_deepsleep_voltage_set

The description of rcu_deepsleep_voltage_set is shown as below:

Table 3-722. Function rcu_deepsleep_voltage_set


Function name rcu_deepsleep_voltage_set
Function prototype void rcu_deepsleep_voltage_set(uint32_t dsvol);
Function descriptions set the deep-sleep mode voltage value
Precondition -
The called functions -
Input parameter{in}
dsvol deep sleep mode voltage
RCU_DEEPSLEEP_V_
the core voltage is 1.0V in deep-sleep mode
1_0
RCU_DEEPSLEEP_V_ the core voltage is 0.9V in deep-sleep mode
0_9
RCU_DEEPSLEEP_V_ the core voltage is 0.8V in deep-sleep mode
0_8
RCU_DEEPSLEEP_V_ the core voltage is 0.7V in deep-sleep mode
0_7
Output parameter{out}
- -
Return value
- -

Example:

/* set the deep-sleep mode voltage */

rcu_deepsleep_voltage_set(RCU_DEEPSLEEP_V_1_0);

rcu_clock_freq_get

The description of rcu_clock_freq_get is shown as below:

Table 3-723. Function rcu_clock_freq_get


Function name rcu_clock_freq_get
Function prototype uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock);
Function descriptions get the system clock, bus clock frequency

519
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
clock Clock frequency,refers to Enum rcu_clock_freq_enum
CK_SYS system clock frequency
CK_AHB AHB clock frequency
CK_APB1 APB1 clock frequency
CK_APB2 APB2 clock frequency
CK_USART USART5 clock frequency
Output parameter{out}
- -
Return value
ck_freq clock frequency of system, AHB, APB1, APB2,USART5

Example:

uint32_t temp_freq;

/* get the system clock frequency */

temp_freq = rcu_clock_freq_get(CK_SYS);

3.21. RTC

The Real-time Clock (RTC) is usually used as a clock-calendar. The ones in the Backup
Domain consist of a 32-bit up-counter, an alarm, a prescaler, a divider and the RTC clock
configuration register. The RTC registers are listed in chapter 3.21.1, the RTC firmware
functions are introduced in chapter 3.21.2.

3.21.1. Descriptions of Peripheral registers

RTC registers are listed in the table shown as below:

Table 3-724. RTC Registers


Registers Descriptions
RTC_INTEN Interrupt enable register
RTC_CTL Control register
RTC_PSCH Prescaler high register
RTC_PSCL Prescaler low register
RTC_DIVH Divider high register
RTC_DIVL Divider low register
RTC_CNTH counter high register
RTC_CNTL counter low register
RTC_ALRMH Alarm high register
RTC_ALRML Alarm low register
520
GD32E50x Firmware Library User Guide
3.21.2. Descriptions of Peripheral functions

RTC firmware functions are listed in the table shown as below:

Table 3-725. RTC firmware function


Function name Function description
rtc_configuration_mode_enter enter RTC configuration mode
rtc_configuration_mode_exit exit RTC configuration mode
rtc_lwoff_wait wait RTC last write operation finished flag set
rtc_register_sync_wait wait RTC registers synchronized flag set
rtc_counter_get get RTC counter value
rtc_counter_set set RTC counter value
rtc_prescaler_set set RTC prescaler value
rtc_alarm_config set RTC alarm value
rtc_divider_get get RTC divider value
rtc_interrupt_enable enable RTC interrupt
rtc_interrupt_disable disable RTC interrupt
rtc_flag_get get RTC flag status
rtc_flag_clear clear RTC flag status

rtc_configuration_mode_enter

The description of rtc_configuration_mode_enter is shown as below:

Table 3-726. Function rtc_configuration_mode_enter


Function name rtc_configuration_mode_enter
Function prototype void rtc_configuration_mode_enter(void);
Function descriptions enter RTC configuration mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enter RTC configuration mode */

rtc_configuration_mode_enter( );

rtc_configuration_mode_exit

The description of rtc_configuration_mode_exit is shown as below:


521
GD32E50x Firmware Library User Guide
Table 3-727. Function rtc_configuration_mode_exit
Function name rtc_configuration_mode_exit
Function prototype void rtc_configuration_mode_exit(void);
Function descriptions exit RTC configuration mode
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* exit RTC configuration mode */

rtc_configuration_mode_ exit ( );

rtc_lwoff_wait

The description of rtc_lwoff_wait is shown as below:

Table 3-728. Function rtc_lwoff_wait


Function name rtc_lwoff_wait
Function prototype void rtc_lwoff_wait(void);
Function descriptions wait RTC last write operation finished flag set
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* wait until last write operation on RTC registers has finished */

rtc_lwoff_wait( );

/* enable the RTC second interrupt */

rtc_interrupt_enable(RTC_INT_SECOND);

522
GD32E50x Firmware Library User Guide
rtc_register_sync_wait

The description of rtc_register_sync_wait is shown as below:

Table 3-729. Function rtc_register_sync_wait


Function name rtc_register_sync_wait
Function prototype void rtc_register_sync_wait(void);
Function descriptions wait RTC registers synchronized flag set
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* wait for RTC registers synchronization */

rtc_register_sync_wait( );

rtc_counter_get

The description of rtc_counter_get is shown as below:

Table 3-730. Function rtc_counter_get


Function name rtc_counter_get
Function prototype uint32_t rtc_counter_get(void);
Function descriptions get RTC counter value
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t the value of RTC counter

Example:

/* get the counter value */

uint32_t rtc_counter_value;

rtc_counter_value = rtc_counter_get ( );

523
GD32E50x Firmware Library User Guide
rtc_counter_set

The description of rtc_counter_set is shown as below:

Table 3-731. Function rtc_counter_set


Function name rtc_counter_set
Function prototype void rtc_counter_set(uint32_t cnt);
Function descriptions set RTC counter value
Precondition -
The called functions -
Input parameter{in}
cnt RTC counter value(0-0xFFFF FFFF)
Output parameter{out}
- -
Return value
- -

Example:

/* wait until last write operation on RTC registers has finished */

rtc_lwoff_wait( );

/* set counter value to 0xFFFF */

rtc_counter_set (0xFFFF);

rtc_prescaler_set

The description of rtc_prescaler_set is shown as below:

Table 3-732. Function rtc_prescaler_set


Function name rtc_interrupt_rtc_prescaler_set
Function prototype void rtc_prescaler_set(uint32_t psc);
Function descriptions set RTC prescaler value
before using this function, you must call rtc_lwoff_wait( ) function (wait until
Precondition
LWOFF flag is set)
The called functions rtc_configuration_mode_enter / rtc_configuration_mode_exit
Input parameter{in}
psc RTC prescaler value(0-0x000F FFFF)
Output parameter{out}
- -
Return value
- -

Example:

/* wait until last write operation on RTC registers has finished */

524
GD32E50x Firmware Library User Guide
rtc_lwoff_wait( );

/* set RTC prescaler value to 0x7FFFF */

rtc_prescaler_set (0x7FFFF);

rtc_alarm_config

The description of rtc_alarm_config is shown as below:

Table 3-733. Function rtc_alarm_config


Function name rtc_alarm_config
Function prototype void rtc_alarm_config(uint32_t alarm);
Function descriptions set RTC alarm value
before using this function, you must call rtc_lwoff_wait ( ) function (wait until
Precondition
LWOFF flag is set). -
The called functions rtc_configuration_mode_enter / rtc_configuration_mode_exit
Input parameter{in}
alarm RTC alarm value(0-0xFFFF FFFF)
Output parameter{out}
- -
Return value
- -

Example:

/* wait until last write operation on RTC registers has finished */

rtc_lwoff_wait( );

/* set alarm value to 0xFFFF */

rtc_alarm_config (0xFFFF);

rtc_divider_get

The description of rtc_divider_get is shown as below:

Table 3-734. Function rtc_divider_get


Function name rtc_divider_get
Function prototype uint32_t rtc_divider_get(void);
Function descriptions get RTC divider value
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -

525
GD32E50x Firmware Library User Guide
Return value
uint32_t the value of RTC divider

Example:

/* get the current RTC divider value */

uint32_t rtc_divider_value;

rtc_divider_value = rtc_divider_get ( );

rtc_interrupt_enable

The description of rtc_interrupt_enable is shown as below:

Table 3-735. Function rtc_interrupt_enable


Function name rtc_interrupt_enable
Function prototype void rtc_interrupt_enable(uint32_t interrupt);
Function descriptions enable RTC interrupt
before using this function, you must call rtc_lwoff_wait ( ) function (wait until
Precondition
LWOFF flag is set).
The called functions -
Input parameter{in}
interrupt specify which RTC interrupt to enable
RTC_INT_SECOND second interrupt
RTC_INT_ALARM alarm interrupt
RTC_INT_OVERFLOW overflow interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* wait until last write operation on RTC registers has finished */

rtc_lwoff_wait( );

/* enable the RTC second interrupt */

rtc_interrupt_enable(RTC_INT_SECOND);

rtc_interrupt_disable

The description of rtc_interrupt_disable is shown as below:

Table 3-736. Function rtc_interrupt_disable


Function name rtc_interrupt_disable
Function prototype void rtc_interrupt_disable(uint32_t interrupt);

526
GD32E50x Firmware Library User Guide
Function descriptions disable RTC interrupt
before using this function, you must call rtc_lwoff_wait ( ) function (wait until
Precondition
LWOFF flag is set).
The called functions -
Input parameter{in}
interrupt specify which RTC interrupt to disable
RTC_INT_SECOND second interrupt
RTC_INT_ALARM alarm interrupt
RTC_INT_OVERFLOW overflow interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* wait until last write operation on RTC registers has finished */

rtc_lwoff_wait( );

/* disable the RTC second interrupt */

rtc_interrupt_disable(RTC_INT_SECOND);

rtc_flag_get

The description of rtc_flag_getrtc_interrupt_enable is shown as below:

Table 3-737. Function rtc_flag_get


Function name rtc_flag_get
Function prototype FlagStatus rtc_flag_get(uint32_t flag);
Function descriptions get RTC flag status
Precondition -
The called functions -
Input parameter{in}
flag specify which RTC flag status to get
RTC_FLAG_SECOND second interrupt flag
RTC_FLAG_ALARM alarm interrupt flag
RTC_FLAG_OVERFLO
overflow interrupt flag
W
RTC_FLAG_RSYN registers synchronized flag
RTC_FLAG_LWOF last write operation finished flag
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

527
GD32E50x Firmware Library User Guide
Example:

/* get the RTC overflow interrupt status */

FlagStatus alarm_status;

alarm_status = rtc_flag_get (RTC_FLAG_ALARM);

rtc_flag_clear

The description of rtc_flag_clear is shown as below:

Table 3-738. Function rtc_flag_clear


Function name rtc_flag_clear
Function prototype void rtc_flag_clear(uint32_t flag);
Function descriptions clear RTC flag status
Precondition -
The called functions -
Input parameter{in}
flag specify which RTC flag status to clear
RTC_FLAG_SECOND second interrupt flag
RTC_FLAG_ALARM alarm interrupt flag
RTC_FLAG_OVERFLO
overflow interrupt flag
W
RTC_FLAG_RSYN registers synchronized flag
Output parameter{out}
- -
Return value
- -

Example:

/* clear the RTC alarm flag */

rtc_flag_clear (RTC_FLAG_ALARM);

3.22. SDIO

The secure digital input/output interface (SDIO) defines the SD/SD I/O /MMC CE-ATA card
host interface, which provides command/data transfer between the AHB system bus and SD
memory cards, SD I/O cards, Multimedia Card (MMC), and CE-ATA devices. The SDIO
registers are listed in chapter 3.22.1, the SDIO firmware functions are introduced in chapter
3.22.2.

3.22.1. Descriptions of Peripheral registers

SDIO registers are listed in the table shown as below:


528
GD32E50x Firmware Library User Guide
Table 3-739. SDIO Registers
Registers Descriptions
SDIO_PWRCTL Power control register
SDIO_CLKCTL Clock control register
SDIO_CMDAGMT Command argument register
SDIO_CMDCTL Command control register
SDIO_RSPCMDIDX Command index response register
SDIO_RESPx
Response register
x=0..3
SDIO_DATATO Data timeout register
SDIO_DATALEN Data length register
SDIO_DATACTL Data control register
SDIO_DATACNT Data counter register
SDIO_STAT Status register
SDIO_INTC Interrupt clear register
SDIO_INTEN Interrupt enable register
SDIO_FIFOCNT FIFO counter register
SDIO_FIFO FIFO data register

3.22.2. Descriptions of Peripheral functions

SDIO firmware functions are listed in the table shown as below:

Table 3-740. SDIO firmware function


Function name Function description
sdio_deinit deinitialize the SDIO
sdio_clock_config configure the SDIO clock
sdio_hardware_clock_enable enable hardware clock control
sdio_hardware_clock_disable disable hardware clock control
sdio_bus_mode_set set different SDIO card bus mode
sdio_power_state_set set the SDIO power state
sdio_power_state_get get the SDIO power state
sdio_clock_enable enable SDIO_CLK clock output
sdio_clock_disable disable SDIO_CLK clock output
sdio_command_response_config configure the command and response
sdio_wait_type_set set the command state machine wait type
sdio_csm_enable enable the CSM(command state machine)
sdio_csm_disable disable the CSM(command state machine)
sdio_command_index_get get the last response command index
sdio_response_get get the response for the last received command
sdio_data_config configure the data timeout, data length and data block size
sdio_data_transfer_config configure the data transfer mode and direction
sdio_dsm_enable enable the DSM(data state machine) for data transfer

529
GD32E50x Firmware Library User Guide
Function name Function description
sdio_dsm_disable disable the DSM(data state machine)
sdio_data_write write data(one word) to the transmit FIFO
sdio_data_read read data(one word) from the receive FIFO
get the number of remaining data bytes to be transferred to
sdio_data_counter_get
card
get the number of words remaining to be written or read from
sdio_fifo_counter_get
FIFO
sdio_dma_enable enable the DMA request for SDIO
sdio_dma_disable disable the DMA request for SDIO
sdio_flag_get get the flags state of SDIO
sdio_flag_clear clear the pending flags of SDIO
sdio_interrupt_enable enable the SDIO interrupt
sdio_interrupt_disable disable the SDIO interrupt
sdio_interrupt_flag_get get the interrupt flags state of SDIO
sdio_interrupt_flag_clear clear the interrupt pending flags of SDIO
sdio_readwait_enable enable the read wait mode(SD I/O only)
sdio_readwait_disable disable the read wait mode(SD I/O only)
enable the function that stop the read wait process(SD I/O
sdio_stop_readwait_enable
only)
disable the function that stop the read wait process(SD I/O
sdio_stop_readwait_disable
only)
sdio_readwait_type_set set the read wait type(SD I/O only)
sdio_operation_enable enable the SD I/O mode specific operation(SD I/O only)
sdio_operation_disable disable the SD I/O mode specific operation(SD I/O only)
sdio_suspend_enable enable the SD I/O suspend operation(SD I/O only)
sdio_suspend_disable disable the SD I/O suspend operation(SD I/O only)
sdio_ceata_command_enable enable the CE-ATA command(CE-ATA only)
sdio_ceata_command_disable disable the CE-ATA command(CE-ATA only)
sdio_ceata_interrupt_enable enable the CE-ATA interrupt(CE-ATA only)
sdio_ceata_interrupt_disable disable the CE-ATA interrupt(CE-ATA only)
sdio_ceata_command_completion_en enable the CE-ATA command completion signal(CE-ATA
able only)
sdio_ceata_command_completion_dis disable the CE-ATA command completion signal(CE-ATA
able only)

sdio_deinit

The description of sdio_deinit is shown as below:

Table 3-741. Function sdio_deinit


Function name sdio_deinit
Function prototype void sdio_deinit(void);
Function descriptions deinitialize the SDIO
530
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* deinitialize the SDIO */

sdio_deinit();

sdio_clock_config

The description of sdio_clock_config is shown as below:

Table 3-742. Function sdio_clock_config


Function name sdio_clock_config
void sdio_clock_config(uint32_t clock_edge, uint32_t clock_bypass,
Function prototype
uint32_t clock_powersave, uint16_t clock_division);
Function descriptions configure the SDIO clock
Precondition -
The called functions -
Input parameter{in}
clock_edge SDIO_CLK clock edge
SDIO_SDIOCLKEDGE
select the rising edge of the SDIOCLK to generate SDIO_CLK
_RISING
SDIO_SDIOCLKEDGE
select the falling edge of the SDIOCLK to generate SDIO_CLK
_FALLING
Input parameter{in}
clock_bypass clock bypass
SDIO_CLOCKBYPASS
clock bypass
_ENABLE
SDIO_CLOCKBYPASS
no bypass
_DISABLE
Input parameter{in}
clock_powersave SDIO_CLK clock dynamic switch on/off for power saving
SDIO_CLOCKPWRSA
SDIO_CLK closed when bus is idle
VE_ENABLE
SDIO_CLOCKPWRSA
SDIO_CLK clock is always on
VE_DISABLE
Input parameter{in}

531
GD32E50x Firmware Library User Guide
clock_division clock division, less than 512
Output parameter{out}
- -
Return value
- -

Example:

/* configure the SDIO clock */

sdio_clock_config(SDIO_SDIOCLKEDGE_RISING, SDIO_CLOCKBYPASS_DISABLE,
SDIO_CLOCKPWRSAVE_DISABLE, SD_CLK_DIV_TRANS);

sdio_hardware_clock_enable

The description of sdio_hardware_clock_enable is shown as below:

Table 3-743. Function sdio_hardware_clock_enable


Function name sdio_hardware_clock_enable
Function prototype void sdio_hardware_clock_enable(void);
Function descriptions enable hardware clock control
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable hardware clock control */

sdio_hardware_clock_enable();

sdio_hardware_clock_disable

The description of sdio_hardware_clock_disable is shown as below:

Table 3-744. Function sdio_hardware_clock_disable


Function name sdio_hardware_clock_disable
Function prototype void sdio_hardware_clock_disable(void);
Function descriptions disable hardware clock control
Precondition -
The called functions -
Input parameter{in}
- -
532
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* disable hardware clock control */

sdio_hardware_clock_disable();

sdio_bus_mode_set

The description of sdio_bus_mode_set is shown as below:

Table 3-745. Function sdio_bus_mode_set


Function name sdio_bus_mode_set
Function prototype void sdio_bus_mode_set(uint32_t bus_mode);
Function descriptions set different SDIO card bus mode
Precondition -
The called functions -
Input parameter{in}
bus_mode SDIO card bus mode
SDIO_BUSMODE_1BI
1-bit SDIO card bus mode
T
SDIO_BUSMODE_4BI
4-bit SDIO card bus mode
T
SDIO_BUSMODE_8BI
8-bit SDIO card bus mode
T
Output parameter{out}
- -
Return value
- -

Example:

/* set SDIO bus mode */

sdio_bus_mode_set(SDIO_BUSMODE_1BIT);

sdio_power_state_set

The description of sdio_power_state_set is shown as below:

Table 3-746. Function sdio_power_state_set


Function name sdio_power_state_set
Function prototype void sdio_power_state_set(uint32_t power_state);
Function descriptions set the SDIO power state
533
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
power_state SDIO power state
SDIO_POWER_ON SDIO power on
SDIO_POWER_OFF SDIO power off
Output parameter{out}
- -
Return value
- -

Example:

/* set SDIO power state */

sdio_power_state_set(SDIO_POWER_ON);

sdio_power_state_get

The description of sdio_power_state_get is shown as below:

Table 3-747. Function sdio_power_state_get


Function name sdio_power_state_get
Function prototype uint32_t sdio_power_state_get(void);
Function descriptions get the SDIO power state
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t SDIO_POWER_ON / SDIO_POWER_OFF

Example:

/* get the SDIO power state */

uint32_t sdio_power_value;

sdio_power_value = sdio_power_state_get();

sdio_clock_enable

The description of sdio_clock_enable is shown as below:

Table 3-748. Function sdio_clock_enable


Function name sdio_clock_enable

534
GD32E50x Firmware Library User Guide
Function prototype void sdio_clock_enable(void);
Function descriptions enable SDIO_CLK clock output
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable SDIO_CLK clock output */

sdio_clock_enable();

sdio_clock_disable

The description of sdio_clock_disable is shown as below:

Table 3-749. Function sdio_clock_disable


Function name sdio_clock_disable
Function prototype void sdio_clock_disable(void);
Function descriptions disable SDIO_CLK clock output
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable SDIO_CLK clock output */

sdio_clock_disable();

sdio_command_response_config

The description of sdio_command_response_config is shown as below:

Table 3-750. Function sdio_command_response_config


Function name sdio_command_response_config
void sdio_command_response_config(uint32_t cmd_index, uint32_t
Function prototype
cmd_argument, uint32_t response_type);
535
GD32E50x Firmware Library User Guide
Function descriptions configure the command and response
Precondition -
The called functions -
Input parameter{in}
cmd_index command index, refer to the related specifications
Input parameter{in}
cmd_argument command argument, refer to the related specifications
Input parameter{in}
response_type response type
SDIO_RESPONSETYP
no response
E_NO
SDIO_RESPONSETYP
short response
E_SHORT
SDIO_RESPONSETYP
long response
E_LONG
Output parameter{out}
- -
Return value
- -

Example:

/* CMD2(SD_CMD_ALL_SEND_CID) command response config*/

sdio_command_response_config(SD_CMD_ALL_SEND_CID, (uint32_t)0x0,
SDIO_RESPONSETYPE_LONG);

sdio_wait_type_set

The description of sdio_wait_type_set is shown as below:

Table 3-751. Function sdio_wait_type_set


Function name sdio_wait_type_set
Function prototype void sdio_wait_type_set(uint32_t wait_type);
Function descriptions set the command state machine wait type
Precondition -
The called functions -
Input parameter{in}
wait_type wait type
SDIO_WAITTYPE_NO not wait interrupt
SDIO_WAITTYPE_INT
wait interrupt
ERRUPT
SDIO_WAITTYPE_DAT
wait the end of data transfer
AEND
Output parameter{out}

536
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* set the command state machine wait type */

sdio_wait_type_set(SDIO_WAITTYPE_NO);

sdio_csm_enable

The description of sdio_csm_enable is shown as below:

Table 3-752. Function sdio_csm_enable


Function name sdio_csm_enable
Function prototype void sdio_csm_enable(void);
Function descriptions enable the CSM(command state machine)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the CSM(command state machine) */

sdio_csm_enable();

sdio_csm_disable

The description of sdio_csm_disable is shown as below:

Table 3-753. Function sdio_csm_disable


Function name sdio_csm_disable
Function prototype void sdio_csm_disable(void);
Function descriptions disable the CSM(command state machine)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
537
GD32E50x Firmware Library User Guide
- -

Example:

/* disable the CSM(command state machine) */

sdio_csm_disable();

sdio_command_index_get

The description of sdio_command_index_get is shown as below:

Table 3-754. Function sdio_command_index_get


Function name sdio_command_index_get
Function prototype uint8_t sdio_command_index_get(void);
Function descriptions get the last response command index
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint8_t last response command index

Example:

/* get SDIO command index */

uint8_t sdio_commond_value;

sdio_commond_value = sdio_command_index_get();

sdio_response_get

The description of sdio_response_get is shown as below:

Table 3-755. Function sdio_response_get


Function name sdio_response_get
Function prototype uint32_t sdio_response_get(uint32_t responsex);
Function descriptions get the response for the last received command
Precondition -
The called functions -
Input parameter{in}
responsex SDIO response
SDIO_RESPONSE0 card response[31:0]/card response[127:96]
SDIO_RESPONSE1 card response[95:64]
SDIO_RESPONSE2 card response[63:32]

538
GD32E50x Firmware Library User Guide
SDIO_RESPONSE3 card response[31:1], plus bit 0
Output parameter{out}
- -
Return value
uint32_t response for the last received command

Example:

/* store the CID0 numbers */

uint32_t sdio_cid[0];

sdio_cid[0] = sdio_response_get(SDIO_RESPONSE0);

sdio_data_config

The description of sdio_data_config is shown as below:

Table 3-756. Function sdio_data_config


Function name sdio_data_config
void sdio_data_config(uint32_t data_timeout, uint32_t data_length, uint32_t
Function prototype
data_blocksize);
Function descriptions configure the data timeout, data length and data block size
Precondition -
The called functions -
Input parameter{in}
data_timeout data timeout period in card bus clock periods
Input parameter{in}
data_length number of data bytes to be transferred
Input parameter{in}
data_blocksize size of data block for block transfer
SDIO_DATABLOCKSIZ
block size = 1 byte
E_1BYTE
SDIO_DATABLOCKSIZ
block size = 2 bytes
E_2BYTES
SDIO_DATABLOCKSIZ
block size = 4 bytes
E_4BYTES
SDIO_DATABLOCKSIZ
block size = 8 bytes
E_8BYTES
SDIO_DATABLOCKSIZ
block size = 16 bytes
E_16BYTES
SDIO_DATABLOCKSIZ
block size = 32 bytes
E_32BYTES
SDIO_DATABLOCKSIZ
block size = 64 bytes
E_64BYTES
SDIO_DATABLOCKSIZ block size = 128 bytes

539
GD32E50x Firmware Library User Guide
E_128BYTES
SDIO_DATABLOCKSIZ
block size = 256 bytes
E_256BYTES
SDIO_DATABLOCKSIZ
block size = 512 bytes
E_512BYTES
SDIO_DATABLOCKSIZ
block size = 1024 bytes
E_1024BYTES
SDIO_DATABLOCKSIZ
block size = 2048 bytes
E_2048BYTES
SDIO_DATABLOCKSIZ
block size = 4096 bytes
E_4096BYTES
SDIO_DATABLOCKSIZ
block size = 8192 bytes
E_8192BYTES
SDIO_DATABLOCKSIZ
block size = 16384 bytes
E_16384BYTES
Output parameter{out}
- -
Return value
- -

Example:

/* configure SDIO data */

sdio_data_config(0, 0, SDIO_DATABLOCKSIZE_1BYTE);

sdio_data_transfer_config

The description of sdio_data_transfer_config is shown as below:

Table 3-757. Function sdio_data_transfer_config


Function name sdio_data_transfer_config
void sdio_data_transfer_config(uint32_t transfer_mode, uint32_t
Function prototype
transfer_direction);
Function descriptions configure the data transfer mode and direction
Precondition -
The called functions -
Input parameter{in}
transfer_mode mode of data transfer
SDIO_TRANSMODE_B
block transfer
LOCK
SDIO_TRANSMODE_S
stream transfer or SDIO multibyte transfer
TREAM
Input parameter{in}
transfer_direction data transfer direction, read or write

540
GD32E50x Firmware Library User Guide
SDIO_TRANSDIRECTI
write data to card
ON_TOCARD
SDIO_TRANSDIRECTI
read data from card
ON_TOSDIO
Output parameter{out}
- -
Return value
- -

Example:

/* configure SDIO data transmisson */

sdio_data_transfer_config(SDIO_TRANSDIRECTION_TOSDIO,
SDIO_TRANSMODE_BLOCK);

sdio_dsm_enable

The description of sdio_dsm_enable is shown as below:

Table 3-758. Function sdio_dsm_enable


Function name sdio_dsm_enable
Function prototype void sdio_dsm_enable(void);
Function descriptions enable the DSM(data state machine) for data transfer
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the DSM(data state machine) */

sdio_dsm_enable();

sdio_dsm_disable

The description of sdio_dsm_disable is shown as below:

Table 3-759. Function sdio_dsm_disable


Function name sdio_dsm_disable
Function prototype void sdio_dsm_disable(void);
Function descriptions disable the DSM(data state machine)
Precondition -
541
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the DSM(data state machine) */

sdio_dsm_disable();

sdio_data_write

The description of sdio_data_write is shown as below:

Table 3-760. Function sdio_data_write


Function name sdio_data_write
Function prototype void sdio_data_write(uint32_t data);
Function descriptions write data(one word) to the transmit FIFO
Precondition -
The called functions -
Input parameter{in}
data 32-bit data write to card
Output parameter{out}
- -
Return value
- -

Example:

/* write data(one word) to the transmit FIFO */

sdio_data_write(0x0000 0001);

sdio_data_read

The description of sdio_data_read is shown as below:

Table 3-761. Function sdio_data_read


Function name sdio_data_read
Function prototype uint32_t sdio_data_read(void);
Function descriptions read data(one word) from the receive FIFO
Precondition -
The called functions -
Input parameter{in}
542
GD32E50x Firmware Library User Guide
- -
Output parameter{out}
- -
Return value
uint32_t received data

Example:

/* read data(one word) from the receive FIFO */

sdio_data_read();

sdio_data_counter_get

The description of sdio_data_counter_get is shown as below:

Table 3-762. Function sdio_data_counter_get


Function name sdio_data_counter_get
Function prototype uint32_t sdio_data_counter_get(void);
Function descriptions get the number of remaining data bytes to be transferred to card
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t number of remaining data bytes to be transferred

Example:

/* get the number of remaining data bytes to be transferred to card */

uint32_t sdio_data_value;

sdio_data_value = sdio_data_counter_get();

sdio_fifo_counter_get

The description of sdio_fifo_counter_get is shown as below:

Table 3-763. Function sdio_data_counter_get


Function name sdio_fifo_counter_get
Function prototype uint32_t sdio_fifo_counter_get(void);
Function descriptions get the number of words remaining to be written or read from FIFO
Precondition -
The called functions -
Input parameter{in}

543
GD32E50x Firmware Library User Guide
- -
Output parameter{out}
- -
Return value
uint32_t remaining number of words

Example:

/* get the number of words remaining to be written or read from FIFO */

uint32_t sdio_fifo_value;

sdio_fifo_value = sdio_fifo_counter_get();

sdio_dma_enable

The description of sdio_dma_enable is shown as below:

Table 3-764. Function sdio_dma_enable


Function name sdio_dma_enable
Function prototype void sdio_dma_enable(void);
Function descriptions enable the DMA request for SDIO
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the SDIO DMA */

sdio_dma_enable();

sdio_dma_disable

The description of sdio_dma_disable is shown as below:

Table 3-765. Function sdio_dma_disable


Function name sdio_dma_disable
Function prototype void sdio_dma_disable(void);
Function descriptions disable the DMA request for SDIO
Precondition -
The called functions -
Input parameter{in}

544
GD32E50x Firmware Library User Guide
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the SDIO DMA */

sdio_dma_disable();

sdio_flag_get

The description of sdio_flag_get is shown as below:

Table 3-766. Function sdio_flag_get


Function name sdio_flag_get
Function prototype FlagStatus sdio_flag_get(uint32_t flag);
Function descriptions get the flags state of SDIO
Precondition -
The called functions -
Input parameter{in}
flag flags state of SDIO
SDIO_FLAG_CCRCER
command response received (CRC check failed) flag
R
SDIO_FLAG_DTCRCE
data block sent/received (CRC check failed) flag
RR
SDIO_FLAG_CMDTMO
command response timeout flag
UT
SDIO_FLAG_DTTMOU
data timeout flag
T
SDIO_FLAG_TXURE transmit FIFO underrun error occurs flag
SDIO_FLAG_RXORE received FIFO overrun error occurs flag
SDIO_FLAG_CMDREC
command response received (CRC check passed) flag
V
SDIO_FLAG_CMDSEN
command sent (no response required) flag
D
SDIO_FLAG_DTEND data end (data counter, SDIO_DATACNT, is zero) flag
SDIO_FLAG_STBITE start bit error in the bus flag
SDIO_FLAG_DTBLKE
data block sent/received (CRC check passed) flag
ND
SDIO_FLAG_CMDRUN command transmission in progress flag
SDIO_FLAG_TXRUN data transmission in progress flag
SDIO_FLAG_RXRUN data reception in progress flag

545
GD32E50x Firmware Library User Guide
transmit FIFO is half empty flag: at least 8 words can be written into the
SDIO_FLAG_TFH
FIFO
SDIO_FLAG_RFH receive FIFO is half full flag: at least 8 words can be read in the FIFO
SDIO_FLAG_TFF transmit FIFO is full flag
SDIO_FLAG_RFF receive FIFO is full flag
SDIO_FLAG_TFE transmit FIFO is empty flag
SDIO_FLAG_RFE receive FIFO is empty flag
SDIO_FLAG_TXDTVAL data is valid in transmit FIFO flag
SDIO_FLAG_RXDTVA
data is valid in receive FIFO flag
L
SDIO_FLAG_SDIOINT SD I/O interrupt received flag
SDIO_FLAG_ATAEND CE-ATA command completion signal received (only for CMD61) flag
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the flags state of SDIO */

FlagStatus flag_value;

flag_value = sdio_flag_get(SDIO_FLAG_RFH);

sdio_flag_clear

The description of sdio_flag_clear is shown as below:

Table 3-767. Function sdio_flag_clear


Function name sdio_flag_clear
Function prototype void sdio_flag_clear(uint32_t flag);
Function descriptions clear the pending flags of SDIO
Precondition -
The called functions -
Input parameter{in}
flag flags state of SDIO
SDIO_FLAG_CCRCER
command response received (CRC check failed) flag
R
SDIO_FLAG_DTCRCE
data block sent/received (CRC check failed) flag
RR
SDIO_FLAG_CMDTMO
command response timeout flag
UT
SDIO_FLAG_DTTMOU
data timeout flag
T
SDIO_FLAG_TXURE transmit FIFO underrun error occurs flag
546
GD32E50x Firmware Library User Guide
SDIO_FLAG_RXORE received FIFO overrun error occurs flag
SDIO_FLAG_CMDREC
command response received (CRC check passed) flag
V
SDIO_FLAG_CMDSEN
command sent (no response required) flag
D
SDIO_FLAG_DTEND data end (data counter, SDIO_DATACNT, is zero) flag
SDIO_FLAG_STBITE start bit error in the bus flag
SDIO_FLAG_DTBLKE
data block sent/received (CRC check passed) flag
ND
SDIO_FLAG_SDIOINT SD I/O interrupt received flag
SDIO_FLAG_ATAEND CE-ATA command completion signal received (only for CMD61) flag
Output parameter{out}
- -
Return value
- -

Example:

/* clear the pending flags of SDIO */

sdio_flag_clear(SDIO_FLAG_DTCRCERR);

sdio_interrupt_enable

The description of sdio_interrupt_enable is shown as below:

Table 3-768. Function sdio_interrupt_enable


Function name sdio_interrupt_enable
Function prototype void sdio_interrupt_enable(uint32_t int_flag);
Function descriptions enable the SDIO interrupt
Precondition -
The called functions -
Input parameter{in}
int_flag interrupt flags state of SDIO
SDIO_INT_CCRCERR SDIO CCRCERR interrupt
SDIO_INT_DTCRCER
SDIO DTCRCERR interrupt
R
SDIO_INT_CMDTMOU
SDIO CMDTMOUT interrupt
T
SDIO_INT_DTTMOUT SDIO DTTMOUT interrupt
SDIO_INT_TXURE SDIO TXURE interrupt
SDIO_INT_RXORE SDIO_INT_RXORE
SDIO_INT_CMDRECV SDIO CMDRECV interrupt
SDIO_INT_CMDSEND SDIO CMDSEND interrupt
SDIO_INT_DTEND SDIO DTEND interrupt

547
GD32E50x Firmware Library User Guide
SDIO_INT_STBITE SDIO STBITE interrupt
SDIO_INT_DTBLKEND SDIO DTBLKEND interrupt
SDIO_INT_CMDRUN SDIO CMDRUN interrupt
SDIO_INT_TXRUN SDIO TXRUN interrupt
SDIO_INT_RXRUN SDIO RXRUN interrupt
SDIO_INT_TFH SDIO TFH interrupt
SDIO_INT_RFH SDIO RFH interrupt
SDIO_INT_TFF SDIO TFF interrupt
SDIO_INT_RFF SDIO RFF interrupt
SDIO_INT_TFE SDIO TFE interrupt
SDIO_INT_RFE SDIO RFE interrupt
SDIO_INT_TXDTVAL SDIO TXDTVAL interrupt
SDIO_INT_RXDTVAL SDIO RXDTVAL interrupt
SDIO_INT_SDIOINT SDIO SDIOINT interrupt
SDIO_INT_ATAEND SDIO ATAEND interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* enable the SDIO corresponding interrupts */

sdio_interrupt_enable(SDIO_INT_CCRCERR | SDIO_INT_DTTMOUT | SDIO_INT_RXORE


| SDIO_INT_DTEND | SDIO_INT_STBITE);

sdio_interrupt_disable

The description of sdio_interrupt_disable is shown as below:

Table 3-769. Function sdio_interrupt_disable


Function name sdio_interrupt_disable
Function prototype void sdio_interrupt_disable(uint32_t int_flag);
Function descriptions disable the SDIO interrupt
Precondition -
The called functions -
Input parameter{in}
int_flag interrupt flags state of SDIO
SDIO_INT_CCRCERR SDIO CCRCERR interrupt
SDIO_INT_DTCRCER
SDIO DTCRCERR interrupt
R
SDIO_INT_CMDTMOU
SDIO CMDTMOUT interrupt
T
SDIO_INT_DTTMOUT SDIO DTTMOUT interrupt

548
GD32E50x Firmware Library User Guide
SDIO_INT_TXURE SDIO TXURE interrupt
SDIO_INT_RXORE SDIO_INT_RXORE
SDIO_INT_CMDRECV SDIO CMDRECV interrupt
SDIO_INT_CMDSEND SDIO CMDSEND interrupt
SDIO_INT_DTEND SDIO DTEND interrupt
SDIO_INT_STBITE SDIO STBITE interrupt
SDIO_INT_DTBLKEND SDIO DTBLKEND interrupt
SDIO_INT_CMDRUN SDIO CMDRUN interrupt
SDIO_INT_TXRUN SDIO TXRUN interrupt
SDIO_INT_RXRUN SDIO RXRUN interrupt
SDIO_INT_TFH SDIO TFH interrupt
SDIO_INT_RFH SDIO RFH interrupt
SDIO_INT_TFF SDIO TFF interrupt
SDIO_INT_RFF SDIO RFF interrupt
SDIO_INT_TFE SDIO TFE interrupt
SDIO_INT_RFE SDIO RFE interrupt
SDIO_INT_TXDTVAL SDIO TXDTVAL interrupt
SDIO_INT_RXDTVAL SDIO RXDTVAL interrupt
SDIO_INT_SDIOINT SDIO SDIOINT interrupt
SDIO_INT_ATAEND SDIO ATAEND interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* disable the SDIO interrupt */

sdio_interrupt_disable(SDIO_INT_DTCRCERR);

sdio_interrupt_flag_get

The description of sdio_interrupt_flag_get is shown as below:

Table 3-770. Function sdio_interrupt_flag_get


Function name sdio_interrupt_flag_get
Function prototype FlagStatus sdio_interrupt_flag_get(uint32_t int_flag);
Function descriptions get the interrupt flags state of SDIO
Precondition -
The called functions -
Input parameter{in}
int_flag interrupt flags state of SDIO
SDIO_INT_FLAG_CCR
SDIO CCRCERR interrupt flag
CERR

549
GD32E50x Firmware Library User Guide
SDIO_INT_FLAG_DTC
SDIO DTCRCERR interrupt flag
RCERR
SDIO_INT_FLAG_CMD
SDIO CMDTMOUT interrupt flag
TMOUT
SDIO_INT_FLAG_DTT
SDIO DTTMOUT interrupt flag
MOUT
SDIO_INT_FLAG_TXU
SDIO TXURE interrupt flag
RE
SDIO_INT_FLAG_RXO
SDIO_INT_RXORE flag
RE
SDIO_INT_FLAG_CMD
SDIO CMDRECV interrupt flag
RECV
SDIO_INT_FLAG_CMD
SDIO CMDSEND interrupt flag
SEND
SDIO_INT_FLAG_DTE
SDIO DTEND interrupt flag
ND
SDIO_INT_FLAG_STBI
SDIO STBITE interrupt flag
TE
SDIO_INT_FLAG_DTB
SDIO DTBLKEND interrupt flag
LKEND
SDIO_INT_FLAG_CMD
SDIO CMDRUN interrupt flag
RUN
SDIO_INT_FLAG_TXR
SDIO TXRUN interrupt flag
UN
SDIO_INT_FLAG_RXR
SDIO RXRUN interrupt flag
UN
SDIO_INT_FLAG_TFH SDIO TFH interrupt flag
SDIO_INT_FLAG_RFH SDIO RFH interrupt flag
SDIO_INT_FLAG_TFF SDIO TFF interrupt flag
SDIO_INT_FLAG_RFF SDIO RFF interrupt flag
SDIO_INT_FLAG_TFE SDIO TFE interrupt flag
SDIO_INT_FLAG_RFE SDIO RFE interrupt flag
SDIO_INT_FLAG_TXD
SDIO TXDTVAL interrupt flag
TVAL
SDIO_INT_FLAG_RXD
SDIO RXDTVAL interrupt flag
TVAL
SDIO_INT_FLAG_SDI
SDIO SDIOINT interrupt flag
OINT
SDIO_INT_FLAG_ATA
SDIO ATAEND interrupt flag
END
Output parameter{out}
- -
Return value

550
GD32E50x Firmware Library User Guide
FlagStatus SET or RESET

Example:

/* get the interrupt flags state of SDIO */

FlagStatus flag_value;

flag_value = sdio_interrupt_flag_get(SDIO_INT_FLAG_DTEND);

sdio_interrupt_flag_clear

The description of sdio_interrupt_flag_clear is shown as below:

Table 3-771. Function sdio_interrupt_flag_clear


Function name sdio_interrupt_flag_clear
Function prototype void sdio_interrupt_flag_clear(uint32_t int_flag);
Function descriptions clear the interrupt pending flags of SDIO
Precondition -
The called functions -
Input parameter{in}
int_flag interrupt flags state of SDIO
SDIO_INT_FLAG_CCR
command response received (CRC check failed) flag
CERR
SDIO_INT_FLAG_DTC
data block sent/received (CRC check failed) flag
RCERR
SDIO_INT_FLAG_CMD
command response timeout flag
TMOUT
SDIO_INT_FLAG_DTT
data timeout flag
MOUT
SDIO_INT_FLAG_TXU
transmit FIFO underrun error occurs flag
RE
SDIO_INT_FLAG_RXO
received FIFO overrun error occurs flag
RE
SDIO_INT_FLAG_CMD
command response received (CRC check passed) flag
RECV
SDIO_INT_FLAG_CMD
command sent (no response required) flag
SEND
SDIO_INT_FLAG_DTE
data end (data counter, SDIO_DATACNT, is zero) flag
ND
SDIO_INT_FLAG_STBI
start bit error in the bus flag
TE
SDIO_INT_FLAG_DTB
data block sent/received (CRC check passed) flag
LKEND
SDIO_INT_FLAG_SDI
SD I/O interrupt received flag
OINT

551
GD32E50x Firmware Library User Guide
SDIO_INT_FLAG_ATA
CE-ATA command completion signal received (only for CMD61) flag
END
Output parameter{out}
- -
Return value
- -

Example:

/* clear the interrupt pending flags of SDIO */

sdio_interrupt_flag_clear(SDIO_INT_FLAG_DTEND);

sdio_readwait_enable

The description of sdio_readwait_enable is shown as below:

Table 3-772. Function sdio_readwait_enable


Function name sdio_readwait_enable
Function prototype void sdio_readwait_enable(void);
Function descriptions enable the read wait mode(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the read wait mode(SD I/O only) */

sdio_readwait_enable();

sdio_readwait_disable

The description of sdio_readwait_disable is shown as below:

Table 3-773. Function sdio_readwait_disable


Function name sdio_readwait_disable
Function prototype void sdio_readwait_disable(void);
Function descriptions disable the read wait mode(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
- -
552
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* disable the read wait mode(SD I/O only) */

sdio_readwait_disable();

sdio_stop_readwait_enable

The description of sdio_stop_readwait_enable is shown as below:

Table 3-774. Function sdio_stop_readwait_enable


Function name sdio_stop_readwait_enable
Function prototype void sdio_stop_readwait_enable(void);
Function descriptions enable the function that stop the read wait process(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the function that stop the read wait process(SD I/O only) */

sdio_stop_readwait_enable();

sdio_stop_readwait_disable

The description of sdio_stop_readwait_disable is shown as below:

Table 3-775. Function sdio_stop_readwait_disable


Function name sdio_stop_readwait_disable
Function prototype void sdio_stop_readwait_disable(void);
Function descriptions disable the function that stop the read wait process(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
553
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* disable the function that stop the read wait process(SD I/O only) */

sdio_stop_readwait_disable();

sdio_readwait_type_set

The description of sdio_readwait_type_set is shown as below:

Table 3-776. Function sdio_readwait_type_set


Function name sdio_readwait_type_set
Function prototype void sdio_readwait_type_set(uint32_t readwait_type);
Function descriptions set the read wait type(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
readwait_type SD I/O read wait type
SDIO_READWAITTYP
read wait control by stopping SDIO_CLK
E_CLK
SDIO_READWAITTYP
read wait control using SDIO_DAT[2]
E_DAT2
Output parameter{out}
- -
Return value
- -

Example:

/* set the read wait type(SD I/O only) */

sdio_readwait_type_set(uint32_t readwait_type);

sdio_operation_enable

The description of sdio_operation_enable is shown as below:

Table 3-777. Function sdio_operation_enable


Function name sdio_operation_enable
Function prototype void sdio_operation_enable(void);
Function descriptions enable the SD I/O mode specific operation(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
- -
554
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* enable the SD I/O mode specific operation(SD I/O only) */

sdio_operation_enable();

sdio_operation_disable

The description of sdio_operation_disable is shown as below:

Table 3-778. Function sdio_operation_disable


Function name sdio_operation_disable
Function prototype void sdio_operation_disable(void);
Function descriptions disable the SD I/O mode specific operation(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the SD I/O mode specific operation(SD I/O only) */

void sdio_operation_disable();

sdio_suspend_enable

The description of sdio_suspend_enable is shown as below:

Table 3-779. Function sdio_suspend_enable


Function name sdio_suspend_enable
Function prototype void sdio_suspend_enable(void);
Function descriptions enable the SD I/O suspend operation(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
555
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* enable the SD I/O suspend operation(SD I/O only) */

sdio_suspend_enable();

sdio_suspend_disable

The description of sdio_suspend_disable is shown as below:

Table 3-780. Function sdio_suspend_disable


Function name sdio_suspend_disable
Function prototype void sdio_suspend_disable(void);
Function descriptions disable the SD I/O suspend operation(SD I/O only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the SD I/O suspend operation(SD I/O only) */

sdio_suspend_disable();

sdio_ceata_command_enable

The description of sdio_ceata_command_enable is shown as below:

Table 3-781. Function sdio_ceata_command_enable


Function name sdio_ceata_command_enable
Function prototype void sdio_ceata_command_enable(void);
Function descriptions enable the CE-ATA command(CE-ATA only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -
556
GD32E50x Firmware Library User Guide
Example:

/* enable the CE-ATA command(CE-ATA only) */

sdio_ceata_command_enable();

sdio_ceata_command_disable

The description of sdio_ceata_command_disable is shown as below:

Table 3-782. Function sdio_ceata_command_disable


Function name sdio_ceata_command_disable
Function prototype void sdio_ceata_command_disable(void);
Function descriptions disable the CE-ATA command(CE-ATA only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the CE-ATA command(CE-ATA only) */

sdio_ceata_command_disable();

sdio_ceata_interrupt_enable

The description of sdio_ceata_interrupt_enable is shown as below:

Table 3-783. Function sdio_ceata_interrupt_enable


Function name sdio_ceata_interrupt_enable
Function prototype void sdio_ceata_interrupt_enable(void);
Function descriptions enable the CE-ATA interrupt(CE-ATA only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

557
GD32E50x Firmware Library User Guide
/* enable the CE-ATA interrupt(CE-ATA only) */

sdio_ceata_interrupt_enable();

sdio_ceata_interrupt_disable

The description of sdio_ceata_interrupt_disable is shown as below:

Table 3-784. Function sdio_ceata_interrupt_disable


Function name sdio_ceata_interrupt_disable
Function prototype void sdio_ceata_interrupt_disable(void);
Function descriptions disable the CE-ATA interrupt(CE-ATA only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the CE-ATA interrupt(CE-ATA only) */

sdio_ceata_interrupt_disable();

sdio_ceata_command_completion_enable

The description of sdio_ceata_command_completion_enable is shown as below:

Table 3-785. Function sdio_ceata_command_completion_enable


Function name sdio_ceata_command_completion_enable
Function prototype void sdio_ceata_command_completion_enable(void);
Function descriptions enable the CE-ATA command completion signal(CE-ATA only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the CE-ATA command completion signal(CE-ATA only) */

558
GD32E50x Firmware Library User Guide
sdio_ceata_command_completion_enable();

sdio_ceata_command_completion_disable

The description of sdio_ceata_command_completion_disable is shown as below:

Table 3-786. Function sdio_ceata_command_completion_disable


Function name sdio_ceata_command_completion_disable
Function prototype void sdio_ceata_command_completion_disable(void);
Function descriptions disable the CE-ATA command completion signal(CE-ATA only)
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable the CE-ATA command completion signal(CE-ATA only) */

sdio_ceata_command_completion_disable();

3.23. SPI

The SPI/I2S module can communicate with external devices using the SPI protocol or the I2S
audio protocol. The SPI/I2S registers are listed in chapter 3.23.1, the SPI/I2S firmware
functions are introduced in chapter 3.23.2.

3.23.1. Descriptions of Peripheral registers

SPI/I2S registers are listed in the table shown as below:

Table 3-787. SPI/I2S Registers


Registers Descriptions
SPI_CTL0 SPI control register 0
SPI_CTL1 SPI control register 1
SPI_STAT SPI status register
SPI_DATA SPI data register
SPI_CRCPOLY SPI CRC polynomial register
SPI_RCRC SPI receive CRC register
SPI_TCRC SPI transmit CRC register
SPI_I2SCTL SPI/I2S control register

559
GD32E50x Firmware Library User Guide
Registers Descriptions
SPI_I2SPSC SPI/I2S clock prescaler register
SPI_QCTL Quad-SPI mode control register

3.23.2. Descriptions of Peripheral functions

SPI/I2S firmware functions are listed in the table shown as below:

Table 3-788. SPI/I2S firmware function


Function name Function description
spi_i2s_deinit reset SPI and I2S peripheral
spi_struct_para_init initialize the parameters of SPI struct with the default values
spi_init initialize SPI peripheral parameter
spi_enable enable SPI
spi_disable disable SPI
i2s_init initialize I2S peripheral parameter
i2s_psc_config configure I2S peripheral prescaler
i2s_enable enable I2S
i2s_disable disable I2S
spi_nss_output_enable enable SPI NSS output function
spi_nss_output_disable disable SPI NSS output function
spi_nss_internal_high SPI NSS pin high level in software mode
spi_nss_internal_low SPI NSS pin low level in software mode
spi_dma_enable enable SPI DMA function
spi_dma_disable disable SPI DMA function
spi_i2s_data_frame_format_config configure SPI/I2S data frame format
spi_i2s_data_transmit SPI transmit data
spi_i2s_data_receive SPI receive data
spi_bidirectional_transfer_config configure SPI bidirectional transfer direction
spi_crc_polynomial_set set SPI CRC polynomial
spi_crc_polynomial_get get SPI CRC polynomial
spi_crc_on turn on SPI CRC function
spi_crc_off turn off SPI CRC function
spi_crc_next SPI next data is CRC value
spi_crc_get get SPI CRC send value or receive value
spi_ti_mode_enable enable SPI TI mode
spi_ti_mode_disable disable SPI TI mode
spi_nssp_mode_enable enable SPI NSS pulse mode
spi_nssp_mode_disable disable SPI NSS pulse mode
i2s_full_duplex_mode_config configure i2s full duplex mode
qspi_enable enable quad wire SPI
qspi_disable disable quad wire SPI
qspi_write_enable enable quad wire SPI write

560
GD32E50x Firmware Library User Guide
Function name Function description
qspi_read_enable enable quad wire SPI read
qspi_io23_output_enable enable quad wire SPI_IO2 and SPI_IO3 pin output
qspi_io23_output_disable disable quad wire SPI_IO2 and SPI_IO3 pin output
spi_i2s_interrupt_enable enable SPI and I2S interrupt
spi_i2s_interrupt_disable disable SPI and I2S interrupt
spi_i2s_interrupt_flag_get get SPI and I2S interrupt status
spi_i2s_flag_get get SPI and I2S flag status
spi_crc_error_clear clear SPI CRC error flag status

Structure spi_parameter_struct

Table 3-789. spi_parameter_struct


Member name Function description
SPI master or slave
device_mode
(SPI_MASTER, SPI_SLAVE)
SPI transtype
trans_mode (SPI_TRANSMODE_FULLDUPLEX, SPI_TRANSMODE_RECEIVEONLY,
SPI_TRANSMODE_BDRECEIVE, SPI_TRANSMODE_BDTRANSMIT)
SPI frame size
frame_size
(SPI_FRAMESIZE_16BIT, SPI_FRAMESIZE_8BIT)
SPI NSS control by handware or software
nss
(SPI_NSS_SOFT, SPI_NSS_HARD)
SPI big endian or little endian
endian
(SPI_ENDIAN_MSB, SPI_ENDIAN_LSB)
SPI clock phase and polarity
clock_polarity_phas
(SPI_CK_PL_LOW_PH_1EDGE, SPI_CK_PL_HIGH_PH_1EDGE,
e
SPI_CK_PL_LOW_PH_2EDGE, SPI_CK_PL_HIGH_PH_2EDGE)
SPI prescale factor
prescale
(SPI_PSC_n (n=2,4,8,16,32,64,128,256))

spi_i2s_deinit

The description of spi_i2s_deinit is shown as below:

Table 3-790. Function spi_i2s_deinit


Function name spi_i2s_deinit
Function prototype void spi_i2s_deinit(uint32_t spi_periph);
Function descriptions reset SPI and I2S peripheral
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
spi_periph SPI/I2S peripheral
SPIx x=0,1,2

561
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* reset SPI0 */

spi_i2s_deinit(SPI0);

spi_struct_para_init

The description of spi_struct_para_init is shown as below:

Table 3-791. Function spi_struct_para_init


Function name spi_struct_para_init
Function prototype void spi_struct_para_init(spi_parameter_struct* spi_struct);
Function descriptions initialize the parameters of SPI struct with the default values
Precondition -
The called functions -
Input parameter{in}
*spi_struct a spi_parameter_struct address
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the parameters of SPI */

spi_parameter_struct spi_init_struct;

spi_struct_para_init(&spi_init_struct);

spi_init

The description of spi_init is shown as below:

Table 3-792. Function spi_init


Function name spi_init
Function prototype void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct);
Function descriptions initialize SPI peripheral parameter
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral

562
GD32E50x Firmware Library User Guide
SPIx x=0,1,2
Input parameter{in}
SPI parameter initialization stuct, the structure members can refer to
spi_struct
members of the structure Table 3-789. spi_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize SPI0 */

spi_parameter_struct spi_init_struct;

spi_init_struct.trans_mode = SPI_TRANSMODE_BDTRANSMIT;

spi_init_struct.device_mode = SPI_MASTER;

spi_init_struct.frame_size = SPI_FRAMESIZE_8BIT;

spi_init_struct.clock_polarity_phase = SPI_CK_PL_HIGH_PH_2EDGE;

spi_init_struct.nss = SPI_NSS_SOFT;

spi_init_struct.prescale = SPI_PSC_8;

spi_init_struct.endian = SPI_ENDIAN_MSB;

spi_init(SPI0, &spi_init_struct);

spi_enable

The description of spi_enable is shown as below:

Table 3-793. Function spi_enable


Function name spi_enable
Function prototype void spi_enable(uint32_t spi_periph);
Function descriptions enable SPI
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:
563
GD32E50x Firmware Library User Guide
/* enable SPI0 */

spi_enable(SPI0);

spi_disable

The description of spi_disable is shown as below:

Table 3-794. Function spi_disable


Function name spi_disable
Function prototype void spi_disable(uint32_t spi_periph);
Function descriptions disable SPI
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* disable SPI0 */

spi_disable(SPI0);

i2s_init

The description of i2s_init is shown as below:

Table 3-795. Function i2s_init


Function name i2s_init
void i2s_init(uint32_t spi_periph,uint32_t i2s_mode, uint32_t i2s_standard,
Function prototype
uint32_t i2s_ckpl);
Function descriptions initialize I2S peripheral parameter
Precondition -
The called functions -
Input parameter{in}
spi_periph I2S peripheral
SPIx x=1,2
Input parameter{in}
i2s_mode I2S operation mode
I2S_MODE_SLAVETX I2S slave transmit mode
I2S_MODE_SLAVERX I2S slave receive mode
I2S_MODE_MASTERT I2S master transmit mode
564
GD32E50x Firmware Library User Guide
X
I2S_MODE_MASTERR
I2S master receive mode
X
Input parameter{in}
i2s_standard I2S standard
I2S_STD_PHILLIPS I2S phillips standard
I2S_STD_MSB I2S MSB standard
I2S_STD_LSB I2S LSB standard
I2S_STD_PCMSHORT I2S PCM short standard
I2S_STD_PCMLONG I2S PCM long standard
Input parameter{in}
i2s_ckpl I2S idle state clock polarity
I2S_CKPL_LOW I2S clock polarity low level
I2S_CKPL_HIGH I2S clock polarity high level
Output parameter{out}
- -
Return value
- -

Example:

/* initialize I2S1 */

i2s_init(SPI1, I2S_MODE_MASTERTX, I2S_STD_PHILLIPS, I2S_CKPL_LOW);

i2s_psc_config

The description of i2s_psc_config is shown as below:

Table 3-796. Function i2s_psc_config


Function name i2s_psc_config
void i2s_psc_config(uint32_t spi_periph, uint32_t i2s_audiosample, uint32_t
Function prototype
i2s_frameformat, uint32_t i2s_mckout);
Function descriptions configure I2S prescaler
Precondition -
The called functions rcu_clock_freq_get
Input parameter{in}
spi_periph I2S peripheral
SPIx x=1,2
Input parameter{in}
i2s_audiosample I2S audio sample rate
I2S_AUDIOSAMPLE_8
audio sample rate is 8KHz
K
I2S_AUDIOSAMPLE_1
audio sample rate is 11KHz
1K

565
GD32E50x Firmware Library User Guide
I2S_AUDIOSAMPLE_1
audio sample rate is 16KHz
6K
I2S_AUDIOSAMPLE_2
audio sample rate is 22KHz
2K
I2S_AUDIOSAMPLE_3
audio sample rate is 32KHz
2K
I2S_AUDIOSAMPLE_4
audio sample rate is 44KHz
4K
I2S_AUDIOSAMPLE_4
audio sample rate is 48KHz
8K
I2S_AUDIOSAMPLE_9
audio sample rate is 96KHz
6K
I2S_AUDIOSAMPLE_1
audio sample rate is 192KHz
92K
Input parameter{in}
i2s_frameformat I2S data length and channel length
I2S_FRAMEFORMAT_
I2S data length is 16 bit and channel length is 16 bit
DT16B_CH16B
I2S_FRAMEFORMAT_
I2S data length is 16 bit and channel length is 32 bit
DT16B_CH32B
I2S_FRAMEFORMAT_
I2S data length is 24 bit and channel length is 32 bit
DT24B_CH32B
I2S_FRAMEFORMAT_
I2S data length is 32 bit and channel length is 32 bit
DT32B_CH32B
Input parameter{in}
i2s_mckout I2S master clock output
I2S_MCKOUT_ENABL
I2S master clock output enable
E
I2S_MCKOUT_DISABL
I2S master clock output disable
E
Output parameter{out}
- -
Return value
- -

Example:

/* configure I2S1 prescaler */

i2s_psc_config(SPI1, I2S_AUDIOSAMPLE_44K, I2S_FRAMEFORMAT_DT16B_CH16B,


I2S_MCKOUT_DISABLE);

i2s_enable

The description of i2s_enable is shown as below:


566
GD32E50x Firmware Library User Guide
Table 3-797. Function i2s_enable
Function name i2s_enable
Function prototype void i2s_enable(uint32_t spi_periph);
Function descriptions enable I2S
Precondition -
The called functions -
Input parameter{in}
spi_periph I2S peripheral
SPIx x=1,2
Output parameter{out}
- -
Return value
- -

Example:

/* enable I2S1*/

i2s_enable(SPI1);

i2s_disable

The description of i2s_disable is shown as below:

Table 3-798. Function i2s_disable


Function name i2s_disable
Function prototype void i2s_disable(uint32_t spi_periph);
Function descriptions disable I2S
Precondition -
The called functions -
Input parameter{in}
spi_periph I2S peripheral
SPIx x=1,2
Output parameter{out}
- -
Return value
- -

Example:

/* disable I2S1*/

i2s_disable(SPI1);

spi_nss_output_enable

The description of spi_nss_output_enable is shown as below:

567
GD32E50x Firmware Library User Guide
Table 3-799. Function spi_nss_output_enable
Function name spi_nss_output_enable
Function prototype void spi_nss_output_enable(uint32_t spi_periph);
Function descriptions enable SPI NSS output function
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 NSS output */

spi_nss_output_enable(SPI0);

spi_nss_output_disable

The description of spi_nss_output_disable is shown as below:

Table 3-800. Function spi_nss_output_disable


Function name spi_nss_output_disable
Function prototype void spi_nss_output_disable(uint32_t spi_periph);
Function descriptions disable SPI NSS output function
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* disable SPI0 NSS output */

spi_nss_output_disable(SPI0);

spi_nss_internal_high

The description of spi_nss_internal_high is shown as below:

568
GD32E50x Firmware Library User Guide
Table 3-801. Function spi_nss_internal_high
Function name spi_nss_internal_high
Function prototype void spi_nss_internal_high(uint32_t spi_periph);
Function descriptions SPI NSS pin high level in software mode
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* SPI0 NSS pin is pulled high level in software mode */

spi_nss_internal_high(SPI0);

spi_nss_internal_low

The description of spi_nss_internal_low is shown as below:

Table 3-802. Function spi_nss_internal_low


Function name spi_nss_internal_low
Function prototype void spi_nss_internal_low(uint32_t spi_periph);
Function descriptions SPI NSS pin low level in software mode
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* SPI0 NSS pin is pulled low level in software mode */

spi_nss_internal_low(SPI0);

spi_dma_enable

The description of spi_dma_enable is shown as below:

569
GD32E50x Firmware Library User Guide
Table 3-803. Function spi_dma_enable
Function name spi_dma_enable
Function prototype void spi_dma_enable(uint32_t spi_periph, uint8_t dma);
Function descriptions enable SPI DMA function
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
dma SPI DMA mode
SPI_DMA_TRANSMIT SPI transmit data use DMA
SPI_DMA_RECEIVE SPI receive data use DMA
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 transmit data DMA function */

spi_dma_enable(SPI0, SPI_DMA_TRANSMIT);

spi_dma_disable

The description of spi_dma_disable is shown as below:

Table 3-804. Function spi_dma_disable


Function name spi_dma_disable
Function prototype void spi_dma_disable(uint32_t spi_periph, uint8_t dma);
Function descriptions disable SPI DMA function
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
dma SPI DMA mode
SPI_DMA_TRANSMIT SPI transmit data use DMA
SPI_DMA_RECEIVE SPI receive data use DMA
Output parameter{out}
- -
Return value
- -

570
GD32E50x Firmware Library User Guide
Example:

/* disable SPI0 transmit data DMA function */

spi_dma_disable(SPI0, SPI_DMA_TRANSMIT);

spi_i2s_data_frame_format_config

The description of spi_i2s_data_frame_format_config is shown as below:

Table 3-805. Function spi_i2s_data_frame_format_config


Function name spi_i2s_data_frame_format_config
void spi_i2s_data_frame_format_config(uint32_t spi_periph, uint16_t
Function prototype
frame_format);
Function descriptions configure SPI/I2S data frame format
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
frame_format SPI frame size
SPI_FRAMESIZE_16BI
SPI frame size is 16 bits
T
SPI_FRAMESIZE_8BIT SPI frame size is 8 bits
Output parameter{out}
- -
Return value
- -

Example:

/* configure SPI1/I2S1 data frame format size is 16 bits */

spi_i2s_data_frame_format_config(SPI1, SPI_FRAMESIZE_16BIT);

spi_i2s_data_transmit

The description of spi_i2s_data_transmit is shown as below:

Table 3-806. Function spi_i2s_data_transmit


Function name spi_i2s_data_transmit
Function prototype void spi_i2s_data_transmit(uint32_t spi_periph, uint16_t data);
Function descriptions SPI transmit data
Precondition -
The called functions -
Input parameter{in}

571
GD32E50x Firmware Library User Guide
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
data 16-bit data
Output parameter{out}
- -
Return value
- -

Example:

/* SPI0 transmit data */

uint16_t spi0_send_array[] = {0x5050,0XA0A0};

spi_i2s_data_transmit(SPI0, spi0_send_array[0]);

spi_i2s_data_receive

The description of spi_i2s_data_receive is shown as below:

Table 3-807. Function spi_i2s_data_receive


Function name spi_i2s_data_receive
Function prototype uint16_t spi_i2s_data_receive(uint32_t spi_periph);
Function descriptions SPI receive data
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
uint16_t 16-bit data

Example:

/* SPI0 receive data */

uint16_t spi0_receive_data;

spi0_receive_data = spi_i2s_data_receive(SPI0);

spi_bidirectional_transfer_config

The description of spi_bidirectional_transfer_config is shown as below:

Table 3-808. Function spi_bidirectional_transfer_config


Function name spi_bidirectional_transfer_config
572
GD32E50x Firmware Library User Guide
void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t
Function prototype
transfer_direction);
Function descriptions configure SPI bidirectional transfer direction
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
transfer_direction SPI transfer direction
SPI_BIDIRECTIONAL_
SPI work in transmit-only mode
TRANSMIT
SPI_BIDIRECTIONAL_
SPI work in receive-only mode
RECEIVE
Output parameter{out}
- -
Return value
- -

Example:

/* SPI0 works in transmit-only mode */

spi_bidirectional_transfer_config(SPI0, SPI_BIDIRECTIONAL_TRANSMIT);

spi_crc_polynomial_set

The description of spi_crc_polynomial_set is shown as below:

Table 3-809. Function spi_crc_polynomial_set


Function name spi_crc_polynomial_set
Function prototype void spi_crc_polynomial_set(uint32_t spi_periph, uint16_t crc_poly);
Function descriptions set SPI CRC polynomial
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
crc_poly CRC polynomial value
Output parameter{out}
- -
Return value
- -

Example:
573
GD32E50x Firmware Library User Guide
/* set SPI0 CRC polynomial */

spi_crc_polynomial_set(SPI0,CRC_VALUE);

spi_crc_polynomial_get

The description of spi_crc_polynomial_get is shown as below:

Table 3-810. Function spi_crc_polynomial_get


Function name spi_crc_polynomial_get
Function prototype uint16_t spi_crc_polynomial_get(uint32_t spi_periph);
Function descriptions get SPI CRC polynomial
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
uint16_t 16-bit CRC polynomial (0-0xFFFF)

Example:

/* get SPI0 CRC polynomial */

uint16_t crc_val;

crc_val = spi_crc_polynomial_get(SPI0);

spi_crc_on

The description of spi_crc_on is shown as below:

Table 3-811. Function spi_crc_on


Function name spi_crc_on
Function prototype void spi_crc_on(uint32_t spi_periph);
Function descriptions turn on SPI CRC function
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

574
GD32E50x Firmware Library User Guide
Example:

/* turn on SPI0 CRC function */

spi_crc_on(SPI0);

spi_crc_off

The description of spi_crc_off is shown as below:

Table 3-812. Function spi_crc_off


Function name spi_crc_off
Function prototype void spi_crc_off(uint32_t spi_periph);
Function descriptions turn off SPI CRC function
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* turn off SPI0 CRC function */

spi_crc_off(SPI0);

spi_crc_next

The description of spi_crc_next is shown as below:

Table 3-813. Function spi_crc_next


Function name spi_crc_next
Function prototype void spi_crc_next(uint32_t spi_periph);
Function descriptions SPI next data is CRC value
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

575
GD32E50x Firmware Library User Guide
Example:

/* SPI0 next data is CRC value */

spi_crc_next(SPI0);

spi_crc_get

The description of spi_crc_get is shown as below:

Table 3-814. Function spi_crc_get


Function name spi_crc_get
Function prototype uint16_t spi_crc_get(uint32_t spi_periph, uint8_t crc);
Function descriptions get SPI CRC send value or receive value
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
crc SPI crc value
SPI_CRC_TX get transmit crc value
SPI_CRC_RX get receive crc value
Output parameter{out}
- -
Return value
uint16_t 16-bit CRC value (0-0xFFFF)

Example:

/* get SPI0 CRC send value */

uint16_t crc_val;

crc_val = spi_crc_get(SPI0, SPI_CRC_TX);

spi_ti_mode_enable

The description of spi_ti_mode_enable is shown as below:

Table 3-815. Function spi_ti_mode_enable


Function name spi_ti_mode_enable
Function prototype void spi_ti_mode_enable(uint32_t spi_periph);
Function descriptions enable SPI TI mode
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
576
GD32E50x Firmware Library User Guide
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 TI mode */

spi_ti_mode_enable(SPI0);

spi_ti_mode_disable

The description of spi_ti_mode_disable is shown as below:

Table 3-816. Function spi_ti_mode_disable


Function name spi_ti_mode_disable
Function prototype void spi_ti_mode_disable(uint32_t spi_periph);
Function descriptions disable SPI TI mode
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* disable SPI0 TI mode */

spi_ti_mode_disable(SPI0);

spi_nssp_mode_enable

The description of spi_nssp_mode_enable is shown as below:

Table 3-817. Function spi_nssp_mode_enable


Function name spi_nssp_mode_enable
Function prototype void spi_nssp_mode_enable(uint32_t spi_periph);
Function descriptions enable SPI NSS pulse mode
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
577
GD32E50x Firmware Library User Guide
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 NSS pulse mode */

spi_nssp_mode_enable(SPI0);

spi_nssp_mode_disable

The description of spi_nssp_mode_disable is shown as below:

Table 3-818. Function spi_nssp_mode_disable


Function name spi_nssp_mode_disable
Function prototype void spi_nssp_mode_disable(uint32_t spi_periph);
Function descriptions disable SPI NSS pulse mode
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* disable SPI0 NSS pulse mode */

spi_nssp_mode_disable(SPI0);

i2s_full_duplex_mode_config

The description of i2s_full_duplex_mode_config is shown as below:

Table 3-819. Function i2s_init


Function name i2s_full_duplex_mode_config
void i2s_full_duplex_mode_config(uint32_t i2s_add_periph,uint32_t
Function prototype i2s_mode,uint32_t i2s_standard,uint32_t i2s_ckpl,uint32_t
i2s_frameformat);
Function descriptions configure i2s full duplex mode
Precondition -
The called functions -
578
GD32E50x Firmware Library User Guide
Input parameter{in}
i2s_add_periph I2S_ADD peripheral
I2Sx_ADD x=1,2
Input parameter{in}
i2s_mode I2S operation mode
I2S_MODE_SLAVETX I2S slave transmit mode
I2S_MODE_SLAVERX I2S slave receive mode
I2S_MODE_MASTERT
I2S master transmit mode
X
I2S_MODE_MASTERR
I2S master receive mode
X
Input parameter{in}
i2s_standard I2S standard
I2S_STD_PHILLIPS I2S phillips standard
I2S_STD_MSB I2S MSB standard
I2S_STD_LSB I2S LSB standard
I2S_STD_PCMSHORT I2S PCM short standard
I2S_STD_PCMLONG I2S PCM long standard
Input parameter{in}
i2s_ckpl I2S idle state clock polarity
I2S_CKPL_LOW I2S clock polarity low level
I2S_CKPL_HIGH I2S clock polarity high level
Input parameter{in}
i2s_frameformat I2S data length and channel length
I2S_FRAMEFORMAT_
I2S data length is 16 bit and channel length is 16 bit
DT16B_CH16B
I2S_FRAMEFORMAT_
I2S data length is 16 bit and channel length is 32 bit
DT16B_CH32B
I2S_FRAMEFORMAT_
I2S data length is 24 bit and channel length is 32 bit
DT24B_CH32B
I2S_FRAMEFORMAT_
I2S data length is 32 bit and channel length is 32 bit
DT32B_CH32B
Output parameter{out}
- -
Return value
- -

Example:

/* configure I2S1_ADD */

i2s_full_duplex_mode_config(I2S1_ADD,I2S_MODE_MASTERTX,I2S_STD_PHILLIPS,
I2S_CKPL_HIGH, I2S_FRAMEFORMAT_DT16B_CH16B);

579
GD32E50x Firmware Library User Guide
qspi_enable

The description of qspi_enable is shown as below:

Table 3-820. Function qspi_enable


Function name qspi_enable
Function prototype void qspi_enable(uint32_t spi_periph);
Function descriptions enable quad wire SPI
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 quad wire mode */

qspi_enable(SPI0);

qspi_disable

The description of qspi_disable is shown as below:

Table 3-821. Function qspi_disable


Function name qspi_disable
Function prototype qspi_disable(uint32_t spi_periph);
Function descriptions disable quad wire SPI
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0
Output parameter{out}
- -
Return value
- -

Example:

/* disable SPI0 quad wire mode */

qspi_disable(SPI0);

580
GD32E50x Firmware Library User Guide
qspi_write_enable

The description of qspi_write_enable is shown as below:

Table 3-822. Function qspi_write_enable


Function name qspi_write_enable
Function prototype void qspi_write_enable(uint32_t spi_periph);
Function descriptions enable quad wire SPI write
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 quad wire write */

qspi_write_enable(SPI0);

qspi_read_enable

The description of qspi_read_enable is shown as below:

Table 3-823. Function qspi_read_enable


Function name qspi_read_enable
Function prototype void qspi_read_enable(uint32_t spi_periph);
Function descriptions enable quad wire SPI read
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 quad wire read */

qspi_read_enable(SPI0);

581
GD32E50x Firmware Library User Guide
qspi_io23_output_enable

The description of qspi_io23_output_enable is shown as below:

Table 3-824. Function qspi_io23_output_enable


Function name qspi_io23_output_enable
Function prototype void qspi_io23_output_enable(uint32_t spi_periph);
Function descriptions enable SPI_IO2 and SPI_IO3 pin output
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 SPI_IO2 and SPI_IO3 pin output */

qspi_io23_output_enable(SPI0);

qspi_io23_output_disable

The description of qspi_io23_output_disable is shown as below:

Table 3-825. Function qspi_io23_output_disable


Function name qspi_io23_output_disable
Function prototype void qspi_io23_output_disable(uint32_t spi_periph);
Function descriptions disable SPI_IO2 and SPI_IO3 pin output
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0
Output parameter{out}
- -
Return value
- -

Example:

/* disable SPI0 SPI_IO2 and SPI_IO3 pin output */

qspi_io23_output_disable(SPI0);

582
GD32E50x Firmware Library User Guide
spi_i2s_interrupt_enable

The description of spi_i2s_interrupt_enable is shown as below:

Table 3-826. Function spi_i2s_interrupt_enable


Function name spi_i2s_interrupt_enable
Function prototype void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t interrupt);
Function descriptions enable SPI and I2S interrupt
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
interrupt SPI/I2S interrupt
SPI_I2S_INT_TBE transmit buffer empty interrupt
SPI_I2S_INT_RBNE receive buffer not empty interrupt
CRC error,configuration error,reception overrun error, transmission
SPI_I2S_INT_ERR
underrun error and format error interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* enable SPI0 transmit buffer empty interrupt */

spi_i2s_interrupt_enable(SPI0, SPI_I2S_INT_TBE);

spi_i2s_interrupt_disable

The description of spi_i2s_interrupt_disable is shown as below:

Table 3-827. Function spi_i2s_interrupt_disable


Function name spi_i2s_interrupt_disable
Function prototype void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t interrupt);
Function descriptions disable SPI and I2S interrupt
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
interrupt SPI/I2S interrupt
SPI_I2S_INT_TBE transmit buffer empty interrupt

583
GD32E50x Firmware Library User Guide
SPI_I2S_INT_RBNE receive buffer not empty interrupt
CRC error,configuration error,reception overrun error, transmission
SPI_I2S_INT_ERR
underrun error and format error interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* disable SPI0 transmit buffer empty interrupt */

spi_i2s_interrupt_disable(SPI0, SPI_I2S_INT_TBE);

spi_i2s_interrupt_flag_get

The description of spi_i2s_interrupt_flag_get is shown as below:

Table 3-828. Function spi_i2s_interrupt_flag_get


Function name spi_i2s_interrupt_flag_get
Function prototype FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t interrupt);
Function descriptions get SPI and I2S interrupt status
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
interrupt SPI/I2S interrupt flag status
SPI_I2S_INT_FLAG_T
transmit buffer empty interrupt
BE
SPI_I2S_INT_FLAG_R
receive buffer not empty interrupt
BNE
SPI_I2S_INT_FLAG_R
overrun interrupt
XORERR
SPI_INT_FLAG_CONF
config error interrupt
ERR
SPI_INT_FLAG_CRCE
CRC error interrupt
RR
I2S_INT_FLAG_TXUR
underrun error interrupt
ERR
SPI_I2S_INT_FLAG_F
format error interrupt
ERR
Output parameter{out}
- -

584
GD32E50x Firmware Library User Guide
Return value
FlagStatus SET or RESET

Example:

/* get SPI0 transmit buffer empty interrupt status */

if(RESET != spi_i2s_interrupt_flag_get(SPI0, SPI_I2S_INT_FLAG_TBE)){

while(RESET == spi_i2s_flag_get(SPI0, SPI_FLAG_TBE));

spi_i2s_data_transmit(SPI0, spi0_send_array[send_n++]);

spi_i2s_flag_get

The description of spi_i2s_flag_get is shown as below:

Table 3-829. Function spi_i2s_flag_get


Function name spi_i2s_flag_get
Function prototype FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t flag);
Function descriptions get SPI and I2S flag status
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Input parameter{in}
flag SPI/I2S flag status
SPI_FLAG_TBE transmit buffer empty flag
SPI_FLAG_RBNE receive buffer not empty flag
SPI_FLAG_TRANS transmit on-going flag
SPI_I2S_INT_FLAG_R
receive overrun error flag
XORERR
SPI_FLAG_CONFERR mode config error flag
SPI_FLAG_CRCERR CRC error flag
SPI_FLAG_FREE format error flag
I2S_FLAG_TBE transmit buffer empty flag
I2S_FLAG_RBNE receive buffer not empty flag
I2S_FLAG_TRANS transmit on-going flag
I2S_FLAG_RXORERR overrun error flag
I2S_FLAG_TXURERR underrun error flag
I2S_FLAG_CH channel side flag
I2S_FLAG_FERR format error flag
Output parameter{out}
- -
585
GD32E50x Firmware Library User Guide
Return value
FlagStatus SET or RESET

Example:

/* get SPI0 transmit buffer empty flag status */

while(RESET == spi_i2s_flag_get(SPI0, SPI_FLAG_TBE));

spi_i2s_data_transmit(SPI0, spi0_send_array[send_n++]);

spi_crc_error_clear

The description of spi_crc_error_clear is shown as below:

Table 3-830. Function spi_crc_error_clear


Function name spi_crc_error_clear
Function prototype void spi_crc_error_clear(uint32_t spi_periph);
Function descriptions clear SPI CRC error flag status
Precondition -
The called functions -
Input parameter{in}
spi_periph SPI peripheral
SPIx x=0,1,2
Output parameter{out}
- -
Return value
- -

Example:

/* clear SPI0 CRC error flag status */

spi_crc_error_clear(SPI0);

3.24. SQPI

Serial/Quad Parallel Interface (SQPI) is a controller for external serial/dual/quad parallel


interface memory peripheral. The SQPI registers are listed in chapter 3.24.1, the SQPI
firmware functions are introduced in chapter 3.24.2.

3.24.1. Descriptions of Peripheral registers

SQPI registers are listed in the table shown as below:

586
GD32E50x Firmware Library User Guide
Table 3-831. SQPI Registers
Registers Descriptions
SQPI_INIT SQPI initial register
SQPI_RCMD SQPI read command register
SQPI_WCMD SQPI write command register
SQPI_IDL SQPI ID low register
SQPI_IDH SQPI ID high register

3.24.2. Descriptions of Peripheral functions

SQPI firmware functions are listed in the table shown as below:

Table 3-832. SQPI firmware function


Function name Function description
sqpi_deinit reset SQPI peripheral
sqpi_struct_para_init initialize the parameters of SQPI struct with the default values
sqpi_init initialize SQPI peripheral parameter
sqpi_read_id_command send SQPI read ID command
sqpi_special_command send SQPI special command
sqpi_read_command_config configure SQPI read command
sqpi_write_command_config configure SQPI write command
sqpi_low_id_receive SQPI receive low ID
sqpi_high_id_receive SQPI receive high ID

Structure sqpi_parameter_struct

Table 3-833. sqpi_parameter_struct


Member name Function description
SQPI sample polarity
polarity
(SQPI_SAMPLE_POLARITY_RISING, SQPI_SAMPLE_POLARITY_FALLING)
external memory ID length
id_length
(QSPI_ID_LENGTH_n_BITS (n=8,16,32,64))
bit number of SPI PSRAM address phase
addr_bit
(0x00 - 0x1F)
clock divider for SQPI output clock
clk_div
(0x01 - 0x3F)
bit number of SQPI controller command phase
cmd_bit
(QSPI_CMDBIT_n_BITS (n=4,8,16))

sqpi_deinit

The description of sqpi_deinit is shown as below:

Table 3-834. Function sqpi_deinit


Function name sqpi_deinit
587
GD32E50x Firmware Library User Guide
Function prototype void sqpi_deinit(void);
Function descriptions reset SQPI peripheral
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset SQPI */

sqpi_deinit();

sqpi_struct_para_init

The description of sqpi_struct_para_init is shown as below:

Table 3-835. Function sqpi_struct_para_init


Function name sqpi_struct_para_init
Function prototype void sqpi_struct_para_init(sqpi_parameter_struct* sqpi_struct);
Function descriptions initialize the parameters of SQPI struct with the default values
Precondition -
The called functions -
Input parameter{in}
*sqpi_struct a sqpi_parameter_struct address
Output parameter{out}
- -
Return value
- -

Example:

/* initialize the parameters of SPI */

sqpi_parameter_struct sqpi_init_struct;

sqpi_struct_para_init(&sqpi_init_struct);

sqpi_init

The description of sqpi_init is shown as below:

Table 3-836. Function sqpi_init


Function name sqpi_init

588
GD32E50x Firmware Library User Guide
Function prototype void sqpi_init(sqpi_parameter_struct* sqpi_struct);
Function descriptions initialize SQPI peripheral parameter
Precondition -
The called functions -
Input parameter{in}
SPI parameter initialization stuct, the structure members can refer to
spi_struct
members of the structure Table 3-833. sqpi_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* initialize SQPI */

sqpi_parameter_struct sqpi_init_struct;

sqpi_struct->polarity = SQPI_SAMPLE_POLARITY_RISING;

sqpi_struct->id_length = QSPI_ID_LENGTH_32_BITS;

sqpi_struct->addr_bit = 24U;

sqpi_struct->clk_div = 2U;

sqpi_struct->cmd_bit = QSPI_CMDBIT_8_BITS;

sqpi_init(&sqpi_init_struct);

sqpi_read_id_command

The description of sqpi_read_id_command is shown as below:

Table 3-837. Function sqpi_read_id_command


Function name sqpi_read_id_command
Function prototype void sqpi_read_id_command (void);
Function descriptions send SQPI read ID command
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

589
GD32E50x Firmware Library User Guide
/* send SQPI read ID command */

sqpi_read_id_command ();

sqpi_special_command

The description of sqpi_special_command is shown as below:

Table 3-838. Function sqpi_special_command


Function name sqpi_special_command
Function prototype void sqpi_special_command(void);
Function descriptions send SQPI special command
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* send SQPI special command */

sqpi_special_command ();

sqpi_read_command_config

The description of sqpi_read_command_config is shown as below:

Table 3-839. Function sqpi_read_command_config


Function name sqpi_read_command_config
void sqpi_read_command_config(uint32_t rmode, uint32_t rwaitcycle,
Function prototype
uint32_t rcmd);
Function descriptions configure SQPI read command
Precondition -
The called functions -
Input parameter{in}
rmode SQPI read command mode
QSPI_MODE_SSQ SSQ mode
QSPI_MODE_SSS SSS mode
QSPI_MODE_SQQ SQQ mode
QSPI_MODE_QQQ QQQ mode
QSPI_MODE_SSD SSD mode
QSPI_MODE_SDD SDD mode
Input parameter{in}
590
GD32E50x Firmware Library User Guide
rwaitcycle SQPI read wait cycle (0x00 – 0x1F)
Input parameter{in}
rcmd SQPI read command(0x00 – 0xFF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure SQPI read command */

sqpi_read_command_config(QSPI_MODE_SSS,0x00,0x9f);

sqpi_write_command_config

The description of sqpi_write_command_config is shown as below:

Table 3-840. Function sqpi_write_command_config


Function name sqpi_write_command_config
void sqpi_write_command_config(uint32_t wmode, uint32_t wwaitcycle,
Function prototype
uint32_t wcmd);
Function descriptions configure SQPI write command
Precondition -
The called functions -
Input parameter{in}
wmode SQPI write command mode
QSPI_MODE_SSQ SSQ mode
QSPI_MODE_SSS SSS mode
QSPI_MODE_SQQ SQQ mode
QSPI_MODE_QQQ QQQ mode
QSPI_MODE_SSD SSD mode
QSPI_MODE_SDD SDD mode
Input parameter{in}
wwaitcycle SQPI write wait cycle (0x00 – 0x1F)
Input parameter{in}
wcmd SQPI write command(0x00 – 0xFF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure SQPI write command */

sqpi_write_command_config(QSPI_MODE_SSS,0x00,0x9f);
591
GD32E50x Firmware Library User Guide
sqpi_low_id_receive

The description of sqpi_low_id_receive is shown as below:

Table 3-841. Function sqpi_low_id_receive


Function name sqpi_low_id_receive
Function prototype uint32_t sqpi_low_id_receive(void);
Function descriptions get low ID value
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t 32-bit IDvalue (0-0xFFFF)

Example:

/* get SQPI low ID value */

uint32_t val;

val = sqpi_low_id_receive ();

sqpi_high_id_receive

The description of sqpi_high_id_receive is shown as below:

Table 3-842. Function sqpi_low_id_receive


Function name sqpi_high_id_receive
Function prototype uint32_t sqpi_high_id_receive(void);
Function descriptions get high ID value
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
uint32_t 32-bit ID value (0-0xFFFF)

Example:

/* get SQPI high ID value */

uint32_t val;

val = sqpi_high_id_receive ();


592
GD32E50x Firmware Library User Guide
3.25. TIMER

The timers have a 16-bit counter that can be used as an unsigned counter and supports both
input capture and output compare. Timers (TIMERx) are divided into five sorts: advanced
timer (TIMERx, x=0, 7), general level0 timer (TIMERx, x=1, 2, 3, 4), general level1 timer
(TIMERx, x=8, 11), general level2 timer (TIMERx, x=9, 10, 12, 13), basic timer (TIMERx, x=5,
6). The specific functions of different types of timer are different. The TIMER registers are
listed in chapter 3.25.1, the TIMER firmware functions are introduced in chapter 3.25.2.

3.25.1. Descriptions of Peripheral registers

TIMERx registers are listed in the table shown as below:

Table 3-843. TIMERx Registers


Registers Descriptions
TIMER_CTL0 Control register 0
TIMER_CTL1 Control register 1
TIMER_SMCFG Slave mode configuration register
TIMER_DMAINTEN DMA and interrupt enable register
TIMER_INTF Interrupt flag register
TIMER_SWEVG Software event generation register
TIMER_CHCTL0 Channel control register 0
TIMER_CHCTL1 Channel control register 1
TIMER_CHCTL2 Channel control register 2
TIMER_CNT Counter register
TIMER_PSC Prescaler register
TIMER_CAR Counter auto reload register
TIMER_CREP Counter repetition register
TIMER_CH0CV Channel 0 capture/compare value register
TIMER_CH1CV Channel 1 capture/compare value register
TIMER_CH2CV Channel 2 capture/compare value register
TIMER_CH3CV Channel 3 capture/compare value register
TIMER_CCHP Channel complementary protection register
TIMER_DMACFG DMA configuration register
TIMER_DMATB DMA transfer buffer register
TIMER_CFG Configuration register

3.25.2. Descriptions of Peripheral functions

The description format of firmware functions are shown as below:

593
GD32E50x Firmware Library User Guide
Table 3-844. TIMERx firmware function
Function name Function description
timer_deinit deinit a timer
initialize the parameters of TIMER init parameter struct with
timer_struct_para_init
the default values
timer_init initialize TIMER counter
timer_enable enable a timer
timer_disable disable a timer
timer_auto_reload_shadow_enable enable the auto reload shadow function
timer_auto_reload_shadow_disable disable the auto reload shadow function
timer_update_event_enable enable the update event
timer_update_event_disable disable the update event
timer_counter_alignment set TIMER counter alignment mode
timer_counter_up_direction set TIMER counter up direction
timer_counter_down_direction set TIMER counter down direction
timer_prescaler_config configure TIMER prescaler
timer_repetition_value_config configure TIMER repetition register value
timer_autoreload_value_config configure TIMER autoreload register value
timer_counter_value_config configure TIMER counter register value
timer_counter_read read TIMER counter value
timer_prescaler_read read TIMER prescaler value
timer_single_pulse_mode_config configure TIMER single pulse mode
timer_update_source_config configure TIMER update source
timer_dma_enable enable the TIMER DMA
timer_dma_disable disable the TIMER DMA
timer_channel_dma_request_ channel DMA request source selection
source_select
timer_dma_transfer_config configure the TIMER DMA transfer
timer_event_software_generate software generate events
timer_break_struct_para_init initialize the parameters of TIMER break parameter struct
with the default values
timer_break_config configure TIMER break function
timer_break_enable enable TIMER break function
timer_break_disable disable TIMER break function
timer_automatic_output_enable enable TIMER output automatic function
timer_automatic_output_disable disable TIMER output automatic function
timer_primary_output_config configure TIMER primary output function
timer_channel_control_shadow_ channel capture/compare control shadow register enable
config
timer_channel_control_shadow_ configure TIMER channel control shadow register update
update_config control
timer_channel_output_struct initialize the parameters of TIMER channel output
_para_init parameter struct with the default values
594
GD32E50x Firmware Library User Guide
Function name Function description
timer_channel_output_config configure TIMER channel output function
timer_channel_output_mode_config configure TIMER channel output compare mode
timer_channel_output_pulse_ configure TIMER channel output pulse value
value_config
timer_channel_output_shadow_ configure TIMER channel output shadow function
config
timer_channel_output_fast_config configure TIMER channel output fast function
timer_channel_output_clear_config configure TIMER channel output clear function
timer_channel_output_polarity_ configure TIMER channel output polarity
config
timer_channel_complementary_ configure TIMER channel complementary output polarity
output_polarity_config
timer_channel_output_state_config configure TIMER channel enable state
timer_channel_complementary_ configure TIMER channel complementary output enable
output_state_config state
timer_channel_input_struct_ initialize the parameters of TIMER channel input parameter
para_init struct with the default values
timer_input_capture_config configure TIMER input capture parameter
timer_channel_input_capture_ configure TIMER channel input capture prescaler value
prescaler_config
timer_channel_capture_value_ read TIMER channel capture compare register valu
register_read
timer_input_pwm_capture_config configure TIMER input pwm capture function
timer_hall_mode_config configure TIMER hall sensor mode
timer_input_trigger_source_select select TIMER input trigger source
timer_master_output_trigger_ select TIMER master mode output trigger source
source_select
timer_slave_mode_select select TIMER slave mode
timer_master_slave_mode_config configure TIMER master slave mode
timer_external_trigger_config configure TIMER external trigger input
timer_quadrature_decoder_ configure TIMER quadrature decoder mode
mode_config
timer_internal_clock_config configure TIMER internal clock mode
timer_internal_trigger_as_external_ configure TIMER the internal trigger as external clock input
clock_config
timer_external_trigger_as_external_ configure TIMER the external trigger as external clock input
clock_config
timer_external_clock_mode0_config configure TIMER the external clock mode 0
timer_external_clock_mode1_config configure TIMER the external clock mode 1
timer_external_clock_mode1_ disable TIMER the external clock mode 1
disable
timer_write_chxval_register_config configure TIMER write CHxVAL register selection
595
GD32E50x Firmware Library User Guide
Function name Function description
timer_output_value_selection_
configure TIMER output value selection
config
timer_flag_get get TIMER flags
timer_flag_clear clear TIMER flags
timer_interrupt_enable enable the TIMER interrupt
timer_interrupt_disable disable the TIMER interrupt
timer_interrupt_flag_get get timer interrupt flag
timer_interrupt_flag_clear clear TIMER interrupt flag

Structure timer_parameter_struct

Table 3-845. Structure timer_parameter_struct


Member name Function description
prescaler prescaler value(0~65535)
aligned mode(TIMER_COUNTER_EDGE,
alignedmode TIMER_COUNTER_CENTER_DOWN, TIMER_COUNTER_CENTER_UP,
TIMER_COUNTER_CENTER_BOTH)
counterdirection counter direction(TIMER_COUNTER_UP, TIMER_COUNTER_DOWN)
period period value
clock division value(TIMER_CKDIV_DIV1, TIMER_CKDIV_DIV2,
clockdivision
TIMER_CKDIV_DIV4)
repetitioncounter the counter repetition value(0~255)

Structure timer_break_parameter_struct

Table 3-846. Structure timer_break_parameter_struct


Member name Function description
run mode off-state(TIMER_ROS_STATE_ENABLE,
runoffstate
TIMER_ROS_STATE_DISABLE)
idle mode off-state(TIMER_IOS_STATE_ENABLE,
ideloffstate
TIMER_IOS_STATE_DISABLE)
deadtime dead time(0~255)
break polarity(TIMER_BREAK_POLARITY_LOW,
breakpolarity
TIMER_BREAK_POLARITY_HIGH)
output automatic enable (TIMER_OUTAUTO_ENABLE,
outputautostate
TIMER_OUTAUTO_DISABLE)
complementary register protect control(TIMER_CCHP_PROT_OFF,
protectmode
TIMER_CCHP_PROT_0, TIMER_CCHP_PROT_1, TIMER_CCHP_PROT_2)
breakstate break enable(TIMER_BREAK_ENABLE, TIMER_BREAK_DISABLE)

596
GD32E50x Firmware Library User Guide
Structure timer_oc_parameter_struct

Table 3-847. Structure timer_oc_parameter_struct


Member name Function description
outputstate channel output state(TIMER_CCX_ENABLE, TIMER_CCX_DISABLE)
channel complementary output state(TIMER_CCXN_ENABLE,
outputnstate
TIMER_CCXN_DISABLE)
channel output polarity(TIMER_OC_POLARITY_HIGH,
ocpolarity
TIMER_OC_POLARITY_LOW)
channel complementary output polarity(TIMER_OCN_POLARITY_HIGH,
ocnpolarity
TIMER_OCN_POLARITY_LOW)
idle state of channel output(TIMER_OC_IDLE_STATE_LOW,
ocidlestate
TIMER_OC_IDLE_STATE_HIGH)
idle state of channel complementary output
ocnidlestate
(TIMER_OCN_IDLE_STATE_LOW, TIMER_OCN_IDLE_STATE_HIGH)

Structure timer_ic_parameter_struct

Table 3-848. Structure timer_ic_parameter_struct


Member name Function description
channel input polarity(TIMER_IC_POLARITY_RISING,
icpolarity
TIMER_IC_POLARITY_FALLING, TIMER_IC_POLARITY_BOTH_EDGE)
channel input mode selection(TIMER_IC_SELECTION_DIRECTTI,
icselection
TIMER_IC_SELECTION_INDIRECTTI, TIMER_IC_SELECTION_ITS)
channel input capture prescaler(TIMER_IC_PSC_DIV1,
icprescaler
TIMER_IC_PSC_DIV2, TIMER_IC_PSC_DIV4, TIMER_IC_PSC_DIV8)
icfilter channel input capture filter control(0~15)

timer_deinit

The description of timer_deinit is shown as below:

Table 3-849. Function timer_deinit


Function name timer_deinit
Function prototype void timer_deinit(uint32_t timer_periph);
Function descriptions deinit a TIMER
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value

597
GD32E50x Firmware Library User Guide
- -

Example:

/* reset TIMER0 */

timer_deinit(TIMER0);

timer_struct_para_init

The description of timer_struct_para_init is shown as below:

Table 3-850. Function timer_struct_para_init


Function name timer_struct_para_init
Function prototype void timer_struct_para_init(timer_parameter_struct* initpara);
initialize the parameters of TIMER init parameter struct with the default
Function descriptions
values
Precondition -
The called functions -
Input parameter{in}
TIMER init parameter struct, the structure members can refer to Structure
initpara
timer_parameter_struct.
Output parameter{out}
- -
Return value
- -

Example:

/* initialize TIMER init parameter struct with a default value */

timer_parameter_struct timer_initpara;

timer_struct_para_init(&timer_initpara);

timer_init

The description of timer_init is shown as below:

Table 3-851. Function timer_init


Function name timer_init
Function prototype void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara);
Function descriptions initialize TIMER counter
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection

598
GD32E50x Firmware Library User Guide
Input parameter{in}
TIMER init parameter struct, the structure members can refer to Structure
initpara
timer_parameter_struct.
Output parameter{out}
- -
Return value
- -

Example:

/* initialize TIMER0 */

timer_parameter_struct timer_initpara;

timer_initpara.prescaler = 107;

timer_initpara.alignedmode = TIMER_COUNTER_EDGE;

timer_initpara.counterdirection = TIMER_COUNTER_UP;

timer_initpara.period = 999;

timer_initpara.clockdivision = TIMER_CKDIV_DIV1;

timer_initpara.repetitioncounter = 1;

timer_init(TIMER0,&timer_initpara);

timer_enable

The description of timer_enable is shown as below:

Table 3-852. Function timer_enable


Function name timer_enable
Function prototype void timer_enable(uint32_t timer_periph);
Function descriptions enable a timer
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable TIMER0 */

timer_enable(TIMER0);
599
GD32E50x Firmware Library User Guide
timer_disable

The description of timer_disable is shown as below:

Table 3-853. Function timer_disable


Function name timer_disable
Function prototype void timer_disable(uint32_t timer_periph);
Function descriptions disable a timer
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable TIMER0 */

timer_disable(TIMER0);

timer_auto_reload_shadow_enable

The description of timer_auto_reload_shadow_enable is shown as below:

Table 3-854. Function timer_auto_reload_shadow_enable


Function name timer_auto_reload_shadow_enable
Function prototype void timer_auto_reload_shadow_enable(uint32_t timer_periph);
Function descriptions enable the auto reload shadow function
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable the TIMER0 auto reload shadow function */

timer_auto_reload_shadow_enable(TIMER0);

600
GD32E50x Firmware Library User Guide
timer_auto_reload_shadow_disable

The description of timer_auto_reload_shadow_disable is shown as below:

Table 3-855. Function timer_auto_reload_shadow_disable


Function name timer_auto_reload_shadow_ disable
Function prototype void timer_auto_reload_shadow_ disable (uint32_t timer_periph);
Function descriptions disable the auto reload shadow function
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable the TIMER0 auto reload shadow function */

timer_auto_reload_shadow_disable(TIMER0);

timer_update_event_enable

The description of timer_update_event_enable is shown as below:

Table 3-856. Function timer_update_event_enable


Function name timer_update_event_enable
Function prototype void timer_update_event_enable(uint32_t timer_periph);
Function descriptions enable the update event
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable TIMER0 the update event */

timer_update_event_enable (TIMER0);

601
GD32E50x Firmware Library User Guide
timer_update_event_disable

The description of timer_update_event_disable is shown as below:

Table 3-857. Function timer_update_event_disable


Function name timer_update_event_ disable
Function prototype void timer_update_event_disable(uint32_t timer_periph);
Function descriptions disable the update event
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable TIMER0 the update event */

timer_update_event_disable (TIMER0);

timer_counter_alignment

The description of timer_counter_alignment is shown as below:

Table 3-858. Function timer_counter_alignment


Function name timer_counter_alignment
Function prototype void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned);
Function descriptions set TIMER counter alignment mode
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7) TIMER peripheral selection
Input parameter{in}
aligned alignment mode
TIMER_COUNTER_ED No center-aligned mode (edge-aligned mode). The direction of the counter
GE isspecified by the DIR bit.
Center-aligned and counting down assert mode. The counter counts under
TIMER_COUNTER_CE center aligned and channel is configured in output mode (CHxMS=00 in
NTER_DOWN TIMERx_CHCTL0register). Only when the counter is counting down,
compare interrupt flag of channels can be set.
TIMER_COUNTER_CE Center-aligned and counting up assert mode. The counter counts under

602
GD32E50x Firmware Library User Guide
NTER_UP center aligned and channel is configured in output mode (CHxMS=00 in
TIMERx_CHCTL0register). Only when the counter is counting up, compare
interrupt flag of channels can be set.
Center-aligned and counting up/down assert mode. The counter counts
TIMER_COUNTER_CE under center-aligned and channel is configured in output mode (CHxMS=00
NTER_BOTH in TIMERx_CHCTL0 register). Both when the counter is counting up and
counting down, compare interrupt flag of channels can be set.
Output parameter{out}
- -
Return value
- -

Example:

/* set TIMER0 counter center-aligned and counting up assert mode */

timer_counter_alignment(TIMER0, TIMER_COUNTER_CENTER_UP);

timer_counter_up_direction

The description of timer_counter_up_direction is shown as below:

Table 3-859. Function timer_counter_up_direction


Function name timer_counter_up_direction
Function prototype void timer_counter_up_direction(uint32_t timer_periph);
Function descriptions set TIMER counter up direction
Precondition set TIMER counter no center-aligned mode (edge-aligned mode)
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* set TIMER0 counter up direction */

timer_counter_up_direction(TIMER0);

timer_counter_down_direction

The description of timer_counter_down_direction is shown as below:

Table 3-860. timer_counter_down_direction


Function name timer_counter_ down _direction

603
GD32E50x Firmware Library User Guide
Function prototype void timer_counter_ down _direction(uint32_t timer_periph);
Function descriptions set TIMER counter down direction
Precondition set TIMER counter no center-aligned mode (edge-aligned mode)
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* set TIMER0 counter down direction */

timer_counter_down_direction(TIMER0);

timer_prescaler_config

The description of timer_prescaler_config is shown as below:

Table 3-861. Function timer_prescaler_config


Function name timer_prescaler_config
void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler,
Function prototype
uint32_t pscreload);
Function descriptions configure TIMER prescaler
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Input parameter{in}
prescaler prescaler value (0~65535)
Input parameter{in}
pscreload prescaler reload mode
TIMER_PSC_RELOAD
the prescaler is loaded right now
_NOW
TIMER_PSC_RELOAD
the prescaler is loaded at the next update event
_UPDATE
Output parameter{out}
- -
Return value
- -

Example:
604
GD32E50x Firmware Library User Guide
/* configure TIMER0 prescaler */

timer_prescaler_config(TIMER0, 3000, TIMER_PSC_RELOAD_NOW);

timer_repetition_value_config

The description of timer_repetition_value_config is shown as below:

Table 3-862. Function timer_repetition_value_config


Function name timer_repetition_value_config
void timer_repetition_value_config(uint32_t timer_periph, uint16_t
Function prototype
repetition);
Function descriptions configure TIMER repetition register value
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Input parameter{in}
repetition the counter repetition value (0~255)
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 repetition register value */

timer_repetition_value_config(TIMER0, 98);

timer_autoreload_value_config

The description of timer_autoreload_value_config is shown as below:

Table 3-863. Function timer_autoreload_value_config


Function name timer_autoreload_value_config
void timer_autoreload_value_config(uint32_t timer_periph, uint32_t
Function prototype
autoreload);
Function descriptions configure TIMER autoreload register value
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Input parameter{in}
autoreload the counter auto-reload value (0-0xFFFFFFFF)
605
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER autoreload register value */

timer_autoreload_value_config(TIMER0, 3000);

timer_counter_value_config

The description of timer_counter_value_config is shown as below:

Table 3-864. Function timer_counter_value_config


Function name timer_counter_value_config
Function prototype void timer_counter_value_config(uint32_t timer_periph, uint32_t counter);
Function descriptions configure TIMER counter register value
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Input parameter{in}
counter the counter value (0-0xFFFFFFFF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 counter register value */

timer_counter_value_config(TIMER0);

timer_counter_read

The description of timer_counter_read is shown as below:

Table 3-865. Function timer_counter_read


Function name timer_counter_read
Function prototype uint32_t timer_counter_read(uint32_t timer_periph);
Function descriptions read TIMER counter value
Precondition -
The called functions -
Input parameter{in}
606
GD32E50x Firmware Library User Guide
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value
uint32_t counter value(0~0xFFFFFFFF)

Example:

/* read TIMER0 counter value */

uint32_t i = 0;

i = timer_counter_read(TIMER0);

timer_prescaler_read

The description of timer_prescaler_read is shown as below:

Table 3-866. Function timer_prescaler_read


Function name timer_prescaler_read
Function prototype uint16_t timer_prescaler_read(uint32_t timer_periph);
Function descriptions read TIMER prescaler value
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Output parameter{out}
- -
Return value
uint16_t prescaler register value (0x0000~0xFFFF)

Example:

/* read TIMER0 prescaler value */

uint16_t i = 0;

i = timer_prescaler_read(TIMER0);

timer_single_pulse_mode_config

The description of timer_single_pulse_mode_config is shown as below:

Table 3-867. Function timer_single_pulse_mode_config


Function name timer_single_pulse_mode_config
void timer_single_pulse_mode_config(uint32_t timer_periph, uint8_t
Function prototype
spmode);

607
GD32E50x Firmware Library User Guide
Function descriptions configure TIMER single pulse mode
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..8,11) TIMER peripheral selection
Input parameter{in}
spmode pulse mode
TIMER_SP_MODE_SIN
single pulse mode
GLE
TIMER_SP_MODE_RE
repetitive pulse mode
PETITIVE
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 single pulse mode */

timer_single_pulse_mode_config(TIMER0, TIMER_SP_MODE_SINGLE);

timer_update_source_config

The description of timer_update_source_config is shown as below:

Table 3-868. Function timer_update_source_config


Function name timer_update_source_config
Function prototype void timer_update_source_config(uint32_t timer_periph, uint32_t update);
Function descriptions configure TIMER update source
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..13) TIMER peripheral selection
Input parameter{in}
update update source
Any of the following events generate an update interrupt or DMA request:

– The UPG bit is set


TIMER_UPDATE_SRC_
GLOBAL
– The counter generates an overflow or underflow event

– The slave mode controller generates an update event


TIMER_UPDATE_SRC_ Only counter overflow/underflow generates an update interrupt or DMA
608
GD32E50x Firmware Library User Guide
REGULAR request.
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER update only by counter overflow/underflow */

timer_update_source_config(TIMER0, TIMER_UPDATE_SRC_REGULAR);

timer_dma_enable

The description of timer_dma_enable is shown as below:

Table 3-869. Function timer_dma_enable


Function name timer_dma_enable
Function prototype void timer_dma_enable(uint32_t timer_periph, uint16_t dma);
Function descriptions enable the TIMER DMA
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
dma timer DMA source enable
TIMER_DMA_UPD update DMA enable, TIMERx(x=0..7)
TIMER_DMA_CH0D channel 0 DMA enable, TIMERx(x=0..4,7)
TIMER_DMA_CH1D channel 1 DMA enable, TIMERx(x=0..4,7)
TIMER_DMA_CH2D channel 2 DMA enable, TIMERx(x=0..4,7)
TIMER_DMA_CH3D channel 3 DMA enable, TIMERx(x=0..4,7)
TIMER_DMA_CMTD commutation DMA request enable, TIMERx(x=0,7)
TIMER_DMA_TRGD trigger DMA enable, TIMERx(x=0..4,7)
Output parameter{out}
- -
Return value
- -

Example:

/* enable the TIMER0 update DMA */

timer_dma_enable(TIMER0, TIMER_DMA_UPD);

609
GD32E50x Firmware Library User Guide
timer_dma_disable

The description of timer_dma_disable is shown as below:

Table 3-870. Function timer_dma_disable


Function name timer_dma_disable
Function prototype void timer_dma_disable (uint32_t timer_periph, uint16_t dma);
Function descriptions disable the TIMER DMA
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
dma timer DMA source disable
TIMER_DMA_UPD update DMA disable, TIMERx(x=0..7)
TIMER_DMA_CH0D channel 0 DMA disable, TIMERx(x=0..4,7)
TIMER_DMA_CH1D channel 1 DMA disable, TIMERx(x=0..4,7)
TIMER_DMA_CH2D channel 2 DMA disable, TIMERx(x=0..4,7)
TIMER_DMA_CH3D channel 3 DMA disable, TIMERx(x=0..4,7)
TIMER_DMA_CMTD commutation DMA request disable, TIMERx(x=0,7)
TIMER_DMA_TRGD trigger DMA disable, TIMERx(x=0..4,7)
Output parameter{out}
- -
Return value
- -

Example:

/* disable the TIMER0 update DMA */

timer_dma_disable(TIMER0, TIMER_DMA_UPD);

timer_channel_dma_request_source_select

The description of timer_channel_dma_request_source_select is shown as below:

Table 3-871. Function timer_channel_dma_request_source_select


Function name timer_channel_dma_request_source_select
void timer_channel_dma_request_source_select(uint32_t timer_periph,
Function prototype
uint32_t dma_request);
Function descriptions channel DMA request source selection
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral

610
GD32E50x Firmware Library User Guide
TIMERx TIMER peripheral selection
Input parameter{in}
dma_request channel DMA request source selection
TIMER_DMAREQUEST
DMA request of channel n is sent when channel y event occurs
_CHANNELEVENT
TIMER_DMAREQUEST
DMA request of channel n is sent when update event occurs
_UPDATEEVENT
Output parameter{out}
- -
Return value
- -

Example:

/* TIMER0 channel DMA request of channel n is sent when channel y event occurs */

timer_channel_dma_request_source_select(TIMER0,
TIMER_DMAREQUEST_CHANNELEVENT);

timer_dma_transfer_config

The description of timer_dma_transfer_config is shown as below:

Table 3-872. Function timer_dma_transfer_config


Function name timer_dma_transfer_config
void timer_dma_transfer_config(uint32_t timer_periph, uint32_t
Function prototype
dma_baseaddr, uint32_t dma_lenth);
Function descriptions configure the TIMER DMA transfer
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
dma_baseaddr DMA transfer access start address
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CTL0, TIMERx(x=0..4,7)
TA_CTL0
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CTL1, TIMERx(x=0..4,7)
TA_CTL1
TIMER_DMACFG_DMA
DMA transfer address is TIMER_SMCFG, TIMERx(x=0..4,7)
TA_SMCFG
TIMER_DMACFG_DMA
DMA transfer address is TIMER_DMAINTEN, TIMERx(x=0..4,7)
TA_DMAINTEN
TIMER_DMACFG_DMA
DMA transfer address is TIMER_INTF, TIMERx(x=0..4,7)
TA_INTF

611
GD32E50x Firmware Library User Guide
TIMER_DMACFG_DMA
DMA transfer address is TIMER_SWEVG, TIMERx(x=0..4,7)
TA_SWEVG
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CHCTL0, TIMERx(x=0..4,7)
TA_CHCTL0
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CHCTL1, TIMERx(x=0..4,7)
TA_CHCTL1
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CHCTL2, TIMERx(x=0..4,7)
TA_CHCTL2
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CNT, TIMERx(x=0..4,7)
TA_CNT
TIMER_DMACFG_DMA
DMA transfer address is TIMER_PSC, TIMERx(x=0..4,7)
TA_PSC
TIMER_DMACFG_DMA
MA transfer address is TIMER_CAR, TIMERx(x=0..4,7)
TA_CAR
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CREP, TIMERx(x=0,7)
TA_CREP
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CH0CV, TIMERx(x=0..4,7)
TA_CH0CV
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CH1CV, TIMERx(x=0..4,7)
TA_CH1CV
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CH2CV, TIMERx(x=0..4,7)
TA_CH2CV
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CH3CV, TIMERx(x=0..4,7)
TA_CH3CV
TIMER_DMACFG_DMA
DMA transfer address is TIMER_CCHP, TIMERx(x=0,7)
TA_CCHP
TIMER_DMACFG_DMA
DMA transfer address is TIMER_DMACFG, TIMERx(x=0..4,7)
TA_DMACFG
TIMER_DMACFG_DMA
DMA transfer address is TIMER_DMATB, TIMERx(x=0..4,7)
TA_DMATB
Input parameter{in}
dma_lenth DMA transfer count
TIMER_DMACFG_DMA
x=1..18, DMA transfer x time
TC_xTRANSFER
Output parameter{out}
- -
Return value
- -

Example:

/* configure the TIMER0 DMA transfer */

timer_dma_transfer_config(TIMER0, TIMER_DMACFG_DMATA_CTL0,
TIMER_DMACFG_DMATC_5TRANSFER);
612
GD32E50x Firmware Library User Guide
timer_event_software_generate

The description of timer_event_software_generate is shown as below:

Table 3-873. Function timer_event_software_generate


Function name timer_event_software_generate
void timer_event_software_generate(uint32_t timer_periph, uint16_t
Function prototype
event);
Function descriptions software generate events
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
event the timer software event generation sources
TIMER_EVENT_SRC_U
update event,TIMERx(x=0..13)
PG
TIMER_EVENT_SRC_C
channel 0 capture or compare event generation,TIMERx(x=0..4,7..13)
H0G
TIMER_EVENT_SRC_C
channel 1 capture or compare event generation,TIMERx(x=0..4,7,8,11)
H1G
TIMER_EVENT_SRC_C
channel 2 capture or compare event generation,TIMERx(x=0..4,7)
H2G
TIMER_EVENT_SRC_C
channel 3 capture or compare event generation,TIMERx(x=0..4,7)
H3G
TIMER_EVENT_SRC_C
channel commutation event generation,TIMERx(x=0,7)
MTG
TIMER_EVENT_SRC_T
trigger event generation,TIMERx(x=0..4,7,8,11)
RGG
TIMER_EVENT_SRC_B
break event generation,TIMERx(x=0,7)
RKG
Output parameter{out}
- -
Return value
- -

Example:

/* software generate update event*/

timer_event_software_generate(TIMER0, TIMER_EVENT_SRC_UPG);

timer_break_struct_para_init

The description of timer_break_struct_para_init is shown as below:


613
GD32E50x Firmware Library User Guide
Table 3-874. Function timer_break_struct_para_init
Function name timer_break_struct_para_init
void timer_break_struct_para_init(timer_break_parameter_struct*
Function prototype
breakpara);
initialize the parameters of TIMER break parameter struct with the default
Function descriptions
values
Precondition -
The called functions -
Input parameter{in}
TIMER break parameter struct, the structure members can refer to
breakpara
Structure timer_break_parameter_struct.
Output parameter{out}
- -
Return value
- -

Example:

/* initialize TIMER break parameter struct with a default value */

timer_break_parameter_struct timer_breakpara;

timer_break_struct_para_init(&timer_breakpara);

timer_break_config

The description of timer_break_config is shown as below:

Table 3-875. Function timer_break_config


Function name timer_break_config
void timer_break_config(uint32_t timer_periph,
Function prototype
timer_break_parameter_struct* breakpara);
Function descriptions configure TIMER break function
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Input parameter{in}
TIMER break parameter struct, the structure members can refer to
breakpara
Structure timer_break_parameter_struct.
Output parameter{out}
- -
Return value
- -

614
GD32E50x Firmware Library User Guide
Example:

/* configure TIMER0 break function */

timer_break_parameter_struct timer_breakpara;

timer_breakpara.runoffstate = TIMER_ROS_STATE_DISABLE;

timer_breakpara.ideloffstate = TIMER_IOS_STATE_DISABLE ;

timer_breakpara.deadtime = 255;

timer_breakpara.breakpolarity = TIMER_BREAK_POLARITY_LOW;

timer_breakpara.outputautostate = TIMER_OUTAUTO_ENABLE;

timer_breakpara.protectmode = TIMER_CCHP_PROT_0;

timer_breakpara.breakstate = TIMER_BREAK_ENABLE;

timer_break_config(TIMER0, &timer_breakpara);

timer_break_enable

The description of timer_break_enable is shown as below:

Table 3-876. Function timer_break_enable


Function name timer_break_enable
Function prototype void timer_break_enable(uint32_t timer_periph);
Function descriptions enable TIMER break function
This function can be called only when PROT [1:0] bit-filed in
Precondition
TIMERx_CCHP register is 00.
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable TIMER0 break function*/

timer_break_enable (TIMER0);

timer_break_disable

The description of timer_break_disable is shown as below:

615
GD32E50x Firmware Library User Guide
Table 3-877. Function timer_break_disable
Function name timer_break_disable
Function prototype void timer_break_disable(uint32_t timer_periph);
Function descriptions disable TIMER break function
This function can be called only when PROT [1:0] bit-filed in
Precondition
TIMERx_CCHP register is 00.
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable TIMER0 break function*/

timer_break_disable(TIMER0);

timer_automatic_output_enable

The description of timer_automatic_output_enable is shown as below:

Table 3-878. Function timer_automatic_output_enable


Function name timer_automatic_output_enable
Function prototype void timer_automatic_output_enable(uint32_t timer_periph);
Function descriptions enable TIMER output automatic function
This function can be called only when PROT [1:0] bit-filed in
Precondition
TIMERx_CCHP register is 00.
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* enable TIMER0 output automatic function */

timer_automatic_output_enable(TIMER0);

616
GD32E50x Firmware Library User Guide
timer_automatic_output_disable

The description of timer_automatic_output_disable is shown as below:

Table 3-879. Function timer_automatic_output_disable


Function name timer_automatic_output_ disable
Function prototype void timer_automatic_output_ disable (uint32_t timer_periph);
Function descriptions disable TIMER output automatic function
This function can be called only when PROT [1:0] bit-filed in
Precondition
TIMERx_CCHP register is 00.
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable TIMER0 output automatic function */

timer_automatic_output_disable(TIMER0);

timer_primary_output_config

The description of timer_primary_output_config is shown as below:

Table 3-880. Function timer_primary_output_config


Function name timer_primary_output_config
void timer_primary_output_config(uint32_t timer_periph, ControlStatus
Function prototype
newvalue);
Function descriptions configure TIMER primary output function
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Input parameter{in}
newvalue control value
ENABLE enable function
DISABLE disable function
Output parameter{out}
- -
Return value

617
GD32E50x Firmware Library User Guide
- -

Example:

/* enable TIMER0 primary output function */

timer_primary_output_config(TIMER0, ENABLE);

timer_channel_control_shadow_config

The description of timer_channel_control_shadow_config is shown as below:

Table 3-881. Function timer_channel_control_shadow_config


Function name timer_channel_control_shadow_config
void timer_channel_control_shadow_config(uint32_t timer_periph,
Function prototype
ControlStatus newvalue);
Function descriptions channel commutation control shadow register enable
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Input parameter{in}
newvalue control value
ENABLE enable function
DISABLE disable function
Output parameter{out}
- -
Return value
- -

Example:

/* channel capture/compare control shadow register enable */

timer_channel_control_shadow_config(TIMER0, ENABLE);

timer_channel_control_shadow_update_config

The description of timer_channel_control_shadow_update_config is shown as below:

Table 3-882. Function timer_channel_control_shadow_update_config


Function name timer_channel_control_shadow_update_config
void timer_channel_control_shadow_update_config(uint32_t timer_periph,
Function prototype
uint32_t ccuctl);
Function descriptions configure commutation control shadow register update control
Precondition -
The called functions -
618
GD32E50x Firmware Library User Guide
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Input parameter{in}
ccuctl channel control shadow register update control
TIMER_UPDATECTL_C
the shadow registers update by when CMTG bit is set
CU
TIMER_UPDATECTL_C the shadow registers update by when CMTG bit is set or an rising edge of
CUTRI TRGI occurs
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel control shadow register update when CMTG bit is set */

timer_channel_control_shadow_update_config(TIMER0, TIMER_UPDATECTL_CCU);

timer_channel_output_struct_para_init

The description of timer_channel_output_struct_para_init is shown as below:

Table 3-883. Function timer_channel_output_struct_para_init


Function name timer_channel_output_struct_para_init
void timer_channel_output_struct_para_init(timer_oc_parameter_struct*
Function prototype
ocpara);
initialize the parameters of TIMER channel output parameter struct with the
Function descriptions
default values
Precondition -
The called functions -
Input parameter{in}
TIMER channel output parameter struct, the structure members can refer to
ocpara
Structure timer_oc_parameter_struct.
Output parameter{out}
- -
Return value
- -

Example:

/* initialize TIMER channel output parameter struct with a default value */

timer_oc_parameter_struct timer_ocinitpara;

timer_channel_output_struct_para_init(&timer_ocinitpara);

619
GD32E50x Firmware Library User Guide
timer_channel_output_config

The description of timer_channel_output_config is shown as below:

Table 3-884. Function timer_channel_output_config


Function name timer_channel_output_config
void timer_channel_output_config(uint32_t timer_periph, uint16_t channel,
Function prototype
timer_oc_parameter_struct* ocpara);
Function descriptions configure TIMER channel output function
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
TIMER channel output parameter struct, the structure members can refer
ocpara
to Structure timer_oc_parameter_struct.
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel 0 output function */

timer_oc_parameter_struct timer_ocinitpara;

timer_ocinitpara.outputstate = TIMER_CCX_ENABLE;

timer_ocinitpara.outputnstate = TIMER_CCXN_ENABLE;

timer_ocinitpara.ocpolarity = TIMER_OC_POLARITY_HIGH;

timer_ocinitpara.ocnpolarity = TIMER_OCN_POLARITY_HIGH;

timer_ocinitpara.ocidlestate = TIMER_OC_IDLE_STATE_HIGH;

timer_ocinitpara.ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;

timer_channel_output_config(TIMER0, TIMER_CH_0, &timer_ocinitpara);

620
GD32E50x Firmware Library User Guide
timer_channel_output_mode_config

The description of timer_channel_output_mode_config is shown as below:

Table 3-885. Function timer_channel_output_mode_config


Function name timer_channel_output_mode_config
void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t
Function prototype
channel, uint16_t ocmode);
Function descriptions configure TIMER channel output compare mode
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
ocmode channel output compare mode
TIMER_OC_MODE_TIM
timing mode
ING
TIMER_OC_MODE_AC
set the channel output
TIVE
TIMER_OC_MODE_INA
clear the channel output
CTIVE
TIMER_OC_MODE_TO
toggle on match
GGLE
TIMER_OC_MODE_LO
force low mode
W
TIMER_OC_MODE_HIG
force high mode
H
TIMER_OC_MODE_PW
PWM mode 0
M0
TIMER_OC_MODE_PW
PWM mode 1
M1
Output parameter{out}
- -
Return value
- -

Example:

621
GD32E50x Firmware Library User Guide
/* configure TIMER0 channel PWM 0 mode */

timer_channel_output_mode_config(TIMER0, TIMER_CH_0, TIMER_OC_MODE_PWM0);

timer_channel_output_pulse_value_config

The description of timer_channel_output_pulse_value_config is shown as below:

Table 3-886. Function timer_channel_output_pulse_value_config


Function name timer_channel_output_pulse_value_config
void timer_channel_output_pulse_value_config(uint32_t timer_periph,
Function prototype
uint16_t channel, uint32_t pulse);
Function descriptions configure TIMER channel output pulse value
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
pulse channel output pulse value(0~0xFFFFFFFF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel 0 output pulse value */

timer_channel_output_pulse_value_config(TIMER0, TIMER_CH_0, 399);

timer_channel_output_shadow_config

The description of timer_channel_output_shadow_config is shown as below:

Table 3-887. Function timer_channel_output_shadow_config


Function name timer_channel_output_shadow_config
void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t
Function prototype
channel, uint16_t ocshadow);
Function descriptions configure TIMER channel output shadow function
Precondition -
622
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
ocshadow channel output shadow state
TIMER_OC_SHADOW_
channel output shadow state enable
ENABLE
TIMER_OC_SHADOW_
channel output shadow state disable
DISABLE
Output parameter{out}
- -
Return value
- -

Example:

/*configure TIMER0 channel 0 output shadow function */

timer_channel_output_shadow_config (TIMER0, TIMER_CH_0,


TIMER_OC_SHADOW_ENABLE);

timer_channel_output_fast_config

The description of timer_channel_output_fast_config is shown as below:

Table 3-888. Function timer_channel_output_fast_config


Function name timer_channel_output_fast_config
void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t
Function prototype
channel, uint16_t ocfast);
Function descriptions configure TIMER channel output fast function
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))

623
GD32E50x Firmware Library User Guide
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 TIMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
ocfast channel output fast function
TIMER_OC_FAST_ENA
channel output fast function enable
BLE
TIMER_OC_FAST_DIS
channel output fast function disable
ABLE
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel 0 output fast function */

timer_channel_output_fast_config (TIMER0, TIMER_CH_0, TIMER_OC_FAST_ENABLE);

timer_channel_output_clear_config

The description of timer_channel_output_clear_config is shown as below:

Table 3-889. Function timer_channel_output_clear_config


Function name timer_channel_output_clear_config
void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t
Function prototype
channel, uint16_t occlear);
Function descriptions configure TIMER channel output clear function
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER periphera
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 TIMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
occlear channel output clear function
TIMER_OC_CLEAR_EN
channel output clear function enable
ABLE
TIMER_OC_CLEAR_DI channel output clear function disable

624
GD32E50x Firmware Library User Guide
SABLE
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel 0 output clear function */

timer_channel_output_clear_config (TIMER0, TIMER_CH_0,


TIMER_OC_CLEAR_ENABLE);

timer_channel_output_polarity_config

The description of timer_channel_output_polarity_config is shown as below:

Table 3-890. Function timer_channel_output_polarity_config


Function name timer_channel_output_polarity_config
void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t
Function prototype
channel, uint16_t ocpolarity);
Function descriptions configure TIMER channel output polarity
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
ocpolarity channel output polarity
TIMER_OC_POLARITY
channel output polarity is high
_HIGH
TIMER_OC_POLARITY
channel output polarity is low
_LOW
Output parameter{out}
- -
Return value
- -

Example:

625
GD32E50x Firmware Library User Guide
/* configure TIMER0 channel 0 output polarity */

timer_channel_output_polarity_config(TIMER0, TIMER_CH_0,
TIMER_OC_POLARITY_HIGH);

timer_channel_complementary_output_polarity_config

The description of timer_channel_complementary_output_polarity_config is shown as below:

Table 3-891. Function timer_channel_complementary_output_polarity_config


Function name timer_channel_complementary_output_polarity_config
void timer_channel_complementary_output_polarity_config(uint32_t
Function prototype
timer_periph, uint16_t channel, uint16_t ocnpolarity);
Function descriptions configure TIMER channel complementary output polarity
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0
TIMER_CH_1 TIMER channel 1
TIMER_CH_2 TIMER channel 2
Input parameter{in}
ocpolarity channel complementary output polarity
TIMER_OCN_POLARIT
channel complementary output polarity is high
Y_HIGH
TIMER_OCN_POLARIT
channel complementary output polarity is low
Y_LOW
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel 0 complementary output polarity */

timer_channel_complementary_output_polarity_config(TIMER0, TIMER_CH_0,
TIMER_OCN_POLARITY_HIGH);

timer_channel_output_state_config

The description of timer_channel_output_state_config is shown as below:

626
GD32E50x Firmware Library User Guide
Table 3-892. Function timer_channel_output_state_config
Function name timer_channel_output_state_config
void timer_channel_output_state_config(uint32_t timer_periph, uint16_t
Function prototype
channel, uint32_t state);
Function descriptions configure TIMER channel enable state
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
state TIMER channel enable state
TIMER_CCX_ENABLE channel enable
TIMER_CCX_DISABLE channel disable
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel 0 enable state */

timer_channel_output_state_config(TIMER0, TIMER_CH_0, TIMER_CCX_ENABLE);

timer_channel_complementary_output_state_config

The description of timer_channel_complementary_output_state_config is shown as below:

Table 3-893. Function timer_channel_complementary_output_state_config


Function name timer_channel_complementary_output_state_config
void timer_channel_complementary_output_state_config(uint32_t
Function prototype
timer_periph, uint16_t channel, uint16_t ocnstate);
Function descriptions configure TIMER channel complementary output enable state
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection

627
GD32E50x Firmware Library User Guide
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0
TIMER_CH_1 TIMER channel 1
TIMER_CH_2 TIMER channel 2
Input parameter{in}
state TIMER channel complementary output enable state
TIMER_CCXN_ENABLE channel complementary enable
TIMER_CCXN_DISABL
channel complementary disable
E
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel 0 complementary output enable state */

timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_0,
TIMER_CCXN_ENABLE);

timer_channel_input_struct_para_init

The description of timer_channel_input_struct_para_init is shown as below:

Table 3-894. Function timer_channel_input_struct_para_init


Function name timer_channel_input_struct_para_init
void timer_channel_input_struct_para_init(timer_ic_parameter_struct*
Function prototype
icpara);
initialize the parameters of TIMER channel input parameter struct with the
Function descriptions
default values
Precondition -
The called functions -
Input parameter{in}
TIMER channel intput parameter struct, the structure members can refer to
icpara
Structure timer_ic_parameter_struct.
Output parameter{out}
- -
Return value
- -

Example:

/* initialize TIMER channel input parameter struct with a default value */

timer_ic_parameter_struct timer_icinitpara;
628
GD32E50x Firmware Library User Guide
timer_channel_input_struct_para_init(&timer_icinitpara);

timer_input_capture_config

The description of timer_input_capture_config is shown as below:

Table 3-895. Function timer_input_capture_config


Function name timer_input_capture_config
void timer_input_capture_config(uint32_t timer_periph, uint16_t channel,
Function prototype
timer_ic_parameter_struct* icpara);
Function descriptions configure TIMER input capture parameter
Precondition -
The called functions timer_channel_input_capture_prescaler_config
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
TIMER channel intput parameter struct, the structure members can refer to
icpara
Structure timer_ic_parameter_struct
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 input capture parameter */

timer_ic_parameter_struct timer_icinitpara;

timer_icinitpara.icpolarity = TIMER_IC_POLARITY_RISING;

timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI;

timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;

timer_icinitpara.icfilter = 0x0;

timer_input_capture_config(TIMER0, TIMER_CH_0, &timer_icinitpara);

629
GD32E50x Firmware Library User Guide
timer_channel_input_capture_prescaler_config

The description of timer_channel_input_capture_prescaler_config is shown as below:

Table 3-896. Function timer_channel_input_capture_prescaler_config


Function name timer_channel_input_capture_prescaler_config
void timer_channel_input_capture_prescaler_config(uint32_t timer_periph,
Function prototype
uint16_t channel, uint16_t prescaler);
Function descriptions configure TIMER channel input capture prescaler value
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Input parameter{in}
prescaler channel input capture prescaler value
TIMER_IC_PSC_DIV1 no prescaler
TIMER_IC_PSC_DIV2 divided by 2
TIMER_IC_PSC_DIV4 divided by 4
TIMER_IC_PSC_DIV8 divided by 8
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 channel 0 input capture prescaler value */

timer_channel_input_capture_prescaler_config(TIMER0, TIMER_CH_0,
TIMER_IC_PSC_DIV2);

timer_channel_capture_value_register_read

The description of timer_channel_capture_value_register_read is shown as below:

Table 3-897. Function timer_channel_capture_value_register_read


Function name timer_channel_capture_value_register_read
uint32_t timer_channel_capture_value_register_read(uint32_t
Function prototype
timer_periph, uint16_t channel);

630
GD32E50x Firmware Library User Guide
Function descriptions read TIMER channel capture compare register value
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0 (TIMERx(x=0..4,7..13))
TIMER_CH_1 TIMER channel 1 (TIMERx(x=0..4,7,8,11))
TIMER_CH_2 TIMER channel 2 (TIMERx(x=0..4,7))
TIMER_CH_3 IMER channel 3 (TIMERx(x=0..4,7))
Output parameter{out}
- -
Return value
uint32_t channel capture compare register value (0~0xFFFFFFFF)

Example:

/* read TIMER0 channel 0 capture compare register value */

uint32_t ch0_value = 0;

ch0_value = timer_channel_capture_value_register_read(TIMER0, TIMER_CH_0);

timer_input_pwm_capture_config

The description of timer_input_pwm_capture_config is shown as below:

Table 3-898. Function timer_input_pwm_capture_config


Function name timer_input_pwm_capture_config
void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t
Function prototype
channel, timer_ic_parameter_struct* icpwm);
Function descriptions configure TIMER input pwm capture function
Precondition -
The called functions timer_channel_input_capture_prescaler_config
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7,8,11) TIMER peripheral selection
Input parameter{in}
channel channel to be configured
TIMER_CH_0 TIMER channel 0
TIMER_CH_1 TIMER channel 1
Input parameter{in}
TIMER channel intput pwm parameter struct, the structure members can
icpwm
refer to Structure timer_ic_parameter_struct.
631
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 input pwm capture parameter */

timer_ic_parameter_struct timer_icinitpara;

timer_icinitpara.icpolarity = TIMER_IC_POLARITY_RISING;

timer_icinitpara.icselection = TIMER_IC_SELECTION_DIRECTTI;

timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;

timer_icinitpara.icfilter = 0x0;

timer_input_pwm_capture_config(TIMER0, TIMER_CH_0, &timer_icinitpara);

timer_hall_mode_config

The description of timer_hall_mode_config is shown as below:

Table 3-899. Function timer_hall_mode_config


Function name timer_hall_mode_config
Function prototype void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode);
Function descriptions configure TIMER hall sensor mode
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7) TIMER peripheral selection
Input parameter{in}
hallmode TIMER hall sensor mode state
TIMER_HALLINTERFA
TIMER hall sensor mode enable
CE_ENABLE
TIMER_HALLINTERFA
TIMER hall sensor mode disable
CE_DISABLE
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 hall sensor mode */

timer_hall_mode_config (TIMER0, TIMER_HALLINTERFACE_ENABLE);


632
GD32E50x Firmware Library User Guide
timer_input_trigger_source_select

The description of timer_input_trigger_source_select is shown as below:

Table 3-900. Function timer_input_trigger_source_select


Function name timer_input_trigger_source_select
void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t
Function prototype
intrigger);
Function descriptions select TIMER input trigger source
Precondition SMC[2:0] = 000
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
intrigger trigger selection
TIMER_SMCFG_TRGS
Internal trigger input 0 (ITI0, TIMERx(x=0..4,7,8,11) )
EL_ITI0
TIMER_SMCFG_TRGS
Internal trigger input 0 (ITI1, TIMERx(x=0..4,7,8,11) )
EL_ITI1
TIMER_SMCFG_TRGS
Internal trigger input 0 (ITI2, TIMERx(x=0..4,7,8,11) )
EL_ITI2
TIMER_SMCFG_TRGS
Internal trigger input 0 (ITI3, TIMERx(x=0..4,7,8,11) )
EL_ITI3
TIMER_SMCFG_TRGS
CI0 edge flag (CI0F_ED, TIMERx(x=0..4,7,8,11) )
EL_CI0F_ED
TIMER_SMCFG_TRGS
channel 0 input Filtered output (CI0FE0, TIMERx(x=0..4,7,8,11) )
EL_CI0FE0
TIMER_SMCFG_TRGS
channel 1 input Filtered output (CI1FE1, TIMERx(x=0..4,7,8,11) )
EL_CI1FE1
TIMER_SMCFG_TRGS
External trigger input filter output(ETIFP, TIMERx(x=0..4,7) )
EL_ETIFP
Output parameter{out}
- -
Return value
- -

Example:

/* select TIMER0 input trigger source */

timer_input_trigger_source_select (TIMER0, TIMER_SMCFG_TRGSEL_ITI0);

timer_master_output_trigger_source_select

The description of timer_master_output_trigger_source_select is shown as below:


633
GD32E50x Firmware Library User Guide
Table 3-901. Function timer_master_output_trigger_source_select
Function name timer_master_output_trigger_source_select
void timer_master_output_trigger_source_select(uint32_t timer_periph,
Function prototype
uint32_t outrigger);
Function descriptions select TIMER master mode output trigger source
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0,7) TIMER peripheral selection
Input parameter{in}
outrigger master mode control
Reset. When the UPG bit in the TIMERx_SWEVG register is set or a reset
TIMER_TRI_OUT_SRC is generated by the slave mode controller, a TRGO pulse occurs. And in
_RESET the latter case, the signal on TRGO is delayed compared to the actual
reset
Enable. This mode is useful to start several timers at the same time or to
control a window in which a slave timer is enabled. In this mode the master
TIMER_TRI_OUT_SRC mode controller selects the counter enable signal as TRGO. The counter
_ENABLE 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.
TIMER_TRI_OUT_SRC Update. In this mode the master mode controller selects the update event
_UPDATE as TRGO.
TIMER_TRI_OUT_SRC Capture/compare pulse. In this mode the master mode controller generates
_CC0 a TRGO pulse when a capture or a compare match occurred in channel 0.
TIMER_TRI_OUT_SRC Compare. In this mode the master mode controller selects the O0CPRE
_O0CPRE signal is used as TRGO.
TIMER_TRI_OUT_SRC Compare. In this mode the master mode controller selects the O1CPRE
_O1CPRE signal is used as TRGO.
TIMER_TRI_OUT_SRC Compare. In this mode the master mode controller selects the O2CPRE
_O2CPRE signal is used as TRGO.
TIMER_TRI_OUT_SRC Compare. In this mode the master mode controller selects the O3CPRE
_O3CPRE signal is used as TRGO.
Output parameter{out}
- -
Return value
- -

Example:

/* select TIMER0 master mode output trigger source */

timer_master_output_trigger_source_select (TIMER0, TIMER_TRI_OUT_SRC_RESET);

634
GD32E50x Firmware Library User Guide
timer_slave_mode_select

The description of timer_slave_mode_select is shown as below:

Table 3-902. Function timer_slave_mode_select


Function name timer_slave_mode_select
Function prototype void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode);
Function descriptions select TIMER slave mode
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7,8,11) TIMER peripheral selection
Input parameter{in}
slavemode slave mode
TIMER_SLAVE_MODE_
slave mode disable
DISABLE
TIMER_ENCODER_MO
encoder mode 0
DE0
TIMER_ENCODER_MO
encoder mode 1
DE1
TIMER_ENCODER_MO
encoder mode 2
DE2
TIMER_SLAVE_MODE_
restart mode
RESTART
TIMER_SLAVE_MODE_
pause mode
PAUSE
TIMER_SLAVE_MODE_
event mode
EVENT
TIMER_SLAVE_MODE_
external clock mode 0
EXTERNAL0
Output parameter{out}
- -
Return value
- -

Example:

/* select TIMER0 slave mode */

timer_slave_mode_select (TIMER0, TIMER_ENCODER_MODE0);

timer_master_slave_mode_config

The description of timer_master_slave_mode_config is shown as below:

635
GD32E50x Firmware Library User Guide
Table 3-903. Function timer_master_slave_mode_config
Function name timer_master_slave_mode_config
void timer_master_slave_mode_config(uint32_t timer_periph, uint8_t
Function prototype
masterslave);
Function descriptions configure TIMER master slave mode
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7,8,11) TIMER peripheral selection
Input parameter{in}
masterslave master slave mode state
TIMER_MASTER_SLAV
master slave mode enable
E_MODE_ENABLE
TIMER_MASTER_SLAV
master slave mode disable
E_MODE_DISABLE
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 master slave mode */

timer_master_slave_mode_config(TIMER0, TIMER_MASTER_SLAVE_MODE_ENABLE);

timer_external_trigger_config

The description of timer_external_trigger_config is shown as below:

Table 3-904. Function timer_external_trigger_config


Function name timer_external_trigger_config
void timer_external_trigger_config(uint32_t timer_periph, uint32_t
Function prototype
extprescaler, uint32_t expolarity, uint32_t extfilter);
Function descriptions configure TIMER external trigger input
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7) TIMER peripheral selection
Input parameter{in}
extprescaler external trigger prescaler
TIMER_EXT_TRI_PSC_
no divided
OFF

636
GD32E50x Firmware Library User Guide
TIMER_EXT_TRI_PSC_
divided by 2
DIV2
TIMER_EXT_TRI_PSC_
divided by 4
DIV4
TIMER_EXT_TRI_PSC_
divided by 8
DIV8
Input parameter{in}
expolarity external trigger polarity
TIMER_ETP_FALLING active low or falling edge active
TIMER_ETP_RISING active high or rising edge active
Input parameter{in}
extfilter external trigger filter control(0~15)
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 external trigger input */

timer_external_trigger_config(TIMER0, TIMER_EXT_TRI_PSC_DIV2,
TIMER_ETP_FALLING, 10);

timer_quadrature_decoder_mode_config

The description of timer_quadrature_decoder_mode_config is shown as below:

Table 3-905. Function timer_quadrature_decoder_mode_config


Function name timer_quadrature_decoder_mode_config
void timer_quadrature_decoder_mode_config(uint32_t timer_periph,
Function prototype
uint32_t decomode, uint16_t ic0polarity, uint16_t ic1polarity);
Function descriptions configure TIMER quadrature decoder mode
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7) TIMER peripheral selection
Input parameter{in}
decomode quadrature decoder mode
TIMER_ENCODER_MO
counter counts on CI0FE0 edge depending on CI1FE1 level
DE0
TIMER_ENCODER_MO
counter counts on CI1FE1 edge depending on CI0FE0 level
DE1
TIMER_ENCODER_MO counter counts on both CI0FE0 and CI1FE1 edges depending on the level

637
GD32E50x Firmware Library User Guide
DE2 of the other input
Input parameter{in}
ic0polarity IC0 polarity
TIMER_IC_POLARITY_
capture rising edge
RISING
TIMER_IC_POLARITY_
capture falling edge
FALLING
TIMER_IC_POLARITY_
active both edge
BOTH_EDGE
Input parameter{in}
ic1polarity IC1 polarity
TIMER_IC_POLARITY_
capture rising edge
RISING
TIMER_IC_POLARITY_
capture falling edge
FALLING
TIMER_IC_POLARITY_
active both edge
BOTH_EDGE
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 quadrature decoder mode */

timer_quadrature_decoder_mode_config(TIMER0, TIMER_ENCODER_MODE0,
TIMER_IC_POLARITY_RISING, TIMER_IC_POLARITY_RISING);

timer_internal_clock_config

The description of timer_internal_clock_config is shown as below:

Table 3-906. Function timer_internal_clock_config


Function name timer_internal_clock_config
Function prototype void timer_internal_clock_config(uint32_t timer_periph);
Function descriptions configure TIMER internal clock mode
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7,8,11) TIMER peripheral selection
Output parameter{out}
- -
Return value

638
GD32E50x Firmware Library User Guide
- -

Example:

/* configure TIMER0 internal clock mode */

timer_internal_clock_config (TIMER0);

timer_internal_trigger_as_external_clock_config

The description of timer_internal_trigger_as_external_clock_config is shown as below:

Table 3-907. Function timer_internal_trigger_as_external_clock_config


Function name timer_internal_trigger_as_external_clock_config
void timer_internal_trigger_as_external_clock_config(uint32_t
Function prototype
timer_periph, uint32_t intrigger);
Function descriptions configure TIMER the internal trigger as external clock input
Precondition -
The called functions timer_input_trigger_source_select
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7,8,11) TIMER peripheral selection
Input parameter{in}
intrigger trigger selection
TIMER_SMCFG_TRGS
Internal trigger input 0 (ITI0)
EL_ITI0
TIMER_SMCFG_TRGS
Internal trigger input 0 (ITI1)
EL_ITI1
TIMER_SMCFG_TRGS
Internal trigger input 0 (ITI2)
EL_ITI2
TIMER_SMCFG_TRGS
Internal trigger input 0 (ITI3)
EL_ITI3
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 the internal trigger ITI0 as external clock input */

timer_internal_trigger_as_external_clock_config(TIMER0, TIMER_SMCFG_TRGSEL_ITI0);

timer_external_trigger_as_external_clock_config

The description of timer_external_trigger_as_external_clock_config is shown as below:

639
GD32E50x Firmware Library User Guide
Table 3-908. Function timer_external_trigger_as_external_clock_config
Function name timer_external_trigger_as_external_clock_config
void timer_external_trigger_as_external_clock_config(uint32_t
Function prototype
timer_periph, uint32_t extrigger, uint16_t expolarity, uint32_t extfilter);
Function descriptions configure TIMER the external trigger as external clock input
Precondition -
The called functions timer_input_trigger_source_select
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7,8,11) TIMER peripheral selection
Input parameter{in}
extrigger external trigger selection
TIMER_SMCFG_TRGS
CI0 edge flag (CI0F_ED)
EL_CI0F_ED
TIMER_SMCFG_TRGS
channel 0 input Filtered output (CI0FE0)
EL_CI0FE0
TIMER_SMCFG_TRGS
channel 1 input Filtered output (CI1FE1)
EL_CI1FE1
Input parameter{in}
expolarity external trigger polarity
TIMER_IC_POLARITY_
active high or rising edge active
RISING
TIMER_IC_POLARITY_
active low or falling edge active
FALLING
TIMER_IC_POLARITY_
active both edge
BOTH_EDGE
Input parameter{in}
extfilter external trigger filter control(0~15)
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 the external trigger CI0FE0 as external clock input */

timer_external_trigger_as_external_clock_config(TIMER0,
TIMER_SMCFG_TRGSEL_CI0FE0, TIMER_IC_POLARITY_RISING, 0);

timer_external_clock_mode0_config

The description of timer_external_clock_mode0_config is shown as below:

640
GD32E50x Firmware Library User Guide
Table 3-909. Function timer_external_clock_mode0_config
Function name timer_external_clock_mode0_config
void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t
Function prototype
extprescaler, uint32_t expolarity, uint32_t extfilter);
Function descriptions configure TIMER the external clock mode0
Precondition -
The called functions timer_external_trigger_config
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7,8,11) TIMER peripheral selection
Input parameter{in}
extprescaler ETI external trigger prescaler
TIMER_EXT_TRI_PSC_
no divided
OFF
TIMER_EXT_TRI_PSC_
divided by 2
DIV2
TIMER_EXT_TRI_PSC_
divided by 4
DIV4
TIMER_EXT_TRI_PSC_
divided by 8
DIV8
Input parameter{in}
expolarity ETI external trigger polarity
TIMER_ETP_FALLING active low or falling edge active
TIMER_ETP_RISING active high or rising edge active
Input parameter{in}
extfilter ETI external trigger filter control(0~15)
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 the external clock mode0 */

timer_external_clock_mode0_config(TIMER0, TIMER_EXT_TRI_PSC_DIV2,
TIMER_ETP_FALLING, 0);

timer_external_clock_mode1_config

The description of timer_external_clock_mode1_config is shown as below:

Table 3-910. Function timer_external_clock_mode1_config


Function name timer_external_clock_mode1_config
Function prototype void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t

641
GD32E50x Firmware Library User Guide
extprescaler, uint32_t expolarity, uint32_t extfilter);
Function descriptions configure TIMER the external clock mode1
Precondition -
The called functions timer_external_trigger_config
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7) TIMER peripheral selection
Input parameter{in}
extprescaler ETI external trigger prescaler
TIMER_EXT_TRI_PSC_
no divided
OFF
TIMER_EXT_TRI_PSC_
divided by 2
DIV2
TIMER_EXT_TRI_PSC_
divided by 4
DIV4
TIMER_EXT_TRI_PSC_
divided by 8
DIV8
Input parameter{in}
expolarity ETI external trigger polarity
TIMER_ETP_FALLING active low or falling edge active
TIMER_ETP_RISING active high or rising edge active
Input parameter{in}
extfilter ETI external trigger filter control(0~15)
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 the external clock mode1 */

timer_external_clock_mode1_config(TIMER0, TIMER_EXT_TRI_PSC_DIV2,
TIMER_ETP_FALLING, 0);

timer_external_clock_mode1_disable

The description of timer_external_clock_mode1_disable is shown as below:

Table 3-911. Function timer_external_clock_mode1_disable


Function name timer_external_clock_mode1_disable
Function prototype void timer_external_clock_mode1_disable(uint32_t timer_periph);
Function descriptions disable TIMER the external clock mode1
Precondition -
The called functions -

642
GD32E50x Firmware Library User Guide
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7) TIMER peripheral selection
Output parameter{out}
- -
Return value
- -

Example:

/* disable TIMER0 the external clock mode1 */

timer_external_clock_mode1_disable(TIMER0);

timer_write_chxval_register_config

The description of timer_write_chxval_register_config is shown as below:

Table 3-912. Function timer_write_chxval_register_config


Function name timer_write_chxval_register_config
void timer_write_chxval_register_config(uint32_t timer_periph, uint16_t
Function prototype
ccsel);
Function descriptions configure TIMER write CHxVAL register selection
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx(x=0..4,7..13) TIMER peripheral selection
Input parameter{in}
ccsel write CHxVAL register selection
TIMER_CHVSEL_DISA
no effect
BLE
TIMER_CHVSEL_ENAB when write the CHxVAL register, if the write value is same as the CHxVAL
LE value, the write access is ignored
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER0 write CHxVAL register selection */

timer_write_chxval_register_config(TIMER0, TIMER_CHVSEL_ENABLE);

643
GD32E50x Firmware Library User Guide
timer_output_value_selection_config

The description of timer_output_value_selection_config is shown as below:

Table 3-913. Function timer_output_value_selection_config


Function name timer_output_value_selection_config
void timer_output_value_selection_config(uint32_t timer_periph, uint16_t
Function prototype
outsel);
Function descriptions configure TIMER output value selection
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx (x=0,7) TIMER peripheral selection
Input parameter{in}
outsel output value selection
TIMER_OUTSEL_DISA
no effect
BLE
TIMER_OUTSEL_ENAB
if POEN and IOS is 0, the output disabled
LE
Output parameter{out}
- -
Return value
- -

Example:

/* configure TIMER output value selection */

timer_output_value_selection_config(TIMER0, TIMER_OUTSEL_ENABLE);

timer_flag_get

The description of timer_flag_get is shown as below:

Table 3-914. Function timer_flag_get


Function name timer_flag_get
Function prototype FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag);
Function descriptions get TIMER flags
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
flag the timer interrupt flags

644
GD32E50x Firmware Library User Guide
TIMER_FLAG_UP update flag,TIMERx(x=0..13)
TIMER_FLAG_CH0 channel 0 flag,TIMERx(x=0..4,7..13)
TIMER_FLAG_CH1 channel 1 flag,TIMERx(x=0..4,7,8,11)
TIMER_FLAG_CH2 channel 2 flag,TIMERx(x=0..4,7)
TIMER_FLAG_CH3 channel 3 flag,TIMERx(x=0..4,7)
TIMER_FLAG_CMT channel commutation flag,TIMERx(x=0,7)
TIMER_FLAG_TRG trigger flag,TIMERx(x=0,7,8,11)
TIMER_FLAG_BRK break flag,TIMERx(x=0,7)
TIMER_FLAG_CH0O channel 0 overcapture flag,TIMERx(x=0..4,7..11)
TIMER_FLAG_CH1O channel 1 overcapture flag,TIMERx(x=0..4,7,8,11)
TIMER_FLAG_CH2O channel 2 overcapture flag,TIMERx(x=0..4,7)
TIMER_FLAG_CH3O channel 3 overcapture flag,TIMERx(x=0..4,7)
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get TIMER0 update flags */

FlagStatus Flag_status = RESET;

Flag_status = timer_flag_get(TIMER0, TIMER_FLAG_UP);

timer_flag_clear

The description of timer_flag_clear is shown as below:

Table 3-915. Function timer_flag_clear


Function name timer_flag_clear
Function prototype void timer_flag_clear(uint32_t timer_periph, uint32_t flag);
Function descriptions clear TIMER flags
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
flag the timer interrupt flags
TIMER_FLAG_UP update flag,TIMERx(x=0..13)
TIMER_FLAG_CH0 channel 0 flag,TIMERx(x=0..4,7..13)
TIMER_FLAG_CH1 channel 1 flag,TIMERx(x=0..4,7,8,11)
TIMER_FLAG_CH2 channel 2 flag,TIMERx(x=0..4,7)
TIMER_FLAG_CH3 channel 3 flag,TIMERx(x=0..4,7)
TIMER_FLAG_CMT channel commutation flag,TIMERx(x=0,7)
645
GD32E50x Firmware Library User Guide
TIMER_FLAG_TRG trigger flag,TIMERx(x=0,7,8,11)
TIMER_FLAG_BRK break flag,TIMERx(x=0,7)
TIMER_FLAG_CH0O channel 0 overcapture flag,TIMERx(x=0..4,7..11)
TIMER_FLAG_CH1O channel 1 overcapture flag,TIMERx(x=0..4,7,8,11)
TIMER_FLAG_CH2O channel 2 overcapture flag,TIMERx(x=0..4,7)
TIMER_FLAG_CH3O channel 3 overcapture flag,TIMERx(x=0..4,7)
Output parameter{out}
- -
Return value
- -

Example:

/* clear TIMER0 update flags */

timer_flag_clear(TIMER0, TIMER_FLAG_UP);

timer_interrupt_enable

The description of timer_interrupt_enable is shown as below:

Table 3-916. Function timer_interrupt_enable


Function name timer_interrupt_enable
Function prototype void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt);
Function descriptions enable the TIMER interrupt
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
interrupt timer interrupt enable source
TIMER_INT_UP update interrupt enable, TIMERx (x=0..13)
TIMER_INT_CH0 channel 0 interrupt enable, TIMERx (x=0..4,7..13)
TIMER_INT_CH1 channel 1 interrupt enable, TIMERx (x=0..4,7,8,11)
TIMER_INT_CH2 channel 2 interrupt enable, TIMERx (x=0..4,7)
TIMER_INT_CH3 channel 3 interrupt enable , TIMERx (x=0..4,7)
TIMER_INT_CMT commutation interrupt enable, TIMERx (x=0,7)
TIMER_INT_TRG trigger interrupt enable, TIMERx (x=0..4,7,8,11)
TIMER_INT_BRK break interrupt enable, TIMERx (x=0,7)
Output parameter{out}
- -
Return value
- -

Example:
646
GD32E50x Firmware Library User Guide
/* enable the TIMER0 update interrupt */

timer_interrupt_enable (TIMER0, TIMER_INT_UP);

timer_interrupt_disable

The description of timer_interrupt_disable is shown as below:

Table 3-917. Function timer_interrupt_disable


Function name timer_interrupt_ disable
Function prototype void timer_interrupt_ disable (uint32_t timer_periph, uint32_t interrupt);
Function descriptions disable the TIMER interrupt
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
interrupt timer interrupt disable source
TIMER_INT_UP update interrupt disable, TIMERx(x=0..13)
TIMER_INT_CH0 channel 0 interrupt disable, TIMERx(x=0..4,7..13)
TIMER_INT_CH1 channel 1 interrupt disable, TIMERx(x=0..4,7,8,11)
TIMER_INT_CH2 channel 2 interrupt disable, TIMERx(x=0..4,7)
TIMER_INT_CH3 channel 3 interrupt disable, TIMERx(x=0..4,7)
TIMER_INT_CMT commutation interrupt disable, TIMERx(x=0,7)
TIMER_INT_TRG trigger interrupt disable, TIMERx(x=0..4,7,8,11)
TIMER_INT_BRK break interrupt disable, TIMERx(x=0,7)
Output parameter{out}
- -
Return value
- -

Example:

/* disable the TIMER0 update interrupt */

timer_interrupt_disable(TIMER0, TIMER_INT_UP);

timer_interrupt_flag_get

The description of timer_interrupt_flag_get is shown as below:

Table 3-918. Function timer_interrupt_flag_get


Function name timer_interrupt_flag_get
FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t
Function prototype
int_flag);
Function descriptions get timer interrupt flag
647
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
int_flag the timer interrupt bits
TIMER_INT_FLAG_UP update interrupt flag,TIMERx(x=0..13)
TIMER_INT_FLAG_CH0 channel 0 interrupt flag,TIMERx(x=0..4,7..13)
TIMER_INT_FLAG_CH1 channel 1 interrupt flag,TIMERx(x=0..4,7,8,11)
TIMER_INT_FLAG_CH2 channel 2 interrupt flag,TIMERx(x=0..4,7)
TIMER_INT_FLAG_CH3 channel 3 interrupt flag,TIMERx(x=0..4,7)
TIMER_INT_FLAG_CM
channel commutation interrupt flag,TIMERx(x=0,7)
T
TIMER_INT_FLAG_TRG trigger interrupt flag,TIMERx(x=0,7,8,11)
TIMER_INT_FLAG_BRK break interrupt flag,TIMERx(x=0,7)
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get TIMER0 update interrupt flag */

FlagStatus Flag_ interrupt = RESET;

Flag_ interrupt = timer_interrupt_flag_get(TIMER0, TIMER_INT_FLAG_UP);

timer_interrupt_flag_clear

The description of timer_interrupt_flag_clear is shown as below:

Table 3-919. Function timer_interrupt_flag_clear


Function name timer_interrupt_flag_clear
Function prototype void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t int_flag);
Function descriptions clear TIMER interrupt flag
Precondition -
The called functions -
Input parameter{in}
timer_periph TIMER peripheral
TIMERx please refer to the following parameters
Input parameter{in}
int_flag the timer interrupt bits
TIMER_INT_FLAG_UP update interrupt flag,TIMERx(x=0..13)
TIMER_INT_FLAG_CH0 channel 0 interrupt flag,TIMERx(x=0..4,7..13)
648
GD32E50x Firmware Library User Guide
TIMER_INT_FLAG_CH1 channel 1 interrupt flag,TIMERx(x=0..4,7,8,11)
TIMER_INT_FLAG_CH2 channel 2 interrupt flag,TIMERx(x=0..4,7)
TIMER_INT_FLAG_CH3 channel 3 interrupt flag,TIMERx(x=0..4,7)
TIMER_INT_FLAG_CM
channel commutation interrupt flag,TIMERx(x=0,7)
T
TIMER_INT_FLAG_TRG trigger interrupt flag,TIMERx(x=0,7,8,11)
TIMER_INT_FLAG_BRK break interrupt flag,TIMERx(x=0,7)
Output parameter{out}
- -
Return value
- -

Example:

/* clear TIMER0 update interrupt flag */

timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_UP);

3.26. TMU

The Trigonometric Math Unit (TMU) is a fully configurable block that execute common
trigonometric and arithmetic operations.The TMU calculation unit can be used to calculate
total 9 kinds of operations. The operation data must meet IEEE 32-Bit Single Precision
Floating-Point Format. The TMU registers are listed in chapter 3.26.1 ,the TMU firmware
functions are introduced in chapter3.26.2.

3.26.1. Descriptions of Peripheral registers

TMU registers are listed in the table shown as below:

Table 3-920. TMU Registers


Registers Descriptions
TMU_IDATA0 input data0 register
TMU_IDATA1 input data1 register
TMU_CTL control register
TMU_DATA0 data0 register
TMU_DATA1 data1 register
TMU_STAT status register

3.26.2. Descriptions of Peripheral functions

TMU firmware functions are listed in the table shown as below:

649
GD32E50x Firmware Library User Guide
Table 3-921. TMU firmware function
Function name Function description
tmu_deinit reset the TMU
tmu_enable enable the TMU
tmu_mode_set configure the TMU mode
tmu_idata0_write write the data to TMU input data0 regisetr
tmu_idata1_write write the data to TMU input data1 regisetr
tmu_data0_read read the data from TMU data0 regisetr
tmu_data1_read read the data from TMU data1 regisetr
tmu_interrupt_enable enable TTMU interrupt
tmu_interrupt_disable disable TTMU interrupt
tmu_flag_get check teh TMU status flag
tmu_interrupt_flag_get check teh TMU interrupt flag

tmu_deinit

The description of tmu_deinit is shown as below:

Table 3-922. Function tmu_deinit


Function name tmu_deinit
Function prototype void tmu_deinit(void);
Function descriptions reset the TMU
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset the TMU */

tmu_deinit();

tmu_enable

The description of tmu_enable is shown as below:

Table 3-923. Function tmu_enable


Function name tmu_enable
Function prototype void tmu_enable (void);
Function descriptions enable the TMU
Precondition -

650
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable the TMU */

void tmu_enable(void);

tmu_mode_set

The description of tmu_mode_set is shown as below:

Table 3-924. Function tmu_mode_set


Function name tmu_mode_set
Function prototype void tmu_mode_set(uint32_t modex);
Function descriptions configure the TMU mode
Precondition -
The called functions -
Input parameter{in}
modex the operation mode of TMU
TMU_MODE0 the operation mode0
TMU_MODE1 the operation mode1
TMU_MODE2 the operation mode2
TMU_MODE3 the operation mode3
TMU_MODE4 the operation mode4
TMU_MODE5 the operation mode5
TMU_MODE6 the operation mode6
TMU_MODE7 the operation mode7
TMU_MODE8 the operation mode8
Output parameter{out}
- -
Return value
- -

Example:

/* configure the TMU mode0 */

tmu_mode_set(TMU_MODE0);

651
GD32E50x Firmware Library User Guide
tmu_idata0_write

The description of tmu_idata0_write is shown as below:

Table 3-925. Function tmu_idata0_write


Function name tmu_idata0_write
Function prototype void tmu_idata0_write(uint32_t idata0);
Function descriptions write the data to TMU input data0 regisetr
Precondition -
The called functions -
Input parameter{in}
idata0 the value write to input data0
Output parameter{out}
- -
Return value
- -

Example:

/* write the idata0 register */

tmu_idata0_write (0XBF000000);

tmu_idata1_write

The description of tmu_idata1_write is shown as below:

Table 3-926. Function tmu_idata1_write


Function name tmu_idata1_write
Function prototype void tmu_idata1_write(uint32_t idata1);
Function descriptions write the data to TMU input data1 regisetr
Precondition -
The called functions -
Input parameter{in}
idata1 the value write to input data1
Output parameter{out}
- -
Return value
- -

Example:

/* write the idata1 register */

tmu_idata1_write (0XBF000000);

652
GD32E50x Firmware Library User Guide
tmu_data0_read

The description of tmu_data0_read is shown as below:

Table 3-927. Function tmu_data0_read


Function name tmu_data0_read
Function prototype uint32_t tmu_data0_read(void);
Function descriptions read the data from TMU data0 regisetr
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
the value of data0 register meet IEEE 32-Bit Single Precision Floating-Point
uint32_t
Format

Example:

/* read the data from TMU data0 regisetr*/

uint32_t tmu_value = 0;

tmu_value = tmu_data0_read();

tmu_data1_read

The description of tmu_data1_read is shown as below:

Table 3-928. Function tmu_data1_read


Function name tmu_data1_read
Function prototype uint32_t tmu_data1_read(void);
Function descriptions read the data from TMU data1 regisetr
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
the value of data1 register meet IEEE 32-Bit Single Precision Floating-Point
uint32_t
Format

Example:

/* read the data from TMU data1 regisetr*/

653
GD32E50x Firmware Library User Guide
uint32_t tmu_value = 0;

tmu_value = tmu_data1_read();

tmu_interrupt_enable

The description of tmu_interrupt_enable is shown as below:

Table 3-929. Function tmu_interrupt_enable


Function name tmu_interrupt_enable
Function prototype void tmu_interrupt_enable(void);
Function descriptions enable TMU interrupt
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable TMU interrupt */

void tmu_interrupt_enable();

tmu_interrupt_disable

The description of tmu_interrupt_disable is shown as below:

Table 3-930. Function tmu_interrupt_disable


Function name tmu_interrupt_disable
Function prototype void tmu_interrupt_disable(void);
Function descriptions disable TMU interrupt
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* disable TMU interrupt */

654
GD32E50x Firmware Library User Guide
void tmu_interrupt_disable();

tmu_flag_get

The description of tmu_flag_get is shown as below:

Table 3-931. Function tmu_flag_get


Function name tmu_flag_get
Function prototype FlagStatus tmu_flag_get(uint32_t flag);
Function descriptions check teh TMU status flag
Precondition -
The called functions -
Input parameter{in}
flag teh TMU status flag
TMU_FLAG_OVRF the flag of TMU overflow
TMU_FLAG_UDRF the flag of TMU underflow
Output parameter{out}
- -
Return value
FlagStatus SET/RESET

Example:

/* check the TMU overflow flag */

tmu_flag_get(TMU_FLAG_OVRF);

tmu_interrupt_flag_get

The description of tmu_interrupt_flag_get is shown as below:

Table 3-932. Function tmu_interrupt_flag_get


Function name tmu_interrupt_flag_get
Function prototype FlagStatus tmu_interrupt_flag_get (uint32_t flag);
Function descriptions check teh TMU interrupt flag
Precondition -
The called functions -
Input parameter{in}
interrupt teh TMU interrupt flag
TMU_INT_FLAG_CFIF the interrupt flag of calculation finished
Output parameter{out}
- -
Return value
FlagStatus SET/RESET

Example:

655
GD32E50x Firmware Library User Guide
/* check teh TMU interrupt flag */

tmu_interrupt_flag_getTMU_INT_FLAG_CFIF);

3.27. USART

The Universal Synchronous/Asynchronous Receiver/Transmitter (USART) provides a flexible


serial data exchange interface. The USART registers are listed in chapter 3.27.1, the USART
firmware functions are introduced in chapter 3.27.2.

3.27.1. Descriptions of Peripheral registers

USART registers are listed in the table shown as below:

Table 3-933. USART Registers


Registers Descriptions
USART_STAT0 Status register 0 (USARTx, x=0..4)
USART_DATA Data register (USARTx, x=0..4)
USART_BAUD Baud rate register (USARTx, x=0..4)
USART_CTL0 Control register 0 (USARTx, x=0..4)
USART_CTL1 Control register 1 (USARTx, x=0..4)
USART_CTL2 Control register 2 (USARTx, x=0..4)
USART_GP Guard time and prescaler register (USARTx, x=0..4)
USART_CTL3 Control register 3 (USARTx, x=0..4)
USART_RT Receiver timeout register (USARTx, x=0..4)
USART_STAT1 Status register 1 (USARTx, x=0..4)
USART_GDCTL GD control register (USARTx, x=0..4)
USART5_CTL0 Control register 0 (USARTx, x=5)
USART5_CTL1 Control register 1 (USARTx, x=5)
USART5_CTL2 Control register 2 (USARTx, x=5)
USART5_BAUD Baud rate register (USARTx, x=5)
USART5_GP Guard time and prescaler register (USARTx, x=5)
USART5_RT Receiver timeout register (USARTx, x=5)
USART5_CMD Command regster (USARTx, x=5)
USART5_STAT Status register (USARTx, x=5)
USART5_INTC Interrupt status clear register (USARTx, x=5)
USART5_RDATA Receive data register (USARTx, x=5)
USART5_TDATA Transmit data register (USARTx, x=5)
USART5_CHC Coherence control register (USARTx, x=5)
USART5_RFCS Receive FIFO control and status register (USARTx, x=5)

656
GD32E50x Firmware Library User Guide
3.27.2. Descriptions of Peripheral functions

USART firmware functions are listed in the table shown as below:

Table 3-934. USART firmware function


Function name Function description
usart_deinit reset USART/UART (USARTx, x=0..5)
usart_baudrate_set configure USART baud rate value (USARTx, x=0..5)
usart_parity_config configure USART parity (USARTx, x=0..5)
usart_word_length_set configure USART word length (USARTx, x=0..5)
usart_stop_bit_set configure USART stop bit length (USARTx, x=0..5)
usart_enable enable USART (USARTx, x=0..5)
usart_disable disable USART (USARTx, x=0..5)
usart_transmit_config configure USART transmitter (USARTx, x=0..5)
usart_receive_config configure USART receiver (USARTx, x=0..5)
usart_oversample_config configure the USART oversample mode (USARTx, x=0..5)
usart_sample_bit_config configure sample bit method (USARTx, x=0..5)
usart_receiver_timeout_enable enable receiver timeout (USARTx, x=0..5)
usart_receiver_timeout_disable disable receiver timeout (USARTx, x=0..5)
usart_receiver_timeout_threshold_con
configure receiver timeout threshold (USARTx, x=0..5)
fig
usart_data_transmit USART transmit data function (USARTx, x=0..5)
usart_data_receive USART receive data function (USARTx, x=0..5)
usart_mute_mode_enable enable mute mode (USARTx, x=0..5)
usart_mute_mode_disable disable mute mode (USARTx, x=0..5)
usart_mute_mode_wakeup_config configure wakeup method in mute mode (USARTx, x=0..5)
usart_lin_mode_enable enable LIN mode (USARTx, x=0..5)
usart_lin_mode_disable disable LIN mode (USARTx, x=0..5)
usart_lin_break_dection_length_confi
configure LIN break frame length (USARTx, x=0..5)
g
usart_halfduplex_enable enable half duplex mode (USARTx, x=0..5)
usart_halfduplex_disable disable half duplex mode (USARTx, x=0..5)
usart_synchronous_clock_enable enable CK pin in synchronous mode (USARTx, x=0..5)
usart_synchronous_clock_disable disable CK pin in synchronous mode (USARTx, x=0..5)
configure USART synchronous mode parameters (USARTx,
usart_synchronous_clock_config
x=0..5)
configure guard time value in smartcard mode (USARTx,
usart_guard_time_config
x=0..5)
usart_smartcard_mode_enable enable smartcard mode (USARTx, x=0..5)
usart_smartcard_mode_disable disable smartcard mode (USARTx, x=0..5)
usart_smartcard_mode_nack_enable enable NACK in smartcard mode (USARTx, x=0..5)
usart_smartcard_mode_nack_disable disable NACK in smartcard mode (USARTx, x=0..5)
usart_smartcard_autoretry_config configure smartcard auto-retry number (USARTx, x=0..5)

657
GD32E50x Firmware Library User Guide
Function name Function description
usart_block_length_config configure block length (USARTx, x=0..5)
usart_irda_mode_enable enable IrDA mode (USARTx, x=0..5)
usart_irda_mode_disable disable IrDA mode (USARTx, x=0..5)
configure the peripheral clock prescaler in USART IrDA low-
usart_prescaler_config
power mode (USARTx, x=0..5)
usart_irda_lowpower_config configure IrDA low-power (USARTx, x=0..5)
usart_hardware_flow_rts_config configure hardware flow control RTS (USARTx, x=0..5)
usart_hardware_flow_cts_config configure hardware flow control CTS (USARTx, x=0..5)
usart_dma_receive_config configure USART DMA reception (USARTx, x=0..5)
usart_dma_transmit_config configure USART DMA transmission (USARTx, x=0..5)
data is transmitted/received with the LSB/MSB first (USARTx,
usart_data_first_config
x=0..4)
usart_invert_config configure USART inverted (USARTx, x=0..4)
configure the address of the USART in wake up by address
usart_address_config
match mode (USARTx, x=0..4)
usart_send_break send break frame (USARTx, x=0..4)
usart_collision_detected_interrupt_en
enable collision detected interrupt (USARTx, x=0..4)
able
usart_collision_detected_interrupt_dis
disable collision detected interrupt (USARTx, x=0..4)
able
usart_collision_detection_enable enable collision detection (USARTx, x=0..4)
usart_collision_detection_disable disable collision detection (USARTx, x=0..4)
usart_flag_get get flag in STAT0/STAT1 register (USARTx, x=0..4)
usart_flag_clear clear flag in STAT0/STAT1 register (USARTx, x=0..4)
usart_interrupt_enable enable USART interrupt (USARTx, x=0..4)
usart_interrupt_disable disable USART interrupt (USARTx, x=0..4)
usart_interrupt_flag_get get USART interrupt flag status (USARTx, x=0..4)
usart_interrupt_flag_clear clear USART interrupt flag (USARTx, x=0..4)
data is transmitted/received with the LSB/MSB first (USARTx,
usart5_data_first_config
x=5)
usart5_invert_config configure USART5 inverted (USARTx, x=5)
usart5_overrun_enable enable the USART5 overrun function (USARTx, x=5)
usart5_overrun_disable disable the USART5 overrun function (USARTx, x=5)
usart5_autobaud_detection_enable enable auto baud rate detection (USARTx, x=5)
usart5_autobaud_detection_disable disable auto baud rate detection (USARTx, x=5)
usart5_autobaud_detection_mode_co
configure auto baud rate detection mode (USARTx, x=5)
nfig
usart5_address_config configure address of the USART5 (USARTx, x=5)
usart5_address_detection_mode_conf
configure address detection mode (USARTx, x=5)
ig
usart5_smartcard_mode_early_nack_
enable early NACK in smartcard mode (USARTx, x=5)
enable
658
GD32E50x Firmware Library User Guide
Function name Function description
usart5_smartcard_mode_early_nack_
disable early NACK in smartcard mode (USARTx, x=5)
disable
usart5_hardware_flow_coherence_co configure hardware flow control coherence mode (USARTx,
nfig x=5)
usart5_rs485_driver_enable enable RS485 driver (USARTx, x=5)
usart5_rs485_driver_disable disable RS485 driver (USARTx, x=5)
usart5_driver_assertime_config configure driver enable assertion time (USARTx, x=5)
usart5_driver_deassertime_config configure driver enable de-assertion time (USARTx, x=5)
usart5_depolarity_config configure driver enable polarity mode (USARTx, x=5)
usart5_reception_error_dma_enable enable DMA on reception error (USARTx, x=5)
usart5_reception_error_dma_disable disable DMA on reception error (USARTx, x=5)
enable USART to wakeup the mcu from deep-sleep mode
usart5_wakeup_enable
(USARTx, x=5)
disable USART to wakeup the mcu from deep-sleep mode
usart5_wakeup_disable
(USARTx, x=5)
configure the USART wakeup mode from deep-sleep mode
usart5_wakeup_mode_config
(USARTx, x=5)
usart5_receive_fifo_enable enable receive FIFO (USARTx, x=5)
usart5_receive_fifo_disable disable receive FIFO (USARTx, x=5)
usart5_receive_fifo_counter_number read receive FIFO counter number (USARTx, x=5)
usart5_flag_get get flag in STAT/RFCS register (USARTx, x=5)
usart5_flag_clear clear USART status (USARTx, x=5)
usart5_interrupt_enable enable USART interrupt (USARTx, x=5)
usart5_interrupt_disable disable USART interrupt (USARTx, x=5)
usart5_command_enable enable USART command (USARTx, x=5)
usart5_interrupt_flag_get get USART interrupt and flag status (USARTx, x=5)
usart5_interrupt_flag_clear clear USART interrupt flag (USARTx, x=5)

Enum usart_flag_enum

Table 3-935. Enum usart_flag_enum


Member name Function description
USART_FLAG_CTS CTS change flag
USART_FLAG_LBD LIN break detected flag
USART_FLAG_TBE transmit data buffer empty
USART_FLAG_TC transmission complete
USART_FLAG_RBNE read data buffer not empty
USART_FLAG_IDLE IDLE line detected flag
USART_FLAG_ORERR overrun error
USART_FLAG_NERR noise error flag
USART_FLAG_FERR frame error flag
USART_FLAG_PERR parity error flag

659
GD32E50x Firmware Library User Guide
Member name Function description
USART_FLAG_BSY busy flag
USART_FLAG_EB end of block flag
USART_FLAG_RT receiver timeout flag
USART_FLAG_CD collision detected flag

Enum usart5_flag_enum

Table 3-936. Enum usart5_flag_enum


Member name Function description
USART5_FLAG_REA receive enable acknowledge flag
USART5_FLAG_TEA transmit enable acknowledge flag
USART5_FLAG_WU wakeup from deep-sleep mode flag
USART5_FLAG_RWU receiver wakeup from mute mode
USART5_FLAG_SB send break flag
USART5_FLAG_AM ADDR match flag
USART5_FLAG_BSY busy flag
USART5_FLAG_ABD auto baudrate detection flag
USART5_FLAG_ABDE auto baudrate detection error
USART5_FLAG_EB end of block flag
USART5_FLAG_RT receiver timeout flag
USART5_FLAG_CTS CTS level
USART5_FLAG_CTSF CTS change flag
USART5_FLAG_LBD LIN break detected flag
USART5_FLAG_TBE transmit data buffer empty
USART5_FLAG_TC transmission complete
USART5_FLAG_RBNE read data buffer not empty
USART5_FLAG_IDLE IDLE line detected flag
USART5_FLAG_ORERR overrun error
USART5_FLAG_NERR noise error flag
USART5_FLAG_FERR frame error flag
USART5_FLAG_PERR parity error flag
USART5_FLAG_EPERR early parity error flag
USART5_FLAG_RFFINT receive FIFO full interrupt flag
USART5_FLAG_RFF receive FIFO full flag
USART5_FLAG_RFE receive FIFO empty flag

Enum usart_interrupt_flag_enum

Table 3-937. Enum usart_interrupt_flag_enum


Member name Function description
USART_INT_FLAG_PERR parity error interrupt and flag
USART_INT_FLAG_TBE transmitter buffer empty interrupt and flag

660
GD32E50x Firmware Library User Guide
Member name Function description
USART_INT_FLAG_TC transmission complete interrupt and flag
USART_INT_FLAG_RBNE read data buffer not empty interrupt and flag
USART_INT_FLAG_RBNE_ORE
read data buffer not empty interrupt and overrun error flag
RR
USART_INT_FLAG_IDLE IDLE line detected interrupt and flag
USART_INT_FLAG_LBD LIN break detected interrupt and flag
USART_INT_FLAG_CTS CTS interrupt and flag
USART_INT_FLAG_ERR_ORER
error interrupt and overrun error
R
USART_INT_FLAG_ERR_NERR error interrupt and noise error flag
USART_INT_FLAG_ERR_FERR error interrupt and frame error flag
USART_INT_FLAG_EB interrupt enable bit of end of block event and flag
USART_INT_FLAG_RT interrupt enable bit of receive timeout event and flag
USART_INT_FLAG_CD collision detected interrupt and flag

Enum usart5_interrupt_flag_enum

Table 3-938. Enum usart5_interrupt_flag_enum


Member name Function description
USART5_INT_FLAG_EB end of block interrupt and flag
USART5_INT_FLAG_RT receiver timeout interrupt and flag
USART5_INT_FLAG_AM address match interrupt and flag
USART5_INT_FLAG_PERR parity error interrupt and flag
USART5_INT_FLAG_TBE transmitter buffer empty interrupt and flag
USART5_INT_FLAG_TC transmission complete interrupt and flag
USART5_INT_FLAG_RBNE read data buffer not empty interrupt and flag
USART5_INT_FLAG_RBNE_ORE
read data buffer not empty interrupt and overrun error flag
RR
USART5_INT_FLAG_IDLE IDLE line detected interrupt and flag
USART5_INT_FLAG_LBD LIN break detected interrupt and flag
USART5_INT_FLAG_WU wakeup from deep-sleep mode interrupt and flag
USART5_INT_FLAG_CTS CTS interrupt and flag
USART5_INT_FLAG_ERR_NERR error interrupt and noise error flag
USART5_INT_FLAG_ERR_ORER
error interrupt and overrun error
R
USART5_INT_FLAG_ERR_FERR error interrupt and frame error flag
USART5_INT_FLAG_RFF receive FIFO full interrupt and flag

661
GD32E50x Firmware Library User Guide
Enum usart_interrupt_enum

Table 3-939. Enum usart_interrupt_enum


Member name Function description
USART_INT_PERR parity error interrupt
USART_INT_TBE transmitter buffer empty interrupt
USART_INT_TC transmission complete interrupt
USART_INT_RBNE read data buffer not empty interrupt and overrun error interrupt
USART_INT_IDLE IDLE line detected interrupt
USART_INT_LBD LIN break detected interrupt
USART_INT_CTS CTS interrupt
USART_INT_ERR error interrupt
USART_INT_EB interrupt enable bit of end of block event
USART_INT_RT interrupt enable bit of receive timeout event
USART_INT_CD collision detected interrupt

Enum usart5_interrupt_enum

Table 3-940. Enum usart5_interrupt_enum


Member name Function description
USART5_INT_EB end of block interrupt
USART5_INT_RT receiver timeout interrupt
USART5_INT_AM address match interrupt
USART5_INT_PERR parity error interrupt
USART5_INT_TBE transmitter buffer empty interrupt
USART5_INT_TC transmission complete interrupt
USART5_INT_RBNE read data buffer not empty interrupt and overrun error interrupt
USART5_INT_IDLE IDLE line detected interrupt
USART5_INT_LBD LIN break detected interrupt
USART5_INT_WU wakeup from deep-sleep mode interrupt
USART5_INT_CTS CTS interrupt
USART5_INT_ERR error interrupt
USART5_INT_RFF receive FIFO full interrupt

Enum usart_invert_enum

Table 3-941. Enum usart_invert_enum


Member name Function description
USART_DINV_ENABLE data bit level inversion
USART_DINV_DISABLE data bit level not inversion
USART_TXPIN_ENABLE TX pin level inversion
USART_TXPIN_DISABLE TX pin level not inversion
USART_RXPIN_ENABLE RX pin level inversion
USART_RXPIN_DISABLE RX pin level not inversion
662
GD32E50x Firmware Library User Guide
Enum usart5_invert_enum

Table 3-942. Enum usart5_invert_enum


Member name Function description
USART5_DINV_ENABLE data bit level inversion
USART5_DINV_DISABLE data bit level not inversion
USART5_TXPIN_ENABLE TX pin level inversion
USART5_TXPIN_DISABLE TX pin level not inversion
USART5_RXPIN_ENABLE RX pin level inversion
USART5_RXPIN_DISABLE RX pin level not inversion
USART5_SWAP_ENABLE swap TX/RX pins
USART5_SWAP_DISABLE not swap TX/RX pins

usart_deinit

The description of usart_deinit is shown as below:

Table 3-943. Function usart_deinit


Function name usart_deinit
Function prototype void usart_deinit(uint32_t usart_periph);
Function descriptions reset USART/UART
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* reset USART0 */

usart_deinit (USART0);

usart_baudrate_set

The description of usart_baudrate_set is shown as below:

Table 3-944. Function usart_baudrate_set


Function name usart_baudrate_set
Function prototype void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval);
Function descriptions configure USART baud rate value

663
GD32E50x Firmware Library User Guide
Precondition -
The called functions rcu_periph_reset_enable / rcu_periph_reset_disable
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
baudval baud rate value
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 baud rate value */

usart_baudrate_set(USART0, 115200);

usart_parity_config

The description of usart_parity_config is shown as below:

Table 3-945. Function usart_parity_config


Function name usart_parity_config
Function prototype void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg);
Function descriptions configure USART parity
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
paritycfg configure USART parity
USART_PM_NONE no parity
USART_PM_ODD odd parity
USART_PM_EVEN even parity
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART parity */

664
GD32E50x Firmware Library User Guide
usart_parity_config(USART0, USART_PM_EVEN);

usart_word_length_set

The description of usart_word_length_set is shown as below:

Table 3-946. Function usart_word_length_set


Function name usart_word_length_set
Function prototype void usart_word_length_set(uint32_t usart_periph, uint32_t wlen);
Function descriptions configure USART word length
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
wlen USART word length
USART_WL_8BIT 8 bits
USART_WL_9BIT 9 bits
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 word length */

usart_word_length_set(USART0, USART_WL_9BIT);

usart_stop_bit_set

The description of usart_stop_bit_set is shown as below:

Table 3-947. Function usart_stop_bit_set


Function name usart_stop_bit_set
Function prototype void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen);
Function descriptions configure USART stop bit length
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}

665
GD32E50x Firmware Library User Guide
stblen USART stop bit
USART_STB_1BIT 1 bit
USART_STB_0_5BIT 0.5 bit, not available for UARTx(x=3,4)
USART_STB_2BIT 2 bits
USART_STB_1_5BIT 1.5 bits, not available for UARTx(x=3,4)
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 stop bit length */

usart_stop_bit_set(USART0, USART_STB_1_5BIT);

usart_enable

The description of usart_enable is shown as below:

Table 3-948. Function usart_enable


Function name usart_enable
Function prototype void usart_enable(uint32_t usart_periph);
Function descriptions enable USART
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART0 */

usart_enable(USART0);

usart_disable

The description of usart_disable is shown as below:

Table 3-949. Function usart_disable


Function name usart_disable
Function prototype void usart_disable(uint32_t usart_periph);
666
GD32E50x Firmware Library User Guide
Function descriptions disable USART
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART0 */

usart_disable(USART0);

usart_transmit_config

The description of usart_transmit_config is shown as below:

Table 3-950. Function usart_transmit_config


Function name usart_transmit_config
Function prototype void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig);
Function descriptions configure USART transmitter
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
txconfig enable or disable USART transmitter
USART_TRANSMIT_E
enable USART transmission
NABLE
USART_TRANSMIT_DI
disable USART transmission
SABLE
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 transmitter */

667
GD32E50x Firmware Library User Guide
usart_transmit_config(USART0,USART_TRANSMIT_ENABLE);

usart_receive_config

The description of usart_receive_config is shown as below:

Table 3-951. Function usart_receive_config


Function name usart_receive_config
Function prototype void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig);
Function descriptions configure USART receiver
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
rxconfig enable or disable USART receiver
USART_RECEIVE_EN
enable USART reception
ABLE
USART_RECEIVE_DIS
disable USART reception
ABLE
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 receiver */

usart_receive_config(USART0, USART_RECEIVE_ENABLE);

usart_oversample_config

The description of usart_oversample_config is shown as below:

Table 3-952. Function usart_oversample_config


Function name usart_oversample_config
Function prototype void usart_oversample_config(uint32_t usart_periph, uint32_t oversamp);
Function descriptions configure the USART oversample mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5

668
GD32E50x Firmware Library User Guide
UARTx x=3,4
Input parameter{in}
oversamp oversample value
USART_OVSMOD_8 8 bits
USART_OVSMOD_16 16 bits
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 oversample mode */

usart_oversample_config(USART0, USART_OVSMOD_8);

usart_sample_bit_config

The description of usart_sample_bit_config is shown as below:

Table 3-953. Function usart_sample_bit_config


Function name usart_sample_bit_config
Function prototype void usart_sample_bit_config(uint32_t usart_periph, uint32_t obsm);
Function descriptions configure sample bit method
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
obsm sample bit
USART_OSB_1bit 1 bits
USART_OSB_3bit 3 bits
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 sample bit */

usart_sample_bit_config(USART0, USART_OSB_1bit);

669
GD32E50x Firmware Library User Guide
usart_receiver_timeout_enable

The description of usart_receiver_timeout_enable is shown as below:

Table 3-954. Function usart_receiver_timeout_enable


Function name usart_receiver_timeout_enable
Function prototype void usart_receiver_timeout_enable(uint32_t usart_periph);
Function descriptions enable receiver timeout
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Output parameter{out}
- -
Return value
- -

Example:

/* enable receiver timeout of USART */

usart_receiver_timeout_enable(USART0);

usart_receiver_timeout_disable

The description of usart_receiver_timeout_disable is shown as below:

Table 3-955. Function usart_receiver_timeout_disable


Function name usart_receiver_timeout_disable
Function prototype void usart_receiver_timeout_disable(uint32_t usart_periph);
Function descriptions disable receiver timeout
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Output parameter{out}
- -
Return value
- -

Example:

/* disable receiver timeout of USART */

usart_receiver_timeout_disable(USART0);

670
GD32E50x Firmware Library User Guide
usart_receiver_timeout_threshold_config

The description of usart_receiver_timeout_threshold_config is shown as below:

Table 3-956. Function usart_receiver_timeout_threshold_config


Function name usart_receiver_timeout_threshold_config
void usart_receiver_timeout_threshold_config(uint32_t usart_periph,
Function prototype
uint32_t rtimeout);
Function descriptions configure receiver timeout threshold
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Input parameter{in}
rtimeout receiver timeout threshold (0x00000000 - 0x00FFFFFF)
Output parameter{out}
- -
Return value
- -

Example:

/* set the receiver timeout threshold of USART0 */

usart_receiver_timeout_threshold_config(USART0, 115200*3);

usart_data_transmit

The description of usart_data_transmit is shown as below:

Table 3-957. Function usart_data_transmit


Function name usart_data_transmit
Function prototype void usart_data_transmit(uint32_t usart_periph, uint32_t data);
Function descriptions USART transmit data function
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
data data of transmission
0-0x1FF data of transmission
Output parameter{out}
- -

671
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* USART0 transmit data */

usart_data_transmit(USART0, 0xAA);

usart_data_receive

The description of usart_data_receiveis shown as below:

Table 3-958. Function usart_data_receive


Function name usart_data_receive
Function prototype void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig);
Function descriptions USART receive data function
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
uint32_t data of received(0-0x1FF)

Example:

/* USART0 receive data */

uint16_t temp;

temp = usart_data_receive(USART0);

usart_mute_mode_enable

The description of usart_mute_mode_enable is shown as below:

Table 3-959. Function usart_mute_mode_enable


Function name usart_mute_mode_enable
Function prototype void usart_mute_mode_enable(uint32_t usart_periph);
Function descriptions enable mute mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral

672
GD32E50x Firmware Library User Guide
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART0 receiver in mute mode */

usart_mute_mode_enable(USART0);

usart_mute_mode_disable

The description of usart_mute_mode_disable is shown as below:

Table 3-960. Function usart_mute_mode_disable


Function name usart_mute_mode_disable
Function prototype void usart_mute_mode_disable(uint32_t usart_periph);
Function descriptions disable mute mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART0 receiver in mute mode */

usart_mute_mode_disable(USART0);

usart_mute_mode_wakeup_config

The description of usart_mute_mode_wakeup_config is shown as below:

Table 3-961. Function usart_mute_mode_wakeup_config


Function name usart_mute_mode_wakeup_config
void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t
Function prototype
wmethod);
Function descriptions configure wakeup method in mute mode
Precondition -
673
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
wmethod two methods be used to enter or exit the mute mode
USART_WM_IDLE idle line
USART_WM_ADDR address mask
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 wakeup method in mute mode */

usart_mute_mode_wakeup_config(USART0, USART_WM_IDLE);

usart_lin_mode_enable

The description of usart_lin_mode_enable is shown as below:

Table 3-962. Function usart_lin_mode_enable


Function name usart_lin_mode_enable
Function prototype void usart_lin_mode_enable(uint32_t usart_periph);
Function descriptions enable LIN mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* USART0 LIN mode enable */

usart_lin_mode_enable(USART0);

674
GD32E50x Firmware Library User Guide
usart_lin_mode_disable

The description of usart_lin_mode_disable is shown as below:

Table 3-963. Function usart_lin_mode_disable


Function name usart_lin_mode_disable
Function prototype void usart_lin_mode_disable(uint32_t usart_periph);
Function descriptions disable LIN mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* USART0 LIN mode disable */

usart_lin_mode_disable(USART0);

usart_lin_break_dection_length_config

The description of usart_lin_break_dection_length_config is shown as below:

Table 3-964. Function usart_lin_break_dection_length_config


Function name usart_lin_break_dection_length_config
void usart_lin_break_dection_length_config(uint32_t usart_periph, uint32_t
Function prototype
lblen);
Function descriptions configure LIN break frame length
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
lblen two methods be used to enter or exit the mute mode
USART_LBLEN_10B break frame length is 10 bits
USART_LBLEN_11B break frame length is 11 bits
Output parameter{out}
- -

675
GD32E50x Firmware Library User Guide
Return value
- -

Example:

/* configure LIN break frame length */

usart_lin_break_dection_length_config(USART0, USART_LBLEN_10B);

usart_halfduplex_enable

The description of usart_halfduplex_enable is shown as below:

Table 3-965. Function usart_halfduplex_enable


Function name usart_halfduplex_enable
Function prototype void usart_halfduplex_enable(uint32_t usart_periph);
Function descriptions enable half duplex mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART0 half duplex mode*/

usart_halfduplex_enable(USART0);

usart_halfduplex_disable

The description of usart_halfduplex_disable is shown as below:

Table 3-966. Function usart_halfduplex_disable


Function name usart_halfduplex_disable
Function prototype void usart_halfduplex_disable(uint32_t usart_periph);
Function descriptions disable half duplex mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
676
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART0 half duplex mode*/

usart_halfduplex_disable(USART0);

usart_synchronous_clock_enable

The description of usart_synchronous_clock_enable is shown as below:

Table 3-967. Function usart_synchronous_clock_enable


Function name usart_synchronous_clock_enable
Function prototype void usart_synchronous_clock_enable(uint32_t usart_periph);
Function descriptions enable CK pin in synchronous mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART0 CK pin in synchronous mode */

usart_synchronous_clock_enable(USART0);

usart_synchronous_clock_disable

The description of usart_synchronous_clock_disable is shown as below:

Table 3-968. Function usart_synchronous_clock_disable


Function name usart_synchronous_clock_disable
Function prototype void usart_synchronous_clock_disable(uint32_t usart_periph);
Function descriptions disable CK pin in synchronous mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
677
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART0 CK pin in synchronous mode */

usart_synchronous_clock_disable(USART0);

usart_synchronous_clock_config

The description of usart_synchronous_clock_config is shown as below:

Table 3-969. Function usart_synchronous_clock_config


Function name usart_synchronous_clock_config
void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen,
Function prototype
uint32_t cph, uint32_t cpl);
Function descriptions configure USART synchronous mode parameters
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Input parameter{in}
clen CK length
USART_CLEN_NONE there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame
USART_CLEN_EN there are 8 CK pulses for an 8 bit frame and 9 CK pulses for a 9 bit frame
Input parameter{in}
cph clock phase
USART_CPH_1CK first clock transition is the first data capture edge
USART_CPH_2CK second clock transition is the first data capture edge
Input parameter{in}
cpl clock polarity
USART_CPL_LOW steady low value on CK pin
USART_CPL_HIGH steady high value on CK pin
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 synchronous mode parameters */

usart_synchronous_clock_config(USART0,USART_CLEN_EN,USART_CPH_2CK,
678
GD32E50x Firmware Library User Guide
USART_CPL_HIGH);

usart_guard_time_config

The description of usart_guard_time_config is shown as below:

Table 3-970. Function usart_guard_time_config


Function name usart_guard_time_config
Function prototype void usart_guard_time_config(uint32_t usart_periph,uint32_t gaut);
Function descriptions configure guard time value in smartcard mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Input parameter{in}
guat guard time value (0x00000000 - 0x000000FF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 guard time value in smartcard mode */

usart_guard_time_config(USART0, 0x0000 0055);

usart_smartcard_mode_enable

The description of usart_smartcard_mode_enable is shown as below:

Table 3-971. Function usart_smartcard_mode_enable


Function name usart_smartcard_mode_enable
Function prototype void usart_smartcard_mode_enable(uint32_t usart_periph);
Function descriptions enable smartcard mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Output parameter{out}
- -
Return value
- -

Example:
679
GD32E50x Firmware Library User Guide
/* USART0 smartcard mode enable */

usart_smartcard_mode_enable(USART0);

usart_smartcard_mode_disable

The description of usart_smartcard_mode_disable is shown as below:

Table 3-972. Function usart_smartcard_mode_disable


Function name usart_smartcard_mode_disable
Function prototype void usart_smartcard_mode_disable(uint32_t usart_periph);
Function descriptions disable smartcard mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Output parameter{out}
- -
Return value
- -

Example:

/* USART0 smartcard mode disable */

usart_smartcard_mode_disable(USART0);

usart_smartcard_mode_nack_enable

The description of usart_smartcard_mode_nack_enable is shown as below:

Table 3-973. Function usart_smartcard_mode_nack_enable


Function name usart_smartcard_mode_nack_enable
Function prototype void usart_smartcard_mode_nack_enable(uint32_t usart_periph);
Function descriptions enable NACK in smartcard mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Output parameter{out}
- -
Return value
- -

Example:

680
GD32E50x Firmware Library User Guide
/* enable USART0 NACK in smartcard mode */

usart_smartcard_mode_nack_enable(USART0);

usart_smartcard_mode_nack_disable

The description of usart_smartcard_mode_nack_disable is shown as below:

Table 3-974. Function usart_smartcard_mode_nack_disable


Function name usart_smartcard_mode_nack_disable
Function prototype void usart_smartcard_mode_nack_disable(uint32_t usart_periph);
Function descriptions disable NACK in smartcard mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART0 NACK in smartcard mode */

usart_smartcard_mode_nack_disable(USART0);

usart_smartcard_autoretry_config

The description of usart_smartcard_autoretry_config is shown as below:

Table 3-975. Function usart_smartcard_autoretry_config


Function name usart_smartcard_autoretry_config
void usart_smartcard_autoretry_config(uint32_t usart_periph, uint32_t
Function prototype
scrtnum);
Function descriptions configure smartcard auto-retry number
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Input parameter{in}
scrtnum smartcard auto-retry number (0x00000000 - 0x00000007)
Output parameter{out}
- -
Return value
681
GD32E50x Firmware Library User Guide
- -

Example:

/* configure smartcard auto-retry number */

usart_smartcard_autoretry_config (USART0, 0x00000007);

usart_block_length_config

The description of usart_block_length_config is shown as below:

Table 3-976. Function usart_block_length_config


Function name usart_block_length_config
Function prototype void usart_block_length_config(uint32_t usart_periph, uint32_t bl);
Function descriptions configure block length
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Input parameter{in}
bl block length (0x00000000 - 0x000000FF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure block length in Smartcard T=1 reception */

usart_block_length_config(USART0, 0x000000FF);

usart_irda_mode_enable

The description of usart_irda_mode_enable is shown as below:

Table 3-977. Function usart_irda_mode_enable


Function name usart_irda_mode_enable
Function prototype void usart_irda_mode_enable(uint32_t usart_periph);
Function descriptions enable IrDA mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
682
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART0 IrDA mode */

usart_irda_mode_enable(USART0);

usart_irda_mode_disable

The description of usart_irda_mode_disable is shown as below:

Table 3-978. Function usart_irda_mode_disable


Function name usart_irda_mode_disable
Function prototype void usart_irda_mode_disable(uint32_t usart_periph);
Function descriptions disable IrDA mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART0 IrDA mode */

usart_irda_mode_disable(USART0);

usart_prescaler_config

The description of usart_prescaler_config is shown as below:

Table 3-979. Function usart_prescaler_config


Function name usart_prescaler_config
Function prototype void usart_prescaler_config(uint32_t usart_periph, uint8_t psc);
Function descriptions configure the peripheral clock prescaler in USART IrDA low-power mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
683
GD32E50x Firmware Library User Guide
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
psc 0x00000000 - 0x000000FF
Output parameter{out}
- -
Return value
- -

Example:

/* configure the USART0 peripheral clock prescaler */

usart_prescaler_config(USART0, 0x00000000);

usart_irda_lowpower_config

The description of usart_irda_lowpower_config is shown as below:

Table 3-980. Function usart_irda_lowpower_config


Function name usart_irda_lowpower_config
Function prototype void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp);
Function descriptions configure IrDA low-power
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
irlp IrDA low-power or normal
USART_IRLP_LOW low-power
USART_IRLP_NORMA
normal
L
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 IrDA low-power */

usart_irda_lowpower_config(USART0, USART_IRLP_LOW);

684
GD32E50x Firmware Library User Guide
usart_hardware_flow_rts_config

The description of usart_hardware_flow_rts_config is shown as below:

Table 3-981. Function usart_hardware_flow_rts_config


Function name usart_hardware_flow_rts_config
void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t
Function prototype
rtsconfig);
Function descriptions configure hardware flow control RTS
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Input parameter{in}
rtsconfig enable or disable RTS
USART_RTS_ENABLE enable RTS
USART_RTS_DISABL
disable RTS
E
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 hardware flow control RTS */

usart_hardware_flow_cts_config(USART0, USART_RTS_ENABLE);

usart_hardware_flow_cts_config

The description of usart_hardware_flow_cts_config is shown as below:

Table 3-982. Function usart_hardware_flow_cts_config


Function name usart_hardware_flow_cts_config
void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t
Function prototype
ctsconfig);
Function descriptions configure hardware flow control RTS
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2,5
Input parameter{in}
ctsconfig enable or disable CTS

685
GD32E50x Firmware Library User Guide
USART_CTS_ENABLE enable CTS
USART_CTS_DISABL
disable CTS
E
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART0 hardware flow control CTS */

usart_hardware_flow_cts_config(USART0, USART_CTS_ENABLE);

usart_dma_receive_config

The description of usart_dma_receive_config is shown as below:

Table 3-983. Function usart_dma_receive_config


Function name usart_dma_receive_config
Function prototype void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd);
Function descriptions configure USART DMA reception
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
dmacmd enable or disable DMA for reception
USART_DENR_ENABL
DMA enable for reception
E
USART_DENR_DISAB
DMA disable for reception
LE
Output parameter{out}
- -
Return value
- -

Example:

/* USART0 DMA enable for reception */

usart_dma_receive_config(USART0, USART_DENR_ENABLE);

686
GD32E50x Firmware Library User Guide
usart_dma_transmit_config

The description of usart_dma_transmit_config is shown as below:

Table 3-984. Function usart_dma_transmit_config


Function name usart_dma_transmit_config
Function prototype void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd);
Function descriptions configure USART DMA transmission
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2,5
UARTx x=3,4
Input parameter{in}
dmacmd enable or disable DMA for transmission
USART_DENT_ENABL
DMA enable for transmission
E
USART_DENT_DISAB
DMA disable for transmission
LE
Output parameter{out}
- -
Return value
- -

Example:

/* USART0 DMA enable for transmission */

usart_dma_transmit_config(USART0, USART_DENT_ENABLE);

usart_data_first_config

Thedescription of usart_data_first_config is shown as below:

Table 3-985. Function usart_data_first_config


Function name usart_data_first_config
Function prototype void usart_data_first_config(uint32_t usart_periph, uint32_t msbf);
Function descriptions data is transmitted/received with the LSB/MSB first
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2
Input parameter{in}
msbf LSB first or MSB first

687
GD32E50x Firmware Library User Guide
USART_MSBF_LSB LSB first
USART_MSBF_MSB MSB first
Output parameter{out}
- -
Return value
- -

Example:

/* configure LSB of data first */

usart_data_first_config(USART0, USART_MSBF_LSB);

usart_invert_config

The description of usart_invert_config is shown as below:

Table 3-986. Function usart_invert_config


Function name usart_invert_config
void usart_invert_config(uint32_t usart_periph, usart_invert_enum
Function prototype
invertpara);
Function descriptions configure USART inversion
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx peripheral
USARTx x=0,1,2
Input parameter{in}
invertpara refer to Enum usart_invert_enum
USART_DINV_ENABL
data bit level inversion
E
USART_DINV_DISABL
data bit level not inversion
E
USART_TXPIN_ENAB
TX pin level inversion
LE
USART_TXPIN_DISAB
TX pin level not inversion
LE
USART_RXPIN_ENAB
RX pin level inversion
LE
USART_RXPIN_DISAB
RX pin level not inversion
LE
Output parameter{out}
- -
Return value
- -

688
GD32E50x Firmware Library User Guide
Example:

/* configure USART inversion */

usart_invert_config(USART0, USART_DINV_ENABLE);

usart_address_config

The description of usart_address_config is shown as below:

Table 3-987. Function usart_address_config


Function name usart_address_config
Function prototype void usart_address_config(uint32_t usart_periph, uint8_t addr);
Function descriptions configure the address of the USART in wake up by address match mode
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2
UARTx x=3,4
Input parameter{in}
addr address of USART/UART (0x00000000 - 0x0000000F)
Output parameter{out}
- -
Return value
- -

Example:

/* configure address of the USART0 */

usart_address_config(USART0, 0x00000000);

usart_send_break

The description of usart_send_break is shown as below:

Table 3-988. Function usart_send_break


Function name usart_send_break
Function prototype void usart_send_break(uint32_t usart_periph);
Function descriptions send break frame
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2
UARTx x=3,4

689
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* USART0 send break frame */

usart_send_break(USART0);

usart_flag_get

The description of usart_flag_get is shown as below:

Table 3-989. Function usart_flag_get


Function name usart_flag_get
Function prototype FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag);
Function descriptions get flag in STAT0/STAT1 register
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2
UARTx x=3,4
Input parameter{in}
flag USART flags, refer to Enum usart_flag_enum
USART_FLAG_CTS CTS change flag
USART_FLAG_LBD LIN break detected flag
USART_FLAG_TBE transmit data buffer empty
USART_FLAG_TC transmission complete
USART_FLAG_RBNE read data buffer not empty
USART_FLAG_IDLE IDLE frame detected flag
USART_FLAG_ORER
overrun error flag
R
USART_FLAG_NERR noise error flag
USART_FLAG_FERR frame error flag
USART_FLAG_PERR parity error flag
USART_FLAG_BSY busy flag
USART_FLAG_EB end of block flag
USART_FLAG_RT receiver timeout flag
USART_FLAG_CD collision detected flag
Output parameter{out}
- -
Return value

690
GD32E50x Firmware Library User Guide
FlagStatus SET or RESET

Example:

/* get flag USART0 state */

FlagStatus status;

status = usart_flag_get(USART0, USART_FLAG_TBE);

usart_flag_clear

The description of usart_flag_clear is shown as below:

Table 3-990. Function usart_flag_clear


Function name usart_flag_clear
Function prototype void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag);
Function descriptions clear flag in STAT0/STAT1 register
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2
UARTx x=3,4
Input parameter{in}
flag USART flags, refer to Enum usart_flag_enum
USART_FLAG_CTS CTS change flag
USART_FLAG_LBD LIN break detected flag
USART_FLAG_TC transmission complete
USART_FLAG_RBNE read data buffer not empty
USART_FLAG_EB end of block flag
USART_FLAG_RT receiver timeout flag
USART_FLAG_CD collision detected flag
Output parameter{out}
- -
Return value
- -

Example:

/* clear USART0 flag */

usart_flag_clear(USART0, USART_FLAG_TC);

usart_interrupt_enable

The description of usart_interrupt_enableis shown as below:

691
GD32E50x Firmware Library User Guide
Table 3-991. Function usart_interrupt_enable
Function name usart_interrupt_enable
void usart_interrupt_enable(uint32_t usart_periph, usart_interrupt_enum
Function prototype
interrupt);
Function descriptions enable USART interrupt
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2
UARTx x=3,4
Input parameter{in}
interrupt USART interrupt, refer to Enum usart_interrupt_enum
USART_INT_PERR parity error interrupt
USART_INT_TBE transmitter buffer empty interrupt
USART_INT_TC transmission complete interrupt
USART_INT_RBNE read data buffer not empty interrupt and overrun error interrupt
USART_INT_IDLE IDLE line detected interrupt
USART_INT_LBD LIN break detected interrupt
USART_INT_ERR error interrupt
USART_INT_CTS CTS interrupt
USART_INT_RT receive timeout event interrupt
USART_INT_EB end of block event interrupt
USART_INT_CD collision detected interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART0 TBE interrupt */

usart_interrupt_enable(USART0, USART_INT_TBE);

usart_interrupt_disable

The description of usart_interrupt_disable is shown as below:

Table 3-992. Function usart_interrupt_disable


Function name usart_interrupt_disable
void usart_interrupt_disable(uint32_t usart_periph, usart_interrupt_enum
Function prototype
interrupt);
Function descriptions disable USART interrupt
Precondition -

692
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2
UARTx x=3,4
Input parameter{in}
int_flag USART interrupt flag, refeer to Enum usart_interrupt_enum
USART_INT_PERR parity error interrupt
USART_INT_TBE transmitter buffer empty interrupt
USART_INT_TC transmission complete interrupt
USART_INT_RBNE read data buffer not empty interrupt and overrun error interrupt
USART_INT_IDLE IDLE line detected interrupt
USART_INT_LBD LIN break detected interrupt
USART_INT_ERR error interrupt
USART_INT_CTS CTS interrupt
USART_INT_RT receive timeout event interrupt
USART_INT_EB end of block event interrupt
USART_INT_CD collision detected interrupt
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART0 TBE interrupt */

usart_interrupt_disable(USART0, USART_INT_TBE);

usart_interrupt_flag_get

The description of usart_interrupt_flag_get is shown as below:

Table 3-993. Function usart_interrupt_flag_get


Function name usart_interrupt_flag_get
FlagStatus usart_interrupt_flag_get(uint32_t usart_periph,
Function prototype
usart_interrupt_flag_enum int_flag);
Function descriptions get USART interrupt flag status
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2
UARTx x=3,4
Input parameter{in}

693
GD32E50x Firmware Library User Guide
int_flag USART interrupt flag, refer to Enum usart_interrupt_flag_enum
USART_INT_FLAG_PE
parity error interrupt and flag
RR
USART_INT_FLAG_TB
transmitter buffer empty interrupt and flag
E
USART_INT_FLAG_TC transmission complete interrupt and flag
USART_INT_FLAG_RB
read data buffer not empty interrupt and flag
NE
USART_INT_FLAG_RB
read data buffer not empty interrupt and overrun error flag
NE_ORERR
USART_INT_FLAG_ID
IDLE line detected interrupt and flag
LE
USART_INT_FLAG_LB
LIN break detected interrupt and flag
D
USART_INT_FLAG_CT
CTS interrupt and flag
S
USART_INT_FLAG_ER
error interrupt and overrun error
R_ORERR
USART_INT_FLAG_ER
error interrupt and noise error flag
R_NERR
USART_INT_FLAG_ER
error interrupt and frame error flag
R_FERR
USART_INT_FLAG_EB end of block event interrupt flag
USART_INT_FLAG_RT receive timeout event interrupt flag
USART_INT_FLAG_C
collision detected interrupt and flag
D
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the USART0 interrupt flag status */

FlagStatus status;

status = usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE);

usart_interrupt_flag_clear

The description of usart_interrupt_flag_clear is shown as below:

Table 3-994. Function usart_interrupt_flag_clear


Function name usart_interrupt_flag_clear
Function prototype void usart_interrupt_flag_clear(uint32_t usart_periph,

694
GD32E50x Firmware Library User Guide
usart_interrupt_flag_enum int_flag);
Function descriptions clear USART interrupt flag
Precondition -
The called functions -
Input parameter{in}
usart_periph USARTx/UARTx peripheral
USARTx x=0,1,2
UARTx x=3,4
Input parameter{in}
int_flag USART interrupt flag, refer to Enum usart_interrupt_flag_enum
USART_INT_FLAG_CT
CTS interrupt and flag
S
USART_INT_FLAG_LB
LIN break detected interrupt and flag
D
USART_INT_FLAG_TC transmission complete interrupt and flag
USART_INT_FLAG_RB
read data buffer not empty interrupt and flag
NE
USART_INT_FLAG_EB interrupt enable bit of end of block event and flag
USART_INT_FLAG_RT interrupt enable bit of receive timeout event and flag
USART_INT_FLAG_C
collision detected interrupt and flag
D
Output parameter{out}
- -
Return value
- -

Example:

/* clear the USART0 interrupt enable bit status */

usart_interrupt_flag_clear(USART0, USART_INT_FLAG_RBNE);

usart5_data_first_config

The description of usart_data_first_config is shown as below:

Table 3-995. Function usart5_ data_first_config


Function name usart5_data_first_config
Function prototype void usart5_data_first_config(uint32_t usart_periph, uint32_t msbf);
Function descriptions data is transmitted/received with the LSB/MSB first
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5

695
GD32E50x Firmware Library User Guide
Input parameter{in}
msbf LSB/MSB
USART5_MSBF_LSB LSB first
USART5_MSBF_MSB MSB first
Output parameter{out}
- -
Return value
- -

Example:

/* configure LSB of data first */

usart5_data_first_config(USART5, USART5_MSBF_LSB);

usart5_invert_config

The description of usart5_invert_config is shown as below:

Table 3-996. Function usart5_invert_config


Function name usart5_invert_config
void usart5_invert_config(uint32_t usart_periph, usart5_invert_enum
Function prototype
invertpara);
Function descriptions configure USART5 inverted
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
invertpara refer to Enum usart5_invert_enum
USART5_DINV_ENAB
data bit level inversion
LE
USART5_DINV_DISAB
data bit level not inversion
LE
USART5_TXPIN_ENA
TX pin level inversion
BLE
USART5_TXPIN_DISA
TX pin level not inversion
BLE
USART5_RXPIN_ENA
RX pin level inversion
BLE
USART5_RXPIN_DISA
RX pin level not inversion
BLE
USART5_SWAP_ENA
swap TX/RX pins
BLE

696
GD32E50x Firmware Library User Guide
USART5_SWAP_DISA
not swap TX/RX pins
BLE
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART5 inversion */

usart5_invert_config(USART5, USART5_DINV_ENABLE);

usart5_overrun_enable

The description of usart5_overrun_enable is shown as below:

Table 3-997. Function usart5_overrun_enable


Function name usart5_overrun_enable
Function prototype void usart5_overrun_enable(uint32_t usart_periph);
Function descriptions enable the USART5 overrun function
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART5 overrun */

usart5_overrun_enable(USART5);

usart5_overrun_disable

The description of usart5_overrun_disable is shown as below:

Table 3-998. Function usart5_overrun_disable


Function name usart5_overrun_disable
Function prototype void usart5_overrun_disable(uint32_t usart_periph);
Function descriptions disable the USART5 overrun function
Precondition -
The called functions -
Input parameter{in}
697
GD32E50x Firmware Library User Guide
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART5 overrun */

usart5_overrun_disable(USART5);

usart5_autobaud_detection_enable

The description of usart5_autobaud_detection_enable is shown as below:

Table 3-999. Function usart5_autobaud_detection_enable


Function name usart5_autobaud_detection_enable
Function prototype void usart5_autobaud_detection_enable(uint32_t usart_periph);
Function descriptions enable auto baud rate detection
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART5 auto baud rate detection */

usart5_autobaud_detection_enable(USART5);

usart5_autobaud_detection_disable

The description of usart5_autobaud_detection_disable is shown as below:

Table 3-1000. Function usart5_autobaud_detection_disable


Function name usart5_autobaud_detection_disable
Function prototype void usart5_autobaud_detection_disable(uint32_t usart_periph);
Function descriptions disable auto baud rate detection
Precondition -
The called functions -
Input parameter{in}
698
GD32E50x Firmware Library User Guide
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART5 auto baud rate detection */

usart5_autobaud_detection_disable(USART5);

usart5_autobaud_detection_mode_config

The description of usart5_autobaud_detection_mode_config is shown as below:

Table 3-1001. Function usart5_autobaud_detection_mode_config


Function name usart5_autobaud_detection_mode_config
void usart5_autobaud_detection_mode_config(uint32_t usart_periph,
Function prototype
uint32_t abdmod);
Function descriptions configure auto baud rate detection mode
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
abdmod auto baud rate detection mode
USART5_ABDM_FTOR falling edge to rising edge measurement
USART5_ABDM_FTOF falling edge to falling edge measurement
Output parameter{out}
- -
Return value
- -

Example:

/* configure USART5 auto baud rate detection mode */

usart5_autobaud_detection_mode_config(USART5, USART5_ABDM_FTOR);

usart5_address_config

The description of usart5_address_config is shown as below:

Table 3-1002. Function usart5_address_config


Function name usart5_address_config
699
GD32E50x Firmware Library User Guide
Function prototype void usart5_address_config(uint32_t usart_periph, uint8_t addr);
Function descriptions configure the address of the USART5 terminal
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
addr address of USART terminal (0x00000000-0x000000FF)
Output parameter{out}
- -
Return value
- -

Example:

/* configure address of the USART5 */

usart5_address_config(USART5, 0x00000000);

usart5_address_detection_mode_config

The description of usart5_address_detection_mode_config is shown as below:

Table 3-1003. Function usart5_address_detection_mode_config


Function name usart5_address_detection_mode_config
void usart5_address_detection_mode_config(uint32_t usart_periph,
Function prototype
uint32_t addmod);
Function descriptions configure address detection mode
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
addmod address detection mode
USART5_ADDM_4BIT 4 bits
USART5_ADDM_FULL
full bits
BIT
Output parameter{out}
- -
Return value
- -

Example:

700
GD32E50x Firmware Library User Guide
/*configure address detection mode */

usart5_address_detection_mode_config(USART5, USART5_ADDM_4BIT);

usart5_smartcard_mode_early_nack_enable

The description of usart5_smartcard_mode_early_nack_enable is shown as below:

Table 3-1004. Function usart5_smartcard_mode_early_nack_enable


Function name usart5_smartcard_mode_early_nack_enable
Function prototype void usart5_smartcard_mode_early_nack_enable(uint32_t usart_periph);
Function descriptions enable early NACK in smartcard mode
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART5 early NACK in smartcard mode */

usart5_smartcard_mode_early_nack_enable(USART5);

usart5_smartcard_mode_early_nack_disable

The description of usart5_smartcard_mode_early_nack_disable is shown as below:

Table 3-1005. Function usart5_smartcard_mode_early_nack_disable


Function name usart5_smartcard_mode_early_nack_disable
Function prototype void usart5_smartcard_mode_early_nack_disable(uint32_t usart_periph);
Function descriptions disable early NACK in smartcard mode
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

701
GD32E50x Firmware Library User Guide
/* disable USART5 early NACK in smartcard mode */

usart5_smartcard_mode_early_nack_disable(USART5);

usart5_hardware_flow_coherence_config

The description of usart5_hardware_flow_coherence_config is shown as below:

Table 3-1006. Function usart5_hardware_flow_coherence_config


Function name usart5_hardware_flow_coherence_config
void usart5_hardware_flow_coherence_config(uint32_t usart_periph,
Function prototype
uint32_t hcm);
Function descriptions configure hardware flow control coherence mode
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
hcm Hardware flow control coherence mode
USART5_HCM_NONE nRTS signal equals to the rxne status register
USART5_HCM_EN nRTS signal is set when the last data bit has been sampled
Output parameter{out}
- -
Return value
- -

Example:

/* configure hardware flow control coherence mode */

usart5_hardware_flow_coherence_config(USART5, USART5_HCM_NONE);

usart5_rs485_driver_enable

The description of usart5_rs485_driver_enable is shown as below:

Table 3-1007. Function usart5_rs485_driver_enable


Function name usart5_rs485_driver_enable
Function prototype void usart5_rs485_driver_enable(uint32_t usart_periph);
Function descriptions enable USART5 RS485 driver
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
702
GD32E50x Firmware Library User Guide
- -
Return value
- -

Example:

/* enable USART5 RS485 driver */

usart5_rs485_driver_enable(USART5);

usart5_rs485_driver_disable

The description of usart5_rs485_driver_disable is shown as below:

Table 3-1008. Function usart5_rs485_driver_disable


Function name usart5_rs485_driver_disable
Function prototype void usart5_rs485_driver_disable(uint32_t usart_periph);
Function descriptions disable USART5 RS485 driver
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART5 RS485 driver */

usart5_rs485_driver_disable (USART5);

usart5_driver_assertime_config

The description of usart5_driver_assertime_config is shown as below:

Table 3-1009. Function usart5_driver_assertime_config


Function name usart5_driver_assertime_config
void usart5_driver_assertime_config(uint32_t usart_periph, uint32_t
Function prototype
deatime);
Function descriptions configure driver enable assertion time
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
703
GD32E50x Firmware Library User Guide
Input parameter{in}
deatime driver enable assertion time (0x00000000 - 0x0000001F)
Output parameter{out}
- -
Return value
- -

Example:

/* set USART5 driver assertime */

usart5_driver_assertime_config(USART5, 0x0000001F);

usart5_driver_deassertime_config

The description of usart5_driver_deassertime_config is shown as below:

Table 3-1010. Function usart5_driver_deassertime_config


Function name usart5_driver_deassertime_config
void usart5_driver_deassertime_config(uint32_t usart_periph, uint32_t
Function prototype
dedtime);
Function descriptions configure driver enable de-assertion time
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
deatime driver enable de-assertion time (0x00000000 - 0x0000001F)
Output parameter{out}
- -
Return value
- -

Example:

/* set USART5 driver deassertime */

usart5_driver_deassertime_config(USART5, 0x0000001F);

usart5_depolarity_config

The description of usart5_depolarity_config is shown as below:

Table 3-1011. Function usart5_depolarity_config


Function name usart5_depolarity_config
Function prototype void usart5_depolarity_config(uint32_t usart_periph, uint32_t dep);
Function descriptions configure driver enable polarity mode
704
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
dep DE signal
USART5_DEP_HIGH DE signal is active high
USART5_DEP_LOW DE signal is active low
Output parameter{out}
- -
Return value
- -

Example:

/* configure driver enable polarity mode */

usart5_driver_depolarity_config(USART5, USART5_DEP_HIGH);

usart5_reception_error_dma_enable

The description of usart5_reception_error_dma_enable is shown as below:

Table 3-1012. Function usart5_reception_error_dma_enable


Function name usart5_reception_error_dma_enable
Function prototype void usart5_reception_error_dma_enable(uint32_t usart_periph);
Function descriptions enable DMA on reception error
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* enable DMA on reception error */

usart5_reception_error_dma_enable(USART5);

usart5_reception_error_dma_disable

The description of usart5_reception_error_dma_disable is shown as below:

705
GD32E50x Firmware Library User Guide
Table 3-1013. Function usart5_reception_error_dma_disable
Function name usart5_reception_error_dma_disable
Function prototype void usart5_reception_error_dma_disable(uint32_t usart_periph);
Function descriptions disable DMA on reception error
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* disable DMA on reception error */

usart5_reception_error_dma_disable(USART5);

usart5_wakeup_enable

The description of usart5_wakeup_enable is shown as below:

Table 3-1014. Function usart5_wakeup_enable


Function name usart5_wakeup_enable
Function prototype void usart5_wakeup_enable(uint32_t usart_periph);
Function descriptions enable USART to wakeup the mcu from deep-sleep mode
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* USART5 wake up enable */

usart5_wakeup_enable(USART5);

usart5_wakeup_disable

The description of usart5_wakeup_disable is shown as below:

706
GD32E50x Firmware Library User Guide
Table 3-1015. Function usart5_wakeup_disable
Function name usart5_wakeup_disable
Function prototype void usart5_wakeup_disable(uint32_t usart_periph);
Function descriptions disable USART to wakeup the mcu from deep-sleep mode
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* USART5 wake up disable */

usart5_wakeup_disable(USART5);

usart5_wakeup_mode_config

The description of usart5_wakeup_mode_config is shown as below:

Table 3-1016. Function usart5_wakeup_mode_config


Function name usart5_wakeup_mode_config
Function prototype void usart5_wakeup_mode_config(uint32_t usart_periph, uint32_t wum);
Function descriptions configure the USART wakeup mode from deep-sleep mode
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
wum wakeup mode
USART5_WUM_ADDR WUF active on address match
USART5_WUM_STAR
WUF active on start bit
TB
USART5_WUM_RBNE WUF active on RBNE
Output parameter{out}
- -
Return value
- -

Example:

707
GD32E50x Firmware Library User Guide
/* configure USART5 wake up mode */

usart5_wakeup_mode_config(USART5, USART5_WUM_ADDR);

usart5_receive_fifo_enable

The description of usart5_receive_fifo_enable is shown as below:

Table 3-1017. Function usart5_receive_fifo_enable


Function name usart5_receive_fifo_enable
Function prototype void usart5_receive_fifo_enable(uint32_t usart_periph);
Function descriptions enable receive FIFO
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

/* enable receive FIFO */

usart5_receive_fifo_enable(USART5);

usart5_receive_fifo_disable

The description of usart5_receive_fifo_disable is shown as below:

Table 3-1018. Function usart5_receive_fifo_disable


Function name Usart5_receive_fifo_disable
Function prototype void usart5_receive_fifo_disable(uint32_t usart_periph);
Function descriptions disable receive FIFO
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
- -

Example:

708
GD32E50x Firmware Library User Guide
/* disable receive FIFO */

usart5_receive_fifo_disable(USART5);

usart5_receive_fifo_counter_number

The description of usart5_receive_fifo_counter_number is shown as below:

Table 3-1019. Function usart5_receive_fifo_counter_number


Function name usart5_receive_fifo_counter_number
Function prototype uint8_t usart5_receive_fifo_counter_number(uint32_t usart_periph);
Function descriptions read receive FIFO counter number
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Output parameter{out}
- -
Return value
uint8_t receive FIFO counter number

Example:

/* read receive FIFO counter number */

uint8_t temp;

temp = usart5_receive_fifo_counter_number(USART5);

usart5_flag_get

The description of usart5_flag_get is shown as below:

Table 3-1020. Function usart5_flag_get


Function name usart5_flag_get
Function prototype FlagStatus usart5_flag_get(uint32_t usart_periph, usart5_flag_enum flag);
Function descriptions get flag in STAT/CHC/RFCS register
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
USART flags, refer to Enum usart5_flag_enum
flag
only one among these parameters can be selected
USART5_FLAG_PERR parity error flag

709
GD32E50x Firmware Library User Guide
USART5_FLAG_FERR frame error flag
USART5_FLAG_NERR noise error flag
USART5_FLAG_ORER
overrun error
R
USART5_FLAG_IDLE idle line detected flag
USART5_FLAG_RBNE read data buffer not empty
USART5_FLAG_TC transmission completed
USART5_FLAG_TBE transmit data register empty
USART5_FLAG_LBD LIN break detected flag
USART5_FLAG_CTSF CTS change flag
USART5_FLAG_CTS CTS level
USART5_FLAG_RT receiver timeout flag
USART5_FLAG_EB end of block flag
USART5_FLAG_ABDE auto baudrate detection error
USART5_FLAG_ABD auto baudrate detection flag
USART5_FLAG_BSY busy flag
USART5_FLAG_AM address match flag
USART5_FLAG_SB send break flag
USART5_FLAG_RWU receiver wakeup from mute mode
USART5_FLAG_WU wakeup from deep-sleep mode flag
USART5_FLAG_TEA transmit enable acknowledge flag
USART5_FLAG_REA receive enable acknowledge flag
USART5_FLAG_EPER
early parity error flag
R
USART5_FLAG_RFE receive FIFO empty flag
USART5_FLAG_RFF receive FIFO full flag
USART5_FLAG_RFFIN
receive FIFO full interrupt flag
T
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get flag USART5 state */

FlagStatus status;

status = usart5_flag_get(USART5, USART5_FLAG_TBE);

usart5_flag_clear

The description of usart5_flag_clear is shown as below:

710
GD32E50x Firmware Library User Guide
Table 3-1021. Function usart5_flag_clear
Function name usart5_flag_clear
Function prototype void usart5_flag_clear(uint32_t usart_periph, usart5_flag_enum flag);
Function descriptions clear flag in STAT register
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
USART flags, refer to Enum usart5_flag_enum
flag
only one among these parameters can be selected
USART5_FLAG_PERR parity error flag
USART5_FLAG_FERR frame error flag
USART5_FLAG_NERR noise detected flag
USART5_FLAG_ORER
overrun error flag
R
USART5_FLAG_IDLE idle line detected flag
USART5_FLAG_TC transmission complete flag
USART5_FLAG_LBD LIN break detected flag
USART5_FLAG_CTSF CTS change flag
USART5_FLAG_RT receiver timeout flag
USART5_FLAG_EB end of block flag
USART5_FLAG_AM address match flag
USART5_FLAG_WU wakeup from deep-sleep mode flag
USART5_FLAG_EPER
early parity error flag
R
Output parameter{out}
- -
Return value
- -

Example:

/* clear USART5 flag */

usart5_flag_clear(USART5, USART5_FLAG_TC);

usart5_interrupt_enable

The description of usart5_interrupt_enable is shown as below:

Table 3-1022. Function usart5_interrupt_enable


Function name usart5_interrupt_enable
Function prototype void usart5_interrupt_enable(uint32_t usart_periph, usart5_interrupt_enum

711
GD32E50x Firmware Library User Guide
interrupt);
Function descriptions enable USART interrupt
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
interrupt USART5 interrupts, refer to Enum usart5_interrupt_enum
USART5_INT_IDLE idle interrupt
read data buffer not empty interrupt and overrun error interrupt enable
USART5_INT_RBNE
interrupt
USART5_INT_TC transmission complete interrupt
USART5_INT_TBE transmit data register empty interrupt
USART5_INT_PERR parity error interrupt
USART5_INT_AM address match interrupt
USART5_INT_RT receiver timeout interrupt
USART5_INT_EB end of block interrupt
USART5_INT_LBD LIN break detection interrupt
USART5_INT_ERR error interrupt enable in multibuffer communication
USART5_INT_CTS CTS interrupt
USART5_INT_WU wakeup from deep-sleep mode interrupt
USART5_INT_RFF receive FIFO full interrupt enable
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART5 TBE interrupt */

usart5_interrupt_enable(USART5, USART5_INT_TBE);

usart5_interrupt_disable

The description of usart5_interrupt_disable is shown as below:

Table 3-1023. Function usart5_interrupt_disable


Function name usart5_interrupt_disable
void usart5_interrupt_disable(uint32_t usart_periph, usart5_interrupt_enum
Function prototype
interrupt);
Function descriptions disable USART interrupt
Precondition -
The called functions -

712
GD32E50x Firmware Library User Guide
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
interrupt USART5 interrupts, refer to Enum usart5_interrupt_enum
USART5_INT_IDLE idle interrupt
read data buffer not empty interrupt and overrun error interrupt enable
USART5_INT_RBNE
interrupt
USART5_INT_TC transmission complete interrupt
USART5_INT_TBE transmit data register empty interrupt
USART5_INT_PERR parity error interrupt
USART5_INT_AM address match interrupt
USART5_INT_RT receiver timeout interrupt
USART5_INT_EB end of block interrupt
USART5_INT_LBD LIN break detection interrupt
USART5_INT_ERR error interrupt enable in multibuffer communication
USART5_INT_CTS CTS interrupt
USART5_INT_WU wakeup from deep-sleep mode interrupt
USART5_INT_RFF receive FIFO full interrupt enable
Output parameter{out}
- -
Return value
- -

Example:

/* disable USART5 TBE interrupt */

usart5_interrupt_disable(USART5, USART5_INT_TBE);

usart5_command_enable

The description of usart5_command_enable is shown as below:

Table 3-1024. Function usart5_command_enable


Function name usart5_command_enable
Function prototype void usart5_command_enable(uint32_t usart_periph, uint32_t cmdtype);
Function descriptions enable USART command
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
cmdtype command type

713
GD32E50x Firmware Library User Guide
USART5_CMD_ABDC
auto baudrate detection command
MD
USART5_CMD_SBKC
send break command
MD
USART5_CMD_MMCM
mute mode command
D
USART5_CMD_RXFC
receive data flush command
MD
USART5_CMD_TXFC
transmit data flush request
MD
Output parameter{out}
- -
Return value
- -

Example:

/* enable USART5 command */

usart5_command_enable(USART5, USART5_CMD_ABDCMD);

usart5_interrupt_flag_get

The description of usart5_interrupt_flag_get is shown as below:

Table 3-1025. Function usart5_interrupt_flag_get


Function name usart5_interrupt_flag_get
FlagStatus usart5_interrupt_flag_get(uint32_t usart_periph,
Function prototype
usart5_interrupt_flag_enum int_flag);
Function descriptions get USART interrupt and flag status
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
int_flag USART interrupt flag, refer to Enum usart5_interrupt_flag_enum
USART5_INT_FLAG_E
end of block interrupt and flag
B
USART5_INT_FLAG_R
receiver timeout interrupt and flag
T
USART5_INT_FLAG_A
address match interrupt and flag
M
USART5_INT_FLAG_P
parity error interrupt and flag
ERR

714
GD32E50x Firmware Library User Guide
USART5_INT_FLAG_T
transmitter buffer empty interrupt and flag
BE
USART5_INT_FLAG_T
transmission complete interrupt and flag
C
USART5_INT_FLAG_R
read data buffer not empty interrupt and flag
BNE
USART5_INT_FLAG_R
read data buffer not empty interrupt and overrun error flag
BNE_ORERR
USART5_INT_FLAG_I
IDLE line detected interrupt and flag
DLE
USART5_INT_FLAG_L
LIN break detected interrupt and flag
BD
USART5_INT_FLAG_
wakeup from deep-sleep mode interrupt and flag
WU
USART5_INT_FLAG_C
CTS interrupt and flag
TS
USART5_INT_FLAG_E
error interrupt and noise error flag
RR_NERR
USART5_INT_FLAG_E
error interrupt and overrun error
RR_ORERR
USART5_INT_FLAG_E
error interrupt and frame error flag
RR_FERR
USART5_INT_FLAG_R
receive FIFO full interrupt and flag
FF
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* get the USART5 interrupt flag status */

FlagStatus status;

status = usart5_interrupt_flag_get(USART5, USART5_INT_FLAG_RBNE);

usart5_interrupt_flag_clear

The description of usart5_interrupt_flag_clear is shown as below:

Table 3-1026. Function usart5_interrupt_flag_clear


Function name usart5_interrupt_flag_clear
void usart5_interrupt_flag_clear(uint32_t usart_periph,
Function prototype
usart5_interrupt_flag_enum flag);
Function descriptions clear USART interrupt flag in STAT register

715
GD32E50x Firmware Library User Guide
Precondition -
The called functions -
Input parameter{in}
usart_periph usart peripheral
USARTx x=5
Input parameter{in}
flag USART interrupt flag, refer to Enum usart5_interrupt_flag_enum
USART5_INT_FLAG_P
parity error interrupt and flag
ERR
USART5_INT_FLAG_E
error interrupt and frame error flag
RR_FERR
USART5_INT_FLAG_E
error interrupt and noise error flag
RR_NERR
USART5_INT_FLAG_R
read data buffer not empty interrupt and overrun error flag
BNE_ORERR
USART5_INT_FLAG_E
error interrupt and overrun error
RR_ORERR
USART5_INT_FLAG_I
IDLE line detected interrupt and flag
DLE
USART5_INT_FLAG_T
transmission complete interrupt and flag
C
USART5_INT_FLAG_L
LIN break detected interrupt and flag
BD
USART5_INT_FLAG_C
CTS interrupt and flag
TS
USART5_INT_FLAG_R
receiver timeout interrupt and flag
T
USART5_INT_FLAG_E
end of block interrupt and flag
B
USART5_INT_FLAG_A
address match interrupt and flag
M
USART5_INT_FLAG_
wakeup from deep-sleep mode interrupt and flag
WU
USART5_INT_FLAG_R
receive FIFO full interrupt and flag
FF
Output parameter{out}
- -
Return value
- -

Example:

/* clear the USART5 interrupt flag */

716
GD32E50x Firmware Library User Guide
usart5_interrupt_flag_clear(USART5, USART5_INT_FLAG_TC);

3.28. WWDGT

The window watchdog timer (WWDGT) is used to detect system failures due to software
malfunctions.The WWDGT registers are listed in chapter 3.28.1, the FWDGT firmware
functions are introduced in chapter 3.28.2.

3.28.1. Descriptions of Peripheral registers

WWDGT registers are listed in the table shown as below:

Table 3-1027. WWDGT Registers


Registers Descriptions
WWDGT_CTL Control register
WWDGT_CFG Configuration register
WWDGT_STAT Status register

3.28.2. Descriptions of Peripheral functions

WWDGT firmware functions are listed in the table shown as below:

Table 3-1028. WWDGT firmware function


Function name Function description
wwdgt_deinit reset the window watchdog timer configuration
wwdgt_enable start the window watchdog timer counter
wwdgt_counter_update configure the window watchdog timer counter value
configure counter value, window value, and prescaler divider
wwdgt_config
value
wwdgt_interrupt_enable enable early wakeup interrupt of WWDGT
wwdgt_flag_get check early wakeup interrupt state of WWDGT
wwdgt_flag_clear clear early wakeup interrupt state of WWDGT

wwdgt_deinit

The description of wwdgt_deinit is shown as below:

Table 3-1029. Function wwdgt_deinit


Function name wwdgt_deinit
Function prototype void wwdgt_deinit(void);
Function descriptions reset the window watchdog timer configuration
Precondition -
The called functions -
Input parameter{in}

717
GD32E50x Firmware Library User Guide
- -
Output parameter{out}
- -
Return value
- -

Example:

/* reset the window watchdog timer configuration */

wwdgt_deinit ( );

wwdgt_enable

The description of wwdgt_enable is shown as below:

Table 3-1030. Function wwdgt_enable


Function name wwdgt_enable
Function prototype void wwdgt_enable(void);
Function descriptions start the window watchdog timer counter
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* start the window watchdog timer counter */

wwdgt_enable ( );

wwdgt_counter_update

The description of wwdgt_counter_update is shown as below:

Table 3-1031. Function wwdgt_counter_update

Function name wwdgt_counter_update


Function prototype void wwdgt_counter_update(uint16_t counter_value);
Function descriptions configure the WWDGT value
Precondition -
The called functions -
Input parameter{in}
counter_value 0x00 - 0x7F

718
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -

Example:

/* update WWDGT counter to 0x7F */

wwdgt_counter_update(127);

wwdgt_config

The description of wwdgt_config is shown as below:

Table 3-1032. Function wwdgt_config


Function name wwdgt_config
Function prototype void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler);
Function descriptions configure counter value, window value, and prescaler divider value
Precondition -
The called functions -
Input parameter{in}
counter 0x00 - 0x7F
Input parameter{in}
window 0x00 - 0x7F
Input parameter{in}
prescaler wwdgt prescaler value
WWDGT_CFG_PSC_D
the time base of window watchdog counter = (PCLK1/4096)/1
IV1
WWDGT_CFG_PSC_D
the time base of window watchdog counter = (PCLK1/4096)/2
IV2
WWDGT_CFG_PSC_D
the time base of window watchdog counter = (PCLK1/4096)/4
IV4
WWDGT_CFG_PSC_D
the time base of window watchdog counter = (PCLK1/4096)/8
IV8
Output parameter{out}
- -
Return value
- -

Example:

/* confiure WWDGT counter value to 0x7F, window value to 0x50, prescaler divider value to
8 */

wwdgt_config(127, 80, WWDGT_CFG_PSC_DIV8);

719
GD32E50x Firmware Library User Guide
wwdgt_interrupt_enable

The description of wwdgt_interrupt_enable is shown as below:

Table 3-1033. Function wwdgt_interrupt_enable


Function name wwdgt_interrupt_enable
Function prototype void wwdgt_interrupt_enable(void);
Function descriptions enable early wakeup interrupt of WWDGT
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* enable early wakeup interrupt of WWDGT */

wwdgt_interrupt_enable ( );

wwdgt_flag_get

The description of wwdgt_flag_get is shown as below:

Table 3-1034. Function wwdgt_flag_get


Function name wwdgt_flag_get
Function prototype FlagStatus wwdgt_flag_get(void);
Function descriptions check early wakeup interrupt state of WWDGT
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
FlagStatus SET or RESET

Example:

/* test if the counter value update has reached the 0x40 */

FlagStatus status;

status = wwdgt_flag_get ( );

if(status == RESET)
720
GD32E50x Firmware Library User Guide
{

...

}else

...

wwdgt_flag_clear

The description of wwdgt_flag_clear is shown as below:

Table 3-1035. Function wwdgt_flag_clear


Function name wwdgt_flag_clear
Function prototype void wwdgt_flag_clear(void);
Function descriptions clear early wakeup interrupt state of WWDGT
Precondition -
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -

Example:

/* clear early wakeup interrupt state of WWDGT */

wwdgt_flag_clear( );

3.29. USBD

Firmware function description of USBD refers to document


GD32E50x_USBD_Firmware_Library_User_Guide_V1.0.

3.30. USBHS

Firmware function description of USBHS refers to document


GD32E50x_USBHS_Firmware_Library_User_Guide_V1.0.

721
GD32E50x Firmware Library User Guide
4. Revision history

Table 4-1. Revision history


Revison No. Description Date
1.0 Initial Release Mar.10, 2020
1.1 Module information modified Aug.26, 2020

722
GD32E50x Firmware Library User Guide

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.

© 2020 GigaDevice – All rights reserved

723

You might also like