forked from deadsy/grbl_stm32f4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
126 lines (108 loc) · 3.11 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
126
# cross compilation tools
XTOOLS_DIR = /opt/gcc-arm-none-eabi-4_8-2014q2
X_LIBC_DIR = $(XTOOLS_DIR)/arm-none-eabi/lib/armv7e-m/fpu
X_LIBGCC_DIR = $(XTOOLS_DIR)/lib/gcc/arm-none-eabi/4.8.3/armv7e-m/fpu
X_CC = $(XTOOLS_DIR)/bin/arm-none-eabi-gcc
X_OBJCOPY = $(XTOOLS_DIR)/bin/arm-none-eabi-objcopy
X_AR = $(XTOOLS_DIR)/bin/arm-none-eabi-ar
X_LD = $(XTOOLS_DIR)/bin/arm-none-eabi-ld
X_GDB = $(XTOOLS_DIR)/bin/arm-none-eabi-gdb
OUTPUT = grbl_stm32f4
USB_SERIAL = 0
# grbl sources
GRBL_DIR = ./grbl/grbl-master
SRC = $(GRBL_DIR)/coolant_control.c \
$(GRBL_DIR)/delay.c \
$(GRBL_DIR)/eeprom.c \
$(GRBL_DIR)/gcode.c \
$(GRBL_DIR)/limits.c \
$(GRBL_DIR)/main.c \
$(GRBL_DIR)/motion_control.c \
$(GRBL_DIR)/nuts_bolts.c \
$(GRBL_DIR)/planner.c \
$(GRBL_DIR)/print.c \
$(GRBL_DIR)/protocol.c \
$(GRBL_DIR)/report.c \
$(GRBL_DIR)/settings.c \
$(GRBL_DIR)/spindle_control.c \
$(GRBL_DIR)/stepper.c \
$(GRBL_DIR)/serial.c \
# hal sources
HAL_DIR = ./hal/src
SRC += $(HAL_DIR)/stm32f4xx_hal.c \
$(HAL_DIR)/stm32f4xx_hal_rcc.c \
$(HAL_DIR)/stm32f4xx_hal_cortex.c \
$(HAL_DIR)/stm32f4xx_hal_gpio.c \
$(HAL_DIR)/stm32f4xx_hal_tim.c \
$(HAL_DIR)/stm32f4xx_hal_tim_ex.c \
# board sources
BOARD_DIR = ./board
SRC += $(BOARD_DIR)/main.c \
$(BOARD_DIR)/system_stm32f4xx.c \
$(BOARD_DIR)/stm32f4xx_it.c \
$(BOARD_DIR)/syscalls.c \
$(BOARD_DIR)/gpio.c \
$(BOARD_DIR)/debounce.c \
$(BOARD_DIR)/timers.c \
$(BOARD_DIR)/stm32f4_regs.c \
# usb/uart sources
USB_DIR = ./usb
ifeq ($(USB_SERIAL), 1)
SRC += $(USB_DIR)/core/usbd_core.c \
$(USB_DIR)/core/usbd_ctlreq.c \
$(USB_DIR)/core/usbd_ioreq.c \
$(USB_DIR)/cdc/usbd_cdc.c \
$(BOARD_DIR)/usbd_conf.c \
$(BOARD_DIR)/usbd_desc.c \
$(BOARD_DIR)/usbd_cdc_interface.c \
$(HAL_DIR)/stm32f4xx_ll_usb.c \
$(HAL_DIR)/stm32f4xx_hal_pcd.c \
$(HAL_DIR)/stm32f4xx_hal_dma.c
else
# uart sources
SRC += $(BOARD_DIR)/usart.c
endif
OBJ = $(patsubst %.c, %.o, $(SRC))
OBJ += $(BOARD_DIR)/start.o
# include files
INC = .
INC += ./cmsis
INC += ./hal/inc
INC += $(BOARD_DIR)
INC += $(GRBL_DIR)
INC += $(USB_DIR)/core
INC += $(USB_DIR)/cdc
INCLUDE = $(addprefix -I,$(INC))
# compiler flags
CFLAGS = -Wall
CFLAGS += -O
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# linker flags
LDSCRIPT = stm32f407vg_flash.ld
LDFLAGS = -T$(LDSCRIPT) -Wl,-Map,$(OUTPUT).map -Wl,--gc-sections
# defines
DEFINES = -DSTM32F407xx
DEFINES += -DENABLE_M7
ifeq ($(USB_SERIAL), 1)
DEFINES += -DUSB_SERIAL
endif
.S.o:
$(X_CC) $(INCLUDE) $(DEFINES) $(CFLAGS) -c $< -o $@
.c.o:
$(X_CC) $(INCLUDE) $(DEFINES) $(CFLAGS) -c $< -o $@
all: grbl_src $(OBJ)
$(X_CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -lm -o $(OUTPUT)
$(X_OBJCOPY) -O binary $(OUTPUT) $(OUTPUT).bin
.PHONY: program
program:
st-flash write $(OUTPUT).bin 0x08000000
.PHONY: grbl_src
grbl_src:
make -C grbl all
clean:
-rm $(OBJ)
-rm $(OUTPUT)
-rm $(OUTPUT).map
-rm $(OUTPUT).bin
make -C grbl clean