cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Keil V5 & RTX & Custom Bootloader

afduarte
Associate II
Posted on August 18, 2014 at 12:37

Hi all,

After some battle i was able to set a jump from my custom Bootloader to the App using in Keil V5.

Custom Bootloader resides in IROM 0x08000000

App resides in IROM 0x08020000

Need to set both mem addr in the Keil projects settings target and link.

Now the tricky bit is that Keil uses a block of mem @ the beginning of the specified mem addr to do some work. In the Bootloader app under debug in the Reset_Handler the __main pointer loaded to R0 will be not 0x08000000 but 0x080001AD instead of the expected 0x08000000.

So the BTL jump routine is:

      JumpAddress = 0x080201AD; // App addr offset + ''Keil offset''

      Jump_To_Application = (pFunction) JumpAddress;

      NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x20000); // App addr offset

      __set_MSP(*(__IO uint32_t*) 0x08020000); // Initialize user application's Stack Pointer

      Jump_To_Application();

Even changing considerably the BTL app the Keil offset still is 0x1AD, so i assume its static.

Im using the same clock and app settings in the BTL & in the App so i dont need to reconfigure anything in the App startup, so basically there is no ''startup sequence'' in the App.

Im using the RTX in the App, but not in the BTL, if i enable the RTX in the BTL, the jump fails.

If someone know more about this subjects, please post...

-> Exactly why Keil has this ''const'' addr offset ? Initiliazation of ZI-data ?

-> If you were able to perform a BTL jump with the RTX enable, please tell us how ...

-> Easier way ... Always good to know...

Thanks,

AD

#bootloader #stm32f4 #keil #rtx
3 REPLIES 3
afduarte
Associate II
Posted on August 18, 2014 at 13:30

Hi guys,

There are some errors in my first post, due to codding errors.

In fact if you set up your project like exposed, even with the RTX enable on the BTL and on the APP everything works.

Also i think that this initialization offset is actually due to the Keil SystemInit() method.

Soo good programming,

AD

Posted on August 18, 2014 at 17:41

The address you are referring too is ResetHandler, which calls SystemInit, and then __main, the __main function initializes the statics and jumps to your main()

Nothing calls 0x08000000, there are two key vectors there that indirectly transfer control to the reset code, the initial stack pointer (SP) is at +0, and the initial program counter (PC) is at +4. The address is ODD because it's 16-bit THUMB code
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
celdran
Associate II
Posted on September 26, 2014 at 09:43

Hi, I post here because the corresponding thread on the Keil Forum is closed.

http://www.keil.com/forum/16555/hardfault-hander-before-os-sys-init/

And I think it will help a lot of people who have problems to start RTX with the ST provided bootloader (USB standalone DFU v1.3.0).

I already have an application that runs RTX with a bootloader, without any problems. But the second version, with just USB and SD-Card drivers added, refuses to start RTX.

With the help I gathered on this forum, I put a custom hard fault handler to find out that the problem came from the rt_systick function.

After three days of hard faults, the system is starting properly by putting :

SysTick->CTRL &= ~1;

at the end of SystemInit function.

It will stop the Systick timer and let RTX configure it as it's needed.

However, I still don't know why the previous application, which is nearly identical, boots smoothly with the same bootloader.