Skip to main content
Visitor II
January 2, 2015
Question

CubeMX, Line ends in generated code

  • January 2, 2015
  • 5 replies
  • 4517 views
Posted on January 02, 2016 at 20:08

Using CubeMX eclipse plugin under linux.

The generated source code has windows style CR-LF lineends, what's very uncommon for this OS (and even for Mac OSX). This issue heavily bothers post processing tools which might working on the generated code (e.g. grep, awk, perl, …).

Could ST please change the code generation to have OS styled lineends (for Linux & OSX, this means LF without CR)?

Further, it would be nice, if the generated code comes without trailing whitespace.

Cheers, Joe
    This topic has been closed for replies.

    5 replies

    Visitor II
    January 3, 2015
    Posted on January 03, 2016 at 15:14

    It's linefeed (''\n'')  on Linux and carriage return (''\r'') on macos. IIRC.... 

    Visitor II
    January 4, 2016
    Posted on January 04, 2016 at 08:31

    ''\r'' for MAC is very outdated. From starting with OSX, which is based upon BSD Unix, MAC has also ''\n'' lineends.

    Graduate II
    February 3, 2016
    Posted on February 03, 2016 at 20:44

    Don't we just write software to be able to deal with the formats that are in heavy/prevalent use? It's not 1970, and the horse left the barn a long time ago, there's no prospect they are going to get unified, you really have to work with what's out in the ecosystem than expect everything to conform to the standard you want to adopt. Got editors here quite capable of using either format, and filtering the file/line data is something an intern should be able to code in an afternoon.

    If your tools aren't agnostic, it is your tool's fault.

    I can see the utility of having this as a check box item, but honestly ST has bigger bugs and defects they should be concentrating on.

    ST Employee
    February 22, 2016
    Posted on February 22, 2016 at 10:58

    Hello,

    Note that generated code use same line end format than the STM32 embedded software libraries themselves.

    Are you requesting solely the generated code to comply to the OS specific line end format?

    Thanks

    Explorer
    September 14, 2023

    Indeed, CubeMX is still generating the Makefile, *.c and *.h with linefeeds under Linux. This is especially annoying when working with git repos that do not have linefeeds. Here's an example: https://github.com/Seeed-Studio/LoRaWan-E5-Node

    My current (and also clumsy) work-around is to run dos2unix on all the generated files, mentioned above, every time I generate the code.

    @stm32cube-t, is it not possible to at least add some button in the code generation options to disable linefeeds?

    Such an option will be backwards compatible. Moreover, even on CRLF-OSes, people might not want the generator to generate their OS-type's endlines. Just imagine, you're working on Windows, but you're working on a git repo with Linux-type endlines.

    Thanks

    Graduate II
    March 3, 2025

    The problem is still existing and is *VERY* annoing.
    Altering all template files in MX does not help, because of wrong setup of code generator.
    Somebody in ST really hates Unix/Linux community.

    Explorer
    March 5, 2025

    Hi @trzeci ,

    Thanks for sharing your findings.

    I've completely ditched using the dos2unix command to clear out the linefeeds, after every code generation.

    My latest workaround, is to just write as much code as possible in separate files, and include that.

    The only file, where this is really hard to do, is the Makefile. Yes, I'm using GNU/make.

    My work-around for this is to copy it to, say make.mk and then just edit make.mk, and run 'make -f make.mk'.

    I have the make.mk file checked into git, so if I have to merge a newly generated Makefile, I simply run it through dos2unix and then merge it, using some git tools. This works well, as the Makefile does not change too much, once the project's peripherals, etc. has been enabled.

    I hope these tips are helpful to you.