Using STM32CubeMX and PlatformIO


#21

Thanks for the tip @ivankravets. It works great.
Now only the linking of the library’s (FreeRTOS and LwIP) sources is left. Tried the -l and -L flags under build_dirs option with no success. What would you recommend?


#22

Do you have archives (*.a) of these libraries?


#23

No, their static-library files aren’t available. Would like to have those libraries shipped with their source-code. Does PlatformIO provide any option to build them first and link them while compiling user application?


#24

Honestly, I don’t understand what are you going to do but you can move 3-rd party libraries/source code to project/lib folder and include them in main project. PIO will find them and build automatically.

Please read project/lib/readme.txt.


#25

Thanks for your response. Have cleaned up the way sources and headers of 3rd party libraries are included by placing them in lib/ and changing _#include_s accordingly. The linking problem that I am facing now has come down to this issue reported here.
How to pass flags to final firmware.elf linkage?.
Fails to pick up hard floating-point flags while linking.


#26

Could you provide full output of pio run -v on https://hastebin.com ?


#27

Sure. Here’s the link : https://hastebin.com/osotijexah.sql
Thanks!


#28

Could you try lib_archive = false?


#29

Hey… gave it a try to see whether I could (force) link the object files. Same error persists.


#30

Copying every *.c and *.h files inside the Middlewares directory into lib/your_preferred_name will solve the problem.
I wrote small scripts and specify it to extra_scripts in platformio.ini, then it worked for me.

import os
import os.path
import shutil

lib_path = os.path.join('lib', 'CubeMX_Middlewares')

shutil.rmtree(lib_path, ignore_errors=True)
os.mkdir(lib_path)

for root, dirs, files in os.walk('Middlewares'):
    for file in files:
        if file.endswith('.c') or file.endswith('.h'):
            shutil.copy2(os.path.join(root, file), lib_path)

#31

Hi,

I have related question.

I have a project that was created for makefile with STM32CubeMX but I don’t have the STM32CubeMX project *.ioc file. I ported it to platform io using just the source and header and the linker script generated and it compiled.

The project comes with a startup script “startup_stm32f103xe.s” that is included in the original makefile, and is generated whenever STM32CubeMX generates a makefile configuration files.

My question is, does pio + stm32 framework generate this startup script automatically, or do I have to copy it over. If so, how can I include it in platformio.ini?

— EDIT
Found the answer by looking at the platform builder file here, the builder takes care of adding the startup file for specific stm32 boards. I’ll keep this here for reference.


#32

Incidentally, you don’t have to copy the files manually for the cubemx and platformio.

You can generate a cubemx project and initialise a project using Pio in the same directory. they share similar folder structure. the only difference IIRC is to add the ‘Inc’ and ‘Driver’ folders to the include folders and you should be good to go… That way you can regenerate the cube project and compile with platformio without redoing the whole project all over.

You must select the “retain user code” or some such option in the cubemx software and ensure that your code only exists within specific marked blocks (USER CODE BEGIN and END comments) in the generated files…
:slight_smile:


#33

Custom LD script could be set via http://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-flags