mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 06:42:32 +08:00
xtensa/esp32s3: Add support to TWAI/CANBus controller
This commit is contained in:
committed by
Xiang Xiao
parent
83ba72e4b4
commit
a26996fb3b
@@ -412,6 +412,24 @@ To test it, just run the following::
|
|||||||
|
|
||||||
Where x in the timer instance.
|
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
|
usbnsh
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ ADC No
|
|||||||
AES No
|
AES No
|
||||||
Bluetooth No
|
Bluetooth No
|
||||||
CAMERA No
|
CAMERA No
|
||||||
CAN/TWAI No
|
CAN/TWAI Yes
|
||||||
DMA Yes
|
DMA Yes
|
||||||
eFuse No
|
eFuse No
|
||||||
GPIO Yes
|
GPIO Yes
|
||||||
|
|||||||
@@ -99,7 +99,7 @@
|
|||||||
#define ESP32S3_PERIPH_PWM1 32
|
#define ESP32S3_PERIPH_PWM1 32
|
||||||
#define ESP32S3_PERIPH_LEDC 35
|
#define ESP32S3_PERIPH_LEDC 35
|
||||||
#define ESP32S3_PERIPH_EFUSE 36
|
#define ESP32S3_PERIPH_EFUSE 36
|
||||||
#define ESP32S3_PERIPH_CAN 37
|
#define ESP32S3_PERIPH_TWAI 37
|
||||||
#define ESP32S3_PERIPH_USB 38
|
#define ESP32S3_PERIPH_USB 38
|
||||||
#define ESP32S3_PERIPH_RTC_CORE 39
|
#define ESP32S3_PERIPH_RTC_CORE 39
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@
|
|||||||
#define ESP32S3_IRQ_PWM1 (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_PWM1)
|
#define ESP32S3_IRQ_PWM1 (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_PWM1)
|
||||||
#define ESP32S3_IRQ_LEDC (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_LEDC)
|
#define ESP32S3_IRQ_LEDC (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_LEDC)
|
||||||
#define ESP32S3_IRQ_EFUSE (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_EFUSE)
|
#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_USB (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_USB)
|
||||||
#define ESP32S3_IRQ_RTC_CORE (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_RTC_CORE)
|
#define ESP32S3_IRQ_RTC_CORE (XTENSA_IRQ_FIRSTPERIPH + ESP32S3_PERIPH_RTC_CORE)
|
||||||
|
|
||||||
|
|||||||
@@ -624,6 +624,11 @@ config ESP32S3_I2C1
|
|||||||
select ESP32S3_I2C
|
select ESP32S3_I2C
|
||||||
select I2C
|
select I2C
|
||||||
|
|
||||||
|
config ESP32S3_TWAI
|
||||||
|
bool "TWAI (CAN)"
|
||||||
|
default n
|
||||||
|
select CAN
|
||||||
|
|
||||||
config ESP32S3_LEDC
|
config ESP32S3_LEDC
|
||||||
bool "LEDC (PWM)"
|
bool "LEDC (PWM)"
|
||||||
default n
|
default n
|
||||||
@@ -1093,6 +1098,57 @@ config ESP32S3_I2CTIMEOMS
|
|||||||
|
|
||||||
endmenu # I2C Configuration
|
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"
|
menu "Wi-Fi Configuration"
|
||||||
depends on ESP32S3_WIFI
|
depends on ESP32S3_WIFI
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ ifeq ($(CONFIG_ESP32S3_RNG),y)
|
|||||||
CHIP_CSRCS += esp32s3_rng.c
|
CHIP_CSRCS += esp32s3_rng.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ESP32S3_TWAI),y)
|
||||||
|
CHIP_CSRCS += esp32s3_twai.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_ESP32S3_LEDC),y)
|
ifeq ($(CONFIG_ESP32S3_LEDC),y)
|
||||||
CHIP_CSRCS += esp32s3_ledc.c
|
CHIP_CSRCS += esp32s3_ledc.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/xtensa/src/esp32s3/esp32s3_twai.h
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_TWAI_H
|
||||||
|
#define __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_TWAI_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/can/can.h>
|
||||||
|
#include "hardware/esp32s3_twai.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ASSEMBLY__
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32s3_twaiinitialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the selected CAN port
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* Port number (for hardware that has multiple TWAI interfaces)
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Valid TWAI device structure reference on success; a NULL on failure
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_CAN) && defined(CONFIG_ESP32S3_TWAI)
|
||||||
|
struct can_dev_s *esp32s3_twaiinitialize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* __ASSEMBLY__ */
|
||||||
|
|
||||||
|
#endif /* __ARCH_XTENSA_SRC_ESP32S3_ESP32S3_TWAI_H */
|
||||||
@@ -300,7 +300,7 @@
|
|||||||
#define SYSTEM_PWM1_CLK_EN_S 20
|
#define SYSTEM_PWM1_CLK_EN_S 20
|
||||||
|
|
||||||
/* SYSTEM_TWAI_CLK_EN : R/W; bitpos: [19]; default: 0;
|
/* SYSTEM_TWAI_CLK_EN : R/W; bitpos: [19]; default: 0;
|
||||||
* Set 1 to enable CAN clock
|
* Set 1 to enable TWAI clock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SYSTEM_TWAI_CLK_EN (BIT(19))
|
#define SYSTEM_TWAI_CLK_EN (BIT(19))
|
||||||
@@ -699,7 +699,7 @@
|
|||||||
#define SYSTEM_PWM1_RST_S 20
|
#define SYSTEM_PWM1_RST_S 20
|
||||||
|
|
||||||
/* SYSTEM_TWAI_RST : R/W; bitpos: [19]; default: 0;
|
/* SYSTEM_TWAI_RST : R/W; bitpos: [19]; default: 0;
|
||||||
* Set 1 to let CAN reset
|
* Set 1 to let TWAI reset
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SYSTEM_TWAI_RST (BIT(19))
|
#define SYSTEM_TWAI_RST (BIT(19))
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,49 @@
|
|||||||
|
#
|
||||||
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||||
|
#
|
||||||
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||||
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
|
# modifications.
|
||||||
|
#
|
||||||
|
# CONFIG_ARCH_LEDS is not set
|
||||||
|
# CONFIG_NSH_ARGCAT is not set
|
||||||
|
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||||
|
CONFIG_ARCH="xtensa"
|
||||||
|
CONFIG_ARCH_BOARD="esp32s3-devkit"
|
||||||
|
CONFIG_ARCH_BOARD_COMMON=y
|
||||||
|
CONFIG_ARCH_BOARD_ESP32S3_DEVKIT=y
|
||||||
|
CONFIG_ARCH_CHIP="esp32s3"
|
||||||
|
CONFIG_ARCH_CHIP_ESP32S3=y
|
||||||
|
CONFIG_ARCH_CHIP_ESP32S3WROOM1=y
|
||||||
|
CONFIG_ARCH_INTERRUPTSTACK=2048
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_ARCH_XTENSA=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_DEBUG_FULLOPT=y
|
||||||
|
CONFIG_DEBUG_SYMBOLS=y
|
||||||
|
CONFIG_ESP32S3_TWAI=y
|
||||||
|
CONFIG_ESP32S3_UART0=y
|
||||||
|
CONFIG_EXAMPLES_CAN=y
|
||||||
|
CONFIG_FS_PROCFS=y
|
||||||
|
CONFIG_HAVE_CXX=y
|
||||||
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||||
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_LINELEN=64
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
|
CONFIG_RAM_SIZE=114688
|
||||||
|
CONFIG_RAM_START=0x20000000
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_START_DAY=6
|
||||||
|
CONFIG_START_MONTH=12
|
||||||
|
CONFIG_START_YEAR=2011
|
||||||
|
CONFIG_SYSLOG_BUFFER=y
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||||
@@ -41,6 +41,10 @@ ifeq ($(CONFIG_ESP32S3_SPI),y)
|
|||||||
CSRCS += esp32s3_board_spi.c
|
CSRCS += esp32s3_board_spi.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ESP32S3_TWAI),y)
|
||||||
|
CSRCS += esp32s3_twai.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_PWM),y)
|
ifeq ($(CONFIG_PWM),y)
|
||||||
CSRCS += esp32s3_ledc.c
|
CSRCS += esp32s3_ledc.c
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -190,5 +190,9 @@ int esp32s3_djoy_initialize(void);
|
|||||||
int esp32s3_pwm_setup(void);
|
int esp32s3_pwm_setup(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32S3_TWAI
|
||||||
|
int esp32s3_twai_setup(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
#endif /* __BOARDS_XTENSA_ESP32S3_ESP32S3_DEVKIT_SRC_ESP32S3_DEVKIT_H */
|
#endif /* __BOARDS_XTENSA_ESP32S3_ESP32S3_DEVKIT_SRC_ESP32S3_DEVKIT_H */
|
||||||
|
|||||||
@@ -205,6 +205,17 @@ int esp32s3_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32S3_TWAI
|
||||||
|
|
||||||
|
/* Initialize TWAI and register the TWAI driver. */
|
||||||
|
|
||||||
|
ret = esp32s3_twai_setup();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: esp32s3_twai_setup failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SENSORS_BMP180
|
#ifdef CONFIG_SENSORS_BMP180
|
||||||
/* Try to register BMP180 device in I2C0 */
|
/* Try to register BMP180 device in I2C0 */
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_twai.c
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/can/can.h>
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
#include "chip.h"
|
||||||
|
|
||||||
|
#include "esp32s3_twai.h"
|
||||||
|
#include "esp32s3-devkit.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_CAN
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Configuration ************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32s3_twai_setup
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize TWAI and register the TWAI device
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32s3_twai_setup(void)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_ESP32S3_TWAI
|
||||||
|
struct can_dev_s *twai;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Call esp32s3_twaiinitialize() to get an instance of the TWAI
|
||||||
|
* interface
|
||||||
|
* */
|
||||||
|
|
||||||
|
twai = esp32s3_twaiinitialize();
|
||||||
|
if (twai == NULL)
|
||||||
|
{
|
||||||
|
canerr("ERROR: Failed to get TWAI interface\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Register the TWAI driver at "/dev/can0" */
|
||||||
|
|
||||||
|
ret = can_register("/dev/can0", twai);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
canerr("ERROR: TWAI1 register failed: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
#else
|
||||||
|
return -ENODEV;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_CAN */
|
||||||
Reference in New Issue
Block a user