Makefile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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:=eval_board
  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:=./u8x8/
  46. U8G2SRC:=$(wildcard ./u8x8/*.c)
  47. # Directory for the linker script
  48. LDSCRIPTDIR:=.
  49. # Name of the linker script (must be the "keep" script, because the other script is not always working)
  50. LDSCRIPT:=stm32l031x6.ld
  51. #================================================
  52. # Main part of the Makefile starts here. Usually no changes are needed.
  53. # Internal Variable Names
  54. LIBNAME:=$(TARGETNAME).a
  55. ELFNAME:=$(TARGETNAME).elf
  56. HEXNAME:=$(TARGETNAME).hex
  57. DISNAME:=$(TARGETNAME).dis
  58. MAPNAME:=$(TARGETNAME).map
  59. OBJ:=$(CSRC:.c=.o) $(SSRC:.s=.o) $(SYSSRC:.c=.o) $(U8G2SRC:.c=.o)
  60. # $(SYSSRC:.c=.o) $(FFSRC:.c=.o)
  61. # Replace standard build tools by arm tools
  62. AS:=$(GCCBINPATH)arm-none-eabi-as
  63. CC:=$(GCCBINPATH)arm-none-eabi-gcc
  64. AR:=$(GCCBINPATH)arm-none-eabi-ar
  65. OBJCOPY:=$(GCCBINPATH)arm-none-eabi-objcopy
  66. OBJDUMP:=$(GCCBINPATH)arm-none-eabi-objdump
  67. SIZE:=$(GCCBINPATH)arm-none-eabi-size
  68. # Common flags
  69. COMMON_FLAGS = -mthumb -mcpu=$(MCPU)
  70. COMMON_FLAGS += -DSTM32L031xx
  71. COMMON_FLAGS += -Wall -I. -I$(SYSINC) -I$(U8G2INC)
  72. # define stack size (defaults to 0x0100)
  73. # COMMON_FLAGS += -D__STACK_SIZE=0x0100
  74. # COMMON_FLAGS += -Os -flto
  75. COMMON_FLAGS += -Os
  76. # COMMON_FLAGS += -fstack-protector
  77. # COMMON_FLAGS += -finstrument-functions
  78. # Do not use stand libs startup code. Uncomment this for gcclib procedures
  79. # memcpy still works, but might be required for __aeabi_uidiv
  80. # COMMON_FLAGS += -nostdlib
  81. # remove unused data and function
  82. #COMMON_FLAGS += -ffunction-sections -fdata-sections -fshort-wchar
  83. COMMON_FLAGS += -ffunction-sections -fdata-sections
  84. # the following seems to be required for newlib nano
  85. # COMMON_FLAGS += -fno-builtin
  86. # C flags
  87. CFLAGS:=$(COMMON_FLAGS) -std=gnu99
  88. # LD flags
  89. # remove unreferenced procedures and variables, but __isr_vector
  90. GC:=-Wl,--gc-sections -Wl,--undefined=__isr_vector
  91. MAP:=-Wl,-Map=$(MAPNAME)
  92. LFLAGS:=$(COMMON_FLAGS) $(GC) $(MAP)
  93. #LDLIBS:=--specs=nosys.specs -lc -lc -lnosys -L$(LDSCRIPTDIR) -T $(LDSCRIPT)
  94. LDLIBS:=--specs=nosys.specs -L$(LDSCRIPTDIR) -T $(LDSCRIPT)
  95. #LDLIBS:=--specs=nano.specs -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 $@