From 9b014138bf8f057b79a60bf661e66edc835516ae Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Fri, 26 Mar 2021 20:56:54 +0800 Subject: [PATCH] Update TWAI driver docs and registers for esp32c3 This commit updates the documentation and register struct of the TWAI driver for the ESP32-C3. Note that the register fields for ESP32-S3 have also been updated. --- components/soc/esp32c3/include/soc/soc_caps.h | 2 +- components/soc/esp32c3/include/soc/twai_struct.h | 3 ++- components/soc/esp32s3/include/soc/twai_caps.h | 2 +- components/soc/esp32s3/include/soc/twai_struct.h | 3 ++- docs/en/api-reference/peripherals/twai.rst | 8 +++++++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/components/soc/esp32c3/include/soc/soc_caps.h b/components/soc/esp32c3/include/soc/soc_caps.h index a402cacd90..30f339318b 100644 --- a/components/soc/esp32c3/include/soc/soc_caps.h +++ b/components/soc/esp32c3/include/soc/soc_caps.h @@ -217,7 +217,7 @@ /*-------------------------- TWAI CAPS ---------------------------------------*/ #define SOC_TWAI_BRP_MIN 2 -#define SOC_TWAI_BRP_MAX 32768 +#define SOC_TWAI_BRP_MAX 16384 #define SOC_TWAI_SUPPORTS_RX_STATUS 1 /*-------------------------- UART CAPS ---------------------------------------*/ diff --git a/components/soc/esp32c3/include/soc/twai_struct.h b/components/soc/esp32c3/include/soc/twai_struct.h index 30d419376c..64cb80e5ed 100644 --- a/components/soc/esp32c3/include/soc/twai_struct.h +++ b/components/soc/esp32c3/include/soc/twai_struct.h @@ -94,7 +94,8 @@ typedef volatile struct twai_dev_s { uint32_t reserved_05; /* Address 5 */ union { struct { - uint32_t brp: 14; /* BTR0[13:0] Baud Rate Prescaler */ + uint32_t brp: 13; /* BTR0[12:0] Baud Rate Prescaler */ + uint32_t reserved1: 1; /* Internal Reserved */ uint32_t sjw: 2; /* BTR0[15:14] Synchronization Jump Width*/ uint32_t reserved16: 16; /* Internal Reserved */ }; diff --git a/components/soc/esp32s3/include/soc/twai_caps.h b/components/soc/esp32s3/include/soc/twai_caps.h index 56bea014da..c9c83861b4 100644 --- a/components/soc/esp32s3/include/soc/twai_caps.h +++ b/components/soc/esp32s3/include/soc/twai_caps.h @@ -19,7 +19,7 @@ extern "C" { #endif #define SOC_TWAI_BRP_MIN 2 -#define SOC_TWAI_BRP_MAX 32768 +#define SOC_TWAI_BRP_MAX 16384 #define SOC_TWAI_SUPPORTS_RX_STATUS 1 diff --git a/components/soc/esp32s3/include/soc/twai_struct.h b/components/soc/esp32s3/include/soc/twai_struct.h index 58bdc6d1ab..6fe4864408 100644 --- a/components/soc/esp32s3/include/soc/twai_struct.h +++ b/components/soc/esp32s3/include/soc/twai_struct.h @@ -94,7 +94,8 @@ typedef volatile struct twai_dev_s { uint32_t reserved_05; /* Address 5 */ union { struct { - uint32_t brp: 14; /* BTR0[13:0] Baud Rate Prescaler */ + uint32_t brp: 13; /* BTR0[12:0] Baud Rate Prescaler */ + uint32_t reserved1: 1; /* Internal Reserved */ uint32_t sjw: 2; /* BTR0[15:14] Synchronization Jump Width*/ uint32_t reserved16: 16; /* Internal Reserved */ }; diff --git a/docs/en/api-reference/peripherals/twai.rst b/docs/en/api-reference/peripherals/twai.rst index 80091481c5..7f314f1632 100644 --- a/docs/en/api-reference/peripherals/twai.rst +++ b/docs/en/api-reference/peripherals/twai.rst @@ -165,7 +165,7 @@ The operating bit rate of the TWAI driver is configured using the :cpp:type:`twa 2. **Timing Segment 1** consists of 1 to 16 time quanta before sample point 3. **Timing Segment 2** consists of 1 to 8 time quanta after sample point -{IDF_TARGET_MAX_BRP:default="128", esp32="128", esp32s2="32768"} +{IDF_TARGET_MAX_BRP:default="128", esp32="128", esp32s2="32768", esp32c3="16384"} The **Baudrate Prescaler** is used to determine the period of each time quanta by dividing the TWAI controller's source clock (80 MHz APB clock). On the {IDF_TARGET_NAME}, the ``brp`` can be **any even number from 2 to {IDF_TARGET_MAX_BRP}**. @@ -202,6 +202,12 @@ Bit timing **macro initializers** are also available for commonly used bit rates :esp32s2: - ``TWAI_TIMING_CONFIG_10KBITS()`` :esp32s2: - ``TWAI_TIMING_CONFIG_5KBITS()`` :esp32s2: - ``TWAI_TIMING_CONFIG_1KBITS()`` + :esp32c3: - ``TWAI_TIMING_CONFIG_20KBITS()`` + :esp32c3: - ``TWAI_TIMING_CONFIG_16KBITS()`` + :esp32c3: - ``TWAI_TIMING_CONFIG_12_5KBITS()`` + :esp32c3: - ``TWAI_TIMING_CONFIG_10KBITS()`` + :esp32c3: - ``TWAI_TIMING_CONFIG_5KBITS()`` + :esp32c3: - ``TWAI_TIMING_CONFIG_1KBITS()`` .. only:: esp32