Skip to content

Minor changes to support ESP32-S6 and esphome 2025.2.2 #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mafrosis
Copy link

@mafrosis mafrosis commented Mar 19, 2025

It would be safest to test this against some existing configs and platformio versions before merging to main, but the changes themselves seem pretty harmless. Mostly compiler noise due to more strict options during build - I'm not sure when that changed.

For reference I'm using one of these:
https://www.waveshare.com/esp32-c6-lcd-1.47.htm

Build config:

esp32:
  board: esp32-c6-devkitc-1
  flash_size: 4MB
  variant: esp32c6
  framework:
    type: esp-idf
    version: 5.3.1
    platform_version: 6.9.0

Note for future readers: you will need to set task_core: 0 on the sound_level_meter config, as the S6 has only a single CPU core.

To test you have to make sure you're referencing the branch named in this PR. In this case it's from my fork:

external_components:
  - source: github://mafrosis/esphome-sound-level-meter@tmp
    components: [i2s, sound_level_meter]

@trianglesis
Copy link

trianglesis commented Mar 22, 2025

I tested this PR on my board and compiled it just fine:

esp32:
  board: esp32-c6-devkitc-1
  flash_size: 8MB
  variant: esp32c6

Installation, however, is not so good:

I][esp-idf:000][main]: I (640) main_task: Returned from app_main()

[E][safe_mode:086]: Boot loop detected. Proceeding to safe mode
[E][component:164]: Component safe_mode set Error flag: unspecified
[I][app:029]: Running through setup()...
[I][esp-idf:000]: I (950) pp: pp rom version: 5b8dcfa

@mafrosis
Copy link
Author

mafrosis commented Mar 23, 2025

Can you share your whole config and more of the boot loop log? There is usually some clue why that happens. Which S6 dev board are you using?

@trianglesis
Copy link

Recreated in a cleaner approach:

  1. The board has only i2s and no sensors - startup fine. Uptime for 1 minute.
  2. Added the simple sensors config: configs/minimal-example-config.yaml - got a bootloop.

Log with only error level:

My Config:

This is the yaml
substitutions:
  name: "esp32-c6-2-mic"
  friendly_name: "ESP32_C6_2-mic"

esphome:
  name: "esp32-c6-2-mic"
  friendly_name: "ESP32_C6_2-mic"

esp32:
  board: esp32-c6-devkitc-1
  flash_size: 8MB
  variant: esp32c6
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESPTOOLPY_FLASHSIZE_8MB: y
    version: "5.3.1"
    platform_version: 6.9.0

external_components:
  - source: github://mafrosis/esphome-sound-level-meter@tmp
    components: [i2s, sound_level_meter]

logger:
  level: WARN
  baud_rate: 115200
  hardware_uart: USB_SERIAL_JTAG
  logs:
    sensor: WARN
    component: WARN
    esp-idf: ERROR
    template.sensor: WARN
    text_sensor: WARN

api:
  encryption:
    key: !secret api_key
ota:
  - platform: esphome
    password: !secret ota_password
wifi:
  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password
    - ssid: !secret wifi_ssid_portable
      password: !secret wifi_password_portable
  # Board will host Wifi by itself
  ap:
    ssid: "${friendly_name}"
    password: !secret fall_back_wifi_password
    manual_ip:
        static_ip: !secret ap_static_ip_portable
        gateway: !secret ap_static_gateway
        subnet: 255.255.255.0
        dns1: !secret ap_static_dns
        dns2: 8.8.8.8
  # When no WifI
  reboot_timeout: 900s
  # Do not fast connect when portable
  # fast_connect: true

# Do not use when portable
# captive_portal:

web_server:
  port: 80
  version: 3
  sorting_groups:
  - id: sorting_group_co2
    name: "CO2 Values (SDC41)"
    sorting_weight: -1
  - id: sorting_group_statistics
    name: "Statistics"
    sorting_weight: 10
  - id: sorting_group_calibration
    name: "Calibration Values"
    sorting_weight: 40
  - id: sorting_group_diagnostic
    name: "Diagnostic info"
    sorting_weight: 60
  - id: sorting_group_service
    name: "Service"
    sorting_weight: 90

i2s:
  bck_pin: 23
  ws_pin: 18
  din_pin: 19
  sample_rate: 48000            # default: 48000
  bits_per_sample: 32           # default: 32

  # right shift samples.
  # for example if mic has 24 bit resolution, and i2s configured as 32 bits,
  # then audio data will be aligned left (MSB) and LSB will be padded with
  # zeros, so you might want to shift them right by 8 bits
  bits_shift: 8                 # default: 0  

sound_level_meter:
  # update_interval specifies over which interval to aggregate audio data
  # you can specify default update_interval on top level, but you can also
  # override it further by specifying it on sensor level
  update_interval: 1s           # default: 60s

  # buffer_size is in samples (not bytes), so for float data type
  # number of bytes will be buffer_size * 4
  buffer_size: 1024             # default: 1024

  # see your mic datasheet to find sensitivity and reference SPL.
  # those are used to convert dB FS to db SPL
  mic_sensitivity: -26dB        # default: empty
  mic_sensitivity_ref: 94dB     # default: empty

  # for flexibility sensors are organized hierarchically into groups.
  # each group can have any number of filters, sensors and nested groups.
  # for examples if there is a top level group A with filter A and nested
  # group B with filter B, then for sensors inside group B filters A
  # and then B will be applied:
  # groups:
  #   # group A
  #   - filters:
  #       - filter A
  #     groups:
  #       # group B
  #       - filters:
  #           - filter B
  #         sensors:
  #           - sensor X
  groups:
    - sensors:
        - type: eq
          name: Leq_1s

# END

The board ESP32 C6 8 Mb version :

nanoESP32-C6

@mafrosis
Copy link
Author

You can see the stackdump happens on a call to xTaskCreatePinnedToCore which is caused because you didn't specify task_core: 0 in your config (I mentioned this in the first PR message up top).

The ESP32s6 has only a single core, so the default task_core: 1 will not work

@trianglesis
Copy link

trianglesis commented Mar 24, 2025

Thanks for your time! I forgot that part trying all different approaches,

xTaskCreatePinnedToCore

Fixed in yaml here:

  # audio processing runs in a separate task, you can change its settings below
  task_stack_size: 4096         # default: 4096
  task_priority: 2              # default: 2
  # https://github.com/stas-sl/esphome-sound-level-meter/pull/39#issue-2931371576
  task_core: 0                  # default: 1

But still no luck, the crash is now happening right after the Wi-Fi is connected.

Trace

 (9601) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (9601) task_wdt:  - loopTask (CPU 0)
E (9601) task_wdt: Tasks currently running:
E (9601) task_wdt: CPU 0: sound_level_met
E (9601) task_wdt: Aborting.


Core  0 register dump:
MEPC    : 0x4002fa5a  RA      : 0x42012b82  SP      : 0x40830320  GP      : 0x408195a4  
TP      : 0x408303f0  T0      : 0x0000001d  T1      : 0x80000000  T2      : 0x0e87f969  
S0/FP   : 0x40825554  S1      : 0x000000af  A0      : 0x00b40000  A1      : 0x00001680  
A2      : 0xffffffef  A3      : 0xfffffff9  A4      : 0x00000000  A5      : 0x00000000  
A6      : 0x00800000  A7      : 0x00000000  S2      : 0x00000000  S3      : 0x40240000  
S4      : 0x40830354  S5      : 0x00000000  S6      : 0x00800000  S7      : 0x0e87f969  
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x00000000  T4      : 0x00000000  T5      : 0x00000000  T6      : 0x00000000  
MSTATUS : 0x00000000  MTVEC   : 0x00000000  MCAUSE  : 0x00000000  MTVAL   : 0x00000000  
MHARTID : 0x00000000  

Stack memory:
40830320: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x40825110 0x00000001 0x40824d88
40830340: 0x40825654 0x4082564c 0x4082546c 0x42012596 0x00000000 0x4083fa90 0x40840a90 0x40840a90
40830360: 0x00000000 0x40825430 0x4082542c 0x420125a0 0x00000001 0x4083daf4 0x4083eaf4 0x4083eaf4
40830380: 0x40824d84 0x40824d08 0x40825110 0x420126a2 0x00000000 0x00000000 0x00000000 0x40824d84
408303a0: 0x00000001 0x4083054c 0x4083154c 0x4083154c 0x00000000 0x00000000 0x00000000 0x00000000
408303c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408303e0: 0x00000000 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0xa5a5a5a5 0x00000150 0x408302a0 0x00000000
40830400: 0x4081d608 0x4081d608 0x408303f8 0x4081d600 0x00000017 0x4082cdfc 0x4082cdfc 0x408303f8
40830420: 0x00000000 0x00000002 0x4082f3f4 0x6e756f73 0x656c5f64 0x5f6c6576 0x0074656d 0x408303f0
40830440: 0x00000002 0x00000000 0x00000000 0x00000000 0x00000022 0x40822e58 0x40822ec0 0x40822f28
40830460: 0x00000000 0x00000000 0x00000001 0x00000000 0x00000000 0x00000000 0x420568f2 0x00000000
40830480: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408304a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408304c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408304e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830500: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830520: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830540: 0x00000000 0x00000000 0x00001000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830560: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830580: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408305a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408305c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408305e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830600: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830620: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830640: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830660: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830680: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408306a0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408306c0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
408306e0: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000
40830700: 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000 0x00000000

UPD:
To double-check, I've tried 0 and 1 to see if this will differ from the previous fail, and it is.
With a 0 core, it fails only after getting a Wi-Fi connection.

UPD2:
The issue is WiFi itself. Removing all networking from the config, and everything is working fine.

Debug log

[D][sensor:093]: 'ESP32_C6_2-mic Uptime': Sending state 86.32000 s with 0 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'ESP32_C6_2-mic Uptime': Sending state 96.30400 s with 0 decimals of accuracy
[W][component:237]: Component uptime.sensor took a long time for an operation (64 ms).
[W][component:238]: Components should block for at most 30 ms.
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy
[D][sensor:093]: 'LZeq_1s': Sending state -inf dB with 2 decimals of accuracy

UPD3:
Turning back network features one by one:

  • Wifi + API = starting IP, and as soon as it accepts Home Assistant connection (can see HA IP in the log) it crashes.
  • Wifi + WebServer (no HA API) = same
  • Just Wifi (no API, no webserver) = same

So, this is Wifi issue, I can't remember where I read about early ESPHome versions having issues with C6 wifi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants