cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX generated code line ending

MHoss.1
Associate III

I've switched to mac and like any responsible adult all of my projects are handled by git. But when I generated the code with CubeMX it was a little confusing to see so many files have changed. A quick search brought me to this topic without any answer:

https://community.st.com/s/question/0D50X00009XkgaG/cubemx-line-ends-in-generated-code

The solution is that CubeMX uses a repository of files in the background (which have DOS line ending) and it appends different files together to generate your code. So the easy way to fix the problem is to do the following steps:

  1. `brew install dos2unix`
  2. find where `STM32Cube` directory is (mine was under home)
  3. Go to `STM32Cube/Repository/STM32Cube_FW_xx_xxxx` which is the firmware version you use. If you're not sure of it, open your CubeMX go to Project Manager, on the left select Project and under "Mcu and Firmware Package" find the firmware version. Running the commands at Repository directory fixes all the firmwares.
  4. Open a terminal at the firmware repository directory and put these two lines: `find . -name '*.h' | xargs dos2unix` and `find . -name '*.c' | xargs dos2unix`

This should take care of the problem mostly (there are some residue I haven't figured how to fix yet).

I had to change a few files manually as they had some weird symbols in them. But you get the gist. Modify anything that's annoying to you there (don't touch the code, just simple stuff).

Another alternative solution for SW4STM32 users is to:

  1. Generate the code
  2. In eclipse select the root directory of the project in "Project Explorer", in "File/Convert Line Delimeters To/Unix" and it should fix the problem.

The last, probably easiest, is to set the git to change the line ending itself by setting the `autocrlf

`. When installing git in windows `auto` should be selected. In mac and linux use `it config --global core.autocrlf input` (the default is `false`). So it changes the DOS line ending to unix when you add the files automatically. After generating the code you might have 70 unstaged changed in git but once you add them the number shrinks to only a few files that have actually been changed.

0 REPLIES 0