Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
全志_RISCV_D1_D1S
[SOLVED] Allwinner D1H USB host
发布于 2024-10-22 12:15:05 浏览:227
订阅该版
[tocm] Hi all, I’m really stuck with the make working USB host in Allwinner D1H BSP and RT-Thread. Now USB host can detect device connections, but communication has not started. Executed at hardware such as [ClockworkPi DevTerm R-01](https://www.clockworkpi.com/home-devterm) and [Sipeed Lichee RV + Dock](https://wiki.sipeed.com/hardware/en/lichee/RV/Dock.html). Inetention is make workable USB keyboard in DevTerm device. This is my GitHub repo: https://github.com/ylyamin/RT-Thread-on-Allwinner-D1H And explanation in more detail: https://github.com/ylyamin/RT-Thread-on-Allwinner-D1H/blob/master/documentation/D1_6_usb_keyboard.md #### 1) Firstly I used existing sunxi-hal: rt-thread/bsp/allwinner/libraries/sunxi-hal/hal/source/usb/host Created driver rt-thread/bsp/allwinner/libraries/drivers/drv_usbh.c: ```c int drv_usb(void) { hal_usb_core_init(); hal_usb_hcd_init(1); } INIT_DEVICE_EXPORT(drv_usb); ``` RTT console output: ```shell [I/DBG] --usb_gen_hub_init---1---- [I/DBG] --usb_gen_hub_init---2---- [I/DBG] [usb bus]: driver "hub drv" detect usb bus. [I/DBG] --usb_virt_bus_drv_reg---1-2-- [I/DBG] --usb_virt_bus_drv_reg---1-3-- [I/DBG] --usb_gen_hub_init---4---- [I/DBG] --usb_gen_hub_init---5---- [I/DBG] [sunxi-ehci11]: probe, sunxi_ehci: 0x0x00000000405816c0, 0x:0x0000000004200000, irq_no:49 plic_irq_toggle irq:49,enable:1 [I/DBG] --open_clock 0x810 = 0x0 [I/DBG] reg_value = 0x701 [I/DBG] ---usb_passby 0x800 = 0x701 [I/DBG] [usbh core]: add gen_dev SW USB2.0 'Enhanced' Host Controller (EHCI) Driver [ehci_qtd_alloc:57] qtd virt = 0x405999c0, phys = 0x405999c0 [I/DBG] ----2--usb_add_hc_gen_dev [I/DBG] ----3--usb_add_hc_gen_dev [I/DBG] --ehci_run: cmd = 0x10005 [I/DBG] --ehci_run: hc_capbase = 0x100 [I/DBG] USB 0.0 started, EHCI 1.00(NULL) [ehci_irq_handler:718] ehci_irq: highspeed device connect [I/DBG] ----4--usb_add_hc_gen_dev [I/DBG] hcd->remote_wakeup=0 [I/DBG] ----5--usb_add_hc_gen_dev [I/DBG] ---usb_get_device_descriptor---1-- [I/DBG] ---usb_get_device_descriptor---2-- [I/DBG] ---usb_get_device_descriptor---3-- [usbh core]: adding sub dev (config #1, interface 0)[I/DBG] --usb_virt_bus_dev_add---0 [I/DBG] --usb_virt_bus_dev_add---1 [I/DBG] ----func_drv->func_drv_name = hub drv [I/DBG] ---usb_core_func_drv_probe----1--- [I/DBG] usb match id suceessfull [I/DBG] ---usb_core_func_drv_probe----2--- [I/DBG] [hub]: usb hub probe [I/DBG] hub_probe--1-- [I/DBG] hub_probe--2-- [I/DBG] hub_probe--3-- [I/DBG] hub_probe--3-4-- [I/DBG] hub_probe--4-- [I/DBG] _hub_config--1-- [I/DBG] _hub_config--2-- [I/DBG] _hub_config--3-- [I/DBG] [hub]: 1 port detected [usbh hub]: stand alone hub[I/DBG] _hub_config--4-- [usbh hub]: individual port power switching[I/DBG] _hub_config--4-- [usbh hub]: global over-current protection[I/DBG] _hub_config--5-- [I/DBG] _hub_config--6-- [usbh hub]: TT requires at most 8 FS bit times[I/DBG] _hub_config--7-- [I/DBG] _hub_config--8-- [I/DBG] _hub_config--9-- [I/DBG] _hub_config--10-- [I/DBG] [usbh hub]: local power source is good [I/DBG] [usbh hub]: no over-current condition exists [I/DBG] _hub_config--11-- [I/DBG] _hub_config--12-- [I/DBG] _hub_config--13-- [I/DBG] _hub_config--14-- [I/DBG] _hub_config--15-- [I/DBG] _hub_config--16-- [I/DBG] ---usb_core_func_drv_probe----3--- [I/DBG] portstatus = 0x501, portchange = 0x1 [I/DBG] port debounce 0... [I/DBG] port debounce 0... [I/DBG] port debounce 25... [I/DBG] port debounce 50... [I/DBG] port debounce 75... [I/DBG] hub_port_init: udev address = 0 [ehci_irq_handler:718] ehci_irq: highspeed device disconnect [E/DBG] port_wait_reset: err = -107 [E/DBG] ERR: hub_port_reset failed! [E/DBG] ERR: hub_port_init failed, retry.... ERR: parameter is NULL, can't freeERR: parameter is NULL, can't freeERR: parameter is NULL, can't freeERR: parameter is NULL, can't free[I/DBG] hub_events--6-10-- [I/DBG] hub_events--7-- [I/DBG] hub_events--8-- [I/DBG] hub_events--9-- [I/DBG] portstatus = 0x100, portchange = 0x1 [I/DBG] port debounce 0... [I/DBG] port debounce 0... [I/DBG] port debounce 25... [I/DBG] port debounce 50... [I/DBG] port debounce 75... [I/DBG] hub_events--6-10-- [I/DBG] hub_events--7-- [I/DBG] hub_events--8-- [I/DBG] hub_events--9-- [I/DBG] ----6--usb_add_hc_gen_dev ``` Seems is detect USB device connection but communication and enumeration did not happen. #### 2) Then I try to use HAL from D1s Melis OS https://github.com/Tina-Linux/d1s-melis/tree/master/ekernel/drivers I moved this usb HAL folder to RTT: rt-thread/bsp/allwinner/libraries/sunxi-hal/hal/source/usb_melis Original RTT USB HAL folder moved to: rt-thread/bsp/allwinner/libraries/sunxi-hal/hal/source/usb_old Is can be compiled and run Melis USB HAL, but also nothing really happen: ```shell [I/DBG] [usb bus]: driver "hub drv" detect usb bus. [ehci-usb1] insmod host driver! [I/DBG] --open_clock 0x810 = 0x0 phy_vbase : 0x4200800, usbc_no : 1, efuse : 0x1e9200f [sunxi-ehci1]: sunxi_set_vbus cnt. [I/DBG] ehci insmod status = 2 [I/DBG] [usbh core]: add gen_dev SW USB2.0 'Enhanced' Host Controller (EHCI) Driver [I/DBG] USB 0.0 started, EHCI 1.00 ehci_irq_handler hcd: 405a26d8 ehci_irq_handler regs: 4200010 ehci_irq_handler status: 4200014 ehci_irq: highspeed device connect [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e7420) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e7420) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e7588) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e7588) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e7650) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e7650) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e7920) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e7920) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e7920) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e7920) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e7a48) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e7a48) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e7b70) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e7b70) [usb_control_msg:70] req:SET_CONFIGURATION(9), req_type:0x0 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e7a78) ctrl-0-out [urb_unlink:127] urb_dequeue(0x00000000405e7a78) [usbh core]: adding sub dev (config #1, interface 0)[I/DBG] usb match id suceessfull [ohci-usb1] insmod host driver! [I/DBG] --open_clock 0x810 = 0x3880 phy_vbase : 0x4200800, usbc_no : 1, efuse : 0x1e9200f [sunxi-ohci1]: sunxi_set_vbus cnt. [I/DBG] [usbh core]: add gen_dev SW USB2.0 'Open' Host Controller (OHCI) Driver [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e97f0) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e97f0) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e9a38) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e9a38) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e9b00) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e9b00) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e9e10) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e9e10) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e9e10) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e9e10) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e9f38) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405e9f38) [usb_control_msg:70] req:GET_DESCRIPTOR(6), req_type:0x80 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405ea060) ctrl-0-in [urb_unlink:127] urb_dequeue(0x00000000405ea060) [usb_control_msg:70] req:SET_CONFIGURATION(9), req_type:0x0 [usb_hcd_link_urb_to_ep:1310] urb_enqueue(0x00000000405e9f68) ctrl-0-out [urb_unlink:127] urb_dequeue(0x00000000405e9f68) [usbh core]: adding sub dev (config #1, interface 0)[I/DBG] usb match id suceessfull ``` Looks like exchange descriptors but I believe is an exchange with a virtual device not real. Seems is detect USB device connection but communication and enumeration did not happen. #### 3) Then I try just using only clock and phy initialization from HAL: ```c hci_clock_init(sunxi_ehci,ehci_table); open_clock(sunxi_ehci); usb_passby(sunxi_ehci, 1); hci_clock_init(sunxi_ohci, ohci_table); open_clock(sunxi_ohci); usb_passby(sunxi_ohci, 1); ``` And for EHCI/OHCI stack try to use [TinyUSB package](https://github.com/RT-Thread-packages/tinyusb): ```c int drv_usb_tiny(void) { init_tinyusb(); } INIT_DEVICE_EXPORT(drv_usb_tiny); ``` Re-route interrupts to TinyUSB: ```c irq_no = 49; request_irq(irq_no, ehci_handler, 0, "ehci", NULL); irq_no = 50; request_irq(irq_no, ohci_handler, 0, "ohci", NULL); ``` RTT Console output: ```shell msh />usb_tiny phy write: 4200810<-0 phy write: 4200800<-701 phy write: 4200810<-0 phy write: 4200800<-701 USBH init on controller 0 sizeof(usbh_device_t) = 312 sizeof(hcd_event_t) = 24 sizeof(_ctrl_xfer) = 40 sizeof(tuh_xfer_t) = 48 sizeof(tu_fifo_t) = 32 sizeof(tu_edpt_stream_t) = 144 osal: rt_mq_init result: 0 HID init HUB init tiny ehci_init EHCI HCIVERSION:0x0100 EHCI HCSPARAMS:0x001101 EHCI HCCPARAMS:0xa026 EHCI HCI_interface: 1793 EHCI HCI_Control_3: 0 EHCI PHY_Control (810): 0 EHCI PHY_Status (824): 0 EHCI HCI_SIE_Port: 3 plic_irq_toggle irq:49,enable:0 plic_irq_toggle irq:49,enable:1 ehci hcd_int_handler: 4 regs->portsc = 1803 Current Connect Status: 1 Connect Status Change : 1 Port Enabled : 0 Port Enabled Change : 0 Port Reset : 0 Port Power : 1 Port Owner : 0 Over current active : 0 Over current change : 0 Port suspend : 0 Port line_status : 2 Wake on connect enable: 0 hcd_event_device_attach osal: rt_mq_send result: 0 tuh_task_ext: tusb_inited osal: rt_mq_recv result: 24 tuh_task_ext: event.event_id 0 tuh_task_ext: USBH DEVICE ATTACH [0:] USBH DEVICE ATTACH ehci hcd_int_handler: 3 ``` In this case, TinyUSB EHCI stack can detect USB line connection but can't start communication. #### 4) Also looked to Linux https://github.com/smaeul/linux/tree/d1/all To implementation linux/drivers/phy/allwinner/phy-sun4i-usb.c Seems to me clocks and phy init are quite the same as in RTT sunxi-hal. So I don't know what i should fix in sunxi-hal to make it work. Maybe someone expert in Allwinner D1H USB stack can help with it, please ?
查看更多
1
个回答
默认排序
按发布时间排序
ylyamin
2024-11-16
这家伙很懒,什么也没写!
UPD: I managed to do USB working. Thanks, user Zoenggit for the tip. Found a hand-made ham radio transceiver project from one guru guy, it has a proper implementation of EHCI/OHCI stack for Allwinner D1/T113 [hftrx_tinyusb](https://github.com/ua1arn/hftrx_tinyusb). I just changed it a little to support RT-Thread. Now USB keyboard sends a key press to the system. This is my GitHub repo: https://github.com/ylyamin/RT-Thread-on-Allwinner-D1H ``` HID device address = 2, instance = 0 is mounted HID Interface Protocol = None HID has 4 reports msh /> H e l l o ! ```
撰写答案
登录
注册新账号
关注者
0
被浏览
227
关于作者
ylyamin
这家伙很懒,什么也没写!
提问
2
回答
2
被采纳
0
关注TA
发私信
相关问题
1
求助全志D1S&amp;RDC纪念版资料以及RTSMART移植教程
2
D1S scons编译
3
D1s M7工具链求寻
4
全志D1运行RT-Thread在烧录程序时异常
5
rtthread d1s编译报错
6
目前最新版的userapps如何安装D1s环境
7
[SOLVED] Not compiled for Allwinner D1H
8
导入bsp\allwinner\d1sb出错
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
如何在master上的BSP中添加配置yml文件
2
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
3
RT-Thread 发布 EtherKit开源以太网硬件!
4
rt-thread使用cherryusb实现虚拟串口
5
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
ulog
C++_cpp
at_device
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
14
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
13
个答案
1
次被采纳
本月文章贡献
程序员阿伟
9
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
5
次点赞
RTT_逍遥
1
篇文章
2
次点赞
ThinkCode
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部