Question
stm32l152: bootloader firmware flashing crash using page program flash
Posted on May 22, 2012 at 15:58
Hello,
my bootloader reflash routine works properly using FLASH_FastProgramWord(). To speed-up the procedure I tried using the faster Page Program FLASH_If_Write() function but most of of the times I get crashes. Can anyone help me? Hereafter my routine:int32_t ImageCopy(void)
{ uint32_t NumPag, SizeLastPage, i, j; uint32_t flashdestination;/* Initialize flashdestination variable */
flashdestination = APPLICATION_ADDRESS;// check image size
if (FIRMWARE_SIZE > FIRMWARE_FLASH_MAX_SIZE) return -2; /* erase user application area */ FLASH_If_Erase(APPLICATION_ADDRESS);// read external flash data
NumPag = FIRMWARE_SIZE / 1024; SizeLastPage = FIRMWARE_SIZE % 1024;uint32_t ramsource;
for (i = 0; i < NumPag; i++) { ramsource = (uint32_t)tab_1024;// read 1024 bytes from external FLASH into tab_1024 buffer
ExternalFlashRead(ADD_DOWNLOAD_IMAGE_START+i*1024, tab_1024, 1024);// page program
if (FLASH_If_Write(&flashdestination, (uint32_t*)ramsource ,256)) return -2; } if (SizeLastPage) { ramsource = (uint32_t)tab_1024; ExternalFlashRead(ADD_DOWNLOAD_IMAGE_START+NumPag*1024, tab_1024, SizeLastPage); if (FLASH_If_Write(&flashdestination, (uint32_t*)ramsource ,SizeLastPage/4)) return -2; } return 0; }