mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-02 10:00:57 +02:00
fix(driver_twai): added ctu_official listen only workaround
Closes https://github.com/espressif/esp-idf/issues/17461
This commit is contained in:
@@ -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_self_test = node_config->flags.enable_self_test,
|
||||||
.enable_loopback = node_config->flags.enable_loopback,
|
.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");
|
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
|
// 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");
|
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");
|
||||||
|
@@ -609,7 +609,7 @@ static IRAM_ATTR bool test_tx_isr_send_cb(twai_node_handle_t handle, const twai_
|
|||||||
|
|
||||||
// Test sending from TX ISR context
|
// Test sending from TX ISR context
|
||||||
if (ctx->tx_isr_send_count < 3) {
|
if (ctx->tx_isr_send_count < 3) {
|
||||||
twai_frame_t isr_frame = {};
|
static twai_frame_t isr_frame = {};
|
||||||
isr_frame.header.id = 0x200 + ctx->tx_isr_send_count;
|
isr_frame.header.id = 0x200 + ctx->tx_isr_send_count;
|
||||||
isr_frame.header.dlc = 1;
|
isr_frame.header.dlc = 1;
|
||||||
isr_frame.buffer = (uint8_t*)(&ctx->tx_isr_send_count);
|
isr_frame.buffer = (uint8_t*)(&ctx->tx_isr_send_count);
|
||||||
@@ -637,7 +637,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)
|
// 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)) {
|
if ((rx_frame.header.id >= 0x100) && (rx_frame.header.id < 0x103) && (ctx->rx_isr_send_count < 3)) {
|
||||||
twai_frame_t response_frame = {};
|
static twai_frame_t response_frame = {};
|
||||||
response_frame.header.id = 0x300 + ctx->rx_isr_send_count;
|
response_frame.header.id = 0x300 + ctx->rx_isr_send_count;
|
||||||
response_frame.header.dlc = 1;
|
response_frame.header.dlc = 1;
|
||||||
response_frame.buffer = (uint8_t*)(&ctx->rx_isr_send_count);
|
response_frame.buffer = (uint8_t*)(&ctx->rx_isr_send_count);
|
||||||
@@ -682,13 +682,11 @@ TEST_CASE("twai send from ISR context (loopback)", "[twai]")
|
|||||||
printf("Testing ISR context sending...\n");
|
printf("Testing ISR context sending...\n");
|
||||||
|
|
||||||
// Send initial frames to trigger RX ISR responses
|
// 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 = {};
|
twai_frame_t trigger_frame = {};
|
||||||
trigger_frame.header.id = 0x100 + i;
|
trigger_frame.header.id = 0x100 + i;
|
||||||
trigger_frame.header.dlc = 1;
|
trigger_frame.header.dlc = 1;
|
||||||
trigger_frame.buffer = (uint8_t[]) {
|
trigger_frame.buffer = &i;
|
||||||
(uint8_t)i
|
|
||||||
};
|
|
||||||
trigger_frame.buffer_len = 1;
|
trigger_frame.buffer_len = 1;
|
||||||
|
|
||||||
TEST_ESP_OK(twai_node_transmit(test_ctx.node, &trigger_frame, 500));
|
TEST_ESP_OK(twai_node_transmit(test_ctx.node, &trigger_frame, 500));
|
||||||
@@ -717,8 +715,6 @@ TEST_CASE("twai send from ISR context (loopback)", "[twai]")
|
|||||||
|
|
||||||
TEST_ESP_OK(twai_node_disable(test_ctx.node));
|
TEST_ESP_OK(twai_node_disable(test_ctx.node));
|
||||||
TEST_ESP_OK(twai_node_delete(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)
|
static IRAM_ATTR bool test_dlc_range_cb(twai_node_handle_t handle, const twai_rx_done_event_data_t *edata, void *user_ctx)
|
||||||
|
@@ -36,7 +36,7 @@ def fixture_create_socket_can() -> Bus:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.twai_std
|
@pytest.mark.twai_std
|
||||||
@pytest.mark.temp_skip_ci(targets=['esp32c5', 'esp32h4'], reason='no runner')
|
@pytest.mark.temp_skip_ci(targets=['esp32h4'], reason='no runner')
|
||||||
@pytest.mark.parametrize('config', ['release'], indirect=True)
|
@pytest.mark.parametrize('config', ['release'], indirect=True)
|
||||||
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
|
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
|
||||||
def test_driver_twai_listen_only(dut: Dut, socket_can: Bus) -> None:
|
def test_driver_twai_listen_only(dut: Dut, socket_can: Bus) -> None:
|
||||||
@@ -59,7 +59,7 @@ def test_driver_twai_listen_only(dut: Dut, socket_can: Bus) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.twai_std
|
@pytest.mark.twai_std
|
||||||
@pytest.mark.temp_skip_ci(targets=['esp32c5', 'esp32h4'], reason='no runner')
|
@pytest.mark.temp_skip_ci(targets=['esp32h4'], reason='no runner')
|
||||||
@pytest.mark.parametrize('config', ['release'], indirect=True)
|
@pytest.mark.parametrize('config', ['release'], indirect=True)
|
||||||
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
|
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
|
||||||
def test_driver_twai_remote_request(dut: Dut, socket_can: Bus) -> None:
|
def test_driver_twai_remote_request(dut: Dut, socket_can: Bus) -> None:
|
||||||
|
@@ -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};
|
twaifd_mode_settings_reg_t opmode = {.val = hw->mode_settings.val};
|
||||||
opmode.stm = self_test;
|
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.bmm = listen_only;
|
||||||
|
opmode.rom = listen_only;
|
||||||
|
opmode.acf = listen_only;
|
||||||
opmode.ilbp = loopback;
|
opmode.ilbp = loopback;
|
||||||
|
|
||||||
hw->mode_settings.val = opmode.val;
|
hw->mode_settings.val = opmode.val;
|
||||||
|
@@ -180,6 +180,9 @@ 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};
|
twaifd_mode_settings_reg_t opmode = {.val = hw->mode_settings.val};
|
||||||
opmode.stm = self_test;
|
opmode.stm = self_test;
|
||||||
opmode.bmm = listen_only;
|
opmode.bmm = listen_only;
|
||||||
|
// esp32h4 using `rom` together with `bmm` although errata 0v2 issue 5 is fixed
|
||||||
|
// see detail in https://github.com/espressif/esp-idf/issues/17461
|
||||||
|
opmode.rom = listen_only;
|
||||||
opmode.ilbp = loopback;
|
opmode.ilbp = loopback;
|
||||||
|
|
||||||
hw->mode_settings.val = opmode.val;
|
hw->mode_settings.val = opmode.val;
|
||||||
|
@@ -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::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.
|
- :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 :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.
|
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.
|
||||||
|
@@ -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::enable_listen_only` 配置为监听模式,节点只接收,不发送任何显性位,包括 ACK 和错误帧。
|
||||||
- :cpp:member:`twai_onchip_node_config_t::flags::no_receive_rtr` 使用过滤器时是否同时过滤掉符合 ID 规则的远程帧。
|
- :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_enable` 将启动 TWAI 控制器,此时 TWAI 控制器就连接到了总线,可以向总线发送报文。如果收到了总线上其他节点发送的报文,或者检测到了总线错误,也将产生相应事件。
|
||||||
|
|
||||||
与之对应的函数是 :cpp:func:`twai_node_disable`,该函数将立即停止节点工作并与总线断开,正在进行的传输将被中止。当下次重新启动时,如果发送队列中有未完成的任务,驱动将立即发起新的传输。
|
与之对应的函数是 :cpp:func:`twai_node_disable`,该函数将立即停止节点工作并与总线断开,正在进行的传输将被中止。当下次重新启动时,如果发送队列中有未完成的任务,驱动将立即发起新的传输。
|
||||||
|
@@ -518,9 +518,6 @@ examples/peripherals/twai/twai_error_recovery:
|
|||||||
examples/peripherals/twai/twai_network:
|
examples/peripherals/twai/twai_network:
|
||||||
disable:
|
disable:
|
||||||
- if: SOC_TWAI_SUPPORTED != 1
|
- if: SOC_TWAI_SUPPORTED != 1
|
||||||
disable_test:
|
|
||||||
- if: IDF_TARGET == "esp32"
|
|
||||||
reason: esp32c5,esp32 test has been disabled, because C5 twai don't support listen only in network test, see errata issue 5
|
|
||||||
depends_components:
|
depends_components:
|
||||||
- esp_driver_twai
|
- esp_driver_twai
|
||||||
|
|
||||||
|
@@ -53,9 +53,6 @@ def generate_target_combinations(target_list: list, count: int = 2) -> list:
|
|||||||
],
|
],
|
||||||
indirect=True,
|
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:
|
def test_twai_network_multi(dut: tuple[IdfDut, IdfDut], socket_can: Bus) -> None:
|
||||||
"""
|
"""
|
||||||
Test TWAI network communication between two nodes:
|
Test TWAI network communication between two nodes:
|
||||||
|
@@ -644,7 +644,7 @@ def test_twai_range_filters(twai: TwaiTestHelper) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.twai_std
|
@pytest.mark.twai_std
|
||||||
@pytest.mark.temp_skip_ci(targets=['esp32c5', 'esp32h4'], reason='no runner')
|
@pytest.mark.temp_skip_ci(targets=['esp32h4'], reason='no runner')
|
||||||
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
|
@idf_parametrize('target', soc_filtered_targets('SOC_TWAI_SUPPORTED == 1'), indirect=['target'])
|
||||||
def test_twai_external_communication(twai: TwaiTestHelper, can_manager: CanBusManager) -> None:
|
def test_twai_external_communication(twai: TwaiTestHelper, can_manager: CanBusManager) -> None:
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user