2016-09-27 01:54 AM
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 #ram2016-09-27 06:38 AM
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 overwrittenMEMORY
{
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
2016-09-27 07:20 AM
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.
2016-09-27 11:55 PM
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.
2016-09-28 12:58 AM
__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
2016-09-28 01:49 AM
2016-10-14 02:10 AM