Electrical – bootloader jump to application address problem

armbootloadercortex-m3keilstm32

I have written a bootloader for my board, but it generates a hard fault when it jumps to the application code.

My error is like this question:

Bootloader jump to main application problem using STM32 with Keil Uvision

  • microcontroller: stm32f103zet
  • software: keil
  • BOOT pins: BOOT1 and BOOT2 are 0 (FLASH boot mode)
  • FLASH_WRITE_ADDRESS: 0x8030000

I did this steps:
in application code:

  1. I changed ROM address to 0x8030000.
  2. I changed VECT_TAB_OFFSET to 0x30000
  3. I used of fromelf for creating .bin file

then I wrote a simple code (blinky)

in bootloader code:
i receive .bin file with USART and then i write it to address 0x8030000 of FLASH
and The following code:

USART_DeInit(USART1);
RCC_DeInit();

__set_CONTROL(ENABLE_PRIVILEGE_MODE);

NVIC->ICER[ 0 ] = 0xFFFFFFFF ;
NVIC->ICER[ 1 ] = 0xFFFFFFFF ;
NVIC->ICER[ 2 ] = 0xFFFFFFFF ;

NVIC->ICPR[ 0 ] = 0xFFFFFFFF ;
NVIC->ICPR[ 1 ] = 0xFFFFFFFF ;
NVIC->ICPR[ 2 ] = 0xFFFFFFFF ;

SysTick->CTRL = 0 ;
SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk ;

SCB->SHCSR &= ~( SCB_SHCSR_USGFAULTENA_Msk |
                                SCB_SHCSR_BUSFAULTENA_Msk | 
                                SCB_SHCSR_MEMFAULTENA_Msk );

__disable_irq();

if( CONTROL_SPSEL_Msk & __get_CONTROL( ) )
{  /* MSP is not active */
    __set_MSP( __get_PSP( ) ) ;
    __set_CONTROL( __get_CONTROL( ) & ~CONTROL_SPSEL_Msk ) ;
}

JumpAddress=(FLASH_WRITE_ADDRESS+4);
JumpToApplication =(void(*)(void))(*((uint32_t*)JumpAddress));
__set_MSP(*(__IO uint32_t*)FLASH_WRITE_ADDRESS);
JumpToApplication();

But it goes to hardfault.
So now I use this part of the code:

/* Jump to user application */
JumpAddress = *(volatile uint32_t*)(FLASH_WRITE_ADDRESS+4);
JumpToApplication = (pFunction) JumpAddress;
__set_MSP((*(volatile uint32_t*) FLASH_WRITE_ADDRESS));
now_pointer=__get_MSP();
JumpToApplication();

but it is the same as before.
What is problem?

This is one second before jump to application code:

And this is result of jump to application code:

okey.now,i find and solve problem:
i put my writing in FLASH mistake picture:
i not regarding little endian writing in FLASH

Best Answer

Most likely you use the standard start-up code from the STM in the user application. Is sets VTOR to the begining of the FLASH memory. Remove this line and it should work