cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0 custom bootloader

andy2
Associate II
Posted on April 28, 2016 at 07:11

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?

2 REPLIES 2
Posted on April 28, 2016 at 22:21

I'd probably not re-enable them until after I'd go the remapping complete.

Review what is being done in SystemInit(), if the app code doesn't need to reconfigure the clocks and restart the HSE/PLL, then don't do that.

Make sure you have a proper Hard Fault Handler, so you can actually catch things when they break.

Pay attention to what you have running, what interrupts are occurring, etc. Be mindful of the ones like SysTick that the HAL uses for it's timing.

Output diagnostic information via a serial ports, so you can understand the flow of the code leading to the failure conditions. Add more as you focus in on specific causes and paths.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
andy2
Associate II
Posted on April 29, 2016 at 17:36

Thank you clive1 for the tips. I have implemented what you said, and hopefully no more freezing :)