How tangtangsix/modbus_tcp works
This project is an embedded firmware for an STM32F103C8 microcontroller that implements a Modbus TCP communication stack using the HAL library and a W5500 Ethernet controller. In other words, it is a network-enabled embedded application that uses hardware abstraction layers (CMSIS and STM32F1xx_HAL_Driver) along with custom application code to provide Modbus TCP over Ethernet.
Main Components
• Hardware Platform: The STM32F103C8 microcontroller board.
• External Networking: W5500 Ethernet controller, which connects to the microcontroller via the SPI interface.
• Software Layers:
– Low-Level Drivers: HAL library files (STM32F1xx_HAL_Driver) and CMSIS components.
– Middleware: Low-level device libraries, possibly RTOS components from the CMSIS/RTOS folders.
– Application Layer: The core Modbus TCP implementation and support code (main.c, gpio.c, spi.c, usart.c, etc.).
• Communication Protocols: Modbus protocol over TCP/IP and the SPI protocol for communication between STM32 and W5500.
Relationships and Interactions
• The STM32 microcontroller acts as the central processor.
• It communicates with the W5500 via the SPI bus to handle Ethernet communications.
• The HAL drivers abstract the microcontroller’s peripherals (GPIO, SPI, USART, etc.) and interface with hardware.
• The Modbus TCP stack sits on top of the networking layer and processes network packets to implement the Modbus protocol.
• Optionally, if the RTOS components are used, they manage tasks (like periodic network polling, interrupt handling, and protocol processing).
Architectural Patterns and Design Principles
• Layered Architecture: Clear separation between hardware abstraction (HAL/CMSIS drivers), device interface (SPI, GPIO, etc.), and application logic (Modbus TCP).
• Separation of Concerns: The hardware-specific libraries (CMSIS, HAL, STM32F1xx_HAL_Driver) are distinct from business logic (Modbus TCP handling) and network interfacing (W5500).
Relevant Technologies and Frameworks
• Keil MDK-ARM (MDK-ARM folders indicate the project is supported by Keil’s toolchain).
• STM32F1xx HAL drivers for hardware interaction.
• CMSIS libraries for device core initialization and abstraction.
• W5500 Ethernet driver located in the W5500 folder.
• Modbus TCP service implementation in the application’s “Src” folder files.
Elements
• Labels for each primary component:
– “STM32F103C8 Microcontroller”
– “W5500 Ethernet Controller”
– “HAL Drivers & CMSIS Core”
– “Modbus TCP Application Logic”
– “SPI Bus Interface”
– Indicate data/control flow from the microcontroller to the W5500 via SPI.
– Show how the HAL drivers feed into the application layer.
– For hardware components (e.g., rectangles for MCU and Ethernet chip).
Detailed Process
– Represent the STM32 microcontroller and separately, the W5500 Ethernet controller.
• Above this hardware layer, show the “HAL & CMSIS” layer that covers all the low-level drivers.
• “RTOS / Scheduler” if your build uses CMSIS-RTOS components, showing how it coordinates tasks among modules.
• Finally, indicate an “External Ethernet Network” block that connects to the W5500 via TCP/IP.
Remember to elaborate on each layer so that the principal software engineer can quickly understand the separation of concerns and interactions between hardware and software components.