Skip to content

Commit fc3bf01

Browse files
committed
samples: hello_world: Change to logging
Change the hello world sample to use Rust's logging mechanism. This is configured to not enable logging in Zephyr, so the output will go to the same printk mechanism it went to before. Signed-off-by: David Brown <[email protected]>
1 parent 41f96ec commit fc3bf01

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

samples/hello_world/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ crate-type = ["staticlib"]
1414

1515
[dependencies]
1616
zephyr = "3.7.0"
17+
log = "0.4.22"

samples/hello_world/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
CONFIG_RUST=y
5+
6+
# CONFIG_RUST_ALLOC=y
7+
# CONFIG_LOG=y

samples/hello_world/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33

44
#![no_std]
55

6-
use zephyr::printkln;
7-
8-
// Reference the Zephyr crate so that the panic handler gets used. This is only needed if no
9-
// symbols from the crate are directly used.
10-
extern crate zephyr;
6+
use log::info;
117

128
#[no_mangle]
139
extern "C" fn rust_main() {
14-
printkln!("Hello world from Rust on {}",
15-
zephyr::kconfig::CONFIG_BOARD);
10+
unsafe { zephyr::set_logger().unwrap(); }
11+
12+
info!("Hello world from Rust on {}", zephyr::kconfig::CONFIG_BOARD);
1613
}

0 commit comments

Comments
 (0)