##############################################################################
# LP-MSPM33C321A: test program in the MAIN flash (0x10000000), blinks the
# red LED (PA0) and counts in SRAM
##############################################################################
# toolchains from <software>/cross, not from $PATH
CROSS_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))../../cross)
GCC_BASE   = $(CROSS_DIR)/arm-ronetix-eabi-11.2.0
GCC_PREFIX = $(GCC_BASE)/bin/arm-ronetix-eabi

GCC      = $(GCC_PREFIX)-gcc
OBJCOPY  = $(GCC_PREFIX)-objcopy
SIZE     = $(GCC_PREFIX)-size

# folder of the TFTP server
TFTP_PATH ?= /tftpboot

CFLAGS  = -Wall -g3 -O1 -mcpu=cortex-m33 -mthumb -ffreestanding -nostdlib
# make STOP=1: enter the STOP mode after 6 LED toggles (test of COREn_LOW_POWER_DEBUG)
ifdef STOP
CFLAGS += -DTEST_STOP
endif

LDFLAGS = -nostartfiles -T mspm33_flash.ld -Wl,-Map=mspm33_flash.map

all: mspm33_flash.elf

mspm33_flash.elf: startup.c main.c mspm33_flash.ld makefile
	$(GCC) $(CFLAGS) $(LDFLAGS) -o $@ startup.c main.c
	$(OBJCOPY) -O binary $@ mspm33_flash.bin
	$(SIZE) $@

# copy the image to the TFTP server
install: all
	cp mspm33_flash.bin $(TFTP_PATH)/

clean:
	rm -f *.elf *.bin *.map *.o
