Skip to content

Commit d8af9a4

Browse files
authored
Merge pull request #1 from howitzer74/main
GD32F4xx support
2 parents 465e375 + 4e07d8f commit d8af9a4

64 files changed

Lines changed: 36199 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

gd32/cmsis/variants/gd32f40x/gd32f4xx.h

Lines changed: 365 additions & 0 deletions
Large diffs are not rendered by default.

gd32/cmsis/variants/gd32f40x/startup_gd32f407.s

Lines changed: 462 additions & 0 deletions
Large diffs are not rendered by default.

gd32/cmsis/variants/gd32f40x/system_gd32f4xx.c

Lines changed: 926 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*!
2+
\file system_gd32f4xx.h
3+
\brief CMSIS Cortex-M4 Device Peripheral Access Layer Header File for
4+
GD32F4xx Device Series
5+
*/
6+
7+
/* Copyright (c) 2012 ARM LIMITED
8+
9+
All rights reserved.
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are met:
12+
- Redistributions of source code must retain the above copyright
13+
notice, this list of conditions and the following disclaimer.
14+
- Redistributions in binary form must reproduce the above copyright
15+
notice, this list of conditions and the following disclaimer in the
16+
documentation and/or other materials provided with the distribution.
17+
- Neither the name of ARM nor the names of its contributors may be used
18+
to endorse or promote products derived from this software without
19+
specific prior written permission.
20+
*
21+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
25+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
POSSIBILITY OF SUCH DAMAGE.
32+
---------------------------------------------------------------------------*/
33+
34+
/* This file refers the CMSIS standard, some adjustments are made according to GigaDevice chips */
35+
36+
#ifndef SYSTEM_GD32F4XX_H
37+
#define SYSTEM_GD32F4XX_H
38+
39+
#ifdef __cplusplus
40+
extern "C" {
41+
#endif
42+
43+
#include <stdint.h>
44+
45+
/* system clock frequency (core clock) */
46+
extern uint32_t SystemCoreClock;
47+
48+
/* function declarations */
49+
/* initialize the system and update the SystemCoreClock variable */
50+
extern void SystemInit (void);
51+
/* update the SystemCoreClock with current core clock retrieved from cpu registers */
52+
extern void SystemCoreClockUpdate (void);
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif
57+
58+
#endif /* SYSTEM_GD32F4XX_H */

gd32/spl/variants/gd32f40x/inc/gd32f4xx_adc.h

Lines changed: 515 additions & 0 deletions
Large diffs are not rendered by default.

gd32/spl/variants/gd32f40x/inc/gd32f4xx_can.h

Lines changed: 754 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*!
2+
\file gd32f4xx_crc.h
3+
\brief definitions for the CRC
4+
5+
\version 2016-08-15, V1.0.0, firmware for GD32F4xx
6+
\version 2018-12-12, V2.0.0, firmware for GD32F4xx
7+
\version 2020-09-30, V2.1.0, firmware for GD32F4xx
8+
*/
9+
10+
/*
11+
Copyright (c) 2020, GigaDevice Semiconductor Inc.
12+
13+
Redistribution and use in source and binary forms, with or without modification,
14+
are permitted provided that the following conditions are met:
15+
16+
1. Redistributions of source code must retain the above copyright notice, this
17+
list of conditions and the following disclaimer.
18+
2. Redistributions in binary form must reproduce the above copyright notice,
19+
this list of conditions and the following disclaimer in the documentation
20+
and/or other materials provided with the distribution.
21+
3. Neither the name of the copyright holder nor the names of its contributors
22+
may be used to endorse or promote products derived from this software without
23+
specific prior written permission.
24+
25+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34+
OF SUCH DAMAGE.
35+
*/
36+
37+
#ifndef GD32F4XX_CRC_H
38+
#define GD32F4XX_CRC_H
39+
40+
#include "gd32f4xx.h"
41+
42+
/* CRC definitions */
43+
#define CRC CRC_BASE
44+
45+
/* registers definitions */
46+
#define CRC_DATA REG32(CRC + 0x00U) /*!< CRC data register */
47+
#define CRC_FDATA REG32(CRC + 0x04U) /*!< CRC free data register */
48+
#define CRC_CTL REG32(CRC + 0x08U) /*!< CRC control register */
49+
50+
/* bits definitions */
51+
/* CRC_DATA */
52+
#define CRC_DATA_DATA BITS(0,31) /*!< CRC calculation result bits */
53+
54+
/* CRC_FDATA */
55+
#define CRC_FDATA_FDATA BITS(0,7) /*!< CRC free data bits */
56+
57+
/* CRC_CTL */
58+
#define CRC_CTL_RST BIT(0) /*!< CRC reset CRC_DATA register bit */
59+
60+
61+
/* function declarations */
62+
/* deinit CRC calculation unit */
63+
void crc_deinit(void);
64+
65+
/* reset data register(CRC_DATA) to the value of 0xFFFFFFFF */
66+
void crc_data_register_reset(void);
67+
/* read the value of the data register */
68+
uint32_t crc_data_register_read(void);
69+
70+
/* read the value of the free data register */
71+
uint8_t crc_free_data_register_read(void);
72+
/* write data to the free data register */
73+
void crc_free_data_register_write(uint8_t free_data);
74+
75+
/* calculate the CRC value of a 32-bit data */
76+
uint32_t crc_single_data_calculate(uint32_t sdata);
77+
/* calculate the CRC value of an array of 32-bit values */
78+
uint32_t crc_block_data_calculate(uint32_t array[], uint32_t size);
79+
80+
#endif /* GD32F4XX_CRC_H */
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*!
2+
\file gd32f4xx_ctc.h
3+
\brief definitions for the CTC
4+
5+
\version 2016-08-15, V1.0.0, firmware for GD32F4xx
6+
\version 2018-12-12, V2.0.0, firmware for GD32F4xx
7+
\version 2020-09-30, V2.1.0, firmware for GD32F4xx
8+
*/
9+
10+
/*
11+
Copyright (c) 2020, GigaDevice Semiconductor Inc.
12+
13+
Redistribution and use in source and binary forms, with or without modification,
14+
are permitted provided that the following conditions are met:
15+
16+
1. Redistributions of source code must retain the above copyright notice, this
17+
list of conditions and the following disclaimer.
18+
2. Redistributions in binary form must reproduce the above copyright notice,
19+
this list of conditions and the following disclaimer in the documentation
20+
and/or other materials provided with the distribution.
21+
3. Neither the name of the copyright holder nor the names of its contributors
22+
may be used to endorse or promote products derived from this software without
23+
specific prior written permission.
24+
25+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28+
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34+
OF SUCH DAMAGE.
35+
*/
36+
37+
#ifndef GD32F4XX_CTC_H
38+
#define GD32F4XX_CTC_H
39+
40+
#include "gd32f4xx.h"
41+
42+
/* CTC definitions */
43+
#define CTC CTC_BASE
44+
45+
/* registers definitions */
46+
#define CTC_CTL0 REG32((CTC) + 0x00U) /*!< CTC control register 0 */
47+
#define CTC_CTL1 REG32((CTC) + 0x04U) /*!< CTC control register 1 */
48+
#define CTC_STAT REG32((CTC) + 0x08U) /*!< CTC status register */
49+
#define CTC_INTC REG32((CTC) + 0x0CU) /*!< CTC interrupt clear register */
50+
51+
/* bits definitions */
52+
/* CTC_CTL0 */
53+
#define CTC_CTL0_CKOKIE BIT(0) /*!< clock trim OK(CKOKIF) interrupt enable */
54+
#define CTC_CTL0_CKWARNIE BIT(1) /*!< clock trim warning(CKWARNIF) interrupt enable */
55+
#define CTC_CTL0_ERRIE BIT(2) /*!< error(ERRIF) interrupt enable */
56+
#define CTC_CTL0_EREFIE BIT(3) /*!< EREFIF interrupt enable */
57+
#define CTC_CTL0_CNTEN BIT(5) /*!< CTC counter enable */
58+
#define CTC_CTL0_AUTOTRIM BIT(6) /*!< hardware automatically trim mode */
59+
#define CTC_CTL0_SWREFPUL BIT(7) /*!< software reference source sync pulse */
60+
#define CTC_CTL0_TRIMVALUE BITS(8,13) /*!< IRC48M trim value */
61+
62+
/* CTC_CTL1 */
63+
#define CTC_CTL1_RLVALUE BITS(0,15) /*!< CTC counter reload value */
64+
#define CTC_CTL1_CKLIM BITS(16,23) /*!< clock trim base limit value */
65+
#define CTC_CTL1_REFPSC BITS(24,26) /*!< reference signal source prescaler */
66+
#define CTC_CTL1_REFSEL BITS(28,29) /*!< reference signal source selection */
67+
#define CTC_CTL1_USBSOFSEL BIT(30) /*!< USBFS or USBHS SOF signal selection */
68+
#define CTC_CTL1_REFPOL BIT(31) /*!< reference signal source polarity */
69+
70+
/* CTC_STAT */
71+
#define CTC_STAT_CKOKIF BIT(0) /*!< clock trim OK interrupt flag */
72+
#define CTC_STAT_CKWARNIF BIT(1) /*!< clock trim warning interrupt flag */
73+
#define CTC_STAT_ERRIF BIT(2) /*!< error interrupt flag */
74+
#define CTC_STAT_EREFIF BIT(3) /*!< expect reference interrupt flag */
75+
#define CTC_STAT_CKERR BIT(8) /*!< clock trim error bit */
76+
#define CTC_STAT_REFMISS BIT(9) /*!< reference sync pulse miss */
77+
#define CTC_STAT_TRIMERR BIT(10) /*!< trim value error bit */
78+
#define CTC_STAT_REFDIR BIT(15) /*!< CTC trim counter direction when reference sync pulse occurred */
79+
#define CTC_STAT_REFCAP BITS(16,31) /*!< CTC counter capture when reference sync pulse occurred */
80+
81+
/* CTC_INTC */
82+
#define CTC_INTC_CKOKIC BIT(0) /*!< CKOKIF interrupt clear bit */
83+
#define CTC_INTC_CKWARNIC BIT(1) /*!< CKWARNIF interrupt clear bit */
84+
#define CTC_INTC_ERRIC BIT(2) /*!< ERRIF interrupt clear bit */
85+
#define CTC_INTC_EREFIC BIT(3) /*!< EREFIF interrupt clear bit */
86+
87+
/* constants definitions */
88+
/* hardware automatically trim mode definitions */
89+
#define CTC_HARDWARE_TRIM_MODE_ENABLE CTC_CTL0_AUTOTRIM /*!< hardware automatically trim mode enable*/
90+
#define CTC_HARDWARE_TRIM_MODE_DISABLE ((uint32_t)0x00000000U) /*!< hardware automatically trim mode disable*/
91+
92+
/* reference signal source polarity definitions */
93+
#define CTC_REFSOURCE_POLARITY_FALLING CTC_CTL1_REFPOL /*!< reference signal source polarity is falling edge*/
94+
#define CTC_REFSOURCE_POLARITY_RISING ((uint32_t)0x00000000U) /*!< reference signal source polarity is rising edge*/
95+
96+
/* USBFS or USBHS SOF signal selection definitions */
97+
#define CTC_USBSOFSEL_USBHS CTC_CTL1_USBSOFSEL /*!< USBHS SOF signal is selected*/
98+
#define CTC_USBSOFSEL_USBFS ((uint32_t)0x00000000U) /*!< USBFS SOF signal is selected*/
99+
100+
/* reference signal source selection definitions */
101+
#define CTL1_REFSEL(regval) (BITS(28,29) & ((uint32_t)(regval) << 28))
102+
#define CTC_REFSOURCE_GPIO CTL1_REFSEL(0) /*!< GPIO is selected */
103+
#define CTC_REFSOURCE_LXTAL CTL1_REFSEL(1) /*!< LXTAL is clock selected */
104+
#define CTC_REFSOURCE_USBSOF CTL1_REFSEL(2) /*!< USBSOF is selected */
105+
106+
/* reference signal source prescaler definitions */
107+
#define CTL1_REFPSC(regval) (BITS(24,26) & ((uint32_t)(regval) << 24))
108+
#define CTC_REFSOURCE_PSC_OFF CTL1_REFPSC(0) /*!< reference signal not divided */
109+
#define CTC_REFSOURCE_PSC_DIV2 CTL1_REFPSC(1) /*!< reference signal divided by 2 */
110+
#define CTC_REFSOURCE_PSC_DIV4 CTL1_REFPSC(2) /*!< reference signal divided by 4 */
111+
#define CTC_REFSOURCE_PSC_DIV8 CTL1_REFPSC(3) /*!< reference signal divided by 8 */
112+
#define CTC_REFSOURCE_PSC_DIV16 CTL1_REFPSC(4) /*!< reference signal divided by 16 */
113+
#define CTC_REFSOURCE_PSC_DIV32 CTL1_REFPSC(5) /*!< reference signal divided by 32 */
114+
#define CTC_REFSOURCE_PSC_DIV64 CTL1_REFPSC(6) /*!< reference signal divided by 64 */
115+
#define CTC_REFSOURCE_PSC_DIV128 CTL1_REFPSC(7) /*!< reference signal divided by 128 */
116+
117+
/* CTC interrupt enable definitions */
118+
#define CTC_INT_CKOK CTC_CTL0_CKOKIE /*!< clock trim OK interrupt enable */
119+
#define CTC_INT_CKWARN CTC_CTL0_CKWARNIE /*!< clock trim warning interrupt enable */
120+
#define CTC_INT_ERR CTC_CTL0_ERRIE /*!< error interrupt enable */
121+
#define CTC_INT_EREF CTC_CTL0_EREFIE /*!< expect reference interrupt enable */
122+
123+
/* CTC interrupt source definitions */
124+
#define CTC_INT_FLAG_CKOK CTC_STAT_CKOKIF /*!< clock trim OK interrupt flag */
125+
#define CTC_INT_FLAG_CKWARN CTC_STAT_CKWARNIF /*!< clock trim warning interrupt flag */
126+
#define CTC_INT_FLAG_ERR CTC_STAT_ERRIF /*!< error interrupt flag */
127+
#define CTC_INT_FLAG_EREF CTC_STAT_EREFIF /*!< expect reference interrupt flag */
128+
#define CTC_INT_FLAG_CKERR CTC_STAT_CKERR /*!< clock trim error bit */
129+
#define CTC_INT_FLAG_REFMISS CTC_STAT_REFMISS /*!< reference sync pulse miss */
130+
#define CTC_INT_FLAG_TRIMERR CTC_STAT_TRIMERR /*!< trim value error */
131+
132+
/* CTC flag definitions */
133+
#define CTC_FLAG_CKOK CTC_STAT_CKOKIF /*!< clock trim OK flag */
134+
#define CTC_FLAG_CKWARN CTC_STAT_CKWARNIF /*!< clock trim warning flag */
135+
#define CTC_FLAG_ERR CTC_STAT_ERRIF /*!< error flag */
136+
#define CTC_FLAG_EREF CTC_STAT_EREFIF /*!< expect reference flag */
137+
#define CTC_FLAG_CKERR CTC_STAT_CKERR /*!< clock trim error bit */
138+
#define CTC_FLAG_REFMISS CTC_STAT_REFMISS /*!< reference sync pulse miss */
139+
#define CTC_FLAG_TRIMERR CTC_STAT_TRIMERR /*!< trim value error bit */
140+
141+
/* function declarations */
142+
/* reset ctc clock trim controller */
143+
void ctc_deinit(void);
144+
/* enable CTC trim counter */
145+
void ctc_counter_enable(void);
146+
/* disable CTC trim counter */
147+
void ctc_counter_disable(void);
148+
149+
/* configure the IRC48M trim value */
150+
void ctc_irc48m_trim_value_config(uint8_t trim_value);
151+
/* generate software reference source sync pulse */
152+
void ctc_software_refsource_pulse_generate(void);
153+
/* configure hardware automatically trim mode */
154+
void ctc_hardware_trim_mode_config(uint32_t hardmode);
155+
156+
/* configure reference signal source polarity */
157+
void ctc_refsource_polarity_config(uint32_t polarity);
158+
/* select USBFS or USBHS SOF signal */
159+
void ctc_usbsof_signal_select(uint32_t usbsof);
160+
/* select reference signal source */
161+
void ctc_refsource_signal_select(uint32_t refs);
162+
/* configure reference signal source prescaler */
163+
void ctc_refsource_prescaler_config(uint32_t prescaler);
164+
/* configure clock trim base limit value */
165+
void ctc_clock_limit_value_config(uint8_t limit_value);
166+
/* configure CTC counter reload value */
167+
void ctc_counter_reload_value_config(uint16_t reload_value);
168+
169+
/* read CTC counter capture value when reference sync pulse occurred */
170+
uint16_t ctc_counter_capture_value_read(void);
171+
/* read CTC trim counter direction when reference sync pulse occurred */
172+
FlagStatus ctc_counter_direction_read(void);
173+
/* read CTC counter reload value */
174+
uint16_t ctc_counter_reload_value_read(void);
175+
/* read the IRC48M trim value */
176+
uint8_t ctc_irc48m_trim_value_read(void);
177+
178+
/* interrupt & flag functions */
179+
/* enable the CTC interrupt */
180+
void ctc_interrupt_enable(uint32_t interrupt);
181+
/* disable the CTC interrupt */
182+
void ctc_interrupt_disable(uint32_t interrupt);
183+
/* get CTC interrupt flag */
184+
FlagStatus ctc_interrupt_flag_get(uint32_t int_flag);
185+
/* clear CTC interrupt flag */
186+
void ctc_interrupt_flag_clear(uint32_t int_flag);
187+
/* get CTC flag */
188+
FlagStatus ctc_flag_get(uint32_t flag);
189+
/* clear CTC flag */
190+
void ctc_flag_clear(uint32_t flag);
191+
192+
#endif /* GD32F4XX_CTC_H */

0 commit comments

Comments
 (0)