RF24 Library on Portenta C33

I am trying to use the NRF24L01+ radio transceiver with the Portenta C33. I have been successful with other devices but I can't get the sketch to compile for C33 when including the RF24 library. When omitting #include <RF24.h> the sketch compiles successfully. This is the only error I get when including the library:

In file included from C:\Users\Seth\Documents\Arduino\libraries\RF24\RF24.cpp:9:0:
C:\Users\Seth\Documents\Arduino\libraries\RF24\nRF24L01.h:36:21: error: expected unqualified-id before numeric constant
 #define CD          0x09
                     ^
c:\users\seth\appdata\local\arduino15\packages\arduino\hardware\renesas_portenta\1.1.0\variants\portenta_c33\includes\ra\fsp\src\bsp\cmsis\device\renesas\include\R7FA6M5BH.h:6456:28: note: in expansion of macro 'CD'
             __IOM uint32_t CD   : 1;   /*!< [9..9] Late Collision Detect Flag                                         */
                            ^~

exit status 1

Its a little over my head. Does anyone know how to fix it?

I've included a few lines surrounding the lines noted in the error. Not sure if that will help whoever knows what's going on.

uint32_t            : 2;
            __IOM uint32_t RMAF : 1;   /*!< [7..7] Multicast Address Frame Receive Flag                               */
            __IOM uint32_t TRO  : 1;   /*!< [8..8] Transmit Retry Over Flag                                           */
            __IOM uint32_t CD   : 1;   /*!< [9..9] Late Collision Detect Flag                                         */
            __IOM uint32_t DLC  : 1;   /*!< [10..10] Loss of Carrier Detect Flag                                      */
            __IOM uint32_t CND  : 1;   /*!< [11..11] Carrier Not Detect Flag    
#define RF_SETUP    0x06
#define NRF_STATUS  0x07
#define OBSERVE_TX  0x08
#define CD          0x09
#define RX_ADDR_P0  0x0A
#define RX_ADDR_P1  0x0B
#define RX_ADDR_P2  0x0C
#define RX_ADDR_P3  0x0D

Hi @8751. Unfortunately the developer of the RF24 library chose a fairly generic name for the CD macro. That resulted in a name collision with an unrelated use of that name inside the "Renesas FSP" framework used by the "Arduino Renesas Portenta Boards" platform of the Portenta C33.

The solution is to change the library code to use a unique name. I'll provide instructions you can follow to do that:

  1. Open the file at the following path in any text editor:
    C:\Users\Seth\Documents\Arduino\libraries\RF24\nRF24L01.h
    
  2. Change line 36 from this:
    #define CD          0x09
    
    to this:
    #define RF24_CD          0x09
    
  3. Save the file.
  4. Open the file at the following path in any text editor:
    C:\Users\Seth\Documents\Arduino\libraries\RF24\RF24.cpp
    
  5. Change line 1841 from this:
        return (read_register(CD) & 1);
    
    to this:
        return (read_register(RF24_CD) & 1);
    
  6. Save the file.

Now try compiling your sketch again. Hopefully this time there won't be any errors.


Please let me know if you have any questions or problems while following those instructions.

Such a simple fix! Thanks! Its works just fine!

You are welcome. I'm glad it is working now.

Regards,
Per