Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #
  2. # Generic and Simple GNU ARM Makefile
  3. #
  4. # Desinged for the gnu-arm-none-eabi tool chain
  5. #
  6. # Features
  7. # - create hex file
  8. # - create assembler listing (.dis)
  9. #
  10. # Limitations
  11. # - only C-files supported
  12. # - no automatic dependency checking (call 'make clean' if any .h files are changed)
  13. #
  14. # Targets:
  15. # make
  16. # create hex file, no upload
  17. # make upload
  18. # create and upload hex file
  19. # make clean
  20. # delete all generated files
  21. #
  22. # Note:
  23. # Display list make database: make -p -f/dev/null | less
  24. #
  25. #================================================
  26. # External tools
  27. # The base directory of gcc-arm-none-eabi
  28. # Can be empty on Ubuntu and installed gcc-arm-none-eabi
  29. # If set, GCCBINPATH must contain a "/" at the end.
  30. GCCBINPATH:=/usr/bin/
  31. #================================================
  32. # Project Information
  33. # The name for the project
  34. TARGETNAME:=blink
  35. # The source files of the project
  36. CSRC:=$(wildcard *.c)
  37. SSRC:=$(wildcard ../stm32l0xx/src/*.s)
  38. # The CPU architecture (will be used for -mcpu)
  39. # for the LPC824, can we use "cortex-m0plus"?
  40. MCPU:=cortex-m0plus
  41. # Include directory for the system include files
  42. SYSINC:=../stm32l0xx/inc
  43. SYSSRC:=$(wildcard ../stm32l0xx/src/*.c)
  44. # Include directory for the u8g2 include files
  45. #U8G2INC:=../../../../csrc/
  46. #U8G2SRC:=$(wildcard ../../../../csrc/*.c)
  47. # directory for FatFS
  48. #FFINC:=../fatfs
  49. #FFSRC:=$(wildcard ../fatfs/*.c)
  50. # Directory for the linker script
  51. LDSCRIPTDIR:=.
  52. # Name of the linker script (must be the "keep" script, because the other script is not always working)
  53. LDSCRIPT:=stm32l031x6.ld
  54. #================================================
  55. # Main part of the Makefile starts here. Usually no changes are needed.
  56. # Internal Variable Names
  57. LIBNAME:=$(TARGETNAME).a
  58. ELFNAME:=$(TARGETNAME).elf
  59. HEXNAME:=$(TARGETNAME).hex
  60. DISNAME:=$(TARGETNAME).dis
  61. MAPNAME:=$(TARGETNAME).map
  62. OBJ:=$(CSRC:.c=.o) $(SSRC:.s=.o) $(SYSSRC:.c=.o)
  63. # $(SYSSRC:.c=.o) $(U8G2SRC:.c=.o) $(FFSRC:.c=.o)
  64. # Replace standard build tools by arm tools
  65. AS:=$(GCCBINPATH)arm-none-eabi-as
  66. CC:=$(GCCBINPATH)arm-none-eabi-gcc
  67. AR:=$(GCCBINPATH)arm-none-eabi-ar
  68. OBJCOPY:=$(GCCBINPATH)arm-none-eabi-objcopy
  69. OBJDUMP:=$(GCCBINPATH)arm-none-eabi-objdump
  70. SIZE:=$(GCCBINPATH)arm-none-eabi-size
  71. # Common flags
  72. COMMON_FLAGS = -mthumb -mcpu=$(MCPU)
  73. COMMON_FLAGS += -DSTM32L031xx
  74. COMMON_FLAGS += -Wall -I. -I$(SYSINC) -I$(U8G2INC)
  75. # define stack size (defaults to 0x0100)
  76. # COMMON_FLAGS += -D__STACK_SIZE=0x0100
  77. # COMMON_FLAGS += -Os -flto
  78. COMMON_FLAGS += -Os
  79. # COMMON_FLAGS += -fstack-protector
  80. # COMMON_FLAGS += -finstrument-functions
  81. # Do not use stand libs startup code. Uncomment this for gcclib procedures
  82. # memcpy still works, but might be required for __aeabi_uidiv
  83. # COMMON_FLAGS += -nostdlib
  84. # remove unused data and function
  85. #COMMON_FLAGS += -ffunction-sections -fdata-sections -fshort-wchar
  86. COMMON_FLAGS += -ffunction-sections -fdata-sections
  87. # C flags
  88. CFLAGS:=$(COMMON_FLAGS) -std=gnu99
  89. # LD flags
  90. # remove unreferenced procedures and variables, but __isr_vector
  91. GC:=-Wl,--gc-sections -Wl,--undefined=__isr_vector
  92. MAP:=-Wl,-Map=$(MAPNAME)
  93. LFLAGS:=$(COMMON_FLAGS) $(GC) $(MAP)
  94. #LDLIBS:=--specs=nosys.specs -lc -lc -lnosys -L$(LDSCRIPTDIR) -T $(LDSCRIPT)
  95. LDLIBS:=--specs=nosys.specs -L$(LDSCRIPTDIR) -T $(LDSCRIPT)
  96. # Additional Suffixes
  97. .SUFFIXES: .elf .hex .bin .dis
  98. # Targets
  99. .PHONY: all
  100. all: $(DISNAME) $(HEXNAME)
  101. $(SIZE) $(ELFNAME)
  102. .PHONY: upload
  103. upload: $(DISNAME) $(HEXNAME) $(ELFNAME)
  104. stm32flash -e 255 -g 0 -w $(HEXNAME) -v /dev/ttyUSB0
  105. $(SIZE) $(ELFNAME)
  106. .PHONY: clean
  107. clean:
  108. $(RM) $(OBJ) $(HEXNAME) $(ELFNAME) $(LIBNAME) $(DISNAME) $(MAPNAME) libssp.a libssp_nonshared.a
  109. # implicit rules
  110. .elf.hex:
  111. $(OBJCOPY) -O ihex $< $@
  112. # explicit rules
  113. $(ELFNAME): $(LIBNAME)($(OBJ)) libssp.a libssp_nonshared.a
  114. $(LINK.o) $(LFLAGS) $(LIBNAME) $(LDLIBS) -o $@
  115. $(DISNAME): $(ELFNAME)
  116. $(OBJDUMP) -D -S $< > $@
  117. # create empty ssp libs for -fstack-protector-all -fstack-protector
  118. libssp.a:
  119. $(AR) rcs $@
  120. libssp_nonshared.a:
  121. $(AR) rcs $@