esp32: add pool-based TWAI node module - #603
Open
MilladAnsari wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds ESP32 TWAI/CAN support as a standalone
twaiMicroPython user module, using the ESP-IDF v5.5.1 node-based TWAI API.It follows the architecture proposed by @kdschlosser in the PR #600 discussion: keep CAN transport work off the MicroPython/LVGL core, use interrupt-driven reception where the driver supports it, and reuse preallocated frame objects rather than allocating on the hot path.
Implementation
twai.Nodeand fixed-sizetwai.Frametypes underext_mod/twai.twai_node_register_event_callbacks()fromesp_driver_twai.on_rx_doneISR callback; there is no RX polling task.on_errorandon_state_changetrack error and bus-off events.Framepools.Framehas fixed 8-byte storage and exports the buffer protocol.frame[:]andmemoryview(frame)are supported.release().Node.send()is non-blocking and returnsOSError(EAGAIN)when the software TX queue is full.error_count,bus_off_count, anddropped_rx_count; non-zero values are logged duringNode.deinit().ext_mod/twai/examples/lamp_control.py.esp_driver_twai.Build and partition support
PART_SRCsupport tobuilder/esp32.py, allowing an explicitly supplied partition CSV to be copied verbatim and preventing automatic partition resizing.boards/partitions-16MiB.csv.0x350000, leaving sufficient headroom for the ESP32-S3 image.Validation
Built successfully with:
##Deferred work
This PR intentionally does not add:
These can be added in follow-up work without changing the allocation-free ISR and pool design introduced here.