Ethernet.h compilation issue RTL8720(BW16)

Hi all,

Here is prototype code I tried to compile with RTL8720 board.


#include <SPI.h>
#include <Ethernet.h>


void setup() {

}


void loop() {
 
}

I get the following error message:


In file included from C:\Users\M1\Desktop\WebServer2\WebServer2.ino:3:0:

C:\Users\M1\Documents\Arduino\libraries\Ethernet\src/Ethernet.h:152:32: error: expected class-name before '{' token

 class EthernetUDP : public UDP {

                                ^

In file included from C:\Users\M1\Desktop\WebServer2\WebServer2.ino:3:0:

C:\Users\M1\Documents\Arduino\libraries\Ethernet\src/Ethernet.h:185:15: error: type 'Print' is not a base type for type 'EthernetUDP'

  using Print::write;

               ^~~~~

Multiple libraries were found for "Ethernet.h"

 Used: C:\Users\M1\Documents\Arduino\libraries\Ethernet

Using library SPI at version 1.0.0 in folder: 
C:\Users\M1\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.6\libraries\SPI 

Using library Ethernet at version 2.0.2 in folder: C:\Users\M1\Documents\Arduino\libraries\Ethernet 

exit status 1

Error compiling for board Ai-Thinker BW16 (RTL8720DN).

Please note that there is apparently a problem with using the <Ethernet.h> library, that I cannot understand.

Please help.
TIA

1 Like

Hi Juraj,

But in the ameba github page where you raised this issue, the ameba people have added it.

type or paste code here

Is it that I haven't downloaded it. If the answer is yes, how to correct it.

Tia

Hi @azhaque. I spent a little time looking into this in hopes I could provide instructions for fixing the error. Unfortunately I was not successful, but thought I should share my findings anyway in case they will be useful to you or to another forum helper.

I can see that the bug of the missing Udp.h header file from the link provided by @Juraj has already been fixed in the "Realtek Ameba Boards" platform that adds support to Arduino IDE for your RTL8720 board. The maintainers of the platform haven't made a new release since the time of the fix, so the release version of the platform you get from Arduino IDE Boards Manager still has that bug.

So I installed the development version of the platform by the following procedure:

  1. Select File > Preferences... (or Arduino IDE > Settings... for macOS users) from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Replace the previous "master" URL in the "Additional Boards Manager URLs" field of the "Preferences" dialog:
    https://github.com/Ameba-AIoT/ameba-arduino-d/raw/master/Arduino_package/package_realtek_amebad_index.json
    
    with the "dev" URL (which is provided in the platform's readme):
    https://github.com/Ameba-AIoT/ameba-arduino-d/raw/dev/Arduino_package/package_realtek_amebad_early_index.json
    
  3. Click the "OK" button on the "Preferences" dialog.
    The "Preferences" dialog will close.
  4. You will now see a "Downloading index: ..." notification at the bottom right corner of the IDE window. Wait for that notification to close.
  5. Select Tools > Board > Boards Manager... from the Arduino IDE menus to open the "Boards Manager" view in the left side panel.
  6. Scroll down through the list of boards platforms until you see the "Realtek Ameba Boards (32-bits ARM Cortex-M33 @200MHz)" entry.
  7. Click the "UPDATE" button at the bottom of the entry.
  8. Wait for the update process to finish, as indicated by a notification at the bottom right corner of the Arduino IDE window:

    Successfully installed platform ...

Unfortunately after I did that, I still got the same error. It turns out there is already an unrelated file named Upd.h somewhere else in the platform's toolchain (I didn't track down the exact location of this file), and that header file is being used instead of the intended file from the Arduino core. I was able to work around that problem by giving the header file in the core a unique name:

  1. Change the name of the file at this path on your hard drive:
    C:\Users\M1\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.8-build20241128\cores\ambd\Udp.h
    
    to Arduino_Udp.h.
    • :exclamation: If looking for it with your file manager or command line, note that the AppData folder is hidden by default. On Windows "File Explorer", you can make it visible by opening the "View" menu, then checking the box next to "☐ Hidden items".
  2. Use any text editor to open the file at the following path on your hard drive:
    C:\Users\M1\Documents\Arduino\libraries\Ethernet\src\Ethernet.h
    
  3. Change line 54 from this:
    #include "Udp.h"
    
    to this:
    #if defined(ARDUINO_ARCH_AMEBAD)
    #include "Arduino_Udp.h"
    #else
    #include "Udp.h"
    #endif
    
  4. Save the file.

With hope in my heart, I compiled again. The previous error no longer occurred, but unfortunately I only got to the next one:

In file included from c:\Users\per\Documents\Arduino\libraries\Ethernet\src\socket.cpp:21:0:
C:\Users\per\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.8-build20241128\cores\ambd/Arduino.h:55:18: error: expected unqualified-id before '{' token
 #define yield(x) {}
                  ^
c:\Users\per\Documents\Arduino\libraries\Ethernet\src\socket.cpp:26:13: note: in expansion of macro 'yield'
 extern void yield(void);
             ^~~~~

I gave up at that point, but I was at least a little closer to a working system. Maybe you can pick up from there and achieve success.

1 Like

Many thanks for effort @ptillisch.

I will keep trying from where you left off and post my result like you have.

On the point regarding non inclusion of udp.h in the RTL core, I had a detailed dig into the arduino ide on my computer. I found a directory named realtek. Within this there was a sub directory titled 'core'. It had udp.h included in it. So my newbie take on this is that the udp.h is included herein.

Let me now take you to the next point. All the examples for wifi, included in the rtl8720 compile successfully. Needless to say UDP is also used in wifi, as it is in Ethernet. So my question is how is it that wifi.h compiles (with obvious inclusion of udp function) while Ethernet doesn't.

Note: I haven't finished my post. Will do so tomorrow morning where I saw a discussion on this topic. Will dig it out and post here.

Regards
Azhaque

1 Like

Are you talking about the file at the path I specified in my instructions here?:

If so, that is the file the Ethernet library is intended to use. The file that is used instead is located at this path:

C:\Users\M1\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.8-build20241128\system\component\common\network\lwip\lwip_v2.0.2\src\include\udp.h

Windows has a case-insensitive filesystem, so the compiler considers the filenames Udp.h and udp.h to be equivalent when compiling on a Windows machine.

Because the WiFi library doesn't have an incompatibility with the yield macro defined by the "Realtek Ameba Boards (32-bits ARM Cortex-M33 @200MHz)" platform.

Here you can see that yield is defined as a macro function by the platform's Arduino.h header file:

Here you can see the yield name referenced as a function by the Ethernet library:

We can simplify the bug that occurs when using the Ethernet library down to this:

#define foobar(x) {}  // Simulate the macro defined by the platform
extern void foobar(void);  // Simulate the function reference in the library
void setup() {}
void loop() {}

After C++ preprocessing, that code is equivalent to:

extern void {};
void setup() {}
void loop() {}

Do you see how it becomes invalid? Thus, the sketch fails to compile:

C:\Users\per\Documents\Arduino\000-support\forum\1337743\1337743.ino:1:19: error: expected unqualified-id before '{' token
 #define foobar(x) {}  // Simulate the macro defined by the platform
                   ^
C:\Users\per\Documents\Arduino\000-support\forum\1337743\1337743.ino:2:13: note: in expansion of macro 'foobar'
 extern void foobar(void);  // Simulate the function reference in the library
             ^~~~~~

exit status 1

Compilation error: expected unqualified-id before '{' token

Now here is the equivalent code when using the WiFi library:

#define foobar(x) {}  // Simulate the macro defined by the platform
void setup() {}
void loop() {}

After C++ preprocessing, that code is equivalent to:

void setup() {}
void loop() {}

Do you see how in this case the code is completely valid? For this reason, it compiles successfully.

1 Like

@ptillisch. Thanks again for taking time out to answer in detail.

Yes I am. I had done exactly as you have demonstrated. However these steps did not make any difference which indicated to me that the problem lied elsewhere, as clearly shown by you in your last post; is in the YIELD MACRO. Unfortunately my current level of understanding about the YIELD MACRO is insufficient to say anything substantive. Your reply has however given me a new thread to follow in this regard, which I will be doing.

From your illustrative example given above, I can see the error. However it raises the following question in my mind:

What ingredient is (or isn't) present in the <wifi.h> which causes the YIELD macro to compile it correctly? I guess it's my homework for today :grinning: at 66 years of age.

Regards
azhaque

The WiFi library doesn't have a line like this: