Skip to content

arch/risc-v/espressif: Add TWAI2 support for esp32p4#19176

Open
eren-terzioglu wants to merge 4 commits into
apache:masterfrom
eren-terzioglu:feature/p4_enable_twai2
Open

arch/risc-v/espressif: Add TWAI2 support for esp32p4#19176
eren-terzioglu wants to merge 4 commits into
apache:masterfrom
eren-terzioglu:feature/p4_enable_twai2

Conversation

@eren-terzioglu

@eren-terzioglu eren-terzioglu commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Unnecessary select lines and free to choose ESPRESSIF_TWAI option (which should not be) handled to have clearer Kconfig option system

  • Docs/platforms/risc-v: Add TWAI2 docs for esp32p4

Add TWAI2 docs for esp32p4

  • boards/risc-v/esp32p4: Add TWAI2 support for esp32p4

Add TWAI2 support for esp32p4

  • arch/risc-v/espressif: 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:twai config used with CAN_LOOPBACK and ESPRESSIF_TWAI2 options enabled

Building

Command to build:

make distclean && ./tools/configure.sh esp32p4-function-ev-board:twai && kconfig-tweak -e CAN_LOOPBACK && kconfig-tweak -e  ESPRESSIF_TWAI2 && make olddefconfig && make -j && make download ESPTOOL_PORT=/dev/ttyUSB0

Running

can -n 5 command used to test with connecting PIN 6-7 with a cable

Results

nsh> can -n 5
nmsgs: 5
min ID: 1 max ID: 2047
Bit timing:
   Baud: 909090
  TSEG1: 16
  TSEG2: 5
    SJW: 4
  ID:    1 DLC: 1
  ID:    1 DLC: 1
  ID:    1 DLC: 1 -- OK
  ID:    2 DLC: 2
  ID:    2 DLC: 2
  ID:    2 DLC: 2 -- OK
  ID:    3 DLC: 3
  ID:    3 DLC: 3
  ID:    3 DLC: 3 -- OK
  ID:    4 DLC: 4
  ID:    4 DLC: 4
  ID:    4 DLC: 4 -- OK
  ID:    5 DLC: 5
  ID:    5 DLC: 5
  ID:    5 DLC: 5 -- OK
Terminating!
nsh> 

@github-actions github-actions Bot added Area: Documentation Improvements or additions to documentation Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Size: M The size of the change in this PR is medium Board: risc-v labels Jun 19, 2026
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>
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

Fix twai initialization when multiple twai devices enabled for esp32c6 and esp32p4

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same (about multiple calls to can_register).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Area: Documentation Improvements or additions to documentation Board: risc-v Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants