1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/cpu/cortexm_common/Makefile.include
Benjamin Valentin 2c09d9bd5b cpu/cortexm_common: Make Low-Power SRAM available to programs
Many MCUs contain some Backup or Low Power SRAM that is retained'even
in the deepest sleep modes.

In such sleep modes the MCU is essentually turned off with only the RTC
still running.
It can be woken by a GPIO or a RTC alarm. When this happens, a reset is
triggered and the normal startup routine is invoked.

This adds bss & data section for this memory in the linker script.
This allows for structures to be placed in it e.g.:

e.g.:

    static uint8_t persistent_buffer[64] __attribute__((section(".backup.bss")));
    static uint32_t persistent_counter __attribute__((section(".backup.data"))) = 1234;
2019-10-01 18:39:40 +02:00

72 lines
3.4 KiB
Makefile

# include module specific includes
INCLUDES += -I$(RIOTCPU)/cortexm_common/include
INCLUDES += -I$(RIOTCPU)/cortexm_common/include/vendor
# All variables must be defined in the CPU configuration when using the common
# `ldscripts/cortexm.ld`
ifneq (,$(ROM_START_ADDR)$(RAM_START_ADDR)$(ROM_LEN)$(RAM_LEN))
$(if $(ROM_START_ADDR),,$(error ROM_START_ADDR is not defined))
$(if $(RAM_START_ADDR),,$(error RAM_START_ADDR is not defined))
$(if $(ROM_LEN),,$(error ROM_LEN is not defined))
$(if $(RAM_LEN),,$(error RAM_LEN is not defined))
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_start_addr=$(ROM_START_ADDR)
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_start_addr=$(RAM_START_ADDR)
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_rom_length=$(ROM_LEN)
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_ram_length=$(RAM_LEN)
endif
ifneq (,$(BACKUP_RAM_LEN))
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_backup_ram_start_addr=$(BACKUP_RAM_ADDR)
LINKFLAGS += $(LINKFLAGPREFIX)--defsym=_backup_ram_len=$(BACKUP_RAM_LEN)
CFLAGS += -DCPU_HAS_BACKUP_RAM=1
endif
TOOLCHAINS_SUPPORTED = gnu llvm
# Only define the linker symbol if the variable is set
# The variable can be set using target specific variable thanks to lazy evaluation
# ROM_OFFSET: offset in rom to start linking, allows supporting a bootloader
LINKFLAGS += $(if $(ROM_OFFSET),$(LINKFLAGPREFIX)--defsym=_rom_offset=$(ROM_OFFSET))
# FW_ROM_LEN: rom length to use for firmware linking. Allows linking only in a section of the rom.
LINKFLAGS += $(if $(FW_ROM_LEN),$(LINKFLAGPREFIX)--defsym=_fw_rom_length=$(FW_ROM_LEN))
# Cortex-M0+/1/3/4/7 riotboot settings
# From ARMv7-M (M4, M3, M7) architecture reference manual, section B1.5.3
# https://static.docs.arm.com/ddi0403/e/DDI0403E_d_armv7m_arm.pdf
# "The Vector table must be naturally aligned to a power of two whose alignment
# value is greater than or equal to number of Exceptions supported x 4"
# From ARMv6-M (M0, M0+, M1) architecture reference manual, section B1.5.3
# https://static.docs.arm.com/ddi0419/d/DDI0419D_armv6m_arm.pdf
# "The table offset address that VTOR defines is 32-word aligned. Where more
# than 16 external interrupts are used, the offset word alignment must be
# increased to accommodate vectors for all the exceptions and interrupts
# supported and keep the required table size naturally aligned."
# For reference on the max number in interrupts per processor look in The
# technical reference manual "Interrupt Controller Type Register, ICTR" section.
# * For M4, M3 & M7: Maximum of 256 exceptions (256*4 bytes == 0x400).
# * For M0, M0+ & M1: Maximum of 48 exceptions (48*4 bytes = 192 bytes ~= 0x100).
# The values defined here are a theoretical maximum, in practice most cpu's
# CPU_IRQ_NUMOF value is around 100, in these cases the value can be reduced
# accordingly in the cpu Makefile.include, e.g: `kinetis/Makefile.include`
ifneq (,$(filter cortex-m2% cortex-m4% cortex-m3% cortex-m7%,$(CPU_ARCH)))
RIOTBOOT_HDR_LEN ?= 0x400
else
RIOTBOOT_HDR_LEN ?= 0x100
endif
# Configure riotboot bootloader and slot lengths
# 4KB are currently enough
RIOTBOOT_LEN ?= 0x1000
# Currently 2 slots are supported by default, equals in length
NUM_SLOTS ?= 2
# Take the whole flash minus RIOTBOOT_LEN and divide it by NUM_SLOTS
SLOT0_LEN ?= $(shell printf "0x%x" $$((($(ROM_LEN:%K=%*1024)-$(RIOTBOOT_LEN)) / $(NUM_SLOTS))))
SLOT1_LEN ?= $(SLOT0_LEN)
SLOT0_LEN := $(SLOT0_LEN)
SLOT1_LEN := $(SLOT1_LEN)