This repository was archived by the owner on Oct 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplatform.mk
More file actions
144 lines (114 loc) · 5.06 KB
/
Copy pathplatform.mk
File metadata and controls
144 lines (114 loc) · 5.06 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Helper scripts location
SCRIPT_DIR := $(PLATFORM_DIR)/scripts
# Specify toolchain
CC := $(GCC_ARM_BASE)arm-none-eabi-gcc
LD := $(GCC_ARM_BASE)arm-none-eabi-gcc
OBJCPY := $(GCC_ARM_BASE)arm-none-eabi-objcopy
OBJDUMP := $(GCC_ARM_BASE)arm-none-eabi-objdump
SIZE := bash $(SCRIPT_DIR)/pretty_size.sh $(GCC_ARM_BASE)arm-none-eabi-size
AR := $(GCC_ARM_BASE)arm-none-eabi-gcc-ar
GDB := $(GCC_ARM_BASE)arm-none-eabi-gdb
OPENOCD := openocd
# Set the library to include if using this platform
PLATFORM_LIB := stm32f0xx
PLATFORM_EXT := .elf
# Architecture dependent variables
ARCH_CFLAGS := -mlittle-endian -mcpu=cortex-m0 -march=armv6-m -mthumb
# Linker script location
LDSCRIPT_DIR := $(PLATFORM_DIR)/ldscripts
# Location of newlib binaries with debug symbols enabled
NEWLIB_DEBUG_DIR := $(PLATFORM_DIR)/newlib-debug
# Build flags for the device
CDEFINES := USE_STDPERIPH_DRIVER STM32F072 HSE_VALUE=32000000
CFLAGS := -Wall -Wextra -Werror -g3 -Os -std=c11 -Wno-discarded-qualifiers \
-Wno-unused-variable -Wno-unused-parameter -Wsign-conversion -Wpointer-arith \
-ffunction-sections -fdata-sections \
$(ARCH_CFLAGS) $(addprefix -D,$(CDEFINES))
# Linker flags - linker script set per target
LDFLAGS := -L$(LDSCRIPT_DIR) -Wl,--gc-sections -Wl,--undefined=uxTopUsedPriority \
--specs=nosys.specs --specs=nano.specs -lm
ifeq (true,$(STDLIB_DEBUG))
CFLAGS += -nostdlib
LDFLAGS := $(filter-out --specs=nosys.specs --specs=nano.specs,$(LDFLAGS)) -L$(NEWLIB_DEBUG_DIR) -lc
endif
# temporary build mechanism for applications: set DEFAULT_LINKER_SCRIPT=stm32f0_application.ld
DEFAULT_LINKER_SCRIPT ?= stm32f0_default.ld
ifeq ($(MAKECMDGOALS),temp-bootloader-write)
DEFAULT_LINKER_SCRIPT := stm32f0_application.ld
CFLAGS += -DBOOTLOADER_APPLICATION
endif
# Device openocd config file
# Use PROBE=stlink-v2 for discovery boards
PROBE=cmsis-dap
OPENOCD_SCRIPT_DIR := /usr/share/openocd/scripts/
OPENOCD_CFG := -s $(OPENOCD_SCRIPT_DIR) \
-f interface/$(PROBE).cfg \
-f target/stm32f0x.cfg \
-c "$$(python3 $(SCRIPT_DIR)/select_programmer.py $(SERIAL))" \
-f $(SCRIPT_DIR)/stm32f0-openocd.cfg \
-c 'stm32f0x.cpu configure -rtos FreeRTOS'
# Default CAN channel for Babydriver
CHANNEL ?= can0
# Platform targets
.PHONY: program gdb target babydriver analyzestack temp-bootloader-write
BABYDRIVER_DIR := $(PROJ_DIR)/baby_driver/scripts
babydriver:
@make program PROJECT=baby_driver
@python3 -i $(BABYDRIVER_DIR)/repl_setup.py --channel $(CHANNEL)
ANALYZESTACK_DIR := $(PLATFORM_DIR)/scripts/stack_analyzer
ANNOTATION_FILE := analyzestack.yaml
# We use the $(T)_DIR variables built up by the build to include annotation files from all dependencies.
analyzestack: clean build
@python3 $(ANALYZESTACK_DIR)/stack_analyzer.py $(BIN_DIR)/$(PROJECT)$(PLATFORM_EXT) \
$(addprefix --annotation ,$(wildcard \
$(foreach dep,$($(PROJECT)_DEPS) $(PROJECT),$($(dep)_DIR)/$(ANNOTATION_FILE))))
ifeq (,$(MACOS_SSH_USERNAME))
program: $(TARGET_BINARY:$(PLATFORM_EXT)=.bin)
@sudo $(OPENOCD) $(OPENOCD_CFG) -c "stm_flash $<" -c shutdown
gdb: $(TARGET_BINARY)
@pkill $(OPENOCD) || true
@setsid $(OPENOCD) $(OPENOCD_CFG) > /dev/null 2>&1 &
@$(GDB) $< -x "$(SCRIPT_DIR)/gdb_flash"
@pkill $(OPENOCD)
# ABSOLUTELY, COMPLETELY, ENTIRELY TEMPORARY: build + flash the bootloader preloaded with an application
# ONCE IT IS NO LONGER NECESSARY, REMOVE THIS AND ALL ITS REFERENCES
# application code starts at 48K (bootloader) + 2K (config page 1) + 2K (config page 2) = 53248
temp-bootloader-write: $(TARGET_BINARY:$(PLATFORM_EXT)=.bin) $(BIN_DIR)/bootloader.bin
@cp $(BIN_DIR)/bootloader.bin $(BIN_DIR)/bootloader-ready.bin
@dd if=$(TARGET_BINARY:$(PLATFORM_EXT)=.bin) of=$(BIN_DIR)/bootloader-ready.bin bs=1 seek=53248
@$(OPENOCD) $(OPENOCD_CFG) -c "stm_flash $(BIN_DIR)/bootloader-ready.bin" -c shutdown
define session_wrapper
pkill $(OPENOCD) || true
setsid $(OPENOCD) $(OPENOCD_CFG) > /dev/null 2>&1 &
$1; pkill $(OPENOCD)
endef
# Defines command to run for unit testing
define test_run
clear && $(GDB) $1 -x "$(SCRIPT_DIR)/gdb_flash" -ex "b LoopForever" -ex "c" -ex "set confirm off" -ex "q"
endef
else
# VirtualBox default NAT IP
MACOS_SSH_IP := 10.0.2.2
MAKE_ARGS := TEST PROJECT LIBRARY PLATFORM PROBE SERIAL
MAKE_PARAMS := $(foreach arg,$(MAKE_ARGS),$(arg)=$($(arg)))
SSH_CMD := ssh -t $(MACOS_SSH_USERNAME)@$(MACOS_SSH_IP) "bash -c 'cd $(MACOS_SSH_BOX_PATH)/shared/firmware_xiv && make $(MAKECMDGOALS) $(MAKE_PARAMS)'"
.PHONY: unsupported run_ssh
# Use additional dependencies - hopefully they run first, otherwise we'll build unnecessarily
# Unfortunately this only works part of the time
test_all: unsupported
test: run_ssh
# Host is macOS so we can't pass the programmer through - do it all through SSH
program gdb temp-bootloader-write:
@echo "Running command through SSH"
@$(SSH_CMD)
ifneq (,$(TEST))
run_ssh:
@echo "Running command through SSH"
@$(SSH_CMD:make=make -o $(TARGET_BINARY))
else
run_ssh: unsupported
endif
unsupported:
@echo "Please specify a single test to run."
@echo "Consecutive tests for STM32F0xx are not supported on a macOS host." && false
endif