How to compile MySensors on Platformio for Blue Pill



  • Hello.
    I am trying to change to PlatformIO, which has many advantages over Arduino IDE. I want to compile for the STM32 Blue Pill module but have not been able to get the right configuration. I have found many suggestions but have not gotten any to work. At one point I got a compile, but it ignored the MySensors code.

    Can some one please post their working platformio.ini, and are there any detailed instructions anywhere for the exact configuration such as which STM32 library to use?

    I have spent days researching and tried things like;
    board_build.core = maple
    Using a Python script to get rid of multiple main/premain error
    Other Platform & Board options. (such as genericSTM, etc)
    But cant seem to get the right mix.

    Thank you for anyone who can help.

    Also, I have been using MySensors for over 5 years: this is a great system, a great website, has great admin, and a fantastic group of contributors. Thank you all very much for MySensors!

    ++++++++++++++++++++++++++++++++
    [ Below is a sample of the various options I have tried in an experimental platformio.ini. None worked.]

    ;[env:bluepill_f103c8]
    ;platform = ststm32
    ;board = bluepill_f103c8
    ;framework = arduino
    ;upload_protocol = stlink

    ; NOTE - Above lines are not acceptable to MySensors on Blue Pill. Must use maple as shown below.

    ; NOTE - In Platfromio docs, Maple is a different processor
    ;[env:maple]
    ;platform = ststm32
    ;board = maple
    ;framework = arduino
    ;upload_protocol = stlink

    ; NOTE - The below was found when searching the net. It appears an alternative set of ENV entries.
    [env:genericSTM32F103C8]
    platform = ststm32
    board = genericSTM32F103C8
    framework = arduino
    board_build.core = maple
    ;lib_extra_dirs = D:\Dropbox\Elektronik\platformio\libraries
    ;lib_deps = https://github.com/mysensors/MySensors.git#development
    upload_protocol = stlink

    ; Serial Monitor options
    monitor_speed = 115200



  • Hi @novicit ,
    I was just trying to test a BluePill adding a LoRa chip (SX1276) as a new type of MySensors node but got blocked in the first step (no compiling when I include MySensors library).
    In PlatoformIO I installed the default platform (STSTM32). Sorry I cannot give you a solution,...
    Did you get MySensors to compile in the Arduino environment with STM32? (planning to give it a try if it works). Which boards definition?.
    If you are interested I could post the compiler output, but I believe is of no use to you since I have not digged much into the issue. I have used ESP32 and ATmega328 variants in the past with MySensors but wanted to give a try to STM32 architecture as it seems quite promissing when dealing with Analog signals (ADC specs), so I am still at the begginin of the journey...



  • @CarloMagno If you are successful to implement MySensors on the Blue Pill, please post your method. Thank you!

    I have spent 2 weeks on this and remain unable to compile MySensors for the Blue Pill. I can compile and download programs to the BP on both PlatformIO and Arduino IDE, but as soon as I put #include <mysensors.h> in the code, errors appear. I have found these errors on some forum entries, but a clear step-by-step solution method which works has not yet been posted (that I have found).

    I am no expert on coding, so I assume I am missing something.



  • Well, I have tried the Arduino IDE both with the current stable version of MySensors and with the Development version. In both cases i get a HAL error:

    In file included from C:\Users\xxxxx\Documents\Arduino\STM32_MySensors_Test1_v0\STM32_MySensors_Test1_v0.ino:56:
    C:\Users\xxxxx\Documents\Arduino\libraries\MySensors-development/MySensors.h:83:2: error: #error Hardware abstraction not defined (unsupported platform)
       83 | #error Hardware abstraction not defined (unsupported platform)
          |  ^~~~~
    exit status 1
    Error compiling for board Generic STM32F1 series.
    

    Line 56 of the sketch is

    #include <MySensors.h>
    

    So it seems it is related to the compatibility of the official STM32 core provided by ST and the MySensors library. I believe I have read somewhere that the successful implementation of MySensors and STM32 was using another core... I have to dig a little bit more about it. Nevertheless. I'd rather use the ST "official" core as it seems it supports a great number of board and is in continuous development, so new boards that appear could be ready to use... (Cube Cell looks really nice but integrates another type of LoRa radio that I believe will require quite more work from MySensors to get it supported).



  • I will answer to myself... forcing the architecture in the sketch including this line before MySensors (it should be picked automatically but it seems it's not):

    #define ARDUINO_ARCH_STM32F1
    #include <MySensors.h>
    

    The error now goes to the hardware definition where indeed it seems it expects to have the maple core:

    In file included from C:\Users\xxxxx\Documents\Arduino\libraries\MySensors-development/hal/architecture/STM32F1/MyHwSTM32F1.cpp:20,
                     from C:\Users\xxxxx\Documents\Arduino\libraries\MySensors-development/MySensors.h:71,
                     from C:\Users\xxxxx\Documents\Arduino\STM32_MySensors_Test1_v0\STM32_MySensors_Test1_v0.ino:56:
    C:\Users\xxxxx\Documents\Arduino\libraries\MySensors-development/hal/architecture/STM32F1/MyHwSTM32F1.h:23:10: fatal error: libmaple/iwdg.h: No such file or directory
       23 | #include <libmaple/iwdg.h>
          |          ^~~~~~~~~~~~~~~~~
    compilation terminated.
    
    exit status 1
    Error compiling for board Generic STM32F1 series.
    

    I quick search pointed to the Roger Clark github repository (it seems it is the origin of STM32 support in Arduino IDE) https://github.com/rogerclarkmelbourne/Arduino_STM32
    I downloaded the zip file with the repository, created a hardware folder in MyDocuments/arduino folder (it did't exist), and decompressed the zip there. The folder structure is as follows:
    C:\Users\xxxxx\Documents\Arduino\hardware\Arduino_STM32-master

    I closed the Arduino IDE and opened it again so the new boards definition would be available, and in the type of board, under the new group "STM32F1 Boards (STM32duino.com)" I selected the board type "Generic STM32F103C series" and everything compiles OK, (with or without the line #define ARDUINO_ARCH_STM32F1

    Now I have to check if following the indication in https://docs.platformio.org/en/latest/platforms/ststm32.html, including the option "board_build.core = maple" in platformio.ini the compilation will force to use the maple core that seems the one working with MySensors.



  • .. still no luck in Platformio.
    platformio.ini:

    [env:genericSTM32F103CB]
    platform = ststm32
    board = genericSTM32F103CB
    framework = arduino
    board_build.core = maple
    monitor_speed = 115200
    monitor_filters = time, default
    
    [env:Sensor-Serial-Windows]
    upload_port = COM7
    monitor_port = COM7
    
    [env:Sensor-Serial-Linux]
    ; any port that starts with /dev/ttyUSB
    upload_port = /dev/ttyUSB*
    monitor_port = /dev/ttyUSB*
    

    After some warnings regarding definition of SPI2 and not been used, we get to the error when MySensors is included:

    Compiling .pio\build\genericSTM32F103CB\lib5ec\MySensors_ID548\MyASM.S.o
    Archiving .pio\build\genericSTM32F103CB\lib473\libEEPROM.a
    Archiving .pio\build\genericSTM32F103CB\libd15\libSPI.a
    Archiving .pio\build\genericSTM32F103CB\lib5ec\libMySensors_ID548.a
    Linking .pio\build\genericSTM32F103CB\firmware.elf
    .pio\build\genericSTM32F103CB\src\main.cpp.o: In function `premain()':
    main.cpp:(.text.startup._Z7premainv+0x0): multiple definition of `premain()'
    .pio\build\genericSTM32F103CB\FrameworkArduino\main.cpp.o:main.cpp:(.text.startup._Z7premainv+0x0): first defined here        
    .pio\build\genericSTM32F103CB\src\main.cpp.o: In function `main':
    main.cpp:(.text.startup.main+0x0): multiple definition of `main'
    .pio\build\genericSTM32F103CB\FrameworkArduino\main.cpp.o:main.cpp:(.text.startup.main+0x0): first defined here
    collect2.exe: error: ld returned 1 exit status
    *** [.pio\build\genericSTM32F103CB\firmware.elf] Error 1
    ================================================ [FAILED] Took 19.66 seconds ================================================
    

    For what I understand of the error... (nothing)... It seems it will take me quite some time to go any further... At least Arduino IDE is working and I can start testing the Radio with that.



  • @CarloMagno Thank you for putting up your experience and success with the Arduino IDE. It appears we did many of the same steps. I also ran into the HAL error, tried the #define ARDUINO_ARCH..., and failed. Also tried the Roger Clark version and id not get that to run. Today I took an older PC and clean installed the IDE and Roger Clark core as you described and SUCCESS, was able to compile MySensors. There must be something wrong with my configuration on my main PC.

    The "official" core is also my preference as it is available on PlatformIO. And there are libraries available for it that may not run on Roger's. For example I have read there is a sleep/low power library for Blue Pill that only runs on the STM32 "official" core (I have not tested that). I might take another try at getting PlatformIO to work with Roger Clarks core but we are getting to the fringes of my technical skills.

    In either case, I am very happy to be able to compile MySensors for the Blue Pill. Essentially same cost and size of the Pro Mini, but so much more capable. I have a number of applications it will fit perfectly for.

    If I make any progress on PlatformIO, will post here.



  • @CarloMagno Forgot to mention, in my clean install I created - the directory you described and did not work for me. Instead I just dropped the RogerClark core folder in the regular Arduino hardware folder and it worked. Program Files(x86)\Arduino\hardware\Arduino_STM32-master. The arduino IDE read it fine along with all its native hardware folders.



  • You need to either use unofficial stm32 core which is what Mysensors port is built upon, or to make a new port which will be compatible with official core. I looked into this and it seems feasible for me to accomplish. I am now working on a node with STM32, so I will try to make it work.


  • Mod

    @monte have you seen https://github.com/mysensors/MySensors/pull/1422 ? Maybe that is a good way forward for stm32 support.

    KooLru created this issue in mysensors/MySensors

    open Add STM32 cores support #1422



  • @novicit said in How to compile MySensors on Platformio for Blue Pill:

    @CarloMagno Forgot to mention, in my clean install I created - the directory you described and did not work for me. Instead I just dropped the RogerClark core folder in the regular Arduino hardware folder and it worked. Program Files(x86)\Arduino\hardware\Arduino_STM32-master. The arduino IDE read it fine along with all its native hardware folders.

    ...It could be because I used the ZIP file to install the Arduino IDE instead of the windows installer... good to point if someone else faces the same problems.



  • @monte , @mfalkvidd ... Fantastic!!, is good to know that there there is development to support the official ST Core, for sure it will provide much better future stability with the new hardware from ST.


Log in to reply
 

Suggested Topics

  • 30
  • 14
  • 2
  • 5
  • 28
  • 2
  • 7
  • 2

7
Online

9.4k
Users

10.0k
Topics

104.3k
Posts