Hi,
I have new section defined in linker file
cfgdata (RW) : ORIGIN = 0x00016000, LENGTH = 0x00001000
.cfgdata :
{
. = ALIGN(4);
*(.cfgdata)
. = ALIGN (0x4);
} > cfgdata
in sourcecode:
uint8_t tmpdata[8] __attribute__((section(".cfgdata"))) ={7,6,5,4,3,2,1,0} ;
after startup I call this function:
void test_write()
{
uint8_t data[8]={0,1,2,3,4,5,6,7};
uint8_t newdata[8];
uint32_t addr=0x16000;
uint32_t ret = FLASH_DRV_Init(&Flash1_InitConfig0, &flashSSDConfig2);
ret = FLASH_DRV_EraseSector(&flashSSDConfig2, addr, 4096u);
ret = FLASH_DRV_Program(&flashSSDConfig2, addr, 8, data);
memcpy(newdata,tmpdata,8);
}
when I check memory map , I see 76543210 at addr 0x16000 at startup
when I do FLASH_DRV_EraseSector, it's still there, EraseSector function returns 0, that is success, so why is it not erased?
when I do FLASH_DRV_Program, which also returns 0/success , still old data there ..
BUT!
when I do memcpy(newdata,tmpdata,8); then I have 01234567 bytes in newdata variable ...
BUT - after program reset, I still only see old 76543210 in memory map at tmpdata location ...
When I define tmpdata without specific location (or force it into another location I have configured),
uint8_t tmpdata[8] ={7,6,5,4,3,2,1,0} ;
then erase/flash write is working fine, I can see data at 0x16000 being erased, then written
Does anybody have any idea why this is happening?
Hello Martin,
Have you tried defining the structure in that location without initializing it? I think this could be due to the interpretation the compiler is doing about initializing the structure as a dependant address global variable.
Best Regards,
Alexis Andalon
Hi Alexis,
I need it initialized, because it's part of bootloader and I need to know the data at the startup, I cannot assign them in runtime, because I will be overwriting this area by Cyclone programmer if necessary (but it should use defaults written by JTAG when flashing bootloader for the first time).
But anyway I tried it and just did
uint8_t tmpdata[8] __attribute__((section(".cfgdata"))) ;
and in main()
tmpdata[0]=7;
tmpdata[1]=6;
tmpdata[2]=5;
tmpdata[3]=4;
tmpdata[4]=3;
tmpdata[5]=2;
tmpdata[6]=1;
tmpdata[7]=0;
but it crashes (jumps into defaultISR) on the second line (because I am trying to write into flash area, not ram may be)
Still I don't understand what compiler has to do with MCU instruction for erasing flash/writing phrase into flash. This was working fine on MCF51JM.
Hello Martin,
Did you try using the flash write command instead of writing directly to the array?
Best Regards,
Alexis Andalon
Hi Alexis,
it's the same as at the beginig - FLASH_DRV_EraseSector returns 0, FLASH_DRV_Program returns 0, but flash is not erased nor written.
BTW: I should have written, that I am using J-Link EDU
Because now I also tried PEmicro Cyclone FX and it seems to be working fine ... so much time wasted because of that stupid J-Link EDU