AnsweredAssumed Answered

Custom bootloader STM32F405VG

Question asked by Alex on Nov 26, 2016
Latest reply on Dec 2, 2016 by Alex

I'm working in a custom bootloader. I have follow many discussions here and then i end up with this code.
commenting the function PerformFirmwareUpdate() the code works ok!  

     pFunction appEntry;
     uint32_t appStack;
     /* Get the application stack pointer (First entry in the application vector table) */
     appStack = (uint32_t) *((__IO uint32_t*)EXEC_ZONE_ADDR);

     /* Get the application entry point (Second entry in the application vector table) */
     appEntry = (pFunction) *(__IO uint32_t*) (EXEC_ZONE_ADDR);// + 4);

     if (CheckFirmwareUpdate)
     /* Reconfigure vector table offset register to match the application location */

     /* Set the application stack pointer */

     /* Start the application */

when i uncomment the function which copies the program in the execution sector (5), then i get the problem:
the appEntry gets the value of sector 6 instead of sector 5 which is the real value assigned.

void PerformFirmwareUpdate(void)
     if (FlashErase(FLASH_SECTOR_5))//(FLASH_SECTOR_5);
          uint32_t *data_ptr = (uint32_t *)PROG_ZONE_ADDR;
          for(uint32_t i = 0; i < (SECTOR_SIZE); i += sizeof(uint32_t), data_ptr++ )
               if(HAL_FLASH_Program(FLASH_TYPEPROGRAM_WORD, EXEC_ZONE_ADDR + i, *data_ptr) != HAL_OK)
               { //WORD = 32bits
               FLASH_WaitForLastOperation (4000); //in ms, max time to erase whole sector; see datasheet

Thanks to all, I hope someone could help me with this!