Hello, I am trying to implement a 'firmware switch' feature by setting the fuses for Flash remapping (0x6E0) and calling the firmware switch using the ROM API. I've been using AN12255SW as a guide, however I've been unable to get the 'firmware_swap' example working in MCUXpresso.
I set the fuses using the following code in my main function:
#define EXAMPLE_OCOTP_FUSE_MAP_ADDRESS 0x6E0
#define EXAMPLE_OCOTP_FUSE_WRITE_VALUE 0x001C7000 // 7 MB image size, 7 MB offset
OCOTP_Init(OCOTP, CLOCK_GetFreq(kCLOCK_IpgClk));
// Reload the current register values
OCOTP_ReloadShadowRegister(OCOTP);
// Read the fuse value
OCOTP_ReadFuseShadowRegister(OCOTP, EXAMPLE_OCOTP_FUSE_MAP_ADDRESS));
// Write the new fuse values
OCOTP_WriteFuseShadowRegister(OCOTP, EXAMPLE_OCOTP_FUSE_MAP_ADDRESS, EXAMPLE_OCOTP_FUSE_WRITE_VALUE))
After this the fuse value persists, but the program does not seem to jump to the right spot
void bl_api_init(void){
g_bootloaderTree = (bootloader_api_entry_t *)*(uint32_t *)0x0020001c;
}
void bl_firmware_switch(uint32_t index){
run_bootloader_ctx_t boot_para;
boot_para.B.imageIndex = index;
boot_para.B.serialBootInterface = kEnterBootloader_SerialInterface_USB;
boot_para.B.bootMode = kEnterBootloader_Mode_Default;
boot_para.B.tag = kEnterBootloader_Tag;
g_bootloaderTree->runBootloader( (void *)&boot_para );
}
I would expect that at the end of bl_firmware_switch(), the PC counter jumps to 0x60700000, but this does not seem to be the case. Is there anything I'm missing?
I'm not sure in the AN12255SW firmware_swap example how FIRMWARE_INDEX is set to 0. Am I supposed to combine the two binaries into a single image, and then program? I'm not using the MFGTool.