cancel
Showing results for 
Search instead for 
Did you mean: 

How to jump to an application without reinit all previous initial modules

Ypinh.1
Associate III

Hello guys, First i would like to thank you about your products and all the knowledge you share from your rich experience with us, really appreciate and helpful.

I am using STM32L412RBPT evaluation board.

This MCU has only 1 bank in the nvm of 128KByte (64 pages * 2KByte per each)

i have in the nvm memory 2 different applications

first code is on page 0 which on address: (0x08000000)

this code makes init of all the modules i need in my project, such as nvic,clocks, rtc,rng,adc,timers,i2c,led... and more.

After the initialize i can use the modules successfully and all works.

when im done with the initial modules i perform jump to another application which in page 32 - address 0x08010000.

In this application in the first line of the main function i try to use those modules and i find out that several of them are not working such as rng,adc... and only init them again makes things works as well in application 2 same as in application 1

I would like to know how can i "bring" to application 2 the settings of all the initialized modules i performed in application 1.

Thanks for everyone!

9 REPLIES 9
Ypinh.1
Associate III

To be more clear:

i am using the board: NUCLEO-L412RB-P

the MCU is STM32L412RBPT

Pavel A.
Evangelist III

Do you use the "HAL" library? Perhaps what's happening is that the "main" application uses un-initialized "handle" structures:

// In bootloader:
 
UART_HandleTypeDef huart5;
 
void MX_UART5_Init(void)
{
  huart5.Instance = UART5;
  huart5.Init.BaudRate = 115200;
  //......... etc
  HAL_UART_Init(&huart5);
  }
 
 
// In main app:
UART_HandleTypeDef huart5;
HAL_UART_Transmit(&huart5, "junk\n", 5, 10); //OOPS! huart5 not initialized
 

>>I would like to know how can i "bring" to application 2 the settings of all the initialized modules i performed in application 1.

You'd have to have a common area where you store all the instances that you want to share so that the initialization, callbacks, interrupts etc can function.

You're current approach seems a bit beyond you're ability, so is it really a course of action you want to be taking? The HAL is more complex in this regard, than say the prior SPL, or using simpler bare-metal/register approaches.

What actually needs to be initialized by the loader? Clocks, pins, etc?

You'll need to come up with a plan on how you transfer ownership, and also how the linker reallocates RAM. You can partition RAM into different sections, or take some out of the view that the linker sees/uses for the application code.

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

Pavel thanks for reply!

It seems very logic what you said, i fixed 1 module thanks to you.

seems for me, that it will lead me to the right solution, thanks a lot!!

ill update if solved totally, soon!

MM..1
Chief II

I try understand your idea , but from my side this is one application not two.

Why you split?

Normal two app need thirdh or zero bootloader part, that invoke app1 or 2.

If you in both use complete same init peripherals, then why you dont write it as one app with more func?

Ypinh.1
Associate III

You right.

I didnt tell all the story because i wanted to explain the problem only.

So my real code is divided into 4 parts actually.

The Bootloader on page0 decide what application to jump according to some variables.

The difference between the app1 and app2 for example can be speed of blinking led.

and i dont want to init again the led peripheral as it already initialized before in address of 0x40..0 -> it means for me at least, that nothing should be changed on those all peripheral addresses when jumping because the user parts in the nvm is 0x080....0.

I understand now why its not working.

This is because in app2 i dont have the modules peripheral variables initialized as Pavel A and Tesla DeLorean wrote about.

But all those variables should be already in memory.

Thanks a lot for your reply!

i will try to use common area for all the instance i want to be known in both apps.

actually if i think about it bit more - common area for those instances,etc.. are actually on the memory where the registers locations -> so copying the contents from memory to the variables in app2 can make the job if im not missing something but it means init in another way (not helpful that much), bit confusing but ill think on it and update.

Thanks again

Piranha
Chief II

When in the future you will decide that you need a different configuration of peripherals, the application will have to deinitialize them and then initialize. Generally it's a bad design choice. The safest and most robust is for a bootloader to deinitialize everything to the default state.

Ypinh.1
Associate III

Thanks a lot Piranha i understand now the problematic method i use in my idea...