Regarding the PHY construction of LWIP, the PHY chip used is LAN8720A, RMII mode.
Regarding the hardware connection part, the Atomic board F407 is used, and the hardware connection is as follows:
Note: LAN8720A can be configured through the PHYAD0 pin, which is multiplexed with the RXER pin. The chip has a pull-down resistor inside. After the hard reset is over, LAN8720A will read the pin level as the SMI address of the device. When the pull-down resistor is connected (it can also be floating because the chip has a pull-down resistor inside), the SMI address is set to 0. When the pull-up resistor is connected externally, it can be set to 1. The RXER pin of this hardware is floating, and its PHY chip address is 0
Regarding the configuration of SMT32CubeMx pin clock and other configurations, you can configure them according to the actual situation, so I will not go into details here;
click the Parameter Setting tab in the ETH configuration and configure it as follows:
In this tab, just fill in the PHY address according to the actual situation. The PHY chip address I use is 0, so just enter 0 here;
click the Advanced Parameters tab in the ETH configuration and select as follows:
Since the STM32CubeMx system defaults to LAN8742A, we choose user PHY configuration LAN8720A;
its configuration is as follows:
There are not many configuration items about the PHY chip, most of which use the default parameters. Those that need to be changed are marked with red lines, such as:
PHY Address Value: This is the PHY chip address we set before;
PHY Name: This is just an identifier and can be set at will. Here I set it to LAN8720;
PHY Special Control/Status Register Offset: You can find it according to the chip manual, as follows:
Note: The address of this register is decimal 31.
Similarly, the settings of the PHY Speed mask and PHY Duplex mask registers are as follows:
Bits4:2 includes the PHY Speed mask and PHY Duplex mask,
Bits2 represents two speeds: 10MB/s and 100MB/s; PHY Speed mask (0x0004)
Bits4 represents two working modes: half-duplex and full-duplex; PHY Duplex mask (0x0010)
Then enable ETH interrupt and use the default priority;
The LWIP configuration is as follows:
The rest can be kept as default
Finally, in the generated code, add the code for resetting the PHY hardware in the ETH hardware initialization section: (Note: This code is added here because of hardware design, add it according to the actual situation)
Add the following code:
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f4xx_hal.h"
#include "lwip.h"
#include "gpio.h"
/* USER CODE BEGIN Includes */
#include "tcp.h"
#include "stats.h"
/* USER CODE END Includes */
static struct tcp_pcb *tcp_echoserver_pcb;
void tcp_echoserver_init(void);
static err_t tcp_echoserver_accept(void *arg,struct tcp_pcb *newpcb,err_t err);
static err_t tcp_echoserver_recv(void *arg,struct tcp_pcb *tpcb,struct pbuf *p,err_t err);
void tcp_echoserver_init(void)
{
err_t err;
tcp_echoserver_pcb=tcp_new();
if(tcp_echoserver_pcb!=NULL)
{
err=tcp_bind(tcp_echoserver_pcb,IP_ADDR_ANY,7);
if(err==ERR_OK)
{
tcp_echoserver_pcb=tcp_listen(tcp_echoserver_pcb);
tcp_accept(tcp_echoserver_pcb,tcp_echoserver_accept);
}
else
{
memp_free(MEMP_TCP_PCB,tcp_echoserver_pcb);
}
}
}
static err_t tcp_echoserver_accept(void *arg,struct tcp_pcb *newpcb,err_t err)
{
tcp_recv(newpcb,tcp_echoserver_recv);
return ERR_OK;
}
static err_t tcp_echoserver_recv(void *arg,struct tcp_pcb *tpcb,struct pbuf *p,err_t err)
{
tcp_write(tpcb,p->payload,p->len,1);
pbuf_free(p);
return ERR_OK;
}
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_LWIP_Init();
/* USER CODE BEGIN 2 */
tcp_echoserver_init();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
MX_LWIP_Process();
}
/* USER CODE END 3 */
}
Download the program to the target board and connect the network cable to the computer;
change the properties of the computer's IPV4 as follows:
Finally, use the command line to ping the target board as follows:
At this point, the test of the PHY chip is completed, and LWIP works normally;
As a side note, the configuration of other PHY chips is similar to this, but please note the differences in the register addresses of each chip;
Previous article:Implementing microsecond delay of general timer under STM32Cubemx
Next article:Stm32cubeMX generates configuration project examples and process records
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- How to choose the right RF module
- 【Review of SGP40】+ Comprehensive demo
- When designing a power supply, what cooling method do you choose?
- DSP28035_Baud rate setting
- Fuse selection
- Complaint: Xiaomi 8 got stuck and bricked after automatic upgrade
- Improved logging
- [Image recognition classification & motion detection & analog signal processing system based on Raspberry Pi 400, fifth post] Project conclusion & documentation - 11.0...
- Circuit analysis, please help me
- bq4050 protection recovery problem