From aa901ac4a2b87079777280aa678b82294b9d9bee Mon Sep 17 00:00:00 2001
From: Serhiy-K <52166448+Serhiy-K@users.noreply.github.com>
Date: Sat, 17 Oct 2020 00:21:21 +0300
Subject: [PATCH] Fix HAL/STM32 FastIO for analog pins (#19735)

---
 Marlin/src/HAL/STM32/fastio.h               | 10 +++++-----
 Marlin/src/HAL/STM32/pinsDebug_STM32duino.h | 10 ++++------
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/Marlin/src/HAL/STM32/fastio.h b/Marlin/src/HAL/STM32/fastio.h
index f000d68cf0..ea28b8f3bf 100644
--- a/Marlin/src/HAL/STM32/fastio.h
+++ b/Marlin/src/HAL/STM32/fastio.h
@@ -51,15 +51,15 @@ void FastIO_init(); // Must be called before using fast io macros
 
 #if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx)
   #define _WRITE(IO, V) do { \
-    if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \
-    else   FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR  = _BV32(STM_PIN(digitalPin[IO])) ; \
+    if (V) FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BSRR = _BV32(STM_PIN(digitalPinToPinName(IO))) ; \
+    else   FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BRR  = _BV32(STM_PIN(digitalPinToPinName(IO))) ; \
   }while(0)
 #else
-  #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + ((V) ? 0 : 16)))
+  #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BSRR = _BV32(STM_PIN(digitalPinToPinName(IO)) + ((V) ? 0 : 16)))
 #endif
 
-#define _READ(IO)               bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO]))))
-#define _TOGGLE(IO)             (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO])))
+#define _READ(IO)               bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->IDR, _BV32(STM_PIN(digitalPinToPinName(IO)))))
+#define _TOGGLE(IO)             (FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->ODR ^= _BV32(STM_PIN(digitalPinToPinName(IO))))
 
 #define _GET_MODE(IO)
 #define _SET_MODE(IO,M)         pinMode(IO, M)
diff --git a/Marlin/src/HAL/STM32/pinsDebug_STM32duino.h b/Marlin/src/HAL/STM32/pinsDebug_STM32duino.h
index 09f2bb54e6..71480153a7 100644
--- a/Marlin/src/HAL/STM32/pinsDebug_STM32duino.h
+++ b/Marlin/src/HAL/STM32/pinsDebug_STM32duino.h
@@ -51,8 +51,8 @@
  *  It contains:
  *    - name of the signal
  *    - the Ard_num assigned by the pins_YOUR_BOARD.h file using the platform defines.
- *        EXAMPLE:  "#define KILL_PIN  PB1" results in Ard_num of 57.  57 is then used as an
- *                  index into digitalPin[] to get the Port_pin number
+ *        EXAMPLE:  "#define KILL_PIN  PB1" results in Ard_num of 57.  57 is then used as the
+ *                  argument to digitalPinToPinName(IO) to get the Port_pin number
  *    - if it is a digital or analog signal.  PWMs are considered digital here.
  *
  *  pin_xref is a structure generated by this header file.  It is generated by the
@@ -68,8 +68,6 @@
  *          signal.  The Arduino pin number is listed by the M43 I command.
  */
 
-extern const PinName digitalPin[];  // provided by the platform
-
 ////////////////////////////////////////////////////////
 //
 // make a list of the Arduino pin numbers in the Port/Pin order
@@ -137,7 +135,7 @@ const XrefInfo pin_xref[] PROGMEM = {
 
 uint8_t get_pin_mode(const pin_t Ard_num) {
   uint32_t mode_all = 0;
-  const PinName dp = digitalPin[Ard_num];
+  const PinName dp = digitalPinToPinName(Ard_num);
   switch (PORT_ALPHA(dp)) {
     case 'A' : mode_all = GPIOA->MODER; break;
     case 'B' : mode_all = GPIOB->MODER; break;
@@ -218,7 +216,7 @@ bool pwm_status(const pin_t Ard_num) {
 void pwm_details(const pin_t Ard_num) {
   if (pwm_status(Ard_num)) {
     uint32_t alt_all = 0;
-    const PinName dp = digitalPin[Ard_num];
+    const PinName dp = digitalPinToPinName(Ard_num);
     pin_t pin_number = uint8_t(PIN_NUM(dp));
     const bool over_7 = pin_number >= 8;
     const uint8_t ind = over_7 ? 1 : 0;