Strange failure in KSDK Erase Sector function

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

Strange failure in KSDK Erase Sector function

1,520 Views
MAPC
Senior Contributor I

Hello,

 

I ran into a strange problem reported by a customer.

 

When we debug the step by step Erase Sector function, we noticed that the variable "temp" which receives several data remains "optimized out" and we don't have any access to its content.

 

Antother thing is that it runs ramdomly through the lines in a strange sequence and skips parts which should be executed.

 

We got Error "0x20" from the function but the reason for this error explained in KSDK corresponding header file is not helping at all. We still don't know how to fix it.

 

#define FTFx_ERR_ACCERR                    0x0020U

/*! @brief  Cannot change protection status

*

* Possible causes:

*

* Violates protection transition.

*

* Solution:

*

* In NVM normal mode, protection size cannot be decreased. Therefore, the only increasing

* protection size is permitted if the device is operating in this mode.

 

For a better visualization, we recorded a small video of the code debugging:

 

 

 

Attached it goes his firmware that runs in KDS 3.0 and KSDK 1.3.0 (The MCU is MK22FX512).

 

Can anybody help us with this please?

 

 

 

 

Thanks and best regards,

 

Marco Coelho

Applications Engineer

Siletec Eletronica

Original Attachment has been moved to: 2_Sensores_V00_00_00.rar

Labels (1)
12 Replies

802 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Marco Aurelio P. Coelho,

      I can't see your video, chould you please put it in the attachment?

      FTFx_ERR_ACCERR always caused by 3 codition:

1: Command not available in current mode/security

2: Program flash is selected and the address is out of program flash range

3: Flash address is not longword aligned

    I check your code, but when I build it, it has a lot of problems. It is mainly about the fsl_uart.h and fsl_lpluart.h, please check these two file source path.

   Besides, please tell me the full name of your chip, not only MK22FX512,I need know the package.

Waiting for your reply!

Jingjing

0 Kudos

802 Views
MAPC
Senior Contributor I

Hello, Dear Jingjing

I don't understand why the video doesn't show for you. I can see it here perfectly.

Anyway, the link for the video is:

KSDK "Flash Erase Sector" function strange problem - Debugging step by step in KDS - YouTube

I don't know why this errors from fsl_uart.h and fsl_lpluart.h appear to you. Have you built the KSDK (1.3.0) platform library first?

Regarding the 3 conditions you commented above, he calls "FlashGetSecurityState" before "Erase_Sector" , and it returns "FLASH_NOT_SECURE". Also, "RelocateFunction" returns a valid address inside RAM, as well as Flash destination address is inside the valid range and seems to be longword aligned.

The part used is the same as the one is mounted on FRDM-K22F kit: MK22FN512VLH12.

If you only could run and debug the customer's code, you would be able to reproduce the problem we are talking over on your side. The video can also help you see it. Please let me know if you are able to open and see the video now.

Thanks and best regards,

Marco Coelho

0 Kudos

802 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Marco Coelho,

     Actually, if you have the IAR IDE, you can use this IDE, when do step debug in the  FlashEraseSector function, it can view the local variable:

flash2.jpg

  Besides, this IDE don't have the strange sequence and skips.

You can test this project on your side: C:\Freescale\KSDK_1.3.0\examples\frdmk22f\demo_apps\flash_demo\iar

Wish it helps you!

Best Regards,

Jingjing

0 Kudos

802 Views
MAPC
Senior Contributor I

Hello, Dear Jingjing

We saw that demo project also runs ramdomly through the lines. So, that is not a bad signal.

But, we still don't understand what is causing the error.

The warning you see there refers to a folder that physically doesn't exist in his project. So, we just removed its path from ARM C Compiler Includes in Project Properties. The startup files are already present in another folder (Project Settings / Startup Code). We really don't know how that path came up.

startup_files.png

delete_startup_folder_path.png

After recompiling the project, some irrelevant warnings came up, but nothing that I believe we have to worry about:

warnings_after_recompiling.png

But we are still facing the same error and so far we don't have a clue on what is causing it. Could you please make the changes as described above? Probably you will be able to reproduce the same error (0x20) from "Erase Sector" function on your side.

Please help us!

Thanks and best regards,

Marco Coelho

Applications Engineer

Siletec Eletronica

0 Kudos

802 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Marco Coelho,

   Any updated test result from your side?

Waiting for your reply!

Have a great day,

Jingjing

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

0 Kudos

802 Views
MAPC
Senior Contributor I

Hello, Jingjing

I'm glad to tell you that after your last tips, "Erase Sector" function is working fine now. Thank you very much! But I need to ask you: Shouldn't those tips be present in "KSDK API Reference Manual" or in another KSDK manual? We really haven't found any document from Freescale mentioning this...

Two points that call our attention:

Acording to K22 reference manual, its Flash have 4K sectors. But Flash sector size is defined in "MK22F51212_features.h" and its value is 2048. Why?

pastedImage_0.png

The other point is that "CLOCK_SETUP" symbol with value 0 is not defined in Properties of "flash_demo_frdmk22f" project. Could you explain us why?

Thank you very much and best regards,

Marco Coelho

Applications Engineer

Siletec Eletronica

0 Kudos

802 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Marco Aurelio,

    That's very good to hear your flash erase is working now, actually, about the flash clock limited frequence is already given in the reference manual. The symbols defination is the experience, maybe the KDS still should be updated.

    Now answer your 2 points:

1.  I don't know which K22 reference manual you are refering, because you tell me your chip is MK22FN512VLH12, then you need to refer K22P121M120SF7RM.pdf.

Page 628, you will find that the sector size is 2KB, not 4KB, so the data is 2048.

2. You can delete your CLOCK_SETUP in the symbols, it will work ok, just use the default the internal clock.

Wish it helps you!

If you still have question, please contact with me!

Have a great day,

Jingjing

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

0 Kudos

802 Views
MAPC
Senior Contributor I

Hello, Jingjing

I got a little confused. I had refered to MK22FN1M0 and MK22FX512 reference manual, where I saw that Flash sector size is 4K. When I checked MK22FN512 reference manual, I found that, for this MCU, Flash sector size is 2K. So, there are no errors in KSDK FRDM-K22F Flash demo. I was wrong!

That makes sense, because MK22FX512 has a bigger Flash memory, since part of it is Flex Memory, and thus, has bigger sectors like MK22FN1M0, as well.

Regarding the issue with symbols, I hope that it is solved in the next KSDK version.

Everything is crystal clear now!

Thank you very much and best regards,

Marco Coelho

Applications Engineer

Siletec Eletronica

0 Kudos

802 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Marco Coelho,

  Thank you for your more detials, I can reproduce your problem on my side now.

  1: Debug in step run s ramdomly

    I think this is the KDS debug bug, I already report this problem to the KDS department, they will help to solve this KDS problem.

  2: variable output "optimized out"

    KDS engineer think this is not the bug, you can add volatile before the variable defination to solve it, eg, define temp1 as: volatile uint32_t temp1;

  3: flash sector erase error: 0x20 in FTFA_FSTAT

  I check your code, and test it carefully, at last I find it caused by the KDS option define problem, you need to delete all your old define symbol, and add it again, please configure it like this:

DEFINE.jpgDEFINE1.jpg

After the new configuration, then build it again, you will find your flash sector erase is ok.

You problem is caused by the define is invalid, then your flash clock will not correct, it will cause the flash operation error.

Attachment is my modified project, you can refer to it!

Wish it helps you!

If you still have question, please contact with me!


Have a great day,
(my name)

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

0 Kudos

802 Views
marek_neuzil
NXP Employee
NXP Employee

Hello,

I have verified the behavior of the debugger on the FRDM-K22F target board and I have found out that the "strange" behavior of the debugger is caused by the size optimization (level 4) that is defined for the FlashEraseSector() function, see below:

Definition of the FlashEraseSector() function:

uint32_t SIZE_OPTIMIZATION FlashEraseSector(PFLASH_SSD_CONFIG pSSDConfig, \
                                  uint32_t dest, \
                                  uint32_t size, \
                                  pFLASHCOMMANDSEQUENCE pFlashCommandSequence)
{
. . .

The SIZE_OPTIMIZATION macro is defined:

#if ((defined _GNUC_) && (CPU_CORE == ARM_CORTEX_M))
#define SIZE_OPTIMIZATION _attribute_((optimize("O4")))
#else
#define SIZE_OPTIMIZATION
#endif

When you define the SIZE_OPTIMIZATION macro by the following way (remove the optimization attribute from the definition):

#if ((defined _GNUC_) && (CPU_CORE == ARM_CORTEX_M))
#define SIZE_OPTIMIZATION
#else
#define SIZE_OPTIMIZATION
#endif

you can debug the code of the FlashEraseSector() without any unpredictable jumps in the code.

Best Regards,

Marek Neuzil

802 Views
MAPC
Senior Contributor I

Hello, Marek Neuzil

Thank you very much for the enlightenment on this issue. I would never find out.

Probably this optimization is for reducing code, because we usually don't need to know what is inside the function. But, especially in this case, we wanted to know what point of the function caused the error.

We really appreciated your support, Marek and Jingjing!

Best regards,

Marco Coelho

Applications Engineer

Siletec Eletronica

0 Kudos

802 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Marco Coelho,

      I can see your video now, it caused by my network limitation.

      But I still can't run your project on my side, it has a lot of complie problems, I already complie my KSDK libray.

    1: it has this warning:

Description Resource Path Location Type

Invalid project path: Include path not found (E:\KinetisCode\question\2_Sensores_V00_00_00\2_Sensores_V00_00_00\SDK\platform\devices\MK22F51212\startup). 2_Sensores_V00_00_00  pathentry Path Entry Problem

  I check your code path:2_Sensores_V00_00_00\SDK\platform\devices\MK22F51212, there has no startup folder,

  2: then I copy :C:\Freescale\KSDK_1.3.0\platform\devices\MK22F51212\startup

to your project folder, but there has a lot of errors, just like the following picture:

flash.jpg

So, I think maybe you can check your project in another computer again.

  Now I check the K22 flash code in the KSDK:C:\Freescale\KSDK_1.3.0\examples\frdmk22f\demo_apps\flash_demo\kds

  When do debug, it is really have the local variable view problem and the strange sequence problem, I will check this problem with our KDS engineer, then I will reply you again!

  But although the local variable can't be view, if you check the flash register:FCCOB0-FCCOB3, you can find the register can be write correctly, and the return ret in function FlashEraseSector is 0, it has no error. So, I think maybe you can also check this project on your side, whether it has the function problem.

Best Regards,

Jingjing

0 Kudos