GD32A513 User Manual Table of Contents Table of Contents ......................2 List of Figures ......................16 List of Tables ........................ 22 1. System and memory architecture ................ 25 ® ® -M33 processor ..................25 1.1. Cortex System architecture ....................... 26 1.2.
Page 3
GD32A513 User Manual 2.3.7. Mass erase ........................... 57 2.3.8. Main flash programming ....................... 58 2.3.9. Main Flash Fast Programming ....................60 2.3.10. Check blank command ......................63 2.3.11. OTP programming ........................ 63 2.3.12. Shared RAM ......................... 63 2.3.13. Data Flash operation ......................64 2.3.14.
Page 4
GD32A513 User Manual 3.4.1. Control register (PMU_CTL) ....................101 3.4.2. Control and status register (PMU_CS) ................102 4. Backup registers (BKP) ..................105 4.1. Overview ........................105 4.2. Characteristics ......................105 4.3. Function overview......................105 4.3.1. RTC clock calibration ......................105 4.3.2.
Page 5
GD32A513 User Manual 6.2. Characteristics ......................146 6.3. Interrupts function overview ..................146 6.4. External interrupt and event (EXTI) block diagram..........150 6.5. External Interrupt and Event function overview ............150 Register definition......................153 6.6. 6.6.1. Interrupt enable register (EXTI_INTEN) ................153 6.6.2.
® -M33 processor ............26 Figure 1-1. The structure of the Cortex Figure 1-2. Series system architecture of GD32A513 series ..........28 Figure 1-3. ECC decoder ......................33 Figure 2-1. Process of page erase operation ................57 Figure 2-2. Process of mass erase operation ................58 Figure 2-3.
Page 17
GD32A513 User Manual Figure 14-9. Data storage mode of 8-bit resolution ............... 274 Figure 14-10. Data storage mode of 6-bit resolution ............. 274 Figure 14-11. 20-bit to 16-bit result truncation ............... 277 Figure 14-12. Numerical example with 5-bits shift and rounding ......... 278 Figure 14-13.
Page 18
GD32A513 User Manual Figure 18-26. CHx_O output with a pulse in edge-aligned mode (CHxOMPSEL≠2’b00) ..349 Figure 18-27. CHx_O output with a pulse in center-aligned mode (CHxOMPSEL≠2’b00) . 349 Figure 18-28. Channel output complementary PWM with dead-time insertion....352 Figure 18-29. Break function diagram ..................353 Figure 18-30.
Page 19
GD32A513 User Manual Figure 19-4. Oversampling method of a receive frame bit (OSB=0) ........477 Figure 19-5. Configuration step when using DMA for USART transmission ...... 478 Figure 19-6. Configuration step when using DMA for USART reception ......479 Figure 19-7. Hardware flow control between two USARTs ............ 479 Figure 19-8.
Page 20
GD32A513 User Manual Figure 21-6. A typical simplex connection (Master: Transmit only, Slave: Receive) ..556 Figure 21-7. A typical bidirectional connection ..............556 Figure 21-8. Timing diagram of TI master mode with discontinuous transfer ....558 Figure 21-9. Timing diagram of TI master mode with continuous transfer ......559 Figure 21-10.
Page 21
GD32A513 User Manual CHLEN=1, CKPL=1) ......................572 Figure 21-43. PCM standard long frame synchronization mode timing diagram (DTLEN=00, CHLEN=0, CKPL=0) ......................572 Figure 21-44. PCM standard long frame synchronization mode timing diagram (DTLEN=00, CHLEN=0, CKPL=1) ......................572 Figure 21-45. PCM standard long frame synchronization mode timing diagram (DTLEN=10, CHLEN=1, CKPL=0) ......................
List of Tables Table 1-1. Bus Interconnection Matrix ..................26 Table 1-2. Memory map of GD32A513 devices ................. 29 Table 2-1. Base address and size for 384 KB flash memory ........... 50 Table 2-2. Base address and size for 256 KB flash memory ........... 50 Table 2-3.
Page 23
GD32A513 User Manual Table 14-2. ADC input pins definition ..................268 Table 14-3. External trigger source for routine sequence ............. 275 Table 14-4. t timings depending on resolution ..............276 CONV Table 14-5. Maximum output results for N and M (Grayed values indicates truncation)... 278 Table 14-6.
Page 24
GD32A513 User Manual Table 23-6. Rx FIFO descriptor ....................608 Table 23-7. Mailbox arbitration value(32 bit) when local priority disabled ......617 Table 23-8. Mailbox arbitration value(35 bit) when local priority enabled ......618 Table 23-9. Rx mailbox matching ..................... 624 Table 23-10.
GD32A513 User Manual System and memory architecture The GD32A513 series are 32-bit general-purpose microcontrollers based on the Arm ® Cortex -M33 processor. The Arm Cortex -M33 processor includes two AHB buses known as ® ® ® Code and System buses. All memory accesses of the Arm...
ROM table Debug system Interface interface Note: Although the GD32A513 series has an ITM module, it does not support the output of trace data. 1.2. System architecture A 32-bit multilayer bus is implemented in the GD32A513 devices, which enables parallel access paths between multiple masters and slaves in the system.
Page 27
The two APB buses connect with all the APB peripherals. APB1 is up to 50MHz, APB2 operates at full speed (up to 100MHz depending on the device). These are interconnected using a multilayer AHB bus architecture as shown in Figure 1-2. Series system architecture of GD32A513 series below:...
GD32A513 User Manual Figure 1-2. Series system architecture of GD32A513 series 1.1V TPIU GPIO Ports A, B, C, D,E, CBus AHB2: Fma x = 100MHz POR/PDR ARM Cortex-M33 Processor C/SBus SRAM SRAM : 100MHz Controller SBus Flash CBus Flash Memory...
Table 1-2. Memory map of GD32A513 devices shows the memory map of the GD32A513 devices, including Code, SRAM, peripheral, and other pre-defined regions. Almost each peripheral is allocated 1KB of space. This allows simplifying the address decoding for each peripheral.
On-chip SRAM memory 1.3.1. The GD32A513 series contain up to 48KB of on-chip SRAM which starts at the address 0x2000 0000. It supports byte, half-word (16 bits), and word (32 bits) accesses. When reading and writing SRAM, it supports 7-bit ECC function. It can correct 1 bit error and detect multiple bits (two bits) error.
GD32A513 User Manual Decoder: When performing a SRAM read operation, it uses the same algorithm as the encoder to decode and generate a 7-bit ECC code. The ECC code includes ECC error status and information which specific bit of the 32-bit data has single bit error.
1.4. Boot mode The GD32A513 series only supports booting from the main FLASH. After power-on sequence or a system reset, main flash memory (original memory space beginning at 0x0800 0000) is aliased in the boot memory space which begins at the address 0x0000 0000.The Arm ®...
GD32A513 User Manual 1.6. System configuration registers SYSCFG base address: 0x4001 0000 System configuration register 0 (SYSCFG_CFG0) 1.6.1. Address offset: 0x00 Reset value: 0x0000 0000 This register can be accessed by word(32-bit). Reserved PA9_ Reserved Reserved PA12_ Bits Fields Descriptions...
GD32A513 User Manual ADC0CH9RMP ADC0 channel 9 remapping bit 0: ADC0_IN9 is mapping on PB1. 1: ADC0_IN9 is mapping on PC6. ADC0CH8RMP ADC0 channel 8 remapping bit 0: ADC0_IN8 is mapping on PB2. 1: ADC0_IN8 is mapping on PC7. ADC1CH15RMP ADC1 channel 15 remapping bit 0: ADC1_IN15 is mapping on PB13.
GD32A513 User Manual TIMER0/7/19/20. LOCKUP_LOCK Cortex-M33 LOCKUP output lock This bit is set by software and cleared by a system reset. 0: The Cortex-M33 LOCKUP output is disconnected from the break input of TIMER0/7/19/20. 1: The Cortex-M33 LOCKUP output is connected from the break input of TIMER0/7/19/20.
GD32A513 User Manual 0: no SRAM non-correction error event is detected. 1: SRAM non-correction error event is detected. Note: SRAM multi-bits (two bits) non-correction ECC error will cause a NMI interrupt when the SRAMECCMEIE bit is set. System configuration register 3 (SYSCFG_CFG3) 1.6.9.
GD32A513 User Manual Bits Fields Descriptions 31:16 SRAM_DENSITY SRAM density [15:0] The value indicates the on-chip SRAM density of the device in Kbytes. Example: 0x0008 indicates 8 Kbytes. 15:0 FLASH_DENSITY Flash memory density [15:0] The value indicates the Flash memory density of the device in Kbytes.
GD32A513 User Manual Flash memory controller (FMC) 2.1. Overview The flash memory controller, FMC, provides all the necessary functions for the on-chip flash memory. A little waiting time is needed while CPU executes instructions stored from the 384K bytes of the flash. It also provides page erase, mass erase, and program operations for flash memory.
GD32A513 User Manual erased individually. Table 2-1. Base address and size for 384 KB flash memory shows the base address and size. Table 2-1. Base address and size for 384 KB flash memory Block Name Address size(bytes) Page 0 0x0800 0000 - 0x0800 03FF...
GD32A513 User Manual only once. If any bit has been set 0, the entire double word cannot be written anymore, even with the value 0x0000 0000 0000 0000. Error Checking and Correcting (ECC) 2.3.2. The ECC mechanism supports: One error detection and correction ...
GD32A513 User Manual When an ECC error is reported, a new read at the error address may not generate an ECC error if the data is still present in the current buffer / prefetch buffer / cache, even if ECCCOR and ECCDET are cleared.
GD32A513 User Manual operation. So in the case of sequential code, the next data can get from current buffer without repeat fetch from flash memory. Pre-fetch buffer: The pre-fetch buffer is enabled by setting the PFEN bit in the FMC_WS register. In the case of sequential code, when CPU executes the current buffer data (64-bit), 32-bit needs at least 2 clocks and 16-bit needs at least 4 clocks.
GD32A513 User Manual The unlocking sequence includes two write operations, which are writing 0x45670123 and 0xCDEF89AB to FMC_OBKEY register, then the OBWEN bit in FMC_CTL1 register is set by hardware. The software can clear OBWEN bit to protect the OB0PG bit and OB0ER bit in FMC_CTL1 register again.
GD32A513 User Manual Figure 2-1. Process of page erase operation Start Is the LK bit 0 Unlock the FMC_CTLx Is the BUSY bit 0 Set the FMC_ADDRx, PER bit Send the command to FMC by setting START Is the BUSY bit 0...
GD32A513 User Manual Since all flash data will be reset to a value of 0xFFFF FFFF, the mass erase operation can be implemented using a program that runs in SRAM or by using the debugging tool to access the FMC registers directly. Additionally, the mass erase operation will be ignored if any page is erase / program protected.
Page 59
GD32A513 User Manual Unlock the FMC_CTLx register if necessary. Check the BUSY bit in FMC_STATx register to confirm that no flash memory operation is in progress (BUSY equal to 0). Otherwise, wait until the operation has been finished.
GD32A513 User Manual Figure 2-3. Process of word program operation Start Is the LK bit 0 Unlock the FMC_CTLx Is the BUSY bit 0 Set the PG bit Perform word write by DBUS Is the BUSY bit 0 Finish Note: Reading the flash should be avoided when a program / erase operation is ongoing in the same bank.
GD32A513 User Manual 1. Set Shared RAM to fast program mode by configuring the SRAMCMD bits to "01". 2. Check the row (32 double-word) in flash to confirm all data in flash is all 0xFF. The check blank command can be used to check the page the row in.
Page 62
GD32A513 User Manual Figure 2-4. Process of fast programming operation Start Configure SRAMCMD Check the row is all 0xFF Unlock the Is the LK bit is 0 FMC_CTLx Is the BUSY bit is 0 Set the FSTPG bit Perform 32 double...
GD32A513 User Manual 5. The cache must be flushed before fast programming. Check blank command 2.3.10. The check blank command is used to check if the flash area which is specified by FMC_ADDRx and CBCMDLEN bits in FMC_CTLx register are all 0xFF or not. Configure the...
GD32A513 User Manual SRAMCMD will be cleared. Otherwise, wait until the command has been finished. Note that bank 1 is used in the process and cannot be used for other operations. Fast program SRAM The fast program SRAM command is sent by configuring the SRAMCMD bits as "01". After sending the fast program SRAM command, the Shared RAM initializes to all 1.
GD32A513 User Manual Programming. Emulated EEPROM 2.3.14. The EEPROM SRAM size is configured by EPSIZE. And the EEPROM backup size is configured by EFALC. The larger the ratio of EEPROM backup and EEPROM SRAM makes the better endurance. The emulated EEPROM file system locates all valid EEPROM SRAM data records in EEPROM backup and copies the newest data to Shared RAM.
GD32A513 User Manual Option bytes 0 erase 2.3.15. The FMC provides an erase function which is used to initialize the option bytes 0 block in flash. The following steps show the erase sequence. Unlock the FMC_CTL1 register if necessary.
GD32A513 User Manual Option bytes 1 programming The following steps show the modify operation sequence. Unlock the FMC_CTL1 register if necessary. Check the BUSY bit in FMC_STAT1 register to confirm that no flash memory operation is in progress (BUSY equal to 0). Otherwise, wait until the operation has been finished.
GD32A513 User Manual Address Name Description 0x1fff f80d OB_BK0WP_N[23:16] OB_BK0WP complement value bit 23 to 16 0x1fff f80e OB_BK0WP[31:24] Page erase / program protection of bank0 bit 31 to 24 0x1fff f80f OB_BK0WP_N[31:24] OB_BK0WP complement value bit 31 to 24...
GD32A513 User Manual Address Name Description 1011: Reserved 1100: Reserved 1101: Reserved 1110: Reserved 1111: 0 Bytes Specified the size of the data flash and EEPROM backup in the extend flash memory. Extend memory that is not partitioned for data flash is used to store EEPROM records.
GD32A513 User Manual Address Name Description 1010: Reserved 1011: Reserved 1100: Reserved 1101: Reserved 1110: Reserved 1111: 0 Bytes Specified the size of the data flash and EEPROM backup in the extend flash memory. Extend memory that is not partitioned for data flash is used to store EEPROM records.
GD32A513 User Manual Address Name Description 1001: Reserved 1010: Reserved 1011: Reserved 1100: Reserved 1101: Reserved 1110: Reserved 1111: 0 Bytes Specified the size of the data flash and EEPROM backup in the extend flash memory. Extend memory that is not partitioned for data flash is used to store EEPROM records.
GD32A513 User Manual get the attention of the CPU. Page erase / program protection of bank 0 The page erase / program protection of bank 0 can be individually enabled by configuring the OB_BK0WP[31:0] bit field to 0 in the option bytes 0. If a page erase operation is executed on the Option Byte region, all the flash memory page erase / program protection functions will be disabled.
GD32A513 User Manual Note: 1. BANK1_SIZE is the memory size of bank1. 2. OTP write protection is controlled by OB_BK1WP[7]. Page erase / program protection of data flash The page erase / program protection of data flash can be individually enabled by configuring the OB_DFWP[7:0] bit field to 0 in the option bytes 0.
GD32A513 User Manual for protected shows which pages are protected by setting OB_EPWP[7:0]. Table 2-14. OB_EPWP bit for protected OB_EPWP bit pages protected OB_EPWP[0] EEPROM_SIZE / 8 OB_EPWP[1] EEPROM_SIZE / 8 OB_EPWP[6] EEPROM_SIZE / 8 OB_EPWP[7] EEPROM_SIZE / 8 Note: EEPROM_SIZE is the memory size of backup EEPROM.
GD32A513 User Manual PGSERR conditions. Table 2-15. PGSERR conditions Mode Condition Operation program / fast PG and FSTPG are cleared Write data program 1. not write by address order fast program 2. not write from 0 or not write full 32 double-word Set START 3.
GD32A513 User Manual Table 2-16. PGAERR bit in FMC_CTLx register will be set if one of the conditions occurs in PGAERR conditions. Table 2-16. PGAERR conditions Mode Condition Operation 1. The DBUS program do not use 32-bit write. 2. The DBUS write is not alignment. The first DBUS...
GD32A513 User Manual 2.4. Register definition FMC base address: 0x4002 2000 Wait state register (FMC_WS) 2.4.1. Address offset: 0x00 Reset value: 0x0000 0210 This register has to be accessed by word (32-bit). PRAMRD BRAMRD ERAMRD Reserved SLEEP_S Reserved Reserved IDRST...
GD32A513 User Manual 1: Reset the cache if cache is disabled Reserved Must be kept at reset value. IDCEN Cache enable 0: Cache disable 1: Cache enable Reserved Must be kept at reset value. PFEN Pre-fetch enable 0: Pre-fetch disable...
Page 80
GD32A513 User Manual 0: No ECC error is detected and corrected. 1: An ECC error is detected and corrected. EPECCDET EEPROM two bit errors detect flag. This bit is cleared by writing 1. 0: Two ECC errors of EEPROM are not detected.
GD32A513 User Manual OB0_ECC If an ECC bit error is detected in option bytes 0, this bit will be set. And the ECCADDR records the offset address of option bytes 0. 0: No ECC error is detected in option bytes 0.
GD32A513 User Manual 31:16 Reserved Must be kept at reset value. RSTERR If the voltage is below 3.0V or a system reset occurs during flash programming or erasing, an error will be generated and this bit will be set. When the error is occurred, the data in the current address unreliable, and it is necessary to erase and program again.
Page 83
GD32A513 User Manual Reserved ENDIE Reserved ERRIE Reserved FSTPG START Reserved Bits Fields Descriptions 31:29 CBCMDLEN[2:0] CBCMD read length 2^(CBCMDLEN). The read length by check blank command. The read length is 2^ CBCMDLEN double words. 28:17 Reserved Must be kept at reset value.
GD32A513 User Manual 1: main flash page erase command Main flash program command bit This bit is set or clear by software 0: no effect 1: main flash program command Note: This register should be reset after the corresponding flash operation completed.
GD32A513 User Manual Unlock key register 1 (FMC_KEY1) 2.4.8. Address offset: 0x48 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). KEY[31:16] KEY[15:0] Bits Fields Descriptions 31:0 KEY[31:0] FMC_CTL1 unlock key These bits are only be written by software Write KEY[31:0] with key to unlock FMC_CTL1 register.
GD32A513 User Manual 0: The checked page is all 0xFF. 1: The checked page is not all 0xFF. ENDF End of operation flag bit When the operation executed successfully, this bit is set by hardware. The software can clear it by writing 1.
Page 87
GD32A513 User Manual 01: set fast program RAM mode 10: set Basic RAM mode 11: set EEPROM RAM mode 23:17 Reserved Must be kept at reset value. CBCMD The command to check the selected page is blank or not. 15:14 Reserved Must be kept at reset value.
GD32A513 User Manual This bit is set or clear by software 0: no effect 1: option bytes 0 program command MERDF Data flash mass erase command bit This bit is set or cleared by software 0: no effect 1: Data flash mass erase command...
GD32A513 User Manual Reset value: 0x0000 0000 (When the EEPROM has been configured as valid space by EPSIZE and EFALC in option byets 1, the reset value is 0x0000 0000. Otherwise, the reset value is 0x0FFF FFFF.) This register has to be accessed by word (32-bit).
GD32A513 User Manual Erase / Program protection register 0 (FMC_WP0) 2.4.14. Address offset: 0x60 Reset value: 0xXXXX XXXX This register has to be accessed by word(32-bit). BK0WP[31:16] BK0WP[15:0] Bits Fields Descriptions 31:0 BK0WP[31:0] Store OB_BK0WP[31:0] of option bytes 0 block after system reset.
GD32A513 User Manual OB1STA EPLOAD Reserved EPSIZE[3:0] EFALC[3:0] Reserved OB1LK OB1ERR Bits Fields Descriptions 31:16 LKVAL[15:0] Load LKVAL of option byte 1 after reset. These bits can be written by software when OB1LK is 0. EPLOAD Load EPLOAD of option byte 1 after reset. This bit can be written by software when OB1LK is 0.
Page 92
GD32A513 User Manual These bits are read only by software. These bits are unchanged constant after power on. These bits are one time program when the chip produced.
The power consumption is regarded as one of the most important issues for the devices of GD32A513 series. Power management unit (PMU) provides three types of power saving modes, including Sleep, Deep-sleep and Standby mode. These modes reduce the power consumption and allow the application to achieve a best tradeoff among the conflicting demands of CPU operating time, speed and power consumption.
GD32A513 User Manual PC13 can be used as GPIO or RTC function pin described in the RTC clock calibration. PC14 and PC15 can be used as either GPIO or LXTAL crystal oscillator pins. power domain 3.3.2. domain includes two parts: V domain and V domain.
GD32A513 User Manual shows the relationship between the supply voltage and the BOR reset signal. V which defined in the BOR_TH bits in option bytes, indicates the threshold of BOR on reset. The hysteresis voltage (V ) is 40mV. hyst Figure 3-3.
GD32A513 User Manual Figure 3-4. Waveform of the LVD threshold threshold 100mV hyst LVD output Figure 3-5. Waveform of the OVD threshold threshold 25mV hyst OVD output Generally, digital circuits are powered by V , while most of analog circuits are powered by .
Power saving modes 3.3.4. After a system reset or a power reset, the GD32A513 MCU operates at full function state and all power domains are active. Users can achieve lower power consumption through slowing down the system clocks (HCLK, PCLK1 and PCLK2), closing the clocks of the unused peripherals.
Page 99
GD32A513 User Manual and SRAM2 (32kB ~ 48kB) in deep sleep mode can be set respectively. The LDO can operate in normal mode or in low power mode depending on the LDOLP bit in the PMU_CTL register. Before entering the Deep-sleep mode, it is necessary to set the SLEEPDEEP bit in the ®...
GD32A513 User Manual alarm, the FWDGT reset and the rising edge on WKUP pin. The Standby mode achieves the lowest power consumption, but spends longest time to wake up. Besides, the contents of SRAM and registers in 1.1V power domain are lost in Standby mode. When exiting from the ®...
GD32A513 User Manual Register definition 3.4. PMU base address: 0x4000 7000 Control register (PMU_CTL) 3.4.1. Address offset: 0x00 Reset value: 0x0000 8000 (reset after wakeup from Standby mode) This register can be accessed by half-word(16-bit) or word(32-bit). SRAMSW SRAMSW Reserved...
GD32A513 User Manual 0: Disable write access to the registers in Backup domain 1: Enable write access to the registers in Backup domain After reset, any write access to the registers in Backup domain is ignored. This bit has to be set to enable write access to these registers.
Page 103
GD32A513 User Manual This register can be accessed by half-word(16-bit) or word(32-bit). Reserved Reserved WUPEN1 WUPEN0 Reserved OVDF LVDF STBF Bits Fields Descriptions 31:10 Reserved Must be kept at reset value. WUPEN1 WKUP Pin1 Enable (PC13) 0: Disable WKUP pin1 function...
Page 104
GD32A513 User Manual This bit is cleared only by a POR/PDR or by setting the STBRST bit in the PMU_CTL register. Wakeup Flag 0: No wakeup event has been received 1: Wakeup event occurred from the WKUP pin or the RTC alarm event This bit is reset by the system or cleared by setting the WURST bit in the PMU_CTL register.
GD32A513 User Manual Backup registers (BKP) Overview 4.1. The Backup registers are located in the Backup domain that remains powered-on by V power, there are ten 16-bit (20 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.
Page 106
GD32A513 User Manual the BKP_TPCTL register. To prevent the tamper event from losing, the edge detection is logically ANDed with the TPEN bit, used for tamper detection signal. So the tamper detection configuration should be set before enable TAMPER pin. When the tamper event is detected, the corresponding TEF bit in the BKP_TPCS register will be set.
GD32A513 User Manual Register definition 4.4. BKP base address: 0x4000 6C00 Backup data register x (BKP_DATAx) (x= 0..9) 4.4.1. Address offset: 0x04 to 0x28 Reset value: 0x0000 0000 This register can be accessed by half-word (16-bit) or word (32-bit). Reserved...
GD32A513 User Manual This bit is reset only by a Backup domain reset. CCOSEL RTC clock output selection 0: RTC clock div 64 1: RTC clock This bit is reset only by a POR. 13:10 Reserved Must be kept at reset value.
GD32A513 User Manual 31:16 Reserved Must be kept at reset value. PCSEL OSC32_IN pin select 0: PC13 is OSC32_IN pin 1: PC14 is OSC32_IN pin 14:2 Reserved Must be kept at reset value. TPAL TAMPER pin active level 0: The TAMPER pin is active high...
Page 110
GD32A513 User Manual This bit is reset only by a system reset and wake-up from Standby mode. Tamper interrupt reset 0: No effect 1: Reset the TIF bit This bit is always read as 0. Tamper event reset 0: No effect 1: Reset the TEF bit This bit is always read as 0.
Overview 5.1.1. GD32A513 reset control includes the control of three kinds of reset: power reset, system reset and backup domain reset. The power on reset, known as a cold reset, resets the full system except the backup domain during a power up. A system reset resets the processor core and peripheral IP components with the exception of the SW-DP controller and the backup domain.
GD32A513 User Manual FLASH or SRAM 2-bit ECC error reset (ECC_RSTn) LVD_RSTn / LOH_RSTn / LOP_RSTn / LOCKUP_RSTn / ECC_RSTn should be enable by software. A system reset resets the processor core and peripheral IP components except for the SW- DP controller and the backup domain.
GD32A513 User Manual which can source from the IRC8M, HXTAL or PLL. The maximum operating frequency of the system clock (CK_SYS) can be up to 100 MHz. Figure 5-2. Clock tree CK_I2S (to I2S) CK_FMC SCS[1:0] FMC enable (to FMC)
GD32A513 User Manual Figure 5-4. HXTAL clock source in bypass mode OSCIN OSCOUT External cl ock Select the HXTAL frequency scale by using the HXTALSCAL bit in the control register, RCU_CTL. If HXTAL frequency is higher than 8MHz, HXTALSCAL bit must be set.
Page 116
GD32A513 User Manual related interrupt enable bit, LXTALSTBIE, in the interrupt register RCU_INT is set when the LXTAL becomes stable. Select external clock bypass mode by setting the LXTALBPS and LXTALEN bits in the backup domain control register (RCU_BDCTL). The CK_LXTAL is equal to the external clock which drives the OSC32IN pin.
GD32A513 User Manual in the control register, RCU_CTL. This function should be enabled after the HXTAL start-up delay and disabled when the HXTAL is stopped. Once the HXTAL failure is detected, Loss- of-HXTAL reset will generate decided by LOHRSTEN in the reset source /clock register, RCU_RSTSCK.
GD32A513 User Manual If the USART0/1/2 clock is selected IRC8M clock in Deep-sleep mode, they have capable of open IRC8M clock or close IRC8M clock, which used to the USART0/1/2 to wake up the Deep-sleep mode. Voltage control The core domain voltage in Deep-sleep mode can be controlled by DSLPVS[1:0] bits in the Deep-sleep mode voltage register (RCU_DSV).
GD32A513 User Manual 5.3. Register definition RCU base address: 0x4002 1000 Control register (RCU_CTL) 5.3.1. Address offset: 0x00 Reset value: 0x0000 XX83 where X is undefined. This register can be accessed by byte(8-bit), half-word(16-bit) and word(32-bit) HXTALSC HXTALB HXTALST HXTALE...
Page 120
GD32A513 User Manual LCKMEN enable the hardware detects that the LXTAL clock is stuck at a low/high state or slow down to about 20KHz. PLLMEN PLL clock monitor enable 0: Disable the PLL clock monitor 1: Enable the PLL clock monitor PLLMEN enable the hardware detects that the PLL clock is stuck at a low/high state.
GD32A513 User Manual Reserved Must be kept at reset value. IRC8MSTB IRC8M high speed internal oscillator stabilization flag Set by hardware to indicate if the IRC8M oscillator is stable and ready for use. 0: IRC8M oscillator is not stable 1: IRC8M oscillator is stable...
Page 122
GD32A513 User Manual 26:24 CKOUTSEL[2:0] CK_OUT clock source selection Set and reset by software. 000: No clock selected 001: Reserved 010: Internal 40K RC oscillator clock selected 011: External low speed oscillator clock selected 100: System clock selected 101: Internal 8MHz RC oscillator clock selected...
Page 123
GD32A513 User Manual 11101: (PLL source clock x 30) 11110: (PLL source clock x 31) 11111: (PLL source clock x 31) Note: The PLL output frequency must not exceed 100 MHz. DPLL Double PLL clock 0: Double PLL clock 1: PLL clock...
GD32A513 User Manual 01: Select CK_HXTAL as the CK_SYS source 10: Select CK_PLL as the CK_SYS source 11: Reserved SCS[1:0] System clock switch Set by software to select the CK_SYS source. Because the change of CK_SYS has inherent latency, software should read SCSS to confirm whether the switching is complete or not.
Page 125
GD32A513 User Manual 1: Reset LCKMIF flag PLLSTBIC PLL stabilization interrupt clear Write 1 by software to reset the PLLSTBIF flag. 0: Not reset PLLSTBIF flag 1: Reset PLLSTBIF flag HXTALSTBIC HXTAL stabilization interrupt clear Write 1 by software to reset the HXTALSTBIF flag.
Page 126
GD32A513 User Manual IRC8MSTBIE IRC8M stabilization interrupt enable Set and reset by software to enable/disable the IRC8M stabilization interrupt 0: Disable the IRC8M stabilization interrupt 1: Enable the IRC8M stabilization interrupt LXTALSTBIE LXTAL stabilization interrupt enable LXTAL stabilization interrupt enable/disable control...
GD32A513 User Manual Set by hardware when the internal 8 MHz RC oscillator clock is stable and the IRC8MSTBIE bit is set. Reset by software when setting the IRC8MSTBIC bit. 0: No IRC8M stabilization interrupt generated 1: IRC8M stabilization interrupt generated...
Page 128
GD32A513 User Manual 29:22 Reserved Must be kept at reset value TIMER20RST TIMER20 reset This bit is set and reset by software. 0: No reset 1: Reset the TIMER20 TIMER19RST TIMER19 reset This bit is set and reset by software.
GD32A513 User Manual 1: Reset comparator CFGRST System configuration reset This bit is set and reset by software. 0: No reset 1: Reset system configuration APB1 reset register (RCU_APB1RST) 5.3.5. Address offset: 0x10 Reset value: 0x0000 0000 This register can be accessed by byte(8-bit), half-word(16-bit) and word(32-bit)
Page 130
GD32A513 User Manual I2C0RST I2C0 reset This bit is set and reset by software. 0: No reset 1: Reset I2C0 20:19 Reserved Must be kept at reset value USART2RST USART2 reset This bit is set and reset by software. 0: No reset...
GD32A513 User Manual 16:15 Reserved Must be kept at reset value MFCOMEN MFCOM port A clock enable This bit is set and reset by software. 0: Disabled MFCOM port A clock 1: Enabled MFCOM port A clock 13:7 Reserved Must be kept at reset value...
Page 133
GD32A513 User Manual TRIGSEL TIMER20 TIMER19E CAN1EN CAN0EN Reserved Reserved USART0 TIMER7E TIMER0E Reserved SPI0EN ADC1EN ADC0EN Reserved CMPEN CFGEN Bits Fields Descriptions CAN1EN CAN1 clock enable This bit is set and reset by software. 0: Disabled CAN1 clock 1: Enabled CAN1 clock...
GD32A513 User Manual 1: Enabled TIMER7 timer clock SPI0EN SPI0 clock enable This bit is set and reset by software. 0: Disabled SPI0 clock 1: Enabled SPI0 clock TIMER0EN TIMER0 timer clock enable This bit is set and reset by software.
Page 135
GD32A513 User Manual Bits Fields Descriptions 31:30 Reserved Must be kept at reset value DACEN DAC clock enable This bit is set and reset by software. 0: Disabled DAC clock 1: Enabled DAC clock PMUEN Power interface clock enable This bit is set and reset by software.
GD32A513 User Manual 1: Enabled SPI1 clock 13:12 Reserved Must be kept at reset value WWDGTEN Window watchdog timer clock enable This bit is set and reset by software. 0: Disabled window watchdog timer clock 1: Enabled window watchdog timer clock...
GD32A513 User Manual BKPRST Backup domain reset This bit is set and reset by software. 0: No reset 1: Resets backup domain RTCEN RTC clock enable This bit is set and reset by software. 0: Disabled RTC clock 1: Enabled RTC clock...
Page 138
GD32A513 User Manual Reset value: 0x0C80 0000, reset flags reset by power reset only, other reset by system reset. This register can be accessed by byte(8-bit), half-word(16-bit) and word(32-bit) WWDGT FWDGT LOCKUP RSTFC Reserved RSTF RSTF RSTF RSTF RSTF RSTF...
Page 139
GD32A513 User Manual Reset by writing 1 to the RSTFC bit. 0: No external PIN reset generated 1: External PIN reset generated OBLRSTF Option byte loader reset flag Set by hardware when an option byte loader generated. Reset by writing 1 to the RSTFC bit.
GD32A513 User Manual 0: No CPU Lock-Up error reset generated 1: CPU Lock-Up error reset generated BORRSTF BOR reset flag Set by hardware when a BOR reset generated. Reset by writing 1 to the RSTFC bit. 0: No BOR reset generated...
Page 141
GD32A513 User Manual Reserved PFRST PERST PDRST PCRST PBRST PARST Reserved MFCOMR DMAMUX DMA1 DMA0 Reserved Reserved CRCRST Reserved Reserved Bits Fields Descriptions 31:23 Reserved Must be kept at reset value PFRST GPIO port F reset This bit is set and reset by software.
GD32A513 User Manual 13:7 Reserved Must be kept at reset value CRCRST CRC reset This bit is set and reset by software. 0: No reset CRC module 1: Reset CRC module Reserved Must be kept at reset value DMAMUXRST DMAMUX reset This bit is set and reset by software.
GD32A513 User Manual 0010: Input to PLL divided by 3 0011: Input to PLL divided by 4 0100: Input to PLL divided by 5 0101: Input to PLL divided by 6 0110: Input to PLL divided by 7 0111: Input to PLL divided by 8...
GD32A513 User Manual 00: CK_CAN0 select CK_HXTAL 01: CK_CAN0 select CK_PCLK2 10: CK_CAN0 select CK_PCLK2/2 11: CK_CAN0 select CK_IRC8M 11:7 Reserved Must be kept at reset value USART2SEL[1:0] CK_USART2 clock source selection This bit is set and reset by software.
GD32A513 User Manual to the RCU_VKEY, the RCU_DSV register can be written. Deep-sleep mode voltage register (RCU_DSV) 5.3.15. Offset: 0x134 Reset value: 0x0000 0003 This register can be accessed by byte(8-bit), half-word(16-bit) and word(32-bit) Reserved Reserved DSLPVS[1:0] Bits Fields Descriptions...
GD32A513 User Manual Interrupt / event controller (EXTI) Overview 6.1. ® Cortex -M33 integrates the Nested Vectored Interrupt Controller (NVIC) for efficient exception and interrupts processing. NVIC facilitates low-latency exception and interrupt handling and power management controls. It’s tightly coupled to the processer core. You can read the Technical Reference Manual of Cortex -M33 for more details about NVIC.
GD32A513 User Manual ® Table 6-1. NVIC exception types in Cortex -M33 Vector Exception type Priority (a) Vector address Description number 0x0000_0000 Reserved Reset 0x0000_0004 Reset 0x0000_0008 Non maskable interrupt. HardFault 0x0000_000C All class of fault MemManage Programmable 0x0000_0010 Memory management...
Page 148
GD32A513 User Manual Interrupt Vector Peripheral interrupt description Vector address number number IRQ 18 ADC0 and ADC1 interrupt 0x0000_0088 IRQ 19 CAN0 Interrupt for message buffer 0x0000_008C IRQ 20 CAN0 Interrupt for Bus off / Bus off done 0x0000_0090 IRQ 21...
Page 149
GD32A513 User Manual Interrupt Vector Peripheral interrupt description Vector address number number IRQ52 Reserved 0x0000_0110 IRQ53 Reserved 0x0000_0114 IRQ54 TIMER5 interrupt, DAC global interrupt 0x0000_0118 IRQ55 TIMER6 global interrupt 0x0000_011C IRQ56 DMA1 Channel 0 global interrupt 0x0000_0120 IRQ57 DMA1 Channel 1 global interrupt...
GD32A513 User Manual External interrupt and event (EXTI) block diagram 6.4. Figure 6-1. Block diagram of EXTI Polarity Software Control Trigger EXTI Line0~24 Edge detector To NVIC Interrupt Mask Control To Wakeup Unit Event Event Mask Generate Control External Interrupt and Event function overview 6.5.
GD32A513 User Manual Hardware trigger Hardware trigger may be used to detect the voltage change of external or internal signals. The software should follow these steps to use this function: Configure EXTI sources in SYSCFG module based on application requirement.
Page 152
GD32A513 User Manual EXTI Line Source Number RTC Alarm CAN0 CAN1 CMP output USART0 Wakeup USART1 Wakeup USART2 Wakeup Over voltage...
GD32A513 User Manual Trigger selection controller (TRIGSEL) Overview 7.1. The trigger selection controller (TRIGSEL) allows software to select the trigger input signal for various peripherals. TRIGSEL provides a flexible mechanism for a peripheral to select different trigger inputs. With TRIGSEL, there are up to 4 trigger selection outputs could be selected for each peripheral.
GD32A513 User Manual Register definition 7.5. TRIGSEL base address: 0x4001 8400 Trigger selection for EXTOUT0 register (TRIGSEL_EXTOUT0) 7.5.1. Address offset: 0x00 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). INSEL3[6:0] Reserved INSEL2[6:0] Reserved INSEL1[6:0] Reserved...
GD32A513 User Manual is used as the source of external output0 signal. For the detailed configuration, please refer to Table 7-1. Trigger input bit fields selection. Trigger selection for EXTOUT1 register (TRIGSEL_EXTOUT1) 7.5.2. Address offset: 0x04 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
GD32A513 User Manual please refer to Table 7-1. Trigger input bit fields selection. Trigger selection for ADC0 register (TRIGSEL_ADC0) 7.5.3. Address offset: 0x08 Reset value: 0x0000 1E16 This register has to be accessed by word (32-bit). Reserved Reserved INSEL0[6:0] Bits...
GD32A513 User Manual TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_ADC1 register. 0: TRIGSEL_ADC1 register write is enabled. 1: TRIGSEL_ADC1 register write is disabled.
GD32A513 User Manual This register has to be accessed by word (32-bit). INSEL3[6:0] Reserved INSEL2[6:0] Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER0IN register.
GD32A513 User Manual INSEL3[6:0] Reserved INSEL2[6:0] Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER0BRKIN register.
GD32A513 User Manual INSEL3[6:0] Reserved INSEL2[6:0] Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER7IN register.
GD32A513 User Manual Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER7BRKIN register. 0: TRIGSEL_TIMER7BRKIN register write is enabled.
GD32A513 User Manual Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER19IN register. 0: TRIGSEL_TIMER19IN register write is enabled.
GD32A513 User Manual Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER19BRKIN register. 0: TRIGSEL_TIMER19BRKIN register write is enabled.
GD32A513 User Manual Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER20IN register. 0: TRIGSEL_TIMER20IN register write is enabled.
GD32A513 User Manual Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER20BRKIN register. 0: TRIGSEL_TIMER20BRKIN register write is enabled.
GD32A513 User Manual Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_TIMER1IN register. 0: TRIGSEL_TIMER1IN register write is enabled.
GD32A513 User Manual Reserved INSEL1[6:0] Reserved INSEL0[6:0] Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_MFCOM register. 0: TRIGSEL_MFCOM register write is enabled.
GD32A513 User Manual Bits Fields Descriptions TRIGSEL register lock. This bit is set by software and cleared only by a system reset. When it is set, it disables write access to TRIGSEL_CAN0 register. 0: TRIGSEL_CAN0 register write is enabled. 1: TRIGSEL_CAN0 register write is disabled.
GD32A513 User Manual General-purpose and alternate-function I/Os (GPIO and AFIO) 8.1. Overview There are up to 88 general purpose I/O pins (GPIO), named PA0~PA15, PB0~PB15, PC0~PC15, PD0~PD15, PE0~PE15, PF0~ PF7 for the device to implement logic input/output functions. Each GPIO port has related control and configuration registers to satisfy the requirements of specific applications.
GD32A513 User Manual as floating (no pull-up and pull-down), pull-up or pull-down function by GPIO pull-up/pull-down registers (GPIOx_PUD). Table 8-1. GPIO configuration table PAD TYPE CTLy PUDy Floating GPIO pull-up INPUT pull-down Floating push-pull pull-up GPIO pull-down OUTPUT Floating open-drain...
GD32A513 User Manual GPIO pin configuration 8.3.1. During or just after the reset period, the alternative functions are all inactive and the GPIO ports are configured into the input floating mode that input disabled without Pull-Up(PU)/Pull- Down(PD) resistors. But the JTAG/Serial-Wired Debug pins are in input PU/PD mode after...
GD32A513 User Manual Input configuration 8.3.5. When GPIO pin is configured as input: The schmitt trigger input is enabled. The weak pull-up and pull-down resistors could be chosen. Every AHB clock cycle the data present on the I/O pin is got to the port input status register.
GD32A513 User Manual Analog configuration 8.3.7. When GPIO pin is used as analog configuration: The weak pull-up and pull-down resistors are disabled. The output buffer is disabled. The schmitt trigger input is disabled. The port input status register of this I/O port bit is “0”.
GD32A513 User Manual Figure 8-5. Basic structure of Alternate function configuration Alternate Function Output Output driver protect I / O pin Alternate Function Input Input driver GPIO locking function 8.3.9. The locking mechanism allows the IO configuration to be protected.
GD32A513 User Manual 8.4. Register definition GPIOA base address: 0x4800 0000 GPIOB base address: 0x4800 0400 GPIOC base address: 0x4800 0800 GPIOD base address: 0x4800 0C00 GPIOE base address: 0x4800 1000 GPIOF base address: 0x4800 1400 Port control register (GPIOx_CTL, x=A..F) 8.4.1.
Page 184
GD32A513 User Manual 21:20 CTL10[1:0] Pin 10 configuration bits These bits are set and cleared by software. Refer to CTL0[1:0] description 19:18 CTL9[1:0] Pin 9 configuration bits These bits are set and cleared by software. Refer to CTL0[1:0] description 17:16...
GD32A513 User Manual Port output mode register (GPIOx_OMODE, x=A..F) 8.4.2. Address offset: 0x04 Reset value: 0x0000 0000 This register can be accessed by byte(8-bit), half-word(16-bit) and word(32-bit) Reserved OM15 OM14 OM13 OM12 OM11 OM10 Bits Fields Descriptions 31:16 Reserved Must be kept at reset value...
GD32A513 User Manual These bits are set and cleared by software. Refer to OM0 description Pin 6 output mode bit These bits are set and cleared by software. Refer to OM0 description Pin 5 output mode bit These bits are set and cleared by software.
Page 187
GD32A513 User Manual These bits are set and cleared by software. Refer to OSPD0[1:0] description 29:28 OSPD14[1:0] Pin 14 output max speed bits These bits are set and cleared by software. Refer to OSPD0[1:0] description 27:26 OSPD13[1:0] Pin 13 output max speed bits These bits are set and cleared by software.
GD32A513 User Manual Refer to OSPD0[1:0] description OSPD2[1:0] Pin 2 output max speed bits These bits are set and cleared by software. Refer to OSPD0[1:0] description OSPD1[1:0] Pin 1 output max speed bits These bits are set and cleared by software.
Page 189
GD32A513 User Manual These bits are set and cleared by software. Refer to PUD0[1:0] description 21:20 PUD10[1:0] Pin 10 pull-up or pull-down bits These bits are set and cleared by software. Refer to PUD0[1:0] description 19:18 PUD9[1:0] Pin 9 pull-up or pull-down bits These bits are set and cleared by software.
GD32A513 User Manual Port input status register (GPIOx_ISTAT, x=A..F) 8.4.5. Address offset: 0x10 Reset value: 0x0000 XXXX This register can be accessed by byte(8-bit), half-word(16-bit) and word(32-bit) Reserved ISTAT15 ISTAT14 ISTAT13 ISTAT12 ISTAT11 ISTAT10 ISTAT9 ISTAT8 ISTAT7 ISTAT6 ISTAT5 ISTAT4...
GD32A513 User Manual sequence. 15:0 Port lock bit y(y=0..15) These bits are set and cleared by software. 0: Port configuration not locked 1: Port configuration locked Alternate function selected register 0 (GPIOx_AFSEL0, x=A..F) 8.4.9. Address offset: 0x20 Reset value: 0x0000 0000...
GD32A513 User Manual Refer to SEL8[3:0] description 15:12 SEL11[3:0] Pin 11 alternate function selected These bits are set and cleared by software. Refer to SEL8[3:0] description 11:8 SEL10[3:0] Pin 10 alternate function selected These bits are set and cleared by software.
GD32A513 User Manual These bits are set and cleared by software. 0: No action on the corresponding OCTLy bit 1: Clear the corresponding OCTLy bit Port bit toggle register (GPIOx_TG, x=A..F) 8.4.12. Address offset: 0x2C Reset value: 0x0000 0000 This register can be accessed by byte(8-bit), half-word(16-bit) and word(32-bit)
GD32A513 User Manual Multi-function communication Interface (MFCOM) 9.1. Overview The MFCOM is a highly configurable module provide emulation of a variety of serial communication protocols and flexible timers. 9.2. Characteristics Continuous data transfer configuration Shift register with dual cache regions supports continuous data transfer.
GD32A513 User Manual Access the MFCOM register through the AHB bus clock, MFCOM has 4 timers, 4 shifters and 8 pins. Can select the shifter's pin input and output through SPSEL[2:0] bit. By configuring INSRC, can select the input source of the shifte (the output of the shifter or the input of the pin are optional).
GD32A513 User Manual SSTAT、Interrupt Shifter working SERR、Interrupt Mode DMA request setting mechanism setting conditions conditions assigned timer. The shifter will shift data in and continuously check A match occurs, Match for a match result returns the current A match occurs.
Page 200
GD32A513 User Manual configured by a 16-bit counter. When the 16-bit counter equal to zero and decrement, the timer output switches and the counter is reloaded from the comparison register. When the 16- bit counter equal to zero and decrement, the timer comparison event occurs and the timer status flag is set.
GD32A513 User Manual decrement only occurs when the low 8-bits equal to zero and decrement. A timer comparison event is triggered when the timer counter decrements to 0. The trigger of the timer comparison event will cause the timer counter to load the contents of the comparison register, the timer output to the toggle, the send shift register of any configuration to load, and the receive shift register of any configuration to store.
GD32A513 User Manual on a bidirectional output. Any timer or shifter may be driven by another timer or shifter, configured to control output so that data can be output bidirectional on one pin. Pin synchronization When a pin is configured as input, the input signal is first synchronized with the MFCOM clock before the signal is used by a timer or shifter.
GD32A513 User Manual or more MFCOM timers can be triggered. Output triggers The output trigger of each MFCOM timer is equal to the timer output, and the timer output is not affected by the timer's pin polarity configuration. Typical configuration of application 9.4.7.
Page 204
GD32A513 User Manual can be written to an SBUF[7:0] to initiate an 8-bit transmission, using the shifter status flag bit to determine when to use an interrupt or DMA request to write. Supports the MSB first transfer write to the SBUFBBS[7:0] register instead.
Page 205
GD32A513 User Manual 0. Can invert input data by setting PINPL. Set the value of register MFCOM_TMCMPx as 0x00000F01, configure 8-bit transfer with baud rate of divide by 4 of the MFCOM clock. Set TMCVALUE [15:8] = (number of bits x 2) - 1.
Page 206
GD32A513 User Manual Keep the value of register MFCOM_SCFG(x+1) as default, start and stop bit disabled. Set the bits SPSEL[2:0], and SMOD[1:0] as 0b001, and 0b01 in register MFCOM_SCTL(x+1) respectively, configure receive using timer 0 on posedge of clock with input data on pin1.
Page 207
GD32A513 User Manual Set the bits TMOUT[1:0], TMDIS[2:0], TMEN[2:0] TMSTOP[1:0], and TMSTART as 0b01, 0b010, 0b010, 0b10, and 0b1 in register MFCOM_TMCFGx respectively, configure start bit, stop bit, enable on trigger high and disable on compare, initial clock state is logic 0.
Page 208
GD32A513 User Manual Set TMCVALUE [15:0] = (number of bits x 2) - 1. Set the bits TMOUT[1:0], TMDEC[1:0] and TMEN[2:0] as 0b01, 0b10, and 0b110 in register MFCOM_TMCFGx respectively, configure enable on trigger rising edge, initial clock state is logic 0 and decrement on pin input.
Page 209
GD32A513 User Manual I2C master The I2C master mode uses two timers, two shifters and two pins, one timer for generating the SCL output and the other for controlling the shifter. Two shifters are used to send and receive each word. When receiving, the transmitter must send 0xFF for tristate output. MFCOM waits for a write to the transfer data buffer before enabling SCL generation.
Page 210
GD32A513 User Manual with baud rate of divide by 4 of the MFCOM clock. Set TMCVALUE [15:8] = (number of words x 18) + 1. Set TMCVALUE [7:0] = (baud rate divider / 2) - 1. Set the bits TMOUT[1:0], TMRST[2:0], TMDIS[2:0], TMEN[2:0], TMSTOP[1:0] and...
Page 211
GD32A513 User Manual pin 0. Set the bits in register MFCOM_SCFG(x+1) as default value, start and stop bit disabled. Set the bits TMPL, SPSEL[2:0] and SMOD[2:0] as 0b1, 0b001, and 0b001 in register MFCOM_SCTL(x+1) respectively, configure receive using timer 1 on falling edge of clock with input data on pin 1.
Page 212
GD32A513 User Manual the output frame length of the falling edge of the bit clock. When timer 1 outputs timer 0 to 1, the rising edge of the bit clock controls the shift register of 32-bit data transmission. I2S slave configuration Set the value of register MFCOM_SCFGx as default value, start and stop bit disabled.
GD32A513 User Manual MFCOM_SBUF register instead. 15. Set the bit SBUF[31:0] as data to receive in register MFCOM_SBUF(x+1), received data can be read from MFCOM_SBUFBISx, use the shifter status flag to indicate when data can be read using interrupt or DMA request. Can support LSB first transfer by reading from MFCOM_SBUF register instead.
GD32A513 User Manual Reserved PDATA[7:0] Bits Fields Descriptions 31:8 Reserved Must be kept at reset value PDATA[7:0] data of pins The input/output data of each MFCOM pins. Shifter status register (MFCOM_SSTAT) 9.5.3. Address offset: 0x08 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
GD32A513 User Manual Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved Reserved SERR[3:0] Bits Fields Descriptions 31:4 Reserved Must be kept at reset value SERR[3:0] Shifter x error flags The shift error flag is set when one of the following events occurs: SMOD = Receive, MFCOM_SBUF overrun, or the receive start or stop bit does not match the expected value.
GD32A513 User Manual occur. In 8-bit baud counter mode, the timer status flag will be set when the upper 8-bit counter down to zero and the decrement is active. In 8-bit high PWM mode, the timer status flag will be set when the upper 8-bit counter down to zero and the decrement is active.
GD32A513 User Manual Bits Fields Descriptions 31:4 Reserved Must be kept at reset value SEIEN[3:0] Shifter error interrupt enable Enable interrupt when the shifter x error flag bits in bit field SERR[3:0] are set 0: Shifter error flags do not generate an interrupt...
GD32A513 User Manual SSDMAEN[3:0] Shifter status DMA enable DMA is enabled when the timer x status flags in bit field SSTAT[3:0] are set 0: Shifter status flags do not generate DMA requests 1: Shifter status flags generate DMA requests Shifter control x register (MFCOM_SCTLx) 9.5.10.
GD32A513 User Manual 1: Pin active low Reserved Must be kept at reset value. SMOD[2:0] Shifter mode Configures the mode of the shifter. 000: Disabled. 001: Receive mode. 010: Transmit mode. 011: Reserved. 100: Match store mode. 101: Match continuous mode.
GD32A513 User Manual allows automatic insertion of stop bits. In receive or match store mode, if the selected timer has the stop bit enabled, the data frame allows automatic verification of the stop bit. Reserved Must be kept at reset value.
GD32A513 User Manual Shifter buffer x bit swapped register (MFCOM_SBUFBISx) 9.5.13. Address offset: 0x280 + 0x004 * x, (x = 0 to 3) Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). SBUFBIS[31:16] SBUFBIS[15:0] Bits Fields...
GD32A513 User Manual SBUFBBS[15:0] Bits Fields Descriptions 31:0 SBUFBBS[31:0] Shift buffer bit byte swapped Same as the MFCOM_SBUF register, except that the read/write register is bit swapped within each byte, and reads return {SBUF[24:31], SBUF[16:23], SBUF[8:15], SBUF[0:7]}. Timer control x register (MFCOM_TMCTLx) 9.5.16.
GD32A513 User Manual 1010: Pin5 1011: Timer 2 trigger 1100: Pin6 1101: Shifter 3 flag 1110: Pin7 1111: Timer 2 trigger TRIGPL Trigger polarity 0: Trigger is activated at high 1: Trigger is activated at low TRIGSRC Trigger source 0: Select external trigger...
Page 224
GD32A513 User Manual Reserved TMOUT[1:0] Reserved TMDEC[1:0] Reserved TMRST[2:0] Reserved TMDIS[2:0] Reserved TMEN[2:0] Reserved TMSTOP[1:0] Reserved TMSTART Reserved Bits Fields Descriptions 31:26 Reserved Must be kept at reset value 25:24 TMOUT[1:0] Timer output Configures the initial state of the timer output and whether it is affected by the timer reset.
GD32A513 User Manual 001: Disabled on timer x-1 disable 010: Disabled on timer compare 011: Disabled on timer compare and trigger low 100: Disabled on pin rising or falling edge 101: Disabled on pin rising or falling edge and provided trigger is high...
Page 226
GD32A513 User Manual TMCVALUE[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value 15:0 TMCVALUE[15:0] Timer compare value The timer compare value is loaded into the timer counter when the timer is first enabled, the timer is reset, and the timer is reduced to zero.
GD32A513 User Manual CRC calculation unit (CRC) Overview 10.1. A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data. This CRC calculation unit can be used to calculate 7/8/16/32 bit CRC code within user...
GD32A513 User Manual Function overview 10.3. CRC calculation unit is used to calculate the 32-bit raw data, and CRC_DATA register will receive the raw data and store the calculation result. If the CRC_DATA register has not been cleared by setting the CRC_CTL register, the new input raw data will be calculated based on the result of previous value of CRC_DATA.
GD32A513 User Manual Register definition 10.4. CRC base address: 0x4002 3000 Data register (CRC_DATA) 10.4.1. Address offset: 0x00 Reset value: 0xFFFF FFFF This register has to be accessed by word (32-bit). DATA[31:16] DATA[15:0] Bits Fields Descriptions 31:0 DATA[31:0] CRC calculation result bits Software writes and reads.
GD32A513 User Manual by any other peripheral. The CRC_CTL register will generate no effect to the byte. Control register (CRC_CTL) 10.4.3. Address offset: 0x08 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved Reserved REV_O...
GD32A513 User Manual This register has to be accessed by word (32-bit). IDATA[31:16] IDATA[15:0] Bits Fields Descriptions 31:0 IDATA[31:0] Configurable initial CRC data value When RST bit in CRC_CTL asserted, CRC_DATA will be programmed to this value. Polynomial register (CRC_POLY) 10.4.5.
GD32A513 User Manual Direct memory access controller (DMA) 11.1. Overview The direct memory access (DMA) controller provides a hardware method of transferring data between peripherals and/or memory without intervention from the CPU, thereby freeing up bandwidth for other system functions. Data can be quickly moved by DMA between peripherals and memory as well as memory and memory without any CPU actions.
GD32A513 User Manual The CNT bits in the DMA_CHxCNT register control how many data to be transmitted on the channel and must be configured before enable the CHEN bit in the register. During the transmission, the CNT bits indicate the remaining number of data items to be transferred.
GD32A513 User Manual Arbitration 11.4.3. When two or more requests are received at the same time, the arbiter determines which request is served based on the priorities of channels. There are two-stage priorities, including the software priority and the hardware priority. The arbiter determines which channel is selected to respond according to the following priority rules: ...
GD32A513 User Manual 1. Read the CHEN bit and judge whether the channel is enabled or not. If the channel is enabled, clear the CHEN bit by software. When the CHEN bit is read as ‘0’, configuring and starting a new DMA transfer is allowed.
GD32A513 User Manual Figure 11-3. DMA interrupt logic FTFIFx FTFIEx HTFIFx CHxINTF HTFIEx ERRIFx ERRIEx Note: “x” indicates channel number (x=0…6). DMA request mapping 11.4.9. The DMA requests of a channel are coming from the AHB/APB peripherals through the corresponding channel output of DMAMUX request multiplexer, refer to Table 12-3.
GD32A513 User Manual 11.5. Register definition DMA base address: 0x4002 0000 DMA1 base address: 0x4002 0400 Note: For DMA1 having 5 channels, all bits related to channel 5 and channel 6 in the following registers are not suitable for DMA1 Interrupt flag register (DMA_INTF) 11.5.1.
GD32A513 User Manual Interrupt flag clear register (DMA_INTC) 11.5.2. Address offset: 0x04 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved ERRIFC6 HTFIFC6 FTFIFC6 GIFC6 ERRIFC5 HTFIFC5 FTFIFC5 GIFC5 ERRIFC4 HTFIFC4 FTFIFC4 GIFC4 ERRIFC3 HTFIFC3 FTFIFC3...
Page 241
GD32A513 User Manual Bits Fields Descriptions 31:15 Reserved Must be kept at reset value. Memory to Memory mode Software set and cleared 0: Disable Memory to Memory mode 1: Enable Memory to Memory mode This bit can not be written when CHEN is ‘1’.
GD32A513 User Manual 0: Disable circular mode 1: Enable circular mode This bit can not be written when CHEN is ‘1’. Transfer direction Software set and cleared 0: Read from peripheral and write to memory 1: Read from memory and write to peripheral This bit can not be written when CHEN is ‘1’.
GD32A513 User Manual 15:0 CNT[15:0] Transfer counter These bits can not be written when CHEN in the DMA_CHxCTL register is ‘1’. This register indicates how many transfers remain. Once the channel is enabled, it is read-only, and decreases after each DMA transfer. If the register is zero, no transaction can be issued whether the channel is enabled or not.
Page 244
GD32A513 User Manual Bits Fields Descriptions 31:0 MADDR[31:0] Memory base address These bits can not be written when CHEN in the DMA_CHxCTL register is ‘1’. When MWIDTH in the DMA_CHxCTL register is 01 (16-bit), the LSB of these bits is ignored. Access is automatically aligned to a half word address.
GD32A513 User Manual DMA request multiplexer (DMAMUX) 12.1. Overview DMAMUX is a transmission scheduler for DMA requests. The DMAMUX request multiplexer is used for routing a DMA request line between the peripherals / generated DMA request (from the DMAMUX request generator) and the DMA controller. Each DMAMUX request multiplexer channel selects a unique DMA request line, unconditionally or synchronously with events from its DMAMUX synchronization inputs.
GD32A513 User Manual Note: The NBR[4:0] bits value shall only be written by software when both synchronization enable bit SYNCEN and event generation enable EVGEN bit of the corresponding request multiplexer channel x are disabled. When synchronization mode is enabled...
GD32A513 User Manual be routed to the DMAMUX multiplexer channel output until a synchronization input event occurs again. Channel event generation Each DMA request line multiplexer channel has an event output called Evtx_out, which is the DMA request multiplexer counter underrun event. Signals dmamux_evt0 ~ dmamux_evt3 can be used for DMA request chaining.
GD32A513 User Manual DMAMUX request generator 12.4.3. The DMAMUX request generator produces DMA requests upon trigger input event. Its component unit is the request generator channels. DMA request trigger inputs are connected in parallel to all request generator channels. And there is a built-in DMAMUX request generator counter for each request generator channel.
GD32A513 User Manual Set and configure the DMA channel x completely, except enabling the channel x. Set and configure the related DMAMUX channel y completely. Configure the CHEN bit with ‘1’ in the DMA_CHxCTL register to enable the DMA channel Interrupt 12.4.5.
GD32A513 User Manual Request multiplexer channel input identification Source MUXID[6:0] TIMER20_MCH2 TIMER20_MCH3 Trigger input mapping The DMA request trigger input for the DMAMUX request generator channel x is selected through the TID[4:0] bits in DMAMUX_RG_CHxCFG register, the sources can refer to Table 12-4.
GD32A513 User Manual Synchronization input mapping The synchronization input is selected by SYNCID[4:0] bits in the DMAMUX_RM_CHxCFG register, the sources can refer to Table 12-5. Synchronization input mapping. Table 12-5. Synchronization input mapping Synchronization input Source identification SYNCID[4:0] EXTI_0 EXTI_1...
GD32A513 User Manual 12.5. Register definition DMAMUX base address: 0x4002 0800 Request multiplexer channel configuration register 12.5.1. (DMAMUX_RM_CHxCFG) x = 0...11, where x is a channel number Address offset: 0x00 + 0x04 × x Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
GD32A513 User Manual Bits Fields Descriptions 31:12 Reserved Must be kept at reset value. 11:0 SOIFCx Clear bit for synchronization overrun event flag of request multiplexer channel x (x=0..11) Writing 1 clears the corresponding overrun flag SOIFx in the DMAMUX_RM_INTF register.
GD32A513 User Manual 0: Disable interrupt 1: Enable interrupt Reserved Must be kept at reset value. TID[4:0] Trigger input identification Selects the DMA request trigger input source. Request generator interrupt flag register (DMAMUX_RG_INTF) 12.5.5. Address offset: 0x140 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 260
GD32A513 User Manual 31:4 Reserved Must be kept at reset value. TOIFCx Clear bit for trigger overrun event flag of request generator channel x (x=0..3) Writing 1 in each bit clears the corresponding overrun flag TOIFx in the DMAMUX_RG_INTF register.
GD32A513 User Manual Debug (DBG) Introduction 13.1. The GD32A513 series provide a large variety of debug and test features. They are implemented with a standard configuration of the Arm CoreSightTM module together with a ® daisy chained standard TAP controller. Debug function is integrated into the Arm ®...
GD32A513 User Manual Table 13-1. Pin assignment Debug interface JTDI JTCK/SWCLK JTMS/SWDIO NJTRST JTDO By default, 5-pin standard JTAG debug mode is chosen after reset. Users can also use JTAG function without NJTRST pin, then the PB3 can be used to other GPIO functions (NJTRST tied to 1 by hardware).
GD32A513 User Manual When DSLP_HOLD bit in DBG control register (DBG_CTL) is set and entering the deep-sleep mode, the clock of AHB bus and system clock are provided by CK_IRC8M, and the debugger can debug in deep-sleep mode. When SLP_HOLD bit in DBG control register (DBG_CTL) is set and entering the sleep mode, the clock of AHB bus for CPU is not closed, and the debugger can debug in sleep mode.
GD32A513 User Manual Registers definition 13.4. DEBUG base address: 0xE004 4000 ID code register (DBG_ID) 13.4.1. Address offset: 0x00 Read only This register has to be accessed by word (32-bit). ID_CODE[31:16] ID_CODE[15:0] Bits Fields Descriptions 31:0 ID_CODE[31:0] DBG ID code register These bits read by software.
Page 265
GD32A513 User Manual 1: Hold the TIMER10 counter for debug when core halted. 29:24 Reserved Must be kept at reset value. CAN1_HOLD CAN1 hold bit This bit is set and reset by software. 0: no effect 1: Hold the CAN1 counter for debug when core halted.
Page 266
GD32A513 User Manual 0: no effect 1: Hold the TIMER1 counter for debug when core halted. TIMER0_HOLD TIMER0 hold bit This bit is set and reset by software. 0: no effect 1: Hold the TIMER0 counter for debug when core halted.
GD32A513 User Manual Analog-to-digital converter (ADC) Overview 14.1. A 12-bit successive approximation analog-to-digital converter module(ADC) is integrated on the MCU chip, which can sample analog signals from 16 external channels and 2 internal channels. The 18 ADC sampling channels all support a variety of operation modes. After...
GD32A513 User Manual – Oversampling ratio adjustable from 2x to 256x. – Programmable data shift up to 8-bit. Module supply requirements: 2.7V to 5.5V, and typical power supply voltage is 5V. ≤V ≤V Channel input range: V REFN REFP.
GD32A513 User Manual Wait until CLB=0. ADC clock 14.4.2. The CK_ADC clock is synchronous with the AHB clock and provided by the clock controller. ADC clock can be divided and configured by RCU controller. 14.4.3. ADC enable The ADCON bit on the ADC_CTL1 register is the enable switch of the ADC module. The ADC module will keep in reset state if this bit is 0.
GD32A513 User Manual Make sure the DISRC, SM in the ADC_CTL0 register and CTN bit in the ADC_CTL1 register are reset. Configure RSQ0 in ADC_RSQ2 register with the analog channel number. Configure ADC_SAMPTx register. Configure ETERC and ETSRC bits in the ADC_CTL1 register if in need.
GD32A513 User Manual Scan operation mode The scan operation mode will be enabled when SM bit in the ADC_CTL0 register is set. In this mode, the ADC performs conversion on the channels with a specific sequence specified in the ADC_RSQ0~ADC_RSQ2 registers. When the ADCON has been set high, the ADC samples and converts specified channels one by one in the routine sequence till the end of the routine sequence, once the corresponding software trigger or TRIGSEL trigger is active.
GD32A513 User Manual the ADC_CTL0 register. When the corresponding software trigger or TRIGSEL trigger is active, samples converts next channels configured ADC_RSQ0~ADC_RSQ2 registers until all the channels of routine sequence are done. The EOC will be set after every circle of the routine sequence. An interrupt will be generated if the EOCIE bit is set.
GD32A513 User Manual watchdog 1 can be configured in the ADC_WDT1 register. 14.4.7. Data storage mode The alignment of data stored after conversion can be specified by DAL bit in the ADC_CTL1 register. Figure 14-7. Data storage mode of 12-bit resolution...
GD32A513 User Manual by the SPTn[2:0] bits in the ADC_SAMPT0 and ADC_SAMPT1 registers. A different sample time can be specified for each channel. For 12-bits resolution, the total sampling and conversion time is “sampling time + 12.5” CK_ADC cycles. For example: CK_ADC = 15MHz and sample time is 2.5 cycles, the total time is “2.5+12.5”...
GD32A513 User Manual Enable the temperature sensor by setting the TSVEN bit in the ADC control register 1 (ADC_CTL1). Start the ADC conversion by setting the ADCON bit or by the triggers. Read the internal temperature sensor output voltage (V...
GD32A513 User Manual 433 ns 600 ns On-chip hardware oversampling 14.4.13. The on-chip hardware oversampling circuit performs data preprocessing to offload the CPU. It can handle multiple conversions and average them into a single data with increased data width, up to 16-bit. It provides a result with the following form, where N and M can be adjusted,...
GD32A513 User Manual Figure 14-12. Numerical example with 5-bits shift and rounding Raw 20-bit data Final result after 5-bit shift and rounding to nearest Table 14-5. Maximum output results for N and M (Grayed values indicates truncation) below gives the data format for the various N and M combination, for a raw conversion data equal to 0xFFF.
GD32A513 User Manual routine data register (ADC0_RDATA). The modes in Table 14-6. ADC sync mode table can be configured. In ADC sync mode, the DMA bit must be set even if it is not used. The converted data of ADC1 routine channel can be read from the ADC0 routine data register (ADC0_RDATA).
GD32A513 User Manual Routine parallel mode 14.5.2. The routine parallel mode is enabled by setting the SYNCM[3:0] bits in the ADC0_CTL0 register to 4b’0110. In the routine parallel mode. All of the ADCs convert the routine sequence parallelly at the selected external trigger of ADC0. The trigger is selected by configuring the ETSRC bit in the ADC_CTL1 register of ADC0.
GD32A513 User Manual Note: The maximum sampling time allowed is < 7 CK_ADC cycles to avoid the overlap between ADC0 and ADC1 sampling phases in the event that they convert the same channel. Figure 14-15. Routine follow-up fast mode on 1 channel in continuous operation mode 7 ADCCLK cycles ·...
GD32A513 User Manual ADC interrupts 14.6. The interrupt can be produced on one of the events: End of conversion for routine sequence. The analog watchdog 0/1 event. Separate interrupt enable bits are available for flexibility. The interrupts of ADC0 and ADC1 are mapped into the same interrupt vector IRQ18.
GD32A513 User Manual Register definition 14.7. ADC0 base address: 0x4001 2400 ADC1 base address: 0x4001 2800 Status register (ADC_STAT) 14.7.1. Address offset: 0x00 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved WDE1 Reserved rc_w0...
GD32A513 User Manual 1: Analog watchdog 0 event is happening Set by hardware when the converted voltage crosses the values programmed in the ADC_WDLT0 and ADC_WDHT0 registers. Cleared by software writing 0 to it. Control register 0 (ADC_CTL0) 14.7.2. Address offset: 0x04 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 285
GD32A513 User Manual Reserved Must be kept at reset value. DISRC Discontinuous mode on routine sequence 0: Discontinuous operation mode on routine sequence disable 1: Discontinuous operation mode on routine sequence enable Reserved Must be kept at reset value. WD0SC When in scan mode, analog watchdog 0 is effective on a single channel.
GD32A513 User Manual the temperature sensor, and to V inputs. REFINT ADC1 analog inputs Channel16, and Channel17 are internally connected to Control register 1 (ADC_CTL1) 14.7.3. Address offset: 0x08 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
GD32A513 User Manual 1: MSB alignment 10:9 Reserved Must be kept at reset value. DMA request enable 0: DMA request disable 1: DMA request enable Note: This bit is only used in ADC0. Reserved Must be kept at reset value.
GD32A513 User Manual Bits Fields Descriptions 31:24 Reserved Must be kept at reset value. 23:21 SPT17[2:0] Refer to SPT10[2:0] description 20:18 SPT16[2:0] Refer to SPT10[2:0] description 17:15 SPT15[2:0] Refer to SPT10[2:0] description 14:12 SPT14[2:0] Refer to SPT10[2:0] description 11:9 SPT13[2:0]...
GD32A513 User Manual This register has to be accessed by word (32-bit). Reserved Reserved WDLT0[11:0] Bits Fields Descriptions 31:12 Reserved Must be kept at reset value. 11:0 WDLT0[11:0] Low threshold for analog watchdog 0 These bits define the low threshold for the analog watchdog 0.
GD32A513 User Manual This register has to be accessed by word (32-bit). Reserved RSQ11[4:0] RSQ10[4:0] RSQ9[4:1] RSQ9[0] RSQ8[4:0] RSQ7[4:0] RSQ6[4:0] Bits Fields Descriptions 31:30 Reserved Must be kept at reset value. 29:25 RSQ11[4:0] Refer to RSQ0[4:0] description 24:20 RSQ10[4:0] Refer to RSQ0[4:0] description...
GD32A513 User Manual RSQ0[4:0] The channel number (0..17) is written to these bits to select a channel as the nth conversion in the routine sequence. Routine data register (ADC_RDATA) 14.7.11. Address offset: 0x4C Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 293
GD32A513 User Manual 11: 6-bit 11:10 Reserved Must be kept at reset value. TOVS Triggered Oversampling This bit is set and cleared by software. 0: All oversampled conversions for a channel are done consecutively after a trigger. 1: Each conversion needs a trigger for an oversampled channel and the number of triggers is determined by the oversampling ratio (OVSR[2:0]).
GD32A513 User Manual Note: The software allows this bit to be written only when ADCON = 0 (this ensures that no conversion is in progress). Watchdog 1 channel selection register (ADC_WD1SR) 14.7.13. Address offset: 0xA0 Reset value: 0x00000000 This register has to be accessed by word (32-bit).
Page 295
GD32A513 User Manual Bits Fields Descriptions 31:24 Reserved Must be kept at reset value. 23:16 WDHT1[7:0] High threshold for analog watchdog 1 These bits define the high threshold for the analog watchdog 1. Note: Software is allowed to write these bits only when the ADC is disabled (ADCON =0).
GD32A513 User Manual Digital-to-analog converter (DAC) Overview 15.1. The Digital-to-analog converter converts 12-bit digital data to a voltage on the external pins. The digital data can be configured to 8-bit or 12-bit mode, left-aligned or right-aligned mode. DMA can be used to update the digital data on external triggers.
GD32A513 User Manual Table 15-1. DAC I/O description Name Description Signal type Analog power supply Input, analog supply Ground for analog power supply Input, analog supply ground Positive reference voltage of DAC Input, analog positive reference REFP DACy_OUTx DAC analog output Analog output signal The below table details the triggers and outputs of the DAC.
GD32A513 User Manual is loaded by DAC_OUTx_R8DH register, only the MSB 8 bits are configurable, the LSB 4 bits are forced to 4’b0000. DAC trigger 15.3.4. The DAC conversion can be triggered by software or rising edge of external trigger source.
GD32A513 User Manual Figure 15-2. DAC LFSR algorithm Triangle noise mode: a triangle signal is added to the OUTx_DH value, and then the result is stored into the DAC_OUTx_DO register. The minimum value of the triangle signal is 0, while the maximum value of the triangle signal is (2 <<...
Page 300
GD32A513 User Manual If the second external trigger arrives before confirming the previous request, the new request will not be serviced, and an underrun error event occurs. The DDUDRx bit in the DAC_STAT0 register is set, an interrupt will be generated if the DDUDRIEx bit in the DAC_CTL0 register...
GD32A513 User Manual Register definition 15.4. DAC0 base address: 0x4000 7400 DACx control register 0 (DAC_CTL0) 15.4.1. Address offset: 0x00 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved DDUDR DDMA Reserved DDISC0 DWBW0[3:0] DWM0[1:0]...
GD32A513 User Manual 0110: The bit width of the wave signal is 7 0111: The bit width of the wave signal is 8 1000: The bit width of the wave signal is 9 1001: The bit width of the wave signal is 10 1010: The bit width of the wave signal is 11 ≥1011: The bit width of the wave signal is 12...
GD32A513 User Manual Bits Fields Descriptions 31:1 Reserved Must be kept at reset value. SWTR0 DACx_OUT0 software trigger, cleared by hardware. 0: Software trigger disabled 1: Software trigger enabled DACx_OUT0 12-bit right-aligned data holding register 15.4.3. (DAC_OUT0_R12DH) Address offset: 0x08 Reset value: 0x0000 0000 This register has to be accessed by word(32-bit).
GD32A513 User Manual Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:4 OUT0_DH[11:0] DACx_OUT0 12-bit left-aligned data. These bits specify the data that is to be converted by DACx_OUT0. Reserved Must be kept at reset value. DACx_OUT0 8-bit right-aligned data holding register (DAC_OUT0_R8DH) 15.4.5.
GD32A513 User Manual DACx_OUT0. DACx status register 0 (DAC_STAT0) 15.4.7. Address offset: 0x18 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit) Reserved Reserved DDUDR0 Reserved rc_w1 Bits Fields Descriptions 31:14 Reserved Must be kept at reset value.
GD32A513 User Manual Watchdog timer (WDGT) The watchdog timer (WDGT) is a hardware timing circuitry that can be used to detect system failures due to software malfunctions. There are two watchdog timer peripherals in the chip: free watchdog timer (FWDGT) and window watchdog timer (WWDGT). They offer a combination of a high safety level, flexibility of use and timing accuracy.
GD32A513 User Manual Figure 16-1. Free watchdog block diagram Status: PUD 12-Bit Reset IRC40K Prescaler DownCounter /4/8 256 Reload Control register Reload Status: RUD register The free watchdog is enabled by writing the value (0xCCCC) to the control register (FWDGT_CTL), then counter starts counting down. When the counter reaches the value (0x000), there will be a reset.
GD32A513 User Manual Register definition 16.1.4. FWDGT base address: 0x4000 3000 Control register (FWDGT_CTL) Address offset: 0x00 Reset value: 0x0000 0000 This register can be accessed by half-word (16-bit) or word (32-bit). Reserved CMD[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value.
Page 310
GD32A513 User Manual FWDGT_STAT register is set and the value read from this register is invalid. 000: 1 / 4 001: 1 / 8 010: 1 / 16 011: 1 / 32 100: 1 / 64 101: 1 / 128...
Page 311
GD32A513 User Manual Reset value: 0x0000 0000 This register can be accessed by half-word (16-bit) or word (32-bit). Reserved Reserved Bits Fields Descriptions 31:3 Reserved Must be kept at reset value. Watchdog counter window value update When a write operation to FWDGT_WND register ongoing, this bit is set and the value read from FWDGT_WND register is invalid.
Page 312
GD32A513 User Manual These bits are write protected. Write 0x5555 in the FWDGT_CTL register before writing these bits. If several window values are used by the application, it is mandatory to wait until WUD bit has been reset before changing the window value. However, after updating...
GD32A513 User Manual 16.2. Window watchdog timer (WWDGT) Overview 16.2.1. The window watchdog timer (WWDGT) is used to detect system failures due to software malfunctions. After the window watchdog timer starts, the value of down counter reduces progressively. The watchdog timer causes a reset when the counter reached 0x3F (the CNT[6] bit has been cleared).
GD32A513 User Manual The window watchdog timer is always disabled after power on reset. The software starts the watchdog by setting the WDGTEN bit in the WWDGT_CTL register. When window watchdog timer is enabled, the counter counts down all the time, the configured value of the counter should be greater than 0x3F(it implies that the CNT[6] bit should be set).
GD32A513 User Manual Register definition 16.2.4. WWDGT base address: 0x4000 2C00 Control register (WWDGT_CTL) Address offset: 0x00 Reset value: 0x0000 007F This register can be accessed by half-word (16-bit) or word (32-bit). Reserved Reserved WDGTEN CNT[6:0] Bits Fields Descriptions 31:8 Reserved Must be kept at reset value.
Page 317
GD32A513 User Manual WWDGTRST bit of the RCU module. A write operation of 0 has no effect. PSC[1:0] Prescaler. The time base of the watchdog counter 00: (PCLK1 / 4096) / 1 01: (PCLK1 / 4096) / 2 10: (PCLK1 / 4096) / 4...
GD32A513 User Manual Real-time clock (RTC) Overview 17.1. The RTC is usually used as a clock-calendar. The RTC circuits are located in two power supply domains. 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.
GD32A513 User Manual RTC configuration 17.3.3. The RTC_PSC, RTC_CNT and RTC_ALRM registers in the RTC core are writable. These registers’ value can be set only when the peripheral enter configuration mode. And the CMF bit in the RTC_CTL register is used to indicate the configuration mode status. The write operation executes when the peripheral exit configuration mode, and it takes at least three RTCCLK cycles to complete.
GD32A513 User Manual Figure 17-2. RTC second and alarm waveform example (RTC_PSC = 3, RTC_ALRM = 2) Figure 17-3. RTC second and overflow waveform example (RTC_PSC= 3) RTCCLK RTC_ PSC RTC_Second FFFFFFFD FFFFFFFE FFFFFFFF RTC_ CNT RTC_ Overflow OVIF OVIF flag can be cleared by software...
GD32A513 User Manual Register definition 17.4. RTC base address: 0x4000 2800 RTC interrupt enable register (RTC_INTEN) 17.4.1. Address offset: 0x00 Reset value: 0x0000 0000 This register can be accessed by half-word (16-bit) or word (32-bit). Reserved Reserved OVIE ALRMIE SCIE...
GD32A513 User Manual 31:6 Reserved Must be kept at reset value. LWOFF Last write operation finished flag 0: Last write operation on RTC registers did not finished. 1: Last write operation on RTC registers finished. Configuration mode flag 0: Exit configuration mode.
GD32A513 User Manual PSC[19:16] RTC prescaler value high RTC prescaler low register (RTC_PSCL) 17.4.4. Address offset: 0x0C Reset value: 0x0000 8000 This register can be accessed by half-word (16-bit) or word (32-bit). Reserved PSC[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value.
GD32A513 User Manual DIV[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:0 DIV[15:0] RTC divider value low The RTC divider register is reloaded by hardware when the RTC prescaler or RTC counter register updated. RTC counter high register (RTC_CNTH) 17.4.7.
GD32A513 User Manual RTC alarm high register (RTC_ALRMH) 17.4.9. Address offset: 0x20 Reset value: 0x0000 FFFF This register can be accessed by half-word (16-bit) or word (32-bit). Reserved ALRM[31:16] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value.
GD32A513 User Manual 18.1. Advanced timer (TIMERx, x=0, 7, 19, 20) Overview 18.1.1. The advanced timer module (TIMER0/7/19/20) is a eight-channel timer that supports both input capture and output compare. They can generate PWM signals to control motor or be used for power management applications.
GD32A513 User Manual Block diagram 18.1.3. Figure 18-1. Advanced timer block diagram provides details of the internal configuration of the advanced timer, and Table 18-2. Advanced timer channel description introduces the input and output of the channels. Figure 18-1. Advanced timer block diagram...
GD32A513 User Manual The default clock source is the CK_TIMER for driving the counter prescaler when the SMC[2:0] = 3’b000. When the CEN is set, the CK_TIMER will be divided by PSC value to generate PSC_CLK. In this mode, the TIMER_CK which drives counter’s prescaler to count is equal to CK_TIMER which is from RCU module.
GD32A513 User Manual pulse on each ETI signal rising edge to clock the counter prescaler. Note: The ETI pin can select from TIMER_ETIx(x=0..2) pins, and each advanced TIMER only can use one of them. Plese refer to TIMER input source select register (SYSCFG_TIMERINSEL) for more details.
GD32A513 User Manual If the UPDIS bit in TIMERx_CTL0 register is set, the update event is disabled. When an update event occurs, all the shadow registers (repetition counter register, counter auto reload register, prescaler register) are updated. Figure 18-4. Timing chart of up counting mode, PSC=0/2 Figure 18-5.
GD32A513 User Manual Figure 18-5. Timing chart of up counting mode, change TIMERx_CAR on the go TIMER_CK PSC_CLK ARSE = 0 CNT_REG Update event (UPE) Hardware set Update interrupt flag (UPIF) Auto-reload register change CAR Vaule ARSE = 1 CNT_REG...
GD32A513 User Manual the counter behavior in different clock frequencies when TIMERx_CAR = 0x99. Figure 18-6. Timing chart of down counting mode, PSC=0/2 TIMER_CK PSC = 0 PSC_CLK CNT_REG Update event (UPE) Hardware set Update interrupt flag (UPIF) PSC = 2...
Page 335
GD32A513 User Manual Counter center-aligned counting In this mode, the counter counts up from 0 to the counter-reload value and then counts down to 0 alternatively. The Timer module generates an overflow event when the counter counts to the counter-reload value subtract 1 in the up-counting direction and generates an underflow event when the counter counts to 1 in the down-counting direction.
GD32A513 User Manual If an update event is generated by software after writing an odd number to CREP, the update events will be generated on the underflow. If the next update event occurs on overflow after writing an odd number to CREP, then the subsequent update events will be generated on the overflow.
GD32A513 User Manual Figure 18-11. Repetition counter timing chart of down counting mode TIMER_CK PSC_CLK CNT_REG Underflow Overflow TIMERx_CREP = 0x0 UPIF TIMERx_CREP = 0x1 UPIF TIMERx_CREP = 0x2 UPIF Input capture and output compare channels The advanced timer has eight independent channels which can be used as capture inputs or compare outputs.
GD32A513 User Manual capture signal can also be selected from the input signal of other channel or the internal trigger signal by configuring CHxMS/ MCHxMS bits. The IC prescaler makes several input events generate one effective capture event. On the capture event, TIMERx_CHxCV/ TIMERx_MCHxCV will store the value of counter.
Page 342
GD32A513 User Manual output level of CHx_O and MCHx_O depends on OxCPRE signal, CHxP bit and CHxEN bit.. It is invalid for the configuration of MCHx_O. Please refer to Figure 18-15. Channel output compare principle (when MCHxMSEL = 2’01, x=0, 1, 2, ...
GD32A513 User Manual Figure 18-17. Output-compare under three modes shows the three compare modes: toggle/set/clear. CARL=0x63, CHxVAL=0x3. Figure 18-17. Output-compare under three modes CNT_CLK …. …. …. CNT_REG 03 04 03 04 03 04 Overflow match toggle OxCPRE match set...
GD32A513 User Manual Figure 18-18. EAPWM timechart CARL CHxVAL OxCPRE OxCPRE CHxIF CHxOF Figure 18-19. CAPWM timechart CARL CHxVAL PWM MODE0 OxCPRE PWM MODE1 OxCPRE Interrupt signal CAM=2'b01 down only CHxIF CHxOF CAM=2'b10 up only CHxIF CHxOF CAM=2'b11 up/down CHxIF...
GD32A513 User Manual If CHxCOMCTL = 3’b111 (PWM mode 1) and DIR = 1’b0 (up counting mode), or CHxCOMCTL = 3’b110 (PWM mode 0) and DIR = 1’b1 (down counting mode) the channel x output is forced high when the counter matches the value of CHxVAL. It is forced low when the counter matches the value of CHxCOMVAL_ADD.
GD32A513 User Manual next counter next counter period period If more than one channels are configured in composite PWM mode, it is possible to fix an offset for the channel x match edge of each pair with respect to other channels. This behavior is useful in the generation of lighting PWM control signals where it is desirable that edges are not coincident with each other pair to help eliminate noise generation.
GD32A513 User Manual CHxOMPSEL = 2’b00, the OxCPRE signal is output normally with the configuration of CHxCOMCTL[2:0] bits; CHxOMPSEL = 2’b01, only the counter is counting up, the OxCPRE signal is output a pulse when the match events occur, and the pulse width is one CK_TIMER clock cycle.
Page 350
GD32A513 User Manual Channel output prepare signal Figure 18-14. Channel output compare principle (when MCHxMSEL = 2’00, As is shown in x=0, 1, 2, 3) Figure 18-16. Channel output compare principle (with complementary output when MCHxMSEL = 2’11, x=0,1,2,3), when TIMERx is configured in compare match output mode, a middle signal named OxCPRE or MOxCPRE (channel x output or multi mode channel x output prepare signal) will be generated before the channel outputs signal.
GD32A513 User Manual =2’b11)), ISOx and Complementary outputs controlled by parameters (MCHxMSEL ISOxN bits in the TIMERx_CTL1 register. The output polarity is determined by CHxP and MCHxP bits in the TIMERx_CHCTL2 register. Table 18-4. Complementary outputs controlled by parameters (MCHxMSEL =2’b11)
GD32A513 User Manual (4) ⊕: Xor calculate. (5) (!OxCPRE):the complementary output of the OxCPRE signal. Insertion dead time for complementary PWM The dead time insertion is enabled when MCHxMSEL=2’b11 and both CHxEN and MCHxEN are configured to 1’b1, it is also necessary to configure POEN to 1. The field named DTCFG defines the dead time delay that can be used for all channels.
GD32A513 User Manual independent control of dead-time insertion function for each pair of channels. When the DTIENCHx(x=0..3) bit is “0”, the corresponding channels CHx_O and CHx_ON will not be inserted into the dead-time. Break mode In this function, CHx_O and MCHx_O are controlled by the POEN, OAEN, IOS and ROS bits in the TIMERx_CCHP register, ISOx and ISOxN bits in the TIMERx_CTL1 register.
GD32A513 User Manual As soon as POEN is 0, the level of the CHx_O and MCHx_O outputs are determined by the ISOx and ISOxN bits in the TIMERx_CTL1 register. If IOS = 0, the timer releases the enable output, otherwise, the enable output remains high. The complementary outputs are first in the reset state, and then the dead time generator is reactivated to drive the outputs with the level programmed in the ISOx and ISOxN bits after a dead time.
GD32A513 User Manual function. When the FCCHPyEN=0, the ROS、IOS and DTCFG[7:0] bits in TIMERx_CCHP register is active; When the FCCHPyEN=1, the ROS 、 IOS and DTCFG[7:0] bits in TIMERx_FCCHP0 register is active. Quadrature decoder The quadrature decoder function uses two quadrature inputs CI0FE0 and CI1FE1 derived from the TIMERx_CH0 and TIMERx_CH1 pins respectively to interact with each other to generate the counter value.
GD32A513 User Manual Figure 18-32. Counter behavior with CI0FE0 polarity inverted in mode 2 Hall sensor function Hall sensor is generally used to control BLDC motor, the timers can support this function. Figure 18-33. Hall sensor is used for BLDC motor shows how to connect the timer and the motor.
GD32A513 User Manual Figure 18-33. Hall sensor is used for BLDC motor Hall Sensor Rotor Position signals TIMER_in Input capture Driver Motor GPIO Core TIMER_out BLDC Motor Output compare PWM output Figure 18-34. Hall sensor timing between two timers Advanced/General L0 TIMER_in under input capture mode...
GD32A513 User Manual Master-slave management The TIMERx can be synchronized with a trigger in several modes including restart mode, pause mode and event mode which is selected by the SMC[2:0] bits in the TIMERx_SMCFG register. The input trigger of these modes can be selected by the TRGS[3:0] bits in the TIMERx_SMCFG register.
GD32A513 User Manual Mode Selection Source Selection Polarity Selection Filter and Prescaler and it will start when event will occur on the the trigger input is rising edge only. high. Figure 18-36. Pause mode TIMER_CK CNT_REG CI0FE0 TRGIF Event mode...
GD32A513 User Manual update event occurs or the CEN bit is written to 0 by software. If the CEN bit is cleared to 0 by software, the counter will be stopped and its value will be held. In the single pulse mode, the active edge of trigger which sets the CEN bit to 1 will enable the counter.
GD32A513 User Manual (MMC=3’b001 in the TIMER1_CTL1 register). 2. Select TIMER1 as TIMER0 input trigger source (TRGS=3’b010 in the TIMERx_SMCFG register). 3. Configure TIMER0 in event mode (SMC=3’b110 in TIMERx_SMCFG register). 4. Start TIMER1 by writing 1 to the CEN bit (TIMER1_CTL0 register).
GD32A513 User Manual Figure 18-41. Triggering TIMER0 and TIMER1 with TIMER1’s CI0 input TIMER1 TIMER_CK TRGIF CNT_REG TIMER0 TRGIF CNT_CK CNT_REG Timer DMA mode Timer DMA mode is the function that configures timer’s register by DMA module. The relative registers are TIMERx_DMACFG and TIMERx_DMATB. Corresponding DMA request bit should be asserted to enable DMA request for internal interrupt event.
GD32A513 User Manual Registers definition (TIMERx, x=0, 7, 19, 20) 18.1.5. TIMER0 base address: 0x4001 2C00 TIMER7 base address: 0x4001 3400 TIMER19 base address: 0x4001 5000 TIMER20 base address: 0x4001 5400 Control register 0 (TIMERx_CTL0) Address offset: 0x00 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 365
GD32A513 User Manual 11: Center-aligned and counting up/down assert mode. The counter counts in center-aligned mode and channel is configured in output mode (CHxMS = 3’b000 in TIMERx_CHCTL0 register). Both when counting up and counting down, the CHxF bit can be set.
Page 366
GD32A513 User Manual Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved ISO3N ISO3 ISO2N ISO2 ISO1N ISO1 ISO0N ISO0 TI0S MMC[2:0] DMAS CCUC Reserved CCSE Bits Fields Descriptions 31:16 Reserved Must be kept at reset value.
Page 367
GD32A513 User Manual slave timers for synchronization function. 000: When a counter reset event occurs, a TRGO trigger signal is output. The counter resert source: Master timer generate a reset the UPG bit in the TIMERx_SWEVG register is set 001: Enable. When a conter start event occurs, a TRGO trigger signal is output. The...
Page 368
GD32A513 User Manual Slave mode configuration register (TIMERx_SMCFG) Address offset: 0x08 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). TRGS[3] Reserved SMC1 ETPSC[1:0] ETFC[3:0] TRGS[2:0] Reserved SMC[2:0] Bits Fields Descriptions TRGS[3] Trigger selection. Refer to TRGS[2:0] description.
Page 369
GD32A513 User Manual filtering capability. Basic principle of digital filter: continuously sample the external trigger signal according to f and record the number of times of the same level of the signal. SAMP After reaching the filtering capacity configured by this bit-field, it is considered to be an effective level.
Page 370
GD32A513 User Manual 1010:The filtered output of multi mode channel 0 input (MCI0FEM0) 1011:The filtered output of multi mode channel 1 input (MCI1FEM1) 1100:The filtered output of multi mode channel 2 input (MCI2FEM2) 1101:The filtered output of multi mode channel 3 input (MCI3FEM3) 1110:Reserved...
Page 371
GD32A513 User Manual Note: This bit just used in composite PWM mode (when CH3CPWMEN=1, CH3MS[2:0] = 3’b000 and CH3COMCTL=3’b110 or 3’b111). CH2COMADDIE Channel 2 additional compare interrupt enable 0: Disabled 1: Enabled Note: This bit just used in composite PWM mode (when CH2CPWMEN=1, CH2MS[2:0] = 3’b000 and CH2COMCTL=3’b110 or 3’b111).
Page 372
GD32A513 User Manual Note: This bit just used for channel input and output independent mode (when MCH3MSEL[1:0] = 2b’00). MCH2IE Multi mode channel 2 capture/compare interrupt enable 0: Disabled 1: Enabled Note: This bit just used for channel input and output independent mode (when MCH2MSEL[1:0] = 2b’00).
Page 375
GD32A513 User Manual TIMERx_MCH0CV. 0: No multi mode channel 0 capture/compare interrupt occurred 1: Multi mode channel 0 capture/compare interrupt occurred 19:13 Reserved Must be kept at reset value. CH3OF Channel 3 over capture flag Refer to CH0OF description CH2OF...
Page 376
GD32A513 User Manual Refer to CH0IF description CH0IF Channel 0 capture/compare interrupt flag This flag is set by hardware and cleared by software. If channel 0 is in input mode, this flag is set when a capture event occurs. If channel 0 is in output mode, this flag is set when a compare event occurs.
Page 377
GD32A513 User Manual Note: This bit just used in composite PWM mode (when CH0CPWMEN=1, CH0MS[2:0] = 3’b000 and CH0COMCTL=3’b110 or 3’b111). 27:24 Reserved Must be kept at reset value. MCH3G Multi mode channel 3 capture or compare event generation. Refer to MCH0G description.
Page 378
GD32A513 User Manual Refer to CH0G description CH2G Channel 2 capture or compare event generation Refer to CH0G description CH1G Channel 1 capture or compare event generation Refer to CH0G description CH0G Channel 0 capture or compare event generation This bit is set by software to generate a capture or compare event in channel 0, it is automatically cleared by hardware.
Page 379
GD32A513 User Manual Refer to CH1MS[1:0]description CH0MS[2] Channel 0 I/O mode selection Refer to CH0MS[1:0] description CH1COMADDSEN Channel 1 additional compare output shadow enable Refer to CH0COMADDSEN description. CH0COMADDSEN Channel 0 additional compare output shadow enable When this bit is set, the shadow register of TIMERx_CH0COMV_ADD register which updates at each update event will be enabled.
Page 380
GD32A513 User Manual 0: Channel 0 output compare clear disabled 1: Channel 0 output compare clear enabled CH0COMCTL[2:0] Channel 0 compare output control This bit-field controls the behavior of O0CPRE which drives CH0_O. The active level of O0CPRE is high, while the active level of CH0_O depends on CH0P bit.
Page 381
GD32A513 User Manual This bit cannot be modified when PROT[1:0] bit-field in TIMERx_CCHP register is 11 and CH0MS bit-field is 000. Reserved Must be kept at reset value. CH0MS[1:0] Channel 0 I/O mode selection This bit-field specifies the work mode of the channel and the input signal selection.
Page 382
GD32A513 User Manual CH0CAPFLT [3:0] Times SAMP 4’b0000 Filter disabled. 4’b0001 4’b0010 CK_TIMER 4’b0011 4’b0100 4’b0101 4’b0110 4’b0111 4’b1000 4’b1001 4’b1010 4’b1011 4’b1100 4’b1101 4’b1110 4’b1111 CH0CAPPSC[1:0] Channel 0 input capture prescaler This bit-field specifies the factor of the prescaler on channel 0 input. The prescaler is reset when CH0EN bit in TIMERx_CHCTL2 register is cleared.
Page 384
GD32A513 User Manual CH2COMCEN Channel 2 output compare clear enable. When this bit is set, if the ETIFP signal is detected as high level, the O2CPRE signal will be cleared. 0: Channel 2 output compare clear disabled 1: Channel 2 output compare clear enabled...
Page 385
GD32A513 User Manual CH2COMSEN Channel 2 compare output shadow enable When this bit is set, the shadow register of TIMERx_CH2CV register, which updates at each update event will be enabled. 0: Channel 2 output compare shadow disabled 1: Channel 2 output compare shadow enabled The PWM mode can be used without verifying the shadow register only in single pulse mode (when SPM=1).
Page 386
GD32A513 User Manual The CI2 input signal can be filtered by digital filter and this bit-field configure the filtering capability. Basic principle of digital filter: continuously sample the CI2 input signal according to and record the number of times of the same level of the signal. After reaching SAMP the filtering capacity configured by this bit, it is considered to be an effective level.
Page 387
GD32A513 User Manual MCH3P MCH3EN CH3P CH3EN MCH2P MCH2EN CH2P CH2EN MCH1P MCH1EN CH1P CH1EN MCH0P MCH0EN CH0P CH0EN Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. MCH3P Multi mode channel 3 capture/compare polarity Refer to MCH0P description.
Page 388
GD32A513 User Manual 11 or 10. MCH0EN Multi mode channel 0 capture/compare enable When multi mode channel 0 is configured in output mode, setting this bit enables MCH0_O signal in active state. When multi mode channel 0 is configured in input mode, setting this bit enables the capture event in multi mode channel 0.
Page 389
GD32A513 User Manual Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:0 CNT[15:0] This bit-field indicates the current counter value. Writing to this bit-field can change the value of the counter. Prescaler register (TIMERx_PSC) Address offset: 0x28 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 390
GD32A513 User Manual Note: When the timer is configured in input capture mode, this register must be configured a non-zero value (such as 0xFFFF) which is larger than user expected value. Counter repetition register (TIMERx_CREP) Address offset: 0x30 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 391
GD32A513 User Manual When channel 0 is configured in output mode, this bit-field contains value to be compared to the counter. When the corresponding shadow register is enabled, the shadow register updates by every update event. Channel 1 capture/compare value register (TIMERx_CH1CV)
Page 392
GD32A513 User Manual at the last capture event. And this bit-field is read-only. When channel 2 is configured in output mode, this bit-field contains value to be compared to the counter. When the corresponding shadow register is enabled, the shadow register updates by every update event.
Page 393
GD32A513 User Manual The bit can be set to 1 by: - Write 1 to this bit - If OAEN is set to 1, this bit is set to 1 at the next update event. The bit can be cleared to 0 by: - Write 0 to this bit - Valid fault input.
Page 394
GD32A513 User Manual When POEN bit is reset (Idle mode), this bit can be set to enable the “off-state” for the channels which has been configured in output mode. Please refer to Table 18-4. =2’b11). Complementary outputs controlled by parameters (MCHxMSEL 0: “off-state”...
Page 395
GD32A513 User Manual Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). MCH1 MCH0 Reserved MS[2] MS[2] MCH1CO MCH1CO MCH0CO MCH0CO MCH1COMCTL[2:0] Reserved MCH0COMCTL[2:0] Reserved MCEN MSEN MCEN MSEN MCH1MS[1:0] MCH0MS[1:0] MCH1CAPPSC MCH0CAPPSC MCH1CAPFLT[3:0] MCH0CAPFLT[3:0] [1:0]...
Page 396
GD32A513 User Manual 101~111: Reserved. MCH0COMCEN Multi mode channel 0 output compare clear enable. When this bit is set, if the ETIFP signal is detected as high level, the MO0CPRE signal will be cleared. 0: Multi mode channel 0 output compare clear disabled.
Page 397
GD32A513 User Manual 0: Multi mode channel 0 output compare shadow disabled 1: Multi mode channel 0 output compare shadow enabled The PWM mode can be used without verifying the shadow register only in single pulse mode (when SPM=1). This bit cannot be modified when PROT[1:0] bit-field in TIMERx_CCHP register is 11 and MCH0MS bit-field is 00.
Page 398
GD32A513 User Manual reaching the filtering capacity configured by this bit, it is considered to be an effective level. The filtering capability configuration is as follows: MCH0CAPFLT[3:0] Times SAMP 4’b0000 Filter disabled. 4’b0001 4’b0010 TIMER_CK 4’b0011 4’b0100 4’b0101 4’b0110 4’b0111 4’b1000...
Page 399
GD32A513 User Manual MCH3CAPFLT[3:0] MCH3CAPPSC[1:0] MCH2CAPFLT[3:0] MCH2CAPPSC[1:0] Output compare mode: Bits Fields Descriptions MCH3MS[2] Multi mode channel 1 I/O mode selection Refer to MCH3MS[1:0]description. MCH2MS[2] Multi mode channel 0 I/O mode selection Refer to MCH2MS[1:0] description. 29:16 Reserved Must be kept at reset value.
Page 400
GD32A513 User Manual Note: When multi mode channel 2 is configured in output mode, and the MCH2MSEL[1:0] = 2b’11, the CH2COMCTL[2:0] bit-field controls the behavior of O2CPRE which drives CH2_O and MCH2_O, while the active level of CH2_O and MCH2_O depends on CH2P and MCH2P bits.
Page 401
GD32A513 User Manual 000: Multi mode channel 2 is programmed as output. 001: Multi mode channel 2 is programmed as input, MIS2 is connected to MCI2FEM2. 010: Multi mode channel 2 is programmed as input, MIS2 is connected to MCI3FEM2.
Page 402
GD32A513 User Manual 4’b0111 4’b1000 4’b1001 4’b1010 4’b1011 4’b1100 4’b1101 4’b1110 4’b1111 MCH2CAPPSC[1:0] Multi mode channel 2 input capture prescaler. This bit-field specifies the factor of the prescaler on channel 2 input. The prescaler is reset when MCH2EN bit in TIMERx_CHCTL2 register is cleared.
Page 403
GD32A513 User Manual When multi mode channel 0 is configured in output mode, and the MCH0MSEL[1:0] = 2b’00, these bits specifie the multi mode channel 0 output signal polarity. 00: Multi mode channel 0 active high 01: Multi mode channel 0 active low 10: Reserved.
Page 404
GD32A513 User Manual Multi mode channel 1 capture/compare value register (TIMERx_MCH1CV) Address offset: 0x58 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved MCH1VAL[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value.
Page 405
GD32A513 User Manual Multi mode channel 3 capture/compare value register (TIMERx_MCH3CV) Address offset: 0x60 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved MCH3VAL[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value.
Page 406
GD32A513 User Manual Channel 1 additional compare value register (TIMERx_CH1COMV_ADD) Address offset: 0x68 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved CH1COMVAL_ADD[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:0...
Page 407
GD32A513 User Manual Channel 3 additional compare value register (TIMERx_CH3COMV_ADD) Address offset: 0x70 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved CH3COMVAL_ADD[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:0...
Page 409
GD32A513 User Manual 11: Both the counter is counting up and counting down, the O3CPRE signal is output a pulse when the match events occur, and the pulse width is one CK_TIMER clock cycle. 13:12 CH2OMPSEL[1:0] Channel 2 output match pulse select When the match events occurs, this bit is used to select the output of O2CPRE which drives CH2_O.
Page 410
GD32A513 User Manual BRKENCH3 Break control enable for channel 3 0: Disabled 1: Enabled BRKENCH2 Break control enable for channel 2 0: Disabled 1: Enabled BRKENCH1 Break control enable for channel 1 0: Disabled 1: Enabled BRKENCH0 Break control enable for channel 0...
Page 411
GD32A513 User Manual Bits Fields Descriptions BRK3P BRKIN3 input signal polarity This bit specifies the polarity of the BRKIN3 input signal. 0: BRKIN3 input active low 1: BRKIN3 input active high This bit can be modified only when PROT[1:0] bit-field in TIMERx_CCHP register is...
Page 412
GD32A513 User Manual 0: BRKIN0 input active low 1: BRKIN0 input active high This bit can be modified only when PROT[1:0] bit-field in TIMERx_CCHP register is BRK0EN BRKIN0 input signal enable This bit can be set to enable the BRKIN0 input.
Page 413
GD32A513 User Manual 0101: f /2, N=8 SAMP 0110: f /4, N=6 SAMP 0111: f /4, N=8 SAMP 1000: f /8, N=6 SAMP 1001: f /8, N=8 SAMP 1010: f /16, N=5 SAMP 1011: f /16, N=6 SAMP 1100: f...
Page 414
GD32A513 User Manual 0100: f /2, N=6 SAMP 0101: f /2, N=8 SAMP 0110: f /4, N=6 SAMP 0111: f /4, N=8 SAMP 1000: f /8, N=6 SAMP 1001: f /8, N=8 SAMP 1010: f /16, N=5 SAMP 1011: f...
Page 415
GD32A513 User Manual enabled, with relationship to CH0EN/MCH0EN bits in TIMERx_CHCTL2 register. This bit cannot be modified when PROT [1:0] bit-filed in TIMERx_CCHP register is 10 or 11. Idle mode off-state configure When POEN bit is reset, this bit specifies the output state for the channels which has been configured in output mode.
Page 416
GD32A513 User Manual 1: the ROS、IOS and DTCFG[7:0] bits in TIMERx_FCCHP1 register is active This bit can be modified only when PROT [1:0] bit-filed in TIMERx_CCHP register is 00. 30:12 Reserved Must be kept at reset value. Run mode off-state configure When POEN bit is set, this bit specifies the output state for the channels which has a complementary output and has been configured in output mode.
Page 417
GD32A513 User Manual FCCHP2 Reserved Reserved Reserved DTCFG[7:0] Bits Fields Descriptions FCCHP2EN Free complementary channel protection register 2 enable 0: the ROS、IOS and DTCFG[7:0] bits in TIMERx_CCHP register is active 1: the ROS、IOS and DTCFG[7:0] bits in TIMERx_FCCHP2 register is active This bit can be modified only when PROT [1:0] bit-filed in TIMERx_CCHP register is 00.
Page 418
GD32A513 User Manual DTCFG [7:5] =3’b111: DTvalue = (32+DTCFG [4:0])xt *16. This bit can be modified only when PROT [1:0] bit-filed in TIMERx_CCHP register is 00. Free complementary channel protection register 3 (TIMERx_FCCHP3) Address offset: 0x88 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 419
GD32A513 User Manual This bit cannot be modified when PROT [1:0] bit-filed in TIMERx_CCHP register is 10 or 11. Reserved Must be kept at reset value. DTCFG[7:0] Dead time configure This bit-field controls the value of the dead-time, which is inserted before the output transitions.
Page 420
GD32A513 User Manual DMA transfer buffer register (TIMERx_DMATB) Address offset: 0xE4 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved DMATB[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:0 DMATB[15:0] DMA transfer buffer...
Page 421
GD32A513 User Manual This bit-field is set and reset by software. 1: If POEN bit and IOS bit are 0, the output is disabled. 0: No effect.
GD32A513 User Manual 18.2. General level0 timer (TIMERx, x=1) Overview 18.2.1. The general level0 timer module (TIMER1) is a four-channel timer that supports input capture and output compare. They can generate PWM signals to control motor or be used for power management applications.
GD32A513 User Manual Figure 18-44. Timing chart of PSC value change from 0 to 2 TIMER_CK PSC value Prescaler shadow Prescaler CNT PSC_CLK CNT_REG Reload Pulse Counter up counting In this mode, the counter counts up continuously from 0 to the counter-reload value, which is defined in the TIMERx_CAR register, in a count-up direction.
GD32A513 User Manual Counter down counting In this mode, the counter counts down continuously from the counter-reload value, which is defined in the TIMERx_CAR register, to 0 in a count-down direction. Once the counter reaches to 0, the counter will start counting down from the counter-reload value. The update event is generated at each counter underflow.
GD32A513 User Manual Figure 18-48. Timing chart of down counting mode, change TIMERx_CAR on the go TIMER_CK PSC_CLK ARSE = 0 CNT_REG Update event (UPE) Hardware set Update interrupt flag (UPIF) Auto-reload register change CAR Vaule ARSE = 1 CNT_REG...
GD32A513 User Manual Figure 18-49. Timing chart of center-aligned counting mode shows the example of the counter behavior when TIMERx_CAR=0x99, TIMERx_PSC=0x0. Figure 18-49. Timing chart of center-aligned counting mode TIMER_CK PSC_CLK CNT_REG Underflow Overflow UPIF CHxCV=2 TIMERx_CTL0 CAM = 2'b11...
GD32A513 User Manual The channel input capture function can be also used for pulse width measurement from signals on the TIMERx_CHx pins. For example, PWM signal connects to CI0 input. Select CI0 as channel 0 capture signals by setting CH0MS to 2’b01 in the channel control register (TIMERx_CHCTL0) and set capture on rising edge.
GD32A513 User Manual Step3: Interrupt/DMA-request enables configuration by CHxIE/CHxDEN. Step4: Compare output timing configuration by TIMERx_CAR and TIMERx_CHxCV. The TIMERx_CHxCV can be changed onging to meet the expected waveform. Step5: Start the counter by configuring CEN to 1. Figure 18-52. Output-compare under three modes shows the three compare modes toggle/set/clear.
GD32A513 User Manual TIMERx_CAR, the output will be always active in PWM mode 0 (CHxCOMCTL=3’b110). And if the value of TIMERx_CHxCV is greater than the value of TIMERx_CAR, the output will be always inactive in PWM mode 1 (CHxCOMCTL=3’b111). Figure 18-53. EAPWM timechart...
GD32A513 User Manual setting to low by configuring the CHxCOMCTL field to 0x02 or toggling signal by configuring the CHxCOMCTL field to 0x03 when the counter value matches the content of the TIMERx_CHxCV register. The PWM mode 0/PWM mode 1 output is another output type of OxCPRE which is setup by configuring the CHxCOMCTL field to 0x06/0x07.
GD32A513 User Manual Mode Selection Source Selection Polarity Selection Filter and Prescaler 101: CI0FE0 If ETIFP (the filtered prescaler can be used. 110: CI1FE1 output external For the ETIFP, filter can 111: ETIFP trigger input ETI) is be used by configuring...
GD32A513 User Manual Mode Selection Source Selection Polarity Selection Filter and Prescaler The counter will start ETIFP is selected. ETI does not change. divided by 2. to count when a rising ETFC = 0, ETI does not edge of trigger input filter.
GD32A513 User Manual Figure 18-60. Single pulse mode TIMERx_CHxCV = 0x04, TIMERx_CAR=0x99 Timers interconnection Refer to Advanced timer (TIMERx, x=0, 7, 19, 20)Timers interconnection. Timer DMA mode Timer DMA mode is the function that configures timer’s register by DMA module. The relative Corresponding registers are TIMERx_DMACFG and TIMERx_DMATB.
GD32A513 User Manual Registers definition (TIMERx, x=1) 18.2.5. TIMER1 base address: 0x4000 0000 Control register 0 (TIMERx_CTL0) Address offset: 0x00 Reset value: 0x0000 0000 This register can be accessed by half-word (16-bit) or word (32-bit). Reserved Reserved CKDIV[1:0] ARSE CAM[1:0]...
Page 440
GD32A513 User Manual After the counter is enabled, these bits cannot be switched from 0x00 to non 0x00. Direction 0: Count up 1: Count down If the timer work in center-aligned mode or decoder mode, this bit is read only.
Page 441
GD32A513 User Manual Reserved Reserved TI0S MMC[2:0] DMAS Reserved Bits Fields Descriptions 31:8 Reserved Must be kept at reset value. TI0S Channel 0 trigger input selection 0: The TIMERx_CH0 pin input is selected as channel 0 trigger input. 1: The result of combinational XOR of TIMERx_CH0, TIMERx_CH1 and TIMERx_CH2 pins is selected as channel 0 trigger input.
Page 442
GD32A513 User Manual Reserved Must be kept at reset value. Slave mode configuration register (TIMERx_SMCFG) Address offset: 0x08 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved SMC1 ETPSC[1:0] ETFC[3:0] TRGS[2:0] Reserved SMC[2:0] Bits Fields...
Page 443
GD32A513 User Manual filtering capability. Basic principle of digital filter: continuously sample the external trigger signal according to f and record the number of times of the same level of the signal. SAMP After reaching the filtering capacity configured by this bit-field, it is considered to be an effective level.
Page 444
GD32A513 User Manual Reserved Must be kept at reset value. SMC[2:0] Slave mode control 000: Disable slave mode. The slave mode is disabled; The prescaler is clocked directly by the internal clock (TIMER_CK) when CEN bit is set high. 001: Quadrature decoder mode 0. The counter counts on CI0FE0 edge, while the direction depends on CI1FE1 level.
Page 446
GD32A513 User Manual Reserved Reserved CH3OF CH2OF CH1OF CH0OF Reserved TRGIF Reserved CH3IF CH2IF CH1IF CH0IF UPIF rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 rc_w0 Bits Fields Descriptions 31:13 Reserved Must be kept at reset value. CH3OF Channel 3 over capture flag...
Page 447
GD32A513 User Manual 0 is in output mode, this flag is set when a compare event occurs. If channel 0 is set to input mode, this bit will be reset by reading TIMERx_CH0CV. 0: No channel 0 interrupt occurred 1: Channel 0 interrupt occurred...
Page 448
GD32A513 User Manual and the corresponding interrupt or DMA request will be sent if enabled. In addition, if channel 0 is configured in input mode, the current value of the counter is captured to TIMERx_CH0CV register, and the CH0OF flag is set if the CH0IF flag has been set.
Page 449
GD32A513 User Manual 00: Channel 1 is programmed as output. 01: Channel 1 is programmed as input, IS1 is connected to CI1FE1. 10: Channel 1 is programmed as input, IS1 is connected to CI0FE1. 11: Channel 1 is programmed as input, IS1 is connected to ITS. This mode is working only if an internal trigger input is selected (through TRGS bits in TIMERx_SMCFG register).
Page 450
GD32A513 User Manual Reserved Must be kept at reset value. CH0MS[1:0] Channel 0 I/O mode selection This bit-field specifies the work mode of the channel and the input signal selection. This bit-field is writable only when the channel is not active (CH0EN bit in TIMERx_CHCTL2 register is reset).
Page 451
GD32A513 User Manual 4’b1011 4’b1100 4’b1101 4’b1110 4’b1111 CH0CAPPSC[1:0] Channel 0 input capture prescaler This bit-field specifies the factor of the prescaler on channel 0 input. The prescaler is reset when CH0EN bit in TIMERx_CHCTL2 register is cleared. 00: Prescaler disabled, input capture occurs on every channel input edge.
Page 452
GD32A513 User Manual This bit-field is writable only when the channel is not active (CH3EN bit in TIMERx_CHCTL2 register is reset). 00: Channel 3 is programmed as output. 01: Channel 3 is programmed as input, IS3 is connected to CI3FE3.
Page 453
GD32A513 User Manual 1: Channel 2 output compare shadow enabled The PWM mode can be used without verifying the shadow register only in single pulse mode (when SPM=1). Reserved Must be kept at reset value. CH2MS[1:0] Channel 2 I/O mode selection This bit-field specifies the work mode of the channel and the input signal selection.
Page 454
GD32A513 User Manual 4’b1000 4’b1001 4’b1010 4’b1011 4’b1100 4’b1101 4’b1110 4’b1111 CH2CAPPSC[1:0] Channel 2 input capture prescaler This bit-field specifies the factor of the prescaler on channel 2 input. The prescaler is reset when CH2EN bit in TIMERx_CHCTL2 register is cleared.
Page 455
GD32A513 User Manual CH2NP Channel 2 complementary capture/compare polarity Refer to CH0NP description. Reserved Must be kept at reset value. CH2P Channel 2 capture/compare function polarity Refer to CH0P description CH2EN Channel 2 capture/compare function enable Refer to CH0EN description...
Page 456
GD32A513 User Manual 11 or 10. CH0EN Channel 0 capture/compare function enable When channel 0 is configured in output mode, setting this bit enables CH0_O signal in active state. When channel 0 is configured in input mode, setting this bit enables the capture event in channel0.
Page 457
GD32A513 User Manual The TIMER_CK clock is divided by (PSC+1) to generate the counter clock. The value of this bit-field will be loaded to the corresponding shadow register at every update event. Counter auto reload register (TIMERx_CAR) Address offset: 0x2C Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 458
GD32A513 User Manual When channel 0 is configured in output mode, this bit-field contains value to be compared to the counter. When the corresponding shadow register is enabled, the shadow register updates by every update event. Channel 1 capture/compare value register (TIMERx_CH1CV)
Page 459
GD32A513 User Manual at the last capture event. And this bit-field is read-only. When channel 2 is configured in output mode, this bit-field contains value to be compared to the counter. When the corresponding shadow register is enabled, the shadow register updates by every update event.
Page 460
GD32A513 User Manual This filed defines the number(n) of the register that DMA will access(R/W), n = (DMATC [4:0] +1). DMATC [4:0] is from 5’b00000 to 5’b10001. Reserved Must be kept at reset value. DMATA[4:0] DMA transfer access start address This field define the first address for the DMA access the TIMERx_DMATB.
Page 461
GD32A513 User Manual Bits Fields Descriptions 31:2 Reserved Must be kept at reset value. CI0_RMP[1:0] Channel 0 input remap 00: Channel 0 input is connected to GPIO(TIMER1_CH0) 01: Channel 0 input is connected to the LXTAL 10: Channel 0 input is connected to HXTAL/128 clock 11: Channel 0 input is connected to CKOUT0SEL.
GD32A513 User Manual 18.3. Basic timer (TIMERx, x=5, 6) Overview 18.3.1. The basic timer module (TIMER5/6) has a 16-bit counter that can be used as an unsigned counter. The basic timer can be configured to generate a DMA request and a TRGO to connect to DAC.
GD32A513 User Manual Figure 18-62. Timing chart of internal clock divided by 1 CK_TIMER update event generate(UPG) Reload Pulse Update event (UPE) PSC_CLK = TIMER_CK CNT_REG Clock prescaler The counter clock (PSC_CK) is obtained by the TIMER_CK through the prescaler, and the prescale factor can be configured from 1 to 65536 through the prescaler register (TIMERx_PSC).
GD32A513 User Manual Counter up counting In this mode, the counter counts up continuously from 0 to the counter reload value, which is defined in the TIMERx_CAR register, in a count-up direction. Once the counter reaches the counter reload value, the counter will start counting up from 0 again. The update event is generated at each counter overflow.
GD32A513 User Manual Figure 18-65. Timing chart of up counting mode, change TIMERx_CAR on the go TIMER_CK PSC_CLK ARSE = 0 CNT_REG Update event (UPE) Hardware set Update interrupt flag (UPIF) Auto-reload register change CAR Vaule ARSE = 1 CNT_REG...
GD32A513 User Manual Registers definition (TIMERx, x=5, 6) 18.3.5. TIMER5 base address: 0x4000 1000 TIMER6 base address: 0x4000 1400 Control register 0 (TIMERx_CTL0) Address offset: 0x00 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved...
Page 467
GD32A513 User Manual – The UPG bit is set – The counter generates an overflow or underflow event – The restart mode generates an update event. 1: Update event disable. Note: When this bit is set to 1, setting UPG bit or the restart mode does not generate an update event, but the counter and prescaler are initialized.
Page 468
GD32A513 User Manual Interrupt enable register (TIMERx_DMAINTEN) Address offset: 0x0C Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved Reserved UPDEN Reserved UPIE Bits Fields Descriptions 31:9 Reserved Must be kept at reset value. UPDEN...
Page 469
GD32A513 User Manual Software event generation register (TIMERx_SWEVG) Address offset: 0x14 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved Reserved Bits Fields Descriptions 31:1 Reserved Must be kept at reset value. This bit can be set by software, and automatically cleared by hardware. When this bit is set, the counter is cleared.
Page 470
GD32A513 User Manual Reserved PSC[15:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:0 PSC[15:0] Prescaler value of the counter clock The TIMER_CK clock is divided by (PSC+1) to generate the counter clock. The value of this bit-field will be loaded to the corresponding shadow register at every update event.
GD32A513 User Manual Universal synchronous/asynchronous receiver /transmitter (USART) 19.1. Overview The Universal Synchronous/Asynchronous Receiver/Transmitter (USART) provides a flexible serial data exchange interface. Data frames can be transferred in full duplex or half duplex mode, synchronously or asynchronously through this interface. A programmable baud rate generator divides the UCLK (PCLK, CK_SYS, LXTAL or IRC16M) to produces a dedicated wide range baudrate clock for the USART transmitter and receiver.
GD32A513 User Manual Transmits parity bit – Checks parity of received data byte – LIN Break generation and detection IrDA Support Synchronous mode and transmitter clock output for synchronous transmission ISO 7816-3 compliant smartcard interface Character mode (T=0) –...
GD32A513 User Manual Type Description Output I/O (single- Transmit Data. High level When enabled but wire/smartcard mode) nothing to be transmitted Output Serial clock for synchronous communication nCTS Input Clear to send in Hardware flow control mode nRTS Output Request to send in Hardware flow control mode Figure 19-1.
GD32A513 User Manual bits in the USART_CTL1 register. Table 19-2. Configuration of stop bits STB[1:0] stop bit length (bit) usage description Default value Smartcard mode for receiving Normal USART and single-wire modes Smartcard mode for transmitting and receiving In an idle frame, all the frame bits are logic 1. The frame length is equal to the normal USART frame.
GD32A513 User Manual USART transmitter 19.3.3. If the transmit enable bit (TEN) in USART_CTL0 register is set, when the transmit data buffer is not empty, the transmitter shifts out the transmit data frame through the TX pin. The polarity of the TX pin can be configured by the TINV bit in the USART_CTL1 register. Clock pulses can output through the CK pin.
GD32A513 User Manual It is necessary to wait for the TC bit to be asserted before disabling the USART or entering the power saving mode. This bit can be cleared by set the TCC bit in USART_INTC register. The break frame is sent when the SBKCMD bit is set, and SBKCMD bit is reset after the transmission.
GD32A513 User Manual Figure 19-4. Oversampling method of a receive frame bit (OSB=0) one frame bit RX pin oversampling 8 mode sample bits oversampling 16 mode sample bits If the parity check function is enabled by setting the PCEN bit in the USART_CTL0 register, the receiver calculates the expected parity value while receiving a frame.
GD32A513 User Manual Configuration step when using DMA for USART transmission. Figure 19-5. Configuration step when using DMA for USART transmission Clear the TC bit in USART_STAT Set the address of USART_TDATA as the DMA destination address Set the address of data in internal...
GD32A513 User Manual Figure 19-6. Configuration step when using DMA for USART reception Set the address of USART_RDATA as the DMA source address Set the address of the buffer in internal sram as the DMA destination address Set the number of data as the DMA...
GD32A513 User Manual RTS flow control The USART receiver outputs the nRTS, which reflects the status of the receive buffer. When data frame is received, the nRTS signal goes high to prevent the transmitter from sending next frame. The nRTS signal keeps high when the receive buffer is full.
GD32A513 User Manual The idle frame wake up method is selected by default. If the RWU bit is reset, an idle frame is detected on the RX pin, the IDLEF bit in USART_STAT will be set. If the RWU bit is set, an idle frame is detected on the RX pin, the hardware clears the RWU bit and exits the mute mode.
GD32A513 User Manual frame can be selected by configuring LBLEN in USART_CTL1. When the RX pin is detected at low state for a time that is equal to or longer than the expected break frame length (10 bits when LBLEN=0, or 11 bits when LBLEN=1), the LBDF bit in USART_STAT is set. An interrupt occurs if the LBDIE bit in USART_CTL1 is set.
GD32A513 User Manual Figure 19-11. Example of USART in synchronous mode Data output Data input USART Device (master mode) (slave mode) Clock input Figure 19-12. 8-bit format USART synchronous waveform (CLEN=1) IrDA SIR ENDEC mode 19.3.10. The IrDA mode is enabled by setting the IREN bit in USART_CTL2. The LMEN, STB[1:0], CKEN bits in USART_CTL1 and HDEN, SCEN bits in USART_CTL2 should be cleared in IrDA mode.
GD32A513 User Manual Figure 19-13. IrDA SIR ENDEC module Inside chip Outside chip RX pin Receive Decoder Infrared Normal IREN USART TX pin Transmit Encoder SIR MODULE In IrDA mode, the polarity of the TX and RX pins is different. The TX pin is usually at low state, while the RX pin is usually at high state.
GD32A513 User Manual Half-duplex communication mode 19.3.11. The half-duplex communication mode is enabled by setting the HDEN bit in USART_CTL2. The LMEN, CKEN bits in USART_CTL1 and SCEN, IREN bits in USART_CTL2 should be cleared in half-duplex communication mode. Only one wire is used in half-duplex mode. The TX and RX pins are connected together internally.
Page 486
GD32A513 User Manual During USART transmission, if a parity error event is detected, the smartcard may NACK the current frame by pulling down the TX pin during the last 1 bit time of the stop bits. The USART can automatically resend data according to the protocol for SCRTNUM times. An interframe gap of 2.5 bits time will be inserted before the start of a resented frame.
Page 487
GD32A513 User Manual programming the BL value. However, before the start of the block, the maximum value of BL (0xFF) may be programmed. The real value will be programmed after the reception of the third character. The total block length (including prologue, epilogue and information fields) equals BL+4. The end of the block is signaled to the software through the EBF flag and interrupt (when EBIE bit is set).
GD32A513 User Manual Figure 19-16. USART Receive FIFO structure RX Module RX shift register RX FIFO EN FIFO 0 RX Buffer FIFO 1 FIFO 2 FIFO 3 If the software read receive data buffer in the routing of the RBNE interrupt, the RBNEIE bit should be reset at the beginning of the routing and set after all of the receive data is read out.
Page 489
GD32A513 User Manual Interrupt event Event flag Enable Control bit CTS flag CTSF CTSIE Transmission complete TCIE Received data ready to be RBNE read RBNEIE Overrun error detected ORERR Receive FIFO full RFFINT RFFIE Idle line detected IDLEF IDLEIE Parity error flag...
Page 491
GD32A513 User Manual 19.4. Register definition USART0 base address: 0x4001 3800 USART1 base address: 0x4000 4400 USART2 base address: 0x4000 4800 Control register 0 (USART_CTL0) 19.4.1. Address offset: 0x00 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit).
Page 492
GD32A513 User Manual expressed in sample time units (1/8 or 1/16 bit time), which are configured by the OVSMOD bit. This bit field cannot be written when the USART is enabled (UEN=1). OVSMOD Oversample mode. 0: Oversampling by 16. 1: Oversampling by 8.
Page 493
GD32A513 User Manual 1: Transmission complete interrupt is enabled. RBNEIE Read data buffer not empty interrupt and overrun error interrupt enable. 0: Read data register not empty interrupt and overrun error interrupt disabled. 1: An interrupt will occur whenever the ORERR bit is set or the RBNE bit is set in USART_STAT.
Page 494
GD32A513 User Manual When WM[1:0] = 01, if the ADDM bit is reset, only the ADDR[3:0] bits are used to compare. In normal reception, these bits are also used for character detection. The whole received character (8-bit) is compared to the ADDR[7:0] value and AMF flag is set on matching.
Page 495
GD32A513 User Manual 11: 1.5 Stop bit. This bit field cannot be written when the USART is enabled (UEN=1). CKEN CK pin enable. 0: CK pin disabled. 1: CK pin enabled. This bit field cannot be written when the USART is enabled (UEN=1).
Page 496
GD32A513 User Manual Control register 2 (USART_CTL2) 19.4.3. Address offset: 0x08 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). Reserved WUIE WUM[1:0] SCRTNUM[2:0] Reserved DDRE OVRD CTSIE CTSEN RTSEN DENT DENR SCEN NKEN HDEN IRLP...
Page 497
GD32A513 User Manual 1: DE signal is active low. This bit field cannot be written when the USART is enabled (UEN=1). Driver enable mode. This bit is used to activate the external transceiver control, through the DE signal, which is output on the RTS pin.
Page 498
GD32A513 User Manual space in the receive buffer. This bit field cannot be written when the USART is enabled (UEN=1). DENT DMA enable for transmission. 0: DMA mode is disabled for transmission. 1: DMA mode is enabled for transmission. DENR DMA enable for reception.
Page 499
GD32A513 User Manual Reserved BRR [15:4] BRR[3:0] Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:4 BRR[15:4] Integer of baud-rate divider. INTDIV = BRR[15:4]. BRR [3:0] Fraction of baud-rate divider. If OVSMOD = 0, FRADIV = BRR[3:0].
Page 500
GD32A513 User Manual PSC[4:0] bits. And the bits of PSC[7:5] must be kept at reset value. The division factor is twice as the prescaler value. 00000: Reserved - do not program this value. 00001: divides the source clock by 2.
Page 501
GD32A513 User Manual received character. Command register (USART_CMD) 19.4.7. Address offset: 0x18 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit) Reserved Reserved TXFCMD RXFCMD MMCMD SBKCMD Reserved Bits Fields Descriptions 31:5 Reserved Must be kept at reset value.
Page 502
GD32A513 User Manual Bits Fields Descriptions 31:23 Reserved Must be kept at reset value. Receive enable acknowledge flag. This bit, which is set/reset by hardware, reflects the receive enable state of the USART core logic. 0: The USART core receiving logic has not been enabled.
Page 503
GD32A513 User Manual Busy flag. 0: USART reception path is idle. 1: USART reception path is working. 15:13 Reserved Must be kept at reset value. End of block flag. 0: End of Block not reached. 1: End of Block (number of characters) reached. An interrupt is generated if the EBIE=1 in the USART_CTL1 register.
Page 504
GD32A513 User Manual transferred into the transmit shift register or writing 1 to TXFCMD bit of the USART_CMD register. Cleared by a write to the USART_TDATA. Transmission completed. 0: Transmission is not completed. 1: Transmission is complete. An interrupt will occur if the TCIE bit is set in USART_CTL0.
Page 505
GD32A513 User Manual 1: Frame error flag or break character is detected. In multibuffer communication, an interrupt will occur if the ERRIE bit is set in USART_CTL2. Set by hardware when a de-synchronization, excessive noise or a break character is detected. This bit will be set when the maximum number of transmit attempts is reached without success (the card NACKs the data frame), when USART transmits in smartcard mode.
Page 506
GD32A513 User Manual Reserved Must be kept at reset value. CTSC CTS change clear. Writing 1 to this bit clears the CTSF bit in the USART_STAT register. LBDC LIN break detected clear. Writing 1 to this bit clears the LBDF flag in the USART_STAT register.
Page 507
GD32A513 User Manual received parity bit, if receiving with the parity is enabled (PCEN bit set to 1 in the USART_CTL0 register). Transmit data register (USART_TDATA) 19.4.11. Address offset: 0x28 Reset value: Undefined This register has to be accessed by word (32-bit).
Page 508
GD32A513 User Manual 1: Parity error is detected. Reserved Forced by hardware to 0. Hardware flow control coherence mode. 0: nRTS signal equals to the RBNE in status register. 1: nRTS signal is set when the last data bit (parity bit when pce is set) has been sampled.
Page 509
GD32A513 User Manual The NACK pulse occurs 1/16 bit time earlier when the parity error is detected. 0:Early NACKdisable when smartcard mode is selected. 1:Early NACKenable when smartcard mode is selected.
GD32A513 User Manual Inter-integrated circuit interface (I2C) 20.1. Overview 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. I2C bus uses two serial lines: a serial data line (SDA) and a serial clock line (SCL).
GD32A513 User Manual DNF[3:0]×t Analog filter delay is maximum 260ns. Digital filter delay is I2CCLK The period of PCLK clock match the conditions as follows: PCLK <4/3*t PCLK with: : the period of SCL Note: When the I2C kernel is provided by PCLK, this clock must match the conditions for...
GD32A513 User Manual Figure 20-3. START and STOP signal START STOP Each I2C device is recognized by a unique address (whether it is a microcontroller, LCD driver, memory or keyboard interface) and can operate as either a transmitter or receiver, depending on the function of the device.
GD32A513 User Manual Figure 20-5. I2C communication flow with 7-bit address (Master Transmit) Figure 20-6. I2C communication flow with 7-bit address (Master Receive) Start Slave address DATA0 …… DATAN NACK Stop R(1) data transfer (N+1 bytes) From master to slave...
GD32A513 User Manual Noise filter 20.3.3. Analog noise filter and digital noise filter are integrated in I2C peripherals, the noise filters can be configured before the I2C peripheral is enabled according to the actual requirements. The analog noise filter is disabled by setting the ANOFF bit in I2C_CTL0 register and enabled when ANOFF is 0.
GD32A513 User Manual Figure 20-10. Data setup time SU;DAT When the SCL falling edge is internally detected, a delay is inserted before sending SDA output. This delay is t = SDADELY * t where t = (PSC+1) * t SDADELY...
GD32A513 User Manual Table 20-2. Data setup time and data hold time Standard Fast mode Fast mode SMBus Symbol Parameter mode plus Unit Data hold time HD;DAT Data valid time 3.45 0.45 VD;DAT Data setup time SU;DAT Rising time of...
GD32A513 User Manual Figure 20-11. Data transmission SCL Stretch Shift register write data1 write data2 data0 data1 data2 I2C_TDATA Data Reception When receiving data, the data will be received in the shift register first. If RBNE is 0, the data in the shift register will move into I2C_RDATA register.
Page 519
GD32A513 User Manual Working mode Action Slave receiver mode ACK control SMBus mode PEC generation/checking The number of bytes to be transferred is configured by BYTENUM[7:0] in I2C_CTL1 register. If BYTENUM is greater than 255, or in slave byte control mode, the reload mode must be enabled by setting the RELOAD bit in I2C_CTL1 register.
Page 520
GD32A513 User Manual low if necessary. The SCL will be stretched in following cases. The SCL is stretched when the ADDSEND bit is set, and released when the ADDSEND bit is cleared. In slave transmitting mode, after the ADDSEND bit is cleared, the SCL will be stretched before the first data byte writing to the I2C_TDATA register.
GD32A513 User Manual 1. I2CEN=0. 2. The slave has not been addressed. 3. ADDSEND=1. Only when the ADDSEND=1, or TCR=1, the RELOAD bit can be modified. Figure 20-13. I2C initialization in slave mode START I2CEN=0 Configure DNF[3:0] in I2C_CTL0 Configure PSC[3:0], SDADELY[3:0],...
GD32A513 User Manual When SBCTL is 0, if ADDSEND=1, and the TBE bit in I2C_STAT register is 0, the data in I2C_TDATA register can be chosed to be transmitted or flushed. The data is flushed by setting the TBE bit.
GD32A513 User Manual Figure 20-15. Programming model for slave transmitting when SS=1 I2C Line State Hardware Action Software Flow I2C initialization IDLE Set TBE Write DATA(1) to I2C_TDATA Master generates START condition Master sends Address read READDR and TR in...
GD32A513 User Manual Figure 20-16. Programming model for slave receiving I2C Line State Hardware Action Software Flow IDLE Master generates START Software initialization condition Master sends Address Slave sends Acknowledge read READDR and TR in Set ADDSEND I2C_STAT, clear ADDSEND...
GD32A513 User Manual configured in I2C_CTL1 register. When the addressing mode is 10-bit in master receiving mode, the HEAD10R bit must be configured to decide whether the complete address sequence must be executed, or only the header to be sent. The number of bytes to be transferred should be configured in BYTENUM[7:0] in I2C_CTL1 register.
GD32A513 User Manual If data of BYTENUM[7:0] bytes have been transferred and RELOAD=0, the AUTOEND bit in I2C_CTL1 can be set to generate a STOP signalautomatically. When AUTOEND is 0, the TC bit in I2C_STAT register will be set and the SCL is stretched. In this case, the master can generate a STOP signalby setting the STOP bit in the I2C_CTL1 register.
GD32A513 User Manual Figure 20-21. Programming model for master receiving (N>255) I2C Line State Hardware Action Software Flow Software initialization RELOAD =1 BYTENUM[7:0]=0xFF N=N-255 IDLE Set START START Condition Master sends Address Slave sends Acknowledge Slave sends DATA(1) Master sends Acknowledge...
Page 530
GD32A513 User Manual Configuration and Power Management Interface (abbreviated to ACPI) specifications. Address resolution protocol The SMBus uses I2C hardware and I2C hardware addressing, but adds second-level software for building special systems. Additionally, its specifications include an Address Resolution Protocol that can make dynamic address allocations. Dynamic reconfiguration of the hardware and software allow bus devices to be ‘hot-plugged’...
GD32A513 User Manual (BUSTOA+1)*2048*t , the TIMEOUT flag will be set in I2C_STAT register. I2CCLK The BUSTOB[11:0] is used to check the t of the slave and the t of the LOW:SEXT LOW:MEXT master. The timer can be enabled by setting the EXTOEN bit in the I2C_TIMEOUT register, after the EXTOEN bit is set, the BUSTOB[11:0] cannot be changed.
Page 532
GD32A513 User Manual Bus idle detection If the master detects that the high level duration of the clock and data signals is greater than , the bus can be considered idle. HIGH,MAX This timing parameter includes the case of a master that has been dynamically added to the bus and may not have detected a state transition on a SMBCLK or SMBDAT lines.
GD32A513 User Manual must be set. In order to check the PEC byte, it is necessary to clear the RELOAD bit and set PECTRANS bit. After receiving BYTENUM-1 data, the next received byte will be compared with the data in the I2C_PEC register. If the PEC values does not match, the NACK is automatically generated.
GD32A513 User Manual Use DMA for data transfer 20.3.11. As is shown in I2C slave mode and I2C master mode, each time TI or RBNE is asserted, software should write or read a byte, this may cause CPU’s high overload. The DMA controller can be used to process TI and RBNE flag: each time TI or RBNE is asserted, DMA controller does a read or write operation automatically.
Page 535
GD32A513 User Manual I2C debug mode 20.3.13. When the microcontroller enters the debug mode (Cortex®-M33 core halted), the SMBus timeout either continues to work normally or stops, depending on the I2Cx_HOLD configuration bits in the DBG module.
Page 536
GD32A513 User Manual 20.4. Register definition I2C0 base address: 0x4000 5400 I2C1 base address: 0x4000 5800 Control register 0 (I2C_CTL0) 20.4.1. Address offset: 0x00 Reset value: 0x0000 0000 This register can be accessed by word (32-bit). SMBALT SMBDAE SMBHAE Reserved...
Page 537
GD32A513 User Manual 1: Slave will response to a General Call Reserved Must be kept at reset value. Whether to stretch SCL low when data is not ready in slave mode. This bit is set and cleared by software. 0: SCL Stretching is enabled 1: SCL Stretching is disabled Note: When in master mode, this bit must be 0.
Page 538
GD32A513 User Manual STPDETIE Stop detection interrupt enable 0: Stop detection (STPDET) interrupt is disabled 1: Stop detection (STPDET) interrupt is enabled NACKIE Not acknowledge received interrupt enable 0: NACK received interrupt is disabled 1: NACK received interrupt is enabled...
Page 539
GD32A513 User Manual 0: Don’t transfer PEC value 1: Transfer PEC Note: This bit has no effect when RELOAD=1, or SBCTL=0 in slave mode. AUTOEND Automatic end mode in master mode 0: TC bit is set when the transfer of BYTENUM[7:0] bytes is completed.
Page 540
GD32A513 User Manual (write) + slave address byte 2 + RESTART + header of 10-bit address (read). 1: The 10 bit master receive address sequence is RESTART + header of 10-bit address (read). Note: When the START bit is set, this bit can not be changed.
Page 541
GD32A513 User Manual ADDRESSEN I2C address enable 0: I2C address disable. 1: I2C address enable. 14:11 Reserved Must be kept at reset value. ADDFORMAT Address mode for the I2C slave 0: 7-bit address 1: 10-bit address Note: When ADDRESSEN is set, this bit should not be written.
Page 542
GD32A513 User Manual 111: ADDRESS2[7:1] are masked. All 7-bit received addresses are acknowledged except the reserved address (0b0000xxx and 0b1111xxx). Note: When ADDRESS2EN is set, these bits should not be written. If ADDMSK2 is not equal to 0, the reserved I2C addresses (0b0000xxx and 0b1111xxx) are not acknowledged even if all the bits are matched.
Page 543
GD32A513 User Manual =(SCLH+1)*t SCLH Note: These bits can only be used in master mode. SCLL[7:0] SCL low period SCL low period can be generated by configuring these bits. =(SCLL+1)*t SCLL Note: These bits can only be used in master mode.
Page 544
GD32A513 User Manual 0: BUSTOA is used to detect SCL low timeout 1: BUSTOA is used to detect both SCL and SDA high timeout when the bus is idle Note: This bit can be written only when TOEN =0. 11:0...
Page 545
GD32A513 User Manual setting the SMBALTC bit. This bit is cleared by hardware when I2CEN=0. 0: SMBALERT event is not detected on SMBA pin 1: SMBALERT event is detected on SMBA pin TIMEOUT TIMEOUT flag. When a timeout or extended clock timeout occurred, this bit will be set. It is cleared by software by setting the TIMEOUTC bit and cleared by hardware when I2CEN=0.
Page 546
GD32A513 User Manual BYTENUM[7:0] bytes have been transferred. It is cleared by software when START bit or STOP bit is set. 0: Transfer of BYTENUM[7:0] bytes is not completed 1: Transfer of BYTENUM[7:0] bytes is completed STPDET STOP signal detected in slave mode This flag is set by hardware when a STOP signal is detected on the bus.
Page 547
GD32A513 User Manual Status clear register (I2C_STATC) 20.4.8. Address offset: 0x1C Reset value: 0x0000 0000 This register can be accessed by word (32-bit). Reserved SMBALT TIMEOUT PECERR LOSTAR STPDET ADDSEN Reserved OUERRC BERRC Reserved NACKC Reserved Bits Fields Descriptions 31:14 Reserved Must be kept at reset value.
Page 548
GD32A513 User Manual PEC register (I2C_PEC) 20.4.9. Address offset: 0x20 Reset value: 0x0000 0000 This register can be accessed by word (32-bit). Reserved Reserved PECV[7:0] Bits Fields Descriptions 31:8 Reserved Must be kept at reset value. PECV[7:0] Packet Error Checking Value that calculated by hardware when PEC is enabled.
Page 549
GD32A513 User Manual Reserved TDATA [7:0] Bits Fields Descriptions 31:8 Reserved Must be kept at reset value. TDATA[7:0] Transmit data value Control register 2 (I2C_CTL2) 20.4.12. Address offset: 0x90 Reset value: 0x0000 FE00 This register can be accessed by word (32-bit).
Page 550
GD32A513 User Manual Serial peripheral interface/Inter-IC sound (SPI/I2S) Overview 21.1. The SPI/I2S module can communicate with external devices using the SPI protocol or the I2S audio protocol. The serial peripheral interface (SPI) provides a SPI protocol of data transmission and reception function in master or slave mode.
GD32A513 User Manual Pin name Direction Description application. Slave in hardware NSS mode: NSS input, as a chip select signal for slave. Quad-SPI configuration SPI is in single wire mode by default and enters into Quad-SPI mode after QMOD bit in SPI_QCTL register is set (only available in SPI0).
GD32A513 User Manual Figure 21-3. SPI timing diagram in Quad-SPI mode (CKPL=1, CKPH=1, LF=0) sample MOSI D0[4] D0[0] D1[4] D1[0] MISO D0[5] D0[1] D1[5] D1[1] D0[6] D0[2] D1[6] D1[2] D1[7] D0[7] D0[3] D1[3] In normal mode, the length of data is configured by the FF16 bit in the SPI_CTL0 register.
GD32A513 User Manual software NSS mode) goes low, the SPI automatically enters slave mode and triggers a master fault flag CONFERR. If the application wants to use NSS line to control the SPI slave, NSS should be configured to hardware output mode (SWNSSEN=0, NSSDRV=1). NSS goes low after SPI is enabled.
Page 555
GD32A513 User Manual Mode Description Register configuration Data pin usage BDOEN: Don’t care MSTMOD = 1 Master reception with RO = 1 MOSI: Not used unidirectional connection BDEN = 0 MISO: Reception BDOEN: Don’t care MSTMOD = 1 Master transmission with...
Page 557
GD32A513 User Manual SPI initialization sequence Before transmiting or receiving data, application should follow the SPI initialization sequence described below: If master mode or slave TI mode is used, program the PSC [2:0] bits in SPI_CTL0 register to generate SCK with desired baud rate or configure the Td time in TI mode, otherwise, ignore this step.
GD32A513 User Manual receive buffer and RBNE (receive buffer not empty) will be set. The application should read SPI_DATA register to get the received data and this will clear the RBNE flag automatically. In MRU and MRB modes, hardware continuously sends clock signal to receive the next data frame, while in full-duplex master mode (MFD), hardware only receives the next data frame when the transmit buffer is not empty.
GD32A513 User Manual Figure 21-9. Timing diagram of TI master mode with continuous transfer In master TI mode, SPI can perform continuous or non-continuous transfer. If the master writes SPI_DATA register fast enough, the transfer is continuous, otherwise non-continuous. In non-continuous transfer, there is an extra header clock cycle before each byte. While in continuous transfer, the extra header clock cycle only exists before the first byte and the following bytes’...
GD32A513 User Manual place, several additional conditions must be met, users must also set the device into master mode, and frame format should follow the normal SPI protocol, and set the data capture edge to first clock transition. In summary: NSSP = 1; MSTMOD = 1; CKPH = 0;...
GD32A513 User Manual Figure 21-12. Timing diagram of quad write operation in Quad-SPI mode Software write SPI_DATA Hardware sets TBE again sample MOSI D0[0] D0[4] D1[4] D1[0] MISO D0[5] D0[1] D1[5] D1[1] D0[6] D0[2] D1[6] D1[2] D0[7] D0[3] D1[7] D1[3] Quad read operation SPI works in quad read mode when QMOD and QRD bits are both set in SPI_QCTL register.
Page 563
GD32A513 User Manual Quad-SPI mode Before leaving quad wire mode or disabling SPI, software should first check that TBE bit is set and TRANS bit is cleared, then the QMOD bit in SPI_QCTL register and SPIEN bit in SPI_CTL0 register are cleared.
Page 564
GD32A513 User Manual SPI interrupts 21.3.8. Status flags Transmit buffer empty flag (TBE) This bit is set when the transmit buffer is empty, the software can write the next data to the transmit buffer by writing the SPI_DATA register.
GD32A513 User Manual I2S signal description 21.4.2. There are four pins on the I2S interface, including I2S_CK, I2S_WS, I2S_SD and I2S_MCK. I2S_CK is the serial clock signal, which shares the same pin with SPI_SCK. I2S_WS is the frame control signal, which shares the same pin with SPI_NSS. I2S_SD is the serial data signal, which shares the same pin with SPI_MOSI.
GD32A513 User Manual Figure 21-16. I2S Phillips standard timing diagram (DTLEN=00, CHLEN=0, CKPL=1) When the packet type is 16-bit data packed in 16-bit frame, only one write or read operation the transmission of to or from the SPI_DATA register is needed to complete a frame.
GD32A513 User Manual transmission mode, if a 24-bit data D[23:0] is going to be sent, the first data written to the SPI_DATA register should be the higher 16 bits D[23:8]. And the second one should be a 16- bit data, the higher 8 bits of this 16-bit data should be D[7:0] and the lower 8 bits can be any value.
GD32A513 User Manual than the data length, the valid data is aligned to LSB for LSB justified standard while the valid data is aligned to MSB for MSB justified standard. The timing diagrams for the cases that the channel length is greater than the data length are shown below.
GD32A513 User Manual PCM standard For PCM standard, I2S_WS and I2S_SD are updated on the rising edge of I2S_CK, and the I2S_WS signal indicates frame synchronization information. Both the short frame synchronization mode and the long frame synchronization mode are available and configurable using the PCMSMOD bit in the SPI_I2SCTL register.
Page 576
GD32A513 User Manual Figure 21-52. I2S initialization sequence Start Configure the DIV [7:0] bits, the OF Is the bit is 1 bit, and the MCKOEN bit to define MSTMOD the I2S bitrate and master clock Configure the CKPL bit to define the clock polarity...
Page 577
GD32A513 User Manual and no transmission sequence is processing in the shift register. When a half word is written to the SPI_DATA register (TBE goes low), the data is transferred from the transmit buffer to the shift register (TBE goes high) immediately. At the moment, the transmission sequence begins.
GD32A513 User Manual Figure 21-53. I2S master reception disabling sequence Start If DTLEN == 2b'00&&CHLEN == 2b'1 && I2SSTD ==2b'10 ? If DTLEN == 2b'00&&CHLEN == Wait for the second last RBNE 2b'1 && I2SSTD !=2b'10 ? Wait for the last RBNE...
Page 579
GD32A513 User Manual I2S slave reception sequence The reception sequence in slave mode is similar to that in master mode. The differences between them are described below. In slave mode, the slave has to be enabled before the external master starts the communication.
GD32A513 User Manual Transmission underrun error flag (TXURERR) TXURERR will be set when the transmit buffer is empty and the valid SCK signal starts in slave transmission mode. Reception overrun error flag (RXORERR) This situation occurs when the receive buffer is full and a newly incoming data has been completely received.
Page 581
GD32A513 User Manual Register definition 21.5. SPI0 base address: 0x4001 3000 SPI1/I2S1 base address: 0x4000 3800 Control register 0 (SPI_CTL0) 21.5.1. Address offset: 0x00 Reset value: 0x0000 0000 This register can be accessed by half-word (16-bit) or word (32-bit). This register has no meaning in I2S mode.
Page 582
GD32A513 User Manual FF16 Data frame format 0: 8-bit data frame format 1: 16-bit data frame format Receive only mode When BDEN is cleared, this bit determines the direction of transfer. 0: Full-duplex mode 1: Receive-only mode SWNSSEN NSS software mode enable 0: NSS hardware mode.
Page 583
GD32A513 User Manual Control register 1 (SPI_CTL1) 21.5.2. Address offset: 0x04 Reset value: 0x0000 0000 This register can be accessed by half-word (16-bit) or word (32-bit). Reserved Reserved TBEIE RBNEIE ERRIE TMOD NSSP NSSDRV DMATEN DMAREN Bits Fields Descriptions 31:8 Reserved Must be kept at reset value.
Page 584
GD32A513 User Manual 1: Transmit buffer DMA is enabled. When the TBE bit in SPI_STAT is set, it will generate a DMA request at corresponding DMA channel. DMAREN Receive buffer DMA enable 0: Receive buffer DMA is disabled 1: Receive buffer DMA is enabled. When the RBNE bit in SPI_STAT is set, it will generate a DMA request at corresponding DMA channel.
Page 585
GD32A513 User Manual 1: Configuration fault occurred. (In master mode, the NSS pin is pulled low in NSS hardware mode or SWNSS bit is low in NSS software mode.) This bit is set by hardware and cleared by a read or write operation on the SPI_STAT register followed by a write access to the SPI_CTL0 register.
Page 586
GD32A513 User Manual 31:16 Reserved Must be kept at reset value. 15:0 SPI_DATA[15:0] Data transfer register The hardware has two buffers, including transmit buffer and receive buffer. Write data to SPI_DATA will save the data to transmit buffer and read data from SPI_DATA will get the data from receive buffer.
Page 587
GD32A513 User Manual Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. 15:0 RCRC[15:0] RX CRC value When the CRCEN bit of SPI_CTL0 is set, the hardware computes the CRC value of the received bytes and saves them in RCRC register. If the data frame format is set to 8-...
Page 588
GD32A513 User Manual I2S control register (SPI_I2SCTL) 21.5.8. Address offset: 0x1C Reset value: 0x0000 0000 This register can be accessed by half-word (16-bit) or word (32-bit). Reserved Reserved I2SSEL I2SEN I2SOPMOD[1:0] PCMSMOD Reserved I2SSTD[1:0] CKPL DTLEN[1:0] CHLEN Bits Fields Descriptions...
Page 589
GD32A513 User Manual 11: PCM standard These bits should be configured when I2S is disabled. These bits are not used in SPI mode. CKPL Idle state clock polarity 0: The idle state of I2S_CK is low level 1: The idle state of I2S_CK is high level This bit should be configured when I2S is disabled.
Page 590
GD32A513 User Manual This bit is not used in SPI mode. Odd factor for the prescaler 0: Real divider value is DIV * 2 1: Real divider value is DIV * 2 + 1 This bit should be configured when I2S is disabled.
Page 591
GD32A513 User Manual This bit is only available in SPI0.
Page 592
GD32A513 User Manual Comparator (CMP) 22.1. Overview The general purpose CMP can work either standalone (all terminal are available on I / Os) or together with the timers. It can be used to wake up the MCU from low-power mode by an analog signal, provide a trigger source when an analog signal is in a certain condition, achieve some current control by working together with a PWM output of a timer and the DAC.
GD32A513 User Manual Figure 22-1. CMP block diagram CMP0BLK[2:0] CMP0PSEL[2:0] Polarity Selection CMP0PL CMP0MISEL[2:0] CMP0MESEL[2:0] Note: V is 1.2V. REFINT CMP clock 22.3.1. The clock of the CMP which is connected to APB bus, is synchronous with PCLK. It has private reset and clock enable bits.
Page 594
GD32A513 User Manual Table 22-1. CMP inputs and outputs summary CMP0 CMP non inverting inputs connected to I / Os PC10 PC11 CMP inverting inputs connected to I / Os PC10 PC11 REFINT CMP inverting REFINT inputs connected * 3 / 4...
GD32A513 User Manual CMP hysteresis 22.3.4. In order to avoid spurious output transitions that caused by the noise signal, a programmable hysteresis is designed to force the hysteresis value by configuring CMPx_CS register. This function could be shut down if it is unnecessary.
GD32A513 User Manual Figure 22-3. The CMP outputs signal blanking CMP_IM CMP_IP Blanking signal CMP outputs raw singal CMP outputs final singal CMP voltage scaler function 22.3.7. The voltage scaler function can provide selectable 1 / 4, 1 / 2, 3 / 4 reference voltage for CMP input.
Page 597
GD32A513 User Manual 22.4. Register definition CMP base address:0x4001 7C00 CMP Control/status register (CMPx_CS) 22.4.1. Address offset: 0x00 Reset value: 0x0000 0000 This register has to be accessed by word (32-bit). CMP0LK CMP0O Reserved CMP0SEN CMP0BEN Reserved CMP0BLK[2:0] CMP0HST[1:0] CMP0PL...
Page 598
GD32A513 User Manual 000: No blanking 001: Select TIMER0_CH1 as blanking source 010: Select TIMER7_CH1 as blanking source 011: Select TIMER1_CH1 as blanking source 100~111: Reserved 17:16 CMP0HST[1:0] CMP0 hysteresis These bits are used to control the hysteresis level. 00: No hysteresis...
Page 599
GD32A513 User Manual 100: PA7(DAC0_OUT0) 101: Result of CMP0_IM external input selection 110~111: Reserved CMP0MESEL[2:0] CMP0_IM external input selection These bits are used to select the external source connected to the CMP0_IM input of the CMP0. 000: PC11 001: PC10...
Page 600
GD32A513 User Manual Controller area network (CAN) Overview 23.1. CAN bus (Controller Area Network) is a bus standard designed to allow microcontrollers and devices to communicate with each other without a host computer. The CAN interface supports the CAN 2.0A/B protocol, ISO 11898-1:2015 and BOSCH CAN FD specification.
GD32A513 User Manual FIFO. Supports priority of message reception between mailboxes and Rx FIFO during matching process. Rx FIFO identifier filtering, supports identifier matching against either 104 extended, 208 standard, or 416 partial (8 bit) identifiers. Rx FIFO up to 6 frames depth, with DMA support.
GD32A513 User Manual including: Tx arbitration: Find out the frame with the highest priority. Rx matching: Compare the frame data received in the Rx shift buffer (an internal mailbox descriptor) with the fields in Rx mailbox or Rx FIFO according to the configured matching order.
Page 603
GD32A513 User Manual TIMESTAMP[15:0] Bits Fields Descriptions FD format indicator This bit is used to distinguish between CAN and CAN FD format frames. For reception (Rx mailbox), no need to write this bit, it will be stored with the value received on the CAN bus.
GD32A513 User Manual For transmission (Tx mailbox), if this bit is set to '1' (recessive), and the bus transmits this bit as ‘0’ (dominant), then it means an arbitration loss. If this bit is set to '0' (dominant), and the bus transmits this bit as '1' (recessive), it is treated as a bit error.
GD32A513 User Manual CODE Servi RRFR CODE Meaning after Description reception FULL. It remains FULL. If a new frame is moved to the FULL mailbox after the mailbox was serviced, the code still remains FULL. 0b0010 FULL If the mailbox is FULL and a new frame is moved to...
Page 606
GD32A513 User Manual CODE after CODE Meaning Description transmission mailbox automatically becomes an Rx empty mailbox with the same ID. This is an intermediate code which is automatically written to the mailbox by the controller interface when a matching remote request frame is received. After...
GD32A513 User Manual DATA_i+2[7:0] DATA_i+3[7:0] Bits Fields Descriptions 31:24 DATA_i[7:0] Data byte i (i = 4*x - 8) Refer to DATA_i+3[7:0] descriptions. 23:16 DATA_i+1[7:0] Data byte i+1 (i = 4*x - 8) Refer to DATA_i+3[7:0] descriptions. 15:8 DATA_i+2[7:0] Data byte i+2 (i = 4*x - 8) Refer to DATA_i+3[7:0] descriptions.
GD32A513 User Manual of the FIFO which is the oldest message that has been received but not yet read by the CPU. The RAM region 0x90-0xDF is reserved for internal use of the FIFO. When RFEN bit in CAN_CTL0 register is 1, the RAM space which normally occupied by mailbox 6–31 with 8 byte payload is used for the ID filter table (configurable for 8 to up to 104...
Page 609
GD32A513 User Manual 1: Frame format is extended. Remote transmission request 0: Data frames are accepted 1: Remote frames are accepted 19:16 DLC[3:0] Data length code in bytes This bit field is the length (in bytes) of the Rx payload.
Page 610
GD32A513 User Manual Bits Fields Descriptions 31:24 DATA_0[7:0] Data byte 0 Refer to DATA_3[7:0] descriptions. 23:16 DATA_1[7:0] Data byte 1 Refer to DATA_3[7:0] descriptions. 15:8 DATA_2[7:0] Data byte 2 Refer to DATA_3[7:0] descriptions. DATA_3[7:0] Data byte 3 Up to 8 bytes can be used for a data frame, depending on the DLC value of the mailbox.
Page 611
GD32A513 User Manual Format A mode: ID_STD_A[10:0] Reserved RTR_A IDE_A Reserved ID_EXD_A[28:16] Reserved ID_EXD_A[15:0] Bits Fields Descriptions RTR_A Remote frame for format A This bit specifies whether remote frames can be stored into the FIFO or not when matches. 0: It indicates that remote frames are rejected and data frames can be stored.
Page 612
GD32A513 User Manual 0: It indicates that remote frames are rejected and data frames can be stored. 1: It indicates that remote frames can be stored and data frames are rejected. IDE_B0 ID Extended frame 0 for format B This bit specifies whether extended frames can be stored into the FIFO or not when matches.
Page 613
GD32A513 User Manual Refer to ID_C_0[7:0] descriptions. Communication modes 23.3.3. The CAN interface has four communication modes: Normal mode Inactive mode Loopback and silent mode Monitor mode Normal mode In normal mode, the message reception and transmission, and errors are all managed normally, and all CAN protocol functions are enabled.
Page 614
GD32A513 User Manual Loopback and silent mode To enter this mode, set the LSCMOD bit in CAN_CTL1 register to 1. In this mode, the messages are internally transmitted back to the receiver input, and the bit sent during the ACK slot in the frame acknowledge field is ignored to ensure reception transmitted by itself.
Page 615
GD32A513 User Manual Pretended Networking mode Pretended Networking mode is used to receive wakeup messages with low power consumption. This mode can work together with MCU deepsleep mode. To enter Pretended Networking mode, set PNEN bit and PNMOD bit in CAN_CTL0 register to 1, and optionally put the MCU into deepsleep mode.
Page 616
GD32A513 User Manual If the mailbox is active (either Tx or Rx), inactivate the mailbox by method described in Tx mailbox inactivation Rx mailbox inactivation, when Tx mailbox inactivation is performed, do the following steps, when Rx mailbox inactivation is performed, go to step 6.
GD32A513 User Manual winner exists, and the CAN bus is not in SOF-DATA field / SOF-Control field of a data / remote frame or Error / Overload flag field of an Error / Overload frame. CAN node enters Bus Integration state (refer to...
Page 619
GD32A513 User Manual register will be set. The writing of ABORT (0b1001) to the mailbox MDES0 word is blocked when shift-out of the mailbox is already finished, or when the mailbox is being transmitted. In this situation, the abort request is captured and kept pending until the frame is transmitted successfully or failed: ...
Page 620
GD32A513 User Manual Poll the the corresponding MSx bit in CAN_STAT register to be set, or by the interrupt when MIEx bit in CAN_INTEN register is set. Read back the CODE field to make sure that the mailbox is aborted, or transmitted.
Page 621
GD32A513 User Manual INACTIVE). But this operation may lead to a result that a matched message lost without notice. Note: The Rx mailbox inactivation will automatically unlocks the mailbox. There is no write protection for Rx FIFO. Rx FIFO reception The Rx FIFO is 6-message deep.
Page 622
GD32A513 User Manual if there are more than one messages in the Rx FIFO, the act of reading FDES3 word will update the Rx FIFO FDES0-FDES3 words with the next message, and CAN_RFIFOIFMN register (should be read before FDES3) will be updated at the same time, the flag MS5_RFNE remains set, and a DMA request is generated again.
Page 623
GD32A513 User Manual matching. The matching process starts when completes the DLC field reception. Searching process When the Rx FIFO is enabled, the RFO bit in CAN_CTL2 register gives the searching order. If RFO bit is set to 1, matching process starts from Rx mailbox to Rx FIFO. The Rx mailbox is searched from the lowest number mailbox to the higher ones.
GD32A513 User Manual EMPTY, FULL, and OVERRUN will be searched: When IDERTR_RMF bit in CAN_CTL2 register is 0, it means the IDE field will be compared and RTR field will not be compared (regardless of bit 30 and bit 31 in related filter register).
GD32A513 User Manual filter data configurations in related filter register. Searching conditions for matched Rx FIFO Table 23-10. Rx FIFO matching: Searching conditions for matched Rx FIFO, refers to If the FS[1:0] bits in CAN_CTL0 register is 0 or 1, it means A or B format of filter table is adopted, then all the IDE, RTR and ID fields will be compared, using bit 0 to bit 31 filter data configurations in related filter register.
Page 626
GD32A513 User Manual The shift-in process can be cancelled for a Rx mailbox, but can not be cancelled for the Rx FIFO. The shift-in process will be cancelled when matching one of the following situations: The target mailbox is inactivated after the CAN bus has reached the first bit of Intermission field next to the frame that carried the message and its matching process has finished.
Page 627
GD32A513 User Manual There are four groups of registers used for matched message storage: CAN_PN_RWMxCS, CAN_PN_RWMxI, CAN_PN_RWMxD0 and CAN_PN_RWMxD1 registers, group x from 0 to 3. Therefore, four messages can be stored at most (when NMM[7:0] bits in CAN_PN_CTL0 register is larger than or equal to 4), and only the latest messages will be stored. The group x indicates the message arrival order.
Page 628
GD32A513 User Manual When FFT[1:0] bit field in CAN_PN_CTL0 register is configured to 1, it means a wakeup match event occurs when a frame is received with all fields (that is IDE, RTR, ID, DLC, and DATA field matched) matched.
Page 629
GD32A513 User Manual DATA field matching When DATAFT[1:0] bit field in CAN_PN_CTL0 register is configured to 0, it means the DATA field of a matched message is the same as the configured expected DATA field in CAN_PN_EDLx (x = 0,1) registers, using filter data in CAN_PN_DF0EDH0 and CAN_PN_DF1EDH1 registers.
Page 630
GD32A513 User Manual detected) of a CAN FD frame with BRS bit set (refer to ISO11898-1 or Bosch CAN FD Specification V1.0). When BRSEN bit in CAN_FDCTL register is set to 1 (takes effect at the next message), and BRS bit in Tx mailbox is written as recessive ‘1’, then higher bit time (called as data bit time) will be used for the Data Phase of CAN FD frame, the nominal bit time will be used for the rest of the bits.
Page 631
GD32A513 User Manual For reception, the CRC polynomial used for CRC check is determined by the received FDF and DLC field. Note: In Classical frames, the CRC delimiter is one single recessive bit. In FD frames, the CRC delimiter may consist of one or two recessive bits. A transmitter shall send only one recessive bit as CRC delimiter, but it shall accept two recessive bits before the edge from recessive to dominant that starts the acknowledge slot.
GD32A513 User Manual with = TDCO[4:0] × t (23-2) offset CANCLK (23-3) offset PBS1_FD PTS_FD SYNC_SEG = (DPBS1[2:0] + 1) × t (23-4) PBS1_FD q_FD = DPTS[4:0] × t (23-5) PTS_FD q_FD = (DBAUDPSC[9:0] + 1) × t (23-6) q_FD...
Page 633
GD32A513 User Manual (REFCNT[7:0] bits in the CAN_ERR0 register) and a Transmit Error Counter for data phase of CAN FD messages (TEFCNT[7:0] bits in the CAN_ERR0 register) are used additionally only when the BRS field of the frame is set. They stop counting and keep their values when in Bus off state, and they restart counting after returned to error active state by Bus off recovery.
Page 634
GD32A513 User Manual Bus integration state If the node starts the protocol operation during Bus off recovery, or detects the protocol exception event (the event occurs when FDEN bit in CAN_CTL0 register is set to 0, and a FDF bit of a FD frame is received), the node enters the bus integration state. In this state, the synchronicity to the CAN bus is lost.
GD32A513 User Manual occurs. Refers to CRCFERR and CRCERR bit in CAN_ERR1 register. Form error When a fixed-form bit field contains at least one illegal bit, a form error occurs. Refers to FMFERR and FMERR bit in CAN_ERR1 register. Stuff error Refers to STFFERR and STFERR bit in CAN_ERR1 register.
Page 636
GD32A513 User Manual A valid edge is defined as the first toggle in a bit time from dominant to recessive bus level before the controller sends a recessive bit. If a valid edge is detected in BS1, not in SYNC_SEG, BS1 is added with up to SJW maximumly, so that the sample point is delayed.
Page 637
GD32A513 User Manual , and N are configured by the DPTS[4:0] bits, DPBS1[2:0] bits, DPTS PBS1 PBS2 BAUDPSC DPBS2[2:0] bits, and DBAUDPSC[9:0] bits respectively in CAN_FDBT register. Timestamp A 16-bit internal counter of the CAN hardware in CAN_TIMER register is used to generate the timestamp value.
GD32A513 User Manual Interrupts 23.3.11. Table 23-11. Interrupt events. The CAN interrupt events and flags are list in Table 23-11. Interrupt events Flag Enable control Interrupt event Control Enable Control Register Enable bit register register Bus off BOIE CAN_CTL1 Bus off recovery...
Page 639
GD32A513 User Manual reset or system reset, so CAN will automatically enters Inactive mode for configuration of CAN registers. Service the flags in CAN_STAT register Read the Rx mailbox or Rx FIFO descriptor contents, clear the corresponding asserted flag bit in CAN_STAT register, then read the CAN_TIMER register at last for a complete flag bit service.
Page 640
GD32A513 User Manual Initialize the Tx / Rx mailbox descriptors 1) If message transmission is needed, initialize the Tx mailbox descriptors. 2) If message reception is needed, initialize the Rx mailbox descriptors, if Rx FIFO is enabled, also initialize the Rx FIFO descriptors including the ID filter table elements.
Page 641
GD32A513 User Manual CAN registers 23.5. CAN0 base address: 0x4001 A000 CAN1 base address: 0x4001 B000 Control register 0 (CAN_CTL0) 23.5.1. Address offset: 0x00 Reset value: 0x5900 000F All bits except bit 30, 28, 25, 19 of this register should be configured in Inactive mode only, because they are blocked by hardware in other modes.
Page 642
GD32A513 User Manual 0: CAN is ready 1: CAN is not ready Reserved Must be kept at reset value. SWRST Software reset When this bit is set, CAN internal state machines and CAN registers will be reset. This bit is automitically cleared by hardware when software reset is completed.
Page 643
GD32A513 User Manual 1: Select Pretended Networking mode LAPRIOEN Local arbitration priority enable 0: Disable local arbitration priority 1: Enable local arbitration priority Mailbox stop transmission 0: Disable transmission abort 1: Enable transmission abort FDEN CAN FD operation enable 0: Disable CAN FD operation...
GD32A513 User Manual Reserved BOIE ERRSIE Reserved LSCMOD TWERRIE RWERRIE Reserved BSPMOD ABORDIS TSYNC MMOD Reserved Bits Fields Descriptions 31:16 Reserved Must be kept at reset value. BOIE Bus off interrupt enable 0: Disable Bus off interrupt 1: Enable Bus off interrupt...
Page 645
GD32A513 User Manual TSYNC Time synchronization enable synchronization 0: Disable time synchronization 1: Enable time Mailbox transmission order 0: Highest priority mailbox is transmitted first 1: Lowest number mailbox is transmitted first MMOD Monitor mode 0: Disable Monitor mode 1: Enable Monitor mode Reserved Must be kept at reset value.
Page 646
GD32A513 User Manual MFD15 MFD14 MFD13 MFD12 MFD11 MFD10 MFD9 MFD8 MFD7 MFD6 MFD5 MFD4 MFD3 MFD2 MFD1 MFD0 Bits Fields Descriptions 31:0 MFDx Mailbox filter data MFD31 bit is used to filter the mailbox descriptor RTR field. MFD30 bit is used to filter the mailbox descriptor IDE field.
GD32A513 User Manual rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 BRERR BDERR ACKERR CRCERR FMERR STFERR TWERRF RWERRF IDLEF ERRSI[1:0] ERRSF Reserved rc_w1 rc_w1 Bits Fields Descriptions BRFERR Bit recessive error in data phase of FD frames with the BRS bit set...
GD32A513 User Manual 1: Bus off recovery sequence event occurs Synchronization flag 0: Not synchronized to the CAN bus 1: Synchronized to the CAN bus TWERRIF Tx error warning interrupt flag This bit is not used during Bus off state.
Page 649
GD32A513 User Manual RWERRF Rx error warning flag This bit is updated when exiting from Pretended Networking mode. 0: No event occurrence. 1: RECNT[7:0] in CAN_ERR0 register is greater than or equal to 96 IDLEF IDLE flag 0: No event occurrence...
GD32A513 User Manual 0: No successful transmission or reception has occurred in the mailbox descriptor 6 when Rx FIFO is disabled. / Rx FIFO has no warning when Rx FIFO is enabled. 1: A successful transmission or reception has occurred in the mailbox descriptor 6 when Rx FIFO is disabled.
GD32A513 User Manual ITSRC PREEN Reserved EFDIS Reserved Bits Fields Descriptions ERRFSIE Error summary interrupt enable bit for data phase of FD frames with BRS bit set 0: Disable error summary interrupt for data phase of FD frames with BRS bit set...
Page 653
GD32A513 User Manual 1: Mailboxes are filtered first RRFRMS Remote request frame is stored 0: Remote response frame is generated when a mailbox with CODE RANSWER is found with the same ID 1: Remote request frame is stored as a data frame without automatic remote...
Page 654
GD32A513 User Manual Bits Fields Descriptions 31:21 Reserved Must be kept at reset value. 20:16 ANTM[4:0] Associated number of mailbox for transmitting the CRCTC[14:0] value This bit field contains the number of the mailbox which transmits the CRCTC[14:0] value. Reserved Must be kept at reset value.
Page 655
GD32A513 User Manual Reserved Reserved IDFMN[8:0] Bits Fields Descriptions 31:9 Reserved Must be kept at reset value. IDFMN[8:0] Identifier filter matching number This field is valid only when MS5_RFNE bit in CAN_STAT register is 1. This bit field indicates which ID filter table element matches the received message that is in the output of the Rx FIFO.
Page 656
GD32A513 User Manual Phase buffer segment 1 time quantum = PBS1[4:0] + 1 PBS2[4:0] Phase buffer segment 2 Phase buffer segment 2 time quantum = PBS2[4:0] + 1 Receive FIFO/mailbox private filter x register (CAN_RFIFOMPFx)(x=0..31) 23.5.14. Address offset: 0x880 + 4 x Reset value: 0xXXXX XXXX These register is located in RAM.
Page 657
GD32A513 User Manual Bits Fields Descriptions 31:18 Reserved Must be kept at reset value. WTOIE Wakeup timeout interrupt enable 0: Disable wakeup timeout interrupt 1: Enable wakeup timeout interrupt WMIE Wakeup match interrupt enable 0: Disable wakeup match interrupt 1: Enable wakeup match interrupt...
Page 658
GD32A513 User Manual 01: All fields are filtered 10: All fields except DATA field, DLC field are filtered with NMM[7:0] matching times 11: All fields are filtered with NMM[7:0] matching times Pretended Networking mode timeout register (CAN_PN_TO) 23.5.16. Address offset: 0xB04...
Page 659
GD32A513 User Manual 1: Wakeup timeout event occured Wakeup match flag status 0: No wakeup match event occured 1: Wakeup match event occured 15:8 MMCNT[7:0] Matching message counter in Pretended Networking mode This bit field indicates the matching message number during Pretended Networking mode.
Page 660
GD32A513 User Manual This bit field is used as expected ID field when IDFT[1:0] bit field in CAN_PN_CTL0 register is 0 / 1 / 2, or is used as expected ID low threshold when IDFT[1:0] bit field is 3. For extended frame format, all 29 bits are used.
GD32A513 User Manual Bits Fields Descriptions 31:24 DB0ELT[7:0] Data byte 0 expected low threshold in Pretended Networking mode Refer to DB3ELT[7:0] descriptions. 23:16 DB1ELT[7:0] Data byte 1 expected low threshold in Pretended Networking mode Refer to DB3ELT[7:0] descriptions. 15:8 DB2ELT[7:0] Data byte 2 expected low threshold in Pretended Networking mode Refer to DB3ELT[7:0] descriptions.
Page 662
GD32A513 User Manual Pretended Networking mode identifier filter / expected identifier 1 23.5.22. register (CAN_PN_IFEID1) Address offset: 0x B1C Reset value: 0x0000 0000 All bits of this register should be configured in Inactive mode only, because they are blocked by hardware in other modes.
Page 663
GD32A513 User Manual This register has to be accessed by word(32-bit). DB0FD_EHT[7:0] DB1FD_EHT[7:0] DB2FD_EHT[7:0] DB3FD_EHT[7:0] Bits Fields Descriptions 31:24 DB0FD_EHT[7:0] Data byte 0 filter data / Data byte 0 expected high threshold in Pretended Networking mode Refer to DB3FD_EHT[7:0] descriptions.
Page 664
GD32A513 User Manual Bits Fields Descriptions 31:24 DB4FD_HTF[7:0] Data byte 4 filter data / Data byte 4 expected high threshold in Pretended Networking mode Refer to DB3FD_EHT[7:0] descriptions. 23:16 DB5FD_HTF[7:0] Data byte 5 filter data / Data byte 5 expected high threshold in Pretended Networking mode Refer to DB3FD_EHT[7:0] descriptions.
Page 665
GD32A513 User Manual 19:16 RDLC[3:0] Received DLC bits The bit field indicates the valid data byte length. 15:0 Reserved Must be kept at reset value. Pretended Networking mode received wakeup mailbox x identifier 23.5.26. register (CAN_PN_RWMxI)(x=0..3) Address offset: 0xB44 + 16 * x Reset value: 0x0000 0000 This register has to be accessed by word(32-bit).
Page 666
GD32A513 User Manual 23:16 RDB1[7:0] Received data byte 1 15:8 RDB2[7:0] Received data byte 2 RDB3[7:0] Received data byte 3 Pretended Networking mode received wakeup mailbox x data 1 register 23.5.28. (CAN_PN_RWMxD1)(x=0..3) Address offset: 0xB4C + 16 * x Reset value: 0x0000 0000 This register has to be accessed by word(32-bit).
Page 667
GD32A513 User Manual Bits Fields Descriptions BRSEN Bit rate of data switch enable 0: Bit rate not switch 1: The bit rate shall be switched from the nominal bit rate to the preconfigured data bit rate during the data phase when BRS bit in Tx mailbox is recessive ‘1’...
Page 668
GD32A513 User Manual This register has to be accessed by word(32-bit). Reserved DBAUDPSC[9:0] Reserved DSJW[2:0] Reserved DPTS[4:0] Reserved DPBS1[2:0] Reserved DPBS2[2:0] Bits Fields Descriptions 31:30 Reserved Must be kept at reset value. 29:20 DBAUDPSC[9:0] Baud rate prescaler for data bit time The CAN data bit time baud rate prescaler.
Page 669
GD32A513 User Manual 31:29 Reserved Must be kept at reset value. 28:24 ANTM[4:0] Associated number of mailbox for transmitting the CRCTCI[20:0] value This bit field contains the number of the mailbox which transmits the CRCTCI[20:0] value for both classical and FD frames.
GD32A513 User Manual Appendix 24.1. List of abbreviations used in register Table 24-1. List of abbreviations used in register abbreviations for Descriptions registers read/write (rw) Software can read and write to this bit. read-only (r) Software can only read this bit.
Page 671
GD32A513 User Manual 24.3. Available peripherals For availability of peripherals and their number across all MCU series types, refer to the corresponding device data datasheet.
GD32A513 User Manual Revision history Table 25-1. Revision history Revision No. Description Date Initial Release Mar.11, 2024...
Page 673
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.
Need help?
Do you have a question about the GD32A513 and is the answer not in the manual?
Questions and answers