STM32F4 LAN8720 and LWIP porting and debugging records (3)

Publisher:快乐时刻Latest update time:2018-04-22 Source: eefocusKeywords:STM32F4  LAN8720  LWIP Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

LAN8720 configuration: 
IP: 192.168.192.30 
Gateway: 192.168.192.1


A high frequency of ARP packets is detected

The content of the packet asks for the mac address of 192.168.192.1, and asks the responder to send to 192.168.192.30. 
It can be judged that LAN8720 may want to send packets across the network segment, but cannot find the network manager. 
So the gateway of LAN8720 is changed to 192.168.192.15, which is the IP of the PC. 
Then use wireshark to capture the packet. 
You can see the high-frequency error packet information. 
Write the picture description here 
From the captured packet, you can see that the IP address and port are not what you want. 
Find the IP address assignment in the sendto function, the atomic routine, the assignment method is as follows:

upcb->remote_ip=*addr;1

The type of remote_ip in pcb is the same as the type of addr, both are: struct ip_addr *

/* This is the aligned version of ip_addr_t,
   used as local variable, on the stack, etc. */
struct ip_addr {
  u32_t addr;
};12345

So I changed my code to:

pcb->remote_ip.addr = 0x0FC0A8C0;1

So it was sent out.

When the content sent is an array, it will die in the sending function.

Call stack before sending: 
Call stack before sending

The call stack after calling sendto: 
Write the picture description here 
Then it will crash when the stack is popped later.

If you try using an atomic routine, the code will also fall into a Hardfault. 
Atomic routine:


//UDP server sends data

void udp_demo_senddata(struct udp_pcb *upcb)

{

    struct pbuf *ptr;

    ptr=pbuf_alloc(PBUF_TRANSPORT,strlen((char*)tcp_demo_sendbuf),PBUF_POOL); //Apply for memory

    if(ptr)

    {

        ptr->payload=(void*)tcp_demo_sendbuf; 

        udp_send(upcb,ptr); //udp sends data

        pbuf_free(ptr); //release memory

    } 


The strange thing is 

ptr->payload = (void*)tcp_demo_sendbuf; 

The payload does not use memcpy but is directly assigned by a pointer. 

According to the example on the Internet, change this to:


memset(ptr->payload, 0, ptr->len);

memcpy(ptr->payload, dataptr, sendsize); 


Then no error is reported. I don't know why the atomic one can run through.

The recvfrom function crashed


int len;

len = recvfrom(socket_n, _commandBuffer, len, MSG_DONTWAIT, (sockaddr *)&remoteaddr, &remoteaddrlen);


The problem is that the third parameter passed in, len, is the buffer length. 

The requested len is mistakenly passed in as a value. 

In the recvfrom function, memset is called to clear the buffer. Then the code crashes.


Keywords:STM32F4  LAN8720  LWIP Reference address:STM32F4 LAN8720 and LWIP porting and debugging records (3)

Previous article:STM32F407 and LAN8720 debug log (1)
Next article:Solution to the network failure when hot-plugging the network cable of STM32 transplantation LWIP

Recommended ReadingLatest update time:2024-11-23 01:47

STM32f4 timer interrupt experimental code
Let's take a look at our time.c file. The code of the timer.c file is as follows: //General timer 3 interrupt initialization //arr: automatic reload value. psc: clock pre-division number //Timer overflow time calculation method: Tout=((arr+1)*(psc+1))/Ft us. //Ft=timer operating frequency, unit: Mhz //Timer 3 is used
[Microcontroller]
Clock configuration problem of stm32f407 development board
To use an 8M crystal oscillator, you need to modify two macro definitions based on the official example: 1) Change PLL_M to 8 in systm_stm32f40x.c 2) Change HSE_VALUE to 8000000 in stm32f40x.h, as follows: #define USED_HSE_8M #if !defined (HSE_VALUE)  #ifdef USED_HSE_8M    #define HSE_VALUE ((uint32_t)8000000) /*! Val
[Microcontroller]
STM32F4 - Independent watchdog and window watchdog
1. Introduction:     It is used to detect and resolve faults caused by software errors. When the counter reaches the set timeout value, a system reset will occur. Its features are: 1. The clock it uses is generated by an independent RC oscillator, so it can run in standby and stop modes. 2. After the watchdog is activ
[Microcontroller]
STM32F4 - Independent watchdog and window watchdog
STM32F4_RCC system clock configuration and description
I. Overview We all know the function of the system clock, which is the heart that drives the entire chip. Without it, it is like a person without a heartbeat. For those who use the development board for learning, the knowledge of RCC system clock is probably not configured much, because the crystal oscillator provided
[Microcontroller]
STM32F4_RCC system clock configuration and description
LCD display design based on STM32F4x9, hardware design guide
With the growing demand for human-machine interface (GUI) in various application fields of medical, industrial and consumer electronics, highly integrated and high-performance TFT liquid crystal display solutions have become an important part of electronic product design and development. In the absence of a built-in l
[Microcontroller]
LCD display design based on STM32F4x9, hardware design guide
DAC of stm32f407 (operation register)
DAC The DAC embedded in Stm32f4 is a 12-bit digital input, voltage output digital-to-analog converter. The DAC can be configured in 8-bit or 12-bit mode, and can also be used in conjunction with a DMA controller. When the DAC works in 12-bit mode, the data can be set to left-aligned or right-aligned. The DAC module
[Microcontroller]
stm32f4 uses Systick to achieve delay
Using Systick timer to achieve delay 1. SysTick timer characteristics The SysTick timer is a 24-bit down counter, that is, when vlue is decremented to 0, an interrupt is triggered and the load value is reloaded, and the cycle continues. In the stm32f4 library file, the priority is set to the lowest priority by def
[Microcontroller]
Problems with floating point calculations with stm32F4
Dear experts, I am now porting a program to stm32F4. It was previously running on a PC. I chose this chip because it has an FPU. When debugging, I found many problems. In addition to setting the FPU, I found that some very simple calculations would also go wrong. I wonder if anyone has encountered the same problem? It
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号