You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

77 lines
2.2 KiB

  1. .SUFFIXES:
  2. .PHONY: all
  3. CROSS_COMPILE ?= arm-none-eabi-
  4. CC := $(CROSS_COMPILE)gcc
  5. LD := $(CROSS_COMPILE)ld
  6. OBJCOPY := $(CROSS_COMPILE)objcopy
  7. PROJECTNAME=template
  8. SOURCES := main.c hw_pinout.c
  9. GECKO_SDK_PATH := lib/GeckoSDK
  10. EFM_DEVICE_PATH := $(GECKO_SDK_PATH)/Device/SiliconLabs/EFM32TG
  11. DEVICE_SOURCES := system_efm32tg.c GCC/startup_efm32tg.c
  12. LINKER_SCRIPT := $(EFM_DEVICE_PATH)/Source/GCC/efm32tg.ld
  13. EMLIB_PATH := $(GECKO_SDK_PATH)/emlib
  14. EMLIB_SRC_PATH := $(EMLIB_PATH)/src
  15. CMSIS_PATH := $(GECKO_SDK_PATH)/CMSIS
  16. LIB_SOURCES := em_acmp.c em_adc.c em_aes.c em_assert.c em_burtc.c em_cmu.c \
  17. em_cryotimer.c em_crypto.c em_dac.c em_dbg.c em_dma.c em_ebi.c em_emu.c \
  18. em_gpcrc.c em_gpio.c em_i2c.c em_idac.c em_int.c em_lcd.c em_ldma.c \
  19. em_lesense.c em_letimer.c em_leuart.c em_mpu.c em_msc.c em_opamp.c \
  20. em_pcnt.c em_prs.c em_rmu.c em_rtc.c em_rtcc.c em_system.c em_timer.c \
  21. em_usart.c em_vcmp.c em_wdog.c
  22. OBJ_DIR := build
  23. OBJECTS := $(addprefix $(OBJ_DIR)/src/, $(SOURCES:.c=.o)) \
  24. $(addprefix $(OBJ_DIR)/$(EMLIB_SRC_PATH)/, $(LIB_SOURCES:.c=.o)) \
  25. $(addprefix $(OBJ_DIR)/$(EFM_DEVICE_PATH)/Source/, $(DEVICE_SOURCES:.c=.o))
  26. OUTPUT_DIR := build
  27. VPATH = .:src:$(EMLIB_SRC_PATH):$(EMLIB_DEVICE_PATH):$(EFM_DEVICE_PATH)/Source
  28. INCLUDE_DIRS := inc $(EFM_DEVICE_PATH)/Include $(EMLIB_PATH)/inc \
  29. $(CMSIS_PATH)/Include
  30. CFLAGS := -Wall -Wextra -mcpu=cortex-m3 -mthumb \
  31. -mfix-cortex-m3-ldrd -ffunction-sections \
  32. -fdata-sections -fomit-frame-pointer -std=c99 \
  33. -DEFM32TG110F32 \
  34. $(addprefix -I, $(INCLUDE_DIRS))
  35. LDFLAGS := -Xlinker -Map=$(PROJECTNAME).map -mcpu=cortex-m3 -mthumb \
  36. -T$(LINKER_SCRIPT)
  37. LIBS := -Wl,--gc-sections \
  38. -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
  39. all: $(PROJECTNAME).bin
  40. $(OUTPUT_DIR):
  41. mkdir -p $@
  42. $(OBJECTS): $(OUTPUT_DIR)/%.o: %.c
  43. @mkdir -p $(dir $@)
  44. $(CC) -c $(CFLAGS) -o $@ $<
  45. $(PROJECTNAME).elf: $(OBJECTS)
  46. @echo "Linking target: $@"
  47. $(CC) -o $@ $(LDFLAGS) $(OBJECTS) $(LIBS)
  48. %.bin: %.elf
  49. $(OBJCOPY) -O binary $< $@
  50. clean:
  51. @echo "Cleaning output files"
  52. @rm -rf build *.elf *.bin *.map
  53. debug:
  54. openocd -f interface/stlink-v2.cfg -f target/efm32.cfg
  55. flash: $(PROJECTNAME).elf
  56. openocd -f interface/stlink-v2.cfg -f target/efm32.cfg \
  57. -c 'init; program $(PROJECTNAME).elf verify reset exit ;'