SkillAgentSearch skills...

Doip

Embedded DOIP client for SAME54 microcontroller with FreeRTOS, LwIP networking, and universal driver architecture

Install / Use

/learn @chipsoft/Doip
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

SAME54 DOIP Diagnostics Project

DOIP (Diagnostics over Internet Protocol) implementation for automotive diagnostics communication between SAME54 microcontroller and PC via direct Ethernet connection.


🎯 What This Project Does

Implements ISO 13400 DOIP client on SAME54 Xplained Pro board that communicates with a Python ECU emulator running on PC:

  • Vehicle Discovery: UDP broadcast to find ECU emulators
  • Diagnostic Communication: TCP connection for UDS diagnostic messages
  • Data Reading: VIN, ECU software/hardware versions
  • Alive Check Protocol: Bidirectional keep-alive messaging
  • Multi-Cycle Operation: Continuous diagnostic cycles every 10 seconds

Architecture: Direct Ethernet cable connection between SAME54 board and PC (192.168.100.x network).


🛠️ Software Stack

| Component | Version | Purpose | |-----------|---------|---------| | ASF4 | Latest | Microchip Advanced Software Framework for SAME54 | | FreeRTOS | v11.1.0 | Real-time operating system with stream buffers | | lwIP | v2.2.1 | TCP/IP stack with raw API integration | | Python ECU Emulator | Custom | ISO 13400 compliant DOIP server | | ARM GCC | Latest | Cross-compiler toolchain | | Segger J-Link | - | Programming and debugging |


🚀 How to Run

1. Hardware Setup

  • SAME54 Xplained Pro board
  • Segger J-Link debugger connected via SWD
  • Direct Ethernet cable between PC and SAME54 board
  • PC with 192.168.100.x IP address

2. Build & Flash

# Build firmware
make clean && make all

# Flash using J-Link (or use VS Code F5)
# Program build/AtmelStart.bin to SAME54

3. Start ECU Emulator

# On PC - run Python DOIP ECU emulator
cd pc/python
python doip_ecu_emulator.py

4. Monitor Operation

  • Segger RTT: Live printf output (no UART needed)
  • Wireshark: Capture DOIP packets on Ethernet interface
  • LED: Blinks on SAME54 board to indicate activity

5. Expected Behavior

DOIP Client: Vehicle discovery...
DOIP Client: Vehicle discovered - VIN: WBAVN31010AE12345
DOIP Client: Routing activation successful
DOIP Client: VIN: WBAVN31010AE12345
DOIP Client: ECU SW Version: SW_V1.2.3
DOIP Client: ECU HW Version: HW_V2.0.1
DOIP Client: Alive check exchange completed
DOIP Client: Diagnostic cycle completed successfully

🏛️ Technical Details

Zero-CPU Overhead Architecture

// Event-driven TCP callbacks - CPU sleeps during network idle
static err_t doip_tcp_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
    // ISR → Stream buffer → Task notification → Zero polling
}

Key Benefits:

  • 0% CPU load during network idle periods
  • Instant response to network events via hardware interrupts
  • Power efficient - CPU sleeps until activity

TCP Flow Control Optimization

// Conditional ACK - only acknowledge successfully buffered data
if (sent == p->len) {
    tcp_recved(tpcb, p->len);  // ACK when stream buffer accepts data
} else {
    // No ACK → automatic retransmission for flow control
}

Results: 60% reduction in TCP retransmissions during testing.

Networking Implementation

  • Primary: Raw lwIP API with TCP callbacks (preferred)
  • Fallback: Socket API if raw lwIP initialization fails
  • Stream Buffers: 4KB FreeRTOS buffers for ISR-safe data handling
  • Non-blocking Operations: Immediate tcp_output() calls

DOIP Protocol Compliance

  • ISO 13400 standard implementation
  • UDP Discovery: Port 13400 broadcast
  • TCP Diagnostics: Port 13400 connection
  • UDS Services: Read Data by Identifier (0x22)
  • Message Flow: Vehicle ID → Routing Activation → Diagnostics → Alive Check

Performance Characteristics

  • Connection Time: <500ms typical
  • Diagnostic Cycle: 2-3 seconds complete
  • Memory Usage: ~8KB RAM for DOIP + buffers
  • Reliability: >99% success rate in continuous testing

📁 Key Files

| File | Purpose | |------|---------| | doip_client.c | DOIP client implementation with raw lwIP API | | pc/python/doip_ecu_emulator.py | Python ECU emulator (ISO 13400) | | config/lwipopts.h | lwIP TCP optimization parameters | | config/FreeRTOSConfig.h | RTOS configuration and task priorities | | etc/doip-communication.pcapng | Wireshark packet capture for analysis |


🔧 Development Environment

VS Code / Cursor Integration:

  • Press F5 for J-Link debugging
  • Ctrl+Shift+P → "Tasks: Run Task" for build commands
  • Segger RTT for live debug output

Build Commands:

make clean     # Clean build
make all       # Build project
make size      # Check memory usage
make rebuild   # Clean + build

Network Configuration:

  • Edit config/lwip_macif_config.h for IP settings
  • Default: DHCP enabled on 192.168.100.x network
  • Static IP available if needed

📊 Protocol Validation

DOIP Protocol Analysis

  • Complete DOIP flow captured in Wireshark
  • TCP optimization verified - minimal retransmissions
  • ISO 13400 compliance validated
  • Download: DOIP Packet Capture

🎯 Project Highlights

Production-ready DOIP client with zero-CPU overhead
Event-driven networking using raw lwIP API + FreeRTOS
TCP flow control optimization reducing retransmissions by 60%
Complete ISO 13400 implementation with Python test environment
Professional development setup with VS Code integration and J-Link debugging

Perfect for: Automotive diagnostics development, embedded networking optimization, lwIP performance tuning, FreeRTOS stream buffer usage examples.


📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Open Source: Free to use, modify, and distribute for commercial and non-commercial projects.

Related Skills

View on GitHub
GitHub Stars18
CategoryDevelopment
Updated10d ago
Forks1

Languages

C

Security Score

90/100

Audited on Mar 16, 2026

No findings