mirror of
https://github.com/espressif/esptool.git
synced 2025-10-15 12:37:18 +08:00
feat(flasher_stub): Increase CPU frequency and write/read speeds over native USB (USB-OTG)
This commit is contained in:

committed by
Radim Karniš

parent
dccf4dff0a
commit
52278a9c69
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -45,7 +45,8 @@
|
||||
#define WITH_USB_OTG 1
|
||||
#endif // ESP32S3
|
||||
|
||||
#define USE_MAX_CPU_FREQ WITH_USB_JTAG_SERIAL // Increase CPU freq only when USB-JTAG/Serial is used
|
||||
// Increase CPU freq to speed up read/write operations over USB
|
||||
#define USE_MAX_CPU_FREQ (WITH_USB_JTAG_SERIAL || WITH_USB_OTG)
|
||||
|
||||
/**********************************************************
|
||||
* Per-SOC based peripheral register base addresses
|
||||
@@ -69,6 +70,7 @@
|
||||
#define GPIO_BASE_REG 0x3f404000
|
||||
#define USB_BASE_REG 0x60080000
|
||||
#define RTCCNTL_BASE_REG 0x3f408000
|
||||
#define SYSTEM_BASE_REG 0x3F4C0000
|
||||
#endif
|
||||
|
||||
#ifdef ESP32S3
|
||||
@@ -319,6 +321,20 @@
|
||||
#define SYSTEM_SOC_CLK_MAX 1
|
||||
#endif // ESP32C3
|
||||
|
||||
#ifdef ESP32S2
|
||||
#define SYSTEM_CPU_PER_CONF_REG (SYSTEM_BASE_REG + 0x018)
|
||||
#define SYSTEM_CPUPERIOD_SEL_M ((SYSTEM_CPUPERIOD_SEL_V)<<(SYSTEM_CPUPERIOD_SEL_S))
|
||||
#define SYSTEM_CPUPERIOD_SEL_V 0x3
|
||||
#define SYSTEM_CPUPERIOD_SEL_S 0
|
||||
#define SYSTEM_CPUPERIOD_MAX 2 // CPU_CLK frequency is 240 MHz
|
||||
|
||||
#define SYSTEM_SYSCLK_CONF_REG (SYSTEM_BASE_REG + 0x08C)
|
||||
#define SYSTEM_SOC_CLK_SEL_M ((SYSTEM_SOC_CLK_SEL_V)<<(SYSTEM_SOC_CLK_SEL_S))
|
||||
#define SYSTEM_SOC_CLK_SEL_V 0x3
|
||||
#define SYSTEM_SOC_CLK_SEL_S 10
|
||||
#define SYSTEM_SOC_CLK_MAX 1
|
||||
#endif // ESP32S2
|
||||
|
||||
/**********************************************************
|
||||
* Per-SOC security info buffer size
|
||||
*/
|
||||
|
@@ -54,3 +54,9 @@ void stub_io_idle_hook(void);
|
||||
#if WITH_USB_JTAG_SERIAL
|
||||
bool stub_uses_usb_jtag_serial(void);
|
||||
#endif
|
||||
|
||||
/* Checks if USB-OTG is being currently used.
|
||||
*/
|
||||
#if WITH_USB_OTG
|
||||
bool stub_uses_usb_otg(void);
|
||||
#endif
|
||||
|
@@ -49,12 +49,26 @@ static uint8_t calculate_checksum(uint8_t *buf, int length)
|
||||
}
|
||||
|
||||
#if USE_MAX_CPU_FREQ
|
||||
static bool can_use_max_cpu_freq()
|
||||
{
|
||||
/* Check if any of available USB modes are being used. */
|
||||
#if WITH_USB_OTG && !WITH_USB_JTAG_SERIAL
|
||||
return stub_uses_usb_otg();
|
||||
#elif !WITH_USB_OTG && WITH_USB_JTAG_SERIAL
|
||||
return stub_uses_usb_jtag_serial();
|
||||
#elif WITH_USB_OTG && WITH_USB_JTAG_SERIAL
|
||||
return stub_uses_usb_otg() || stub_uses_usb_jtag_serial();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t cpu_per_conf_reg = 0;
|
||||
static uint32_t sysclk_conf_reg = 0;
|
||||
|
||||
static void set_max_cpu_freq()
|
||||
{
|
||||
if (stub_uses_usb_jtag_serial())
|
||||
if (can_use_max_cpu_freq())
|
||||
{
|
||||
/* Set CPU frequency to max. This also increases SPI speed. */
|
||||
cpu_per_conf_reg = READ_REG(SYSTEM_CPU_PER_CONF_REG);
|
||||
@@ -68,7 +82,7 @@ static void reset_cpu_freq()
|
||||
{
|
||||
/* Restore saved sysclk_conf and cpu_per_conf registers.
|
||||
Use only if set_max_cpu_freq() has been called. */
|
||||
if (stub_uses_usb_jtag_serial() && sysclk_conf_reg != 0 && cpu_per_conf_reg != 0)
|
||||
if (can_use_max_cpu_freq() && sysclk_conf_reg != 0 && cpu_per_conf_reg != 0)
|
||||
{
|
||||
WRITE_REG(SYSTEM_CPU_PER_CONF_REG, (READ_REG(SYSTEM_CPU_PER_CONF_REG) & ~SYSTEM_CPUPERIOD_SEL_M) | (cpu_per_conf_reg & SYSTEM_CPUPERIOD_SEL_M));
|
||||
WRITE_REG(SYSTEM_SYSCLK_CONF_REG, (READ_REG(SYSTEM_SYSCLK_CONF_REG) & ~SYSTEM_SOC_CLK_SEL_M) | (sysclk_conf_reg & SYSTEM_SOC_CLK_SEL_M));
|
||||
@@ -444,8 +458,10 @@ void stub_main()
|
||||
cmd_loop();
|
||||
|
||||
/* if cmd_loop returns, it's due to ESP_RUN_USER_CODE command. */
|
||||
|
||||
#if USE_MAX_CPU_FREQ
|
||||
reset_cpu_freq();
|
||||
#endif // USE_MAX_CPU_FREQ
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -116,7 +116,7 @@ static void stub_cdcacm_write_char(char ch)
|
||||
}
|
||||
}
|
||||
|
||||
static bool stub_uses_usb_otg(void)
|
||||
bool stub_uses_usb_otg(void)
|
||||
{
|
||||
UartDevice *uart = GetUartDevice();
|
||||
|
||||
|
Reference in New Issue
Block a user