<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックLPC4357 fw upgrade</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC4357-fw-upgrade/m-p/555742#M15001</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by pgeloso on Thu Jun 11 06:56:49 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;


Hi,
I'm trying to run a m4 firmware upgrade code using LPC4357, but as soon as I erase sector 0, the code halts.
- I'm not using interrupts
- I've left 32Byte of stack offset. ... MCU Linker -&amp;gt; Target -&amp;gt; stack offest = 32
- I placed routines into RAM
- I copied the firmware that will upgrade the m4 into a free sector of Flash bank A then, to upgrade the firmware, I simply copy these sectors into sectors starting from 0 

Am I missing something else?

Probably I'm not correctly using the instructions to place routines into RAM.
I'm attaching parts of the code:
could you please double check?
Any suggestions?

Thank you
Pietro


int main(void) {
&amp;nbsp;&amp;nbsp; uint8_t result8=0;

&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t (*longfunc)(void) = &amp;amp;ram_copy_fw_upgrade;

&amp;nbsp;&amp;nbsp;&amp;nbsp; SystemCoreClockUpdate();
&amp;nbsp;&amp;nbsp;&amp;nbsp; Board_UART_Init(0);//needed, or it will not compile

&amp;nbsp;&amp;nbsp;&amp;nbsp; Chip_IAP_Initialise();//important! Or iap will not work!

&amp;nbsp;&amp;nbsp; result8=(*longfunc)();// routine that runs from RAM!


&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1) {

&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0 ;
}


#define IAP_INIT_CMD 49

void Chip_IAP_Initialise(void)
{
uint32_t command[5], result[4];

command[0] = IAP_INIT_CMD;
iap_entry(command, result);
}

__RAMFUNC(RAM) uint8_t ram_Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
{
uint32_t command[5], result[4];

command[0] = IAP_PREWRRITE_CMD;
command[1] = strSector;
command[2] = endSector;
command[3] = flashBank;
iap_entry(command, result);

return result[0];
}

__RAMFUNC(RAM) uint8_t ram_Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt)
{
uint32_t command[5], result[4];

command[0] = IAP_WRISECTOR_CMD;
command[1] = dstAdd;
command[2] = (uint32_t) srcAdd;
command[3] = byteswrt;
command[4] = SystemCoreClock / 1000;
iap_entry(command, result);

return result[0];
}

__RAMFUNC(RAM) uint8_t ram_Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
{
uint32_t command[5], result[4];

command[0] = IAP_ERSSECTOR_CMD;
command[1] = strSector;
command[2] = endSector;
command[3] = SystemCoreClock / 1000;
command[4] = flashBank;
iap_entry(command, result);

return result[0];
}


__RAMFUNC(RAM) uint8_t ram_copy_fw_upgrade(void){
//routine placed in ram that uses routines placed in ram
//In a previous run I copied blinky.h data into sector STARTING_SECTOR_N=8
//Now I copy flash sector 8 into sector 0
uint32_t fw_lenght,sector_address;
int i;
uint8_t result8;

uint32_t n_sector=0;//we start writing data in this sector

uint32_t *read_address=(uint32_t *)sector_banka_start_map[STARTING_SECTOR_N];//leggo da qui

/// pointers to call routines placed into RAM
uint8_t (*longfunc_prepare)(uint32_t strSector, uint32_t endSector, uint8_t flashBank) = &amp;amp;ram_Chip_IAP_PreSectorForReadWrite;
uint8_t (*longfunc_copy)(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt) = &amp;amp;ram_Chip_IAP_CopyRamToFlash;
uint8_t (*longfunc_erase)(uint32_t strSector, uint32_t endSector, uint8_t flashBank) = &amp;amp;ram_Chip_IAP_EraseSector;

 __disable_irq();

sector_address=sector_banka_start_map[n_sector];
result8=(*longfunc_prepare)(n_sector, n_sector, 0);//prepare..Flash Bank A
result8 +=(*longfunc_erase)(n_sector, n_sector, 0);//erase&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; ---------- HERE THE PROGRAM HALTS -----------

 fw_lenght=12988;//sizeof(new_firmware);

 while(fw_lenght&amp;gt;0){

for(i=0;i&amp;lt;FLASH_DWORD_BLOCK;i++){ //copy sectors
flash_data&lt;I&gt;=*read_address;&amp;nbsp; 
fw_lenght -=4;
read_address++;
if(!(fw_lenght&amp;gt;0)){//last_iteration?
&amp;nbsp;&amp;nbsp; for(i=i+1;i&amp;lt;FLASH_DWORD_BLOCK;i++) flash_data&lt;I&gt;=0xFFFFFFFF;// fill with erased data
break;//fine del ciclo for
}
}

//storing data into flash
result8+=(*longfunc_prepare)(n_sector, n_sector, 0);//prepare
result8 +=(*longfunc_copy)(sector_address, flash_data, FLASH_BLOCK);//erase

//update flash address
sector_address +=FLASH_BLOCK;
if(!(sector_address&amp;lt;sector_banka_end_map[n_sector])){//if needed, change sector
n_sector++; //new sector
if(!(n_sector&amp;lt;MAX_FLASH_SECTOR)){
//fail !!
}
sector_address=sector_banka_start_map[n_sector];//new address
//nuovo settore:
result8+=(*longfunc_prepare)(n_sector, n_sector, 0);//prepare
result8 +=(*longfunc_erase)(n_sector, n_sector, 0);//erase
}
 }

 __enable_irq();

 return result8;
}




&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Jun 2016 18:39:01 GMT</pubDate>
    <dc:creator>lpcware</dc:creator>
    <dc:date>2016-06-15T18:39:01Z</dc:date>
    <item>
      <title>LPC4357 fw upgrade</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/LPC4357-fw-upgrade/m-p/555742#M15001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;STRONG&gt;Content originally posted in LPCWare by pgeloso on Thu Jun 11 06:56:49 MST 2015&lt;/STRONG&gt;&lt;BR /&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD bgcolor="#cacaca"&gt; &lt;PRE&gt;


Hi,
I'm trying to run a m4 firmware upgrade code using LPC4357, but as soon as I erase sector 0, the code halts.
- I'm not using interrupts
- I've left 32Byte of stack offset. ... MCU Linker -&amp;gt; Target -&amp;gt; stack offest = 32
- I placed routines into RAM
- I copied the firmware that will upgrade the m4 into a free sector of Flash bank A then, to upgrade the firmware, I simply copy these sectors into sectors starting from 0 

Am I missing something else?

Probably I'm not correctly using the instructions to place routines into RAM.
I'm attaching parts of the code:
could you please double check?
Any suggestions?

Thank you
Pietro


int main(void) {
&amp;nbsp;&amp;nbsp; uint8_t result8=0;

&amp;nbsp;&amp;nbsp;&amp;nbsp; uint8_t (*longfunc)(void) = &amp;amp;ram_copy_fw_upgrade;

&amp;nbsp;&amp;nbsp;&amp;nbsp; SystemCoreClockUpdate();
&amp;nbsp;&amp;nbsp;&amp;nbsp; Board_UART_Init(0);//needed, or it will not compile

&amp;nbsp;&amp;nbsp;&amp;nbsp; Chip_IAP_Initialise();//important! Or iap will not work!

&amp;nbsp;&amp;nbsp; result8=(*longfunc)();// routine that runs from RAM!


&amp;nbsp;&amp;nbsp;&amp;nbsp; while(1) {

&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0 ;
}


#define IAP_INIT_CMD 49

void Chip_IAP_Initialise(void)
{
uint32_t command[5], result[4];

command[0] = IAP_INIT_CMD;
iap_entry(command, result);
}

__RAMFUNC(RAM) uint8_t ram_Chip_IAP_PreSectorForReadWrite(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
{
uint32_t command[5], result[4];

command[0] = IAP_PREWRRITE_CMD;
command[1] = strSector;
command[2] = endSector;
command[3] = flashBank;
iap_entry(command, result);

return result[0];
}

__RAMFUNC(RAM) uint8_t ram_Chip_IAP_CopyRamToFlash(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt)
{
uint32_t command[5], result[4];

command[0] = IAP_WRISECTOR_CMD;
command[1] = dstAdd;
command[2] = (uint32_t) srcAdd;
command[3] = byteswrt;
command[4] = SystemCoreClock / 1000;
iap_entry(command, result);

return result[0];
}

__RAMFUNC(RAM) uint8_t ram_Chip_IAP_EraseSector(uint32_t strSector, uint32_t endSector, uint8_t flashBank)
{
uint32_t command[5], result[4];

command[0] = IAP_ERSSECTOR_CMD;
command[1] = strSector;
command[2] = endSector;
command[3] = SystemCoreClock / 1000;
command[4] = flashBank;
iap_entry(command, result);

return result[0];
}


__RAMFUNC(RAM) uint8_t ram_copy_fw_upgrade(void){
//routine placed in ram that uses routines placed in ram
//In a previous run I copied blinky.h data into sector STARTING_SECTOR_N=8
//Now I copy flash sector 8 into sector 0
uint32_t fw_lenght,sector_address;
int i;
uint8_t result8;

uint32_t n_sector=0;//we start writing data in this sector

uint32_t *read_address=(uint32_t *)sector_banka_start_map[STARTING_SECTOR_N];//leggo da qui

/// pointers to call routines placed into RAM
uint8_t (*longfunc_prepare)(uint32_t strSector, uint32_t endSector, uint8_t flashBank) = &amp;amp;ram_Chip_IAP_PreSectorForReadWrite;
uint8_t (*longfunc_copy)(uint32_t dstAdd, uint32_t *srcAdd, uint32_t byteswrt) = &amp;amp;ram_Chip_IAP_CopyRamToFlash;
uint8_t (*longfunc_erase)(uint32_t strSector, uint32_t endSector, uint8_t flashBank) = &amp;amp;ram_Chip_IAP_EraseSector;

 __disable_irq();

sector_address=sector_banka_start_map[n_sector];
result8=(*longfunc_prepare)(n_sector, n_sector, 0);//prepare..Flash Bank A
result8 +=(*longfunc_erase)(n_sector, n_sector, 0);//erase&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; ---------- HERE THE PROGRAM HALTS -----------

 fw_lenght=12988;//sizeof(new_firmware);

 while(fw_lenght&amp;gt;0){

for(i=0;i&amp;lt;FLASH_DWORD_BLOCK;i++){ //copy sectors
flash_data&lt;I&gt;=*read_address;&amp;nbsp; 
fw_lenght -=4;
read_address++;
if(!(fw_lenght&amp;gt;0)){//last_iteration?
&amp;nbsp;&amp;nbsp; for(i=i+1;i&amp;lt;FLASH_DWORD_BLOCK;i++) flash_data&lt;I&gt;=0xFFFFFFFF;// fill with erased data
break;//fine del ciclo for
}
}

//storing data into flash
result8+=(*longfunc_prepare)(n_sector, n_sector, 0);//prepare
result8 +=(*longfunc_copy)(sector_address, flash_data, FLASH_BLOCK);//erase

//update flash address
sector_address +=FLASH_BLOCK;
if(!(sector_address&amp;lt;sector_banka_end_map[n_sector])){//if needed, change sector
n_sector++; //new sector
if(!(n_sector&amp;lt;MAX_FLASH_SECTOR)){
//fail !!
}
sector_address=sector_banka_start_map[n_sector];//new address
//nuovo settore:
result8+=(*longfunc_prepare)(n_sector, n_sector, 0);//prepare
result8 +=(*longfunc_erase)(n_sector, n_sector, 0);//erase
}
 }

 __enable_irq();

 return result8;
}




&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Jun 2016 18:39:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/LPC4357-fw-upgrade/m-p/555742#M15001</guid>
      <dc:creator>lpcware</dc:creator>
      <dc:date>2016-06-15T18:39:01Z</dc:date>
    </item>
  </channel>
</rss>

