diff --git a/components/esp_driver_twai/esp_twai_onchip.c b/components/esp_driver_twai/esp_twai_onchip.c index 51391522e3..f8c2a82674 100644 --- a/components/esp_driver_twai/esp_twai_onchip.c +++ b/components/esp_driver_twai/esp_twai_onchip.c @@ -707,13 +707,6 @@ esp_err_t twai_new_node_onchip(const twai_onchip_node_config_t *node_config, twa .enable_self_test = node_config->flags.enable_self_test, .enable_loopback = node_config->flags.enable_loopback, }; -#if CONFIG_IDF_TARGET_ESP32C5 - // ESP32C5 has a bug that the listen only mode don't work when there are other nodes sending ACK each other - // See IDF-13059 for more details - if (node_config->flags.enable_listen_only) { - ESP_LOGW(TAG, "Listen only mode for ESP32C5 may not work properly when there are more than 2 nodes on the bus that are sending ACKs to each other"); - } -#endif ESP_GOTO_ON_FALSE(twai_hal_init(node->hal, &hal_config), ESP_ERR_INVALID_STATE, err, TAG, "hardware not in reset state"); // Configure bus timing ESP_GOTO_ON_ERROR(_node_calc_set_bit_timing(&node->api_base, node_config->clk_src, &node_config->bit_timing, &node_config->data_timing), err, TAG, "bitrate error"); diff --git a/components/esp_driver_twai/test_apps/test_twai/main/test_twai_common.c b/components/esp_driver_twai/test_apps/test_twai/main/test_twai_common.c index 791662d890..ec1ecfa9f7 100644 --- a/components/esp_driver_twai/test_apps/test_twai/main/test_twai_common.c +++ b/components/esp_driver_twai/test_apps/test_twai/main/test_twai_common.c @@ -646,8 +646,7 @@ static IRAM_ATTR bool test_rx_isr_send_cb(twai_node_handle_t handle, const twai_ // Test sending from RX ISR context (response pattern) if ((rx_frame.header.id >= 0x100) && (rx_frame.header.id < 0x103) && (ctx->rx_isr_send_count < 3)) { - static twai_frame_t response_frame; - response_frame = (twai_frame_t) {}; + static twai_frame_t response_frame = {}; response_frame.header.id = 0x300 + ctx->rx_isr_send_count; response_frame.header.dlc = 1; response_frame.buffer = (uint8_t*)(&ctx->rx_isr_send_count); @@ -692,13 +691,11 @@ TEST_CASE("twai send from ISR context (loopback)", "[twai]") printf("Testing ISR context sending...\n"); // Send initial frames to trigger RX ISR responses - for (int i = 0; i < 3; i++) { + for (uint8_t i = 0; i < 3; i++) { twai_frame_t trigger_frame = {}; trigger_frame.header.id = 0x100 + i; trigger_frame.header.dlc = 1; - trigger_frame.buffer = (uint8_t[]) { - (uint8_t)i - }; + trigger_frame.buffer = &i; trigger_frame.buffer_len = 1; TEST_ESP_OK(twai_node_transmit(test_ctx.node, &trigger_frame, 500)); @@ -727,8 +724,6 @@ TEST_CASE("twai send from ISR context (loopback)", "[twai]") TEST_ESP_OK(twai_node_disable(test_ctx.node)); TEST_ESP_OK(twai_node_delete(test_ctx.node)); - - printf("ISR send test passed!\n"); } static IRAM_ATTR bool test_dlc_range_cb(twai_node_handle_t handle, const twai_rx_done_event_data_t *edata, void *user_ctx) diff --git a/components/esp_driver_twai/test_apps/test_twai/pytest_driver_twai.py b/components/esp_driver_twai/test_apps/test_twai/pytest_driver_twai.py index 4bd32b3f4b..a08017531b 100644 --- a/components/esp_driver_twai/test_apps/test_twai/pytest_driver_twai.py +++ b/components/esp_driver_twai/test_apps/test_twai/pytest_driver_twai.py @@ -36,7 +36,6 @@ def fixture_create_socket_can() -> Bus: @pytest.mark.twai_std -@pytest.mark.temp_skip_ci(targets=['esp32c5'], reason='no runner') @pytest.mark.parametrize('config', ['release'], indirect=True) @idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target']) def test_driver_twai_listen_only(dut: Dut, socket_can: Bus) -> None: @@ -59,7 +58,6 @@ def test_driver_twai_listen_only(dut: Dut, socket_can: Bus) -> None: @pytest.mark.twai_std -@pytest.mark.temp_skip_ci(targets=['esp32c5'], reason='no runner') @pytest.mark.parametrize('config', ['release'], indirect=True) @idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target']) def test_driver_twai_remote_request(dut: Dut, socket_can: Bus) -> None: diff --git a/components/hal/esp32c5/include/hal/twaifd_ll.h b/components/hal/esp32c5/include/hal/twaifd_ll.h index 59b72699b0..f6c8baa4fa 100644 --- a/components/hal/esp32c5/include/hal/twaifd_ll.h +++ b/components/hal/esp32c5/include/hal/twaifd_ll.h @@ -174,7 +174,11 @@ static inline void twaifd_ll_set_mode(twaifd_dev_t *hw, bool listen_only, bool s twaifd_mode_settings_reg_t opmode = {.val = hw->mode_settings.val}; opmode.stm = self_test; + // esp32c5 using `rom` and `acf` together with `bmm` to warkaround the errata 0v2 issue 5 + // see issue https://github.com/espressif/esp-idf/issues/17461 opmode.bmm = listen_only; + opmode.rom = listen_only; + opmode.acf = listen_only; opmode.ilbp = loopback; hw->mode_settings.val = opmode.val; diff --git a/docs/en/api-reference/peripherals/twai.rst b/docs/en/api-reference/peripherals/twai.rst index f78cf279a9..12e6356446 100644 --- a/docs/en/api-reference/peripherals/twai.rst +++ b/docs/en/api-reference/peripherals/twai.rst @@ -90,12 +90,6 @@ Below are additional configuration fields of the :cpp:type:`twai_onchip_node_con - :cpp:member:`twai_onchip_node_config_t::flags::enable_listen_only`: Configures the node in listen-only mode. In this mode, the node only receives and does not transmit any dominant bits, including ACK and error frames. - :cpp:member:`twai_onchip_node_config_t::flags::no_receive_rtr`: When using filters, determines whether remote frames matching the ID pattern should be filtered out. -.. only:: esp32c5 - - .. note:: - - Note: The listen-only mode on ESP32C5 can't work properly when there are multiple nodes on the bus that are sending ACKs to each other. An alternative is to use transceiver which supports listen-only mode itself (e.g. TJA1145), and combine it with self-test mode enabled. - The :cpp:func:`twai_node_enable` function starts the TWAI controller. Once enabled, the controller is connected to the bus and can transmit messages. It also generates events upon receiving messages from other nodes on the bus or when bus errors are detected. The corresponding function, :cpp:func:`twai_node_disable`, immediately stops the node and disconnects it from the bus. Any ongoing transmissions will be aborted. When the node is re-enabled later, if there are pending transmissions in the queue, the driver will immediately initiate a new transmission attempt. diff --git a/docs/zh_CN/api-reference/peripherals/twai.rst b/docs/zh_CN/api-reference/peripherals/twai.rst index f5007fd7f9..0f3a25ff91 100644 --- a/docs/zh_CN/api-reference/peripherals/twai.rst +++ b/docs/zh_CN/api-reference/peripherals/twai.rst @@ -90,12 +90,6 @@ TWAI 是一种适用于汽车和工业应用的高可靠性的多主机实时串 - :cpp:member:`twai_onchip_node_config_t::flags::enable_listen_only` 配置为监听模式,节点只接收,不发送任何显性位,包括 ACK 和错误帧。 - :cpp:member:`twai_onchip_node_config_t::flags::no_receive_rtr` 使用过滤器时是否同时过滤掉符合 ID 规则的远程帧。 -.. only:: esp32c5 - - .. note:: - - 注意: ESP32C5 的监听模式在总线上有多个节点相互发送 ACK 信号时无法正常工作。一种替代方案是使用本身支持监听模式的收发器(例如 TJA1145),并结合启用自测模式。 - 函数 :cpp:func:`twai_node_enable` 将启动 TWAI 控制器,此时 TWAI 控制器就连接到了总线,可以向总线发送报文。如果收到了总线上其他节点发送的报文,或者检测到了总线错误,也将产生相应事件。 与之对应的函数是 :cpp:func:`twai_node_disable`,该函数将立即停止节点工作并与总线断开,正在进行的传输将被中止。当下次重新启动时,如果发送队列中有未完成的任务,驱动将立即发起新的传输。 diff --git a/examples/peripherals/.build-test-rules.yml b/examples/peripherals/.build-test-rules.yml index 0d8afbba3c..11706d46d2 100644 --- a/examples/peripherals/.build-test-rules.yml +++ b/examples/peripherals/.build-test-rules.yml @@ -499,9 +499,6 @@ examples/peripherals/twai/twai_error_recovery: examples/peripherals/twai/twai_network: disable: - if: SOC_TWAI_SUPPORTED != 1 - disable_test: - - if: IDF_TARGET == "esp32c5" - reason: esp32c5,esp32 test has been disabled, because C5 twai don't support listen only in network test, see errata issue 5 depends_components: - esp_driver_twai diff --git a/examples/peripherals/twai/twai_network/pytest_twai_network.py b/examples/peripherals/twai/twai_network/pytest_twai_network.py index 3901cef2eb..d1bfc7c6f5 100644 --- a/examples/peripherals/twai/twai_network/pytest_twai_network.py +++ b/examples/peripherals/twai/twai_network/pytest_twai_network.py @@ -54,9 +54,6 @@ def generate_target_combinations(target_list: list, count: int = 2) -> list: ], indirect=True, ) -@pytest.mark.temp_skip_ci( - targets=['esp32c5,esp32'], reason="C5 twai don't support listen only in network test, see errata issue 5" -) def test_twai_network_multi(dut: Tuple[IdfDut, IdfDut], socket_can: Bus) -> None: # type: ignore """ Test TWAI network communication between two nodes: