From c3724af35bf99a4683237f85e2eac1cbf6b97bc0 Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 26 Aug 2024 15:34:56 +0200 Subject: [PATCH 1/9] examples/rust-gcoap: Expose LEDs --- examples/rust-gcoap/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/rust-gcoap/src/lib.rs b/examples/rust-gcoap/src/lib.rs index 538a508665..344432f0f8 100644 --- a/examples/rust-gcoap/src/lib.rs +++ b/examples/rust-gcoap/src/lib.rs @@ -23,6 +23,7 @@ fn main() { 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"])) .with_wkc() From 7b78cc1f71e1f9f49aa55fb9e2eaaeab439fd3bd Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 26 Aug 2024 15:48:24 +0200 Subject: [PATCH 2/9] examples/rust-gcoap: Expose netif demo --- examples/rust-gcoap/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/rust-gcoap/src/lib.rs b/examples/rust-gcoap/src/lib.rs index 344432f0f8..a23dfd2e31 100644 --- a/examples/rust-gcoap/src/lib.rs +++ b/examples/rust-gcoap/src/lib.rs @@ -26,6 +26,7 @@ fn main() { .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()) .with_wkc() ; let mut handler = riot_wrappers::coap_handler::v0_2::GcoapHandler(handler); From bfcc25a9c3a9dfa0cb7ff114cb18e6354aedd8cc Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 26 Aug 2024 15:47:42 +0200 Subject: [PATCH 3/9] examples/rust-gcoap: Point out security situation --- examples/rust-gcoap/README.md | 4 ++++ 1 file changed, 4 insertions(+) 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). From 9f3bb827f4d6c4d77738ec03af6767005215472e Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 26 Aug 2024 16:23:58 +0200 Subject: [PATCH 4/9] examples/rust-gcoap: Update stack size Tests with a particle-xenon show 5KiB free stack now; before, that would have been an overflow by 3KiB. --- examples/rust-gcoap/Makefile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/rust-gcoap/Makefile b/examples/rust-gcoap/Makefile index 418cfb0608..2137478bcd 100644 --- a/examples/rust-gcoap/Makefile +++ b/examples/rust-gcoap/Makefile @@ -34,10 +34,9 @@ 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 16k 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)+16384)' # 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)' From 84354ffb8061a3c3e8b299636100905ca7a81a75 Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 26 Aug 2024 15:49:30 +0200 Subject: [PATCH 5/9] examples/rust-gcoap: Update external module dependency This updates riot-sys, riot-wrappers and the riot-example-modules in for this example, as all those are needed for full LED exposure, as well as coap-message-utils for better error responses. An update to coap-handler-implementations enables the use of the latest riot-examples-modules. --- examples/rust-gcoap/Cargo.lock | Bin 27096 -> 27155 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/examples/rust-gcoap/Cargo.lock b/examples/rust-gcoap/Cargo.lock index d2b74b687f0eef65b360528de0756ee14a40d7bc..38bc8beb17d497f73675a49ea89a949dcea559e2 100644 GIT binary patch delta 507 zcma)&y=s(E5Qh06jSw-x-3@3HOp`)k=KP<=1SBRKa7}OHnLnb~tsr_C9=rgtvJ>_S z0ydVSMf#-h2JHP-ya3x_=9%|-FMkaE=kVq0)`0!{&8LS(EUsyz5_4=C34tN7#uO@x z2Sm@Aoq#}z?5n3-Tk^%kr&eO<+dH%Va{Kq-N8H&%=0?E`fw(n7$p)C&2W_zyt>#d$ zj00!Mpd`tSBo-hD=%DtCquFZX_J^UrzjJoLo*Lu?poJy0M3z-S%!O*45>csCIEkw8 z7?^^N>99J*K;FX$+gTkxVa_!JA(wz)+Wxt0^ktV@6ijYFzu_x;rl>prd^Sb$yNad~&t##T975LiDC7MnyJJ%6VKj Stl5E!ED+WQt8epLyMF+cXPFWJ delta 484 zcma)&ziZS%5XJd|=>p!7*k<-uX*!E^R`!nnf_>or z1$zrE>@|=-Bb&zB_VM0__n!Tle*c_qzt8O5i_K}rK-`(CvU5eXd5>NsD*{Rt^c-6h z0BHr<@FqwxIuEXg1~FutA1>_2)y!_@clK$qIUVu{M$v)wg=;U}v#%;86^<$`I0AMl zrp6@6bL$j=I_4sdg>BkhYu9I25^FyQkPh`kH@J< xV@Fy7azHG8TybE3*MC+yCL+Zg#zh`Ug|dKe(jWEWW6EA4QGX0 Date: Mon, 16 Sep 2024 20:07:32 +0200 Subject: [PATCH 6/9] examples/rust-gcoap: Add ping, passive ping and nib resources --- examples/rust-gcoap/Cargo.lock | Bin 27155 -> 28904 bytes examples/rust-gcoap/Cargo.toml | 3 ++- examples/rust-gcoap/Makefile | 2 ++ examples/rust-gcoap/src/lib.rs | 19 +++++++++++++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/rust-gcoap/Cargo.lock b/examples/rust-gcoap/Cargo.lock index 38bc8beb17d497f73675a49ea89a949dcea559e2..0cf8a6723822a731743d896d983bcee9b4ba9f33 100644 GIT binary patch delta 1721 zcma)7OK(+G6wc+gflCVl(%#l8xm4l{d)@E7wn18gP(XtPL9LI-eyklE%Dqi{W5kJZ z?jvE3aKzNaf#k$6!jW;}07;xH#zg)Aaq7C4@+cEMqqFxpXRq~r>-)Y_eyiQSRr`Mb zaK(qqNcntxVJ;xEfZ$~286f%~ISQXa2D%)JNoPQZPD@acwp36$LekQvoKfnsvpHUF zoZC@8-TB#6i?z9H^XV72wx%yEb(Ui2uF{@RZFOmWtlGY7rM`LnopNYos=7S(!)W6p zzdYmDE_P!1a<89bQAGnf1k5%gmr+KOl1g3}P#lwVz%WaRw2CQZ&viubkOLtAP^C6H zR{mJrR_AS2Zo!k~$n;Mm7Xqe)X{O_s%efIhn}WlPF=*?9R@plaRs$`S2MpU`}eSEwe-o3lo2`%2HLIc2^?#x<`YGAM2+%q-#P|cZMT)|Iz z*jZcZcGk+f2MA^sXqCy@C}|;UE$MJbU>JZ-R-yNxvoa!t1U3b!z)KW1<|vJjY#nB! z-iLJMXtUf|Y*t&IUf5L*H^$0$syWmrz3e@+FzW)UY#1t@6DkWq8s{JYfZ$FU@3W6u zG1O8!j@G20r4!t<7=_SbQ0crrR@ZHQ_dM&9VM0X4lsEKgW;qC;MyW3&xk}nAOwk&P z+Vlkzqkg}eSNk-zUTICUwl1e$I5o#Z z#E41;E~IjfTV&1*hHngKR#=+9tsU2a5FK0+Brq6Dx@(RD~vAuz(n=S z?2X~)oX~>C7a%5}7c8|DB@*c@OPwu=75k*S`+mHAGI?8 z#S3V=(a<7Mc?*Zc27AfXQ$et6>%V|{hvVB>)a ze?D=tyfnYByz|<(+gj6WJ>Of3A4XhW?nA03UjL_7uC^BDz{fyr22eH%MH!%lHilv- zS*yVa=B?litR_tn&uFtTGDeaW4G1U<`hoMsP@}qj^6cj7##^U1O*|;IK@_62X5XAk z-~yv8qpb1(Qb{gAq`*nvN@l4%IVESZsG<1F%5!6s<}Mh6Tt$xkdXKGa)ZPG5Yw@p5 zlj~F4P?rLjjC6C`8wXL5uY;#NC1;Sih1FyO^eP#`?8sdlg3XL}O%BmTmJv+wRyspS zS3a1m>hC`@R2!T&8!@lW)?@N-a14JZk{$8OC8RYw9HASQ^ulYg_Yc6(7<^B zWKIRCv#}rrqL$i#=0fD819wSiQ~Z{zJ7=cq)#}-;+5mUtC;A;IT3iGnjSkAG>_FM5 zxaQs$i6|skt6cP+gT@rCjzVWdk#gcDI6?mKc=e-muU@Hh?}uhf8_6c+%A1hUx+3M0 zl{QA>3=2G#%q%DW@ALf&n>5osNmsi!>345}es$A-iBwM(R%(B@DFsf_zQtqo_WV&g zeQ}aj7aOyH!ZI(jR8YE5D)E>x1!Dkn=FSKvR7AEr$J50}^u_vV}H*V64N*5++a zZ@QzzTGRA-X^4ZTQ8<`quKA6jF|_AK^g(fIzXed_b9d@(#(~6 zjoLdQ%MXe#I)(u?I0ZTc+}-BgB^;=ZT=_asZHDQ=owU(OYmlST$`^Iz63@s26j&j% jlE{PzMj=S+bu3V2Q6dY+O<|sa`ZwO=wYlokTC?#7ou%;X diff --git a/examples/rust-gcoap/Cargo.toml b/examples/rust-gcoap/Cargo.toml index 7bb7b50be4..c461e5e75b 100644 --- a/examples/rust-gcoap/Cargo.toml +++ b/examples/rust-gcoap/Cargo.toml @@ -23,10 +23,11 @@ riot-wrappers = { version = "^0.9.0", features = [ "set_panic_handler", "panic_h 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" diff --git a/examples/rust-gcoap/Makefile b/examples/rust-gcoap/Makefile index 2137478bcd..980208bcaa 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 diff --git a/examples/rust-gcoap/src/lib.rs b/examples/rust-gcoap/src/lib.rs index a23dfd2e31..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,18 +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); @@ -57,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)); + } }) } From 5eaa09a872a4793713ea05898388357433206da3 Mon Sep 17 00:00:00 2001 From: chrysn Date: Mon, 16 Sep 2024 23:12:56 +0200 Subject: [PATCH 7/9] examples/rust-gcoap: Tighten stack sizes This still leaves a comfortable 976 byte on the gcoap stack, and 812 on main -- and makes the application fit on way more boards. --- examples/rust-gcoap/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/rust-gcoap/Makefile b/examples/rust-gcoap/Makefile index 980208bcaa..e610f585cd 100644 --- a/examples/rust-gcoap/Makefile +++ b/examples/rust-gcoap/Makefile @@ -36,12 +36,12 @@ DEVELHELP ?= 1 # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 -# Add 16k extra stack: The Rust examples take more of it than gcoap expects, +# 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)+16384)' +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 From 455b19962e47750a6d59055d79f9f724e631bf6a Mon Sep 17 00:00:00 2001 From: chrysn Date: Tue, 17 Sep 2024 09:21:11 +0200 Subject: [PATCH 8/9] examples/rust-gcoap: Use patched try-lock version for armv6 devices --- examples/rust-gcoap/Cargo.lock | Bin 28904 -> 29022 bytes examples/rust-gcoap/Cargo.toml | 9 ++++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/rust-gcoap/Cargo.lock b/examples/rust-gcoap/Cargo.lock index 0cf8a6723822a731743d896d983bcee9b4ba9f33..b994dcef61fa9784c83fc1af73d6c5fc5401d3f8 100644 GIT binary patch delta 180 zcmaFykn!Fl#trhWlbN}NCo3~)Z8mY;$TeAoNoeyU|JjWE1^GoKiAg!Bx``$ExtYnE zD*{&wOwJYNpFCHbBda(yF)ueiuec)illA*f7~R+1xxO+0;OpScQ`rxy2@biqqJ Date: Wed, 18 Sep 2024 17:38:34 +0200 Subject: [PATCH 9/9] examples/rust-gcoap: Regenerate Makefile.ci --- examples/rust-gcoap/Makefile.ci | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 \