mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
Merge branch 'feat/support_twai_on_h21' into 'master'
feat(twai): support twai on esp32h21 Closes IDF-11574 and IDF-11575 See merge request espressif/esp-idf!40888
This commit is contained in:
@@ -115,6 +115,10 @@ config SOC_REG_I2C_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TWAI_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_RMT_SUPPORTED
|
||||
bool
|
||||
default y
|
||||
@@ -711,6 +715,34 @@ config SOC_MWDT_SUPPORT_SLEEP_RETENTION
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TWAI_CONTROLLER_NUM
|
||||
int
|
||||
default 1
|
||||
|
||||
config SOC_TWAI_MASK_FILTER_NUM
|
||||
int
|
||||
default 1
|
||||
|
||||
config SOC_TWAI_CLK_SUPPORT_XTAL
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TWAI_BRP_MIN
|
||||
int
|
||||
default 2
|
||||
|
||||
config SOC_TWAI_BRP_MAX
|
||||
int
|
||||
default 32768
|
||||
|
||||
config SOC_TWAI_SUPPORTS_RX_STATUS
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_TWAI_SUPPORT_SLEEP_RETENTION
|
||||
bool
|
||||
default y
|
||||
|
||||
config SOC_EFUSE_DIS_PAD_JTAG
|
||||
bool
|
||||
default y
|
||||
|
||||
@@ -290,6 +290,21 @@ typedef enum {
|
||||
SPI_CLK_SRC_RC_FAST = SOC_MOD_CLK_RC_FAST, /*!< Select RC_FAST as SPI source clock */
|
||||
} soc_periph_spi_clk_src_t;
|
||||
|
||||
//////////////////////////////////////////////////TWAI/////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* @brief Array initializer for all supported clock sources of TWAI
|
||||
*/
|
||||
#define SOC_TWAI_CLKS {SOC_MOD_CLK_XTAL}
|
||||
|
||||
/**
|
||||
* @brief TWAI clock source
|
||||
*/
|
||||
typedef enum {
|
||||
TWAI_CLK_SRC_XTAL = SOC_MOD_CLK_XTAL, /*!< Select XTAL as the source clock */
|
||||
TWAI_CLK_SRC_DEFAULT = SOC_MOD_CLK_XTAL, /*!< Select XTAL as the default clock choice */
|
||||
} soc_periph_twai_clk_src_t;
|
||||
|
||||
//////////////////////////////////////////////////MWDT/////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
// #define SOC_PHY_SUPPORTED 1
|
||||
// #define SOC_PCNT_SUPPORTED 1 //TODO: [ESP32H21] IDF-11566
|
||||
// #define SOC_MCPWM_SUPPORTED 1 //TODO: [ESP32H21] IDF-11601
|
||||
// #define SOC_TWAI_SUPPORTED 1 //TODO: [ESP32H21] IDF-11574
|
||||
#define SOC_TWAI_SUPPORTED 1
|
||||
// #define SOC_ETM_SUPPORTED 1 //TODO: [ESP32H21] IDF-11576
|
||||
// #define SOC_PARLIO_SUPPORTED 1 //TODO: [ESP32H21] IDF-11570, IDF-11572
|
||||
#define SOC_RMT_SUPPORTED 1
|
||||
@@ -446,11 +446,13 @@
|
||||
#define SOC_MWDT_SUPPORT_SLEEP_RETENTION (1)
|
||||
|
||||
/*-------------------------- TWAI CAPS ---------------------------------------*/
|
||||
// #define SOC_TWAI_CONTROLLER_NUM 1UL
|
||||
// #define SOC_TWAI_CLK_SUPPORT_XTAL 1
|
||||
// #define SOC_TWAI_BRP_MIN 2
|
||||
// #define SOC_TWAI_BRP_MAX 32768
|
||||
// #define SOC_TWAI_SUPPORTS_RX_STATUS 1
|
||||
#define SOC_TWAI_CONTROLLER_NUM 1U
|
||||
#define SOC_TWAI_MASK_FILTER_NUM 1U
|
||||
#define SOC_TWAI_CLK_SUPPORT_XTAL 1
|
||||
#define SOC_TWAI_BRP_MIN 2
|
||||
#define SOC_TWAI_BRP_MAX 32768
|
||||
#define SOC_TWAI_SUPPORTS_RX_STATUS 1
|
||||
#define SOC_TWAI_SUPPORT_SLEEP_RETENTION 1
|
||||
|
||||
/*-------------------------- eFuse CAPS----------------------------*/
|
||||
#define SOC_EFUSE_DIS_PAD_JTAG 1
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -484,215 +484,46 @@ typedef union {
|
||||
uint32_t val;
|
||||
} twai_interrupt_enable_reg_t;
|
||||
|
||||
|
||||
/** Group: Data Registers */
|
||||
/** Type of data_0 register
|
||||
* Data register 0.
|
||||
/** Type of buffer register
|
||||
* TX RX Buffer.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_0 : R/W; bitpos: [7:0]; default: 0;
|
||||
/** byte : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, it is acceptance code register 0 with R/W Permission. In operation
|
||||
* mode, when software initiate write operation, it is tx data register 0 and when
|
||||
* software initiate read operation, it is rx data register 0.
|
||||
*/
|
||||
uint32_t data_0:8;
|
||||
uint32_t byte:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_0_reg_t;
|
||||
} twai_tx_rx_buffer_reg_t;
|
||||
|
||||
/** Type of data_1 register
|
||||
* Data register 1.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_1 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, it is acceptance code register 1 with R/W Permission. In operation
|
||||
* mode, when software initiate write operation, it is tx data register 1 and when
|
||||
* software initiate read operation, it is rx data register 1.
|
||||
*/
|
||||
uint32_t data_1:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_1_reg_t;
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
uint32_t byte: 8; /* ACRx[7:0] Acceptance Code */
|
||||
uint32_t reserved8: 24; /* Internal Reserved */
|
||||
};
|
||||
uint32_t val;
|
||||
} acr[4];
|
||||
union {
|
||||
struct {
|
||||
uint32_t byte: 8; /* AMRx[7:0] Acceptance Mask */
|
||||
uint32_t reserved8: 24; /* Internal Reserved */
|
||||
};
|
||||
uint32_t val;
|
||||
} amr[4];
|
||||
uint32_t reserved_60;
|
||||
uint32_t reserved_64;
|
||||
uint32_t reserved_68;
|
||||
uint32_t reserved_6c;
|
||||
uint32_t reserved_70;
|
||||
} acceptance_filter_reg_t;
|
||||
|
||||
/** Type of data_2 register
|
||||
* Data register 2.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_2 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, it is acceptance code register 2 with R/W Permission. In operation
|
||||
* mode, when software initiate write operation, it is tx data register 2 and when
|
||||
* software initiate read operation, it is rx data register 2.
|
||||
*/
|
||||
uint32_t data_2:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_2_reg_t;
|
||||
|
||||
/** Type of data_3 register
|
||||
* Data register 3.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_3 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, it is acceptance code register 3 with R/W Permission. In operation
|
||||
* mode, when software initiate write operation, it is tx data register 3 and when
|
||||
* software initiate read operation, it is rx data register 3.
|
||||
*/
|
||||
uint32_t data_3:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_3_reg_t;
|
||||
|
||||
/** Type of data_4 register
|
||||
* Data register 4.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_4 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, it is acceptance mask register 0 with R/W Permission. In operation
|
||||
* mode, when software initiate write operation, it is tx data register 4 and when
|
||||
* software initiate read operation, it is rx data register 4.
|
||||
*/
|
||||
uint32_t data_4:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_4_reg_t;
|
||||
|
||||
/** Type of data_5 register
|
||||
* Data register 5.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_5 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, it is acceptance mask register 1 with R/W Permission. In operation
|
||||
* mode, when software initiate write operation, it is tx data register 5 and when
|
||||
* software initiate read operation, it is rx data register 5.
|
||||
*/
|
||||
uint32_t data_5:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_5_reg_t;
|
||||
|
||||
/** Type of data_6 register
|
||||
* Data register 6.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_6 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, it is acceptance mask register 2 with R/W Permission. In operation
|
||||
* mode, when software initiate write operation, it is tx data register 6 and when
|
||||
* software initiate read operation, it is rx data register 6.
|
||||
*/
|
||||
uint32_t data_6:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_6_reg_t;
|
||||
|
||||
/** Type of data_7 register
|
||||
* Data register 7.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_7 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, it is acceptance mask register 3 with R/W Permission. In operation
|
||||
* mode, when software initiate write operation, it is tx data register 7 and when
|
||||
* software initiate read operation, it is rx data register 7.
|
||||
*/
|
||||
uint32_t data_7:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_7_reg_t;
|
||||
|
||||
/** Type of data_8 register
|
||||
* Data register 8.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_8 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, reserved with RO. In operation mode, when software initiate write
|
||||
* operation, it is tx data register 8 and when software initiate read operation, it
|
||||
* is rx data register 8.
|
||||
*/
|
||||
uint32_t data_8:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_8_reg_t;
|
||||
|
||||
/** Type of data_9 register
|
||||
* Data register 9.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_9 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, reserved with RO. In operation mode, when software initiate write
|
||||
* operation, it is tx data register 9 and when software initiate read operation, it
|
||||
* is rx data register 9.
|
||||
*/
|
||||
uint32_t data_9:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_9_reg_t;
|
||||
|
||||
/** Type of data_10 register
|
||||
* Data register 10.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_10 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, reserved with RO. In operation mode, when software initiate write
|
||||
* operation, it is tx data register 10 and when software initiate read operation, it
|
||||
* is rx data register 10.
|
||||
*/
|
||||
uint32_t data_10:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_10_reg_t;
|
||||
|
||||
/** Type of data_11 register
|
||||
* Data register 11.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_11 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, reserved with RO. In operation mode, when software initiate write
|
||||
* operation, it is tx data register 11 and when software initiate read operation, it
|
||||
* is rx data register 11.
|
||||
*/
|
||||
uint32_t data_11:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_11_reg_t;
|
||||
|
||||
/** Type of data_12 register
|
||||
* Data register 12.
|
||||
*/
|
||||
typedef union {
|
||||
struct {
|
||||
/** data_12 : R/W; bitpos: [7:0]; default: 0;
|
||||
* In reset mode, reserved with RO. In operation mode, when software initiate write
|
||||
* operation, it is tx data register 12 and when software initiate read operation, it
|
||||
* is rx data register 12.
|
||||
*/
|
||||
uint32_t data_12:8;
|
||||
uint32_t reserved_8:24;
|
||||
};
|
||||
uint32_t val;
|
||||
} twai_data_12_reg_t;
|
||||
|
||||
|
||||
typedef struct twai_dev_t {
|
||||
@@ -710,19 +541,10 @@ typedef struct twai_dev_t {
|
||||
volatile twai_err_warning_limit_reg_t err_warning_limit;
|
||||
volatile twai_rx_err_cnt_reg_t rx_err_cnt;
|
||||
volatile twai_tx_err_cnt_reg_t tx_err_cnt;
|
||||
volatile twai_data_0_reg_t data_0;
|
||||
volatile twai_data_1_reg_t data_1;
|
||||
volatile twai_data_2_reg_t data_2;
|
||||
volatile twai_data_3_reg_t data_3;
|
||||
volatile twai_data_4_reg_t data_4;
|
||||
volatile twai_data_5_reg_t data_5;
|
||||
volatile twai_data_6_reg_t data_6;
|
||||
volatile twai_data_7_reg_t data_7;
|
||||
volatile twai_data_8_reg_t data_8;
|
||||
volatile twai_data_9_reg_t data_9;
|
||||
volatile twai_data_10_reg_t data_10;
|
||||
volatile twai_data_11_reg_t data_11;
|
||||
volatile twai_data_12_reg_t data_12;
|
||||
volatile union {
|
||||
acceptance_filter_reg_t acceptance_filter;
|
||||
twai_tx_rx_buffer_reg_t tx_rx_buffer[13];
|
||||
};
|
||||
volatile twai_rx_message_counter_reg_t rx_message_counter;
|
||||
uint32_t reserved_078;
|
||||
volatile twai_clock_divider_reg_t clock_divider;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "soc/twai_periph.h"
|
||||
#include "soc/twai_reg.h"
|
||||
#include "soc/gpio_sig_map.h"
|
||||
|
||||
const twai_signal_conn_t twai_periph_signals[SOC_TWAI_CONTROLLER_NUM] = {
|
||||
[0] = {
|
||||
.module_name = "TWAI0",
|
||||
.irq_id = ETS_TWAI0_INTR_SOURCE,
|
||||
.tx_sig = TWAI0_TX_IDX,
|
||||
.rx_sig = TWAI0_RX_IDX,
|
||||
.bus_off_sig = TWAI0_BUS_OFF_ON_IDX,
|
||||
.clk_out_sig = TWAI0_CLKOUT_IDX,
|
||||
.stand_by_sig = TWAI0_STANDBY_IDX,
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* TWAI Registers to be saved during sleep retention
|
||||
* - TWAI_MODE_REG
|
||||
* - TWAI_INTERRUPT_ENABLE_REG
|
||||
* - TWAI_BUS_TIMING_0_REG / TWAI_BUS_TIMING_1_REG
|
||||
* - TWAI_ERR_WARNING_LIMIT_REG
|
||||
* - TWAI_RX_ERR_CNT_REG
|
||||
* - TWAI_TX_ERR_CNT_REG
|
||||
* - TWAI_DATA_x_REG
|
||||
* - TWAI_CLOCK_DIVIDER_REG
|
||||
* - TWAI_SW_STANDBY_CFG_REG
|
||||
* - TWAI_HW_CFG_REG
|
||||
* - TWAI_HW_STANDBY_CNT_REG
|
||||
* - TWAI_IDLE_INTR_CNT_REG
|
||||
* - TWAI_ECO_CFG_REG
|
||||
* - TWAI_TIMESTAMP_PRESCALER_REG
|
||||
* - TWAI_TIMESTAMP_CFG_REG
|
||||
*/
|
||||
#define TWAI_RETENTION_REGS_CNT 28
|
||||
#define TWAI_RETENTION_REGS_BASE(i) DR_REG_TWAI_BASE
|
||||
static const uint32_t twai_regs_map[4] = {0x9fffe0d1, 0xdf, 0x0, 0x0};
|
||||
#define TWAI_SLEEP_RETENTION_ENTRIES(id) { \
|
||||
[0] = { .config = REGDMA_LINK_ADDR_MAP_INIT(REGDMA_TWAI_LINK(0x00), \
|
||||
TWAI_RETENTION_REGS_BASE(id), TWAI_RETENTION_REGS_BASE(id), \
|
||||
TWAI_RETENTION_REGS_CNT, 0, 0, \
|
||||
twai_regs_map[0], twai_regs_map[1], \
|
||||
twai_regs_map[2], twai_regs_map[3]), \
|
||||
.owner = ENTRY(0) | ENTRY(2) }, \
|
||||
}
|
||||
|
||||
static const regdma_entries_config_t twai0_regs_retention[] = TWAI_SLEEP_RETENTION_ENTRIES(0);
|
||||
const twai_reg_retention_info_t twai_reg_retention_info[SOC_TWAI_CONTROLLER_NUM] = {
|
||||
[0] = {
|
||||
.module_id = SLEEP_RETENTION_MODULE_TWAI0,
|
||||
.entry_array = twai0_regs_retention,
|
||||
.array_size = ARRAY_SIZE(twai0_regs_retention)
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user