Bootloader jump problem

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

Moderator: RoccoMarco

Post Reply
kamil
Posts: 15
Joined: Mon Oct 13, 2014 10:32 pm

Bootloader jump problem

Post by kamil »

I wrote and bootloader using Chibios 3.0.x and an application using Chibios 3.0.x too (app1) and everything works fine: bootloader flahses and jumps to application.
But now i have to flash apllication written using just CMSIS and some st libraries (app2) and I have a problem. Application flashes fine but bootloader can't jump to the app2 correctly.
bootloader starts from 0x08000000 and app1 and app2 starts from 0x08008000. Microcontroller is stm32f407ig.

The app2 uses Keil compiler. To prepare the app2 to new address base I made following things:
1. set VECT_TAB_OFFSET to 0x8000 in system_stm32f4xx.c file
2. in linker options set new fash range: IROM1: 0x08008000, 0xF8000
3. in st-link options add new flash rule to 0x08008000-0x080FFFF range
I thing that app2 is linked and flashed well, because if I starts app2 form st-link command line:

Code: Select all

ST-LINK_CLI.exe -c SWD -Run 0x00008000

Everything starts fine, and application works (interesting that command ST-LINK_CLI.exe -c SWD -Run 0x08008000 doesn't work).

I thing that problem is connected with vector table: If application is rather simple and doesn't use any interrupts:

Code: Select all

int main( void ) {
   pin p = {GPIOH, 3};
   gpio_init ( p, GPIO_MODE_OUTPUT, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO_PUPD_FLOAT );
   while(1) {
      u32 i = 0xFFFFFF;
      gpio_up(p);
      while(i--);
      i = 0xFFFFFF;
      gpio_down(p);
      while(i--);
   }
}

after jumping from bootloader it works fine, len on the PH3 is blinking.

I'm jumping using the following function:

Code: Select all

void flashJumpApplication(uint32_t address) {
   boardStop();

   typedef void (*pFunction)(void);

   pFunction Jump_To_Application;

   volatile u32* JumpAddress;
   const volatile u32* ApplicationAddress = (volatile u32*) address;

   JumpAddress = (volatile u32*) ApplicationAddress[1];

   Jump_To_Application = (pFunction) JumpAddress;

   chSysDisable();

   SCB->ICSR &= ~SCB_ICSR_PENDSVSET_Msk;

   int i;
   for(i=0; i<8; i++)
      NVIC->ICER[i] = NVIC->IABR[i];

   __set_MSP((u32) (ApplicationAddress[0]));
   Jump_To_Application();
}

found on some bootloader code based on chibios. I just add here boardStop() to stop any peripherals.

Does anybody have any idea, where is my mistake?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Bootloader jump problem

Post by Giovanni »

Have you initialize the NVIC register that points to the vectors table? (VTOR) assuming the library code is supposed to do that, is it really initialized?

Giovanni
kamil
Posts: 15
Joined: Mon Oct 13, 2014 10:32 pm

Re: Bootloader jump problem

Post by kamil »

Giovanni wrote:Have you initialize the NVIC register that points to the vectors table? (VTOR) assuming the library code is supposed to do that, is it really initialized?

Giovanni


Yes, it was a first that I check. VECT_TAB_OFFSET definition is responsible for it:
/* Configure the Vector Table location add offset address ------------------*/
#ifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
#else
SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */
#endif

FLASH_BASE is 0x08000000. VECT_TAB_SRAM is undefined. I think that it really inits correctly, because it is possible to tun application form 0x08008000 using st-link command line.

And I try to add

Code: Select all

SCB->VTOR = 0x08008000;

before jump, but it doesn't help.
kamil
Posts: 15
Joined: Mon Oct 13, 2014 10:32 pm

Re: Bootloader jump problem

Post by kamil »

Any ideas? Even most stupid?
I just don't know what to check next.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Bootloader jump problem

Post by Giovanni »

Could it be VTOR is re-initialized after you wrote it? are interrupts enabled? is basepri set to zero?

Giovanni
kamil
Posts: 15
Joined: Mon Oct 13, 2014 10:32 pm

Re: Bootloader jump problem

Post by kamil »

Well, I've found the problem.

I just run app2 using st-link and write the value of every control register and then run app2 from bootloader, and compare control register values with previous one.

Preblem is that when you run app2 form bootloader CONTROL register value is 0x0000006 (so it is fpu and psp is active). I just __set_CONTROL(0); and program starts correctly.

So, finnaly jump funciton is

Code: Select all

#define JUMP_TO(address)   boardStop(); \
                     int i; \
                     for(i=0; i<8; i++) \
                        NVIC->ICER[i] = NVIC->IABR[i]; \
                     __set_CONTROL(0); \
                     __set_MSP( (u32) (((u32*) address)[0]) ); \
                     ( (void (*)(void)) (((u32*) address)[1]) )();

Maybe it will help somebody.

Thanks Giovanni for help!
Post Reply