---
title: "Nucleo-G031 W5500 mongoose"
url: "https://maker.wiznet.io/Aimee0/projects/nucleo-g031-w5500-mongoose/"
markdown_url: "https://maker.wiznet.io/Aimee0/projects/nucleo-g031-w5500-mongoose/md"
type: "UCC: User Created Content"
author: "Aimee"
author_url: "https://maker.wiznet.io/Aimee0/"
original_author: "Aimee"
original_url: "https://github.com/cesanta/mongoose/tree/master/examples/stm32/nucleo-g031-make-baremetal-builtin"
published: "2024-01-02"
language: "en"
hardware: ["WIZnet W5500"]
likes: 0
views: 346
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Nucleo-G031 W5500 mongoose

> This is a project that uses the mongoose library to perform network communication over the W5500 Ethernet controller.

Original author: Aimee (source: https://github.com/cesanta/mongoose/tree/master/examples/stm32/nucleo-g031-make-baremetal-builtin)

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

- [mongoose](https://github.com/cesanta/mongoose/tree/master/examples/stm32/nucleo-g031-make-baremetal-builtin) (code)

## Article

This is a project that uses the mongoose library to perform network communication over the W5500 Ethernet controller.

**What is mongoose?**

Mongoose is a lightweight web server and web framework library used in embedded systems and IoT devices. Based on event-based and non-blocking architecture, it supports various protocols such as TCP, UDP, HTTP, WebSocket, and MQTT.

#main.c

```plaintext
  // Initialise Mongoose network stack
  spi_init(&spi_pins);
  struct mg_tcpip_spi spi = {
      .begin = (void (*)(void *)) spi_begin,
      .end = (void (*)(void *)) spi_end,
      .txn = (uint8_t(*)(void *, uint8_t)) spi_txn,
      .spi = &spi_pins,
  };
  struct mg_tcpip_if mif = {.mac = GENERATE_LOCALLY_ADMINISTERED_MAC(),
                            // Uncomment below for static configuration:
                            // .ip = mg_htonl(MG_U32(192, 168, 0, 223)),
                            // .mask = mg_htonl(MG_U32(255, 255, 255, 0)),
                            // .gw = mg_htonl(MG_U32(192, 168, 0, 1)),
                            .driver = &mg_tcpip_driver_w5500,
                            .driver_data = &spi};
  mg_tcpip_init(&mgr, &mif);
```

Initializes SPI and initializes settings for the network interface. If you look at “mif.driver”, it is connected to the mg_tcpip_driver_w5500 structure and the structure is defined in mongose/src/drivers/w5500.c.

```plaintext
  for (;;) {
    mg_mgr_poll(&mgr, 0);
  }
```

Continue polling the Event Manager in the for(;;).

---

Source: https://maker.wiznet.io/Aimee0/projects/nucleo-g031-w5500-mongoose/
