esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
291 stars 36 forks source link

LD2420 triggers boot loop due WDT on ESP32S3 #5705

Open andyvandesand opened 7 months ago

andyvandesand commented 7 months ago

The problem

I'm trying to get an LD2420 to work with an ESP32-S3, the waveshare s3-zero version. As the specific board profile isn't available yet I've already tried changing some paramters, without success. I've tried just the UART without the LD2420, that's working fine. Other pins don't seem to change much either. When monitoring the uart I can see the sensor actually providing valid data, but then the WDT resets the chip.

The sensor is working on an ESP32-WROOM-32E.

Any help would be appreciated...

EDIT: removed external components to narrow down the issue

Which version of ESPHome has the issue?

2024.4.0

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2024.4.0

What platform are you using?

ESP32

Board

Waveshare ESP32-S3-Zero

Component causing the issue

LD2420

Example YAML snippet

substitutions:
  name: esphome-web-529aa0
  friendly_name: "Theatre AC"
  # Unique device ID in HA
  deviceid: "thatreacesp"
  # Unique device name in HA
  devicename: "Theatre AC"

esphome:
  name: ${deviceid}
  friendly_name: ${devicename}
  name_add_mac_suffix: false
  platformio_options:
    board_build.flash_mode: dio
    board_build.f_cpu: 240000000L
    board_build.f_flash: 80000000L
    board_upload.maximum_ram_size: 327680
    board_upload.maximum_size: 4194304
    build_flags:
      - "-DBOARD_HAS_PSRAM"
      - "-DARDUINO_USB_MODE=1"
  project:
    name: esphome.web
    version: '1.0'

esp32:
  board: adafruit_feather_esp32s3
  flash_size: 4MB

  variant: ESP32S3
  framework:
    type: arduino

psram:
  mode: octal
  speed: 80MHz

# Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-529aa0"
    password: !secret wifi_backup

# In combination with the `ap` this allows the user
# to provision wifi credentials to the device via WiFi AP.
captive_portal:

dashboard_import:
  package_import_url: github://esphome/firmware/esphome-web/esp32s3.yaml@v2
  import_full_config: true

# Sets up Bluetooth LE (Only on ESP32) to allow the user
# to provision wifi credentials to the device.
#esp32_improv:
#  authorizer: none

# To have a "next url" for improv serial
#web_server:

uart:
  id: mmuart
  tx_pin: 7
  rx_pin: 8
  baud_rate: 115200
#  debug:
#    direction: BOTH
#    after:
#      delimiter: "\r\n"
#    sequence:
#      - lambda: UARTDebug::log_string(direction, bytes);

ld2420:

text_sensor:
  - platform: version
    name: ESPHome Version
  - platform: wifi_info
    ip_address:
      name: IP
    ssid:
      name: SSID
    bssid:
      name: BSSID
  - platform: ld2420
    fw_version:
      name: LD2420 Firmware

sensor:
  - platform: uptime
    name: Uptime
  - platform: wifi_signal
    name: WiFi Signal
    update_interval: 60s
  - platform: ld2420
    moving_distance:
      name : Moving Distance
#  - platform: internal_temperature
#    id: internaltemp
#    name: "Internal Temperature"

binary_sensor:
  - platform: ld2420
    has_target:
      name: Presence

select:
  - platform: ld2420
    operating_mode:
      name: Operating Mode

number:
  - platform: ld2420
    presence_timeout:
      name: Detection Presence Timeout
    min_gate_distance:
      name: Detection Gate Minimum
    max_gate_distance:
      name: Detection Gate Maximum
    # See "Number" section below for detail
    gate_select:
      name: Select Gate to Set
    still_threshold:
      name: Set Still Threshold Value
    move_threshold:
      name: Set Move Threshold Value

button:
  - platform: ld2420
    apply_config:
      name: Apply Config
    factory_reset:
      name: Factory Reset
    restart_module:
      name: Restart Module
    revert_config:
      name: Undo Edits
  - platform: restart
    name: Restart
    entity_category: diagnostic

light:
  - platform: esp32_rmt_led_strip
    id: rgbled
    rgb_order: RGB
    pin: GPIO21
    num_leds: 1
    rmt_channel: 1
    chipset: ws2812
    name: "Light"

#switch:
#  - platform: gpio
#    pin: 1
#    id: pin1
#    name: "pin1"

Anything in the logs that might be useful for us?

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40378c1e
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x39c
load:0x403c9700,len:0x9bc
load:0x403cc700,len:0x28dc
entry 0x403c98c0
[I][logger:158]: Log initialized
[C][ota:483]: There have been 0 suspected unsuccessful boot attempts.
[D][esp32.preferences:114]: Saving 1 preferences to flash...
[D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[C][uart.arduino_esp32:077]: Setting up UART...
[C][ld2420:114]: Setting up LD2420...
[D][ld2420:566]: Sending set config enable command: FF
E (10682) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (10682) task_wdt:  - loopTask (CPU 1)
E (10682) task_wdt: Tasks currently running:
E (10682) task_wdt: CPU 0: IDLE
E (10682) task_wdt: CPU 1: loopTask
E (10682) task_wdt: Aborting.
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40377590
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x39c
load:0x403c9700,len:0x9bc
load:0x403cc700,len:0x28dc
entry 0x403c98c0
[I][logger:158]: Log initialized
[C][ota:483]: There have been 1 suspected unsuccessful boot attempts.

Additional information

No response

StreakingJerry commented 7 months ago

Totally same issue with esp32c3

fragpic commented 6 months ago

Is the LD2420 connected to the board when you boot it? The LD2420 component has an issue where if no data is seen on the RX pin at boot, it will bootloop. #6594 is supposed to fix it

andyvandesand commented 6 months ago

I just tried without the board attached at all, and it does the same. Going off the fact that the LD actually sends data through the uart until the WDT resets when I monitor it I would assume this is purely a bug in the ld2420 library?

andyvandesand commented 6 months ago

Sorry took me a while to get a local version setup. I can confirm this is at least a partial fix. There is still an issue, in that on every other cold power up the sensor just gets flagged as "failed". Restarting the board seems to fix this. I don't have the required insight to fix this, but I'm very happy to do some local testing if anyone has any info for me.

LBrinston commented 5 months ago

I believe I too am experiencing this issue with the standard ESP32 dev board and the LD2420. I see the watchdog resetting the ESP part way through setting up the LD2420. This results in a boot loop during programming ultimately ending in the ESP booting into safe mode and thus being undiscovered by Home Assistant.

Hard resetting via RTS pin...
INFO Successfully uploaded program.
INFO Starting log output from /dev/ttyUSB0 with baud rate 115200
[14:23:00]\x80\00x\x80\00\x80\00x\xf8\00x\x80x\x80\xf8x\00\x80x\x80x\xf8x\xf8\x80\00\x80\xc10,hd_drv:0x00,wp_drv:0x00
[14:23:00]mode:DIO, clock div:2
[14:23:00]load:0x3fff0030,len:1184
[14:23:00]load:0x40078000,len:13132
[14:23:00]load:0x40080400,len:3036
[14:23:00]entry 0x400805e4
[14:23:01][I][logger:158]: Log initialized
[14:23:01][C][ota:483]: There have been 0 suspected unsuccessful boot attempts.
[14:23:01][D][esp32.preferences:114]: Saving 1 preferences to flash...
[14:23:01][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[14:23:01][I][app:029]: Running through setup()...
[14:23:01][C][uart.arduino_esp32:077]: Setting up UART...
[14:23:01][C][ld2420:114]: Setting up LD2420...
[14:23:01][D][ld2420:566]: Sending set config enable command: FF
[14:23:01][D][ld2420:448]: LD2420 reply - set config enable: CMD = FF success
[14:23:01][D][ld2420:647]: Sending read gate min max and timeout command:  8
[14:23:01][D][ld2420:448]: LD2420 reply - set config enable: CMD = FF success
[14:23:01][D][number:012]: 'Detection Presence Timeout': Sending state 0.000000
[14:23:01][D][number:012]: 'Select Gate to Set': Sending state 0.000000
[14:23:01][D][number:012]: 'Detection Gate Minimum': Sending state 0.000000
[14:23:01][D][number:012]: 'Detection Gate Maximum': Sending state 0.000000
[14:23:01][D][number:012]: 'Set Still Threshold Value': Sending state 0.000000
[14:23:01][D][number:012]: 'Set Move Threshold Value': Sending state 0.000000
[14:23:01][D][ld2420:682]: Sending read firmware version command:  0
[14:23:01][D][ld2420:488]: LD2420 reply - module firmware version:  v0.0.0 success
[14:23:01][D][text_sensor:064]: 'LD2420 Firmware': Sending state 'v0.0.0'
[14:23:01][D][ld2420:622]: Sending read gate 0 high/low theshold command:  8
[14:23:04][D][sensor:094]: 'Moving Distance': Sending state 70.00000 cm with 0 decimals of accuracy
[14:23:04][D][binary_sensor:036]: 'Presence': Sending state ON
[14:23:05][D][ld2420:448]: LD2420 reply - set config enable: CMD = FF success
[14:23:05][D][ld2420:622]: Sending read gate 1 high/low theshold command:  8
[14:23:06]E (10402) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
[14:23:06]E (10402) task_wdt:  - loopTask (CPU 1)
[14:23:06]E (10402) task_wdt: Tasks currently running:
[14:23:06]E (10402) task_wdt: CPU 0: IDLE
[14:23:06]E (10402) task_wdt: CPU 1: loopTask
[14:23:06]E (10402) task_wdt: Aborting.
[14:23:06]
[14:23:06]abort() was called at PC 0x400fa1dc on core 0
[14:23:06]
[14:23:06]
[14:23:06]Backtrace:0x400837cd:0x3ffbe9bc |<-CORRUPTED
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x400837cd: panic_abort at /Users/ficeto/Desktop/ESP32/ESP32S2/esp-idf-public/components/esp_system/panic.c:402
[14:23:06]
[14:23:06]
[14:23:06]
[14:23:06]
[14:23:06]ELF file SHA256: 0000000000000000
[14:23:06]
[14:23:06]Rebooting...

Above is the first instance of the ESP trying to communicate with the LD2420 right after flashing. It does this about 9 times before it boots into safe mode.

I've hooked both UART0 (programming/logger) and UART1(LD2420) up to a logic analyzer and can actually see the LD2420 response traffic on initial programming and if I power cycle the ESP after attempting to program. For some reason I can't seem to get the logger traffic to appear on a Serial monitor that isn't the one provided by ESPHome. For example : tio -b 115200 /dev/ttyUSB0 just results in an empty monitor when I restart the ESP.

This is the yaml I am using to program the ESP:

esphome:
  name: office-presence
  friendly_name: Office_Presence

esp32:
  board: esp32dev

# Enable logging - Uses UART0 
logger:
  level: VERY_VERBOSE

api:
  encryption:
    key: "redacted"

ota:
  password: "redacted"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "redacted"
    password: "redacted"

captive_portal:

uart:
  tx_pin: GPIO17
  rx_pin: GPIO16
  baud_rate: 115200
  parity: NONE
  stop_bits: 1

ld2420:

text_sensor:
  - platform: ld2420
    fw_version:
      name: LD2420 Firmware

sensor:
  - platform: ld2420
    moving_distance:
      name : Moving Distance

binary_sensor:
  - platform: ld2420
    has_target:
      name: Presence

select:
  - platform: ld2420
    operating_mode:
      name: Operating Mode

number:
  - platform: ld2420
    presence_timeout:
      name: Detection Presence Timeout
    min_gate_distance:
      name: Detection Gate Minimum
    max_gate_distance:
      name: Detection Gate Maximum
    # See "Number" section below for detail
    gate_select:
      name: Select Gate to Set
    still_threshold:
      name: Set Still Threshold Value
    move_threshold:
      name: Set Move Threshold Value

button:
  - platform: ld2420
    apply_config:
      name: Apply Config
    factory_reset:
      name: Factory Reset
    restart_module:
      name: Restart Module
    revert_config:
      name: Undo Edits

It is the boiler plate given on the ESPHome page for the LD2420.

GelidusResearch commented 4 months ago

Are you still experiencing issues on this issue?