summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: e3dde256b0f5960ee7f0bb14b942505280c0d520 (plain) (blame)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/make -f

VERSION		= 1
PATCHLEVEL	= .0
SUBLEVEL	= 
EXTRAVERSION	=
NAME		= little-bird

export	VERSION
export	PATCHLEVEL
export	SUBLEVEL

################################################################################
# Project template for development board STM32F0Discovery
# Uses libraries HAL, which are placed in dedicated
# directory (where is also Makefile for them)
# Andrej Bendzo  <andrej.sl@azet.sk>
# 2016.08.11
#
# Modified for development board STM32L476xx
# Colomar Andrés, Alejandro  <1903716@gmail.com>
# García Pedroche, Francisco Javier  <@.>
# 2018
################################################################################

# This Makefile contains:
# rule "flash", which is intended for writing of program into MCU,
# rule "erase" for erasing Flash memory of MCU
# rule "reset" for system resetting of MCU.

################################################################################
# Beautify output
# ---------------------------------------------------------------------------
# Prefix commands with $(Q) - that's useful
# for commands that shall be hidden in non-verbose mode.
#
#	$(Q)some command here
#
# If BUILD_VERBOSE equals 0 then the above command will be hidden.
# If BUILD_VERBOSE equals 1 then the above command is displayed.
#
# To put more focus on warnings, be less verbose as default
# Use 'make V=1' to see the full commands

ifeq ("$(origin V)","command line")
  BUILD_VERBOSE = $(V)
endif
ifndef BUILD_VERBOSE
  BUILD_VERBOSE = 0
endif

ifeq ($(BUILD_VERBOSE), 1)
  Q =
else
  Q = @
endif

# If the user is running make -s (silent mode), suppress echoing of
# commands

ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
  Q = @
endif

export	Q
export	BUILD_VERBOSE

################################################################################
# Do not print "Entering directory ...",
# but we want to display it when entering to the output directory
# so that IDEs/editors are able to understand relative filenames.
MAKEFLAGS += --no-print-directory

################################################################################
PROGRAMVERSION	= $(VERSION)$(if $(PATCHLEVEL),$(PATCHLEVEL)$(if $(SUBLEVEL),$(SUBLEVEL)))$(EXTRAVERSION)
export	PROGRAMVERSION

################################################################################




#  *****  Basic settings of project  *****
# ==============================================================================

# all the files will be generated with this name (main.elf, main.bin, main.hex, etc)
PROJECT_NAME = main

export	PROJECT_NAME

# ==============================================================================

################################################################################
# directories

MAIN_DIR	= $(CURDIR)
LIBALX_DIR	= $(MAIN_DIR)/libalx/
DRIVERS_DIR	= $(MAIN_DIR)/stm32l4-drivers/
MODULES_DIR	= $(MAIN_DIR)/stm32l4-modules/
SRC_DIR		= $(MAIN_DIR)/src/
INC_DIR		= $(MAIN_DIR)/inc/
DEP_DIR		= $(MAIN_DIR)/dep/
TMP_DIR		= $(MAIN_DIR)/tmp/
BIN_DIR		= $(MAIN_DIR)/bin/

export	MAIN_DIR
export	LIBALX_DIR
export	DRIVERS_DIR
export	MODULES_DIR


################################################################################
# Make variables (CC, etc...)
CC	= arm-none-eabi-gcc
AS	= arm-none-eabi-as
AR	= arm-none-eabi-ar
GDB	= arm-none-eabi-gdb
OBJCOPY	= arm-none-eabi-objcopy
OBJDUMP	= arm-none-eabi-objdump
SIZE	= arm-none-eabi-size

export	CC
export	AS
export	AR
export	GDB
export	OBJCOPY
export	OBJDUMP
export	SIZE


################################################################################
# CFLAGS
CFLAGS_STD	= -std=c11

#CFLAGS_OPT	= -Os

CFLAGS_MCU	= -mlittle-endian
CFLAGS_MCU     += -march=armv7e-m
CFLAGS_MCU     += -mcpu=cortex-m4
CFLAGS_MCU     += -mthumb
CFLAGS_MCU     += -mfpu=fpv4-sp-d16
CFLAGS_MCU     += -mfloat-abi=hard

CFLAGS_W	= -Wall
CFLAGS_W       += -Wextra
CFLAGS_W       += -Wstrict-prototypes
CFLAGS_W       += -Werror

CFLAGS_F	= -ffreestanding
CFLAGS_F       += -flto
CFLAGS_F       += -fsingle-precision-constant
CFLAGS_F       += -ffunction-sections
CFLAGS_F       += -fdata-sections

# defining used MCU (instead of in file stm32f00x.h): -DSTM32F051x8//
CFLAGS_D	= -D USE_HAL_DRIVER	# to include file stm32l4xx_hal.h

CFLAGS		= $(CFLAGS_STD)
CFLAGS	       += $(CFLAGS_OPT)
CFLAGS	       += $(CFLAGS_MCU)
CFLAGS	       += $(CFLAGS_W)
CFLAGS	       += $(CFLAGS_F)
CFLAGS	       += $(CFLAGS_D)
CFLAGS	       += $(C_INCLUDES)

export	CFLAGS


################################################################################
# LDFLAGS
# Settings of linker
LDFLAGS		=  -mcpu=cortex-m4 -mthumb
LDFLAGS        += -Wl,--gc-sections -Wl,-Map=$(PROJECT_NAME).map,--cref,--no-warn-mismatch

export	LDFLAGS


################################################################################


.PHONY: all stm32l4-drivers libalx stm32l4-modules main target flash erase reset clean mrproper

all: target

stm32l4-drivers:
	@echo	'	MAKE	drivers'
	$(Q)$(MAKE) -C $(DRIVERS_DIR)

libalx:
	@echo	'	MAKE	libalx'
	$(Q)$(MAKE) base	-C $(LIBALX_DIR)

stm32l4-modules: stm32l4-drivers libalx
	@echo	'	MAKE	modules'
	$(Q)$(MAKE) -C $(MODULES_DIR)

main: libalx stm32l4-modules
	@echo	"	MAKE	main"
	$(Q)$(MAKE) -C $(TMP_DIR)

target: main
	@echo	"	MAKE	target"
	$(Q)$(MAKE) -C $(BIN_DIR)


flash:
	openocd -f board/stm32l4nucleo.cfg -c "program $(BIN_DIR)/$(PROJECT_NAME).hex verify reset exit"
#second approach:	openocd -f board/stm32f0discovery.cfg -c "init" -c "reset halt" -c "flash write_image erase $(BINDIR)/$(PROJECT_NAME).hex" -c "verify_image $(BINDIR)/$(PROJECT_NAME).hex" -c "reset run" -c "exit"
#third approach:	openocd -f interface/stlink-v2.cfg -f target/stm32f0x_stlink.cfg -c "init" -c "reset halt" -c "flash write_image erase $(BINDIR)/$(PROJECT_NAME).hex" -c "verify_image $(BINDIR)/$(PROJECT_NAME).hex" -c "reset run" -c "exit"

erase:
	openocd -f board/stm32l4nucleo.cfg -c "init" -c "reset halt" -c "stm32l4x mass_erase 0" -c "reset" -c "shutdown"

reset:
	openocd -f board/stm32l4nucleo.cfg -c "init" -c "reset" -c "shutdown"

clean:
	@echo	'	CLEAN	bin'
	$(Q)$(MAKE) clean -C $(BIN_DIR)
	@echo	'	CLEAN	tmp'
	$(Q)$(MAKE) clean -C $(TMP_DIR)

mrproper: clean
	@echo	'	CLEAN	modules'
	$(Q)$(MAKE) clean -C $(MODULES_DIR)
	@echo	'	CLEAN	libalx'
	$(Q)$(MAKE) clean -C $(LIBALX_DIR)
	@echo	'	CLEAN	drivers'
	$(Q)$(MAKE) clean -C $(DRIVERS_DIR)




################################################################################
######## End of file ###########################################################
################################################################################