Hi,
I'm trying to implement the internal flash dual image boot on LPC5536 using IAR.
First of all let me know if i understand well how it works: Let's consider figure 86, chapter 26.3.1.1.1.1 of of LPC553x Reference Manual, and let's assume that header of image0 contains an image version 0, and header of image1 contains an image version 1. At startup ROM checks both headers and since image1 has an higher image version, image1 is run. Correct?
In LPC5536 the total size of the flash is 0x3DC00, so dividing it by 2, each block will have size 0x1EE00
First thing to do is to change the CMPA fields FLASH_REMAP_SIZE and FLASH_REMAP_OFFSET to match the 0x1EE00 block size.
To access CMPA, i used functions from fsl_flash_ffr.h, named FFR_GetCustomerData and FFR_CustFactoryPageWrite. In particular, after calling FLASH_Init and FFR_Init, I use these functions as follows:
static cmpa_cfg_info_t cmpa;
status = FFR_GetCustomerData(&s_flashDriver,(uint8_t *)&cmpa,0,512);
if (status != kStatus_Success)
{
error_trap();
}
cmpa.flashRemapSize = 0x1EDFF;
cmpa.flashRemapOffset = 0x1EE00;
status = FFR_CustFactoryPageWrite(&s_flashDriver,(uint8_t *)&cmpa,false);
if (status != kStatus_Success)
{
error_trap();
}
This part of code seems to work without particular problems.
Second thing to do is to produce image with version number in the header; to achive this, i change the "startup_LPC55S36.s" file as follows:
__vector_table
DCD sfe(CSTACK)
DCD Reset_Handler
DCD NMI_Handler
DCD HardFault_Handler
DCD MemManage_Handler
DCD BusFault_Handler
DCD UsageFault_Handler
__vector_table_0x1c
DCD SecureFault_Handler
DCD 0x1EDFF
DCD 0x10400
DCD 0
DCD SVC_Handler
DCD DebugMon_Handler
DCD 0
DCD PendSV_Handler
DCD SysTick_Handler
...
In this way, using 0x10400 i produce an image with version number 1, using 0x20400 i produce an image with version number 2 and so on.
I completed the example application turning on a blue LED in image0 and a red LED in image1.
From IAR options i created a srec file filling unused memory with 0xFF until address 0x1EDFF, and i used ISP functions to write the images into flash.
The problem is that regardless of the image version, the only image loaded at startup is image0.
So the question is can you help me to spot the mistake in this code and to implement the dual image boot correctly?
Thanks
Enrico