K21 write a sector return FSTAT[ACCERR]=1

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

K21 write a sector return FSTAT[ACCERR]=1

667 Views
Mike1981
Contributor I

Hello,

I'm trying to porting a firmware from K60FN1M0VLQ15 to K21FN1M0VLQ12.

Everything works fine (USB, SD, flash commands, ...) less Program section command (FCMD=0x0B) in my bootloader program.

All FPROT registers are to 0xFF, flexram is accessible, Backdoor key access is disabled, Mass erase is enabled, Freescale factory access granted, MCU security status is unsecure and program flash swap is disabled.

Lunch Erase Flash Block (FCMD=0x08) erase correctly the sector, then I write 0x1000 bytes in flexram (from address 0x14000000), then I lunch Program section command but it returns me FSTAT[ACCERR]=1.

I temporary solved the issue using lunching the Program Phrase (FCMD=0x07), that works correctly, instead the Program section command.

Anyone know why the Program section command is not working me correctly?

 

Thanks in advance for availability,

Michele

Labels (1)
Tags (3)
0 Kudos
3 Replies

660 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @Mike1981 

I hope you are doing well!

According to the user manual there are various things that cold have went wrong

diego_charles_1-1627081528418.png

As per your description , we may eliminate current mode security  or invalid  flash address error conditions.

The MK60FN does not have MCUXpresso SDK drivers. In your porting task to the MK21 are you using MCUxpresso SDK drivers for Flash and FTFE, or KSDK ones ?

Is this happening with other  Flash blocks ? Which flash sector are you trying to program?

We have a pflash example for the TWR-21 (MK21FN1M0Axxx12) , in that example the function FLASH_Program() is used in particular, it may help you as a reference for your porting.

All the best, 

Diego.

0 Kudos

644 Views
Mike1981
Contributor I

Thank you Diego for your reply.

 

I've already checked the various things that could have gone wrong, described in the user manual, but without success.

I was trying to program sectors from 0x5000 to 0x0069-0000.

I already fail on the first sector to program, at 0x5000.

I setted FTFE_FCCOB4 register to 1 and FTFE_FCCOB5 to 0 (I also tried to set FTFE_FCCOB4 register to 0 and FTFE_FCCOB5 to 0x80 like k60), but it didn't work.

The FlexRAM is set to work as a traditional RAM. I can use it correctly, I still use it for the temporary solution with Program Phrase command.

I can't find the example that you mentioned on the TWR-21, but I'm not using a MK21FN1M0-A-xxx12.

For my port, I don't use any program, I only based on iar example for kinetis k21 for the drivers.

 

Thank you for your help,

Michele

634 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @Mike1981 

Thank you for your reply as well.

Could you try to write only up to 1KB with program section command?

According to below snaps from the MK21  RM, the FlexRAM  section program buffer will hold up to 1 KB of data for the program section command. I think that you mentioned that you are trying to write 0x1000 bytes , or 4KB. 

 

diego_charles_6-1627338328322.png

diego_charles_5-1627338295785.png

I am mentioning this , as I  have been running the MCUXpresso SDK pflash demo  with specific modifications to pflash.c on my K64F: (as I do not have any MK2x board with me during this Corona virus lock down) 

1 Use your address of 0x5000

diego_charles_0-1627338043461.png

2 Use the FLASH  function for  program section command, not program  FLASH_Program. If we leave that last one, we can program 4KB. If I am not wrong , that function  programs each 8 bytes, using like your current workarround, the  program phase command.

diego_charles_1-1627338119211.png

3 Play with the length of the dummy buffer that the demo uses for writing in to the flash. As it is expressed in 4 byte words, that 256 corresponds to 1KB.

diego_charles_7-1627338887116.png

Below , find my relevant test results:

A) Using  1 KB  for buffer length,  no errors, see console results:

diego_charles_8-1627339530657.png

B) Using more than 1 KB, or 4 KB , we have flash errors

diego_charles_10-1627339848668.png

In particular the below  error corresponds to when I used a buffer with a length of 4 Kb.

The FTFx_FSTAT_ACCERR_MASK error is raised.

diego_charles_0-1627341040101.png

Therefore , my recommendation is to test program section command for 1 KB and check our MCUxpresso SDK pflash examples and use latest MK21 flash driver. This can be found at MCUxpresso SDK builder. I have mentioned the TWR-K21 Plash example as uses a similar MK21.

Let me know your results

Diego.

 

 

 

0 Kudos