I want to configure global variable in specific flash address(High address 0x00160000:H7 Block).
so I used flash erase and write sequence function with the Manual.
And EPPC Target in Target settings panels, Small Data and Small Data2 -->0
So, I can check the variable is configured in address 0x00160000
Now, My question.
Only 'Const' can be saved in flash memory? Or can be delete or not? The flash erase sequence doesn't operate. The variable "test" value can't be modified in flash??
How can I modify this value(test) in flash memory?
<lcf>
MEMORY
{
resetvector: org = 0x00000000, len = 0x00000008
init: org = 0x00000020, len = 0x00000FE0
exception_handlers: org = 0x00001000, len = 0x00001000
internal_flash: org = 0x00002000, len = 0x00160000
my_Flash: org = 0x00160000, len = 0x0001E000
internal_ram: org = 0x40000000, len = 0x0000A000
heap : org = 0x4000A000, len = 0x00002000 /* Heap start location */
stack : org = 0x4000C000, len = 0x00004000 /* Start location for Stack */
}
.
.
SECTIONS
{
.__bam_bootarea LOAD (0x00000000): {} > resetvector
GROUP : {
.init LOAD (0x00000020) : {}
.init_vle (VLECODE) LOAD (_e_init) : {
*(.init)
*(.init_vle)
}
} > init
.__exception_handlers LOAD (0x00001000): {} > exception_handlers
GROUP : {
.text : {}
.text_vle (VLECODE) ALIGN(0x1000): {
*(.text)
*(.text_vle)
}
.rodata (CONST) : {
*(.rdata)
*(.rodata)
}
.ctors : {}
.dtors : {}
extab : {}
extabindex : {}
} > internal_flash
.__my_Flash LOAD(0x00160000):{}>my_Flash
GROUP : {
.__uninitialized_intc_handlertable ALIGN(0x10) : {}
.data : {}
.sdata : {}
.sbss : {}
.sdata2 : {}
.sbss2 : {}
.bss : {}
} > internal_ram
}
<.c file>
#pragma push
#pragma section all_types ".__my_Flash" ".__my_Flash"
uint32_t test=0x1000;
#pragma pop
<write sequence>
unsigned int* b = (unsigned int*)address;
FLASH.MCR.B.PGM = 1;
test = data;
add=&test;
FLASH.MCR.B.EHV = 1;
while(FLASH.MCR.B.DONE == 1){};
FLASH.MCR.B.EHV = 0;
FLASH.MCR.B.PGM = 0;
<Result>
&test = 0x00160000
*test = 0x1000
But I can't modify this variable's value.
Thank you for your help and I checked the code of your example.
I think, I don't understand yet. T.T
I have a global variable, 'Offset'. This variable is modified at once( when the main application is start) by auto calibration function.
So, The auto calibration function will find the 'Offset' value, then I need to save this value in flash address.
And then, after the value save in flash address, I will use this value(Offset) on the main application's operation without the auto calibration even after Power Reset.
So, I used #pragma to configure the variable direct in flash address.
This way has a problem the only constant value can save in flash.
And, I made the flash routine, but there're bus error.
#pragma push
#pragma section all_types ".__my_Flash" ".__my_Flash"
static const vuint32_t WVar=0xAAAAAAAA;
#pragma pop
I want make operation like 'WVar=Offset'.
void Program_FLASH(void)
{
#define FLASH_HLR_PASSWORD 0xB2B22222
/* enable high address space */
FLASH.HLR.R = FLASH_HLR_PASSWORD; // unlock register
FLASH.HLR.B.HBLOCK = 0x00000000; // unlock all high blocks
/* step1. erase H1 (0xC0000-0xFFFFF) */
FLASH.MCR.B.ERS = 1;
FLASH.HSR.B.HBSEL = 0x00000001; // select H1 block
*((unsigned int*) p_test) = 0xFFFFFFFF; // interlock write
FLASH.MCR.B.EHV = 1; // start the erase operation
while(FLASH.MCR.B.DONE == 0){}; // wait for DONE
FLASH.MCR.B.EHV = 0;
FLASH.MCR.B.ERS = 0;
/* step2. program data */
FLASH.MCR.B.PGM = 1;
*((unsigned int*)p_test) = Offset; //Is this valid?? This is my main question
// *((unsigned int*) p_test++) = data_to_be_written[0]; // first write
// *((unsigned int*) p_test++) = data_to_be_written[1]; // additional write
// *((unsigned int*) p_test++) = data_to_be_written[2]; // additional write
// *((unsigned int*) p_test) = data_to_be_written[3]; // additional write
FLASH.MCR.B.EHV = 1; //start the erase operation
while(FLASH.MCR.B.DONE == 0){}; //wait for DONE
FLASH.MCR.B.EHV = 0;
FLASH.MCR.B.PGM = 0;
}
Flash permission only constant like 0x0001?
And I adjust yout example on my code, but there're bus error too.
What I miss? T.T
I hope your help, please and thank you.
It is typical to define non-volatile data as const storage class.
I have recently shared example code for MPC5643L simple flash programming. It could help you to understand the procedure (although it is different device, principle is the same):
https://community.freescale.com/docs/DOC-101849
Pay attention to main.c file and MPC5643L_my_sections.lcf linker command file.
Hope it helps.