Bluepill_f103c8 can't use the arduino libraries (like servo.h) in PlattformIO but it works in the arduino IDE

Hi,
I’m not sure why exactly but whenever I try to use some basic libraries from the arduino framework they never are supported. I’m using an bluepill_f103c8 with STM32duino (or atleast I think that what it’s using)
This is my configuration:
image
I always get an compile error:

.pio\libdeps\bluepill_f103c8\Servo\src/Servo.h:77:2: error: #error "This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor."

Which is weird, because when I copy&paste my code to the Arduino IDE it compiles without any problem for that board. I’m only trying to use the <Servo.h> library.

My current guess is that STM32Duino isn’t really targeted due to a misconfiguration, though in another thread the addition of board_build.core fixed the issue which sadly didn’t help on my end.

Any help is appreciated!

I suspect you have been misled by the Arduino IDE when it comes to libraries. When you “add library” there, all that happens is a #include is added to your code.

At the build stage, the IDE works out which libraries you asked for,compiles them from source, and links them with your sketch to create the executable.

In PlatformIO you need to add the library using the home page, or – my preferred method – using lib_deps in platformio.ini.

If the library is built in, as Servo should be:

lib_deps = servo

Should do the necessary. If the library is not built in, search for it on the home page or on PlatformIO Registry where you will be able to specify the name and platform to get suitable results.

Pick one, click the examples, installation and headers tabs for instructions and examples.

HTH

Cheers,
Norm.

Well yeah I tried that out, but it still picks the “wrong” servo library :frowning:
All servo libraries that are in the registry either don’t work or also show the same compability issue (even if they show compability to my plattform ).

I’m not exactly sure where the Arduino IDE + STM32Duino picks out their servo library but whatever the stm32duino version/implementation in PlattformIO does it’s not compatible at all to all other libraries. (even normal arduino ones that don’t use any hardware specific features.)

Allowed core values are only stm32 or maple. ststm32 is an unknown core.

Works for me with the basic platformio.ini

[env:bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino

and code

#include "Arduino.h"
#include <Servo.h>

Servo myservo;

#define POT_PIN 0

void setup()
{
  myservo.attach(9);
}

void loop()
{
  int val = analogRead(POT_PIN);        // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);              // sets the servo position according to the scaled value
  delay(15);                       // waits for the servo to get there
}

the LDF will pick up the internal library automatically since it sees #include<Servo.h> in the main file.

(verbose build output)

LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 13 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Servo> 1.1.2 (C:\Users\Max\.platformio\packages\framework-arduinoststm32\libraries\Servo)
Building in release mode

I’d suggest to reproduce my config and remove the .pio folder of the project completely and rebuild.

that’s weird, I created a new project, entered your settings in plattform.ini and copied your code in main.cpp.

But for some reason I still get this:

/Servo.h:77:2: error: #error “This library only supports boards with an AVR, SAM, SAMD, NRF52 or STM32F4 processor.”

That’s weird

What’s the output for a “Verbose Build”? (https://hastebin.com/ if too long)

If you mean the library it picks:
image

I think that’s the latest servo.h library on the registry but not the one in the STM32duino core like yours

The full verbose output in text, I meant, copy pasted. Project tasks -> Advanced -> Verbose Build.

Processing bluepill_f103c8 (platform: ststm32; board: bluepill_f103c8; framework - Pastebin.com this should be everything. I’m using the latest PIO and all libraries/plattforms are updated

Aha, I suspected that.

Dependency Graph
|-- <Servo> 1.1.7 (C:\Users\Soland\.platformio\lib\Servo)

You’ve globally installed the general Arduino (AVR etc…) version of the Servo library. This will overshadow the correct Servo library from the framework.

To fix the error, please remove the Servo library from the global storage. Removing the folder C:\Users\Soland\.platformio\lib\Servo should suffice.

This is why global library dependencies are dangerous – I’d promote strict per-project library management per lib_deps without global libraries because of this.

1 Like

okay this is embarassing :sweat_smile:

I can’t even remember on which project I did that and how many years ago that was.
Yeah I did that in the beginning, I’m always using the per-project settings on current projects to avoid this problem :joy:.

THANK YOU so much!

Don’t worry!

From version 5.x.x of PlatformIO, global libraries went away – for this reason! Plus, library names got a “vendor” part to distinguish between libraries with thd same name.

Takes a bit of getting used to. :wink:

Cheers,
Norm.

Yeah i used global libraries back then because adding it to a specific project wasn’t automatic and a bit cumbersome. Though back then it was mostly with small projects.

It’s adding everything automatically now which is amazing (I mean like the lib_deps stuff)

1 Like