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

What impact will the cancellation of data roaming have on telecom operators?

With the development of economy and society, the ...

In-depth interpretation of the principles and applications of HTTP/3

HTTP3 is the latest version of the HTTP protocol....

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

What exactly is SmartNIC (Intelligent Network Car...

6 trends that will boost the impact of IoT in 2018

In 2016-2017, the trend of IoT was widely accepte...

Yunnan Yuxi and Huawei Enterprise Cloud deepen cooperation

On March 30, 2017, the People's Government of...

DesiVPS: $110/month-2*E5-2670v2/64GB/1TB SSD/30TB@10Gbps/San Jose data center

DesiVPS is a foreign hosting company headquartere...

Bypassing 5G and heading straight for 6G, Russia made an "incredible" decision

Russia made an incredible decision - abandoning 5...