From 2c341a855767bb8d67a0d96baf089517a892d466 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 17 May 2022 18:55:39 +0200 Subject: [PATCH 1/8] console: minor fixes - wrong comment - duplicated setvbuf --- components/console/esp_console_repl.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/components/console/esp_console_repl.c b/components/console/esp_console_repl.c index 7cee440e5f7..123572d62f2 100644 --- a/components/console/esp_console_repl.c +++ b/components/console/esp_console_repl.c @@ -81,7 +81,7 @@ esp_err_t esp_console_new_repl_usb_cdc(const esp_console_dev_usb_cdc_config_t *d /* Move the caret to the beginning of the next line on '\n' */ esp_vfs_dev_cdcacm_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); - /* Enable non-blocking mode on stdin and stdout */ + /* Enable blocking mode on stdin and stdout */ fcntl(fileno(stdout), F_SETFL, 0); fcntl(fileno(stdin), F_SETFL, 0); @@ -142,15 +142,12 @@ esp_err_t esp_console_new_repl_usb_serial_jtag(const esp_console_dev_usb_serial_ goto _exit; } - /* Disable buffering on stdin */ - setvbuf(stdin, NULL, _IONBF, 0); - /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); - /* Enable non-blocking mode on stdin and stdout */ + /* Enable blocking mode on stdin and stdout */ fcntl(fileno(stdout), F_SETFL, 0); fcntl(fileno(stdin), F_SETFL, 0); From c7b409aa949fff0d74d69e2753be08402ad23d6a Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 18 Jan 2022 18:39:06 +0100 Subject: [PATCH 2/8] esp_rom: sync changes for ESP32-S3 USB related files, minor fix for S2 Used esp-rom tag esp32s3-20210327 and did manual cleanup. Rename s_usb_osglue to rom_usb_osglue like it was done for esp32s2. Some comments in esp32s2 headers are synced from esp32s3. --- components/esp_rom/esp32s3/ld/esp32s3.rom.ld | 2 +- .../esp_rom/include/esp32s2/rom/usb/usb_dc.h | 34 +++++++++++++++--- .../include/esp32s2/rom/usb/usb_device.h | 6 ++++ .../include/esp32s3/rom/usb/usb_common.h | 20 ----------- .../esp_rom/include/esp32s3/rom/usb/usb_dc.h | 35 +++++++++++++++---- .../include/esp32s3/rom/usb/usb_device.h | 6 ++++ .../esp_rom/include/esp32s3/rom/usb/usb_dfu.h | 1 + .../include/esp32s3/rom/usb/usb_os_glue.h | 20 ++++------- .../include/esp32s3/rom/usb/usb_persist.h | 20 ++++------- tools/ci/check_copyright_ignore.txt | 2 -- 10 files changed, 84 insertions(+), 62 deletions(-) diff --git a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index 85bf3a7715e..ca7ddf111ac 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -792,7 +792,7 @@ usb_dfu_force_detach = 0x40002a54; usb_dev_deinit = 0x40002a60; usb_dw_ctrl_deinit = 0x40002a6c; /* Data (.data, .bss, .rodata) */ -s_usb_osglue = 0x3fceffac; +rom_usb_osglue = 0x3fceffac; /*************************************** diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_dc.h b/components/esp_rom/include/esp32s2/rom/usb/usb_dc.h index f20e897c71a..acfbf34952e 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_dc.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_dc.h @@ -372,19 +372,43 @@ int usb_dc_ep_read_continue(uint8_t ep); int usb_dc_ep_mps(uint8_t ep); - -//Hack - fake interrupts by pollinfg +/** + * @brief Poll for interrupts that need to be handled + * + * When the USB interrupt is not hooked up to an actual CPU interrupt, you + * can call this periodically to handle the USB events that need handling. + */ void usb_dc_check_poll_for_interrupts(void); -//Prepare for USB persist. You should reboot after this. +/* + * @brief Prepare for USB persist + * + * This takes the USB peripheral offline in such a way that it seems 'just busy' to the + * host. This way, the chip can reboot (e.g. into bootloader mode) and pick up the USB + * configuration again, without the conenction to the host being interrupted. + * + * @note Actual persistence is depending on USBDC_PERSIST_ENA being set in flags, as this + * is also used to e.g. reboot into DFU mode. + * + * @note Please reboot soon after calling this. + */ int usb_dc_prepare_persist(void); - +/* + * @brief USB interrupt handler + * + * This can be hooked up by the OS to the USB peripheral interrupt. + */ void usb_dw_isr_handler(void); +/** + * @brief Provide IDF with an interface to clear the static variable usb_dw_ctrl + * + * + */ +void usb_dw_ctrl_deinit(void); -int usb_dc_ep_write_would_block(const uint8_t ep); #ifdef __cplusplus diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_device.h b/components/esp_rom/include/esp32s2/rom/usb/usb_device.h index a63288c71bb..e5103c143a9 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_device.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_device.h @@ -392,6 +392,12 @@ int usb_transfer_sync(uint8_t ep, uint8_t *data, size_t dlen, unsigned int flags */ void usb_cancel_transfer(uint8_t ep); +/** + * @brief Provide IDF with an interface to clear the static variable usb_dev + * + * + */ +void usb_dev_deinit(void); void usb_dev_resume(int configuration); int usb_dev_get_configuration(void); diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_common.h b/components/esp_rom/include/esp32s3/rom/usb/usb_common.h index c3bd52cfb94..06ae01a93c7 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_common.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_common.h @@ -217,26 +217,6 @@ struct string_descriptor { uint16_t bString[]; } __packed; -#define ROM_MAX_CFG_DESC_CNT 1 - -struct rom_usb_descriptors { - const struct usb_device_descriptor *device_descr; - const void *config_descr[ROM_MAX_CFG_DESC_CNT]; - int string_count; // including string_descriptor_zero - const struct string_descriptor_zero *string0_descr; - const struct string_descriptor *string_descrs[]; -}; - -/* Descriptors defined in the ROM */ -extern struct usb_device_descriptor general_device_descr; -extern const void* acm_config_descr; -extern const void* dfu_config_descr; -extern const struct string_descriptor str_manu_descr; -extern const struct string_descriptor str_prod_descr; -extern const struct string_descriptor_zero string0_descr; -extern const struct rom_usb_descriptors acm_usb_descriptors; -extern const struct rom_usb_descriptors dfu_usb_descriptors; -extern const struct rom_usb_descriptors *rom_usb_curr_desc; #ifdef __cplusplus } diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_dc.h b/components/esp_rom/include/esp32s3/rom/usb/usb_dc.h index f20e897c71a..2e74044057b 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_dc.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_dc.h @@ -372,19 +372,42 @@ int usb_dc_ep_read_continue(uint8_t ep); int usb_dc_ep_mps(uint8_t ep); - -//Hack - fake interrupts by pollinfg +/** + * @brief Poll for interrupts that need to be handled + * + * When the USB interrupt is not hooked up to an actual CPU interrupt, you + * can call this periodically to handle the USB events that need handling. + */ void usb_dc_check_poll_for_interrupts(void); -//Prepare for USB persist. You should reboot after this. +/* + * @brief Prepare for USB persist + * + * This takes the USB peripheral offline in such a way that it seems 'just busy' to the + * host. This way, the chip can reboot (e.g. into bootloader mode) and pick up the USB + * configuration again, without the conenction to the host being interrupted. + * + * @note Actual persistence is depending on USBDC_PERSIST_ENA being set in flags, as this + * is also used to e.g. reboot into DFU mode. + * + * @note Please reboot soon after calling this. + */ int usb_dc_prepare_persist(void); - +/* + * @brief USB interrupt handler + * + * This can be hooked up by the OS to the USB peripheral interrupt. + */ void usb_dw_isr_handler(void); - -int usb_dc_ep_write_would_block(const uint8_t ep); +/** + * @brief Provide IDF with an interface to clear the static variable usb_dw_ctrl + * + * + */ +void usb_dw_ctrl_deinit(void); #ifdef __cplusplus diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_device.h b/components/esp_rom/include/esp32s3/rom/usb/usb_device.h index a63288c71bb..e5103c143a9 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_device.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_device.h @@ -392,6 +392,12 @@ int usb_transfer_sync(uint8_t ep, uint8_t *data, size_t dlen, unsigned int flags */ void usb_cancel_transfer(uint8_t ep); +/** + * @brief Provide IDF with an interface to clear the static variable usb_dev + * + * + */ +void usb_dev_deinit(void); void usb_dev_resume(int configuration); int usb_dev_get_configuration(void); diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h b/components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h index dec7ea93a39..1cfa80d8c56 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h @@ -140,6 +140,7 @@ int dfu_custom_handle_req(struct usb_setup_packet *pSetup, typedef void(*usb_dfu_detach_routine_t)(int delay); void usb_dfu_set_detach_cb(usb_dfu_detach_routine_t cb); +void usb_dfu_force_detach(void); #ifdef __cplusplus diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_os_glue.h b/components/esp_rom/include/esp32s3/rom/usb/usb_os_glue.h index 9abad6d0b96..4989b00ec57 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_os_glue.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_os_glue.h @@ -1,16 +1,8 @@ -// Copyright 2019-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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -33,7 +25,7 @@ typedef struct { usb_osglue_wait_routine_t wait_proc; } usb_osglue_data_t; -extern usb_osglue_data_t s_usb_osglue; +extern usb_osglue_data_t rom_usb_osglue; #ifdef __cplusplus } diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_persist.h b/components/esp_rom/include/esp32s3/rom/usb/usb_persist.h index bcf11b7c48c..90dfe98e4ad 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_persist.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_persist.h @@ -1,16 +1,8 @@ -// Copyright 2019-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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -34,7 +26,7 @@ extern "C" { //This being non-0 indicates a memory location where a 'testament' is stored, aka a piece of text that should be output //after a reboot. Can contain core dump info or something. -#define USBDC_TESTAMENT_LOC_MASK 0x7FFFF //bits 19-0; this is added to a base address of 0x3FF80000. +#define USBDC_TESTAMENT_LOC_MASK 0x7FFFF //bits 19-0; this is added to a base address of SOC_MEM_INTERNAL_LOW. (0x3FF9E000) //The testament is a FIFO. The ROM will output all data between textstart and textend; if textend is lower than textstart it will //output everything from textstart to memend, then memstart to textend. diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 15a10cc57e3..fcf6ae5a272 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -524,8 +524,6 @@ components/esp_rom/include/esp32s3/rom/usb/usb_dc.h components/esp_rom/include/esp32s3/rom/usb/usb_descriptor.h components/esp_rom/include/esp32s3/rom/usb/usb_device.h components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h -components/esp_rom/include/esp32s3/rom/usb/usb_os_glue.h -components/esp_rom/include/esp32s3/rom/usb/usb_persist.h components/esp_rom/include/esp_rom_crc.h components/esp_rom/include/esp_rom_gpio.h components/esp_rom/include/linux/soc/reset_reasons.h From 228dbe103f0ffa3f167f8615316929e6c07f77c5 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 17 May 2022 23:43:47 +0200 Subject: [PATCH 3/8] esp_rom: add USB_OTG "port" number for S2 and S3 --- components/bootloader_support/src/bootloader_console.c | 2 +- components/esp_rom/esp32s2/Kconfig.soc_caps.in | 4 ++++ components/esp_rom/esp32s2/esp_rom_caps.h | 1 + components/esp_rom/esp32s3/Kconfig.soc_caps.in | 4 ++++ components/esp_rom/esp32s3/esp_rom_caps.h | 1 + components/esp_system/port/soc/esp32s2/usb_console.c | 4 +++- 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/bootloader_support/src/bootloader_console.c b/components/bootloader_support/src/bootloader_console.c index effff7e0f3f..fa6d3b681df 100644 --- a/components/bootloader_support/src/bootloader_console.c +++ b/components/bootloader_support/src/bootloader_console.c @@ -98,7 +98,7 @@ void bootloader_console_init(void) #endif esp_rom_uart_usb_acm_init(s_usb_cdc_buf, sizeof(s_usb_cdc_buf)); - esp_rom_uart_set_as_console(ESP_ROM_UART_USB); + esp_rom_uart_set_as_console(ESP_ROM_USB_OTG_NUM); esp_rom_install_channel_putc(1, bootloader_console_write_char_usb); #if SOC_USB_SERIAL_JTAG_SUPPORTED usb_phy_ll_usb_wrap_pad_enable(&USB_WRAP, true); diff --git a/components/esp_rom/esp32s2/Kconfig.soc_caps.in b/components/esp_rom/esp32s2/Kconfig.soc_caps.in index d399b8c5cb1..f94ca745ae0 100644 --- a/components/esp_rom/esp32s2/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32s2/Kconfig.soc_caps.in @@ -30,3 +30,7 @@ config ESP_ROM_HAS_NEWLIB_NANO_FORMAT config ESP_ROM_HAS_FLASH_COUNT_PAGES_BUG bool default y + +config ESP_ROM_USB_OTG_NUM + int + default 3 diff --git a/components/esp_rom/esp32s2/esp_rom_caps.h b/components/esp_rom/esp32s2/esp_rom_caps.h index 0657e446c09..2261d70b57c 100644 --- a/components/esp_rom/esp32s2/esp_rom_caps.h +++ b/components/esp_rom/esp32s2/esp_rom_caps.h @@ -13,3 +13,4 @@ #define ESP_ROM_HAS_REGI2C_BUG (1) // ROM has the regi2c bug #define ESP_ROM_HAS_NEWLIB_NANO_FORMAT (1) // ROM has the newlib nano version of formatting functions #define ESP_ROM_HAS_FLASH_COUNT_PAGES_BUG (1) // ROM api Cache_Count_Flash_Pages will return unexpected value +#define ESP_ROM_USB_OTG_NUM (3) // The serial port ID (UART, USB, ...) of USB_OTG CDC in the ROM. diff --git a/components/esp_rom/esp32s3/Kconfig.soc_caps.in b/components/esp_rom/esp32s3/Kconfig.soc_caps.in index 30b1f52d169..94b178a10e6 100644 --- a/components/esp_rom/esp32s3/Kconfig.soc_caps.in +++ b/components/esp_rom/esp32s3/Kconfig.soc_caps.in @@ -27,6 +27,10 @@ config ESP_ROM_HAS_RETARGETABLE_LOCKING bool default y +config ESP_ROM_USB_OTG_NUM + int + default 3 + config ESP_ROM_USB_SERIAL_DEVICE_NUM int default 4 diff --git a/components/esp_rom/esp32s3/esp_rom_caps.h b/components/esp_rom/esp32s3/esp_rom_caps.h index ee3740b53ab..3312efac0ae 100644 --- a/components/esp_rom/esp32s3/esp_rom_caps.h +++ b/components/esp_rom/esp32s3/esp_rom_caps.h @@ -12,6 +12,7 @@ #define ESP_ROM_HAS_JPEG_DECODE (1) // ROM has JPEG decode library #define ESP_ROM_UART_CLK_IS_XTAL (1) // UART clock source is selected to XTAL in ROM #define ESP_ROM_HAS_RETARGETABLE_LOCKING (1) // ROM was built with retargetable locking +#define ESP_ROM_USB_OTG_NUM (3) // The serial port ID (UART, USB, ...) of USB_OTG CDC in the ROM. #define ESP_ROM_USB_SERIAL_DEVICE_NUM (4) // The serial port ID (UART, USB, ...) of USB_SERIAL_JTAG in the ROM. #define ESP_ROM_HAS_ERASE_0_REGION_BUG (1) // ROM has esp_flash_erase_region(size=0) bug #define ESP_ROM_GET_CLK_FREQ (1) // Get clk frequency with rom function `ets_get_cpu_frequency` diff --git a/components/esp_system/port/soc/esp32s2/usb_console.c b/components/esp_system/port/soc/esp32s2/usb_console.c index 16a6360762b..c2a5783ce9a 100644 --- a/components/esp_system/port/soc/esp32s2/usb_console.c +++ b/components/esp_system/port/soc/esp32s2/usb_console.c @@ -27,6 +27,7 @@ #include "hal/soc_hal.h" #include "esp_rom_uart.h" #include "esp_rom_sys.h" +#include "esp_rom_caps.h" #include "esp32s2/rom/usb/usb_dc.h" #include "esp32s2/rom/usb/cdc_acm.h" #include "esp32s2/rom/usb/usb_dfu.h" @@ -288,7 +289,8 @@ esp_err_t esp_usb_console_init(void) #ifdef CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF /* Install esp_rom_printf handler */ - ets_install_putc1(&esp_usb_console_write_char); + esp_rom_uart_set_as_console(ESP_ROM_USB_OTG_NUM); + esp_rom_install_channel_putc(1, &esp_usb_console_write_char); #endif // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF return ESP_OK; From 6d1f573945eae36d6b974850e72a204bcc41a365 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 18 Jan 2022 20:48:37 +0100 Subject: [PATCH 4/8] esp_rom: implement usb deinit functions added in S3 ROM for S2 This cleans up usb_console.c and prepares it for S3 support. --- components/esp_rom/CMakeLists.txt | 2 +- .../esp32s2/{usb_descriptors.c => usb_patches.c} | 16 ++++++++++++++++ .../esp_system/port/soc/esp32s2/usb_console.c | 7 ++----- 3 files changed, 19 insertions(+), 6 deletions(-) rename components/esp_rom/esp32s2/{usb_descriptors.c => usb_patches.c} (76%) diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index d9a30c530e0..aaf7727ddcd 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -288,5 +288,5 @@ else() # Regular app build endif() if(target STREQUAL "esp32s2") - target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_descriptors.c") + target_sources(${COMPONENT_LIB} PRIVATE "esp32s2/usb_patches.c") endif() diff --git a/components/esp_rom/esp32s2/usb_descriptors.c b/components/esp_rom/esp32s2/usb_patches.c similarity index 76% rename from components/esp_rom/esp32s2/usb_descriptors.c rename to components/esp_rom/esp32s2/usb_patches.c index 279930095dc..978c9b1f788 100644 --- a/components/esp_rom/esp32s2/usb_descriptors.c +++ b/components/esp_rom/esp32s2/usb_patches.c @@ -65,3 +65,19 @@ void rom_usb_cdc_set_descriptor_patch(void) /* Override the pointer to descriptors structure */ rom_usb_curr_desc = &s_acm_usb_descriptors_override; } + +/* On ESP32-S2, ROM doesn't provide interfaces to clear usb_dev and usb_dw_ctrl structures. + * Starting from ESP32-S3, usb_dev_deinit and usb_dw_ctrl_deinit ROM functions are available. + * Here we implement the missing functionality for the ESP32-S2. + */ +void usb_dev_deinit(void) +{ + extern char rom_usb_dev, rom_usb_dev_end; + memset((void *) &rom_usb_dev, 0, &rom_usb_dev_end - &rom_usb_dev); +} + +void usb_dw_ctrl_deinit(void) +{ + extern char rom_usb_dw_ctrl, rom_usb_dw_ctrl_end; + memset((void *) &rom_usb_dw_ctrl, 0, &rom_usb_dw_ctrl_end - &rom_usb_dw_ctrl); +} diff --git a/components/esp_system/port/soc/esp32s2/usb_console.c b/components/esp_system/port/soc/esp32s2/usb_console.c index c2a5783ce9a..c1875c2a446 100644 --- a/components/esp_system/port/soc/esp32s2/usb_console.c +++ b/components/esp_system/port/soc/esp32s2/usb_console.c @@ -232,12 +232,9 @@ void esp_usb_console_before_restart(void) */ static void esp_usb_console_rom_cleanup(void) { - extern char rom_usb_dev, rom_usb_dev_end; - extern char rom_usb_dw_ctrl, rom_usb_dw_ctrl_end; - + usb_dev_deinit(); + usb_dw_ctrl_deinit(); uart_acm_dev = NULL; - memset((void *) &rom_usb_dev, 0, &rom_usb_dev_end - &rom_usb_dev); - memset((void *) &rom_usb_dw_ctrl, 0, &rom_usb_dw_ctrl_end - &rom_usb_dw_ctrl); } esp_err_t esp_usb_console_init(void) From 22dd730a7c9ecdbc72f1dbe2f09c67fd5abc1c04 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 1 Aug 2022 09:12:32 +0200 Subject: [PATCH 5/8] esp_rom: convert USB related headers to SPDX, update COPYRIGHTS.rst --- .../esp_rom/include/esp32s2/rom/usb/cdc_acm.h | 36 +++--------------- .../esp32s2/rom/usb/chip_usb_dw_wrapper.h | 18 +++------ .../esp_rom/include/esp32s2/rom/usb/cpio.h | 18 +++------ .../esp_rom/include/esp32s2/rom/usb/usb_cdc.h | 4 +- .../include/esp32s2/rom/usb/usb_common.h | 37 +++---------------- .../esp_rom/include/esp32s2/rom/usb/usb_dc.h | 4 +- .../include/esp32s2/rom/usb/usb_descriptor.h | 18 +++------ .../include/esp32s2/rom/usb/usb_device.h | 31 +++------------- .../esp_rom/include/esp32s2/rom/usb/usb_dfu.h | 36 +++--------------- .../include/esp32s2/rom/usb/usb_os_glue.h | 18 +++------ .../include/esp32s2/rom/usb/usb_persist.h | 18 +++------ .../esp_rom/include/esp32s3/rom/usb/cdc_acm.h | 36 +++--------------- .../esp32s3/rom/usb/chip_usb_dw_wrapper.h | 18 +++------ .../esp_rom/include/esp32s3/rom/usb/cpio.h | 18 +++------ .../esp_rom/include/esp32s3/rom/usb/usb_cdc.h | 5 +-- .../include/esp32s3/rom/usb/usb_common.h | 37 +++---------------- .../esp_rom/include/esp32s3/rom/usb/usb_dc.h | 4 +- .../include/esp32s3/rom/usb/usb_descriptor.h | 18 +++------ .../include/esp32s3/rom/usb/usb_device.h | 31 +++------------- .../esp_rom/include/esp32s3/rom/usb/usb_dfu.h | 36 +++--------------- docs/en/COPYRIGHT.rst | 12 ++++++ tools/ci/check_copyright_config.yaml | 9 +++++ tools/ci/check_copyright_ignore.txt | 20 ---------- 23 files changed, 107 insertions(+), 375 deletions(-) diff --git a/components/esp_rom/include/esp32s2/rom/usb/cdc_acm.h b/components/esp_rom/include/esp32s2/rom/usb/cdc_acm.h index 38161d7a313..9d203c7c1ba 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/cdc_acm.h +++ b/components/esp_rom/include/esp32s2/rom/usb/cdc_acm.h @@ -1,34 +1,8 @@ -/******************************************************************************* - * - * Copyright(c) 2015,2016 Intel Corporation. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ******************************************************************************/ +/* + * SPDX-FileCopyrightText: 2015, 2016 Intel Corporation. + * + * SPDX-License-Identifier: BSD-3-Clause + */ #pragma once #include diff --git a/components/esp_rom/include/esp32s2/rom/usb/chip_usb_dw_wrapper.h b/components/esp_rom/include/esp32s2/rom/usb/chip_usb_dw_wrapper.h index a7c50643593..693412478a9 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/chip_usb_dw_wrapper.h +++ b/components/esp_rom/include/esp32s2/rom/usb/chip_usb_dw_wrapper.h @@ -1,16 +1,8 @@ -// Copyright 2019-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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include diff --git a/components/esp_rom/include/esp32s2/rom/usb/cpio.h b/components/esp_rom/include/esp32s2/rom/usb/cpio.h index 886b5080fb4..ca0912e45b9 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/cpio.h +++ b/components/esp_rom/include/esp32s2/rom/usb/cpio.h @@ -1,16 +1,8 @@ -// Copyright 2015-2016 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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /** diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_cdc.h b/components/esp_rom/include/esp32s2/rom/usb/usb_cdc.h index c241bcfe065..26c773ec726 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_cdc.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_cdc.h @@ -1,7 +1,5 @@ -/* usb_cdc.h - USB CDC-ACM and CDC-ECM public header */ - /* - * Copyright (c) 2017 PHYTEC Messtechnik GmbH + * SPDX-FileCopyrightText: 2017 PHYTEC Messtechnik GmbH * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_common.h b/components/esp_rom/include/esp32s2/rom/usb/usb_common.h index 796a77bc000..7105750d71d 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_common.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_common.h @@ -1,36 +1,9 @@ -/*************************************************************************** +/* + * SPDX-FileCopyrightText: 2015,2016 Intel Corporation + * SPDX-FileContributor: 2017 PHYTEC Messtechnik GmbH * - * - * Copyright(c) 2015,2016 Intel Corporation. - * Copyright(c) 2017 PHYTEC Messtechnik GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ***************************************************************************/ + * SPDX-License-Identifier: BSD-3-Clause + */ /** * @file diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_dc.h b/components/esp_rom/include/esp32s2/rom/usb/usb_dc.h index acfbf34952e..5587cc22ba8 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_dc.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_dc.h @@ -1,7 +1,5 @@ -/* usb_dc.h - USB device controller driver interface */ - /* - * Copyright (c) 2016 Intel Corporation. + * SPDX-FileCopyrightText: 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_descriptor.h b/components/esp_rom/include/esp32s2/rom/usb/usb_descriptor.h index 1b20ef80f0c..3ac62afa06d 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_descriptor.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_descriptor.h @@ -1,16 +1,8 @@ -// Copyright 2019-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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_device.h b/components/esp_rom/include/esp32s2/rom/usb/usb_device.h index e5103c143a9..87dbcda15b2 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_device.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_device.h @@ -1,29 +1,10 @@ /* - * LPCUSB, an USB device driver for LPC microcontrollers - * Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) - * Copyright (c) 2016 Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * SPDX-FileCopyrightText: 2006 Bertrik Sikken (bertrik@sikken.nl) + * SPDX-FileContributor: 2016 Intel Corporation + * + * SPDX-License-Identifier: BSD-3-Clause + * + * LPCUSB, an USB device driver for LPC microcontrollers */ /** diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_dfu.h b/components/esp_rom/include/esp32s2/rom/usb/usb_dfu.h index dec7ea93a39..442546d2f0f 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_dfu.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_dfu.h @@ -1,35 +1,9 @@ -/*************************************************************************** - * - * Copyright(c) 2015,2016 Intel Corporation. - * Copyright(c) 2017 PHYTEC Messtechnik GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * SPDX-FileCopyrightText: 2015,2016 Intel Corporation + * SPDX-FileContributor: 2017 PHYTEC Messtechnik GmbH * - ***************************************************************************/ + * SPDX-License-Identifier: BSD-3-Clause + */ /** * @file diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_os_glue.h b/components/esp_rom/include/esp32s2/rom/usb/usb_os_glue.h index 74d9b2a778e..4989b00ec57 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_os_glue.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_os_glue.h @@ -1,16 +1,8 @@ -// Copyright 2019-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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once diff --git a/components/esp_rom/include/esp32s2/rom/usb/usb_persist.h b/components/esp_rom/include/esp32s2/rom/usb/usb_persist.h index bcf11b7c48c..c45c8b49e2b 100644 --- a/components/esp_rom/include/esp32s2/rom/usb/usb_persist.h +++ b/components/esp_rom/include/esp32s2/rom/usb/usb_persist.h @@ -1,16 +1,8 @@ -// Copyright 2019-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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once diff --git a/components/esp_rom/include/esp32s3/rom/usb/cdc_acm.h b/components/esp_rom/include/esp32s3/rom/usb/cdc_acm.h index 04e313d8584..8e4b606bf7d 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/cdc_acm.h +++ b/components/esp_rom/include/esp32s3/rom/usb/cdc_acm.h @@ -1,34 +1,8 @@ -/******************************************************************************* - * - * Copyright(c) 2015,2016 Intel Corporation. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ******************************************************************************/ +/* + * SPDX-FileCopyrightText: 2015, 2016 Intel Corporation. + * + * SPDX-License-Identifier: BSD-3-Clause + */ #pragma once #include diff --git a/components/esp_rom/include/esp32s3/rom/usb/chip_usb_dw_wrapper.h b/components/esp_rom/include/esp32s3/rom/usb/chip_usb_dw_wrapper.h index a7c50643593..693412478a9 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/chip_usb_dw_wrapper.h +++ b/components/esp_rom/include/esp32s3/rom/usb/chip_usb_dw_wrapper.h @@ -1,16 +1,8 @@ -// Copyright 2019-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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once #include diff --git a/components/esp_rom/include/esp32s3/rom/usb/cpio.h b/components/esp_rom/include/esp32s3/rom/usb/cpio.h index 886b5080fb4..ca0912e45b9 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/cpio.h +++ b/components/esp_rom/include/esp32s3/rom/usb/cpio.h @@ -1,16 +1,8 @@ -// Copyright 2015-2016 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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /** diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_cdc.h b/components/esp_rom/include/esp32s3/rom/usb/usb_cdc.h index c241bcfe065..f62684f5855 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_cdc.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_cdc.h @@ -1,12 +1,9 @@ -/* usb_cdc.h - USB CDC-ACM and CDC-ECM public header */ - /* - * Copyright (c) 2017 PHYTEC Messtechnik GmbH + * SPDX-FileCopyrightText: 2017 PHYTEC Messtechnik GmbH * * SPDX-License-Identifier: Apache-2.0 */ - /** * @file * @brief USB Communications Device Class (CDC) public header diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_common.h b/components/esp_rom/include/esp32s3/rom/usb/usb_common.h index 06ae01a93c7..dbe5c8f350c 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_common.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_common.h @@ -1,36 +1,9 @@ -/*************************************************************************** +/* + * SPDX-FileCopyrightText: 2015,2016 Intel Corporation + * SPDX-FileContributor: 2017 PHYTEC Messtechnik GmbH * - * - * Copyright(c) 2015,2016 Intel Corporation. - * Copyright(c) 2017 PHYTEC Messtechnik GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ***************************************************************************/ + * SPDX-License-Identifier: BSD-3-Clause + */ /** * @file diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_dc.h b/components/esp_rom/include/esp32s3/rom/usb/usb_dc.h index 2e74044057b..725362fa191 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_dc.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_dc.h @@ -1,7 +1,5 @@ -/* usb_dc.h - USB device controller driver interface */ - /* - * Copyright (c) 2016 Intel Corporation. + * SPDX-FileCopyrightText: 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_descriptor.h b/components/esp_rom/include/esp32s3/rom/usb/usb_descriptor.h index 1b20ef80f0c..3ac62afa06d 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_descriptor.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_descriptor.h @@ -1,16 +1,8 @@ -// Copyright 2019-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. +/* + * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_device.h b/components/esp_rom/include/esp32s3/rom/usb/usb_device.h index e5103c143a9..87dbcda15b2 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_device.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_device.h @@ -1,29 +1,10 @@ /* - * LPCUSB, an USB device driver for LPC microcontrollers - * Copyright (C) 2006 Bertrik Sikken (bertrik@sikken.nl) - * Copyright (c) 2016 Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * SPDX-FileCopyrightText: 2006 Bertrik Sikken (bertrik@sikken.nl) + * SPDX-FileContributor: 2016 Intel Corporation + * + * SPDX-License-Identifier: BSD-3-Clause + * + * LPCUSB, an USB device driver for LPC microcontrollers */ /** diff --git a/components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h b/components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h index 1cfa80d8c56..13f242d5f3b 100644 --- a/components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h +++ b/components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h @@ -1,35 +1,9 @@ -/*************************************************************************** - * - * Copyright(c) 2015,2016 Intel Corporation. - * Copyright(c) 2017 PHYTEC Messtechnik GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +/* + * SPDX-FileCopyrightText: 2015,2016 Intel Corporation + * SPDX-FileContributor: 2017 PHYTEC Messtechnik GmbH * - ***************************************************************************/ + * SPDX-License-Identifier: BSD-3-Clause + */ /** * @file diff --git a/docs/en/COPYRIGHT.rst b/docs/en/COPYRIGHT.rst index e9432cf61a9..38c14897ca3 100644 --- a/docs/en/COPYRIGHT.rst +++ b/docs/en/COPYRIGHT.rst @@ -93,6 +93,13 @@ ESP32, ESP32-S and ESP32-C Series SoCs mask ROM hardware includes binaries compi * `Mbed TLS`_ library, Copyright (C) 2006-2018 ARM Limited and licensed under Apache 2.0 License. +* Parts of Zephyr RTOS USB stack: + * `DesignWare USB device driver`_ Copyright (c) 2016 Intel Corporation and licensed under Apache 2.0 license. + * `Generic USB device driver`_ Copyright (c) 2006 Bertrik Sikken (bertrik@sikken.nl), 2016 Intel Corporation and licensed under BSD 3-clause license. + * `USB descriptors functionality`_ Copyright (c) 2017 PHYTEC Messtechnik GmbH, 2017-2018 Intel Corporation and licensed under Apache 2.0 license. + * `USB DFU class driver`_ Copyright(c) 2015-2016 Intel Corporation, 2017 PHYTEC Messtechnik GmbH and licensed under BSD 3-clause license. + * `USB CDC ACM class driver`_ Copyright(c) 2015-2016 Intel Corporation and licensed under Apache 2.0 license + Xtensa libhal MIT License ========================= @@ -168,3 +175,8 @@ Copyright (C) 2011, ChaN, all right reserved. .. _sphinx_idf_theme: https://github.com/espressif/sphinx_idf_theme .. _sphinx_rtd_theme: https://github.com/readthedocs/sphinx_rtd_theme .. _SEGGER SystemView: https://www.segger.com/downloads/systemview/ +.. _DesignWare USB device driver: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/drivers/usb/device/usb_dc_dw.c +.. _Generic USB device driver: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/subsys/usb/usb_device.c +.. _USB descriptors functionality: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/subsys/usb/usb_descriptor.c +.. _USB DFU class driver: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/subsys/usb/class/usb_dfu.c +.. _USB CDC ACM class driver: https://github.com/zephyrproject-rtos/zephyr/blob/v1.12-branch/subsys/usb/class/cdc_acm.c diff --git a/tools/ci/check_copyright_config.yaml b/tools/ci/check_copyright_config.yaml index b2822138bf7..2d4e49f4939 100644 --- a/tools/ci/check_copyright_config.yaml +++ b/tools/ci/check_copyright_config.yaml @@ -157,6 +157,15 @@ tinyusb: - Unlicense - CC0-1.0 +# Portions of the USB stack in ROM are derived from Zephyr project, +# with files licensed under a mix of Apache and BSD-3-Clause licenses. +esp_rom_usb: + include: + - 'components/esp_rom/include/*/rom/usb/' + allowed_licenses: + - Apache-2.0 + - BSD-3-Clause + protocol_examples_common_component: include: - 'examples/common_components/protocol_examples_common/' diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index fcf6ae5a272..0a9a72d4126 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -496,17 +496,6 @@ components/esp_rom/include/esp32s2/rom/libc_stubs.h components/esp_rom/include/esp32s2/rom/opi_flash.h components/esp_rom/include/esp32s2/rom/rsa_pss.h components/esp_rom/include/esp32s2/rom/sha.h -components/esp_rom/include/esp32s2/rom/usb/cdc_acm.h -components/esp_rom/include/esp32s2/rom/usb/chip_usb_dw_wrapper.h -components/esp_rom/include/esp32s2/rom/usb/cpio.h -components/esp_rom/include/esp32s2/rom/usb/usb_cdc.h -components/esp_rom/include/esp32s2/rom/usb/usb_common.h -components/esp_rom/include/esp32s2/rom/usb/usb_dc.h -components/esp_rom/include/esp32s2/rom/usb/usb_descriptor.h -components/esp_rom/include/esp32s2/rom/usb/usb_device.h -components/esp_rom/include/esp32s2/rom/usb/usb_dfu.h -components/esp_rom/include/esp32s2/rom/usb/usb_os_glue.h -components/esp_rom/include/esp32s2/rom/usb/usb_persist.h components/esp_rom/include/esp32s3/rom/bigint.h components/esp_rom/include/esp32s3/rom/crc.h components/esp_rom/include/esp32s3/rom/digital_signature.h @@ -515,15 +504,6 @@ components/esp_rom/include/esp32s3/rom/opi_flash.h components/esp_rom/include/esp32s3/rom/rsa_pss.h components/esp_rom/include/esp32s3/rom/sha.h components/esp_rom/include/esp32s3/rom/tjpgd.h -components/esp_rom/include/esp32s3/rom/usb/cdc_acm.h -components/esp_rom/include/esp32s3/rom/usb/chip_usb_dw_wrapper.h -components/esp_rom/include/esp32s3/rom/usb/cpio.h -components/esp_rom/include/esp32s3/rom/usb/usb_cdc.h -components/esp_rom/include/esp32s3/rom/usb/usb_common.h -components/esp_rom/include/esp32s3/rom/usb/usb_dc.h -components/esp_rom/include/esp32s3/rom/usb/usb_descriptor.h -components/esp_rom/include/esp32s3/rom/usb/usb_device.h -components/esp_rom/include/esp32s3/rom/usb/usb_dfu.h components/esp_rom/include/esp_rom_crc.h components/esp_rom/include/esp_rom_gpio.h components/esp_rom/include/linux/soc/reset_reasons.h From 6ec4937cec841055f7955c2f07cae3b7ec2e55fc Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 18 Jan 2022 20:50:33 +0100 Subject: [PATCH 6/8] esp_system: usb_console support for ESP32-S3 Closes https://github.com/espressif/esp-idf/issues/8879 Closes https://github.com/espressif/esp-idf/issues/8738 --- .../include/esp_private/usb_console.h | 32 ++ components/esp_system/port/CMakeLists.txt | 4 + .../port/soc/esp32s2/CMakeLists.txt | 3 - .../port/soc/esp32s3/CMakeLists.txt | 3 - .../esp_system/port/soc/esp32s3/usb_console.c | 418 ------------------ .../port/{soc/esp32s2 => }/usb_console.c | 36 +- components/esp_system/system_init_fn.txt | 2 +- 7 files changed, 61 insertions(+), 437 deletions(-) delete mode 100644 components/esp_system/port/soc/esp32s3/usb_console.c rename components/esp_system/port/{soc/esp32s2 => }/usb_console.c (92%) diff --git a/components/esp_system/include/esp_private/usb_console.h b/components/esp_system/include/esp_private/usb_console.h index 1243b1325c8..0440b016974 100644 --- a/components/esp_system/include/esp_private/usb_console.h +++ b/components/esp_system/include/esp_private/usb_console.h @@ -50,14 +50,46 @@ esp_err_t esp_usb_console_init(void); */ ssize_t esp_usb_console_write_buf(const char* buf, size_t size); +/** + * @brief Wait until all buffered USB CDC output is written + * + * @return ssize_t Number of bytes written, or -1 if the driver is not initialized + */ ssize_t esp_usb_console_flush(void); +/** + * @brief Read data from USB CDC + * + * May read less data than requested. + * + * @param buf Buffer to read data into + * @param buf_size Size of the buffer + * @return ssize_t Number of bytes written into the buffer, or -1 if the driver is not initialized + */ ssize_t esp_usb_console_read_buf(char* buf, size_t buf_size); +/** + * @brief Get the number of bytes available for reading from USB CDC + * + * @return ssize_t Number of bytes available, or -1 if the driver is not initialized + */ ssize_t esp_usb_console_available_for_read(void); +/** + * @brief Check if data can be written into USB CDC + * + * @return true if data can be written now without blocking + */ bool esp_usb_console_write_available(void); +/** + * @brief Set RX/TX callback functions to be called from ISR + * + * @param rx_cb RX callback function + * @param tx_cb TX callback function + * @param arg callback-specific context pointer + * @return ESP_OK if the callbacks were set, ESP_ERR_INVALID_STATE if the driver is not initialized + */ esp_err_t esp_usb_console_set_cb(esp_usb_console_cb_t rx_cb, esp_usb_console_cb_t tx_cb, void* arg); #ifdef __cplusplus diff --git a/components/esp_system/port/CMakeLists.txt b/components/esp_system/port/CMakeLists.txt index d14df8b8fba..3e3d88b6a79 100644 --- a/components/esp_system/port/CMakeLists.txt +++ b/components/esp_system/port/CMakeLists.txt @@ -12,6 +12,10 @@ if(CONFIG_SOC_BOD_SUPPORTED) list(APPEND srcs "brownout.c") endif() +if(CONFIG_ESP_CONSOLE_USB_CDC) + list(APPEND srcs "usb_console.c") +endif() + add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" ${srcs}) target_sources(${COMPONENT_LIB} PRIVATE ${srcs}) diff --git a/components/esp_system/port/soc/esp32s2/CMakeLists.txt b/components/esp_system/port/soc/esp32s2/CMakeLists.txt index 03b7d6659d8..2adf51698a4 100644 --- a/components/esp_system/port/soc/esp32s2/CMakeLists.txt +++ b/components/esp_system/port/soc/esp32s2/CMakeLists.txt @@ -22,9 +22,6 @@ endif() add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" ${srcs}) target_sources(${COMPONENT_LIB} PRIVATE ${srcs}) -if(CONFIG_ESP_CONSOLE_USB_CDC) - target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/usb_console.c") -endif() #ld_include_highint_hdl is added as an undefined symbol because otherwise the #linker will ignore highint_hdl.S as it has no other files depending on any diff --git a/components/esp_system/port/soc/esp32s3/CMakeLists.txt b/components/esp_system/port/soc/esp32s3/CMakeLists.txt index bb4f4f1726d..c910e6d3ea8 100644 --- a/components/esp_system/port/soc/esp32s3/CMakeLists.txt +++ b/components/esp_system/port/soc/esp32s3/CMakeLists.txt @@ -23,9 +23,6 @@ endif() add_prefix(srcs "${CMAKE_CURRENT_LIST_DIR}/" ${srcs}) target_sources(${COMPONENT_LIB} PRIVATE ${srcs}) -if(CONFIG_ESP_CONSOLE_USB_CDC) - target_sources(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/usb_console.c") -endif() #ld_include_highint_hdl is added as an undefined symbol because otherwise the #linker will ignore panic_highint_hdl.S as it has no other files depending on any diff --git a/components/esp_system/port/soc/esp32s3/usb_console.c b/components/esp_system/port/soc/esp32s3/usb_console.c deleted file mode 100644 index 31dbac2a7d5..00000000000 --- a/components/esp_system/port/soc/esp32s3/usb_console.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include -#include "sdkconfig.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "esp_system.h" -#include "esp_intr_alloc.h" -#include "esp_private/usb_console.h" -#include "soc/periph_defs.h" -#include "soc/rtc_cntl_reg.h" -#include "soc/usb_struct.h" -#include "soc/usb_reg.h" -#include "spinlock.h" -#include "hal/soc_hal.h" -#include "esp_rom_uart.h" -#include "esp_rom_sys.h" -#include "esp32s3/rom/usb/usb_dc.h" -#include "esp32s3/rom/usb/cdc_acm.h" -#include "esp32s3/rom/usb/usb_dfu.h" -#include "esp32s3/rom/usb/usb_device.h" -#include "esp32s3/rom/usb/usb_os_glue.h" -#include "esp32s3/rom/usb/usb_persist.h" -#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h" - -#define CDC_WORK_BUF_SIZE (ESP_ROM_CDC_ACM_WORK_BUF_MIN + CONFIG_ESP_CONSOLE_USB_CDC_RX_BUF_SIZE) - -typedef enum { - REBOOT_NONE, - REBOOT_NORMAL, - REBOOT_BOOTLOADER, - REBOOT_BOOTLOADER_DFU, -} reboot_type_t; - - -static reboot_type_t s_queue_reboot = REBOOT_NONE; -static int s_prev_rts_state; -static intr_handle_t s_usb_int_handle; -static cdc_acm_device *s_cdc_acm_device; -static char s_usb_tx_buf[ACM_BYTES_PER_TX]; -static size_t s_usb_tx_buf_pos; -static uint8_t cdcmem[CDC_WORK_BUF_SIZE]; -static esp_usb_console_cb_t s_rx_cb; -static esp_usb_console_cb_t s_tx_cb; -static void *s_cb_arg; - -#ifdef CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF -static portMUX_TYPE s_write_lock = portMUX_INITIALIZER_UNLOCKED; -void esp_usb_console_write_char(char c); -#define ISR_FLAG ESP_INTR_FLAG_IRAM -#else -#define ISR_FLAG 0 -#endif // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF - - -/* Optional write lock routines; used only if esp_rom_printf output via CDC is enabled */ -static inline void write_lock_acquire(void); -static inline void write_lock_release(void); - -/* The two functions below need to be revisited in the multicore case TODO ESP32-S3 IDF-2048*/ -_Static_assert(SOC_CPU_CORES_NUM == 1, "usb_osglue_*_int is not multicore capable"); - -/* Called by ROM to disable the interrupts - * Non-static to allow placement into IRAM by ldgen. - */ -void esp_usb_console_osglue_dis_int(void) -{ - if (s_usb_int_handle) { - esp_intr_disable(s_usb_int_handle); - } -} - -/* Called by ROM to enable the interrupts - * Non-static to allow placement into IRAM by ldgen. - */ -void esp_usb_console_osglue_ena_int(void) -{ - if (s_usb_int_handle) { - esp_intr_enable(s_usb_int_handle); - } -} - -/* Delay function called by ROM USB driver. - * Non-static to allow placement into IRAM by ldgen. - */ -int esp_usb_console_osglue_wait_proc(int delay_us) -{ - if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING || - !xPortCanYield()) { - esp_rom_delay_us(delay_us); - return delay_us; - } - if (delay_us == 0) { - /* We should effectively yield */ - vPortYield(); - return 1; - } else { - /* Just delay */ - int ticks = MAX(delay_us / (portTICK_PERIOD_MS * 1000), 1); - vTaskDelay(ticks); - return ticks * portTICK_PERIOD_MS * 1000; - } -} - -/* Called by ROM CDC ACM driver from interrupt context./ - * Non-static to allow placement into IRAM by ldgen. - */ -void esp_usb_console_cdc_acm_cb(cdc_acm_device *dev, int status) -{ - if (status == USB_DC_RESET || status == USB_DC_CONNECTED) { - s_prev_rts_state = 0; - } else if (status == ACM_STATUS_LINESTATE_CHANGED) { - uint32_t rts, dtr; - cdc_acm_line_ctrl_get(dev, LINE_CTRL_RTS, &rts); - cdc_acm_line_ctrl_get(dev, LINE_CTRL_DTR, &dtr); - if (!rts && s_prev_rts_state) { - if (dtr) { - s_queue_reboot = REBOOT_BOOTLOADER; - } else { - s_queue_reboot = REBOOT_NORMAL; - } - } - s_prev_rts_state = rts; - } else if (status == ACM_STATUS_RX && s_rx_cb) { - (*s_rx_cb)(s_cb_arg); - } else if (status == ACM_STATUS_TX && s_tx_cb) { - (*s_tx_cb)(s_cb_arg); - } -} - -/* Non-static to allow placement into IRAM by ldgen. */ -void esp_usb_console_dfu_detach_cb(int timeout) -{ - s_queue_reboot = REBOOT_BOOTLOADER_DFU; -} - -/* USB interrupt handler, forward the call to the ROM driver. - * Non-static to allow placement into IRAM by ldgen. - */ -void esp_usb_console_interrupt(void *arg) -{ - usb_dc_check_poll_for_interrupts(); - /* Restart can be requested from esp_usb_console_cdc_acm_cb or esp_usb_console_dfu_detach_cb */ - if (s_queue_reboot != REBOOT_NONE) { - esp_restart(); - } -} - -/* Call the USB interrupt handler while any interrupts are pending, - * but not more than a few times. - * Non-static to allow placement into IRAM by ldgen. - */ -void esp_usb_console_poll_interrupts(void) -{ - const int max_poll_count = 10; - for (int i = 0; (USB0.gintsts & USB0.gintmsk) != 0 && i < max_poll_count; i++) { - usb_dc_check_poll_for_interrupts(); - } -} - -/* This function gets registered as a restart handler. - * Prepares USB peripheral for restart and sets up persistence. - * Non-static to allow placement into IRAM by ldgen. - */ -void esp_usb_console_before_restart(void) -{ - esp_usb_console_poll_interrupts(); - usb_dc_prepare_persist(); - if (s_queue_reboot == REBOOT_BOOTLOADER) { - chip_usb_set_persist_flags(USBDC_PERSIST_ENA); - REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); - } else if (s_queue_reboot == REBOOT_BOOTLOADER_DFU) { - chip_usb_set_persist_flags(USBDC_BOOT_DFU); - REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT); - } else { - chip_usb_set_persist_flags(USBDC_PERSIST_ENA); - esp_usb_console_poll_interrupts(); - } -} - -/* Reset some static state in ROM, which survives when going from the - * 2nd stage bootloader into the app. This cleans some variables which - * indicates that the driver is already initialized, allowing us to - * initialize it again, in the app. - */ -static void esp_usb_console_rom_cleanup(void) -{ - /* TODO ESP32-S3 IDF-2987 */ - // extern char rom_usb_dev, rom_usb_dev_end; - // extern char rom_usb_dw_ctrl, rom_usb_dw_ctrl_end; - - // uart_acm_dev = NULL; - // memset((void *) &rom_usb_dev, 0, &rom_usb_dev_end - &rom_usb_dev); - // memset((void *) &rom_usb_dw_ctrl, 0, &rom_usb_dw_ctrl_end - &rom_usb_dw_ctrl); -} - -esp_err_t esp_usb_console_init(void) -{ - esp_err_t err; - err = esp_register_shutdown_handler(esp_usb_console_before_restart); - if (err != ESP_OK) { - return err; - } - - esp_usb_console_rom_cleanup(); - - /* Install OS hooks */ - s_usb_osglue.int_dis_proc = esp_usb_console_osglue_dis_int; - s_usb_osglue.int_ena_proc = esp_usb_console_osglue_ena_int; - s_usb_osglue.wait_proc = esp_usb_console_osglue_wait_proc; - - /* Install interrupt. - * In case of ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF: - * Note that this the interrupt handler has to be placed into IRAM because - * the interrupt handler can also be called in polling mode, when - * interrupts are disabled, and a write to USB is performed with cache disabled. - * Since the handler function is in IRAM, we can register the interrupt as IRAM capable. - * It is not because we actually need the interrupt to work with cache disabled! - */ - err = esp_intr_alloc(ETS_USB_INTR_SOURCE, ISR_FLAG | ESP_INTR_FLAG_INTRDISABLED, - esp_usb_console_interrupt, NULL, &s_usb_int_handle); - if (err != ESP_OK) { - esp_unregister_shutdown_handler(esp_usb_console_before_restart); - return err; - } - - /* Initialize USB / CDC */ - s_cdc_acm_device = cdc_acm_init(cdcmem, CDC_WORK_BUF_SIZE); - usb_dc_check_poll_for_interrupts(); - - /* Set callback for handling DTR/RTS lines and TX/RX events */ - cdc_acm_irq_callback_set(s_cdc_acm_device, esp_usb_console_cdc_acm_cb); - cdc_acm_irq_state_enable(s_cdc_acm_device); - - /* Set callback for handling DFU detach */ - usb_dfu_set_detach_cb(esp_usb_console_dfu_detach_cb); - - /* Enable interrupts on USB peripheral side */ - USB0.gahbcfg |= USB_GLBLLNTRMSK_M; - - /* Enable the interrupt handler */ - esp_intr_enable(s_usb_int_handle); - -#ifdef CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF - /* Install esp_rom_printf handler */ - ets_install_putc1(&esp_usb_console_write_char); -#endif // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF - - return ESP_OK; -} - -/* Non-static to allow placement into IRAM by ldgen. - * Must be called with the write lock held. - */ -ssize_t esp_usb_console_flush_internal(size_t last_write_size) -{ - if (s_usb_tx_buf_pos == 0) { - return 0; - } - assert(s_usb_tx_buf_pos >= last_write_size); - ssize_t ret; - size_t tx_buf_pos_before = s_usb_tx_buf_pos - last_write_size; - int sent = cdc_acm_fifo_fill(s_cdc_acm_device, (const uint8_t*) s_usb_tx_buf, s_usb_tx_buf_pos); - if (sent == last_write_size) { - /* everything was sent */ - ret = last_write_size; - s_usb_tx_buf_pos = 0; - } else if (sent == 0) { - /* nothing was sent, roll back to the original state */ - ret = 0; - s_usb_tx_buf_pos = tx_buf_pos_before; - } else { - /* Some data was sent, but not all of the buffer. - * We can still tell the caller that all the new data - * was "sent" since it is in the buffer now. - */ - ret = last_write_size; - memmove(s_usb_tx_buf, s_usb_tx_buf + sent, s_usb_tx_buf_pos - sent); - s_usb_tx_buf_pos = s_usb_tx_buf_pos - sent; - } - return ret; -} - -ssize_t esp_usb_console_flush(void) -{ - if (s_cdc_acm_device == NULL) { - return -1; - } - write_lock_acquire(); - int ret = esp_usb_console_flush_internal(0); - write_lock_release(); - return ret; -} - -ssize_t esp_usb_console_write_buf(const char* buf, size_t size) -{ - if (s_cdc_acm_device == NULL) { - return -1; - } - if (size == 0) { - return 0; - } - write_lock_acquire(); - ssize_t tx_buf_available = ACM_BYTES_PER_TX - s_usb_tx_buf_pos; - ssize_t will_write = MIN(size, tx_buf_available); - memcpy(s_usb_tx_buf + s_usb_tx_buf_pos, buf, will_write); - s_usb_tx_buf_pos += will_write; - - ssize_t ret; - if (s_usb_tx_buf_pos == ACM_BYTES_PER_TX || buf[size - 1] == '\n') { - /* Buffer is full, or a newline is found. - * For binary streams, we probably shouldn't do line buffering, - * but text streams are likely going to be the most common case. - */ - ret = esp_usb_console_flush_internal(will_write); - } else { - /* nothing sent out yet, but all the new data is in the buffer now */ - ret = will_write; - } - write_lock_release(); - return ret; -} - -ssize_t esp_usb_console_read_buf(char *buf, size_t buf_size) -{ - if (s_cdc_acm_device == NULL) { - return -1; - } - if (!esp_usb_console_read_available()) { - return 0; - } - int bytes_read = cdc_acm_fifo_read(s_cdc_acm_device, (uint8_t*) buf, buf_size); - return bytes_read; -} - -esp_err_t esp_usb_console_set_cb(esp_usb_console_cb_t rx_cb, esp_usb_console_cb_t tx_cb, void *arg) -{ - if (s_cdc_acm_device == NULL) { - return ESP_ERR_INVALID_STATE; - } - s_rx_cb = rx_cb; - if (s_rx_cb) { - cdc_acm_irq_rx_enable(s_cdc_acm_device); - } else { - cdc_acm_irq_rx_disable(s_cdc_acm_device); - } - s_tx_cb = tx_cb; - if (s_tx_cb) { - cdc_acm_irq_tx_enable(s_cdc_acm_device); - } else { - cdc_acm_irq_tx_disable(s_cdc_acm_device); - } - s_cb_arg = arg; - return ESP_OK; -} - -bool esp_usb_console_read_available(void) -{ - if (s_cdc_acm_device == NULL) { - return false; - } - return cdc_acm_rx_fifo_cnt(s_cdc_acm_device) > 0; -} - -bool esp_usb_console_write_available(void) -{ - if (s_cdc_acm_device == NULL) { - return false; - } - return cdc_acm_irq_tx_ready(s_cdc_acm_device) != 0; -} - - -#ifdef CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF -/* Used as an output function by esp_rom_printf. - * The LF->CRLF replacement logic replicates the one in esp_rom_uart_putc. - * Not static to allow placement into IRAM by ldgen. - */ -void esp_usb_console_write_char(char c) -{ - char cr = '\r'; - char lf = '\n'; - - if (c == lf) { - esp_usb_console_write_buf(&cr, 1); - esp_usb_console_write_buf(&lf, 1); - } else if (c == '\r') { - } else { - esp_usb_console_write_buf(&c, 1); - } -} -static inline void write_lock_acquire(void) -{ - portENTER_CRITICAL_SAFE(&s_write_lock); -} -static inline void write_lock_release(void) -{ - portEXIT_CRITICAL_SAFE(&s_write_lock); -} - -#else // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF - -static inline void write_lock_acquire(void) -{ -} - -static inline void write_lock_release(void) -{ -} -#endif // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF diff --git a/components/esp_system/port/soc/esp32s2/usb_console.c b/components/esp_system/port/usb_console.c similarity index 92% rename from components/esp_system/port/soc/esp32s2/usb_console.c rename to components/esp_system/port/usb_console.c index c1875c2a446..7e5dc5b7a7a 100644 --- a/components/esp_system/port/soc/esp32s2/usb_console.c +++ b/components/esp_system/port/usb_console.c @@ -28,6 +28,7 @@ #include "esp_rom_uart.h" #include "esp_rom_sys.h" #include "esp_rom_caps.h" +#ifdef CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/rom/usb/usb_dc.h" #include "esp32s2/rom/usb/cdc_acm.h" #include "esp32s2/rom/usb/usb_dfu.h" @@ -35,7 +36,15 @@ #include "esp32s2/rom/usb/usb_os_glue.h" #include "esp32s2/rom/usb/usb_persist.h" #include "esp32s2/rom/usb/chip_usb_dw_wrapper.h" - +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/rom/usb/usb_dc.h" +#include "esp32s3/rom/usb/cdc_acm.h" +#include "esp32s3/rom/usb/usb_dfu.h" +#include "esp32s3/rom/usb/usb_device.h" +#include "esp32s3/rom/usb/usb_os_glue.h" +#include "esp32s3/rom/usb/usb_persist.h" +#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h" +#endif #define CDC_WORK_BUF_SIZE (ESP_ROM_CDC_ACM_WORK_BUF_MIN + CONFIG_ESP_CONSOLE_USB_CDC_RX_BUF_SIZE) @@ -61,8 +70,17 @@ static esp_timer_handle_t s_restart_timer; static const char* TAG = "usb_console"; +/* This lock is used for two purposes: + * - To protect functions which write something to USB, e.g. esp_usb_console_write_buf. + * This is necessary since these functions may be called by esp_rom_printf, so the calls + * may preempt each other or happen concurrently. + * (The calls coming from regular 'printf', i.e. via VFS layer, are already protected + * by a mutex in the VFS driver.) + * - To implement "osglue" functions of the USB stack. These normally require interrupts + * to be disabled. However on multi-core chips a critical section is necessary. + */ +static portMUX_TYPE s_lock = portMUX_INITIALIZER_UNLOCKED; #ifdef CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF -static portMUX_TYPE s_write_lock = portMUX_INITIALIZER_UNLOCKED; void esp_usb_console_write_char(char c); #define ISR_FLAG ESP_INTR_FLAG_IRAM #else @@ -74,8 +92,6 @@ void esp_usb_console_write_char(char c); static inline void write_lock_acquire(void); static inline void write_lock_release(void); -/* The two functions below need to be revisited in the multicore case */ -_Static_assert(SOC_CPU_CORES_NUM == 1, "usb_osglue_*_int is not multicore capable"); /* Other forward declarations */ void esp_usb_console_before_restart(void); @@ -85,9 +101,7 @@ void esp_usb_console_before_restart(void); */ void esp_usb_console_osglue_dis_int(void) { - if (s_usb_int_handle) { - esp_intr_disable(s_usb_int_handle); - } + portENTER_CRITICAL_SAFE(&s_lock); } /* Called by ROM to enable the interrupts @@ -95,9 +109,7 @@ void esp_usb_console_osglue_dis_int(void) */ void esp_usb_console_osglue_ena_int(void) { - if (s_usb_int_handle) { - esp_intr_enable(s_usb_int_handle); - } + portEXIT_CRITICAL_SAFE(&s_lock); } /* Delay function called by ROM USB driver. @@ -450,11 +462,11 @@ void esp_usb_console_write_char(char c) } static inline void write_lock_acquire(void) { - portENTER_CRITICAL_SAFE(&s_write_lock); + portENTER_CRITICAL_SAFE(&s_lock); } static inline void write_lock_release(void) { - portEXIT_CRITICAL_SAFE(&s_write_lock); + portEXIT_CRITICAL_SAFE(&s_lock); } #else // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF diff --git a/components/esp_system/system_init_fn.txt b/components/esp_system/system_init_fn.txt index 93c6687425b..0818eedf845 100644 --- a/components/esp_system/system_init_fn.txt +++ b/components/esp_system/system_init_fn.txt @@ -31,7 +31,7 @@ # usb_console needs to create an esp_timer at startup. # This can be done only after esp_timer initialization, which is now in init_components0. -220: esp_usb_console_init_restart_timer in components/esp_system/port/soc/esp32s2/usb_console.c on BIT(0) +220: esp_usb_console_init_restart_timer in components/esp_system/port/usb_console.c on BIT(0) # usb_serial_jtag needs to create and acquire a PM clock at startup. # This makes more sense to be done after esp_pm_impl_init, which is initialized in init_components0. From e2f1327a5c62262c2f64f94fb9011b45920e158f Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 1 Aug 2022 08:15:08 +0200 Subject: [PATCH 7/8] examples: re-enable system/console/advanced_usb_cdc for ESP32-S3 Closes https://github.com/espressif/esp-idf/issues/9364 --- examples/system/.build-test-rules.yml | 6 ++---- examples/system/console/advanced_usb_cdc/README.md | 12 ++++++++---- .../console/advanced_usb_cdc/sdkconfig.defaults | 3 --- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/system/.build-test-rules.yml b/examples/system/.build-test-rules.yml index 7a70c429485..dd8e63da37a 100644 --- a/examples/system/.build-test-rules.yml +++ b/examples/system/.build-test-rules.yml @@ -17,10 +17,8 @@ examples/system/console/advanced: reason: lack of runners examples/system/console/advanced_usb_cdc: - enable: - - if: IDF_TARGET == "esp32s2" - temporary: true - reason: the other targets are not tested yet + disable: + - if: SOC_USB_PERIPH_NUM == 0 examples/system/console/basic: disable: diff --git a/examples/system/console/advanced_usb_cdc/README.md b/examples/system/console/advanced_usb_cdc/README.md index d2b69b50b11..9245a851936 100644 --- a/examples/system/console/advanced_usb_cdc/README.md +++ b/examples/system/console/advanced_usb_cdc/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32-S2 | -| ----------------- | -------- | +| Supported Targets | ESP32-S2 | ESP32-S3 | +| ----------------- | -------- | -------- | # USB_OTG CDC Console Example @@ -14,7 +14,11 @@ The interactive shell implemented in this example contains a wide variety of com ### Hardware Required -This example can run on an ESP32-S2 development board, with a USB cable connected to GPIO19 and GPIO20. +This example can run on an ESP32-S2 or ESP32-S3 development board with USB port attached to the built-in USB_OTG controller. + +For more details about connecting and configuring USB_OTG (including pin numbers), see the IDF Programming Guide: +* [ESP32-S2 USB_OTG](https://docs.espressif.com/projects/esp-idf/en/stable/esp32s2/api-guides/usb-otg-console.html) +* [ESP32-S3 USB_OTG](https://docs.espressif.com/projects/esp-idf/en/stable/esp32s3/api-guides/usb-otg-console.html) ### Build and Flash @@ -36,7 +40,7 @@ idf.py -p PORT flash #### Flashing the project for the first time using USB -We can also use the ESP32-S2 built-in USB bootloader to flash the program for the first time. +We can also use the built-in USB bootloader in the ESP chip to flash the program for the first time. 1. Connect the development board using a USB breakout cable to the computer. 2. Put the chip into bootloader (download) mode, by holding "Boot" button (connected to GPIO0) and pressing "Reset" button. diff --git a/examples/system/console/advanced_usb_cdc/sdkconfig.defaults b/examples/system/console/advanced_usb_cdc/sdkconfig.defaults index d87eb3e60ba..4cc7e875b00 100644 --- a/examples/system/console/advanced_usb_cdc/sdkconfig.defaults +++ b/examples/system/console/advanced_usb_cdc/sdkconfig.defaults @@ -1,6 +1,3 @@ -# Build for ESP32-S2 by default -CONFIG_IDF_TARGET="esp32s2" - # Enable USB console CONFIG_ESP_CONSOLE_USB_CDC=y From 6481b0161cc21e2895b9270ceaf14d909422c5fe Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 3 Jan 2023 15:39:31 +0100 Subject: [PATCH 8/8] ci: add build test for CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF --- .../system/build_test/sdkconfig.ci.usb_console_ets_printf | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tools/test_apps/system/build_test/sdkconfig.ci.usb_console_ets_printf diff --git a/tools/test_apps/system/build_test/sdkconfig.ci.usb_console_ets_printf b/tools/test_apps/system/build_test/sdkconfig.ci.usb_console_ets_printf new file mode 100644 index 00000000000..52aabffb986 --- /dev/null +++ b/tools/test_apps/system/build_test/sdkconfig.ci.usb_console_ets_printf @@ -0,0 +1,3 @@ +CONFIG_IDF_TARGET="esp32s3" +CONFIG_ESP_CONSOLE_USB_CDC=y +CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF=y