How to Build a PROFINET-Oriented STM32 Ethernet Device with W5500?
This project uses an STM32 microcontroller with the WIZnet W5500 to provide wired 10/100 Ethernet connectivity through SPI.
How to Build a PROFINET-Oriented STM32 Ethernet Device with W5500?
Summary
This project uses an STM32 microcontroller with the WIZnet W5500 to provide wired 10/100 Ethernet connectivity through SPI. The original implementation covers W5500 initialization, IPv4 network configuration, DHCP, and TCP communication. For a commercial PROFINET device, this provides a useful Ethernet hardware baseline, but the original project does not implement PROFINET. PROFINET RT requires additional Layer-2 protocol handling and a PROFINET device stack beyond the demonstrated TCP/IP firmware.
What the Project Does
The source project demonstrates how to add Ethernet networking to an STM32 using an external W5500 controller. The firmware initializes the STM32 SPI peripheral, communicates with the W5500, configures its MAC address and IPv4 parameters, initializes socket memory, and then performs network communication including DHCP and TCP tests.
The resulting architecture is straightforward:
STM32 application → SPI → W5500 → Ethernet PHY → RJ45 → Ethernet network
The W5500 contains the Ethernet MAC/PHY and a hardwired IPv4 TCP/IP engine. WIZnet specifies eight hardware sockets, 32 KB of internal TX/RX memory, and SPI operation up to 80 MHz. TCP, UDP, IPv4, ARP, ICMP, and related protocols can therefore be handled without placing a conventional software TCP/IP stack on the STM32. WIZnet 文檔系統
For a commercial industrial product, however, ordinary Ethernet connectivity and PROFINET communication need to be separated conceptually. PROFINET uses standard TCP/IP for engineering and non-time-critical communication, while cyclic PROFINET RT process data uses its real-time Ethernet channel. PI identifies standard MCUs with standard Ethernet controllers as one possible implementation path for PROFINET RT-class devices, while more demanding IRT implementations use dedicated hardware support. PROFINET
Therefore, the CSDN project should be treated as an STM32 + W5500 Ethernet foundation, not as a completed PROFINET implementation.
Where WIZnet Fits
The exact WIZnet component is the W5500 Hardwired TCP/IP Ethernet Controller.
In the original implementation, the W5500 sits between the STM32 application and the physical Ethernet network. The STM32 accesses it over SPI while the W5500 provides the MAC, PHY, packet buffers, and hardware TCP/IP functions. This avoids consuming STM32 RAM and processing time for an ordinary software TCP/IP implementation.
That distinction becomes important when adapting the design for PROFINET.
For conventional TCP/IP services associated with an industrial device—configuration interfaces, diagnostics, maintenance servers, or other IP-based communication—the W5500 hardware sockets can offload TCP/UDP processing. The device provides eight sockets and 32 KB of packet memory independently of STM32 RAM. WIZnet 文檔系統
PROFINET RT traffic is different. It cannot simply be implemented as a TCP or UDP application running through a normal W5500 hardware socket. Layer-2 Ethernet frames must be accessible to the PROFINET stack.
The W5500 provides MACRAW mode for this purpose at the Ethernet-frame level. Its documentation specifies that MACRAW operation is available on Socket 0 and permits direct transmission and reception of Ethernet frames rather than processing them through the hardware TCP/IP engine. WIZnet 文檔系統
A possible architecture is therefore:
Commercial Application
|
PROFINET Stack
/ \
RT / Layer 2 TCP/IP services
| |
MACRAW W5500 sockets
\ /
STM32 Driver
|
SPI
|
W5500
|
10/100 EthernetThis is an integration architecture, not functionality demonstrated by the CSDN source. Whether a particular PROFINET stack can operate successfully through W5500 MACRAW mode must be verified with that stack vendor, including its driver interface, timing requirements, and certification target.
PI explicitly lists protocol stacks on standard MCUs with integrated standard Ethernet controllers as an implementation option, while hardware-assisted implementations are used when higher real-time requirements demand them. PROFINET
For a commercial product, that distinction should be established before PCB and firmware architecture are frozen.
Implementation Notes
The source article demonstrates the conventional TCP/IP side of the STM32/W5500 design rather than PROFINET.
Its W5500 network initialization uses calls including:
setSHAR(...);
setSUBR(...);
setGAR(...);
setSIPR(...);
sysinit(...);These configure the W5500 network identity and socket-memory environment used by the example. The article then builds DHCP and TCP communication on that Ethernet foundation.
For a commercial PROFINET-oriented implementation, the firmware architecture would need to extend beyond these functions:
STM32 startup
|
SPI + GPIO initialization
|
W5500 reset / PHY verification
|
W5500 initialization
|
+-------------------------------+
| |
Standard TCP/IP MACRAW
W5500 hardware sockets |
| |
Management / service Ethernet frames
traffic |
|
PROFINET stack
|
Cyclic / acyclic services
|
Application I/OThe important boundary is MACRAW. WIZnet documents MACRAW as direct Ethernet-frame operation, and only Socket 0 can operate in this mode. MAC filtering can also be enabled so the host does not have to process every Ethernet frame visible on the link. WIZnet 文檔系統
That has architectural consequences for a commercial device. The STM32 must move frames between the W5500 and PROFINET stack over SPI, so SPI transfer latency, interrupt latency, frame-buffer management, task scheduling, and worst-case application load all become part of the real-time design.
A PROFINET stack must also supply substantially more functionality than the original DHCP/TCP example. Device integration involves PROFINET protocol behavior, device identification and configuration, cyclic process data, diagnostics, and the required device description. PI notes that commercial PROFINET products must be certified through an accredited test laboratory; manufacturers also require a Vendor ID and Device ID for the device definition. PROFINET
Consequently, the CSDN firmware should not be relabeled as PROFINET firmware. It is better used as a verified starting point for the STM32 ↔ SPI ↔ W5500 ↔ Ethernet portion of a larger commercial architecture.
Practical Tips / Pitfalls
- Separate TCP/IP from PROFINET RT early. Do not assume a working W5500 TCP or UDP example means that PROFINET RT will operate through the same socket API. RT requires the appropriate Ethernet-frame path and PROFINET stack.
- Validate MACRAW throughput before selecting the final MCU. MACRAW frames cross the STM32/W5500 SPI boundary, so measure worst-case SPI transfer time, ISR latency, and scheduling jitter with the intended PROFINET cycle and application workload.
- Reserve Socket 0 appropriately. W5500 MACRAW operation is restricted to Socket 0. Account for that when allocating the remaining sockets to TCP/UDP services. WIZnet 文檔系統
- Treat DHCP as optional for the commercial architecture. The original project demonstrates DHCP, but PROFINET commissioning and device addressing have their own requirements. Do not make the demonstration DHCP state machine part of the PROFINET architecture without checking the selected stack.
- Design the physical interface for the factory environment. Use appropriate magnetics, grounding, shielding, ESD protection, and industrial Ethernet cabling practices rather than treating the RJ45 interface as an office-Ethernet design. PI specifically recommends industrially appropriate, ruggedized cabling and infrastructure for factory installations. Profinet
- Decide the required PROFINET conformance level before hardware selection. PI distinguishes RT-oriented CC-A/CC-B implementations from more demanding IRT functionality. Dedicated PROFINET hardware may be more appropriate if the product requires IRT, integrated switching, line topology, or tighter timing behavior. PROFINET
- Plan certification from the beginning. A device sold as a PROFINET product requires certification, so stack selection, Vendor/Device IDs, GSD configuration, diagnostics, hardware behavior, and testability should be treated as product requirements rather than final-stage additions. PROFINET
FAQ
Q: Why use W5500 with STM32 for this design?
The W5500 gives an STM32 an external 10/100 Ethernet MAC/PHY, hardware TCP/IP engine, eight sockets, and 32 KB of internal packet memory through SPI. This is useful when the commercial device needs conventional TCP/IP connectivity without dedicating substantial STM32 resources to a software TCP/IP stack. For PROFINET specifically, however, the decision also depends on whether the required PROFINET stack and timing requirements can be supported through W5500 MACRAW operation. WIZnet 文檔系統
Q: How does W5500 connect to STM32?
The host interface is SPI, with the normal SCK, MOSI, MISO, and chip-select signals plus control signals such as reset and, when used, interrupt. W5500 supports SPI modes 0 and 3 with an interface clock of up to 80 MHz. For PROFINET-oriented firmware, using the interrupt path rather than repeatedly polling for incoming traffic is particularly worth evaluating because frame-reception latency becomes part of the timing budget. WIZnet 文檔系統
Q: What role would W5500 play in this PROFINET project?
The original project uses W5500 as the STM32's Ethernet and TCP/IP controller; it does not implement PROFINET. In a proposed PROFINET architecture, W5500 could provide the Ethernet physical interface and expose Layer-2 frames through Socket 0 MACRAW mode, while the STM32 executes the PROFINET stack. Its hardware TCP/IP sockets could potentially remain useful for separate standard IP services, subject to the selected stack architecture. WIZnet 文檔系統
Q: Can a beginner turn the original STM32/W5500 example into a commercial PROFINET product?
The original Ethernet example is accessible to developers familiar with STM32 HAL/firmware, SPI, IPv4, DHCP, and sockets. A commercial PROFINET implementation is substantially more involved: the developer needs Ethernet frame handling, real-time embedded scheduling, a suitable PROFINET stack, device configuration, diagnostics, GSD integration, and certification planning. PI states that products marketed as PROFINET devices require certification. PROFINET
Q: How does W5500 compare with STM32 Ethernet plus LwIP for PROFINET?
For ordinary TCP/IP communication, W5500 moves TCP/UDP/IPv4 processing and packet memory into dedicated hardware, whereas an STM32 Ethernet MAC combined with LwIP normally leaves the protocol stack and its buffers in MCU software. That makes W5500 attractive when TCP/IP offload is important. PROFINET changes the comparison: its RT communication requires access to Ethernet frames, so an STM32 with a directly accessible Ethernet MAC may provide a more conventional interface to some commercial PROFINET stacks, while W5500 requires evaluating its MACRAW/SPI path. PI confirms that standard MCU and Ethernet-controller architectures are possible for RT implementations, but the final choice depends on the required conformance class and product topology. Profinet
Source
Original Project: CSDN — STM32/W5500 Ethernet implementation
Technical References: WIZnet W5500 documentation and PROFIBUS & PROFINET International implementation guidance. WIZnet 文檔系統
Original Project License: No explicit reusable source-code license was verified from the supplied CSDN article. The implementation excerpts should therefore be treated as reference material rather than assumed to carry an open-source license.
Tags
#W5500 #STM32 #PROFINET #IndustrialEthernet #IndustrialAutomation #SPI #Ethernet #EmbeddedSystems #CommercialDevice #IIoT
W5500과 STM32로 PROFINET 지향형 산업용 이더넷 장치를 구현하는 방법은?
Summary
이 프로젝트는 STM32 마이크로컨트롤러와 WIZnet W5500을 SPI로 연결하여 10/100 Ethernet 통신을 구현합니다. 원본 구현에는 W5500 초기화, IPv4 네트워크 설정, DHCP, TCP 통신이 포함되어 있습니다. 상용 PROFINET 장치 개발 관점에서는 유용한 Ethernet 하드웨어 기반이지만, 원본 프로젝트 자체가 PROFINET을 구현하는 것은 아닙니다. PROFINET RT를 구현하려면 기존 TCP/IP 펌웨어 외에 Layer 2 Ethernet 프레임 처리와 별도의 PROFINET Device Stack이 필요합니다.
What the Project Does
원본 프로젝트는 외부 Ethernet 컨트롤러인 W5500을 이용해 STM32에 유선 네트워크 기능을 추가하는 방법을 보여줍니다. 펌웨어는 STM32의 SPI 주변장치를 초기화하고 W5500과 통신한 뒤 MAC 주소와 IPv4 네트워크 파라미터를 설정하고, 소켓 메모리를 초기화하여 DHCP와 TCP 통신을 수행합니다.
전체 데이터 경로는 다음과 같이 구성됩니다.
STM32 Application → SPI → W5500 → Ethernet PHY → RJ45 → Ethernet Network
W5500은 Ethernet MAC/PHY와 Hardwired TCP/IP Engine을 포함합니다. WIZnet 사양 기준으로 8개의 하드웨어 소켓, 32 KB의 내부 TX/RX 메모리, 최대 80 MHz SPI 인터페이스를 지원합니다. 따라서 TCP, UDP, IPv4, ARP, ICMP 등의 처리를 STM32의 일반적인 소프트웨어 TCP/IP Stack에 전적으로 의존하지 않고 수행할 수 있습니다.
상용 산업용 장치로 확장할 때는 일반적인 Ethernet 연결과 PROFINET 통신을 구분해야 합니다. PROFINET은 엔지니어링 및 비실시간 통신에 표준 TCP/IP를 활용할 수 있지만, 주기적인 PROFINET RT Process Data는 별도의 Real-Time Ethernet 통신 경로를 사용합니다.
따라서 원본 CSDN 프로젝트는 완성된 PROFINET 구현이 아니라 STM32 + W5500 Ethernet 기반 구현으로 보는 것이 정확합니다.
Where WIZnet Fits
이 프로젝트에서 사용되는 WIZnet 제품은 W5500 Hardwired TCP/IP Ethernet Controller입니다.
원본 구현에서 W5500은 STM32 애플리케이션과 물리적인 Ethernet 네트워크 사이에 위치합니다. STM32는 SPI를 통해 W5500에 접근하며, W5500은 Ethernet MAC, PHY, 패킷 버퍼 및 하드웨어 TCP/IP 기능을 제공합니다.
이 구조에서는 일반 TCP/IP 처리를 위해 STM32 RAM과 CPU 자원을 상당 부분 사용하는 소프트웨어 네트워크 Stack을 반드시 운영할 필요가 없습니다.
상용 장치에서 설정 인터페이스, 진단 서버, 유지보수 기능 등 일반 TCP/IP 기반 서비스가 필요하다면 W5500의 하드웨어 소켓을 사용할 수 있습니다. 8개의 소켓과 32 KB의 내부 패킷 메모리를 MCU 메모리와 별도로 사용할 수 있다는 점도 소형 STM32 시스템에서는 유용합니다.
그러나 PROFINET RT는 일반적인 W5500 TCP 또는 UDP Socket Application으로 단순 구현할 수 없습니다.
PROFINET Stack이 Layer 2 Ethernet Frame을 직접 처리할 수 있는 경로가 필요합니다.
W5500은 이를 위해 MACRAW Mode를 제공합니다. MACRAW는 Socket 0에서 사용할 수 있으며, W5500의 하드웨어 TCP/IP 처리 대신 Ethernet Frame을 직접 송수신하는 방식입니다.
PROFINET을 고려한다면 다음과 같은 구조를 검토할 수 있습니다.
Commercial Application
|
PROFINET Stack
/ \
RT / Layer 2 TCP/IP Services
| |
MACRAW W5500 Sockets
\ /
STM32 Driver
|
SPI
|
W5500
|
10/100 Ethernet단, 이 구조는 원본 CSDN 프로젝트에서 구현된 기능이 아니라 확장 가능한 통합 아키텍처입니다.
실제 상용 제품에서는 선택한 PROFINET Stack이 W5500 MACRAW 인터페이스와 결합 가능한지, 필요한 Frame Driver 구조를 지원하는지, 그리고 요구되는 Real-Time Timing을 만족할 수 있는지를 Stack 공급사와 함께 검증해야 합니다.
Implementation Notes
원본 프로젝트에서 확인할 수 있는 것은 PROFINET이 아니라 STM32/W5500의 일반 TCP/IP 구현입니다.
W5500 네트워크 초기화 과정에서는 다음과 같은 함수들이 사용됩니다.
setSHAR(...);
setSUBR(...);
setGAR(...);
setSIPR(...);
sysinit(...);이 부분은 W5500의 MAC 주소, Subnet Mask, Gateway, IP 주소 및 Socket Memory 환경을 구성하기 위해 존재합니다.
그 위에서 원본 프로젝트는 DHCP와 TCP 통신을 구현합니다.
PROFINET을 목표로 한다면 펌웨어 구조를 다음 단계까지 확장해야 합니다.
STM32 Startup
|
SPI + GPIO Initialization
|
W5500 Reset / PHY Verification
|
W5500 Initialization
|
+-------------------------------+
| |
Standard TCP/IP MACRAW
W5500 Hardware Sockets |
| |
Management / Service Ethernet Frames
Traffic |
|
PROFINET Stack
|
Cyclic / Acyclic Services
|
Application I/O여기서 중요한 경계가 MACRAW입니다.
W5500의 MACRAW Mode를 사용하면 TCP/IP Socket 처리를 거치지 않고 Ethernet Frame을 STM32가 직접 다룰 수 있습니다. 다만 MACRAW Mode는 Socket 0에 제한됩니다.
따라서 PROFINET 통신에서는 STM32와 W5500 사이의 SPI가 단순한 설정용 인터페이스가 아니라 실제 Ethernet Frame의 데이터 경로가 됩니다.
이 때문에 상용 설계에서는 다음 항목을 실제 하드웨어에서 측정해야 합니다.
SPI Transfer Latency → Interrupt Latency → Frame Buffer Handling → PROFINET Task Scheduling → Application Processing
특히 평균 성능보다 Worst-Case Latency와 Jitter를 확인하는 것이 중요합니다.
또한 PROFINET Device를 완성하려면 원본 프로젝트의 DHCP/TCP 구현보다 훨씬 많은 기능이 필요합니다. Device Identification, Configuration, Cyclic Process Data, Acyclic Communication, Diagnostics, Device Description 등의 기능은 별도의 PROFINET Stack 및 제품 설계 영역에 해당합니다.
따라서 원본 펌웨어를 PROFINET Firmware라고 표현하기보다는 STM32 ↔ SPI ↔ W5500 ↔ Ethernet 구간을 검증한 기반 구현으로 활용하는 것이 적절합니다.
Practical Tips / Pitfalls
TCP/IP와 PROFINET RT를 설계 초기부터 분리해야 합니다. W5500 TCP/UDP 예제가 정상적으로 동작한다고 해서 동일한 Socket API만으로 PROFINET RT를 구현할 수 있는 것은 아닙니다.
MACRAW 처리 성능을 실제 하드웨어에서 검증해야 합니다. Ethernet Frame이 SPI를 통해 STM32로 전달되므로 SPI 전송 시간, ISR Latency, Task Scheduling Jitter를 목표 PROFINET Cycle과 함께 측정해야 합니다.
Socket 0 사용 계획이 중요합니다. W5500의 MACRAW Mode는 Socket 0을 사용하므로, PROFINET용으로 할당한다면 나머지 Socket을 TCP/UDP 서비스에 어떻게 배분할지 미리 설계해야 합니다.
원본 프로젝트의 DHCP 구현을 그대로 PROFINET 네트워크 설계로 간주하면 안 됩니다. PROFINET Device의 Commissioning 및 Addressing 요구사항을 선택한 Stack 기준으로 별도 검토해야 합니다.
상용 제품에서는 Ethernet Physical Interface 설계도 중요합니다. Magnetics, ESD Protection, Grounding, Shielding, Connector 및 EMI/EMC 설계를 일반적인 개발 보드 수준이 아니라 실제 산업 환경을 기준으로 검토해야 합니다.
요구되는 PROFINET 기능을 먼저 결정해야 합니다. 기본적인 RT 통신과 더 높은 수준의 실시간 기능은 하드웨어 요구사항이 다를 수 있습니다. IRT나 통합 Switch, Line Topology 등이 필요한 제품이라면 전용 PROFINET Hardware가 더 적절할 수 있습니다.
인증 요구사항을 개발 후반에 추가하지 않는 것이 중요합니다. 상용 PROFINET Device를 목표로 한다면 Stack 선정, Vendor/Device ID, GSD, Diagnostics, Hardware Behavior 및 Testability를 초기 제품 요구사항에 포함해야 합니다.
FAQ
Q: STM32 산업용 Ethernet 설계에서 왜 W5500을 사용하나요?
W5500은 STM32에 10/100 Ethernet MAC/PHY, Hardwired TCP/IP Engine, 8개의 Hardware Socket과 32 KB 내부 Packet Memory를 SPI 인터페이스로 제공합니다. 따라서 일반 TCP/IP 통신에서는 MCU가 Software TCP/IP Stack 전체를 처리하는 구조보다 네트워크 처리를 W5500으로 분리할 수 있습니다. 단, PROFINET 적용 여부는 별도로 MACRAW 성능과 PROFINET Stack 호환성을 검증해야 합니다.
Q: W5500은 STM32와 어떻게 연결하나요?
SPI의 SCK, MOSI, MISO, CS 신호를 기본으로 사용하며 Reset 및 필요에 따라 Interrupt 신호도 연결합니다. W5500의 SPI 인터페이스는 최대 80 MHz까지 지원합니다. PROFINET처럼 Frame Reception Latency가 중요한 응용에서는 단순 Polling 방식뿐 아니라 Interrupt 기반 처리 구조도 검토할 필요가 있습니다.
Q: 이 PROFINET 프로젝트에서 W5500은 어떤 역할을 하나요?
원본 프로젝트에서 W5500은 STM32의 Ethernet 및 TCP/IP Controller 역할을 하며 PROFINET 자체를 구현하지는 않습니다. PROFINET으로 확장할 경우에는 W5500이 Ethernet Physical Interface를 제공하고, Socket 0의 MACRAW Mode를 통해 Layer 2 Ethernet Frame을 STM32의 PROFINET Stack에 전달하는 구조를 검토할 수 있습니다. 일반적인 TCP/IP 서비스는 별도의 W5500 Hardware Socket을 활용하는 구조도 고려할 수 있습니다.
Q: 초보자도 원본 STM32/W5500 프로젝트를 상용 PROFINET 제품으로 확장할 수 있나요?
원본 Ethernet 구현은 STM32 HAL, SPI, IPv4, DHCP, TCP Socket에 대한 기본 지식이 있다면 접근할 수 있습니다. 하지만 상용 PROFINET Device 개발에는 Ethernet Frame 처리, Embedded Real-Time Scheduling, PROFINET Stack 통합, Device Configuration, Diagnostics, GSD 및 인증 과정에 대한 추가 경험이 필요합니다. 따라서 기본 W5500 Ethernet 프로젝트와 상용 PROFINET 제품 개발의 난이도에는 상당한 차이가 있습니다.
Q: PROFINET 구현에서 W5500과 STM32 Ethernet + LwIP 방식은 어떤 차이가 있나요?
일반 TCP/IP 통신에서는 W5500이 TCP/UDP/IPv4 처리와 Packet Memory를 전용 하드웨어로 분리한다는 차이가 있습니다. 반면 STM32 Ethernet MAC + LwIP 구조에서는 TCP/IP Stack과 관련 Buffer가 MCU Software 영역에서 동작합니다. 하지만 PROFINET RT에서는 Layer 2 Ethernet Frame 접근이 중요하기 때문에 비교 기준이 달라집니다. STM32의 Ethernet MAC을 직접 사용하는 방식은 일부 PROFINET Stack과 보다 일반적인 Driver 구조를 구성할 수 있는 반면, W5500에서는 MACRAW와 SPI를 통한 Frame 전달 경로의 호환성과 Timing을 추가로 검증해야 합니다.
Source
Original Project: CSDN — STM32/W5500 Ethernet implementation
https://blog.csdn.net/2501_90250923/article/details/145226562
Technical References: WIZnet W5500 documentation, PROFIBUS & PROFINET International implementation guidance.
Original Project License: 제공된 CSDN 문서에서는 재사용 가능한 명시적 Open-Source License를 확인하지 못했습니다. 따라서 원문의 코드는 공개 라이선스가 부여된 코드로 가정하지 않고 기술 참고 자료로 취급하는 것이 적절합니다.
Tags
#W5500 #STM32 #PROFINET #IndustrialEthernet #IndustrialAutomation #SPI #Ethernet #EmbeddedSystems #CommercialDevice #IIoT
