Skip to content

Commit

Permalink
esp32[c3]: Add XTWDT support
Browse files Browse the repository at this point in the history
  • Loading branch information
eren-terzioglu committed Jun 4, 2024
1 parent 6f50847 commit e5d23b0
Show file tree
Hide file tree
Showing 7 changed files with 439 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ To test it, just run the following command::

Where X is the watchdog instance.

To test the XTWDT(/dev/watchdog3) an interrupt handler needs to be
implemented because XTWDT does not have system reset feature. To implement
an interrupt handler `WDIOC_CAPTURE` command can be used. When interrupt
rises, XTAL32K clock can be restored with `WDIOC_RSTCLK` command.

wifi
----

Expand Down
78 changes: 78 additions & 0 deletions arch/risc-v/src/common/espressif/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ endmenu # Bootloader and Image Configuration

menu "Peripheral Support"

config ESPRESSIF_RTC
bool "Real Time Clock (RTC)"
default y

config ESPRESSIF_UART
bool
default n
Expand Down Expand Up @@ -360,6 +364,37 @@ config ESPRESSIF_RWDT
to have the RTC module reset, please, use the Timers' Module WDTs.
They will only reset Main System.

config ESPRESSIF_XTWDT
bool "XTAL32K Watchdog Timer"
depends on ARCH_CHIP_ESP32C3_GENERIC
depends on ESPRESSIF_RTCIO_IRQ
depends on ESPRESSIF_RTC_CLK_EXT_OSC || ESPRESSIF_RTC_CLK_EXT_XTAL
default n
select ESPRESSIF_WDT
---help---
Includes XTWDT. This watchdog timer monitors the status of the
external 32 kHz crystal oscillator (XTAL32K). When XTAL32K_CLK works
as the clock source of RTC_SLOW_CLK and it stops oscillating, the
XTAL32K watchdog timer first switches to BACKUP32K_CLK derived from
RC_SLOW_CLK (if ESP32S2_XTWDT_BACKUP_CLK_ENABLE) and, then, generates
an interrupt that could be captured by WDIOC_CAPTURE.

config ESPRESSIF_XTWDT_TIMEOUT
int "XTAL32K watchdog timeout period"
depends on ESPRESSIF_XTWDT
range 1 255
default 200
help
Timeout period configuration for the XTAL32K watchdog timer based on RTC_CLK.

config ESPRESSIF_XTWDT_BACKUP_CLK_ENABLE
bool "Automatically switch to BACKUP32K_CLK when timer expires"
depends on ESPRESSIF_XTWDT
default y
---help---
Enable this to automatically switch to BACKUP32K_CLK as the source of
RTC_SLOW_CLK when the watchdog timer expires.

config ESPRESSIF_BROWNOUT_DET
bool "Brownout Detector"
default y
Expand Down Expand Up @@ -925,6 +960,49 @@ config ESPRESSIF_STORAGE_MTD_SIZE

endmenu # SPI Flash Configuration

menu "RTC Configuration"
depends on ESPRESSIF_RTC

choice ESPRESSIF_RTC_CLK_SRC
prompt "RTC clock source"
default ESPRESSIF_RTC_CLK_INT_RC
---help---
Choose which clock is used as RTC clock source.

- "Internal 90KHz oscillator" option provides lowest deep sleep current
consumption, and does not require extra external components. However
frequency stability with respect to temperature is poor, so time may
drift in deep/light sleep modes.
- "External 32KHz crystal" provides better frequency stability, at the
expense of slightly higher (1uA) deep sleep current consumption.
- "External 32KHz oscillator" allows using 32KHz clock generated by an
external circuit. In this case, external clock signal must be connected
to 32K_XN pin. Amplitude should be <1.2V in case of sine wave signal,
and <1V in case of square wave signal. Common mode voltage should be
0.1 < Vcm < 0.5Vamp, where Vamp is the signal amplitude.
Additionally, 1nF capacitor must be connected between 32K_XP pin and
ground. 32K_XP pin can not be used as a GPIO in this case.
- "Internal 8.5MHz oscillator divided by 256" option results in higher
deep sleep current (by 5uA) but has better frequency stability than
the internal 90KHz oscillator. It does not require external components.

config ESPRESSIF_RTC_CLK_INT_RC
bool "Internal 90KHz RC oscillator"

config ESPRESSIF_RTC_CLK_EXT_XTAL
bool "External 32KHz crystal"
select ESP_SYSTEM_RTC_EXT_XTAL

config ESPRESSIF_RTC_CLK_EXT_OSC
bool "External 32KHz oscillator at 32K_XN pin"
select ESP_SYSTEM_RTC_EXT_XTAL

config ESPRESSIF_RTC_CLK_INT_8MD256
bool "Internal 8.5MHz oscillator, divided by 256 (~33kHz)"

endchoice
endmenu # "RTC Configuration"

menu "LEDC configuration"
depends on ESPRESSIF_LEDC

Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/common/espressif/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ endif

ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty
ifndef ESP_HAL_3RDPARTY_VERSION
ESP_HAL_3RDPARTY_VERSION = ee8c7b0ad6a117465312d4c9a6e654cb7b2b9469
ESP_HAL_3RDPARTY_VERSION = 6c58b9c8d29fc2faa8cb6273a169340b80229df5
endif

ifndef ESP_HAL_3RDPARTY_URL
Expand Down
Loading

0 comments on commit e5d23b0

Please sign in to comment.