---
title: "W5500 and mbed-os 5"
url: "https://maker.wiznet.io/forum/13628"
markdown_url: "https://maker.wiznet.io/forum/13628/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "JojoS"
created: "2020-01-04T13:49:07+09:00"
last_activity: "2020-08-27T07:17:31+09:00"
language: "en"
views: 1914
replies: 10
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500 and mbed-os 5

## Question

Asked by JojoS on 2020-01-04 in Ethernet Chips.

hello,
I’m trying to use W5500 with Mbed. have tried the examples from

![](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/a/a850d1328011795701f0cf04184ff1afc5e808f1.png) [os.mbed.com](https://os.mbed.com/teams/EthernetInterfaceW5500-makers/code/W5500Interface//file/5499fa2d8898/EthernetInterface.cpp/)

### [W5500Interface - This is the Interface library for WIZnet W5500 ch… | Mbed](https://os.mbed.com/teams/EthernetInterfaceW5500-makers/code/W5500Interface//file/5499fa2d8898/EthernetInterface.cpp/)

This is the Interface library for WIZnet W5500 chip which forked of EthernetInterfaceW5500, WIZnetInterface and WIZ550ioInterface. This library has simple name as "W5500Interface". and can be used for Wiz550io users also.

and

![](https://github.githubassets.com/favicons/favicon.svg) [github.com](https://github.com/Wiznet/mbed-os-example-sockets/tree/master)

### [GitHub - Wiznet/mbed-os-example-sockets: Simple example for the network-socket...](https://github.com/Wiznet/mbed-os-example-sockets/tree/master)

[master](https://github.com/Wiznet/mbed-os-example-sockets/tree/master)

Simple example for the network-socket API. Contribute to Wiznet/mbed-os-example-sockets development by creating an account on GitHub.

The 2nd does not compile with W5500, event include path are wrong. After fixing, the init with MAC failed. The MAC is set and the a hardware reset is called. After fixing this, the IP is delivered by DHCP, but then init is called and a hardware reset is performed again.
It looks like this was never tested and is not maintained, the Issue button is also disabled for this repo.
I was able to fix this woes, but now the SPI communication is stopping after about 7-8 s. There are also a lot of polling loops that do not yield. Is there some better code for working with multitasking OS?
thanks, Johannes

## Replies

### Reply 1 by teddy, 2020-01-07

hello
I will update that’s code.
please, see this code.

![](https://github.githubassets.com/favicons/favicon.svg) [GitHub](https://github.com/WIZnet-MbedEthernet/mbed-os-example-sockets_Nucleo-F103RB_W5500)

![](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/7/782e430f5eb14fa10227c5e3b2fcac46159888c1.png)

### [GitHub - WIZnet-MbedEthernet/mbed-os-example-sockets_Nucleo-F103RB_W5500:...](https://github.com/WIZnet-MbedEthernet/mbed-os-example-sockets_Nucleo-F103RB_W5500)

using Mbed Studio Nucleo-F103RB With W5500 api.ipify.org get External IP address - GitHub - WIZnet-MbedEthernet/mbed-os-example-sockets_Nucleo-F103RB_W5500: using Mbed Studio Nucleo-F103RB With W5...

Or you create mbed-os-example-sockets.
Import WIZnetInterface library to the project.

![](https://github.githubassets.com/favicons/favicon.svg) [GitHub](https://github.com/WIZnet-MbedEthernet/WIZnetInterface)

![](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/4/4317273465271bd11ff88be17a214088ed2177b0.png)

### [GitHub - WIZnet-MbedEthernet/WIZnetInterface: arm Mbed-OS 5 WIZnet chipset...](https://github.com/WIZnet-MbedEthernet/WIZnetInterface)

arm Mbed-OS 5 WIZnet chipset driver (W7xxx, W5/6xxx) - GitHub - WIZnet-MbedEthernet/WIZnetInterface: arm Mbed-OS 5 WIZnet chipset driver (W7xxx, W5/6xxx)

and modify file ‘mbed_app.json’
{

```
"config": {
    "network-interface":{
        "help": "options are ETHERNET, ETHERNET_WIZNET",
        "value": "ETHERNET_WIZNET"
    }
},
"target_overrides": {
    "*": {
        "platform.stdio-baud-rate": 115200,
        "platform.stdio-convert-newlines": true,
        "mbed-trace.enable": 0
    }
}
```

}

and check file ‘mbed_lib.json’ in WIZnetInterface
{

```
"name": "WIZNET",
"config": {
    "sck": {
        "help": "sck pin for spi connection. defaults to SPI_SCK",
        "value": "SPI_SCK"
    },
    "cs": {
        "help": "cs pin for spi connection. defaults to SPI_CS",
        "value": "SPI_CS"
    },
    "miso": {
        "help": "miso pin for spi connection. defaults to SPI_MISO",
        "value": "SPI_MISO"
    },
    "mosi": {
        "help": "mosi pin for spi connection. defaults to SPI_MOSI",
        "value": "SPI_MOSI"
    },
    "rst": {
        "help": "RESET pin for spi connection. defaults to D15",
        "value": "D15"
    },
    "debug": {
        "help": "Enable debug logs. [true/false]",
        "value": flase
    },
    "interface": {
        "help": "Set the wiznet module interface [W5500/W6100]",
        "value": "W5500"
    },
    "socket-bufsize": {
        "help": "Max socket data heap usage",
        "value": 8192
    },
    "default-network": {
        "help": "Set the default network interface",
        "options" : [true,false],
        "value": true
    }
},
"target_overrides": {
}
```

}

### Reply 2 by JojoS, 2020-01-08

Hello Teddy, tanks for your fast reply and your support. The recommended Wiznet Library contains the same problems, f.e. that init first sets the mac address and then calls reset. This deletes the mac and dhcp will fail: github.com WIZnet-MbedEthernet/WIZnetInterface/blob/0b62ecebbb73d8b232b504e2079abcad10b9ae1a/WIZnetInterface.cpp#L139 init_socks(); return 0; } int WIZnetInterface::init(uint8_t * mac) { _dhcp_enable = true; _wiznet.reg_wr&lt;uint32_t>(SIPR, 0x00000000); // local ip "0.0.0.0" // should set the mac address and keep the value in this class for (int i =0; i &lt; 6; i++) _wiznet.mac[i] = mac[i]; _wiznet.setmac(); _wiznet.reset(); // reset chip and write mac address init_socks(); return 0; } // add this function, because sometimes no needed MAC address in init calling. int WIZnetInterface::init(const char* ip, const char* mask, const char* gateway) { _dhcp_enable = false; In the meantime, I was able to fix a numer of problems by myself: the easy_connect does a dhcp call when used init with mac, but then calls init and reset again, ip is lost there is a WIZNET_ACCEPT_TIMEOUT, but why? In non blocking, it should never timeout. When it is running into timeout, in mbed5 it is hanging at an event in TCPSocket. the socket callbacks are not thread safe, the callback can be set to 0 and then the system is running into hardfault there are some functions deprecated, f.e. const char* get_ip_address(). The newer functions that make use of SocketAddress are not defined yet. there is a Sock Status enumeration which interferes with a mbed definition, I have use a namespace to fix this. I also don’t want to use easy_connect because it is deprecated with current Mbed mechanism to get default EthernetInterface. I’m checking how to integrate it to existing Mbed classes to use also Mbed dhcp and bring_up/down interface. The existing code works only when the ethernet is plugged in at system start. I can publish this on github if you want to adopt or review my changes.

### Reply 3 by teddy, 2020-01-09 (in reply to reply 2)

hello

Now we checked after MBED-OS version updated our code did not execute.

I’m checking. please wait.

I always welcome your opinion. And there is a thought to change.

And here WIZNET_ACCEPT_TIMEOUT is that can’t wait indefinitely before connecting, so we’ve set a timeout.

[github.com](https://github.com/WIZnet-MbedEthernet/WIZnetInterface/blob/0b62ecebbb73d8b232b504e2079abcad10b9ae1a/WIZnetInterface.cpp#L445)

#### [WIZnet-MbedEthernet/WIZnetInterface/blob/0b62ecebbb73d8b232b504e2079abcad10b9ae1a/WIZnetInterface.cpp#L445](https://github.com/WIZnet-MbedEthernet/WIZnetInterface/blob/0b62ecebbb73d8b232b504e2079abcad10b9ae1a/WIZnetInterface.cpp#L445)

```
      

          
1. return NSAPI_ERROR_NO_SOCKET;

          
2. }

          
- 3. SKT(server)->connected = false;
  
- 4. Timer t;
  
5. t.reset();
  
6. t.start();
  
- 7. while(1) {
  
8. if (t.read_ms() > WIZNET_ACCEPT_TIMEOUT) {
  
9. DBG("WIZnetInterface::socket_accept, timed out\r\n");
  
10. return NSAPI_ERROR_WOULD_BLOCK;
  
11. }
  
12. if (_wiznet.is_connected(SKT(server)->fd)) break;
  
13. }
  
- 14. //get socket for the connection
  
15. *handle = get_sock(SKT(server)->fd, SKT(server)->proto);
  
- 16. if (!(*handle)) {
```

Thank you.

### Reply 4 by JojoS, 2020-01-09

Thanks again for your support.
This timeout I have already modified:

```
#define WIZNET_TIMEOUT_INFINITE (-1)
#define WIZNET_ACCEPT_TIMEOUT   WIZNET_TIMEOUT_INFINITE 

        if ((t.read_ms() > WIZNET_ACCEPT_TIMEOUT) && (WIZNET_ACCEPT_TIMEOUT != WIZNET_TIMEOUT_INFINITE)) {
            debug("WIZnetInterface::socket_accept, timed out\r\n");
            return NSAPI_ERROR_WOULD_BLOCK;
        }
```

with WIZNET_ACCEPT_TIMEOUT=WIZNET_TIMEOUT_INFINITE is infinite waiting.
But I’ve checked the generic ioLibrary, maybe it is better to start from scratch with this library?
And instead of using polling, the interrupt and using Mbed Events sounds like a smarter solution?

I have checked also if I can use TCPsocket.set_blocking(false), but the blocking or timeout for reading is not used in the recv/send function.

### Reply 5 by teddy, 2020-01-10

Hello

![](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/48.png) JojoS:

> with WIZNET_ACCEPT_TIMEOUT=WIZNET_TIMEOUT_INFINITE is infinite waiting.

your code is dangerous. if It is not connected, maybe Your program is stuck in an infinite loop and can do nothing.
If timeouts are frequent, it is recommended to increase the timeout time.

And I don’t understand this question.

![](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/48.png) JojoS:

> But I’ve checked the generic ioLibrary, maybe it is better to start from scratch with this library?

I think the interrupt or Mbed Event method is more efficient.

TCPsocket.set_blocking(false) is not WIZNET Function.
now our send/recv Function is not used.
but I will check mbed-os internal Functions with WizInterface Function.
I’ll find a way to be compatible with MBED-OS internal functions and WIZInterface functions.

Thank you

### Reply 6 by JojoS, 2020-01-10

![](https://avatars.discourse-cdn.com/v4/letter/t/da6949/48.png) teddy:

> your code is dangerous. if It is not connected, maybe Your program is stuck in an infinite loop and can do nothing.

yes, you’re right. The code should handle events when the interface is coming up/down, f.e. when the network cable is pulled out and plugged in.

about ioLibrary: the mbed-os related code is a few years old, the ioLibrary is newer. So my question was if it is better to add mbed features to ioLibrary.

### Reply 7 by teddy, 2020-01-13

Hello

Yes. I think so that.
I will also consider the IOLibrary to add the MBED structure.

Thank you.

### Reply 8 by teddy, 2020-01-31

hello.
I’m sorry.
The schedule is getting late.
We will support you as soon as possible.
Please waits for more.
Thank you

### Reply 9 by teddy, 2020-05-07

![](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/48.png) MMMike:

> Sorry to say, but we are waiting for help since almost 3 month now. Please Wiznet Team, help us!

Sorry.
We are currently working.
Please wait a little longer

### Reply 10 by teddy, 2020-08-27

Hello Mike.
Sorry for the delay in response.
We updated WIZnetInterface for mbed-os 6.

![](https://github.githubassets.com/favicons/favicon.svg) [GitHub](https://github.com/WIZnet-MbedEthernet/WIZnetInterface)

![](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/4/4317273465271bd11ff88be17a214088ed2177b0.png)

### [GitHub - WIZnet-MbedEthernet/WIZnetInterface: arm Mbed-OS 5 WIZnet chipset...](https://github.com/WIZnet-MbedEthernet/WIZnetInterface)

arm Mbed-OS 5 WIZnet chipset driver (W7xxx, W5/6xxx) - GitHub - WIZnet-MbedEthernet/WIZnetInterface: arm Mbed-OS 5 WIZnet chipset driver (W7xxx, W5/6xxx)

It is the using method but language is Korean.

[Medium – 24 Jun 20](https://medium.com/wiznet/mbed-studio%EC%97%90%EC%84%9C-w5500-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-4492c0ff7cc2)

![](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/e/ed54b7c857e09944a4b8d39e7639c339c6fad089.jpeg)

### [Mbed Studio에서 W5500 사용하기](https://medium.com/wiznet/mbed-studio%EC%97%90%EC%84%9C-w5500-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0-4492c0ff7cc2)

최초 배포 일자 : 2020/06/24 최종 수정 일자 : 2020/06/24

Reading time: 5 min read

we will translate language later.

thanks.

---

Source: https://maker.wiznet.io/forum/13628
