AnsweredAssumed Answered

STM32L151 Flash write speed

Question asked by h.brad on Oct 12, 2012
Latest reply on Oct 12, 2012 by Clive One
Hello all,

I have a question about in application programming speeds with the L151.

I have a working bootloader for both the L151 and the F207 micros. They are nearly 100% identical take a master/slave setup. For in application programming they will both serially receive a 526 byte packet with 512 bytes countaining actual program data.

To the real question. Is it just me or does the flash write in the L151 take a ridiculously long amount of time? To write 512 bytes ( 1 word at a time ) it takes nearly 400ms. On the F207 I can write much, much faster(have not measured that, but easily 10-20 times faster).

Anyone else have experience with this? I also find it weird that when erased flash is 0x00 instead of 0xFF.. this is the first chip I have ever worked with that does this.

Let me show you a bit of the code that goes into programming the 512byte block. I do use the STM32 library.

uint8_t Flash_Write ( uint32_t StartAddress, uint8_t *p, uint32_t Size )
      uint32_t idx;
      uint32_t Address;
      __IO FLASH_Status status = FLASH_COMPLETE;

      Address = StartAddress;

      /* Unlock the FLASH Program memory */
      FLASH_Unlock ( );
      /* Clear all pending flags */     
      FLASH_ClearFlag ( FLASH_FLAG_EOP     |
                        FLASH_FLAG_WRPERR  |
                        FLASH_FLAG_PGAERR  |
                        FLASH_FLAG_SIZERR  |
                        FLASH_FLAG_OPTVERR );  
      while  ( Address < StartAddress + Size )
            status = FLASH_FastProgramWord ( Address,  *(uint32_t *)p );
            Address = Address + 4;
            p = p + 4;
            if ( status != FLASH_COMPLETE ) return status;

      /* Lock the FLASH Program memory */
      FLASH_Lock ( );

      return (uint8_t)status;

And this is from the STM32L1xx_flash.c:

FLASH_Status FLASH_FastProgramWord(uint32_t Address, uint32_t Data)
      FLASH_Status status = FLASH_COMPLETE;

      /* Check the parameters */
      /* Wait for last operation to be completed */
      status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);
      if(status == FLASH_COMPLETE)
            /* If the previous operation is completed, proceed to program the new  word */ 
            *(__IO uint32_t *)Address = Data;
            /* Wait for last operation to be completed */
            status = FLASH_WaitForLastOperation(FLASH_ER_PRG_TIMEOUT);      
      /* Return the Write Status */
      return status;

The only documentation for timing I could find in the Flash Programming manual was for the data EEPROM and if the word has been erased (which is the case here as the entire application flash is erased before intiating the write) it takes 1 Tprog.

What is a Tprog? There is no definiation of the time, or a way to calculate it in the Programmin Manual (PM0062).

Anyone have any ideas or experience that can provide a way to reliably speed this process up?