I am currently working on a bootloader firmware application targeted to STM32F030C8. I specified in my scatter file that the bootloader app will occupy main memory location 0x08000000 to 0x08002FFF (sector 0 to sector 2). I also wrote a main firmware application that is stored from 0x08003000 to 0x0800C800. After downloading both firmware to the MCU internal FLASH, I lauched the main app from the bootloader using the code below:
/************************************************************//**
* \brief Start the main application if available and correct
*****************************************************************/
void INTFLASH_execute_main_app(const char mode)
{
MyFunc_ptr AppEntry;
uint32_t temp[1];
IRQn_Type index;
memcpy(temp, (void*)&NVIC->ISER, sizeof(NVIC->ISER)); //Save enabled interrupts
for( index = (IRQn_Type)0; index<= (IRQn_Type)28; index++) //Disable all interrupts
NVIC_DisableIRQ(index);
AppEntry = (MyFunc_ptr) INTFLASH_calculate_page_addr(IAP_APP_START_PAGE);
if( mode || intflash_check_main_app() )
{
Main_App_ptr = (uint8_t*)AppEntry;
if( (*Main_App_ptr != 0xFF) && (Main_App_ptr) )
{
AppEntry();
}
}
memcpy( (void*)&NVIC->ISER, temp, sizeof(NVIC->ISER) ); //Restore interrupts
}
For some reason, when it executes AppEntry(), it jumps to the code below and does not execute the main app at location 0x08003000:
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
I have used this sort of logic before on ARM7 MCU and it works fine, I cannot quite figure out why it doesnt work on this cortex M0 based MCU. Any help would be greatly appreciated.
See Scatter files for bootloader and main app below:
LR_IROM1 0x08000000 0x00003000 { ; load region size_region
ER_IROM1 0x08000000 0x00003000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00002000 { ; RW data
.ANY (+RW +ZI)
}
}
LR_IROM1 0x08003000 0x0000C800 { ; load region size_region
ER_IROM1 0x08003000 0x0000C800 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00002000 { ; RW data
.ANY (+RW +ZI)
}
}