Skip to content

Commit a5ac3d5

Browse files
committed
samd: Add support for building with user C modules.
Fixes issue micropython#7545. Signed-off-by: Damien George <[email protected]>
1 parent 7649f5f commit a5ac3d5

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

ports/samd/Makefile

+18-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ CFLAGS_MCU_SAMD21 = -mtune=cortex-m0plus -mcpu=cortex-m0plus -msoft-float
3333
CFLAGS_MCU_SAMD51 = -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
3434
CFLAGS = $(INC) -Wall -Werror -std=c99 -nostdlib -mthumb $(CFLAGS_MCU_$(MCU_SERIES)) -fsingle-precision-constant -Wdouble-promotion
3535
CFLAGS += -DMCU_$(MCU_SERIES) -D__$(CMSIS_MCU)__
36+
CFLAGS += $(CFLAGS_MOD)
37+
3638
LDFLAGS = -nostdlib $(addprefix -T,$(LD_FILES)) -Map=$@.map --cref
39+
LDFLAGS += $(LDFLAGS_MOD)
40+
3741
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
3842

3943
# Tune for Debugging or Optimization
@@ -45,6 +49,14 @@ LDFLAGS += --gc-sections
4549
CFLAGS += -fdata-sections -ffunction-sections
4650
endif
4751

52+
# Flags for optional C++ source code
53+
CXXFLAGS += $(filter-out -std=c99,$(CFLAGS))
54+
CXXFLAGS += $(CXXFLAGS_MOD)
55+
ifneq ($(SRC_CXX)$(SRC_MOD_CXX),)
56+
LIBSTDCPP_FILE_NAME = "$(shell $(CXX) $(CXXFLAGS) -print-file-name=libstdc++.a)"
57+
LDFLAGS += -L"$(shell dirname $(LIBSTDCPP_FILE_NAME))"
58+
endif
59+
4860
SRC_C = \
4961
main.c \
5062
modutime.c \
@@ -70,17 +82,22 @@ SRC_C = \
7082
shared/runtime/pyexec.c \
7183
shared/runtime/stdout_helpers.c \
7284

85+
SRC_C += $(SRC_MOD)
86+
87+
SRC_CXX += $(SRC_MOD_CXX)
88+
7389
ifeq ($(MCU_SERIES),SAMD21)
7490
SRC_S = shared/runtime/gchelper_m0.s
7591
else
7692
SRC_S = shared/runtime/gchelper_m3.s
7793
endif
7894

7995
# List of sources for qstr extraction
80-
SRC_QSTR += modutime.c modmachine.c
96+
SRC_QSTR += modutime.c modmachine.c $(SRC_MOD) $(SRC_CXX)
8197

8298
OBJ += $(PY_O)
8399
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
100+
OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o))
84101
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
85102

86103
# Workaround for bug in older gcc, warning on "static usbd_device_t _usbd_dev = { 0 };"

ports/samd/main.c

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ void nlr_jump_fail(void *val) {
8787
}
8888
}
8989

90+
void abort(void) {
91+
for (;;) {
92+
}
93+
}
94+
9095
#ifndef NDEBUG
9196
void MP_WEAK __assert_func(const char *file, int line, const char *func, const char *expr) {
9297
mp_printf(MP_PYTHON_PRINTER, "Assertion '%s' failed, at file %s:%d\n", expr, file, line);

ports/samd/sections.ld

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,28 @@ SECTIONS
1111
*(.rodata*)
1212
. = ALIGN(4);
1313
_etext = .;
14-
_sidata = _etext;
1514
} >FLASH
1615

17-
.data : AT ( _sidata )
16+
/* For C++ exception handling */
17+
.ARM :
18+
{
19+
__exidx_start = .;
20+
*(.ARM.exidx*)
21+
__exidx_end = .;
22+
} >FLASH
23+
24+
/* Used by the start-up code to initialise data */
25+
_sidata = LOADADDR(.data);
26+
27+
.data :
1828
{
1929
. = ALIGN(4);
2030
_sdata = .;
2131
*(.data)
2232
*(.data*)
2333
. = ALIGN(4);
2434
_edata = .;
25-
} >RAM
35+
} >RAM AT> FLASH
2636

2737
.bss :
2838
{

0 commit comments

Comments
 (0)