Skip to content

Commit

Permalink
esp32s2: drivers: serial: add minimal uart driver
Browse files Browse the repository at this point in the history
based on uart rom functions, also enable console driver
on top of this driver, which enables logging

Signed-off-by: Glauber Maroto Ferreira <glauber.ferreira@espressif.com>
  • Loading branch information
Glauber Maroto Ferreira authored and cfriedt committed Aug 9, 2021
1 parent ee3f50f commit 8e865a7
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
/drivers/serial/Kconfig.test @str4t0m
/drivers/serial/serial_test.c @str4t0m
/drivers/serial/*esp32c3* @uLipe
/drivers/serial/*esp32s2* @glaubermaroto
/drivers/disk/ @jfischer-no
/drivers/disk/sdmmc_sdhc.h @JunYangNXP
/drivers/disk/sdmmc_spi.c @JunYangNXP
Expand Down
7 changes: 7 additions & 0 deletions boards/xtensa/esp32s2_saola/esp32s2_saola.dts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@

chosen {
zephyr,sram = &sram0;
zephyr,console = &uart0;
zephyr,shell-uart = &uart0;
};
};

&uart0 {
status = "okay";
current-speed = <115200>;
};
5 changes: 5 additions & 0 deletions boards/xtensa/esp32s2_saola/esp32s2_saola_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ CONFIG_MAIN_STACK_SIZE=2048

CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=240000000

CONFIG_CONSOLE=y
CONFIG_SERIAL=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_ROM_ESP32S2=y

CONFIG_XTENSA_USE_CORE_CRT1=n

CONFIG_GEN_ISR_TABLES=y
Expand Down
1 change: 1 addition & 0 deletions drivers/serial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ zephyr_library_sources_ifdef(CONFIG_UART_CC32XX uart_cc32xx.c)
zephyr_library_sources_ifdef(CONFIG_UART_CMSDK_APB uart_cmsdk_apb.c)
zephyr_library_sources_ifdef(CONFIG_UART_ESP32 uart_esp32.c)
zephyr_library_sources_ifdef(CONFIG_UART_ROM_ESP32C3 uart_rom_esp32c3.c)
zephyr_library_sources_ifdef(CONFIG_UART_ROM_ESP32S2 uart_rom_esp32s2.c)
zephyr_library_sources_ifdef(CONFIG_UART_SIFIVE uart_sifive.c)
zephyr_library_sources_ifdef(CONFIG_UART_GECKO uart_gecko.c)
zephyr_library_sources_ifdef(CONFIG_LEUART_GECKO leuart_gecko.c)
Expand Down
2 changes: 2 additions & 0 deletions drivers/serial/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ source "drivers/serial/Kconfig.esp32"

source "drivers/serial/Kconfig.esp32c3_rom"

source "drivers/serial/Kconfig.esp32s2_rom"

source "drivers/serial/Kconfig.gecko"

source "drivers/serial/Kconfig.leuart_gecko"
Expand Down
10 changes: 10 additions & 0 deletions drivers/serial/Kconfig.esp32s2_rom
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

config UART_ROM_ESP32S2
bool "ESP32S2 ROM UART driver"
default y
select SERIAL_HAS_DRIVER
depends on SOC_ESP32S2
help
Enable the ESP32S2 UART using ROM routines.
57 changes: 57 additions & 0 deletions drivers/serial/uart_rom_esp32s2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT espressif_esp32s2_uart

/* Include esp-idf headers first to avoid redefining BIT() macro */
#include <soc.h>
#include <esp_attr.h>
#include <device.h>
#include <drivers/uart.h>
#include <drivers/clock_control.h>

static int uart_rom_esp32s2_poll_in(const struct device *dev, unsigned char *p_char)
{
ARG_UNUSED(dev);
return (int)esp_rom_uart_rx_one_char(p_char);
}

static IRAM_ATTR void uart_rom_esp32s2_poll_out(const struct device *dev,
unsigned char c)
{
ARG_UNUSED(dev);
esp_rom_uart_tx_one_char(c);
}

static int uart_rom_esp32s2_poll_err_check(const struct device *dev)
{
ARG_UNUSED(dev);
return 0;
}

static int uart_rom_esp32s2_init(const struct device *dev)
{
ARG_UNUSED(dev);
return 0;
}

static const DRAM_ATTR struct uart_driver_api uart_rom_esp32s2_api = {
.poll_in = uart_rom_esp32s2_poll_in,
.poll_out = uart_rom_esp32s2_poll_out,
.err_check = uart_rom_esp32s2_poll_err_check,
};

#define ESP32S2_ROM_UART_INIT(idx) \
DEVICE_DT_DEFINE(DT_NODELABEL(uart##idx), \
&uart_rom_esp32s2_init, \
NULL, \
NULL, \
NULL, \
PRE_KERNEL_1, \
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \
&uart_rom_esp32s2_api); \

DT_INST_FOREACH_STATUS_OKAY(ESP32S2_ROM_UART_INIT)
32 changes: 32 additions & 0 deletions dts/bindings/serial/espressif,esp32s2-uart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
description: ESP32S2 UART

compatible: "espressif,esp32s2-uart"

include: uart-controller.yaml

properties:
reg:
required: true

interrupts:
required: false

tx-pin:
type: int
description: TX pin
required: false

rx-pin:
type: int
description: RX pin
required: false

rts-pin:
type: int
description: RTS pin
required: false

cts-pin:
type: int
description: CTS pin
required: false
7 changes: 7 additions & 0 deletions dts/xtensa/espressif/esp32s2.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
compatible = "mmio-sram";
reg = <0x3ffb0000 0x50000>;
};

uart0: uart@3f400000 {
compatible = "espressif,esp32s2-uart";
reg = <0x3f400000 0x400>;
label = "UART_0";
status = "disabled";
};
};

};

0 comments on commit 8e865a7

Please sign in to comment.