ХЗ как в хале, но вот вполне рабочая прога
- #define FLASH_PROG_ERROR_MASK (FLASH_SR_PROGERR | FLASH_SR_WRPERR | FLASH_SR_PGAERR | FLASH_SR_SIZERR | FLASH_SR_PGSERR)
bool flash_prog(void* data, const void* flash_addr, int size)
{
bool res = false;
uint32_t* ptr = data;
uint32_t* flash_ptr = (uint32_t*)flash_addr;
flash_enable();
if(!flash_page_erase((uint32_t)flash_addr))
goto end;
FLASH->SR = 0xffffffff;
FLASH->CR = FLASH_CR_PG;
while(size > 0)
{
*flash_ptr++ = *ptr++;
*flash_ptr++ = *ptr++;
while (FLASH->SR & FLASH_SR_BSY1);
if(FLASH->SR & FLASH_PROG_ERROR_MASK)
goto end;
FLASH->SR = 0xffffffff;
size -=8;
}
res = true;
end:
FLASH->CR = 0;
flash_disable();
return res;
}