Xinyuan-LilyGO / LilyGo-LoRa-Series

LILYGO LoRa Series examples
602 stars 168 forks source link

Lilygo ESP32 T3-S3, ULP wrong wakeup cause after deep sleep #125

Closed redarflap closed 6 months ago

redarflap commented 6 months ago

ESP-IDF version: v5.1 / v5.2.0 Hardware: Lilygo Lora T3S3 V1.2

What is the expected behavior?

Get wakeup cause ESP_SLEEP_WAKEUP_ULP after calling ulp_riscv_wakeup_main_processor() from ULP.

What is the actual behavior?

I keep getting ESP_SLEEP_WAKEUP_UNDEFINED no matter what I try. I suspect that the issue is related to the Lilygo board, since I cannot immagine such a major bug to be present in ESP-IDF unnoticed.

Steps to reproduce:

Step 1: Using ESP-IDF, create one of the provided ULP example projects
Step 2: Build, Flash (UART) and Monitor (UART)
Step 3: Observe output

Debug Logs

Entering in deep sleep

None
Waiting for the device to reconnect
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0xa (SPI_FAST_FLASH_BOOT)
Saved PC:0x40378d02
0x40378d02: esp_cpu_wait_for_intr at C:/Users/Joi/esp/esp-idf/components/esp_hw_support/cpu.c:145

SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3810,len:0x12b4
load:0x403c9700,len:0x4
load:0x403c9704,len:0xaf0
load:0x403cc700,len:0x2bdc
entry 0x403c9898
Not a ULP-RISC-V wakeup, initializing it! 
Wakeup cause: 0
Entering in deep sleep

Example code main processor:

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");

static void init_ulp_program(void);

void app_main(void)
{

  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)
  {
    printf("Not a ULP-RISC-V wakeup, initializing it! \n");
    printf("Wakeup cause: %d\n", cause);
    init_ulp_program();
  }

  /* ULP Risc-V read and detected a change in GPIO_0, prints */
  if (cause == ESP_SLEEP_WAKEUP_ULP)
  {
    printf("ULP-RISC-V woke up the main CPU! \n");
  }

  /* Go back to sleep, only the ULP Risc-V will run */
  printf("Entering in deep sleep\n\n");

  /* Small delay to ensure the messages are printed */
  ESP_ERROR_CHECK(esp_sleep_enable_ulp_wakeup());
  vTaskDelay(1000);
  esp_deep_sleep_start();
}

static void init_ulp_program(void)
{
  esp_err_t err = ulp_riscv_load_binary(ulp_main_bin_start, (ulp_main_bin_end - ulp_main_bin_start));
  ESP_ERROR_CHECK(err);
  ulp_set_wakeup_period(0, 2000000);

  /* Start the program */
  err = ulp_riscv_run();
  ESP_ERROR_CHECK(err);
}

Example code ULP:

int main(void)
{
  ulp_riscv_wakeup_main_processor();
  /* ulp_riscv_halt() is called automatically when main exits */

  return 0;
}
redarflap commented 6 months ago

The problem appears to be related to a UART or JTAG monitoring session being open. When disconnecting the monitoring session and printing the output to the OLED instead, everything works as expected.

Is there any workaround to this behaviour?

redarflap commented 6 months ago

Update: The issue is indeed related to the Serial connection.

See espressif/esp-idf#12899 for further details.