Skip to content

Commit

Permalink
added p4, seems to work well and enumerated
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Sep 25, 2024
1 parent fefeabb commit d7c53c1
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 87 deletions.
9 changes: 8 additions & 1 deletion .idea/cmake.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions hw/bsp/espressif/boards/espressif_p4_function_ev/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Apply board specific content here
set(IDF_TARGET "esp32p4")
43 changes: 43 additions & 0 deletions hw/bsp/espressif/boards/espressif_p4_function_ev/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020, Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* This file is part of the TinyUSB stack.
*/

#ifndef BOARD_H_
#define BOARD_H_

#ifdef __cplusplus
extern "C" {
#endif

// #define NEOPIXEL_PIN 48

#define BUTTON_PIN 0
#define BUTTON_STATE_ACTIVE 0

#ifdef __cplusplus
}
#endif

#endif /* BOARD_H_ */
3 changes: 3 additions & 0 deletions hw/bsp/espressif/family.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ string(TOUPPER ${IDF_TARGET} FAMILY_MCUS)
# Add example src and bsp directories
set(EXTRA_COMPONENT_DIRS "src" "${CMAKE_CURRENT_LIST_DIR}/boards" "${CMAKE_CURRENT_LIST_DIR}/components")

# set SDKCONFIG for each IDF Target
set(SDKCONFIG ${CMAKE_SOURCE_DIR}/sdkconfig.${IDF_TARGET})

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6 changes: 3 additions & 3 deletions src/common/tusb_mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,13 @@
#elif TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
#define TUP_USBIP_DWC2
#define TUP_USBIP_DWC2_ESP32
#define TUP_DCD_ENDPOINT_MAX 6
#define TUP_DCD_ENDPOINT_MAX 7 // only 5 TX FIFO for endpoint IN

#elif TU_CHECK_MCU(OPT_MCU_ESP32P4)
#define TUP_USBIP_DWC2
#define TUP_USBIP_DWC2_ESP32
#define TUP_RHPORT_HIGHSPEED 1 // 1 port FS, 1 port HS
#define TUP_DCD_ENDPOINT_MAX 8 // FS 6 ep, HS 8 ep
#define TUP_RHPORT_HIGHSPEED 1 // port0 FS, port1 HS
#define TUP_DCD_ENDPOINT_MAX 16 // FS 7 ep, HS 16 ep

#elif TU_CHECK_MCU(OPT_MCU_ESP32, OPT_MCU_ESP32C2, OPT_MCU_ESP32C3, OPT_MCU_ESP32C6, OPT_MCU_ESP32H2)
#if (CFG_TUD_ENABLED || !(defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421))
Expand Down
23 changes: 9 additions & 14 deletions src/portable/synopsys/dwc2/dcd_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,18 +508,6 @@ static void edpt_schedule_packets(uint8_t rhport, uint8_t const epnum, uint8_t c
/*------------------------------------------------------------------*/
/* Controller API
*------------------------------------------------------------------*/
#if CFG_TUSB_DEBUG >= DWC2_DEBUG
void print_dwc2_info(dwc2_regs_t* dwc2) {
// print guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4
// use dwc2_info.py/md for bit-field value and comparison with other ports
volatile uint32_t const* p = (volatile uint32_t const*) &dwc2->guid;
TU_LOG(DWC2_DEBUG, "guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4\r\n");
for (size_t i = 0; i < 5; i++) {
TU_LOG(DWC2_DEBUG, "0x%08" PRIX32 ", ", p[i]);
}
TU_LOG(DWC2_DEBUG, "0x%08" PRIX32 "\r\n", p[5]);
}
#endif

static void reset_core(dwc2_regs_t* dwc2) {
// reset core
Expand Down Expand Up @@ -633,8 +621,15 @@ static void phy_hs_init(dwc2_regs_t* dwc2) {
}

static bool check_dwc2(dwc2_regs_t* dwc2) {
#if CFG_TUSB_DEBUG >= DWC2_DEBUG
print_dwc2_info(dwc2);
#if CFG_TUSB_DEBUG >= DWC2_DEBUG || 1
// print guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4
// Run 'dwc2_info.py render-md' and check dwc2_info.md for bit-field value and comparison with other ports
volatile uint32_t const* p = (volatile uint32_t const*) &dwc2->guid;
TU_LOG1("guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4\r\n");
for (size_t i = 0; i < 5; i++) {
TU_LOG1("0x%08" PRIX32 ", ", p[i]);
}
TU_LOG1("0x%08" PRIX32 "\r\n", p[5]);
#endif

// For some reason: GD32VF103 snpsid and all hwcfg register are always zero (skip it)
Expand Down
48 changes: 37 additions & 11 deletions src/portable/synopsys/dwc2/dwc2_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,55 @@
#include "soc/periph_defs.h"
#include "soc/usb_wrap_struct.h"

#define DWC2_REG_BASE 0x60080000UL
#define DWC2_EP_MAX 7
#define DWC2_EP_IN_MAX 5
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
#define DWC2_PERIPH_COUNT 1
#define DWC2_FS_REG_BASE 0x60080000UL
#define DWC2_EP_MAX 7

static const dwc2_controller_t _dwc2_controller[] = {
{ .reg_base = DWC2_REG_BASE, .irqnum = 0, .ep_count = DWC2_EP_MAX, .ep_in_count = DWC2_EP_IN_MAX, .ep_fifo_size = 1024 }
{ .reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5, .ep_fifo_size = 1024 }
};

static intr_handle_t usb_ih;
#elif TU_CHECK_MCU(OPT_MCU_ESP32P4)

#define DWC2_PERIPH_COUNT 2
#define DWC2_FS_REG_BASE 0x50040000UL
#define DWC2_HS_REG_BASE 0x50000000UL
#define DWC2_EP_MAX 16

// On ESP32 for consistency we associate
// - Port0 to OTG_FS, and Port1 to OTG_HS
static const dwc2_controller_t _dwc2_controller[] = {
{
.reg_base = DWC2_HS_REG_BASE, .irqnum = ETS_USB_OTG_INTR_SOURCE, .ep_count = 16, .ep_in_count = 8,
.ep_fifo_size = 4096
},
{
.reg_base = DWC2_FS_REG_BASE, .irqnum = ETS_USB_OTG11_CH0_INTR_SOURCE, .ep_count = 7, .ep_in_count = 5,
.ep_fifo_size = 1024
}

};
#endif

enum {
DWC2_CONTROLLER_COUNT = TU_ARRAY_SIZE(_dwc2_controller)
};

static intr_handle_t usb_ih[DWC2_CONTROLLER_COUNT];

static void dcd_int_handler_wrap(void* arg) {
(void)arg;
dcd_int_handler(0);
const uint8_t rhport = (uint8_t) arg;
dcd_int_handler(rhport);
}

TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_enable(uint8_t rhport) {
(void)rhport;
esp_intr_alloc(ETS_USB_INTR_SOURCE, ESP_INTR_FLAG_LOWMED, dcd_int_handler_wrap, NULL, &usb_ih);
esp_intr_alloc(_dwc2_controller[rhport].irqnum, ESP_INTR_FLAG_LOWMED,
dcd_int_handler_wrap, (void*) rhport, &usb_ih[rhport]);
}

TU_ATTR_ALWAYS_INLINE static inline void dwc2_dcd_int_disable(uint8_t rhport) {
(void)rhport;
esp_intr_free(usb_ih);
esp_intr_free(usb_ih[rhport]);
}

TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) {
Expand Down
Loading

0 comments on commit d7c53c1

Please sign in to comment.