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
<re_irc> <harcrow> Hi Everyone. I'm a hardware person trying to keep up with the embedded FW world. I've been trying to work with and understand the stm32f4xx_hal, and am struggling to understand how some of the type alias syntax is derived. In an example setting up I2C w/ DMA -- ```pub type I2c1Handle = I2CMasterDma<
<re_irc> I2C1, // Instance of I2C
<re_irc> (PB8<AF4<OpenDrain>>, PB9<AF4<OpenDrain>>), // Pins
<re_irc> ...
<re_irc> <harcrow> Hi Everyone. I'm a hardware person trying to keep up with the embedded FW world. I've been trying to work with and understand the stm32f4xx_hal, and am struggling to understand how some of the type alias syntax is derived. In an example setting up I2C w/ DMA --
<re_irc> pub type I2c1Handle = I2CMasterDma<
<re_irc> (PB8<AF4<OpenDrain>>, PB9<AF4<OpenDrain>>), // Pins
<re_irc> I2C1, // Instance of I2C
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #rust-embedded
<re_irc> < (@dkhayes117:matrix.org)> I want to have a "&'a str" in a struct with the "#[derive(Deserialize)]". For example
<re_irc> struct TempSensor<'a> {
<re_irc> #[derive(Format, Serialize, Deserialize)]
<re_irc> temp: f32,
<re_irc> < (@dkhayes117:matrix.org)> * there
<re_irc> < (@jamesmunns:beeper.com)> serde.rs has a good overview of the lifetimes here
<re_irc> < (@jamesmunns:beeper.com)> In general, it means your deserializer library either doesn't support borrowed data, or doesnt have the right lifetime signature
<re_irc> < (@jamesmunns:beeper.com)> Specifically https://serde.rs/lifetimes.html ^
<re_irc> < (@jamesmunns:beeper.com)> If you have a public repo that reproduces it, I can take a quick look
<re_irc> < (@jamesmunns:beeper.com)> Or if you can link me to the deserializer
<re_irc> < (@dkhayes117:matrix.org)> I read through that some and understand it on a high level, but not enough to solve my problem.
<re_irc> I know that deserialize implements the `<'de>` lifetime and it has ensure that <'de> lives longer than <'a>.
<re_irc> That's all I know so far :).
<re_irc> < (@jamesmunns:beeper.com)> cloning...
<re_irc> < (@dkhayes117:matrix.org)> Specific function is `lightdb_state_read` in lib.rs
<re_irc> < (@jamesmunns:beeper.com)> rust-analyzer loading...
<re_irc> < (@dkhayes117:matrix.org)> * `lightdb_read_state`
<re_irc> < (@jamesmunns:beeper.com)> Ah shoot, c libs aren't building
<re_irc> < (@jamesmunns:beeper.com)> Okay, stubbed that out, it builds for me on main, do you have a commit that fails?
<re_irc> < (@dkhayes117:matrix.org)> Oh sorry, remove this line from /bin/main.rs
<re_irc> < (@jamesmunns:beeper.com)> oh
<re_irc> < (@jamesmunns:beeper.com)> yeah, you are trying to borrow from a packet that gets dropped at the end of that function
<re_irc> < (@jamesmunns:beeper.com)> so... you can't do that.
<re_irc> < (@dkhayes117:matrix.org)> Oh, I see what you are saying.
<re_irc> < (@jamesmunns:beeper.com)> You could used an owned type, like an "alloc::String" or "heapless::String", but you can't return data that borrows from a temporary that is dropped.
<re_irc> < (@dkhayes117:matrix.org)> I had it stuck in my head that it was the struct I created in main is what was being deserialized, but that's totally wrong.
<re_irc> < (@jamesmunns:beeper.com)> it's more immediately complaining that your type bound is "<T: DeserializeOwned>", which doesn't support borrowed data
<re_irc> < (@jamesmunns:beeper.com)> (the serde docs talk about "Deserialize<'de>" vs "DeserializeOwned", which is basically "Deserialize<'static>"
<re_irc> < (@jamesmunns:beeper.com)> you could loosen the bound, which would allow you to used the borrowed deser'd data inside of that function, but not longer than "response" lives.
<re_irc> < (@jamesmunns:beeper.com)> (so no returning the "T")
<re_irc> < (@dkhayes117:matrix.org)> Okay, I understand what's going on now. Thanks for the knowledge!
<re_irc> < (@jamesmunns:beeper.com)> IF you received the data outside that function, your signature could look something like:
<re_irc> pub async fn lightdb_read_state<'de, T: Deserialize<'de>>(
<re_irc> path: &str,
<re_irc> &mut self,
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #rust-embedded
IlPalazzo-ojiisa has quit [Quit: Leaving.]
<re_irc> < (@halfbit:matrix.org)> This is like the coolest part of rust to me, in C++/C this would a horror show
<re_irc> < (@halfbit:matrix.org)> * one of
<re_irc> < (@halfbit:matrix.org)> * parts
<re_irc> < (@halfbit:matrix.org)> Perfectly plausible to do, but with so many footguns
cyrozap_ has quit [Quit: ZNC 1.8.2+deb2+b1 - https://znc.in]
cyrozap has joined #rust-embedded
<re_irc> < (@firefrommoonlight:matrix.org)> harcrow: It's a quirk of that and some other libs. Intent is to use type checker to enforce pin configs. Results in APis with nested traits.
<re_irc> < (@firefrommoonlight:matrix.org)> * APIs
<re_irc> < (@firefrommoonlight:matrix.org)> Tangent: How did you come across that lib?
madb has joined #rust-embedded
madb has quit [Changing host]
madb has joined #rust-embedded
lehmrob has joined #rust-embedded
lehmrob has quit [Remote host closed the connection]
lehmrob has joined #rust-embedded
brazuca has quit [Quit: Client closed]
brazuca has joined #rust-embedded
<re_irc> < (@drtobbe:matrix.org)> Hi, while implementing a device driver for an external flash, we have seen that there are no traits for QSPI (quad spi) peripherals in embedded-hal. Is there any specific reason that those are missing? Some MCUs support QSPI, some HALs implement it, so it seems natural to also support it in embedded-hal, right?
brazuca has quit [Quit: Client closed]
<re_irc> < (@ryan-summers:matrix.org)> Embedded-hal traits are only needed when something needs to be cross-compatible (i.e. driver crates agnostic of the HAL). Are QSPI flashes generally agnostic? I'm not so sure
<re_irc> < (@drtobbe:matrix.org)> I guess they (the flash hardware) should be agnostic of the MCU in use, so the flash driver should be agnostic, too.
<re_irc> < (@dirbaio:matrix.org)> as an example:
<re_irc> < (@dirbaio:matrix.org)> the nrf52/nrf53 QSPI peripheral is hardcoded for QSPI flash chips, It can only do the fixed set of standard SPI/QSPI flash read/write/etc commands
<re_irc> < (@ryan-summers:matrix.org)> Seems like maybe that use of QSPI would go in "embedded-storage"? or similar?
<re_irc> < (@dirbaio:matrix.org)> but the stm32 QSPI is more like "raw SPI by with 4 lanes", it can tx/rx any arbitrary byte
<re_irc> < (@ryan-summers:matrix.org)> There's a lot of other QSPI uses - Stabilizer users it as a raw SPI with 4 lanes to talk to a DDS chip
<re_irc> < (@dirbaio:matrix.org)> so if we did an embedded-hal trait for QSPI which is "raw SPI but with 4 lanes" then the nrf wouldn't be able to implement it
<re_irc> < (@dirbaio:matrix.org)> and yes, what the nrf qspi can impl is the embedded-storage traits. "embassy-nrf" already does.
<re_irc> < (@drtobbe:matrix.org)> so there is too little agreement on what qspi controllers do so it would be too arbitrary to declare qspi traits in embedded-hal?
<re_irc> is there enough agreement on that qspi flash chip interface? then it would actually make sense to just impl the embedded-storage traits on the qspi controllers themselves (in the specific hals). It would just not work if no flash chip is attached then.
<re_irc> < (@ryan-summers:matrix.org)> In general, there's no real way to know if something is connected to SPI outside of reading a known-non-zero value from the device
<re_irc> < (@ryan-summers:matrix.org)> I don't think that's in the realm of embedded-rust to take care of
<re_irc> < (@drtobbe:matrix.org)> sure, i am just wondering how we can write our driver code in a device-independent way. normally, using embedded-hal traits has been the way to go but in this case it seems to be different.
<re_irc> < (@ryan-summers:matrix.org)> In this case, wouldn't you just use the "embedded-storage" traits instead?
<re_irc> < (@dirbaio:matrix.org)> I think what is referring is:
<re_irc> hal impls qspi trait -> hal-agnostic qspi flash driver, impls embedded-storage trait -> user code uses embedded-storage trait
IlPalazzo-ojiisa has joined #rust-embedded
<re_irc> < (@ryan-summers:matrix.org)> Ah, I see that now. Didn't realize embedded-storage didn't have actual traits to handle the interface to the chip itself
brazuca has joined #rust-embedded
brazuca has quit [Client Quit]
brazuca has joined #rust-embedded
<re_irc> < (@firefrommoonlight:matrix.org)> For the most common use of memory-mapped, faster-than-SPI flash, I think this belongs on HALs for the host MCU
<re_irc> < (@firefrommoonlight:matrix.org)> Likely with an initialization function, then the user memory-maps as required using "read_volatile" and "write_volatile" etc. And probably "read", "write", and "erase" functions for supporting non-memory mapped modes
lehmrob has quit [Quit: Konversation terminated!]
<re_irc> <Colin Leftwich> HI, I have a friend who made a rust library for a 3642bs 7 segment display. This is his first library and really wanted some feedback. Would anyone be willing to look it over?
<re_irc> <Colin Leftwich> +he
<re_irc> < (@jamesmunns:beeper.com)> cr1901: it looks like you could remove all the consts in the infomem crate and just do "static $var_name: [u8; include_bytes!($pim).len()] = *include_bytes!($pim);", which is hilarious to me.
<re_irc> < (@jamesmunns:beeper.com)> I don't think this actually matters, it's all const whatever, so I won't open a PR unless you want me to, but learning more about "include_bytes!()"'s capabilities is fun.
brazuca has quit [Quit: Client closed]
<cr1901> uuuuuugh...
<re_irc> < (@adamgreig:matrix.org)> (will be a couple mins late today, sorry!)
<re_irc> < (@adamgreig:matrix.org)> ok room , meeting time again! agenda is https://hackmd.io/3v7LPLeFQYK4FyKGS7rZZg, please add anything you'd like to announce or discuss, we'll start in a minute :)
<re_irc> < (@adamgreig:matrix.org)> let's start! couple of quick release announcements for probe-rs 0.17 and smoltcp 0.9 πŸŽ‰
<re_irc> < (@dirbaio:matrix.org)> smoltcp 0.9.0 adds support for DNS and fragmentation, includes a cleaner API and many fixes. Changelog -> https://github.com/smoltcp-rs/smoltcp/blob/master/CHANGELOG.md
<re_irc> < (@dirbaio:matrix.org)> smoltcp 0.9.0 adds support for DNS and fragmentation, includes a cleaner API and many fixes. Changelog -> https://github.com/smoltcp-rs/smoltcp/blob/master/CHANGELOG.md
<re_irc> < (@adamgreig:matrix.org)> and fewer managed slices, yay
<re_irc> < (@adamgreig:matrix.org)> i have been doing but work for the last week πŸ’€ so I don't have a ton of other topics here... still looking for anyone interested in helping maintain the aarch64-cpu crate, please message me if so
<re_irc> < (@adamgreig:matrix.org)> I think we wrapped up the discussion about Delay taking shared refs nicely last week
<re_irc> < (@adamgreig:matrix.org)> i have been doing nothing but work for the last week πŸ’€ so I don't have a ton of other topics here... still looking for anyone interested in helping maintain the aarch64-cpu crate, please message me if so
<re_irc> < (@adamgreig:matrix.org)> does anyone else have anything they'd like to discuss?
<cr1901> I'm trying to get a new embedded-rust crate released. Does that count :P?
<re_irc> < (@dirbaio:matrix.org)> nothing from me :o
<cr1901> (and am looking for ppl to break it/comment/complain)
<re_irc> < (@therealprof:matrix.org)> Busy with other stuff, too. I've seen some activity on various WG crates and of course the dreaded e-h 1.0 release is still waiting to happen. ;)
<re_irc> <Slushee> cr1901: Share the repo!
<cr1901> https://github.com/cr1901/postcard-infomem By using this workspace of crates, you can automate embeddeding metadata about your project, rust compiler, and user-defined data into your binary. The data is serialized w/ jamesmunns postcard crate.
<cr1901> I'm working on automating the linker script snippet generation and finishing the docs
<re_irc> < (@jamesmunns:beeper.com)> : I'm out of the loop, do we not have any crates for armv7a now?
<cr1901> So there will unfortunately be a bit more breakage before release is ready (but will be soon)
<re_irc> < (@jamesmunns:beeper.com)> (we can discuss this after meeting, just idly wondering)
<re_irc> < (@adamgreig:matrix.org)> the cortex-a crate was renamed aarch64-cpu
<re_irc> < (@adamgreig:matrix.org)> I don't know to what extent it originally supported armv7a?
<re_irc> < (@jamesmunns:beeper.com)> Gotcha, I just noticed the rename after that person was having bss issues
<re_irc> < (@jamesmunns:beeper.com)> I think? It used to support 32-bit arm, I know the iqlusion imx6ull project was arm7a
<re_irc> < (@jamesmunns:beeper.com)> Ah, maybe Jorge forked it to get things working: https://github.com/iqlusioninc/usbarmory.rs/tree/develop/firmware/cortex-a
<cr1901> Where is japaric, btw?
<cr1901> Haven't seen/heard from them in ages
<re_irc> <thejpster> Busy at Ferrous
<re_irc> <thejpster> If we’re quiet tonight, can I plug rust-embedded-community? The GitHub org where crates go to get some love and attention when their owners no longer have time.
<re_irc> < (@adamgreig:matrix.org)> that sounds nice 😭
<re_irc> < (@adamgreig:matrix.org)> well, if that's all for this week let's wrap up early, thanks everyone!
<re_irc> < (@adamgreig:matrix.org)> hopefully next week i won't be wrangling pipes until two minutes before the meeting starts πŸ˜₯
emerent has quit [Ping timeout: 248 seconds]
emerent has joined #rust-embedded
brazuca has joined #rust-embedded
madb has quit [Ping timeout: 252 seconds]
<re_irc> < (@drtobbe:matrix.org)> : Exactly! But due to the missing qspi trait, I am not sure anymore how we should implement our driver code in an MCU-agnostic way.
<re_irc> I guess we will have a look at the nrf qspi peripherals to get a better understanding of how other qspis work (we mostly use stm32). Then, we'll decide. Thanks for the input.
<re_irc> < (@dirbaio:matrix.org)> fwiw i'm not saying it's a bad idea
<re_irc> < (@dirbaio:matrix.org)> it doesn't exist because there hasn't been enough demand for it
<re_irc> < (@dirbaio:matrix.org)> * much
<re_irc> < (@dirbaio:matrix.org)> we could still have the trait even if nrf can't impl it
<re_irc> < (@dirbaio:matrix.org)> nrf would do:
<re_irc> hal impls embedded-storage trait -> user code uses embedded-storage trait
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded