---
title: "Nucleo_F412_W5100S_Test"
url: "https://maker.wiznet.io/teddy/projects/nucleo-f412-w5100s-test/"
markdown_url: "https://maker.wiznet.io/teddy/projects/nucleo-f412-w5100s-test/md"
type: "WCC: WIZnet Created Content"
author: "teddy"
original_author: "teddy"
published: "2023-11-20"
language: "en"
tags: ["Internet of Things"]
hardware: ["STMicroelectronics NUCLEO-F412ZG", "wiznet W5100S Ethernet Shield"]
likes: 0
views: 128
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Nucleo_F412_W5100S_Test

> Nucleo_F412_W5100S send udp data

Original author: teddy

## Components

- **STMicroelectronics NUCLEO-F412ZG** x 1
- **wiznet W5100S Ethernet Shield** x 1

## Documents and links

- [Nucleo_F412_W5100S_Test](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test.git) (code): github source code

## Article

## HardWare Set

Nucleo-F412

W5100S-shield

[![HW config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/HW_Set.jpg)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/HW_Set.jpg)

## <https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test#project-set>Project Set

PIN Config

[![PIN config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/PinSet.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/PinSet.png)

CLK Config

[![CLK config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/CLK_Set.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/CLK_Set.png)

GPIO Config

[![GPIO config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/GPIO_Set.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/GPIO_Set.png)

SPI Config

Parameter Settings

[![SPI Parameter config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/SPI_Set_Para.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/SPI_Set_Para.png)

DMA Settings

[![SPI DMA config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/SPI_Set_DMA.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/SPI_Set_DMA.png)

## <https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test#program-seq>Program Seq

Program Diagram

[![Program Diagram](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/w5100_Test_diagram_seq.drawio.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/w5100_Test_diagram_seq.drawio.png)

SPI Config Code

```plaintext
  void csEnable(void)
  {
      HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET);
  }

  void csDisable(void)
  {
      HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_SET);
  }

  void spiWriteByte(uint8_t tx)
  {
      uint8_t rx;
      while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
      HAL_SPI_TransmitReceive(&hspi1, &tx, &rx, 1, 10);
      while (HAL_SPI_GetState(&hspi1) == HAL_SPI_STATE_BUSY_TX);    
  }

  uint8_t spiReadByte(void)
  {
      uint8_t rx = 0, tx = 0xFF;
      while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY);
      HAL_SPI_TransmitReceive(&hspi1, &tx, &rx, 1, 10);
      while (HAL_SPI_GetState(&hspi1) == HAL_SPI_STATE_BUSY_RX);
      return rx;
  }

  static void wizchip_read_burst(uint8_t *pBuf, uint16_t len)
  {
      HAL_SPI_Receive_DMA(&hspi1, pBuf, len);
      while (HAL_DMA_GetState(hspi1.hdmarx) == HAL_DMA_STATE_BUSY);
      while (HAL_SPI_GetState(&hspi1) == HAL_SPI_STATE_BUSY_RX);    
      return;
  }

  static void wizchip_write_burst(uint8_t *pBuf, uint16_t len)
  {
      HAL_SPI_Transmit_DMA(&hspi1, pBuf, len);
      while (HAL_DMA_GetState(hspi1.hdmatx) == HAL_DMA_STATE_BUSY);
      while (HAL_SPI_GetState(&hspi1) == HAL_SPI_STATE_BUSY_TX);
      return;
  }
```

## <https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test#test-config>Test Config

[![Test Config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/w5100_Test_diagram_config.drawio.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/w5100_Test_diagram_config.drawio.png)

## <https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test#result>Result

Program Log

[![SPI DMA config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/Prog_Log1.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/Prog_Log1.png)

AX2

[![SPI DMA config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/AX2_Cap.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/AX2_Cap.png)

WireShark

[![SPI DMA config](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/raw/main/Image/wireshark_cap.png)](https://github.com/wiznetmaker/Nucleo_F412_W5100S_Test/blob/main/Image/wireshark_cap.png)

When transmitting 41,820 bytes using UDP, with a TX buffer allocated at 8K and an SPI clock at 20 MHz utilizing DMA, the results indicated that each transmission took approximately 25 to 35 milliseconds.

---

Source: https://maker.wiznet.io/teddy/projects/nucleo-f412-w5100s-test/
