2021-07-19 11:45 PM
Hi All,
I'm using STMCubeIDE for an assembly project and I want to be able to store some variables in Flash memory at a specific address (like data tables).
I tried using a command like this but it didn't work:
#pragma location=0x08001000
DataStart:
.word 0
.word 0x10
When I look at the result in IDAPro this is what has actually happened (not located at the address I'd hoped for).
.text: 0800038E DataStart
.text: 0800038E DCD 0
.text: 08000392 DCD 0x10
Can someone please tell me how I can force the compiler to store values at a defined address.
Thanks.
2021-07-20 12:14 AM
Oh man assembly.... i have no clue.
What if you find a working C code that does what you want and then look in the dissasembly view from the debugger?
Use the linker script?
I believe you cannot write into flash memory like it was RAM,
you need to erase the full memory page and then write it again, or programm it at flashtime along your code
2021-07-20 01:45 AM
I wasn't trying to write to the flash with the program running (but you are right, there is specific processes to erase and write to flash memory).
I'm just trying to set up data tables in the program so when it is compliled (and flashed using STLink) they are in specific locations when the program is written to the MCU.
2021-07-20 02:33 AM
Then yes, you need to tell the linker script hey i need you to set this variables in this specific flash positions.
Similar to what i did here under @Community member advice
2021-07-20 03:11 AM
Ok thanks I'll have a read of that later (long thread).
I was hoping it might just be a simple as an .org directive, unfortunately what this seems to do is just advance the location from current to + whatever is defined as the value after .org
2021-07-20 03:32 AM
You can read it all if you want but i was pointing to the solution : (just change ram for flash)
in the linker script:
...............................
.fini_array :
{
. = ALIGN(4);
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
} >FLASH
/*javi*/
/*https://community.st.com/s/question/0D53W00000trgpiSAA/how-to-boot-to-random-address-without-vecttaboffset-stm32f072*/
/* redirected vector must go to top of the RAM */
.ram_vector :
{
*(.ram_vector)
} >RAM
/*javi*/
.................
in my c code
/* USER CODE BEGIN PV */
volatile uint32_t __attribute__((section(".ram_vector,\"aw\",%nobits @"))) ram_vector[VECTOR_TABLE_SIZE];
extern volatile uint32_t g_pfnVectors[VECTOR_TABLE_SIZE];
/* USER CODE END PV */