xtensa/esp32s3: Enable UART pins to use IOMUX and bypass GPIO matrix

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
Gustavo Henrique Nihei 2022-03-18 09:55:06 -03:00 committed by Petro Karashchenko
parent 77944ceb42
commit f21a9f9578
2 changed files with 150 additions and 15 deletions

View File

@ -40,6 +40,7 @@
#include "chip.h"
#include "xtensa.h"
#include "hardware/esp32s3_pinmap.h"
#include "hardware/esp32s3_system.h"
#include "hardware/esp32s3_uart.h"
#include "hardware/esp32s3_soc.h"
@ -50,6 +51,10 @@
#include "esp32s3_lowputc.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
@ -139,6 +144,59 @@ struct esp32s3_uart_s g_uart1_config =
#endif /* CONFIG_ESP32S3_UART1 */
#endif /* HAVE_UART_DEVICE */
/****************************************************************************
* Name: uart_is_iomux
*
* Description:
* Check if the selected UART pins can use IOMUX directly. Otherwise, UART
* signals will be routed via GPIO Matrix.
*
* Input Parameters:
* priv - Pointer to the private driver struct.
*
* Returned Value:
* True if can use IOMUX or false if can't.
*
****************************************************************************/
static inline bool uart_is_iomux(const struct esp32s3_uart_s *priv)
{
bool mapped = false;
if (priv->id == 0)
{
if (priv->txpin == UART0_IOMUX_TXPIN
&& priv->rxpin == UART0_IOMUX_RXPIN
#ifdef CONFIG_UART0_IFLOWCONTROL
&& priv->rtspin == UART0_IOMUX_RTSPIN
#endif
#ifdef CONFIG_UART0_OFLOWCONTROL
&& priv->ctspin == UART0_IOMUX_CTSPIN
#endif
)
{
mapped = true;
}
}
else if (priv->id == 1)
{
if (priv->txpin == UART1_IOMUX_TXPIN
&& priv->rxpin == UART1_IOMUX_RXPIN
#ifdef CONFIG_UART1_IFLOWCONTROL
&& priv->rtspin == UART1_IOMUX_RTSPIN
#endif
#ifdef CONFIG_UART1_OFLOWCONTROL
&& priv->ctspin == UART1_IOMUX_CTSPIN
#endif
)
{
mapped = true;
}
}
return mapped;
}
/****************************************************************************
* Public Functions
****************************************************************************/
@ -737,28 +795,54 @@ void esp32s3_lowputc_config_pins(const struct esp32s3_uart_s *priv)
{
/* Configure the pins */
esp32s3_gpio_matrix_out(priv->txpin, priv->txsig, 0, 0);
esp32s3_configgpio(priv->txpin, OUTPUT_FUNCTION_2);
if (uart_is_iomux(priv))
{
esp32s3_configgpio(priv->txpin, OUTPUT_FUNCTION_1);
esp32s3_gpio_matrix_out(priv->txpin, SIG_GPIO_OUT_IDX, 0, 0);
esp32s3_configgpio(priv->rxpin, INPUT_FUNCTION_2);
esp32s3_gpio_matrix_in(priv->rxpin, priv->rxsig, 0);
esp32s3_configgpio(priv->rxpin, INPUT_FUNCTION_1);
esp32s3_gpio_matrix_out(priv->rxpin, SIG_GPIO_OUT_IDX, 0, 0);
#ifdef CONFIG_SERIAL_IFLOWCONTROL
if (priv->iflow)
{
esp32s3_configgpio(priv->rtspin, OUTPUT_FUNCTION_1);
esp32s3_gpio_matrix_out(priv->rtspin, priv->rtssig,
0, 0);
}
if (priv->iflow)
{
esp32s3_configgpio(priv->rtspin, OUTPUT_FUNCTION_3);
esp32s3_gpio_matrix_out(priv->rtspin, SIG_GPIO_OUT_IDX, 0, 0);
}
#endif
#ifdef CONFIG_SERIAL_OFLOWCONTROL
if (priv->oflow)
{
esp32s3_configgpio(priv->ctspin, INPUT_FUNCTION_1);
esp32s3_gpio_matrix_in(priv->ctspin, priv->ctssig, 0);
}
if (priv->oflow)
{
esp32s3_configgpio(priv->ctspin, INPUT_FUNCTION_3);
esp32s3_gpio_matrix_out(priv->ctspin, SIG_GPIO_OUT_IDX, 0, 0);
}
#endif
}
else
{
esp32s3_configgpio(priv->txpin, OUTPUT_FUNCTION_2);
esp32s3_gpio_matrix_out(priv->txpin, priv->txsig, 0, 0);
esp32s3_configgpio(priv->rxpin, INPUT_FUNCTION_2);
esp32s3_gpio_matrix_in(priv->rxpin, priv->rxsig, 0);
#ifdef CONFIG_SERIAL_IFLOWCONTROL
if (priv->iflow)
{
esp32s3_configgpio(priv->rtspin, OUTPUT_FUNCTION_2);
esp32s3_gpio_matrix_out(priv->rtspin, priv->rtssig, 0, 0);
}
#endif
#ifdef CONFIG_SERIAL_OFLOWCONTROL
if (priv->oflow)
{
esp32s3_configgpio(priv->ctspin, INPUT_FUNCTION_2);
esp32s3_gpio_matrix_in(priv->ctspin, priv->ctssig, 0);
}
#endif
}
}
/****************************************************************************

View File

@ -0,0 +1,51 @@
/****************************************************************************
* arch/xtensa/src/esp32s3/hardware/esp32s3_pinmap.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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32S3_HARDWARE_ESP32S3_PINMAP_H
#define __ARCH_XTENSA_SRC_ESP32S3_HARDWARE_ESP32S3_PINMAP_H
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/**
* Peripheral' fixed mapped pins by IOMUX, these GPIO pins can have better
* speed performance.
*/
/* UART0 */
#define UART0_IOMUX_TXPIN (43)
#define UART0_IOMUX_RXPIN (44)
#define UART0_IOMUX_RTSPIN (15)
#define UART0_IOMUX_CTSPIN (16)
/* UART1 */
#define UART1_IOMUX_TXPIN (17)
#define UART1_IOMUX_RXPIN (18)
#define UART1_IOMUX_RTSPIN (19)
#define UART1_IOMUX_CTSPIN (20)
#endif /* __ARCH_XTENSA_SRC_ESP32S3_HARDWARE_ESP32S3_PINMAP_H */