From 9d3f7efb40e10992220783afff36e2bf06f9f97e Mon Sep 17 00:00:00 2001 From: windowsair Date: Sat, 29 Oct 2022 13:59:24 +0800 Subject: [PATCH] fix(dap): fix the debug clok of esp32/esp32c3 at low speed --- README.md | 2 ++ components/DAP/source/DAP.c | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c173e43..4cd9f49 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,8 @@ python ./idf.py -p /dev/ttyS5 flash The following example shows a possible way to build: ```bash +# Set build target +idf.py set-target esp32 # Build idf.py build # Flash diff --git a/components/DAP/source/DAP.c b/components/DAP/source/DAP.c index 8feaf7a..a6daaee 100644 --- a/components/DAP/source/DAP.c +++ b/components/DAP/source/DAP.c @@ -412,10 +412,16 @@ static uint32_t DAP_SWJ_Clock(const uint8_t *request, uint8_t *response) { DAP_Data.fast_clock = 0U; SWD_TransferSpeed = kTransfer_GPIO_normal; - ////FIXME: esp32 - #define CPU_CLOCK_FIXED 80000000 - delay = ((CPU_CLOCK_FIXED/2U) + (clock - 1U)) / clock; +#ifdef CONFIG_IDF_TARGET_ESP8266 + #define BUS_CLOCK_FIXED 80000000 +#elif defined CONFIG_IDF_TARGET_ESP32 + #define BUS_CLOCK_FIXED 100000000 +#elif defined CONFIG_IDF_TARGET_ESP32C3 + #define BUS_CLOCK_FIXED 80000000 +#endif + + delay = ((BUS_CLOCK_FIXED/2U) + (clock - 1U)) / clock; if (delay > IO_PORT_WRITE_CYCLES) { delay -= IO_PORT_WRITE_CYCLES; delay = (delay + (DELAY_SLOW_CYCLES - 1U)) / DELAY_SLOW_CYCLES;