AnsweredAssumed Answered

Compilation with files from STM32CubeF4 on linux

Question asked by gad.pablo on Sep 6, 2014
Latest reply on Nov 27, 2014 by Montassar BEN ROMDHANE
Hello all. I just got a STM32F429-DISCO board and compiled my first successful program. I'm working under linux compiling with the GNU toolchain for ARM.
In order to be able to compile my program, I had to modify some files on the firmware package, due to them having incorrect paths on a lot of #include's: they use a backslash instead of a slash in the header files search paths, which works correctly on Windows but returns an error on unix-like systems. Note that the C standards mandate that a slash should be used in this context regardless of the system, it will work on all contexts.

So I made a little shell script to correct all the incorrect #include lines on .h and .c files inside the firmware package tree, and the purpose of this message is to share it here in the hope that someone will find it useful :) .

Here it is:


rm -f log_copy.txt

for i in `find STM32Cube_FW_F4_V1.3.0 -name "*.[ch]" | xargs grep -l -E -e '#include "\.\.\\\' -e '#include "\\\'`; do
    echo "COPY $i -> $i.orig" | tee log_copy.txt
    cp $i $i.orig
    echo "CHANGE SLASH $i"
    sed -i '/#include/{s|\\|/|g}' $i | tee log_copy.txt
    diff $i $i.orig | tee log_copy.txt

It will backup the original files to .orig and then modify the wrong #include directives. The script must be placed in the directory where the FW package has been decompressed.

As a final word, I'd like to request ST to correct their source files for the next version of the firmware package, and even include makefiles for GNU in addition to the currently present build files.

Best regards!