0 Replies Latest reply on Nov 24, 2016 9:34 PM by nishal

    Flash erase error due to a bug in bootloader

    nishal

      Hi All,

       

      I was trying to do OTA upgrade on our custom hardware which has STM32F427. This Controller has 2MB of flash and 256KB of SRAM.

       

      Hence this controller has 24 Flash sector, (0-23). It is found in the data sheet  of STM32F4 that few address are not flash sector address, but the waf_bootloader was trying to erase the sectors without checking for the this condition.

       

      I am attaching the code here with this fix.

       

       

       

      platform_result_t platform_erase_flash( uint16_t start_sector, uint16_t end_sector )

      {

          uint32_t i;

       

          /* Unlock the STM32 Flash */

          FLASH_Unlock( );

       

          /* Clear any error flags */

          FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR );

       

          platform_watchdog_kick( );

       

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

          {

          /*Erase the sector only if the Sector is a valid sector address*/

         if(IS_FLASH_SECTOR(i))                            //Check required.

          {

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

        {

        /* Error occurred during erase. */

        /* TODO: Handle error */

        while ( 1 )

        {

        }

        }

          }

              platform_watchdog_kick( );

          }

       

       

          FLASH_Lock( );

       

       

          return PLATFORM_SUCCESS;

      }

       

      Hope this will be fixed in future SDK release, and help others who are using current SDK.

       

      Regards,

      Nishal