cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 custom bootloader problem

giovani
Associate II
Posted on June 14, 2016 at 14:38

Hello!

I am working in a project that I want to use a custom bootloader for firmware update of stm32f407, I had developed for stm32f107 and all works fine, but for STM32F407 I getting some problems.

Below I posted the source code of the bootloader, debugging this code when execute this line ''if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)    '' always return 0, I don't know why this occur because in application firmware I defined ''&sharpdefine VECT_TAB_OFFSET  0x8000'' all looks correct but never enter if condition and execute Jump_To_Application.

On Flash address (0x80E0000) is located the firmware for update the firmware on address (0x8008000).

Bootloader.c

&sharpdefine ApplicationAddress    (0x8008000)

&sharpdefine ApplicationAddress_Firmware  (0x80E0000)

typedef  void (*pFunction)(void);

uint32_t JumpAddress;

pFunction Jump_To_Application;

/*----------------------------------------------------------------------------

  Main Thread 'main': Run Network

 *---------------------------------------------------------------------------*/

int main (void) {

    uint8_t* App_ptr;

    SystemClock_Config();//initialize clocks

        BKP_Init();

    if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR6) == 0xA5A5){    

    

        if (((*(__IO uint32_t*)ApplicationAddress_Firmware) & 0x2FFE0000 ) == 0x20000000)                                                                                                                                

        {

            /* Jump to user application */

            JumpAddress = *(__IO uint32_t*) (ApplicationAddress_Firmware + 4);

            Jump_To_Application = (pFunction) JumpAddress;

            App_ptr = (uint8_t*)Jump_To_Application;

            

            if( (*App_ptr != 0xFF) &&  (App_ptr) )

            {                 

                /* Initialise user application's Stack Pointer */

                __set_MSP(*(__IO uint32_t*) ApplicationAddress_Firmware);        

                

                Jump_To_Application();

            }

        }  

    }else{

        if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)                                                                                                                                

        {

            /* Jump to user application */

            JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);

            Jump_To_Application = (pFunction) JumpAddress;

            App_ptr = (uint8_t*)Jump_To_Application;

            

            if( (*App_ptr != 0xFF) &&  (App_ptr) )

            {                 

                /* Initialise user application's Stack Pointer */

                __set_MSP(*(__IO uint32_t*) ApplicationAddress);        

                

                Jump_To_Application();

            }

        }

    }

    

}

Another think is the Scatter file looks good.

Bootloader Scatter File

; *************************************************************

; *** Scatter-Loading Description File generated by uVision ***

; *************************************************************

LR_IROM1 0x08000000 0x00007FFF  {    ; load region size_region

  ER_IROM1 0x08000000 0x00007FFF  {  ; load address = execution address

   *.o (RESET, +First)

   *(InRoot$$Sections)

   .ANY (+RO)

  }

  RW_IRAM1 0x20000000 0x00020000  {  ; RW data

   .ANY (+RW +ZI)

  }

  RW_IRAM2 0x10000000 UNINIT 0x00010000  {

   .ANY (+RW +ZI)

  }

}

Application Scatter File

; *************************************************************

; *** Scatter-Loading Description File                         ***

; *************************************************************

LR_IROM1 0x08008000 0x000D7FFF  {    ; load region size_region

  ER_IROM1 0x08008000 0x000D7FFF  {  ; load address = execution address

   *.o (RESET, +First)

   *(InRoot$$Sections)

   .ANY (+RO)

  }

  RW_IRAM1 0x20000000 0x00020000  {  ; RW data

   .ANY (+RW +ZI)

  }

  RW_IRAM2 0x10000000 UNINIT 0x00010000  {

   .ANY (+RW +ZI)

  }

}

Thanks,

Giovani

#stm32-stm32f4-bootloader
10 REPLIES 10
Posted on June 15, 2016 at 21:07

The code in __main, not your main(), unpacks the load regions as described in the scatter-file, derived from your GUI settings. The code in SystemInit() needs to enable whatever clocks, and memory interfaces, you expect the C runtime to copy/zero statics into.

You have already used the CCM (0x10000000) region for your stack, so I assume it's probably working right off the bat. It is not going to be usable for DMA operations.

I'd recommend you step-into the code, and look at what memory it is zeroing and copying, and contrast that to the memory areas it is describing in the .MAP. Look at what it is actually faulting against, I'd strongly recommend coding a proper Hard Fault Handler to decompose the faulting state, and review that. (See Joseph Yiu)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..