-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
162 lines (132 loc) · 5.25 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#
# !!!! Do NOT edit this makefile with an editor which replace tabs by spaces !!!!
#
##############################################################################################
#
# On command line:
#
# make all = Create project
#
# make clean = Clean project files.
#
# To rebuild project do "make clean" and "make all".
#
# Included originally in the yagarto projects. Original Author : Michael Fischer
# Modified to suit our purposes by Hussam Al-Hertani
# Use at your own risk!!!!!
##############################################################################################
# Start of default section
#
CCPREFIX = arm-none-eabi-
CC = $(CCPREFIX)gcc
CP = $(CCPREFIX)objcopy
AS = $(CCPREFIX)gcc -x assembler-with-cpp
GDBTUI = $(CCPREFIX)gdbtui
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
MCU = cortex-m0
# List all C defines here
DDEFS = -DSTM32F0XX -DUSE_STDPERIPH_DRIVER
#
# Define project name and Ram/Flash mode here
PROJECT = iotogglem0_wspl
# List C source files here
LIBSDIRS = ../../STM32F0308-Discovery_FW_V1.0.1/Libraries
CORELIBDIR = $(LIBSDIRS)/CMSIS/Include
DEVDIR = $(LIBSDIRS)/CMSIS/Device/ST/STM32F0xx
STMSPDDIR = $(LIBSDIRS)/STM32F0xx_StdPeriph_Driver
STMSPSRCDDIR = $(STMSPDDIR)/src
STMSPINCDDIR = $(STMSPDDIR)/inc
DISCOVERY = ../../STM32F0308-Discovery_FW_V1.0.1/Utilities/STM32F0308-Discovery
#list of src files to include in build process
SRC = ./src/main.c
SRC += ./src/stm32f0xx_it.c
SRC += $(DEVDIR)/Source/Templates/system_stm32f0xx.c
## used parts of the STM-Library
#SRC += $(STMSPSRCDDIR)/stm32f0xx_adc.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_cec.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_crc.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_comp.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_dac.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_dbgmcu.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_dma.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_exti.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_flash.c
SRC += $(STMSPSRCDDIR)/stm32f0xx_gpio.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_syscfg.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_i2c.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_iwdg.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_pwr.c
SRC += $(STMSPSRCDDIR)/stm32f0xx_rcc.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_rtc.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_spi.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_tim.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_usart.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_wwdg.c
#SRC += $(STMSPSRCDDIR)/stm32f0xx_misc.c
# List assembly startup source file here
STARTUP = ./startup/startup_stm32f0xx.s
# List all directories here
INCDIRS = $(DEVDIR)/Include \
$(CORELIBDIR) \
$(STMSPINCDDIR) \
$(DISCOVERY) \
./inc
# List the user directory to look for the libraries here
LIBDIRS += $(LIBSDIRS)
# List all user libraries here
LIBS =
# Define optimisation level here
OPT = -Os
# Define linker script file here
LINKER_SCRIPT = ./linker/stm32f0_linker.ld
INCDIR = $(patsubst %,-I%, $(INCDIRS))
LIBDIR = $(patsubst %,-L%, $(LIBDIRS))
LIB = $(patsubst %,-l%, $(LIBS))
##reference only flags for run from ram...not used here
##DEFS = $(DDEFS) $(UDEFS) -DRUN_FROM_FLASH=0 -DVECT_TAB_SRAM
## run from Flash
DEFS = $(DDEFS) -DRUN_FROM_FLASH=1
OBJS = $(STARTUP:.s=.o) $(SRC:.c=.o)
MCFLAGS = -mcpu=$(MCU)
ASFLAGS = $(MCFLAGS) -g -gdwarf-2 -mthumb -Wa,-amhls=$(<:.s=.lst)
CPFLAGS = $(MCFLAGS) $(OPT) -g -gdwarf-2 -mthumb -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)
LDFLAGS = $(MCFLAGS) -g -gdwarf-2 -mthumb -nostartfiles -T$(LINKER_SCRIPT) -Wl,-Map=$(PROJECT).map,--cref,--no-warn-mismatch $(LIBDIR) $(LIB)
#
# makefile rules
#
all: $(OBJS) $(PROJECT).elf $(PROJECT).hex $(PROJECT).bin
$(TRGT)size $(PROJECT).elf
%o: %c
$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
%o: %s
$(AS) -c $(ASFLAGS) $< -o $@
%elf: $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) $(LIBS) -o $@
%hex: %elf
$(HEX) $< $@
%bin: %elf
$(BIN) $< $@
flash_openocd: $(PROJECT).bin
openocd -s ~/EmbeddedArm/openocd-bin/share/openocd/scripts/ -f interface/stlink-v2.cfg -f target/stm32f0x_stlink.cfg -c "init" -c "reset halt" -c "sleep 100" -c "wait_halt 2" -c "flash write_image erase $(PROJECT).bin 0x08000000" -c "sleep 100" -c "verify_image $(PROJECT).bin 0x08000000" -c "sleep 100" -c "reset run" -c shutdown
flash_stlink: $(PROJECT).bin
st-flash write $(PROJECT).bin 0x8000000
erase_openocd:
openocd -s ~/EmbeddedArm/openocd-bin/share/openocd/scripts/ -f interface/stlink-v2.cfg -f target/stm32f0x_stlink.cfg -c "init" -c "reset halt" -c "sleep 100" -c "stm32f1x mass_erase 0" -c "sleep 100" -c shutdown
erase_stlink:
st-flash erase
debug_openocd: $(PROJECT).elf flash_openocd
xterm -e openocd -s ~/EmbeddedArm/openocd-bin/share/openocd/scripts/ -f interface/stlink-v2.cfg -f target/stm32f0x_stlink.cfg -c "init" -c "halt" -c "reset halt" &
$(GDBTUI) --eval-command="target remote localhost:3333" $(PROJECT).elf
debug_stlink: $(PROJECT).elf
xterm -e st-util &
$(GDBTUI) --eval-command="target remote localhost:4242" $(PROJECT).elf -ex 'load'
clean:
-rm -rf $(OBJS)
-rm -rf $(PROJECT).elf
-rm -rf $(PROJECT).map
-rm -rf $(PROJECT).hex
-rm -rf $(PROJECT).bin
-rm -rf $(SRC:.c=.lst)
-rm -rf $(ASRC:.s=.lst)
# *** EOF ***