Skip to content

Commit 346836b

Browse files
soburicarlescufi
authored andcommitted
boards: riscv: add M5Stack STAMP-C3
Add M5Stack STAMP-C3 an ESP32-C3 based board. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent c7d9f2b commit 346836b

File tree

9 files changed

+400
-0
lines changed

9 files changed

+400
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# M5Stack STAMP-C3 board configuration
2+
3+
# Copyright 2022 TOKITA Hiroshi <[email protected]>
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
config BOARD_STAMP_C3
7+
bool "M5Stack STAMP-C3 Board"
8+
depends on SOC_ESP32C3
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# M5Stack STAMP-C3 board configuration
2+
3+
# Copyright 2022 TOKITA Hiroshi <[email protected]>
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
config BOARD
7+
default "stamp_c3"
8+
depends on BOARD_STAMP_C3
9+
10+
config HEAP_MEM_POOL_SIZE
11+
default 98304 if WIFI
12+
default 16384 if BT
13+
default 4096
14+
15+
if BT
16+
17+
choice BT_HCI_BUS_TYPE
18+
default BT_ESP32
19+
endchoice
20+
21+
endif # BT

boards/riscv/stamp_c3/board.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
if(NOT "${OPENOCD}" MATCHES "^${ESPRESSIF_TOOLCHAIN_PATH}/.*")
4+
set(OPENOCD OPENOCD-NOTFOUND)
5+
endif()
6+
find_program(OPENOCD openocd PATHS ${ESPRESSIF_TOOLCHAIN_PATH}/openocd-esp32/bin NO_DEFAULT_PATH)
7+
8+
include(${ZEPHYR_BASE}/boards/common/esp32.board.cmake)
9+
include(${ZEPHYR_BASE}/boards/common/openocd.board.cmake)
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
.. _stamp_c3:
2+
3+
M5Stack STAMP-C3
4+
##################
5+
6+
Overview
7+
********
8+
9+
STAMP-C3 featuring ESPRESSIF ESP32-C3 RISC-V MCU with Wi-Fi connectivity
10+
for IoT edge devices such as home appliances and Industrial Automation.
11+
12+
For more details see the `M5Stack STAMP-C3`_ page.
13+
14+
Supported Features
15+
==================
16+
17+
The STAMP-C3 board configuration supports the following hardware features:
18+
19+
+-----------+------------+------------------+
20+
| Interface | Controller | Driver/Component |
21+
+===========+============+==================+
22+
| PMP | on-chip | arch/riscv |
23+
+-----------+------------+------------------+
24+
| INTMTRX | on-chip | intc_esp32c3 |
25+
+-----------+------------+------------------+
26+
| PINMUX | on-chip | pinctrl_esp32 |
27+
+-----------+------------+------------------+
28+
| USB UART | on-chip | serial_esp32_usb |
29+
+-----------+------------+------------------+
30+
| GPIO | on-chip | gpio_esp32 |
31+
+-----------+------------+------------------+
32+
| UART | on-chip | uart_esp32 |
33+
+-----------+------------+------------------+
34+
| I2C | on-chip | i2c_esp32 |
35+
+-----------+------------+------------------+
36+
| SPI | on-chip | spi_esp32_spim |
37+
+-----------+------------+------------------+
38+
| TWAI | on-chip | can_esp32_twai |
39+
+-----------+------------+------------------+
40+
41+
42+
Prerequisites
43+
-------------
44+
45+
Espressif HAL requires WiFi and Bluetooth binary blobs in order work. Run the command
46+
below to retrieve those files.
47+
48+
.. code-block:: console
49+
50+
west blobs fetch hal_espressif
51+
52+
.. note::
53+
54+
It is recommended running the command above after :file:`west update`.
55+
56+
Building & Flashing
57+
-------------------
58+
59+
Build and flash applications as usual (see :ref:`build_an_application` and
60+
:ref:`application_run` for more details).
61+
62+
.. zephyr-app-commands::
63+
:zephyr-app: samples/hello_world
64+
:board: stamp_c3
65+
:goals: build
66+
67+
The usual ``flash`` target will work with the ``stamp_c3`` board
68+
configuration. Here is an example for the :ref:`hello_world`
69+
application.
70+
71+
.. zephyr-app-commands::
72+
:zephyr-app: samples/hello_world
73+
:board: stamp_c3
74+
:goals: flash
75+
76+
Open the serial monitor using the following command:
77+
78+
.. code-block:: shell
79+
80+
west espressif monitor
81+
82+
After the board has automatically reset and booted, you should see the following
83+
message in the monitor:
84+
85+
.. code-block:: console
86+
87+
***** Booting Zephyr OS vx.x.x-xxx-gxxxxxxxxxxxx *****
88+
Hello World! stamp_c3
89+
90+
Debugging
91+
---------
92+
93+
As with much custom hardware, the ESP32 modules require patches to
94+
OpenOCD that are not upstreamed yet. Espressif maintains their own fork of
95+
the project. The custom OpenOCD can be obtained at `OpenOCD ESP32`_
96+
97+
The Zephyr SDK uses a bundled version of OpenOCD by default. You can overwrite that behavior by adding the
98+
``-DOPENOCD=<path/to/bin/openocd> -DOPENOCD_DEFAULT_PATH=<path/to/openocd/share/openocd/scripts>``
99+
parameter when building.
100+
101+
Here is an example for building the :ref:`hello_world` application.
102+
103+
.. zephyr-app-commands::
104+
:zephyr-app: samples/hello_world
105+
:board: stamp_c3
106+
:goals: build flash
107+
:gen-args: -DOPENOCD=<path/to/bin/openocd> -DOPENOCD_DEFAULT_PATH=<path/to/openocd/share/openocd/scripts>
108+
109+
You can debug an application in the usual way. Here is an example for the :ref:`hello_world` application.
110+
111+
.. zephyr-app-commands::
112+
:zephyr-app: samples/hello_world
113+
:board: stamp_c3
114+
:goals: debug
115+
116+
References
117+
**********
118+
119+
.. target-notes::
120+
121+
.. _`M5Stack STAMP-C3`: https://docs.m5stack.com/en/core/stamp_c3
122+
.. _`ESP32C3 Technical Reference Manual`: https://espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf
123+
.. _`ESP32C3 Datasheet`: https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf
124+
.. _`OpenOCD ESP32`: https://github.com/espressif/openocd-esp32/releases
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2022 TOKITA Hiroshi <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/pinctrl/esp-pinctrl-common.h>
8+
#include <dt-bindings/pinctrl/esp32c3-pinctrl.h>
9+
#include <zephyr/dt-bindings/pinctrl/esp32c3-gpio-sigmap.h>
10+
11+
&pinctrl {
12+
13+
uart0_default: uart0_default {
14+
group1 {
15+
pinmux = <UART0_TX_GPIO21>;
16+
};
17+
group2 {
18+
pinmux = <UART0_RX_GPIO20>;
19+
bias-pull-up;
20+
};
21+
};
22+
23+
spim2_default: spim2_default {
24+
group1 {
25+
pinmux = <SPIM2_MISO_GPIO5>,
26+
<SPIM2_SCLK_GPIO4>,
27+
<SPIM2_CSEL_GPIO7>;
28+
};
29+
group2 {
30+
pinmux = <SPIM2_MOSI_GPIO6>;
31+
output-low;
32+
};
33+
};
34+
35+
i2c0_default: i2c0_default {
36+
group1 {
37+
pinmux = <I2C0_SDA_GPIO8>,
38+
<I2C0_SCL_GPIO9>;
39+
bias-pull-up;
40+
drive-open-drain;
41+
output-high;
42+
};
43+
};
44+
45+
twai_default: twai_default {
46+
group1 {
47+
pinmux = <TWAI_TX_GPIO0>,
48+
<TWAI_RX_GPIO1>;
49+
};
50+
};
51+
};

boards/riscv/stamp_c3/stamp_c3.dts

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*
2+
* Copyright 2022 TOKITA Hiroshi <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/dts-v1/;
8+
9+
#include <espressif/esp32c3.dtsi>
10+
#include "stamp_c3-pinctrl.dtsi"
11+
12+
/ {
13+
model = "M5Stack STAMP-C3";
14+
compatible = "m5stack,stamp_c3";
15+
16+
chosen {
17+
zephyr,sram = &sram0;
18+
zephyr,console = &uart0;
19+
zephyr,shell-uart = &uart0;
20+
zephyr,flash = &flash0;
21+
};
22+
23+
aliases {
24+
sw0 = &button0;
25+
i2c-0 = &i2c0;
26+
watchdog0 = &wdt0;
27+
};
28+
29+
power-states {
30+
light_sleep: light_sleep {
31+
compatible = "zephyr,power-state";
32+
power-state-name = "standby";
33+
min-residency-us = <200>;
34+
exit-latency-us = <60>;
35+
};
36+
37+
deep_sleep: deep_sleep {
38+
compatible = "zephyr,power-state";
39+
power-state-name = "soft-off";
40+
min-residency-us = <660>;
41+
exit-latency-us = <105>;
42+
};
43+
};
44+
45+
gpio_keys {
46+
compatible = "gpio-keys";
47+
button0: button0 {
48+
label = "BTN";
49+
gpios = <&gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
50+
};
51+
};
52+
};
53+
54+
&cpu0 {
55+
clock-frequency = <ESP32_CLK_CPU_160M>;
56+
cpu-power-states = <&deep_sleep &light_sleep>;
57+
};
58+
59+
&uart0 {
60+
status = "okay";
61+
current-speed = <115200>;
62+
pinctrl-0 = <&uart0_default>;
63+
pinctrl-names = "default";
64+
};
65+
66+
&usb_serial {
67+
status = "okay";
68+
};
69+
70+
&i2c0 {
71+
status = "okay";
72+
clock-frequency = <I2C_BITRATE_STANDARD>;
73+
pinctrl-0 = <&i2c0_default>;
74+
pinctrl-names = "default";
75+
};
76+
77+
&trng0 {
78+
status = "okay";
79+
};
80+
81+
&spi2 {
82+
#address-cells = <1>;
83+
#size-cells = <0>;
84+
status = "okay";
85+
pinctrl-0 = <&spim2_default>;
86+
pinctrl-names = "default";
87+
};
88+
89+
&gpio0 {
90+
status = "okay";
91+
};
92+
93+
&wdt0 {
94+
status = "okay";
95+
};
96+
97+
&timer0 {
98+
status = "disabled";
99+
};
100+
101+
&timer1 {
102+
status = "disabled";
103+
};
104+
105+
&twai {
106+
/* requires external CAN transceiver or jumper on RX and TX pins for loopback testing */
107+
status = "disabled";
108+
pinctrl-0 = <&twai_default>;
109+
pinctrl-names = "default";
110+
bus-speed = <125000>;
111+
};
112+
113+
&flash0 {
114+
status = "okay";
115+
partitions {
116+
compatible = "fixed-partitions";
117+
#address-cells = <1>;
118+
#size-cells = <1>;
119+
120+
/* Reserve 60kB for the bootloader */
121+
boot_partition: partition@0 {
122+
label = "mcuboot";
123+
reg = <0x00000000 0x0000F000>;
124+
read-only;
125+
};
126+
127+
/* Reserve 1024kB for the application in slot 0 */
128+
slot0_partition: partition@10000 {
129+
label = "image-0";
130+
reg = <0x00010000 0x00100000>;
131+
};
132+
133+
/* Reserve 1024kB for the application in slot 1 */
134+
slot1_partition: partition@110000 {
135+
label = "image-1";
136+
reg = <0x00110000 0x00100000>;
137+
};
138+
139+
/* Reserve 256kB for the scratch partition */
140+
scratch_partition: partition@210000 {
141+
label = "image-scratch";
142+
reg = <0x00210000 0x00040000>;
143+
};
144+
145+
storage_partition: partition@250000 {
146+
label = "storage";
147+
reg = <0x00250000 0x00006000>;
148+
};
149+
};
150+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
identifier: stamp_c3
2+
name: M5Stack STAMP-C3
3+
type: mcu
4+
arch: riscv
5+
toolchain:
6+
- zephyr
7+
supported:
8+
- gpio
9+
- i2c
10+
- spi
11+
- uart
12+
- watchdog
13+
testing:
14+
ignore_tags:
15+
- net
16+
- bluetooth
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
CONFIG_BOARD_STAMP_C3=y
4+
CONFIG_SOC_ESP32C3=y
5+
CONFIG_MAIN_STACK_SIZE=2048
6+
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=1000000
7+
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
8+
CONFIG_CONSOLE=y
9+
CONFIG_SERIAL=y
10+
CONFIG_UART_CONSOLE=y
11+
CONFIG_GPIO=y
12+
CONFIG_CLOCK_CONTROL=y

0 commit comments

Comments
 (0)