# The processor!
MCU_CORE=cm3
# Set up include paths
MCU_INCLUDE += -I$(LIBDIR)/CMSIS/Include
MCU_INCLUDE += -I$(LIBDIR)/CMSIS/Device/ST/STM32F10x/Include
MCU_INCLUDE += -I$(LIBDIR)/STM32F10x_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)/libstm32f10x.a

# CMSIS
STM32F10x_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32F10x/Source/Templates/system_stm32f10x.o
# Standard Peripheral Library
STM32F10x_OBJSR = misc.o stm32f10x_dac.o stm32f10x_gpio.o stm32f10x_sdio.o \
	stm32f10x_adc.o stm32f10x_dbgmcu.o stm32f10x_i2c.o stm32f10x_spi.o \
	stm32f10x_bkp.o stm32f10x_dma.o stm32f10x_iwdg.o stm32f10x_tim.o \
	stm32f10x_can.o stm32f10x_exti.o stm32f10x_pwr.o stm32f10x_usart.o \
	stm32f10x_cec.o stm32f10x_flash.o stm32f10x_rcc.o stm32f10x_wwdg.o \
	stm32f10x_crc.o stm32f10x_fsmc.o stm32f10x_rtc.o

STM32F10x_OBJS += $(addprefix $(LIBDIR)/STM32F10x_StdPeriph_Driver/src/,$(STM32F10x_OBJSR))

# Bookkeeping
MCU_LIBS_OBJS += $(STM32F10x_OBJS)

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

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

