cancel
Showing results for 
Search instead for 
Did you mean: 

COSMIC Compiler structure initialisation

Aaron Derbyshire
Associate II
Posted on June 14, 2017 at 11:58

Currently I have an issue when trying to allocate a structure to RAM.

The issue I have is that my structure occupies a total of 373 bytes but the compiler/linker is insistent on trying to locate this structure in the zero page (first 256 bytes). To enable compilation I have reduced the size of the structure to allow for viewing of the map file to see where the compiler is allocating this data.

I have attempted to use the pragma directives to allocate this structure to the @near range, which would allow anywhere within the RAM space. This again gave me a section overflow of the zero page!

To go one step further I have defined my own section within the RAM space with the required size memory allocation. I have positioned this directly after the zero page and prior to the .data section. Using absolute addressing and the pragma directives I am still experiencing the same issues, or, now I have an error as the symbol has been defined for the zero page. I have e-mailed Cosmic but they don't seem to care for offering support.

Has anyone got any advice?

UPDATE: Just to add some further information.

- RAM size = 1024 bytes.

- Zero Page = 256 bytes.

- Max stack size 513 bytes (my thoughts are that this will be given the optimal size by the compiler/linker depending in the .data and .bss usage).

- Default linker file is being used, with the exception of the test section described above.

#ram #stm8 #cosmic #cosmic-stm8-cosmic-lkf
1 ACCEPTED SOLUTION

Accepted Solutions
luca239955_stm1_st
Senior II
Posted on June 14, 2017 at 18:26

Hello,

in order to put your structure (or any other variable) in the @near address space (out of page zero), you either have to specify the @near attribute for you structure or to use a memory model where this attribute is the default (+modsl0 is the usual choice for this).

If neither of these solutions seem to work please post your code here and I'll see what is wrong with it (I will also check with my colleagues if they have received your email on the support address).

Regards,

Luca

View solution in original post

7 REPLIES 7
luca239955_stm1_st
Senior II
Posted on June 14, 2017 at 18:26

Hello,

in order to put your structure (or any other variable) in the @near address space (out of page zero), you either have to specify the @near attribute for you structure or to use a memory model where this attribute is the default (+modsl0 is the usual choice for this).

If neither of these solutions seem to work please post your code here and I'll see what is wrong with it (I will also check with my colleagues if they have received your email on the support address).

Regards,

Luca

Posted on June 15, 2017 at 09:48

Hi Luca,

Thanks for your response! A member of the Cosmic support team has now been in contact with me.

I have tried to use the space modifier, however, I am returned with a space attribute conflict error. Similarly this happens when using the pragma directives also. I will look at modifying the default memory model.

Thanks again,

Aaron

Posted on June 15, 2017 at 09:56

I have modified the default configuration file to use the stack long memory model and that has compiled first time and allocated my structure in the .data section as desired!

Thank you very much for your help!

Aaron

Posted on October 26, 2017 at 08:38

Dear Aaron, could you please be so kind and tell me how you have done this?

Posted on October 26, 2017 at 10:17

Hi Klaus,

After speaking with COSMIC it became apparent that I was using the incorrect memory model.

In the STVD environment the memory model settings can be altered under Project Settings ->  C Compiler -> Memory Models and select short stack. Then when declaring the structure I have used the @near identifier.

There are a number of other ways that this can be done, for example defining your own linker file and start-up program.

Hope this helps.
Posted on October 30, 2017 at 14:36

Hi Aaron,

yes it looks as there are some wrong default values. I solved my problem this way:

Project -> Settings -> Linker -> Input. The RAM end value should be 0x3FF, but was 0x1FF.

Then I spread my variables using the @tiny and @near attributes.

Now facing the next problem: suddenly my constants are placed in the address range 0xFFE0 to 0x10060. These addresses do not exist in the flash STM8S103 (and are not defined with above settings).

As there seem to be faulty data for the address ranges, where can I find the default definitions for the address ranges? Is this in .h or .ini files, is it with Cosmic or with STVD?

Thanks,  Klaus

Posted on October 30, 2017 at 14:53

Klaus,

I would suggest some further contemplation before redefing your RAM space. The reason your 'RAM' doesn't end at the correct address is because there is an allowance in RAM for your stack which starts at 0x3FF and decrements down as items are added i.e. when you stored variables etc during function calls. As long as you are aware of this and handle it accordingly then you should have no issues.

Also, as a quick side note you should read the corresponding compiler documentation to ascertain whether or not you need to modify the linker file and what consequences this will have on your desired process.

In order to obtain your address ranges I would refer back to the correct datasheet. Providing you are using the STM8S003F3 then it can be found

http://www.st.com/content/st_com/en/products/microcontrollers/stm8-8-bit-mcus/stm8s-series/stm8s-value-line/stm8s003f3.html

.

Hope this helps,

Aaron