cancel
Showing results for 
Search instead for 
Did you mean: 

How to customize startup file?

trieunguyen
Associate II

I am a newbie in embedded programming. My idea is to build 3 applications with 3 separate project file. These 3 applications will work together in 1 CPU as shown in the image below:

trieunguyen_0-1722178081604.png

To jump from App to another APP, I do the same way bootloader jumps to application:

 

#define ADDR_APP_2_PROGRAM 0x08120000
#define ADDR_APP_3_PROGRAM 0x08140000

typedef void (*pJumpFunc)(void);
pJumpFunc	Jump_To_App;

void Jum_To_APP_2(void);

int main(void)
{
	Jum_To_APP_2();
}

void Jum_To_APP_2(void)
{
	Jump_To_App = (pJumpFunc)*(volatile uint32_t*)(ADDR_APP_2_PROGRAM + 4);
	
//	__disable_irq();
	__set_MSP(*(volatile uint32_t*) ADDR_APP_2_PROGRAM);
	Jump_To_App();
}

 

Jump from one application to another was successful. But the obvious problem here is that data segment initializers copy from flash to SRAM of APP_2 and APP_3 will be performed repeatedly in a loop. I thought of a few ideas like: skipping the copy instructions in the startup code from the 2nd loop onwards, but I'm stuck. I don't find any commands related to _sdata, _sidata... or bss in the startup file generated by STM32CubeMX.  Is there some hidden code associated with the current startup file? Can I create a custom startup file to replace the current startup file?

If you can I would love for you to give me an idea! Thank you very much!

(I'm using Keil.I used the label STM32CubeIDE because I couldn't find a more suitable label.)

15 REPLIES 15
MM..1
Chief II

Try explain more. If you  plan more MCU work together, then seems APP1 is run only once then waste MCU here...

And memory can be set as NOINIT then stay as is when MCU is powered...

Yes, APP_1 only runs once, then APP_2 and APP_3 will form an infinite loop. In each main function of each APP there is no while (1) loop. All apps are in only 1 CPU.
I am using Keil, I have successfully made the jump from APP to APP but I can't find a way to customize the startup code.

TDK
Guru

The default startup file generated by CubeMX initializes SRAM appropriately and uses the _sdata and similar variables. For example, here is an excerpt:

TDK_0-1722189601254.png

The startup file is typically named startup_stm32*.s

 

You can, of course, modify the startup file however you want as long as you do the necessary things inside of it.

 

Edit:

The _sdata and similar get defined in the linker file, which depend on the sections you define in there. Maybe that's what you're missing. You'll have to ensure the sections for each program do not overlap at all, then it should just work.

Seems a whole lot easier to make one program rather than 3. But the scheme is certainly doable.

If you feel a post has answered your question, please click "Accept as Solution".
Pavel A.
Evangelist III

 I thought of a few ideas like: skipping the copy instructions in the startup code from the 2nd loop onwards, 

But APP_2 and APP_3 run in turns. You must allocate separate data areas for APP_2 and APP_3 else they will overwrite data of the other app. If their summary data size does not fit in the physical RAM, you'll need to save the data of one app before jumping to another.

 

I am really sorry for the omission in my post that I forgot to mention that I am using Keil I used the label STM32CubeIDE because I couldn't find a more suitable label.

Thank you for the valuable information for me. I found them in Cube IDE. However, in Keil there is no linker file, instead I found a scatter file. Maybe it is not possible to create branch conditions in the scatter file?? Can I create a linker file to replace the scatter file?

One of the main reasons why I combined 3 programs instead of 1 was because an important requirement was simplicity, while using Cube IDE is quite complicated!

Yes, I have allocated separate memory areas for each application.

When u use one MCU you here waste your and us time. Create one project.

Maybe it is not possible to create branch conditions in the scatter file??

In your code snippets above, no changes in linker or scatter files were needed. Just set correct ROM and RAM addresses for each app in Keil project options and you're done.

I'm sorry for wasting your time! I will take care to phrase my question better.