2017-06-21 01:43 AM
Many thanks
2017-06-21 08:26 AM
Hi, Denis!
Your need is just a small part of IAP (In application programming)...
That is fairly easy, you just need to build up two projects with separate ROM.
For example, if I am using L011K4T6. This is lovely little fellow has 16KB(0x4000) Flash.
Suppose I need to separate this ROM into 2 applications equally. (8KB for each)
You may build your first project (in your project setting) with ROM map starts from 0x80000000 with Size 0x2000;
Similarly, build your second project with ROM start from 0x80002000 with Size 0x2000;
Finally you may build a simple mechanism to jump from 1st application to 2nd application.
For that, you may use following ST style codes (extracted from IAP example codes)
(For 1st application to jump to 2nd application)
/* APP2 Address */
#define APPLICATION2_ADDRESS (uint32_t)0x08002000
typedef void (*pFunction)(void);
pFunction JumpToApplication;
static uint32_t JumpAddress;
...
...
...
if(your external signal on)
{
JumpAddress = (__IO uint32_t*) (APPLICATION2_ADDRESS + 4);
JumpToApplication = (pFunction)JumpAddress;
__set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS);
JumpToApplication();
}
else
{
/*stay in 1st application*/
}
Hope you like this!
2017-06-24 01:19 PM
Hi and many thanks for your reply.
My function in the follow:[code]void MainClass::FlashJumpTo() {
typedef void(*pFunction)(void); pFunction JumpToApplication; uint32_t JumpAddress= *(__IO uint32_t*)(FLASH_APPLICATION_BEGIN+ 4); JumpToApplication= (pFunction)JumpAddress; __set_MSP(*(__IO uint32_t*)FLASH_APPLICATION_BEGIN); JumpToApplication();}[/code]When I run it nothing happens. After a while the watchdog resets the microcontroller but the firmware running is still the firmware of my microcontroller.Have you got any idea?2017-06-25 08:54 AM
You may first turn off the watchdog for testing purpose.
But have you already programmed your second application in the flash at
FLASH_APPLICATION_BEGIN?
Make some outputs to indicate that the 2nd application is running, like blinking a led or print a message to console.
What stm32 you are using?
2017-06-25 09:27 AM
Isn't be easier to have just single program with two applications inside to avoid tricks with compilation of two programs in differen ROM regions, etc. I guess for simple apps it should work:
int testExternalSignal(void)
{
// put the code to test external pin to select specific app
return X // 1 for the first app, 2 for the 2nd app
}
void firstApp(void)
{
}
void secondApp(void)
{
}
int main(void)
{
if(testExternalSignal()==1)
{
firstApp();
}
else
{
secondApp();
}
}
2017-06-25 11:07 AM
I'm sure that at FLASH_APPLICATION_BEGIN there is the firmware of the second application. I'm a little bit unsure if i have built it this the right rom parameter.
But if there is or not an application at FLASH_APPLICATION_BEGIN the bootloader should run it or to die? Is it right?But the bootloader goes only to freeze and the bootloader watchdog (still alive) resets the micro.2017-06-25 08:20 PM
I think you really should turn off your Watch dog first for testing purpose.
If your second app does NOT start at you
FLASH_APPLICATION_BEGIN address, the watch dog surely reset your core.
If your second app starts and this app doesn't reset the Watch dog immediately, the watch dog reset your core too.
I am not sure why you want to do this, it would be cumbersome if you have to maintain two different projects.
(Not to mention later how you want to program them into your flash: merge these hex files and program once or simply program twice)
Nevertheless,
please take a look at
and
http://www.st.com/en/embedded-software/x-cube-iap-usart.html
There are necessary ingredients you need to achieve your need.
(Developers build their their own boot loaders using this simple trick )
Or you just tell me your STM32 Series,
I think I can easily setup a simple demo for you.(If I have similar STM32 at hands)
Zt.
2017-06-26 12:12 AM
Many thanks.
The last question: when the bootloader starts the app and the app runs, the bootloader is still in action?2017-06-26 02:33 AM
Should not anymore in action.