Commit e097c11
fix: analogWrite() silently fails when PWM pin lookup fails on Uno Q
On Arduino Uno Q, calling analogWrite() on any pin silently returns
without doing anything in two cases:
1. When pwm_pin_index() cannot find the pin in the arduino_pwm_pins[]
lookup table (idx >= ARRAY_SIZE(arduino_pwm))
2. When pwm_is_ready_dt() returns false for the PWM device
This causes analogWrite() to appear completely broken to users - no
output, no error, no warning. The function just silently does nothing.
The pwm-pin-gpios mapping in the Uno Q device tree overlay is missing
some pins (D0, D1, D4 are absent or commented out). This means
pwm_pin_index() returns (size_t)-1 for those pins, which is always
>= ARRAY_SIZE(arduino_pwm), causing an immediate silent return.
Added a digitalWrite() fallback in both early-return paths:
- If PWM lookup fails → fall back to digitalWrite HIGH/LOW
- If PWM device not ready → fall back to digitalWrite HIGH/LOW
This ensures analogWrite() always produces some output even when
hardware PWM is unavailable, which is consistent with how other
Arduino cores handle non-PWM pins.
Tested on Arduino Uno Q with:
- Motor driver (SmartElex L298N integrated board)
- Confirmed analogWrite() was completely silent before fix
- Confirmed digitalWrite() fallback works correctly after fix
- Pins tested: 3, 4, 5, 6, 7, 8, 9, 10
- No breaking changes
- Existing PWM functionality unchanged
- Non-PWM pins now behave like standard Arduino (HIGH if value > 127)
- Fixes user confusion when analogWrite() silently does nothing
Co-Authored-by: Satvik <145106491+vs11official@users.noreply.github.com>
Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>1 parent c41892c commit e097c11
1 file changed
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
| 484 | + | |
| 485 | + | |
484 | 486 | | |
485 | 487 | | |
486 | 488 | | |
487 | 489 | | |
| 490 | + | |
| 491 | + | |
488 | 492 | | |
489 | 493 | | |
490 | 494 | | |
| |||
0 commit comments