Further updates for C++ support.

This commit is contained in:
Solomon Peachy 2019-11-29 19:29:16 -05:00
parent 320e766ee1
commit dfb519ba95
19 changed files with 53 additions and 21 deletions

10
BUILD
View file

@ -20,6 +20,12 @@ the sources and build:
git clone git://git.shaftnet.org/mcu_base.git
cd mcu_base
echo MCU=stm32f10x >> Makefile.opts
echo MCU_SUBTYPE=stm32f10x_hd >> Makefile.opts
echo "MCU=stm32f10x" >> Makefile.opts
echo "MCU_SUBTYPE=stm32f10x_hd" >> Makefile.opts
make
Alternatively, instead of relying on the toolchain bundled with this repo,
the ARM embedded bare-metal GCC port works great. Download and install it
somewhere appropriate, and run:
echo "CROSS_COMPILE = /some/path/gcc-arm-none-eabi-9-2019-q4-major/bin/arm-none-eabi-" >> Makefile.opts

View file

@ -1,5 +1,5 @@
* Microcontroller Base Project & Build Scripts
* Copyright 2013 Solomon Peachy
* Copyright 2013-2019 Solomon Peachy
* All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");

View file

@ -10,6 +10,7 @@ TOOLCHAIN_SRC_DIR=crosstool-ng
CROSS_DIR ?= ${HOME}/x-tools/arm-$(MCU_CORE)_v3a-eabi
CROSS_COMPILE ?= ${CROSS_DIR}/bin/arm-$(MCU_CORE)_v3a-eabi-
CC=$(CROSS_COMPILE)gcc
CXX=$(CROSS_COMPILE)g++
CPP=$(CROSS_COMPILE)cpp
LD=$(CROSS_COMPILE)gcc
OBJCOPY=$(CROSS_COMPILE)objcopy
@ -35,6 +36,7 @@ MCU_INCLUDE += -I$(LIBDIR)/CMSIS/Include
# Compiler flags
CFLAGS += -pipe -Wall -Wextra -g -Os -std=c99 $(MCU_CFLAGS) $(TARGET_CFLAGS)
CXXFLAGS += -pipe -Wall -Wextra -g -Os -std=c++03 $(MCU_CXXFLAGS) $(TARGET_CXXFLAGS)
CPPFLAGS += $(MCU_INCLUDE) $(INCLUDE) $(MCU_CPPFLAGS) $(TARGET_CPPFLAGS)
LDCPPFLAGS += -DMCU=$(MCU) -DMCU_SUBTYPE=$(MCU_SUBTYPE) $(TARGET_LDCPPFLAGS)
@ -44,9 +46,11 @@ LDFLAGS += -nostartfiles -fno-exceptions -ffunction-sections -fdata-sections -s
# Use LTO?
ifneq ($(USE_LTO),)
CFLAGS += -flto # -ffat-lto-objects
CXXFLAGS += -flto # -ffat-lto-objects
LDFLAGS += -fuse-linker-plugin -flto=$(JLEVEL) $(CFLAGS)
else
CFLAGS += -ffunction-sections
CXXFLAGS += -ffunction-sections
LDFLAGS += -fwhole-program
endif
@ -108,6 +112,14 @@ $(LIBDIR)/lib$(MCU).a: $(MCU_LIBS_OBJS)
@$(RM) -f $*.dt
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
%.o: %.cpp Makefile.opts $(VERSION_H) # These last two are ... special
@$(E) " CX " $<
$(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) -MM $< > $(@:.o=.dt)
$(Q)sed -e 's|.*:|$*.o:|' < $*.dt > $*.d
$(Q)sed -e 's/.*://' -e 's/\\$$//' < $*.dt | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@$(RM) -f $*.dt
$(Q)$(CC) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
%.elf: %.ld $(LIBRARIES) $(PROGRAM_LIBS)
@$(E) " LINK " $@
$(Q)$(CC) -o $@ $(LDFLAGS) \
@ -161,7 +173,7 @@ distclean: clean libclean
$(MAKE) && \
./ct-ng build ; \
cd - ) ; \
fi
fi
@if [ ! -x $(CROSS_COMPILE)gcc ] ; then \
$(ECHO) "Toolchain Build failed!" ; \
exit 1 ;\

View file

@ -64,7 +64,8 @@ MCU_SUBTYPE=stm32f446xx
#MCU_SUBTYPE=samd20j14
# Many more
#TARGET_LDCPPFLAGS +=
#TARGET_LDCPPFLAGS +=
#TARGET_CPPFLAGS +=
#TARGET_CFLAGS +=
#TARGET_CXXFLAGS +=

5
README
View file

@ -1,12 +1,12 @@
This project provides the base/skeleton necessary to develop
applications targeting ARM Cortex-M microcontrollers.
C/C++ applications targeting ARM Cortex-M microcontrollers.
Based on the MCU selected, it automagically compiles the toolchain,
support/peripheral support libraries, startup code, and an empty main()
function. Everything, even the toolchain, is supplied in pure source
form.
Current hardware supported:
Current hardware supported: (As of mid-2016..)
* Entire STM32 family (except for T1)
* Entire EFM32 family (except for ZG)
@ -21,7 +21,6 @@ Down the line, I'd like to expand the scope of this project to include:
* Considerably better documentation (including prerequisites for builds)
* Running purely out of RAM
* OpenOCD-based debugging
* Support for the ARM proprietary compilers.
* Flash image cooking/generation/uploading
I built this framework for my own personal (and professional) needs, and

View file

@ -5,7 +5,8 @@ MCU_CORE=cm3
include $(LIBDIR)/efm32_common.mk
# Set up CFLAGS
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
# Any specific target?
EFM32G_OBJS =

View file

@ -5,7 +5,8 @@ MCU_CORE=cm3
include $(LIBDIR)/efm32_common.mk
# Set up CFLAGS
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
# Any specific target?
EFM32GG_OBJS =

View file

@ -5,7 +5,8 @@ MCU_CORE=cm3
include $(LIBDIR)/efm32_common.mk
# Set up CFLAGS
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
# Any specific target?
EFM32LG_OBJS =

View file

@ -5,7 +5,8 @@ MCU_CORE=cm3
include $(LIBDIR)/efm32_common.mk
# Set up CFLAGS
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
# Any specific target?
EFM32TG_OBJS =

View file

@ -6,7 +6,8 @@ include $(LIBDIR)/efm32_common.mk
# Set up CFLAGS
MATH_CPPFLAGS += -D__FPU_PRESENT=1
MCU_CFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
# Any specific target?
EFM32WG_OBJS =

View file

@ -19,7 +19,8 @@ MCU_INCLUDE += -I$(LIBDIR)/ATMEL/common/utils/interrupt
# Set up CFLAGS
MCU_CPPFLAGS += -D__$(shell echo -n $(MCU_SUBTYPE) | tr a-z A-Z )__
MCU_CFLAGS += -mcpu=cortex-m0plus -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m0plus -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m0plus -mthumb -Wa,-mthumb
# CMSIS & Peripheral Library
STARTUP_OBJS = utils/cmsis/samd20/source/system_samd20.o \

View file

@ -6,7 +6,8 @@ MCU_INCLUDE += -I$(LIBDIR)/STM32F0xx_StdPeriph_Driver/inc
# Set up CFLAGS
MCU_CPPFLAGS += -D"assert_param(expr)=((void)0)"
MCU_CFLAGS += -mcpu=cortex-m0 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m0 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m0 -mthumb -Wa,-mthumb
# CMSIS
STARTUP_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32F0xx/Source/Templates/system_stm32f0xx.o $(LIBDIR)/startup_$(MCU).o

View file

@ -7,7 +7,8 @@ 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
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
# CMSIS
STARTUP_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32F10x/Source/Templates/system_stm32f10x.o $(LIBDIR)/startup_$(MCU_SUBTYPE).o

View file

@ -6,7 +6,8 @@ MCU_INCLUDE += -I$(LIBDIR)/STM32F2xx_StdPeriph_Driver/inc
# Set up CFLAGS
MCU_CPPFLAGS += -D"assert_param(expr)=((void)0)"
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
# CMSIS
STARTUP_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32F2xx/Source/Templates/system_stm32f2xx.o $(LIBDIR)/startup_$(MCU).o

View file

@ -7,7 +7,8 @@ MCU_INCLUDE += -I$(LIBDIR)/STM32F30x_StdPeriph_Driver/inc
# Set up CFLAGS
MATH_CPPFLAGS += -D__FPU_PRESENT=1
MCU_CPPFLAGS += -D"assert_param(expr)=((void)0)"
MCU_CFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
# CMSIS
STARTUP_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32F30x/Source/Templates/system_stm32f30x.o $(LIBDIR)/startup_$(MCU).o

View file

@ -7,7 +7,8 @@ MCU_INCLUDE += -I$(LIBDIR)/STM32F37x_StdPeriph_Driver/inc
# Set up CFLAGS
MATH_CPPFLAGS += -D__FPU_PRESENT=1
MCU_CPPFLAGS += -D"assert_param(expr)=((void)0)"
MCU_CFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
MCU_CFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb
# CMSIS
STARTUP_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32F37x/Source/Templates/system_stm32f37x.o $(LIBDIR)/startup_$(MCU).o

View file

@ -9,6 +9,7 @@ MATH_CPPFLAGS += -D__FPU_PRESENT=1
MCU_CPPFLAGS += -D$(shell echo -n $(MCU_SUBTYPE) | tr a-z A-Z | tr X x )
MCU_CPPFLAGS += -D"assert_param(expr)=((void)0)"
MCU_CFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard
MCU_CXXFLAGS += -mcpu=cortex-m4 -mthumb -Wa,-mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard
# CMSIS
STARTUP_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.o $(LIBDIR)/startup_$(MCU_SUBTYPE).o

View file

@ -7,7 +7,8 @@ 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
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
# CMSIS
STM32L1xx_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32L1xx/Source/Templates/system_stm32l1xx.o

View file

@ -7,7 +7,8 @@ MCU_INCLUDE += -I$(LIBDIR)/STM32W108xx_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
MCU_CFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
MCU_CXXFLAGS += -mcpu=cortex-m3 -mthumb -Wa,-mthumb
# CMSIS
STM32W108xx_OBJS = $(LIBDIR)/CMSIS/Device/ST/STM32W108xx/Source/Templates/system_stm32w108xx.o