2017-10-15 08:50 PM
Hi, I have got an issue with STM32F107 bootloader. The jump to application fails and results in hardfault. Before jumping, I have disabled all interrupts including systick timer and also set the MSP to the initial value as needed for the application program. Is there anything else to be taken care of, before making the jump? Could someone help? I have just copied the relevant part of my code below.
/********************************* declarations and defines ****************************/
unsigned *p;
void (*user_code_entry)(void);
unsigned int Address_PgrmCounter;
#define APPLICATIONADDRESS (unsigned int)0x800e000
/********************************* reset system and disable all interrupts****************/
HAL_RCC_DeInit();
HAL_DeInit(); SysTick->CTRL &= ~0x00000011; /* Disable systick counter*/ __HAL_RCC_TIM2_CLK_DISABLE();__disable_irq();
for(i=0;i<68;i++)
{ HAL_NVIC_DisableIRQ(i); } for(i=0;i<=15;i++) { __HAL_GPIO_EXTI_CLEAR_IT(i); }SCB->ICSR &= ~(0x10000000) ;
/********************************* set MSP **********************************************/
__set_MSP(APPLICATIONADDRESS);
/********************************* Jump to application
********************************/
Address_PgrmCounter = APPLICATIONADDRESS + 4; p = (unsigned *)(Address_PgrmCounter); user_code_entry = (void *) *p; user_code_entry();Solved! Go to Solution.
2017-10-16 01:19 AM
Can we try to not jam the entire question in the title, edit to fix.
You want the MSP to be a RAM address. Ie the value AT the application address and NOT the application address.
2017-10-16 01:19 AM
Can we try to not jam the entire question in the title, edit to fix.
You want the MSP to be a RAM address. Ie the value AT the application address and NOT the application address.
2017-10-17 05:41 AM
__disable_irq(); // if you do this you must enable on the other side
__set_MSP(*((uint32_t *)APPLICATIONADDRESS)); // the content of SP describe IN the vector table
2017-10-17 07:37 AM
Thanks for the reply. It helped! Jumping to application is successful after rectifying the MSP value.