cancel
Showing results for 
Search instead for 
Did you mean: 

How to Jump,correctly, to application on a bootloader?

CopaCabana_ Reemer
Associate II

Hi,

I'm using the STM32H743 Nucleo Board, to development a bootloader code with USB_MSC, I based my code on the "STM32H743I_EVAL" this is the address to the file "STM32H743I_EVAL\Applications\USB_Host\FWupgrade_Standalone" and everything work good, at the end of the process i can see the exactly hex code, what I donwloaded on my Pen Drive, in the flash memory.

But the problem is, when reset the code with NVIC_SystemReset() ,the Jump Function don't work, and really dont know why, I suppose it is something about the interrupt vectors or the deincialisations that must be done before, however I dont know what I need to do.

I saw this post https://community.st.com/s/question/0D50X00009hmVzpSAE/stm32h743-is-there-a-different-handling-for-code-entry-points-compared-to-stm32f4-stm32f7?t=1544011706860 who GS@G said that we need to enable the interrupts on "the other side", can't understand this.

I'm use 0x08020000 to APPLICATION_ADDRESS, and this jump code to:

int main ()

{

FLASH_If_FlashUnlock();

// SysTick->CTRL = 0x000;

// SysTick->LOAD = 0x000;

// SysTick->VAL = 0x000;

// SCB->VTOR  = APPLICATION_ADDRESS;

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

if ( ( JumpAddress & 0x2FFE0000) == 0x20320000)//0x20000000

{

/* Jump to user application */

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

Jump_To_Application = (pFunction) JumpAddress;

/* Initialize user application's Stack Pointer */

__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);

Jump_To_Application();

}

MPU_Config();

CPU_CACHE_Enable();

HAL_Init(); ...

}

If anyone can help, I would be grateful. Thanks.

6 REPLIES 6

Is the Initial SP really up around 0x2032xxxx ?

>> we need to enable the interrupts on "the other side", can't understand this.

If you disable interrupts on the processor before you call, they don't magically get re-enabled, you actual have to enable them again.

What do you learn from debugging, and stepping through the code?

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

I could watch until the flash memory was filled, and I could see that , the Initial SP up around 0x2032xxxx, I could also see, that before entering jump Function the variable JumpAddress receives "0x3032303a" and when entering, the variables JumpAddress and JumpApplication receive the value of "0x30303030" after that the program makes the jump and I can not companion, just rebuild the program and clean the flash start again.

I need to make the interrupts enable in my new code or inside of jump function?

You're not writing the ASCII HEX file into memory right? You need to decode it the machine isn't running ASCII

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

Yes, Clive you were right. In my application I was writing the ACII HEX direct without decode this kind of file.I've made this modification and now everything seems to work correctly, the initial SP up around is "0x20000000" and JumpAddress gets "0x80002ad", but still jumps and does not work. In flash memory, the code is the same as in my file.

I'm using the IDE "System workbench for STM32" and after jump if I stop the debug, show this "No source available for "__do_global_dtors_aux() at 0x80002ac" ".I suppose the jumping address is incorrect right?? Can I make this test in debug mode?

You need the linker to build the code for the 0x08020000, so in the scatter file, linker script, or via user interface.

The code in SystemInit() also needs to set SCB->VTOR to point at the vector table.

In the Keil debugger I can debug the loader side, for the app I need to load that, and have the boot loader code drop though allowing the debugger to "run to main()" on the app side. I'd try the loader side first and step through the transition first, will switch to a disassembly view but trying to prove it enters the code in startup_stm32xxxx.s and how deep it goes.

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

Hi, thanks for your time and pacient to reply all this questions, because i saw that you reply almost all questions and I like it and I think it's very good for our community.

For my problem now everything works good:

1º - Hadn't made the necessary modifications to not overwrite the bootloader in flash on the application code, so i had to start the application code in 0x08020000 in my case, and set the SCB->VTOR to 0x08020000. The strangest thing is that if i just modify that define to "

2º - i modified my linker script,on my bootloader code to separate the flash, then set this:

MEMORY
{
DTCMRAM (xrw)    : ORIGIN = 0x20000000, LENGTH = 128K
RAM_D1 (xrw)     : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw)     : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw)     : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw)    : ORIGIN = 0x00000000, LENGTH = 64K
FLASH (rx)       : ORIGIN = 0x08000000, LENGTH = 2048k
}
 
/* Define output sections */
SECTIONS
{
  /* The startup code goes first into FLASH */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH
...

to this:

MEMORY
{
DTCMRAM (xrw)    : ORIGIN = 0x20000000, LENGTH = 128K
RAM_D1 (xrw)     : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw)     : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw)     : ORIGIN = 0x38000000, LENGTH = 64K
ITCMRAM (xrw)    : ORIGIN = 0x00000000, LENGTH = 64K
FLASH (rx)       : ORIGIN = 0x08000000, LENGTH = 128k
APPLICATION (rx) : ORIGIN = 0x08020000, LENGTH = 2048k - 128k
}
 
/* Define output sections */
SECTIONS
{
  /* The startup code goes first into FLASH */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector)) /* Startup code */
    . = ALIGN(4);
  } >FLASH

Thank for everything.