Main Content

Exchanging Ethernet Data with STM32F746G Discovery Board

This example shows you how to use Embedded Coder® Support Package for STMicroelectronics® STM32 Processors to run on the STM32F746G Discovery Board to send and receive the UDP and TCP messages.

Introduction

In this example you will learn how to use TCP/IP Send, TCP/IP Receive, UDP Send and UDP Receive blocks to send and receive Ethernet data with the STM32F746G Discovery Board.

The Ethernet port on the STM32F746G Discovery Board supports the IEEE 802.3 standard.

Prerequisites

We recommend completing Getting Started with Embedded Coder Support Package for STMicroelectronics Discovery Boards.

Required Hardware

To run this example you will need the following hardware:

The STM32F746G Discovery Board provides an Ethernet port. This port can be used for data communication using the lwIP TCP/IP stack.

Hardware and Network Configuration

In this task you will configure the hardware and network properties needed to run this example.

  • The default Configuration of the target models present in this example are configured to get an IP address at startup using DHCP. This workflow is compatible when both the host computer and the target hardware are connected to a router. If you wish to connect the board straight into your host computer with the Ethernet cable, assign the STM32F746G Discovery board with a static IP address. The Ethernet settings are located in the Configuration Parameters of the model under Hardware Implementation > Target Hardware Resources > Ethernet. To choose a static IP address, deselect the Enable DHCP for IP address assignment. This will prompt you to enter the static IP and subnet mask. Ensure that the IP address and subnet mask are unique and appropriate.

Settings for Automatic IP Address Assignment using DHCP:

  • Connect the STM32F746G Discovery Board with a network cable to a router for automatic IP address assignment. In this configuration, the host computer also needs to be connected to the same router. This can be done with a network cable or over WiFi.

Ethernet Settings for Static IP Address Assignment:

  • Connect the STM32F746G Discovery Board with a network cable to the host computer. In this configuration, set the controlCARD with a static IP address.

Task 1 - UDP Communication between the Target and the Host Computer

In this task, you will run the Model Fault-Tolerant Fuel Control System example on the STM32F746G Discovery Board. The control algorithm runs on the target while the host runs a plant simulation of the system. The target and the host communicate via UDP. The target model receives the fuel system control sensors values from the host model and transmits back the calculated fuel mixture ratio to the host computer.

Models Involved in this Example

1. stm32f746gdiscovery_UDP_target

2. stm32f746gdiscovery_UDP_host

Run the Model configured for the target on the hardware

1. Open the stm32f746gdiscovery_UDP_target.

2. Configure the network properties for the model as described in the previous task: Hardware and Network Configuration.

  • On the target UDP Send block, the remote IP port has to match the local IP port of the host model UDP Receive block. Make sure that the remote IP address is matching the host IP address.

  • On the target UDP Receive block, the local IP port has to match the remote IP port of the host model UDP Send block.

3. The UDP Send and Receive blocks on the target model are configured to do a transmit broadcast and receive from all IP address in the subnet. You can change this to send to a specific IP address and receive from a specific IP address if you know the IP address of the host computer.

4. On the stm32f746gdiscovery_UDP_target, press Ctrl+B or On the Hardware tab, click Build, Deploy & Start > Build Stand-Alone to build, load and run the model on the target.

Run the Host Model and analyze the data

  • While the target model is running, run the stm32f746gdiscovery_UDP_host to send simulated sensor data to the target and visualize the calculated response by the controller.

Task 2 - TCP Communication between the Target and the Host Computer

In this task, you will run the Model Fault-Tolerant Fuel Control System example on the STM32F746G Discovery board. The control algorithm runs on the target while the host runs a plant simulation of the system. The target and the host communicate via TCP. The target model receives the fuel system control sensors values from the host model and transmits back the calculated fuel mixture ratio to the host computer.

Note: For multiple clients at the host to communicate with the board configured as a server, there must be multiple server blocks in the board.

Models Involved in this Example

1. stm32f746gdiscovery_TCP_target

2. stm32f746gdiscovery_TCP_host - This model requires Instrument Control Toolbox.

Run the model configured for the target on the hardware

1. Open the stm32f746gdiscovery_TCP_target.

2. Configure the network properties for the model as described in the previous task: Hardware and Network Configuration.

  • On the target TCP Send block, the local IP port has to match the port of the host model TCP Receive block.

  • On the target TCP Receive block, the local IP port has to match the port of the host model TCP Send block.

3. On the stm32f746gdiscovery_TCP_target, press Ctrl+B or on the Hardware tab, click Build, Deploy & Start > Build Stand-Alone to build, load and run the model on the target.

Run the Host Model to receive and analyze the data

  • While the target model is running, run the stm32f746gdiscovery_TCP_host to send simulated sensor data to the target and visualize the calculated response by the controller.

Summary

This example introduced the workflow for exchanging data between Host and the target via Ethernet Communication.