unions in Fastspin C

If I compile the following program I get a strange error message "error: unknown identifier data in class __struct__anon_b08d68d60000006d"
#include "propeller2.h"

struct __using("FullDuplexSerial2.spin") com;

#define pinLedG 6
#define pinLedY 7
#define pinLedR 8
#define pinRel  9
#define pinFan  37
#define pinDTX  62
#define pinDRX  63
#define pinMTX  11
#define pinMTE  12
#define pinMRX  13

#define modePll 0b1_000000_0000001000_1111_10_11 // S 0=RC20M, 1=RC20k, 2=XI, 3=PLL
#define _XTALFREQ   20_000_000
#define _CLOCKFREQ 180_000_000
#define delay100   (_CLOCKFREQ / 10)

#define baudRate1 230_400	// serial debug port
#define baudRate2 1_000_000	// RS485 port

enum cmd_t {getPar=0, setPar, getScope, getMon, save, load, tune, test};
#define maxDataLen 1024
#define headerSize 12

typedef struct
    int32_t supplyVolt;
    int32_t temperature;
    int32_t motorI2t;
    int32_t status;
    int32_t actPos;
    int32_t posDiff;
    int32_t torque;
    int32_t actVel;
    int32_t debug;
} MonitorData;

typedef struct 
    int32_t cmd;   // what to do
    char    id[4]; // parameter name or register ID
    int32_t len;   // size of data (>0) or error (<0)
        int32_t num[maxDataLen/4];
        float   par[maxDataLen/4];
        char    text[maxDataLen];
        MonitorData data;
} CmdBuffer;

CmdBuffer cmd;

void TestRS485 ()
  for (;;)
    com.read (&cmd, 12, 1);
    if (cmd.len>1024) cmd.len= 1024;
    if (cmd.len>0) com.read (&cmd.data, cmd.len, 1);
    com.hex (cmd.cmd, 8);
    com.tx (32);
    com.hex (cmd.id, 8);
    com.tx (32);
    com.hex (cmd.len, 8);
    com.tx (10);

void main()
  clkset (modePll, _CLOCKFREQ);
  _pinl (pinLedY);
  _pinh (pinLedG);
  com.start2 (pinDRX, pinDTX, 0, baudRate1, pinMRX, pinMTX, 0, baudRate2);
  TestRS485 ();
  for (;;)
    _pinnot (pinLedY);
    _waitx (delay100);
The problem seems to be related to the union. If I replace "&cmd.data" with "&cmd.len" the compiler doesn't give an error.


  • Fastspin doesn't yet support anonymous unions. For now you'll have to give the union a name (like "u") and then do "&cmd.u.data".
  • Ah, thanks. No problem if it was documented or if the error message was a little clearer.
Sign In or Register to comment.