ioLibrary_Driver icon indicating copy to clipboard operation
ioLibrary_Driver copied to clipboard

#define IR conflicts with STM32G4 series HAL

Open lroop opened this issue 2 years ago • 1 comments

The definition of IR to refer to the Wizchip's interrupt register causes build errors when trying to build for an STM32G4xx series microcontroller using ST's HAL and CMSIS common code.

If you look at https://github.com/STMicroelectronics/STM32CubeG4/blob/c4132af65fe74ddd7f54aced85a0f4acce736405/Drivers/CMSIS/Device/ST/STM32G4xx/Include/stm32g474xx.h#L271 you'll see that IR is the name of a variable inside a struct for the STM's CAN-FD controller, but the #define in Wiznet's code at https://github.com/Wiznet/ioLibrary_Driver/blob/3847fb3b5d1a6a1dc8f7e38b239d7e57951f3a8a/Ethernet/W5500/w5500.h#L270 causes this variable name to be replaced with a numeric constant by the C preprocessor. It is generally considered best practice to namespace #defines in libraries to avoid this, for instance this define in the Wiznet code could be named WIZCHIP_REG_IR or similar instead of just IR.

lroop avatar Sep 08 '23 14:09 lroop

As a comment for this problem, what i do is change the name of this define to something like this: IR_5500, this workaround the issue, but it should be named different as you mention. Environment: NUCLEO64 STM32G474

Gerard-170 avatar Dec 08 '24 20:12 Gerard-170

Ideally, header files should include namespace in macros e.g. #define WIZ_IR

mrx23dot avatar May 07 '25 16:05 mrx23dot