ChanServ changed the topic of #rust-embedded to: Welcome to the Rust Embedded IRC channel! Bridged to #rust-embedded:matrix.org and logged at https://libera.irclog.whitequark.org/rust-embedded, code of conduct at https://www.rust-lang.org/conduct.html
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
_whitelogger has joined #rust-embedded
duderonomy has joined #rust-embedded
IlPalazzo-ojiisa has joined #rust-embedded
bpye has quit [Quit: Ping timeout (120 seconds)]
bpye has joined #rust-embedded
emerent has quit [Ping timeout: 248 seconds]
emerent has joined #rust-embedded
GenTooMan has quit [Ping timeout: 256 seconds]
GenTooMan has joined #rust-embedded
<re_irc> <@dirbaio:matrix.org> wow this is jank. Works:
<re_irc> #[interrupt]
<re_irc> Fails:
<re_irc> unsafe fn SWI1_EGU1() { .. }
<re_irc> use foobar_pac::interrupt;
<re_irc> use foobar_pac::interrupt::{self, ....};
<re_irc> #[interrupt] // cannot determine resolution for the attribute macro `interrupt`
<re_irc> unsafe fn SWI1_EGU1() { .. }
<re_irc> <@dirbaio:matrix.org> "use pac::interrupt::{self}" imports the "interrupt" mod, but not the macro
<re_irc> vs "use pac::interrupt" imports both the mod and macro.
<re_irc> <@dirbaio:matrix.org> and rust-analyzer loves autoimporting with the "self" style 😭
<re_irc> <@dkhayes117:matrix.org> I ran into that the other day, but I didn't know why it didn't work with self. Now I know, interesting.
<re_irc> <@romancardenas:matrix.org> I have another question regarding safety etc. when dealing with peripherals. If a generic register is defined as follows:
<re_irc> #[derive(Clone, Copy, Debug, Eq, PartialEq)]
<re_irc> #[repr(transparent)]
<re_irc> pub struct Reg<T: Copy, A: Access> {
<re_irc> pub ptr: *mut T,
<re_irc> phantom: PhantomData<A>,
<re_irc> }
<re_irc> and I perform volatile read/writes, then:
<re_irc> 1. should the "new(...)" function be "unsafe" with a safety condition of "ptr" being valid?
<re_irc> 2. I guess "read()" should be unsafe with a safety condition of avoiding "read-modify-write" operations
<re_irc> 3. Then... "write()" would be safe?
<re_irc> Sorry if I'm saying nonsense stuff
<re_irc> - new() safe, read/write unsafe because they can be used to dereference arbitrary pointers
<re_irc> <@dirbaio:matrix.org> you can either make
<re_irc> or
<re_irc> - new() unsafe, read/write safe
<re_irc> <@dirbaio:matrix.org> RMW races on volatile registers are not Undefined Behavior, they're just wrong behavior
<re_irc> <@dirbaio:matrix.org> (this is still somewhat controversial, see discussion from that linked message)
<re_irc> <@romancardenas:matrix.org> Hmm... I personally like the idea of making "new" unsafe so PACs can ensure the safety of deferring the pointer. Almost everything would avoid "unsafe" scary sections
<re_irc> <@dirbaio:matrix.org> also if you do "new() unsafe, read/write safe", then make sure the ptr is not "pub", otherwise the user can overwrite it with any pointer (safe) and then call read/write (safe), dereferencing arbitrary pointers
<re_irc> <@romancardenas:matrix.org> good catch
<re_irc> <@dirbaio:matrix.org> yeah, in chiptool I did "new() safe, read/write unsafe"
<re_irc> <@dirbaio:matrix.org> and I somewhat regret it
<re_irc> <@dirbaio:matrix.org> the motivation was "prevent RMW races" but now my opinion is they're not UB..
<re_irc> <@dirbaio:matrix.org> * because it leads to unsafe EVERYWHERE
<re_irc> <@romancardenas:matrix.org> Well, theoretically pointers can still be public, as deferring them is unsafe
<re_irc> <@dirbaio:matrix.org> the motivation was "prevent RMW races" but now my opinion is they're not UB..
<re_irc> <@romancardenas:matrix.org> And it will make some pointer arithmetics easier with more complex register sets
<re_irc> <@dirbaio:matrix.org> : making the field public allows the user to _write_ to it
<re_irc> <@dirbaio:matrix.org> ie change the pointer with a completely different one=
<re_irc> <@dirbaio:matrix.org> * one
<re_irc> <@dirbaio:matrix.org> * for
<re_irc> <@romancardenas:matrix.org> Oh true
<re_irc> <@dirbaio:matrix.org> it's fine if you offer a readonly getter
<re_irc> <@romancardenas:matrix.org> yep, I'll do that. I'll work in a PoC for the "riscv" crate and add it to one of our meeting's agenda so we can have a discussion about this approach. Thanks for the feedback!
<re_irc> <@thejpster:matrix.org> So you should know I rewrote a bunch of the blocking SD card crate.
<re_irc> <@thejpster:matrix.org> Wish we had keyword generics so we didn’t have to fork it.
m5zs7k has quit [Ping timeout: 246 seconds]
m5zs7k has joined #rust-embedded
dc740 has joined #rust-embedded
duderonomy has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dc740 has quit [Remote host closed the connection]
IlPalazzo-ojiisa has quit [Ping timeout: 268 seconds]
IlPalazzo-ojiisa has joined #rust-embedded