Skip to main content
JFELI.13
Associate III
January 31, 2024
Solved

STM32 bin file at address 0x4

  • January 31, 2024
  • 16 replies
  • 4912 views

..

This topic has been closed for replies.
Best answer by Tesla DeLorean

This seems unnecessarily complex and laboured.

Typically you build an app for a specific address, via the linker. The Vector Table is part of the image. The SystemInit() code can set the address of SCB->VTOR based on the symbol the linker assigns the table in a given build. The application should and can be agnostic to the location it's built to live.

You put the Loader at 0x08000000, App1 at 0x08008000, App2 at 0x08020000, or however they need to space related to the size of the respective images and the space available in the FLASH. These BASE addresses are the only thing the Loader really needs to know.

The Vector Table contains the entry point (Reset_Handler) and you hand off control there.

It's also not hard to embedded length of image data in there too if need be.

Most of the CM3 from ST will want the vector table to live at a 512-byte boundary, but this depends on the size and total number of vectors, rounded to the next power of 2

The LINKER is DESIGNED to compute and solve placement problems, and fixate addresses, it can use and generate symbols, let it do the hard work by doing it's job.

16 replies

Andrew Neil
Super User
January 31, 2024

What about it?

:thinking_face:

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.
JFELI.13
JFELI.13Author
Associate III
January 31, 2024

"Small"  one
Small.jpg

Bigger one, at the same adress



Big.jpg

 

JFELI.13
JFELI.13Author
Associate III
January 31, 2024

And big soft has about 50ko lenght (at always start at 0x2B200)

JFELI.13
JFELI.13Author
Associate III
January 31, 2024

Sorry. Here the question :
I made a testing soft who start at 0x2B200
I notice than bin file has the (org address+1) at 0x04 
That's OK and I used it for controlling file.
But when the file increase in size I noticed value at 0x4 was now 0x35B29   !
What can I do for this ?

TDK
January 31, 2024

> What can I do for this ?

Why do you want to do something about it? What problem is it presenting?

That is the location of Reset_Handler within the binary.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JFELI.13
JFELI.13Author
Associate III
January 31, 2024

With the value of bin file at 0x4 , how do you calculate address to jum to ?

 

JFELI.13
JFELI.13Author
Associate III
January 31, 2024

Sorry for my keyboard.
I try again.
If my soft has a low size, I can calculate jump address will be (value at 0x4)-1
But if the soft is bigger, how do you calculate jump adress using 0x4 value ?

TDK
January 31, 2024

I don't understand why the value matters. The calculation is the same. (value at 0x04 - 1).

"If you feel a post has answered your question, please click ""Accept as Solution""."
JFELI.13
JFELI.13Author
Associate III
January 31, 2024

0x35B29-1=0x35B28, not 0x2B200 

Andrew Neil
Super User
January 31, 2024

What makes you think it should be 0x2B200 ?

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.
JFELI.13
JFELI.13Author
Associate III
January 31, 2024

If you need to understand why it's important, this is a part of bootloader:

#define PROG2_AD 0x2B200
#define PROG1_AD 0x400
#define PROG1_VECT_AD 0x300
#define PROG2_VECT_AD 0x200
...

pg1_Present=FALSE;
x4=PROG1_VECT_AD+4;
ptr=(unsigned long *)x4;
y4=*ptr-1; 

switch (y4)
{
case PROG1_AD:
pg1_Present=TRUE;
pgStop=PROG2_AD-1;
pg1_End=Flash_FindProgEnd(PROG1_VECT_AD);
pg_Size = pg1_End - PROG1_AD;
pg1_SizeKo=pg_Size / 1024;
pg1_PercentUse =(char)((pg_Size * 100) / (pgStop - PROG1_AD));
break;

default: 
break;
}

pg2_Present=FALSE;
x4=PROG2_VECT_AD+4;
ptr=(unsigned long *)x4;
y4=*ptr-1; 

switch (y4)
{
case PROG2_AD:
case 0x35B28: // if I add this line it will work at this time
pg2_Present=TRUE;
pgStop=BOOTLOADER_AD - 1;;
pg2_End=Flash_FindProgEnd(PROG2_VECT_AD);
pg_Size = pg2_End - PROG2_AD;
pg2_SizeKo=pg_Size / 1024;
pg2_PercentUse =(char)((pg_Size * 100) / (pgStop - PROG2_AD));
break;

default: // no soft
break;
}
IEE_ProgVect=IEEPROM_READ32(IEE_PGACTIVE_VECT); 

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
January 31, 2024

This seems unnecessarily complex and laboured.

Typically you build an app for a specific address, via the linker. The Vector Table is part of the image. The SystemInit() code can set the address of SCB->VTOR based on the symbol the linker assigns the table in a given build. The application should and can be agnostic to the location it's built to live.

You put the Loader at 0x08000000, App1 at 0x08008000, App2 at 0x08020000, or however they need to space related to the size of the respective images and the space available in the FLASH. These BASE addresses are the only thing the Loader really needs to know.

The Vector Table contains the entry point (Reset_Handler) and you hand off control there.

It's also not hard to embedded length of image data in there too if need be.

Most of the CM3 from ST will want the vector table to live at a 512-byte boundary, but this depends on the size and total number of vectors, rounded to the next power of 2

The LINKER is DESIGNED to compute and solve placement problems, and fixate addresses, it can use and generate symbols, let it do the hard work by doing it's job.

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