Skip to content

Commit

Permalink
Update CherryUSB
Browse files Browse the repository at this point in the history
  • Loading branch information
udoudou committed Jan 4, 2024
1 parent 1d1b146 commit 116a237
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "CherryUSB"]
path = CherryUSB
url = https://github.com/cherry-embedded/CherryUSB.git
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
idf_component_get_property(cusb_path leeebo__cherryusb COMPONENT_DIR)
set(cusb_path "CherryUSB")

set(srcs "additions/esp_cherryusb.c")
set(inc_dirs "additions" "${cusb_path}/common" "${cusb_path}/core")
Expand Down
1 change: 1 addition & 0 deletions CherryUSB
Submodule CherryUSB added at d867ca
25 changes: 17 additions & 8 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,11 @@ menu "ESP CherryUSB"
config USBHOST_MAX_INTERFACES
int "Maximum number of interfaces"
depends on CHERRYUSBH_ENABLED
default 6
range 6 6
default 8
config USBHOST_MAX_INTF_ALTSETTINGS
int "Maximum number of interface alternate settings"
depends on CHERRYUSBH_ENABLED
default 1
default 8
config USBHOST_MAX_ENDPOINTS
int "Maximum number of endpoints"
depends on CHERRYUSBH_ENABLED
Expand All @@ -249,18 +248,15 @@ menu "ESP CherryUSB"
int "Maximum number of Video class devices"
depends on CHERRYUSBH_ENABLED
default 1
config USBHOST_MAX_RNDIS_CLASS
int "Maximum number of RNDIS class devices"
depends on CHERRYUSBH_ENABLED
default 1
config USBHOST_DEV_NAMELEN
int "Maximum length of device name"
depends on CHERRYUSBH_ENABLED
default 16
config USBHOST_PSC_PRIO
int "Priority of the Host PSC task"
depends on CHERRYUSBH_ENABLED
default 4
range 0 23
default 0
config USBHOST_PSC_STACKSIZE
int "Stack size of the Host PSC task"
depends on CHERRYUSBH_ENABLED
Expand All @@ -269,6 +265,15 @@ menu "ESP CherryUSB"
bool "Get string descriptor"
depends on CHERRYUSBH_ENABLED
default n
config USBHOST_MSOS_ENABLE
bool "todo"
depends on CHERRYUSBH_ENABLED
default n
config USBHOST_MSOS_VENDOR_CODE
hex "todo"
depends on USBHOST_MSOS_ENABLE
range 0x00 0xff
default 0x00
config USBHOST_REQUEST_BUFFER_LEN
int "Largest size (in bytes) of transfers from/to ep0"
depends on CHERRYUSBH_ENABLED
Expand All @@ -277,6 +282,10 @@ menu "ESP CherryUSB"
int "Timeout for control transfers (in ms)"
depends on CHERRYUSBH_ENABLED
default 500
config USBHOST_MSC_TIMEOUT
int "Timeout for MSC (in ms)"
depends on CHERRYUSBH_ENABLED
default 5000
endmenu

endmenu #ESP CherryUSB
9 changes: 7 additions & 2 deletions additions/esp_cherryusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ static intr_handle_t s_interrupt_handle = NULL;

static void usb_interrupt_cb(void *arg_pv)
{
extern void OTG_FS_IRQHandler();
extern void USBD_IRQHandler();

OTG_FS_IRQHandler();
USBD_IRQHandler();
}

uint32_t usbd_get_dwc2_gccfg_conf(void)
{
return 0;
}

void usb_dc_low_level_init(void)
Expand Down
142 changes: 111 additions & 31 deletions additions/usb_config.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#define CHERRYUSB_VERSION 0x001001
#define CHERRYUSB_VERSION 0x010000
#define CHERRYUSB_VERSION_STR "v1.0.0"

#include "sdkconfig.h"
#include "esp_rom_sys.h"

Expand Down Expand Up @@ -36,60 +38,138 @@
// NOTE: Below configurations are removed to Kconfig, `idf.py menuconfig` to config them

/* Ep0 max transfer buffer, specially for receiving data from ep0 out */
// #define CONFIG_USBDEV_REQUEST_BUFFER_LEN 256
/******
#define CONFIG_USBDEV_REQUEST_BUFFER_LEN 256
******/

/* Setup packet log for debug */
// #define CONFIG_USBDEV_SETUP_LOG_PRINT

/* Check if the input descriptor is correct */
// #define CONFIG_USBDEV_DESC_CHECK

/* Enable test mode */
// #define CONFIG_USBDEV_TEST_MODE

#ifndef CONFIG_USBDEV_MSC_BLOCK_SIZE
#define CONFIG_USBDEV_MSC_BLOCK_SIZE 512
#endif

#ifndef CONFIG_USBDEV_MSC_MANUFACTURER_STRING
#define CONFIG_USBDEV_MSC_MANUFACTURER_STRING ""
#endif

#ifndef CONFIG_USBDEV_MSC_PRODUCT_STRING
#define CONFIG_USBDEV_MSC_PRODUCT_STRING ""
#endif

#ifndef CONFIG_USBDEV_MSC_VERSION_STRING
#define CONFIG_USBDEV_MSC_VERSION_STRING "0.01"
#endif

// #define CONFIG_USBDEV_MSC_THREAD

#ifndef CONFIG_USBDEV_MSC_PRIO
#define CONFIG_USBDEV_MSC_PRIO 4
#endif

#ifndef CONFIG_USBDEV_MSC_STACKSIZE
#define CONFIG_USBDEV_MSC_STACKSIZE 2048
#endif

#ifndef CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE
#define CONFIG_USBDEV_RNDIS_RESP_BUFFER_SIZE 156
#endif

#ifndef CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE
#define CONFIG_USBDEV_RNDIS_ETH_MAX_FRAME_SIZE 1536
#endif

#ifndef CONFIG_USBDEV_RNDIS_VENDOR_ID
#define CONFIG_USBDEV_RNDIS_VENDOR_ID 0x0000ffff
#endif

#ifndef CONFIG_USBDEV_RNDIS_VENDOR_DESC
#define CONFIG_USBDEV_RNDIS_VENDOR_DESC "CherryUSB"
#endif

#define CONFIG_USBDEV_RNDIS_USING_LWIP

/* ================ USB HOST Stack Configuration ================== */
// NOTE: Below configurations are removed to Kconfig, `idf.py menuconfig` to config them

// #define CONFIG_USBHOST_MAX_RHPORTS 1
// #define CONFIG_USBHOST_MAX_EXTHUBS 1
// #define CONFIG_USBHOST_MAX_EHPORTS 4
// #define CONFIG_USBHOST_MAX_INTERFACES 6
// #define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
// #define CONFIG_USBHOST_MAX_ENDPOINTS 4
// #define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
// #define CONFIG_USBHOST_MAX_HID_CLASS 4
// #define CONFIG_USBHOST_MAX_MSC_CLASS 2
// #define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
// #define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
// #define CONFIG_USBHOST_MAX_RNDIS_CLASS 1
// #define CONFIG_USBHOST_DEV_NAMELEN 16
// #define CONFIG_USBHOST_PSC_PRIO 4
// #define CONFIG_USBHOST_PSC_STACKSIZE 2048
/******
#define CONFIG_USBHOST_MAX_RHPORTS 1
#define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_MAX_EHPORTS 4
#define CONFIG_USBHOST_MAX_INTERFACES 8
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
#define CONFIG_USBHOST_MAX_HID_CLASS 4
#define CONFIG_USBHOST_MAX_MSC_CLASS 2
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
#define CONFIG_USBHOST_DEV_NAMELEN 16
******/

#ifndef CONFIG_USBHOST_PSC_PRIO
#define CONFIG_USBHOST_PSC_PRIO 0
#endif
#ifndef CONFIG_USBHOST_PSC_STACKSIZE
#define CONFIG_USBHOST_PSC_STACKSIZE 2048
#endif

// #define CONFIG_USBHOST_GET_STRING_DESC
// #define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
// #define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500

// #define CONFIG_USBHOST_MSOS_ENABLE
/******
#define CONFIG_USBHOST_MSOS_VENDOR_CODE 0x00
******/

/* Ep0 max transfer buffer */
/******
#define CONFIG_USBHOST_REQUEST_BUFFER_LEN 512
******/

#ifndef CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT
#define CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT 500
#endif

#ifndef CONFIG_USBHOST_MSC_TIMEOUT
#define CONFIG_USBHOST_MSC_TIMEOUT 5000
#endif

/* ================ USB Device Port Configuration ================*/

#define USBD_IRQHandler USBD_IRQHandler
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define CONFIG_USB_DWC2_PORT FS_PORT
#define USB_BASE 0x60080000
// esp32s2/s3 has 6 endpoints in device mode (except ep0)
#define USB_NUM_BIDIR_ENDPOINTS 4
#define USBD_BASE 0x60080000
// esp32s2/s3 has 7 endpoints in device mode (include ep0)
#define CONFIG_USBDEV_EP_NUM 7
#define CONFIG_USB_DWC2_RAM_SIZE 1280
#define CONFIG_USB_DWC2_TX6_FIFO_SIZE (128)
#elif CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32P4
#define CONFIG_USB_DWC2_PORT HS_PORT
#define CONFIG_USB_HS
#define USB_BASE 0x60080000
#define USBD_BASE 0x60080000
// todo: check c5, p4 in later
#define USB_NUM_BIDIR_ENDPOINTS 4
#define CONFIG_USBDEV_EP_NUM 7
#else
#error "Unsupported SoC"
#endif

/* ================ USB Host Port Configuration ==================*/

#define USBH_IRQHandler USBH_IRQHandler
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
// esp32s2/s3 has 7 endpoints in host mode (except ep0)
#define CONFIG_USBHOST_PIPE_NUM 7
#define USBH_BASE 0x60080000
// esp32s2/s3 has 8 endpoints in host mode (include ep0)
#define CONFIG_USBHOST_PIPE_NUM 8
#elif CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32P4
// todo: check c5, p4 in later
#define CONFIG_USBHOST_PIPE_NUM 7
#define USBH_BASE 0x60080000
#define CONFIG_USBHOST_PIPE_NUM 8
#else
#error "Unsupported SoC"
#endif
1 change: 0 additions & 1 deletion idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ repository: https://github.com/udoudou/esp_cherryusb.git
issues: https://github.com/udoudou/esp_cherryusb/issues
dependencies:
idf: ">=4.4.1"
leeebo/cherryusb: "~=0.10.1"
cmake_utilities: "0.*"

0 comments on commit 116a237

Please sign in to comment.