Skip to content

Commit 72aa2a9

Browse files
LucasTamborkartben
authored andcommitted
samples: boards: espressif: ulp: Add Echo Sample
Add an echo sample based on polling API from UART. Signed-off-by: Lucas Tamborrino <lucas.tamborrino@espressif.com>
1 parent 466051b commit 72aa2a9

File tree

11 files changed

+166
-0
lines changed

11 files changed

+166
-0
lines changed
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+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../echo_ulp_lpcore/zephyr)
6+
7+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
8+
9+
message(STATUS "${CONFIG_BOARD_TARGET} compile as Master in this sample")
10+
project(echo_ulp_hpcore)
11+
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
source "share/sysbuild/Kconfig"
5+
6+
config ULP_REMOTE_BOARD
7+
string
8+
default "esp32c6_devkitc/esp32c6/lpcore" if $(BOARD) = "esp32c6_devkitc"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.. zephyr:code-sample:: echo-ulp
2+
:name: Echo ULP
3+
4+
Leverage Zephyr's UART API to use the LP UART on the ESP32-C6's LP core.
5+
6+
Overview
7+
********
8+
9+
This sample application demonstrates how to use poll-based APIs from the Zephyr
10+
UART driver subsystem. It reads characters from the LP UART using
11+
:c:func:`uart_poll_in` and echoes them back using :c:func:`uart_poll_out`.
12+
13+
Building and Flashing
14+
*********************
15+
16+
Build the sample code as follows:
17+
18+
.. zephyr-app-commands::
19+
:zephyr-app: samples/boards/espressif/ulp/lp_core/echo_ulp
20+
:board: esp32c6_devkitc/esp32c6/hpcore
21+
:west-args: --sysbuild
22+
:goals: build
23+
:compact:
24+
25+
Flash it to the device with the command:
26+
27+
.. zephyr-app-commands::
28+
:zephyr-app: samples/boards/espressif/ulp/lp_core/echo_ulp
29+
:board: esp32c6_devkitc/esp32c6/hpcore
30+
:west-args: --sysbuild
31+
:goals: flash
32+
:compact:
33+
34+
Sample Output
35+
=============
36+
37+
.. code-block:: console
38+
39+
UART echo example started. Type something...
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&lp_uart {
8+
status = "okay";
9+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ULP_COPROC_ENABLED=y
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
7+
message(STATUS "${BOARD} compiles as remote in this sample")
8+
project(echo_ulp_lpcore)
9+
10+
target_sources(app PRIVATE src/main.c)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_MAIN_STACK_SIZE=1024
2+
CONFIG_ISR_STACK_SIZE=64
3+
CONFIG_IDLE_STACK_SIZE=32
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <zephyr/device.h>
9+
#include <zephyr/drivers/uart.h>
10+
11+
#define UART_DEVICE_NODE DT_NODELABEL(lp_uart)
12+
13+
int main(void)
14+
{
15+
const struct device *uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE);
16+
char c;
17+
int ret = 0;
18+
19+
printf("UART echo example started. Type something...\n");
20+
21+
while (1) {
22+
ret = uart_poll_in(uart_dev, &c);
23+
if (ret == 0) {
24+
/* Echo character back out */
25+
uart_poll_out(uart_dev, c);
26+
if (c == '\r') {
27+
uart_poll_out(uart_dev, '\n');
28+
}
29+
}
30+
}
31+
32+
return 0;
33+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sample:
2+
name: ESP32-C6 LP_CORE Echo Sample
3+
tests:
4+
sample.boards.espressif.ulp.lp_core.echo_ulp:
5+
platform_allow:
6+
- esp32c6_devkitc/esp32c6/hpcore
7+
tags:
8+
- samples
9+
sysbuild: true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <zephyr/sys/poweroff.h>
9+
#include <esp_sleep.h>
10+
#include <ulp_lp_core.h>
11+
#include <zephyr/kernel.h>
12+
13+
int main(void)
14+
{
15+
while (1) {
16+
k_sleep(K_MSEC(1000));
17+
}
18+
19+
return 0;
20+
}

0 commit comments

Comments
 (0)