1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

cpu/esp32: add esp-bootloader-reset

This commit is contained in:
Benjamin Valentin 2023-01-06 01:37:28 +01:00
parent 12a05b8fa2
commit 7607b9c0f5
5 changed files with 81 additions and 0 deletions

View File

@ -30,6 +30,7 @@ config CPU_FAM_ESP32S2
select MODULE_PTHREAD if MODULE_CPP
select MODULE_RTT_RTC if HAS_PERIPH_RTT && MODULE_PERIPH_RTC
select MODULE_USBDEV_SYNOPSYS_DWC2 if MODULE_PERIPH_USBDEV
select MODULE_USB_BOARD_RESET if MODULE_USBUS_CDC_ACM || MODULE_TINYUSB_CLASS_CDC
imply MODULE_NEWLIB_NANO
config CPU_FAM

View File

@ -37,6 +37,7 @@ config CPU_FAM_ESP32S3
select MODULE_PTHREAD if MODULE_CPP
select MODULE_RTT_RTC if HAS_PERIPH_RTT && MODULE_PERIPH_RTC
select MODULE_USBDEV_SYNOPSYS_DWC2 if MODULE_PERIPH_USBDEV
select MODULE_USB_BOARD_RESET if MODULE_USBUS_CDC_ACM || MODULE_TINYUSB_CLASS_CDC
imply MODULE_NEWLIB_NANO
config CPU_FAM

View File

@ -13,6 +13,10 @@ ifneq (, $(filter esp_bootloader, $(USEMODULE)))
DIRS += bootloader
endif
ifneq (, $(filter usb_board_reset, $(USEMODULE)))
SRC += usb_reset.c
endif
ifneq (, $(filter esp_ble_nimble, $(USEMODULE)))
DIRS += esp-ble-nimble
endif

View File

@ -184,3 +184,10 @@ endif
ifneq (,$(filter esp_jtag,$(USEMODULE)))
FEATURES_REQUIRED += esp_jtag
endif
# enable bootloader reset over USB, requires CDC ACM to be used
ifneq (,$(filter usbus_cdc_acm tinyusb_class_cdc,$(USEMODULE)))
USEMODULE += usb_board_reset
include $(RIOTMAKE)/tools/usb_board_reset.mk
endif

68
cpu/esp32/usb_reset.c Normal file
View File

@ -0,0 +1,68 @@
/*
* Copyright (C) 2023 Benjamin Valentin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup cpu_esp32
* @{
*
* @file
* @brief Trigger reset to the bootloader stored in the internal boot ROM
* memory.
*
* This will start the USB/UART bootloader.
*
* @author Benjamin Valentin <benpicco@googlemail.com>
* @author Gunar Schorcht <gunar@schorcht.net>
*
* @}
*/
#include "driver/periph_ctrl.h"
#include "rom/usb/chip_usb_dw_wrapper.h"
#include "rom/usb/usb_persist.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/rtc_cntl_struct.h"
#include "soc/soc_caps.h"
#if SOC_USB_SERIAL_JTAG_SUPPORTED
#include "soc/usb_serial_jtag_reg.h"
#include "soc/usb_serial_jtag_struct.h"
#endif
#include "periph/pm.h"
static void _reconfigure_usb(void)
{
#ifdef CPU_FAM_ESP32S3
/* disable USB OTG controller */
periph_module_reset(PERIPH_USB_MODULE);
periph_module_disable(PERIPH_USB_MODULE);
/* allow USB Serial/JTAG to use the internal USB transceiver */
RTCCNTL.usb_conf.sw_usb_phy_sel = 0;
/* control the internal USB transceiver selection via hardware (efuse) */
RTCCNTL.usb_conf.sw_hw_usb_phy_sel = 0;
/* don't enable USB transceiver function */
RTCCNTL.usb_conf.usb_pad_enable = 0;
/* select internal PHY for USB Serial/JTAG */
USB_SERIAL_JTAG.conf0.phy_sel = 0;
/* enable USB pad function */
USB_SERIAL_JTAG.conf0.usb_pad_enable = 1;
#endif
}
void __attribute__((weak)) usb_board_reset_in_bootloader(void)
{
/* If we are here, the USB port is not connected to the Serial/JTAG interface.
We have to re-configure it back to this mode first. */
_reconfigure_usb();
chip_usb_set_persist_flags(USBDC_PERSIST_ENA);
REG_WRITE(RTC_CNTL_OPTION1_REG, RTC_CNTL_FORCE_DOWNLOAD_BOOT);
pm_reboot();
}