Skip to content

Commit

Permalink
cpu/sam0_common: derive ROM_LEN, RAM_LEN from part number & vendor file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
benpicco committed Mar 25, 2020
1 parent 0edfce8 commit 7796110
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions cpu/sam0_common/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7796110

Please sign in to comment.