IAP commands Copy to Flash

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

IAP commands Copy to Flash

1,846 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldisGold on Fri Oct 02 11:42:27 MST 2015
Hi,

Board: LPC54102 Sensor processing
IDE: LPC Xpresso v 7.7.2

I am working on building a secondary bootloader and using IAP commands to copy a binary(application firmware) to the flash. However the Copy RAM to Flash doesn't work for me. I am using the  function Chip_IAP_CopyRamToFlash from iap.c passing arguments as follows

Chip_IAP_CopyRamToFlash(START_WRITE_ADDR, src_iap_array_data01, IAP_NUM_BYTES_TO_WRITE);

Start_write_address is 0x00018000

src_iap_array_data01 is the array containing the data from the binary(application firmware)

IAP_NUM_BYTES_TO_WRITE is 4096


I have prepared the sector for erase/write prior to calling the Chip_IAP_CopyRamToFlash.

Regards,
OldidGold
Labels (1)
0 Kudos
7 Replies

1,037 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldisGold on Wed Nov 25 16:30:23 MST 2015
Hi xianghuiwang   Thanks for your help  :)   I got the sbl working somehow.
0 Kudos

1,037 Views
juanabelaira
Contributor III

Good. In the same way you come here for help, if you share your findings and solutions you can help other people, that's the point of a forum.

0 Kudos

1,037 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xianghuiwang on Fri Nov 20 15:59:49 MST 2015
Hi,
There is sample project periph_flashiap in the LPCOpen package. You can bring up the sample project and then compare the execution with your project to tell what's missing.

https://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc5410x-packages

For the source code of the boot loader, it may take a bit time to prepare for you.
regards,
0 Kudos

1,037 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldisGold on Mon Oct 05 14:34:46 MST 2015
Any Pointers as to why the above code fails ? Any help is very much appreciated.

I tried running my application binary on top of the SBL hex provided by NXP (AN11610.zip) and it works fine. Can anybody give me the source code for that

Regards,
OldisGold.
0 Kudos

1,037 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldisGold on Fri Oct 02 16:56:26 MST 2015
This is the code in main.c

        uint32_t *p;
uint8_t ret_code;
#define START_WRITE_ADDR  0x00018000
Board_LED_Set(1, TRUE);
__disable_irq();// Start by disabling interrupts, before changing interrupt vectors
//Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_IRC); //switch to IRC

//Check Firmware Version
if(*new_firmware_version > *current_firmware_version)
{
//
//******************************Copy Extracted download firmware to location 0x18000*******************************************************//
/* IAP Flash programming */

// Prepare to write/erase the last sector
ret_code = Chip_IAP_PreSectorForReadWrite(3, 3);
if (ret_code != IAP_CMD_SUCCESS) { DEBUGSTR("Command failed to execute PrepareSectorForReadWrite.  \r\n");} // Error checking


//Erase sector for Write
ret_code = Chip_IAP_EraseSector(3,3);
if (ret_code != IAP_CMD_SUCCESS) { DEBUGSTR("Command failed to execute. EraseSector  \r\n");}
// Write to the last sector



// Prepare to write/erase the last sector
ret_code = Chip_IAP_PreSectorForReadWrite(3, 3);
if (ret_code != IAP_CMD_SUCCESS) { DEBUGSTR("Command failed to execute PrepareSectorForReadWrite.  \r\n");} // Error checking


ret_code = Chip_IAP_CopyRamToFlash(START_WRITE_ADDR, src_iap_array_data00, 4096);
if (ret_code != IAP_CMD_SUCCESS) { DEBUGSTR("Command failed to execute array00.  \r\n");}// Error checking
DEBUGSTR("Flash array00\r\n");


START_WRITE_ADDR = START_WRITE_ADDR+0x1000;

ret_code = Chip_IAP_PreSectorForReadWrite(3, 3);
if (ret_code != IAP_CMD_SUCCESS) { DEBUGSTR("Command failed to execute.PrepareSectorForReadWrite  \r\n");}  //Error checking

ret_code = Chip_IAP_CopyRamToFlash(START_WRITE_ADDR, src_iap_array_data01, 4096);
if (ret_code != IAP_CMD_SUCCESS) { DEBUGSTR("Command failed to execute array01.  \r\n");}// Error checking
DEBUGSTR("Flash array01\r\n");


//*current_firmware_version = *new_firmware_version; //Set the Current Firmware Version to the new firmware after copying


/*******************To Check State of Sector 3**************************/

ret_code = Chip_IAP_BlankCheckSector(3,3);
if(ret_code == IAP_SECTOR_NOT_BLANK) {DEBUGSTR("Sector 3 Not Blank");}
/*************************************************************************/

}

DEBUGSTR("To test the SBL Code\n");
/* Set vector table offset*/
SCB->VTOR = user_start_sector_address;

p = (uint32_t *)user_start_sector_address;

Board_LED_Set(1, FALSE);

__enable_irq();//Enable interrupts before jumping to application


/*Set stack pointer to given address*/
__set_MSP(*p);

/*Set address for RESET*/
p++;
user_code_entry = (void (*)(void))(*p);

/*Jump to application*/
user_code_entry();
0 Kudos

1,037 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OldisGold on Fri Oct 02 13:42:26 MST 2015
Both functions

Chip_IAP_PreSectorForReadWrite() and Chip_IAP_CopyRamToFlash()  returns 0 (IAP_CMD_SUCCESS)


I am also checking Chip_IAP_BlankCheckSector after the above functions and it returns CMD_SUCCESS showing the sector to be empty.
0 Kudos

1,037 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Oct 02 12:03:00 MST 2015

Quote: OldisGold
I am using the  function Chip_IAP_CopyRamToFlash...



And what is the function returning  :quest:  :~  :quest:
0 Kudos