2012-05-22 06:58 AM
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; }2012-05-22 09:30 AM
Nothing immediately jumps out, but you might want to check that you have an adequate stack depth. FLASH_If_Write() has a footprint of about 144 bytes.
Here's a cite for the IAP library for others. It is inconsistently attached to STM32L15x ''Design Support'' pages.http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/stm32l1_iap_usart.zip
2012-05-22 09:17 PM
// page program
if (FLASH_If_Write(&flashdestination, (uint32_t*)ramsource ,256)) return -2;
As per my understanding from PM0062, the flash can be erased with page size of 256 but for programming it is programmed in HalfPage mode. So, only 128B can be programed usingFLASH_If_Write.
See also the comments inside this function on the fw library
2012-05-23 01:48 AM
Thanks for the hints. The stack depth should be ok, the crash occurs into the while loop below. Everything freeze.
__RAM_FUNC FLASH_ProgramHalfPage(uint32_t Address, uint32_t* pBuffer) { (snip)/* Write one half page directly with 32 different words */
while(count < 32) { *(__IO uint32_t*) (Address + (4 * count)) = *(pBuffer++); count ++; }From: clive1
Posted: Tuesday, May 22, 2012 6:30 PMSubject: stm32l152: bootloader firmware flashing crash using page program flashNothing immediately jumps out, but you might want to check that you have an adequate stack depth. FLASH_If_Write() has a footprint of about 144 bytes.
Here's a cite for the IAP library for others. It is inconsistently attached to STM32L15x ''Design Support'' pages.http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/FIRMWARE/stm32l1_iap_usart.zip
2012-05-23 01:52 AM
yes. In fact FLASH_If_Write() itself calls FLASH_ProgramHalfPage() until the end of memory chunk to program.
2012-05-23 04:28 AM
As per my understanding from PM0062, the flash can be erased with page size of 256 but for programming it is programmed in HalfPage mode. So, only 128B can be programed using FLASH_If_Write.
The code for FLASH_If_Write can handle/expects multiples of 128 bytes. Some of the code is expected to be run from RAM. I'd check the address it writes too when faulting. Also check the errata STM32-One pointed too last week.