From 2e0d8f14012a6c4d6fdb21405c429bb8913fd15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Wed, 3 Dec 2025 23:59:05 +0100 Subject: [PATCH] Fix SWD, output couldn't be disabled in dedic_gpio The SWDIO output was never disabled, and this caused all readings to be wrong. This seems related to ESP32-S2 and S3 SOC_DEDIC_GPIO_OUT_AUTO_ENABLE. I change to use dedic_gpio only for input, and then I drive the output the usual gpio_ll_set_level way. This makes openocd finally work for me; debugging an nrf52 target. --- components/debug_probe/debug_gpio.c | 2 +- components/debug_probe/debug_gpio.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/debug_probe/debug_gpio.c b/components/debug_probe/debug_gpio.c index 59c1ff6..8a77472 100644 --- a/components/debug_probe/debug_gpio.c +++ b/components/debug_probe/debug_gpio.c @@ -106,7 +106,7 @@ void debug_probe_init_swd_pins(void) .gpio_array = bundle_io_gpios, .array_size = ARRAY_SIZE(bundle_io_gpios), .flags = { - .out_en = 1, + .out_en = 0, /* We will output without dedic_gpio, or we cannot disable output */ .in_en = 1, }, }; diff --git a/components/debug_probe/debug_gpio.h b/components/debug_probe/debug_gpio.h index 2c195b2..3c15c02 100644 --- a/components/debug_probe/debug_gpio.h +++ b/components/debug_probe/debug_gpio.h @@ -103,12 +103,12 @@ void debug_probe_notify_activity(bool active); __STATIC_FORCEINLINE void debug_probe_swdio_out_enable(void) { - REG_WRITE(GPIO_FUNC0_OUT_SEL_CFG_REG + (GPIO_SWDIO * 4), dedic_gpio_conf); gpio_ll_output_enable(dedic_gpio_dev, GPIO_SWDIO); } __STATIC_FORCEINLINE void debug_probe_swdio_out_disable(void) { + REG_WRITE(GPIO_FUNC0_OUT_SEL_CFG_REG + (GPIO_SWDIO * 4), dedic_gpio_conf); gpio_ll_output_disable(dedic_gpio_dev, GPIO_SWDIO); } @@ -129,17 +129,17 @@ __STATIC_FORCEINLINE void debug_probe_swclk_clr(void) __STATIC_FORCEINLINE void debug_probe_swdio_set(void) { - dedic_gpio_cpu_ll_write_mask(GPIO_SWDIO_OUT_MASK, GPIO_SWDIO_OUT_MASK); + gpio_ll_set_level(dedic_gpio_dev, GPIO_SWDIO, 1); } __STATIC_FORCEINLINE void debug_probe_swdio_clr(void) { - dedic_gpio_cpu_ll_write_mask(GPIO_SWDIO_OUT_MASK, 0); + gpio_ll_set_level(dedic_gpio_dev, GPIO_SWDIO, 0); } __STATIC_FORCEINLINE void debug_probe_swdio_write(int val) { - dedic_gpio_cpu_ll_write_mask(GPIO_SWDIO_OUT_MASK, (val & 0x01) ? GPIO_SWDIO_OUT_MASK : 0); + gpio_ll_set_level(dedic_gpio_dev, GPIO_SWDIO, (val & 0x1)?1:0); } __STATIC_FORCEINLINE void debug_probe_swd_blink(int on)