Browse Source

🐛 Fix STM32 Pins Debugging (#22896)

ellensp 2 years ago
parent
commit
367c11dfa2
No account linked to committer's email address

+ 0
- 1
Marlin/src/HAL/DUE/pinsDebug.h View File

86
           || pwm_status(pin));
86
           || pwm_status(pin));
87
 }
87
 }
88
 
88
 
89
-
90
 void pwm_details(int32_t pin) {
89
 void pwm_details(int32_t pin) {
91
   if (pwm_status(pin)) {
90
   if (pwm_status(pin)) {
92
     uint32_t chan = g_APinDescription[pin].ulPWMChannel;
91
     uint32_t chan = g_APinDescription[pin].ulPWMChannel;

+ 29
- 18
Marlin/src/HAL/STM32/pinsDebug.h View File

79
 // make a list of the Arduino pin numbers in the Port/Pin order
79
 // make a list of the Arduino pin numbers in the Port/Pin order
80
 //
80
 //
81
 
81
 
82
-#define _PIN_ADD_2(NAME_ALPHA, ARDUINO_NUM) { {NAME_ALPHA}, ARDUINO_NUM },
83
 #define _PIN_ADD(NAME_ALPHA, ARDUINO_NUM) { NAME_ALPHA, ARDUINO_NUM },
82
 #define _PIN_ADD(NAME_ALPHA, ARDUINO_NUM) { NAME_ALPHA, ARDUINO_NUM },
84
 #define PIN_ADD(NAME) _PIN_ADD(#NAME, NAME)
83
 #define PIN_ADD(NAME) _PIN_ADD(#NAME, NAME)
85
 
84
 
108
 /**
107
 /**
109
  * Translation of routines & variables used by pinsDebug.h
108
  * Translation of routines & variables used by pinsDebug.h
110
  */
109
  */
111
-#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
110
+
111
+#if PA0 >= NUM_DIGITAL_PINS
112
+  #define HAS_HIGH_ANALOG_PINS 1
113
+#endif
114
+#define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS + TERN0(HAS_HIGH_ANALOG_PINS, NUM_ANALOG_INPUTS)
112
 #define VALID_PIN(ANUM) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
115
 #define VALID_PIN(ANUM) ((ANUM) >= 0 && (ANUM) < NUMBER_PINS_TOTAL)
113
 #define digitalRead_mod(Ard_num) extDigitalRead(Ard_num)  // must use Arduino pin numbers when doing reads
116
 #define digitalRead_mod(Ard_num) extDigitalRead(Ard_num)  // must use Arduino pin numbers when doing reads
114
 #define PRINT_PIN(Q)
117
 #define PRINT_PIN(Q)
164
   return pin_mode == MODE_PIN_OUTPUT || pin_mode == MODE_PIN_ALT;  // assume all alt definitions are PWM
167
   return pin_mode == MODE_PIN_OUTPUT || pin_mode == MODE_PIN_ALT;  // assume all alt definitions are PWM
165
 }
168
 }
166
 
169
 
167
-int8_t digital_pin_to_analog_pin(pin_t Ard_num) {
168
-  Ard_num -= NUM_ANALOG_FIRST;
169
-  return (Ard_num >= 0 && Ard_num < NUM_ANALOG_INPUTS) ? Ard_num : -1;
170
+int8_t digital_pin_to_analog_pin(const pin_t Ard_num) {
171
+  if (WITHIN(Ard_num, NUM_ANALOG_FIRST, NUM_ANALOG_FIRST + NUM_ANALOG_INPUTS - 1))
172
+    return Ard_num - NUM_ANALOG_FIRST;
173
+
174
+  const uint32_t ind = digitalPinToAnalogInput(Ard_num);
175
+  return (ind < NUM_ANALOG_INPUTS) ? ind : -1;
170
 }
176
 }
171
 
177
 
172
 bool IS_ANALOG(const pin_t Ard_num) {
178
 bool IS_ANALOG(const pin_t Ard_num) {
173
   return get_pin_mode(Ard_num) == MODE_PIN_ANALOG;
179
   return get_pin_mode(Ard_num) == MODE_PIN_ANALOG;
174
 }
180
 }
175
 
181
 
176
-bool is_digital(const pin_t x) {
177
-  const uint8_t pin_mode = get_pin_mode(pin_array[x].pin);
182
+bool is_digital(const pin_t Ard_num) {
183
+  const uint8_t pin_mode = get_pin_mode(pin_array[Ard_num].pin);
178
   return pin_mode == MODE_PIN_INPUT || pin_mode == MODE_PIN_OUTPUT;
184
   return pin_mode == MODE_PIN_INPUT || pin_mode == MODE_PIN_OUTPUT;
179
 }
185
 }
180
 
186
 
200
     SERIAL_ECHO_SP(7);
206
     SERIAL_ECHO_SP(7);
201
 
207
 
202
   // Print number to be used with M42
208
   // Print number to be used with M42
203
-  sprintf_P(buffer, PSTR(" M42 P%d "), Ard_num);
204
-  SERIAL_ECHO(buffer);
205
-  if (Ard_num < 10) SERIAL_CHAR(' ');
206
-  if (Ard_num < 100) SERIAL_CHAR(' ');
209
+  int calc_p = Ard_num % (NUM_DIGITAL_PINS + 1);
210
+  if (Ard_num > NUM_DIGITAL_PINS && calc_p > 7) calc_p += 8;
211
+  SERIAL_ECHOPGM(" M42 P", calc_p);
212
+  SERIAL_CHAR(' ');
213
+  if (calc_p < 100) {
214
+    SERIAL_CHAR(' ');
215
+    if (calc_p <  10)
216
+      SERIAL_CHAR(' ');
217
+  }
207
 }
218
 }
208
 
219
 
209
 bool pwm_status(const pin_t Ard_num) {
220
 bool pwm_status(const pin_t Ard_num) {
225
         case 'D' : alt_all = GPIOD->AFR[ind]; break;
236
         case 'D' : alt_all = GPIOD->AFR[ind]; break;
226
         #ifdef PE_0
237
         #ifdef PE_0
227
           case 'E' : alt_all = GPIOE->AFR[ind]; break;
238
           case 'E' : alt_all = GPIOE->AFR[ind]; break;
228
-        #elif defined (PF_0)
239
+        #elif defined(PF_0)
229
           case 'F' : alt_all = GPIOF->AFR[ind]; break;
240
           case 'F' : alt_all = GPIOF->AFR[ind]; break;
230
-        #elif defined (PG_0)
241
+        #elif defined(PG_0)
231
           case 'G' : alt_all = GPIOG->AFR[ind]; break;
242
           case 'G' : alt_all = GPIOG->AFR[ind]; break;
232
-        #elif defined (PH_0)
243
+        #elif defined(PH_0)
233
           case 'H' : alt_all = GPIOH->AFR[ind]; break;
244
           case 'H' : alt_all = GPIOH->AFR[ind]; break;
234
-        #elif defined (PI_0)
245
+        #elif defined(PI_0)
235
           case 'I' : alt_all = GPIOI->AFR[ind]; break;
246
           case 'I' : alt_all = GPIOI->AFR[ind]; break;
236
-        #elif defined (PJ_0)
247
+        #elif defined(PJ_0)
237
           case 'J' : alt_all = GPIOJ->AFR[ind]; break;
248
           case 'J' : alt_all = GPIOJ->AFR[ind]; break;
238
-        #elif defined (PK_0)
249
+        #elif defined(PK_0)
239
           case 'K' : alt_all = GPIOK->AFR[ind]; break;
250
           case 'K' : alt_all = GPIOK->AFR[ind]; break;
240
-        #elif defined (PL_0)
251
+        #elif defined(PL_0)
241
           case 'L' : alt_all = GPIOL->AFR[ind]; break;
252
           case 'L' : alt_all = GPIOL->AFR[ind]; break;
242
         #endif
253
         #endif
243
       }
254
       }

+ 7
- 7
Marlin/src/gcode/config/M43.cpp View File

313
 
313
 
314
   // 'P' Get the range of pins to test or watch
314
   // 'P' Get the range of pins to test or watch
315
   uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
315
   uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
316
-          last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1;
316
+          last_pin = parser.seenval('P') ? first_pin : TERN(HAS_HIGH_ANALOG_PINS, NUM_DIGITAL_PINS, NUMBER_PINS_TOTAL) - 1;
317
 
317
 
318
   if (first_pin > last_pin) return;
318
   if (first_pin > last_pin) return;
319
 
319
 
333
       if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
333
       if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
334
       pinMode(pin, INPUT_PULLUP);
334
       pinMode(pin, INPUT_PULLUP);
335
       delay(1);
335
       delay(1);
336
-        /*
337
-        if (IS_ANALOG(pin))
338
-          pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...]
339
-        else
340
-        //*/
341
-          pin_state[i - first_pin] = extDigitalRead(pin);
336
+      /*
337
+      if (IS_ANALOG(pin))
338
+        pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...]
339
+      else
340
+      //*/
341
+        pin_state[i - first_pin] = extDigitalRead(pin);
342
     }
342
     }
343
 
343
 
344
     #if HAS_RESUME_CONTINUE
344
     #if HAS_RESUME_CONTINUE

+ 2
- 2
buildroot/share/PlatformIO/variants/MARLIN_BIGTREE_OCTOPUS_PRO_V1_F429/variant.h View File

141
 #define PG15  111 //D79
141
 #define PG15  111 //D79
142
 
142
 
143
 // This must be a literal with the same value as PEND
143
 // This must be a literal with the same value as PEND
144
-#define NUM_DIGITAL_PINS        125
144
+#define NUM_DIGITAL_PINS        112
145
 // This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
145
 // This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
146
 #define NUM_ANALOG_INPUTS       13
146
 #define NUM_ANALOG_INPUTS       13
147
-#define NUM_ANALOG_FIRST        112
147
+#define NUM_ANALOG_FIRST        NUM_DIGITAL_PINS
148
 
148
 
149
 //#define ADC_RESOLUTION          12
149
 //#define ADC_RESOLUTION          12
150
 
150
 

+ 2
- 2
buildroot/share/PlatformIO/variants/MARLIN_BIGTREE_OCTOPUS_V1/variant.h View File

141
 #define PG15  111 //D79
141
 #define PG15  111 //D79
142
 
142
 
143
 // This must be a literal with the same value as PEND
143
 // This must be a literal with the same value as PEND
144
-#define NUM_DIGITAL_PINS        125
144
+#define NUM_DIGITAL_PINS        112
145
 // This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
145
 // This must be a literal with a value less than or equal to to MAX_ANALOG_INPUTS
146
 #define NUM_ANALOG_INPUTS       13
146
 #define NUM_ANALOG_INPUTS       13
147
-#define NUM_ANALOG_FIRST        112
147
+#define NUM_ANALOG_FIRST        NUM_DIGITAL_PINS
148
 
148
 
149
 //#define ADC_RESOLUTION          12
149
 //#define ADC_RESOLUTION          12
150
 
150
 

Loading…
Cancel
Save