W5500 library is (finally) ported

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.


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.


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.

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.

//#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


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.


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.


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.


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) :

-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*


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 :

-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*


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 :
-rwxrwxr-x 1 martin martin 43512 Aug 20 19:13 /tmp/build889919623780855637.tmp/MapleMini-Buffet.cpp.bin


Vassilis
Fri Aug 21, 2015 12:03 pm
Martin, I worked in parallel with you to solve the DHCP problem.

Finally I solve it.

Compiling with static gave me:
Sketch uses 20,476 bytes (15%) of program storage space. Maximum is 131,072 bytes.


mrburnette
Fri Aug 21, 2015 12:18 pm
WOW!

Only 2% delta. I do not even have a need for the class, but may use it simply because it is so efficient! :lol:

Seriously, great job… hope your tests are all successful.

Ray


Vassilis
Sat Aug 22, 2015 7:10 pm
Thanks Ray!

The new library is ready. The old Ethernet_STM library supports only the W5100 chip and it has been published to my GitHub. From there, the Roger was created a link to his repository.
The new library supports both W5100 and W5500 chips. I have made the necessary modifications for supporting the W5200 too, but I don’t have a W5200 Ethernet module to test it.

Should I replace the old “Ethernet_STM” library files on my GitHub with the new “Ethernet_STM” library files (keep the same library name) or should I create a new repository for example Ethernet2_STM ?


martinayotte
Sun Aug 23, 2015 3:25 am
Thanks Vassilis !

Should I replace the old “Ethernet_STM” library files on my GitHub with the new “Ethernet_STM” library files (keep the same library name) or should I create a new repository for example Ethernet2_STM ?
I don’t think keep the old one is worth, since the new lib is also working with W5100, except if you know something that we don’t know. ;)
That is bringing me the question, question not only for you : is the Serasidis_EtherCard_STM still useful ? If not, maybe Roger need to delete too …


Vassilis
Sun Aug 23, 2015 7:53 am
martinayotte wrote:…That is bringing me the question, question not only for you : is the Serasidis_EtherCard_STM still useful ? If not, maybe Roger need to delete too …

martinayotte
Sun Aug 23, 2015 1:24 pm
Vassilis wrote:On the other hand, the UIPEthernet is full compatible with the standard Ethernet library

Vassilis
Sun Aug 23, 2015 1:48 pm
I committed the new Ethernet_STM library.

The DHCP problem was on the “_dhcp = new DhcpClass()” as already told Martin (thanks man!). Sadly, the Martins solution didn’t work for me.
So, what I did was to create a new DhcpClass object globally named _dhcp into the Ethernet_STM.cpp file and the structure dereference lines containing “_dhcp->” replace by “_dhcp.”

For example the line
W5100.setIPAddress(_dhcp->getLocalIp().raw_address());


martinayotte
Sun Aug 23, 2015 3:49 pm
Vassilis wrote:The DHCP problem was on the “_dhcp = new DhcpClass()” as already told Martin (thanks man!). Sadly, the Martins solution didn’t work for me.

Vassilis
Sun Aug 23, 2015 5:21 pm
martinayotte wrote:Vassilis wrote:The DHCP problem was on the “_dhcp = new DhcpClass()” as already told Martin (thanks man!). Sadly, the Martins solution didn’t work for me.

martinayotte
Sun Aug 23, 2015 7:53 pm
Vassilis wrote:I already did that but it didn’t work for me Martin. A lot of errors were appeared during compiling :?

yaqubap
Thu Feb 18, 2016 8:44 am
Anyone use WIZ550io?

WIZ550io has PIC for store IP and MAC address. I use Serasidis STM32duino library. I got NULL when I am trying to get the MAC Address.

I have set the MAC address, but it was not stored to PIC (I always get NULL after WIZ550io rebooted). Anyone can help me?


Vassilis
Thu Feb 18, 2016 12:09 pm
Edit the Ethernet_STM/src/utility/w5100.h file and comment out (enable) the line 22 by removing the double slash
//#define WIZ550io_WITH_MACADDRESS // Use assigned MAC address of WIZ550io

yaqubap
Fri Feb 19, 2016 7:42 am
I have commented out that line, but I still can’t get the MAC address.

I finally know why I can’t get it. Just comment line 45 in file w5500.cpp :

write(0x00, 0x05, 128); // Software reset the W5500 chip


acronis
Tue Jul 11, 2017 8:44 am
Hello.
Will this library work with BLACK Board STM32F407VET6 ?

stevestrong
Tue Jul 11, 2017 8:50 am
Just try it (pay attention to the correct SPI port selection, the F4 board has 3 SPI ports), and post here if something does not work.

acronis
Tue Jul 11, 2017 9:01 am
I use my library #include <Ethernet_STM.h>
a lot of errors.If I use my library a lot of errors

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dhcp.cpp: In member function 'uint8_t DhcpClass::parseDHCPResponse(long unsigned int, uint32_t&)':

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dhcp.cpp:332:55: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

if( *((uint32_t*)_dhcpDhcpServerIp) == 0 ||

^

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:7:0:

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp: In member function 'uint16_t DNSClient::ProcessResponse(uint16_t, IPAddress&)':

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:285:58: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

uint16_t header_flags = htons(*((uint16_t*)&header[2]));

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility/util.h:4:22: note: in definition of macro 'htons'

#define htons(x) ( ((x)<< 8 & 0xFF00) | \

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:285:58: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

uint16_t header_flags = htons(*((uint16_t*)&header[2]));

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility/util.h:5:22: note: in definition of macro 'htons'

((x)>> 8 & 0x00FF) )

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:287:50: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

if ( ( iRequestId != (*((uint16_t*)&header[0])) ) ||

^

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:7:0:

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:304:57: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

uint16_t answerCount = htons(*((uint16_t*)&header[6]));

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility/util.h:4:22: note: in definition of macro 'htons'

#define htons(x) ( ((x)<< 8 & 0xFF00) | \

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:304:57: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

uint16_t answerCount = htons(*((uint16_t*)&header[6]));

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility/util.h:5:22: note: in definition of macro 'htons'

((x)>> 8 & 0x00FF) )

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:313:58: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

for (uint16_t i =0; i < htons(*((uint16_t*)&header[4])); i++)

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility/util.h:4:22: note: in definition of macro 'htons'

#define htons(x) ( ((x)<< 8 & 0xFF00) | \

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\Dns.cpp:313:58: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

for (uint16_t i =0; i < htons(*((uint16_t*)&header[4])); i++)

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility/util.h:5:22: note: in definition of macro 'htons'

((x)>> 8 & 0x00FF) )

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\socket.cpp: In function 'uint16_t igmpsend(SOCKET, const uint8_t*, uint16_t)':

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\socket.cpp:322:11: warning: variable 'status' set but not used [-Wunused-but-set-variable]

uint8_t status=0;

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp: In member function 'void W5500Class::init()':

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:37:19: error: no matching function for call to 'SPIClass::begin(int)'

SPI.begin(SPI_CS);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:37:19: note: candidate is:

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src/utility/w5100.h:13:0,

from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:13:

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:170:10: note: void SPIClass::begin()

void begin(void);

^

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:170:10: note: candidate expects 0 arguments, 1 provided

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:42:32: error: no matching function for call to 'SPIClass::setClockDivider(int, int)'

SPI.setClockDivider(SPI_CS, 2); // 42 Mhz, ok

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:42:32: note: candidate is:

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src/utility/w5100.h:13:0,

from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:13:

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:198:7: note: void SPIClass::setClockDivider(uint32_t)

void setClockDivider(uint32_t clockDivider);

^

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:198:7: note: candidate expects 1 argument, 2 provided

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:43:36: error: no matching function for call to 'SPIClass::setDataMode(int, spi_mode)'

SPI.setDataMode(SPI_CS, SPI_MODE0);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:43:36: note: candidate is:

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src/utility/w5100.h:13:0,

from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:13:

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:200:7: note: void SPIClass::setDataMode(uint8_t)

void setDataMode(uint8_t dataMode);

^

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:200:7: note: candidate expects 1 argument, 2 provided

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp: In static member function 'static uint8_t W5500Class::write(uint16_t, uint8_t, uint8_t)':

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:132:36: error: 'SPI_CONTINUE' was not declared in this scope

SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:135:29: error: no matching function for call to 'SPIClass::transfer(int, uint8_t&)'

SPI.transfer(SPI_CS, _data);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:135:29: note: candidate is:

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src/utility/w5100.h:13:0,

from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:13:

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:261:11: note: uint8 SPIClass::transfer(uint8) const

uint8 transfer(uint8 data) const;

^

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:261:11: note: candidate expects 1 argument, 2 provided

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp: In static member function 'static uint16_t W5500Class::write(uint16_t, uint8_t, const uint8_t*, uint16_t)':

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:162:36: error: 'SPI_CONTINUE' was not declared in this scope

SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:168:30: error: no matching function for call to 'SPIClass::transfer(int, const uint8_t&)'

SPI.transfer(SPI_CS, _buf[i]);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:168:30: note: candidate is:

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src/utility/w5100.h:13:0,

from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:13:

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:261:11: note: uint8 SPIClass::transfer(uint8) const

uint8 transfer(uint8 data) const;

^

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:261:11: note: candidate expects 1 argument, 2 provided

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp: In static member function 'static uint8_t W5500Class::read(uint16_t, uint8_t)':

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:191:38: error: 'SPI_CONTINUE' was not declared in this scope

SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:194:43: error: no matching function for call to 'SPIClass::transfer(int, int)'

uint8_t _data = SPI.transfer(SPI_CS, 0);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:194:43: note: candidate is:

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src/utility/w5100.h:13:0,

from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:13:

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:261:11: note: uint8 SPIClass::transfer(uint8) const

uint8 transfer(uint8 data) const;

^

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:261:11: note: candidate expects 1 argument, 2 provided

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp: In static member function 'static uint16_t W5500Class::read(uint16_t, uint8_t, uint8_t*, uint16_t)':

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:221:38: error: 'SPI_CONTINUE' was not declared in this scope

SPI.transfer(SPI_CS, _addr >> 8, SPI_CONTINUE);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:227:42: error: no matching function for call to 'SPIClass::transfer(int, int)'

_buf[_len-1] = SPI.transfer(SPI_CS, 0);

^

C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:227:42: note: candidate is:

In file included from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src/utility/w5100.h:13:0,

from C:\Users\Admin\Documents\Arduino\libraries\Ethernet_STM-master\src\utility\w5500.cpp:13:

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:261:11: note: uint8 SPIClass::transfer(uint8) const

uint8 transfer(uint8 data) const;

^

C:\Users\Admin\Documents\Arduino\hardware\Arduino_STM32-master\STM32F4\libraries\SPI\src/SPI.h:261:11: note: candidate expects 1 argument, 2 provided


zoomx
Tue Jul 11, 2017 9:21 am
acronis,
please provide
Which board are you using?
Which core are you using?

I loaded the Telnet example and it compiles withouth errors. Try using an example.


acronis
Tue Jul 11, 2017 9:28 am
BLACK Board STM32F407VET6
[libmaple] Black F407VET6 ( https://github.com/stevstrong/Arduino_STM32)

stevestrong
Tue Jul 11, 2017 9:42 am
The problem is that this lib still has some defines for non-STM32 devices.
This lib is working for F1 family due to:
#if defined(__STM32F1__)

stevestrong
Wed Jul 12, 2017 8:32 am
I will rework this library because it has many things which are not configurable but which should be, for instance the SPI class object (currently is fix coded).
And I will remove all non-STM32 references to avoid further issues.

acronis
Wed Jul 12, 2017 8:57 am
Great !
I am very grateful for YOUR work !
You do so much for everyone !

THANK you !!!


stevestrong
Sat Jul 29, 2017 9:30 am
I finally managed to rework the existing Ethernet lib from Vassilis (thanks for the great job, Vassilis!) in a more generally usable way.
https://github.com/stevstrong/Ethernet_STM32

The main changes:
– in only works on W5500-based boards, any other derivative target has been removed
– it only supports STM32F1 and F4, any other reference to AVR or other targets has been removed
– there is no need to edit any header file for setup, the SPI object and the chip select pin is passed by using an additional function:
Ethernet.init([spi_object], [chip_select_pin]);


acronis
Sat Jul 29, 2017 12:10 pm
WOW !
SUPER !
I’M REALLY WAITING FOR THIS !

Could you tell me what pins you need and where to connect, I will check !

https://ru.aliexpress.com/item/Free-shi … 0.0.H5Ls9p

Thank YOU very much for your work !


stevestrong
Sat Jul 29, 2017 3:08 pm
I think it is straight forward.
You need to connect the appropriate SPI pins (of which ever SPI port you want), the chip select and power supply 5V + GND.
The 3.3V, INT and RST pins are not used.

Vassilis
Thu Sep 14, 2017 11:53 am
@stevestrong
I like the way anyone can choose the SPI port and CS pin.
Well done !

efftek
Mon Aug 27, 2018 11:43 am
Hi Guys,

Thanks for all your hard work porting this library. I have a query.

I want to use a number of STM32duinos to send sensor information to a PC. The PC will request this information and I want to be able to assign the IP address to each module myself rather than it possibly having a different address each time the power has been off etc. I am just starting and this is the code I have so far.

#include <Ethernet_STM32.h>
#include <SPI.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 16, 1);
//EthernetClient client;

SPIClass mSpi(2);

void setup()
{
Serial.begin(115200);
delay(3000);
Ethernet.init(mSpi, PB12);
Ethernet.begin(mac, ip);
Serial.print(" IP Address assigned ");
Serial.println(Ethernet.localIP());

}

void loop()
{
}


Vassilis
Mon Aug 27, 2018 2:47 pm
If you want to set static IP to your W5500, it is better to set the dns, gateway and subnet mask also.

void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)


stevestrong
Mon Aug 27, 2018 3:23 pm
A small extension what Vassilis already pointed out.

[efftek – Mon Aug 27, 2018 11:43 am] –
Now, it reports that this IP address ( 192.168.16.1) has been assigned but I can’t ping it. Ive also tried several other addresses.

The router will not accept a fix IP allocation if DHCP is activated, that is why you cannot ping it from other net client.
A static IP address is only accessible if the DHCP is deactivated on the router. In this case you need all net components to have static IP addresses allocated.


efftek
Tue Aug 28, 2018 8:00 am
Thanks Vassilis & Steve. Thats answered a couple of questions and created a new one.

If I use DHCP to dynamically allocate the IP addresses, when a bluepill module (server) comes online, it can contact the client to anounce itself, give its serial number which can identify who it is and its latest IP address. The client will look up the serial number in its database and change the IP address stored for it so it knows how to contact it to request data. That seems straightforward and sensible. But how does the server know what the clients IP address is if it isnt static?

So can I give the PC client a fixed IP address and still use DHCP to allocate the server’s individual addresses?

This networking stuff is all new to me and Im confused. Thanks for your guidance.

Steve F.


stevestrong
Wed Aug 29, 2018 1:23 pm
Normally the client contacts first the server, not vice versa.
In case both the server and the client are attached to a DHCP router, they both will get IP addresses allocated.
You have to find out the server address and hard code it in the client application, so the client has to know the server address. The server will find out the client address when the client issues a request to the server.

efftek
Wed Sep 05, 2018 2:09 pm
Hi Guys,

Next problem.

I have the STM32 working with the W5500 board. I create the MAC address from the STM32’s ID no and the DCHP sets the IP address. My PC can send a request and the STM32 reply. I now need to get the SD card working – the volume of data I need to collect from the ADC at 10,000 sps has to be written to SD card and then sent onwards by Ethernet.

The W5500 is on SPI2 and the SD card, SPI1 – Id be happy to put the SD card on SPI2 also if I knew how to change the SD settings.

This code initialises the W5500
#include <Ethernet_STM32.h>
#include <SPI.h>
#include <SD.h>

Sd2Card card;
SdVolume volume;
SdFile root;

const int chipSelect = 4;

byte *id5 = (byte *) (0x1FFFF7EC);
byte *id4 = (byte *) (0x1FFFF7EC+0x01);
byte *id3 = (byte *) (0x1FFFF7EC+0x02);
byte *id2 = (byte *) (0x1FFFF7EC+0x03);
byte *id1 = (byte *) (0x1FFFF7EC+0x04);
byte mac[] = { 0xEA, *id1, *id2, *id3, *id4, *id5 };

unsigned int localPort = 8000;
EthernetServer server(localPort);
SPIClass mSpi(2); //USING SPI2 PB12-PB15

void setup()
{
Serial.begin(115200);
delay(3000);
Ethernet.init(mSpi, PB12);
Ethernet.begin(mac);
Serial.print("IP Address assigned ");
Serial.println(Ethernet.localIP());
server.begin();
}


stevestrong
Wed Sep 05, 2018 5:23 pm
Two suggestions (tested) to make both devices to work.

1. change the order of SD card init and Ethernet init

2. leave this order, and before card.init() call:
SPI.setModule(1);


efftek
Wed Sep 05, 2018 5:37 pm
Thanks SteveStrong,

I will try this in the morning. I’ll keep you posted.


efftek
Thu Sep 06, 2018 6:52 am
Fantastic! Thank you so much for your assistance.

A bit of experimenting (without the W5500 card connected) and I find I can simply use
SPI.setModule(2);
card.init(SPI_HALF_SPEED, 8));


stevestrong
Thu Sep 06, 2018 7:32 am
Two or more devices on the same port will share the SPI speed settings unless you call
SPI.beginTransaction(SPISettings(<speed_in_Hz>, [other_params])); // only speed is mandatory, the rest is optional

efftek
Thu Sep 06, 2018 8:53 am
Once again, thank you so much for your help. I’m so glad the world has people like you (and all the other people on here, Roger, Ray, Vassilis, Squonk, Rick et al) who are happy to share their knowledge. I can’t thank you ALL enough.

I wish I knew half as much about this topic as you do, but then you’d still know twice as much as me!


efftek
Tue Sep 18, 2018 5:15 am
Guys,

This is my code for starting conncting my BluePill to the ethernet
void StartEther()
{
SPI.setModule(1);
Ethernet.init(PA4);
if(Ethernet.begin(mac))
{
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
else
Serial.println("Server FAIL");
}


stevestrong
Tue Sep 18, 2018 6:34 am
https://www.dummies.com/programming/net … p-command/:
An ARP cache is a simple mapping of IP addresses to MAC addresses. Each time a computer’s TCP/IP stack uses ARP to determine the Media Access Control (MAC) address for an IP address, it records the mapping in the ARP cache so that future ARP lookups go faster.
Afaik, as long as you do not access the new IP address, the cache cannot know it, since it works only from “cache”.

efftek
Tue Sep 18, 2018 7:06 am
[stevestrong – Tue Sep 18, 2018 6:34 am] –
Afaik, as long as you do not access the new IP address, the cache cannot know it, since it works only from “cache”.

Thanks again, that would explain how the IP address is in the arp list after I ping it and not before. So, is there a way I access the IP address from the BluePill after the server.begin() command once it know’s its own address? Can I set it up as a client first then become a server?

Cheers, Steve


stevestrong
Tue Sep 18, 2018 8:40 am
Normally, if you don’t change the MAC address of the device, it should get the same IP address each time it is connecting to the DHCP enabled router.
Thus you know its IP address.

OTOH, this is what I have found on the net:
https://www.iplocation.net/find-private-network-ip:

How do I find the IP address of all devices on my network?
Ping your network using a broadcast address, i.e. “ping 192.168.1.255”. After that, perform “arp -a” to determine all the computing devices connected to the network. 3. You may also use “netstat -r” command to find an IP address of all network routes.


efftek
Wed Sep 19, 2018 7:37 am
SORTED!!!

I will be installing 20 modules at various locations on a plant on their own network using PoE. Each module has its own mac based on the STM32’s unique ID so I know which mac I have installed where and I can assign them on the Client PC to units on a database but first they need to appear in the arp table so the client PC can see them and their IP addresses.

I have managed to get the modules to appear in the arp table straight away. This is how I did it. I set my client PC to a static IP address 192.168.2.14 (the one it happened to be at the time) and declared;
IPAddress ip(192, 168, 2, 14);
EthernetServer server(6000);
EthernetClient arp;


All Comments

Leave a Reply

Your email address will not be published. Required fields are marked *