hi david,
suppose my code size was exceed 512kb i mean block-0 sector over then it will come to block-1 am i right?
at that time if i am writing some data to internal flash i am not able to write. when i call flashprogram API function its was hanging. am trying to write data in 0xfa000 adrress but i cant. why this things happening..?
i am using MK64FN1M0VLL12 controller. this one dnt have EEPROM also. so where can i write my data..?
if my code size less than 512kb means internal flash write/erase function was working fine. once its going more than 512kb means i am facing this problem. how to avoid that problem. and also i want to know how to write one function in particular memory location? i am waiting for your valuable reply.
thanks and regards,
sudhakar p
已解决! 转到解答。
Hello sudhakar p:
The code looks OK. The root cause is very hard to determine without debugging, so if you could attach your project for me to recreate the problem it would be very helpful.
Some things I think you can check and debug:
- g_FlashLaunchCommand must be global and should point to a VALID address in RAM space after calling RelocateFunction().
- __ram_func must be global and defined as in the flash example: uint16_t __ram_func[LAUNCH_CMD_SIZE/2];
- Try disabling all interrupts before calling FlashEraseSector(). Something like this:
#include "fsl_interrupt_manager.h"...
INT_SYS_DisableIRQGlobal();
ret = FlashEraseSector(&flashSSDConfig, destination, size, g_FlashLaunchCommand);
INT_SYS_EnableIRQGlobal();
...
If I can think of more possible causes I will let you know.
Regards!
Jorge Gonzalez
Hi Sudhakar,
Please start new post after a question has been answered with new title. This helps others to find answers.
Thank you for including the device you are working with and that you are using MQX. Please add additional information like what version of MQX and what tool set you are using.
Note that in the MQX4.2/mqx/examples/flashx has good PDF and example project for flashx_frdmk64f (and other Kinetis devices).
I gave DOC link on your other post to address moving code to specific location: https://community.freescale.com/message/530594?et=watches.email.thread#530594
Regards,
David
Hi david,
i want to implement SD card FAT file into ethernet to serial project. i dnt have any idea. i already gone through MFS example project and SDHC code. but i cant implement that code into my project. i want to write ETHERnet rxd data into SD card(with FAT system).
Previously i am nt worked on SD card. please give some idea.
regards,
sudhakar p
hi,
i am waiting for your reply.
i studied in PDF suppose you are in block-1 at that time you cant do any write/erase( i mean same block). is like that any problem i am not understand clearly. give some idea
regards,
sudhakar p
Hello sudhakar p:
- The first error I detect in your code is that you are calling RelocateFunction() for the FlashCommandSequence only inside of internal_flash_write(). I mean this call:
g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence);
This code must be called BEFORE executing any flash erase/write command, such as erasing a sector. This ensures that the flash command is launched from RAM.
- It seems you are not using the callback feature at all, so you can remove the line which installs the callback. I am referring to this code:
flashSSDConfig.CallBack = (PCALLBACK)RelocateFunction((uint32_t)__ram_for_callback , CALLBACK_SIZE , (uint32_t)callback);
And about your last question, you cannot execute code from the same flash block which you are erasing/writing. So for example in K64FN1M0 which has 2 x 512 KB Pflash blocks, you can only erase/write block 0 by launching and waiting for the command to complete from block 1, or the other way around, erasing/writing block 1 while launching/waiting from block 0. This problem is avoided if the flash command is copied to RAM, so you have freedom to erase/write any flash location in any block.
I hope this helps!
Regards!
Jorge Gonzalez
hi,
i removed following function in my code but still i cant erase data. using FlashEraseSector() API.
flashSSDConfig.CallBack = (PCALLBACK)RelocateFunction((uint32_t)__ram_for_callback , CALLBACK_SIZE , (uint32_t)callback);
actually my code was looping in this place, i dnt know why. i already put snapshot image also.
ret = pFlashCommandSequence(pSSDConfig);
could you tell what exactly problem..? my new code i attached.
void internal_flash_write()
{
uint32_t ret; /* Return code from each SSD function */
uint32_t destination; /* Address of the target location */
uint32_t size;
uint32_t end;
uint8_t securityStatus; /* Return protection status */
uint16_t number; /* Number of longword or phrase to be program or verify*/
uint32_t *p_data;
uint32_t margin_read_level; /* 0=normal, 1=user - margin read for reading 1's */
uint8_t sudha_data[200];
uint8_t sudha_data_2[10];
uint32_t i=0, FailAddr;
unsigned char *dst;
unsigned char addr;
unsigned char adj_size;
uint32_t FlashValueAtFA00=0;
uint32_t FlashValueAtFA04=0;
gCallBackCnt=0;
CACHE_DISABLE
/**************************************************************************
* Set CallBack to callback function
***************************************************************************/
g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence);
//**************************************************************************
destination = flashSSDConfig.PFlashBase + (flashSSDConfig.PFlashSize - 6*FTFx_PSECTOR_SIZE);
end = destination + 3*FTFx_PSECTOR_SIZE; // erase and program two sectors
while ((destination + (FTFx_PSECTOR_SIZE)) < end)
{
size = FTFx_PSECTOR_SIZE;
ret = FlashEraseSector(&flashSSDConfig, destination, size, g_FlashLaunchCommand);
if (FTFx_OK != ret)
{
ErrorTrap(ret);
}
// Verify section for several sector of PFLASH
number = FTFx_PSECTOR_SIZE/FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT;
for(margin_read_level = 0; margin_read_level < 0x2; margin_read_level++)
{
ret = FlashVerifySection(&flashSSDConfig, destination, number, margin_read_level, g_FlashLaunchCommand);
if (FTFx_OK != ret)
{
ErrorTrap(ret);
}
}
destination += (size);
}
destination = flashSSDConfig.PFlashBase + (flashSSDConfig.PFlashSize - 6*FTFx_PSECTOR_SIZE);
exist_params=new_params;
size=sizeof(exist_params);//size of flash program must be multiple of 8 so adjust the size
size-=8;// here i am mincing(-) dnt_remove parameter size (confg parameter) because that variable for adjusting purpose only
if((size%8)!=0)//checking size is multiple of 8 or not if not it will adjust
{
adj_size=(size%8);
adj_size=8-adj_size;
size=size+adj_size;
}
if((size%8)==0)
{
//on 21-5-15 printf("\n\r\tVALUE ADJUSTED");
}
else
{
//on 21-5-15 printf("\n\r\tADJUSTED FAILED");
}
ret = FlashProgram(&flashSSDConfig, destination, size, \
&exist_params, g_FlashLaunchCommand);
if (FTFx_OK != ret)
{
ErrorTrap(ret);
}
}
void internal_flash_read()
{
unsigned char *dst;
unsigned char *exitparam_dst;
uint32_t FlashValueAtFA00=0;
uint32_t FlashValueAtFA04=0;
uint32_t i=0;
dst=flashSSDConfig.PFlashBase + (flashSSDConfig.PFlashSize - 6*FTFx_PSECTOR_SIZE);
//dst=1040384;
//dst=0x20000000;
exitparam_dst=&exist_params;
// printf("\n\rDATA START=%d\n\r=",FlashValueAtFA00);
for (i = 0; i <sizeof(exist_params); i++)
{
*exitparam_dst=*dst;
//FlashValueAtFA00=*exitparam_dst;
//printf("%d",FlashValueAtFA00);
dst++;exitparam_dst++;
}
// printf("\n\rDATA END\n\r");
}
Hello sudhakar p:
The code looks OK. The root cause is very hard to determine without debugging, so if you could attach your project for me to recreate the problem it would be very helpful.
Some things I think you can check and debug:
- g_FlashLaunchCommand must be global and should point to a VALID address in RAM space after calling RelocateFunction().
- __ram_func must be global and defined as in the flash example: uint16_t __ram_func[LAUNCH_CMD_SIZE/2];
- Try disabling all interrupts before calling FlashEraseSector(). Something like this:
#include "fsl_interrupt_manager.h"...
INT_SYS_DisableIRQGlobal();
ret = FlashEraseSector(&flashSSDConfig, destination, size, g_FlashLaunchCommand);
INT_SYS_EnableIRQGlobal();
...
If I can think of more possible causes I will let you know.
Regards!
Jorge Gonzalez
hi jorge,
thank you very very much. i am very happy now. actually interrupt only problem.
after disabling interrupt its working fine. you are great.. once again thanks for your support , and thanks to
David also.
thanks and regards,
sudhakar p
hi jorge,
i am not getting what you are saying exactly. is i want to remove following function
g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence);
or i want to add CALLBACK function. i am not getting clearly.if you dnt mind please can you edit that code. and mark what are the changes i want to do. actually i used and modified flash demo example code only. just i added flashprogram API for flash writing.when i start this project its working fine upto 512KB(.bin code size) . now my code size was 544KB. now i am facing problem. may be its due to whatever you told block-0 and block-1 problem. i am struggling last 15days so please can you modified that code and send me.
thanks and regards,
sudhakar p
hi David,
i am using KDS2.0 and KSDK1.1.0. version. when my application code size more than 512 kb i cant write any data in internal flash memory. when i call flasherase or flashprogram API function its was hanging. mean whatever output i am expecting am not getting. if less than 512 KB i am getting whatever i am expecting output. this is my flash code.
void internal_flash_write()
{
uint32_t ret; /* Return code from each SSD function */
uint32_t destination; /* Address of the target location */
uint32_t size;
uint32_t end;
uint8_t securityStatus; /* Return protection status */
uint16_t number; /* Number of longword or phrase to be program or verify*/
uint32_t *p_data;
uint32_t margin_read_level; /* 0=normal, 1=user - margin read for reading 1's */
uint8_t sudha_data[200];
uint8_t sudha_data_2[10];
uint32_t i=0, FailAddr;
unsigned char *dst;
unsigned char addr;
unsigned char adj_size;
uint32_t FlashValueAtFA00=0;
uint32_t FlashValueAtFA04=0;
CACHE_DISABLE
/**************************************************************************
* Set CallBack to callback function
***************************************************************************/
flashSSDConfig.CallBack = (PCALLBACK)RelocateFunction((uint32_t)__ram_for_callback , CALLBACK_SIZE , (uint32_t)callback);
g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence);
//**************************************************************************
destination = flashSSDConfig.PFlashBase + (flashSSDConfig.PFlashSize - 6*FTFx_PSECTOR_SIZE);
internal_flash_erase();
exist_params=new_params;
size=sizeof(exist_params);//size of flash program must be multiple of 8 so adjust the size
size-=8;// here i am mincing(-) dnt_remove parameter size (confg parameter) because that variable for adjusting purpose only
if((size%8)!=0)//checking size is multiple of 8 or not if not it will adjust
{
adj_size=(size%8);
adj_size=8-adj_size;
size=size+adj_size;
}
ret = FlashProgram(&flashSSDConfig, destination, size, \
&exist_params, g_FlashLaunchCommand);
if (FTFx_OK != ret)
{
ErrorTrap(ret);
}
}
void internal_flash_read()
{
unsigned char *dst;
unsigned char *exitparam_dst;
uint32_t FlashValueAtFA00=0;
uint32_t FlashValueAtFA04=0;
uint32_t i=0;
dst=flashSSDConfig.PFlashBase + (flashSSDConfig.PFlashSize - 6*FTFx_PSECTOR_SIZE);
exitparam_dst=&exist_params;
for (i = 0; i <sizeof(exist_params); i++)
{
*exitparam_dst=*dst;
dst++;exitparam_dst++;
}
}
void internal_flash_erase()
{
uint32_t ret; /* Return code from each SSD function */
uint32_t destination; /* Address of the target location */
uint32_t size;
uint32_t end;
uint16_t number; /* Number of longword or phrase to be program or verify*/
uint32_t *p_data;
uint32_t margin_read_level;
//on 21-5-15 printf("\n\n\r---->Demo: Running FlashEraseSector() and FlashVerifySection()...");
//***********************************************************************
// Erase several sectors on upper pflash block where there is no code
//***********************************************************************
destination = flashSSDConfig.PFlashBase + (flashSSDConfig.PFlashSize - 6*FTFx_PSECTOR_SIZE);
end = destination + 3*FTFx_PSECTOR_SIZE; // erase and program two sectors
while ((destination + (FTFx_PSECTOR_SIZE)) < end)
{
size = FTFx_PSECTOR_SIZE;
ret = FlashEraseSector(&flashSSDConfig, destination, size, g_FlashLaunchCommand);
if (FTFx_OK != ret)
{
ErrorTrap(ret);
}
number = FTFx_PSECTOR_SIZE/FSL_FEATURE_FLASH_PFLASH_SECTION_CMD_ADDRESS_ALIGMENT;
for(margin_read_level = 0; margin_read_level < 0x2; margin_read_level++)
{
ret = FlashVerifySection(&flashSSDConfig, destination, number, margin_read_level, g_FlashLaunchCommand);
if (FTFx_OK != ret)
{
ErrorTrap(ret);
}
}
destination += (size);
}
}
Hi David,
i find exactly where my code was hanging. i added image just see and give some solution.
inside FlashEraseSector() API function one while loop there, here my code was looping.
so i debug through serial its outing only "Before flash command" its not outing "After flash command"
string. i searched that function definition but am not get anywhere. what that function will do. what is the use of that function if i comment that line
i can able to program internal flash only one time. after reset my board am getting following error
---- HALTED DUE TO FLASH ERROR! ----
above error coming only my code size exceed 512kb (.bin) file size.