Skip to content

Commit

Permalink
samd: Add support for building with user C modules.
Browse files Browse the repository at this point in the history
Fixes issue #7545.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Jul 22, 2021
1 parent 7649f5f commit a5ac3d5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
19 changes: 18 additions & 1 deletion ports/samd/Makefile
Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -70,17 +82,22 @@ 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
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 };"
Expand Down
5 changes: 5 additions & 0 deletions ports/samd/main.c
Expand Up @@ -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);
Expand Down
16 changes: 13 additions & 3 deletions ports/samd/sections.ld
Expand Up @@ -11,18 +11,28 @@ 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 = .;
*(.data)
*(.data*)
. = ALIGN(4);
_edata = .;
} >RAM
} >RAM AT> FLASH

.bss :
{
Expand Down

0 comments on commit a5ac3d5

Please sign in to comment.