How to link Luos and Robus to Platformio

The aim of this post is to show you how works the link between Luos, Robus and PlatformIO. This connection is very important, thanks to it we can now reorganize our github page in order to make the download easier and multiplatform for users. Indeed once they will download a module for example button_module they just have to start the PlatformIO project and compile it.

All the necessary libraries will be found without any configuration on his parts and if they want to add another module to their project they just have to drag and drop the module of their choice and add it to the lib folder of PlatformIO. And if they want that his project support other board they just have to add a new env in their platformio.ini.

PlatformIO documentation

To do the link between Luos, Robus and PlatformIO we followed the instructions of the PlatformIO documentation :

https://docs.platformio.org/en/latest/librarymanager/config.html#extrascript

This documentation explains that we have to create a python script and a .json file for each library in order to select the right board according to the value of the board in platformio.ini. To select the board we want, we simply add a define to build_flags in platformio.ini.

For a better understanding we will see at the end the structure of our two libraries Luos and Robus and just before that the different configuration files (platformio.ini, .json(Luos,Robus), sript.py(Luos,Robus) ).

Platformio.ini

[env:eval_f072vb]

platform = ststm32

board = eval_f072vb

framework = stm32cube

build_flags = 

    -D USE_FULL_LL_DRIVER

    -D USE_HAL_DRIVER

    -I Inc

    -DHAL=l0

lib_extra_dirs = 
    C:\Users\antoi\OneDrive\Bureau\LUOS\Luos_Dev

This file is use to configure the platformIO project we can see that we are using an stm32 platform which is the eval_f072vb board. Then we have build_flags

a very important field which are in charge of the preprocessing, compilation, assembly and linking processes for C code. In our case we use it for three reason.

1) Make preprocessor define:

        -D USE_FULL_LL_DRIVER

        -D USE_HAL_DRIVER

2) Include header file generate by CubeMX:

        -I Inc

3) Select our board

        -DHAL=l0 

Thanks to -DHAL=l0 line we indicate to our scripts what board it must choose in the hal folder of it library.

WARNING : It is very important that there is a hal folder and that it contains the same folder in the both library otherwise the platformio project will don’t work.

We also have the lib_extra_dirs field to indicate to the compilator where are our librairies Luos and Robus.

library.json (Luos)


{

    "name": "Luos",

    "keywords": "robus,network",

    "description": "distributing operating system",

    "version": "0.6.0",

    "frameworks": "stm32cube",

    "platforms": "ststm32",

    "authors": {

        "name": "Luos",

        "url": "https://luos.io"

    },

    "licence": "MIT",

    "build" : {

        "flags": [

            "-I Inc",

            "-I OD"

        ],

        "extraScript": "select_board_script.py"

    },

    "dependencies":

    [

        {

        "name": "Robus"

        }

    ]

}

This .json file is related to the Luos library as we can see in the name field.

This file have 3 goals:

1&2- Include the header file useful to Luos and execute the python script to use the board reference in platformio.ini :


    "build" : {

        "flags": [

            "-I Inc",

            "-I OD"

        ],

        "extraScript": "select_board_script.py"

    },


3- Make a dependance to robus because we need Robus to make Luos works:


    "dependencies":

    [

        {

        "name": "Robus"

        }

    ]

library.json (Robus)


{

    "name": "Robus",

    "keywords": "robus,network",

    "description": "distributing operating system",

    "version": "1.0",

    "authors": {

        "name": "Robus",

        "url": "https://luos-robotics.com"

    },

    "licence": "MIT",

    "build" : {

        "flags": [

            "-I Inc"

        ],

        "extraScript": "select_board_script.py"

    }

}

This .json file it related to the Robus library as we can see in the name field.

This file have 2 goals:

Include the header files useful to Luos and execute the python script to use the board reference in platformio.ini lunch the python script :


    "build" : {

        "flags": [

            "-I Inc"

         ],

        "extraScript": "select_board_script.py"

    }

select_board_script.py (Luos)


Import('env')

from os.path import join, realpath

# private library flags

for item in env.get("CPPDEFINES", []):

    if isinstance(item, tuple) and item[0] == "HAL":

        env.Append(CPPPATH=[realpath(join("hal", item[1]))])

        env.Replace(SRC_FILTER=["+<../src/*>", "-<../hal>", "+<%s>" % join("../hal", item[1])])

        break

# pass flags to a global build environment (for all libraries, etc)

global_env = DefaultEnvironment()

global_env.Append(

    CPPDEFINES=[

        ("MQTT_MAX_PACKET_SIZE", 512),

        "ARDUINOJSON_ENABLE_STD_STRING",

        ("BUFFER_LENGTH", 32)

    ]

)

This python script will specify which source files should be include from build process in fucntion of the selected board. In our case l0 source file place in the hal folder of Luos and the src folder of Luos.

select_board_script.py (Robus)


Import('env')

from os.path import join, realpath

# private library flags

for item in env.get("CPPDEFINES", []):

    if isinstance(item, tuple) and item[0] == "HAL":

        env.Append(CPPPATH=[realpath(join("hal", item[1]))])

        env.Replace(SRC_FILTER=["+<../Src/*>", "-<../hal>", "+<%s>" % join("../hal", item[1])])

        break

# pass flags to a global build environment (for all libraries, etc)

global_env = DefaultEnvironment()

global_env.Append(

    CPPDEFINES=[

        ("MQTT_MAX_PACKET_SIZE", 512),

        "ARDUINOJSON_ENABLE_STD_STRING",

        ("BUFFER_LENGTH", 32)

    ]

)

This python script will specify which source files should be included from build process in fucntion of the selected board. In our case l0 source file place in the hal folder of Robus and the Src folder of Robus.

Luos folder structure


  Luos
    β”‚   library.json
    β”‚   select_board_script.py
    β”‚
    β”œβ”€β”€β”€hal
    β”‚   └───l0
    β”‚           eeprom.c
    β”‚           eeprom.h
    β”‚           luos_board.c
    β”‚           luos_board.h
    β”‚
    β”œβ”€β”€β”€Inc
    β”‚       
    β”œβ”€β”€β”€OD
    β”‚     
    └───src

Robus folder structure


  Robus
    β”‚   library.json
    β”‚   README.md
    β”‚   select_board_script.py
    β”‚
    β”œβ”€β”€β”€doc
    β”‚
    β”œβ”€β”€β”€hal
    β”‚   └───l0
    β”‚           hal.c
    β”‚           hal.h
    β”‚           L0.ioc
    β”‚
    β”œβ”€β”€β”€Inc
    β”‚
    └───Src

1 Like