I'd like to manually start the ROM bootloader on a low PORTB.4 during reset. I used the following code according to instructions in the
datasheet how to set the non-volatile flash register BOOTCFG. But with no success so far:
---------------------------------------------------------------------------------
UARTprintf("BOOTCFG register is reading %8x\n",HWREG(FLASH_BOOTCFG)); if (( HWREG(FLASH_BOOTCFG) & FLASH_BOOTCFG_NW ) != 0 ) { UARTprintf("BOOTCFG has not been committed yet\n"); // Write the desired boot configuration to the FMD register HWREG(FLASH_FMD) = (FLASH_BOOTCFG_PORT_B | FLASH_BOOTCFG_PIN_4 | FLASH_BOOTCFG_DBG1); UARTprintf("FMD set to 0x%8x\n", HWREG(FLASH_FMD)); // Write the address of the register which we wish to commit HWREG(FLASH_FMA) = 0x75100000; UARTprintf("Register to be committed written in FMA: 0x%8x\n",HWREG(FLASH_FMA)); // Write to non-volatile register (KEY + COMT bit) HWREG(FLASH_FMC) = (FLASH_FMC_WRKEY | FLASH_FMC_COMT); UARTprintf("Start committing... FMC: 0x%8x\n",HWREG(FLASH_FMC)); //Poll COMT bit in the FMC register until the commit operation is complete while((HWREG(FLASH_FMC) & FLASH_FMC_COMT)) { UARTprintf("Committing... FMC: 0x%8x\n",HWREG(FLASH_FMC)); } UARTprintf("Committed! FMC: 0x%8x Change takes effect after reset\n",HWREG(FLASH_FMC)); } else { UARTprintf("BOOTCFG has already been committed\n"); }
---------------------------------------------------------------------------------------------------
The output on the UART always reads:
Programming BOOTCFG RegisterBOOTCFG register is reading fffffffeBOOTCFG has not been committed yetFMD set to 0x00003002Register to be committed written in FMA: 0x75100000Start committing... FMC: 0x 8Committed! FMC: 0x 0 Change takes effect after reset
and this everytime I push the reset button.
I've also changed the code to write the USERREG0 instead of the BOOTCFG what worked correctly. That's why I guess implementation is actually correct.
There is an errata on this issue suggesting a special mass erease with the "unlock function" but this didn't help either.
------
SOLUTION:
Just before posting this the solution finally hit me. Instead of a simple reset as stated in the datasheet (p. 315) a power cycle is needed for the changes in BOOTCFG
to take effect.
Hope this helps anybody.