Skip to content

Commit

Permalink
soc: esp32s2: add initial soc support files for esp32s2
Browse files Browse the repository at this point in the history
by adding specific soc files for esp32s2 bring-up, such as:
- linker script
- soc initialization code
- initial device tree source files
- esp32s2 saola board support.

Signed-off-by: Glauber Maroto Ferreira <glauber.ferreira@espressif.com>
  • Loading branch information
Glauber Maroto Ferreira authored and cfriedt committed Jul 29, 2021
1 parent bcdaaa0 commit ed63e2a
Show file tree
Hide file tree
Showing 19 changed files with 1,417 additions and 3 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@
/dts/x86/ @jhedberg
/dts/xtensa/xtensa.dtsi @ydamigos
/dts/xtensa/intel/ @dcpleung
/dts/xtensa/espressif/ @glaubermaroto
/dts/sparc/ @martin-aberg
/dts/bindings/ @galak
/dts/bindings/can/ @alexanderwachter
Expand Down
2 changes: 1 addition & 1 deletion Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ endif # BOOTLOADER_MCUBOOT

config BOOTLOADER_ESP_IDF
bool "ESP-IDF bootloader support"
depends on SOC_ESP32
depends on SOC_ESP32 || SOC_ESP32S2
help
This option will trigger the compilation of the ESP-IDF bootloader
inside the build folder.
Expand Down
64 changes: 64 additions & 0 deletions boards/xtensa/esp32s2_saola/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SPDX-License-Identifier: Apache-2.0

if(CONFIG_BOOTLOADER_ESP_IDF)
include(ExternalProject)

## we use hello-world project, but I think any can be used.
set(espidf_components_dir ${ESP_IDF_PATH}/components)
set(espidf_prefix ${CMAKE_BINARY_DIR}/esp-idf)
set(espidf_build_dir ${espidf_prefix}/build)

ExternalProject_Add(
EspIdfBootloader
PREFIX ${espidf_prefix}
SOURCE_DIR ${espidf_components_dir}/bootloader/subproject
BINARY_DIR ${espidf_build_dir}/bootloader
CONFIGURE_COMMAND
${CMAKE_COMMAND} -G${CMAKE_GENERATOR}
-S ${espidf_components_dir}/bootloader/subproject
-B ${espidf_build_dir}/bootloader -DSDKCONFIG=${espidf_build_dir}/sdkconfig
-DIDF_PATH=${ESP_IDF_PATH} -DIDF_TARGET=${CONFIG_SOC}
-DPYTHON_DEPS_CHECKED=1
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER}
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
BUILD_COMMAND
${CMAKE_COMMAND} --build .
INSTALL_COMMAND "" # This particular build system has no install command
)

ExternalProject_Add(
EspPartitionTable
SOURCE_DIR ${espidf_components_dir}/partition_table
BINARY_DIR ${espidf_build_dir}
CONFIGURE_COMMAND ""
BUILD_COMMAND
python ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
--offset 0x1000 --flash-size 4MB ${ESP_IDF_PATH}/components/partition_table/partitions_singleapp.csv ${espidf_build_dir}/partitions_singleapp.bin
INSTALL_COMMAND ""
)

if(CONFIG_BUILD_OUTPUT_BIN)
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND python ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
ARGS --chip esp32s2 elf2image --flash_mode dio --flash_freq 40m
-o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)
endif()

set_property(TARGET bintools PROPERTY disassembly_flag_inline_source)

add_dependencies(app EspIdfBootloader EspPartitionTable)

board_finalize_runner_args(esp32 "--esp-flash-bootloader=${espidf_build_dir}/bootloader/bootloader.bin")

board_finalize_runner_args(esp32 "--esp-flash-partition_table=${espidf_build_dir}/partitions_singleapp.bin")

board_finalize_runner_args(esp32 "--esp-boot-address=0x1000")

board_finalize_runner_args(esp32 "--esp-partition-table-address=0x8000")

board_finalize_runner_args(esp32 "--esp-app-address=0x10000")

endif()
8 changes: 8 additions & 0 deletions boards/xtensa/esp32s2_saola/Kconfig.board
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ESP32S2 saola board configuration

# Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

config BOARD_ESP32S2_SAOLA
bool "ESP32S2 Saola Board"
depends on SOC_ESP32S2
8 changes: 8 additions & 0 deletions boards/xtensa/esp32s2_saola/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ESP32S2 Saola board configuration

# Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

config BOARD
default "esp32s2_saola"
depends on BOARD_ESP32S2_SAOLA
3 changes: 3 additions & 0 deletions boards/xtensa/esp32s2_saola/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0

include(${ZEPHYR_BASE}/boards/common/esp32.board.cmake)
137 changes: 137 additions & 0 deletions boards/xtensa/esp32s2_saola/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
.. _esp32s2_saola:

ESP32-S2
########

Overview
********

ESP32-S2 is a highly integrated, low-power, single-core Wi-Fi Microcontroller SoC, designed to be secure and
cost-effective, with a high performance and a rich set of IO capabilities. [1]_

The features include the following:

- RSA-3072-based secure boot
- AES-XTS-256-based flash encryption
- Protected private key and device secrets from software access
- Cryptographic accelerators for enhanced performance
- Protection against physical fault injection attacks
- Various peripherals:

- 43x programmable GPIOs
- 14x configurable capacitive touch GPIOs
- USB OTG
- LCD interface
- camera interface
- SPI
- I2S
- UART
- ADC
- DAC

System requirements
*******************

Build Environment Setup
=======================

Some variables must be exported into the environment prior to building this port.
Find more information at :ref:`env_vars` on how to keep this settings saved in you environment.

.. note::

In case of manual toolchain installation, set :file:`ESPRESSIF_TOOLCHAIN_PATH` accordingly.
Otherwise, set toolchain path as below. If necessary.

On Linux and macOS:

.. code-block:: console
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
export ESPRESSIF_TOOLCHAIN_PATH="${HOME}/.espressif/tools/xtensa-esp32s2-elf/esp-2020r3-8.4.0/xtensa-esp32s2-elf"
On Windows:

.. code-block:: console
# on CMD:
set ESPRESSIF_TOOLCHAIN_PATH=%USERPROFILE%\.espressif\tools\xtensa-esp32s2-elf\esp-2020r3-8.4.0\xtensa-esp32s2-elf
set ZEPHYR_TOOLCHAIN_VARIANT=espressif
# on PowerShell
$env:ESPRESSIF_TOOLCHAIN_PATH="$env:USERPROFILE\.espressif\tools\xtensa-esp32s2-elf\esp-2020r3-8.4.0\xtensa-esp32s2-elf"
$env:ZEPHYR_TOOLCHAIN_VARIANT="espressif"
Finally, retrieve required submodules to build this port. This might take a while for the first time:

.. code-block:: console
west espressif update
.. note::

It is recommended running the command above after :file:`west update` so that submodules also get updated.

Flashing
========

The usual ``flash`` target will work with the ``esp32s2_saola`` board
configuration. Here is an example for the :ref:`hello_world`
application.

.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: esp32s2_saola
:goals: flash

Refer to :ref:`build_an_application` and :ref:`application_run` for
more details.

It's impossible to determine which serial port the ESP32-S2 board is
connected to, as it uses a generic RS232-USB converter. The default of
``/dev/ttyUSB0`` is provided as that's often the assigned name on a Linux
machine without any other such converters.

The baud rate of 921600bps is recommended. If experiencing issues when
flashing, try halving the value a few times (460800, 230400, 115200,
etc).

All flashing options are now handled by the :ref:`west` tool, including flashing
with custom options such as a different serial port. The ``west`` tool supports
specific options for the ESP32-S2 board, as listed here:

--esp-idf-path ESP_IDF_PATH
path to ESP-IDF
--esp-device ESP_DEVICE
serial port to flash, default /dev/ttyUSB0
--esp-baud-rate ESP_BAUD_RATE
serial baud rate, default 921600
--esp-flash-size ESP_FLASH_SIZE
flash size, default "detect"
--esp-flash-freq ESP_FLASH_FREQ
flash frequency, default "40m"
--esp-flash-mode ESP_FLASH_MODE
flash mode, default "dio"
--esp-tool ESP_TOOL if given, complete path to espidf. default is to
search for it in [ESP_IDF_PATH]/components/esptool_py/
esptool/esptool.py
--esp-flash-bootloader ESP_FLASH_BOOTLOADER
Bootloader image to flash
--esp-flash-partition_table ESP_FLASH_PARTITION_TABLE
Partition table to flash

For example, to flash to ``/dev/ttyUSB2``, use the following command after
having build the application in the ``build`` directory:


.. code-block:: console
west flash -d build/ --skip-rebuild --esp-device /dev/ttyUSB2
References
**********

.. [1] https://www.espressif.com/en/products/socs/esp32-s2
.. _`ESP32S2 Technical Reference Manual`: https://espressif.com/sites/default/files/documentation/esp32-s2_technical_reference_manual_en.pdf
.. _`ESP32S2 Datasheet`: https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf
18 changes: 18 additions & 0 deletions boards/xtensa/esp32s2_saola/esp32s2_saola.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

/dts-v1/;

#include <espressif/esp32s2.dtsi>

/ {
model = "esp32s2_saola";
compatible = "espressif,esp32s2";

chosen {
zephyr,sram = &sram0;
};
};
6 changes: 6 additions & 0 deletions boards/xtensa/esp32s2_saola/esp32s2_saola.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
identifier: esp32s2_saola
name: ESP32-S2
type: mcu
arch: xtensa
toolchain:
- espressif
16 changes: 16 additions & 0 deletions boards/xtensa/esp32s2_saola/esp32s2_saola_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: Apache-2.0

CONFIG_XTENSA_RESET_VECTOR=n

CONFIG_BOARD_ESP32S2_SAOLA=y
CONFIG_SOC_ESP32S2=y
CONFIG_MAIN_STACK_SIZE=2048

CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=240000000

CONFIG_XTENSA_USE_CORE_CRT1=n

CONFIG_GEN_ISR_TABLES=y
CONFIG_GEN_IRQ_VECTOR_TABLE=n

CONFIG_BOOTLOADER_ESP_IDF=y
15 changes: 13 additions & 2 deletions cmake/toolchain/espressif/generic.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ set(COMPILER gcc)
set(LINKER ld)
set(BINTOOLS gnu)

set(CROSS_COMPILE_TARGET xtensa-esp32-elf)
set(SYSROOT_TARGET xtensa-esp32-elf)
file(GLOB toolchain_paths
LIST_DIRECTORIES true
${TOOLCHAIN_HOME}
)

if(toolchain_paths)
list(GET toolchain_paths 0 soc_toolchain_path)

get_filename_component(soc_toolchain "${soc_toolchain_path}" NAME)

set(CROSS_COMPILE_TARGET ${soc_toolchain})
set(SYSROOT_TARGET ${soc_toolchain})
endif()

set(CROSS_COMPILE ${TOOLCHAIN_HOME}/bin/${CROSS_COMPILE_TARGET}-)
set(SYSROOT_DIR ${TOOLCHAIN_HOME}/${SYSROOT_TARGET})
Expand Down
35 changes: 35 additions & 0 deletions dts/xtensa/espressif/esp32s2.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <mem.h>

/ {
#address-cells = <1>;
#size-cells = <1>;

cpus {
#address-cells = <1>;
#size-cells = <0>;

cpu0: cpu@0 {
device_type = "cpu";
compatible = "cadence,tensilica-xtensa-lx7";
reg = <0>;
};
};

soc {
#address-cells = <1>;
#size-cells = <1>;
compatible = "simple-bus";
ranges;

sram0: memory@3ffb0000 {
compatible = "mmio-sram";
reg = <0x3ffb0000 0x50000>;
};
};

};
5 changes: 5 additions & 0 deletions soc/xtensa/esp32s2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_sources(
soc.c
)
29 changes: 29 additions & 0 deletions soc/xtensa/esp32s2/Kconfig.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ESP32S2 board configuration

# Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
# SPDX-License-Identifier: Apache-2.0

if SOC_ESP32S2

config SOC
default "esp32s2"

config GEN_ISR_TABLES
default y

config GEN_IRQ_VECTOR_TABLE
default n

config XIP
default n

config ISR_STACK_SIZE
default 2048

config IRQ_OFFLOAD_INTNUM
default 7

config MP_NUM_CPUS
default 1

endif
Loading

0 comments on commit ed63e2a

Please sign in to comment.