Erase flash

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User3847
Level 3
Level 3
Hello there,

I am working on a XMC bootloader and I am having problems with the FLASH002 app. The thing is, I am trying to erase the flash entirely, then validate it has been flashed and then flash new contents. When I use the FLASH002 app to erase the flash it returns DAVEApp_SUCCESS but when later I try reading the flash to see the contents they are intact. I have not configured any UCB or protection whatsoever. Has anyone experienced something similar? Must something else be done for this to work?

See the Erase and VerifyErase code attached.


bool EraseFlash()
{
status_t status = DAVEApp_SUCCESS;
status = Flash002_EraseSector(FLASH002_SECTOR0_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR1_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR2_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR3_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR4_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR5_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR6_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR7_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR8_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR9_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR10_BASE);
if(status != DAVEApp_SUCCESS)
return false;
status = Flash002_EraseSector(FLASH002_SECTOR11_BASE);
if(status != DAVEApp_SUCCESS)
return false;
return true;
}

bool VerifyEraseFlash()
{
uint32_t* address = FLASH002_SECTOR0_BASE;
while(address < LAST_REG_ADDRESS)
{
if(*address != 0x00000000)
return false;
address++;
}
return true;
}
0 Likes
12 Replies
User7921
Level 3
Level 3
Hi,

erasing the flash yields to a value of 0xFFFFFFFF in all locations, not to 0x00000000.

I'm using the Flash003 app to have a small E²Prom-like area and it works fine.
I'm using the Flash003_ErasePage() function which erases 16 blocks (256 bytes).

Michael
0 Likes
Not applicable
Hi Michael,

I think sblanco is using XMC4000 device as he is using FLASH002 app.
Erased flash in XMC4000 should be 0x00000000.

For you is XMC1000 device which is using FLASH003 App.
For XMC1000 device, the erased flash is 0xFFFFFFFF.

rgds,
Rou
0 Likes
Not applicable
Hi,

Rou is right, the erase value for XMC4000 flash is 0x00000000 and for XMC1000 is 0xFFFFFFFF.

sblanco,

Are you trying to erase all the flash sector? that will include your 'EraseFlash' and 'VerifyEraseFlash' code as well..
Is that really want you intended?
Maybe you can try to erase with one sector which is not your application code sector and see whether it works for you or not.
For me, I have tested on both AA step and AB step devices, all are working fine.
0 Likes
User3847
Level 3
Level 3
Hi Jackson,

My bootloader code is running from PSRAM so I should have no problem erasing everything. The problem is, my EraseFlash function returns OK, but the first check I do in VerifyEraseFlash fails as the flash is intact. I am accesing the non-cacheable address space so I think that should be working.

Is there any default protection or anything? I call FLASH002_Init before doing all this and I have no interrupts set up for it.

Best regards,
0 Likes
lock attach
Attachments are accessible only for community members.
User3847
Level 3
Level 3
Any ideas? I am trying different things to no avail. I am using step AA (from back when XMC was being released), the chip markings say:

AA13 EES
ZA211002R03

Can it be chip related? J-Link debugger related? The most strange thing is that the Flash erase cycles take reasonable time (so the flash module is busy) and returns success (no error flag), which should mean the flash module is doing the job. I am a bit lost here, so I would appreciate help.

Find attached the sources I am using to test (I am building with scons, I left the config there just in case)



Best regards,
0 Likes
User3847
Level 3
Level 3
Come on, can someone help me with this? Thanks
0 Likes
Not applicable
Hi sblanco,

From your erase and verify code, I see nothing wrong there.
Most probably is due to the integration of the whole application that fails the erase operation.
From your code, I can see that you are running on RTOS, so I don't think you have the whole RTOS code running on SRAM don't you?
And if you running on RTOS, meaning the kernel would run on other task when the scheduler is time out.
But during the flash been erase, the whole flash is inaccessible.
So, I'm not sure if this does affect on the flash operation or not..

Anyway, I would advise you try to erase just on one sector (let's say sector 11) and see if the erase is successful or not.
0 Likes
User3847
Level 3
Level 3
Dear Jackson,

The code is not what it seems, if you look more closely you'll see that the RTOS doesn't get anywhere near starting. The modified startup file does the following:

* Copies to RAM the bootloader and needed DAVE functions
* Copies DATA section
* Clears BSS sections
* Remaps vector table, updates system clock, libc_init_array
* Calls bootloader
* Reset stack pointer and jump to main

So main is never executed in the example.

I agree it seems it must be a problem of how I am arriving to the bootloader, but can't see what as all the needed code is there.

I will try erasing from main program one high sector, but even if it works, I still don't know what should I do with this problem, as what I need is to do a bootloader in RAM.

Best regards,
0 Likes
User3847
Level 3
Level 3
The problem is related to a custom section that goes at the end of flash.

.last_reg ABSOLUTE(0x080FFF00) : AT(0x0c0FFF00)
{
KEEP(*(.last_reg))
} > FLASH_1_cached

This section will have just an integer constant:

#define MAGIC_WORD_LAST_REG 0xAA551234
const uint32_t __attribute__((section(".last_reg"))) f_last_reg = MAGIC_WORD_LAST_REG;

I do this so I can check whether the firmware has been fully flashed or not.

Checking the map file:

.last_reg 0x080fff00 0x4 load address 0x0c0fff00
*(.last_reg)
.last_reg 0x080fff00 0x4 Debug/obj/src/bootloader/bootloader.o
0x080fff00 f_last_reg

.rel.dyn 0x080fff04 0x0 load address 0x0c0fff04
.rel.iplt 0x00000000 0x0 Debug/obj/src/main.o

I see those relocation sections (well, it is not like my code has anything relocatable and I compile and link using -fno-pic).

If I just get the section definition out of the linker script the FLASH002 functions work, and I get in the map file:

.last_reg 0x00000000 0x4 Debug/obj/src/bootloader/bootloader.o
...
.rel.dyn 0x080057e4 0x0 load address 0x0c0057e4
.rel.iplt 0x00000000 0x0 Debug/obj/src/main.o
0x080057f0 . = ALIGN (0x10)
0x0c0057f0 eROData = (. | 0x4000000)

The other differences are in debug_aranges, debug_macro, etc.

I don't see why that should be a problem, but I am no expert in ARM binary linking either way.

Anyone has any idea why this happens and how can I keep my custom section without interfering?

Best regards,
0 Likes
User3847
Level 3
Level 3
Anyone? How can I put some data in an arbitrary address in flash without breaking FLASH002?

Thanks
0 Likes
Not applicable
Hi sblanco,

What do you mean by arbitrary address?
0 Likes
User3847
Level 3
Level 3
Hello Jackson,

What I mean is I want to have two const variables (a version string and an special integer) in a fixed address in FLASH, so they can be checked the same way for any firmware version. I like the special string at the end of flash so that when I erase the flash it gets erased and then I know the board needs flashing.

My code fails when I put this special string in the flash end:

.last_reg ABSOLUTE(0x080FFF00) : AT(0x0c0FFF00)
{
KEEP(*(.last_reg))
} > FLASH_1_cached

#define MAGIC_WORD_LAST_REG 0xAA551234
const uint32_t __attribute__((section(".last_reg"))) f_last_reg = MAGIC_WORD_LAST_REG;

Just by commenting out the linker definition for .last_reg it works ok, if I put it the FLASH002 app breaks.
0 Likes