STM32Fx : Librairy STM32_ISR_Servo works only on PCx pins

Hello

Core : STM32 MCU based board by STMicro v2.2.0
Boards : bluepill copy with original STM32F103T8C6, Blackpill F411CEU, STM32F030T8C6 board

I'm trying to drive servo with the STM32_ISR_Servo librairy.
As i was having no result at all, i simply copy/paste the example code for mutiple servo that's here and only changed the SERVO_PIN_# definition to try every pins.
On STM32F103 and STM32F030, none of them work.
On the blackpill with STM32F411, the pins PC14, PC15 and PC16 only works (there's no PC# pins on the 2 other boards).

Here's the full code :

 #if !( defined(STM32F0) || defined(STM32F1) || defined(STM32F2) || defined(STM32F3)  ||defined(STM32F4) || defined(STM32F7) || \ 
        defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32H7)  ||defined(STM32G0) || defined(STM32G4) || \ 
        defined(STM32WB) || defined(STM32MP1) || defined(STM32L5)) 
   #error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting. 
 #endif 
  
 #define TIMER_INTERRUPT_DEBUG       0 
 #define ISR_SERVO_DEBUG             1 
  
 // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error 
 #include "STM32_ISR_Servo.h" 
  
 // Default is TIMER_SERVO (TIM7 for many boards) 
 #define USE_STM32_TIMER_NO          TIMER_SERVO 
  
 // Published values for SG90 servos; adjust if needed 
 #define MIN_MICROS        800  //544 
 #define MAX_MICROS        2450 
  
 #define SERVO_PIN_1       PC14 
 #define SERVO_PIN_2       PC13 
 #define SERVO_PIN_3       PC15
 #define SERVO_PIN_4       A0 
 #define SERVO_PIN_5       PB1 
 #define SERVO_PIN_6       A8 
  
 typedef struct 
 { 
   int     servoIndex; 
   uint8_t servoPin; 
 } ISR_servo_t; 
  
 #if ( defined(STM32L0) || defined(STM32L1) || defined(STM32L4) || defined(STM32L5) ) 
   #define NUM_SERVOS        3 
   ISR_servo_t ISR_servo[NUM_SERVOS] = 
   { 
     { -1, SERVO_PIN_1 }, { -1, SERVO_PIN_2 }, { -1, SERVO_PIN_3 } 
   }; 
 #else 
   #define NUM_SERVOS        6 
   ISR_servo_t ISR_servo[NUM_SERVOS] = 
   { 
     { -1, SERVO_PIN_1 }, { -1, SERVO_PIN_2 }, { -1, SERVO_PIN_3 }, { -1, SERVO_PIN_4 }, { -1, SERVO_PIN_5 }, { -1, SERVO_PIN_6 } 
   }; 
 #endif 
  
 void setup() 
 { 
   Serial.begin(115200); 
   while (!Serial); 
  
   delay(200); 
  
   Serial.print(F("\nStarting STM32_MultipleServos on ")); Serial.println(BOARD_NAME); 
   Serial.println(STM32_ISR_SERVO_VERSION); 
  
   //Select STM32 timer USE_STM32_TIMER_NO 
   STM32_ISR_Servos.useTimer(USE_STM32_TIMER_NO); 
  
   for (int index = 0; index < NUM_SERVOS; index++) 
   { 
     ISR_servo[index].servoIndex = STM32_ISR_Servos.setupServo(ISR_servo[index].servoPin, MIN_MICROS, MAX_MICROS); 
  
     if (ISR_servo[index].servoIndex != -1) 
     { 
       Serial.print(F("Setup OK Servo index = ")); Serial.println(ISR_servo[index].servoIndex); 
     } 
     else 
     { 
       Serial.print(F("Setup Failed Servo index = ")); Serial.println(ISR_servo[index].servoIndex); 
     } 
   } 
 } 
  
 void loop() 
 { 
   int position;      // position in degrees 
  
   for (position = 0; position <= 180; position += 5) 
   { 
     // goes from 0 degrees to 180 degrees 
     // in steps of 1 degree 
     for (int index = 0; index < NUM_SERVOS; index++) 
     { 
       STM32_ISR_Servos.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180 ); 
     } 
     // waits 1s for the servo to reach the position 
     delay(200); 
   } 
  
   for (position = 180; position >= 0; position -= 5) 
   { 
     // goes from 0 degrees to 180 degrees 
     // in steps of 1 degree 
     for (int index = 0; index < NUM_SERVOS; index++) 
     { 
       STM32_ISR_Servos.setPosition(ISR_servo[index].servoIndex, (position + index * (180 / NUM_SERVOS)) % 180); 
     } 
     // waits 1s for the servo to reach the position 
     delay(200); 
   } 
  
   delay(200); 
 } 

Note that on this board, the serial link doesn't work so i can't see debugging infos

Any help to understand would be great !

Original code:

#define SERVO_PIN_1 D1
#define SERVO_PIN_2 D2
#define SERVO_PIN_3 D3
#define SERVO_PIN_4 D4
#define SERVO_PIN_5 D5
#define SERVO_PIN_6 D6

The original code uses references that exist on the Arduino platform, for example D1, D2 etc. but in your code there is a reference that the STM32 uses, that is, it is PC14, PC13 etc. Could it be that instead of using PC14 you have to use C14?

The pin mapping that I came up with:

Arduino pin  2 = B7
Arduino pin  3 = B6
Arduino pin  4 = B5
Arduino pin  5 = B4
Arduino pin  6 = B3
Arduino pin  7 = A15
Arduino pin  8 = A12
Arduino pin  9 = A11
Arduino pin 10 = A10
Arduino pin 11 = A9
Arduino pin 12 = A8
Arduino pin 13 = B15
Arduino pin 14 = B14
Arduino pin 15 = B13
Arduino pin 16 = null
Arduino pin 17 = C13, onboard led, input only.
Arduino pin 18 = C14
Arduino pin 19 = C15
Arduino pin 20 = A0
Arduino pin 21 = A1
Arduino pin 22 = A2
Arduino pin 23 = A3
Arduino pin 24 = A4
Arduino pin 25 = A5
Arduino pin 26 = A6
Arduino pin 27 = A7
Arduino pin 28 = B0
Arduino pin 29 = B1
Arduino pin 30 = B10
Arduino pin 31 = B11

Note that according to the datasheet, pin C13 (PC13) is the tamper-RTC pin and as such is low current input. The pattern set by the sketch is reversed. See notes 5 and 6 in the Pinouts and pin description of the datasheet.

Also note that Arduino pin 17 returned NO pin associated with it on the blue pill, and blue pill pin B12 is absent from the listing.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.