2018-12-25 08:46 AM
Project based on "01_NVMEraseProg" from the "STM32L0xx_Snippets_Package_V1.2.0" crashes.
Below is a source code to erase/write 100 flash pages. Code crashes 9 time out of 10.
int main(void)
{
uint32_t addr;
error = 0;
SysTick_Config(2000); /* 1ms config */
SystemClock_Config();
ConfigureGPIO();
if (error != 0)
{
while(1) /* endless loop */
{
}
}
SysTick_Config(16000); /* 1ms config */
UnlockPELOCK();
UnlockPRGLOCK();
for (uint32_t i=0; i < 100; i++)
{
addr = FLASH_USER_START_ADDR + (i * FLASH_PAGE_SIZE * 4); // FLASH_PAGE_SIZE is in words
FlashErase(addr);
FlashHalfPageProg(addr, data_for_hpage);
FlashHalfPageProg(addr + FLASH_PAGE_SIZE * 2, data_for_hpage);
}
LockNVM();
while (1) /* Infinite loop */
{
}
}