Makefile 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. PROJECT=main
  2. # Selecting Core
  3. CORTEX_M=4
  4. # Use newlib-nano. To disable it, specify USE_NANO=
  5. USE_NANO=--specs=nano.specs
  6. # Use semihosting
  7. USE_SEMIHOST=--specs=rdimon.specs
  8. # Use retarget
  9. # USE_SEMIHOST=--specs=nosys.specs
  10. # Compiler & Linker
  11. CC=arm-none-eabi-gcc
  12. AR=arm-none-eabi-ar
  13. AS=arm-none-eabi-as
  14. LD=arm-none-eabi-ld
  15. SIZE=arm-none-eabi-size
  16. OBJCOPY=arm-none-eabi-objcopy
  17. OBJDUMP=arm-none-eabi-objdump
  18. LDSCRIPTS=-L. -T STM32L432KCUx_FLASH.ld
  19. INCLUDES = \
  20. -I../Include \
  21. -I../../../../Include \
  22. -I../../../../../STM32L4xx_HAL_Driver/Inc
  23. SOURCES = main.c \
  24. system_stm32l4xx.c \
  25. startup_stm32l432xx.s \
  26. # Options for specific architecture
  27. ARCH_FLAGS=-mthumb -mcpu=cortex-m$(CORTEX_M)
  28. # -Os -flto -ffunction-sections -fdata-sections to compile for code size
  29. # CFLAGS=$(ARCH_FLAGS) $(INCLUDES) -Os -flto -ffunction-sections -fdata-sections
  30. CFLAGS=$(ARCH_FLAGS) $(INCLUDES) -g -flto -ffunction-sections -fdata-sections
  31. # Link for code size and create a map file
  32. # If not using semihosting/retarget:
  33. # LFLAGS=$(USE_NANO) $(USE_SEMIHOST) -nostartfiles -Wl,--gc-sections,-Map=$(PROJECT).map
  34. # Else:
  35. LFLAGS=$(USE_NANO) $(USE_SEMIHOST) -Wl,--gc-sections,-Map=$(PROJECT).map
  36. all: $(PROJECT).bin $(PROJECT).dis $(PROJECT).axf
  37. # Build ELF w/ symbols
  38. $(PROJECT).axf: $(SOURCES)
  39. $(CC) $^ $(CFLAGS) $(LFLAGS) $(LDSCRIPTS) -o $@
  40. # Generate binary to flash
  41. $(PROJECT).bin: $(PROJECT).axf
  42. $(OBJCOPY) -O binary $< $@
  43. # Export dissassembly of binary
  44. $(PROJECT).dis: $(PROJECT).axf
  45. $(OBJDUMP) -S -d -marm $< -Mforce-thumb > $@
  46. clean:
  47. rm -f *.axf *.bin *.map *.dis *.o