Skip to content

Commit 235bbef

Browse files
authored
feat(gd32 driver) Add support for hardware i2c with gd32e230
1 parent 715334f commit 235bbef

File tree

10 files changed

+716
-11
lines changed

10 files changed

+716
-11
lines changed

bsp/gd32/arm/gd32e230-lckfb/.ci/attachconfig/ci.attachconfig.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ hw_drv_onchip.i2c0:
2222
kconfig:
2323
- CONFIG_BSP_USING_I2C0=y
2424
- CONFIG_BSP_I2C0_SCL_PIN=22
25-
- CONFIG_BSP_I2C0_SDA_PIN=23
25+
- CONFIG_BSP_I2C0_SDA_PIN=23
26+
hw_drv_onchip.i2c1:
27+
kconfig:
28+
- CONFIG_BSP_USING_HW_I2C=y
29+
- CONFIG_BSP_USING_HW_I2C1=y
30+
- CONFIG_BSP_HW_I2C1_CLOCK_SPEED=400000

bsp/gd32/arm/gd32e230-lckfb/.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
# CONFIG_RT_UTEST_TC_USING_KLIBC is not set
109109
# end of klibc options
110110

111-
CONFIG_RT_NAME_MAX=8
111+
CONFIG_RT_NAME_MAX=20
112112
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
113113
# CONFIG_RT_USING_NANO is not set
114114
# CONFIG_RT_USING_SMART is not set

bsp/gd32/arm/gd32e230-lckfb/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,18 @@
3636
| :--- | :---: | :--- |
3737
| GPIO | 支持 | PAx, PBx... |
3838
| UART | 支持 | USART0, USART1 |
39+
| I2C | 支持 | I2C0, I2C1 硬件I2C |
3940
| **扩展模块** | **支持情况** | **备注** |
4041
| 暂无 | 暂不支持 | 暂不支持 |
4142

43+
### 补充说明
44+
45+
I2C 引脚分配:
46+
- **I2C0**: SCL(PB6), SDA(PB7)
47+
- **I2C1**: SCL(PB10), SDA(PB11)
48+
默认速率400KHz,可以配置调整。
49+
50+
4251
## 使用说明
4352

4453
使用说明分为如下两个章节:
@@ -95,7 +104,7 @@ pyocd flash -t gd32e230c8t6 rtthread.bin
95104
4. 输入 `scons -j12` 编译。
96105

97106
## 注意事项
98-
1. GD32E230资源受限,虽然通过调整参数极限运行msh,但是意义不大,建议关闭。
107+
1. GD32E230资源受限,虽然通过调整参数可以运行msh,但是意义不大,建议关闭。
99108
2. **GPIOA-13****GPIOA-14** 默认用于 SWD 调试下载功能,建议不要配置为其它功能,否则将可能导致无法正常下载和调试。
100109

101110
## 联系人信息

bsp/gd32/arm/gd32e230-lckfb/board/Kconfig

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,35 @@ menu "On-chip Peripheral Drivers"
146146
select RT_USING_I2C
147147
default n
148148
if BSP_USING_HW_I2C
149-
config BSP_USING_I2C0
149+
config BSP_USING_HW_I2C0
150150
bool "Enable I2C0"
151151
default y
152152

153-
config BSP_USING_I2C1
153+
config BSP_HW_I2C0_CLOCK_SPEED
154+
int "I2C0 Clock Speed (Hz)"
155+
depends on BSP_USING_HW_I2C0
156+
range 100000 1000000
157+
default 400000
158+
help
159+
Set the I2C0 clock speed in Hz.
160+
Standard mode: 100000 (100KHz)
161+
Fast mode: 400000 (400KHz)
162+
Fast mode plus: 1000000 (1MHz)
163+
164+
config BSP_USING_HW_I2C1
154165
bool "Enable I2C1"
155166
default n
167+
168+
config BSP_HW_I2C1_CLOCK_SPEED
169+
int "I2C1 Clock Speed (Hz)"
170+
depends on BSP_USING_HW_I2C1
171+
range 100000 1000000
172+
default 400000
173+
help
174+
Set the I2C1 clock speed in Hz.
175+
Standard mode: 100000 (100KHz)
176+
Fast mode: 400000 (400KHz)
177+
Fast mode plus: 1000000 (1MHz)
156178
endif
157179
menuconfig BSP_USING_I2C0
158180
bool "Enable I2C0 BUS (software simulation)"

bsp/gd32/arm/gd32e230-lckfb/board/linker_scripts/link.ld

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ SECTIONS
129129

130130
/* Discard all debugging and comment sections using the correct wildcard syntax */
131131
*(.comment)
132-
*(.debug*)
133-
*(.line)
134-
*(.stab)
135-
*(.stabstr)
136132
*(.note.gnu.build-id)
137133
*(.ARM.attributes)
138134
}

bsp/gd32/arm/gd32e230-lckfb/rtconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
/* end of rt_strnlen options */
6363
/* end of klibc options */
64-
#define RT_NAME_MAX 8
64+
#define RT_NAME_MAX 20
6565
#define RT_CPUS_NR 1
6666
#define RT_ALIGN_SIZE 8
6767
#define RT_THREAD_PRIORITY_32

bsp/gd32/arm/gd32e230-lckfb/rtconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
if os.getenv('RTT_EXEC_PATH'):
2929
EXEC_PATH = os.getenv('RTT_EXEC_PATH')
3030

31-
BUILD = 'release'
31+
BUILD = 'debug'
3232

3333
if PLATFORM == 'gcc':
3434
# toolchains

bsp/gd32/arm/libraries/gd32_drivers/SConscript

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ if GetDepend(['RT_USING_SERIAL']):
2323
if GetDepend(['RT_USING_I2C', 'RT_USING_I2C_BITOPS']):
2424
if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1') or GetDepend('BSP_USING_I2C2') or GetDepend('BSP_USING_I2C3'):
2525
src += ['drv_soft_i2c.c']
26+
27+
# add i2c hard drivers.
28+
if GetDepend(['RT_USING_I2C']):
29+
if GetDepend('BSP_USING_HW_I2C0') or GetDepend('BSP_USING_HW_I2C1'):
30+
src += ['drv_hw_i2c.c']
2631

2732
# add spi drivers.
2833
if GetDepend('RT_USING_SPI'):

0 commit comments

Comments
 (0)