cancel
Showing results for 
Search instead for 
Did you mean: 

Bootloader Problem with STM32F4

QUANG Nguyen
Associate
Posted on January 31, 2017 at 15:33

Hello guys,

I have problem with bootloader on STM32F427xx.  

Bootloader: 0x08000000 ---128Kb

APP:          0x08020000 ----512Kb

In Linker Script for App, the ResetHandler located at 

.start 0x08020200 :

{

. = ALIGN(4);

KEEP(*(.start)) /* Startup code */

. = ALIGN(4);

} > FLASH

but when I tried to executed these:

#define APPLICATION_ADDRESS (0x08020000UL)

pFunction Jump_To_Application;

uint32_t JumpAddress;

SCB->VTOR = FLASH_BASE | 0x20000;

/* Initialize user application's Stack Pointer */

__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

/* Jump to user application */

JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4 + 0x200);

Jump_To_Application = (pFunction) JumpAddress;

Jump_To_Application();

I couldn't jump into App section. 

Can you help me pls, thanks!

PS: I use Jlink Debugger.

3 REPLIES 3
Sean Park
ST Employee
Posted on February 01, 2017 at 00:57

I tested it with the code above and it works fine.

#define APPLICATION_ADDRESS   (uint32_t)

0x08020000

//

Bootloader 

Test code

{

   printf('\n\n JUMP USER FW -->\n');

   /* Test if user code is programmed starting from address 'APPLICATION_ADDRESS' */

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

   {

      /* Jump to user application */

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

      JumpToApplication = (pFunction) JumpAddress;

      /* Initialize user application's Stack Pointer */

      __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

      JumpToApplication();

   }

}

// Application

Test code

-> system_stm32f4xx.c    SystemInit() function   ( 

Application project )

    

VECT_TAB_OFFSET : The value needs to be modified in application project.

    #define VECT_TAB_OFFSET

0x20000

Please test it.

Posted on February 01, 2017 at 01:21

Why on earth do you have the +0x200 in there?

JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4 + 0x200);

You are loading an ADDRESS from the vector table, the ADDRESS should point to the ResetHandler

Also, this would be less ambiguous

SCB->VTOR = APPLICATION_ADDRESS;

If you are unsure about addresses you can print them out, or step the code with a debugger. You can look at the .MAP file of the APP to understand if you are going to the right functions

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
keaven
Associate II
Posted on February 02, 2017 at 16:44

I have a configuration similar to you with a custom flashloader located at 0x0802 0000 and my application at 0x0804 0000. The way I found easier for us is to reconfigure the option bytes and reset the CPU.

here is my function to do it

void StartIPLB2FlashLoaderCode(void)
{
 HAL_StatusTypeDef Status = HAL_ERROR;
 //Address = (<ADDR_BOOT_PIN_1> << 16) | <ADDR_BOOT_PIN_0>
 uint32_t Address = 0x00400088;
 //Clear Any Pending Flash Flags
 __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |\
 FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR| FLASH_FLAG_ERSERR); 
 
 if(HAL_FLASH_Unlock() == HAL_OK)
 {
 //Set Half-Word write operation
 FLASH->CR &= CR_PSIZE_MASK;
 FLASH->CR |= FLASH_PSIZE_HALF_WORD;
 HAL_FLASH_Lock();
 
 if(HAL_FLASH_OB_Unlock() == HAL_OK)
 {
 if(FLASH_WaitForLastOperation((uint32_t)FLASH_TIMEOUT_VALUE) == HAL_OK)
 {
 FLASH->OPTCR1 = Address;
 Status = HAL_FLASH_OB_Launch();
 }
 HAL_FLASH_Lock();
 }
 }
 
 if(Status == HAL_OK)
 {
 HAL_NVIC_SystemReset();
 }
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?