Makefile 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. export
  2. DEVICE_FAMILY = STM32F4xx
  3. DEVICE_TYPE = STM32F401xE
  4. STARTUP_FILE = stm32f401xe
  5. SYSTEM_FILE = stm32f4xx
  6. CMSIS = Drivers/CMSIS
  7. CMSIS_DEVSUP = $(CMSIS)/Device/ST/$(DEVICE_FAMILY)/
  8. CMSIS_OPT = -D$(DEVICE_TYPE) -DUSE_HAL_DRIVER
  9. OTHER_OPT = "-D__weak=__attribute__((weak))" "-D__packed=__attribute__((__packed__))"
  10. CPU = -mthumb -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
  11. SYSTEM = arm-none-eabi
  12. #LDSCRIPT = STM32F401ZG_FLASH.ld
  13. LDSCRIPT = "SW4STM32/test Configuration/STM32F401RETx_FLASH.ld"
  14. SRCDIR := Src/
  15. INCDIR := Inc/
  16. LIBDIR := Drivers/
  17. MDLDIR := Middlewares/
  18. #LIBINC := $(shell find $(INCDIR) -name *.h -printf "-I%h/\n"|sort|uniq)
  19. #LIBINC += $(shell find $(LIBDIR) -name *.h -printf "-I%h/\n"|sort|uniq)
  20. #LIBINC += $(shell find $(MDLDIR) -name *.h -printf "-I%h/\n"|sort|uniq|sed -e 's/lwip\///'|sed -e 's/arch\///')
  21. LIBINC := -IInc
  22. #LIBINC += -IMiddlewares/Third_Party/LwIP/system
  23. #LIBINC += -IMiddlewares/Third_Party/LwIP/src/include
  24. #LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/ipv4
  25. LIBINC += -IDrivers/STM32F4xx_HAL_Driver/Inc
  26. #LIBINC += -IMiddlewares/Third_Party/FatFs/src/drivers
  27. #LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F
  28. #LIBINC += -IMiddlewares/ST/STM32_USB_Device_Library/Core/Inc
  29. #LIBINC += -IMiddlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc
  30. #LIBINC += -IMiddlewares/ST/STM32_USB_Host_Library/Core/Inc
  31. #LIBINC += -IMiddlewares/ST/STM32_USB_Host_Library/Class/MSC/Inc
  32. #LIBINC += -IMiddlewares/Third_Party/FatFs/src
  33. #LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/include
  34. #LIBINC += -IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS
  35. #LIBINC += -IMiddlewares/Third_Party/LwIP/system/arch
  36. #LIBINC += -IMiddlewares/Third_Party/LwIP/system/OS
  37. #LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/ipv4/lwip
  38. #LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/lwip
  39. #LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/netif
  40. #LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/posix
  41. #LIBINC += -IMiddlewares/Third_Party/LwIP/src/include/posix/sys
  42. #LIBINC += -IMiddlewares/Third_Party/LwIP/src/netif/ppp
  43. LIBINC += -IDrivers/CMSIS/Include
  44. LIBINC += -IDrivers/CMSIS/Device/ST/STM32F4xx/Include
  45. LIBS := ./$(LIBDIR)/STM32F4xx_HAL_Driver/libstm32fw.a
  46. #LIBS += ./$(MDLDIR)/Third_Party/FatFs/fatfs.a
  47. #LIBS += ./$(MDLDIR)/Third_Party/FreeRTOS/freertos.a
  48. #LIBS += ./$(MDLDIR)/Third_Party/LwIP/lwip.a
  49. #LIBS += ./$(MDLDIR)/ST/STM32_USB_Device_Library/libstm32usbdev.a
  50. #LIBS += ./$(MDLDIR)/ST/STM32_USB_Host_Library/libstm32usbhost.a
  51. LIBS += -lm
  52. CC = $(SYSTEM)-gcc
  53. CCDEP = $(SYSTEM)-gcc
  54. LD = $(SYSTEM)-gcc
  55. AR = $(SYSTEM)-ar
  56. AS = $(SYSTEM)-gcc
  57. OBJCOPY = $(SYSTEM)-objcopy
  58. OBJDUMP = $(SYSTEM)-objdump
  59. GDB = $(SYSTEM)-gdb
  60. SIZE = $(SYSTEM)-size
  61. OCD = sudo ~/openocd-git/openocd/src/openocd \
  62. -s ~/openocd-git/openocd/tcl/ \
  63. -f interface/stlink-v2.cfg \
  64. -f target/stm32f4x_stlink.cfg
  65. # INCLUDES = -I$(SRCDIR) $(LIBINC)
  66. INCLUDES = $(LIBINC)
  67. CFLAGS = $(CPU) $(CMSIS_OPT) $(OTHER_OPT) -Wall -fno-common -fno-strict-aliasing -O2 $(INCLUDES) -g -Wfatal-errors -g
  68. ASFLAGS = $(CFLAGS) -x assembler-with-cpp
  69. LDFLAGS = -Wl,--gc-sections,-Map=$*.map,-cref -T $(LDSCRIPT) $(CPU)
  70. ARFLAGS = cr
  71. OBJCOPYFLAGS = -Obinary
  72. OBJDUMPFLAGS = -S
  73. STARTUP_OBJ = $(CMSIS_DEVSUP)/Source/Templates/gcc/startup_$(STARTUP_FILE).o
  74. SYSTEM_OBJ = $(CMSIS_DEVSUP)/Source/Templates/system_$(SYSTEM_FILE).o
  75. BIN = main.bin
  76. OBJS = $(sort \
  77. $(patsubst %.c,%.o,$(wildcard Src/*.c)) \
  78. $(patsubst %.s,%.o,$(wildcard Src/*.s)) \
  79. $(STARTUP_OBJ) \
  80. $(SYSTEM_OBJ))
  81. all: $(BIN)
  82. reset:
  83. $(OCD) -c init -c "reset run" -c shutdown
  84. #$(GDB) main.out <reset.gdb
  85. flash: $(BIN)
  86. $(OCD) -c init -c "reset halt" \
  87. -c "flash write_image erase "$(BIN)" 0x08000000" \
  88. -c "reset run" \
  89. -c shutdown
  90. $(BIN): main.out
  91. $(OBJCOPY) $(OBJCOPYFLAGS) main.out $(BIN)
  92. $(OBJDUMP) $(OBJDUMPFLAGS) main.out > main.list
  93. $(SIZE) main.out
  94. @echo Make finished
  95. main.out: $(LIBS) $(OBJS)
  96. $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
  97. $(LIBS): libs
  98. libs:
  99. @$(MAKE) -C $(LIBDIR)
  100. # @$(MAKE) -C $(MDLDIR)
  101. libclean: clean
  102. @$(MAKE) -C $(LIBDIR) clean
  103. # @$(MAKE) -C $(MDLDIR) clean
  104. clean:
  105. -rm -f $(OBJS)
  106. -rm -f main.list main.out main.hex main.map main.bin .depend
  107. depend dep: .depend
  108. include .depend
  109. .depend: Src/*.c
  110. $(CCDEP) $(CFLAGS) -MM $^ | sed -e 's@.*.o:@Src/&@' > .depend
  111. .c.o:
  112. @echo cc $<
  113. @$(CC) $(CFLAGS) -c -o $@ $<
  114. .s.o:
  115. @echo as $<
  116. @$(AS) $(ASFLAGS) -c -o $@ $<