Reboot when try to write flash

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

Reboot when try to write flash

908 Views
denismatt
Contributor I

Hi all, im working with the Kinetis Design Studio, Version: 3.2.0. Now im programming a routine that erases and writes Flash. I took some example Code and that works fine when i run it by singlestep "step into (F5)".

But when i let run it normally the MCU reboots suddenly as when he reaches the execute command:

FTFA_FSTAT = 0x80;      // write the CCIF Bit to clear it and start the command

All associated Interrupts are switched off. What is different in the singlestep mode ?

Labels (1)
Tags (2)
0 Kudos
4 Replies

535 Views
josephwalsh
Contributor I

I know this is an old thread, but for anyone stumbling onto this one, I encountered a similar issue.  I happen to be using an MKV30 bare chip vs a dev kit, but the issue is the same.  What I found, and is stated in the manual, but not obvious due to teh relative location in the manual of this information, is that flash access is not allowed in HSRUN mode, or VLP mode.  In the case of HSRUN mode, an ACCERR error will be flagged in FSTAT register, where in VLP mode, flash commands are ignored.  I found in HSRUN mode, with the debugger attached, I do indeed trigger resets as a result of the Flash Access Error (ACCERR).  I hope this might help others.

JW

0 Kudos

535 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Denis,

Which board or chip ?

Have you test the demo code or a simple project ?

If still have the error , please share the project you test .

BR

ALice

0 Kudos

535 Views
denismatt
Contributor I

Hi Alice,

i tought that may be a general problem, so i didnt attach many details.

Curious, in singlestep mode it works fine. It seems to be a conflict, maybe the MCU try to read the next command while the flash write command is still running. I dont know if so, but the Flowchart in the Reference Manual suggest to check the CCIF Bit to check the command is finished. If not two actions at same time are running, the next command will be done after the flash command is done and we not have to check the CCIF Bit.

Error bits i cannot readout, because the MCU reboots directly when it should execute the command.

To my setup: I have a board, but there is another MCU implemented as i wants to work with. So i attached a MKV10Z32VLC7 directly to the NXP LPC-Link 2 Programmer and like to program baremetal. I use the "KV10 Sub-Family Reference Manual" Document Number: KV10P48M75RM. I already programmed the clock, interrupts, PWM, UART..

I also looked into the sample code of "SDK_2.2_MKV10Z32xxx7" and others. But in this case i didnt found anything about this theme. The code in this examples is automatic generated and often too complicated to read for me. Beseides, i like to change it for my special requirements.

Here my nonworking code to write flash:

int main(void)
{
    SetClock75MHz();           // Sets the system Clock to 75 MHz and the Bus Clock/Flash Clock to 25MHz

    FTFA_FCNFG = 0x00;    // Command Complete Interrupt and Read Collision Error Interrupt off

    while(((FTFA_FSTAT & 0x10) | (FTFA_FSTAT & 0x20)) > 0){}    // check on ACCERR und FPVIOL

    //SIM_SCGC6 |= 0x00000001;        // Clockgate enable, but not needed

    //       Erase
    while((FTFA_FSTAT & 0x80) == 0){}    // check CCIF Bit, whether a command is still running
    FTFA_FSTAT = 0x70;                    // delete all old Errorbits (also 0x30 may be correct)
    FTFA_FCCOB0 = 0x09;                    //load "Erase Flash Sector" Command
    FTFA_FCCOB1 = 0x00;                    // Adresse High Byte
    FTFA_FCCOB2 = 0x7C;                    // Adresse, Middle Byte
    FTFA_FCCOB3 = 0x00;                    // Adresse Low Byte (must be longword aligned)
    FTFA_FSTAT = 0x80;                    // write CCIF Bit to clear it and execute the command

    //while((FTFA_FSTAT & 0x80) != 0){Wait(5);}    // from a forum, its needly ?

    while((FTFA_FSTAT & 0x80) == 0){}    // check CCIF Bit

    //        Write
    while((FTFA_FSTAT & 0x80) == 0){}    // check CCIF Bit, whether a command is still running
    FTFA_FSTAT = 0x70;                          // delete all old Errorbits
    FTFA_FCCOB0 = 0x06;                    // load "Program Longword" Command
    FTFA_FCCOB1 = 0x00;                    // Adresse High Byte
    FTFA_FCCOB2 = 0x7C;                    // Adresse, Middle Byte
    FTFA_FCCOB3 = 0x00;                    // Adresse Low Byte (must be longword aligned)
    FTFA_FCCOB4 = 0xAB;                    // load 4. Byte
    FTFA_FCCOB5 = 0xCD;                    // load 3. Byte
    FTFA_FCCOB6 = 0xEF;                    // load 2. Byte
    FTFA_FCCOB7 = 0x01;                    // load 1. Byte
    FTFA_FSTAT = 0x80;                    // write CCIF Bit to clear it and execute the command
    while((FTFA_FSTAT & 0x80) == 0){}    // check CCIF Bit

I also tried with the associated enabled interrupt (and an IRQ Handler Routine):

NVIC_EnableIRQ(5);                    // enable Interrupt Vektor
FTFA_FCNFG = 0x80;                    // Command Complete Interrupt                 

0 Kudos

535 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Denis,

- Please first run the flash demo under SDKv2.2 to check whether can work well.

If can't whether can change another debug mode to run.

If it work well, please refer to the code to check your code.

- There is FLASH driver Search Results: c90tfs_flash_driver 

pastedImage_4.png

it includes flash demo about MKV10Z32xxx4, (under IAR IDE), you can refer to the code to check your code too.

pastedImage_5.png

- For I will have holiday from 5.27 to 5.28 , after I come to work , if you still have question about this , I will continue

help .

BR

Alice

0 Kudos