• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 //! An example demonstrating how to use the `pw_log` modules and set up a
16 //! tokenized backend.
17 //!
18 //! See <https://pigweed.dev/pw_rust/> for instructions on how to build this
19 //! example.  See the `pw_log_backend` crate in this directory for details on
20 //! how the tokenized backend is setup.
21 #![no_main]
22 #![no_std]
23 
24 // Panic handler that halts the CPU on panic.
25 use panic_halt as _;
26 
27 // Cortex M runtime entry macro.
28 use cortex_m_rt::entry;
29 
30 // Semihosting support which is well supported for QEMU targets.
31 use cortex_m_semihosting::{debug, hprintln};
32 
33 use pw_log::{critical, infof, warnf};
34 
35 #[entry]
main() -> !36 fn main() -> ! {
37     // Plain text printout without `pw_log`
38     hprintln!("Hello, Pigweed!");
39 
40     // printf style `pw_log` messages
41     infof!("Bare string");
42     warnf!("Integer value %d", 42);
43 
44     // core::fmt style `pw_log` messages
45     //
46     // Note the support for this is in progress with the following notes:
47     // * only `u32`, `i32`, and '&str' arguments are supported right now.
48     // * arguments must be annotated with `as <type>` to work with `stable`
49     //   toolchains.
50     //
51     // Both of these will be addressed in the future.
52     critical!(
53         "Generic rusty arguments: 0x{:08x} {}",
54         0xaa as u32,
55         -42 as i32
56     );
57 
58     debug::exit(debug::EXIT_SUCCESS);
59     loop {}
60 }
61