It is not possible to erase the MCU flash, help. :-(

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

It is not possible to erase the MCU flash, help. :-(

Jump to solution
4,702 Views
markosiponen
Contributor III

I use a MK10DN512VLL10.

I can't erase the memory of my MCU. But I can still debug the application through JTAG. I "played" with protection settings when this happened. I'm making a bootloader that I want to protect.

The flash configuration memory from 0x400 and forward is:

0x400 = FF

0x401 = FF

0x402 = FF

0x403 = FF

0x404 = FF

0x405 = FF

0x406 = FF

0x407 = FF

0x408 = FE (FPROT0) <---- The first part of the FLASH is protected. I think this prevents mass erase???

0x409 = FF (FPROT1)

0x40A = FF (FPROT2)

0x40B = FF (FPROT3)

0x40C = FA (FSEC)  

0x40D = FF (FOPT)

0x40E = FF (FEPROT)

0x40F = FF (FDPROT)

Is it possible to erase the memory in some way or do I have to replace the MCU?

0 Kudos
1 Solution
2,541 Views
markosiponen
Contributor III

I solved the problem. I selected "Connect: under Reset" and did not check the "Reset after Connect". Then I managed to erase the flash. :smileyhappy:

ok.png

View solution in original post

0 Kudos
6 Replies
2,541 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Marko:

If you see those flash values when debugging, then FSEC = 0xFA, which means that mass erase is enabled and mcu is not secured; so do not worry, your MCU is still alive :smileyhappy:.

Now the questions are: What software/hardware tools and procedure are you using to try to erase the MCU? Are you trying to program the device or just a mass erase?

Please provide more details.

Regards!
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
2,541 Views
markosiponen
Contributor III

I'm using the KEIL µVision4 .

I select Flash/Erase from the menu. It reply "Full Chip Erase Failed!"

I also tried to call a function in the code I managed to download to the MCU before it got stuck. The function is used to erase a flash sector (see code snipped below). Just before calling execute_flash_command() i changed the FTFL->FCCOB0 to 0x44 (Erase All Blocks).

Result:

FSTAT{CCIF] = 1 (the command is ready)

FSTAT[FPVIOL] = 1 (Flash Protection Violation Flag, not good)

static uint8_t erase_flash_sector(uint32_t address)

{

    uint32_t i;

 

    // Clear ACCERR & FPVIOL & RDCOLERR flag in flash status register

    FTFL->FSTAT = FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK | FTFL_FSTAT_RDCOLERR_MASK;

   

    FTFL->FCCOB0 = 9;

    FTFL->FCCOB1 = address >> 16;

    FTFL->FCCOB2 = address >> 8;

    FTFL->FCCOB3 = address;

 

   execute_flash_command();

 

    // Check error bits

    // Get flash status register value

    if(FTFL->FSTAT & (FTFL_FSTAT_ACCERR_MASK | FTFL_FSTAT_FPVIOL_MASK |  FTFL_FSTAT_RDCOLERR_MASK | FTFL_FSTAT_MGSTAT0_MASK))

    {

        // Failed

        return 0;

    }

0 Kudos
2,541 Views
mjbcswitzerland
Specialist V

Hi

This is the problem that I had. Your code can (is allowed to) set protection bits from '1' to '0' in the PROT registers but not from '0' to '1'. This means that the only way to unprotect a protected region is to change the values in the Flash configuration area in Flash and then reboot. If the first region is protected this is not possible without using the mass ersase command (can only be commanded by the debugger or EZPORT).

If you install CW you can do it with the flash utility by setting the connection setting to do a mass erase on connection.

If using Keil you can look around to see whether they have something similar. I would however ask Keil directly because they must have a method. Please report back as to what needs to be done in that environment so that it is generally known.

Regards

Mark

0 Kudos
2,542 Views
markosiponen
Contributor III

I solved the problem. I selected "Connect: under Reset" and did not check the "Reset after Connect". Then I managed to erase the flash. :smileyhappy:

ok.png

0 Kudos
2,541 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hi Markos:

The "Erase all blocks" command in code cannot be executed when one or more flash sectors are protected, so you will always have errors.

The solution is a mass-erase using an external JTAG tool or the EZPORT interface. In CodeWarrior I know about the method pointed my Mark, but I am not experienced with KEIL uVision. There should be an option to trigger a mass-erase.


Regards!
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
2,541 Views
mjbcswitzerland
Specialist V

Hi

Try the following with CW - https://community.freescale.com/thread/321396

Hopefully it has the same option with the JTAG interface you are using... I just manged to unsecure sector 0 of a KL26 with it ;-)

Regards

Mark

0 Kudos