Skip to main content
Associate II
July 28, 2024
Question

How to customize startup file?

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.)

This topic has been closed for replies.

15 replies

MM..1
Super User
July 28, 2024

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...

Associate II
July 28, 2024

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
July 28, 2024

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""."
Associate II
July 29, 2024

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!

MM..1
Super User
July 29, 2024

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

Pavel A.
July 28, 2024

>  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.

 

Associate II
July 29, 2024

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

Andrew Neil
Super User
July 29, 2024

@trieunguyen wrote:

I am a newbie in embedded programming. My idea is to build 3 applications with 3 separate project file. .)


Why 3 separate apps?

It sounds like what you really have is just one application, with 3 modes.

That can easily be implemented as 3 functions:

do_app1_stuff();

while(1)
{
 do_app2_stuff();
 do_app3_stuff();
}

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate II
July 29, 2024

Well, if the ultimate goal is to implement a technological process, the simplest and most efficient way is to create an application. But 3 separate apps instead of one will allow members to work completely independently but still achieve a common goal.

Andrew Neil
Super User
July 29, 2024

You can easily do that without the unnecessary complication of 3 separate apps.

Each function can be implemented in its own separate (set of) file(s).

This is how most development is done - with various people/teams working separately on different parts of the one "app".

 


@trieunguyen wrote:

separate apps instead of one will allow members to work completely independently but still achieve a common goal.


Not completely independently - they still have to collaborate to bring the 3 apps together to run on the target!

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
Associate II
August 6, 2024

Thank you everyone! I solved this!

Andrew Neil
Super User
August 6, 2024

Good to hear.

For the benefit of others who may find this, please describe the solution, and mark it:

https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.