samd: Add support for building with user C modules.

Fixes issue #7545.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2021-07-22 16:18:54 +10:00
parent 7649f5fbd2
commit a5ac3d5645
3 changed files with 36 additions and 4 deletions

View File

@ -33,7 +33,11 @@ CFLAGS_MCU_SAMD21 = -mtune=cortex-m0plus -mcpu=cortex-m0plus -msoft-float
CFLAGS_MCU_SAMD51 = -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS = $(INC) -Wall -Werror -std=c99 -nostdlib -mthumb $(CFLAGS_MCU_$(MCU_SERIES)) -fsingle-precision-constant -Wdouble-promotion
CFLAGS += -DMCU_$(MCU_SERIES) -D__$(CMSIS_MCU)__
CFLAGS += $(CFLAGS_MOD)
LDFLAGS = -nostdlib $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref
LDFLAGS += $(LDFLAGS_MOD)
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
# Tune for Debugging or Optimization
@ -45,6 +49,14 @@ LDFLAGS += --gc-sections
CFLAGS += -fdata-sections -ffunction-sections
endif
# Flags for optional C++ source code
CXXFLAGS += $(filter-out -std=c99,$(CFLAGS))
CXXFLAGS += $(CXXFLAGS_MOD)
ifneq ($(SRC_CXX)$(SRC_MOD_CXX),)
LIBSTDCPP_FILE_NAME = "$(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)"
LDFLAGS += -L"$(shell dirname $(LIBSTDCPP_FILE_NAME))"
endif
SRC_C = \
main.c \
modutime.c \
@ -70,6 +82,10 @@ SRC_C = \
shared/runtime/pyexec.c \
shared/runtime/stdout_helpers.c \
SRC_C += $(SRC_MOD)
SRC_CXX += $(SRC_MOD_CXX)
ifeq ($(MCU_SERIES),SAMD21)
SRC_S = shared/runtime/gchelper_m0.s
else
@ -77,10 +93,11 @@ SRC_S = shared/runtime/gchelper_m3.s
endif
# List of sources for qstr extraction
SRC_QSTR += modutime.c modmachine.c
SRC_QSTR += modutime.c modmachine.c $(SRC_MOD) $(SRC_CXX)
OBJ += $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
# Workaround for bug in older gcc, warning on "static usbd_device_t _usbd_dev = { 0 };"

View File

@ -87,6 +87,11 @@ void nlr_jump_fail(void *val) {
}
}
void abort(void) {
for (;;) {
}
}
#ifndef NDEBUG
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
mp_printf(MP_PYTHON_PRINTER, "Assertion '%s' failed, at file %s:%d\n", expr, file, line);

View File

@ -11,10 +11,20 @@ SECTIONS
*(.rodata*)
. = ALIGN(4);
_etext = .;
_sidata = _etext;
} >FLASH
.data : AT ( _sidata )
/* For C++ exception handling */
.ARM :
{
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} >FLASH
/* Used by the start-up code to initialise data */
_sidata = LOADADDR(.data);
.data :
{
. = ALIGN(4);
_sdata = .;
@ -22,7 +32,7 @@ SECTIONS
*(.data*)
. = ALIGN(4);
_edata = .;
} >RAM
} >RAM AT> FLASH
.bss :
{