# The processor!
MCU_CORE=cm4
# Set up include paths
MCU_INCLUDE += -I$(LIBDIR)/CMSIS/Include
MCU_INCLUDE += -I$(LIBDIR)/CMSIS/Device/ST/STM32F4xx/Include
MCU_INCLUDE += -I$(LIBDIR)/STM32F4xx_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-m4 -mthumb -Wa,-mthumb 

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

# CMSIS
STM32F4xx_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.o
# Standard Peripheral Library
STM32F4xx_OBJSR = misc.o stm32f4xx_dma.o stm32f4xx_rcc.o stm32f4xx_adc.o \
        stm32f4xx_exti.o stm32f4xx_rng.o stm32f4xx_can.o stm32f4xx_flash.o \
	stm32f4xx_rtc.o stm32f4xx_crc.o stm32f4xx_fsmc.o stm32f4xx_sdio.o \
	stm32f4xx_cryp_aes.o stm32f4xx_gpio.o stm32f4xx_spi.o \
	stm32f4xx_cryp.o stm32f4xx_hash.o stm32f4xx_syscfg.o \
	stm32f4xx_cryp_des.o stm32f4xx_hash_md5.o stm32f4xx_tim.o \
	stm32f4xx_cryp_tdes.o stm32f4xx_hash_sha1.o  stm32f4xx_usart.o \
	stm32f4xx_dac.o stm32f4xx_i2c.o stm32f4xx_wwdg.o stm32f4xx_dbgmcu.c \
	stm32f4xx_iwdg.o stm32f4xx_dcmi.o stm32f4xx_pwr.o

STM32F4xx_OBJS += $(addprefix $(LIBDIR)/STM32F4xx_StdPeriph_Driver/src/,$(STM32F4xx_OBJSR))

# Bookkeeping
MCU_LIBS_OBJS += $(STM32F4xx_OBJS)

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

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

