From 321e82c451732bf1bb582be7b8b49fb172020f10 Mon Sep 17 00:00:00 2001 From: Martin Luessi Date: Thu, 1 Jun 2023 08:50:09 -0700 Subject: [PATCH] AP_HAL_ChibiOS: Copy vector table to RAM if external flash is primary --- .../AP_HAL_ChibiOS/hwdef/common/chibios_board.mk | 4 ++++ .../AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/chibios_board.mk b/libraries/AP_HAL_ChibiOS/hwdef/common/chibios_board.mk index 14382747e7..5f2a87faaa 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/chibios_board.mk +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/chibios_board.mk @@ -250,6 +250,10 @@ endif # Define ASM defines here UADEFS = +ifeq ($(COPY_VECTORS_TO_RAM),yes) + UADEFS += -DCRT0_INIT_VECTORS=1 +endif + # List all user directories here UINCDIR = diff --git a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py index a4f77ac8ff..4bb546ffb1 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py +++ b/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py @@ -1292,12 +1292,25 @@ MEMORY INCLUDE common.ld ''' % (flash_base, flash_length, ram0_start, ram0_len)) - else: + elif int_flash_primary: if ext_flash_size > 32: error("We only support 24bit addressing over external flash") env_vars['HAS_EXTERNAL_FLASH_SECTIONS'] = 1 f.write('''/* generated ldscript.ld */ MEMORY +{ + flash : org = 0x%08x, len = %uK + ext_flash : org = 0x%08x, len = %uK + ram0 : org = 0x%08x, len = %u +} + +INCLUDE common_mixf.ld +''' % (flash_base, flash_length, ext_flash_base, ext_flash_length, ram0_start, ram0_len)) + else: + self.env_vars['HAS_EXTERNAL_FLASH_SECTIONS'] = 1 + self.build_flags.append('COPY_VECTORS_TO_RAM=yes') + f.write('''/* generated ldscript.ld */ +MEMORY { default_flash (rx) : org = 0x%08x, len = %uK instram : org = 0x%08x, len = %uK