I am trying to setup updates over CAN Bus from inside the app without using a bootloader. I used the "LPC5536: How to Use Dual Image" tutorial with the flashiap example project to get started and it works great flashing image 1 from inside image 0 over CAN Bus. However, after rebooting into image 1, the offset prevents access to image 0 memory regions preventing me from writing over image 0 for the next update. Reference manual 19.3.4.1 makes mention of enabling/disabling the offset via a register but having trouble finding how to implement that if it is at all possible. Is there another way to access flash memory for image 0 from image 1 when the offset is enabled?
CPMA 0x3E230 Config: 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00
Looks like maybe I partially answered my question as I found there is an API call in LPC5536.h
/*! REMAPEN - AHB Bus Address Remap Enable
* 0b0..HADDR REMAP Disabled
* 0b1..HADDR REMAP Enabled
*/
#define FLEXSPI_HADDRSTART_REMAPEN(x) (((uint32_t)(((uint32_t)(x)) << FLEXSPI_HADDRSTART_REMAPEN_SHIFT)) & FLEXSPI_HADDRSTART_REMAPEN_MASK)
However, before trying to access Flash 0x0 from a 0x20000 offset is still reading location 0x20000. What else might I be missing?
#define IMAGE_0_ADDRESS 0x00000
#define IMAGE_1_ADDRESS 0x20000
int compareVersions(void)
{
status_t status;
uint32_t lowerVersion = 0;
uint32_t upperVersion = 0;
uint8_t readPage[512];
// Disable offset to ensure image 0 can be read
FLEXSPI_HADDRSTART_REMAPEN(0) ;
status = FLASH_VerifyErase(&s_flashDriver, IMAGE_0_ADDRESS, 512);
if(status == kStatus_Success)
{
LOG_INFO("\r\nThere is no app installed at location %X\r\n", IMAGE_0_ADDRESS);
}
else
{
memcpy(readPage, (uint32_t *)IMAGE_0_ADDRESS, 512);
lowerVersion = readPage[4+0x20] + (readPage[5+0x20] <<
LOG_INFO("\r\nApp version %X is installed at location %X\r\n", lowerVersion, IMAGE_0_ADDRESS);
}
status = FLASH_VerifyErase(&s_flashDriver, IMAGE_1_ADDRESS, 512);
if(status == kStatus_Success)
{
LOG_INFO("\r\nThere is no app installed at location %X\r\n", IMAGE_1_ADDRESS);
}
else
{
memcpy(readPage, (uint32_t *)IMAGE_1_ADDRESS, 512);
upperVersion = readPage[4+0x20] + (readPage[5+0x20] <<
LOG_INFO("\r\nApp version %X is installed at location %X\r\n", upperVersion, IMAGE_1_ADDRESS);
}
// Reenable offset
FLEXSPI_HADDRSTART_REMAPEN(1) ;
return (lowerVersion > upperVersion);
}
Output:
App version 30400 is installed at location 0
App version 30400 is installed at location 20000