mirror of
https://github.com/apache/nuttx.git
synced 2026-08-11 07:25:13 +00:00
arch/risc-v/espressif: Add TWAI2 support for esp32p4
Enable TWAI2 support for esp32p4 Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
This commit is contained in:
parent
2a7cf05a20
commit
6a2eef788d
2 changed files with 101 additions and 0 deletions
|
|
@ -1645,6 +1645,14 @@ config ESPRESSIF_TWAI1
|
|||
select ARCH_HAVE_CAN_ERRORS
|
||||
select CAN
|
||||
|
||||
config ESPRESSIF_TWAI2
|
||||
bool "TWAI2 (CAN)"
|
||||
default n
|
||||
depends on ARCH_CHIP_ESP32P4
|
||||
select ESPRESSIF_TWAI
|
||||
select ARCH_HAVE_CAN_ERRORS
|
||||
select CAN
|
||||
|
||||
config ESPRESSIF_USBSERIAL
|
||||
bool "USB-Serial-JTAG Driver"
|
||||
default n
|
||||
|
|
@ -3438,6 +3446,48 @@ config ESPRESSIF_TWAI1_SAM
|
|||
|
||||
endif # ESPRESSIF_TWAI1
|
||||
|
||||
if ESPRESSIF_TWAI2
|
||||
|
||||
config ESPRESSIF_TWAI2_TXPIN
|
||||
int "TWAI2 TX Pin"
|
||||
default 6
|
||||
|
||||
config ESPRESSIF_TWAI2_RXPIN
|
||||
int "TWAI2 RX Pin"
|
||||
default 7
|
||||
|
||||
choice ESPRESSIF_TWAI2_TIMING
|
||||
prompt "TWAI2 Timing config"
|
||||
default TWAI2_TIMING_100KBITS
|
||||
---help---
|
||||
These options control timing of TWAI2.
|
||||
|
||||
config TWAI2_TIMING_100KBITS
|
||||
bool "100 KBits"
|
||||
|
||||
config TWAI2_TIMING_125KBITS
|
||||
bool "125 KBits"
|
||||
|
||||
config TWAI2_TIMING_250KBITS
|
||||
bool "250 KBits"
|
||||
|
||||
config TWAI2_TIMING_500KBITS
|
||||
bool "500 KBits"
|
||||
|
||||
config TWAI2_TIMING_800KBITS
|
||||
bool "800 KBits"
|
||||
|
||||
endchoice # ESPRESSIF_TWAI2_TIMING
|
||||
|
||||
config ESPRESSIF_TWAI2_SAM
|
||||
bool "TWAI2 sampling"
|
||||
default n
|
||||
---help---
|
||||
The bus is sampled 3 times (recommended for low to medium speed buses
|
||||
to spikes on the bus-line).
|
||||
|
||||
endif # ESPRESSIF_TWAI2
|
||||
|
||||
config ESPRESSIF_TWAI_TEST_MODE
|
||||
bool "TWAI character driver loopback test mode (for testing only)"
|
||||
default n
|
||||
|
|
|
|||
|
|
@ -99,6 +99,20 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_TWAI2
|
||||
# ifdef CONFIG_TWAI2_TIMING_100KBITS
|
||||
# define TWAI2_TIMING_CONFIG TWAI_TIMING_CONFIG_100KBITS()
|
||||
# elif CONFIG_TWAI2_TIMING_125KBITS
|
||||
# define TWAI2_TIMING_CONFIG TWAI_TIMING_CONFIG_125KBITS()
|
||||
# elif CONFIG_TWAI2_TIMING_250KBITS
|
||||
# define TWAI2_TIMING_CONFIG TWAI_TIMING_CONFIG_250KBITS()
|
||||
# elif CONFIG_TWAI2_TIMING_500KBITS
|
||||
# define TWAI2_TIMING_CONFIG TWAI_TIMING_CONFIG_500KBITS()
|
||||
# else
|
||||
# define TWAI2_TIMING_CONFIG TWAI_TIMING_CONFIG_800KBITS()
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ARCH_CHIP_ESP32C3)
|
||||
# define INT_ENA_REG(hw) hw->interrupt_enable_reg.val
|
||||
#elif defined(CONFIG_ARCH_CHIP_ESP32P4)
|
||||
|
|
@ -226,6 +240,24 @@ static struct can_dev_s g_twai1dev =
|
|||
};
|
||||
#endif /* CONFIG_ESPRESSIF_TWAI1 */
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_TWAI2
|
||||
static struct esp_twai_dev_s g_twai2priv =
|
||||
{
|
||||
.port = 2,
|
||||
.cpuint = -ENOMEM,
|
||||
.t_config = TWAI2_TIMING_CONFIG,
|
||||
#ifdef CONFIG_PM
|
||||
.pm_lock = NULL,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct can_dev_s g_twai2dev =
|
||||
{
|
||||
.cd_ops = &g_twaiops,
|
||||
.cd_priv = &g_twai2priv,
|
||||
};
|
||||
#endif /* CONFIG_ESPRESSIF_TWAI2 */
|
||||
|
||||
static const twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
|
||||
|
||||
/****************************************************************************
|
||||
|
|
@ -865,6 +897,25 @@ struct can_dev_s *esp_twaiinitialize(int port)
|
|||
else
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_TWAI2
|
||||
if (port == 2)
|
||||
{
|
||||
int tx_sig = twai_periph_signals[2].tx_sig;
|
||||
int rx_sig = twai_periph_signals[2].rx_sig;
|
||||
|
||||
/* Configure CAN GPIO pins */
|
||||
|
||||
esp_gpio_matrix_out(CONFIG_ESPRESSIF_TWAI2_TXPIN, tx_sig, 0, 0);
|
||||
esp_configgpio(CONFIG_ESPRESSIF_TWAI2_TXPIN, TX_PIN_ATTR);
|
||||
|
||||
esp_gpio_matrix_in(CONFIG_ESPRESSIF_TWAI2_RXPIN, rx_sig, 0);
|
||||
esp_configgpio(CONFIG_ESPRESSIF_TWAI2_RXPIN, RX_PIN_ATTR);
|
||||
|
||||
dev = &g_twai2dev;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
{
|
||||
canerr("ERROR: Unsupported port: %d\n", port);
|
||||
leave_critical_section(flags);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue