adafruit / adafruit/Adafruit_Wippersnapper_Arduino

UART PM2.5 driver: crash, wrong publish tag, empty payload, missing ENV, single-read-per-cycle

Open
#950 2 comments 0 reactions 1 assignee Claimed by @tyeth View on GitHub
api-v2 uart
Dominant language
C++
Stars
54
Forks
56
Avg merge
2d 12h
Merged PRs (30d)
11

Description

### Component

UART / `drvUartPm25` (PM2.5 AQI driver)

### Summary

`drvUartPm25::begin()` dereferences `_pm25` without ever allocating it, causing a null-pointer dereference the first time a PM2.5 (PMS5003 / PM1006) sensor is added over UART. On ESP32-C5 this manifests as a **`Guru Meditation Error: Load access fault`** (`MCAUSE=5`, `A0=0x0`, `MTVAL=0x8`) roughly 3 s after the UART `Add` (immediately after the driver's boot delay), which then boot-loops the device.

### Details

In [`src/components/uart/drivers/drvUartPm25.h`](https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/blob/api-v2-pins-as-strings/src/components/uart/drivers/drvUartPm25.h), the member is declared but never constructed:

```cpp
bool begin() override {
delay(3 * ONE_SECOND_IN_MS); // wait for the sensor to boot
return _pm25->begin_UART(_hw_serial); // _pm25 is still nullptr here
}
// ...
Adafruit_PM25AQI *_pm25 = nullptr; // never assigned via new
```

The sibling I2C driver [`src/components/i2c/drivers/drvPm25.h`](https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/blob/api-v2-pins-as-strings/src/components/i2c/drivers/drvPm25.h) does the allocation correctly (`_pm25 = new Adafruit_PM25AQI();` at the top of `begin()`); the UART driver was simply missing that line. The existing destructor already `delete`s `_pm25`, so it always expected a heap instance.

### Steps to reproduce

1. Flash a build that includes the UART component.
2. Send a UART `Add` with `cfg_device.pm25aqi` (e.g. a PMS5003, PID 3686).
3. Device prints `[uart] Added PM2.5 AQI device!`, then panics ~3 s later.

Reproduced on HIL with a LilyGO T-Dongle C5 (ESP32-C5) and a PMS5003 on the UART0 pads:

```
[uart] Added PM2.5 AQI device!
Guru Meditation Error: Core 0 panic'ed (Load access fault). Exception was unhandled.
MCAUSE : 0x00000005 MTVAL : 0x00000008 A0 : 0x00000000
```

### Fix

Allocate `_pm25` in `begin()` before use, mirroring the I2C driver.

- Fix commit: https://github.com/adafruit/Adafruit_Wippersnapper_Arduino/commit/8ef2b4be3e83a6ca903ea1909e957c12701f29c4
- Included in #943 (base `api-v2-pins-as-strings`)
- Carried by #949 (LilyGO T-Dongle C5 board PR, rebased onto #943)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.