Skip to content

Commit 480b3ce

Browse files
committed
GENERIC_STM32H747_M4: fix VTOR if relocated to SDRAM
1 parent 5af0bd7 commit 480b3ce

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

mbed-os-to-arduino

+10
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ generate_flags () {
200200
*(.pdm_buffer)\n \
201201
} > RAM_D3\n"
202202

203+
if [[ $ARDUINOVARIANT == *GENERIC*M4 ]]; then
204+
echo "Fixing VTOR base in $ARDUINOVARIANT/linker_script.ld"
205+
VTOR_SECTION="#if (CM4_BINARY_START == 0x60000000)\n \
206+
REGION_ALIAS(\"RAM\", FLASH);\n \
207+
#else\n \
208+
REGION_ALIAS(\"RAM\", RAM_D2);\n \
209+
#endif\n"
210+
sed -i "s?REGION_ALIAS.*?${VTOR_SECTION}?g" $ARDUINOVARIANT/linker_script.ld
211+
fi
212+
203213
if [[ $ARDUINOVARIANT == *PORTENTA*M7* || $ARDUINOVARIANT == *GIGA* || $ARDUINOVARIANT == *OPTA* ]]; then
204214
OPENAMP_SECTION="${OPENAMP_SECTION} \
205215
_dtcm_lma = __etext + SIZEOF(.data);\n \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 2d834973fc86b787535204b174303a0311e1f36f Mon Sep 17 00:00:00 2001
2+
From: Martino Facchin <[email protected]>
3+
Date: Fri, 19 Jan 2024 11:13:09 +0100
4+
Subject: [PATCH] stm32h747: cm4: set VTOR at boot
5+
6+
---
7+
.../STM32Cube_FW/system_stm32h7xx_dualcore_boot_cm4_cm7.c | 2 +-
8+
.../TOOLCHAIN_GCC_ARM/stm32h747xI_CM4.ld | 8 +++++++-
9+
2 files changed, 8 insertions(+), 2 deletions(-)
10+
11+
diff --git a/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/system_stm32h7xx_dualcore_boot_cm4_cm7.c b/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/system_stm32h7xx_dualcore_boot_cm4_cm7.c
12+
index b4a4cc7826..8e0017de2a 100644
13+
--- a/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/system_stm32h7xx_dualcore_boot_cm4_cm7.c
14+
+++ b/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/system_stm32h7xx_dualcore_boot_cm4_cm7.c
15+
@@ -232,7 +232,7 @@ __weak void SystemInit (void)
16+
/* Configure the Vector Table location add offset address ------------------*/
17+
#ifdef VECT_TAB_SRAM
18+
SCB->VTOR = D2_AXISRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
19+
-#elif !defined(NO_VTOR_RELOCATE)
20+
+#else
21+
#include "nvic_addr.h" // MBED
22+
SCB->VTOR = NVIC_FLASH_VECTOR_ADDRESS; // MBED
23+
#endif
24+
diff --git a/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_STM32H747xI_CM4/TOOLCHAIN_GCC_ARM/stm32h747xI_CM4.ld b/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_STM32H747xI_CM4/TOOLCHAIN_GCC_ARM/stm32h747xI_CM4.ld
25+
index ea81a18b11..7d2651dcb4 100644
26+
--- a/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_STM32H747xI_CM4/TOOLCHAIN_GCC_ARM/stm32h747xI_CM4.ld
27+
+++ b/targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_STM32H747xI_CM4/TOOLCHAIN_GCC_ARM/stm32h747xI_CM4.ld
28+
@@ -38,10 +38,16 @@
29+
MEMORY
30+
{
31+
FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE
32+
- RAM (rwx) : ORIGIN = MBED_RAM_START + VECTORS_SIZE, LENGTH = MBED_RAM_SIZE - VECTORS_SIZE
33+
+ RAM_D2 (rwx) : ORIGIN = MBED_RAM_START + VECTORS_SIZE, LENGTH = MBED_RAM_SIZE - VECTORS_SIZE
34+
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
35+
}
36+
37+
+#if (CM4_BINARY_START == 0x60000000)
38+
+REGION_ALIAS("RAM", FLASH);
39+
+#else
40+
+REGION_ALIAS("RAM", RAM_D2);
41+
+#endif
42+
+
43+
/* Linker script to place sections and symbol values. Should be used together
44+
* with other linker script that defines memory regions FLASH and RAM.
45+
* It references following symbols, which must be defined in code:
46+
--
47+
2.43.0
48+

0 commit comments

Comments
 (0)