Skip to content

Instantly share code, notes, and snippets.

@ftp27
Created January 5, 2014 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ftp27/8267599 to your computer and use it in GitHub Desktop.
Save ftp27/8267599 to your computer and use it in GitHub Desktop.
MakeFile for STM32L
##############################################################################################
#
# On command line:
#
# make all = Create project
#
# make clean = Clean project files.
#
# To rebuild project do "make clean" and "make all".
#
##############################################################################################
# Start of default section
#
#TOOLCHAIN = /opt/gcc-arm-none-eabi/bin
TOOLCHAIN = /opt/codesourcery/arm-2011.03/bin
TRGT = $(TOOLCHAIN)/arm-none-eabi-
CC = $(TRGT)gcc
LD = $(TRGT)gcc
CP = $(TRGT)objcopy
AS = $(TRGT)as#gcc -x assembler-with-cpp
AR = $(TRGT)ar
GDB = $(TRGT)gdb
HEX = $(CP) -O ihex
BIN = $(CP) -O binary -S
MCU = cortex-m3
# List all default C defines here, like -D_DEBUG=1
DDEFS = -DSTM32L1XX_MD -DUSE_STDPERIPH_DRIVER
# List all default ASM defines here, like -D_DEBUG=1
DADEFS =
# List all default directories to look for include files here
DINCDIR =
# List the default directory to look for the libraries here
DLIBDIR =
# List all default libraries here
DLIBS =
#
# End of default section
##############################################################################################
##############################################################################################
# Start of user section
#
#
# Define project name and Ram/Flash mode here
PROJECT = IOToggle
RUN_FROM_FLASH = 1
# List all user C define here, like -D_DEBUG=1
UDEFS =
# Define ASM defines here
UADEFS =
# List C source files here
LIBSDIR = ../Libraries
CORELIBDIR = $(LIBSDIR)/CMSIS/Include
DEVDIR = $(LIBSDIR)/CMSIS/Device/ST/STM32L1xx
DEVINCDIR = $(DEVDIR)/Include
STMSPDDIR = $(LIBSDIR)/STM32L1xx_StdPeriph_Driver
STMSPSRCDDIR = $(STMSPDDIR)/src
STMSPINCDDIR = $(STMSPDDIR)/inc
#STMUSBDIR = $(LIBSDIR)/STM32_USB-FS-Device_Driver
#STMUSBSRCDIR = $(STMUSBDIR)/src
#STMUSBINCDIR = $(STMUSBDIR)/inc
DISCOVERY = ../Utilities/STM32_EVAL/STM32L152D_EVAL
LINKER = ../Linker
LDFILE = STM32_flash.ld
SRC = ./main.c
SRC += ./system_stm32l1xx.c
SRC += ./stm32l1xx_it.c
#SRC += $(DEVDIR)\Source\Templates\system_stm32f0xx.c
#SRC += startup_stm32f0xx.S
#SRC += $(DISCOVERY)\stm32f0_discover
#y.c
## used parts of the STM-Library
SRC += $(STMSPSRCDDIR)/misc.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_exti.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_pwr.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_adc.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_flash.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_rcc.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_aes.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_flash_ramfunc.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_rtc.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_aes_util.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_fsmc.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_sdio.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_comp.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_spi.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_crc.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_i2c.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_syscfg.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_dac.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_iwdg.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_tim.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_dbgmcu.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_lcd.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_gpio.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_usart.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_dma.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_opamp.c
SRC += $(STMSPSRCDDIR)/stm32l1xx_wwdg.c
## used parts of the USB Device Driver STM-Library
#SRC += $(STMUSBDIR)/usb_core.c
#SRC += $(STMUSBDIR)/usb_init.c
#SRC += $(STMUSBDIR)/usb_int.c
#SRC += $(STMUSBDIR)/usb_mem.c
#SRC += $(STMUSBDIR)/usb_regs.c
#SRC += $(STMUSBDIR)/usb_sil.c
# List ASM source files here
ASRCDIE = $(DEVDIR)/Source/Templates/TrueSTUDIO
ASRC = $(ASRCDIE)/startup_stm32l1xx_md.s
#ASRC = $(ASRCDIE)/startup_stm32l1xx_hd.s
#ASRC += $(ASRCDIE)/startup_stm32l1xx_mdp.s
# List all user directories here
UINCDIR = $(DEVDIR)/Include \
$(CORELIBDIR) \
$(STMSPINCDDIR) \
$(DISCOVERY) \
$(DEVINCDIR) \
$(STMSPINCDDIR) \
$(STMSPSRCDDIR) \
./
# $(STMUSBINCDIR) \
./inc
# List the user directory to look for the libraries here
ULIBDIR =
# List all user libraries here
ULIBS =
# Define optimisation level here
OPT = -Os
#
# End of user defines
##############################################################################################
#
# Define linker script file here
#
ifeq ($(RUN_FROM_FLASH), 0)
LDSCRIPT = $(LINKER)/$(LDFILE)
FULL_PRJ = $(PROJECT)_ram
else
LDSCRIPT = ../Linker/STM32_flash.ld
FULL_PRJ = $(PROJECT)_rom
endif
INCDIR = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
LIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
ifeq ($(RUN_FROM_FLASH), 0)
DEFS = $(DDEFS) $(UDEFS) -DRUN_FROM_FLASH=0 -DVECT_TAB_SRAM
else
DEFS = $(DDEFS) $(UDEFS) -DRUN_FROM_FLASH=1
endif
ADEFS = $(DADEFS) $(UADEFS)
OBJS = $(ASRC:.s=.o) $(SRC:.c=.o)
LIBS = $(DLIBS) $(ULIBS)
MCFLAGS = -mcpu=$(MCU)
ASFLAGS = $(MCFLAGS) -g -gdwarf-2 -mthumb -Wa -amhls=$(<:.s=.lst) $(ADEFS)
CPFLAGS = $(MCFLAGS) $(OPT) -gdwarf-2 -mthumb -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)
LDFLAGS = $(MCFLAGS) -mthumb -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(FULL_PRJ).map,--cref,--no-warn-mismatch $(LIBDIR)
# Generate dependency information
CPFLAGS += -MD -MP -MF .dep\$(@F).d
#
# makefile rules
#
all: $(OBJS) $(FULL_PRJ).elf $(FULL_PRJ).hex $(FULL_PRJ).bin
ifeq ($(RUN_FROM_FLASH), 0)
$(TRGT)size $(PROJECT)_ram.elf
else
$(TRGT)size $(PROJECT)_rom.elf
endif
%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) $< $@
clean:
rm -f $(OBJS)
rm -f $(FULL_PRJ).elf
rm -f $(FULL_PRJ).map
rm -f $(FULL_PRJ).hex
rm -f $(FULL_PRJ).bin
# del $(SRC:.c=.c.bak)
rm -f $(SRC:.c=.lst)
# del $(ASRC:.s=.s.bak)
rm -f $(ASRC:.s=.lst)
rm -fr .dep /S /Q
#
# Include the dependency files, should be the last of the makefile
#
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# *** EOF ***
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment