# The processor!
MCU_CORE=cm3
# Set up include paths
MCU_INCLUDE += -I$(LIBDIR)/CMSIS/Include
MCU_INCLUDE += -I$(LIBDIR)/CMSIS/Device/ST/STM32L1xx/Include
MCU_INCLUDE += -I$(LIBDIR)/STM32L1xx_StdPeriph_Driver/inc

# Set up CFLAGS
MCU_CPPFLAGS += -D$(shell echo -n $(MCU_SUBTYPE) | tr a-z A-Z )
MCU_CPPFLAGS += -D"assert_param(expr)=((void)0)"
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb 

# Target Libraries
MCU_LIBS += $(LIBDIR)/libstm32l1xx.a

# CMSIS
STM32L1xx_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32L1xx/Source/Templates/system_stm32l1xx.o
# Standard Peripheral Library
STM32L1xx_OBJSR = misc.o stm32l1xx_adc.o stm32l1xx_aes.o stm32l1xx_aes_util.o \
	stm32l1xx_comp.o stm32l1xx_crc.o stm32l1xx_dac.o stm32l1xx_dbgmcu.o \
	stm32l1xx_dma.o stm32l1xx_exti.o stm32l1xx_flash.o \
	stm32l1xx_flash_ramfunc.o stm32l1xx_fsmc.o stm32l1xx_gpio.o \
	stm32l1xx_i2c.o stm32l1xx_iwdg.o stm32l1xx_lcd.o stm32l1xx_opamp.o \
	stm32l1xx_pwr.o stm32l1xx_rcc.o stm32l1xx_rtc.o stm32l1xx_sdio.o \
	stm32l1xx_spi.o stm32l1xx_syscfg.o stm32l1xx_tim.o stm32l1xx_usart.o \
	stm32l1xx_wwdg.o

STM32L1xx_OBJS += $(addprefix $(LIBDIR)/STM32L1xx_StdPeriph_Driver/src/,$(STM32L1xx_OBJSR))

# Bookkeeping
MCU_LIBS_OBJS += $(STM32L1xx_OBJS)

# Build Rules
$(LIBDIR)/startup_$(MCU_SUBTYPE).o: $(LIBDIR)/CMSIS/Device/ST/STM32L1xx/Source/Templates/gcc_ride7/startup_$(MCU_SUBTYPE).s
	@$(E) "  AS " $@
	$(Q)$(AS) -c -o $@ $<

$(LIBDIR)/libstm32l1xx.a:  $(STM32L1xx_OBJS) $(LIBDIR)/startup_$(MCU_SUBTYPE).o
	@$(E) "  AR " $@
	$(Q)$(AR) cr $@ $(STM32L1xx_OBJS) $(LIBDIR)/startup_$(MCU_SUBTYPE).o

