---
title: "RyanW5500 BSD socket implementation"
url: "https://maker.wiznet.io/praveen_k/projects/ryanw5500-bsd-socket-implementation/"
markdown_url: "https://maker.wiznet.io/praveen_k/projects/ryanw5500-bsd-socket-implementation/md"
type: "UCC: User Created Content"
author: "Ryan_CW"
author_url: "https://club.rt-thread.org/ask/article/1d915f397d88494d.html"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Ryan_CW"
original_url: "https://club.rt-thread.org/ask/article/1d915f397d88494d.html"
license: "Apache License 2.0 (Apache-2.0)"
published: "2023-01-03"
language: "en"
hardware: ["WIZnet W5500"]
likes: 7
views: 580
comments: 1
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# RyanW5500 BSD socket implementation

> RyanW5500 implements some common BSD socket APIs.

Original author: Ryan_CW (source: https://club.rt-thread.org/ask/article/1d915f397d88494d.html)

## Components

- **WIZnet W5500** x 1 ([docs](https://docs.wiznet.io/Product/Chip/Ethernet/W5500))

WIZnet parts: W5500 ([Datasheet](https://docs.wiznet.io/Product/Chip/Ethernet/W5500/datasheet?utm_source=maker&utm_medium=project&utm_campaign=w5500), [product hub](https://maker.wiznet.io/products/w5500/))

## Documents and links

- [Ryan-CW-Code / RyanW5500](https://github.com/Ryan-CW-Code/RyanW5500) (code)

## Article

1 Introduction
RyanW5500 implements some common BSD socket APIs.

BSD socket API facilitates porting of upper layer applications
Developed based on wizchip socket, optimized to support RTOS, avoiding infinite loop
dhcp automatic lease renewal
Less resource usage
Docking RT-Thread sal and netdev components
2. Design
Temporarily only supports W5500, only W5500 in hand.

In the implementation, all the wizchip interfaces that can be used use the wizchip interface, which is convenient for transplantation to other chip platforms of wiz.

To be added

3. Platform interface
Only RT-Thread is supported for the time being, and cross-platform will be considered later (more troublesome).

4. Examples
To use the RyanW5500 package, you need to select it in the package management of RT-Thread:

Enable RyanW5500 example : configure and start RyanW5500 example
SPI device name : Configure the name of the device using SPI (users should mount the spi device to the bus in advance)
Reset PIN number : Configure the reset pin number of the device connection (modify according to the actual pin number)
IRQ PIN number : Configure the interrupt pin number of the device connection (modify according to the actual pin number)
Version : software package version selection (before the official version is released, latest is recommended, and bugs will be fixed in time)
For detailed use, please refer to example, which provides some test interfaces and usage examples

The figure below shows the test of sending data using udp echo server and tcp echo server.

A udp client 40ms polling send

Two tcp clients send 40/30ms polling

The result is quite stable, the usage of f407cpu is about 20%, it will be better if dma is turned on.

5. Dependence
ulog component
SAL components
netdev-components
spi
pin
6. Declaration
If you encounter problems, you can ask questions in the issue / RT-Thread community, thank you.

4 likes Post a comment share collect grateful report
2 comments

xiaorui4 days ago
Xiaorui figure https://item.taobao.com/item.htm?id=674889867009
Thanks for sharing, what room for improvement is there in the original PR?

0 Reply report

Ryan_CW4 days ago
The guy is lazy and writes nothing!
Many of @xiaorui
RyanW5500 refer to the wiznet package, and originally wanted to provide a pr for the wiznet package.
The W5500 module selected before the project, combined with kaway-mqtt (the mqtt that comes with lwip has been used before), will fall into a state of suspended animation at every turn.
Later, I chose lan8720 (mqtt was also replaced by RyanMqtt ), but using lan8720 limited many single-chip models.
Recently, I have time. I want to be familiar with w5500, and then I can use it directly when I meet Ethernet requirements.

In my opinion, there may be problems with wiznet:
1. The resource consumption is a little bit high, which may be caused by later repairs.
RyanW5500 only needs an event flag group, a mutex, and a thread. Listen requires a message queue. A small modification has been made to the dhcp / dns library to reduce resource consumption
. 2. The wizchip library is implemented based on bare metal, and there are many infinite loops , A little problem in the communication may lead to a crash . RyanW5500 adds delay and timeout judgment in it
. 3. If there are multiple sockets in use and the data transmission is very fast, it may be too late to write 1 to the interrupt flag bit of w5500 in the interrupt callback function, so that w5500 will not trigger an interrupt again. It is almost inevitable that
RyanW5500 reads the SIR register cyclically after receiving the interrupt to ensure that the socket channel interrupt has been cleared before exiting
4. No use of errno (probably not a shortcoming)

I can't remember the rest

---

Source: https://maker.wiznet.io/praveen_k/projects/ryanw5500-bsd-socket-implementation/
