Flash Driver is not writing into 0x80F00,801F00 etc

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

Flash Driver is not writing into 0x80F00,801F00 etc

4,249 Views
kotteeswarangs
Contributor I

Hi,

I am using K70 Microcontroller - MK70FN1MOVMJ12.

I want to write DDR to Flash. I am using Flash driver - flash_kinetis.c (I tried latest driver , but it is not writing to the flash at all, so I have used old driver -atleast it writes into flash)

If I mention my flash start address 0x8000 and the length is 256 . It is writing the all the locations(every 0x100) except

0x80F00,0x81F00,0x82F00 etc

I dont know why the flash driver is not writing to the specific location 0x80F00 (next 256 data is only 0xFFFFFFFF),0x81F00 etc (I see AccErr when I debug).

My code is this:

***********************************************************************

length = 256;

ram_data = (unsigned long*)0x70000000;

for(mn=0;mn<256;mn++)

{

         ram_data[mn] =  mn;

}    

  

length >>= 2;

      

for(original_address.complete = 0x80000;original_address.complete < 0x90000;original_address.complete = original_address.complete+0x100)

{

            write_flash_ret = WRITE_FLASH_FUNC(original_address.complete, (LWord*)ram_data, length);

}

*****************************************************************************

Please have a look on the above and let me know your response.

Thanks,

Regards,

Kotteeswaran G S

Labels (1)
0 Kudos
Reply
22 Replies

3,589 Views
Kan_Li
NXP TechSupport
NXP TechSupport

! !Hi Kotteeswaran G S,


I have tried to reproduce such issue on my TWR-K70F120M board, but my project works well on the address 0x80F00, so I suspected it might be a driver issue, and I used the flash driver from PE. Please kindly refer to the following for details.

1.png

I attached my project here, and You may try it on your board .

Hope that helps,


Have a great day,
Kan

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

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi,

Thanks for your update.

I am using code warrior, it is not understanding your project macros.

I understand the driver may have some issues,

If you have code warrior project, pls share with me.

Thanks,

Regards,

Kotteeswaran G S

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi,

OK.I understand. I opened your project in code warrior ,and it looks fine.

But I need just driver to work with my bootloader. Can you give me just pluggable driver.

When I try to add your project files to my project, it gave me lots of errors (it is not understanding PE macros)

Meanwhile , I will also try.

Thanks,

Regards,

Kotteeswaran G S

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi,

I tried to add the code in my bootloader project, but it failed.

Your project have "Generated Code" in which low level initalisation has been done,which is not underrstood by my code,and also I dont know how to add your "generated code" to my project.

Can you give just pluggable driver(flash), so  that I can add to my project and will try.

Please let me know your response.

Thanks,

Regards,

Kotteeswaran G S

0 Kudos
Reply

3,589 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi

Such kind of flash driver is available at http://cache.freescale.com/files/32bit/software/C90TFS_FLASH_DRIVER.exe , after installation, you may demo for TWr-K70 in the folder of something like "C:\Freescale\Standard Sotfware Driver v101\C90TFS\Demos\build\MK70FN1M0xxx12"

Hope that helps,


Have a great day,
Kan

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

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi,

I have used the latest driver which I got from Freescale, I have looked at swap_demo and tried to adapt my case.

So I changed the following code :

returnCode = FlashProgramPhrase(&ftfl_cfg, PFLASH_HALF1_BASE, size, PFLASH_HALF0_BASE, FlashCommandSequence);

to

returnCode = FlashProgramPhrase(&ftfl_cfg, 0x80000, 256, 0x70000000, FlashCommandSequence);

0x70000000 - RAM Location

0x80000 - Flash Location

size is 256.

I get Access Error enabled in FlashCommandSequence routine. You can see these flash driver routines which I got from the freescale site.(KINETIS_120MHZ_SC.zip)

Thanks,

Regards,

Kotteeswaran  G S

0 Kudos
Reply

3,589 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Kotteeswaran,

Have you erase the sector containing 0x80000 before programming? otherwise it would cause such issue.


Have a great day,
Kan

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

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi,

I tried to do the following:

1. I erase the block

2. I program the block.

This time FlashCommandSequence called from erase block function is failing.

Basically FlashCommandSequence is failing by returning error codes

(FTFx_ERR_ACCERR,FTFx_SSD_FSTAT_FPVIOL,FTFx_SSD_FSTAT_MGSTAT0).

But when I check the registers in the debugger, these bits are not enabled. It looks strange.

Thanks,

Regards,

Kotteeswaran G S

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi,

I am using Flash driver Which I got from Freescale (flash_kinetis.c - attached) and I have used the APIs,also attached(can_tx.c)

Please check the main(can_tx.c) function on how I am using.

My requirement is I need to copy from DDR to flash.

Just have a look on the attachment and let me know what I am using is correct, it is not working as expected.

The following observations noted:

1. It erases multiple times after /before writing

2.It is not writing into 0x80F00

3.It is writing beyond 256 long words.

Thanks,

Regards,

Kotteeswaran G S

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi Kan,

Please use the attached with the one(previous) reply - flash_kinetis,c

and sample app (Look at the main() function - can_tx.c).

Let me know whether I am doing the correct steps or not?

Thanks,

Regards,

Kotteeswaran G S

0 Kudos
Reply

3,589 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Kotteeswaran G S,

I noticed you had not put the base address to be erased at the boundary of 4KB, for example, the 4KB boundary should be at 0x80000,0x81000,0x82000, while in your code, you use 0x80E00,0x80F00 as the base address,

for(original_address.complete = 0x80E00;original_address.complete < 0x90000;original_address.complete = original_address.complete+0x100)

      {

        

          FTFL_EraseSector(original_address.complete);        

        

            write_flash_ret = WRITE_FLASH_FUNC(original_address.complete, (LWord*)ram_data, length);

          

          

            /*if(write_flash_ret == 0x3)

            {

                flash_error_addr[err_cnt] = original_address.complete;

                err_cnt++;

            }*/

  

        

      }


Have a great day,
Kan

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

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi Kan,

I have modified the code as below:

for(original_address.complete = 0x80000;original_address.complete < 0x90000;original_address.complete = original_address.complete+0x1000)

       {

           FTFL_EraseSector(original_address.complete);

       }

       for(original_address.complete = 0x80000;original_address.complete < 0x90000;original_address.complete = original_address.complete+0x100)

       {

          

           write_flash_ret = WRITE_FLASH_FUNC(original_address.complete, (LWord*)ram_data, length);

     }

This time it writes beyond 256 bytes..I dont know the reason..

Thanks,

Regards,

Kotteeswaran  G S

0 Kudos
Reply

3,589 Views
Kan_Li
NXP TechSupport
NXP TechSupport

What is the value for length? I am sorry but I didnt find any definition for it. and after I review the flash driver you provided, I found you are using the phase access method, which program the flash with 8 byte once, that is correct as the length is 256 bytes less than the sector size, but in the implemenation, the flash command is for section program, have you modified the flash driver from www.freescale.com? I think that is why you found it wrote beyond 256 bytes.

/********************************************************

* Function for Programming of one section (maximum is 2048 Bytes)

*

********************************************************/

Byte FTFL_ProgramSectionPhrases(LWord destination, LWord* pSource, LWord size)

{

    // LWord* pProgBuff = &programbuffer[0];

      LWord* pProgBuff;

      LWord my_size;

      (unsigned long*)pProgBuff = (unsigned long*)0x14000000;

    // pProgBuff = &programbuffer[0];

  // check the size of memory

      if(size >= sizeof(programbuffer))

          return FTFL_FAIL;

     

        if(destination & 0x00000003)

          return FTFL_FAIL;

     

        if(destination & 0x00000004)

        {

          if(!FTFL_ProgramLongWord(destination, *pSource++))

            return FTFL_FAIL;

          size--;

       

       

          destination += 4;

        }

        my_size = size & 0xFFFFFFFE;

   

        if(my_size)

        {

          /* preparing passing parameter to program the flash block */

          CommandObj.regsLong.fccob3210 = destination;

          CommandObj.regs.fccob0 = FTFL_PROGRAM_SECTION;

          CommandObj.regs.fccob4 = (Byte)(size >> 9);

          CommandObj.regs.fccob5 = (Byte)((size >> 1) & 0xff);

       

          destination += 4* my_size;

       

          //  copy source data to program buffer

          while(my_size--)

            *pProgBuff++ = *pSource++;

         

          //  call flash sequence

          ret_val = FTFL_FlashCommandSequence(PROGRAM_SECTION_INDEX);

          if(ret_val == 0)

            return FTFL_FAIL;

          else if(ret_val == FLASH_WRITE_ERROR)

              return FLASH_WRITE_ERROR;

          else {}

        }

         

     

     

        if(size & 0x00000001)

          if(!FTFL_ProgramLongWord(destination, *pSource))

            return FTFL_FAIL;

         

   

        return 1;

}


Have a great day,
Kan

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

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi Kan,

The value for length is 256, you can see it in can_tx.c

I havent modified the freescale code except consolidating error (which are returned from FlashCommandSequence)

My aim is copy DDR to flash. can you please tell me which function(writing to flash) I have to use, so that I can try here.

Thanks,

Regards,

Kotteeswaran  G S

0 Kudos
Reply

3,589 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Kotteeswaran  G S,

I think you may use the program phase command, shown as below:

1.png

Our released flash driver has already implemented it, you may refer to the attachment for more details.  To download the whole flash driver, please refer to the link I provided previously in this thread.


Have a great day,
Kan

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

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi Kan,

Thanks for your support.

I have downloaded the driver and integrated with my boot loader code.

I would like to know , how to use FlashProgram function, do you have any sample simple application which you can share?

Please let me know, meanwhile I will also explore.

Thanks,

Regards,

Kotteeswaran G S

0 Kudos
Reply

3,589 Views
kotteeswarangs
Contributor I

Hi Kan,

Do you have any update?

I am looking for sample application which uses FlashProgram function, if you can have and tested one,please share.

Thanks,

Regards,

Kotteeswaran  G S

0 Kudos
Reply

3,589 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi Kotteeswaran  G S,

If you have installed the driver from  http://cache.freescale.com/files/32bit/software/C90TFS_FLASH_DRIVER.exe, you may find example for flashprogram function in the demo_normal, which locates in "C:\Freescale\Standard Sotfware Driver v101\C90TFS\Demos\build\MK70FN1M0xxx12\IAR\demo_normal".

Hope that helps,


Have a great day,
Kan

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

0 Kudos
Reply

3,587 Views
kotteeswarangs
Contributor I

Hi Kan,

I have gone through the "demo_normal"and tried to simulate the same in my environment.

It is not writing into my flash, It looks very large and complex,

Can you give simple and small app, so that I can try, I have attached what I am doing in my app (same as demo_normal)

Thanks,

Regards,

Kotteeswaran  G S

0 Kudos
Reply

3,587 Views
kotteeswarangs
Contributor I

Hi Kan,

Do you have any update?

When I try to replicate what demo_normal does, either it is crashing or it gives Access Error.

You can see what I am doing from the previous update.

Please let me know is there any easy(correct) way of doing flash wirting.

Thanks,

Regards,

Kotteeswaran  G S

0 Kudos
Reply