Skip to content

Commit 1f0de17

Browse files
authored
Merge pull request #43 from OpenPSG/add-defmt-logging
Add defmt logging support
2 parents 1525bee + 200897e commit 1f0de17

File tree

11 files changed

+602
-49
lines changed

11 files changed

+602
-49
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sntpc = { version = "0.5", features = ["sync"] }
3333
```rust
3434
use sntpc::{sync::get_time, NtpContext, StdTimestampGen};
3535

36-
use std::net::{ToSocketAddrs, UdpSocket};
36+
use std::net::{SocketAddr, ToSocketAddrs, UdpSocket};
3737
use std::thread;
3838
use std::time::Duration;
3939

@@ -56,7 +56,7 @@ fn main() {
5656
.set_read_timeout(Some(Duration::from_secs(2)))
5757
.expect("Unable to set UDP socket read timeout");
5858

59-
for addr in POOL_NTP_ADDR.to_socket_addrs().unwrap() {
59+
for addr in POOL_NTP_ADDR.to_socket_addrs().filter(SocketAddr::is_ipv4).unwrap() {
6060
let ntp_context = NtpContext::new(StdTimestampGen::default());
6161
let result = get_time(addr, &socket, ntp_context);
6262

examples/embassy-net/Cargo.toml

+6-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ version = "0.1.0"
44
edition = "2021"
55
publish = false
66

7-
[features]
8-
log = ["dep:simple_logger", "dep:log", "sntpc/log", "embassy-executor/log", "embassy-time/log", "embassy-net/log"]
9-
107
[dependencies]
11-
sntpc = { path = "../../sntpc", default-features = false, features = ["embassy-socket"] }
12-
log = { version = "~0.4", optional = true }
13-
simple_logger = { version = "5", optional = true }
14-
embassy-executor = { version = "0.6.3", features = ["task-arena-size-32768", "arch-std", "executor-thread"] }
15-
embassy-time = { version = "0.3.2", features = ["std", "generic-queue"] }
16-
embassy-net = { version = "0.5.0", features = ["std", "medium-ethernet", "udp", "dns"] }
8+
sntpc = { path = "../../sntpc", default-features = false, features = ["defmt", "embassy-socket"] }
9+
embassy-executor = { version = "0.6.3", features = ["arch-std", "defmt", "task-arena-size-32768", "executor-thread"] }
10+
embassy-time = { version = "0.3.2", features = ["std", "defmt", "generic-queue"] }
11+
embassy-net = { version = "0.5.0", features = ["std", "defmt", "medium-ethernet", "udp", "dns"] }
1712
static_cell = "2"
1813
heapless = { version = "0.8", default-features = false }
14+
defmt = "0.3"
15+
defmt-logger-tcp = "0.2"
1916

2017
[target.'cfg(unix)'.dependencies]
2118
embassy-net-tuntap = "0.1.0"

examples/embassy-net/build.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::env;
2+
use std::path::{Path, PathBuf};
3+
4+
fn main() {
5+
if cfg!(target_os = "linux") {
6+
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
7+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
8+
9+
// The default linker script can be overriden by setting `LDSCRIPTDIR` and `LDSCRIPT`.
10+
// If not specified, the binutils default linker script for the target architecture is used.
11+
let ldscript_dir = env::var("LDSCRIPTDIR").map_or_else(
12+
|_| Path::new(&manifest_dir).join("ldscripts"),
13+
PathBuf::from,
14+
);
15+
let ldscript = env::var("LDSCRIPT")
16+
.unwrap_or_else(|_| format!("elf_{target_arch}.x"));
17+
18+
// Add the linker script to the search path.
19+
println!("cargo:rustc-link-search={}", ldscript_dir.to_string_lossy());
20+
println!("cargo:rustc-link-arg=-T{ldscript}");
21+
22+
// Add the defmt strings section to the elf file.
23+
println!("cargo:rustc-link-arg=-Tdefmt.x");
24+
25+
// Enable info level logging for the current crate (if not already set).
26+
if env::var("DEFMT_LOG").is_err() {
27+
println!("cargo:rustc-env=DEFMT_LOG=info");
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
/* Default linker script, for normal executables */
2+
/* Copyright (C) 2014-2023 Free Software Foundation, Inc.
3+
Copying and distribution of this script, with or without modification,
4+
are permitted in any medium without royalty provided the copyright
5+
notice and this notice are preserved. */
6+
OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64",
7+
"elf64-littleaarch64")
8+
OUTPUT_ARCH(aarch64)
9+
ENTRY(_start)
10+
SEARCH_DIR("=/usr/aarch64-linux-gnu/lib");
11+
SECTIONS
12+
{
13+
/* Read-only sections, merged into text segment: */
14+
PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x00400000)); . = SEGMENT_START("text-segment", 0x00400000);
15+
.interp : { *(.interp) }
16+
.note.gnu.build-id : { *(.note.gnu.build-id) }
17+
.hash : { *(.hash) }
18+
.gnu.hash : { *(.gnu.hash) }
19+
.dynsym : { *(.dynsym) }
20+
.dynstr : { *(.dynstr) }
21+
.gnu.version : { *(.gnu.version) }
22+
.gnu.version_d : { *(.gnu.version_d) }
23+
.gnu.version_r : { *(.gnu.version_r) }
24+
.rela.init : { *(.rela.init) }
25+
.rela.text : { *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*) }
26+
.rela.fini : { *(.rela.fini) }
27+
.rela.rodata : { *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*) }
28+
.rela.data.rel.ro : { *(.rela.data.rel.ro .rela.data.rel.ro.* .rela.gnu.linkonce.d.rel.ro.*) }
29+
.rela.data : { *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*) }
30+
.rela.tdata : { *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*) }
31+
.rela.tbss : { *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*) }
32+
.rela.ctors : { *(.rela.ctors) }
33+
.rela.dtors : { *(.rela.dtors) }
34+
.rela.got : { *(.rela.got) }
35+
.rela.bss : { *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*) }
36+
.rela.ifunc : { *(.rela.ifunc) }
37+
.rela.plt :
38+
{
39+
*(.rela.plt)
40+
PROVIDE_HIDDEN (__rela_iplt_start = .);
41+
*(.rela.iplt)
42+
PROVIDE_HIDDEN (__rela_iplt_end = .);
43+
}
44+
.init :
45+
{
46+
KEEP (*(SORT_NONE(.init)))
47+
} =0x1f2003d5
48+
.plt : { *(.plt) *(.iplt) }
49+
.text :
50+
{
51+
*(.text.unlikely .text.*_unlikely .text.unlikely.*)
52+
*(.text.exit .text.exit.*)
53+
*(.text.startup .text.startup.*)
54+
*(.text.hot .text.hot.*)
55+
*(SORT(.text.sorted.*))
56+
*(.text .stub .text.* .gnu.linkonce.t.*)
57+
/* .gnu.warning sections are handled specially by elf.em. */
58+
*(.gnu.warning)
59+
} =0x1f2003d5
60+
.fini :
61+
{
62+
KEEP (*(SORT_NONE(.fini)))
63+
} =0x1f2003d5
64+
PROVIDE (__etext = .);
65+
PROVIDE (_etext = .);
66+
PROVIDE (etext = .);
67+
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
68+
.rodata1 : { *(.rodata1) }
69+
.eh_frame_hdr : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
70+
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
71+
.sframe : ONLY_IF_RO { *(.sframe) *(.sframe.*) }
72+
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
73+
.gnu_extab : ONLY_IF_RO { *(.gnu_extab*) }
74+
/* These sections are generated by the Sun/Oracle C++ compiler. */
75+
.exception_ranges : ONLY_IF_RO { *(.exception_ranges*) }
76+
/* Adjust the address for the data segment. We want to adjust up to
77+
the same address within the page on the next page up. */
78+
. = ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1));
79+
/* Exception handling */
80+
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
81+
.sframe : ONLY_IF_RW { *(.sframe) *(.sframe.*) }
82+
.gnu_extab : ONLY_IF_RW { *(.gnu_extab) }
83+
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
84+
.exception_ranges : ONLY_IF_RW { *(.exception_ranges*) }
85+
/* Thread Local Storage sections */
86+
.tdata :
87+
{
88+
PROVIDE_HIDDEN (__tdata_start = .);
89+
*(.tdata .tdata.* .gnu.linkonce.td.*)
90+
}
91+
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
92+
.preinit_array :
93+
{
94+
PROVIDE_HIDDEN (__preinit_array_start = .);
95+
KEEP (*(.preinit_array))
96+
PROVIDE_HIDDEN (__preinit_array_end = .);
97+
}
98+
.init_array :
99+
{
100+
PROVIDE_HIDDEN (__init_array_start = .);
101+
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
102+
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
103+
PROVIDE_HIDDEN (__init_array_end = .);
104+
}
105+
.fini_array :
106+
{
107+
PROVIDE_HIDDEN (__fini_array_start = .);
108+
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
109+
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
110+
PROVIDE_HIDDEN (__fini_array_end = .);
111+
}
112+
.ctors :
113+
{
114+
/* gcc uses crtbegin.o to find the start of
115+
the constructors, so we make sure it is
116+
first. Because this is a wildcard, it
117+
doesn't matter if the user does not
118+
actually link against crtbegin.o; the
119+
linker won't look for a file to match a
120+
wildcard. The wildcard also means that it
121+
doesn't matter which directory crtbegin.o
122+
is in. */
123+
KEEP (*crtbegin.o(.ctors))
124+
KEEP (*crtbegin?.o(.ctors))
125+
/* We don't want to include the .ctor section from
126+
the crtend.o file until after the sorted ctors.
127+
The .ctor section from the crtend file contains the
128+
end of ctors marker and it must be last */
129+
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
130+
KEEP (*(SORT(.ctors.*)))
131+
KEEP (*(.ctors))
132+
}
133+
.dtors :
134+
{
135+
KEEP (*crtbegin.o(.dtors))
136+
KEEP (*crtbegin?.o(.dtors))
137+
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
138+
KEEP (*(SORT(.dtors.*)))
139+
KEEP (*(.dtors))
140+
}
141+
.jcr : { KEEP (*(.jcr)) }
142+
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
143+
.dynamic : { *(.dynamic) }
144+
.got : { *(.got) *(.igot) }
145+
.got.plt : { *(.got.plt) *(.igot.plt) }
146+
.data :
147+
{
148+
__data_start = .;
149+
*(.data .data.* .gnu.linkonce.d.*)
150+
SORT(CONSTRUCTORS)
151+
}
152+
.data1 : { *(.data1) }
153+
_edata = .; PROVIDE (edata = .);
154+
. = .;
155+
__bss_start = .;
156+
__bss_start__ = .;
157+
.bss :
158+
{
159+
*(.dynbss)
160+
*(.bss .bss.* .gnu.linkonce.b.*)
161+
*(COMMON)
162+
/* Align here to ensure that the .bss section occupies space up to
163+
_end. Align after .bss to ensure correct alignment even if the
164+
.bss section disappears because there are no input sections.
165+
FIXME: Why do we need it? When there is no .bss section, we do not
166+
pad the .data section. */
167+
. = ALIGN(. != 0 ? 64 / 8 : 1);
168+
}
169+
_bss_end__ = .; __bss_end__ = .;
170+
. = ALIGN(64 / 8);
171+
. = SEGMENT_START("ldata-segment", .);
172+
. = ALIGN(64 / 8);
173+
__end__ = .;
174+
_end = .; PROVIDE (end = .);
175+
.stack 0x80000 :
176+
{
177+
_stack = .;
178+
*(.stack)
179+
}
180+
/* Stabs debugging sections. */
181+
.stab 0 : { *(.stab) }
182+
.stabstr 0 : { *(.stabstr) }
183+
.stab.excl 0 : { *(.stab.excl) }
184+
.stab.exclstr 0 : { *(.stab.exclstr) }
185+
.stab.index 0 : { *(.stab.index) }
186+
.stab.indexstr 0 : { *(.stab.indexstr) }
187+
.comment 0 : { *(.comment) }
188+
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
189+
/* DWARF debug sections.
190+
Symbols in the DWARF debugging sections are relative to the beginning
191+
of the section so we begin them at 0. */
192+
/* DWARF 1. */
193+
.debug 0 : { *(.debug) }
194+
.line 0 : { *(.line) }
195+
/* GNU DWARF 1 extensions. */
196+
.debug_srcinfo 0 : { *(.debug_srcinfo) }
197+
.debug_sfnames 0 : { *(.debug_sfnames) }
198+
/* DWARF 1.1 and DWARF 2. */
199+
.debug_aranges 0 : { *(.debug_aranges) }
200+
.debug_pubnames 0 : { *(.debug_pubnames) }
201+
/* DWARF 2. */
202+
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
203+
.debug_abbrev 0 : { *(.debug_abbrev) }
204+
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
205+
.debug_frame 0 : { *(.debug_frame) }
206+
.debug_str 0 : { *(.debug_str) }
207+
.debug_loc 0 : { *(.debug_loc) }
208+
.debug_macinfo 0 : { *(.debug_macinfo) }
209+
/* SGI/MIPS DWARF 2 extensions. */
210+
.debug_weaknames 0 : { *(.debug_weaknames) }
211+
.debug_funcnames 0 : { *(.debug_funcnames) }
212+
.debug_typenames 0 : { *(.debug_typenames) }
213+
.debug_varnames 0 : { *(.debug_varnames) }
214+
/* DWARF 3. */
215+
.debug_pubtypes 0 : { *(.debug_pubtypes) }
216+
.debug_ranges 0 : { *(.debug_ranges) }
217+
/* DWARF 5. */
218+
.debug_addr 0 : { *(.debug_addr) }
219+
.debug_line_str 0 : { *(.debug_line_str) }
220+
.debug_loclists 0 : { *(.debug_loclists) }
221+
.debug_macro 0 : { *(.debug_macro) }
222+
.debug_names 0 : { *(.debug_names) }
223+
.debug_rnglists 0 : { *(.debug_rnglists) }
224+
.debug_str_offsets 0 : { *(.debug_str_offsets) }
225+
.debug_sup 0 : { *(.debug_sup) }
226+
.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
227+
.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
228+
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
229+
}

0 commit comments

Comments
 (0)