From 77961106f9bb2799d9cd15746484997cdf89fb6d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 10 Mar 2020 12:15:35 +0100 Subject: [PATCH] cpu/sam0_common: derive ROM_LEN, RAM_LEN from part number & vendor file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ROM size is encoded in the part number of the Atmel SAM chips. RAM size is not encoded directly, so get it by parsing the chip's vendor file. The file remains in the page cache for the compiler to use, so the overhead should be minimal: on master: Benchmark #1: make BOARD=samr21-xpro -j Time (mean ± σ): 527.9 ms ± 4.9 ms [User: 503.1 ms, System: 69.6 ms] Range (min … max): 519.7 ms … 537.2 ms 10 runs with this patch: Benchmark #1: make BOARD=samr21-xpro -j Time (mean ± σ): 535.6 ms ± 4.0 ms [User: 507.6 ms, System: 75.1 ms] Range (min … max): 530.6 ms … 542.0 ms 10 runs --- cpu/sam0_common/Makefile.include | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/cpu/sam0_common/Makefile.include b/cpu/sam0_common/Makefile.include index f02e58a25fbc..61a693084398 100644 --- a/cpu/sam0_common/Makefile.include +++ b/cpu/sam0_common/Makefile.include @@ -4,25 +4,19 @@ CFLAGS += -DCPU_FAM_$(call uppercase_and_underscore,$(CPU_FAM)) # Generate ASF compatible model definition CFLAGS += -D__$(call uppercase_and_underscore,$(CPU_MODEL))__ -# Set ROM and RAM lengths according to CPU model -ifneq (,$(filter samd21g18a samd21j18a saml21j18b saml21j18a samr21e18a \ - samr21g18a samr30g18a samr34j18b,$(CPU_MODEL))) - - ROM_LEN ?= 0x40000 - RAM_LEN ?= 0x8000 -endif -ifneq (,$(filter saml10e16a saml11e16a,$(CPU_MODEL))) - ROM_LEN ?= 64K - RAM_LEN ?= 16K -endif -ifneq (,$(filter samd21j17d,$(CPU_MODEL))) - ROM_LEN ?= 128K - RAM_LEN ?= 16K -endif -ifneq (,$(filter samd51j20a same54p20a,$(CPU_MODEL))) - ROM_LEN ?= 1024K - RAM_LEN ?= 256K -endif +# Compute CPU_LINE +LINE := $(shell echo $(CPU_MODEL) | sed -E -e 's/^sam([a-z][0-9][0-9])(.)([0-9][0-9])(.)/\1 \2 \3 \4/') +FAMILY := $(word 1, $(LINE)) +TYPE1 := $(word 2, $(LINE)) +MEMORY := $(word 3, $(LINE)) +TYPE2 := $(word 4, $(LINE)) + +# ROM length is directly encoded in the part number +ROM_LEN := $(shell echo $$((1 << $(MEMORY)))) + +# get vendor file to extract RAM length +VENDOR_FILE := $(shell find $(RIOTCPU)/sam0_common/include/vendor/sam$(FAMILY) -name $(CPU_MODEL).h | grep include.*/sam) +RAM_LEN := $(shell sed -E -n 's/\#define (HMCRAMC0_SIZE|HSRAM_SIZE).*(0x[[:xdigit:]]*).*/\2/p' $(VENDOR_FILE)) ROM_START_ADDR ?= 0x00000000 RAM_START_ADDR ?= 0x20000000