diff --git a/examples/rust-gcoap/Cargo.lock b/examples/rust-gcoap/Cargo.lock index d2b74b687f..b994dcef61 100644 Binary files a/examples/rust-gcoap/Cargo.lock and b/examples/rust-gcoap/Cargo.lock differ diff --git a/examples/rust-gcoap/Cargo.toml b/examples/rust-gcoap/Cargo.toml index 7bb7b50be4..99d15c69d8 100644 --- a/examples/rust-gcoap/Cargo.toml +++ b/examples/rust-gcoap/Cargo.toml @@ -19,14 +19,22 @@ codegen-units = 1 opt-level = "s" [dependencies] -riot-wrappers = { version = "^0.9.0", features = [ "set_panic_handler", "panic_handler_format", "with_coap_message", "with_coap_handler" ] } +riot-wrappers = { version = "^0.9.0", features = [ "set_panic_handler", "panic_handler_format", "with_coap_message", "with_coap_handler", "provide_critical_section_1_0" ] } +portable-atomic = { version = "1", features = [ "critical-section" ] } coap-message-demos = { git = "https://gitlab.com/chrysn/coap-message-demos/", default-features = false } coap-handler-implementations = "0.5" -riot-coap-handler-demos = { git = "https://gitlab.com/etonomy/riot-module-examples/", features = [ "vfs", "saul" ] } +riot-coap-handler-demos = { git = "https://gitlab.com/etonomy/riot-module-examples/", features = [ "vfs", "saul", "nib", "ping" ] } # While currently this exmple does not use any RIOT modules implemented in # Rust, that may change; it is best practice for any RIOT application that has # its own top-level Rust crate to include rust_riotmodules from inside # RIOTBASE. rust_riotmodules = { path = "../../sys/rust_riotmodules/" } +static_cell = "2.1.0" + +[patch.crates-io] +# from https://github.com/seanmonstar/try-lock/pull/11, necessary for those +# platforms without atomics (which also needs provide_critical_section_1_0 from +# riot-wrappers, and portable-atomic/critical-section to bridge the gap) +try-lock = { git = "https://github.com/seanmonstar/try-lock", rev = "45c39685b56a4dba1b71bdbbbe5f731c3c77dc50" } diff --git a/examples/rust-gcoap/Makefile b/examples/rust-gcoap/Makefile index 418cfb0608..e610f585cd 100644 --- a/examples/rust-gcoap/Makefile +++ b/examples/rust-gcoap/Makefile @@ -19,6 +19,8 @@ USEMODULE += ztimer_usec USEMODULE += ztimer_msec USEMODULE += ztimer_sec +USEMODULE += gnrc_netapi_callbacks + # for the "vfs" feature of riot-coap-handler-demos (and vfs.c) USEMODULE += vfs USEMODULE += constfs @@ -34,13 +36,12 @@ DEVELHELP ?= 1 # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 -# Add 8k extra stack: The Rust examples take more of it than gcoap expects, -# presumably because the example use the standard library's sting formatting -# instead of one of the more optimized formatters. -CFLAGS += -DGCOAP_STACK_SIZE='(THREAD_STACKSIZE_DEFAULT+DEBUG_EXTRA_STACKSIZE+sizeof(coap_pkt_t)+8192)' +# Add 12k extra stack: The Rust examples take more of it than gcoap expects, +# for reasons that are not fully understood (it's not the string formatter). +CFLAGS += -DGCOAP_STACK_SIZE='(THREAD_STACKSIZE_DEFAULT+DEBUG_EXTRA_STACKSIZE+sizeof(coap_pkt_t)+12288)' # This thread needs some more stack for printing the addresses, once more being # hit by string formatting. -CFLAGS += -DTHREAD_STACKSIZE_MAIN='(THREAD_STACKSIZE_DEFAULT+THREAD_EXTRA_STACKSIZE_PRINTF+2048)' +CFLAGS += -DTHREAD_STACKSIZE_MAIN='(THREAD_STACKSIZE_DEFAULT+THREAD_EXTRA_STACKSIZE_PRINTF+1024)' # The name of crate (as per Cargo.toml package name, but with '-' replaced with '_') APPLICATION_RUST_MODULE = rust_gcoap diff --git a/examples/rust-gcoap/Makefile.ci b/examples/rust-gcoap/Makefile.ci index 6d79d2b9fc..cf8d98ffa9 100644 --- a/examples/rust-gcoap/Makefile.ci +++ b/examples/rust-gcoap/Makefile.ci @@ -1,5 +1,6 @@ BOARD_INSUFFICIENT_MEMORY := \ airfy-beacon \ + arduino-mkr1000 \ b-l072z-lrwan1 \ blackpill-stm32f103c8 \ blackpill-stm32f103cb \ @@ -12,6 +13,7 @@ BOARD_INSUFFICIENT_MEMORY := \ cc2650stk \ e104-bt5010a-tb \ e104-bt5011a-tb \ + feather-m0-wifi \ gd32vf103c-start \ hifive1 \ hifive1b \ @@ -21,7 +23,6 @@ BOARD_INSUFFICIENT_MEMORY := \ lsn50 \ maple-mini \ microbit \ - microbit-v2 \ nrf51dongle \ nrf6310 \ nucleo-c031c6 \ @@ -34,10 +35,15 @@ BOARD_INSUFFICIENT_MEMORY := \ nucleo-f302r8 \ nucleo-f303k8 \ nucleo-f334r8 \ + nucleo-f410rb \ + nucleo-g070rb \ + nucleo-g071rb \ + nucleo-g431rb \ nucleo-l011k4 \ nucleo-l031k6 \ nucleo-l053r8 \ nucleo-l073rz \ + nucleo-l412kb \ olimexino-stm32 \ opencm904 \ samd10-xmini \ diff --git a/examples/rust-gcoap/README.md b/examples/rust-gcoap/README.md index 5d8a5b42f1..42835e531e 100644 --- a/examples/rust-gcoap/README.md +++ b/examples/rust-gcoap/README.md @@ -51,3 +51,7 @@ Once that is ready, in a parallel shell, run: ``` $ aiocoap-client 'coap://[2a02:0b18:c13b:8018:1234:56ff:fe78:90ab]/.well-known/core' ``` + +Note that no security is enabled by default so far; this is considered a bug. +To mitigate this, no controls that are expected to be harmful are exposed in this example. +(For example, while LEDs are exposed, GPIO pins are not, for they might not tolerate driving to some level depending on the hardware connected to them). diff --git a/examples/rust-gcoap/src/lib.rs b/examples/rust-gcoap/src/lib.rs index 538a508665..1b15ac8c09 100644 --- a/examples/rust-gcoap/src/lib.rs +++ b/examples/rust-gcoap/src/lib.rs @@ -6,7 +6,7 @@ #![no_std] use riot_wrappers::{riot_main, println}; -use riot_wrappers::{gcoap, thread, ztimer, gnrc}; +use riot_wrappers::{gcoap, ztimer, gnrc}; use coap_handler_implementations::{ReportingHandlerBuilder, HandlerBuilder}; @@ -21,16 +21,30 @@ fn main() { unsafe { do_vfs_init() }; + static PINGS: riot_coap_handler_demos::ping::PingPool = riot_coap_handler_demos::ping::PingPool::new(); + static PING_PASSIVE: riot_coap_handler_demos::ping_passive::PingHistoryMutex<{ riot_coap_handler_demos::ping_passive::DEFAULT_SIZE }> = riot_coap_handler_demos::ping_passive::PingHistoryMutex::new(); + let handler = coap_message_demos::full_application_tree(None) .below(&["ps"], riot_coap_handler_demos::ps::ps_tree()) + .below(&["led"], riot_coap_handler_demos::led::all_leds()) .below(&["vfs"], riot_coap_handler_demos::vfs::vfs("")) .below(&["saul"], riot_coap_handler_demos::saul::SaulHandler::new(&["saul"])) + .below(&["netif"], riot_coap_handler_demos::netif::netif()) + .below(&["nib", "neigh"], riot_coap_handler_demos::nib::neighbor_cache()) + .below(&["ping"], riot_coap_handler_demos::ping::ping_tree(&PINGS)) + .at(&["pinged"], riot_coap_handler_demos::ping_passive::resource(&PING_PASSIVE)) .with_wkc() ; let mut handler = riot_wrappers::coap_handler::v0_2::GcoapHandler(handler); let mut listener = gcoap::SingleHandlerListener::new_catch_all(&mut handler); + static SLOT: static_cell::StaticCell> = static_cell::StaticCell::new(); + PINGS.register(SLOT.init(Default::default())); + + static PASSIVE_SLOT: static_cell::StaticCell>> = static_cell::StaticCell::new(); + PING_PASSIVE.register(PASSIVE_SLOT.init(Default::default())); + gcoap::scope(|greg| { greg.register(&mut listener); @@ -55,6 +69,9 @@ fn main() { // Sending main thread to sleep; can't return or the Gcoap handler would need to be // deregistered (which it can't). - loop { thread::sleep(); } + loop { + PINGS.tick(); + sectimer.sleep(ztimer::Ticks(1)); + } }) }