GD32E50x Firmware Library User Guide Rev1.1
GD32E50x Firmware Library User Guide Rev1.1
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
3.3. BKP............................................................................................................................. 73
3.3.1. Descriptions of Peripheral registers ...................................................................................... 74
3.3.2. Descriptions of Peripheral functions ..................................................................................... 74
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
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
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:
1.1.1. Peripherals
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
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.
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;
– 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.
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:
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:
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:
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:
Utilities folder includes files about the firmware examples on evaluation board:
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.
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.
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.
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.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.
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
41
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -
Example:
/* reset ADC0 */
adc_deinit(ADC0);
adc_enable
Example:
/* enable ADC0 */
adc_enable(ADC0);
adc_disable
Example:
/* disable ADC0 */
adc_disable(ADC0);
adc_calibration_enable
Example:
adc_calibration_enable(ADC0);
adc_calibration_number
Example:
adc_calibration_number(ADC0, ADC_CALIBRATION_NUM16);
adc_dma_mode_enable
Example:
44
GD32E50x Firmware Library User Guide
adc_dma_mode_enable(ADC0);
adc_dma_mode_disable
Example:
adc_dma_mode_disable(ADC0);
adc_tempsensor_vrefint_enable
Example:
adc_tempsensor_vrefint_enable();
45
GD32E50x Firmware Library User Guide
adc_tempsensor_vrefint_disable
Example:
adc_tempsensor_vrefint_disable();
adc_discontinuous_mode_config
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:
adc_mode_config
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:
adc_mode_config(ADC_MODE_FREE);
adc_special_function_config
48
GD32E50x Firmware Library User Guide
Example:
adc_data_alignment_config
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:
adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
adc_channel_length_config
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:
adc_regular_channel_config
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:
adc_inserted_channel_config
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:
adc_inserted_channel_offset_config
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:
adc_channel_differential_mode_config
53
GD32E50x Firmware Library User Guide
- -
Example:
adc_channel_differential_mode_config(ADC0,
ADC_DIFFERENTIAL_MODE_CHANNEL_ALL, ENABLE);
adc_external_trigger_config
Example:
adc_external_trigger_source_config
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:
adc_external_trigger_source_config(ADC0,ADC_REGULAR_CHANNEL,
ADC0_1_EXTTRIG_REGULAR_T0_CH0);
adc_software_trigger_enable
57
GD32E50x Firmware Library User Guide
Example:
adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);
adc_regular_data_read
Example:
uint16_t adc_value = 0;
adc_value = adc_regular_data_read(ADC0);
adc_inserted_data_read
Example:
uint16_t adc_value = 0;
adc_sync_mode_convert_value_read
Example:
/* read the last ADC0 and ADC1 conversion result data in sync mode */
uint32_t adc_value = 0;
adc_watchdog0_single_channel_enable
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:
adc_watchdog0_single_channel_enable(ADC0, ADC_CHANNEL_1);
adc_watchdog0_group_channel_enable
60
GD32E50x Firmware Library User Guide
- -
Example:
adc_watchdog0_group_channel_enable(ADC0, ADC_REGULAR_CHANNEL);
adc_watchdog0_disable
Example:
adc_watchdog0_disable(ADC0);
adc_watchdog1_channel_config
Example:
adc_watchdog1_channel_config(ADC0, ADC_AWD1_2_SELECTION_CHANNEL_1,
ENABLE);
adc_watchdog2_channel_config
62
GD32E50x Firmware Library User Guide
DISABLE disable function
Output parameter{out}
- -
Return value
- -
Example:
adc_watchdog2_channel_config(ADC0, ADC_AWD1_2_SELECTION_CHANNEL_1,
ENABLE);
adc_watchdog1_disable
Example:
adc_watchdog1_disable(ADC0);
adc_watchdog2_disable
Example:
adc_watchdog2_disable(ADC0);
adc_watchdog0_threshold_config
Example:
adc_watchdog1_threshold_config
Example:
adc_watchdog2_threshold_config
65
GD32E50x Firmware Library User Guide
Example:
adc_resolution_config
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:
adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
adc_oversample_mode_config
66
GD32E50x Firmware Library User Guide
uint16_t shift, uint8_t ratio);
Function descriptions configure ADC oversample mode
Precondition -
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:
adc_oversample_mode_config(ADC1, ADC_OVERSAMPLING_ALL_CONVERT,
ADC_OVERSAMPLING_SHIFT_4B, ADC_OVERSAMPLING_RATIO_MUL16);
adc_oversample_mode_enable
Example:
adc_oversample_mode_enable (ADC0);
68
GD32E50x Firmware Library User Guide
adc_oversample_mode_disable
Example:
adc_oversample_mode_disable (ADC0);
adc_flag_get
69
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
FlagStatus SET or RESET
Example:
FlagStatus flag_value;
adc_flag_clear
Example:
adc_flag_clear(ADC0, ADC_FLAG_WDE0);
70
GD32E50x Firmware Library User Guide
adc_interrupt_enable
Example:
adc_interrupt_enable(ADC0, ADC_INT_WDE0);
adc_interrupt_disable
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:
adc_interrupt_disable(ADC0, ADC_INT_WDE0);
adc_interrupt_flag_get
Example:
72
GD32E50x Firmware Library User Guide
/* get the ADC0 analog watchdog 0 interrupt bits*/
FlagStatus flag_value;
adc_interrupt_flag_clear
Example:
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.
74
GD32E50x Firmware Library User Guide
Enum bkp_data_register_enum
bkp_deinit
Example:
bkp_deinit ();
bkp_write_data
76
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -
Example:
bkp_read_data
Example:
uint16_t data;
bkp_rtc_calibration_output_enable
77
GD32E50x Firmware Library User Guide
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -
Example:
bkp_rtc_calibration_output_enable();
bkp_rtc_calibration_output_disable
Example:
bkp_rtc_calibration_output_disable();
bkp_rtc_signal_output_enable
Example:
bkp_rtc_signal_output_enable();
bkp_rtc_signal_output_disable
Example:
bkp_rtc_signal_output_disable();
bkp_rtc_output_select
Example:
bkp_rtc_output_select (RTC_OUTPUT_ALARM_PULSE);
bkp_rtc_clock_output_select
Example:
bkp_rtc_clock_output_select (RTC_CLOCK_DIV_64);
bkp_rtc_clock_calibration_direction
Example:
bkp_rtc_clock_calibration_direction (RTC_CLOCK_SLOWED_DOWN);
bkp_rtc_calibration_value_set
Example:
bkp_rtc_calibration_value_set (0x7f);
bkp_tamper_detection_enable
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:
bkp_tamper_detection_enable();
bkp_tamper_detection_disable
Example:
bkp_tamper_detection_disable();
bkp_tamper_active_level_set
Example:
bkp_tamper_active_level_set (TAMPER_PIN_ACTIVE_HIGH);
bkp_tamper_interrupt_enable
Example:
bkp_tamper_interrupt_enable ();
bkp_tamper_interrupt_disable
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:
bkp_tamper_interrupt_disable ();
bkp_flag_get
Example:
FlagStatus status;
bkp_flag_clear
Example:
bkp_flag_clear (BKP_FLAG_TAMPER);
bkp_interrupt_flag_get
Example:
bkp_interrupt_flag_get (BKP_INT_FLAG_TAMPER);
85
GD32E50x Firmware Library User Guide
bkp_interrupt_flag_clear
Example:
bkp_interrupt_flag_clear (BKP_INT_FLAG_TAMPER);
3.4. CRC
86
GD32E50x Firmware Library User Guide
3.4.2. Descriptions of Peripheral functions
crc_deinit
Example:
/* deinitialize CRC */
crc_deinit();
crc_data_register_reset
Example:
crc_data_register_reset ();
crc_reverse_output_data_enable
Example:
crc_reverse_output_data_enable ();
crc_reverse_output_data_disable
Example:
crc_reverse_output_data_disable ();
crc_input_data_reverse_config
Example:
crc_input_data_reverse_config (CRC_INPUT_DATA_WORD);
89
GD32E50x Firmware Library User Guide
crc_data_register_read
Example:
uint32_t crc_value = 0;
crc_value = crc_data_register_read();
crc_free_data_register_read
Example:
uint8_t crc_value = 0;
crc_value = crc_free_data_register_read();
90
GD32E50x Firmware Library User Guide
crc_free_data_register_write
Example:
crc_free_data_register_write(0x11);
crc_init_data_register_write
Example:
crc_init_data_register_write (0x11223344);
91
GD32E50x Firmware Library User Guide
crc_polynomial_size_set
Example:
crc_polynomial_size_set (CRC_CTL_PS_7);
crc_polynomial_set
Example:
crc_single_data_calculate
Example:
val = (uint32_t)0xabcd1234;
rcu_periph_clock_enable(RCU_CRC);
valcrc = crc_single_data_calculate(val);
crc_block_data_calculate
Example:
#define BUFFER_SIZE 6
uint32_t valcrc = 0;
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.
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
Example:
/* reset CTC */
ctc_deinit();
95
GD32E50x Firmware Library User Guide
ctc_counter_enable
Example:
ctc_counter_enable ();
ctc_counter_disable
Example:
ctc_counter_disable ();
96
GD32E50x Firmware Library User Guide
ctc_irc48m_trim_value_config
Example:
ctc_irc48m_trim_value_config (0x01);
ctc_software_refsource_pulse_generate
Example:
ctc_software_refsource_pulse_generate ();
97
GD32E50x Firmware Library User Guide
ctc_hardware_trim_mode_config
Example:
ctc_hardware_trim_mode_config (CTC_HARDWARE_TRIM_MODE_ENABLE);
ctc_refsource_polarity_config
98
GD32E50x Firmware Library User Guide
- -
Example:
ctc_refsource_polarity_config (CTC_REFSOURCE_POLARITY_RISING);
ctc_refsource_signal_select
Example:
ctc_refsource_signal_select (CTC_REFSOURCE_LXTAL);
ctc_refsource_prescaler_config
Example:
ctc_refsource_prescaler_config(CTC_REFSOURCE_PSC_DIV2);
ctc_clock_limit_value_config
Example:
100
GD32E50x Firmware Library User Guide
/* configure clock trim base limit value */
ctc_clock_limit_value_config (0x1F);
ctc_counter_reload_value_config
Example:
ctc_counter_reload_value_config (0x00FF);
ctc_counter_capture_value_read
Example:
101
GD32E50x Firmware Library User Guide
uint16_t ctc_value = 0;
ctc_counter_direction_read
Example:
ctc_counter_reload_value_read
Example:
102
GD32E50x Firmware Library User Guide
/* read CTC counter reload value */
uint16_t ctc_reload_value = 0;
ctc_irc48m_trim_value_read
Example:
uint8_t ctc_trim_value = 0;
ctc_flag_get
Example:
ctc_flag_clear
Example:
ctc_flag_clear (CTC_FLAG_CKOK);
ctc_interrupt_enable
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:
ctc_interrupt_enable (CTC_INT_CKOK);
ctc_interrupt_disable
Example:
105
GD32E50x Firmware Library User Guide
/* disable CTC clock trim OK interrupt */
ctc_interrupt_disable (CTC_INT_CKOK);
ctc_interrupt_flag_get
Example:
ctc_interrupt_flag_clear
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:
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.
107
GD32E50x Firmware Library User Guide
3.6.2. Descriptions of Peripheral functions
Enum cmp_enum
Enum inverting_input_enum
Enum cmp_output_enum
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
cmp_deinit
Example:
/* deinitialize comparator */
cmp_deinit();
cmp_input_init
Example:
cmp_output_init
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:
cmp_output_init (CMP1,CMP_OUTPUT_NONE,
CMP_OUTPUT_POLARITY_NOINVERTED);
cmp_outputblank_init
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:
cmp_enable
Example:
/* enable comparator1 */
cmp_enable (CMP1);
cmp_disable
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
Example:
cmp_lock_enable (CMP1);
cmp_output_level_get
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:
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.
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
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
Example:
/* deinitialize DAC */
dac_deinit();
dac_enable
116
GD32E50x Firmware Library User Guide
Return value
- -
Example:
/* enable DAC_OUT0 */
dac_enable(DAC_OUT_0);
dac_disable
Example:
/* disable DAC_OUT0 */
dac_disable(DAC_OUT_0);
dac_dma_enable
Example:
dac_dma_enable(DAC_OUT_0);
dac_dma_disable
Example:
dac_dma_disable(DAC_OUT_0);
dac_output_buffer_enable
Example:
dac_output_buffer_enable(DAC_OUT_0);
dac_output_buffer_disable
Example:
dac_output_buffer_disable(DAC_OUT_0);
dac_output_value_get
Example:
data = dac_output_value_get(DAC_OUT_0);
dac_data_set
Example:
dac_output_fifo_enable
Example:
dac_output_fifo_enable(DAC_OUT_0);
dac_output_fifo_disable
Example:
dac_output_fifo_disable(DAC_OUT_0);
dac_output_fifo_number_get
Example:
dac_trigger_enable
Example:
dac_trigger_enable(DAC_OUT_0);
dac_trigger_disable
Example:
dac_trigger_disable(DAC_OUT_0);
dac_trigger_source_config
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:
dac_trigger_source_config(DAC_OUT_0, DAC_TRIGGER_T1_TRGO);
dac_software_trigger_enable
Example:
dac_software_trigger_enable(DAC_OUT_0);
124
GD32E50x Firmware Library User Guide
dac_software_trigger_disable
Example:
dac_software_trigger_disable(DAC_OUT_0);
dac_wave_mode_config
125
GD32E50x Firmware Library User Guide
Return value
- -
Example:
dac_wave_mode_config(DAC_OUT_0, DAC_WAVE_DISABLE);
dac_wave_bit_width_config
Example:
dac_wave_bit_width_config(DAC_OUT_0, DAC_WAVE_BIT_WIDTH_1);
dac_lfsr_noise_config
Example:
dac_lfsr_noise_config(DAC_OUT_0, DAC_LFSR_BIT0);
dac_triangle_noise_config
Example:
dac_triangle_noise_config(DAC_OUT_0, DAC_TRIANGLE_AMPLITUDE_1);
127
GD32E50x Firmware Library User Guide
dac_concurrent_enable
Example:
dac_concurrent_enable();
dac_concurrent_disable
Example:
dac_concurrent_disable();
128
GD32E50x Firmware Library User Guide
dac_concurrent_software_trigger_enable
Example:
dac_concurrent_software_trigger_enable();
dac_concurrent_software_trigger_disable
Example:
dac_concurrent_software_trigger_disable();
129
GD32E50x Firmware Library User Guide
dac_concurrent_output_buffer_enable
Example:
dac_concurrent_output_buffer_enable();
dac_concurrent_output_buffer_disable
Example:
dac_concurrent_output_buffer_disable();
130
GD32E50x Firmware Library User Guide
dac_concurrent_data_set
Example:
dac_flag_get
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:
FlagStatus flag_value;
dac_flag_clear
Example:
dac_flag_clear(DAC_OUT_0, DAC_FLAG_FIFOOVR0);
dac_interrupt_enable
133
GD32E50x Firmware Library User Guide
- -
Example:
dac_interrupt_enable(DAC_OUT_0, DAC_INT_DDUDRIE0);
dac_interrupt_disable
Example:
dac_interrupt_disable(DAC_OUT_0, DAC_INT_DDUDRIE0);
dac_interrupt_flag_get
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:
FlagStatus flag_value;
dac_interrupt_flag_clear
Example:
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.
Enum dbg_periph_enum
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:
dbg_deinit();
dbg_id_get
Example:
uint32_t id_value = 0;
id_value = dbg_id_get();
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:
dbg_low_power_enable(DBG_LOW_POWER_SLEEP);
dbg_low_power_disable
139
GD32E50x Firmware Library User Guide
Example:
dbg_low_power_disable(DBG_LOW_POWER_SLEEP);
dbg_periph_enable
Example:
dbg_periph_enable(DBG_TIMER0_HOLD);
dbg_periph_disable
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:
dbg_periph_disable(DBG_TIMER0_HOLD);
dbg_trace_pin_enable
Example:
dbg_trace_pin_enable();
dbg_trace_pin_disable
Example:
dbg_trace_pin_disable();
dbg_trace_pin_mode_set
Example:
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.
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
Structure dma_parameter_struct
144
GD32E50x Firmware Library User Guide
direction channel data transfer direction
dma_deinit
Example:
dma_struct_para_init
dma_init
Example:
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
Example:
dma_circulation_disable
Example:
dma_memory_to_memory_enable
Example:
dma_memory_to_memory_disable
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:
dma_channel_enable
Example:
dma_channel_disable
Example:
dma_periph_address_config
Example:
dma_memory_address_config
Example:
151
GD32E50x Firmware Library User Guide
uint8_t g_destbuf[TRANSFER_NUM];
dma_transfer_number_config
Example:
dma_transfer_number_get
Example:
uint32_t number = 0;
dma_priority_config
153
GD32E50x Firmware Library User Guide
Return value
- -
Example:
dma_memory_width_config
Example:
dma_periph_width_config
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_memory_increase_enable
Example:
dma_memory_increase_enable(DMA0, DMA_CH0);
dma_memory_increase_disable
Example:
dma_memory_increase_disable(DMA0, DMA_CH0);
dma_periph_increase_enable
Example:
dma_periph_increase_enable(DMA0, DMA_CH0);
dma_periph_increase_disable
Example:
dma_periph_increase_disable(DMA0, DMA_CH0);
157
GD32E50x Firmware Library User Guide
dma_transfer_direction_config
Example:
dma_flag_get
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:
dma_flag_clear
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_interrupt_enable
Example:
160
GD32E50x Firmware Library User Guide
dma_interrupt_disable
Example:
dma_interrupt_flag_get
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:
dma_interrupt_flag_clear
Example:
3.10. ENET
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
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
Structure enet_descriptors_struct
Structure enet_ptp_systime_struct
169
GD32E50x Firmware Library User Guide
nanosecond nanosecond of system time
sign sign of system time
Enum enet_flag_enum
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
Enum enet_int_enum
173
GD32E50x Firmware Library User Guide
Enum enet_int_flag_enum
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
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
Enum enet_msc_counter_enum
176
GD32E50x Firmware Library User Guide
GUFCNT
Enum enet_option_enum
Enum enet_mediamode_enum
177
GD32E50x Firmware Library User Guide
Enum enet_chksumconf_enum
Enum enet_frmrecept_enum
Enum enet_registers_type_enum
Enum enet_dmadirection_enum
178
GD32E50x Firmware Library User Guide
ENET_DMA_RX DMA Rx descriptors
Enum enet_phydirection_enum
Enum enet_regdirection_enum
Enum enet_macaddress_enum
Enum enet_descstate_enum
enet_deinit
Example:
enet_deinit( );
enet_initpara_config
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_init
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:
ErrStatus enet_init_status;
enet_software_reset
Example:
reval_state = enet_software_reset();
185
GD32E50x Firmware Library User Guide
enet_rxframe_size_get
Function descriptions check receive frame valid and return frame size
Precondition -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
Example:
uint32_t reval;
reval = enet_rxframe_size_get();
enet_descriptors_chain_init
186
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -
Example:
enet_descriptors_chain_init(ENET_DMA_TX);
enet_descriptors_ring_init
Example:
enet_descriptors_ring_init(ENET_DMA_TX);
enet_frame_receive
Example:
uint8_t data_buffer[1500];
uint32_t data_size;
enet_frame_receive(data_buffer, &data_size);
enet_frame_transmit
Example:
uint8_t data_buffer[1500];
188
GD32E50x Firmware Library User Guide
enet_transmit_checksum_config
Return value
ErrStatus ERROR or SUCCESS
Example:
enet_descriptors_struct rx_desc;
enet_transmit_checksum_config(rx_desc, ENET_CHECKSUM_TCPUDPICMP_FULL);
enet_enable
Example:
enet_enable();
enet_disable
Example:
enet_disable();
enet_mac_address_set
Example:
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
Example:
enet_flag_get
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:
enet_flag_get (ENET_DMA_FLAG_RS);
enet_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:
enet_flag_clear(ENET_DMA_FLAG_RS_CLR);
enet_interrupt_enable
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:
enet_interrupt_enable(ENET_DMA_INT_NIE);
enet_interrupt_disable
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:
enet_interrupt_disable(ENET_DMA_INT_NIE);
enet_interrupt_flag_get
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:
enet_interrupt_flag_get(ENET_DMA_INT_FLAG_RS);
enet_interrupt_flag_clear
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:
enet_interrupt_flag_clear(ENET_DMA_INT_FLAG_RS);
enet_tx_enable
201
GD32E50x Firmware Library User Guide
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -
Example:
enet_tx_enable();
enet_tx_disable
Example:
enet_tx_disable();
enet_rx_enable
Example:
enet_rx_enable();
enet_rx_disable
Example:
enet_rx_disable();
enet_registers_get
Example:
uint32_t register_buffer[5];
enet_registers_get(ALL_MAC_REG, 5, register_buffer);
enet_debug_status_get
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:
uint32_t debug_value;
enet_address_filter_enable
205
GD32E50x Firmware Library User Guide
- -
Return value
- -
Example:
enet_address_filter_enable(ENET_MAC_ADDRESS1);
enet_address_filter_disable
Example:
enet_address_filter_disable(ENET_MAC_ADDRESS1);
enet_address_filter_config
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:
enet_phy_config
Example:
enet_phy_config();
enet_phy_write_read
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:
enet_phyloopback_enable
Example:
phy_state = enet_phyloopback_enable();
enet_phyloopback_disable
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:
phy_state = enet_phyloopback_disable();
enet_forward_feature_enable
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
Example:
enet_forward_feature_enable(ENET_FORWARD_UNDERSZ_GOODFRAMES);
enet_fliter_feature_enable
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:
enet_fliter_feature_enable(ENET_SRC_FILTER);
enet_fliter_feature_disable
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:
enet_fliter_feature_enable(ENET_SRC_FILTER);
enet_pauseframe_generate
Example:
ErrStatus reval;
reval = enet_pauseframe_generate();
enet_pauseframe_detect_config
Example:
enet_pauseframe_detect_config(ENET_UNIQUE_PAUSEDETECT);
enet_pauseframe_config
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:
enet_pauseframe_config(30, ENET_PAUSETIME_MINUS4);
enet_flowcontrol_threshold_config
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:
enet_flowcontrol_threshold_config(ENET_DEACTIVE_THRESHOLD_256BYTES, ENET_A
CTIVE_THRESHOLD_256BYTES);
enet_flowcontrol_feature_enable
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:
enet_flowcontrol_feature_enable(ENET_ZERO_QUANTA_PAUSE);
enet_flowcontrol_feature_disable
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
Example:
uint32_t reval;
reval = enet_dmaprocess_state_get(ENET_DMA_RX);
if(ENET_RX_STATE_SUSPENDED == reval){
do…
enet_dmaprocess_resume
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:
enet_dmaprocess_resume(ENET_DMA_RX);
enet_rxprocess_check_recovery
Example:
enet_rxprocess_check_recovery();
219
GD32E50x Firmware Library User Guide
enet_txfifo_flush
Example:
reval = enet_txfifo_flush();
enet_current_desc_address_get
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:
uint32_t reval;
reval = enet_current_desc_address_get(ENET_RX_DESC_TABLE);
enet_desc_information_get
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:
uint32_t reval;
enet_missed_frame_counter_get
Example:
enet_missed_frame_counter_get(&rxcnt, &txcnt);
enet_desc_flag_get
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:
FlagStatus reval;
enet_desc_flag_set
Example:
enet_desc_flag_set(p_txdesc, ENET_TDES0_VFRM);
enet_desc_flag_clear
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:
enet_desc_flag_clear(p_txdesc, ENET_TDES0_VFRM);
enet_rx_desc_immediate_receive_complete_interrupt
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
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
227
GD32E50x Firmware Library User Guide
- -
Return value
- -
Example:
enet_rxframe_drop( );
enet_dma_feature_enable
Example:
enet_dma_feature_enable(ENET_NO_FLUSH_RXFRAME);
enet_dma_feature_disable
Example:
enet_dma_feature_disable(ENET_NO_FLUSH_RXFRAME);
enet_rx_desc_enhanced_status_get
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:
uint32_t status;
enet_desc_select_enhanced_mode
Example:
enet_desc_select_enhanced_mode();
enet_ptp_enhanced_descriptors_chain_init
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
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
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;
enet_ptpframe_transmit_enhanced_mode
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;
enet_desc_select_normal_mode
Example:
enet_desc_select_normal_mode( );
enet_ptp_normal_descriptors_chain_init
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
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
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;
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;
enet_wum_filter_register_pointer_reset
Example:
enet_wum_filter_register_pointer_reset ();
enet_wum_filter_config
Example:
uint32_t wum_data[8];
enet_wum_filter_config (wum_data);
enet_wum_feature_enable
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:
enet_wum_feature_enable(ENET_WUM_POWER_DOWN);
enet_wum_feature_disable
Example:
238
GD32E50x Firmware Library User Guide
enet_wum_feature_disable(ENET_WUM_POWER_DOWN);
enet_msc_counters_reset
Example:
enet_msc_counters_reset();
enet_msc_feature_enable
239
GD32E50x Firmware Library User Guide
- -
Example:
enet_msc_feature_enable(ENET_MSC_COUNTER_STOP_ROLLOVER);
enet_msc_feature_disable
Example:
enet_msc_feature_disable(ENET_MSC_COUNTER_STOP_ROLLOVER);
enet_msc_counters_preset_config
Example:
enet_msc_counters_preset_config (ENET_MSC_PRESET_HALF);
enet_msc_counters_get
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
Example:
uin32_t reval;
enet_ptp_nanosecond_2_subsecond
Example:
uin32_t reval;
enet_ptp_feature_enable
243
GD32E50x Firmware Library User Guide
Example:
enet_ptp_feature_enable(ENET_ALL_RX_TIMESTAMP);
enet_ptp_feature_disable
Example:
enet_ptp_feature_disable(ENET_ALL_RX_TIMESTAMP);
244
GD32E50x Firmware Library User Guide
enet_ptp_timestamp_function_config
Example:
reval = enet_ptp_timestamp_function_config(ENET_PTP_ADDEND_UPDATE);
enet_ptp_subsecond_increment_config
Example:
enet_ptp_subsecond_increment_config(0x1F);
enet_ptp_timestamp_addend_config
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
- -
enet_ptp_timestamp_addend_config(0x1FFF);
enet_ptp_timestamp_update_config
Example:
enet_ptp_timestamp_update_config(ENET_PTP_ADD_TO_TIME, 0, 0);
enet_ptp_expected_time_config
Example:
enet_ptp_expected_time_config(2000, 0);
enet_ptp_system_time_get
Example:
enet_ptp_systime_struct systime;
enet_ptp_system_time_get(&systime);
enet_ptp_pps_output_frequency_config
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:
enet_ptp_pps_output_frequency_config(ENET_PPSOFC_1HZ);
enet_ptp_start
Example:
250
GD32E50x Firmware Library User Guide
/* gconfigure and start PTP timestamp counter*/
enet_ptp_finecorrection_adjfreq
Example:
enet_ptp_finecorrection_adjfreq(10);
enet_ptp_coarsecorrection_systime_update
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
Example:
enet_ptp_systime_struct systime_struct;
enet_ptp_finecorrection_settime (&systime_struct);
enet_ptp_flag_get
252
GD32E50x Firmware Library User Guide
UPDATE
ENET_PTP_SYSTIME_
timestamp initialize
INIT
Output parameter{out}
- -
Return value
FlagStatus SET or RESET
Example:
enet_initpara_reset
Example:
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.
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
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
Structure exmc_norsram_parameter_struct
255
GD32E50x Firmware Library User Guide
Structure exmc_nand_pccard_timing_parameter_struct
Structure exmc_nand_parameter_struct
Structure exmc_pccard_parameter_struct
exmc_norsram_deinit
Example:
exmc_norsram_deinit(EXMC_BANK0_NORSRAM_REGION1);
exmc_norsram_struct_para_init
Example:
exmc_norsram_parameter_struct nor_init_struct;
exmc_norsram_struct_para_init (&nor_init_struct);
257
GD32E50x Firmware Library User Guide
exmc_norsram_init
Example:
exmc_norsram_parameter_struct lcd_init_struct;
exmc_norsram_timing_parameter_struct lcd_timing_init_struct;
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;
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
Example:
exmc_norsram_enable(EXMC_BANK0_NORSRAM_REGION1);
259
GD32E50x Firmware Library User Guide
exmc_norsram_disable
Example:
exmc_norsram_disable(EXMC_BANK0_NORSRAM_REGION1);
exmc_norsram_page_size_config
260
GD32E50x Firmware Library User Guide
EXMC_CRAM_PAGE_
page size is 1024 bytes
SIZE_1024_BYTES
Output parameter{out}
- -
Return value
- -
Example:
exmc_norsram_page_size_config (EXMC_CRAM_PAGE_SIZE_128_BYTES);
exmc_nand_deinit
Example:
exmc_norsram_deinit(EXMC_BANK1_NAND);
exmc_nand_struct_para_init
Example:
exmc_nand_parameter_struct nand_init_struct;
exmc_nand_struct_para_init (&nand_init_struct);
exmc_nand_init
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
Example:
exmc_nand_enable(EXMC_BANK1_NAND);
exmc_nand_disable
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:
exmc_nand_disable(EXMC_BANK1_NAND);
exmc_nand_ecc_config
Example:
exmc_nand_ecc_config(EXMC_BANK1_NAND, ENABLE);
exmc_ecc_get
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:
uint32_t ecc_value;
ecc_value = exmc_ecc_get(EXMC_BANK1_NAND);
exmc_pccard_deinit
Example:
exmc_pccard_deinit();
exmc_pccard_struct_para_init
Example:
exmc_pccard_parameter_struct pccard_init_struct;
exmc_pccard_struct_para_init (&pccard_init_struct);
exmc_pccard_init
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;
exmc_pccard_init(&pccard_init_struct);
exmc_pccard_enable
Example:
exmc_pccard_enable();
exmc_pccard_disable
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:
exmc_pccard_disable();
exmc_interrupt_enable
268
GD32E50x Firmware Library User Guide
Return value
- -
Example:
exmc_interrupt_enable(EXMC_BANK1_NAND, EXMC_NAND_PCCARD_INT_FLAG_RISE);
exmc_interrupt_disable
Example:
exmc_interrupt_disable(EXMC_BANK1_NAND,
EXMC_NAND_PCCARD_INT_FLAG_RISE);
269
GD32E50x Firmware Library User Guide
exmc_flag_get
Example:
exmc_flag_clear
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:
exmc_flag_clear(EXMC_BANK1_NAND, EXMC_NAND_PCCARD_FLAG_RISE);
exmc_interrupt_flag_get
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:
if(RESET!=exmc_interrupt_flag_get(EXMC_BANK1_NAND,EXMC_NAND_PCCARD_INT_
FLAG_RISE));
exmc_interrupt_flag_clear
272
GD32E50x Firmware Library User Guide
Return value
- -
Example:
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.
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
Enum exti_mode_enum
Enum exti_trig_type_enum
exti_deinit
Example:
exti_deinit();
exti_init
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_interrupt_enable
Example:
exti_interrupt_enable(EXTI_0);
exti_interrupt_disable
Example:
exti_interrupt_disable(EXTI_0);
exti_event_enable
Example:
exti_event_enable(EXTI_0);
exti_event_disable
Example:
exti_event_disable(EXTI_0);
exti_software_interrupt_enable
Example:
exti_software_interrupt_enable(EXTI_0);
exti_software_interrupt_disable
Example:
exti_software_interrupt_disable(EXTI_0);
exti_flag_get
Example:
exti_flag_clear
Example:
exti_flag_clear(EXTI_0);
exti_interrupt_flag_get
Example:
exti_interrupt_flag_clear
Example:
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.
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
282
GD32E50x Firmware Library User Guide
fmc_unlock
Example:
fmc_unlock ( );
fmc_lock
Example:
fmc_lock( );
283
GD32E50x Firmware Library User Guide
fmc_wscnt_set
Example:
fmc_wscnt_set (WS_WSCNT_1);
fmc_prefetch_enable
Example:
284
GD32E50x Firmware Library User Guide
/* enable pre-fetch */
fmc_prefetch_enable( );
fmc_prefetch_disable
Example:
/* disable pre-fetch */
fmc_prefetch_disable( );
fmc_ibus_enable
Example:
285
GD32E50x Firmware Library User Guide
fmc_ibus_enable( );
fmc_ibus_disable
Example:
fmc_ibus_disable( );
fmc_ibus_reset
Example:
fmc_ibus_reset();
286
GD32E50x Firmware Library User Guide
fmc_dbus_enable
Example:
fmc_dbus_enable( );
fmc_dbus_disable
Example:
fmc_dbus_disable( );
287
GD32E50x Firmware Library User Guide
fmc_dbus_reset
Example:
fmc_dbus_reset( );
fmc_page_erase
Example:
/* erase page */
fmc_unlock();
288
GD32E50x Firmware Library User Guide
fmc_mass_erase
Example:
fmc_unlock();
fmc_word_program
Example:
289
GD32E50x Firmware Library User Guide
fmc_unlock();
fmc_page_erase(0x08004000);
ob_unlock
Example:
fmc_unlock( );
ob_unlock ( );
ob_lock
290
GD32E50x Firmware Library User Guide
Example:
fmc_unlock( );
ob_lock( );
ob_erase
Example:
fmc_unlock( );
ob_unlock( );
ob_write_protection_enable
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:
fmc_unlock( );
ob_unlock( );
ob_security_protection_config
Example:
ob_unlock( );
ob_user_write
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:
fmc_unlock( );
ob_unlock( );
OB_STDBY_RST);
ob_data_program
Example:
fmc_unlock( );
ob_unlock( );
ob_user_get
Example:
ob_data_get
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:
ob_write_protection_get
Example:
uint32_t wp = ob_write_protection_get ( );
ob_security_protection_flag_get
Example:
fmc_flag_get
Example:
fmc_flag_clear
Example:
fmc_interrupt_enable
Example:
fmc_unlock( );
fmc_interrupt_enable(FMC_INT_END);
297
GD32E50x Firmware Library User Guide
fmc_interrupt_disable
Example:
fmc_unlock( );
fmc_interrupt_disable(FMC_INT_END);
fmc_interrupt_flag_get
298
GD32E50x Firmware Library User Guide
K0_PGERR
Output parameter{out}
- -
Return value
FlagStatus SET or RESET
Example:
fmc_interrupt_flag_clear
Example:
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.
fwdgt_write_enable
Example:
fwdgt_write_enable ( );
fwdgt_write_disable
Example:
fwdgt_write_disable ( );
fwdgt_enable
301
GD32E50x Firmware Library User Guide
Example:
fwdgt_enable ( );
fwdgt_prescaler_value_config
Example:
fwdgt_prescaler_value_config (FWDGT_PSC_DIV8);
fwdgt_reload_value_config
302
GD32E50x Firmware Library User Guide
reload_value specify reload value(0x0000 - 0x0FFF)
Output parameter{out}
- -
Return value
- -
Example:
fwdgt_reload_value_config(625);
fwdgt_config
Example:
fwdgt_config(2*500, FWDGT_PSC_DIV64);
fwdgt_counter_reload
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:
fwdgt_counter_reload ( );
fwdgt_flag_get
Example:
FlagStatus status;
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.
305
GD32E50x Firmware Library User Guide
3.15.2. Descriptions of Peripheral functions
gpio_deinit
306
GD32E50x Firmware Library User Guide
- -
Example:
/* reset GPIOA */
gpio_deinit (GPIOA);
gpio_afio_deinit
Example:
gpio_afio_deinit();
gpio_init
Example:
gpio_bit_set
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_reset
Example:
/* reset PA0*/
gpio_bit_write
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_port_write
310
GD32E50x Firmware Library User Guide
Return value
- -
Example:
gpio_input_bit_get
Example:
FlagStatus bit_state;
gpio_input_port_get
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:
uint16_t port_state;
port_state = gpio_input_port_get(GPIOA);
gpio_output_bit_get
Example:
FlagStatus bit_state;
312
GD32E50x Firmware Library User Guide
gpio_output_port_get
Example:
uint16_t port_state;
gpio_pin_remap_config
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:
gpio_afio_port_config
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:
319
GD32E50x Firmware Library User Guide
gpio_ethernet_phy_select
Example:
gpio_ethernet_phy_select (GPIO_ENET_PHY_RMII);
gpio_exti_source_select
320
GD32E50x Firmware Library User Guide
- -
Example:
gpio_event_output_config
Example:
gpio_event_output_enable
Example:
gpio_event_output_enable(void);
gpio_event_output_disable
Example:
gpio_event_output_disable(void);
gpio_pin_lock
Example:
/* lock PA0 */
gpio_compensation_config
Example:
gpio_compensation_config (GPIO_COMPENSATION_ENABLE);
gpio_compensation_flag_get
Example:
FlagStatus cell_state;
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.
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
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
Structure shrtimer_timerinit_parameter_struct
329
GD32E50x Firmware Library User Guide
Structure shrtimer_timercfg_parameter_struct
Structure shrtimer_comparecfg_parameter_struct
Structure shrtimer_exevfilter_parameter_struct
330
GD32E50x Firmware Library User Guide
Structure shrtimer_deadtimecfg_parameter_struct
Structure shrtimer_carriersignalcfg_parameter_struct
Structure shrtimer_synccfg_parameter_struct
Structure shrtimer_bunchmode_parameter_struct
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
Structure shrtimer_faultcfg_parameter_struct
Structure shrtimer_adctrigcfg_parameter_struct
Structure shrtimer_channel_outputcfg_parameter_struct
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
Example:
/* reset SHRTIMER */
shrtimer_deinit(SHRTIMER0);
shrtimer_dll_calibration_start
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:
shrtimer_dll_calibration_start(SHRTIMER0, SHRTIMER_CALIBRATION_ONCE);
shrtimer_baseinit_struct_para_init
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
Example:
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_counter_enable
Example:
/* enable a counter */
shrtimer_timers_counter_disable
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
337
GD32E50x Firmware Library User Guide
Example:
shrtimer_timers_update_event_enable(SHRTIMER0, SHRTIMER_MASTER_TIMER);
shrtimer_timers_update_event_disable
Example:
shrtimer_timers_update_event_disable(SHRTIMER0, SHRTIMER_MASTER_TIMER);
shrtimer_software_update
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:
shrtimer_software_counter_reset
339
GD32E50x Firmware Library User Guide
Example:
void shrtimer_software_counter_reset(SHRTIMER0,
SHRTIMER_COUNTER_RESET_SW_MT);
shrtimer_timerinit_struct_para_init
Example:
shrtimer_timerinit_parameter_struct timerinit_para;
shrtimer_timerinit_struct_para_init(&timerinit_para);
shrtimer_timers_waveform_init
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:
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
Example:
shrtimer_timercfg_parameter_struct timercfg_para;
shrtimer_timercfg_struct_para_init(timercfg_para);
shrtimer_slavetimer_waveform_config
Example:
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
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
Example:
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
Example:
shrtimer_channel_outputcfg_parameter_struct outcfg_para;
shrtimer_channel_outputcfg_struct_para_init(&outcfg_para);
shrtimer_slavetimer_waveform_channel_config
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:
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
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:
shrtimer_slavetimer_waveform_channel_software_request (SHRTIMER0,
SHRTIMER_SLAVE_TIMER0, SHRTIMER_ST0_CH0,
SHRTIMER_CHANNEL_SOFTWARE_SET);
shrtimer_slavetimer_waveform_channel_output_level_get
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:
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
Example:
uint32_t output_state;
shrtimer_deadtimercfg_struct_para_init
349
GD32E50x Firmware Library User Guide
- -
Example:
shrtimer_deadtimecfg_parameter_struct deadtimecfg_para;
shrtimer_deadtimercfg_struct_para_init(&deadtimecfg_para);
shrtimer_slavetimer_deadtime_config
Example:
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
Example:
shrtimer_carriersignalcfg_parameter_struct carriercfg;
shrtimer_carriersignalcfg_struct_para_init(&carriercfg);
shrtimer_slavetimer_carriersignal_config
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:
shrtimer_carriersignalcfg_parameter_struct carriercfg;
shrtimer_carriersignalcfg_struct_para_init(&carriercfg);
shrtimer_slavetimer_carriersignal_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
&carriercfg);
shrtimer_output_channel_enable
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:
shrtimer_output_channel_disable
Example:
353
GD32E50x Firmware Library User Guide
shrtimer_slavetimer_compare_value_config
Example:
shrtimer_slavetimer_compare_value_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
SHRTIMER_COMPARE0, 3);
shrtimer_slavetimer_compare_value_get
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:
uint32_t cmpvalue;
shrtimer_mastertimer_compare_value_config
Example:
shrtimer_mastertimer_compare_value_get
Example:
uint32_t cmpvalue;
cmpvalue = shrtimer_mastertimer_compare_value_get(SHRTIMER0,
SHRTIMER_COMPARE0)
shrtimer_timers_counter_value_config
Example:
shrtimer_timers_counter_value_get
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:
uint32_t value;
shrtimer_timers_autoreload_value_config
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
Example:
uint32_t value;
value = shrtimer_timers_autoreload_value_get(SHRTIMER0,
SHRTIMER_MASTER_TIMER);
shrtimer_timers_repetition_value_config
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:
shrtimer_timers_repetition_value_get
360
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
uint32_t the counter value
Example:
uint32_t value;
shrtimer_exevfilter_struct_para_init
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
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:
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
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:
shrtimer_exeventcfg_parameter_struct exevcfg;
shrtimer_exeventcfg_struct_para_init(&exevcfg);
shrtimer_exevent_config
Example:
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_prescaler
Example:
364
GD32E50x Firmware Library User Guide
shrtimer_exevent_prescaler(SHRTIMER0, SHRTIMER_EXEV_PRESCALER_DIV1);
shrtimer_synccfg_struct_para_init
Example:
shrtimer_synccfg_parameter_struct synccfg;
shrtimer_synccfg_struct_para_init (&synccfg);
shrtimer_synchronization_config
Example:
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
Example:
shrtimer_faultcfg_parameter_struct faultcfg;
shrtimer_synccfg_struct_para_init (&faultcfg);
shrtimer_fault_config
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:
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_prescaler_config
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:
void shrtimer_fault_prescaler_config(SHRTIMER0,
SHRTIMER_FAULT_PRESCALER_DIV1);
shrtimer_fault_input_enable
Example:
368
GD32E50x Firmware Library User Guide
/* fault input enable */
shrtimer_fault_input_enable(SHRTIMER0, SHRTIMER_FAULT_0);
shrtimer_fault_input_disable
Example:
shrtimer_fault_input_disable(SHRTIMER0, SHRTIMER_FAULT_0);
shrtimer_timers_dma_enable
Example:
shrtimer_timers_dma_enable(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_DMA_CMP0);
shrtimer_timers_dma_disable
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:
shrtimer_timers_dma_disable(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_DMA_CMP0);
371
GD32E50x Firmware Library User Guide
shrtimer_dmamode_config
Example:
shrtimer_dmamode_config(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_DMAMODE_NONE);
shrtimer_bunchmode_struct_para_init
Example:
shrtimer_bunchmode_struct_para_init(&bmcfg);
shrtimer_bunchmode_config
Example:
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
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:
shrtimer_bunchmode_enable(SHRTIMER0);
shrtimer_bunchmode_disable
Example:
shrtimer_bunchmode_disable(SHRTIMER0);
shrtimer_bunchmode_flag_get
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:
uint32_t flag;
flag = shrtimer_bunchmode_flag_get(SHRTIMER0);
shrtimer_bunchmode_software_start
Example:
shrtimer_bunchmode_software_start(SHRTIMER0);
376
GD32E50x Firmware Library User Guide
shrtimer_slavetimer_capture_config
Example:
shrtimer_slavetimer_capture_config(SHRTIMER0, SHRTIMER_SLAVE_TIMER0,
SHRTIMER_CAPTURE_0, SHRTIMER_CAPTURETRIGGER_NONE);
shrtimer_slavetimer_capture_software
Example:
shrtimer_slavetimer_capture_software(SHRTIMER0, SHRTIMER_SLAVE
SHRTIMER_CAPTURE_0);
378
GD32E50x Firmware Library User Guide
shrtimer_slavetimer_capture_value_read
Example:
uint32_t capture_value;
shrtimer_adctrigcfg_struct_para_init
Example:
shrtimer_adctrigcfg_parameter_struct triggercfg;
shrtimer_adctrigcfg_struct_para_init(&triggercfg);
shrtimer_adc_trigger_config
Example:
380
GD32E50x Firmware Library User Guide
shrtimer_adctrigcfg_parameter_struct triggercfg;
shrtimer_adctrigcfg_struct_para_init(&triggercfg);
triggercfg.update_source = SHRTIMER_ADCTRGI_UPDATE_MT;
shrtimer_timers_flag_get
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:
shrtimer_timers_flag_clear
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:
shrtimer_timers_flag_clear(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_FLAG_CMP0);
shrtimer_common_flag_get
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:
shrtimer_common_flag_clear
Example:
shrtimer_common_flag_clear(SHRTIMER0, SHRTIMER_FLAG_FLT0);
shrtimer_timers_interrupt_enable
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:
shrtimer_timers_interrupt_enable(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_INT_CMP0);
shrtimer_timers_interrupt_disable
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:
shrtimer_timers_interrupt_disable(SHRTIMER0, SHRTIMER_MASTER_TIMER,
SHRTIMER_MT_ST_INT_CMP0);
shrtimer_timers_interrupt_flag_get
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:
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:
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
Example:
shrtimer_common_interrupt_enable(SHRTIMER0, SHRTIMER_INT_FLT0);
shrtimer_common_interrupt_disable
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:
shrtimer_common_interrupt_disable(SHRTIMER0, SHRTIMER_INT_FLT0);
shrtimer_common_interrupt_flag_get
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:
shrtimer_common_interrupt_flag_clear
392
GD32E50x Firmware Library User Guide
- -
Example:
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.
393
GD32E50x Firmware Library User Guide
Registers Descriptions
I2C2_TDATA Transmit data register
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
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
Enum i2c_interrupt_flag_enum
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
i2c_deinit
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
Example:
/* enable I2C0 */
i2c_enable (I2C0);
i2c_disable
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
Example:
i2c_start_on_bus (I2C0);
i2c_stop_on_bus
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:
i2c_stop_on_bus (I2C0);
i2c_slave_response_to_gcall_enable
Example:
i2c_slave_response_to_gcall_enable (I2C0);
i2c_slave_response_to_gcall_disable
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:
i2c_slave_response_to_gcall_disable (I2C0);
i2c_stretch_scl_low_enable
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
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
Example:
403
GD32E50x Firmware Library User Guide
i2c_data_receive
Example:
uint32_t i2c_receiver;
i2c_receiver = i2c_data_receive(I2C0);
i2c_pec_transfer
Example:
404
GD32E50x Firmware Library User Guide
i2c_pec_transfer (I2C0);
i2c_pec_enable
Example:
i2c_pec_enable (I2C0);
i2c_pec_disable
Example:
405
GD32E50x Firmware Library User Guide
i2c_pec_disable (I2C0);
i2c_pec_value_get
Example:
uint32_t pec_value;
i2c_clock_config
Precondition -
I2Cx (x=0,1)
Input parameter{in}
406
GD32E50x Firmware Library User Guide
clkspeed i2c clock speed
Input parameter{in}
I2C_DTCY_2 T_low/T_high=2
I2C_DTCY_16_9 T_low/T_high=16/9
Output parameter{out}
- -
Return value
- -
Example:
i2c_mode_addr_config
407
GD32E50x Firmware Library User Guide
Input parameter{in}
addr I2C address
Output parameter{out}
- -
Return value
- -
Example:
i2c_smbus_type_config
Example:
i2c_ack_config
Example:
i2c_ackpos_config
Example:
409
GD32E50x Firmware Library User Guide
/* The ACK of I2C0 is send for the current frame*/
i2c_master_addressing
Example:
i2c_dualaddr_enable
Example:
i2c_dualaddr_disable
Example:
i2c_dualaddr_disable (I2C0);
i2c_dma_enable
Example:
i2c_dma_last_transfer_config
Example:
412
GD32E50x Firmware Library User Guide
i2c_software_reset_config
Example:
i2c_smbus_issue_alert
413
GD32E50x Firmware Library User Guide
BLE
Output parameter{out}
- -
Return value
- -
Example:
i2c_smbus_arp_enable
Example:
i2c_sam_enable
Example:
i2c_sam_enable (I2C0);
i2c_sam_disable
Example:
i2c_sam_disable (I2C0);
i2c_sam_timeout_enable
Example:
i2c_sam_timeout_enable (I2C0);
i2c_sam_timeout_disable
Example:
i2c_sam_timeout_disable (I2C0);
i2c_start_early_termination_mode_config
Example:
i2c_timeout_calculation_enable
Example:
i2c_timeout_calculation_enable (I2C0);
417
GD32E50x Firmware Library User Guide
i2c_timeout_calculation_disable
Example:
i2c_timeout_calculation_disable (I2C0);
i2c_record_received_slave_address_enable
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
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
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_status_clear_enable
Example:
i2c_status_clear_enable (I2C0);
i2c_status_clear_disable
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:
i2c_status_clear_disable (I2C0);
i2c_status_bit_clear
Example:
421
GD32E50x Firmware Library User Guide
/* clear i2c status register bit */
i2c_flag_get
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:
i2c_flag_clear
Example:
i2c_interrupt_enable
Example:
424
GD32E50x Firmware Library User Guide
i2c_interrupt_disable
Example:
i2c_interrupt_flag_get
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*/
i2c_interrupt_flag_clear
427
GD32E50x Firmware Library User Guide
- -
Return value
- -
Example:
i2c_timing_config
Example:
i2c_digital_noise_filter_config
Example:
i2c_analog_noise_filter_enable
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:
i2c_analog_noise_filter_enable (I2C2);
i2c_analog_noise_filter_disable
Example:
i2c_analog_noise_filter_disable (I2C2);
i2c_wakeup_from_deepsleep_enable
Example:
i2c_wakeup_from_deepsleep_enable (I2C2);
i2c_wakeup_from_deepsleep_disable
Example:
i2c_wakeup_from_deepsleep_disable (I2C2);
i2c_master_clock_config
Example:
i2c2_master_addressing
432
GD32E50x Firmware Library User Guide
- -
Example:
i2c_address10_header_enable
Example:
/* 10-bit address header executes read direction only in master receive mode */
i2c_address10_header_enable (I2C2);
i2c_address10_header_disable
Example:
i2c_address10_header_disable (I2C2);
i2c_address10_enable
Example:
i2c_address10_enable (I2C2);
i2c_address10_disable
Example:
i2c_address10_disable (I2C2);
i2c_automatic_end_enable
Example:
i2c_automatic_end_enable (I2C2);
i2c_automatic_end_disable
Example:
i2c_automatic_end_disable (I2C2);
i2c_address_config
Example:
i2c_address_disable
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:
i2c_address_disable (I2C2);
i2c_second_address_config
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:
i2c_second_address_disable
Example:
i2c_second_address_disable (I2C2);
i2c_recevied_address_get
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:
uint32_t address;
i2c_slave_byte_control_enable
Example:
i2c_slave_byte_control_enable (I2C2);
i2c_slave_byte_control_disable
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:
i2c_slave_byte_control_disable (I2C2);
i2c_nack_enable
Example:
i2c_nack_enable (I2C2);
i2c_nack_disable
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:
i2c_nack_disable (I2C2);
i2c_reload_enable
Example:
i2c_reload_enable (I2C2);
i2c_reload_disable
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:
i2c_reload_disable (I2C2);
i2c_transfer_byte_number_config
Example:
442
GD32E50x Firmware Library User Guide
i2c2_dma_enable
Example:
i2c2_dma_disable
443
GD32E50x Firmware Library User Guide
- -
Return value
- -
Example:
i2c_smbus_alert_enable
Example:
i2c_smbus_alert_enable (I2C2);
i2c_smbus_alert_disable
Example:
i2c_smbus_alert_disable (I2C2);
i2c_smbus_default_addr_enable
Example:
i2c_smbus_default_addr_enable (I2C2);
i2c_smbus_default_addr_disable
Example:
i2c_smbus_default_addr_disable (I2C2);
i2c_smbus_host_addr_enable
Example:
i2c_smbus_host_addr_enable (I2C2);
i2c_smbus_host_addr_disable
Example:
i2c_smbus_host_addr_disable (I2C2);
i2c_extented_clock_timeout_enable
Example:
i2c_extented_clock_timeout_enable (I2C2);
i2c_extented_clock_timeout_disable
Example:
i2c_extented_clock_timeout_disable (I2C2);
i2c_clock_timeout_enable
Example:
i2c_clock_timeout_enable (I2C2);
i2c_clock_timeout_disable
Example:
i2c_clock_timeout_disable (I2C2);
i2c_bus_timeout_b_config
Example:
i2c_bus_timeout_a_config
Example:
i2c_idle_clock_timeout_config
Example:
i2c2_flag_get
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:
i2c2_flag_clear
Example:
i2c2_interrupt_enable
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:
i2c2_interrupt_disable
Example:
453
GD32E50x Firmware Library User Guide
/* disable I2C2 transmit interrupt */
i2c2_interrupt_flag_get
454
GD32E50x Firmware Library User Guide
- -
Return value
FlagStatus SET / RESET
Example:
i2c2_interrupt_flag_clear
455
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -
Example:
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.
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
Enum IRQn_Type
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
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
Example:
460
GD32E50x Firmware Library User Guide
nvic_irq_enable(WWDGT_IRQn, 1, 1);
nvic_irq_disable
Output parameter{out}
- -
Return value
- -
Example:
nvic_system_reset
Example:
461
GD32E50x Firmware Library User Guide
nvic_vector_table_set
Example:
system_lowpower_set
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
Example:
/* the system will exit low power mode by exiting from ISR */
system_lowpower_reset (SCB_LPM_SLEEP_EXIT_ISR);
systick_clksource_set
Example:
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.
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
Example:
/* reset PMU */
pmu_deinit ();
465
GD32E50x Firmware Library User Guide
pmu_lvd_select
Example:
pmu_lvd_select (PMU_LVDT_7);
pmu_lvd_disable
466
GD32E50x Firmware Library User Guide
- -
Example:
pmu_lvd_disable ();
pmu_highdriver_mode_enable
Example:
pmu_highdriver_mode_enable ();
pmu_highdriver_mode_disable
467
GD32E50x Firmware Library User Guide
Example:
pmu_highdriver_mode_disable ();
pmu_highdriver_switch_select
Example:
pmu_highdriver_switch_select (PMU_HIGHDR_SWITCH_EN);
pmu_lowdriver_mode_enable
468
GD32E50x Firmware Library User Guide
Return value
- -
Example:
pmu_lowdriver_mode_enable ();
pmu_lowdriver_mode_disable
Example:
pmu_lowdriver_mode_disable ();
pmu_lowpower_driver_config
Example:
pmu_lowpower_driver_config (PMU_NORMALDR_LOWPWR);
pmu_normalpower_driver_config
Example:
pmu_normalpower_driver_config (PMU_NORMALDR_LOWPWR);
pmu_to_sleepmode
Example:
pmu_to_sleepmode (WFI_CMD);
pmu_to_deepsleepmode
Example:
471
GD32E50x Firmware Library User Guide
pmu_to_deepsleepmode_1
Example:
pmu_to_deepsleepmode_2
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_to_standbymode
Example:
pmu_to_standby (WFI_CMD);
pmu_backup_write_enable
Example:
pmu_backup_write_enable ();
pmu_backup_write_disable
Example:
pmu_backup_write_disable ();
pmu_wakeup_pin_enable
Example:
pmu_wakeup_pin_enable (PMU_WAKEUP_PIN0);
pmu_wakeup_pin_disable
Example:
475
GD32E50x Firmware Library User Guide
/* disable wakeup pin 0 */
pmu_wakeup_pin_disable (PMU_WAKEUP_PIN0);
pmu_flag_get
Example:
FlagStatus status;
pmu_flag_clear
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:
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.
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
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
Enum rcu_periph_reset_enum
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
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
483
GD32E50x Firmware Library User Guide
Enum rcu_int_flag_clear_enum
Enum rcu_int_enum
Enum rcu_osci_type_enum
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
rcu_deinit
Example:
/* reset RCU */
rcu_deinit();
rcu_periph_clock_enable
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:
486
GD32E50x Firmware Library User Guide
rcu_periph_clock_enable(RCU_USART0);
rcu_periph_clock_disable
487
GD32E50x Firmware Library User Guide
Return value
- -
Example:
rcu_periph_clock_disable(RCU_USART0);
rcu_periph_clock_sleep_enable
Example:
rcu_periph_clock_sleep_enable(RCU_FMC_SLP);
rcu_periph_clock_sleep_disable
Example:
rcu_periph_clock_sleep_disable(RCU_FMC_SLP);
rcu_periph_reset_enable
489
GD32E50x Firmware Library User Guide
Return value
- -
Example:
rcu_periph_reset_enable(RCU_SPI0RST);
rcu_periph_reset_disable
490
GD32E50x Firmware Library User Guide
Example:
rcu_periph_reset_disable(RCU_SPI0RST);
rcu_bkp_reset_enable
Example:
rcu_bkp_reset_enable();
rcu_bkp_reset_disable
Example:
491
GD32E50x Firmware Library User Guide
/* disable the BKP domain reset */
rcu_bkp_reset_disable();
rcu_system_clock_source_config
Example:
rcu_system_clock_source_config(RCU_CKSYSSRC_HXTAL);
rcu_system_clock_source_get
Example:
uint32_t temp_cksys_status;
temp_cksys_status = rcu_system_clock_source_get();
rcu_ahb_clock_config
Example:
/* configure CK_SYS/128 */
rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV128);
rcu_apb1_clock_config
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:
rcu_apb1_clock_config(RCU_APB1_CKAHB_DIV16);
rcu_apb2_clock_config
494
GD32E50x Firmware Library User Guide
- -
Example:
rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV8);
rcu_ckout0_config
495
GD32E50x Firmware Library User Guide
- -
Return value
- -
Example:
rcu_ckout0_config(RCU_CKOUT0SRC_HXTAL);
rcu_pll_config
Example:
rcu_pll_config(RCU_PLLSRC_HXTAL, RCU_PLL_MUL10);
rcu_pllpresel_config
Example:
rcu_pllpresel_config (RCU_PLLPRESRC_HXTAL);
rcu_predv0_config(HD、XD series)
Example:
rcu_predv0_config(RCU_PREDV0_DIV1);
rcu_predv0_config(CL series)
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:
rcu_predv0_config(RCU_PREDV0SRC_HXTAL_IRC48M, RCU_PREDV0_DIV4);
rcu_predv1_config(CL series)
Example:
498
GD32E50x Firmware Library User Guide
/* configure the PREDV1 division factor */
rcu_predv1_config(RCU_PREDV1_DIV8);
rcu_pll1_config(CL series)
Example:
rcu_pll1_config(RCU_PLL1_MUL8);
rcu_pll2_config(CL series)
Example:
499
GD32E50x Firmware Library User Guide
/* configure the PLL2 clock */
rcu_pll2_config(RCU_PLL2_MUL8);
rcu_pllusbpresel_config(CL series)
Example:
rcu_pllusbpresel_config(RCU_PLLUSBPRESRC_HXTAL);
Example:
rcu_pllusbpredv_config(RCU_PLLUSBPREDVSRC_HXTAL_IRC48M, RCU_PLLUSBPREDV_DIV15) ;
Example:
rcu_pllusb_config(RCU_PLLUSB_MUL16);
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:
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV8);
rcu_usb_clock_config
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:
rcu_usb_clock_config(RCU_CKUSB_CKPLL_DIV2_5);
rcu_rtc_clock_config
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:
rcu_rtc_clock_config(RCU_RTCSRC_IRC40K);
rcu_shrtimer_clock_config
Example:
rcu_shrtimer_clock_config (RCU_SHRTIMERSRC_CKAPB2);
rcu_usart5_clock_config
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:
rcu_usart5_clock_config(RCU_USART5SRC_CKAPB2);
rcu_i2c2_clock_config
505
GD32E50x Firmware Library User Guide
- -
Example:
rcu_i2c2_clock_config(RCU_I2C2SRC_CKAPB1);
rcu_i2s1_clock_config(CL series)
Example:
rcu_i2s1_clock_config(RCU_I2S1SRC_CKPLL2_MUL2);
rcu_i2s2_clock_config(CL series)
Example:
rcu_i2s2_clock_config(RCU_I2S2SRC_CKPLL2_MUL2);
rcu_ck48m_clock_config
Example:
rcu_ck48m_clock_config (RCU_CK48MSRC_IRC48M);
507
GD32E50x Firmware Library User Guide
rcu_usbhssel_config (CL series)
Example:
rcu_usbhssel_config(RCU_USBHSSRC_48M);
Example:
508
GD32E50x Firmware Library User Guide
/* configure the USBHSDV division factor */
rcu_usbdv_config(RCU_USBHSDV_DIV16);
rcu_flag_get
if(RESET != rcu_flag_get(RCU_FLAG_LXTALSTB)){
rcu_all_reset_flag_clear
Example:
rcu_all_reset_flag_clear();
rcu_interrupt_flag_get
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:
if(SET == rcu_interrupt_flag_get(RCU_INT_FLAG_HXTALSTB)){
rcu_interrupt_flag_clear
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:
rcu_interrupt_flag_clear(RCU_INT_FLAG_HXTALSTB_CLR);
rcu_interrupt_enable
512
GD32E50x Firmware Library User Guide
RCU_INT_IRC48MSTB IRC48M stabilization interrupt enable
Output parameter{out}
- -
Return value
- -
Example:
rcu_interrupt_enable(RCU_INT_HXTALSTB);
rcu_interrupt_disable
Example:
rcu_interrupt_disable(RCU_INT_HXTALSTB);
rcu_lxtal_drive_capability_config
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:
rcu_lxtal_drive_capability_config (RCU_LXTAL_LOWDRI);
rcu_osci_stab_wait
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:
if(SUCCESS == rcu_osci_stab_wait(RCU_HXTAL)){
rcu_osci_on
Example:
rcu_osci_on(RCU_HXTAL);
515
GD32E50x Firmware Library User Guide
rcu_osci_off
Example:
rcu_osci_off(RCU_HXTAL);
rcu_osci_bypass_mode_enable
516
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -
Example:
rcu_osci_bypass_mode_enable(RCU_HXTAL);
rcu_osci_bypass_mode_disable
Example:
rcu_osci_bypass_mode_disable(RCU_HXTAL);
rcu_hxtal_clock_monitor_enable
Example:
rcu_hxtal_clock_monitor_enable();
rcu_hxtal_clock_monitor_disable
Example:
rcu_hxtal_clock_monitor_disable();
rcu_irc8m_adjust_value_set
Example:
rcu_irc8m_adjust_value_set(0x10);
rcu_deepsleep_voltage_set
Example:
rcu_deepsleep_voltage_set(RCU_DEEPSLEEP_V_1_0);
rcu_clock_freq_get
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;
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.
rtc_configuration_mode_enter
Example:
rtc_configuration_mode_enter( );
rtc_configuration_mode_exit
Example:
rtc_configuration_mode_ exit ( );
rtc_lwoff_wait
Example:
rtc_lwoff_wait( );
rtc_interrupt_enable(RTC_INT_SECOND);
522
GD32E50x Firmware Library User Guide
rtc_register_sync_wait
Example:
rtc_register_sync_wait( );
rtc_counter_get
Example:
uint32_t rtc_counter_value;
rtc_counter_value = rtc_counter_get ( );
523
GD32E50x Firmware Library User Guide
rtc_counter_set
Example:
rtc_lwoff_wait( );
rtc_counter_set (0xFFFF);
rtc_prescaler_set
Example:
524
GD32E50x Firmware Library User Guide
rtc_lwoff_wait( );
rtc_prescaler_set (0x7FFFF);
rtc_alarm_config
Example:
rtc_lwoff_wait( );
rtc_alarm_config (0xFFFF);
rtc_divider_get
525
GD32E50x Firmware Library User Guide
Return value
uint32_t the value of RTC divider
Example:
uint32_t rtc_divider_value;
rtc_divider_value = rtc_divider_get ( );
rtc_interrupt_enable
Example:
rtc_lwoff_wait( );
rtc_interrupt_enable(RTC_INT_SECOND);
rtc_interrupt_disable
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:
rtc_lwoff_wait( );
rtc_interrupt_disable(RTC_INT_SECOND);
rtc_flag_get
527
GD32E50x Firmware Library User Guide
Example:
FlagStatus alarm_status;
rtc_flag_clear
Example:
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.
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
Example:
sdio_deinit();
sdio_clock_config
531
GD32E50x Firmware Library User Guide
clock_division clock division, less than 512
Output parameter{out}
- -
Return value
- -
Example:
sdio_clock_config(SDIO_SDIOCLKEDGE_RISING, SDIO_CLOCKBYPASS_DISABLE,
SDIO_CLOCKPWRSAVE_DISABLE, SD_CLK_DIV_TRANS);
sdio_hardware_clock_enable
Example:
sdio_hardware_clock_enable();
sdio_hardware_clock_disable
Example:
sdio_hardware_clock_disable();
sdio_bus_mode_set
Example:
sdio_bus_mode_set(SDIO_BUSMODE_1BIT);
sdio_power_state_set
Example:
sdio_power_state_set(SDIO_POWER_ON);
sdio_power_state_get
Example:
uint32_t sdio_power_value;
sdio_power_value = sdio_power_state_get();
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:
sdio_clock_enable();
sdio_clock_disable
Example:
sdio_clock_disable();
sdio_command_response_config
Example:
sdio_command_response_config(SD_CMD_ALL_SEND_CID, (uint32_t)0x0,
SDIO_RESPONSETYPE_LONG);
sdio_wait_type_set
536
GD32E50x Firmware Library User Guide
- -
Return value
- -
Example:
sdio_wait_type_set(SDIO_WAITTYPE_NO);
sdio_csm_enable
Example:
sdio_csm_enable();
sdio_csm_disable
Example:
sdio_csm_disable();
sdio_command_index_get
Example:
uint8_t sdio_commond_value;
sdio_commond_value = sdio_command_index_get();
sdio_response_get
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:
uint32_t sdio_cid[0];
sdio_cid[0] = sdio_response_get(SDIO_RESPONSE0);
sdio_data_config
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:
sdio_data_config(0, 0, SDIO_DATABLOCKSIZE_1BYTE);
sdio_data_transfer_config
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:
sdio_data_transfer_config(SDIO_TRANSDIRECTION_TOSDIO,
SDIO_TRANSMODE_BLOCK);
sdio_dsm_enable
Example:
sdio_dsm_enable();
sdio_dsm_disable
Example:
sdio_dsm_disable();
sdio_data_write
Example:
sdio_data_write(0x0000 0001);
sdio_data_read
Example:
sdio_data_read();
sdio_data_counter_get
Example:
uint32_t sdio_data_value;
sdio_data_value = sdio_data_counter_get();
sdio_fifo_counter_get
543
GD32E50x Firmware Library User Guide
- -
Output parameter{out}
- -
Return value
uint32_t remaining number of words
Example:
uint32_t sdio_fifo_value;
sdio_fifo_value = sdio_fifo_counter_get();
sdio_dma_enable
Example:
sdio_dma_enable();
sdio_dma_disable
544
GD32E50x Firmware Library User Guide
- -
Output parameter{out}
- -
Return value
- -
Example:
sdio_dma_disable();
sdio_flag_get
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:
FlagStatus flag_value;
flag_value = sdio_flag_get(SDIO_FLAG_RFH);
sdio_flag_clear
Example:
sdio_flag_clear(SDIO_FLAG_DTCRCERR);
sdio_interrupt_enable
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:
sdio_interrupt_disable
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:
sdio_interrupt_disable(SDIO_INT_DTCRCERR);
sdio_interrupt_flag_get
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:
FlagStatus flag_value;
flag_value = sdio_interrupt_flag_get(SDIO_INT_FLAG_DTEND);
sdio_interrupt_flag_clear
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:
sdio_interrupt_flag_clear(SDIO_INT_FLAG_DTEND);
sdio_readwait_enable
Example:
sdio_readwait_enable();
sdio_readwait_disable
Example:
sdio_readwait_disable();
sdio_stop_readwait_enable
Example:
/* enable the function that stop the read wait process(SD I/O only) */
sdio_stop_readwait_enable();
sdio_stop_readwait_disable
Example:
/* disable the function that stop the read wait process(SD I/O only) */
sdio_stop_readwait_disable();
sdio_readwait_type_set
Example:
sdio_readwait_type_set(uint32_t readwait_type);
sdio_operation_enable
Example:
sdio_operation_enable();
sdio_operation_disable
Example:
void sdio_operation_disable();
sdio_suspend_enable
Example:
sdio_suspend_enable();
sdio_suspend_disable
Example:
sdio_suspend_disable();
sdio_ceata_command_enable
sdio_ceata_command_enable();
sdio_ceata_command_disable
Example:
sdio_ceata_command_disable();
sdio_ceata_interrupt_enable
Example:
557
GD32E50x Firmware Library User Guide
/* enable the CE-ATA interrupt(CE-ATA only) */
sdio_ceata_interrupt_enable();
sdio_ceata_interrupt_disable
Example:
sdio_ceata_interrupt_disable();
sdio_ceata_command_completion_enable
Example:
558
GD32E50x Firmware Library User Guide
sdio_ceata_command_completion_enable();
sdio_ceata_command_completion_disable
Example:
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.
559
GD32E50x Firmware Library User Guide
Registers Descriptions
SPI_I2SPSC SPI/I2S clock prescaler register
SPI_QCTL Quad-SPI mode control register
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
spi_i2s_deinit
561
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -
Example:
/* reset SPI0 */
spi_i2s_deinit(SPI0);
spi_struct_para_init
Example:
spi_parameter_struct spi_init_struct;
spi_struct_para_init(&spi_init_struct);
spi_init
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
Example:
563
GD32E50x Firmware Library User Guide
/* enable SPI0 */
spi_enable(SPI0);
spi_disable
Example:
/* disable SPI0 */
spi_disable(SPI0);
i2s_init
Example:
/* initialize I2S1 */
i2s_psc_config
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:
i2s_enable
Example:
/* enable I2S1*/
i2s_enable(SPI1);
i2s_disable
Example:
/* disable I2S1*/
i2s_disable(SPI1);
spi_nss_output_enable
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:
spi_nss_output_enable(SPI0);
spi_nss_output_disable
Example:
spi_nss_output_disable(SPI0);
spi_nss_internal_high
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:
spi_nss_internal_high(SPI0);
spi_nss_internal_low
Example:
spi_nss_internal_low(SPI0);
spi_dma_enable
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:
spi_dma_enable(SPI0, SPI_DMA_TRANSMIT);
spi_dma_disable
570
GD32E50x Firmware Library User Guide
Example:
spi_dma_disable(SPI0, SPI_DMA_TRANSMIT);
spi_i2s_data_frame_format_config
Example:
spi_i2s_data_frame_format_config(SPI1, SPI_FRAMESIZE_16BIT);
spi_i2s_data_transmit
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:
spi_i2s_data_transmit(SPI0, spi0_send_array[0]);
spi_i2s_data_receive
Example:
uint16_t spi0_receive_data;
spi0_receive_data = spi_i2s_data_receive(SPI0);
spi_bidirectional_transfer_config
Example:
spi_bidirectional_transfer_config(SPI0, SPI_BIDIRECTIONAL_TRANSMIT);
spi_crc_polynomial_set
Example:
573
GD32E50x Firmware Library User Guide
/* set SPI0 CRC polynomial */
spi_crc_polynomial_set(SPI0,CRC_VALUE);
spi_crc_polynomial_get
Example:
uint16_t crc_val;
crc_val = spi_crc_polynomial_get(SPI0);
spi_crc_on
574
GD32E50x Firmware Library User Guide
Example:
spi_crc_on(SPI0);
spi_crc_off
Example:
spi_crc_off(SPI0);
spi_crc_next
575
GD32E50x Firmware Library User Guide
Example:
spi_crc_next(SPI0);
spi_crc_get
Example:
uint16_t crc_val;
spi_ti_mode_enable
Example:
spi_ti_mode_enable(SPI0);
spi_ti_mode_disable
Example:
spi_ti_mode_disable(SPI0);
spi_nssp_mode_enable
Example:
spi_nssp_mode_enable(SPI0);
spi_nssp_mode_disable
Example:
spi_nssp_mode_disable(SPI0);
i2s_full_duplex_mode_config
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
Example:
qspi_enable(SPI0);
qspi_disable
Example:
qspi_disable(SPI0);
580
GD32E50x Firmware Library User Guide
qspi_write_enable
Example:
qspi_write_enable(SPI0);
qspi_read_enable
Example:
qspi_read_enable(SPI0);
581
GD32E50x Firmware Library User Guide
qspi_io23_output_enable
Example:
qspi_io23_output_enable(SPI0);
qspi_io23_output_disable
Example:
qspi_io23_output_disable(SPI0);
582
GD32E50x Firmware Library User Guide
spi_i2s_interrupt_enable
Example:
spi_i2s_interrupt_enable(SPI0, SPI_I2S_INT_TBE);
spi_i2s_interrupt_disable
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:
spi_i2s_interrupt_disable(SPI0, SPI_I2S_INT_TBE);
spi_i2s_interrupt_flag_get
584
GD32E50x Firmware Library User Guide
Return value
FlagStatus SET or RESET
Example:
spi_i2s_data_transmit(SPI0, spi0_send_array[send_n++]);
spi_i2s_flag_get
Example:
spi_i2s_data_transmit(SPI0, spi0_send_array[send_n++]);
spi_crc_error_clear
Example:
spi_crc_error_clear(SPI0);
3.24. SQPI
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
Structure sqpi_parameter_struct
sqpi_deinit
Example:
/* reset SQPI */
sqpi_deinit();
sqpi_struct_para_init
Example:
sqpi_parameter_struct sqpi_init_struct;
sqpi_struct_para_init(&sqpi_init_struct);
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
Example:
589
GD32E50x Firmware Library User Guide
/* send SQPI read ID command */
sqpi_read_id_command ();
sqpi_special_command
Example:
sqpi_special_command ();
sqpi_read_command_config
Example:
sqpi_read_command_config(QSPI_MODE_SSS,0x00,0x9f);
sqpi_write_command_config
Example:
sqpi_write_command_config(QSPI_MODE_SSS,0x00,0x9f);
591
GD32E50x Firmware Library User Guide
sqpi_low_id_receive
Example:
uint32_t val;
sqpi_high_id_receive
Example:
uint32_t val;
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.
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
Structure timer_break_parameter_struct
596
GD32E50x Firmware Library User Guide
Structure timer_oc_parameter_struct
Structure timer_ic_parameter_struct
timer_deinit
597
GD32E50x Firmware Library User Guide
- -
Example:
/* reset TIMER0 */
timer_deinit(TIMER0);
timer_struct_para_init
Example:
timer_parameter_struct timer_initpara;
timer_struct_para_init(&timer_initpara);
timer_init
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
Example:
/* enable TIMER0 */
timer_enable(TIMER0);
599
GD32E50x Firmware Library User Guide
timer_disable
Example:
/* disable TIMER0 */
timer_disable(TIMER0);
timer_auto_reload_shadow_enable
Example:
timer_auto_reload_shadow_enable(TIMER0);
600
GD32E50x Firmware Library User Guide
timer_auto_reload_shadow_disable
Example:
timer_auto_reload_shadow_disable(TIMER0);
timer_update_event_enable
Example:
timer_update_event_enable (TIMER0);
601
GD32E50x Firmware Library User Guide
timer_update_event_disable
Example:
timer_update_event_disable (TIMER0);
timer_counter_alignment
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:
timer_counter_alignment(TIMER0, TIMER_COUNTER_CENTER_UP);
timer_counter_up_direction
Example:
timer_counter_up_direction(TIMER0);
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:
timer_counter_down_direction(TIMER0);
timer_prescaler_config
Example:
604
GD32E50x Firmware Library User Guide
/* configure TIMER0 prescaler */
timer_repetition_value_config
Example:
timer_repetition_value_config(TIMER0, 98);
timer_autoreload_value_config
Example:
timer_autoreload_value_config(TIMER0, 3000);
timer_counter_value_config
Example:
timer_counter_value_config(TIMER0);
timer_counter_read
Example:
uint32_t i = 0;
i = timer_counter_read(TIMER0);
timer_prescaler_read
Example:
uint16_t i = 0;
i = timer_prescaler_read(TIMER0);
timer_single_pulse_mode_config
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:
timer_single_pulse_mode_config(TIMER0, TIMER_SP_MODE_SINGLE);
timer_update_source_config
Example:
timer_update_source_config(TIMER0, TIMER_UPDATE_SRC_REGULAR);
timer_dma_enable
Example:
timer_dma_enable(TIMER0, TIMER_DMA_UPD);
609
GD32E50x Firmware Library User Guide
timer_dma_disable
Example:
timer_dma_disable(TIMER0, TIMER_DMA_UPD);
timer_channel_dma_request_source_select
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
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:
timer_dma_transfer_config(TIMER0, TIMER_DMACFG_DMATA_CTL0,
TIMER_DMACFG_DMATC_5TRANSFER);
612
GD32E50x Firmware Library User Guide
timer_event_software_generate
Example:
timer_event_software_generate(TIMER0, TIMER_EVENT_SRC_UPG);
timer_break_struct_para_init
Example:
timer_break_parameter_struct timer_breakpara;
timer_break_struct_para_init(&timer_breakpara);
timer_break_config
614
GD32E50x Firmware Library User Guide
Example:
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
Example:
timer_break_enable (TIMER0);
timer_break_disable
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:
timer_break_disable(TIMER0);
timer_automatic_output_enable
Example:
timer_automatic_output_enable(TIMER0);
616
GD32E50x Firmware Library User Guide
timer_automatic_output_disable
Example:
timer_automatic_output_disable(TIMER0);
timer_primary_output_config
617
GD32E50x Firmware Library User Guide
- -
Example:
timer_primary_output_config(TIMER0, ENABLE);
timer_channel_control_shadow_config
Example:
timer_channel_control_shadow_config(TIMER0, ENABLE);
timer_channel_control_shadow_update_config
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
Example:
timer_oc_parameter_struct timer_ocinitpara;
timer_channel_output_struct_para_init(&timer_ocinitpara);
619
GD32E50x Firmware Library User Guide
timer_channel_output_config
Example:
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;
620
GD32E50x Firmware Library User Guide
timer_channel_output_mode_config
Example:
621
GD32E50x Firmware Library User Guide
/* configure TIMER0 channel PWM 0 mode */
timer_channel_output_pulse_value_config
Example:
timer_channel_output_shadow_config
Example:
timer_channel_output_fast_config
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:
timer_channel_output_clear_config
624
GD32E50x Firmware Library User Guide
SABLE
Output parameter{out}
- -
Return value
- -
Example:
timer_channel_output_polarity_config
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
Example:
timer_channel_complementary_output_polarity_config(TIMER0, TIMER_CH_0,
TIMER_OCN_POLARITY_HIGH);
timer_channel_output_state_config
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:
timer_channel_complementary_output_state_config
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:
timer_channel_complementary_output_state_config(TIMER0, TIMER_CH_0,
TIMER_CCXN_ENABLE);
timer_channel_input_struct_para_init
Example:
timer_ic_parameter_struct timer_icinitpara;
628
GD32E50x Firmware Library User Guide
timer_channel_input_struct_para_init(&timer_icinitpara);
timer_input_capture_config
Example:
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;
629
GD32E50x Firmware Library User Guide
timer_channel_input_capture_prescaler_config
Example:
timer_channel_input_capture_prescaler_config(TIMER0, TIMER_CH_0,
TIMER_IC_PSC_DIV2);
timer_channel_capture_value_register_read
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:
uint32_t ch0_value = 0;
timer_input_pwm_capture_config
Example:
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_hall_mode_config
Example:
Example:
timer_master_output_trigger_source_select
Example:
634
GD32E50x Firmware Library User Guide
timer_slave_mode_select
Example:
timer_master_slave_mode_config
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:
timer_master_slave_mode_config(TIMER0, TIMER_MASTER_SLAVE_MODE_ENABLE);
timer_external_trigger_config
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:
timer_external_trigger_config(TIMER0, TIMER_EXT_TRI_PSC_DIV2,
TIMER_ETP_FALLING, 10);
timer_quadrature_decoder_mode_config
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:
timer_quadrature_decoder_mode_config(TIMER0, TIMER_ENCODER_MODE0,
TIMER_IC_POLARITY_RISING, TIMER_IC_POLARITY_RISING);
timer_internal_clock_config
638
GD32E50x Firmware Library User Guide
- -
Example:
timer_internal_clock_config (TIMER0);
timer_internal_trigger_as_external_clock_config
Example:
timer_internal_trigger_as_external_clock_config(TIMER0, TIMER_SMCFG_TRGSEL_ITI0);
timer_external_trigger_as_external_clock_config
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:
timer_external_trigger_as_external_clock_config(TIMER0,
TIMER_SMCFG_TRGSEL_CI0FE0, TIMER_IC_POLARITY_RISING, 0);
timer_external_clock_mode0_config
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:
timer_external_clock_mode0_config(TIMER0, TIMER_EXT_TRI_PSC_DIV2,
TIMER_ETP_FALLING, 0);
timer_external_clock_mode1_config
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:
timer_external_clock_mode1_config(TIMER0, TIMER_EXT_TRI_PSC_DIV2,
TIMER_ETP_FALLING, 0);
timer_external_clock_mode1_disable
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:
timer_external_clock_mode1_disable(TIMER0);
timer_write_chxval_register_config
Example:
timer_write_chxval_register_config(TIMER0, TIMER_CHVSEL_ENABLE);
643
GD32E50x Firmware Library User Guide
timer_output_value_selection_config
Example:
timer_output_value_selection_config(TIMER0, TIMER_OUTSEL_ENABLE);
timer_flag_get
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:
timer_flag_clear
Example:
timer_flag_clear(TIMER0, TIMER_FLAG_UP);
timer_interrupt_enable
Example:
646
GD32E50x Firmware Library User Guide
/* enable the TIMER0 update interrupt */
timer_interrupt_disable
Example:
timer_interrupt_disable(TIMER0, TIMER_INT_UP);
timer_interrupt_flag_get
Example:
timer_interrupt_flag_clear
Example:
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.
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
Example:
tmu_deinit();
tmu_enable
650
GD32E50x Firmware Library User Guide
The called functions -
Input parameter{in}
- -
Output parameter{out}
- -
Return value
- -
Example:
void tmu_enable(void);
tmu_mode_set
Example:
tmu_mode_set(TMU_MODE0);
651
GD32E50x Firmware Library User Guide
tmu_idata0_write
Example:
tmu_idata0_write (0XBF000000);
tmu_idata1_write
Example:
tmu_idata1_write (0XBF000000);
652
GD32E50x Firmware Library User Guide
tmu_data0_read
Example:
uint32_t tmu_value = 0;
tmu_value = tmu_data0_read();
tmu_data1_read
Example:
653
GD32E50x Firmware Library User Guide
uint32_t tmu_value = 0;
tmu_value = tmu_data1_read();
tmu_interrupt_enable
Example:
void tmu_interrupt_enable();
tmu_interrupt_disable
Example:
654
GD32E50x Firmware Library User Guide
void tmu_interrupt_disable();
tmu_flag_get
Example:
tmu_flag_get(TMU_FLAG_OVRF);
tmu_interrupt_flag_get
Example:
655
GD32E50x Firmware Library User Guide
/* check teh TMU interrupt flag */
tmu_interrupt_flag_getTMU_INT_FLAG_CFIF);
3.27. USART
656
GD32E50x Firmware Library User Guide
3.27.2. Descriptions of Peripheral functions
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
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
Enum usart_interrupt_flag_enum
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
661
GD32E50x Firmware Library User Guide
Enum usart_interrupt_enum
Enum usart5_interrupt_enum
Enum usart_invert_enum
usart_deinit
Example:
/* reset USART0 */
usart_deinit (USART0);
usart_baudrate_set
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:
usart_baudrate_set(USART0, 115200);
usart_parity_config
Example:
664
GD32E50x Firmware Library User Guide
usart_parity_config(USART0, USART_PM_EVEN);
usart_word_length_set
Example:
usart_word_length_set(USART0, USART_WL_9BIT);
usart_stop_bit_set
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:
usart_stop_bit_set(USART0, USART_STB_1_5BIT);
usart_enable
Example:
/* enable USART0 */
usart_enable(USART0);
usart_disable
Example:
/* disable USART0 */
usart_disable(USART0);
usart_transmit_config
Example:
667
GD32E50x Firmware Library User Guide
usart_transmit_config(USART0,USART_TRANSMIT_ENABLE);
usart_receive_config
Example:
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
usart_oversample_config
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:
usart_oversample_config(USART0, USART_OVSMOD_8);
usart_sample_bit_config
Example:
usart_sample_bit_config(USART0, USART_OSB_1bit);
669
GD32E50x Firmware Library User Guide
usart_receiver_timeout_enable
Example:
usart_receiver_timeout_enable(USART0);
usart_receiver_timeout_disable
Example:
usart_receiver_timeout_disable(USART0);
670
GD32E50x Firmware Library User Guide
usart_receiver_timeout_threshold_config
Example:
usart_receiver_timeout_threshold_config(USART0, 115200*3);
usart_data_transmit
671
GD32E50x Firmware Library User Guide
Return value
- -
Example:
usart_data_transmit(USART0, 0xAA);
usart_data_receive
Example:
uint16_t temp;
temp = usart_data_receive(USART0);
usart_mute_mode_enable
672
GD32E50x Firmware Library User Guide
USARTx x=0,1,2,5
UARTx x=3,4
Output parameter{out}
- -
Return value
- -
Example:
usart_mute_mode_enable(USART0);
usart_mute_mode_disable
Example:
usart_mute_mode_disable(USART0);
usart_mute_mode_wakeup_config
Example:
usart_mute_mode_wakeup_config(USART0, USART_WM_IDLE);
usart_lin_mode_enable
Example:
usart_lin_mode_enable(USART0);
674
GD32E50x Firmware Library User Guide
usart_lin_mode_disable
Example:
usart_lin_mode_disable(USART0);
usart_lin_break_dection_length_config
675
GD32E50x Firmware Library User Guide
Return value
- -
Example:
usart_lin_break_dection_length_config(USART0, USART_LBLEN_10B);
usart_halfduplex_enable
Example:
usart_halfduplex_enable(USART0);
usart_halfduplex_disable
Example:
usart_halfduplex_disable(USART0);
usart_synchronous_clock_enable
Example:
usart_synchronous_clock_enable(USART0);
usart_synchronous_clock_disable
Example:
usart_synchronous_clock_disable(USART0);
usart_synchronous_clock_config
Example:
usart_synchronous_clock_config(USART0,USART_CLEN_EN,USART_CPH_2CK,
678
GD32E50x Firmware Library User Guide
USART_CPL_HIGH);
usart_guard_time_config
Example:
usart_smartcard_mode_enable
Example:
679
GD32E50x Firmware Library User Guide
/* USART0 smartcard mode enable */
usart_smartcard_mode_enable(USART0);
usart_smartcard_mode_disable
Example:
usart_smartcard_mode_disable(USART0);
usart_smartcard_mode_nack_enable
Example:
680
GD32E50x Firmware Library User Guide
/* enable USART0 NACK in smartcard mode */
usart_smartcard_mode_nack_enable(USART0);
usart_smartcard_mode_nack_disable
Example:
usart_smartcard_mode_nack_disable(USART0);
usart_smartcard_autoretry_config
Example:
usart_block_length_config
Example:
usart_block_length_config(USART0, 0x000000FF);
usart_irda_mode_enable
Example:
usart_irda_mode_enable(USART0);
usart_irda_mode_disable
Example:
usart_irda_mode_disable(USART0);
usart_prescaler_config
Example:
usart_prescaler_config(USART0, 0x00000000);
usart_irda_lowpower_config
Example:
usart_irda_lowpower_config(USART0, USART_IRLP_LOW);
684
GD32E50x Firmware Library User Guide
usart_hardware_flow_rts_config
Example:
usart_hardware_flow_cts_config(USART0, USART_RTS_ENABLE);
usart_hardware_flow_cts_config
685
GD32E50x Firmware Library User Guide
USART_CTS_ENABLE enable CTS
USART_CTS_DISABL
disable CTS
E
Output parameter{out}
- -
Return value
- -
Example:
usart_hardware_flow_cts_config(USART0, USART_CTS_ENABLE);
usart_dma_receive_config
Example:
usart_dma_receive_config(USART0, USART_DENR_ENABLE);
686
GD32E50x Firmware Library User Guide
usart_dma_transmit_config
Example:
usart_dma_transmit_config(USART0, USART_DENT_ENABLE);
usart_data_first_config
687
GD32E50x Firmware Library User Guide
USART_MSBF_LSB LSB first
USART_MSBF_MSB MSB first
Output parameter{out}
- -
Return value
- -
Example:
usart_data_first_config(USART0, USART_MSBF_LSB);
usart_invert_config
688
GD32E50x Firmware Library User Guide
Example:
usart_invert_config(USART0, USART_DINV_ENABLE);
usart_address_config
Example:
usart_address_config(USART0, 0x00000000);
usart_send_break
689
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -
Example:
usart_send_break(USART0);
usart_flag_get
690
GD32E50x Firmware Library User Guide
FlagStatus SET or RESET
Example:
FlagStatus status;
usart_flag_clear
Example:
usart_flag_clear(USART0, USART_FLAG_TC);
usart_interrupt_enable
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:
usart_interrupt_enable(USART0, USART_INT_TBE);
usart_interrupt_disable
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:
usart_interrupt_disable(USART0, USART_INT_TBE);
usart_interrupt_flag_get
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:
FlagStatus status;
usart_interrupt_flag_clear
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:
usart_interrupt_flag_clear(USART0, USART_INT_FLAG_RBNE);
usart5_data_first_config
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:
usart5_data_first_config(USART5, USART5_MSBF_LSB);
usart5_invert_config
696
GD32E50x Firmware Library User Guide
USART5_SWAP_DISA
not swap TX/RX pins
BLE
Output parameter{out}
- -
Return value
- -
Example:
usart5_invert_config(USART5, USART5_DINV_ENABLE);
usart5_overrun_enable
Example:
usart5_overrun_enable(USART5);
usart5_overrun_disable
Example:
usart5_overrun_disable(USART5);
usart5_autobaud_detection_enable
Example:
usart5_autobaud_detection_enable(USART5);
usart5_autobaud_detection_disable
Example:
usart5_autobaud_detection_disable(USART5);
usart5_autobaud_detection_mode_config
Example:
usart5_autobaud_detection_mode_config(USART5, USART5_ABDM_FTOR);
usart5_address_config
Example:
usart5_address_config(USART5, 0x00000000);
usart5_address_detection_mode_config
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
Example:
usart5_smartcard_mode_early_nack_enable(USART5);
usart5_smartcard_mode_early_nack_disable
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
Example:
usart5_hardware_flow_coherence_config(USART5, USART5_HCM_NONE);
usart5_rs485_driver_enable
Example:
usart5_rs485_driver_enable(USART5);
usart5_rs485_driver_disable
Example:
usart5_rs485_driver_disable (USART5);
usart5_driver_assertime_config
Example:
usart5_driver_assertime_config(USART5, 0x0000001F);
usart5_driver_deassertime_config
Example:
usart5_driver_deassertime_config(USART5, 0x0000001F);
usart5_depolarity_config
Example:
usart5_driver_depolarity_config(USART5, USART5_DEP_HIGH);
usart5_reception_error_dma_enable
Example:
usart5_reception_error_dma_enable(USART5);
usart5_reception_error_dma_disable
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:
usart5_reception_error_dma_disable(USART5);
usart5_wakeup_enable
Example:
usart5_wakeup_enable(USART5);
usart5_wakeup_disable
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_wakeup_disable(USART5);
usart5_wakeup_mode_config
Example:
707
GD32E50x Firmware Library User Guide
/* configure USART5 wake up mode */
usart5_wakeup_mode_config(USART5, USART5_WUM_ADDR);
usart5_receive_fifo_enable
Example:
usart5_receive_fifo_enable(USART5);
usart5_receive_fifo_disable
Example:
708
GD32E50x Firmware Library User Guide
/* disable receive FIFO */
usart5_receive_fifo_disable(USART5);
usart5_receive_fifo_counter_number
Example:
uint8_t temp;
temp = usart5_receive_fifo_counter_number(USART5);
usart5_flag_get
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:
FlagStatus status;
usart5_flag_clear
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:
usart5_flag_clear(USART5, USART5_FLAG_TC);
usart5_interrupt_enable
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:
usart5_interrupt_enable(USART5, USART5_INT_TBE);
usart5_interrupt_disable
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:
usart5_interrupt_disable(USART5, USART5_INT_TBE);
usart5_command_enable
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:
usart5_command_enable(USART5, USART5_CMD_ABDCMD);
usart5_interrupt_flag_get
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:
FlagStatus status;
usart5_interrupt_flag_clear
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:
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.
wwdgt_deinit
717
GD32E50x Firmware Library User Guide
- -
Output parameter{out}
- -
Return value
- -
Example:
wwdgt_deinit ( );
wwdgt_enable
Example:
wwdgt_enable ( );
wwdgt_counter_update
718
GD32E50x Firmware Library User Guide
Output parameter{out}
- -
Return value
- -
Example:
wwdgt_counter_update(127);
wwdgt_config
Example:
/* confiure WWDGT counter value to 0x7F, window value to 0x50, prescaler divider value to
8 */
719
GD32E50x Firmware Library User Guide
wwdgt_interrupt_enable
Example:
wwdgt_interrupt_enable ( );
wwdgt_flag_get
Example:
FlagStatus status;
status = wwdgt_flag_get ( );
if(status == RESET)
720
GD32E50x Firmware Library User Guide
{
...
}else
...
wwdgt_flag_clear
Example:
wwdgt_flag_clear( );
3.29. USBD
3.30. USBHS
721
GD32E50x Firmware Library User Guide
4. Revision history
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.
723