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] 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