Talk about STM32 network interruption

Talk about STM32 network interruption

[[380734]]

01 Introduction

Network interrupt vectors: one for normal network operation and another for Ethernet wakeup events (with wakeup frame or magic packet detection) when it is mapped to EXIT line 19

The first network interrupt is reserved for interrupts generated by the MAC and DMA, as described in the MAC Interrupt and DMA Interrupt sections.

The second interrupt is reserved for the interrupt generated by the PMT on a wake-up event. The mapping of the wake-up event to the EXIT line 19 causes the STM32F20X and STM32F21X to exit low-power mode and generate an interrupt.

When an Ethernet wakeup event mapped to EXIT line 19 occurs and the MACPMT interrupt is enabled and there is a rising edge on the EXIT line 19 interrupt is also enabled, they can both wake up the interrupt.

The RS bit (ETH_DMASR register) can be flexibly controlled using the watchdog timer (see ETH_DMARSWTR register). When this watchdog timer is programmed with a non-zero value, the watchdog timer is activated as soon as the RXDMA completes sending a received data frame to the system memory without triggering the receive state because it is not enabled in the corresponding receive descriptor (RDES1[31]). When the timer runs according to the programmed value, the RS bit is set to 1 and an interrupt occurs if the corresponding bit in the ETH_DMAIER register is enabled. The watchdog timer fails before running when a data frame is sent to the memory and RS is set to 1 because the timer is enabled for the descriptor.

Notice:

Reading the PMT control and status register automatically clears the received wakeup frame and received magic packet PMT interrupt flags. However, since the registers for these flags are located in the CLK_RX domain, there may be a significant delay before the firmware can see this update. This delay is particularly long when the RX clock is slow (in 10 Mbit mode) and when the AHB bus is high frequency.

Since the interrupt request from PMT to CPU is based on the same register in CLK_RX domain, the CPU may mistakenly call the interrupt routine a second time even after reading PMT_CSR. Therefore, the firmware may need to poll the received wakeup frame and received magic packet bits and exit the interrupt service routine only if they are both found to be '0'.

02Code

The network interrupt of STM32 should actually be the interrupt of the network-specific DMA. The data packets in the network conform to the 1518 rule, that is, they are 1460 bytes. The data packets received by MAC are 2K bytes. After each data packet on the network is received by MAC, an interrupt will be generated.

The official code is this

Obviously, the query method is used, and no interruption is used.

The interrupts are used as follows:

Configuring Network Interrupts

Comment out the query code provided by the official website.

After we use the interrupt form, the code is

With this code, we have no problem receiving data smaller than the data size of a DMA descriptor, and it is very smooth.

For more information about DMA descriptors, please refer to "DMA Controller for STM32 Network".

When receiving a large amount of data, errors will occur, the reception will be slow, and receiving too much will cause a crash.

The solution is:

Change if to while

In this way, the interrupt will be triggered after the entire data packet is received, thus solving this problem.

This article is reprinted from the WeChat public account "Zhixiao Programming", which can be followed through the following QR code. To reprint this article, please contact the WeChat public account "Zhixiao Programming".

<<:  my country successfully launched the communication technology experimental satellite No. 6: mainly used for satellite communications, radio and television, data transmission and other services

>>:  4 cases, a whole article of valuable information! Make your edge computing not "edge"

Recommend

Global users' views on 5G: Five keys to commercial success

Recently, Ericsson Consumer Lab released the &quo...

5G "new infrastructure", new scenarios, new models

Since the beginning of the year, the central gove...

Why has 5G, which is on the cusp of the trend, not really exploded yet?

Recently, according to foreign media LADbible, th...

Talking about new IP technology in data centers

Ethernet technology, also known as IP technology,...

VULTR Launches Free VPS Plan

VULTR released information about the launch of a ...

How does a mountain city build an education "network"?

As an important part of the country's new inf...

The Difference Between a Network Hub and a Network Switch

What is a Network Hub? A hub in a computer networ...

RackNerd Los Angeles restock, low-cost US VPS annual payment starts from $9.89

RackNerd is a foreign hosting company founded in ...

Brief analysis: What exactly does a smart network card do?

What exactly is SmartNIC (Intelligent Network Car...

Soul-searching question: Do you fully understand TCP&UDP?

Everyone should have heard of TCP and UDP. Both T...