diff --git a/arch/risc-v/src/esp32c3/Make.defs b/arch/risc-v/src/esp32c3/Make.defs index d86ce14e6d6..d3a6c51939b 100644 --- a/arch/risc-v/src/esp32c3/Make.defs +++ b/arch/risc-v/src/esp32c3/Make.defs @@ -45,7 +45,7 @@ endif # Specify our C code within this directory to be included -CHIP_CSRCS = esp32c3_allocateheap.c esp32c3_start.c esp32c3_idle.c +CHIP_CSRCS = esp32c3_allocateheap.c esp32c3_start.c esp32c3_wdt.c esp32c3_idle.c CHIP_CSRCS += esp32c3_irq.c CHIP_CSRCS += esp32c3_clockconfig.c esp32c3_gpio.c CHIP_CSRCS += esp32c3_lowputc.c @@ -85,12 +85,9 @@ ifeq ($(CONFIG_ESP32C3_PARTITION),y) CHIP_CSRCS += esp32c3_partition.c endif -ifeq ($(CONFIG_ESP32C3_WDT),y) -CHIP_CSRCS += esp32c3_wdt.c ifeq ($(CONFIG_WATCHDOG),y) CHIP_CSRCS += esp32c3_wdt_lowerhalf.c endif -endif ifeq ($(CONFIG_ESP32C3_TIMER),y) CHIP_CSRCS += esp32c3_tim.c diff --git a/arch/risc-v/src/esp32c3/esp32c3_start.c b/arch/risc-v/src/esp32c3/esp32c3_start.c index 2ce266f5c6c..659c0878043 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_start.c +++ b/arch/risc-v/src/esp32c3/esp32c3_start.c @@ -34,6 +34,7 @@ #include "esp32c3_irq.h" #include "esp32c3_lowputc.h" #include "esp32c3_start.h" +#include "esp32c3_wdt.h" /**************************************************************************** * Pre-processor Definitions @@ -94,6 +95,10 @@ void __esp32c3_start(void) showprogress('B'); + /* Disable any wdt enabled by bootloader */ + + esp32c3_wdt_early_deinit(); + /* Initialize onboard resources */ esp32c3_board_initialize(); diff --git a/arch/risc-v/src/esp32c3/esp32c3_wdt.c b/arch/risc-v/src/esp32c3/esp32c3_wdt.c index f53b8382322..4f4106cd7de 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wdt.c +++ b/arch/risc-v/src/esp32c3/esp32c3_wdt.c @@ -876,6 +876,24 @@ struct esp32c3_wdt_dev_s *esp32c3_wdt_init(enum esp32c3_wdt_inst_e wdt_id) return (struct esp32c3_wdt_dev_s *)wdt; } +/**************************************************************************** + * Name: esp32c3_wdt_early_deinit + * + * Description: + * Disable the WDT(s) that was/were enabled by the bootloader. + * + ****************************************************************************/ + +void esp32c3_wdt_early_deinit(void) +{ + uint32_t regval; + putreg32(RTC_CNTL_WDT_WKEY_VALUE, RTC_CNTL_WDTWPROTECT_REG); + regval = getreg32(RTC_CNTL_WDTCONFIG0_REG); + regval &= ~RTC_CNTL_WDT_EN; + putreg32(regval, RTC_CNTL_WDTCONFIG0_REG); + putreg32(0, RTC_CNTL_WDTWPROTECT_REG); +} + /**************************************************************************** * Name: esp32c3_wdt_deinit * diff --git a/arch/risc-v/src/esp32c3/esp32c3_wdt.h b/arch/risc-v/src/esp32c3/esp32c3_wdt.h index 4316d114f05..61e78ee7391 100644 --- a/arch/risc-v/src/esp32c3/esp32c3_wdt.h +++ b/arch/risc-v/src/esp32c3/esp32c3_wdt.h @@ -141,6 +141,7 @@ struct esp32c3_wdt_ops_s ****************************************************************************/ struct esp32c3_wdt_dev_s *esp32c3_wdt_init(enum esp32c3_wdt_inst_e wdt_id); +void esp32c3_wdt_early_deinit(void); void esp32c3_wdt_deinit(struct esp32c3_wdt_dev_s *dev); bool esp32c3_wdt_is_running(struct esp32c3_wdt_dev_s *dev); diff --git a/arch/risc-v/src/esp32c3/hardware/esp32c3_rtccntl.h b/arch/risc-v/src/esp32c3/hardware/esp32c3_rtccntl.h index 9f9282a17df..4ef6c8a8048 100644 --- a/arch/risc-v/src/esp32c3/hardware/esp32c3_rtccntl.h +++ b/arch/risc-v/src/esp32c3/hardware/esp32c3_rtccntl.h @@ -49,13 +49,13 @@ * write-enable the wdt registers */ -#define RTC_CNTL_WDT_WKEY_VALUE 0x50D83AA1 +#define RTC_CNTL_WDT_WKEY_VALUE 0x50d83aa1 /* The value that needs to be written to RTC_CNTL_SWD_WPROTECT_REG * to write-enable the wdt registers */ -#define RTC_CNTL_SWD_WKEY_VALUE 0x8F1D312A +#define RTC_CNTL_SWD_WKEY_VALUE 0x8f1d312a /* Possible values for RTC_CNTL_WDT_CPU_RESET_LENGTH * and RTC_CNTL_WDT_SYS_RESET_LENGTH