introduction
If you want to quickly complete the network protocol stack and USB OTG functions, it is best to use ST's own tool STM32CubMx. If you don't know how to use it yet, don't worry. I will tell you how to do it step by step with pictures.
Software platform: windows, STM32CubMx, keil v5
Hardware platform: Atom's stm32f407ZGT6 development board,
STM32CubMx configuration
1. Mapping configuration of Ethernet pins
First: Read the schematic diagram and use STM32CubMx to complete the configuration. The schematic diagram is not explained here. Go directly to STM32CubMx configuration.
(1) Open the STM32CubMx software, select New Project, select the corresponding chip in the pop-up menu, and click OK. As shown below:
(2) Set the clock. The board uses an 8MHz crystal oscillator, and the software corresponds to Peripheral -> RCC. As shown below:
(3) Configure Ethernet according to the schematic diagram. Select the RMII interface. Note that due to pin reuse, after selecting RMII, the software automatically may not correspond to the principle. We should configure the pins according to the schematic diagram! If they correspond, there is no need to change them. If they do not correspond, they must be changed. As shown below:
、
The Ethernet PHY chip pin connection diagram in the original picture is the RMII interface, as shown below:
Corresponding pins, software corresponding pin configuration
The corresponding positions of the pins RMII_REF_CLK, ETH_MDIO, RMII_CRS_DV, ETH_RESET, RMII_TX_EN, RMII_TXD0, and RMII_TXD1, as well as the configuration on the software, are shown in the following figure:
After the above configuration, the Ethernet pins are basically mapped. To modify the pin configuration, click a key and select the corresponding function in the pop-up function menu!
2. USB OTG pin mapping
OTG configuration! Use FS for OTG, because the schematic diagram uses FS.
The pins use the default ones and do not need to be changed.
3. UART1 as the printer port mapping
The pins use the default ones and do not need to be changed.
4. Configuration of third-party libraries
(1) The configuration of the third-party library mainly includes the file system (required for USB OTG), the network protocol stack (required for Ethernet), and the RT OS (the OS is selected this time to facilitate the scheduling of Ethernet and USB OTG tasks later).
As follows: Since OS is selected, and the tick of OS is based on Systick, we have to select another timer for software tcik. Here we select TIM1. As shown in the figure below:
Configure sys tick, system timer, in ms
Optional third-party libraries:
Select USB Disk as the file system
Enable freeOS (embedded real-time operating system) and LWIP (TCP/IP protocol stack)
Details:
System clock configuration
The system clock configuration is set in the Clock configuration tab, as follows: Use a 168MHz clock, and the USB clock must be 48MHz. The specific configuration is as follows:
The function is configured in the Configuration tab. To facilitate web page development, I configure the httpd function of LWIP and set the GPIO output to High. As shown below:
The overall detailed framework is as follows:
Steps to generate code framework:
Generate code framework, menu project->setting to set the compilation platform and directory, Generator code generates code framework!
Code configuration
1. Enter the software and code platform writing!
(1) Writing PHY driver
Since the code generated according to the above steps is basically usable, but the code is based on the PHY configured by the LAN8742A chip, the schematic uses LAN8720. Note that the PHY chips are basically the same. The main chip and PHY communicate through the MDIO interface. This is standardized, so the framework program is also like this. These basically do not need to be changed. In addition, PHY is a standard module defined in IEEE802.3. The register address 0-31 of the PHY chip is also standardized in IEEE802.3, so it is very convenient when transplanting. The difference is the PHY reset time and the PHY chip address. The address LAN8720 has the following description:
The PHYAD0 bit is driven high or low to give each PHY a unique address.
PHYAD 0 bit is set to 1 or 0 to give the PHY a unique address, which is the address of the LAN7820A. This address is latched into an internal register at the end of a hardware reset (default = 0b).
In a multi-PHY application (such as a repeater), the controller is able to manage each PHY via the unique address.
Each PHY checks each management data frame for a matching address in the relevant bits.
When a match is recognized, the PHY responds to that particular frame.
The PHY address is also used to seed the scrambler.
In a multi-PHYapplication, this ensures that the scramblers are out of synchronization and dispersesthe electromagneticradiation across the frequency spectrum.
According to the above statement, the address of LAN7820 here should be 0, so find the definition of LAN8742A_PHY_ADDRESS and change it to 0.
Location: Stm32f4xx_hal_conf.h
Reset time
IP Modification
Modify your own IP. Note that the framework turns on DHCP by default. With the DHCP function, the device can request the DHCP server to dynamically configure the device's IP in the network. We want to set it to a fixed IP here, so disable DHCP! As follows:
Header file: lwipopts.h
lwip.c file modification
Fixed IP modification, for ease of use, I define a union type to store IP addresses, as shown below:
Modify the HAL_ETH_Init function and add a hard reset as follows:
LWIP Test Results
After this modification, it can be completed! Only the host can ping. Note that the printer port mapping code is not written out. This is very simple. You can find it by searching Baidu. The specific experimental diagram is as follows:
You must use the serial port tool of Zhengdian Atom. Note that you need to turn on some debugging information to see these print information.
USB OTG can be used directly, allowing USB monitoring status. The experimental effect is as follows:
USB Test Results
Insert the USB, the host detects that the USB is connected, and you can call the mount and fopen functions to read the file normally. This is basically done!
Summarize
1. After completing the functions of LWIP and USB, the remaining part is network communication, which are all applications and are relatively simple. Network communication is nothing more than SOCKET, and USB is the fopen function calling write and read functions, etc.
2. Regarding the printing port, I saw httpd_init. That’s because I added a web page design, and I can modify the IP address through the web page.
3. Use STM's STM32CubMx software to quickly develop the framework you want. Most of the underlying configurations do not need to be calculated manually, such as the clock. If you use your own calculations to allocate clock sources to each bus, it will be quite troublesome. I have experienced this when I was working on STM32F103. If you don't know how to use this software, it is recommended that you learn it, because it can help us a lot. As someone who is engaged in STM32 and Linux development, it saves a lot of time.
Previous article:STM32 Driver DP83848 Notes
Next article:STM32F407VGT6+LAN8720 debugging notes
Recommended ReadingLatest update time:2024-11-23 15:06
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- [Recommended] Embedded real-time memory database eXtremeDB
- SHT31 Review + Getting Started Tutorial (Part 1)
- I am looking for a manufacturer that produces resistors. Used for temperature compensation
- [Qinheng RISC-V core CH582] 8-CH582 realizes temperature and humidity data collection, display, upload to mobile phone, and message function
- Share an NFC 13.56MHz antenna model HFSS
- Happy Sharing: List of National IC Design Companies
- Chengdu is recruiting embedded software engineers for automotive MCU
- Integrating RFID Web Services into EAI Applications in SOA
- Sensor interface ICs for automotive high-temperature applications
- [RVB2601 Creative Application Development] Unboxing + Detailed Picture Sharing