Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. How to compile MySensors on Platformio for Blue Pill

How to compile MySensors on Platformio for Blue Pill

Scheduled Pinned Locked Moved Troubleshooting
24 Posts 5 Posters 284 Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N novicit

    @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.

    C Offline
    C Offline
    CarloMagno
    wrote on last edited by
    #11

    @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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      CarloMagno
      wrote on last edited by
      #12

      @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.

      1 Reply Last reply
      0
      • mfalkviddM mfalkvidd

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

        monteM Offline
        monteM Offline
        monte
        wrote on last edited by
        #13

        @mfalkvidd I guess this will make the code compile, but I was going to implement at least the same functionality that is present with current port. Nice to see that someone else is also working on it :)

        mfalkviddM 1 Reply Last reply
        0
        • monteM monte

          @mfalkvidd I guess this will make the code compile, but I was going to implement at least the same functionality that is present with current port. Nice to see that someone else is also working on it :)

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #14

          @monte I can't judge the quality or completeness of the suggested code contribution unfortunately.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            novicit
            wrote on last edited by
            #15

            @CarloMagno I have now compiled 2 small test programs, using RogerClarks core. I was very surprised as both used most of the Blue Pill Flash and Memory for very small sketchs.

            1. test sketch simple relay off/on used 48k (73%) of flash and 5k (24%) of memory.
            2. Sketch with simple LED off/on with 'receive' from controller and rfm69 use 58k flash (88%) and 5.2k (25%) of memory.

            I used MySensors current release, & latest Arduino IDE. Have you had similar results in the work you are doing? This would take away the Blue Pill advantage of twice the flash of a pro mini, and make it unusable.

            I will dig deeper, and try the @KooLru code above to see if it makes a difference. @monte states that it might not have functionality, but I am not sure what that means as 'core' work is beyond my skill level.

            Again, I will assume I am doing something incorrectly as I know others on MySensors forum have used the blue pill.

            1 Reply Last reply
            1
            • C Offline
              C Offline
              CarloMagno
              wrote on last edited by
              #16

              @novicit I can more or less confirm your results. I have used the PH dummy sketch to simulate a value sent to the gateway and it has worked perfectly. Using MySensors development branch the compilation results are:

              Sketch uses 47216 bytes (72%) of program storage space. Maximum is 65536 bytes.
              Global variables use 5384 bytes (26%) of dynamic memory, leaving 15096 bytes for local variables. Maximum is 20480 bytes.
              
              

              This results are selecting the variant in the "STMF103C8 (20k RAM, 64k Flash)" of the board in the Arduino IDE tools menu.
              However, In the multiple forums I have read about the STM32F103 it seems that regardless of the amount of memory the board you have bought, (64k or 128k) most of them are 128k,... so, you can always try 128k.. or buy 128k variants (STM32F103CB), in which case the compilation results give more headroom for bigger sketches:

              Sketch uses 47216 bytes (36%) of program storage space. Maximum is 131072 bytes.
              Global variables use 5384 bytes (26%) of dynamic memory, leaving 15096 bytes for local variables. Maximum is 20480 bytes.
              
              

              I have tried changing the definition to the 128k variant and can confirm that the upload works and that the node works (message received in the gateway)... I don't know if the 64k of sketch are exceeded the code will upload... I believe the upload would have failed if the board does not have that flash memory space.
              Find attached the sketch I am using that I can confirm that works... in my setup. I am using a SX1276 LoRa radio.
              I used a STLink V2 clone to upload the sketch and a TTL to usb attached to PA9 and PA10 pins to serial print messages. To get Serial.print working (for MySensors connection debug) I had to redirect debug messages to Serial1 port (PA9 and PA10 in STM32 maple core). I believe that Serial corresponds to the on-board usb but mine does't work out of the box and I believe that I would have to upload first a bootloader in order to use it... so I took the short test route and used the TTL to usb instead.

              // Enable debug prints to serial monitor
              #define MY_DEBUG
              
              // Enable and select radio type attached
              //#define MY_RADIO_RF24
              //#define MY_RADIO_NRF5_ESB
              //#define MY_RADIO_RFM69
              #define MY_RADIO_RFM95
              #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF128     // Default, medium range
              //#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW500CR45SF128   // Fast, short range
              //#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW31_25CR48SF512 // Slow, long range
              //#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR48SF4096  // Slow, long range
              
              // For RFM95 connections. Following: https://www.thethingsnetwork.org/labs/story/a-cheap-stm32-arduino-node 
              #define MY_RFM95_IRQ_PIN      PA11               //  SX1276's IRQ(Interrupt Request)
              #define MY_RFM95_IRQ_NUM      MY_RFM95_IRQ_PIN
              #define MY_RFM95_CS_PIN       PA4                // SX1276's CS (NSS)
              #define MY_RFM95_RST_PIN      PB0                // SX1276's RESET
              //#define MY_SOFTSPI
              #define MY_SOFT_SPI_SCK_PIN   PA5                // SX1276's SCK
              #define MY_SOFT_SPI_MISO_PIN  PA6                // SX1276's MISnO 
              #define MY_SOFT_SPI_MOSI_PIN  PA7                // SX1276's MOSI  
              //#define MY_RFM95_POWER_PIN (3)                // What is this used for?
              
              
              #define MY_SERIALDEVICE Serial1 // Force using Serial 1 (RX ->PA9 and TX -> PA10) for MySensor debug messages
              // Define a static node address, remove if you want auto address assignment 
              #define MY_NODE_ID   70 
              //#define ARDUINO_ARCH_STM32F1
              #include <MySensors.h>
              
              #define COMPARE_PH 1 // Send PH only if changed? 1 = Yes 0 = No
              const int ledPIN = PC13; 
              
              uint32_t SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
              float lastPH;
              bool receivedConfig = false;
              bool metric = true;
              // Initialize PH message
              MyMessage msg(0, V_PH);
              
              void setup()
              {
                Serial1.begin(115200); //RX->PA9 / TX->PA10
                // initialize digital pin PC13 as an outp
                pinMode(ledPIN, OUTPUT);
                //Setup your PH sensor here (I2C,Serial,Phidget...)
              }
              
              float getPH()
              {
                //query your PH sensor here (I2C,Serial,Phidget...)
                float dummy = 7;
                return dummy;
              }
              
              void presentation()
              {
                // Send the sketch version information to the gateway and Controller
                //sendSketchInfo("PH Sensor", "1.1");
                present(0, S_WATER_QUALITY);
              
              }
              
              void loop()
              {
              
                float ph = getPH();
                Serial1.println("PH: ");Serial1.println(ph);
              #if COMPARE_PH == 1
                if (lastPH != ph) {
              #endif
              
                  // Send in the new PH value
                  send(msg.set(ph, 1));
                  // Save new PH value for next compare
                  lastPH = ph;
              
              #if COMPARE_PH == 1
                }
              #endif
                wait(SLEEP_TIME);
              }
              
              1 Reply Last reply
              1
              • monteM Offline
                monteM Offline
                monte
                wrote on last edited by monte
                #17

                Just pulled commits proposed by @KooLru and tried compiling relay example for a test.
                STM32F103C8:

                Sketch uses 27700 bytes (42%) of program storage space. Maximum is 65536 bytes.
                Global variables use 2832 bytes (13%) of dynamic memory, leaving 17648 bytes for local variables. Maximum is 20480 bytes.
                

                The same example compiled for ATmega 328p:

                Sketch uses 13712 bytes (44%) of program storage space. Maximum is 30720 bytes.
                Global variables use 449 bytes (21%) of dynamic memory, leaving 1599 bytes for local variables. Maximum is 2048 bytes.
                

                The same, but for NRF52832:

                Sketch uses 29784 bytes (5%) of program storage space. Maximum is 524288 bytes.
                

                I guess overhead is added by ARM specific HAL and other similar stuff.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  CarloMagno
                  wrote on last edited by CarloMagno
                  #18

                  I still have to try the commits by @KooLru .. (first I have to figure out how to use a commit in a library with the Arduino IDE :face_with_rolling_eyes: ) but in the meantime I have found that the compiling problem with PlatformIO, STM32 and MySensors had been already documented in previous posts:
                  https://forum.mysensors.org/topic/10324/platformio-not-longer-working-with-mysensors/6
                  That also links to this post:
                  https://forum.mysensors.org/topic/10193/stm32f103c8-problem-at-compilation/12
                  That points to the ticket open in the PlatformIO and temporary workaroud (I have to learn to test it):
                  https://github.com/platformio/platform-ststm32/issues/283#issuecomment-533585597

                  I have tested the temporary solution in the github ticket and it has compiled for the mapple core. The Plaformio.ini file is:

                  [env:genericSTM32F103CB]
                  platform = ststm32
                  board = genericSTM32F103CB
                  framework = arduino
                  board_build.core = maple
                  extra_scripts = pre:fix_main.py
                  

                  Before getting it to compile I had to install Python for the OS (in this case I am using Windows 10) and the Python extension for PlatformIO (I chose Microsoft one).
                  And also, it seems something has changed in the last versions of PlatformIO since solution post in the fix and I had to change the variable name in the Python script PROJECTPACKAGES_DIR by PROJECT_PACKAGES_DIR, so the line in the final line in that scrips is as follows:

                  STM32_FRAMEWORK_DIR = env['PROJECT_PACKAGES_DIR'] + "/framework-arduinoststm32-maple"
                  
                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    novicit
                    wrote on last edited by
                    #19

                    @CarloMagno I also found the links you refer to. They appear to be "workarounds" rather than truly solving the real problem. I was never able to get the script shown to work. I did get an error free compile with the information in them, but for some reason it appeared to never link the MySensors library. I did not get a splash screen, or any MySensors debug messages.

                    The tests @monte did seemed to show a significant decrease in flash usage when using the STM32 core. So I also used the @KooLru proposed commits on the same two sketches as before, with promising results (on arduino IDE):

                    Sketch #1
                    w/ RogerClarke core Flash used 58k (88%)
                    w/ @KooLru STM32 core Flash used 41k (61%)

                    Sketch #2
                    w/ RogerClarke core Flash used 48k (73%)
                    w/ @KooLru STM32 core Flash used 30k (45%)

                    This looks good. I have only tested compile, not yet loaded a Blue Pill with the output.

                    To use @KooLru proposed commits:

                    1. must use development branch.
                    2. create folder MySensors\hal\archetecture\STM32
                    3. drop @koolru 3 files in above directory. [MyMainSTM32.cpp, MyHwSTM32.h & .cpp]
                    4. Replace MySensors.h with his version.

                    @CarloMagno I forgot that most Blue Pills are actually 128k - nice suggestion! I found the following website which shows how to check the flash in a blue pill. [https://www.onetransistor.eu/2020/01/stm32-bluepill-arduino-support.html]

                    Next Steps:

                    1. Try @koolru modified development branch with PlatformIO.
                    2. Live test a program compiled with the modifications in a working MySensors network.
                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      novicit
                      wrote on last edited by
                      #20

                      Re: the site to check if Blue Pill is 128k: I believe the "STM32CubeProgrammer" is loaded as part of the STM32 core and does not need to be loaded separately. Should be able to execute those commands without installing anything else.

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        CarloMagno
                        wrote on last edited by CarloMagno
                        #21

                        @novicit Using the link you provided I have confirmed that my board is a 128k flash variant (installing STM32CubeProgrammer" and launching its graphical IDE, not tried the command line option).
                        I have sucessfully compiled the koolru branch with PlatformIO and got the node to send messages go the gateway. What I did:

                        1. Installed in PlatformIO the stable MySensors library (from PlatformIO library manager)
                        2. Downloaded the koolru MySensos full library (Download Zip option from View Code Github) and decompress it into a custom folder
                        3. Linked the koolru MySensors library as a project specific library (to be used for that project instead of the global MySensors library). Place the decompressed folder library in a folder, for example: H:\PlatformIO\custom_libraries\ (so the files for the custom MySensors library are in *H:\PlatformIO\custom_libraries\MySensors-development* ).
                        4. Created the fix_main.py with the modified line I posted in the previous post (you need to have installed pyton intepreter for OS and Pytnon plugin for PlatformIO to be able to use this precompiling script)

                        The platformio.ini file is:

                        [env:genericSTM32F103CB]
                        platform = ststm32
                        board = genericSTM32F103CB
                        framework = arduino
                        ;board_build.core = maple
                        monitor_speed = 115200
                        monitor_filters = time, default
                        extra_scripts = pre:fix_main.py
                        lib_extra_dirs = H:\PlatformIO\custom_libraries\
                        
                        [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*
                        

                        Start of the compiling process (you can see that the python script is being executed and that the development version of MySensors is selected):

                        Processing genericSTM32F103CB (platform: ststm32; board: genericSTM32F103CB; framework: arduino)
                        ------------------------------------------------------------------------------------------------------------------------------
                        
                        Verbose mode can be enabled via `-v, --verbose` option
                        
                        ================================= STM32 FRAMEWORK PATCHER =================================
                        
                        [INFO] Patching file: C:\Users\xxxxxx\.platformio\packages/framework-arduinoststm32-maple\STM32F1\cores\maple\main.cpp
                        [INFO] Patching file: C:\Users\xxxxxx\.platformio\packages/framework-arduinoststm32-maple\STM32F4\cores\maple\libmaple\main.cpp
                        
                        ============================================================================================
                        
                        CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/genericSTM32F103CB.html
                        PLATFORM: ST STM32 6.1.0 > STM32F103CB (20k RAM. 128k Flash)
                        HARDWARE: STM32F103CBT6 72MHz, 20KB RAM, 128KB Flash
                        DEBUG: Current (blackmagic) External (blackmagic, jlink, stlink)
                        PACKAGES:
                         - framework-arduinoststm32-maple 2.10000.200103 (1.0.0)
                         - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
                        LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
                        LDF Modes: Finder ~ chain, Compatibility ~ soft
                        Found 48 compatible libraries
                        Scanning dependencies...
                        Dependency Graph
                        |-- <MySensors> 2.4.0-alpha
                        |   |-- <Wire> 1.0
                        |   |-- <SPI> 1.0
                        |   |-- <EEPROM>
                        Building in release mode
                        

                        And the compilation results (I got several warnings regarding SPI but the result is sucessful):

                        Building .pio\build\genericSTM32F103CB\firmware.bin
                        Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
                        RAM:   [===       ]  26.3% (used 5384 bytes from 20480 bytes)
                        Flash: [====      ]  38.0% (used 49840 bytes from 131072 bytes)
                        ================================================ [SUCCESS] Took 17.96 seconds ================================================
                        

                        ... @novicit you mention that using the script previously you couldn't get it to work.. check Python install and plugins.. also to debug MySensor messages I used a separate usb to TTL (not STLINK attached to PA9 and PA10 as I explained before).

                        ... and now the next problem... the STM32LowPower.h library (to get the STM32 to deep sleep) is compiling properly in Arduino IDE but does not compile in PlatformIO ... again... :disappointed:

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          novicit
                          wrote on last edited by
                          #22

                          @CarloMagno You are fortunate to have the 128k Blue Pill. I hope mine are also.

                          Funny, in coding there are always different ways to do things. Working with PlatformIO, I linked to the MySensors development branch in the platform.ini as follows:

                          [env:bluepill_f103c8]
                          platform = ststm32
                          board = bluepill_f103c8
                          framework = arduino
                          
                          lib_deps =
                            https://github.com/mysensors/MySensors.git#development
                          
                          lib_ignore =
                            ;MySensors standard library
                            548
                          

                          It seemed to work. But I have not yet finished testing.

                          In your compile on PlatformIO, it makes me wonder if perhaps it used the maple (RogerClark) core instead of STM32. I observe:

                          1. The STM core also includes the maple core. (https://docs.platformio.org/en/latest/platforms/ststm32.html)
                          2. Though the .ini file does not have "board_build.core = maple" in it, the compile output has "framework-arduinoststm32-maple 2.10000.200103 (1.0.0)" in the output.
                          3. The output file size of 50k flash seems large and is comparable to the output I got from my Maple/RogerClark testing. Is it the same size as you got when compiling in the Arduino IDE with STM32 core?
                          4. The low power library has been written up as not compiling with maple/RogerClark core, but does with STM32 core.
                            ==> Just some observations to be confirmed?

                          In my initial attempts to compile with STM32 core on PlatformIO, it uses the development branch, but I get an error message:
                          ".pio/build/bluepill_f103c8/FrameworkArduinoVariant/PeripheralPins.c' not found, needed by target..."
                          => I have not had the time to solve this yet. But, compiler is looking for a file which describe pin map - PeripheralPins.c I am guessing this is similar to MySensors instructions for Nrf5 where two files are in the sketch directory to specify pin assignments. (MyBoardNRF5.cpp and .h)

                          [Sorry I am not able to make faster progress contributing to this thread. I am a couple weeks out of the hospital and can only sit at my computer for short periods so far. But happy, repairs were successful :) ]

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            CarloMagno
                            wrote on last edited by
                            #23

                            @novicit, nice to hear hospital "repairs" doing well!
                            I don't have much time either, so, when I find some time in the weekends I try the following step...
                            A couple of things regarding your comments:

                            1. The way you included the development branch of MySensors in Platformio I believe it takes the "official" MySensors development branch, and I don't konw if the commit by koolru has been merged into that branch.. i believe not.. so it is not using the right code for the STM official core, and could be the origin of your error message. That is the reason I downloaded the library and used a local stored copy from koolru repository. I had also to have installed the official MySensors library (otherwise it gave me compiling errors), as if some library dependencies were missing from koolru branch ¿?.
                            2. It is true that STM32 core in platformio has both the Roger Clark and Official ststm core. By default it uses the official core. If you want to compile for the Rogre Clark you include the option board_build.core = maple in Platformio.ini.
                            3. The LowPower library is compiling in the Arduino IDE but gives errors in Platformio with ststm32 core (official).
                            1 Reply Last reply
                            0
                            • Bogusz JagodaB Offline
                              Bogusz JagodaB Offline
                              Bogusz Jagoda
                              wrote on last edited by
                              #24

                              Maybe diggin a topic a bit, but as for June 2021 :

                              In library file MyHwSTM32.h one line seems to be lost :

                              
                              #ifndef MyHwSTM32_h
                              #define MyHwSTM32_h
                              
                              #include <IWatchdog.h>
                              #include <itoa.h>
                              #include <SPI.h>
                              #include <EEPROM.h>   <<--- this is necessary to compile agains BluePill
                              
                              

                              and something like this in platformio.ini

                              [env:bluepill_f103c8]
                              platform = ststm32
                              board = bluepill_f103c8
                              framework = arduino
                              
                              upload_protocol = stlink
                              debug_port = stlink
                              debug_tool = stlink
                              monitor_speed = 115200
                              monitor_filters = time, default
                              
                              

                              Just to keep you entertained.
                              Cheerz.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              9

                              Online

                              11.7k

                              Users

                              11.2k

                              Topics

                              113.0k

                              Posts


                              Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • MySensors
                              • OpenHardware.io
                              • Categories
                              • Recent
                              • Tags
                              • Popular