Hi Chandan,
Welcome to interrupt!
You are correct. I wanted to cover this technique, but it is not required or even appropriate for every project. Reasons you might want to relocate to RAM are:
- It might be faster than ROM on some chips
- Not every MCU supports executing from flash
You are correct, you end up with two copies of that code. It is technically possible to use a single copy of the code shared between the app and the bootloader, but it is non trivial. In the past I have done this to avoid having two copies of libc
(in bootloader & app). The trick is to link your app against your bootloader. Perhaps we will cover this in a future post.
You can find documentation for the naked
attribute here. This attribute is used to tell the compiler it should not add a function prologue / epilogue. It is recommended when a function contains only inline assembly. In this case, omitting it likely would not cause problems.
I am not familiar with the STM32 workbench, but remember that you should be taking a reference to the variable. I would expect &_shared_data_start
to be 0x20000300
, but if you remove the &
you won’t get the expected value.
Hope that helps!