Skip to content

Instantly share code, notes, and snippets.

@Oxore
Created March 6, 2023 08:08
Show Gist options
  • Save Oxore/65539592fed02c01cb75692760038329 to your computer and use it in GitHub Desktop.
Save Oxore/65539592fed02c01cb75692760038329 to your computer and use it in GitHub Desktop.
My idea of MCU firmware project structure

My idea of MCU firmware project structure

- app/
  - some_module/
  - another_module/
  - main.cpp
  - common.h
  - platform/
    - stm32f103-gcc-newlib/
      - retarget.cpp
    - pic32mx-gcc-newlib/
    - pic32mx-xc32/
    - stub/
    - host/
    - platform.h
- boot/
  - platform/
  - some_module/
  - main.cpp
- ci/
- third_party/
  - CMSIS/
  - freertos/
  - printf/
  - cjson/
- cmake-build/ <- Not in SCM
- cmake-build-fw/ <- Not in SCM
- CMakeLists.txt
- toolchain-gcc-newlib.cmake
- toolchain-xc32.cmake
- unit_tests.cmake

app/

Here goes the firmware itself, it's business logic and it's own platform specific initialization. It may be as simple as single main.cpp or can have complex functionality split into multiple modules. There is a single main.cpp suitable for every platform it is intended to be run on.

All the platform specific code is located in platform/ and can be used universally across all supported platform by calling functions declared in platform/platform.h. The platforms may be various MCUs as well as simulation running on developer's PC in form of CLI application, graphical application or some virtual machine like QEMU.

The code that is identical between several platforms may be extracted to a file and shared as symlink like this: app/platform/pic32mx-xc32/retarget.cpp -> app/platform/pic32mx-gcc-newlib/retarget.cpp.

boot/

Bootloader code.

The code that is common between a bootloader and an app may be extracted to a file or module and shared as a symlink.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment