Introduction: Compiling Marlin 3d Printer Firmware With Stm32duino Core - the Unorthodox Way

This is a build log rather than a 'how to' post. I managed to compile

Marlin Firmware 2.0 https://github.com/MarlinFirmware/Marlin
with STM32duino core https://github.com/stm32duino/Arduino_Core_STM32
http://www.stm32duino.com
and got it running on STM32 F4VET6 black board https://stm32-base.org/boards/STM32F407VET6-STM32-...

(this isn't quite a '3d printer board' more than it is a 'development board', takes some imagination add 'ramps' board to get it to work) using a unix/linux makefile.
This makefile is maintained in this gist

https://gist.github.com/ag88/62249784b455ff8d8c3fa...

VS Code Platform IO

Accordingly the recommended method is to use Platform IO running in VS Code. There is also a "Auto Build Marlin" vscode extension for it https://marlinfw.org/docs/basics/install_platform...

Some issues

Note that building Marlin firmware in Arduino IDE, you may confront various challenges/problems with stm32duino. Apparently i found out that there are some defines passed from platformio ini files. This may mean that the original Arduino IDE may not work with the stm32duino core with Marlin 2.0 as it implies things like platform.txt and boards.txt files may need to be edited. It may work though, but i've not tried.

Common approaches / Configuration

The 'usual' way to build marlin seemed to be, 1st get (e.g. git clone) the source https://github.com/MarlinFirmware/Marlin https://marlinfw.org/
and edit the configuration file https://github.com/MarlinFirmware/Marlin
Configuration.h
and
Configuration_adv.h

There are some examples in this repository https://github.com/MarlinFirmware/Configurations

e.g. for the STM32 F4VET6 black board there is one there https://github.com/MarlinFirmware/Configurations/t...

Those can be used in place of the default Configuration.h and Configuration_adv.h but be sure to check and edit the configurations https://github.com/MarlinFirmware/Marlin

Makefile

What I've done instead is I've created a makefile, works only in linux/unix. This makefile should be considered 'alpha' code, i.e. it works for me but it may not work for you. The makefile is board and mcu specific (one single board variant at at time). Hence if you use a board other than STM32 F4VET6 black board, you would need to edit the various definitions / defines in the makefile and use a different variant. The makefile includes a pretty large exclusion list those are replicated from platformio.ini from Marlin firmware repository. If you build Marlin using this makefile and you are getting object not found errors at the linking stage, search in the exclusion list and comment off the relevant exclusions.

If you want to use this makefile (linux/unix only) in Windows, it would likely need Windows Subsystem for Linux https://docs.microsoft.com/en-us/windows/wsl/inst...
Using the makefile requires you to setup this project folder structure as follows, each of those are directories with the makefile being a file.

This makefile can't handle the brackets/paranthesis naming convention used for the variants hence you need to create a local variant folder and copy all the files in
Arduino_Core_STM32/variants/STM32F4xx/F407V(E-G)T_F417V(E-G)T/
to
variants/F407VX/

Note that the section above that discuss updating the configuration (i.e. Configuration.h, Configuration_adv.h) is still relevant. If you pulled the Marlin repository using a git clone command, those should be found in the sub-directory Marlin/Marlin.

You would also have to edit the makefile to point to the installed location of your arm-none-eabi-gcc compiler in the make file in the line
ARM_NONE_EABI_PATH := /opt/arduino/xpack-arm-none-eabi-gcc/9.2.1-1.1/

If you are looking for that compiler normally if you install stm32duino https://github.com/stm32duino/wiki/wiki/Getting-St.... The compiler is normally found in the (note the dot) .arduino15 folder in your home directory, in packages/STM32/tools/xpack-arm-none-eabi-gcc. You can maintain a path to point it there. Otherwise, to get e.g. the xpack-arm-none-eabi-gcc compiler toolchain you could visit https://xpack.github.io/arm-none-eabi-gcc/. This isn't the only one around there are those from ARM itself and Linaro a google/bing search should find them.

This makefile is maintained in this gist https://gist.github.com/ag88/62249784b455ff8d8c3f...

After you have set it up, all it takes is to go into your project directory with the above folder structure setup and run

make clean
make

Your firmware would be found in the build directory as a .bin file.

In the makefile there is a target that can install the firmware into the board using dfu-util http://dfu-util.sourceforge.net/. if you have that (dfu-util) installed, you would need to set the BOOT0 pin and reconnect usb cable.
Then to install, it is:

make install

After that restore the BOOT0 pin and press reset (on the board, not your pc).
that's it ;)