LPC FLASH CLOCK

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

LPC FLASH CLOCK

911 Views
liujs1
Contributor I

my device is lpc54102,system clock is 100M,FLASHTIM is 0x05,I use flash IAP like this :FLASHIAP_ErasePage(start_addr >> 8, end_addr >> 8, 24000000u);fast than FLASHIAP_ErasePage(start_addr >> 8, end_addr >> 8, SystemCoreClock); SystemCoreClock is 100M;Why is this?

0 Kudos
6 Replies

650 Views
jeremyzhou
NXP Employee
NXP Employee

Hi liu js1,

Thank you for your interest in NXP Semiconductor products and 
the opportunity to serve you.
I don't think the format of Param2 is correct, please try again.
pastedImage_1.png

Have a great day,
TIC

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

0 Kudos

650 Views
liujs1
Contributor I

The clock will be converted to the correct format,this is the function code is:

status_t FLASHIAP_ErasePage(uint32_t startPage, uint32_t endPage, uint32_t systemCoreClock)
{
uint32_t command[5], result[4];

command[0] = kIapCmd_FLASHIAP_ErasePage;
command[1] = startPage;
command[2] = endPage;
command[3] = systemCoreClock / HZ_TO_KHZ_DIV;
iap_entry(command, result);

return translate_iap_status(result[0]);

}

HZ_TO_KHZ_DIV is 1000

0 Kudos

650 Views
jeremyzhou
NXP Employee
NXP Employee

Hi liu js,

Thanks for your reply.

I was wondering if you can illustrates testing steps and result, as it can help me to figure out this issue.
Have a great day,
TIC

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

0 Kudos

650 Views
liujs1
Contributor I

I have 2K data to be stored in flash,address is 0x50000,When the data changes, erase the existing data and store the new data. The system clock is always 100M and FLASHTIM is always 0x05.At first, I used 100M to erase&store data,Other modules are always waiting for time to go out of time.So I want to shorten this processing time.when  I change FLASHIAP_ErasePage(start_addr >> 8, end_addr >> 8, 100000000u) to FLASHIAP_ErasePage(start_addr >> 8, end_addr >> 8, 24000000u);,Other modules can wait for the correct results within the specified time。I don't know why.

0 Kudos

650 Views
jeremyzhou
NXP Employee
NXP Employee

Hi liu js,

Thanks for your reply.

According to your testing, how long does it spend when Param2 is 100 MHZ and 24 MHz respectively on MCUXpresso LPC54102 board?
Have a great day,
TIC

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

0 Kudos

650 Views
liujs1
Contributor I

When called function "int updateTempleteToFlash",erase flash "void EraseFlash(unsigned int start_addr, unsigned int end_addr)" use 24000000u,The return result is faster than use SystemCoreClock(100M),sorry,I can't provide accurate running time。

The code is as follows:

void EraseFlash(unsigned int start_addr, unsigned int end_addr)
{
unsigned int u32irq;

if(start_addr > end_addr) return;
u32irq = DisableGlobalIRQ();
FLASHIAP_PrepareSectorForWrite((start_addr >> 15), (end_addr >> 15));
//FLASHIAP_ErasePage(start_addr >> 8, end_addr >> 8, SystemCoreClock);
FLASHIAP_ErasePage(start_addr >> 8, end_addr >> 8, 24000000u);
EnableGlobalIRQ(u32irq);
}

void deleteTemplate(const unsigned char index)
{
WWDT_Refresh(WWDT);
EraseFlash(Template_addr_index_buffer(index), (Template_addr_index_buffer(index) + TEMPLATE_SIZE -1));
}


int ProgramToFlash1(unsigned int addr, const unsigned char *buffer, const unsigned int num)
{
unsigned int temp_addr, start_sector, end_sector;
unsigned char *temp_pointer;
// unsigned int u32irq;
int status;

temp_pointer = (unsigned char *)buffer;
temp_addr = addr;
__ASM("CPSID I");

// u32irq = DisableGlobalIRQ();
while(temp_addr < addr + num)
{
start_sector = temp_addr >> 15;
end_sector = (temp_addr + 1024) >> 15;
FLASHIAP_PrepareSectorForWrite(start_sector, end_sector);
status = FLASHIAP_CopyRamToFlash(temp_addr, (unsigned int*)temp_pointer, 1024, SystemCoreClock);
if(status != kStatus_FLASHIAP_Success)
{
debug_printf("IAP error\n");
return -1;
}
temp_addr += 1024;
temp_pointer += 1024;
}
__ASM("CPSIE I");
// EnableGlobalIRQ(u32irq);e
debug_printf("IAP ok\n");
return 0;
}

unsigned char u8temp[9];

int updateTempleteToFlash(const unsigned char index, const BL_TEMPLATE *template_pointer)
{
unsigned int u32temp;
unsigned int i;
unsigned char *p, *p_flash;

u32temp = *((unsigned int*)(Template_addr_index_buffer(index) + TEMPLATE_FLAG_OFFSET)); // get the flash flag
if(0xffffffff != u32temp)
{
debug_printf("template have in\n");
deleteTemplate(index);
//return -1;
}

u32temp = template_pointer -> templateSize;
if(u32temp > (TEMPLATE_SIZE - TEMPLATE_DATA_OFFSET))
{
debug_printf("template too large\n");
return -1;
}
p = 0;
p = malloc(TEMPLATE_SIZE);
if(0 == p)
{
debug_printf("store malloc error\n");
return -1;
}

// for(i = 0; i < TEMPLATE_SIZE; i++)
// {
// p[i] = 0;
// }

u32temp = TEMPLATE_FLAG; // store template flag
p[0] = u32temp & 0xff;
p[1] = (u32temp >> 8) & 0xff;
p[2] = (u32temp >> 16) & 0xff;
p[3] = (u32temp >> 24) & 0xff;

u32temp = template_pointer -> templateSize; // store template size
p[4] = u32temp & 0xff;
p[5] = (u32temp >> 8) & 0xff;
p[6] = (u32temp >> 16) & 0xff;
p[7] = (u32temp >> 24) & 0xff;

p[8] = template_pointer -> templateType; // store template type

memcpy(&p[TEMPLATE_DATA_OFFSET], template_pointer -> pTemplateData, template_pointer -> templateSize); // store template data

for(i = 0; i < template_pointer -> templateSize; i++)
{
if(template_pointer -> pTemplateData[i] != p[TEMPLATE_DATA_OFFSET + i])
{
debug_printf("*****not match ****\n");
free(p);
return -1;
}
}
debug_printf("begin to store\n");

u32temp = template_pointer -> templateSize + TEMPLATE_DATA_OFFSET;
ProgramToFlash1(Template_addr_index_buffer(index), p, u32temp);
p_flash = (unsigned char *)Template_addr_index_buffer(index);

for(i = 0; i < u32temp; i++)
{
if(p_flash[i] != p[i])
{
debug_printf("flash check noce error\n");
ProgramToFlash1(Template_addr_index_buffer(index), p, u32temp);
for(i = 0; i < u32temp; i++)
{
if(p_flash[i] != p[i])
{
free(p);
deleteTemplate(index);
debug_printf("flash check twice error and delete\n");
return -1;
}
}
}
}
free(p);
return 0;
}

0 Kudos