arduino / arduino/ArduinoCore-samd

Arduino hangs when reading from non-existent pins.

Open
#674 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
502
Forks
740
PR merge metrics
No merged PRs in 30d

Description

the hang happens in the function pinPeripheral in the file wiring_private.c at line 96 or 105 (it changes depending on an if statement) when the function tries to multiplex the pin number.

this can be easily fixed by adding the code below to the analogRead function at line 135 in the file wiring_analog.c
```
if (g_APinDescription[pin].ulPinType != PIO_ANALOG){
return -1;
}
```
this will check if the pin is an analog pin before trying to read/multiplex it.

you can read more on the Arduino forums [here](https://forum.arduino.cc/t/mkr-zero-freezes-when-i-try-to-read-a-non-existent-pin/1006258).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in wiring_analog.c around analogRead at line 135, then inspect the pin multiplexing path in wiring_private.c around line 96 or 105. Reproduce an analogRead on a non-existent pin and verify that it returns -1 without hanging or attempting invalid multiplexing.

Written by the indexing model from the issue text.

Assessment

Tech stack
arduino, c
Domain
embedded-iot
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.