From 8982ff186d00ddbd98541c3c9d454023d736a35d Mon Sep 17 00:00:00 2001 From: CXSforHPU <19511928573@163.com> Date: Sun, 1 Feb 2026 00:24:15 +0800 Subject: [PATCH] Add an example for measuring the onboard peripherals of the I2C board --- bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig | 14 ++++ .../risc-v/gd32vw553h-eval/board/SConscript | 6 ++ .../gd32vw553h-eval/board/port/SConscript | 24 +++++++ .../board/port/at24c02/at24c02_sample.c | 69 +++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 bsp/gd32/risc-v/gd32vw553h-eval/board/port/SConscript create mode 100644 bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02_sample.c diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig index 6bb5df41373..cb608fad953 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/Kconfig @@ -84,6 +84,20 @@ endmenu menu "Board extended module Drivers" + menuconfig BSP_USING_AT24C02 + bool "Enable AT24C02 I2C0( SCL[PA2 : 2] SDA[PA3 : 3] )" + default n + select PKG_USING_AT24CXX + select PKG_AT24CXX_EE_TYPE_AT24C02 + + if BSP_USING_AT24C02 + + config BSP_USING_AT24C02_FINISH_TEST + bool "Enable the test of AT24C02" + default n + + endif + endmenu endmenu diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/SConscript b/bsp/gd32/risc-v/gd32vw553h-eval/board/SConscript index 71fadebe66f..e8721535066 100644 --- a/bsp/gd32/risc-v/gd32vw553h-eval/board/SConscript +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/SConscript @@ -24,4 +24,10 @@ if rtconfig.PLATFORM in ['gcc']: CPPDEFINES = ['GD32VW553H_EVAL'] group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES) +list = os.listdir(cwd) +for item in list: + if os.path.isfile(os.path.join(cwd, item, 'SConscript')): + group = group + SConscript(os.path.join(item, 'SConscript')) + + Return('group') diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/port/SConscript b/bsp/gd32/risc-v/gd32vw553h-eval/board/port/SConscript new file mode 100644 index 00000000000..61cdfc37375 --- /dev/null +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/port/SConscript @@ -0,0 +1,24 @@ +import os +from building import * + +objs = [] +cwd = GetCurrentDir() + +# add general drivers +src = [] +path = [cwd] + +if GetDepend(['BSP_USING_AT24C02_FINISH_TEST']): + path += [cwd + "/at24c02"] + src += ["./at24c02/at24c02_sample.c"] + + +CPPDEFINES = ['GD32VW553H_EVAL'] +group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES) + +list = os.listdir(cwd) +for item in list: + if os.path.isfile(os.path.join(cwd, item, 'SConscript')): + group = group + SConscript(os.path.join(item, 'SConscript')) + +Return('group') diff --git a/bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02_sample.c b/bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02_sample.c new file mode 100644 index 00000000000..d0c3e95365b --- /dev/null +++ b/bsp/gd32/risc-v/gd32vw553h-eval/board/port/at24c02/at24c02_sample.c @@ -0,0 +1,69 @@ +#include "rtconfig.h" + +#ifdef BSP_USING_AT24C02 + +#include "at24cxx.h" +#include + +#define AT24C02_I2C_NAME "i2c0" +#define TEST_DATA "WELCOM TO RTT" + +static at24cxx_device_t dev = RT_NULL; + +/** + * @brief AT24C02 EEPROM测试函数 + * + * @param argc 参数个数 + * @param argv 参数数组 + */ +void gd32_at24c02_test(int argc, char *argv[]) +{ + rt_err_t result = RT_EOK; + uint8_t write_buffer[] = TEST_DATA; + uint8_t AddrInput = 0x0; + int data_size = sizeof(write_buffer); + + uint8_t read_buffer[50] = {0}; + + /* 初始化设备 */ + if (dev == RT_NULL) + { + dev = at24cxx_init(AT24C02_I2C_NAME, AddrInput); + if (dev == RT_NULL) + { + rt_kprintf("AT24C02 initialization failed\n"); + return; + } + rt_kprintf("AT24C02 initialized successfully\n"); + } + + /* 写入数据 */ + result = at24cxx_write(dev, 0, write_buffer, data_size); + if (result == RT_ERROR) + { + rt_kprintf("Failed to write data to AT24C02\n"); + goto cleanup; + } + rt_kprintf("Successfully wrote to AT24C02: %s\n", write_buffer); + + /* 读取数据 */ + result = at24cxx_read(dev, 0, read_buffer, data_size); + if (result == RT_ERROR) + { + rt_kprintf("Failed to read data from AT24C02\n"); + goto cleanup; + } + rt_kprintf("Successfully read from AT24C02: %s\n", read_buffer); + + +cleanup: + /* 清理资源 */ + + at24cxx_deinit(dev); + + return; +} + +MSH_CMD_EXPORT(gd32_at24c02_test, GD32 AT24C02 EEPROM test function); + +#endif \ No newline at end of file