Makefile 1.5 KB

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