Skip to content

Commit bbd40b8

Browse files
sylvioalvescarlescufi
authored andcommitted
soc: esp32s3: add base source content
This brings esp32s3 linker, DTS and all necessary files to allow the soc support. Signed-off-by: Sylvio Alves <[email protected]>
1 parent fde5281 commit bbd40b8

File tree

12 files changed

+2073
-1
lines changed

12 files changed

+2073
-1
lines changed

dts/xtensa/espressif/esp32s3.dtsi

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <mem.h>
7+
#include <xtensa/xtensa.dtsi>
8+
#include <zephyr/dt-bindings/gpio/gpio.h>
9+
#include <zephyr/dt-bindings/clock/esp32s3_clock.h>
10+
#include <zephyr/dt-bindings/interrupt-controller/esp32s3-xtensa-intmux.h>
11+
#include <dt-bindings/pinctrl/esp32s3-pinctrl.h>
12+
13+
/ {
14+
chosen {
15+
zephyr,flash-controller = &flash;
16+
};
17+
18+
cpus {
19+
#address-cells = <1>;
20+
#size-cells = <0>;
21+
22+
cpu0: cpu@0 {
23+
device_type = "cpu";
24+
compatible = "cdns,tensilica-xtensa-lx7";
25+
reg = <0>;
26+
};
27+
28+
cpu1: cpu@1 {
29+
device_type = "cpu";
30+
compatible = "cdns,tensilica-xtensa-lx7";
31+
reg = <1>;
32+
};
33+
34+
};
35+
36+
pinctrl: pin-controller {
37+
compatible = "espressif,esp32-pinctrl";
38+
status = "okay";
39+
};
40+
41+
soc {
42+
#address-cells = <1>;
43+
#size-cells = <1>;
44+
compatible = "simple-bus";
45+
ranges;
46+
47+
sram0: memory@3fc88000 {
48+
compatible = "mmio-sram";
49+
reg = <0x3fc88000 0x77FFF>;
50+
};
51+
52+
intc: interrupt-controller@600c2000 {
53+
#interrupt-cells = <1>;
54+
compatible = "espressif,esp32-intc";
55+
interrupt-controller;
56+
reg = <0x600c2000 0x1000>;
57+
status = "okay";
58+
};
59+
60+
rtc: rtc@60021000 {
61+
compatible = "espressif,esp32-rtc";
62+
reg = <0x60021000 0x2000>;
63+
xtal-freq = <ESP32_CLK_XTAL_40M>;
64+
#clock-cells = <1>;
65+
status = "okay";
66+
67+
rtc_timer: rtc_timer {
68+
compatible = "espressif,esp32-rtc-timer";
69+
slow-clk-freq = <ESP32_RTC_SLOW_CLK_FREQ_150K>;
70+
interrupts = <RTC_CORE_INTR_SOURCE>;
71+
interrupt-parent = <&intc>;
72+
status = "okay";
73+
};
74+
};
75+
76+
flash: flash-controller@60002000 {
77+
compatible = "espressif,esp32-flash-controller";
78+
reg = <0x60002000 0x1000>;
79+
/* interrupts = <3 0>; */
80+
81+
#address-cells = <1>;
82+
#size-cells = <1>;
83+
84+
flash0: flash@0 {
85+
compatible = "soc-nv-flash";
86+
reg = <0 0x800000>;
87+
erase-block-size = <4096>;
88+
write-block-size = <4>;
89+
};
90+
};
91+
92+
uart0: uart@60000000 {
93+
compatible = "espressif,esp32-uart";
94+
reg = <0x60000000 0x1000>;
95+
interrupts = <UART0_INTR_SOURCE>;
96+
interrupt-parent = <&intc>;
97+
clocks = <&rtc ESP32_UART0_MODULE>;
98+
status = "disabled";
99+
};
100+
101+
uart1: uart@60010000 {
102+
compatible = "espressif,esp32-uart";
103+
reg = <0x60010000 0x1000>;
104+
interrupts = <UART1_INTR_SOURCE>;
105+
interrupt-parent = <&intc>;
106+
clocks = <&rtc ESP32_UART1_MODULE>;
107+
status = "disabled";
108+
};
109+
110+
uart2: uart@6002e000 {
111+
compatible = "espressif,esp32-uart";
112+
reg = <0x6002e000 0x1000>;
113+
interrupts = <UART2_INTR_SOURCE>;
114+
interrupt-parent = <&intc>;
115+
clocks = <&rtc ESP32_UART2_MODULE>;
116+
status = "disabled";
117+
};
118+
119+
gpio: gpio {
120+
compatible = "simple-bus";
121+
gpio-map-mask = <0xffffffe0 0xffffffc0>;
122+
gpio-map-pass-thru = <0x1f 0x3f>;
123+
gpio-map = <
124+
0x00 0x0 &gpio0 0x0 0x0
125+
0x20 0x0 &gpio1 0x0 0x0
126+
>;
127+
#gpio-cells = <2>;
128+
#address-cells = <1>;
129+
#size-cells = <1>;
130+
ranges;
131+
132+
gpio0: gpio@60004000 {
133+
compatible = "espressif,esp32-gpio";
134+
gpio-controller;
135+
#gpio-cells = <2>;
136+
reg = <0x60004000 0x800>;
137+
interrupts = <GPIO_INTR_SOURCE>;
138+
interrupt-parent = <&intc>;
139+
ngpios = <32>;
140+
};
141+
142+
gpio1: gpio@60004800 {
143+
compatible = "espressif,esp32-gpio";
144+
gpio-controller;
145+
#gpio-cells = <2>;
146+
reg = <0x60004800 0x800>;
147+
interrupts = <GPIO_INTR_SOURCE>;
148+
interrupt-parent = <&intc>;
149+
ngpios = <13>;
150+
};
151+
};
152+
153+
};
154+
};

soc/xtensa/esp32s3/CMakeLists.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
zephyr_sources(
4+
soc.c
5+
loader.c
6+
)
7+
8+
zephyr_library_sources_ifdef(CONFIG_NEWLIB_LIBC newlib_fix.c)
9+
10+
# get code-partition slot0 address
11+
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
12+
dt_reg_addr(img_0_off PATH ${dts_partition_path})
13+
14+
# get code-partition boot address
15+
dt_nodelabel(dts_partition_path NODELABEL "boot_partition")
16+
dt_reg_addr(boot_off PATH ${dts_partition_path})
17+
18+
# get flash size to use in esptool as string
19+
math(EXPR esptoolpy_flashsize "${CONFIG_FLASH_SIZE} / 0x100000")
20+
21+
if(CONFIG_BOOTLOADER_ESP_IDF)
22+
include(ExternalProject)
23+
24+
## we use hello-world project, but I think any can be used.
25+
set(espidf_components_dir ${ESP_IDF_PATH}/components)
26+
set(espidf_prefix ${CMAKE_BINARY_DIR}/esp-idf)
27+
set(espidf_build_dir ${espidf_prefix}/build)
28+
29+
ExternalProject_Add(
30+
EspIdfBootloader
31+
PREFIX ${espidf_prefix}
32+
SOURCE_DIR ${espidf_components_dir}/bootloader/subproject
33+
BINARY_DIR ${espidf_build_dir}/bootloader
34+
CONFIGURE_COMMAND
35+
${CMAKE_COMMAND} -G${CMAKE_GENERATOR}
36+
-S ${espidf_components_dir}/bootloader/subproject
37+
-B ${espidf_build_dir}/bootloader -DSDKCONFIG=${espidf_build_dir}/sdkconfig
38+
-DIDF_PATH=${ESP_IDF_PATH} -DIDF_TARGET=${CONFIG_SOC}
39+
-DPYTHON_DEPS_CHECKED=1
40+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
41+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
42+
-DCMAKE_ASM_COMPILER=${CMAKE_ASM_COMPILER}
43+
-DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}
44+
-DPYTHON=${PYTHON_EXECUTABLE}
45+
BUILD_COMMAND
46+
${CMAKE_COMMAND} --build .
47+
INSTALL_COMMAND "" # This particular build system has no install command
48+
)
49+
50+
ExternalProject_Add(
51+
EspPartitionTable
52+
SOURCE_DIR ${espidf_components_dir}/partition_table
53+
BINARY_DIR ${espidf_build_dir}
54+
CONFIGURE_COMMAND ""
55+
BUILD_COMMAND
56+
${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/partition_table/gen_esp32part.py -q
57+
--offset 0x8000 --flash-size ${esptoolpy_flashsize}MB ${ESP_IDF_PATH}/components/partition_table/partitions_singleapp.csv ${espidf_build_dir}/partitions_singleapp.bin
58+
INSTALL_COMMAND ""
59+
)
60+
61+
if(CONFIG_BUILD_OUTPUT_BIN)
62+
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
63+
COMMAND ${PYTHON_EXECUTABLE} ${ESP_IDF_PATH}/components/esptool_py/esptool/esptool.py
64+
ARGS --chip esp32s3 elf2image --flash_mode dio --flash_freq 40m --flash_size ${esptoolpy_flashsize}MB
65+
-o ${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.bin
66+
${CMAKE_BINARY_DIR}/zephyr/${CONFIG_KERNEL_BIN_NAME}.elf)
67+
endif()
68+
69+
set_property(TARGET bintools PROPERTY disassembly_flag_inline_source)
70+
71+
add_dependencies(app EspIdfBootloader EspPartitionTable)
72+
73+
board_finalize_runner_args(esp32 "--esp-flash-bootloader=${espidf_build_dir}/bootloader/bootloader.bin")
74+
75+
board_finalize_runner_args(esp32 "--esp-flash-partition_table=${espidf_build_dir}/partitions_singleapp.bin")
76+
77+
board_finalize_runner_args(esp32 "--esp-partition-table-address=0x8000")
78+
79+
endif()
80+
81+
board_finalize_runner_args(esp32 "--esp-boot-address=${boot_off}")
82+
83+
board_finalize_runner_args(esp32 "--esp-app-address=${img_0_off}")
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# ESP32 board configuration
2+
3+
# Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
if SOC_ESP32S3
7+
8+
if BOOTLOADER_MCUBOOT
9+
config HAS_FLASH_LOAD_OFFSET
10+
default y
11+
12+
config MCUBOOT_GENERATE_UNSIGNED_IMAGE
13+
default y
14+
15+
config MCUBOOT_GENERATE_CONFIRMED_IMAGE
16+
default y
17+
18+
config ROM_START_OFFSET
19+
default 0x20
20+
21+
config HAS_DYNAMIC_DEVICE_HANDLES
22+
default y
23+
endif
24+
25+
config SOC
26+
default "esp32s3"
27+
28+
config SOC_TOOLCHAIN_NAME
29+
string
30+
default "espressif_esp32s3"
31+
32+
config HEAP_MEM_POOL_SIZE
33+
default 32768
34+
35+
config MINIMAL_LIBC_OPTIMIZE_STRING_FOR_SIZE
36+
default n
37+
38+
config SYS_CLOCK_HW_CYCLES_PER_SEC
39+
default $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency)
40+
41+
config XTENSA_CCOUNT_HZ
42+
default SYS_CLOCK_HW_CYCLES_PER_SEC
43+
44+
endif

0 commit comments

Comments
 (0)