mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(twai): busoff and clkout may not available in SOC
return ESP_ERR_NOT_SUPPORTED if these signals are required from user but not available in SOC
This commit is contained in:
@@ -123,6 +123,8 @@ static esp_err_t _node_config_io(twai_onchip_ctx_t *node, const twai_onchip_node
|
||||
ESP_RETURN_ON_FALSE(GPIO_IS_VALID_OUTPUT_GPIO(node_config->io_cfg.tx), ESP_ERR_INVALID_ARG, TAG, "Invalid tx gpio num");
|
||||
ESP_RETURN_ON_FALSE(GPIO_IS_VALID_GPIO(node_config->io_cfg.rx), ESP_ERR_INVALID_ARG, TAG, "Invalid rx gpio num");
|
||||
uint64_t reserve_mask = BIT64(node_config->io_cfg.tx);
|
||||
ESP_RETURN_ON_FALSE(!(GPIO_IS_VALID_OUTPUT_GPIO(node_config->io_cfg.quanta_clk_out) && (twai_controller_periph_signals.controllers[node->ctrlr_id].clk_out_sig < 0)), ESP_ERR_NOT_SUPPORTED, TAG, "quanta_clk_out is not supported");
|
||||
ESP_RETURN_ON_FALSE(!(GPIO_IS_VALID_OUTPUT_GPIO(node_config->io_cfg.bus_off_indicator) && (twai_controller_periph_signals.controllers[node->ctrlr_id].bus_off_sig < 0)), ESP_ERR_NOT_SUPPORTED, TAG, "bus_off_indicator is not supported");
|
||||
|
||||
// Set RX pin
|
||||
gpio_input_enable(node_config->io_cfg.rx);
|
||||
|
||||
@@ -29,7 +29,7 @@ static IRAM_ATTR bool test_driver_install_rx_cb(twai_node_handle_t handle, const
|
||||
{
|
||||
twai_frame_t rx_frame = {0};
|
||||
if (ESP_OK == twai_node_receive_from_isr(handle, &rx_frame)) {
|
||||
ESP_EARLY_LOGI("Recv ", "id 0x%lx rtr %d", rx_frame.header.id, rx_frame.header.rtr);
|
||||
esp_rom_printf("Recv id 0x%lx rtr %d", rx_frame.header.id, rx_frame.header.rtr);
|
||||
}
|
||||
if (rx_frame.header.id != 0x100) {
|
||||
TEST_FAIL(); //callback is unregistered, should not run here
|
||||
@@ -111,6 +111,8 @@ static void test_twai_baudrate_correctness(twai_clock_source_t clk_src, uint32_t
|
||||
.clk_src = clk_src,
|
||||
.io_cfg.tx = TEST_TX_GPIO,
|
||||
.io_cfg.rx = TEST_TX_GPIO,
|
||||
.io_cfg.quanta_clk_out = GPIO_NUM_NC,
|
||||
.io_cfg.bus_off_indicator = GPIO_NUM_NC,
|
||||
.bit_timing.bitrate = test_bitrate,
|
||||
.tx_queue_depth = 1,
|
||||
.flags.enable_loopback = true,
|
||||
|
||||
@@ -67,6 +67,8 @@ TEST_CASE("twai range filter (loopback)", "[twai]")
|
||||
twai_onchip_node_config_t node_config = {
|
||||
.io_cfg.tx = TEST_TX_GPIO,
|
||||
.io_cfg.rx = TEST_TX_GPIO, // Using same pin for test without transceiver
|
||||
.io_cfg.quanta_clk_out = GPIO_NUM_NC,
|
||||
.io_cfg.bus_off_indicator = GPIO_NUM_NC,
|
||||
.bit_timing.bitrate = 1000000,
|
||||
.tx_queue_depth = TEST_TWAI_QUEUE_DEPTH,
|
||||
.flags.enable_loopback = true,
|
||||
@@ -142,6 +144,8 @@ TEST_CASE("twai fd transmit time (loopback)", "[twai]")
|
||||
twai_onchip_node_config_t node_config = {
|
||||
.io_cfg.tx = TEST_TX_GPIO,
|
||||
.io_cfg.rx = TEST_TX_GPIO, // Using same pin for test without transceiver
|
||||
.io_cfg.quanta_clk_out = GPIO_NUM_NC,
|
||||
.io_cfg.bus_off_indicator = GPIO_NUM_NC,
|
||||
.bit_timing.bitrate = 1000000,
|
||||
.data_timing.bitrate = 4000000,
|
||||
.data_timing.ssp_permill = 700, // ssp 70.0%
|
||||
|
||||
@@ -31,6 +31,8 @@ TEST_CASE("twai_listen_only", "[twai_net]")
|
||||
twai_onchip_node_config_t node_config = {
|
||||
.io_cfg.tx = TEST_TX_GPIO,
|
||||
.io_cfg.rx = TEST_RX_GPIO,
|
||||
.io_cfg.quanta_clk_out = GPIO_NUM_NC,
|
||||
.io_cfg.bus_off_indicator = GPIO_NUM_NC,
|
||||
.bit_timing.bitrate = 250000,
|
||||
.tx_queue_depth = 3,
|
||||
.flags.enable_listen_only = true,
|
||||
@@ -72,6 +74,8 @@ TEST_CASE("twai_remote_request", "[twai_net]")
|
||||
twai_onchip_node_config_t node_config = {
|
||||
.io_cfg.tx = TEST_TX_GPIO,
|
||||
.io_cfg.rx = TEST_RX_GPIO,
|
||||
.io_cfg.quanta_clk_out = GPIO_NUM_NC,
|
||||
.io_cfg.bus_off_indicator = GPIO_NUM_NC,
|
||||
.bit_timing.bitrate = 250000,
|
||||
.fail_retry_cnt = -1, // retry forever if send remote frame failed
|
||||
.tx_queue_depth = 3,
|
||||
|
||||
@@ -26,13 +26,13 @@ def fixture_create_socket_can() -> Bus:
|
||||
start_command = 'sudo ip link set can0 up type can bitrate 250000'
|
||||
stop_command = 'sudo ip link set can0 down'
|
||||
try:
|
||||
subprocess.run(start_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
subprocess.run(start_command, shell=True, capture_output=True, text=True)
|
||||
except Exception as e:
|
||||
print(f'Open bus Error: {e}')
|
||||
bus = Bus(interface='socketcan', channel='can0', bitrate=250000)
|
||||
yield bus # test invoked here
|
||||
bus.shutdown()
|
||||
subprocess.run(stop_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
||||
subprocess.run(stop_command, shell=True, capture_output=True, text=True)
|
||||
|
||||
|
||||
@pytest.mark.twai_std
|
||||
|
||||
Reference in New Issue
Block a user