This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Failed to copy some part of my code into SRAM instead of FLASH (as CODE memory) on MBED BOARDS (DISCO_L496AG, NUCLEO_F413ZH)

Hi, i am using DISCO_L496AG, NUCLEO_F413ZH mbed board, as a start i would like to run a basic benchmark code.
Agenda:
Transferring the data within the same memory type i.e FLASH - FLASH and SRAM - SRAM and capture the time of the data transfer.
Here is my code:

(Perform the test by storing the CODE area in FLASH region and CODE area in SRAM region).
→ CODE in FLASH can be achieved with the default linker script (I.e CODE resides in FLASH region, DATA, bss, stack resides in SRAM )
location of original linker script:
mbed-os/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L496xG/TOOLCHAIN_GCC_ARM/stm32l496xg.ld

Now the real problem starts:

To achieve the 2nd part (CODE area in SRAM region) i am facing lot of issues and i have come-up with the list which i have tried so far… (see below):

1st method: Added a new section to the original linker script and added my main.cpp file into that section and excluded the same file in the original text section but the output of .bin file is very large (in MB) here are my additions to the original linker script:
FYI: i have tried placing NOLOAD also to avoid large .bin file but it didn’t worked.
.text_b :
{
. = ALIGN(4);
__text_b_start = .;
main.o(.text* .rodata*)
. = ALIGN(4);
__text_b_end = .;
} > RAM
.text :
{
*(EXCLUDE_FILE(main.o) .text .rodata)
} > FLASH

2nd Method:
Instead of placing complete file into RAM memory i tried to place my private function into particular linker section but ended up with no luck still the code is executing from the FLASH memory only.
FYI: I tried other experiment also i.e to keep the “ram” is the VMA & rom in the LMA.
Here is my code:
.text_b :
{
. = ALIGN(4);
__text_b_start = .;
(.text_b)
__text_b_end = .;
} > RAM AT > FLASH

3rd method(last sad try):
The idea is to copy my private function code from the FLASH to the SRAM during the execution which will run from the SRAM execution, i am 100% sure that my function is copying into the SRAM correctly but its going into exception handler. When trying to print the PC address it is correctly printing the my_func() address but throwing an exception.

here is my code:

If anyone knows anything about the issue please help me thanks in advance.

Exception:
Here i have tried to print the data located stored RAM address which is exactly matched with the .lst file
Note: here R3 register is the exact location of my_func() but the exception i am getting at location prior to the R3 register (0x20000F6C)

++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0x20000F6C
Error Value: 0x20004130
Current Thread: main Id: 0x200017C0 Entry: 0x8001E71 StackSize: 0x1000 StackMem: 0x200030F0 SP: 0x200040B0
For more info, visit: mbedos-error
– MbedOS Error Info –
¦m-timestamp-mode-performance
m-lap-us-9484
m-init-done
m-ready
Data matched with the .lst file
38b5
7946
124c
1348
2160
fff7
acff
1248
124d
fff7
a8ff
1248
2f0
dff8
1148
fff7
a2ff
1148
023
2a68
d15c
268
d154
133
b3f5
04f
f7d1
a48
2f0
2f9
6a46
b4b
1a60
7b46
2360
7246
94b
1a60
38bd
0bf
e8f
020
923a
48
9a3a
48
b41
020
f0f
020
aa3a
48
b81
020
ecf
020
e4f
020
ram func = 20000f6d

++ MbedOS Fault Handler ++

FaultType: HardFault

Context:
R 0: 00000014
R 1: 0000000A
R 2: 00000000
R 3: 20000F6D
R 4: 20000FE0
R 5: 20000FE0
R 6: 08043AE9
R 7: 20000FEC
R 8: 08043B6D
R 9: 20000FE4
R 10: 08043B47
R 11: 08043B21
R 12: 00000000
SP : 200040B0
LR : 0800043B
PC : 20000F6C
xPSR : 01010000
PSP : 20004048
MSP : 2003FFC0
CPUID: 410FC241
HFSR : 40000000
MMFSR: 00000001
BFSR : 00000000
UFSR : 00000000
DFSR : 00000008
AFSR : 00000000
Mode : Thread
Priv : Privileged
Stack: PSP

– MbedOS Fault Handler –

++ MbedOS Error Info ++
Error Status: 0x80FF013D Code: 317 Module: 255
Error Message: Fault exception
Location: 0x20000F6C
Error Value: 0x20004130
Current Thread: main Id: 0x200017C0 Entry: 0x8001E71 StackSize: 0x1000 StackMem: 0x200030F0 SP: 0x200040B0
For more info, visit: mbedos-error
– MbedOS Error Info –

.lst file data: