Open lomal788 opened 4 months ago
The ESP32 (base variant) only has a single TWAI/CAN controller in the hardware. You can not install a second instance.
The only ESP32 variants with additional controllers are ESP32-P4 (3), ESP32-C5 (2) and ESP32-C6 (2).
@atanisoft is there any way could i use 2 can bus with esp32 wrover-E ? ex ) one for TWAI the other for MCP2515 would work?
@lomal788 that should work since the MCP2515 is an SPI device and wouldn't depend on the TWAI driver in any way, you would need to use a compatible driver for that IC with it's API.
@lomal788 Hi, dose issue resolved
Answers checklist.
Hardware
ESP32 Wrover-IE Devboard
IDF version.
5.2.1, but master branch does the same
Operating System used.
Windows
How did you build your project?
VS Code IDE
If you are using Windows, please specify command line type.
PowerShell
What is the expected behavior?
twai driver install multiple instance.q
What is the actual behavior?
first instance was successfully install, started. but second instance is not started. ( error : ESP_ERR_INVALID_ARG ( 0x102 ) )
Steps to reproduce.
same as this code. https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/twai.html?highlight=twai#install-multiple-twai-instances
Build or installation Logs.
-- modify SOC_TWAI_CONTROLLER_NUM as 2 build error
␛[0;32mI (236) cpu_start: ESP-IDF: 5.2.1␛[0m ␛[0;32mI (241) cpu_start: Min chip rev: v0.0␛[0m ␛[0;32mI (245) cpu_start: Max chip rev: v3.99 ␛[0m ␛[0;32mI (250) cpu_start: Chip rev: v3.0␛[0m ␛[0;32mI (255) heap_init: Initializing. RAM available for dynamic allocation:␛[0m ␛[0;32mI (262) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM␛[0m ␛[0;32mI (268) heap_init: At 3FFB2BB8 len 0002D448 (181 KiB): DRAM␛[0m ␛[0;32mI (274) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM␛[0m ␛[0;32mI (281) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM␛[0m ␛[0;32mI (287) heap_init: At 4008DD00 len 00012300 (72 KiB): IRAM␛[0m ␛[0;32mI (294) spi_flash: detected chip: generic␛[0m ␛[0;32mI (298) spi_flash: flash io: dio␛[0m ␛[0;32mI (303) main_task: Started on CPU0␛[0m ␛[0;32mI (313) main_task: Calling app_main()␛[0m ␛[0;32mI (313) CAN_BASE: Booting CAN Layer␛[0m ␛[0;32mI (313) gpio: GPIO[4]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 ␛[0m ␛[0;32mI (323) gpio: GPIO[5]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 ␛[0m First Instance Driver installed Calling Setup Trying to install Second Instance Guru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled.
Core 0 register dump: PC : 0x400d8018 PS : 0x00060030 A0 : 0x800eab8c A1 : 0x3ffb4da0
A2 : 0x3ffb6268 A3 : 0x3ffb4dd8 A4 : 0x3f409fac A5 : 0x00060023
A6 : 0xffffffff A7 : 0x0000cdcd A8 : 0x3ffb6268 A9 : 0x00000000 A10 : 0x04c4b400 A11 : 0xffffffff A12 : 0x00060020 A13 : 0x00060023 A14 : 0x3ffb6290 A15 : 0x0000cdcd SAR : 0x0000000f EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0xffffffff
Backtrace: 0x400d8015:0x3ffb4da0 0x400eab89:0x3ffb4dd0 0x400d13ee:0x3ffb4e00 0x400d1279:0x3ffb4e70 0x400d118b:0x3ffb4e90 0x400eb910:0x3ffb4eb0 0x400873e9:0x3ffb4ee0
ELF file SHA256: 2ef650abc678c159
Rebooting...
More Information.
only 1 instance was successfully work.
I found theres code in twai_driver_install_v2 function theres "TWAI_CHECK(g_config->controller_id < SOC_TWAI_CONTROLLER_NUM, ESP_ERR_INVALID_ARG);" SOC_TWAI_CONTROLLER_NUM defined 1UL which only controller_id = 0 is work.
if I make controller_id as 0 as the second instance it successfully pass the TWAI_CHECK area and change error code : ESP_ERR_INVALID_STATE - > which already client is using.
SOC_TWAI_CONTROLLER_NUM should be editable by user or it should over a 2
If i fix SOC_TWAI_CONTROLLER_NUM as 2 It pass every TWAI_CHECK ( for multiple instance error ) but got "Core 0 panic'ed (LoadProhibited). Exception was unhandled." error either I change client_id as 1 to install only one instance it has same error. single instance always work ( I use GPIO 5,4 pin and 23,22 pin ) both are work only single instance..