2020-06-18 08:38 AM
im trying to implement a firmware update via uart on stm32f042.
turns out that in order to jump to system memory boot mode in mid program, i need to clear first 4 bytes of the flash (AN2606)
also it turns out that it is not possible to delete only few bytes, but minimal deletion would be 1 page (1k byte).. which means that i delete my own code that is running on the mcu.
so first question would be, is there any other way to preform this firmware update?
second question would be, is there a way that my code doesnt start on the beginning of the flash (for example, flash address is 0x08000000, and there would be some kind of "go to address 0x08000400", and then my main code would be there)
is that doable?
any other insights are more than welcome
2020-06-18 09:17 AM
Here is my code for an F0:
void platform_request_boot(void)
{
uint32_t *magic = (uint32_t *) &_ebss;
magic[0] = BOOTMAGIC0;
magic[1] = BOOTMAGIC1;
scb_reset_system();
}
And the startup code:
volatile uint32_t *magic = (uint32_t *) &_ebss;
/* If RCC_CFGR is not at it's reset value, the bootloader was executed
* and SET_ADDRESS got us to this place. On F3 ???, without further efforts,
* DFU does not start in that case.
* So issue an reset to allow a clean start!
*/
if (RCC_CFGR)
scb_reset_system();
SYSCFG_MEMRM &= ~3;
/* Buttom is BOOT0, so buttom is already evaluated!*/
if (((magic[0] == BOOTMAGIC0) && (magic[1] == BOOTMAGIC1))) {
magic[0] = 0;
magic[1] = 0;
/* Jump to the built in bootloader by mapping System flash.
As we just come out of reset, no other deinit is needed!*/
SYSCFG_MEMRM |= 1;
void (*bootloader)(void) = (void (*)(void)) (*((uint32_t *) SYSMEM_RESET_VECTOR));
/* We come out of reset, so MSP is already set*/
bootloader();
while (1);
}
2020-06-18 01:57 PM
You can flag your update code to be ran from RAM instead of FLASH. That way, when you delete the flash, your code can still execute.
There are other options as well. Depends on what your goal is.
You can have your code elsewhere, but then you need a bootloader to be able to send execution to that point.
2020-06-20 03:12 AM
> so first question would be, is there any other way to preform this firmware update?
Yes, it's called bootloader and there are literally hundreds of examples and topics on that in the internet and this forum.