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
IsaBang[m] has quit [Quit: Idle timeout reached: 172800s]
HumanG33k has quit [Ping timeout: 252 seconds]
HumanG33k has joined #rust-embedded
AlexandrosLiarok has joined #rust-embedded
<AlexandrosLiarok> What is the best way to define a shared struct between cores at shared memory and access it without causing immediate UB ?
<diondokter[m]> <AlexandrosLiarok> "eg embassy currently does some..." <- Why do you think this is UB?
<diondokter[m]> AFAIK, any combination of underlying bits should yield a valid value for the struct
<diondokter[m]> Oh, I thought it was legal to do on integers, but apparently not according to the docs
<AlexandrosLiarok> I think I have an idea on what to do about this, give me a minute. This is pretty underspecified on Rust really.
<diondokter[m]> Has this changed? Because I've thought that for the past couple of years haha
<diondokter[m]> This section is probably what we should do:
<AlexandrosLiarok> There is also a chance that the Uninit will read the magic value on startup. This could happen for example on soft reset if someone used backup memory for the shared data.
<diondokter[m]> Yeah I know... I don't really know how to solve that
<AlexandrosLiarok> something like this protocol.
<diondokter[m]> Yeah, but then you're assuming the second core will always run
<diondokter[m]> Might not be the case
<AlexandrosLiarok> yea true in which case we may just want a variant that won't lock for the primary core. I don't really have a solution here just brainstorming.
cr1901_ has joined #rust-embedded
cr1901 has quit [Read error: Connection reset by peer]
lehmrob has joined #rust-embedded
Darius has quit [Ping timeout: 248 seconds]
Darius has joined #rust-embedded
<AlexandrosLiarok> diondokter: I was thinking something like this: https://rust.godbolt.org/z/PY98d9jsW
Socke has quit [Ping timeout: 255 seconds]
Socke has joined #rust-embedded
<diondokter[m]> <AlexandrosLiarok> "diondokter: I was thinking..." <- I don't think this works because with this each core would initialize the shared data
<diondokter[m]> Hmmm I see. It might work. But only if both cores are booting at the same time.
<diondokter[m]> And also, both cores initialize the shared data. But this is done none-atomically, so not sure if that's allowed.
<diondokter[m]> Maybe this can help?
Socke has quit [Ping timeout: 248 seconds]
<AlexandrosLiarok> The memory model does not help with this stuff. I do think we need to handle this better but there are UB minefields everywhere.
<AlexandrosLiarok> Even as it is it should work in practice but that's famous last words.
<AlexandrosLiarok> Could stop working anytime.
Socke has joined #rust-embedded
<AlexandrosLiarok> This is similar to issues that arise from usage of mmap
lehmrob has quit [Quit: Konversation terminated!]
Socke has quit [Ping timeout: 248 seconds]
Socke has joined #rust-embedded
djdisodo[m] has joined #rust-embedded
<djdisodo[m]> i want to write a driver for i2c, is there shared async i2c interface on embedded-hal?
<ryan-summers[m]> The docs on the embedded-hal I2C trait explain what you should do djdisodo : https://docs.rs/embedded-hal/latest/embedded_hal/i2c/index.html#for-driver-authors
<ryan-summers[m]> The tl;dr is don't do any sharing yourself. There are external crates that rust-embedded manages (embedded-hal-bus specifically does this for you)
<djdisodo[m]> <ryan-summers[m]> "The docs on the embedded-hal I2C..." <- this is not for async
<ryan-summers[m]> I believe the same principles apply to the embedded-hal-async
<ryan-summers[m]> Yeah, embedded-hal-bus specifically talks about async also being supported here: https://docs.rs/embedded-hal-bus/latest/embedded_hal_bus/#optional-cargo-features
<ryan-summers[m]> Although https://github.com/rust-embedded/embedded-hal/issues/572 may be relevant
<ryan-summers[m]> Sounds like bus sharing on async is hard because the mutex type is nonstandard. Probably best to look at what embassy does
<ryan-summers[m]> But I would imagine the same principles applie as I referenced, where sharing is handled entirely externally to the driver implementation
<ryan-summers[m]> s/applie/apply/
<djdisodo[m]> <ryan-summers[m]> "But I would imagine the same..." <- so it seems like i don't have to care when implementing driver
<djdisodo[m]> but it seems like i should use embassy-embedded-hal when i need shared i2c bus since embedded-hal-bus doesn't support it
<ryan-summers[m]> Yeah, you'd use embassy-embedded-hal once you've implemented the driver. But don't implement the driver with dependencies on embassy, or you'll block anyone that wants to use it outside of embassy as well
<djdisodo[m]> btw embassy one doesn't seem to implement embedded-hal-async traits either, only has some bounds on them
<djdisodo[m]> wonder why....
<djdisodo[m]> nah it does
<djdisodo[m]> nice
<ryan-summers[m]> For anyone interested, I did some interesting stuff with C/Rust/bindgen stuff and embedded sensors and it ended up making life pretty easy for me, even though the firmware was in C. Wrote up a quick blog about it: https://blog.forged.dev/rust-for-c-projects/
<ryan-summers[m]> s/stuff//
<ryan-summers[m]> 100% open to constructive feedback on the post by the way, would like to do more interesting embedded blogging in the future :)
takkaryx[m] has quit [Quit: Idle timeout reached: 172800s]
YuhanLin[m] has quit [Quit: Idle timeout reached: 172800s]
Amit[m] has quit [Quit: Idle timeout reached: 172800s]
JamesSizeland[m] has quit [Quit: Idle timeout reached: 172800s]
sourcebox[m] has quit [Quit: Idle timeout reached: 172800s]
freakingpenguin has joined #rust-embedded
ejpcmac[m] has quit [Quit: Idle timeout reached: 172800s]
vollbrecht[m] has quit [Quit: Idle timeout reached: 172800s]
bartmassey[m] has quit [Quit: Idle timeout reached: 172800s]
Henk[m] has quit [Quit: Idle timeout reached: 172800s]
rmsyn[m] has quit [Quit: Idle timeout reached: 172800s]
jannic[m] has quit [Quit: Idle timeout reached: 172800s]
adamgreig[m] has quit [Quit: Idle timeout reached: 172800s]
braincode[m] has quit [Quit: Idle timeout reached: 172800s]
cr1901_ is now known as cr1901
dirbaio[m] has quit [Quit: Idle timeout reached: 172800s]