Skip to content

Commit db43b70

Browse files
authored
fix(CMSIS): Share multi core data 7800x when using RISCV_LOAD (#1568)
The .shared section correctly shared data when using _arm/_riscv ld scripts. But it didn't work when use the max7800x.ld script with RISCV_LOAD=1. As a result, SystemCoreClock on the RISC-V side got uninitialised values. This meant that peripheral configuration could compute wrong divisors etc. Create a SHARED section that is defined for both ARM and RISC-V and place the .shared section there. I've also moved it to the end of the memory block to avoid wasting space, but I keep it by default in a location that doesn't get used for ICC1. Old CFS projects don't have the SHARED section defined, and replace the MEMORY command in the ld script with one that doesn't have SHARED. So we can't map to SHARED directly. Instead, place at the symbol value and add an assert that the mapped data fits in the region to force an error if not. If CFS doesn't provide SHARED, place the data at the very end of the memory and hope there's no conflict. Note that for multi-core projects, this location might conflict with ICC1, but old CFS projects would have been broken anyway so it doesn't matter too much. Signed-off-by: Michael Perkins <Michael.Perkins@analog.com>
1 parent d52b2c8 commit db43b70

8 files changed

Lines changed: 84 additions & 22 deletions

File tree

Libraries/CMSIS/Device/Maxim/MAX78000/Source/GCC/common.ld

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* Shared RISC-V and ARM memory map */
22
_FlashLength_ = __FlashLength;
3+
34
MEMORY {
45
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000 /* 64kB - ROM */
56

@@ -9,8 +10,14 @@ MEMORY {
910

1011
SRAM1 (rwx) : ORIGIN = 0x20008000, LENGTH = 0x00008000 /* 32 kB - ARM Stack */
1112

12-
SRAM2 (rwx) : ORIGIN = 0x20010000, LENGTH = 0x0000C000 /* 48kB SRAM2 - RV Data */
13+
SRAM2 (rwx) : ORIGIN = 0x20010000, LENGTH = 0x0000BFF8 /* ~48kB SRAM2 - RV Data */
14+
15+
SHARED (rw) : ORIGIN = 0x2001BFF8, LENGTH = 0x00000008 /* 8B Shared - ARM, RV Data */
1316

1417
SRAM3 (rwx) : ORIGIN = 0x2001C000, LENGTH = 0x00004000 /* 16kB SRAM3 - RV Code */
1518
}
1619

20+
/* The address and length of the SHARED section defined above. */
21+
__shared_origin = ORIGIN(SHARED);
22+
__shared_length = LENGTH(SHARED);
23+

Libraries/CMSIS/Device/Maxim/MAX78000/Source/GCC/max78000.ld

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
44
* Analog Devices, Inc.),
5-
* Copyright (C) 2023-2024 Analog Devices, Inc.
5+
* Copyright (C) 2023-2026 Analog Devices, Inc.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -21,9 +21,14 @@
2121
MEMORY {
2222
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000 /* 64kB ROM */
2323
FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 0x00080000 /* 512KB Flash */
24-
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00020000 /* 128kB SRAM */
24+
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0001FFF8 /* ~128KB SRAM */
25+
SHARED (rw) : ORIGIN = 0x2001FFF8, LENGTH = 0x00000008 /* 8B Shared */
2526
}
2627

28+
/* The address and length of the SHARED section defined above. */
29+
__shared_origin = ORIGIN(SHARED);
30+
__shared_length = LENGTH(SHARED);
31+
2732
SECTIONS {
2833
.rom :
2934
{
@@ -149,17 +154,27 @@ SECTIONS {
149154
_ebss = ALIGN(., 4);
150155
} > SRAM
151156

152-
.shared :
157+
/* We map the .shared section to a symbol rather than >SHARED to allow for backwards compatibility in CFS
158+
* with older projects that did not provide SHARED (note that CFS replaces the MEMORY command at the top of
159+
* this file). In that case, we just map to the end of memory.
160+
* We add an assert to ensure that the section fits in the available space.
161+
*/
162+
PROVIDE(__shared_origin = 0x2001FFF8);
163+
PROVIDE(__shared_length = 8);
164+
165+
.shared __shared_origin (NOLOAD) :
153166
{
154167
. = ALIGN(4);
155168
_shared = .;
156169
*(.mailbox*)
157170
. = ALIGN(4);
158171
*(.shared*) /*read-write zero initialized data: uninitialzed global variable*/
159172
_eshared = ALIGN(., 4);
160-
} > SRAM AT>FLASH
173+
}
161174
__shared_data = LOADADDR(.shared);
162175

176+
ASSERT(SIZEOF(.shared) <= __shared_length, ".shared section overflow: exceeds inter-core shared memory region")
177+
163178
/* Set stack top to end of RAM, and stack limit move down by
164179
* size of stack_dummy section */
165180
__StackTop = ORIGIN(SRAM) + LENGTH(SRAM);

Libraries/CMSIS/Device/Maxim/MAX78000/Source/GCC/max78000_arm.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
44
* Analog Devices, Inc.),
5-
* Copyright (C) 2023-2024 Analog Devices, Inc.
5+
* Copyright (C) 2023-2026 Analog Devices, Inc.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -62,15 +62,15 @@ SECTIONS {
6262
* aligned to mod 256 address... REQUIRED */
6363
__FlashStart_ = (((LOADADDR(.data) + SIZEOF(.data)) & 0x1FFFFF00) + 0x100);
6464

65-
.shared :
65+
.shared (NOLOAD) :
6666
{
6767
. = ALIGN(4);
6868
_shared = .;
6969
*(.mailbox*)
7070
. = ALIGN(4);
7171
*(.shared*) /*read-write zero initialized data: uninitialzed global variable*/
7272
_eshared = ALIGN(., 4);
73-
} > SRAM2 AT>FLASH
73+
} > SHARED
7474
__shared_data = LOADADDR(.shared);
7575

7676
.data :

Libraries/CMSIS/Device/Maxim/MAX78000/Source/GCC/max78000_riscv.ld

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
44
* Analog Devices, Inc.),
5-
* Copyright (C) 2023-2024 Analog Devices, Inc.
5+
* Copyright (C) 2023-2026 Analog Devices, Inc.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -40,15 +40,24 @@ SECTIONS {
4040
_etext = .;
4141
} > FLASH
4242

43-
.shared (NOLOAD) : /* CM4 loads this section from flash in startup code */
43+
/* We map the .shared section to a symbol rather than >SHARED to allow for backwards compatibility in CFS
44+
* with older projects that did not provide SHARED (note that CFS replaces the MEMORY command at the top of
45+
* this file). In that case, we just map to the end of memory.
46+
* We add an assert to ensure that the section fits in the available space.
47+
*/
48+
PROVIDE(__shared_origin = 0x2001FFF8);
49+
PROVIDE(__shared_length = 8);
50+
51+
.shared __shared_origin (NOLOAD) :
4452
{
4553
. = ALIGN(4);
4654
_shared = .;
4755
*(.mailbox*)
4856
. = ALIGN(4);
4957
*(.shared*) /*read-write zero initialized data: uninitialzed global variable*/
5058
_eshared = ALIGN(., 4);
51-
} > SRAM2
59+
}
60+
ASSERT(SIZEOF(.shared) <= __shared_length, ".shared section overflow: exceeds inter-core shared memory region")
5261

5362
/* short/global data section */
5463
.sdata :

Libraries/CMSIS/Device/Maxim/MAX78002/Source/GCC/common.ld

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* Shared RISC-V and ARM memory map */
22
_FlashLength_ = __FlashLength;
3+
34
MEMORY {
45
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000 /* 64kB - ROM */
56

@@ -15,10 +16,16 @@ MEMORY {
1516

1617
SRAM4 (rwx) : ORIGIN = 0x20030000, LENGTH = 0x00010000 /* 64kB SRAM4 - RV, ARM */
1718

18-
SRAM5 (rwx) : ORIGIN = 0x20040000, LENGTH = 0x00010000 /* 64kB SRAM5 - RV, ARM */
19+
SRAM5 (rwx) : ORIGIN = 0x20040000, LENGTH = 0x00010000 /* ~64kB SRAM5 - RV, ARM */
20+
21+
SHARED (rw) : ORIGIN = 0x2004FFF8, LENGTH = 0x00000008 /* 8B Shared - RV, ARM */
1922

2023
SRAM6 (rwx) : ORIGIN = 0x20050000, LENGTH = 0x0000C000 /* 48kB SRAM6 - RV, ARM */
2124

2225
SRAM7 (rwx) : ORIGIN = 0x2005C000, LENGTH = 0x00004000 /* 16kB SRAM7 - RV, ICC1, or ARM */
2326
}
2427

28+
/* The address and length of the SHARED section defined above. */
29+
__shared_origin = ORIGIN(SHARED);
30+
__shared_length = LENGTH(SHARED);
31+

Libraries/CMSIS/Device/Maxim/MAX78002/Source/GCC/max78002.ld

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
44
* Analog Devices, Inc.),
5-
* Copyright (C) 2023-2024 Analog Devices, Inc.
5+
* Copyright (C) 2023-2026 Analog Devices, Inc.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -21,10 +21,15 @@
2121
MEMORY {
2222
ROM (rx) : ORIGIN = 0x00000000, LENGTH = 0x00010000 /* 64 kB ROM */
2323
FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 0x00280000 /* 2.5 MB Flash */
24-
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00060000 /* 384 kB SRAM */
24+
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0005FFF8 /* ~384kB SRAM */
25+
SHARED (rw) : ORIGIN = 0x2005FFF8, LENGTH = 0x00000008 /* 8B Shared */
2526
/*CSI2 (rwx) : ORIGIN = 0x2001F000, LENGTH = 0x00001000 4096 B CSI2 Buffer */
2627
}
2728

29+
/* The address and length of the SHARED section defined above. */
30+
__shared_origin = ORIGIN(SHARED);
31+
__shared_length = LENGTH(SHARED);
32+
2833
SECTIONS {
2934
.rom :
3035
{
@@ -152,17 +157,27 @@ SECTIONS {
152157
_ebss = ALIGN(., 4);
153158
} > SRAM
154159

155-
.shared :
160+
/* We map the .shared section to a symbol rather than >SHARED to allow for backwards compatibility in CFS
161+
* with older projects that did not provide SHARED (note that CFS replaces the MEMORY command at the top of
162+
* this file). In that case, we just map to the end of memory.
163+
* We add an assert to ensure that the section fits in the available space.
164+
*/
165+
PROVIDE(__shared_origin = 0x2005FFF8);
166+
PROVIDE(__shared_length = 8);
167+
168+
.shared __shared_origin (NOLOAD) :
156169
{
157170
. = ALIGN(4);
158171
_shared = .;
159172
*(.mailbox*)
160173
. = ALIGN(4);
161174
*(.shared*) /*read-write zero initialized data: uninitialzed global variable*/
162175
_eshared = ALIGN(., 4);
163-
} > SRAM
176+
}
164177
__shared_data = LOADADDR(.shared);
165178

179+
ASSERT(SIZEOF(.shared) <= __shared_length, ".shared section overflow: exceeds inter-core shared memory region")
180+
166181
/* Set stack top to end of RAM, and stack limit move down by
167182
* size of stack_dummy section */
168183
__StackTop = ORIGIN(SRAM) + LENGTH(SRAM);

Libraries/CMSIS/Device/Maxim/MAX78002/Source/GCC/max78002_arm.ld

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
44
* Analog Devices, Inc.),
5-
* Copyright (C) 2023-2024 Analog Devices, Inc.
5+
* Copyright (C) 2023-2026 Analog Devices, Inc.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -52,15 +52,15 @@ SECTIONS {
5252
* aligned to mod 256 address... REQUIRED */
5353
__FlashStart_ = (((LOADADDR(.data) + SIZEOF(.data)) & 0x1FFFFF00) + 0x100);
5454

55-
.shared :
55+
.shared (NOLOAD) :
5656
{
5757
. = ALIGN(4);
5858
_shared = .;
5959
*(.mailbox*)
6060
. = ALIGN(4);
6161
*(.shared*) /*read-write zero initialized data: uninitialzed global variable*/
6262
_eshared = ALIGN(., 4);
63-
} > SRAM5 AT>FLASH
63+
} > SHARED
6464
__shared_data = LOADADDR(.shared);
6565

6666
.data :

Libraries/CMSIS/Device/Maxim/MAX78002/Source/GCC/max78002_riscv.ld

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*
33
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
44
* Analog Devices, Inc.),
5-
* Copyright (C) 2023-2024 Analog Devices, Inc.
5+
* Copyright (C) 2023-2026 Analog Devices, Inc.
66
*
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
@@ -40,15 +40,24 @@ SECTIONS {
4040
_etext = .;
4141
} > FLASH
4242

43-
.shared (NOLOAD) : /* CM4 loads this section from flash in startup code */
43+
/* We map the .shared section to a symbol rather than >SHARED to allow for backwards compatibility in CFS
44+
* with older projects that did not provide SHARED (note that CFS replaces the MEMORY command at the top of
45+
* this file). In that case, we just map to the end of memory.
46+
* We add an assert to ensure that the section fits in the available space.
47+
*/
48+
PROVIDE(__shared_origin = 0x2005FFF8);
49+
PROVIDE(__shared_length = 8);
50+
51+
.shared __shared_origin (NOLOAD) :
4452
{
4553
. = ALIGN(4);
4654
_shared = .;
4755
*(.mailbox*)
4856
. = ALIGN(4);
4957
*(.shared*) /*read-write zero initialized data: uninitialzed global variable*/
5058
_eshared = ALIGN(., 4);
51-
} > SRAM5
59+
}
60+
ASSERT(SIZEOF(.shared) <= __shared_length, ".shared section overflow: exceeds inter-core shared memory region")
5261

5362
/* short/global data section */
5463
.sdata :

0 commit comments

Comments
 (0)