CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
OBJCOPY = arm-none-eabi-objcopy

LINKER_SCRIPT = -TSTM32L476xG.ld

CFLAGS = -g -O2 -Wall
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
CFLAGS += -fno-common

all:	lab9.bin

-include ../Makefile.lib

lab9.bin:	lab9.elf
	$(OBJCOPY) -Obinary lab9.elf lab9.bin

lab9.elf:	main.o #lcd.o
	$(LD) $(LINKER_SCRIPT) -nostartfiles -o lab9.elf main.o #lcd.o

lcd.o:	lcd.c stm32l476xx.h
	$(CC) $(CFLAGS)  -c -o lcd.o lcd.c

main.o:	main.c stm32l476xx.h
	$(CC) $(CFLAGS)  -c -o main.o main.c


flash:		lab9.elf
#	openocd -f board/stm32ldiscovery.cfg -c "program filename.bin 0x08000000"
	openocd -f board/stm32l4discovery.cfg \
			-c "program lab9.elf verify" \
			-c "reset run"


disassem:	lab9.elf
	$(OBJDUMP) --disassemble-all lab9.elf > lab9.dis

clean:	
	rm -f *~ *.o *.bin *.elf *.dis
