Emandhal / MCP251XFD

MCP2517FD, MCP2518FD and MCP251863 driver
MIT License
28 stars 6 forks source link

Variable name conflict on STM32 #4

Closed BombaMat closed 2 years ago

BombaMat commented 2 years ago

There is a conflict with a STM32 define named CRC. It happen with the typedef union PACKED MCP251XFD_CRC_Register in MCP251XFD.h where there is uint32_t CRC.

STM32 Driver code : #define CRC ((CRC_TypeDef *) CRC_BASE)

MCP251XFD Code : uint32_t CRC;

I tried to change the variable name put it broke the PACKITEM system. How should I do it ?

Emandhal commented 2 years ago

Hi,

Change the CRC register lines by theses:

//! CRC Register
PACKITEM
typedef union __PACKED__ MCP251XFD_CRC_Register
{
  uint32_t CRCreg;
  uint8_t Bytes[sizeof(uint32_t)];
  struct
  {
    uint32_t CRCbits : 16; //!<  0-15 - Cycle Redundancy Check from last CRC mismatch
    uint32_t CRCERRIF:  1; //!< 16    - CRC Error Interrupt Flag: '1' = CRC mismatch occurred ; '0' = No CRC error has occurred
    uint32_t FERRIF  :  1; //!< 17    - CRC Command Format Error Interrupt Flag: '1' = Number of Bytes mismatch during “SPI with CRC” command occurred ; '0' = No SPI CRC command format error occurred
    uint32_t         :  6; //!< 18-23
    uint32_t CRCERRIE:  1; //!< 24    - CRC Error Interrupt Enable
    uint32_t FERRIE  :  1; //!< 25    - CRC Command Format Error Interrupt Enable
    uint32_t         :  6; //!< 26-31
  } Bits;
} MCP251XFD_CRC_Register;
UNPACKITEM;
ControlItemSize(MCP251XFD_CRC_Register, 4);

It should work as the .c file does not use this structure. I will commit this change later.

Thank you Regards, Emandhal

BombaMat commented 2 years ago

Hi!

Thank you for the fast support, it fixed the problem !