AnsweredAssumed Answered

STM32F0 custom bootloader

Question asked by winix on Apr 28, 2016
Latest reply on Apr 29, 2016 by winix
Hi, I have made a custom bootloader, but it sometimes freeze when going from bootloader to the actual firmware.  Usually the bootloader should just go to the firmware by doing the following:

uint32_t startAddress = *(__IO uint32_t*)(FIRMWARE_START_ADDRESS + 4);
pFunction RestartFirmware = (pFunction)startAddress;
__set_MSP(*(__IO uint32_t*)FIRMWARE_START_ADDRESS);
RestartFirmware();

Where the FIRMWARE_START_ADDRESS is the first data for the actual firmware.

In the firmware itself, I would copy the vector table, and do as normal.

uint32_t i = 0;
     
for(i = 0; i < 48; i++)
{
     VectorTable[i] = *(__IO uint32_t*)(FIRMWARE_START_ADDRESS + (i<<2));
}
          
__enable_irq();       
__SYSCFG_CLK_ENABLE();
__HAL_REMAPMEMORY_SRAM();


I do not know what is failing, and when it is failing.  Someone experienced told me to actually disable the IRQ and also de-init everything before passing to firmware, which I will do.  However, is there anything best practice to do this?

Just for information, I am going to add:
__disable_irq();
     
HAL_I2C_MspDeInit(&hi2c1);               
HAL_UART_MspDeInit(&huart1);
HAL_UART_MspDeInit(&huart2);
                      
__ADC1_CLK_DISABLE();
__TIM1_CLK_DISABLE();
__SPI1_CLK_DISABLE();
__TIM16_CLK_DISABLE();
__TIM17_CLK_DISABLE();
__USART1_CLK_DISABLE();
__DBGMCU_CLK_DISABLE();
__SYSCFG_CLK_DISABLE();

Before the jumping of bootloader to firmware to disable everything first.

Am I doing the right thing?

Outcomes