PlatformIO Community

Pio+stm32 links to wrong servo library. why?

project: GitHub - MarginallyClever/Makelangelo-firmware: CNC firmware for many different control boards and kinematic systems. Originally the brain of the Makelangelo art robot.
platformio.ini: ; PlatformIO Project Configuration File;; Build options: build flags, sour - Pastebin.com
I am building BIGTREE_SKR_PRO-Sixi3. The MCU is The board I have is an STM32F407ZG.

I have no lib_deps. The dependency scanner finds arduino-libraries/Servo 1.1.7. Then it fails to build and says

#error “This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor.”

which is clearly wrong. In the servo.h included by the dependency scanner I see

#elif defined(ARDUINO_ARCH_STM32F4)

Why pio didn’t define this as part of stm32+arduino? I tried to add it to my build flags (-DARDUINO_ARCH_STM32F4). Clean build produces

.pio\libdeps\BIGTREE_SKR_PRO-Sixi3\Servo\src/stm32f4/ServoTimers.h:34:10: fatal error: types.h: No such file or directory

Okay… I went looking for a solution elsewhere. Marlin has a build for the same board, so I tried that. It magically links to ststm32-core Servo library v 1.1.2 and it works! It works. Digging into their version it asks for inttypes.h. Marlin also has no mention of lib_deps=*servo* that I - or the Marlin people I talked with - can find.

My sanity is hanging by a thread and I’d really love for someone to show me why and how I’m wrong.
Why is my project linking to the wrong library when Marlin gets it right? How do I un-break this garbage?

Please and thank you,

I don’t even get into the position where I see that error – if I clone the Makelangelo-firmware repo and buld the BIGTREE_SKR_PRO environment (pio run -e BIGTREE_SKR_PRO) I have a lot of errors regarding macros it can’t find… and it attempting to access AVR peripheral registers on an STM32 chip…

src\motor.h:24:22: error: 'NUM_MOTORS' was not declared in this scope; did you mean 'ALL_MOTORS'?
   24 | #define NUM_MUSCLES (NUM_MOTORS + NUM_SERVOS)
      |                      ^~~~~~~~~~
src\motor.h:120:12: note: in expansion of macro 'NUM_MUSCLES'
  120 |   Muscle a[NUM_MUSCLES];
      |            ^~~~~~~~~~~
In file included from src\configure.h:105,
                 from src\gripper_hande.cpp:6:
..
src\motor.cpp:312:3: error: 'TCCR1A' was not declared in this scope
  312 |   TCCR1A = 0;
      |   ^~~~~~

Can you create a branch where everything is pre-configured and shows the error you’re having?

But what I can also say that by default, it chooses the correct Servo version. You can see that with a Advanced → Verbose Build or (or pio run -e BIGREE_SKR_PRO -v)

>pio run -e BIGTREE_SKR_PRO -v
Processing BIGTREE_SKR_PRO (platform: ststm32@~6.1.0; board: black_f407zg; framework: arduino; build_flags: -DHEADER_SKRPRO, -DPIO, -DUSB_PRODUCT=\"STM32F407ZG\", -DTARGET_STM32F4 -DSTM32F407_5ZX -DVECT_TAB_OFFSET=0x8000, -DUSBD_USE_CDC_COMPOSITE -DUSE_USB_FS; monitor_speed: 57600)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/black_f407zg.html
PLATFORM: ST STM32 (6.1.1) > Black STM32F407ZE
HARDWARE: STM32F407ZGT6 168MHz, 128KB RAM, 1MB Flash
DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
PACKAGES:
 - framework-arduinoststm32 4.10800.200207 (1.8.0)
 - toolchain-gccarmnoneeabi 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 10 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <SPI> 1.0 (C:\Users\Max\.platformio\packages\framework-arduinoststm32@4.10800.200207\libraries\SPI)
|-- <EEPROM> 2.0.1 (C:\Users\Max\.platformio\packages\framework-arduinoststm32@4.10800.200207\libraries\EEPROM)
|-- <SoftwareSerial> 1.0 (C:\Users\Max\.platformio\packages\framework-arduinoststm32@4.10800.200207\libraries\SoftwareSerial)
|-- <Wire> 1.0 (C:\Users\Max\.platformio\packages\framework-arduinoststm32@4.10800.200207\libraries\Wire)
|-- <Servo> 1.1.2 (C:\Users\Max\.platformio\packages\framework-arduinoststm32@4.10800.200207\libraries\Servo)
Building in release mode

See how Servo comes from the framework’s internal Servo library [...]\.platformio\packages\framework-arduinoststm32@4.10800.200207\libraries\Servo. No problems there.

@maxgerhardt interesting. I don’t get that error.

It seems the pre: script Marlin\buildroot\share\PlatformIO\scripts\generic_create_variant.py somehow makes platformio include the correct library. I am not well versed in what the script is doing, all i know is if I call it from my code everything works. :upside_down_face: