Skip to content

Code generated by CubeMX have CRLF Windows-style line ending #2

@ttzeng

Description

@ttzeng

STM32CubeMX generates code with Windows-style line endings by default. Though this is consistent with the line ending format used in the underlying STM32 embedded software libraries, it causes issues when working in Linux or when collaborating in a Git repository where a different line ending convention (i.e. LF) is preferred. Since then, several workarounds have been proposed in the community.

Potential Solutions and Workarounds by Gemini

Using dos2unix (for Linux/macOS users).

If working on a Unix-like system, the dos2unix utility can be used to convert the generated files to LF line endings. This often needs to be done after each code generation.

find . -name '*.h' | xargs dos2unix
find . -name '*.c' | xargs dos2unix

Configuring your IDE/Text Editor.

Many IDEs and text editors (like VS Code) allow you to configure the default line ending format. You can set it to LF for compatibility with Unix-like systems or CRLF for Windows. Git Configuration.

Git offers settings like core.autocrlf to manage line ending conversions automatically during commits and checkouts. Understanding and configuring this setting can help prevent line ending issues in collaborative projects.

Note:
While there have been discussions and requests in the STMicroelectronics community forums for an option to control line ending generation directly within STM32CubeMX, as of the current information, this feature is not yet available. Therefore, external tools or IDE configurations remain the primary methods for managing line endings in generated code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions