Skip to content

Commit cc7fbab

Browse files
Serhiy-Kthinkyhead
authored andcommitted
Fix HAL/STM32 FastIO for analog pins (MarlinFirmware#19735)
1 parent 28a9708 commit cc7fbab

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Marlin/src/HAL/STM32/fastio.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ void FastIO_init(); // Must be called before using fast io macros
5151

5252
#if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx)
5353
#define _WRITE(IO, V) do { \
54-
if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \
55-
else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \
54+
if (V) FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BSRR = _BV32(STM_PIN(digitalPinToPinName(IO))) ; \
55+
else FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BRR = _BV32(STM_PIN(digitalPinToPinName(IO))) ; \
5656
}while(0)
5757
#else
58-
#define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO]) + ((V) ? 0 : 16)))
58+
#define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->BSRR = _BV32(STM_PIN(digitalPinToPinName(IO)) + ((V) ? 0 : 16)))
5959
#endif
6060

61-
#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO]))))
62-
#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO])))
61+
#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->IDR, _BV32(STM_PIN(digitalPinToPinName(IO)))))
62+
#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPinToPinName(IO))]->ODR ^= _BV32(STM_PIN(digitalPinToPinName(IO))))
6363

6464
#define _GET_MODE(IO)
6565
#define _SET_MODE(IO,M) pinMode(IO, M)

Marlin/src/HAL/STM32/pinsDebug_STM32duino.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
* It contains:
5252
* - name of the signal
5353
* - the Ard_num assigned by the pins_YOUR_BOARD.h file using the platform defines.
54-
* EXAMPLE: "#define KILL_PIN PB1" results in Ard_num of 57. 57 is then used as an
55-
* index into digitalPin[] to get the Port_pin number
54+
* EXAMPLE: "#define KILL_PIN PB1" results in Ard_num of 57. 57 is then used as the
55+
* argument to digitalPinToPinName(IO) to get the Port_pin number
5656
* - if it is a digital or analog signal. PWMs are considered digital here.
5757
*
5858
* pin_xref is a structure generated by this header file. It is generated by the
@@ -68,8 +68,6 @@
6868
* signal. The Arduino pin number is listed by the M43 I command.
6969
*/
7070

71-
extern const PinName digitalPin[]; // provided by the platform
72-
7371
////////////////////////////////////////////////////////
7472
//
7573
// make a list of the Arduino pin numbers in the Port/Pin order
@@ -137,7 +135,7 @@ const XrefInfo pin_xref[] PROGMEM = {
137135

138136
uint8_t get_pin_mode(const pin_t Ard_num) {
139137
uint32_t mode_all = 0;
140-
const PinName dp = digitalPin[Ard_num];
138+
const PinName dp = digitalPinToPinName(Ard_num);
141139
switch (PORT_ALPHA(dp)) {
142140
case 'A' : mode_all = GPIOA->MODER; break;
143141
case 'B' : mode_all = GPIOB->MODER; break;
@@ -218,7 +216,7 @@ bool pwm_status(const pin_t Ard_num) {
218216
void pwm_details(const pin_t Ard_num) {
219217
if (pwm_status(Ard_num)) {
220218
uint32_t alt_all = 0;
221-
const PinName dp = digitalPin[Ard_num];
219+
const PinName dp = digitalPinToPinName(Ard_num);
222220
pin_t pin_number = uint8_t(PIN_NUM(dp));
223221
const bool over_7 = pin_number >= 8;
224222
const uint8_t ind = over_7 ? 1 : 0;

0 commit comments

Comments
 (0)