Skip to main content

Introduction and initial setup of embedded ethernet

Introduction

Ethernet is the protocol used to communicate between all the components. It uses the auto-generated Ethernet driver code from cubeMX to use the physical Ethernet peripheral. It also uses LWIP to do the lowest levels of packet handling. Lastly, we use freeRTOS for multi threading. The current implementation cannot work without it.

CubeMX

CubeMX is used to automatically generate setup code for the stm32. To use Ethernet you have to set up a few things in cubeMX. To write this driver I mostly used videos from ControllersTech on YouTube as documentation. The most useful video is STM32 Ethernet (Part 1): How to configure Ethernet peripheral and perform successful ping test. So if you do not understand anything, watch that video.

ETH

ETH is under connectivity in cubeMX. It sets up the Ethernet peripheral. Set it to RMII mode.

afbeelding.png

Turn on Ethernet global interrupt in NVIC settings.

afbeelding.png

Setup all the PINS like it is done in the PIN schematic.

image.png


LWIP

LWIP is a middleware generated by cubeMX. You can find it under middleware.

General settings

image.png

The most important configurations here are the DHCP and IP address settings. The IP address settings don't matter, they will be set in a configuration file in the code.

Key options

The most important part of the tab Key options is to check if LWIP_ARP is enabled. You also need to keep track of the MEM_SIZE (Heap Memory Size). Start with a value of 1024*16 bytes. That is the value I use, but it can be changed if need be.

Platform Settings

Set up LAN8742, to signal that that is the physical Ethernet driver you use.

image.png

CORTEX_M7

You can find CORTEX_M7 under System Core.

Turn on CPU ICache and CPU DCache.

Setup memory protection like seen below

image.png

The MPU Region Base Address is the address of the first Rx descriptor (seen in the ETH tab). The MPU region size is calculated using heap memory size and the RX buffers. Watch the video mentioned above for more information.

FreeRTOS

Freertos is automatically integrated in LWIP if you turn it on in cubeMX. It does not have to be modified, it just has to be turned on. Make sure you use CMSIS_V2, because V1 did not work well.

The Code

After you generate the code for your board, you can look through networking component, in the ethernet.h file, to see all public Ethernet functions. For a full guide of how to use Ethernet, I refer you to Driver usage.