PlatformIO Community

How to compile code with stm32 and PlatformIO on Arduino framework?

Hello, I don’t understand how to compile the library in platformIO, with Arduino framework with an STM32F103CBT6 bluepill. I have set genericSTM32F103CB in platformio.ini. I succeeded to test my LCD with an Arduino UNO and everything works fine. When I compile (GLUE_Demo_320x240) for the stm32 I have more than 1000 errors.

Do I need to define some macros when I use STM32?

Thank for all reply.

Have you been able to test the standard blink sketch with your blue pill? If not, that’s usually a good place to start to make sure that your toolchain is working fine. That sketch doesn’t use any specific libraries so obviously won’t test those.

Next up, are you using a library that is specific to the STM port of the Arduino framework? I assume this to be the case, but it’s possible you’ve installed an STM specific library rather than one for the Arduino framework, perhaps MBED?

I have a couple of Blue Pills (which I must get around to doing something with) and I use the MBED framework at the moment, but in my platformio.ini I have this:

platform = ststm32
board = bluepill_f103c8
framework = mbed

You will probably have the framework = arduino instead? I’ve tested my Blue Pill with the Arduino framework and code and it worked fine.

Can you post a link to the GLUE_Demo_320x240 code that you are using please? A Google search returned numerous versions all over the internet.

What library are you using in your lib_deps to talk to the LCD? Can you post your platformio.ini file please?


Assuming it is MCUFRIEND_kbv/GLUE_Demo_320x240.ino at master · prenticedavid/MCUFRIEND_kbv · GitHub, then I compile that sketch, placed as src\main.cpp using

platform = ststm32
board = bluepill_f103c8_128k
framework = arduino
lib_deps =
   adafruit/Adafruit GFX Library @ ^1.10.10
   adafruit/Adafruit BusIO @ ^1.7.5

In this case using board = genericSTM32F103CB will not work because the library tries to detect the used variant with the inherent target macros

The genericSTM32F103CB defines none of these macros, but bluepill_f103c8_128k does. You can open the mcufriend_shield.h file in VSCode and it will highlight you the actived or non-actived sections and the macros they depend on, then you’ll see what I mean.

Also note that the pinout used then is

Thank you for your enthusiastic reply, I used this code:
The LCD_ID_readreg.ino give me 0x4747 (for my LCD Screen seem to be an HX8347 driver) with both Arduino UNO and STM32F103CBT6 with both Arduino IDE and PlatformIO.
In PlatformIO there are not .ino file but only .cpp / .c / .h file.

Thank you for your reply, I will check it carefully.