From 9d41418bd25a08daf7b0b0bc95d864c11261777a Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Mon, 15 Jan 2024 11:58:46 +0800 Subject: [PATCH] fix(ulp): improve ULP examples for users using usb-jtag-serial When using USB-serial-jtag for monitoring idf-monitor will lose connection during deep sleep (because the peripheral powers down) and will need some time to reconnect when we wake-up. In the ULP examples this would result in the chip waking up->printing-> going back to sleep, before idf-monitor is even able to connect, and users would erroneously assume the chip never woke up. Add a 1 sec delay at the start of the examples to improve the user experience when using jtag-serial. --- .../ulp/lp_core/gpio/main/lp_core_gpio_example_main.c | 9 ++++++++- examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c | 11 ++++++++++- .../lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c | 11 ++++++++++- .../lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c | 11 ++++++++++- .../system/ulp/ulp_fsm/ulp/main/ulp_example_main.c | 11 ++++++++++- .../ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c | 9 ++++++++- .../ulp_riscv/adc/main/ulp_riscv_adc_example_main.c | 10 +++++++++- .../main/ulp_riscv_ds18b20_example_main.c | 9 ++++++++- .../ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c | 9 ++++++++- .../main/ulp_riscv_gpio_intr_example_main.c | 9 ++++++++- .../i2c/main/ulp_riscv_rtc_i2c_example_main.c | 9 ++++++++- .../touch/main/ulp_riscv_touch_example_main.c | 9 ++++++++- .../uart_print/main/ulp_riscv_example_main.c | 9 ++++++++- 13 files changed, 113 insertions(+), 13 deletions(-) diff --git a/examples/system/ulp/lp_core/gpio/main/lp_core_gpio_example_main.c b/examples/system/ulp/lp_core/gpio/main/lp_core_gpio_example_main.c index a8300a8110..e80cdea4a7 100644 --- a/examples/system/ulp/lp_core/gpio/main/lp_core_gpio_example_main.c +++ b/examples/system/ulp/lp_core/gpio/main/lp_core_gpio_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -30,6 +30,13 @@ static void init_ulp_program(void); void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + /* Initialize selected GPIO as RTC IO, enable input, disable pullup and pulldown */ rtc_gpio_init(WAKEUP_PIN); rtc_gpio_set_direction(WAKEUP_PIN, RTC_GPIO_MODE_INPUT_ONLY); diff --git a/examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c b/examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c index 42fe307609..0e0d57f0ec 100644 --- a/examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c +++ b/examples/system/ulp/lp_core/lp_i2c/main/lp_i2c_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -9,6 +9,8 @@ #include "lp_core_main.h" #include "ulp_lp_core.h" #include "lp_core_i2c.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" extern const uint8_t lp_core_main_bin_start[] asm("_binary_lp_core_main_bin_start"); extern const uint8_t lp_core_main_bin_end[] asm("_binary_lp_core_main_bin_end"); @@ -53,6 +55,13 @@ static void lp_i2c_init(void) void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (cause != ESP_SLEEP_WAKEUP_ULP) { printf("Not an LP core wakeup. Cause = %d\n", cause); diff --git a/examples/system/ulp/lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c b/examples/system/ulp/lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c index c6126c1b0e..f5af38d35a 100644 --- a/examples/system/ulp/lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c +++ b/examples/system/ulp/lp_core/lp_uart/lp_uart_echo/main/lp_uart_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,6 +10,8 @@ #include "lp_core_main.h" #include "ulp_lp_core.h" #include "lp_core_uart.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" extern const uint8_t lp_core_main_bin_start[] asm("_binary_lp_core_main_bin_start"); extern const uint8_t lp_core_main_bin_end[] asm("_binary_lp_core_main_bin_end"); @@ -41,6 +43,13 @@ static void lp_core_init(void) void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (cause != ESP_SLEEP_WAKEUP_ULP) { printf("Not an LP core wakeup. Cause = %d\n", cause); diff --git a/examples/system/ulp/lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c b/examples/system/ulp/lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c index 9f4149c1b8..08c4fd3997 100644 --- a/examples/system/ulp/lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c +++ b/examples/system/ulp/lp_core/lp_uart/lp_uart_print/main/lp_uart_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -10,6 +10,8 @@ #include "lp_core_main.h" #include "ulp_lp_core.h" #include "lp_core_uart.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" extern const uint8_t lp_core_main_bin_start[] asm("_binary_lp_core_main_bin_start"); extern const uint8_t lp_core_main_bin_end[] asm("_binary_lp_core_main_bin_end"); @@ -42,6 +44,13 @@ static void lp_core_init(void) void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (cause != ESP_SLEEP_WAKEUP_ULP) { printf("Not an LP core wakeup. Cause = %d\n", cause); diff --git a/examples/system/ulp/ulp_fsm/ulp/main/ulp_example_main.c b/examples/system/ulp/ulp_fsm/ulp/main/ulp_example_main.c index a148aa0c96..5a9ab22485 100644 --- a/examples/system/ulp/ulp_fsm/ulp/main/ulp_example_main.c +++ b/examples/system/ulp/ulp_fsm/ulp/main/ulp_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -24,6 +24,8 @@ #include "driver/rtc_io.h" #include "ulp.h" #include "ulp_main.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start"); extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end"); @@ -33,6 +35,13 @@ static void update_pulse_count(void); void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (cause != ESP_SLEEP_WAKEUP_ULP) { printf("Not ULP wakeup, initializing ULP\n"); diff --git a/examples/system/ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c b/examples/system/ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c index b167825299..ed10d2524b 100644 --- a/examples/system/ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c +++ b/examples/system/ulp/ulp_fsm/ulp_adc/main/ulp_adc_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -44,6 +44,13 @@ static void start_ulp_program(void); void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); if (cause != ESP_SLEEP_WAKEUP_ULP) { printf("Not ULP wakeup\n"); diff --git a/examples/system/ulp/ulp_riscv/adc/main/ulp_riscv_adc_example_main.c b/examples/system/ulp/ulp_riscv/adc/main/ulp_riscv_adc_example_main.c index 0f330c1bf3..d4a0c39889 100644 --- a/examples/system/ulp/ulp_riscv/adc/main/ulp_riscv_adc_example_main.c +++ b/examples/system/ulp/ulp_riscv/adc/main/ulp_riscv_adc_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -19,6 +19,8 @@ #include "ulp_adc.h" #include "ulp_main.h" #include "ulp/example_config.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start"); @@ -28,6 +30,12 @@ static void init_ulp_program(void); void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); diff --git a/examples/system/ulp/ulp_riscv/ds18b20_onewire/main/ulp_riscv_ds18b20_example_main.c b/examples/system/ulp/ulp_riscv/ds18b20_onewire/main/ulp_riscv_ds18b20_example_main.c index a7dedfb0ac..f3a397dbf2 100644 --- a/examples/system/ulp/ulp_riscv/ds18b20_onewire/main/ulp_riscv_ds18b20_example_main.c +++ b/examples/system/ulp/ulp_riscv/ds18b20_onewire/main/ulp_riscv_ds18b20_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -37,6 +37,13 @@ static void init_ulp_program(void); void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); /* not a wakeup from ULP, load the firmware */ if (cause != ESP_SLEEP_WAKEUP_ULP) { diff --git a/examples/system/ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c b/examples/system/ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c index 0b5b042326..13dea70f00 100644 --- a/examples/system/ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c +++ b/examples/system/ulp/ulp_riscv/gpio/main/ulp_riscv_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -31,6 +31,13 @@ static void init_ulp_program(void); void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + /* Initialize selected GPIO as RTC IO, enable input, disable pullup and pulldown */ rtc_gpio_init(GPIO_NUM_0); rtc_gpio_set_direction(GPIO_NUM_0, RTC_GPIO_MODE_INPUT_ONLY); diff --git a/examples/system/ulp/ulp_riscv/gpio_interrupt/main/ulp_riscv_gpio_intr_example_main.c b/examples/system/ulp/ulp_riscv/gpio_interrupt/main/ulp_riscv_gpio_intr_example_main.c index 35010f2dd2..cc2569fcfe 100644 --- a/examples/system/ulp/ulp_riscv/gpio_interrupt/main/ulp_riscv_gpio_intr_example_main.c +++ b/examples/system/ulp/ulp_riscv/gpio_interrupt/main/ulp_riscv_gpio_intr_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -42,6 +42,13 @@ static void wakeup_gpio_init(void) void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); /* not a wakeup from ULP, load the firmware */ if (cause != ESP_SLEEP_WAKEUP_ULP) { diff --git a/examples/system/ulp/ulp_riscv/i2c/main/ulp_riscv_rtc_i2c_example_main.c b/examples/system/ulp/ulp_riscv/i2c/main/ulp_riscv_rtc_i2c_example_main.c index 55e58694ef..7a08796d60 100644 --- a/examples/system/ulp/ulp_riscv/i2c/main/ulp_riscv_rtc_i2c_example_main.c +++ b/examples/system/ulp/ulp_riscv/i2c/main/ulp_riscv_rtc_i2c_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -38,6 +38,13 @@ static void init_i2c(void); void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + uint8_t data_rd = 0; int16_t ut_data = 0; int32_t up_data = 0; diff --git a/examples/system/ulp/ulp_riscv/touch/main/ulp_riscv_touch_example_main.c b/examples/system/ulp/ulp_riscv/touch/main/ulp_riscv_touch_example_main.c index 1f5dc449cc..dd5d4a2998 100644 --- a/examples/system/ulp/ulp_riscv/touch/main/ulp_riscv_touch_example_main.c +++ b/examples/system/ulp/ulp_riscv/touch/main/ulp_riscv_touch_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -76,6 +76,13 @@ static void init_ulp_program(void) void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); /* not a wakeup from ULP, load the firmware */ if (cause != ESP_SLEEP_WAKEUP_ULP) { diff --git a/examples/system/ulp/ulp_riscv/uart_print/main/ulp_riscv_example_main.c b/examples/system/ulp/ulp_riscv/uart_print/main/ulp_riscv_example_main.c index 13cf3cd8a4..811421ddbb 100644 --- a/examples/system/ulp/ulp_riscv/uart_print/main/ulp_riscv_example_main.c +++ b/examples/system/ulp/ulp_riscv/uart_print/main/ulp_riscv_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -26,6 +26,13 @@ static void init_ulp_program(void); void app_main(void) { + /* If user is using USB-serial-jtag then idf monitor needs some time to + * re-connect to the USB port. We wait 1 sec here to allow for it to make the reconnection + * before we print anything. Otherwise the chip will go back to sleep again before the user + * has time to monitor any output. + */ + vTaskDelay(pdMS_TO_TICKS(1000)); + esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause(); /* not a wakeup from ULP, load the firmware */ if (cause != ESP_SLEEP_WAKEUP_ULP) {