0 Replies Latest reply on Nov 26, 2015 6:20 AM by andrew.lukin_cogniance

    Error in platform_erase_flash() for STM32F4xx

    andrew.lukin_cogniance

      There is the problem in an erasing of an internal flash. System will stop if you will erase more than 1 MB of a flash at a time.

      To be more precise, it happening when you erasing over a flash bank border (1st MB -- 1st bank, 2nd MB -- 2nd bank).

       

      platform_erase_flash() in WICED/platform/MCU/STM32F4xx/WAF/waf_platform.c uses that fact that addresses of a flash sectors are continuously growing by adding 8.

      Please see the following code fragment from stm32f4xx_flash.h:

      ...

      #define FLASH_Sector_9   ((uint16_t)0x0048) /*!< Sector Number 9   */
      #define
      FLASH_Sector_10   ((uint16_t)0x0050) /*!< Sector Number 10  */

      #define FLASH_Sector_11   ((uint16_t)0x0058) /*!< Sector Number 11  */
      #define FLASH_Sector_12   ((uint16_t)0x0080) /*!< Sector Number 12  */
      #define FLASH_Sector_13   ((uint16_t)0x0088) /*!< Sector Number 13  */
      ...


      However, there is a gap in an addressing between FLASH_Sector_11 and FLASH_Sector_12, maybe because of a flash banks border there.

      Once it will be reached, system will go to an infinite loop. Please see the following fragment from WICED/platform/MCU/STM32F4xx/WAF/waf_platform.c:


         for ( i = start_sector; i <= end_sector; i += 8 )

         {

             if ( FLASH_EraseSector( i, ERASE_VOLTAGE_RANGE ) != FLASH_COMPLETE )

             {

                 /* Error occurred during erase. */

                 /* TODO: Handle error */

                 while ( 1 )

                 {

                 }

             }

             platform_watchdog_kick( );

         }



      I propose to fix it by introducing an additional check by already provided CMSIS macro IS_FLASH_SECTOR():


         for ( i = start_sector; i <= end_sector; i += 8 )

         {

             if ( FLASH_EraseSector( i, ERASE_VOLTAGE_RANGE ) != FLASH_COMPLETE )

             {

                 if ( ! IS_FLASH_SECTOR( i ) )

                 {

                     continue;

                 }

                 /* Error occurred during erase. */

                 /* TODO: Handle error */

                 while ( 1 )

                 {

                 }

             }

             platform_watchdog_kick( );

         }


      Is it possible to change it to the following in a next WICED release? It will simplify a porting process.