Hello,
I am trying to erase the sector of 0x00980000. Unfortunately I'm unable to successfully erase any flash sector within the RWW partition 6. After failing to flash, the mcu resets when accessing memory within that sector.
I have posted my code below. The code works for erasing the sector of 0x00A00000 (which is in RWW partition 7), but doesn't work for the sector 0x00980000. I have not had any success with other sectors in partition 6 either.
I have disabled interrupts with the instruction "wrteei 0" prior to this and the code is running from RAM. Any insight would be appreciated.
volatile uint32_t startAddress = 0x00980000;
volatile uint32_t flashSector = 0x40;
C55FMC.LOCK2.R = ~flashSector; // unlock sector for erase: 1 = lock 0 = unlock
C55FMC.MCR.B.ERS = 1;
C55FMC.SEL2.R = flashSector; // select sector for erase: 1 = erasing 0 = not erasing
asm("sync");
*(uint32_t*)startAddress = 0xFFFFFFFF; // interlock write (can be an arbitrary address within the sector being erased)
asm("sync");
C55FMC.MCR.B.EHV = 1; // set high voltage to perform erase method
while(C55FMC.MCR.B.DONE == 0);
C55FMC.MCR.B.EHV = 0; // turn off high voltage
C55FMC.MCR.B.ERS = 0; // turn off erase flag
*Note: I am not servicing the watchdog as everytime i try to access the register SWT_SR (for SWT_A) I am unable to and the mcu resets. I am unsure of why this would happen as I have not experienced this in other applications. It was not an issue in erasing the block at 0x00A00000.
Thanks,
Victor
Hi Victor,
that piece of code works on my side, there's no problem.
What does it mean that the programming is failing? Is the DONE bit set? When it is set, what is the content of C55FMC_MCR register? Or is the device reset during erase operation? If yes, what is the content of Reset Status Register SIU_RSR after this reset? (please make sure you erase all flags in this register before erasing, so there's only one source of reset catched after erase is started)
When you check the content of memory after erase by debugger, what can you see? If it is full of double bit ECC errors, you should see characters like '??' or 'XX' in the memory window depending on your debugger.
I guess you don't handle Machine Check exception IVOR1, right? If core tries to access memory corrupted by double bit ECC error then this exception is triggered. If this event is not handled, the device may be reset - depending on code (or just some garbage) present on IVOR1 handler.
Are you testing the code with a debugger? Debuggers usually disable the watchdog by default, so there shouldn't be problem. Or do you enable it explicitly in your code?
And the last thing - MPC5777C is multicore device. Is the second core running? Are you sure it's not accessing the partition 6?
Regards,
Lukas