SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By Gorlash
#136711
Okay, I've learned how to move code to Bank1, and it executes properly.

After having some problems getting bank1 booting to work, we decided to instead try copying our firmware into an external Flash chip and validate it, then switch to code which is entirely in Bank1, to write from the external flash back into bank0.

I first wrote and tested code to enable unused sectors in Bank1 and write/verify code; this works fine.

Now I'm trying to write code from Ext Flash to bank0:

//**************************************************************************************************
u8 *src = (u8 *) ALT_FEPROM ;
u8 *dest = (u8 *) (0) ; // Bank0 Sector 0
bytes_remaining = datum[0] ;

unsigned flags = disable_IRQ(); // make sure nothing tries to execute from bank0 !!

set_led_green_on() ;
while (LOOP_FOREVER) {
wlen = (bytes_remaining > SIZE_64K) ? SIZE_64K : bytes_remaining ;
// this function is executing successfully...
if (feprom_program_enable_bank0(dest, BANK0_FM) == FALSE) {
break;
}
set_led_red_on() ;
delay_250msec(4) ;
u32 u32SectorAddr;
// if the physical address does not belong to any of the internal flash sectors, fail.
if (!bank0_bGetBankSecAddrByPhyAddr((uint) dest, &u32SectorAddr, NULL)) {
break;
}

// 12/07/11 - here is the show-stopper...
// If I call this function, which writes to two registers in the internal flash-programming interface,
// the sector erase proceeds successfully, but the code never returns to here...
bank0_EraseSector(u32SectorAddr); // Erase the sector
//**************************************************************************************************

However, as the comments reflect, the sector-erase function never returns.
I used OpenOCD via the JTAG interface, to look at bank0 space after the crash, and it appears that the erase *did* occur, but the function never returns.
bank0_EraseSector() contains only two writes to the STR9 CUI interface:

//**************************************************************************************************
static void bank0_EraseSector(vu32 FMI_Sector)
{
/* Write an erase set-up command to the sector */
*(vu16 *)FMI_Sector = 0x20;

/* Write an erase confirm command to the sector */
*(vu16 *)FMI_Sector = 0xD0;
}
//**************************************************************************************************

So why does this crash? What else do I need to do to make this work?

I tried remapping bank1 to boot bank and bank0 to non-boot bank, using
// FMI_BankRemapConfig(0, 6, 0x80000, 0) ; // this crashes the board immediately!!
but that doesn't work either...

Our system: STR912 512K/32K