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
rjframe has quit [Quit: Leaving]
M762spr[m] has joined #rust-embedded
<M762spr[m]> I have a question that isn't directly related to embedded, but I think the problem is DEFMT so I'm hoping someone here can point me in the right direction...
<M762spr[m]> I wrote a library for a radio module. Works fine, no problems there. It has a fairly elaborate builder for the radio config that prevents incorrect configuration combinations and I want to re-use that code so on my desktop app that communicates with the STM32 I can make sure I have a correct configuration, and send it over. tl;dr I want to use the same library for a desktop app
<M762spr[m]> The problem arises when I include my library in the source of my desktop app and build I get a linker error and a wall of output text. At the end it seems to reference DEFMT so I suspect that's the problem. any ideas?
<M762spr[m]> I tried adding defmt and defmt-rtt to my cargo.toml with no change
<M762spr[m]> ok yeah it's definitly defmt
<M762spr[m]> I removed it from my library which was mostly just used for info! prints and now it compiled on the desktop
<M762spr[m]> BUT without defmt, I can't derive Fromat which means in my embedded environment I can't print any of my custom structs/enums
mameluc[m] has joined #rust-embedded
<mameluc[m]> M762spr[m]: without knowing what is in the wall of text it is hard to say what might be wrong. however adding defmt needs some flags to work
<M762spr[m]> oh! yeah I obviously haven't done the linker script mods that makes sense
<M762spr[m]> it's been a while since I setup the embedded environment that I use it with so I forgot all about it
<M762spr[m]> hm. adding the rustflag didn't work. which makes sense I guess because I am compiling a desktop app
GrantM11235[m] has joined #rust-embedded
<GrantM11235[m]> Embassy uses cfg features to switch between defmt and log at compile time https://github.com/embassy-rs/embassy/blob/main/embassy-executor/src/fmt.rs
<M762spr[m]> I think this is what I need. I don't really understand macros so I will try to process it
sethiam[m] has joined #rust-embedded
<sethiam[m]> In your library you could define the info! macro as either from use tracing::info or equivalent or use defmt::info based on a feature flag you define in your cargo.toml. That flag should also gate the defmt dependency when compiling for std.
<M762spr[m]> makes sense
<M762spr[m]> I will use the embassy file as reference and see if I can get it figured out
<sethiam[m]> That way you can include the library for ur std app with a feature flag that allows std and some logging framework for std, and without said flag, compile for no_std and with defmt.
<GrantM11235[m]> Just copy that file into you crate and add pub(crate) mod fmt to the top of your lib.rs or main.rs (It must be BEFORE any other modules)
<M762spr[m]> haha well that's easy I'll see how it goes! thanks!
<M762spr[m]> <GrantM11235[m]> "Just copy that file into you..." <- hmm still no luck. I added the fmt.rs to my library and the module to the lib.rs file... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/byVuXquDrnGgSdIVshnYTuHh>)
<M762spr[m]> I might be adding the features wrong, I haven't messed with that much
<M762spr[m]> oh, maybe it's because I still had defmt included in the lib.rs
<GrantM11235[m]> You will also need to set up a logger for the log crate
<M762spr[m]> but without it I can't derive Format, so I think I need to add that to the macro?
<GrantM11235[m]> You can conditionally derive Format
<GrantM11235[m]> #[cfg_attr(feature = "defmt", derive(defmt::Format))]
<M762spr[m]> <GrantM11235[m]> "You will also need to set up a..." <- ah, just got there! at least it's progressing 😅
<M762spr[m]> So basically I need to add a dependency for my library to swap in when using the log feature?
<GrantM11235[m]> I think env_logger is the most popular one and it looks pretty easy to use https://docs.rs/env_logger/latest/env_logger/
<M762spr[m]> so if I'm reading this right, the library should use log and the app should use env_logger?
<GrantM11235[m]> I think so. And the library only needs to use the log crate if your log feature is enabled
vanner- has joined #rust-embedded
vanner has quit [Read error: Connection reset by peer]
<M762spr[m]> awesome. ALMOST compiling. It's just mad that:
<M762spr[m]> ``the trait `UpperHex` is not implemented for `[u8; 5]```
<M762spr[m]> now but I can probably just live without that
<M762spr[m]> * awesome. ALMOST compiling. It's just mad that:
<M762spr[m]> `\`\`the trait `UpperHex` is not implemented for \`\[u8; 5\]\`\`\`
<M762spr[m]> now but I can probably just live without that
<M762spr[m]> s/`//, s/```/``/
cr1901_ has joined #rust-embedded
cr1901 has quit [Ping timeout: 252 seconds]
<M762spr[m]> GrantM11235: sethiam it seems to be working now, HUGE thanks to both of you I probably wouldn't have been able to figure that out on my own!
<M762spr[m]> RE: the UpperHex issue, I noticed the fmt.rs file had something for LowerHex but obviously it had to be implemented for a custom type
<M762spr[m]> so I duplicated it and modified it for UpperHex... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/jbHaElIKUyRNbyZgZMvKFvbp>)
<M762spr[m]> not 100% sure if that would print the desired results BUT I don't really care on the desktop app anyway I'm just using a small portion to make the configuration
<M762spr[m]> anyway, thanks again! 🙏
<gmarull[m]> Hi, I observe the following warning on enums when using `chiptool`: `variant 'X_Y_Z' should have an upper camel case name`. Shouldn't `chiptool` be adding `#[allow(non_camel_case_types)]`? Am I missing something? dirbaio
<ivmarkov[m]> I have a question around the semantics of `embedded_io::Read::read` and thefore - also for `std::io::Read::read` and also for `embedded_io_async::read::Read`:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/AhKdWtAgLJLGTdrpvSmAbVNv>)
<ivmarkov[m]> * I have a question around the semantics of `embedded_io::Read::read` and thefore - also for `std::io::Read::read` and also for `embedded_io_async::read::Read`:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/wwdvCaBxkkZgKMIyYoXUJODF>)
<dirbaio[m]> >Is read guaranteed to return without blocking, if there is at least one byte in the internal TCP ringbuffer?... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/yIBZnlKwqYGXDkRZTVraFhqL>)
<dirbaio[m]> so, option A
<dirbaio[m]> option B is wrong
<ivmarkov[m]> Absolutely, really, 100% sure? Asking, because the documentation is realy NOT explicit about that.
<JamesMunns[m]> iirc std::io::Read agrees with option A as well
<dirbaio[m]> docs could be more explicit ... but they refer to std::io, and std::io works like that. Also std::io in turn follows posix io
<dirbaio[m]> * posix io, which also works like that.
<dirbaio[m]> option B is bad because it doesn't allow doing certain things. for example you can't read until newline with bigger buffers because it'll block until the buffer is full, which may be more than just one line
<dirbaio[m]> you're forced to do 1-byte read calls
<dirbaio[m]> which would be bad
<dirbaio[m]> basically the semantics are "when a byte arrives, I want to see it ASAP. Don't wait more"
<JamesMunns[m]> tbh I can't find anything that says Option B is wrong, but it definitely doesn't match how most OSs implement it (down to the syscall level)
<ivmarkov[m]> Fair enough. Thanks! I really wanted to confirm that these are official, specified (somewhere??) semantics, and not an internal implementation detail that is leaking through the API, and people just abusing it (sub)consciously.
<ivmarkov[m]> JamesMunns[m]: But that's the problem! Are we relying on a well-defined, documented semantics, or on an internal implementation detail? That's what I'm trying to understand, but Dario seems super convinced yes.
<dirbaio[m]> uhhh it's worked like this forever
<dirbaio[m]> and it's the way that makes "the most sense"
<JamesMunns[m]> like, an OS may be allowed to wait a little longer even if data is ready if it thinks it's likely to get more asap, but always blocking until the full read is available would definitely be odd
<JamesMunns[m]> (that's what read_exact is for)
<vollbrecht[m]> in this case its about defining a good enough timeout that is short enough, but not to short. Such that if the buffer is not full it will return internally with all it got?
<vollbrecht[m]> * good enough internal timeout that
<JamesMunns[m]> fwiw for sockets and stuff this is controlled "out of band" by configuring the read timeout
<dirbaio[m]> read timeout is a different thing
<JamesMunns[m]> (at least out of band to the call to the read syscall)
<vollbrecht[m]> well its different, but here we are talking about returning even if somewhere only 1 byte was internally but into the read buffer
<ivmarkov[m]> JamesMunns[m]: No, `read_exact` is just a convenience if you want to avoid the OS returning you a partial buffer. I don't think its mere existence rules out that Option B" is a valid contract for `Read::read`.
<vollbrecht[m]> s/but/put/
<ivmarkov[m]> ... and it is implemented on top of Read::read anyway
<JamesMunns[m]> I didn't say "invalid", just "weird"
<JamesMunns[m]> s/weird/odd/
<ivmarkov[m]> * out that "Option B"
<dirbaio[m]> it's invalid
<JamesMunns[m]> dirbaio[m]: I would be very interested in a citation for that
<JamesMunns[m]> like, I agree it's not how linux/mac/windows work
<ivmarkov[m]> JamesMunns[m]: Me too :(. show me _something_. Could be a POSIX documentation, where it is super clear on that subject. I'm struggling to fine it. :(
<ivmarkov[m]> s/fine/find/
<ivmarkov[m]> (BTW my oroblem is weird ESP IDF UART does Option B, and I now have a user who claims I'm not fullfilling the contract of Read, as he interprets it as Option A.)
<JamesMunns[m]> And for the record, I think you SHOULD do Option A, and that Option B is odd
<dirbaio[m]> well we can just expand embedded-io docs to make B illegal 😎
<JamesMunns[m]> but at least in a quick search, I can't find anything that says option B is wrong, just odd, and likely to cause confusion
<dirbaio[m]> if people are going to contract-lawyer this I think we should
<dirbaio[m]> because if impls doing Option B proliferate they'll cause interop problems
<dirbaio[m]> I didn't explicitly document this because I thought it was obvious :|
<JamesMunns[m]> The recv syscall DOES talk about this
<JamesMunns[m]> If no messages are available at the socket, the receive calls... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/bDhbrxrRcnfwALAypGMVfLwy>)
<dirbaio[m]> > When attempting to read from an empty pipe or FIFO:
<dirbaio[m]> > (...)
<dirbaio[m]> > If some process has the pipe open for writing and O_NONBLOCK is clear, read() shall block the calling thread **until some data is written** or the pipe is closed by all processes that had the pipe open for writing.
<diondokter[m]> JamesMunns[m]: > <@jamesmunns:beeper.com> If no messages are available at the socket, the receive calls... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/vAniRpenZNRgHuFSuwjjdcRr>)
<dirbaio[m]> some data, not nbyte bytes of data
<dirbaio[m]> and
<dirbaio[m]> > If fildes refers to a socket, read() shall be equivalent to recv() with no flags set.
<dirbaio[m]> and recv() is quite explicit about this as James said
<JamesMunns[m]> Yeah, I think some of the wavyness is that io::Read covers all kinds of readable things, like files (which are more likely to read exact), but also sockets (which only ever read until nonzero that I've ever seen), and we're talking about serial ports here specifically
<dirbaio[m]> yeah, posix is a bad standard
<dirbaio[m]> * bad standard if it allows different behavior for different kinds of fileds
<dirbaio[m]> * bad standard if it allows different behavior for different kinds of fd's
<dirbaio[m]> I don't think we have to copy this "badness"
<dirbaio[m]> also even with serial ports, read() in linux returns available data, it doesn't wait for all N bytes to be received
<JamesMunns[m]> anyway, I think you could probably rules lawyer Option B as "technically correct", but I think that a serial port being more socket-y than file-y would make the case that doing Option B is very odd and shouldn't be done.
<JamesMunns[m]> (even if it's SHOULD not SHALL)
<dirbaio[m]> then we just edit the docs to explicitly make option B illegal
<JamesMunns[m]> we could, but then is it valid to implement embedded_io::Read on top of a std::io::Read?
<JamesMunns[m]> std::io::Read doesn't make that claim.
<JamesMunns[m]> I think we SHOULD add a SHOULD there though, to make it more clear in the future :)
<dirbaio[m]> there's no std::io::Read impls out there that do the "wait until all N bytes have been received"
<ivmarkov[m]> Ok. I declare defeat. I'll do option A on top of option B. But maybe editing the docs to be more explicit about option A would be a good idea.
<dirbaio[m]> the closest is reading from files, but that kinda makes sense because data from files is always "immediately available", it's on a local disk so it can't take an unbounded amount of time to arrive
<JamesMunns[m]> Even then linux will cap out a read at < 32 bits worth
<dirbaio[m]> so i'd argue if an std::io::Read impl waits for full buffer, it's also wrong
<ivmarkov[m]> In fact, maybe we should ping STD as _they_ have to be more explicit too?
<JamesMunns[m]> I think adding a "should" or a note "hey you really shouldn't treat this like read_exact", and "here's how posix recv talks about it" is a good idea
<JamesMunns[m]> I think opening an issue for std is reasonable too, at least citing recv. I don't know if they'd make it "normative"
Etuk[m]1 has joined #rust-embedded
Etuk[m]1 has left #rust-embedded [#rust-embedded]
<JamesMunns[m]> 🔨🔨🔨 (triple room ban hammer lol)
AtleoS has quit [Ping timeout: 260 seconds]
<mameluc[m]> Don't know if this is a common problem but serde got and std. Something somewhere is passing the std feature to serde and now my no_std project won't compile anymore.
<JamesMunns[m]> theres a cargo tree commande where you can figure out which dep is activating which feature
<JamesMunns[m]> are you in a workspace or no?
<mameluc[m]> not a workspace no
<mameluc[m]> parent directory is a workspace but the embedded stuff is excluded and works as its own thing
<JamesMunns[m]> Try cargo tree -e feature
<JamesMunns[m]> * Try cargo tree -e features
<JamesMunns[m]> (features, not feature, sorry)
<mameluc[m]> allright ty, a lot of stuff to go trough 👍️
<JamesMunns[m]> hmm, heapless does set default-features = false, are you?
<mameluc[m]> yes I am disabling default-features
<mameluc[m]> to be clear this code base compiled before but I ran rustup update and have no clue what else changed 😅
<JamesMunns[m]> 📣 Hello @room ! The 2024 Embedded WG Survey is now live!... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/QfbueuRfkGhoEbwNtKSeRbcC>)
<JamesMunns[m]> (sorry to everyone about all the rooms I'm about to share this in)
danielb[m] has joined #rust-embedded
<danielb[m]> <JamesMunns[m]> "(sorry to everyone about all the..." <- what a spammer 🫶
<JamesMunns[m]> danielb[m]: hope the mod lists don't catch up to me :p
<JamesMunns[m]> If anyone here has Mastodon/Fediverse accounts: I'd appreciate some shares there too! I don't, so any help would be great :)
<JamesMunns[m]> (link them here or in the issue above so people can find them)
<diondokter[m]> JamesMunns[m]: I shared it there too
<diondokter[m]> * there too, I'll add to the list
<JamesMunns[m]> Also pinging Amit for passing on to the Tock-OS folks :)
<dirbaio[m]> re-xitted. also added it to https://docs.embassy.dev :D
<JamesMunns[m]> <dirbaio[m]> "re-xitted. also added it to..." <- It's kinda odd and floating on mobile
<dirbaio[m]> yeah.. the header was already broken on mobile tho
<dirbaio[m]> who reads rustdocs on mobiile? :D
aprl[m] has quit [Quit: Idle timeout reached: 172800s]
burrbull[m] has quit [Quit: Idle timeout reached: 172800s]
dngrs[m] has joined #rust-embedded
<dngrs[m]> is there a crate/tool that helps with core vs std abstraction?
<dirbaio[m]> what do you want to abstract?
<dngrs[m]> imports
<dirbaio[m]> you can still import core in an std crate, there's no downside
<dngrs[m]> let's say I want to port to no_std; that's a lot of work
<dngrs[m]> * let's say I want to port https://github.com/RustPython/Parser to no_std; that's a lot of work
<dirbaio[m]> you can replace use std::.. with use core:: or use alloc:: and it'll still work for std
<dngrs[m]> dirbaio[m]: I know I can do that, but *that's a lot of manual work*
<diondokter[m]> There are usually only four-ish things that you have to look at:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/umTpxVZTNMaBJAyDTiOjSHQi>)
<dngrs[m]> and also it seems like it should be easier on ... the language level maybe
<dirbaio[m]> find and replac? :D
<dirbaio[m]> only if you have things that only exist in std then you have to leave them as use std::... and add #[cfg(feature="std")]or whatever
<diondokter[m]> dngrs[m]: Well, no_std should've been default Rust IMO. But it's a bit too late for that
<dngrs[m]> diondokter[m]: I agree; maybe for the next edition? :)
<dngrs[m]> dirbaio[m]: kindasorta - with the various ways imports can be written, this feels hard to automate, at least in a general and robust way
<dirbaio[m]> iirc there's talks of unifying core, alloc, std? so you always use std, just there's more or less stuff available depending on the target
<dirbaio[m]> that'd be cool :P
<dngrs[m]> dirbaio[m]: that's exactly the kind of stuff I'm looking for, do you have any pointers?
<diondokter[m]> Interesting. I'd be inclined to do it the other way around. Std would only contain stuff that's exclusive to std.
<diondokter[m]> Wanna use a slice? Then `core::slice` it is.
<diondokter[m]> That probably has plenty of issues too though
<JamesMunns[m]> dngrs[m]: I wrote about it in my RFC for std aware cargo
<dngrs[m]> anyway James Munns this is definitely a pain point I forgot to add to my survey answers
<JamesMunns[m]> I don't think it's anywhere close to practically happening
<dngrs[m]> JamesMunns[m]: ah, nice one
<dngrs[m]> JamesMunns[m]: sadface
<dngrs[m]> we should just rename std:: to no_std::
<PedroFerreira[m]> <JamesMunns[m]> "Tweet for sharing: https://x.com..." <- let me know if someone posts it on Mastodon, so that I boost it
<JamesMunns[m]> PedroFerreira[m]: https://github.com/rust-embedded/wg/issues/782#issuecomment-2304466766 a copiple people linked here
<dngrs[m]> PedroFerreira[m]: in the gh issue there's two masto posts, by diondokter and me
<JamesMunns[m]> s/copiple/couple/
<JamesMunns[m]> If anyone has a moment to review my PR for the Inside Rust blog, I'd appreciate it!
<adamhott[m]> I just added a comment, I don't believe I have review capabilities.
<adamhott[m]> Looks great!
<adamgreig[m]> <JamesMunns[m]> "If anyone has a moment to review..." <- > <@jamesmunns:beeper.com> If anyone has a moment to review my PR for the Inside Rust blog, I'd appreciate it!... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/ShbffQofYfrwmZyToDaLPuor>)
<JamesMunns[m]> > This is the main Rust blog. Rust teams use this blog to announce major developments in the world of Rust.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/LNDdIFJdUuFdEIsGWlCmlSwj>)
<adamgreig[m]> Fair, that's a better fit than I thought then
<ivmarkov[m]> <diondokter[m]> "There are usually only four-..." <- > <@diondokter:matrix.org> There are usually only four-ish things that you have to look at:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/dqKfDkSnMVXHBcUvOWYAXfvo>)
<diondokter[m]> Yeah, next version 1.81 has it right?
siho[m] has joined #rust-embedded
<siho[m]> Is anyone up to help me with a beginner question?
K900 has joined #rust-embedded
<K900> Just ask
<K900> Don't ask to ask
ryan-summers[m] has joined #rust-embedded
<ryan-summers[m]> Just shoot :)
<siho[m]> I'm trying to use svd2rust to generate a PAC for an unsupported device. That works fine, now I just want to blink a LED. The problem is that the field i need to toogle is the type of FieldWriter and i really can't get the writer to be &mut
<siho[m]> `portb_dout().write(|w| w.dout().set(0b10));`
<siho[m]> If it's not obvious this is a efm32 device
<siho[m]> I'm sorry for the bad formatting but I've only setup matrix on my phone for now.
<ryan-summers[m]> What's the error you're getting exactly?
<siho[m]> The error I get is that the method set is only available on a &mut W<efm32> while what I apparently is not. It's totally fine to just set the bits raw but I kind of wanted to have the register length check
<ryan-summers[m]> Ah so doing like .set_bits()... works fine? It's probably a bug in the SVG then not properly marking the field as writable
<ryan-summers[m]> s/./`./, s/.../`.../, s/SVG/SVD/
<siho[m]> This is sort of close to what I'm generating
<siho[m]> ryan-summers[m]: `.bits()`.works fine inside an unsafe block. The field is marked as read-write in the svd
<ryan-summers[m]> I wonder if Rust is accidentally picking up the dout() for DOUT_R instead of DOUT_W? Sorry, I haven't done much with PAC generation myself so I'm unsure here
<ryan-summers[m]> The copy-pasted error from the compile would be helpful in sorting that out though
<siho[m]> <ryan-summers[m]> "What's the error you're getting..." <- I'm so sorry 😔 I'll have to set up the matrix on my setup.
<ryan-summers[m]> Have you looked at the generated docs? It's saying a set()function doesn't exist
<ryan-summers[m]> Is there a different API you should be using instead of set()?
<JamesMunns[m]> (btw, someone submitted the survey to Reddit: https://old.reddit.com/r/rust/comments/1eyjyd7/2024_embedded_wg_microsurvey/ )
<ryan-summers[m]> Yeah it looks like you have to use bits() or variant on the fieldwriter type, not set(). Check out the generated docs for the PAC
<ryan-summers[m]> But from other PACs available on docs.rs, I can see that set() doesn't seem to be in the fieldwriter API: https://docs.rs/efm32g-pac/latest/efm32g_pac/type.FieldWriter.html
<siho[m]> Well I probably should do something different that I'm aware of xD
<ryan-summers[m]> tl;dr I think your code works fine if you replace the set() with bits()
<siho[m]> Yes that's true it's just that set exists in the FieldWriter and I want to use:)
<ryan-summers[m]> The compiler is saying it doesn't, and I don't see it on the docs. How do you know it exists?
<siho[m]> The PAC I linked too was generated with an old svd2rust
<ryan-summers[m]> In the error, it's saying that `set()` exists on (another type) &mut W<...>, but your type is `FieldWriter<..>`, so it doesn't have the same API as W<..>
<siho[m]> ryan-summers[m]: I don't know how readable this is
PaulDFaria[m] has joined #rust-embedded
<PaulDFaria[m]> If it does exist on FieldWriter (I'm thinking not given the comments and screenshot above) then there's likely a trait not in scope or a trait bound on one of the generics that's not being upheld.
<ryan-summers[m]> My guess is the register doesn't implement the proper trait bounds to expose set()
<PaulDFaria[m]> Are you sure the fields are implementing the bounds correctly?
<siho[m]> Please correct me if the set does not exist for the FieldWriter. I just assumed it did according to the docs in the photo
<ryan-summers[m]> It does only if the trait bounds are met.
<ryan-summers[m]> So in this case, those bounds may not be met, meaning set may not be available on this register
<dirbaio[m]> svd2rust docs are quite hard to read 🙃
<PaulDFaria[m]> You need to check whether PortbDoutSpec implements RegisterSpec and Writable, and Dout implements FieldSpec.
<ryan-summers[m]> Yeah its also super opaque to figure out what types impl what
<ryan-summers[m]> That's why I tend to just listen to the compiler. You can reason through it, but it'll take a while
<siho[m]> It should be available but I guess that's where the bug is in the svd let me try to setup Matrix on my machine xD
<PaulDFaria[m]> In the docs, I would search for the types in the error. Then check what traits they impl
<PaulDFaria[m]> If they impl the traits then maybe you just need to import the traits?
<PaulDFaria[m]> Though I've never run into that before
<JamesMunns[m]> Or if you don't have Rust Analyzer installed, it can give you autocomplete, which is super helpful working with svd2rust!
<siho[m]> Anyways thanks for all the pointers and sorry for being so insistent on trying to use set. I just wanted to have some safety when setting the bits
<ryan-summers[m]> There's likely other APIs other than set by the way that are safe
<ryan-summers[m]> But maybe newer svd2rust replaced them all with set... IDK
<siho[m]> There is .variant I have no idea what that API is trying to communicate
<ryan-summers[m]> The .variant is allowing you to use variants specified in the SVD as allowable for that field
<ryan-summers[m]> So like, if there's an enumeration of allowable values, those are exposed via SVD2Rust and you can use them directly
<siho[m]> Using variant I get IsEnum is not implemented since the field doesn't have any enumerated values
<ryan-summers[m]> The enum would be auto-generated by svd2rust, and I didn't think it generated the variant() accessor if no enums existed in the svd
<siho[m]> I walked down that path and added them myself XD but I just thought 💭 that if the FieldWriter had the register size I could use that Safety instead
<ryan-summers[m]> I don't think the intent is that you'd ever manually add to the svd2rust generated outputs, and if you did that, it's likely why the enum you crated isn't working
<ryan-summers[m]> The intent would be to correct the svd so that it generates the correct code instead
<siho[m]> I meant I added the enumerated fields to the svd
<ryan-summers[m]> Gotcha, yeah I see the frustration. Maybe take a look at how the stm projects patch the SVDs? Maybe you patched it in a way that didn't quite fully fix the issue
SiHo[m]1 has joined #rust-embedded
<SiHo[m]1> So what I kind of want to know is how to add the constraints needed to make it so that I can use `set`
<SiHo[m]1> Since `set` was added for safe writing :D
<SiHo[m]1> I guess it should be added to the SVD but I wonder what is missing :(
<SiHo[m]1> so I want to take advantage of the Field Range check so that whatever set I call doesn't go out of bounds for the bitWidth.
burrbull[m] has joined #rust-embedded
<burrbull[m]> <SiHo[m]1> "So what I kind of want to know..." <- > <@siho0:matrix.org> So what I kind of want to know is how to add the constraints needed to make it so that I can use `set`... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/dGSyELCtjqHregZLvzMZYJHU>)
<JamesMunns[m]> (we're now live on the Inside Rust blog! https://blog.rust-lang.org/inside-rust/2024/08/22/embedded-wg-micro-survey.html)
<SiHo[m]1> burrbull[m]: Oh, so you have manually patched the SVD to get this to work?
<burrbull[m]> No, it is patched using https://github.com/rust-embedded/svdtools
<SiHo[m]1> burrbull[m]: You still have to find and manually define the YAMLs for patching it right?
<SiHo[m]1> * to find missing values and manually
<dirbaio[m]> yep
dygear[m] has joined #rust-embedded
<dygear[m]> <JamesMunns[m]> "(we're now live on the Inside..." <- The Embedded WG is conducting a MICRO survey. Coincidence I think not!
AdinAck[m] has joined #rust-embedded
<AdinAck[m]> how can i know which target to use for a chip? the STM32G4 claims to be a Cortex M4 "with FPU", does that imply thumbv7em-none-eabihf? i've flashed it with and without the hf seems to work the same
<diondokter[m]> AdinAck[m]: Yep!
<diondokter[m]> It's kind of a mess, but in this you're right
<AdinAck[m]> ok, iirc Embassy has no hf assigned to the G4, let me check again
<AdinAck[m]> thanks :)
<diondokter[m]> Well... It works fine, it just won't use the hardware FPU instructions
<diondokter[m]> So, if you want a nice embassy PR, there ya go!
<AdinAck[m]> is there a cost-benefit decision here? what's the cost of enabling it?
<diondokter[m]> AdinAck[m]: None that I know of
<AdinAck[m]> hm, okey dokey, thanks again!
<diondokter[m]> Maybe more power usage? But I'd think the faster instructions would counter that
<JamesMunns[m]> IIRC there is a TINY penalty in some cases if you definitely never use floating point ops, but all floating point capable hardware can run with soft floats
<JamesMunns[m]> if you DO use floats, you definitely want hf
<JamesMunns[m]> the difference (IIRC?) in memory usage is around register stacking, in that interrupts will reserve space for stacking registers on interrupt call if the floating point core is enabled
<diondokter[m]> JamesMunns[m]: Ah yes interesting!
<JamesMunns[m]> but the registers are only ACTUALLY stacked lazily (unless you enable always-stack mode for determinism reasons)
<AdinAck[m]> i am converting fixed numbers to f32 and assumed the binary size would be larger without hf but it was the same! maybe that conversion isn't accelerated by the FP instructions
<JamesMunns[m]> and the target triple is used by cortex-m-rt to decide whether to enable the fp regs at boot time
<JamesMunns[m]> maybe converting to fp doesn't use floating ops? doing math with it would definitely show noticable difference
<AdinAck[m]> yeah, definitely
<dirbaio[m]> <AdinAck[m]> "in embassy-stm32:..." <- > <@adinack:matrix.org> in embassy-stm32:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/fnayVRMvlcImUCnXwvoxXfss>)
<AdinAck[m]> ah that makes sense
<SiHo[m]1> Still on the I want to get `.set` to work train:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/BjafUeZDgKGpyDpdfsfggxDC>)
<dirbaio[m]> the target that matters is the one you put when building your firmware
<dirbaio[m]> if the chip has a FPU, both -eabi and -eabihf work. -eabi will not use the FPU, so everything still works but floats are slower.
<SiHo[m]1> * svd2rust generics. I don't understand what trait or constraint I'm not satisfying :/
<burrbull[m]> SiHo: what values have you passed in writeConstraint?
<PaulDFaria[m]> SiHo @siho0:matrix.org: in an earlier snippet, you had FI being filled by Dout. Can you paste that type's implementation? It should implement FieldSpec
<SiHo[m]1> burrbull[m]: Sorry I don't see this field so I'm not really certain on what you are asking for?
<SiHo[m]1> > <@pauldfaria:matrix.org> SiHo @siho0:matrix.org: in an earlier snippet, you had FI being filled by Dout. Can you paste that type's implementation? It should implement FieldSpec... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/isVRkLoRyeneUheqBYAAyvZZ>)
<burrbull[m]> SiHo[m]1: As I understood or SVD should looks like:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/XLfhsmkVeHjMDUIyIhUSdlus>)
<SiHo[m]1> SiHo[m]1: Isn't `PortbDoutSpec` what is being filled for FI ?
<burrbull[m]> * As I understood or SVD should looks like:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/gYLxWmlEnVxEBVtQdwAPXxxC>)
<SiHo[m]1> burrbull[m]: It does not have this writeConstraint field in the SVD
<burrbull[m]> * As I understood or SVD should looks like:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/aPhXNWhVwTYRXeHpdLAVCzbA>)
<SiHo[m]1> SiHo[m]1: It just looks like this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/HVQOhkeRllwGdXWwHHVctxZm>)
<burrbull[m]> SiHo[m]1: That's why there no `set`
<SiHo[m]1> burrbull[m]: Okay thank you so much that explains everything then :)
<PaulDFaria[m]> SiHo[m]1: No, that's what's being passed to REG
<SiHo[m]1> SiHo[m]1: I just expected that if it knew the bitOffset and Width it would know the constraints.
<PaulDFaria[m]> PaulDFaria[m]: In https://matrix.to/#/!BHcierreUuwCMxVqOf:matrix.org/$JI0Qn5CKTcqWecQnsFVexYsxVDZq4g4YGjM8WXpByN4?via=matrix.org&via=catircservices.org&via=tchncs.de
<PaulDFaria[m]> You have PortbDoutSpec as the register
<PaulDFaria[m]> PaulDFaria[m]: And Dout as FI, 6 as WI
<burrbull[m]> SiHo[m]1: `width` just specify size of field
<burrbull[m]> burrbull[m]: It does not say what Values are safe to write there
<SiHo[m]1> burrbull[m]: That makes a little bit of sense :) is there anyway of saying all values in the field are safe to write too?
<SiHo[m]1> SiHo[m]1: so the full width can be used or do you still have to specify the writeconstraint?
<SiHo[m]1> PaulDFaria[m]: Ah oki :) I'll look for wher Dout comes from
<burrbull[m]> SiHo[m]1: `writeconstraint`
<burrbull[m]> burrbull[m]: by default we consider all fields more 1 bit width are unsafe
<burrbull[m]> burrbull[m]: and only `unsafe bits()` implemented
<burrbull[m]> * only `unsafe fn bits()` implemented
<burrbull[m]> burrbull[m]: `svdtools` was initially created to easy add `enumeratedValues` and `writeConstraint`
<SiHo[m]1> burrbull[m]: Makes sense since a lot of RW registers have some settable and nonsettable values.
<burrbull[m]> * `svdtools` was initially created to easy add `enumeratedValues` and `writeConstraint`
<burrbull[m]> But then many functions for fixing bugs, collecting registers in arrays, etc. were added
<SiHo[m]1> <SiHo[m]1> "Ah oki :) I'll look for wher..." <- Eh.. I can't find `Dout` from the generated code in the PAC. Anyways burrbull explained well in the above thread why I wasn't able to set it.
<SiHo[m]1> SiHo[m]1: https://matrix.to/#/!BHcierreUuwCMxVqOf:matrix.org/$jZTdWsV6c2vVpSBUtBWawxKUd5n7sq6S2BX9faD5cUE?via=matrix.org&via=catircservices.org&via=tchncs.de
heksa[m] has quit [Quit: Idle timeout reached: 172800s]
jannic[m] has quit [Quit: Idle timeout reached: 172800s]
Henk[m] has quit [Quit: Idle timeout reached: 172800s]
bartmassey[m] has quit [Quit: Idle timeout reached: 172800s]
d3zd3z[m] has joined #rust-embedded
<d3zd3z[m]> In developing Rust+Zephyr, I'm trying to reconcile the worlds of time between them. Fugit seems common in Rust. However, it rounds things down, so for example a Duration on a 32768 Hz clock would convert 10 ms to 327. Zephyr's conversion macros, on the other hand, always round up, so that any delay is always at least as long as requested. I can understand why Zephyr does it this way, but I'm not real sure how to reconcile things,
<d3zd3z[m]> at least not without adding significant code on top of Fugit. Any thoughts?
<d3zd3z[m]> My gut feeling on this, is that Fugit is actually just wrong about this. That when trying to convert time to a tick based timer, durations should always wait at least as long as the requested duration. At least this is how most RTOSes interpret this.
<d3zd3z[m]> So, I'm trying to figure out the best way to handle this. One is to just use Fugit's Duration/Instant as my delay type, and document the caveats. It's likely going to trip up people that are from Zephyr (or pretty much any other RTOS for that matter). Another would be to basically make my own Duration/Instant types. Since the rounding happens before I get the values, I'm not sure if there is a way to actually handle this just using
<d3zd3z[m]> the library.
<d3zd3z[m]> Actually, looking further, I think I just need to document that it is important to use millis_at_least in the fugit library. I think that will do what I need.
<GrantM11235[m]> It might be simpler and easier to use if you just define your own duration and instant types, the Fugit crate is pretty complicated because it tries to be very generic
<d3zd3z[m]> Implementing it myself would also be fairly complicated. The Zephyr macros are pretty complex as well. The problem of changing a time base is just kind of inherently complex, especially to make it do as much as possible at compile time.
<d3zd3z[m]> In my case, though, I will likely have a `pub type Duration = fugit::Duration<Tick, 1, SYS_FREQUENCY>;` where `Tick` and the `SYS_FREQUENCY` get defined based on the particular build and configuration being done.
<d3zd3z[m]> So, it should be pretty much as easy to use as a custom type, but someone can use more of Fugit if that is helpful to them.
crabbedhaloablut has quit []
crabbedhaloablut has joined #rust-embedded
bartmassey[m] has joined #rust-embedded
crabbedhaloablut has quit []
crabbedhaloablut has joined #rust-embedded
crabbedhaloablut has quit []
crabbedhaloablut has joined #rust-embedded
Lumpio- has quit [Ping timeout: 252 seconds]
Lumpio- has joined #rust-embedded