2020-02-10 07:30 AM
Hi there,
I am new to the STM32 microcontrollers and the STM32 Cube IDE, and I'm tasked with including a binary set of data in a program. Most of the code is generated with the CubeMX program to help me with initialization. Please be advised, that I can't post the code in the forum.
Traditionally I would do so by linking it into the binary file during build. However, in the STM32 Cube IDE I can't find any way or option to do so, so I've resorted to incude it as a C-style array of values.
As this set of binary data can change, or may be exchanged completely a number of times during development, this is a hassle, and would be avoidable by just including/linking the binary dataset from a file, then using the symbol names.
Is there a way to do this in the IDE, which I just haven't found yet?
Best regards,
Nils
Solved! Go to Solution.
2020-02-10 07:45 AM
STM32CubeIDE uses the GNU gcc-arm toolchain.
An approach using objcopy is discussed here:
https://stackoverflow.com/questions/17265950/linking-arbitrary-data-using-gcc-arm-toolchain
Its not directly "in" the IDE, you might need to write a pre-build script, edit linker flags etc...
2020-02-10 07:45 AM
STM32CubeIDE uses the GNU gcc-arm toolchain.
An approach using objcopy is discussed here:
https://stackoverflow.com/questions/17265950/linking-arbitrary-data-using-gcc-arm-toolchain
Its not directly "in" the IDE, you might need to write a pre-build script, edit linker flags etc...
2020-02-10 08:14 AM
Thank you for the quick reply.
I will try to incorporate it into my build process. I'm new to this IDE, so might still need some assistance there, on how to do this. The makefile is generated automatically, and overwritten on build.
2020-02-10 09:27 AM
I think I've found my answer, though I am not really sure about it yet (requires some testing to be certain):
Using the steps from your link, I tried converting the binary file to
-O elf-littlearm -B arm
With just objcopy I had no luck (architecture arm unknown), so tried arm-none-eabi-objcopy, as this prefix can be seen in the build logs for pretty much everything; e.g. arm-none-eabi-gcc instead of just gcc.
I then went ahead and fiddled with the build settings until I saw the used flash size increase (and the project made without errors):
Right-click on project in tree --> Properties --> C/C++ Build--> Tool Settings --> MCU GCC Linker --> Miscellaneous --> Additional object files --> Add --> add .o file from filesystem or workspace.
It is subsequently included in the auto-generated objects.mk as USER_OBJS, and will thus be included in the .data segment of the code.
The included data can then be referenced by the standard means of:
extern unsigned char _binary_myFile_start;
extern unsigned char _binary_myFile_end;
extern unsigned char _binary_myFile_size;
Thanks for guiding me in the right direction!
Best regards,
Nils
2020-02-10 10:21 AM
May help maybe ... some binary inclusion setup example from AI pack usage. Let's promote your own material this way...