mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-09 20:45:41 +08:00
ch569w-evt: add usbhs device mode driver (#6330)
ch569w-evt: add usbhs device mode driver * usbd driver tested with cdc_vcom, internal loopback (can't run both MSH & usbd due to 16KB RAM limitation) * reduce usrstack & main thread stack size for usbd test * ch56x_uart.c : iron out UART0_PIN_ALT assignment
This commit is contained in:
1 parent
9cfb864068
commit
a38b39ac25
10 files changed
+1493
-184
No files matched your search
@@ -12,6 +12,9 @@ if GetDepend('SOC_SERIES_CH569'):
|
||||
if GetDepend('RT_USING_WDT'):
|
||||
src += ['ch56x_wdt.c']
|
||||
|
||||
if GetDepend('RT_USING_USB_DEVICE'):
|
||||
src += ['ch56x_usbd.c']
|
||||
|
||||
if GetDepend('RT_USING_PWM'):
|
||||
src += ['ch56x_pwm.c']
|
||||
|
||||
|
||||
@@ -45,8 +45,13 @@ static struct serial_device serial_device_0 =
|
||||
{
|
||||
.reg_base = (struct uart_registers *)UART0_REG_BASE,
|
||||
.irqn = UART0_IRQn,
|
||||
#ifndef BSP_USING_UART0_PIN_ALT
|
||||
.rxd_pin = UART_RXD0_PIN,
|
||||
.txd_pin = UART_TXD0_PIN,
|
||||
#else
|
||||
.rxd_pin = UART_RXD0_ALT,
|
||||
.txd_pin = UART_TXD0_ALT,
|
||||
#endif
|
||||
.name = "uart0",
|
||||
};
|
||||
#endif
|
||||
@@ -250,22 +255,13 @@ int rt_hw_uart_init(void)
|
||||
|
||||
while (--n >= 0)
|
||||
{
|
||||
uint32_t flag, txd_pin, rxd_pin;
|
||||
uint32_t flag;
|
||||
struct serial_device *serial = devices[n];
|
||||
serial->parent.ops = &uart_ops;
|
||||
serial->parent.config = config;
|
||||
|
||||
txd_pin = serial->txd_pin;
|
||||
rxd_pin = serial->rxd_pin;
|
||||
#ifdef BSP_USING_UART0_PIN_ALT
|
||||
if (serial->irqn == UART0_IRQn)
|
||||
{
|
||||
txd_pin = UART_TXD0_ALT;
|
||||
rxd_pin = UART_RXD0_ALT;
|
||||
}
|
||||
#endif
|
||||
rt_pin_mode(txd_pin, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(rxd_pin, PIN_MODE_INPUT_PULLUP);
|
||||
rt_pin_mode(serial->txd_pin, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(serial->rxd_pin, PIN_MODE_INPUT_PULLUP);
|
||||
|
||||
sys_clk_off_by_irqn(serial->irqn, SYS_SLP_CLK_ON);
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -21,6 +21,10 @@
|
||||
#define SOC_SERIES_CH569
|
||||
#endif
|
||||
|
||||
#ifndef __packed
|
||||
#define __packed __attribute__((packed))
|
||||
#endif
|
||||
|
||||
#define CHECK_STRUCT_SIZE(s, size) \
|
||||
static_assert(sizeof(s) == size, #s " has wrong size")
|
||||
|
||||
@@ -29,10 +33,10 @@
|
||||
|
||||
#define FLASH_BASE_ADDRESS 0x00000000
|
||||
#define RAMS_BASE_ADDRESS 0x20000000
|
||||
#define RAMX_BASE_ADDRESS 0x20020000
|
||||
#define BUS8_BASE_ADDRESS 0x80000000
|
||||
|
||||
#ifdef SOC_SERIES_CH569
|
||||
#define RAMX_BASE_ADDRESS 0x20020000
|
||||
#define RAMS_SIZE 16
|
||||
#else
|
||||
#define RAMS_SIZE 32
|
||||
|
||||
@@ -38,9 +38,9 @@ CONFIG_RT_KSERVICE_USING_STDLIB=y
|
||||
#
|
||||
CONFIG_RT_USING_SEMAPHORE=y
|
||||
CONFIG_RT_USING_MUTEX=y
|
||||
# CONFIG_RT_USING_EVENT is not set
|
||||
CONFIG_RT_USING_EVENT=y
|
||||
CONFIG_RT_USING_MAILBOX=y
|
||||
# CONFIG_RT_USING_MESSAGEQUEUE is not set
|
||||
CONFIG_RT_USING_MESSAGEQUEUE=y
|
||||
# CONFIG_RT_USING_SIGNALS is not set
|
||||
|
||||
#
|
||||
@@ -78,7 +78,7 @@ CONFIG_ARCH_RISCV=y
|
||||
#
|
||||
CONFIG_RT_USING_COMPONENTS_INIT=y
|
||||
CONFIG_RT_USING_USER_MAIN=y
|
||||
CONFIG_RT_MAIN_THREAD_STACK_SIZE=2048
|
||||
CONFIG_RT_MAIN_THREAD_STACK_SIZE=1024
|
||||
CONFIG_RT_MAIN_THREAD_PRIORITY=10
|
||||
# CONFIG_RT_USING_LEGACY is not set
|
||||
CONFIG_RT_USING_MSH=y
|
||||
|
||||
@@ -2,9 +2,11 @@ from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
|
||||
app = ARGUMENTS.get('app', "main")
|
||||
|
||||
src = Split("""
|
||||
main.c
|
||||
""")
|
||||
{}.c
|
||||
""".format(app))
|
||||
|
||||
path = [cwd, str(Dir('#'))]
|
||||
|
||||
|
||||
@@ -361,6 +361,52 @@ static void test_pwm(void)
|
||||
#define test_pwm() do {} while(0)
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_USB_DEVICE
|
||||
#if !defined(RT_USING_EVENT) || !defined(RT_USING_MESSAGEQUEUE)
|
||||
#error "event flag or message queue IPC not enabled"
|
||||
#endif
|
||||
static struct rt_thread *udvcom_thread;
|
||||
static rt_device_t vcom;
|
||||
|
||||
static void usbd_vcom_thread(void *param)
|
||||
{
|
||||
char ch;
|
||||
|
||||
while (1)
|
||||
{
|
||||
while (rt_device_read(vcom, 0, &ch, 1) != 1)
|
||||
rt_thread_delay(1);
|
||||
rt_kprintf("(%2d) %02x:%c\n", rt_device_write(vcom, 0, &ch, 1), ch, ch);
|
||||
rt_pin_write(LED1_PIN, (ch & 1) ? PIN_LOW : PIN_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_usbd()
|
||||
{
|
||||
char name[] = "vcom";
|
||||
|
||||
vcom = rt_device_find(name);
|
||||
if (vcom && rt_device_open(vcom, RT_DEVICE_FLAG_INT_RX) == RT_EOK)
|
||||
{
|
||||
rt_kprintf("%s opened\n", name);
|
||||
|
||||
rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
|
||||
rt_pin_write(LED1_PIN, PIN_LOW);
|
||||
|
||||
udvcom_thread = rt_thread_create("udvcom", usbd_vcom_thread, vcom,
|
||||
512, 20, 50);
|
||||
if (udvcom_thread != RT_NULL)
|
||||
rt_thread_startup(udvcom_thread);
|
||||
else
|
||||
rt_kprintf("usvcom thread create failed !\n");
|
||||
|
||||
rt_device_write(vcom, 0, name, rt_strlen(name));
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define test_usbd() do {} while(0)
|
||||
#endif
|
||||
|
||||
void main(void)
|
||||
{
|
||||
uint32_t wdog_timeout = 32;
|
||||
@@ -372,6 +418,7 @@ void main(void)
|
||||
test_hwtimer();
|
||||
test_spi_master();
|
||||
test_pwm();
|
||||
test_usbd();
|
||||
|
||||
rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
|
||||
rt_pin_write(LED0_PIN, led0 = PIN_LOW);
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -25,7 +25,9 @@
|
||||
|
||||
#define RT_USING_SEMAPHORE
|
||||
#define RT_USING_MUTEX
|
||||
#define RT_USING_EVENT
|
||||
#define RT_USING_MAILBOX
|
||||
#define RT_USING_MESSAGEQUEUE
|
||||
|
||||
/* Memory Management */
|
||||
|
||||
@@ -48,7 +50,7 @@
|
||||
|
||||
#define RT_USING_COMPONENTS_INIT
|
||||
#define RT_USING_USER_MAIN
|
||||
#define RT_MAIN_THREAD_STACK_SIZE 2048
|
||||
#define RT_MAIN_THREAD_STACK_SIZE 1024
|
||||
#define RT_MAIN_THREAD_PRIORITY 10
|
||||
#define RT_USING_MSH
|
||||
#define RT_USING_FINSH
|
||||
|
||||
Reference in new issue
Block a user