LPC55xx (Mass) Flash erase with IAP

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC55xx (Mass) Flash erase with IAP

Jump to solution
709 Views
janpieterderuit
Contributor IV

Hi,

I'm using LPC5526 with SDK v2.8.0 with Eclipse IDE (2020-06)  (so not MCUXpresso).

I'm trying to do a runtime mass erase of the flash.

I get the mass erase working with the FLASH_Erase API, specifying the full flash area to erase.
But (obviously) the controller is not capable of doing anything afterwards.

I would like to at least do a FLASH_VerifyErase afterwards.

So I implemented a function in RAM (see https://mcu-things.com/blog/ramfunc-gcc/), calling the IAP ROM functions directly (which I figured should work):

__attribute__((long_call, noinline, section(".ramfunc"))) void MassErase(void) {
   flash_config_t flInst;
   UINT32 flashBlockBase = 0;
   UINT32 flashTotalSize = 0;

   if (FLASH_API_TREE->flash_init(&flInst) == kStatus_FLASH_Success) {

      FLASH_API_TREE->flash_get_property(&flInst, kFLASH_PropertyPflashBlockBaseAddr, &flashBlockBase);
      FLASH_API_TREE->flash_get_property(&flInst, kFLASH_PropertyPflashTotalSize, &flashTotalSize);

      if (FLASH_API_TREE->flash_erase(&flInst, flashBlockBase, flashTotalSize, kFLASH_ApiEraseKey) {
         if (FLASH_API_TREE->flash_verify_erase(&flInst, flashBlockBase, flashTotalSize) == kStatus_FLASH_Success) {
            // Mass erase successfull
         }
      }
   }
}

I verified code is running in RAM.

flash_init returns success and flash_get_property returns correct data, so ROM API calls seems to work OK.

Also flash_erase works (in the end Flash is erased), but I still get a SIGTRAP before flash_verify_erase can be executed.

Any idea what I can be doing wrong?

Labels (1)
Tags (2)
0 Kudos
1 Solution
708 Views
janpieterderuit
Contributor IV

Ah, I just tried a 'step into' the flash_erase function with the debugger, and turned up in an interrupt routine.

Disabling all interrupts fixed the issue.
I can now verify Flash erasure (and anything else) from RAM.

View solution in original post

0 Kudos
1 Reply
709 Views
janpieterderuit
Contributor IV

Ah, I just tried a 'step into' the flash_erase function with the debugger, and turned up in an interrupt routine.

Disabling all interrupts fixed the issue.
I can now verify Flash erasure (and anything else) from RAM.

0 Kudos