From b06ba1d2396ab0514b8103d4743e601dc17d84c3 Mon Sep 17 00:00:00 2001 From: "Vitor Moreno B. Sales" Date: Mon, 13 Jan 2025 13:29:20 -0300 Subject: [PATCH 1/2] Fix dead lock with pin above NUM_DIGITAL_PINS Penalty for the check should be a single instruction for pin numbers below NUM_DIGITAL_PINS, 9 for pin numbers between PNUM_ANALOG_BASE and NUM_ANALOG_INTERNAL_FIRST. Tests done on a Black F407VE board --- cores/arduino/wiring_digital.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 5840435c1a..4cf9957277 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -78,17 +78,28 @@ void pinMode(uint32_t ulPin, uint32_t ulMode) void digitalWrite(uint32_t ulPin, uint32_t ulVal) { - digitalWriteFast(digitalPinToPinName(ulPin), ulVal); + PinName p = digitalPinToPinName(ulPin); + if (p != NC) { + digitalWriteFast(p, ulVal); + } } int digitalRead(uint32_t ulPin) { - return digitalReadFast(digitalPinToPinName(ulPin)); + PinName p = digitalPinToPinName(ulPin); + + if (p == NC) { + return 0; + } + return digitalReadFast(p); } void digitalToggle(uint32_t ulPin) { - digitalToggleFast(digitalPinToPinName(ulPin)); + PinName p = digitalPinToPinName(ulPin); + if (p != NC) { + digitalToggleFast(digitalPinToPinName(ulPin)); + } } #ifdef __cplusplus From 801402702f00f6b7571c6594bbeba27c81bd1645 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 14 Jan 2025 10:22:30 +0100 Subject: [PATCH 2/2] fixup: only one return Signed-off-by: Frederic Pillon --- cores/arduino/wiring_digital.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 4cf9957277..4141772835 100644 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -88,10 +88,7 @@ int digitalRead(uint32_t ulPin) { PinName p = digitalPinToPinName(ulPin); - if (p == NC) { - return 0; - } - return digitalReadFast(p); + return (p == NC) ? 0 : digitalReadFast(p); } void digitalToggle(uint32_t ulPin)