Skip to content

Commit 2647056

Browse files
committed
tests: drivers: gpio-async: Create shell (WIP)
Create a shell app to test gpios. Signed-off-by: David Brown <[email protected]>
1 parent bcc9ee4 commit 2647056

File tree

6 files changed

+113
-0
lines changed

6 files changed

+113
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
project(gpio_async)
8+
rust_cargo_application()

tests/drivers/gpio-async/Cargo.toml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2024 Linaro LTD
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
[package]
5+
# This must be rustapp for now.
6+
name = "rustapp"
7+
version = "0.1.0"
8+
edition = "2021"
9+
description = "Test async gpios"
10+
license = "Apache-2.0 or MIT"
11+
12+
[lib]
13+
crate-type = ["staticlib"]
14+
15+
[dependencies]
16+
zephyr = { version = "0.1.0", features = ["time-driver", "executor-zephyr"] }
17+
log = "0.4.22"
18+
static_cell = "2.1"
19+
heapless = "0.8"
20+
21+
[dependencies.embassy-executor]
22+
version = "0.7.0"
23+
features = [
24+
"log",
25+
"task-arena-size-2048",
26+
]
27+
28+
[dependencies.embassy-futures]
29+
version = "0.1.1"
30+
31+
[dependencies.embassy-sync]
32+
version = "0.6.2"
33+
34+
[dependencies.embassy-time]
35+
version = "0.4.0"
36+
features = ["tick-hz-10_000"]
37+
38+
[dependencies.critical-section]
39+
version = "1.2"
40+
41+
[profile.dev]
42+
opt-level = 1
43+
44+
[profile.release]
45+
debug = true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2024 Linaro LTD
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# This board doesn't have a serial console, so use RTT.
5+
CONFIG_UART_CONSOLE=n
6+
CONFIG_RTT_CONSOLE=y
7+
CONFIG_USE_SEGGER_RTT=y

tests/drivers/gpio-async/prj.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2024 Linaro LTD
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_DEBUG=y
5+
6+
# The default 1k stack isn't large enough for rust string formatting with logging.
7+
CONFIG_MAIN_STACK_SIZE=4096
8+
9+
CONFIG_RUST=y
10+
11+
CONFIG_RUST_ALLOC=y
12+
# CONFIG_LOG=y
13+
14+
CONFIG_LOG_BACKEND_RTT=n
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2024 Linaro LTD
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# This board doesn't have a serial console, so use RTT.
5+
CONFIG_UART_CONSOLE=n
6+
CONFIG_RTT_CONSOLE=y
7+
CONFIG_USE_SEGGER_RTT=y

tests/drivers/gpio-async/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2024 Linaro LTD
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#![no_std]
5+
6+
extern crate alloc;
7+
8+
use zephyr::embassy::Executor;
9+
10+
use embassy_executor::Spawner;
11+
use log::info;
12+
use static_cell::StaticCell;
13+
14+
static EXECUTOR_MAIN: StaticCell<Executor> = StaticCell::new();
15+
16+
#[no_mangle]
17+
extern "C" fn rust_main() {
18+
unsafe {
19+
zephyr::set_logger().unwrap();
20+
}
21+
22+
let executor = EXECUTOR_MAIN.init(Executor::new());
23+
executor.run(|spawner| {
24+
spawner.spawn(main(spawner)).unwrap();
25+
})
26+
}
27+
28+
#[embassy_executor::task]
29+
async fn main(spawner: Spawner) {
30+
info!("Hello world");
31+
let _ = spawner;
32+
}

0 commit comments

Comments
 (0)