soc/hal: add tinyusb support esp32s3

add usb hal/soc, usb_ll files and esp32s3 target for usb
move usb_hal.h into soc common folder
soc/hal: fix soc and periph for usb
tinyusb: fix tinyusb io header
hal: usb_ll fix pull up/down config for esp32s3
soc/hal: fix peripheral addresses
This commit is contained in:
Alex Lisitsyn
2021-05-06 16:20:54 +08:00
committed by Michael (XIAO Xufeng)
parent 0a0234193f
commit ea6710ce98
20 changed files with 116 additions and 23 deletions

View File

@@ -35,6 +35,8 @@
#include "esp32s3/rom/gpio.h" #include "esp32s3/rom/gpio.h"
#elif CONFIG_IDF_TARGET_ESP32C3 #elif CONFIG_IDF_TARGET_ESP32C3
#include "esp32c3/rom/gpio.h" #include "esp32c3/rom/gpio.h"
#elif CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/rom/gpio.h"
#endif #endif
#ifdef CONFIG_LEGACY_INCLUDE_COMMON_HEADERS #ifdef CONFIG_LEGACY_INCLUDE_COMMON_HEADERS

View File

@@ -39,7 +39,7 @@
#define TEST_GPIO_EXT_IN_IO 20 // default input GPIO #define TEST_GPIO_EXT_IN_IO 20 // default input GPIO
#define TEST_GPIO_OUTPUT_PIN 12 #define TEST_GPIO_OUTPUT_PIN 12
#define TEST_GPIO_INPUT_ONLY_PIN 46 #define TEST_GPIO_INPUT_ONLY_PIN 46
#define TEST_GPIO_OUTPUT_MAX GPIO_NUM_47 #define TEST_GPIO_OUTPUT_MAX GPIO_NUM_MAX
#elif CONFIG_IDF_TARGET_ESP32C3 #elif CONFIG_IDF_TARGET_ESP32C3
#define TEST_GPIO_EXT_OUT_IO 2 // default output GPIO #define TEST_GPIO_EXT_OUT_IO 2 // default output GPIO
#define TEST_GPIO_EXT_IN_IO 3 // default input GPIO #define TEST_GPIO_EXT_IN_IO 3 // default input GPIO
@@ -166,7 +166,7 @@ static void drive_capability_set_get(gpio_num_t num, gpio_drive_cap_t capability
TEST_CASE("GPIO config parameters test", "[gpio]") TEST_CASE("GPIO config parameters test", "[gpio]")
{ {
//error param test //error param test
//ESP32 test 41 bit, ESP32-S2 test 48 bit //ESP32 test 41 bit, ESP32-S2 test 48 bit, ESP32-S3 test 49 bit
gpio_config_t io_config = { 0 }; gpio_config_t io_config = { 0 };
io_config.intr_type = GPIO_INTR_DISABLE; io_config.intr_type = GPIO_INTR_DISABLE;
io_config.pin_bit_mask = ((uint64_t)1<<(GPIO_NUM_MAX+1)); io_config.pin_bit_mask = ((uint64_t)1<<(GPIO_NUM_MAX+1));
@@ -176,7 +176,7 @@ TEST_CASE("GPIO config parameters test", "[gpio]")
io_config.pin_bit_mask = 0; io_config.pin_bit_mask = 0;
TEST_ASSERT(gpio_config(&io_config) == ESP_ERR_INVALID_ARG); TEST_ASSERT(gpio_config(&io_config) == ESP_ERR_INVALID_ARG);
//ESP32 test 40 bit, ESP32-S2 test 47 bit //ESP32 test 40 bit, ESP32-S2 test 47 bit, ESP32-S3 test 48 bit
io_config.pin_bit_mask = ((uint64_t)1<<GPIO_NUM_MAX); io_config.pin_bit_mask = ((uint64_t)1<<GPIO_NUM_MAX);
TEST_ASSERT(gpio_config(&io_config) == ESP_ERR_INVALID_ARG); TEST_ASSERT(gpio_config(&io_config) == ESP_ERR_INVALID_ARG);
@@ -396,12 +396,12 @@ TEST_CASE("GPIO set gpio output level test", "[gpio][ignore]")
gpio_config_t io_conf; gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_DISABLE; io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT; io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1<<TEST_GPIO_EXT_OUT_IO); io_conf.pin_bit_mask = ((uint64_t)1<<TEST_GPIO_EXT_OUT_IO);
io_conf.pull_down_en = 0; io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0; io_conf.pull_up_en = 0;
gpio_config(&io_conf); gpio_config(&io_conf);
io_conf.pin_bit_mask = (1<<TEST_GPIO_EXT_IN_IO); io_conf.pin_bit_mask = ((uint64_t)1<<TEST_GPIO_EXT_IN_IO);
io_conf.mode = GPIO_MODE_INPUT; io_conf.mode = GPIO_MODE_INPUT;
gpio_config(&io_conf); gpio_config(&io_conf);
@@ -436,12 +436,6 @@ TEST_CASE("GPIO get input level test", "[gpio][ignore]")
printf("gpio19's level is: %d\n", level2); printf("gpio19's level is: %d\n", level2);
TEST_ASSERT_EQUAL_INT_MESSAGE(level2, 0, "get level error! the level should be low!"); TEST_ASSERT_EQUAL_INT_MESSAGE(level2, 0, "get level error! the level should be low!");
printf("the memory get: %d\n", esp_get_free_heap_size()); printf("the memory get: %d\n", esp_get_free_heap_size());
gpio_num_t num3 = 34; // connect with 3.3v
int level3 = gpio_get_level(num3);
printf("gpio19's level is: %d\n", level3);
TEST_ASSERT_EQUAL_INT_MESSAGE(level3, 0, "get level error! the level should be low!");
printf("the memory get: %d\n", esp_get_free_heap_size());
//when case finish, get the result from multimeter, the pin17 is 3.3v, the pin19 is 0.00v //when case finish, get the result from multimeter, the pin17 is 3.3v, the pin19 is 0.00v
} }

View File

@@ -36,3 +36,4 @@ PROVIDE ( DMA = 0x6003F000 );
PROVIDE ( APB_SARADC = 0x60040000 ); PROVIDE ( APB_SARADC = 0x60040000 );
PROVIDE ( LCD_CAM = 0x60041000 ); PROVIDE ( LCD_CAM = 0x60041000 );
PROVIDE ( USB0 = 0x60080000 ); PROVIDE ( USB0 = 0x60080000 );
PROVIDE ( USB_WRAP = 0x60039000 );

View File

@@ -59,13 +59,13 @@ if(NOT BOOTLOADER_BUILD)
"spi_slave_hd_hal.c" "spi_slave_hd_hal.c"
"systimer_hal.c" "systimer_hal.c"
"touch_sensor_hal.c" "touch_sensor_hal.c"
"usb_hal.c"
"esp32s2/adc_hal.c" "esp32s2/adc_hal.c"
"esp32s2/brownout_hal.c" "esp32s2/brownout_hal.c"
"esp32s2/cp_dma_hal.c" "esp32s2/cp_dma_hal.c"
"esp32s2/touch_sensor_hal.c" "esp32s2/touch_sensor_hal.c"
"esp32s2/dac_hal.c" "esp32s2/dac_hal.c"
"esp32s2/interrupt_descriptor_table.c" "esp32s2/interrupt_descriptor_table.c"
"esp32s2/usb_hal.c"
"esp32s2/usbh_hal.c") "esp32s2/usbh_hal.c")
endif() endif()
@@ -78,6 +78,7 @@ if(NOT BOOTLOADER_BUILD)
"spi_slave_hd_hal.c" "spi_slave_hd_hal.c"
"systimer_hal.c" "systimer_hal.c"
"touch_sensor_hal.c" "touch_sensor_hal.c"
"usb_hal.c"
"esp32s3/brownout_hal.c" "esp32s3/brownout_hal.c"
"esp32s3/interrupt_descriptor_table.c" "esp32s3/interrupt_descriptor_table.c"
"esp32s3/touch_sensor_hal.c") "esp32s3/touch_sensor_hal.c")

View File

@@ -2,7 +2,7 @@ COMPONENT_SRCDIRS := . esp32
COMPONENT_ADD_INCLUDEDIRS := esp32/include include COMPONENT_ADD_INCLUDEDIRS := esp32/include include
COMPONENT_ADD_LDFRAGMENTS += linker.lf COMPONENT_ADD_LDFRAGMENTS += linker.lf
COMPONENT_OBJEXCLUDE += ./spi_slave_hd_hal.o ./spi_flash_hal_gpspi.o ./spi_slave_hd_hal.o ./ds_hal.o ./gdma_hal.o ./lcd_hal.o ./systimer_hal.o COMPONENT_OBJEXCLUDE += ./spi_slave_hd_hal.o ./spi_flash_hal_gpspi.o ./spi_slave_hd_hal.o ./ds_hal.o ./gdma_hal.o ./lcd_hal.o ./systimer_hal.o ./usb_hal.o
ifndef CONFIG_ETH_USE_ESP32_EMAC ifndef CONFIG_ETH_USE_ESP32_EMAC
COMPONENT_OBJEXCLUDE += esp32/emac_hal.o COMPONENT_OBJEXCLUDE += esp32/emac_hal.o

View File

@@ -0,0 +1,42 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "soc/soc.h"
#include "soc/system_reg.h"
#include "soc/gpio_sig_map.h"
#include "soc/usb_periph.h"
static inline void usb_ll_int_phy_enable(void)
{
USB_WRAP.otg_conf.pad_enable = 1;
USB_WRAP.otg_conf.phy_sel = 0;
}
static inline void usb_ll_ext_phy_enable(void)
{
USB_WRAP.otg_conf.pad_enable = 1;
USB_WRAP.otg_conf.phy_sel = 1;
}
static inline void usb_ll_int_phy_pullup_conf(bool dp_pu, bool dp_pd, bool dm_pu, bool dm_pd)
{
usb_wrap_otg_conf_reg_t conf = USB_WRAP.otg_conf;
conf.pad_pull_override = 1;
conf.dp_pullup = dp_pu;
conf.dp_pulldown = dp_pd;
conf.dm_pullup = dm_pu;
conf.dm_pulldown = dm_pd;
USB_WRAP.otg_conf = conf;
}

View File

@@ -76,6 +76,9 @@ typedef enum {
#define GPIO_SEL_44 ((uint64_t)(((uint64_t)1)<<44)) /*!< Pin 44 selected */ #define GPIO_SEL_44 ((uint64_t)(((uint64_t)1)<<44)) /*!< Pin 44 selected */
#define GPIO_SEL_45 ((uint64_t)(((uint64_t)1)<<45)) /*!< Pin 45 selected */ #define GPIO_SEL_45 ((uint64_t)(((uint64_t)1)<<45)) /*!< Pin 45 selected */
#define GPIO_SEL_46 ((uint64_t)(((uint64_t)1)<<46)) /*!< Pin 46 selected */ #define GPIO_SEL_46 ((uint64_t)(((uint64_t)1)<<46)) /*!< Pin 46 selected */
#if CONFIG_IDF_TARGET_ESP32S3
#define GPIO_SEL_47 ((uint64_t)(((uint64_t)1)<<47)) /*!< Pin 47 selected */
#endif
#endif #endif
#define GPIO_PIN_REG_0 IO_MUX_GPIO0_REG #define GPIO_PIN_REG_0 IO_MUX_GPIO0_REG
@@ -125,6 +128,7 @@ typedef enum {
#define GPIO_PIN_REG_44 IO_MUX_GPIO44_REG #define GPIO_PIN_REG_44 IO_MUX_GPIO44_REG
#define GPIO_PIN_REG_45 IO_MUX_GPIO45_REG #define GPIO_PIN_REG_45 IO_MUX_GPIO45_REG
#define GPIO_PIN_REG_46 IO_MUX_GPIO46_REG #define GPIO_PIN_REG_46 IO_MUX_GPIO46_REG
#define GPIO_PIN_REG_47 IO_MUX_GPIO47_REG
#if CONFIG_IDF_TARGET_ESP32 #if CONFIG_IDF_TARGET_ESP32
typedef enum { typedef enum {

View File

@@ -19,7 +19,8 @@ set(srcs
"spi_periph.c" "spi_periph.c"
"timer_periph.c" "timer_periph.c"
"touch_sensor_periph.c" "touch_sensor_periph.c"
"uart_periph.c") "uart_periph.c"
"usb_periph.c")
add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}") add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" "${srcs}")

View File

@@ -90,7 +90,7 @@
#define DR_REG_I2S1_BASE 0x6002D000 #define DR_REG_I2S1_BASE 0x6002D000
#define DR_REG_UART2_BASE 0x6002E000 #define DR_REG_UART2_BASE 0x6002E000
#define DR_REG_SPI4_BASE 0x60037000 #define DR_REG_SPI4_BASE 0x60037000
#define DR_REG_USB_DEVICE_BASE 0x60038000 #define DR_REG_USB_DEVICE_BASE 0x60080000
#define DR_REG_USB_WRAP_BASE 0x60039000 #define DR_REG_USB_WRAP_BASE 0x60039000
#define DR_REG_APB_SARADC_BASE 0x60040000 #define DR_REG_APB_SARADC_BASE 0x60040000
#define DR_REG_LCD_CAM_BASE 0x60041000 #define DR_REG_LCD_CAM_BASE 0x60041000

View File

@@ -130,6 +130,10 @@
#define SOC_UART_SUPPORT_RTC_CLK (1) /*!< Support RTC clock as the clock source */ #define SOC_UART_SUPPORT_RTC_CLK (1) /*!< Support RTC clock as the clock source */
#define SOC_UART_SUPPORT_XTAL_CLK (1) /*!< Support XTAL clock as the clock source */ #define SOC_UART_SUPPORT_XTAL_CLK (1) /*!< Support XTAL clock as the clock source */
/*-------------------------- USB CAPS ----------------------------------------*/
#define SOC_USB_PERIPH_NUM 1
/*--------------------------- SHA CAPS ---------------------------------------*/ /*--------------------------- SHA CAPS ---------------------------------------*/
/* Max amount of bytes in a single DMA operation is 4095, /* Max amount of bytes in a single DMA operation is 4095,
for SHA this means that the biggest safe amount of bytes is for SHA this means that the biggest safe amount of bytes is

View File

@@ -20,6 +20,7 @@
#pragma once #pragma once
#include "soc/usb_pins.h"
#include "soc/gpio_pins.h" #include "soc/gpio_pins.h"
#include "soc/spi_pins.h" #include "soc/spi_pins.h"
#include "soc/sdio_slave_pins.h" #include "soc/sdio_slave_pins.h"

View File

@@ -0,0 +1,31 @@
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "soc/soc_caps.h"
#include "soc/usb_periph.h"
const usb_iopin_dsc_t usb_periph_iopins[] = {
{USBPHY_VP_NUM, USB_EXTPHY_VP_IDX, 0, 1},
{USBPHY_VM_NUM, USB_EXTPHY_VM_IDX, 0, 1},
{USBPHY_RCV_NUM, USB_EXTPHY_RCV_IDX, 0, 1},
{USBPHY_OEN_NUM, USB_EXTPHY_OEN_IDX, 1, 1},
{USBPHY_VPO_NUM, USB_EXTPHY_VPO_IDX, 1, 1},
{USBPHY_VMO_NUM, USB_EXTPHY_VMO_IDX, 1, 1},
{GPIO_MATRIX_CONST_ONE_INPUT, USB_OTG_IDDIG_IN_IDX, 0, 0}, //connected connector is mini-B
//connected connector is mini-B
{GPIO_MATRIX_CONST_ONE_INPUT, USB_SRP_BVALID_IN_IDX, 0, 0}, //HIGH to force USB device mode
{GPIO_MATRIX_CONST_ONE_INPUT, USB_OTG_VBUSVALID_IN_IDX, 0, 0}, //receiving a valid Vbus from host
{GPIO_MATRIX_CONST_ZERO_INPUT, USB_OTG_AVALID_IN_IDX, 0, 0},
{-1, -1, 0, 0}
};

View File

@@ -1,14 +1,27 @@
idf_build_get_property(target IDF_TARGET)
idf_component_register(REQUIRES esp_rom freertos vfs soc) idf_component_register(REQUIRES esp_rom freertos vfs soc)
if(CONFIG_USB_ENABLED) if(CONFIG_USB_ENABLED)
if(target STREQUAL "esp32s3")
set(tusb_mcu "OPT_MCU_ESP32S3")
set(tusb_family "esp32sx")
elseif(target STREQUAL "esp32s2")
set(tusb_mcu "OPT_MCU_ESP32S2")
set(tusb_family "esp32sx")
else()
message("TinyUSB does not support ${target}.")
return()
endif()
### variables ### ### variables ###
################# #################
set(compile_options set(compile_options
"-DCFG_TUSB_MCU=OPT_MCU_ESP32S2" "-DCFG_TUSB_MCU=${tusb_mcu}"
"-DCFG_TUSB_DEBUG=${CONFIG_USB_DEBUG_LEVEL}" "-DCFG_TUSB_DEBUG=${CONFIG_USB_DEBUG_LEVEL}"
"-Wno-type-limits" # needed for the vanila tinyusb with turned off classes "-Wno-type-limits" # needed for the vanila tinyusb with turned off classes
) )
idf_component_get_property(FREERTOS_ORIG_INCLUDE_PATH freertos idf_component_get_property(FREERTOS_ORIG_INCLUDE_PATH freertos
ORIG_INCLUDE_PATH) ORIG_INCLUDE_PATH)
set(includes_private set(includes_private
@@ -33,7 +46,7 @@ if(CONFIG_USB_ENABLED)
"${COMPONENT_DIR}/additions/src/tusb_tasks.c" "${COMPONENT_DIR}/additions/src/tusb_tasks.c"
"${COMPONENT_DIR}/additions/src/usb_descriptors.c" "${COMPONENT_DIR}/additions/src/usb_descriptors.c"
# tusb: # tusb:
"${COMPONENT_DIR}/tinyusb/src/portable/espressif/esp32s2/dcd_esp32s2.c" "${COMPONENT_DIR}/tinyusb/src/portable/espressif/${tusb_family}/dcd_${tusb_family}.c"
"${COMPONENT_DIR}/tinyusb/src/class/cdc/cdc_device.c" "${COMPONENT_DIR}/tinyusb/src/class/cdc/cdc_device.c"
"${COMPONENT_DIR}/tinyusb/src/class/hid/hid_device.c" "${COMPONENT_DIR}/tinyusb/src/class/hid/hid_device.c"
"${COMPONENT_DIR}/tinyusb/src/class/midi/midi_device.c" "${COMPONENT_DIR}/tinyusb/src/class/midi/midi_device.c"

View File

@@ -3,7 +3,7 @@ menu "TinyUSB"
config USB_ENABLED config USB_ENABLED
bool "Enable TinyUSB driver" bool "Enable TinyUSB driver"
default n default n
depends on IDF_TARGET_ESP32S2 depends on IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
select FREERTOS_USE_AUTHENTIC_INCLUDE_PATHS select FREERTOS_USE_AUTHENTIC_INCLUDE_PATHS
help help
Adds support for TinyUSB Adds support for TinyUSB

View File

@@ -16,7 +16,6 @@
#include "esp_rom_gpio.h" #include "esp_rom_gpio.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "driver/periph_ctrl.h" #include "driver/periph_ctrl.h"
#include "esp32s2/rom/gpio.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "hal/gpio_ll.h" #include "hal/gpio_ll.h"

View File

@@ -8,7 +8,7 @@ function(__add_dfu_targets)
elseif("${target}" STREQUAL "esp32s2") elseif("${target}" STREQUAL "esp32s2")
set(dfu_pid "2") set(dfu_pid "2")
elseif("${target}" STREQUAL "esp32s3") elseif("${target}" STREQUAL "esp32s3")
set(dfu_pid "4") set(dfu_pid "6")
elseif("${target}" STREQUAL "esp32c3") elseif("${target}" STREQUAL "esp32c3")
return() return()
elseif("${target}" STREQUAL "linux") elseif("${target}" STREQUAL "linux")