cancel
Showing results for 
Search instead for 
Did you mean: 

Scatter Brain

joe
Associate II
Posted on March 31, 2015 at 14:32

I have a bootloader which needs to read an 8 byte char array from the application area to identify it's version information. 

So bootloader is located at 0x08000000

Application firmware at :   0x08020000

the char array will look something like this:

const char software_versions[] = ''AB1234XY'';

I need the char array to be at a fixed location in the application section so the bootloader always knows where to point.

Is it as simple as:

const char software_versions[] __attribute((at(0x08021000)) = ''AB1234XY'';

or is there a neater way so fixed variables could have own section before main maybe. I'm not too well up on scatter files.

4 REPLIES 4
joe
Associate II
Posted on April 03, 2015 at 12:03

Sorry to be answering my own question but this might help someone else.

I found two methods to do what I wanted. Editing the startup .s file.

DCD FPU_IRQHandler ; FPU
DCD 0x0000000D

 ; Revision

DCB ''XYa0104b'' ; Version String
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors

This method just added the require fixed data to the end of the vector table. If you check the map file you can find the__Vectors_End address so you know the location of your data. The second method also requires you to know where the__Vectors_End address is (for my device STM32F4 vector end address is 0x08000188, 0x08020188 when using bootloader in first sector). Then you can use:

const unsigned int map_rev __attribute__((at(0x08020188))) = 13; 

const unsigned char code_rev[] __attribute__((at(0x0802018C))) = ''XYa0104b'';

somewhere in you code. You will need to keep the memory use word aligned. So use int for variables and if placing strings make sure is multiple of 4. You can then access the data using:

uint8_t my_rev = (*(const uint8_t *)((uint32_t)0x08020188));

if just want the fist byte of the map_rev

uint32_t other_rev = (*(const uint32_t *)((uint32_t)0x08020188));

to grab the whole word. Do the same for the string, just read and assign each byte individually.

So looks like no need to start playing around with scatter files. I think this method is safe? Anyone any thoughts?
AvaTar
Lead
Posted on April 03, 2015 at 12:39

Since I believe to recognise Keil syntax in your examples, I'd like to point you to the

http://www.keil.com/forum/

. You probably get much more response from people with first-hand knowledge of the Keil toolchain, including employees.

There is rarely enother forum in the embedded realm with less participation of the owner company's employees as this one here.

joe
Associate II
Posted on April 03, 2015 at 12:44

Hi argentum, thanks for the link. Much appreciated.

You right, the ST participation is quite lackluster which is a real shame.

AvaTar
Lead
Posted on April 03, 2015 at 13:37

You right, the ST participation is quite lackluster which is a real shame.

 

I sense some schizophrenia at ST's side here.

On one side, they attract hobbyists and students with cheap boards and free tools, and on the other side, they let them ''fight out'' their issues with ST's tools among themselves.

Put away two or three volunteering main posters (like clive1), and this forum is in effect dead ...