cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help for BootLoader in STM32F407xx

RR.7
Associate II

I am trying to implement bootloader code , that run an application code in STM32F407VGT6 micro controller. I have written two different codes one is bootloader and other is Application. My question is How two different code loading at different flash location. I have tried, but its not working. The bootloader code is flashed from Default start address and Application code is flashed by making Vector table value 0x8008000.(Also used download offset 8000)

But the two codes are not worked as expected. here I am attaching the two main.c files. 6KB file is bootloader and 5kb is app code. Anyone please help me to solve the issue

7 REPLIES 7

Use your debugger, step across the transition and understand what is failing, or where execution is going.

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

> But the two codes are not worked as expected.

Perhaps add more detail here. What behavior do you see and what are you expecting instead? Do both of them not work or just the application?

Note that you need to specify the start address in the linker script.

If you feel a post has answered your question, please click "Accept as Solution".
RR.7
Associate II

In the Boot loader code in addition to jump to application I have included Toggling Blue LED. In the Application code Toggling the Green LED. Loading these two programmes from 0x8000000 and 0x8008000 flash memory location, after reset only Blue LED is toggling. The application code is not executed.

In the Linker script I have also added start address as FLASH  (rx)  : ORIGIN = 0x8008000,  LENGTH = 992K (application code linker script)

Double check the .MAP to confirm where each is built.

Have the code in SystemInit() set SCB->VTOR to the vectors in the given builds

Make sure you disable SysTick before transitioning.

Have your ErrorHandler() and HardFault_Handler(), on both loader and application, functional and outputing actionable information so you can establish or diagnose an issue.

Use the Debugger, understand what's happening, it shouldn't be necessary to guess.

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

I have made following things

in SystemInit() (Application)

#define VECT_TAB_OFFSET     0x8000 
SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET;

In linker script (Application)

 MEMORY
{
 CCMRAM  (xrw)  : ORIGIN = 0x10000000,  LENGTH = 64K
 RAM  (xrw)  : ORIGIN = 0x20000000,  LENGTH = 128K
FLASH  (rx)  : ORIGIN = 0x8008000,  LENGTH = 992K
}

In CustomBootloader

void goto_APP(void)
{
  HAL_RCC_DeInit();
  HAL_DeInit();
  SysTick->CTRL = 0;
  SysTick->LOAD = 0;
  SysTick->VAL  = 0;
  if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == GPIO_PIN_SET)
  {
    /* Test if user code is programmed starting from APP_ADD address */
   if(((*(__IO uint32_t*)APP_ADD) & 0x2FFE0000 ) == 0x20000000)
    {
	   __disable_irq();
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (APP_ADD + 4);
      JumpToApplication = (pFunction) JumpAddress;
 
      /* Initialize user application's Stack Pointer */
      __set_MSP((*(__IO uint32_t*) APP_ADD ));
      JumpToApplication();
    }
  }
}

When the board is powered, from the bootloader it is not jump into the application code.

If you can't use the debugger, perhaps output to the serial port? Add output to follow the flow.

Print out the content of the first two vector of the app, or inspect the binary.

Is the stack in the CCMRAM ? You might need to change the test to reflect this possibility.

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

Could be this check failing in the code to jump to application

/* Test if user code is programmed starting from APP_ADD address */

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

RAM setting is 128KB (0x20000), so sp = 0x20020000,

Change the following and check APP_ADD) & 0x2FFB0000,

it should work.