Skip to content

Commit efd4294

Browse files
committed
atmel-samd: Switch to nano newlib and add size script to build.
1 parent 75d0b02 commit efd4294

File tree

2 files changed

+68
-5
lines changed

2 files changed

+68
-5
lines changed

atmel-samd/Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,10 @@ CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
139139
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
140140
endif
141141

142-
LIBGCC_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
143142
LIBM_FILE_NAME = $(shell $(CC) $(CFLAGS) -print-file-name=libm.a)
144-
LDFLAGS = -L asf/thirdparty/CMSIS/Lib/GCC/ -L QTouch/ -L $(dir $(LIBGCC_FILE_NAME)) -L $(dir $(LIBM_FILE_NAME)) -nostdlib -T $(LD_FILE) -Map=$@.map --cref --gc-sections
143+
LDFLAGS = -Lasf/thirdparty/CMSIS/Lib/GCC/ -LQTouch/ -L$(dir $(LIBM_FILE_NAME)) -Wl,-nostdlib -Wl,-T,$(LD_FILE) -Wl,-Map=$@.map -Wl,-cref -Wl,-gc-sections -specs=nano.specs
145144
LIBS = -larm_cortexM0l_math -lsamd21_qtouch_gcc -lm -lgcc -lc
146145

147-
148146
SRC_ASF = $(addprefix asf/sam0/,\
149147
drivers/adc/adc_sam_d_r/adc.c \
150148
drivers/dac/dac_sam_d_c/dac.c \
@@ -260,8 +258,8 @@ all: $(BUILD)/firmware.bin
260258

261259
$(BUILD)/firmware.elf: $(OBJ)
262260
$(ECHO) "LINK $@"
263-
$(Q)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
264-
$(Q)$(SIZE) $@
261+
$(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group
262+
$(Q)$(SIZE) $@ | python3 ../tools/build_memory_info.py $(LD_FILE)
265263

266264
$(BUILD)/firmware.bin: $(BUILD)/firmware.elf
267265
$(ECHO) "Create $@"

tools/build_memory_info.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python3
2+
#
3+
# This file is part of the MicroPython project, http://micropython.org/
4+
#
5+
# The MIT License (MIT)
6+
#
7+
# Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in
17+
# all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
# THE SOFTWARE.
26+
27+
import sys
28+
29+
print()
30+
31+
text = 0
32+
data = 0
33+
bss = 0
34+
# stdin is the linker output.
35+
for line in sys.stdin:
36+
line = line.strip()
37+
if not line.startswith("text"):
38+
text, data, bss = map(int, line.split()[:3])
39+
40+
regions = {}
41+
# This file is the linker script.
42+
with open(sys.argv[1], "r") as f:
43+
for line in f:
44+
line = line.strip()
45+
if line.startswith(("FLASH", "RAM")):
46+
regions[line.split()[0]] = line.split("=")[-1]
47+
48+
for region in regions:
49+
space = regions[region]
50+
if "/*" in space:
51+
space = space.split("/*")[0]
52+
regions[region] = eval(space)
53+
54+
free_flash = regions["FLASH"] - text - data
55+
free_ram = regions["RAM"] - data - bss
56+
print(free_flash, "bytes free in flash out of", regions["FLASH"], "bytes (", regions["FLASH"] / 1024, "kb ).")
57+
print(free_ram, "bytes free in ram for stack out of", regions["RAM"], "bytes (", regions["RAM"] / 1024, "kb ).")
58+
print()
59+
60+
# Check that we have free flash space. GCC doesn't fail when the text + data
61+
# sections don't fit in FLASH. It only counts data in RAM.
62+
if free_flash < 0:
63+
print("Too little flash!!!")
64+
print()
65+
sys.exit(-1)

0 commit comments

Comments
 (0)