forked from squadracorsepolito/tlb_battery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
125 lines (99 loc) · 4.08 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -----------------------------------------------------------------------------
# Title : Cmake makefile for stm32 compilation with cubeMX
# Author : Simone Ruffini <[email protected]>
# Date : Wed May 17 10:37:43 PM CEST 2023
# Notes :
#
# License:
# "THE BEER-WARE LICENSE" (Revision 69):
# Squadra Corse firmware team wrote this project. As long as you retain this
# notice you can do whatever you want with this stuff. If we meet some day,
# and you think this stuff is worth it, you can buy us a beer in return.
# Copyright squadracorsepolito.it
# -----------------------------------------------------------------------------
.PHONY: all erase flash flash_can flash_bootloader build build_srec cmake clean
# User options
# Build type: Debug|Release
# By default = Debug
BUILD_TYPE ?= Debug
# Binary is shifted for bootloader space
# By default = off (firmware will boot without a bootloader)
IS_SHIFTED ?= OFF
BUILD_DIR := build
PROJECT_NAME = tlb_battery
CAN_TX_HEX_ID= 8
CAN_RX_HEX_ID= 182
# Handy aliases
TARGET = tlb_battery
all: build
# Makefile generated by CMAKE
${BUILD_DIR}/Makefile:
# -B: specify build directory where to store files/generate makefile
# -D: cmake options when CMakeList.txt is evaluated
# - PROJECT_NAME : not optional!
# - CMAKE_BUILD_TYPE : output is compiled for debug or realease mode
# - BOOTLOADER_SPACE_EN : whether to compile with space for the
# bootloader (the firmware will not run without one) or without (normal)
# - CMAKE_EXPORT_COMPILE_COMMANDS: export the compilation units compile
# commands in a file called "compile_commands.json" in the build directory
echo shifted ${IS_SHIFTED};
cmake \
-B${BUILD_DIR} \
-DPROJECT_NAME=${PROJECT_NAME} \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DBOOTLOADER_SPACE_EN=${IS_SHIFTED} \
-DCMAKE_EXPORT_COMPILE_COMMANDS=true
cmake: ${BUILD_DIR}/Makefile
# Always touch the CMakeList so that it gets re-evaluated on the next build
# Use this hack for GLOBS
touch ./CMakeLists.txt
build: cmake
# -j: use all available threads
# -C: change to BUILD_DIR directory
# --no-print-directory: don't show the above directory change in the log
$(MAKE) -j -C ${BUILD_DIR} --no-print-directory
#######################################
# clean
#######################################
clean:
rm -rf -fR $(BUILD_DIR)
#######################################
# erase flash of micro
#######################################
erase:
openocd -f ./openocd.cfg -c "init; reset halt; stm32f4x mass_erase 0; exit"
#######################################
# flash
#######################################
# Generating the .elf/.hex/.bin depends on running CMAKE and generating the makefile
$(BUILD_DIR)/$(TARGET).elf: build
$(BUILD_DIR)/$(TARGET).hex: build
$(BUILD_DIR)/$(TARGET).bin: build
# Flashing can happen only if the compile output is built
flash: $(BUILD_DIR)/$(TARGET).elf
openocd -f ./openocd.cfg -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit"
#######################################
# flash bootloader
#######################################
flash_bootloader:
openocd -f ./openocd.cfg -c "program $(BUILDIR)/openblt_f446re.elf verify reset exit"
#######################################
# debug
#######################################
debug: flash
openocd -f ./openocd.cfg
#######################################
# build srec binary file
#######################################
$(BUILD_DIR)/$(TARGET)_shifted.hex: build
$(BUILD_DIR)/$(TARGET)_shifted.elf: build
$(BUILD_DIR)/$(TARGET)_shifted.bin: build
$(BUILD_DIR)/$(TARGET)_shifted.sx : $(BUILD_DIR)/$(TARGET)_shifted.bin
bin2srec -a $$(grep 'FLASH (rx) : ORIGIN =' STM32F446RETx_FLASH_shifted.ld | awk '{print $$6}' | sed 's/.$$//') \
-i $(BUILD_DIR)/$(TARGET)_shifted.bin -o $(BUILD_DIR)/$(TARGET)_shifted.sx
build_srec: $(BUILD_DIR)/$(TARGET)_shifted.sx
#######################################
# can flash
#######################################
flash_can : $(BUILD_DIR)/$(TARGET)_shifted.sx
BootCommander -t=xcp_can -d=can0 -b=1000000 -tid=$(CAN_TX_HEX_ID)h -rid=$(CAN_RX_HEX_ID)h $(BUILD_DIR)/$(TARGET)_shifted.sx