SCL3300 Lib compile error in CRC

Hello,
i am trying to use the SCL3300 library (MEMS sensor) with the PortentaH7.

The sensor is controlled via SPI. The library can be compiled and loaded correctly for other boards like the Uno or Arduino Mega2560. With the Portenta M7 or M4 I unfortunately get a longer error message when compiling. It is probably about the CRC calculation. Could it be an overlap in the namespace because of the library or does someone else have similar errors with the CRC calculation ?

I post the error message here too, maybe someone has some ideas. Otherwise I will program the library myself from the beginning.

Hope it is maybe an easy fix. Thanks.

Arduino: 1.8.13 (Windows 10), Board: "Arduino Portenta H7 (M7 core)"

In file included from C:\Users\jh\AppData\Local\Arduino15\packages\arduino-beta\hardware\mbed\1.2.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h7xx.h:129:0,

from C:\Users\jh\AppData\Local\Arduino15\packages\arduino-beta\hardware\mbed\1.2.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/cmsis.h:21,

from C:\Users\jh\AppData\Local\Arduino15\packages\arduino-beta\hardware\mbed\1.2.2\cores\arduino/mbed/targets/TARGET_STM/PinNamesTypes.h:33,

from C:\Users\jh\AppData\Local\Arduino15\packages\arduino-beta\hardware\mbed\1.2.2\variants\PORTENTA_H7_M7/pinmode_arduino.h:24,

from C:\Users\jh\AppData\Local\Arduino15\packages\arduino-beta\hardware\mbed\1.2.2\cores\arduino/Arduino.h:29,

from sketch\Example1_BasicTiltLevelOffset.ino.cpp:1:

C:\Users\jh\AppData\Local\Arduino15\packages\arduino-beta\hardware\mbed\1.2.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h747xx.h:2598:43: error: expected ')' before '*' token

#define CRC ((CRC_TypeDef *) CRC_BASE)

^

C:\Users\jh\Documents\Arduino\libraries\SCL3300\src/SCL3300.h:146:18: note: in expansion of macro 'CRC'

uint8_t CMD, CRC;

^

C:\Users\jh\AppData\Local\Arduino15\packages\arduino-beta\hardware\mbed\1.2.2\cores\arduino/mbed/targets/TARGET_STM/TARGET_STM32H7/STM32Cube_FW/CMSIS/stm32h747xx.h:2598:43: error: expected ')' before '*' token

#define CRC ((CRC_TypeDef *) CRC_BASE)

^

C:\Users\jh\Documents\Arduino\libraries\SCL3300\src/SCL3300.h:146:18: note: in expansion of macro 'CRC'

uint8_t CMD, CRC;

Rest in attachment.

error.txt (14.4 KB)

Unfortunately, the Mbed OS software uses an extremely common name "CRC" for a macro. This is causing a collision with a completely unrelated use of the name in the SCL3300 library.

The best fix would be to rename all the "CRC" in the library, but there are quite a few of them so it is a little bit complicated.

An easier fix is to do this:

Open C:\Users\jh\Documents\Arduino\libraries\SCL3300\src/SCL3300.h in a text editor.

At line 46, add the following:

#ifdef CRC
#undef CRC
#endif

Save the file.

This is a bit of a hack, because it undefines the Mbed OS CRC macro, but if that macro isn't even being used within the translation units that #include SCL3300.h then it does no harm.

Hello,

thank a lot for your help. I will definitly try this easier fix first and maybe later the rename solution.
I have also written with the creator of the library and here is the link just for the completeness in case someone is dealing with the same problem.

Quick update. Your fast fix/hack working fine, i just hope that i dont need the CRC makro in the future.

I'm glad to hear it's working now. If you do end up needing CRC, at least you know what will be needed. Enjoy!
Per

Thats right thanks again.

And one more update:
The creator of the lib. was also very kind and updated all of the names in a new version 2.1.4. :slight_smile:
Now everything is working. Thanks for all of your help.

That's way cool that the library author was so responsive with a fix! I love to see that sort of dedication to open source projects.