0

I am writing a firmware for stm8 with Cosmic compiler and in ST Visual Develop. I am using astruct as the following:

typedef enum
{
    lcBlack = 0,
    lcRed,
    lcGreen,
    lcOrange
}
led_color_t;

    PUBLIC typedef enum
{
    lppEmpty,
    lppStartup,
    lpp_volt_off,
    lpp_volt_warn,
    lpp_volt_over,
    lpp_volt_under,
    lpp_volt_drop,
    lppPause,
    lppHY,
    lppMLZ,
    lppTD,
    lppOnOK,
    lppOff,
    lppLixilTestTouch
}
led_name_t;


typedef struct
{
    uint8_t             enable;
    led_name_t      led_name;
    led_color_t     led_color;
    uint8_t             prio;
    uint16_t            t_on_0;
    uint16_t            t_off_0;
    uint8_t             cnt_0;
    uint16_t            t_on_1;
    uint16_t            t_off_1;
    uint8_t             cnt_1;
    uint16_t            t_1;
    uint16_t            t_2;
}
led_patt_t;

then I define and initialize an array of structs as the following:

 led_patt_t led_pattern[73] = {
{0, lppEmpty,           lcBlack,       0,      0,       0,      0,      0,       0,      0,      0,       0},
{0, lppStartup,           lcRed,     255,    100,     100,     10,      0,       0,      0,      0,     500},
{1, lpp_volt_off,         lcRed,     210,    100,     100,      2,      0,       0,      0,      0,    1100},
{1, lpp_volt_warn,        lcRed,     210,    150,     150,      2,      0,       0,      0,      0,    1300} 
... };

Next I need to define a function that uses the struct array members as the following:

result_t led_pattern_request (led_patt_t led_patt){       
{
    
led_private.pattern_current.color[0]            = led_patt.led_color;
led_private.pattern_current.color[1]            = led_patt.led_color;
led_private.pattern_current.priority            = led_patt.prio;
led_private.pattern_current.time_on_25ms[0]     = (uint8_t)led_patt.t_on_0;
.
.
.
}

Where

led_data_t led_private;

Then in my main I call the above function as the following:

led_pattern_request (led_pattern[17]);

However, after compiling I get the follwing errors:

  • #error cpstm8 ..\src\memory\flash.c:38(36+2) invalid indirection operand
  • #error cpstm8 ..\src\memory\flash.c:38(38) incompatible argument type
  • #error cpstm8 ..\src\memory\flash.c:38(24+11) led_pattern undefined

This is really confusing for me, I also tried to pass a pointer to the struct to the function but I get the same errors. Any help is greatly appreciated. I am new to programming and need your help.

Thank you in advance. Best regards, Vouria

vouria
  • 25
  • 3
  • 9
  • `I get the follwing errors` Please post the errors verbatim. Is there no "filename:line number:column number: in this and this expression there is this wrong" kind of message? Are the error messages so short? Please post a full [MCVE], at best with a short main - could you post _one_ short code snippet that is not able to compile, so that others may try to compile it with other compilers? Please post the missing definitions - what is `led_data_t`, `led_name_t`, `led_color_t`? Do you get any warnings from the compiler, if it supports them? Did you forget to _declare_ the `led_pattern_request`? – KamilCuk Jan 12 '21 at 08:25
  • I would love to post the requested code, but it is just too long. The error messages are not long, they are as the follwing: #error cpstm8 ..\src\memory\flash.c:38(36+2) invalid indirection operand #error cpstm8 ..\src\memory\flash.c:38(38) incompatible argument type #error cpstm8 ..\src\memory\flash.c:38(24+11) led_pattern undefined led_data_t is a long struct which contain multiple other structs, and led_name_t and led_color_t are enums. I will try to modify the question and add the requested data. To answer your last question: I have declared the led_pattern_request. – vouria Jan 12 '21 at 08:35
  • The Cosmic compiler might be limited, and it might not accept a `struct` as a parameter. Please read its documentation, and if so, try to use a pointer to the `struct`. – the busybee Jan 12 '21 at 14:59

1 Answers1

0

I found the answer. To use the array of struct in other .C files I need to include the struct in that .C file using extern.

vouria
  • 25
  • 3
  • 9