Skip to content

Commit

Permalink
esp_rom: implement usb deinit functions added in S3 ROM for S2
Browse files Browse the repository at this point in the history
This cleans up usb_console.c and prepares it for S3 support.
  • Loading branch information
igrr committed Nov 21, 2023
1 parent 228dbe1 commit 6d1f573
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/esp_rom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 2 additions & 5 deletions components/esp_system/port/soc/esp32s2/usb_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6d1f573

Please sign in to comment.