cancel
Showing results for 
Search instead for 
Did you mean: 

SPC5 studio - placing variables at fixed RAM addresses

alessandro2
Associate III
Posted on September 27, 2016 at 10:54

Hello everyone.

I�m working on a Bolero microcontroller (SPC560D40L3) using SPC5Studio and Hightec Compiler.

I have a question related to variables to be located in RAM.

I have a set of global variables, which I need to place in RAM, at fixed addresses.

How can I do that?

Is it sufficient to declare variable as pointers and initialize them with known values?

Are there ant attributes that can be used to force variables to be located at given addresses?

Do I need to make changes to the linker script?

Thank you.

#address #variables #ram
6 REPLIES 6
Erwan YVIN
ST Employee
Posted on September 27, 2016 at 15:38

Hello Alem ,

yes , it is possible

1) Change the linker file as the attachement (application.ld.backupram)

After each generation , the linker file will be overwritten

MEMORY
{
flash : org = 0x00000000, len = 256k
dataflash : org = 0x00800000, len = 64k
ram : org = 0x40000000, len = 10k
backupram : org = 0x40002800, len = 2k
}

__backupram_size__ = LENGTH(backupram);
__backupram_start__ = ORIGIN(backupram);
__backupram_end__ = ORIGIN(backupram) + LENGTH(backupram);

.standbyram : ALIGN(16) SUBALIGN(16)
{
__standbyram_start__ = .;
*(.standbyram)
*(.standbyram.*)
__standbyram_end__ = .;
} > backupram

2) After used the code section in your source code in front Variable declaration.

__attribute__ ((section (
''.standbyram''
)))

Best regards

Erwan

________________

Attachments :

application.ld.backupram : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006qbAi&d=%2Fa%2F0X0000000bpF%2FS8OuetwlOGDqS6i2g8GFqB6OzpbHfrinu_YVPNlTszw&asPdf=false
alessandro2
Associate III
Posted on September 27, 2016 at 16:20

Hello Erwan,

many thanks for your reply. As far as I understand, looking at the modified linker script, you' ve created a ram section starting at address0x40002800, which length is 2k. First question: let's consider the following code fragment:

1.
__attribute__ ((section (''.standbyram'')))
2.
uint8_t variable_a;
3.
uint16_t variable_b;

''variable_a'' would be placed at0x40002800, right? And ''variable_b'' at0x40002802, because of the 16 bits alignment od ''stanbyram'' section, right? Second question: how do I terminate the section? Suppose I want to declare a variable after ''variable_b'', which is not placed in the ''stanbyram'' section. Third question: why is the section length 2k? Aren't we missing 4k of RAM, this way? In the standard application.ld , the RAM section has 16k length (in this case, only 12k). Thank you for your assistance.
alessandro2
Associate III
Posted on September 28, 2016 at 08:55

OK, I've done some experimenting with the linker script.

I can manage to place variables within memory sections. What I don't understand is why the microcontroller crashes whnever I try to access one the fixed address variables. If I declare a variable like:

uint8_t __attribute__ ((section (''.standbyram''))) PARAMETER1_TEST ;

and I try to access it, the microcontroller crashes. If I just remove the __attribute__ and the variable is declared as a normal variable, everything is OK. Any idea? Thank you.
Erwan YVIN
ST Employee
Posted on September 28, 2016 at 09:58

Hello Alem ,

yes it is well 16K of SRAM .. you can adjust application.ld to match with your SRAM

it was a old application based on STANDBY WAKEUP Interrupt.

i have no problem in my side

__attribute__ ((section (
''.standbyram''
))) uint8_t toto;

/*
* Application entry point.
*/
int
main(
void
) {
uint8_t message[]= 
''Hello World!\r\n''
;
/* Initialization of all the imported components in the order specified in
the application wizard. The function is generated automatically.*/
componentsInit();
/* Enable Interrupts */
irqIsrEnable();
/*
* Activates the serial driver 1 using the driver default configuration.
*/
sd_lld_start(&SD1, NULL);

toto = 2;

MEMORY
{
flash : org = 0x00000000, len = 256k
dataflash : org = 0x00800000, len = 64k
ram : org = 0x40000000, len = 10k
backupram : org = 0x40002800, len = 6k
}

the variable is well at

(Cf screenshot)

Best regards

Erwan

________________

Attachments :

2016-09-28_094530.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006qUK4&d=%2Fa%2F0X0000000bni%2FUOV71dF6k3.E5XK8nC1OcFDK1kgLwHGQOuJRL6FfNOY&asPdf=false
alessandro2
Associate III
Posted on September 28, 2016 at 10:49

Hello Erwan, 

thanks for your reply.

Ok, I unnderstand I can adjust the ''backupram'' size.

Regarding the microcontroller crash, do nothing different than you  and I still got the problem.

Could it be related to compiler settings? (please, see my settings below).

Thank you.

0690X00000602dnQAA.jpg

Erwan YVIN
ST Employee
Posted on October 14, 2016 at 11:10

Hello Alem ,

Maybe the generation will replace automatically your application.ld

we will deliver a a way to create your own user.ld on SPC5Studio 5.1.0

or your application is too big.

          Best regards

                        Erwan