---
title: "Ethernet controller W5300. IPRAW mode"
url: "https://maker.wiznet.io/eric_g/projects/ethernet-controller-w5300-ipraw-mode/"
markdown_url: "https://maker.wiznet.io/eric_g/projects/ethernet-controller-w5300-ipraw-mode/md"
type: "UCC: User Created Content"
author: "Donets Anton"
author_url: "https://blog.radiotech.kz/stm32/ethernet-kontroller-w5300-ipraw-rezhim/"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Donets Anton"
original_url: "https://blog.radiotech.kz/stm32/ethernet-kontroller-w5300-ipraw-rezhim/"
license: "Apache License 2.0 (Apache-2.0)"
published: "2023-01-02"
language: "en"
hardware: ["WIZnet W5300", "STMicroelectronics STM32F405"]
likes: 3
views: 671
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Ethernet controller W5300. IPRAW mode

> IPRAW is data transfer using a layer lower than TCP and UDP.

Original author: Donets Anton (source: https://blog.radiotech.kz/stm32/ethernet-kontroller-w5300-ipraw-rezhim/)

## Components

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

## Article

Original link is <https://blog.radiotech.kz/stm32/ethernet-kontroller-w5300-ipraw-rezhim/>

and posted in the Czech language.

IPRAW is data transfer using a layer lower than TCP and UDP. IPRAW supports protocols such as ICMP (0x01), IGMP (0x02) which can be specified by protocol number (Sn_PROTOR). As I warn you last time, here we are considering an arbitrary package as an example. Of course, you choose your protocol.

### **What do you need:**

— WIZ830MJ;
— STM32F4-Discovery;
— Keil;
- Wireshark (+ WinPcap);
— Colasoft Packet Builder.

The WIZ830MJ connection table to STM32F4-Discovery and part of the register addresses were given in the article [Part 3. W5300 Ethernet Controller. Initialization. Ping](http://blog.radiotech.kz/stm32/ethernet-kontroller-w5300-initsializatsiya-ping/)
Additional register addresses are listed in [Part 4: W5300 Ethernet Controller. MACRAW mode](http://blog.radiotech.kz/stm32/ethernet-kontroller-w5300-macraw-rezhim/)

### **Initializing STM32F4 and W5300**

The STM32F4 initialization (GPIO and TIM6) and W5300 initialization (SHAR, GAR, SUBR, SIPR) procedures were shown in [Part 3. W5300 Ethernet Controller. Initialization. ping](http://blog.radiotech.kz/stm32/ethernet-kontroller-w5300-initsializatsiya-ping/)

### **socket initialization**

We start, as usual, by opening a socket. I chose socket 0, you can choose any of the 8 sockets that will smile at you.
Before initializing the socket, you must specify the MAC address and IP address of the destination:

// Destination MAC address

WriteReg ( S0_DHAR, *0xD027 *) ;

WriteReg ( S0_DHAR2, *0x8885 *) ;

WriteReg ( S0_DHAR4, *0x4D1D *) ;

// destination IP address

WriteReg ( S0_DIPR, *0xC0A8 *) ;

WriteReg ( S0_DIPR2, *0x460B *) ;

Next, we write the S0_PROTOR register in accordance with the protocol chosen (ICMP - 0x01, IGMP - 0x02, TCP - 0x06, UDP - 0x11). Also, the protocol number must be set before the socket is opened.

**do **// ///////////// Initialization of the IPRAW socket /////////////////////////////// /////

{

WriteReg ( S0_PROTOR, *0x0008 *) ; // protocol number

WriteReg ( S0_MR, *0x0003 *) ; // socket in IPRAW mode

WriteReg ( S0_CR, OPEN ) ; // open socket

Dat= ReadReg ( S0_SSR ) ;

}

**while **(( Dat & *0x00FF *) !=SOCK_IPRAW ) ; // socket 0 open in IPRAW mode?

### **Broadcast**

First, by reading the S0_TX_FSR2 register, we check for free memory in the W5300 transmitter memory. We open the data recording cycle. In the registers S0_TX_WRSR and S0_TX_WRSR2 we write the size of the data being sent. Attention!!! It must be specified in bytes. Write the SEND command to the command register.

**while **( 1 )

{

///////////////////// TRANSFER //////////////////////////////////////////

**do **Dat= ReadReg ( S0_TX_FSR2 ) ; // check for free memory

**while **( Dat &lt; SizeB ) ;

**do **//write sent data

{

WriteReg ( S0_TX_FIFOR, SendData ) ;

SendData++;

}

**while **( SendData &lt; SizeW ) ;

WriteReg ( S0_TX_WRSR, *0x0000 *) ; // size of sent data

WriteReg ( S0_TX_WRSR2, SizeB ) ; // size of sent data

WriteReg ( S0_CR, SEND ) ; // sent

delay_us ( 1000 ) ; // just delay between packets

SendData = 0 ;

}

We catch packets on a computer with a sniffer.

![](http://blog.radiotech.kz/wp-content/uploads/2017/07/81085f.jpg)

### **Reception**

The received IP packet according to the datasheet has the following structure: 4 bytes IP address of the destination and 2 bytes data size.

![](http://blog.radiotech.kz/wp-content/uploads/2017/07/bc64aa.jpg)

In order to receive an IPRAW packet, we monitor the S0_RX_RSR2 register, which signals to us that data has been received. We read 4 bytes of the IP address and the size of the data in bytes, we consider how much it will be in words. We read the data into an array and send the RECV command to the S0_CR command register.

**while **( 1 )

{

////////////////////////////////////////////////////////////////////////////

**if **( ReadReg ( S0_RX_RSR2 ) != *0x0000 *) //received data size is non-zero

{

Dat = ReadReg ( S0_RX_FIFOR ) ; // read IP address

Dat = ReadReg ( S0_RX_FIFOR ) ;

pack_size = ReadReg ( S0_RX_FIFOR ) ; // counted data size

// determine how many times to read data

**if **( ( pack_size% 2 ) == 0 ) { read_cnt = pack_size/ 2 ; }

**else **{ read_cnt = ( pack_size+ 1 ) / 2 ; }

**for **( Cnt= 0 ; Cnt &lt; read_cnt; Cnt++ ) //SizeW read received

{

Rcv_data [ Cnt ] = ReadReg ( S0_RX_FIFOR ) ;

}

i++; // packet counter

WriteReg ( S0_CR, RECV ) ; // accepted

}

}

We send a package like this using the Packet Builder. To do this, click on the Send button.

![](http://blog.radiotech.kz/wp-content/uploads/2017/07/db7a1e.jpg)

In the window that appears, select LoopSending, the number is 20 times.

![](http://blog.radiotech.kz/wp-content/uploads/2017/07/1c9fa3.jpg)

In debug mode, we look at the data in Rcv_data. The sniffer shows the same data.

![](http://blog.radiotech.kz/wp-content/uploads/2017/07/fa7074.jpg)

---

Source: https://maker.wiznet.io/eric_g/projects/ethernet-controller-w5300-ipraw-mode/
