hi,
In LPC1768, i have to types of software section.
1) bootloader (flash sector 0 to sector 7)
2) system software (flash sector 8 to 12)
when i am trying to write on flash sector 0 to 7 using IAP, from system software. prepare_sector will execute properly but
when i am try to write to sector 0 it is giving error(status 9) stating that sector is not prepared.
(I want to flash bootloader from system software which is not able to do. please suggest me solution).
Hi, Thank you very much for your quick answer! this can help us to find a solution for this issue. we are using LPC546XX family and I think the procedure is almost the same. Have a good time!
According to the manual the prepare sector command cannot return error 9.
prepare sector is executing properly which returns 0. but when i am going to write that sector(which is sector-0 to sector-7)
it is returning 9. (SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION).
once again i will explain my problem
i am using sector-0 to sector-7 for my bootloader. when i am trying write to these sector after preparing also, it is returning 9.(SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION).
mahadeva,
I have found it necissary to write the REINVOKE ISP command before PREPARE SECTOR and ERASE SECTOR and then performing a reset before I can write to a flash location.
Best regards,
Peter
not working.
1) My bootloader code will occupy first 8 sector of flash.
when i am trying to write sector -1 to sector-7 also not working.
procedure i followed after your answer
1) changer scb->vtor to ram
2) copy content at 0x1c to ram
3) disable interrupt
4)reinvoke isp
5)prepare and erase
6)reset
7) write to sector-0 to sector-7 (returning 9)
8) change scb->vtor to flash
9) enable interrupt
Hi,
Please refer the application note AN10866 for details,
cache.nxp.com/documents/application_note/AN10866.zip?fsrch=1&sr=1&pageNum=1
Have a great day,
Ping
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
As Peter is writing, you must erase the sector before trying to perform write. Also remember to execute the Prepare sector command before the erase command and before every write command as these commands causes the relevant sectors to be protected again after execution
i am preparing sector before writing. even though it is giving same error status
Hey I am currently working on a program that uses the IAP functions and also having problems with programming sector0. Check out the thread here:
It would seem that there is some behavior in sector0 that is not documented, and I am also still waiting on an explanation.
That said, are you making sure to erase the sector before trying to perform the write?
EDIT
I got a response back from the very helpful @Carlos_Mendoza
To program sector0 you need to follow these steps:
1) Relocate interrupt table to RAM by writing new address to VTOR (0xE000ED04)
a)So copy the data in flash from 0x0-0x1F to your new RAM location. Remember that from 0x10000000-0x100001FF is used by the IAP, so relocate it to 0x10000200 or higher.
2) Erase sector0 with erase sector IAP command.
a) I found it necicary to reset the core after an erase before I could send another IAP command.
3) Program secotr0 with copy ram to flash command
a) Check that data includes 2s comp checksum at 0x1C
4) Restore VOTR to 0x0
5) Power cycle
/EDIT
Best Regards,
Peter
Hello Peter,
I tried the steps but it hasn't worked for me. Do you have a piece of code that I can look up to?
Or, would you please have a look at my code and comment?
#define PAGE_SIZE (256)
#define PF1_BOOTLOADER_START_ADDR (0x0000)
uint8_t u8tempArray[32];
uint8_t vtorOnRAM[32];
void FW_updateBootloader(void)
{
uint32_t u32Address = 0;
uint32_t u32Offset = 0;
// Each sector is 4096 bytes
// Each sector can be programmed in sequence - Prepare sector > Erase sector > Program page in the sector
//To program sector0 you need to follow these steps:
//1) Relocate interrupt table to RAM by writing new address to VTOR (0xE000ED04)
// So copy the data in flash from 0x0-0x1F to your new RAM location.
// Remember that from 0x10000000-0x100001FF is used by the IAP, so relocate it to 0x10000200 or higher.
//2) Erase sector0 with erase sector IAP command.
// I found it necicary to reset the core after an erase before I could send another IAP command.
//3) Program secotr0 with copy ram to flash command
//a) Check that data includes 2s comp checksum at 0x1C
//4) Restore VOTR to 0x0
//5) Power cycle
// Criterion for Valid User Code (Section 32.3.1.1, page 627 of UM10360 LPC17XX user manual
// The reserved Cortex-M3 exception vector location 7 (offset 0x 001C in the vector table)
// should contain the 2’s complement of the check-sum of table entries 0 through 6. This
// causes the checksum of the first 8 table entries to be 0. The boot loader code checksums
// the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is
// transferred to the user code.
uint32_t NumBlocks = PF1_APP_START_ADDR / PAGE_SIZE;
for(uint32_t i = 2; i < NumBlocks; i++)
{
/* Write flash sector */
//write_data(CCLK, u32Address, (uint8_t*)&bootloaderImage[u32Offset], PAGE_SIZE);
write_flash((uint32_t*)u32Address, (uint8_t*)&bootloaderImage[u32Offset], PAGE_SIZE);
u32Address = u32Address + PAGE_SIZE;
u32Offset = u32Offset + PAGE_SIZE;
}
// Step 1
// Relocate interrupt table to RAM by writing new address to VTOR (0xE000ED04)
// So copy the data in flash from 0x0-0x1F to your new RAM location.
// Remember that from 0x10000000-0x100001FF is used by the IAP, so relocate it to 0x10000200 or higher.
memset(u8tempArray, 0, sizeof(u8tempArray));
/* Read on-chip sector from internal flah to read the vtor */
Read_Onchip_Flash((void *)PF1_VTOR_START, (uint8_t*)&u8tempArray, sizeof(u8tempArray));
memcpy(vtorOnRAM, u8tempArray, sizeof(vtorOnRAM));
__disable_irq();
uint32_t vtorAddressonRAM = &vtorOnRAM;
SCB->VTOR = vtorAddressonRAM & 0x1FFFFF80;
__enable_irq();
// Step 2
// Erase sector0 with erase sector IAP command.
find_erase_prepare_sector(CCLK, PF1_BOOTLOADER_START_ADDR);
// Step 3
// Program secotr0 with copy ram to flash command
u32Address = 0;
u32Offset = 0;
write_flash((uint32_t*)u32Address, (uint8_t*)&bootloaderImage[u32Offset], PAGE_SIZE);
u32Address += PAGE_SIZE;
u32Offset += PAGE_SIZE;
write_flash((uint32_t*)u32Address, (uint8_t*)&bootloaderImage[u32Offset], PAGE_SIZE);
u32Address += PAGE_SIZE;
u32Offset += PAGE_SIZE;
// Step 4
// Restore VOTR to 0x0
__disable_irq();
SCB->VTOR = 0;
__enable_irq();
NVIC_SystemReset();
}
Hello!
Did you succeed to update the bootloader through firmware using IAP ?
BR
Ali
Hi, yes, I managed to get it working. The code remains the same, just added more code to calculate checksum of vectors and put it at the designated address. You'll find it in the datasheet.
The sector 0 is the section of memory where boot ROM is mapped. In order to be able to access this sector, a flag in MEMMAP register needs to be set.
Section 33.6.1, page 655 of UM10360 LPC17XX user manual states:
The MEMMAP register (Address - 0x400FC040) allows switch the mapping of the bottom of memory, including default reset and interrupt vectors, between the Boot ROM and the bottom of on-chip Flash memory.
If bit 0 is 0 -- Boot mode. A portion of the Boot ROM is mapped to address 0.
If bit 0 is 1 -- User mode. The on-chip Flash memory is mapped to address 0.
Bit 31:1 are reserved.
Section 32.3.1.1, page no. 627 of UM10360 LPC17XX user manual states:
The reserved Cortex-M3 exception vector location 7 (offset 0x 001C in the vector table) should contain the 2’s complement of the check-sum of table entries 0 through 6. This causes the checksum of the first 8 table entries to be 0. The boot loader code checksums the first 8 locations in sector 0 of the flash. If the result is 0, then execution control is transferred to the user code.
Hope this helps!