cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with STM32L4A6AGIXP – Jumping from custom bootloader to application

REldo.1
Associate II

Hello, I've wrote a custom bootloader on address 0x8000000, that after few seconds from system booting, the bootloader will jump to address 0x8008000 and the user application that I've flashed to this area (from address 0x8008000) should be executed properly. The custom bootloader that is the main flash address (0x8000000) looks like this:

In main.c file of the custom-bootloader:

 

if (HAL_GetTick() > 5000)

{

    flash_jump_to_app();

    break;

}

typedef void (*fnc_ptr)(void);

void flash_jump_to_app(void)

{

  // __disable_irq();

  /* Function pointer to the address of the user application. */

  fnc_ptr jump_to_app;

  jump_to_app = (fnc_ptr)(*(volatile uint32_t*) (0x08008000+4u));

  HAL_DeInit();

  /* Change the main stack pointer. */

  __set_MSP(*(volatile uint32_t*)0x08008000);

  jump_to_app();

}

In STM32L4A6AGIXP_FLASH.ld file of the custom-bootloader:

/* Memories definition */

MEMORY

{

  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 320K

  RAM2    (xrw)    : ORIGIN = 0x10000000,   LENGTH = 64K

  FLASH    (rx)    : ORIGIN = 0x8000000,   LENGTH = 1024K

}

 

And in the STM32L4A6AGIXP_RAM.ld file of the custom-bootloader:

/* Memories definition */

MEMORY

{

  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 320K

  RAM2    (xrw)    : ORIGIN = 0x10000000,   LENGTH = 64K

  FLASH    (rx)    : ORIGIN = 0x8000000,   LENGTH = 1024K

}

 

In order to simplify the problem, the user application looks like this:

In main.c file of the user application:

 

  /* USER CODE BEGIN WHILE */

//  _enable_irq();

//   SystemInit();

while (1)

{

global_app_cntr++;

//   HAL_Delay(100);

//   numOfTicks = HAL_GetTick();

 

    /* USER CODE END WHILE */

 

    /* USER CODE BEGIN 3 */

}

 

 

In STM32L4A6AGIXP FLASH.ld file of the user application:

 

/* Memories definition */

MEMORY

{

  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 320K

  RAM2    (xrw)    : ORIGIN = 0x10000000,   LENGTH = 64K

  FLASH    (rx)    : ORIGIN = 0x8008000,   LENGTH = 1024K

}

And In STM32L4A6AGIXP RAM.ld file of the user application:

/* Memories definition */

MEMORY

{

  RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 320K

  RAM2    (xrw)    : ORIGIN = 0x10000000,   LENGTH = 64K

  FLASH    (rx)    : ORIGIN = 0x8008000,   LENGTH = 1024K

}

 

The main application works fine, but if I'll uncomment the 'HAL_Delay(100);' line, the 'global_app_cntr' counter will not counts up and code will stuck. If instead, I'll uncomment the 'numOfTicks = HAL_GetTick()' line, the 'global_app_cntr' counter will count up, but numOfTicks will remains 0 (uint32_t numOfTicks = 0).

 

 

 

If I'll change the flash origin address in the 'STM32L4A6AGIXP FLASH.ld' and 'STM32L4A6AGIXP RAM.ld' files to 0x8000000, the application version will work properly (running It without calling from the custom bootloader). Writing _disable_irq() in the flash_junp_to_app() function at my bootloader code, and _enable_irq() and SystemInit() in the application app, did not solved the problem.

What else can be done, in order to make the main application running correctly after jumping to its address, from the bootloader at the beginning, on MCU startup.

 

Thanks a lot, and Best Regards,
Ran

3 REPLIES 3
MM..1
Chief II

Your app need next one change set vector offset 8000 in system startup file.

Imen.D
ST Employee

Hello @REldo.1 ,

I recommend following this article to achieve your goal:  How to jump to system bootloader from application.

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
REldo.1
Associate II

Thanks all, I'll try it.