Skip to content

Commit cb23469

Browse files
committed
cpu/esp32/periph/pm: fix wake-up by UART for ESP32
1 parent 05af451 commit cb23469

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

cpu/esp32/esp-idf/common/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ ifneq (,$(filter periph_spi,$(USEMODULE)))
9797
ESP32_SDK_SRC += components/soc/$(CPU_FAM)/spi_periph.c
9898
endif
9999

100+
# TODO separate module
101+
ifneq (,$(filter periph_uart,$(USEMODULE)))
102+
ESP32_SDK_SRC += components/soc/$(CPU_FAM)/uart_periph.c
103+
endif
104+
100105
ifneq (,$(filter xtensa%,$(TARGET_ARCH)))
101106
ESP32_SDK_SRC += components/soc/$(CPU_FAM)/rtc_io_periph.c
102107
endif

cpu/esp32/periph/pm.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "periph/uart.h"
3131

3232
/* ESP-IDF headers */
33+
#include "driver/gpio.h"
3334
#include "driver/uart.h"
3435
#include "esp_sleep.h"
3536
#include "rom/rtc.h"
@@ -165,13 +166,30 @@ void pm_set(unsigned mode)
165166
gpio_pm_sleep_enter(mode);
166167

167168
#if (ESP_PM_WUP_UART0 > 2)
169+
_Static_assert(UART_NUMOF > 0, "UART_DEV(0) is not defined");
170+
#if CPU_FAM_ESP32
171+
/* For ESP32, UART RxD has to be configured for direct IO using IOMUX */
172+
const uart_periph_sig_t *sig = &uart_periph_signal[UART_DEV(0)].pins[SOC_UART_RX_PIN_IDX];
173+
gpio_iomux_out(UART0_RXD, sig->iomux_func, false);
174+
gpio_iomux_in(UART0_RXD, sig->signal);
175+
#endif
168176
uart_set_wakeup_threshold(UART_DEV(0), ESP_PM_WUP_UART0);
169177
esp_sleep_enable_uart_wakeup(0);
170178
#endif
171179
#if (ESP_PM_WUP_UART1 > 2)
180+
_Static_assert(UART_NUMOF > 1, "UART_DEV(1) is not defined");
181+
#if CPU_FAM_ESP32
182+
/* For ESP32, UART RxD has to be configured for direct IO using IOMUX */
183+
const uart_periph_sig_t *sig = &uart_periph_signal[UART_DEV(0)].pins[SOC_UART_RX_PIN_IDX];
184+
gpio_iomux_out(UART1_RXD, sig->iomux_func, false);
185+
gpio_iomux_in(UART1_RXD, sig->signal);
186+
#endif
172187
uart_set_wakeup_threshold(UART_DEV(1), ESP_PM_WUP_UART1);
173188
esp_sleep_enable_uart_wakeup(1);
174189
#endif
190+
#if MODULE_STDIO_UART
191+
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
192+
#endif
175193

176194
if (mode == ESP_PM_DEEP_SLEEP) {
177195
esp_deep_sleep_start();

0 commit comments

Comments
 (0)