arch/risc-v/espressif: Add TWAI2 support for esp32p4#19176
Open
eren-terzioglu wants to merge 4 commits into
Open
arch/risc-v/espressif: Add TWAI2 support for esp32p4#19176eren-terzioglu wants to merge 4 commits into
eren-terzioglu wants to merge 4 commits into
Conversation
Enable TWAI2 support for esp32p4 Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
Add TWAI2 support for esp32p4 Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
Add TWAI2 docs for esp32p4 Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
xiaoxiang781216
approved these changes
Jun 19, 2026
Fix twai initialization when multiple twai devices enabled for esp32c6 and esp32p4 Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
tmedicci
reviewed
Jun 19, 2026
Comment on lines
+80
to
+103
| if (port == 0) | ||
| { | ||
| canerr("ERROR: TWAI0 register failed: %d\n", ret); | ||
| return ret; | ||
| /* Register the TWAI driver at "/dev/can0" */ | ||
|
|
||
| ret = can_register("/dev/can0", twai); | ||
| if (ret < 0) | ||
| { | ||
| canerr("ERROR: TWAI0 register failed: %d\n", ret); | ||
| return ret; | ||
| } | ||
| } | ||
| #endif /* CONFIG_ESPRESSIF_TWAI0 */ | ||
|
|
||
| #ifdef CONFIG_ESPRESSIF_TWAI1 | ||
| /* Register the TWAI driver at "/dev/can1" */ | ||
|
|
||
| ret = can_register("/dev/can1", twai); | ||
| if (ret < 0) | ||
| if (port == 1) | ||
| { | ||
| canerr("ERROR: TWAI1 register failed: %d\n", ret); | ||
| return ret; | ||
| /* Register the TWAI driver at "/dev/can1" */ | ||
|
|
||
| ret = can_register("/dev/can1", twai); | ||
| if (ret < 0) | ||
| { | ||
| canerr("ERROR: TWAI1 register failed: %d\n", ret); | ||
| return ret; | ||
| } |
Contributor
There was a problem hiding this comment.
Instead of duplicating the can_register function, can't port be used to derive the device's path and the same function used?
Think of a case with more than two ports; it wouldn't make sense to replicate the function n times.
Comment on lines
+80
to
+118
| if (port == 0) | ||
| { | ||
| canerr("ERROR: TWAI0 register failed: %d\n", ret); | ||
| return ret; | ||
| /* Register the TWAI driver at "/dev/can0" */ | ||
|
|
||
| ret = can_register("/dev/can0", twai); | ||
| if (ret < 0) | ||
| { | ||
| canerr("ERROR: TWAI0 register failed: %d\n", ret); | ||
| return ret; | ||
| } | ||
| } | ||
| #endif /* CONFIG_ESPRESSIF_TWAI0 */ | ||
|
|
||
| #ifdef CONFIG_ESPRESSIF_TWAI1 | ||
| /* Register the TWAI driver at "/dev/can1" */ | ||
|
|
||
| ret = can_register("/dev/can1", twai); | ||
| if (ret < 0) | ||
| if (port == 1) | ||
| { | ||
| canerr("ERROR: TWAI1 register failed: %d\n", ret); | ||
| return ret; | ||
| /* Register the TWAI driver at "/dev/can1" */ | ||
|
|
||
| ret = can_register("/dev/can1", twai); | ||
| if (ret < 0) | ||
| { | ||
| canerr("ERROR: TWAI1 register failed: %d\n", ret); | ||
| return ret; | ||
| } | ||
| } | ||
| #endif /* CONFIG_ESPRESSIF_TWAI1 */ | ||
|
|
||
| #ifdef CONFIG_ESPRESSIF_TWAI2 | ||
| if (port == 2) | ||
| { | ||
| /* Register the TWAI driver at "/dev/can2" */ | ||
|
|
||
| ret = can_register("/dev/can2", twai); | ||
| if (ret < 0) | ||
| { | ||
| canerr("ERROR: TWAI2 register failed: %d\n", ret); | ||
| return ret; | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Same (about multiple calls to can_register).
acassis
approved these changes
Jun 20, 2026
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
Unnecessary select lines and free to choose
ESPRESSIF_TWAIoption (which should not be) handled to have clearer Kconfig option systemAdd TWAI2 docs for esp32p4
Add TWAI2 support for esp32p4
Enable TWAI2 support for esp32p4
Impact
Impact on user: Yes, twai2 can be used with ESP32-P4
Impact on build: No
Impact on hardware: Yes, twai2 peripheral supported for ESP32-P4
Impact on documentation: Yes, related docs added
Impact on security: No
Impact on compatibility: No
Testing
esp32p4-function-ev-board:twaiconfig used withCAN_LOOPBACKandESPRESSIF_TWAI2options enabledBuilding
Command to build:
Running
can -n 5command used to test with connecting PIN 6-7 with a cableResults