STM32f103VET6 Bootloader jump problem.

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

STM32f103VET6 Bootloader jump problem.

Post by franek.bmw »

Hello,
I am just writing my own bootloader for stm32f103vet6. I wanted to test jump to address of application. I have not yet written my app so I am testing that bootloader jump to its beginning (something like soft reset). I stop the OS like is described in http://www.chibios.org/dokuwiki/doku.ph ... os:stop_os , then I make a jump. Then bootloader start working from the beginning but after a while the stack overflow occurs. Chibiplugin indicates that the stack of main thread is overflow and the size of main stack is 0x000000. What is wrong in my code, that such an error occurs?
Below is a piece of code where I turn off the system and jumps.
Can somebody help me? Thank you very much in advance.

Code: Select all

      
void jump_to_app(void)
{
chThdTerminate(tp_error_handler);              /* Requesting termination.                  */
         chThdWait(tp_error_handler);                  /* Waiting for the actual termination.      */
         chThdTerminate(tp_led_display);              /* Requesting termination.                  */
         chThdWait(tp_led_display);          /* Waiting for the actual termination.      */
         chThdTerminate(tp_can_parser);     /* Requesting termination.                  */
         chThdWait(tp_can_parser);          /* Waiting for the actual termination.      */
         chThdTerminate(tp_can_tx);     /* Requesting termination.                  */
         chThdWait(tp_can_tx);          /* Waiting for the actual termination.      */
         chThdTerminate(tp_load_bargraph);     /* Requesting termination.                  */
         chThdWait(tp_load_bargraph);          /* Waiting for the actual termination.      */
         chThdTerminate(tp_leds_handler);     /* Requesting termination.                  */
         chThdWait(tp_leds_handler);

         canStop(&CAND1);

         if(!((GPTD2.state == GPT_STOP) || (GPTD2.state = GPT_READY)))
         {
            gptStop(&GPTD2);
         }
         sdStop(&SD1);

         chSysDisable();

         SysTick->CTRL = 0; //disable SysTick

         chSysEnable();

         jumpToUser(0x08000000);
}


jumpToUser function code:

Code: Select all

void jumpToUser(uint32_t address) {

  typedef void (*pFunction)(void);

  pFunction Jump_To_Application;

  /* variable that will be loaded with the start address of the application */
  vu32* JumpAddress;
  const vu32* ApplicationAddress = (vu32*) address;

  /* get jump address from application vector table */
  JumpAddress = (vu32*) ApplicationAddress[1];

  /* load this address into function pointer */
  Jump_To_Application = (pFunction) JumpAddress;

  /* Clear pending interrupts just to be on the safe side*/
  SCB_ICSR = ICSR_PENDSVCLR;

  /* Disable all interrupts */
  uint8_t i;
  for(i=0; i<8; i++)
    NVIC->ICER[i] = NVIC->IABR[i];

  /* set stack pointer as in application's vector table */
  __set_MSP((u32) (ApplicationAddress[0]));
  Jump_To_Application();
}
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32f103VET6 Bootloader jump problem.

Post by Giovanni »

Hi,

Have you relocated the vectors table in the loaded application? You can redefine CORTEX_VTOR_INIT in chconf.h.

Giovanni
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: STM32f103VET6 Bootloader jump problem.

Post by franek.bmw »

I have to do this even I jump from bootloadet to bootloader?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32f103VET6 Bootloader jump problem.

Post by Giovanni »

You have to do this if your vectors table does not start from address zero.

Giovanni
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: STM32f103VET6 Bootloader jump problem.

Post by franek.bmw »

I make this definition in chconf.h
#define CORTEX_VTOR_INIT 0x08000000

0x08000000 is also my app address where I want to jump.

Stack overflows still occure :(

Franek
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32f103VET6 Bootloader jump problem.

Post by Giovanni »

I have no elements to help.

You posted some code but the problem likely is in the memory organization and C runtime initialization.

Giovanni
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: STM32f103VET6 Bootloader jump problem.

Post by franek.bmw »

Which file I should posted?
I am using demo project from ChibiOS_2.6.7/demos/ARMCM3-STM32F103 where I change in makefile only linker script from STM32F103xB.ld to STM32F103xE.ld.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32f103VET6 Bootloader jump problem.

Post by Giovanni »

franek.bmw wrote:Which file I should posted?


I could answer this if I knew where the problem is...

If you jump to the reset address and then it fails then there must be something you did not de-initialize. Are stacks re-initialized correctly?

Giovanni
franek.bmw
Posts: 57
Joined: Thu Mar 13, 2014 11:15 am
Has thanked: 2 times

Re: STM32f103VET6 Bootloader jump problem.

Post by franek.bmw »

How to check it?


I modeled on that project as well https://github.com/fpoussin/ChibiOS-Boo ... loader_app . The difference is that I do not jump to the beginning of the application but to the beggining of the bootloader.

Franek
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32f103VET6 Bootloader jump problem.

Post by Giovanni »

Placing breakpoints into the startup file and verifying that everything is as expected.

Inspecting stack after the crash could also give hints.

Giovanni
Post Reply