Skip to content

Commit

Permalink
xtensa/esp32s3: Add support to TWAI/CANBus controller
Browse files Browse the repository at this point in the history
  • Loading branch information
eren-terzioglu committed Sep 7, 2023
1 parent ba73272 commit b0c630e
Show file tree
Hide file tree
Showing 14 changed files with 2,373 additions and 5 deletions.
Expand Up @@ -412,6 +412,24 @@ To test it, just run the following::

Where x in the timer instance.

twai
----

This configuration enables the support for the TWAI (Two-Wire Automotive Interface) driver.
You can test it by connecting TWAI RX and TWAI TX pins which are GPIO0 and GPIO2 by default
to a external transceiver or connecting TWAI RX to TWAI TX pin by enabling
the ``Device Drivers -> CAN Driver Support -> CAN loopback mode`` option and running the ``can`` example::

nsh> can
nmsgs: 0
min ID: 1 max ID: 2047
Bit timing:
Baud: 1000000
TSEG1: 15
TSEG2: 4
SJW: 3
ID: 1 DLC: 1

usbnsh
------

Expand Down
2 changes: 1 addition & 1 deletion Documentation/platforms/xtensa/esp32s3/index.rst
Expand Up @@ -93,7 +93,7 @@ ADC No
AES No
Bluetooth No
CAMERA No
CAN/TWAI No
CAN/TWAI Yes
DMA Yes
eFuse No
GPIO Yes
Expand Down
4 changes: 2 additions & 2 deletions arch/xtensa/include/esp32s3/irq.h
Expand Up @@ -99,7 +99,7 @@
#define ESP32S3_PERIPH_PWM1 32
#define ESP32S3_PERIPH_LEDC 35
#define ESP32S3_PERIPH_EFUSE 36
#define ESP32S3_PERIPH_CAN 37
#define ESP32S3_PERIPH_TWAI 37
#define ESP32S3_PERIPH_USB 38
#define ESP32S3_PERIPH_RTC_CORE 39

Expand Down Expand Up @@ -239,7 +239,7 @@
#define ESP32S3_IRQ_PWM1 (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_PWM1)
#define ESP32S3_IRQ_LEDC (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_LEDC)
#define ESP32S3_IRQ_EFUSE (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_EFUSE)
#define ESP32S3_IRQ_CAN (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_CAN)
#define ESP32S3_IRQ_TWAI (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_TWAI)
#define ESP32S3_IRQ_USB (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_USB)
#define ESP32S3_IRQ_RTC_CORE (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_RTC_CORE)

Expand Down
56 changes: 56 additions & 0 deletions arch/xtensa/src/esp32s3/Kconfig
Expand Up @@ -624,6 +624,11 @@ config ESP32S3_I2C1
select ESP32S3_I2C
select I2C

config ESP32S3_TWAI
bool "TWAI (CAN)"
default n
select CAN

config ESP32S3_LEDC
bool "LEDC (PWM)"
default n
Expand Down Expand Up @@ -1093,6 +1098,57 @@ config ESP32S3_I2CTIMEOMS

endmenu # I2C Configuration

menu "TWAI driver options"
depends on ESP32S3_TWAI

if ESP32S3_TWAI

config ESP32S3_TWAI_TXPIN
int "TWAI TX Pin"
default 0

config ESP32S3_TWAI_RXPIN
int "TWAI RX Pin"
default 2

config ESP32S3_TWAI_BITRATE
int "TWAI bitrate"
default 1000000
---help---
TWAI bit rate.

config ESP32S3_TWAI_SAMPLEP
int "TWAI sample point"
default 80
---help---
TWAI sample point location as a percent value.

config ESP32S3_TWAI_SJW
int "TWAI synchronization jump width"
default 3
---help---
SJW limits the number of Time Quanta corrections during bit
Resynchronization.

config ESP32S3_TWAI_SAM
bool "TWAI sampling"
default n
---help---
The bus is sampled 3 times (recommended for low to medium speed buses
to spikes on the bus-line).

endif # ESP32S3_TWAI

config ESP32S3_TWAI_REGDEBUG
bool "TWAI register level debug"
depends on DEBUG_CAN_INFO
default n
---help---
Output detailed register-level TWAI debug information. Requires also
CONFIG_DEBUG_CAN_INFO.

endmenu #ESP32S3_TWAI

menu "Wi-Fi Configuration"
depends on ESP32S3_WIFI

Expand Down
4 changes: 4 additions & 0 deletions arch/xtensa/src/esp32s3/Make.defs
Expand Up @@ -57,6 +57,10 @@ ifeq ($(CONFIG_ESP32S3_RNG),y)
CHIP_CSRCS += esp32s3_rng.c
endif

ifeq ($(CONFIG_ESP32S3_TWAI),y)
CHIP_CSRCS += esp32s3_twai.c
endif

ifeq ($(CONFIG_ESP32S3_LEDC),y)
CHIP_CSRCS += esp32s3_ledc.c
endif
Expand Down

0 comments on commit b0c630e

Please sign in to comment.