Skip to main content
jark
Associate II
Jul 26, 2010 6:46 PM UTC
Question

Accessing EEPROM with Cosmic compiler

Posted on July 26, 2010 at 20:46

Accessing EEPROM with Cosmic compiler

    This topic has been closed for replies.

    10 replies

    luca239955_stm1_st
    Associate
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    Hi,

    there's no need for include files, but you must define a .eeprom segment in the linker file (I'm not sure if STVD does that automatically).

    What linker error do you have exactly?

    Regards,

    Luca

    jark
    jarkAuthor
    Associate II
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    OK - here's the file

    # LINK COMMAND FILE AUTOMATICALLY GENERATED BY STVD: TOTALLY

    # IF AUTO MODE IS ENABLED, OR ONLY PARTIALLY WHEN AUTO MODE

    # IS DISABLED (see below).

    #

    # CAUTION:

    #

    # Sections delimited by <BEGIN ...> and <END ...> markers are

    # reserved for STVD: DO NOT MODIFY INSIDE.

    #

    # Manual modifications are allowed OUTSIDE these sections, WHEN

    # STVD ''auto'' MODE IS DISABLED (if ''auto'' mode is enabled,

    # modifications are lost).

    # When STVD ''auto'' mode is disabled, it is also possible to disable

    # the automatic update inside the reserved sections, by removing the

    # <BEGIN ...> and <END ...> markers of the corresponding section.

    #

    # Please refer to Cosmic User Manuals before any modification.

    # Note that errors in editing this file may have unpredictable results

    # when running STVD.

    # Segment configuration - section reserved for STVD

    #<BEGIN SEGMENT_CONF>

    # Segment Code,Constants:

    +seg .const -b 0x8080 -m 0x7f80 -n .const -it

    +seg .text -a .const -n .text

    # Segment Eeprom:

    +seg .eeprom -b 0x4000 -m 0x400 -n .eeprom

    # Segment Zero Page:

    +seg .bsct -b 0x0 -m 0x100 -n .bsct

    +seg .ubsct -a .bsct -n .ubsct

    +seg .bit -a .ubsct -n .bit -id

    +seg .share -a .bit -n .share -is

    # Segment Ram:

    +seg .data -b 0x100 -m 0x500 -n .data

    +seg .bss -a .data -n .bss

    #<END SEGMENT_CONF>

    # Startup file - section reserved for STVD

    #<BEGIN STARTUP_FILE>

    crtsi0.sm8

    #<END STARTUP_FILE>

    # Object files list - section reserved for STVD

    #<BEGIN OBJECT_FILES>

    Debug\stm8s_clk.o

    Debug\stm8s_gpio.o

    Debug\stm8s_itc.o

    Debug\main.o

    Debug\stm8_interrupt.o

    Debug\stm8s_adc1.o

    Debug\stm8s_beep.o

    Debug\stm8s_exti.o

    Debug\stm8s_lcd.o

    Debug\stm8s_tim1.o

    Debug\stm8s_tim2.o

    Debug\stm8s_tim3.o

    Debug\stm8s_tim4.o

    Debug\timers.o

    Debug\utilities.o

    #<END OBJECT_FILES>

    # Library list - section reserved for STVD

    #<BEGIN LIBRARY_FILES>

    libfs0.sm8

    libis0.sm8

    libm0.sm8

    #<END LIBRARY_FILES>

    # Interrupt vectors file - section reserved for STVD

    #<BEGIN VECTOR_FILE>

    +seg .const -b 0x8000 -k

    Debug\stm8_interrupt_vector.o

    #<END VECTOR_FILE>

    # Defines - section reserved for STVD

    #<BEGIN DEFINED_VARIABLES>

    +def __endzp=@.ubsct            # end of uninitialized zpage

    +def __memory=@.bss                # end of bss segment

    +def __startmem=@.bss

    +def __endmem=0x5ff

    +def __stack=0x7ff

    #<END DEFINED_VARIABLES>

    luca239955_stm1_st
    Associate
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    looks like something is wrong with your linker file, please post it.

    jark
    jarkAuthor
    Associate II
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    Hi,

        Thanks for the quick response.  The error message I get is:

    #error clnk Debug\lc_meter_v1.lkf:1 bad address (0x4000) for zero page symbol _Cstd

     The command: ''clnk -l''C:\Program Files\COSMIC\CXSTM8_16K\Lib''  -o Debug\lc_meter_v1.sm8 -l..\..\..\..\libraries\stm8s_stdperiph_driver -mDebug\lc_meter_v1.map Debug\lc_meter_v1.lkf '' has failed, the returned value is: 1

    exit code=1.

        Thanks,

        Jim

    jark
    jarkAuthor
    Associate II
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    There's nothing confidential about the project but it is, I think, too long to post

    the whole thing.  The section where I define the variables is:

    // global variables follow

    enum menu_t menu_mode;

    enum meas_t measurement_mode;

    float Cstd = 469.0e-12;

    float C1 = 509.0e-12;

    float L68 = 67.0e-6;

    float L1 = 68.0e-6;

    float Cx, Lx;

    long f1, f2;

    u8 s[16];

    float rho;

    char cont;

    As above, it compiles, links and runs correctly.  I get the clink error when I change the line with Cstd in it to the following:

    @eeprom float Cstd = 469.0e-12;

        Jim

    luca239955_stm1_st
    Associate
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    the linker file looks correct, so that's not yet enough information to understand the problem..

    This symbol that is giving the error ''Cstd'', is that something you defined?

    Can I see the definition ? Or you can post the entire project of it not confidential

    jark
    jarkAuthor
    Associate II
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    Hi,

       I may have found the problem.  I used Cstd in both the main.c module and also in another module of the program.  There, I referred to it as:

    extern float Cstd;

    If I referred to it as 'extern @eeprom float Cstd', I got an error; I did not get an error if I referred to it as shown above.

        I only used it in one procedure there and have just found that, if I move that procedure into my main.c module where I declare all the variables, I no longer get a clink error.  I have yet to determine if I can properly access Cstd in the program.  It is only written to in a calibration procedure which is only used infrequently - but it is read in many different places in the project.

    jark
    jarkAuthor
    Associate II
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    Hi,

        The problem was that I was not 'unlocking' the EEPROM before writing to it.  I needed to #include the stm8s_flash.h file at the beginning and then the code to write to the eeprom looked like:

        .......

        FLASH_Unlock(FLASH_MEMTYPE_DATA);

        Cstd = Cstd *factor;

        FLASH_Lock(FLASH_MEMTYPE_DATA);

        ..........

    where Cstd is the variable in eeprom.

                                                               

    jark
    jarkAuthor
    Associate II
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

     Hi,

        I've looked at the assembler code produced by the compiler for the brief code; it looks fine to me but it illustrates the problem.

     352                     ; 187                                                        Cstd = Cstd * factor;

     354  0141 ae0000            ldw    x,#_Cstd

     355  0144 cd0000            call    c_ltor

     357  0147 ae0075            ldw    x,#L531

     358  014a cd0000            call    c_fmul

     360  014d ae0000            ldw    x,#_Cstd

     361  0150 cd0000            call    c_eewrl

     

    It looks like it reads the eeprom, does the multiplication and then tries to store it

    back in eeprom with the call to c_eewrl.  However, when I run the program, the value in Cstd is NOT changed.

       Anyone have any suggestions?

       Jim

    jark
    jarkAuthor
    Associate II
    May 17, 2011 1:09 PM UTC
    Posted on May 17, 2011 at 15:09

    Hi again,  OK, it compiles without errors and the program can read the value of Cstd when it is declared:

    @eeprom float Cstd = 469.0e-12;

    It is read frequently in the program.  However, in a calibration routine, if I try to change it with a statement like:

        Cstd = Cstd * 0.998;

    it does not change - I read it a few lines later and it has just got the same value as initialized in the statement which defines the variable.

        Jim