Compiling Marlin 3d printer firmware with stm32duino official core - the unorthodox way
Posted: Fri Aug 13, 2021 5:28 pm
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 official core
https://github.com/stm32duino/Arduino_Core_STM32
and got it running on STM32 F4VET6 black board
https://stm32-base.org/boards/STM32F407 ... -V2.0.html
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/instal ... ormio.html
note that building marlin firmware in Arduino IDE, you may confront various challenges/problems.
Apparently i found out that there is a define HAL_STM32
https://github.com/MarlinFirmware/Marlin/pull/22537
this define is apparently passed from platformio ini files
https://github.com/.../blob/2.0.x/ini/stm32-common.ini
and this isn't the only one. This effectively means that the original Arduino IDE won't work with the stm32duino STM core with Marlin 2.0
as it implies things like platform.txt and board.txt files need to be edited. it may work though but i've not tried.
what i've done instead is i've created a makefile, works only in linux/unix.
this makefile should be consider 'alpha' code, i.e. it works for me but it may not work for you
the makefile is board and mcu specific (one single 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,
if you build Marlin using this makefile and you are getting object not found errors at the linking stage, search in the exclusion
list aud comment off the relevant exclusions.
The 'usual' way to build marlin seem to be, first get (e.g. git clone) the source
https://github.com/MarlinFirmware/Marlin
https://marlinfw.org/
and edit the configuration file
https://github.com/MarlinFirmware/Marli ... 0.x/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/Confi ... 32F407VET6
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://marlinfw.org/docs/configuration ... ation.html
if you want to use this makefile (linux/unix only), in Windows, it would likely need WSL
https://docs.microsoft.com/en-us/window ... tall-win10
it requires you to setup this project folder structure as follows
you would also have to edit to point to the installed location of your arm-none-eabi-gcc compiler
this makefile is maintained in this gist as well
https://gist.github.com/ag88/62249784b4 ... 65e6b5c9f7
Marlin Firmware 2.0
https://github.com/MarlinFirmware/Marlin
with STM32duino official core
https://github.com/stm32duino/Arduino_Core_STM32
and got it running on STM32 F4VET6 black board
https://stm32-base.org/boards/STM32F407 ... -V2.0.html
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/instal ... ormio.html
note that building marlin firmware in Arduino IDE, you may confront various challenges/problems.
Apparently i found out that there is a define HAL_STM32
https://github.com/MarlinFirmware/Marlin/pull/22537
this define is apparently passed from platformio ini files
https://github.com/.../blob/2.0.x/ini/stm32-common.ini
and this isn't the only one. This effectively means that the original Arduino IDE won't work with the stm32duino STM core with Marlin 2.0
as it implies things like platform.txt and board.txt files need to be edited. it may work though but i've not tried.
what i've done instead is i've created a makefile, works only in linux/unix.
this makefile should be consider 'alpha' code, i.e. it works for me but it may not work for you
the makefile is board and mcu specific (one single 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,
if you build Marlin using this makefile and you are getting object not found errors at the linking stage, search in the exclusion
list aud comment off the relevant exclusions.
The 'usual' way to build marlin seem to be, first get (e.g. git clone) the source
https://github.com/MarlinFirmware/Marlin
https://marlinfw.org/
and edit the configuration file
https://github.com/MarlinFirmware/Marli ... 0.x/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/Confi ... 32F407VET6
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://marlinfw.org/docs/configuration ... ation.html
if you want to use this makefile (linux/unix only), in Windows, it would likely need WSL
https://docs.microsoft.com/en-us/window ... tall-win10
it requires you to setup this project folder structure as follows
Code: Select all
Root (project directory)
+-- src (your sources e.g. the sketch
| the files has to be cpp, c or h, no ino)
|
+-- Arduino_Core_STM32 (from https://github.com/stm32duino/Arduino_Core_STM32)
|
+-- CMSIS_5 (from https://github.com/ARM-software/CMSIS_5)
|
+-- Marlin (from https://github.com/MarlinFirmware/Marlin)
|
+-- variants (see below)
|
+-- Makefile (this makefile)
# 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/
Code: Select all
ARM_NONE_EABI_PATH := /opt/arduino/xpack-arm-none-eabi-gcc/9.2.1-1.1/
https://gist.github.com/ag88/62249784b4 ... 65e6b5c9f7
Code: Select all
# version 0 (alpha)
#
# This make file for libmaple core is possibly *dangerous*
# i.e. it compiles the sources (in src and STM32F1) directory
# and overwrite all the stuff in $(out_dir)
# $(out_dir) is the binary directory where the object files are dumped there
#
# make clean *deletes* the *$(out_dir)* (coded here as bin )
#
# this is a relative path makefile
# the directory structure needs to be
# Root (project directory)
# +-- src (your sources e.g. the sketch
# | the files has to be cpp, c or h, no ino)
# |
# +-- Arduino_Core_STM32 (from https://github.com/stm32duino/Arduino_Core_STM32)
# |
# +-- CMSIS_5 (from https://github.com/ARM-software/CMSIS_5)
# |
# +-- Marlin (from https://github.com/MarlinFirmware/Marlin)
# |
# +-- variants (see below)
# |
# +-- Makefile (this makefile)
#
# 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/
#
# Marlin is from the github repository. v 2.0.x and above is needed to build Marlin with stm32duino
# https://github.com/MarlinFirmware/Marlin
#
# the make needs to be run from the root of this file structure
# the make is relative path from this Root
# generated object files and binaries (elf, bin) are placed into the
# $(out_dir) - bin
#
# make clean - *deletes* $(out_dir)
#
# make all - starts the build
#
# This software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# this folder is deleted with make clean
out_dir := build
# this is the name of the subdirectory under STM32F1/variants
# it needs to match, this caters to a single variant
variant := F407VX
build_series := STM32F4xx
build_arch := STM32
#build_board := GenF4
build_board := BLACK_F407VE
variant_h := variant_BLACK_F407VX.h
product_line := STM32F407xx
#flash offset
ld_flash_offset := 0x0
#flash size
# 512K
ld_flash_size := 0x80000
#sram size
# 128K (sram)
ld_sram_size += 0x20000
# 64k (ccmram) - ccm ram is maint directly in ldscript
# these are the defines passed to gcc, g++ and the assembler
# use += to add more definitions
defines := ARDUINO=189
defines += $(build_series)
defines += ARDUINO_$(build_board)
defines += ARDUINO_ARCH_$(build_arch)
defines += BOARD_NAME=\"$(build_board)\"
defines += VARIANT_H=\"$(variant_h)\"
defines += $(product_line)
#defines += VECT_TAB_SRAM
defines += VECT_TAB_OFFSET=0
defines += DEBUG_LEVEL=DEBUG_NONE
defines += F_CPU=168000000L
defines += HSE_VALUE=8000000L
defines += HAL_UART_MODULE_ENABLED
defines += HAL_PCD_MODULE_ENABLED
defines += USBCON
defines += USBD_VID=0x0483
defines += USBD_PID=0x5740
defines += USB_MANUFACTURER=\"Unknown\"
defines += USB_PRODUCT=\"$(build_board)\"
defines += ADC_RESOLUTION=12
# usb serial
defines += USBD_USE_CDC
# HID keyboard and mouse
#defines += USBD_USE_HID_COMPOSITE
defines += LED_BUILTIN=PA6
defines += HAVE_INITFINI_ARRAY
#Marlin specific defines
defines += HAL_STM32
defines += TIM_IRQ_PRIO=13
# core_root points to the parent folder containing Arduino_Core_STM32 folder in a sub-directory
# this should be 1 level above Arduino_Core_STM32 folder
# this allows the core to be placed in a separate folder rather than in the project folder
# use of this is not encouraged omit the final slash after the directory
core_root := .
core_name := Arduino_Core_STM32
build_core_path = $(core_root)/$(core_name)/cores/arduino
build_system_path = $(core_root)/$(core_name)/system
CMSIS_path := $(core_root)/CMSIS_5
# This is for the CMSIS math lib
CMSIS_LD_PATH := $(core_root)/CMSIS/DSP/Lib/GCC
cmsis_lib_gcc := arm_cortexM4lf_math
start_file_path := $(build_system_path)/Drivers/CMSIS/Device/ST/$(build_series)/Source/Templates/gcc
# these are the source directories for the libmaple core
# and variant, normally they stay unchanged
# if you want to place the libmaple core directory somewhere else,
# define core_root above
coredir := $(core_root)/$(core_name)/cores/arduino
coredir += $(core_root)/$(core_name)/libraries/SrcWrapper/src
#coredir += $(build_system_path)/Drivers/$(build_series)_HAL_Driver/Src
#coredir += $(build_system_path)/$(build_series)
#coredir += $(build_system_path)/Middlewares/ST/STM32_USB_Device_Library/Core/Src
#variantdir := $(core_root)/variants/$(variant)
#local variannt dir
#variantdir := $(core_root)/$(core_name)/variants/$(variant)
#variantdir := $(core_name)/variants/$(build_series)/$(variant)
variantdir := variants/$(variant)
#coredir += $(variantdir)
# source directories
# these are the initial directories to search for sources
# relative to this build (root) directory
# if you use libraries either put them in a sub-directory in src
srcdir := src
# or add it here
#srcdir += library1
srcdir += $(variantdir)
srcdir += $(core_name)/libraries/Servo/src
srcdir += $(core_name)/libraries/SPI/src
srcdir += $(core_name)/libraries/IWatchdog/src/
# add marlin sources
# subdirectories are used to prevent recursion into Marlin/Marlin/src/HAL
# HAL is board/chip specific
marlindir := Marlin/Marlin
srcdir += $(marlindir)/src/core
srcdir += $(marlindir)/src/feature
srcdir += $(marlindir)/src/gcode
srcdir += $(marlindir)/src/inc
srcdir += $(marlindir)/src/lcd
srcdir += $(marlindir)/src/libs
srcdir += $(marlindir)/src/module
srcdir += $(marlindir)/src/sd
srcdir += $(marlindir)/src/HAL/shared
srcdir += $(marlindir)/src/HAL/STM32
$(info $(srcdir))
# sources to exclude
# excludelist is from platformio.ini
# to exclude full directory use % wildcard as suffix
marexcl :=
marexcl += src/lcd/HD44780/%
marexcl += src/lcd/TFTGLCD/%
marexcl += src/lcd/dwin/%
marexcl += src/lcd/dogm/%
marexcl += src/lcd/tft/%
marexcl += src/lcd/tft_io/%
marexcl += src/HAL/STM32/tft/%
marexcl += src/HAL/STM32F1/tft/%
#marexcl += src/lcd/menu/%
#
marexcl += src/lcd/menu/game/game.cpp
marexcl += src/lcd/menu/game/brickout.cpp
marexcl += src/lcd/menu/game/invaders.cpp
marexcl += src/lcd/menu/game/maze.cpp
marexcl += src/lcd/menu/game/snake.cpp
#
marexcl += src/lcd/menu/menu_backlash.cpp
marexcl += src/lcd/menu/menu_bed_corners.cpp
marexcl += src/lcd/menu/menu_bed_leveling.cpp
marexcl += src/lcd/menu/menu_cancelobject.cpp
marexcl += src/lcd/menu/menu_delta_calibrate.cpp
marexcl += src/lcd/menu/menu_filament.cpp
marexcl += src/lcd/menu/menu_info.cpp
marexcl += src/lcd/menu/menu_job_recovery.cpp
marexcl += src/lcd/menu/menu_language.cpp
marexcl += src/lcd/menu/menu_led.cpp
marexcl += src/lcd/menu/menu_media.cpp
marexcl += src/lcd/menu/menu_mmu2.cpp
marexcl += src/lcd/menu/menu_password.cpp
marexcl += src/lcd/menu/menu_power_monitor.cpp
marexcl += src/lcd/menu/menu_spindle_laser.cpp
marexcl += src/lcd/menu/menu_temperature.cpp
marexcl += src/lcd/menu/menu_tmc.cpp
marexcl += src/lcd/menu/menu_touch_screen.cpp
marexcl += src/lcd/menu/menu_tramming.cpp
marexcl += src/lcd/menu/menu_ubl.cpp
marexcl += src/lcd/extui/anycubic_chiron/%
marexcl += src/lcd/extui/anycubic_i3mega/%
#
marexcl += src/lcd/extui/dgus/%
marexcl += src/lcd/extui/dgus/fysetc/%
marexcl += src/lcd/extui/dgus/hiprecy/%
marexcl += src/lcd/extui/dgus/mks/%
marexcl += src/lcd/extui/dgus/origin/%
#
marexcl += src/lcd/extui/example/%
marexcl += src/lcd/extui/ftdi_eve_touch_ui/%
marexcl += src/lcd/extui/malyan/%
marexcl += src/lcd/extui/mks_ui/%
marexcl += src/lcd/extui/nextion/%
marexcl += src/lcd/lcdprint.cpp
marexcl += src/lcd/touch/touch_buttons.cpp
# flash
marexcl += src/sd/usb_flashdrive/lib-uhs2/%
marexcl += src/sd/usb_flashdrive/lib-uhs3/%
marexcl += src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp
# sd
marexcl += src/sd/cardreader.cpp
marexcl += src/sd/Sd2Card.cpp
marexcl += src/sd/SdBaseFile.cpp
marexcl += src/sd/SdFatUtil.cpp
marexcl += src/sd/SdFile.cpp
marexcl += src/sd/SdVolume.cpp
marexcl += src/gcode/sd
#
#marexcl += src/HAL/shared/backtrace/%
marexcl += src/HAL/shared/cpu_exception/%
marexcl += src/HAL/shared/eeprom_if_i2c.cpp
marexcl += src/HAL/shared/eeprom_if_spi.cpp
marexcl += src/feature/babystep.cpp
marexcl += src/feature/backlash.cpp
# baricuda
marexcl += src/feature/baricuda.cpp
marexcl += src/gcode/feature/baricuda/%
# auto bed level
marexcl += src/feature/bedlevel/abl/%
marexcl += src/gcode/bedlevel/abl/%
# mesh bed level
marexcl += src/feature/bedlevel/mbl/%
marexcl += src/gcode/bedlevel/mbl/%
# unified bed level
marexcl += src/feature/bedlevel/ubl/%
marexcl += src/gcode/bedlevel/ubl/%
#
marexcl += src/feature/bedlevel/hilbert_curve.cpp
# hestshrink decoder
marexcl += src/feature/binary_stream.cpp
marexcl += src/libs/heatshrink
#
marexcl += src/feature/bltouch.cpp
# cancel object
marexcl += src/feature/cancel_object.cpp
marexcl += src/gcode/feature/cancel
# caselight
marexcl += src/feature/caselight.cpp
marexcl += src/gcode/feature/caselight
#
marexcl += src/feature/closedloop.cpp
# controller fan
marexcl += src/feature/controllerfan.cpp
marexcl += src/gcode/feature/controllerfan
# cooler
marexcl += src/feature/cooler.cpp
marexcl += src/gcode/temp/M143_M193.cpp
# dac/digipot
marexcl += src/feature/dac/%
marexcl += src/feature/digipot/%
# direct stepping
marexcl += src/feature/direct_stepping.cpp
marexcl += src/gcode/motion/G6.cpp
#
marexcl += src/feature/e_parser.cpp
marexcl += src/feature/encoder_i2c.cpp
# ethernet
marexcl += src/feature/ethernet.cpp
marexcl += src/gcode/feature/network/M552-M554.cpp
#
marexcl += src/feature/fanmux.cpp
# fil width
marexcl += src/feature/filwidth.cpp
marexcl += src/gcode/feature/filwidth/%
# firmware retract
marexcl += src/feature/fwretract.cpp
marexcl += src/gcode/feature/fwretract/%
#
marexcl += src/feature/host_actions.cpp
marexcl += src/feature/hotend_idle.cpp
marexcl += src/feature/joystick.cpp
marexcl += src/feature/leds/blinkm.cpp
marexcl += src/feature/leds/leds.cpp
marexcl += src/feature/leds/neopixel.cpp
marexcl += src/feature/leds/pca9533.cpp
marexcl += src/feature/leds/pca9632.cpp
marexcl += src/feature/leds/printer_event_leds.cpp
marexcl += src/feature/leds/tempstat.cpp
marexcl += src/feature/max7219.cpp
marexcl += src/feature/meatpack.cpp
marexcl += src/feature/mixing.cpp
marexcl += src/feature/mmu/mmu.cpp
# prusa mmu2
marexcl += src/feature/mmu/mmu2.cpp
marexcl += src/gcode/feature/prusa_MMU2/%
#
marexcl += src/feature/password/%
marexcl += src/gcode/feature/password/%
#
marexcl += src/feature/pause.cpp
marexcl += src/feature/power.cpp
# power monitor
marexcl += src/feature/power_monitor.cpp
marexcl += src/gcode/feature/power_monitor
# power loss
marexcl += src/feature/powerloss.cpp
marexcl += src/gcode/feature/powerloss/%
#
marexcl += src/feature/probe_temp_comp.cpp
marexcl += src/feature/repeat.cpp
# runout
marexcl += src/feature/runout.cpp
marexcl += src/gcode/feature/runout
#
marexcl += src/feature/snmm.cpp
# solenoid
marexcl += src/feature/solenoid.cpp
marexcl += src/gcode/control/M380_M381.cpp
# spindle laser
marexcl += src/feature/spindle_laser.cpp
marexcl += src/gcode/control/M3-M5.cpp
#
marexcl += src/feature/stepper_driver_safety.cpp
# trinamic
marexcl += src/feature/tmc_util.cpp
marexcl += src/module/stepper/trinamic.cpp
#
marexcl += src/feature/tramming.cpp
marexcl += src/feature/twibus.cpp
marexcl += src/feature/z_stepper_align.cpp
# G26 - Mesh Validation Pattern
marexcl += src/gcode/bedlevel/G26.cpp
# G35 - Tramming Assistant
marexcl += src/gcode/bedlevel/G35.cpp
# G42 - Move to mesh coordinate
marexcl += src/gcode/bedlevel/G42.cpp
# bedlevel
#marexcl += src/gcode/bedlevel/M420.cpp
#marexcl += src/feature/bedlevel/bedlevel.cpp
# G33 - Delta Auto Calibration
marexcl += src/gcode/calibrate/G33.cpp
# G34 - Z Steppers Auto-Alignment, M422 - Set Z Motor XY
marexcl += src/gcode/calibrate/G34.cpp
marexcl += src/gcode/calibrate/G34_M422.cpp
# G76 - Probe temperature calibration
marexcl += src/gcode/calibrate/G76_M192_M871.cpp
# G425 - Backlash Calibration
marexcl += src/gcode/calibrate/G425.cpp
#
marexcl += src/gcode/calibrate/M12.cpp
# M48 - Probe Accuracy Test
marexcl += src/gcode/calibrate/M48.cpp
# M100 - Free Memory
marexcl += src/gcode/calibrate/M100.cpp
# M425 - Backlash compensation
marexcl += src/gcode/calibrate/M425.cpp
# M666 - Set Delta endstop adjustment
marexcl += src/gcode/calibrate/M666.cpp
# M852 - Bed Skew Compensation
marexcl += src/gcode/calibrate/M852.cpp
# M10-M11 - Vacuum / Blower Control
marexcl += src/gcode/control/M10-M11.cpp
# m42 set pin state, m226 wait for pin state
#marexcl += src/gcode/control/M42.cpp
#marexcl += src/gcode/control/M226.cpp
# M43 T - Toggle Pins
#marexcl += src/gcode/config/M43.cpp
# M217 - Filament swap parameters
marexcl += src/gcode/config/M217.cpp
# M218 - Set Hotend Offset
marexcl += src/gcode/config/M218.cpp
# M221 - Set Flow Percentage
#marexcl += src/gcode/config/M221.cpp
# M281 - Edit Servo Angles
marexcl += src/gcode/config/M281.cpp
# M301 - Set Hotend PID
#marexcl += src/gcode/config/M301.cpp
# M302 - Cold Extrude
#marexcl += src/gcode/config/M302.cpp
# M304 - Set Bed PID
marexcl += src/gcode/config/M304.cpp
# M305 - User Thermistor Parameters
marexcl += src/gcode/config/M305.cpp
# M540 - Endstops Abort SD
marexcl += src/gcode/config/M540.cpp
# M575 - Serial baud rate
marexcl += src/gcode/config/M575.cpp
# M672 - Test Speed Warning
marexcl += src/gcode/config/M672.cpp
# M7-M9 - Coolant Controls
marexcl += src/gcode/control/M7-M9.cpp
# M211 - Software Endstops
#marexcl += src/gcode/control/M211.cpp
# M350 - Set micro-stepping
marexcl += src/gcode/control/M350_M351.cpp
# M605 - Dual Nozzle Mode
marexcl += src/gcode/control/M605.cpp
marexcl += src/gcode/feature/advance
marexcl += src/gcode/feature/camera
marexcl += src/gcode/feature/i2c
marexcl += src/gcode/feature/L6470
# M150 - Set RGB(W) Color
marexcl += src/gcode/feature/leds/M150.cpp
# Max7219 LED matrix
marexcl += src/gcode/feature/leds/M7219.cpp
marexcl += src/gcode/feature/macro
# mixing M163 - Set Mix Factor, M164 - Save Mix, M165 - Set Mix
marexcl += src/gcode/feature/mixing/M163-M165.cpp
# M166 - Gradient Mix
marexcl += src/gcode/feature/mixing/M166.cpp
# G27 - Park toolhead
marexcl += src/gcode/feature/pause/G27.cpp
# G60 - Save Current Position
marexcl += src/gcode/feature/pause/G60.cpp
# G61 - Return to Saved Position
marexcl += src/gcode/feature/pause/G61.cpp
# M125 - Park Head
marexcl += src/gcode/feature/pause/M125.cpp
# M600 - Filament Change
marexcl += src/gcode/feature/pause/M600.cpp
# M603 - Configure Filament Change
marexcl += src/gcode/feature/pause/M603.cpp
# M701 - Load filament, M702 - Unload filament
marexcl += src/gcode/feature/pause/M701_M702.cpp
# M122 - TMC Debugging
marexcl += src/gcode/feature/trinamic/M122.cpp
# M569 - Set TMC stepping mode
marexcl += src/gcode/feature/trinamic/M569.cpp
# M906 - TMC Motor Current
marexcl += src/gcode/feature/trinamic/M906.cpp
# M911 - TMC OT Pre-Warn Condition, M912 - Clear TMC OT Pre-Warn,
# M913 - Set Hybrid Threshold Speed, M914 - TMC Bump Sensitivity
marexcl += src/gcode/feature/trinamic/M911-M914.cpp
# G17-G19 - CNC Workspace Planes
marexcl += src/gcode/geometry/G17-G19.cpp
# G53 - Move in Machine Coordinates
# G54-G59.3 - Workspace Coordinate System
marexcl += src/gcode/geometry/G53-G59.cpp
# M206 - Set Home Offsets, M428 - Home Offsets Here
#marexcl += src/gcode/geometry/M206_M428.cpp
# M16 - Expected Printer Check
marexcl += src/gcode/host/M16.cpp
# M113 - Host Keepalive
#marexcl += src/gcode/host/M113.cpp
# M154 - Position Auto-Report
marexcl += src/gcode/host/M154.cpp
# M360 - SCARA Theta A
marexcl += src/gcode/host/M360.cpp
# M876 - Handle Prompt Response
marexcl += src/gcode/host/M876.cpp
# M0-M1 - Unconditional stop
marexcl += src/gcode/lcd/M0_M1.cpp
# M117 - Set LCD Message
marexcl += src/gcode/lcd/M117.cpp
# m250 lcd contrast, m256 lcd brightness
marexcl += src/gcode/lcd/M250.cpp
marexcl += src/gcode/lcd/M256.cpp
# M300 - Play Tone
#marexcl += src/gcode/lcd/M300.cpp
# M414: Set the language for the UI
marexcl += src/gcode/lcd/M414.cpp
# M73 - Set Print Progress
marexcl += src/gcode/lcd/M73.cpp
# M995 - Touch Screen Calibration
marexcl += src/gcode/lcd/M995.cpp
# G2-G3 - Arc or Circle Move
#marexcl += src/gcode/motion/G2_G3.cpp
# G5 - Bézier cubic spline
marexcl += src/gcode/motion/G5.cpp
# G80 - Cancel Current Motion Mode
marexcl += src/gcode/motion/G80.cpp
# M290 - Babystep
marexcl += src/gcode/motion/M290.cpp
# G30 - Single Z-Probe
marexcl += src/gcode/probe/G30.cpp
# G31 - Dock Sled, G32 - Undock Sled,
marexcl += src/gcode/probe/G31_G32.cpp
# G38.2-G38.5 - Probe target
marexcl += src/gcode/probe/G38.cpp
# M401 - Deploy Probe, M402 - Stow Probe
marexcl += src/gcode/probe/M401_M402.cpp
# M851 - XYZ Probe Offset
marexcl += src/gcode/probe/M851.cpp
# M951 - Magnetic Parking Extruder
marexcl += src/gcode/probe/M951.cpp
marexcl += src/gcode/scara/%
marexcl += src/gcode/sd/%
# M32 - Select and Start
marexcl += src/gcode/sd/M32.cpp
# M808 - Repeat Marker
marexcl += src/gcode/sd/M808.cpp
# M104 - Set Hotend Temperature, M109 - Wait for Hotend Temperature
#marexcl += src/gcode/temp/M104_M109.cpp
# M155 - Temperature Auto-Report
#marexcl += src/gcode/temp/M155.cpp
# G20 - Inch Units, G21 - Millimeter Units
marexcl += src/gcode/units/G20_G21.cpp
# M82 - E Absolute, M83 - E Relative
#marexcl += src/gcode/units/M82_M83.cpp
#marexcl += src/gcode/units/M149.cpp
# spi flash
marexcl += src/libs/BL24CXX.cpp
marexcl += src/libs/W25Qxx.cpp
# l64xx stepper driver
marexcl += src/libs/L64XX
marexcl += src/module/stepper/L64xx.cpp
marexcl += src/HAL/shared/HAL_spi_L6470.cpp
#
marexcl += src/libs/MAX31865.cpp
marexcl += src/libs/hex_print.cpp
marexcl += src/libs/least_squares_fit.cpp
# nozzle clean
marexcl += src/libs/nozzle.cpp
marexcl += src/gcode/feature/clean
#
marexcl += src/module/delta.cpp
marexcl += src/module/planner_bezier.cpp
marexcl += src/module/printcounter.cpp
marexcl += src/module/probe.cpp
# scara
marexcl += src/module/scara.cpp
marexcl += src/gcode/calibrate/M665.cpp
# servo
#marexcl += src/module/servo.cpp
#marexcl += src/gcode/control/M280.cpp
#
marexcl += src/module/stepper/TMC26X.cpp
exclsrc := $(addprefix $(marlindir)/,$(marexcl))
# add leafnodes marlin source files - to avoid recursion
cxxadd := $(marlindir)/src/MarlinCore.cpp
#this is the ld script in STM32F1/variants/$(variant)/ld to use
#ldscript := bootloader_20.ld
ldscript := ldscript.ld
LD_SCRIPT_PATH := $(variantdir)/$(ldscript)
#LD_SCRIPT_PATH := variants/Pill_F401CC/$(ldscript)
#add_ld_script:=src/board.ld
#this is the startup asm file, mcu specific
start_mcu_name := stm32f407xx
start_asm_file := ${start_file_path}/startup_${start_mcu_name}.s
#the includes i.e. the -Ipath needs to be exlicitly stated
#no automatic recursive searching
#if you use libraries you may want to add it here
includedir := $(srcdir)
includedir += $(variantdir)
includedir += $(CMSIS_path)/CMSIS/Core/Include
includedir += $(build_system_path)/Drivers/CMSIS/Device/ST/$(build_series)/Include/
#includedir += $(build_system_path)/Drivers/CMSIS/Device/ST/$(build_series)/Source/Templates/gcc/
includedir += $(CMSIS_path)/CMSIS/DSP/Include
includedir += $(build_core_path)
includedir += $(build_core_path)/avr
includedir += $(build_core_path)/stm32
includedir += $(build_core_path)/stm32/LL
includedir += $(build_core_path)/stm32/usb
includedir += $(build_core_path)/stm32/usb/hid
includedir += $(build_core_path)/stm32/usb/cdc
includedir += $(build_system_path)/Drivers/$(build_series)_HAL_Driver/Inc
includedir += $(build_system_path)/Drivers/$(build_series)_HAL_Driver/Src
includedir += $(build_system_path)/$(build_series)
includedir += $(build_system_path)/Middlewares/ST/STM32_USB_Device_Library/Core/Inc
includedir += $(build_system_path)/Middlewares/ST/STM32_USB_Device_Library/Core/Src
includedir += $(core_name)/libraries/Servo/src
includedir += $(core_name)/libraries/SPI/src
includedir += $(core_name)/libraries/IWatchdog/src/
#marlin specific includes
includedir += $(marlindir)
includedir += $(marlindir)/src
includedir += $(marlindir)/src/HAL/shared
includedir += $(marlindir)/src/HAL/STM32
includedir += $(marlindir)/src/pins
includedir += $(marlindir)/src/pins/stm32f4
#if you use core_root, you would need to add that as a prefix
#includedir := $(addprefix $(core_root)/,$(includedir))
# update this to match
# this should be the install base location of ARM_NONE_EABI_GCC toolchain
ARM_NONE_EABI_PATH := /opt/arduino/xpack-arm-none-eabi-gcc/9.2.1-1.1/
# this should be the location of the arm standard libraries c & c++
# the arm-none-eabi/lib select the folder matching the arch
# compile options e.g. thumb and v7-m
LD_TOOLCHAIN_PATH := $(ARM_NONE_EABI_PATH)/arm-none-eabi/lib/thumb/v7e-m+fp
# recursive wildcard function, call with params:
# - start directory (finished with /) or empty string for current dir
# - glob pattern
# (taken from http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html)
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
cfiles := $(strip $(foreach s, $(srcdir), $(call rwildcard,$(s),*.c)))
cxxfiles := $(strip $(foreach s, $(srcdir), $(call rwildcard,$(s),*.cpp)))
asfiles := $(strip $(foreach s, $(srcdir), $(call rwildcard,$(s),*.s)))
asfiles += ${start_asm_file}
$(info $(asfiles))
cxxfiles := $(cxxfiles) $(cxxadd)
#exclude sources
cxxfiles := $(filter-out $(exclsrc),$(cxxfiles))
cfiles := $(filter-out $(exclsrc),$(cfiles))
src_files := $(cfiles) $(cxxfiles) $(asfiles)
#$(info $(src_files))
core_cfiles += $(subst $(core_root)/,,$(strip $(foreach s, $(coredir), $(call rwildcard,$(s),*.c))))
core_cxxfiles += $(subst $(core_root)/,,$(strip $(foreach s, $(coredir), $(call rwildcard,$(s),*.cpp))))
core_asfiles += $(subst $(core_root)/,,$(strip $(foreach s, $(coredir), $(call rwildcard,$(s),*.s))))
#exclude due to repeat system init
#core_cfiles := $(filter-out libraries/SrcWrapper/src/stm32/system_stm32yyxx.c,$(core_cfiles))
#$(info $(core_cfiles))
core_files := $(core_cfiles) $(core_cxxfiles) $(core_asfiles)
files := $(src_files) $(core_files)
sdirs := $(sort $(dir $(files)))
$(info $(sdirs))
#hfiles := $(foreach s, $(includedir), $(call rwildcard,$(s),*.h))
#hfiles += $(foreach s, $(srcdir), $(call rwildcard,$(s),*.h))
#incdirs = $(sort $(dir $(hfiles)))
TOOLPREFIX := arm-none-eabi-
CC = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)gcc
CXX = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)g++
AS = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)as
OBJCOPY = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)objcopy
OBJDUMP = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)objdump
AR = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)ar
SIZE = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)size
NM = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)nm
LD = $(ARM_NONE_EABI_PATH)/bin/$(TOOLPREFIX)ld
DFUUTIL = dfu-util
RM = /usr/bin/rm
MKDIR = /usr/bin/mkdir -p
TEST = /usr/bin/test
DEFINES := $(addprefix -D,$(defines))
INCLUDES := $(addprefix -I,$(includedir))
#optimise
# -O0 - none
# -Os - optimise size
# -O1 - optimise
# -O2 - optimise more
# -O3 - optimise most
# -Og - optimise debug
OFLAG := -Os
#debug
# default none
# -g - debug
# -g1 - minimal
# -g3 - maximal
DFLAG = -g
COMMON_OFLAGS := -Wl,--gc-sections $(OFLAG) $(DFLAG) \
-ffunction-sections -fdata-sections \
-fmessage-length=0 -fsigned-char \
-ffreestanding -fno-move-loop-invariants \
--specs=nano.specs -Wall -Wextra
FPU_FLAGS := -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant
#FPU_FLAGS := -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fsingle-precision-constant
TARGET_FLAGS += -mcpu=cortex-m4 -march=armv7e-m+fp -mthumb \
$(FPU_FLAGS) \
$(INCLUDES) $(DEFINES)
GLOBAL_CFLAGS := $(COMMON_OFLAGS) $(TARGET_FLAGS)
TARGET_CFLAGS :=
GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions \
-fno-use-cxa-atexit -fno-threadsafe-statics \
$(COMMON_OFLAGS) \
$(TARGET_FLAGS)
TARGET_CXXFLAGS :=
GLOBAL_ASFLAGS := $(TARGET_FLAGS)
#TARGET_ASFLAGS := -Wl,--gc-sections $(OFLAG) $(DFLAG) -Xassembler -Wall
TARGET_ASFLAGS := -Wl,--gc-sections $(OFLAG) $(DFLAG)
# -nostdlib
# -nodefaultlibs
# -nostartfiles
# -Wl,--gc-sections
GLOBAL_LDFLAGS := --specs=nano.specs \
-Xlinker --gc-sections
TARGET_LDFLAGS := $(TARGET_FLAGS) \
-Xlinker -T$(LD_SCRIPT_PATH) \
-L $(variantdir)
# -Xlinker -T$(add_ld_script)
TARGET_LDFLAGS += -Wl,--defsym,LD_FLASH_OFFSET=$(ld_flash_offset) \
-Wl,--defsym,LD_MAX_SIZE=$(ld_flash_size) \
-Wl,--defsym,LD_MAX_DATA_SIZE=$(ld_sram_size)
CFLAGS = $(GLOBAL_CFLAGS) $(TARGET_CFLAGS)
CXXFLAGS = $(GLOBAL_CXXFLAGS) $(TARGET_CXXFLAGS)
CPPFLAGS =
ASFLAGS = $(GLOBAL_ASFLAGS) $(TARGET_ASFLAGS)
# Add toolchain directory to LD search path
TOOLCHAIN_LDFLAGS := -L $(LD_TOOLCHAIN_PATH) -L $(CMSIS_LD_PATH) -l $(cmsis_lib_gcc)
LDFLAGS = $(GLOBAL_LDFLAGS) $(TARGET_LDFLAGS) $(TOOLCHAIN_LDFLAGS)
#build lists of object files relative to $(out_dir)
COBJS = $(addprefix $(out_dir)/,$(patsubst %.c,%.o,$(cfiles)))
CXXOBJS = $(addprefix $(out_dir)/,$(patsubst %.cpp,%.o,$(cxxfiles)))
ASOBJS = $(addprefix $(out_dir)/,$(patsubst %.s,%.o,$(asfiles)))
CORE_COBJS = $(addprefix $(out_dir)/,$(patsubst %.c,%.o,$(core_cfiles)))
CORE_CXXOBJS = $(addprefix $(out_dir)/,$(patsubst %.cpp,%.o,$(core_cxxfiles)))
CORE_ASOBJS = $(addprefix $(out_dir)/,$(patsubst %.s,%.o,$(core_asfiles)))
variant.ELF = $(out_dir)/$(variant).elf
variant.BIN = $(out_dir)/$(variant).bin
.PHONY: all clean mkdir
all: mkdir $(variant.BIN)
@echo
@$(SIZE) $(variant.ELF)
@echo
@ls -l $(variant.BIN)
@echo
@$(OBJDUMP) --section-headers $(variant.ELF)
@echo
@echo Source dirs
@echo $(srcdir) $(coredir) | sed 's/ /\n/g'
@echo
@echo $(sort $(dir $(src_files))) | sed 's/ /\n/g'
@echo $(addprefix $(core_root)/,$(sort $(dir $(core_files)))) | sed 's/ /\n/g'
@echo
@echo Includes
@echo $(INCLUDES) | sed 's/ /\n/g'
@echo
@echo Defines
@echo $(DEFINES) | sed 's/ /\n/g'
install: all
$(DFUUTIL) -d 0483:df11 -a 0 -s 0x8000000 -D $(variant.BIN)
$(variant.BIN): $(variant.ELF)
$(OBJCOPY) -v -Obinary $(variant.ELF) $@
$(variant.ELF): $(ASOBJS) $(COBJS) $(CXXOBJS) \
$(CORE_COBJS) $(CORE_CXXOBJS) $(CORE_ASOBJS)
$(CXX) $(LDFLAGS) -o $@ -Wl,-Map,$(out_dir)/$(variant).map $+
# General directory independent build rules, generate dependency information
$(COBJS): $(out_dir)/%.o: %.c
$(CC) $(CFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $<
$(CXXOBJS): $(out_dir)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $<
$(ASOBJS): $(out_dir)/%.o: %.s
@echo $(ASOBJS)
$(CC) $(ASFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $<
$(CORE_COBJS): $(out_dir)/%.o: $(core_root)/%.c
$(CC) $(CFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $<
$(CORE_CXXOBJS): $(out_dir)/%.o: $(core_root)/%.cpp
$(CXX) $(CXXFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $<
$(CORE_ASOBJS): $(out_dir)/%.o: $(core_root)/%.s
$(CC) $(ASFLAGS) -MMD -MP -MF $(@:%.o=%.d) -MT $@ -o $@ -c $<
# create the build directories
tgtdirs := $(addsuffix .dir,$(addprefix $(out_dir)/,$(sdirs)))
mkdir: $(tgtdirs)
# the .dir file is a marker file that the directory is created
$(tgtdirs) : $(out_dir)/.dir
$(MKDIR) $(dir $@)
@touch $@
$(out_dir)/.dir:
$(MKDIR) $(dir $@)
@touch $@
clean:
@echo clean
$(RM) -r $(out_dir)
DEPENDS := $(COBJS:%.o=%.d) $(CXXOBJS:%.o=%.d) $(ASOBJS:%.o=%.d)
DEPENDS += $(CORE_COBJS:%.o=%.d) $(CORE_CXXOBJS:%.o=%.d) $(CORE_ASOBJS:%.o=%.d)
-include $(DEPENDS)