Skip to content

feat(isotp): Add ISO-TP (ISO 15765-2) Protocol Component with Examples and Testing Infrastructure (IEC-296) #535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eternal-echo
Copy link
Contributor

@eternal-echo eternal-echo commented Aug 6, 2025

Checklist

Required Items

  • Component contains License
  • Component contains README.md
  • Component contains idf_component.yml with url field
  • Component added to upload job (NEEDS MANUAL ADDITION)
  • Component added to build job (NEEDS MANUAL ADDITION)
  • CI passing

Optional Items

  • Component contains unit tests (pytest)
  • QEMU testing support
  • Multiple examples

Change Description

Complete ISO-TP protocol implementation for ESP-IDF enabling CAN bus communication with large payloads up to 4095 bytes (12-bit protocol limit).

  • example:
    • Echo example with pytest
    • Utils and OTA examples
  • esp_isotp:
    • Add support for canfd

Features

  • Full ISO-TP protocol support (single/multi-frame, flow control)
  • ESP-IDF TWAI driver integration
  • Linux can-utils compatibility
  • Automatic upstream patch management
  • QEMU testing support (currently work with a patched QEMU version)

Structure

isotp/
├── esp_isotp/           # ESP-IDF integration
├── isotp-c/             # Upstream library (submodule)
├── patch/               # Build-time patches
└── examples/
    ├── echo/            ✓ Message echo service
    ├── utils/           ⏳ CLI tools (isotpsend/recv)
    └── ota/             ⏳ Firmware upgrade system

API Example

// Create TWAI node and ISO-TP configuration
twai_onchip_node_config_t twai_cfg = {
    .io_cfg = {.tx = GPIO_NUM_5, .rx = GPIO_NUM_4},
    .bit_timing = {.bitrate = 500000},
    .tx_queue_depth = 16,
};
twai_node_handle_t twai_node;
twai_new_node_onchip(&twai_cfg, &twai_node);

QueueHandle_t rx_queue = xQueueCreate(16, sizeof(isotp_rx_queue_item_t));

esp_isotp_config_t config = {
    .tx_id = 0x7E0, .rx_id = 0x7E8,
    .tx_buffer_size = 4096, .rx_buffer_size = 4096,
    .twai_node = twai_node, .rx_queue = rx_queue,
};
esp_isotp_handle_t isotp_handle = esp_isotp_new(&config);

// Send/receive data
uint8_t data[] = {0x22, 0xF1, 0x90};
esp_isotp_send(isotp_handle, data, sizeof(data));

esp_isotp_poll(isotp_handle);
uint8_t rx_buffer[4096];
int len = esp_isotp_receive(isotp_handle, rx_buffer, sizeof(rx_buffer));

Key Implementation Details

Core API Functions

  • esp_isotp_new() - Create ISO-TP link with TWAI integration
  • esp_isotp_send() - Send data with automatic multi-frame handling
  • esp_isotp_receive() - Receive complete messages (single/multi-frame)
  • esp_isotp_poll() - Process incoming frames and state machine
  • esp_isotp_delete() - Clean up resources

TWAI Integration

  • Uses ESP-IDF's new TWAI driver (esp_driver_twai)
  • ISR-based receive callback for real-time frame processing. Queue-based message handling for thread safety

Build System

  • Automatic patch application during build via CMake. Patches modify isotp-c library for ESP-IDF compatibility.
  • Frame padding disabled for optimal payload usage.
  • Configurable response timeout (default 100ms).

Memory Management

  • Dynamic buffer allocation for TX/RX buffers
  • Configurable buffer sizes (up to 4095 bytes)
  • Automatic cleanup on deletion
  • Queue-based message queuing

Dependencies

  • ESP-IDF v5.5 (esp_driver_twai support)
  • isotp-c library (submodule)

Testing Status

  • Unit tests with pytest framework
  • QEMU integration testing
  • Linux can-utils compatibility verified
  • Multi-frame transmission/reception tested
  • Flow control handling verified

Known Limitations

  • Single instance limitation (underlying isotp-c library design), if I want to use multiple instances of the isotp-c library, I need to use distinguish different twai_node_handle_t by certaion can id.

Related

  • Closes IEC-296

@github-actions github-actions bot changed the title feat(isotp): Add ISO-TP (ISO 15765-2) Protocol Component with Examples and Testing Infrastructure (IEC-296) feat(isotp): Add ISO-TP (ISO 15765-2) Protocol Component with Examples and Testing Infrastructure (IEC-296) (IEC-346) Aug 6, 2025
@anastasia-be anastasia-be added the Component: new request Set this label for issues which request a new component to be added label Aug 6, 2025
@eternal-echo eternal-echo changed the title feat(isotp): Add ISO-TP (ISO 15765-2) Protocol Component with Examples and Testing Infrastructure (IEC-296) (IEC-346) feat(isotp): Add ISO-TP (ISO 15765-2) Protocol Component with Examples and Testing Infrastructure (IEC-296) Aug 6, 2025
@eternal-echo eternal-echo force-pushed the feat/isotp branch 2 times, most recently from 7c48f74 to 9a7585f Compare August 8, 2025 08:17
@eternal-echo eternal-echo marked this pull request as ready for review August 8, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: new request Set this label for issues which request a new component to be added Status: In Progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants