Makefile 1.5 KB

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