2022-09-08 01:22 PM
I am making a bootloader for stm32f030k6t6 using keil, I already made the first tests with the bootloader and a simple application with a led to know if the bootloader jumps for the application and it works fine, it has been hard for me to understand this part of bootloader, I think it is easier to use keil than stm32cubeide, my problem is that I want to record in the flash the new firmware when I press a button for 3 s in the boot of the board, I have the application in the address 0x8002000, in the bootloader I place
uint32_t jump_addr=*((__IO uint32_t *(MAIN_USER_FLASH_BEGIN+4));
to go to the application, where MAIN_USER_FLASH_BEGIN = 0x8002000, my doubt is if I start to erase the flash from 0x8002000? how would it erase all the flash area where the application is?
step for programm in the flash:
// 1._ desbloquear la flash
//2._ borrar las flash
//3._ escribir firmware en la flash en la region de la aplicacion
//4._ bloquear la flash
ret = HAL_FLASH_Unlock();
/* Allow Access to option bytes sector */
HAL_FLASH_OB_Unlock();
if( ret != HAL_OK )
{
break;
}
// no necesita borrar varias veces que entra. borra la flash solo la primera vez que comienza el proceso
if( is_first_block )
{
//Borrando la flash
uint32_t SectorError;
/* Fill EraseInit structure*/
FLASH_EraseInitTypeDef EraseInitStruct;
EraseInitStruct.TypeErase = FLASH_TYPEERASE_PAGES;
EraseInitStruct.PageAddress = 0x8002000;
EraseInitStruct.NbPages = 24;
uint32_t PageError; // Valor do endereço
ret = HAL_FLASHEx_Erase(&EraseInitStruct, &PageError);
if( ret != HAL_OK )
{
break;
}
}
HAL_FLASH_OB_Lock();
HAL_FLASH_Lock();
I am starting to delete from 0x8002000, as the flash has 32k, each page is a 1k, and I am using theoretically 8k from the bootloader, there are 24k left, that would be theoretically 24 pages, that's why in number of pages I put 24.
2022-09-08 01:52 PM
I'm not using this specific part, but yes you'd typically erase from that location, upward, however many pages remain.
You could reduce that if you knew the size of the new application images, or perhaps if you walked the memory determining how much the old application took up, and just erase those pages.