cancel
Showing results for 
Search instead for 
Did you mean: 

stm32l152: bootloader firmware flashing crash using page program flash

bruzzim
Associate II
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;

}

 

5 REPLIES 5
Posted on May 22, 2012 at 18:30

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
alok472
Associate II
Posted on May 23, 2012 at 06:17

      //  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 using

FLASH_If_Write.

 

See also the comments inside this function on the fw library

bruzzim
Associate II
Posted on May 23, 2012 at 10:48

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 PM

Subject: stm32l152: bootloader firmware flashing crash using page program flash

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

bruzzim
Associate II
Posted on May 23, 2012 at 10:52

yes. In fact FLASH_If_Write() itself calls FLASH_ProgramHalfPage() until the end of memory chunk to program.

Posted on May 23, 2012 at 13:28

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..