W5500 library is (finally) ported

Please do not post requests
User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

W5500 library is (finally) ported

Post by Vassilis » Tue Aug 18, 2015 1:43 pm

I ported the new W5500 Ethernet controller for using it with STM32F1 series. Actually, the new library will replace the old Ethernet_STM library.
The new ported library is 100% compatible with the old one and supports both W5100 and W5500 chips.
The library support the W5200 chip too but I haven't ported it to STM32F1.

The W5500 chip is by far faster than the W5100 !
With the combination of STM32F103, VS1053 and W5500 I managed to play Internet streams (WebRadios) up to 192 kbps / 44000 Hz !
I hope with a source code optimization the bit-rate will be increased up to 320 kbps.

I have one more issue to solve before I publish it. When is used the Static IP the produced hex is almost 23 kB. When is used the DHCP client, the produced hex is almost 80 kB. 248% more flash space.

On Arduino nano (I know it's 8-bit not 32-bit) the Static IP consumes ~10 kB and the DHCP ~13 kB. 30% more flash space.
Last edited by Vassilis on Sun Aug 23, 2015 3:41 pm, edited 2 times in total.

victor_pv
Posts: 1472
Joined: Mon Apr 27, 2015 12:12 pm

Re: W5500 library is (almost) ported

Post by victor_pv » Tue Aug 18, 2015 8:27 pm

Vassilis wrote:I ported the new W5500 Ethernet controller for using it with STM32F1 series. Actually, the new library will replace the old Ethernet_STM library.
The new ported library is 100% compatible with the old one and supports both W5100 and W5500 chips.
The library support the W5200 chip too but I haven't ported it to STM32F1.

The W5500 chip is by far faster than the W5100 !
With the combination of STM32F103, VS1053 and W5500 I managed to play Internet streams (WebRadios) up to 192 kbps / 44000 Hz !
I hope with a source code optimization the bit-rate will be increased up to 320 kbps.

I have one more issue to solve before I publish it. When is used the Static IP the produced hex is almost 23 kB. When is used the DHCP client, the produced hex is almost 80 kB. 248% more flash space.

On Arduino nano (I know it's 8-bit not 32-bit) the Static IP consumes ~10 kB and the DHCP ~13 kB. 30% more flash space.
Nice :)

About the code size, when you compile, it should create a file with .map extension. That shows all the flash and static RAM usage in the code.
I would compile one version, save that .map file somewhere else, then compile the other, and compare them, to see to what functions or ram structures that extra is going.

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: W5500 library is (almost) ported

Post by Vassilis » Wed Aug 19, 2015 10:07 am

victor_pv wrote:About the code size, when you compile, it should create a file with .map extension. That shows all the flash and static RAM usage in the code.
I would compile one version, save that .map file somewhere else, then compile the other, and compare them, to see to what functions or ram structures that extra is going.
Thanks Victor, I will try it

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: W5500 library is (almost) ported

Post by Vassilis » Wed Aug 19, 2015 3:09 pm

The Ethernet_STM library that supports both W5100 and W5500 ethernet chips.
To choose between the W5100 or W5500 you have to edit the file Ethernet_STM\src\utility\w5100.h and comment-out the line of the chip you want to use.
The W5500 has been selected by default.

Code: Select all

//#define W5100_ETHERNET_SHIELD // Arduino Ethenret Shield and Compatibles ...
//#define W5200_ETHERNET_SHIELD // WIZ820io, W5200 Ethernet Shield 
#define W5500_ETHERNET_SHIELD   // WIZ550io, ioShield series of WIZnet

@Victor
I have spent a lot of hours trying to solve why the DHCP consumes a lot of flash memory but I found nothing :(
The DHCP works but it consumes a lot of flash memory. If you compile the Ethernet library for Arduino DUE (DhcpAddressPrinter.ino file) you will see that it produces only a 20 kB hex file :o

Maybe you can figure out what causes that problem .
Attachments
Ethernet_STM.zip
(69.7 KiB) Downloaded 466 times
Last edited by Vassilis on Wed Aug 19, 2015 9:27 pm, edited 1 time in total.

User avatar
martinayotte
Posts: 1194
Joined: Mon Apr 27, 2015 1:45 pm

Re: W5500 library is (almost) ported

Post by martinayotte » Wed Aug 19, 2015 6:33 pm

Thanks, Vassilis !

I will give it a try in next few days on F4 and let you know if Flash consumption problem is there too.

User avatar
Vassilis
Posts: 295
Joined: Thu May 21, 2015 6:42 am
Location: Thessaloniki, Greece
Contact:

Re: W5500 library is (almost) ported

Post by Vassilis » Wed Aug 19, 2015 9:23 pm

martinayotte wrote:Thanks, Vassilis !

I will give it a try in next few days on F4 and let you know if Flash consumption problem is there too.
Thanks Martin !

User avatar
RogerClark
Posts: 6381
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: W5500 library is (almost) ported

Post by RogerClark » Wed Aug 19, 2015 10:08 pm

Often when the bin file gets suddenly large, its because the compiler had to link some features that it normally doesnt need to.

I recall a thread several months ago, where someone complained that the sketch was large and it transpired that the compiler needed to bring in loads of additional classes to support one function.

I cant quite remember what Class it was, but it could have been something to do with strings.

User avatar
martinayotte
Posts: 1194
Joined: Mon Apr 27, 2015 1:45 pm

Re: W5500 library is (almost) ported

Post by martinayotte » Wed Aug 19, 2015 11:21 pm

I was in hurry to try it out ... :)
But I've finally did it with F1, since by MapleMini was on a breadboard with free space for the module (My STM32F4Stamp breadboard was full).
Here are the result (of course, bigger than Vassilis compiles, since I have also many other lib in my Sketch_Buffet, such ad SD, MCP23017, etc) :

Code: Select all

-rwxrwxr-x  1 martin martin  93648 Aug 19 19:04 MapleMini-Buffet-W5500Dhcp.bin*
-rwxrwxr-x  1 martin martin  38560 Aug 19 19:03 MapleMini-Buffet-W5500Static.bin*
If I have time later tonight, I will put back the ArduinoUIP (ENC28J60) and do the same tests.
I will also try to free up space on my STM32F4Stamp breadboard, and do the same tests here also.
As Roger said, I suspect that DCHP is bringing some addtionnal libs from GCC, probably for string parsing. We will see...
Anyway, I kept all the *.map for further investigations.

User avatar
martinayotte
Posts: 1194
Joined: Mon Apr 27, 2015 1:45 pm

Re: W5500 library is (almost) ported

Post by martinayotte » Thu Aug 20, 2015 2:14 am

As promised, I've reverted to my previous ArduinoUIP and I found the same size discripency with DHCP :

Code: Select all

-rwxrwxr-x  1 martin martin 101208 Aug 19 22:09 MapleMini-Buffet-UIPDhcp.bin*
-rwxrwxr-x  1 martin martin  46176 Aug 19 22:11 MapleMini-Buffet-UIPStatic.bin*
Further investigations tomorrow ...

EDIT : this means it is not related with Vassilis's library, so @Vassilis, maybe you can still submit a PR to Roger ...
EDIT2 : as described below, the bug is found, so here the conclusion is that both libraries had the same disease ...
Last edited by martinayotte on Fri Aug 21, 2015 3:00 am, edited 1 time in total.

User avatar
martinayotte
Posts: 1194
Joined: Mon Apr 27, 2015 1:45 pm

Re: W5500 library is (almost) ported

Post by martinayotte » Thu Aug 20, 2015 11:21 pm

I've found the memory issue ! :ugeek:
The problem is that the EthernetClass::begin() function using Dhcp is doing a "_dhcp = new DhcpClass()", which bring the GCC memory management into the linkage. In embedded development, it is almost always bad to use "new" functions.
So, I don't if it is the best way to handle/workaround the bug, I've simply declared a DhcpClass globally and static in Ethernet_STM.cpp, and initialize the _dhcp member with its pointer.

So, resulting binary size is now reasonable :

Code: Select all

-rwxrwxr-x 1 martin martin   43512 Aug 20 19:13 /tmp/build889919623780855637.tmp/MapleMini-Buffet.cpp.bin
The fact that ArduinoUIP have the same issue is also related to memory management, since in the begin() is it doing the "static DhcpClass s_dhcp" inside the begin(), not globally, which probably is also equivalent to "new()" ...

EDIT : I've done the same change to ArduinoUIP under my Netduino F4 folder, although F4 have plenty of space ;) , it good to see such saving :

Code: Select all

-rwxrwxr-x  1 martin martin  109956 Aug 20 19:49 netduino-buffet-before.cpp.bin
-rwxrwxr-x  1 martin martin  70828 Aug 20 19:52 netduino-buffet-after.cpp.bin
@Roger, i've sent you PR for ArduinoUIP of F4.
I will leave Vassilis doing the official fix for W5500.

Conclusion ? if we see some libraries which is doing any "new()", beware, it need to fixed ! :D

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests