esp-idf: ESP32-S2:TWAI RX does not work (IDFGH-3670)
Environment
- Development Kit: ESP32-S2
- Kit version (for WroverKit/PicoKit/DevKitC): [v1|v2|v3|v4]
- Module or chip used: WROVER
- IDF version (run
git describe --tagsto find it): master (latest) - Build System: CMake
- Compiler version (run
xtensa-esp32-elf-gcc --versionto find it): 8.2.0r2 - Operating System: Linux
- Using an IDE?: No
- Power Supply: USB (or external 5v or 3v3)
Problem Description
The TWAI driver does not trigger RX events when running at 125kbps (pins rx: 36, tx: 37) with accept all filter.
Expected Behavior
Actual Behavior
Steps to reproduce
After fixing https://github.com/espressif/esp-idf/issues/5603 mappings (minimum needed for my old code):
-#include "hal/can_types.h"
+#include "hal/twai_types.h"
...
+#define CAN_TIMING_CONFIG_125KBITS TWAI_TIMING_CONFIG_125KBITS
+#define CAN_FILTER_CONFIG_ACCEPT_ALL TWAI_FILTER_CONFIG_ACCEPT_ALL
+
+#define CAN_MODE_NORMAL TWAI_MODE_NORMAL
+#define CAN_MSG_FLAG_NONE TWAI_MSG_FLAG_NONE
+#define CAN_MSG_FLAG_EXTD TWAI_MSG_FLAG_EXTD
+#define CAN_MSG_FLAG_RTR TWAI_MSG_FLAG_RTR
+#define CAN_MSG_FLAG_DLC_NON_COMP TWAI_MSG_FLAG_DLC_NON_COMP
+
+typedef twai_timing_config_t can_timing_config_t;
+typedef twai_filter_config_t can_filter_config_t;
+typedef twai_message_t can_message_t;
I was able to compile my old code (https://github.com/openmrn/OpenMRNLite/tree/master/examples/ESP32IOBoard). I can see the frames being transmitted by the S2 to the other devices on the network but the S2 never raises an RX event.
I added
#include "soc_log.h"
SOC_LOGE("TWAI-HAL", "%04x, %04x, %d:%d\n", interrupts, status, tec, rec);
to https://github.com/espressif/esp-idf/blob/master/components/soc/src/hal/twai_hal.c#L91 in order to confirm the RX event was never raised:
[ESP-TWAI] sending frame
E (2070) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
E (2076) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
[ESP-TWAI] sending frame
E (2085) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
Allocating new alias 849 for node 050201030000
[ESP-TWAI] sending frame
E (2287) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
[ESP-TWAI] sending frame
E (2290) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
[ESP-TWAI] sending frame
E (2299) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
[ESP-TWAI] sending frame
E (2308) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
[ESP-TWAI] sending frame
E (2317) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
E (2323) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
[ESP-TWAI] sending frame
E (2332) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
[ESP-TWAI] sending frame
E (2533) TWAI-HAL: 0002, 002c, 0:0
ESP-TWAI: 0400
ESP-TWAI: TX SUCCESS
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 34 (1 by maintainers)
Most probably replacing the “.byte” (x2) by ".val“ would have also worked as this is what is done with the TX buffers. Gone to work right now but I can try that this evening…
[edit] … and I can confirm this version also works:
@Dazza0, I am also facing the Rx issue with ESP32 (ESP-WROOM-32) while Tx is working perfectly. I am using the MCP2515 module as my CAN transceiver.
I tried ESP-IDF v5 as well as v4.4.4, neither of which seem to work.
I saw a YouTube video with someone who used a similar code, and it was working perfectly for him (YouTube Video: link: https://youtu.be/bxzWuIqfn9Y).
This is my code:
@brice-fr @eloebl @atanisoft @jepler
If anyone can help me, it would be really appreciated!
Regards,
Awaiting reply ASAP
@atanisoft MR for v4.3 backport is current review
@atanisoft Seems like there are two separate issues when C++ tries to use the macros provided in
hal/misc.htypeof()on aunion{}register somehow discards itsvolatilequalifier. Not sure why.typeof(base_reg) temp_reg = (base_reg);will invoke a non-existent copy constructor.Try replacing the macros in
hal/misc.hwith the following and see if the issues is resolvedPTAL at commit 2e0ffbd543abc0226f0dbd2f725eb891235abe02. The commit should prevent
s8access on all peripherals.@Dazza0 I’ve tested the TWAI code I linked to above on the ESP32 on latest IDF master with no issues. I’m at a loss as to what is missing on the ESP32-S2 side.
For both the ESP32 and ESP32-S2 I’ve used SN65HVD230 with this circuit to visualize the TX/RX activity:
It appears that even though the frames are visually confirmed as being sent by the SN65HVD230 to the ESP32-S2 it would appear the ESP32-S2 is not processing them.