Hi, I'm trying to implement a boot loader based on the one in AN10995 for the LPC11U68.
I read in the data fine but when I write it, nothing is written to flash.
Here's the code, the copy ram to flash command returns success, however nothing is written to flash. Flash inspection shows nothing is written and the comparison operation returns that they aren't the same. What am I missing?
/* Define flash memory address at which user application is located */
#define APP_START_ADDR (0x00001000UL)
#define APP_END_ADDR (0x00040000UL)/* Define the flash sectors used by the application */
#define APP_START_SECTOR 1
#define APP_END_SECTOR 28static uint32_t u32BootLoader_ProgramFlash(uint8_t *pu8Data, uint16_t u16Len)
{
uint32_t u32Result = 0;static uint32_t u32NextFlashWriteAddr = APP_START_ADDR;
if ((pu8Data != 0) && (u16Len != 0))
{
/* Prepare the flash application sectors for reprogramming */
if (Chip_IAP_PreSectorForReadWrite(APP_START_SECTOR, APP_END_SECTOR) == IAP_CMD_SUCCESS)
{/* Write the data to flash */
if (Chip_IAP_CopyRamToFlash(u32NextFlashWriteAddr, (uint32_t *) pu8Data, u16Len) == IAP_CMD_SUCCESS)
{
/* Check that the write was successful */
if (Chip_IAP_Compare(u32NextFlashWriteAddr, (uint32_t) pu8Data, u16Len) == IAP_CMD_SUCCESS)
{
/* Write was successful */
u32NextFlashWriteAddr += u16Len;
u32Result = 1;
}
}
}
}
return (u32Result);
}
Hi Nicholas Hunn ,
Thank you for your interest in NXP Semiconductor products and the opportunity to serve you.
I consider the issue is caused by inappropriate IAP command calling, please refer to the attachment for checking
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Fixed my own problem, was running the wrong command to wipe the pages.
Got a new problem now, branching to the code results in a crash.
Here's the code snippet I use for this. As far as I understand, this should set the stack pointer to whatever's at the start of the code, then branch the code to my reset ISR.
#define APP_START_ADDR (0x00001000UL)
SCB->VTOR = ( uint32_t )APP_START_ADDR ;
/* Load main stack pointer with application stack pointer initial value,
stored at first location of application area */
asm volatile("ldr r0, =0x1000");
asm volatile("ldr r0, [r0]");
asm volatile("mov sp, r0");
/* Load program counter with application reset vector address, located at
second word of application area. */
asm volatile("ldr r0, =0x1004");
asm volatile("ldr r0, [r0]");
asm volatile("mov pc, r0");
Here's my memory map for the main code in case this is wrong:
MEMORY
{
/* Define each memory region */
MFlash256 (rx) : ORIGIN = 0x1000, LENGTH = 0x39000 /* 252K bytes (alias Flash) (4k by bootloader) */
Ram0_32 (rwx) : ORIGIN = 0x10000000, LENGTH = 0x7FE0 /* 32K bytes (alias RAM) less 32 bytes for IAP */
Ram1_2 (rwx) : ORIGIN = 0x20000000, LENGTH = 0x800 /* 2K bytes (alias RAM2) */
Ram2USB_2 (rwx) : ORIGIN = 0x20004000, LENGTH = 0x800 /* 2K bytes (alias RAM3) */
}/* Define a symbol for the top of each memory region */
__base_MFlash256 = 0x1000 ; /* MFlash256 */
__base_Flash = 0x1000 ; /* Flash */
__top_MFlash256 = 0x1000 + 0x39000 ; /* 256K bytes */
__top_Flash = 0x1000 + 0x39000 ; /* 256K bytes */
__base_Ram0_32 = 0x10000000 ; /* Ram0_32 */
__base_RAM = 0x10000000 ; /* RAM */
__top_Ram0_32 = 0x10000000 + 0x7FE0 ; /* 32K bytes */
__top_RAM = 0x10000000 + 0x7FE0 ; /* 32K bytes */
__base_Ram1_2 = 0x20000000 ; /* Ram1_2 */
__base_RAM2 = 0x20000000 ; /* RAM2 */
__top_Ram1_2 = 0x20000000 + 0x800 ; /* 2K bytes */
__top_RAM2 = 0x20000000 + 0x800 ; /* 2K bytes */
__base_Ram2USB_2 = 0x20004000 ; /* Ram2USB_2 */
__base_RAM3 = 0x20004000 ; /* RAM3 */
__top_Ram2USB_2 = 0x20004000 + 0x800 ; /* 2K bytes */
__top_RAM3 = 0x20004000 + 0x800 ; /* 2K bytes */
Hi Nicholas Hunn ,
/**
* @brief This function is cleanup system before jump to application
* @param Nothing
* @return Nothing
*/
void LPC_SBL_CleanUpSystem(void)
{
/* Switch Main clock resource to IRC */
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_IRC);
/* No need to update the systemclock as user app is going to takeover anyway*/
/* Setup FLASH access to 2 clock */
Chip_FMC_SetFLASHAccess(FLASHTIM_2CLK_CPU);
Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_SYSPLL_PD);
}
/**
* @brief doCleanBoot
* @param Nothing
* @return Nothing
*/
typedef void (*iapfun)(void);
iapfun jump2app;
void doCleanBoot(uint32_t imgAddr)
{
/* disable interrupt */
__ASM volatile ("cpsid i" : : : "memory");
/* Cleanup before going to app */
LPC_SBL_CleanUpSystem();
/* Boot Valid Application */
/* Set Stack */
__set_MSP(*(volatile uint32_t*) (imgAddr));
/* Set app entry point */
jump2app =(iapfun)*(uint32_t*)(imgAddr+4);
/* enable interrupt */
__ASM volatile ("cpsie i" : : : "memory");
/* Jump_To_Application = (pFunction) JumpAddress; */
jump2app();
/***** Control should never come here *****/
}
Thanks for your reply.
You can use the following codes to jump to application.
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------