Skip to content

[ht32][drv]新增了CAN、USB和SDIO的驱动文件 #9876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 218 additions & 44 deletions bsp/ht32/ht32f12366/.config

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bsp/ht32/ht32f12366/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ ESK32-30105使用32位ARM® Cortex®-M3高性能、低功耗单片机HT32F12366
| UART | 支持 | UART0/1 |
| SPI | 支持 | SPI0/1 |
| I2C | 支持 | 硬件 I2C0/1 |
| ADC | 暂不支持 | |
| WDT | 暂不支持 | |
| ADC | 支持 | |
| WDT | 支持 | |

## 使用说明

Expand Down
3 changes: 3 additions & 0 deletions bsp/ht32/ht32f12366/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ rtconfig.BSP_LIBRARY_TYPE = ht32_library
# include libraries
objs.extend(SConscript(os.path.join(libraries_path_prefix, ht32_library, 'SConscript')))

# include usb libraries
objs.extend(SConscript(os.path.join(libraries_path_prefix, 'usbd_library', 'SConscript')))

# include drivers
objs.extend(SConscript(os.path.join(libraries_path_prefix, 'ht32_drivers', 'SConscript')))

Expand Down
123 changes: 121 additions & 2 deletions bsp/ht32/ht32f12366/applications/test.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2024, RT-Thread Development Team
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -58,10 +58,18 @@ static struct rt_semaphore rx_sem;
static rt_mutex_t task_mutex = RT_NULL; /* task mutex */

/* device handle */
#ifdef BSP_USING_UART
static rt_device_t serial;
#endif
#ifdef BSP_USING_WDT
static rt_device_t wdt_dev;
#endif
#ifdef BSP_USING_I2C
struct rt_i2c_bus_device *i2c_dev;
#endif
#ifdef BSP_USING_SPI
static struct rt_spi_device *spi_dev;
#endif

/* In-file function declarations */
static void sys_run_dir(void *parameter);
Expand Down Expand Up @@ -90,6 +98,7 @@ int task_registration(void)
INIT_BOARD_EXPORT(task_registration);

/* System operation indicator */
#ifdef BSP_USING_GPIO
static void sys_run_dir(void *parameter)
{
rt_uint32_t e;
Expand Down Expand Up @@ -301,7 +310,9 @@ static int gpio_input_task(int argc, char *argv[])
return -1;
}
MSH_CMD_EXPORT(gpio_input_task, gpio input task operation);
#endif
/* uart test */
#ifdef BSP_USING_UART
static rt_err_t uart_iqr_handle(rt_device_t dev, rt_size_t size)
{
/* Serial port callback function */
Expand Down Expand Up @@ -396,7 +407,9 @@ static int uart_task(int argc, char *argv[])
return ret;
}
MSH_CMD_EXPORT(uart_task, uart device sample);
#endif
/* hw/sw iic test */
#ifdef BSP_USING_I2C
static void i2c_thread(void *parameter)
{
uint8_t write_addr = 0x00;
Expand Down Expand Up @@ -497,7 +510,9 @@ static int i2c_task(int argc, char *argv[])
return ret;
}
MSH_CMD_EXPORT(i2c_task, i2c device sample);
#endif
/* spi test */
#ifdef BSP_USING_SPI
static void spi_thread(void *parameter)
{
rt_uint8_t w25x_read_id = 0x9F;
Expand Down Expand Up @@ -584,7 +599,9 @@ static int spi_task(int argc, char *argv[])
return ret;
}
MSH_CMD_EXPORT(spi_task, spi device sample);
#endif
/* adc test */
#ifdef BSP_USING_ADC
static void adc_test(void *parameter)
{
rt_uint32_t adc0_ch11_val,adc0_ch12_val;
Expand Down Expand Up @@ -640,8 +657,9 @@ static int adc_task(int argc, char *argv[])
return -1;
}
MSH_CMD_EXPORT(adc_task, adc task operation);

#endif
/* wdt test */
#ifdef BSP_USING_WDT
static void wdt_test(void)
{
rt_device_control(wdt_dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, RT_NULL);
Expand Down Expand Up @@ -712,5 +730,106 @@ static int wdt_task(int argc, char *argv[])
return -1;
}
MSH_CMD_EXPORT(wdt_task, wdt task operation);
#endif
/* usbd test */
#ifdef BSP_USING_USBD
static void usbd_test(void *parameter)
{
rt_device_t dev = RT_NULL;
char dev_name[] = "vcom";
char buf[] = "usbd vcom test!\r\n";

dev = rt_device_find(dev_name);

if (dev)
{
rt_device_open(dev, RT_DEVICE_FLAG_RDWR);
}
else
{
rt_kprintf("Device with name %s not found.\n",dev_name);
rt_thread_t tid = rt_thread_self();
rt_thread_delete(tid);
}
while (1)
{
rt_device_write(dev, 0, buf, rt_strlen(buf));
rt_thread_mdelay(500);
}
}

static int usbd_task(int argc, char *argv[])
{
rt_err_t ret = -RT_ERROR;

if(argc == 2)
{
if(rt_strcmp(argv[1],"start") == 0)
{
/* Gpio input test tasks */
rt_thread_t usbd_vcom_task = rt_thread_create("usbd_vcom_task",
usbd_test, RT_NULL,
THREAD_STACK_SIZE,
THREAD_PRIORITY, THREAD_TIMESLICE);
if (usbd_vcom_task != RT_NULL)
{
rt_thread_startup(usbd_vcom_task);
rt_kprintf("The usbd vcom task is registered.\n");
}
else
{
rt_kprintf("usbd vcom task registration failed.\n");
}
ret = RT_EOK;
}
else if(rt_strcmp(argv[1],"stop") == 0)
{
ret = RT_EOK;
}
}
else
{
rt_kprintf("Necessary parameters are missing.\n");
rt_kprintf("You can use the following commands.\n");
rt_kprintf("%s start\n",__func__);
rt_kprintf("%s stop\n",__func__);
}
return ret;
}
MSH_CMD_EXPORT(usbd_task, usbd task operation);
#endif
#ifdef BSP_USING_SDIO
int mnt_init(void)
{
rt_device_t dev = RT_NULL;
char dev_name[] = BSP_USING_SDIO_NAME;
rt_thread_mdelay(1000);

dev = rt_device_find(dev_name);
if(dev)
{
if(dfs_mount("sd0","/","elm",0,0) == RT_EOK)
{
rt_kprintf("dfs mount success!\r\n");
}
else
{
rt_kprintf("dfs mount failed!\r\n");
rt_kprintf("Formatting the SD card!\r\n");
dfs_mkfs("elm",dev_name);
if(dfs_mount("sd0","/","elm",0,0) == RT_EOK)
{
rt_kprintf("dfs mount success!\r\n");
}
else
{
rt_kprintf("dfs mount failed!\r\n");
rt_kprintf("Exit SD card mount!\r\n");
}
}
}
return 0;
}
INIT_FS_EXPORT(mnt_init);
#endif /* BSP_USING_SDIO */
#endif /* BSP_USING_TEST */
Loading
Loading