17 Commits

Author SHA1 Message Date
sakumisu
e6fde5efab fix(port/dwc2): fix dwc2 rx fifo size, remove divided by 4 2024-09-08 22:11:38 +08:00
sakumisu
0487af6900 fix(port/dwc2): reset dma burst then modify, clear HCINT intstatus first 2024-09-08 22:11:38 +08:00
wangyz1997
be2880a7e8 fix(port/dwc2): fix typo 2024-09-08 22:11:38 +08:00
sakumisu
97e2a38b4a chore(cmake): do not use env variable 2024-09-08 22:11:38 +08:00
sakumisu
a139a70782 update(usbh_core): add terminate char for raw_config_desc 2024-09-07 22:43:43 +08:00
sakumisu
cb6a0c2ad6 chore(cherrymp): add license 2024-09-07 22:42:27 +08:00
sakumisu
bacacdb32c update: remove uvc queue 2024-09-06 22:24:16 +08:00
sakumisu
0323ffb424 update(class/cdc): set cdc acm bFunctionProtocol to 0x00 2024-09-04 22:06:14 +08:00
sakumisu
89e93f6c93 chore(scons): fix missing libpath 2024-09-02 18:57:15 +08:00
sakumisu
1deab668ef fix(port/ehci/usb_glue_ma35d0): fix typo 2024-09-02 18:54:53 +08:00
sakumisu
fbe2e3f8a3 fix(class/msc/usbd_msc): fix missing return value 2024-09-02 18:54:11 +08:00
sakumisu
d03dfe43ca update(port/dwc2/usb_hc_dwc2): power enable at last for common with other host ip 2024-09-01 11:59:11 +08:00
sakumisu
e42e99e975 update(platform/usbh_lwip): check lwip min stack size 2024-08-31 21:01:36 +08:00
sakumisu
8a7979378d update(osal): add error log and assert when alloc fail, and stop working 2024-08-31 18:23:00 +08:00
sakumisu
a8a5d95f8f fix(platform/rtthread/usbh_dfs): fix mem free 2024-08-31 16:08:10 +08:00
sakumisu
02ac1db3ff docs: update logo 2024-08-30 20:35:35 +08:00
tyustli
0d561ea313 Update usb_dc_dwc2.c
According to DS, the status register is W1C, |= will read the register first, write 1 to the corresponding bit, then write the register, if there is more than one status, it will be cleared by mistake. I'm not sure if other IP dcd's have the same problem?
2024-08-29 09:43:11 +08:00
29 changed files with 162 additions and 147 deletions

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.15)
if(DEFINED ENV{BL_SDK_BASE})
if(BL_SDK_BASE)
set(CONFIG_CHERRYUSB_DEVICE 1)
set(CONFIG_CHERRYUSB_DEVICE_CDC 1)
set(CONFIG_CHERRYUSB_DEVICE_HID 1)
@@ -35,7 +35,7 @@ sdk_library_add_sources(${cherryusb_srcs})
sdk_library_add_sources(platform/none/usbh_lwip.c)
elseif(DEFINED ENV{HPM_SDK_BASE})
elseif(HPM_SDK_BASE)
set(CONFIG_CHERRYUSB_HOST 1)
set(CONFIG_CHERRYUSB_HOST_CDC_ACM 1)
set(CONFIG_CHERRYUSB_HOST_CDC_ECM 1)

View File

@@ -51,7 +51,7 @@ if CHERRYUSB
config CHERRYUSB_DEVICE_CHIPIDEA_MCX
bool "chipidea_mcx"
config CHERRYUSB_DEVICE_CHIPIDEA_CUSTOM
bool "chipidea_mcx"
bool "chipidea_custom"
config CHERRYUSB_DEVICE_BL
bool "bouffalo"
config CHERRYUSB_DEVICE_HPM

View File

@@ -211,4 +211,4 @@ CherryUSB discord: https://discord.com/invite/wFfvrSAey8.
Thanks to the following companies for their support (in no particular order).
<img src="docs/assets/bouffalolab.jpg" width="100" height="100"/> <img src="docs/assets/hpmicro.jpg" width="100" height="100" /> <img src="docs/assets/eastsoft.jpg" width="100" height="100" /> <img src="docs/assets/rtthread.jpg" width="100" height="100" /> <img src="docs/assets/sophgo.jpg" width="100" height="100" /> <img src="docs/assets/phytium.jpg" width="100" height="100" /> <img src="docs/assets/thead.jpg" width="100" height="100" /> <img src="docs/assets/nuvoton.jpg" width="100" height="100" /> <img src="docs/assets/artinchip.jpg" width="100" height="100" /> <img src="docs/assets/bekencorp.jpg" width="100" height="100" />
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" />

View File

@@ -213,4 +213,4 @@ CherryUSB 微信群:与我联系后邀请加入
感谢以下企业支持(顺序不分先后)。
<img src="docs/assets/bouffalolab.jpg" width="100" height="100"/> <img src="docs/assets/hpmicro.jpg" width="100" height="100" /> <img src="docs/assets/eastsoft.jpg" width="100" height="100" /> <img src="docs/assets/rtthread.jpg" width="100" height="100" /> <img src="docs/assets/sophgo.jpg" width="100" height="100" /> <img src="docs/assets/phytium.jpg" width="100" height="100" /> <img src="docs/assets/thead.jpg" width="100" height="100" /> <img src="docs/assets/nuvoton.jpg" width="100" height="100" /> <img src="docs/assets/artinchip.jpg" width="100" height="100" /> <img src="docs/assets/bekencorp.jpg" width="100" height="100" />
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" />

View File

@@ -255,7 +255,7 @@ if GetDepend(['PKG_CHERRYUSB_HOST']):
src += Glob('platform/rtthread/usb_msh.c')
src += Glob('platform/rtthread/usb_check.c')
group = DefineGroup('CherryUSB', src, depend = ['PKG_USING_CHERRYUSB'], CPPPATH = path, CPPDEFINES = CPPDEFINES)
group = DefineGroup('CherryUSB', src, depend = ['PKG_USING_CHERRYUSB'], LIBS = LIBS, LIBPATH=LIBPATH, CPPPATH = path, CPPDEFINES = CPPDEFINES)
Return('group')

View File

@@ -287,6 +287,5 @@ endif()
if(CONFIG_CHERRYMP)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/chry_mempool.c)
list(APPEND cherryusb_srcs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp/usbh_uvc_queue.c)
list(APPEND cherryusb_incs ${CMAKE_CURRENT_LIST_DIR}/third_party/cherrymp)
endif()

View File

@@ -266,7 +266,7 @@
* (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
* 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
*/
// #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE) / 4)
// #define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
/* ---------------- MUSB Configuration ---------------- */
// #define CONFIG_USB_MUSB_SUNXI

View File

@@ -421,7 +421,7 @@ struct cdc_ncm_ndp16 {
0x02, /* bInterfaceCount */ \
USB_DEVICE_CLASS_CDC, /* bFunctionClass */ \
CDC_ABSTRACT_CONTROL_MODEL, /* bFunctionSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bFunctionProtocol */ \
CDC_COMMON_PROTOCOL_NONE, /* bFunctionProtocol */ \
0x00, /* iFunction */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
@@ -430,7 +430,7 @@ struct cdc_ncm_ndp16 {
0x01, /* bNumEndpoints */ \
USB_DEVICE_CLASS_CDC, /* bInterfaceClass */ \
CDC_ABSTRACT_CONTROL_MODEL, /* bInterfaceSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS, /* bInterfaceProtocol */ \
CDC_COMMON_PROTOCOL_NONE, /* bInterfaceProtocol */ \
str_idx, /* iInterface */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \
@@ -489,8 +489,8 @@ struct cdc_ncm_ndp16 {
bFirstInterface, /* bFirstInterface */ \
0x02, /* bInterfaceCount */ \
USB_DEVICE_CLASS_WIRELESS, /* bFunctionClass */ \
CDC_DIRECT_LINE_CONTROL_MODEL, /* bFunctionSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS_PCCA_101_AND_ANNEXO, /* bFunctionProtocol */ \
0x01, /* bFunctionSubClass */ \
0x03, /* bFunctionProtocol */ \
0x00, /* iFunction */ \
0x09, /* bLength */ \
USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
@@ -498,8 +498,8 @@ struct cdc_ncm_ndp16 {
0x00, /* bAlternateSetting */ \
0x01, /* bNumEndpoints */ \
USB_DEVICE_CLASS_WIRELESS, /* bInterfaceClass */ \
CDC_DIRECT_LINE_CONTROL_MODEL, /* bInterfaceSubClass */ \
CDC_COMMON_PROTOCOL_AT_COMMANDS_PCCA_101_AND_ANNEXO, /* bInterfaceProtocol */ \
0x01, /* bInterfaceSubClass */ \
0x03, /* bInterfaceProtocol */ \
str_idx, /* iInterface */ \
0x05, /* bLength */ \
CDC_CS_INTERFACE, /* bDescriptorType */ \

View File

@@ -266,10 +266,10 @@ const struct usbh_class_driver cdc_data_class_driver = {
};
CLASS_INFO_DEFINE const struct usbh_class_info cdc_acm_class_info = {
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS | USB_CLASS_MATCH_INTF_PROTOCOL,
.match_flags = USB_CLASS_MATCH_INTF_CLASS | USB_CLASS_MATCH_INTF_SUBCLASS,
.class = USB_DEVICE_CLASS_CDC,
.subclass = CDC_ABSTRACT_CONTROL_MODEL,
.protocol = CDC_COMMON_PROTOCOL_AT_COMMANDS,
.protocol = 0x00,
.id_table = NULL,
.class_driver = &cdc_acm_class_driver
};

View File

@@ -537,6 +537,7 @@ static bool SCSI_read10(uint8_t busid, uint8_t **data, uint32_t *len)
g_usbd_msc[busid].stage = MSC_DATA_IN;
#if defined(CONFIG_USBDEV_MSC_THREAD)
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
return true;
#elif defined(CONFIG_USBDEV_MSC_POLLING)
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
return true;
@@ -574,6 +575,7 @@ static bool SCSI_read12(uint8_t busid, uint8_t **data, uint32_t *len)
g_usbd_msc[busid].stage = MSC_DATA_IN;
#if defined(CONFIG_USBDEV_MSC_THREAD)
usb_osal_mq_send(g_usbd_msc[busid].usbd_msc_mq, MSC_DATA_IN);
return true;
#elif defined(CONFIG_USBDEV_MSC_POLLING)
chry_ringbuffer_write_byte(&g_usbd_msc[busid].msc_rb, MSC_DATA_IN);
return true;

View File

@@ -495,6 +495,8 @@ int usbh_enumerate(struct usbh_hubport *hport)
config_value = ((struct usb_configuration_descriptor *)ep0_request_buffer[hport->bus->busid])->bConfigurationValue;
memcpy(hport->raw_config_desc, ep0_request_buffer[hport->bus->busid], wTotalLength);
hport->raw_config_desc[wTotalLength] = '\0';
#ifdef CONFIG_USBHOST_GET_STRING_DESC
uint8_t string_buffer[128];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 178 KiB

BIN
docs/assets/espressif.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
docs/assets/nxp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -249,7 +249,7 @@
* (largest USB packet used / 4) + 1 for status information + 1 transfer complete +
* 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
*/
#define CONFIG_USB_DWC2_RX_FIFO_SIZE ((200 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE) / 4)
#define CONFIG_USB_DWC2_RX_FIFO_SIZE ((200 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
#elif CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32P4
// todo: check c5, p4 in later

View File

@@ -5,6 +5,8 @@
*/
#include "usb_osal.h"
#include "usb_errno.h"
#include "usb_config.h"
#include "usb_log.h"
#include <FreeRTOS.h>
#include "semphr.h"
#include "timers.h"
@@ -15,6 +17,11 @@ usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size,
TaskHandle_t htask = NULL;
stack_size /= sizeof(StackType_t);
xTaskCreate(entry, name, stack_size, args, configMAX_PRIORITIES - 1 - prio, &htask);
if (htask == NULL) {
USB_LOG_ERR("Create thread %s failed\r\n", name);
while (1) {
}
}
return (usb_osal_thread_t)htask;
}
@@ -25,7 +32,13 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
return (usb_osal_sem_t)xSemaphoreCreateCounting(1, initial_count);
usb_osal_sem_t sem = (usb_osal_sem_t)xSemaphoreCreateCounting(1, initial_count);
if (sem == NULL) {
USB_LOG_ERR("Create semaphore failed\r\n");
while (1) {
}
}
return sem;
}
void usb_osal_sem_delete(usb_osal_sem_t sem)
@@ -66,7 +79,13 @@ void usb_osal_sem_reset(usb_osal_sem_t sem)
usb_osal_mutex_t usb_osal_mutex_create(void)
{
return (usb_osal_mutex_t)xSemaphoreCreateMutex();
usb_osal_mutex_t mutex = (usb_osal_mutex_t)xSemaphoreCreateMutex();
if (mutex == NULL) {
USB_LOG_ERR("Create mutex failed\r\n");
while (1) {
}
}
return mutex;
}
void usb_osal_mutex_delete(usb_osal_mutex_t mutex)
@@ -131,7 +150,9 @@ struct usb_osal_timer *usb_osal_timer_create(const char *name, uint32_t timeout_
timer = pvPortMalloc(sizeof(struct usb_osal_timer));
if (timer == NULL) {
return NULL;
USB_LOG_ERR("Create usb_osal_timer failed\r\n");
while (1) {
}
}
memset(timer, 0, sizeof(struct usb_osal_timer));
@@ -140,7 +161,9 @@ struct usb_osal_timer *usb_osal_timer_create(const char *name, uint32_t timeout_
timer->timer = (void *)xTimerCreate("usb_tim", pdMS_TO_TICKS(timeout_ms), is_period, timer, (TimerCallbackFunction_t)__usb_timeout);
if (timer->timer == NULL) {
return NULL;
USB_LOG_ERR("Create timer failed\r\n");
while (1) {
}
}
return timer;
}

View File

@@ -5,6 +5,8 @@
*/
#include "usb_osal.h"
#include "usb_errno.h"
#include "usb_config.h"
#include "usb_log.h"
#include <rtthread.h>
#include <rthw.h>
@@ -12,6 +14,11 @@ usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size,
{
rt_thread_t htask;
htask = rt_thread_create(name, entry, args, stack_size, prio, 10);
if (htask == NULL) {
USB_LOG_ERR("Create thread %s failed\r\n", name);
while (1) {
}
}
rt_thread_startup(htask);
return (usb_osal_thread_t)htask;
}
@@ -27,7 +34,13 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
return (usb_osal_sem_t)rt_sem_create("usbh_sem", initial_count, RT_IPC_FLAG_FIFO);
usb_osal_sem_t sem = (usb_osal_sem_t)rt_sem_create("usbh_sem", initial_count, RT_IPC_FLAG_FIFO);
if (sem == NULL) {
USB_LOG_ERR("Create semaphore failed\r\n");
while (1) {
}
}
return sem;
}
void usb_osal_sem_delete(usb_osal_sem_t sem)
@@ -68,7 +81,13 @@ void usb_osal_sem_reset(usb_osal_sem_t sem)
usb_osal_mutex_t usb_osal_mutex_create(void)
{
return (usb_osal_mutex_t)rt_mutex_create("usbh_mutex", RT_IPC_FLAG_FIFO);
usb_osal_mutex_t mutex = (usb_osal_mutex_t)rt_mutex_create("usbh_mutex", RT_IPC_FLAG_FIFO);
if (mutex == NULL) {
USB_LOG_ERR("Create mutex failed\r\n");
while (1) {
}
}
return mutex;
}
void usb_osal_mutex_delete(usb_osal_mutex_t mutex)
@@ -127,11 +146,18 @@ struct usb_osal_timer *usb_osal_timer_create(const char *name, uint32_t timeout_
struct usb_osal_timer *timer;
timer = rt_malloc(sizeof(struct usb_osal_timer));
if (timer == NULL) {
USB_LOG_ERR("Create usb_osal_timer failed\r\n");
while (1) {
}
}
memset(timer, 0, sizeof(struct usb_osal_timer));
timer->timer = (void *)rt_timer_create(name, handler, argument, timeout_ms, is_period ? (RT_TIMER_FLAG_PERIODIC | RT_TIMER_FLAG_SOFT_TIMER) : (RT_TIMER_FLAG_ONE_SHOT | RT_TIMER_FLAG_SOFT_TIMER));
if (timer->timer == NULL) {
return NULL;
USB_LOG_ERR("Create timer failed\r\n");
while (1) {
}
}
return timer;
}

View File

@@ -5,6 +5,8 @@
*/
#include "usb_osal.h"
#include "usb_errno.h"
#include "usb_config.h"
#include "usb_log.h"
#include "tx_api.h"
/* create bytepool in tx_application_define
@@ -22,12 +24,16 @@ usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size,
tx_byte_allocate(&usb_byte_pool, (VOID **)&thread_ptr, sizeof(TX_THREAD), TX_NO_WAIT);
if (thread_ptr == TX_NULL) {
return NULL;
USB_LOG_ERR("Create thread %s failed\r\n", name);
while (1) {
}
}
tx_byte_allocate(&usb_byte_pool, (VOID **)&pointer, stack_size, TX_NO_WAIT);
if (pointer == TX_NULL) {
return NULL;
USB_LOG_ERR("Create thread %s failed\r\n", name);
while (1) {
}
}
tx_thread_create(thread_ptr, (CHAR *)name, (VOID(*)(ULONG))entry, (uintptr_t)args,
@@ -70,7 +76,9 @@ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
tx_byte_allocate(&usb_byte_pool, (VOID **)&sem_ptr, sizeof(TX_SEMAPHORE), TX_NO_WAIT);
if (sem_ptr == TX_NULL) {
return NULL;
USB_LOG_ERR("Create semaphore failed\r\n");
while (1) {
}
}
tx_semaphore_create(sem_ptr, "usbh_sem", initial_count);
@@ -115,7 +123,9 @@ usb_osal_mutex_t usb_osal_mutex_create(void)
tx_byte_allocate(&usb_byte_pool, (VOID **)&mutex_ptr, sizeof(TX_MUTEX), TX_NO_WAIT);
if (mutex_ptr == TX_NULL) {
return NULL;
USB_LOG_ERR("Create mutex failed\r\n");
while (1) {
}
}
tx_mutex_create(mutex_ptr, "usbh_mutx", TX_INHERIT);
@@ -157,13 +167,17 @@ usb_osal_mq_t usb_osal_mq_create(uint32_t max_msgs)
tx_byte_allocate(&usb_byte_pool, (VOID **)&queue_ptr, sizeof(TX_QUEUE), TX_NO_WAIT);
if (queue_ptr == TX_NULL) {
return NULL;
USB_LOG_ERR("Create TX_QUEUE failed\r\n");
while (1) {
}
}
tx_byte_allocate(&usb_byte_pool, (VOID **)&pointer, sizeof(uintptr_t) * max_msgs, TX_NO_WAIT);
if (pointer == TX_NULL) {
return NULL;
USB_LOG_ERR("Create mq failed\r\n");
while (1) {
}
}
tx_queue_create(queue_ptr, "usbh_mq", sizeof(uintptr_t) / 4, pointer, sizeof(uintptr_t) * max_msgs);
@@ -206,14 +220,18 @@ struct usb_osal_timer *usb_osal_timer_create(const char *name, uint32_t timeout_
tx_byte_allocate(&usb_byte_pool, (VOID **)&timer, sizeof(struct usb_osal_timer), TX_NO_WAIT);
if (timer == TX_NULL) {
return NULL;
USB_LOG_ERR("Create usb_osal_timer failed\r\n");
while (1) {
}
}
memset(timer, 0, sizeof(struct usb_osal_timer));
tx_byte_allocate(&usb_byte_pool, (VOID **)&timer_ptr, sizeof(TX_TIMER), TX_NO_WAIT);
if (timer_ptr == TX_NULL) {
return NULL;
USB_LOG_ERR("Create TX_TIMER failed\r\n");
while (1) {
}
}
timer->timer = timer_ptr;

View File

@@ -31,6 +31,10 @@
#error PBUF_POOL_BUFSIZE must be larger than 1600
#endif
#if TCPIP_THREAD_STACKSIZE < 1024
#error "TCPIP_THREAD_STACKSIZE must be >= 1024"
#endif
// #define CONFIG_USBHOST_PLATFORM_CDC_ECM
// #define CONFIG_USBHOST_PLATFORM_CDC_RNDIS
// #define CONFIG_USBHOST_PLATFORM_CDC_NCM

View File

@@ -7,11 +7,11 @@
#endif
#if IDLE_THREAD_STACK_SIZE < 2048
#error "IDLE_THREAD_STACK_SIZE must be greater than or equal to 2048"
#error "IDLE_THREAD_STACK_SIZE must be >= 2048"
#endif
#if RT_TIMER_THREAD_STACK_SIZE < 2048
#error "RT_TIMER_THREAD_STACK_SIZE must be greater than or equal to 2048"
#error "RT_TIMER_THREAD_STACK_SIZE must be >= 2048"
#endif
#endif

View File

@@ -9,7 +9,7 @@
#include "rtthread.h"
#include <dfs_fs.h>
#define DEV_FORMAT "/sd%c"
#define DEV_FORMAT "/dev/sd%c"
#ifndef CONFIG_USB_DFS_MOUNT_POINT
#define CONFIG_USB_DFS_MOUNT_POINT "/"
@@ -46,7 +46,7 @@ static rt_err_t rt_udisk_init(rt_device_t dev)
}
static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer,
rt_size_t size)
rt_size_t size)
{
struct usbh_msc *msc_class = (struct usbh_msc *)dev->user_data;
int ret;
@@ -85,7 +85,7 @@ static ssize_t rt_udisk_read(rt_device_t dev, rt_off_t pos, void *buffer,
}
static ssize_t rt_udisk_write(rt_device_t dev, rt_off_t pos, const void *buffer,
rt_size_t size)
rt_size_t size)
{
struct usbh_msc *msc_class = (struct usbh_msc *)dev->user_data;
int ret;
@@ -175,15 +175,17 @@ int udisk_init(struct usbh_msc *msc_class)
ret = usbh_msc_scsi_read10(msc_class, 0, msc_sector, 1);
if (ret != RT_EOK) {
rt_kprintf("usb mass_storage read failed\n");
rt_free(dev);
return ret;
}
for (i = 0; i < 16; i++) {
for (i = 0; i < 4; i++) {
/* Get the first partition */
ret = dfs_filesystem_get_partition(&part0, msc_sector, i);
if (ret == RT_EOK) {
rt_kprintf("Found partition %d: type = %d, offet=0x%x, size=0x%x\n",
i, part0.type, part0.offset, part0.size);
break;
} else {
break;
}
@@ -219,6 +221,8 @@ void usbh_msc_run(struct usbh_msc *msc_class)
void usbh_msc_stop(struct usbh_msc *msc_class)
{
struct rt_device *dev;
char name[CONFIG_USBHOST_DEV_NAMELEN];
char mount_point[CONFIG_USBHOST_DEV_NAMELEN];
@@ -226,5 +230,9 @@ void usbh_msc_stop(struct usbh_msc *msc_class)
snprintf(mount_point, CONFIG_USBHOST_DEV_NAMELEN, CONFIG_USB_DFS_MOUNT_POINT, msc_class->sdchar);
dfs_unmount(mount_point);
rt_device_unregister(rt_device_find(name));
dev = rt_device_find(name);
if (dev) {
rt_device_unregister(dev);
rt_free(dev);
}
}

View File

@@ -44,6 +44,10 @@
#error PBUF_POOL_BUFSIZE must be larger than 1600
#endif
#if RT_LWIP_TCPTHREAD_STACKSIZE < 2048
#error "RT_LWIP_TCPTHREAD_STACKSIZE must be >= 2048"
#endif
// #define CONFIG_USBHOST_PLATFORM_CDC_ECM
// #define CONFIG_USBHOST_PLATFORM_CDC_RNDIS
// #define CONFIG_USBHOST_PLATFORM_CDC_NCM

View File

@@ -119,7 +119,7 @@ USB_NOCACHE_RAM_SECTION struct dwc2_udc {
__attribute__((aligned(32))) struct usb_setup_packet setup;
struct dwc2_ep_state in_ep[CONFIG_USBDEV_EP_NUM]; /*!< IN endpoint parameters*/
struct dwc2_ep_state out_ep[CONFIG_USBDEV_EP_NUM]; /*!< OUT endpoint parameters */
} g_dwc2_udc[CONFIG_USBHOST_MAX_BUS];
} g_dwc2_udc[CONFIG_USBDEV_MAX_BUS];
static inline int dwc2_reset(uint8_t busid)
{
@@ -588,6 +588,7 @@ int usb_dc_init(uint8_t busid)
}
USB_OTG_DEV->DCFG &= ~USB_OTG_DCFG_DESCDMA;
USB_OTG_GLB->GAHBCFG &= ~USB_OTG_GAHBCFG_HBSTLEN;
USB_OTG_GLB->GAHBCFG |= (USB_OTG_GAHBCFG_DMAEN | USB_OTG_GAHBCFG_HBSTLEN_4);
#else
USB_OTG_GLB->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM;
@@ -1111,7 +1112,7 @@ void USBD_IRQHandler(uint8_t busid)
}
}
if (gint_status & USB_OTG_GINTSTS_USBRST) {
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_USBRST;
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_USBRST;
USB_OTG_DEV->DCTL &= ~USB_OTG_DCTL_RWUSIG;
dwc2_flush_txfifo(busid, 0x10U);
@@ -1202,14 +1203,14 @@ void USBD_IRQHandler(uint8_t busid)
}
if (gint_status & USB_OTG_GINTSTS_SOF) {
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_SOF;
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_SOF;
}
if (gint_status & USB_OTG_GINTSTS_USBSUSP) {
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_USBSUSP;
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_USBSUSP;
usbd_event_suspend_handler(busid);
}
if (gint_status & USB_OTG_GINTSTS_WKUINT) {
USB_OTG_GLB->GINTSTS |= USB_OTG_GINTSTS_WKUINT;
USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_WKUINT;
usbd_event_resume_handler(busid);
}
if (gint_status & USB_OTG_GINTSTS_OTGINT) {

View File

@@ -26,7 +26,7 @@
* 1 location each for Bulk/Control endpoint for handling NAK/NYET scenario
*/
#ifndef CONFIG_USB_DWC2_RX_FIFO_SIZE
#define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE) / 4)
#define CONFIG_USB_DWC2_RX_FIFO_SIZE ((1012 - CONFIG_USB_DWC2_NPTX_FIFO_SIZE - CONFIG_USB_DWC2_PTX_FIFO_SIZE))
#endif
#define USB_OTG_GLB ((DWC2_GlobalTypeDef *)(bus->hcd.reg_base))
@@ -498,9 +498,6 @@ int usb_hc_init(struct usbh_bus *bus)
/* Restart the Phy Clock */
USB_OTG_PCGCCTL = 0U;
dwc2_drivebus(bus, 1);
usb_osal_msleep(200);
/* Set default Max speed support */
USB_OTG_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSS);
@@ -524,6 +521,7 @@ int usb_hc_init(struct usbh_bus *bus)
ret = dwc2_flush_txfifo(bus, 0x10U);
ret = dwc2_flush_rxfifo(bus);
USB_OTG_GLB->GAHBCFG &= ~USB_OTG_GAHBCFG_HBSTLEN;
USB_OTG_GLB->GAHBCFG |= USB_OTG_GAHBCFG_HBSTLEN_4;
USB_OTG_GLB->GAHBCFG |= USB_OTG_GAHBCFG_DMAEN;
@@ -531,6 +529,9 @@ int usb_hc_init(struct usbh_bus *bus)
USB_OTG_GLB->GINTMSK |= (USB_OTG_GINTMSK_PRTIM | USB_OTG_GINTMSK_HCIM |
USB_OTG_GINTSTS_DISCINT);
dwc2_drivebus(bus, 1);
usb_osal_msleep(200);
USB_OTG_GLB->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
return ret;
@@ -895,6 +896,7 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
//printf("s1:%08x\r\n", chan_intstatus);
if (chan_intstatus & USB_OTG_HCINT_CHH) {
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
if (chan_intstatus & USB_OTG_HCINT_XFRC) {
urb->errorcode = 0;
@@ -948,7 +950,6 @@ static void dwc2_inchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
urb->errorcode = -USB_ERR_IO;
dwc2_urb_waitup(urb);
}
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
}
}
@@ -965,6 +966,7 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
//printf("s2:%08x\r\n", chan_intstatus);
if (chan_intstatus & USB_OTG_HCINT_CHH) {
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
if (chan_intstatus & USB_OTG_HCINT_XFRC) {
urb->errorcode = 0;
@@ -1029,7 +1031,6 @@ static void dwc2_outchan_irq_handler(struct usbh_bus *bus, uint8_t ch_num)
urb->errorcode = -USB_ERR_IO;
dwc2_urb_waitup(urb);
}
USB_OTG_HC(ch_num)->HCINT = chan_intstatus;
}
}

View File

@@ -57,7 +57,7 @@ void usb_hc_low_level_init(struct usbh_bus *bus)
SYS->MISCFCR0 &= ~SYS_MISCFCR0_UHOVRCURH_Msk;
while (1) {
rt_thread_mdelay(1);
if ((SYS->USBPMISCR & SYS_USBPMISCR_PHY0HSTCKSTB_Msk) &&)
if (SYS->USBPMISCR & SYS_USBPMISCR_PHY0HSTCKSTB_Msk)
break; /* both USB PHY0 and PHY1 clock 60MHz UTMI clock stable */
timeout--;
@@ -88,7 +88,7 @@ void usb_hc_low_level_init(struct usbh_bus *bus)
SYS->MISCFCR0 &= ~SYS_MISCFCR0_UHOVRCURH_Msk;
while (1) {
rt_thread_mdelay(1);
if ((SYS->USBPMISCR & SYS_USBPMISCR_PHY1HSTCKSTB_Msk))
if (SYS->USBPMISCR & SYS_USBPMISCR_PHY1HSTCKSTB_Msk)
break; /* both USB PHY0 and PHY1 clock 60MHz UTMI clock stable */
timeout--;

View File

@@ -1,3 +1,8 @@
/*
* Copyright (c) 2024, sakumisu
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "chry_mempool.h"
int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_size, uint32_t block_count)
@@ -8,7 +13,10 @@ int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_s
ringbuf = usb_osal_malloc(sizeof(uintptr_t) * block_count);
memset(ringbuf, 0, sizeof(uintptr_t) * block_count);
chry_ringbuffer_init(&pool->rb, ringbuf, sizeof(uintptr_t) * block_count);
if (chry_ringbuffer_init(&pool->rb, ringbuf, sizeof(uintptr_t) * block_count) == -1) {
usb_osal_free(ringbuf);
return -1;
}
for (uint32_t i = 0; i < block_count; i++) {
addr = ((uintptr_t)block + i * block_size);

View File

@@ -1,7 +1,11 @@
/*
* Copyright (c) 2024, sakumisu
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef CHRY_MEMPOOL_H
#define CHRY_MEMPOOL_H
#include "usb_config.h"
#include "usb_osal.h"
#include "chry_ringbuffer.h"
@@ -10,10 +14,18 @@ struct chry_mempool {
usb_osal_mq_t mq;
};
#ifdef __cplusplus
extern "C" {
#endif
int chry_mempool_create(struct chry_mempool *pool, void *block, uint32_t block_size, uint32_t block_count);
uintptr_t *chry_mempool_alloc(struct chry_mempool *pool);
int chry_mempool_free(struct chry_mempool *pool, uintptr_t *item);
int chry_mempool_send(struct chry_mempool *pool, uintptr_t *item);
int chry_mempool_recv(struct chry_mempool *pool, uintptr_t **item, uint32_t timeout);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,75 +0,0 @@
#include "usbh_uvc_queue.h"
#include "chry_mempool.h"
struct chry_mempool usbh_uvc_pool;
int usbh_uvc_frame_create(struct usbh_videoframe *frame, uint32_t count)
{
return chry_mempool_create(&usbh_uvc_pool, frame, sizeof(struct usbh_videoframe), count);
}
struct usbh_videoframe *usbh_uvc_frame_alloc(void)
{
return (struct usbh_videoframe *)chry_mempool_alloc(&usbh_uvc_pool);
}
int usbh_uvc_frame_free(struct usbh_videoframe *frame)
{
return chry_mempool_free(&usbh_uvc_pool, (uintptr_t *)frame);
}
int usbh_uvc_frame_send(struct usbh_videoframe *frame)
{
return chry_mempool_send(&usbh_uvc_pool, (uintptr_t *)frame);
}
int usbh_uvc_frame_recv(struct usbh_videoframe **frame, uint32_t timeout)
{
return chry_mempool_recv(&usbh_uvc_pool, (uintptr_t **)frame, timeout);
}
uint8_t frame_buffer1[1]; /* just for test */
uint8_t frame_buffer2[1]; /* just for test */
struct usbh_videoframe frame_pool[2];
void usbh_uvc_frame_init(void)
{
frame_pool[0].frame_buf = frame_buffer1;
frame_pool[0].frame_bufsize = 640 * 480 * 2;
frame_pool[1].frame_buf = frame_buffer2;
frame_pool[1].frame_bufsize = 640 * 480 * 2;
usbh_uvc_frame_create(frame_pool, 2);
}
static void usbh_frame_thread(void *argument)
{
int ret;
struct usbh_videoframe *frame;
while (1) {
ret = usbh_uvc_frame_recv(&frame, 0xfffffff);
if (ret < 0) {
continue;
}
USB_LOG_RAW("frame buf:%p,frame len:%d\r\n", frame->frame_buf, frame->frame_size);
usbh_uvc_frame_free(frame);
}
}
void usbh_uvc_frame_alloc_send_test(void)
{
struct usbh_videoframe *frame = NULL;
frame = usbh_uvc_frame_alloc();
if (frame) {
frame->frame_size = 640 * 480 * 2;
usbh_uvc_frame_send(frame);
}
}
void usbh_uvc_frame_test(void)
{
usbh_uvc_frame_init();
usb_osal_thread_create("usbh_video", 3072, 5, usbh_frame_thread, NULL);
}

View File

@@ -1,18 +0,0 @@
#ifndef USBH_UVC_QUEUE_H
#define USBH_UVC_QUEUE_H
#include "chry_mempool.h"
#include "usbh_core.h"
#include "usbh_video.h"
int usbh_uvc_frame_create(struct usbh_videoframe *frame, uint32_t count);
struct usbh_videoframe *usbh_uvc_frame_alloc(void);
int usbh_uvc_frame_free(struct usbh_videoframe *frame);
int usbh_uvc_frame_send(struct usbh_videoframe *frame);
int usbh_uvc_frame_recv(struct usbh_videoframe **frame, uint32_t timeout);
/* test uvc frame */
void usbh_uvc_frame_alloc_send_test(void);
void usbh_uvc_frame_test(void);
#endif