Skip to content

esp32s3: expose canbus machine property and wire TWAI peripheral#147

Draft
haoruizhou wants to merge 1 commit into
espressif:esp-developfrom
Western-Formula-Racing:wfr/esp32s3-twai-canbus
Draft

esp32s3: expose canbus machine property and wire TWAI peripheral#147
haoruizhou wants to merge 1 commit into
espressif:esp-developfrom
Western-Formula-Racing:wfr/esp32s3-twai-canbus

Conversation

@haoruizhou

@haoruizhou haoruizhou commented Mar 19, 2026

Copy link
Copy Markdown

The ESP32-S3 TWAI device (esp32s3_twai.c, inheriting esp32_twai.c) already implements a 'canbus' link property and calls can_sja_connect_to_bus() in its realize handler — but the machine (esp32s3.c) never exposed a corresponding property or set the link, leaving the TWAI peripheral permanently CAN-isolated.

This patch wires the two together:

  • Add CanBusState *canbus field to Esp32s3MachineState
  • Expose it as a machine property via object_class_property_add_link
  • Set the TWAI 'canbus' link in machine_init before qdev_realize

Usage:
-object can-bus,id=canbus0 -object can-host-socketcan,id=can-host0,if=vcan0,canbus=canbus0 -machine esp32s3,canbus=canbus0

Tested with ESP32-S3 firmware on vcan0 (Linux virtual SocketCAN). Firmware CAN TX and RX confirmed working via candump.

Description

Related

Testing


Checklist

Before submitting a Pull Request, please ensure the following:

  • 🚨 This PR does not introduce breaking changes.
  • All CI checks (GH Actions) pass.
  • Documentation is updated as needed.
  • Tests are updated or added as necessary.
  • Code is well-commented, especially in complex areas.
  • Git history is clean — commits are squashed to the minimum necessary.

The ESP32-S3 TWAI device (esp32s3_twai.c, inheriting esp32_twai.c)
already implements a 'canbus' link property and calls
can_sja_connect_to_bus() in its realize handler — but the machine
(esp32s3.c) never exposed a corresponding property or set the link,
leaving the TWAI peripheral permanently CAN-isolated.

This patch wires the two together:
- Add CanBusState *canbus field to Esp32s3MachineState
- Expose it as a machine property via object_class_property_add_link
- Set the TWAI 'canbus' link in machine_init before qdev_realize

Usage:
  -object can-bus,id=canbus0
  -object can-host-socketcan,id=can-host0,if=vcan0,canbus=canbus0
  -machine esp32s3,canbus=canbus0

Tested with ESP32-S3 firmware on vcan0 (Linux virtual SocketCAN).
Firmware CAN TX and RX confirmed working via candump.
@haoruizhou haoruizhou marked this pull request as draft March 19, 2026 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants