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
IlPalazzo-ojiisa has quit [Quit: Leaving.]
emerent has quit [Ping timeout: 240 seconds]
emerent has joined #rust-embedded
IlPalazzo-ojiisa has joined #rust-embedded
IlPalazzo-ojiisa has quit [Client Quit]
d3zd3z[m] has joined #rust-embedded
<d3zd3z[m]> The rtic book (rtic.rs) seems to be describing 2.0 of rtic, yet crates.io only seems aware of a 1.1 version. Is there documentation for the released version?
<d3zd3z[m]> Or stepping back, is rtic how I should be doing concurrency? My firmware is working ok so far, just with a main loop, and spinning and polling, but I'd like to use interrupts for USB processing and the likes, and ideally be able to have a bit of scheduling. RTIC looks like a good fit, but I'm not sure what of it I should be using.
<dirbaio[m]> the crate name changed https://crates.io/crates/rtic
<d3zd3z[m]> Oh, nice.
crabbedhaloablut has joined #rust-embedded
<d3zd3z[m]> Trying to create a basic rtic on rp2040. It seems that as soon as I put variables in Shared, the first thing that tries to do a critical_section::acquire hangs forever there.
M9names[m] has joined #rust-embedded
<M9names[m]> Do you release the spinlocks like the Eric example does?
<M9names[m]> Eric==rtic, silly auto-carrot
andresovela[m] has joined #rust-embedded
<andresovela[m]> Hi, I'm having a problem naming a generic in my code. I have this struct to represent a driver:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/uMKcBQnUgtypKzNksPvKvIQE>)
<andresovela[m]> Then I have a BSP struct that looks like this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/rooBAbkoeRhDYFOKrtHOkVea>)
<andresovela[m]> I used to have this working when I had... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/tHNWrLtoHEMnRuwnFirsjHHf>)
<andresovela[m]> Because then I could write the same I write in the `Aw9523b` driver, namely... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/DyDCcXwgDThGkbqInoTgANvF>)
<andresovela[m]> But now I have no idea how to define E
lulf[m] has joined #rust-embedded
<lulf[m]> andresovela[m]: Instead of introducing the E, couldn't you also return `Result<(), Error<I2C::Error>>`
<andresovela[m]> lulf[m]: Let me try
<andresovela[m]> <andresovela[m]> "Let me try" <- Where does I2C::Error come from? I can't seem to find it
<andresovela[m]> andresovela[m]: I don't think I can remove the generic
<lulf[m]> lulf[m]: You have a bound on ErrorType for the I2C param, so you should be able to use that
<lulf[m]> lulf[m]: The only bound needed should be `I2C: embedded_hal_async::i2c::I2c` because it includes ErrorType iirc
<andresovela[m]> lulf[m]: I think I figured it out
<andresovela[m]> andresovela[m]: I had to do... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/zgkvWFncreonSVQUMxDmgiPk>)
<andresovela[m]> andresovela[m]: It's not compiling yet, but looks like it's for other reasons now
<lulf[m]> andresovela[m]: Ok, you can do that too, but it should be possible without the specific type
<lulf[m]> lulf[m]: Here's an example (although for SPI, slightly different traits but same structure): https://github.com/lulf/watchful/blob/main/pinetime-flash/src/flash.rs
<lulf[m]> lulf[m]: Maybe others have a generic i2c example to share
zyla[m] has joined #rust-embedded
<zyla[m]> <andresovela[m]> "But now I have no idea how to..." <- You don't have to define it. The bound `I2C: embedded_hal::i2c::ErrorType<Error = E>` constrains `E` to be `<I2C as embedded_hal::i2c::ErrorType>::Error`.
<zyla[m]> So inside the impl you can just use `E`, and when using `Ui` I think the compiler can infer it (at least this example suggest so: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0df091434ddeac8055f8336838b89dea)
<andresovela[m]> Yeah that's similar to what I had before, but now I removed the I2C generic, so I can't write I2C::Error
<andresovela[m]> <lulf[m]> "Maybe others have a generic..." <- This is the same, it has `SPI` as a generic
<andresovela[m]> andresovela[m]: Anyway, maybe I'll add the generic and get it over with
<fu5ha[m]> <andresovela[m]> "Then I have a BSP struct that..." <- > <@andresovela:matrix.org> Then I have a BSP struct that looks like this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/FBtjOSckFFLzgYcgnTbhdZoy>)
<fu5ha[m]> * In reply to @andresovela:matrix.org... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/GUkJbRpNpfFtCKPNkStLyOiQ>)
<fu5ha[m]> Blegh sorry formatting. Apparently editing a message on matrix mobile is a bad idea
<andresovela[m]> Let me try that
<andresovela[m]> It's telling me to use a fully qualified path, but I don't really get it
<fu5ha[m]> *
<fu5ha[m]> `E` is no longer generic. You've named the generic type `I2C` to be `I2cDeviceOnSharedBus` and you previously defined `E` to be equal to
<fu5ha[m]> `<I2C as I2c>::Error` so you can just substitute the generic that you've named and you get `<I2cDeviceOnSharedBus as I2c>::Error` which is just a single type. So get rid of the `E` generic on your impl block and just replace it with that
<andresovela[m]> The type is nasty
<fu5ha[m]> You want `<I2cDeviceOnSharedBus as embedded_hal_async::i2c::ErrorType>::Error` probably
<andresovela[m]> That seems to have done the trick :D
IlPalazzo-ojiisa has joined #rust-embedded
starblue has quit [Ping timeout: 255 seconds]
starblue has joined #rust-embedded
Guest7221 has left #rust-embedded [Error from remote client]
aflanagan has joined #rust-embedded
Guest7221 has joined #rust-embedded
<d3zd3z[m]> <M9names[m]> "Do you release the spinlocks..." <- > <@9names:matrix.org> Do you release the spinlocks like the Eric example does?
<d3zd3z[m]> That does seem to prevent the deadlock.
<d3zd3z[m]> Another rtic question, is it possible to initialize embedded alloc?
korken89[m] has joined #rust-embedded
<korken89[m]> It should work fine
<korken89[m]> https://github.com/rust-embedded/embedded-alloc does have an example that runs for me
<korken89[m]> d3zd3z: ^
<d3zd3z[m]> Thanks, I just had to move HEAP and HEAP_MEM to both be outside of the function, and just do the init in init.
<d3zd3z[m]> So, deeper question, I have a resource that I need both to be owned as a resource, but someone needs a `&dyn Trait` to it. As I understand lifetimes, these can't be in the same resource structure. Normally I'd solve this by Boxing, which does seem to work, but may not be the best.
<korken89[m]> A trampoline with the trait bound should work
<korken89[m]> So `cx.shared.my_resource.lock(|r| my_method_with_trait_bound(&mut r))`
<korken89[m]> Then my_resource can have a concrete type and my_method_with_trait_bound can use it
<korken89[m]> You can probably even do `&mut r as &mut dyn MyTrait`
<d3zd3z[m]> The 'dyn also needs to be given to a resource.
<d3zd3z[m]> In fact, I can make it work by having that resource just own it. But, the types quickly get very complicated.
<d3zd3z[m]> And, for the case of an array of gpio's are actually impossible to declare.
<korken89[m]> Yeah, I don't think that's going to be nice
<d3zd3z[m]> My pre-rtic code just relies on main not exiting, but that doesn't work here, with the init function returning things.
<korken89[m]> Rather than dyn trait I'd recommend you to use an erased pin
<korken89[m]> That's what I generally do when I need arrays of pins
<korken89[m]> E.g. this is what I do in a keyboard firmware: https://github.com/korken89/crkbd-shockburst/blob/main/firmware/src/bsp/keyboard.rs#L54
aflanagan has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<d3zd3z[m]> <korken89[m]> "Rather than dyn trait I'd..." <- `degrade` seems specific to your hal. I'm trying to see what the rp2040-hal is expecting me to use.
<d3zd3z[m]> It seems to be .into_dyn_pin().
aflanagan has joined #rust-embedded
<andresovela[m]> If I have a generic trait, how can I write a struct that has a field that needs to implement that trait? Something like this... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/UFqlIdjtHYNtpJKxfEAUBoBc>)
Guest7221 has left #rust-embedded [Error from remote client]
<andresovela[m]> If I try to write an impl like this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/vlsdMzZiSWsHjepMlCVXACWy>)
<andresovela[m]> It seems the solution is to make the trait non-generic and instead add an associated type
<d3zd3z[m]> <d3zd3z[m]> "> <@9names:matrix.org> Do you..." <- Is this something that should be considered a bug in rp2040_hal?
<dirbaio[m]> it's complicated
<dirbaio[m]> the root cause of the issue is probe-rs only resets core0, not the whole chip
<dirbaio[m]> because rpi's stupid nonstandard multicore implementation
<dirbaio[m]> since the spinlocks are in SIO, which is not part of core0, they don't get reset
<d3zd3z[m]> So, the reason this didn't show up pre-rtic is that I was using the rp2040-specific entry, whereas with rtic, it is using the generic cortex-m entry. There is a small block of code in the rp2040_hal that does this initialization. So, it is reasonable to do it this way here.
<dirbaio[m]> yep, rp-hal added their own entry macro to do the "reset spinlocks" thing as a workaround
<dirbaio[m]> but it's just that, a workaround
<d3zd3z[m]> Seems like this would go away if using something like a J-Link which runs a wire to the chip reset.
Noah[m] has joined #rust-embedded
<Noah[m]> hmm we should also use the wire if its available. but depending on where in the process its not possible
<d3zd3z[m]> Yeah, it isn't on the debug header that I designed to match the pico-probe. But, I could do that in a future board.
jannic[m] has quit [Quit: Idle timeout reached: 172800s]
adamgreig[m] has quit [Quit: Idle timeout reached: 172800s]
<thejpster[m]> Anyone else see a big size regresssion for hello-world on ARMv7E-M between 1.72.1 and 1.73??
<thejpster[m]> 4992 --> 6588 !
newam[m] has joined #rust-embedded
<newam[m]> <thejpster[m]> "4992 --> 6588 !" <- Wow! 👀 What optimization level?
<thejpster[m]> z
<cr1901> thejpster[m]: If you can give me an exact MCVE, I can test later/add to here: https://github.com/cr1901/msp430-size
Guest7221 has joined #rust-embedded
<cr1901> (ignore the repo name, I do ARM testing too)
<cr1901> I have the Rust source code checked out locally and build it once a week, so I have all the infrastructure to bisect (although cargo-bisect-rustc will probably work too since it's been less than 90 days since the regression)
<JamesMunns[m]> Looking at the release notes: https://raw.githubusercontent.com/rust-lang/rust/master/RELEASES.md
<dirbaio[m]> hae you diff'd the asm to see where the bloat comes from?
<JamesMunns[m]> Ones that stand out to me (as a wild guess):... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/OKhHRNpNdOSvLdeCiLLhHUGz>)
<dirbaio[m]> cargo-bisect-rustc might help too. my guess is it'll just point at one of these "update LLVM" commits :P
<cr1901> Yes, that is usually what happens wrt msp430 regressions, so then I end up having to bisect LLVM too :'D
<newam[m]> it's probably just LLVM adding / skipping a pass that it did previously.
<newam[m]> I think the rustc godbolt can show the LLVM passes now if you're interested.
<dirbaio[m]> also try opt-level=s. my experience is z is too conservative when inlining, which actually increases code size bloat because inlining allows optimizing more stuff away
<JamesMunns[m]> * Ones that stand out to me (as a wild guess):... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/DyucLCxYFWsyoVzDpQDmTQUj>)
<JamesMunns[m]> <thejpster[m]> "4992 --> 6588 !" <- Also, tbf: this is a large percentage increase, but not necessarily a very large total increase. Worth checking if you see similar results on a nontrivial project. That's why I included the panic format commit - formatting can easily influence a 1.5KiB change IMO
jasperw has quit [Ping timeout: 255 seconds]
<cr1901> The size has also gotten worse since 1.73... on nightly (960754090), it's using 8000+ bytes now
<JamesMunns[m]> Went to see if I could see it in https://perf.rust-lang.org/index.html, hard to tell because the size metrics aren't stripped, so they are all relatively huge
<JamesMunns[m]> Things seem to actually go down since July 1st, but again, the actual firmware is noise vs the debug info, and we may not actually have a bin crate in the perf tests, only a lib crate (stm32f4)
aflanagan has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
aflanagan has joined #rust-embedded
<cr1901> I cannot duplicate the 4992 result at all. Not anything close to it. What is the _exact_ command-line you're using?
Guest7221 has left #rust-embedded [Error from remote client]
Guest7221 has joined #rust-embedded
<thejpster[m]> cargo +1.72 build --bin hello
<thejpster[m]> in the nrf52-code/radio-apps folder
<thejpster[m]> I'm on macOS for Apple Silicon, if it matters
<thejpster[m]> Oh, also, unrelated, I found https://docs.rs/voladdress/latest/voladdress/ today. Author claims it is not incorrect, "unlike every other volatile crate"
<JamesMunns[m]> That's from Lokathor, who has been pretty vocal about it.
Guest7221 has left #rust-embedded [Error from remote client]
<d3zd3z[m]> Is there any kind of pre-existing utilities for clearing the I and D caches on Cortex-M, or do I need to access cortex_m::peripherals::cbp directly?
<dirbaio[m]> voladdress is not affected by the dereferenceable issue because it wraps a pointer
<dirbaio[m]> ie you use `VolAddress`, not `&VolAddress`
<dirbaio[m]> and you don't do "structs matching the layout of registers"
<dirbaio[m]> honestly it's simpler to generate code using raw pointers directly though, imo
GrantM11235[m] has joined #rust-embedded
<GrantM11235[m]> <dirbaio[m]> "voladdress is not affected by..." <- Actually it wraps a NonZeroUsize. Is there any difference (providence or whatever) between doing a single int-to-ptr cast on construction vs doing the cast for every access?
<dirbaio[m]> lol
<JamesMunns[m]> There was talk of "establish providence" for volatiles in the rust memory model, dunno if that's been stabilized tho
<JamesMunns[m]> the goal was to be able to say something like "I promise this is a pointer to something outside of memory known to the compiler", basically guarantee it's a MIMO value, not a local/stack/heap variable
<dirbaio[m]> in general using usizes for ptrs is a no-no
<dirbaio[m]> though it's true in this case that for device memory, the very first ptr comes from a usize, so perhaps it's fine
firefrommoonligh has joined #rust-embedded
<firefrommoonligh> Latest drone-device - maybe my first DC-DC design that didn't get the magic smoke
<firefrommoonligh> The magic smoke, in this case, thankfully didn't cause the demon fire which is assocaited with it at the relatively higher voltages involved
<firefrommoonligh> * The magic smoke, in this case, thankfully didn't occur, nor ignite the demon fire which is associated with it at the relatively higher voltages involved
<JamesMunns[m]> it's always good to remember that Rust's memory model is aiming at being "a stricter subset of what compilers actually understand", so that if you are good according to Rust's model, you are certainly good on whatever backend you use.
<JamesMunns[m]> Even if Miri says "oh no", LLVM might still say "cool whatever" (for now)
<firefrommoonligh> The actual rust firmware here is pretty straightfoward: Just reading from 14 ADC channels and outputting it over CAN
<JamesMunns[m]> JamesMunns[m]: > <@jamesmunns:beeper.com> it's always good to remember that Rust's memory model is aiming at being "a stricter subset of what compilers actually understand", so that if you are good according to Rust's model, you are certainly good on whatever backend you use.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/UKqXRYxLsLBSPtnxsHyvzhlA>)
<JamesMunns[m]> * but still - if you fall afoul of rust's rules, today's success may not predict future results (like all UB, tbh).
<JamesMunns[m]> However, stuff like MIMO and non-basic understanding of provenance is still not totally specified, afaik.
<JamesMunns[m]> s/providence/provenance/
<GrantM11235[m]> Would it be useful for chiptool to use nonnull instead of regular ptrs?
<JamesMunns[m]> As a total gut guess: I would say it probably doesn't matter. But I have nothing to back that up with. If you found out somewhere that NonNull is actually special in that regard, i'm totally interested
<JamesMunns[m]> afaik nonnull/nonzero is only used for niche-packing, e.g. `Option<NonZero/Null>` can be `== sizeof::<NonZero/Null>()`
<GrantM11235[m]> I guess my question is: does anyone use `Option<ChiptoolReg>`
<JamesMunns[m]> Ah, (my answer was wrt provenance, rather than general usage/perf)
<GrantM11235[m]> Yeah, providence should be the same. There is also covariance, but I don't think that matters when you are just using integers/integer-wrappers
<GrantM11235[m]> Actually I think covariance only matters for `NonNull<T>` when T has a lifetime. In this case it would just be `()`
<JamesMunns[m]> (also a note, I was saying providence before, when I meant provenance, it's been a long day 😅)
<JamesMunns[m]> (provenance is the origin or source of something, providence is divine assistance - we might need both here)
<GrantM11235[m]> eh, potato potato 🤷
<dirbaio[m]> hahaha I figured 🤣
jasperw has joined #rust-embedded
mameluc[m] has joined #rust-embedded
<mameluc[m]> what can I do to debug to debug this. My device runs for ~5ms with probe-run and then I get this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/nzqUOHccnPLPwufYJFhBnvQz>)
<mameluc[m]> it doesn't die at the same point every time
<dirbaio[m]> latest probe-rs?
<dirbaio[m]> try probe-rs run instead of probe-run
<mameluc[m]> ok Ill try. I have some problems installing probe-rs that I have to figure out
<dirbaio[m]> cargo install probe-rs --features cli doesn't work? what error does it give?
<mameluc[m]> ah yes, it was actually about the cli thing
<mameluc[m]> okay now it fails more consistently at the start 😅
<dirbaio[m]> progress! :D
<dirbaio[m]> stm32wl?
<dirbaio[m]> * is it stm32wl?
<mameluc[m]> you know it 😅
<mameluc[m]> wle so single core
<dirbaio[m]> ahh
<newam[m]> Yup, that's the problem target 😅
<dirbaio[m]> was about to suggest a workaround for the multicore one which is currently broken. but afaik the singlecore one should work :|
<newam[m]> Is this a devboard?
<mameluc[m]> yeah it has been working fine on other boards with the same chip
<newam[m]> Which board and what probe?
<mameluc[m]> yeah its my own board. Something broken. Works with HSI but not HSE
<mameluc[m]> and the flashing is flaky
<newam[m]> You can turn on verbose logging and get more information from what's going on at the bus level, but if it's only this one board I'd say it's a hardware issue
<mameluc[m]> I am using a module by Minew and my board is just power and pins. I am using a tag-connect connector that I didn't use before
<mameluc[m]> tried reducing speed
<newam[m]> Hmmm you said it runs for 5ms, does it actually get something from the target (verbose logs can show this)? If it does connect are you changing clock speeds in early boot?
<newam[m]> There are some clock configurations that don't jive with some debuggers
<mameluc[m]> I get defmt log, everything seems to be working fine until it stops
<mameluc[m]> if I reduce the program to just blinking a led it stays running
<newam[m]> Ah, so there is life. Yeah definitely check clocking/power/resets.
<mameluc[m]> and the speed thing I meant I reduced SWO speed
<mameluc[m]> I am using this for clock settings. Maybe should try to reduce that too
<newam[m]> Hmm I checked my notes. Only LPRUN @ 100kHz and MSI-driven sysclk @ 100kHz are problematic.
<newam[m]> (at least as far as I've experienced)
<newam[m]> so that should be fine
<newam[m]> I would definitely recommend bisecting around that code though.
<newam[m]> The mode of failure from probe-rs matches a code issue with clocking/power/resets.
<mameluc[m]> hmm Ill try to get more information
<newam[m]> There's also the brute force approach of single stepping until it fails :D
<newam[m]> I had a script for that in GDB - can't find it at the moment though
<mameluc[m]> I don't fully understand the reset mechanism
<newam[m]> hardware reset should be fine if you're able to connect to the target, when I say "resets" I mean something related to the CPU, debug logic, or things that manage clocking/power
<newam[m]> you're using embassy though, so unless you're driving the registers directly or doing other low-level things that shouldn't really be a problem.
<mameluc[m]> yeah and this code is working on another module with the same chip
<newam[m]> ah, hmmm.
<mameluc[m]> I have also changed the module (in case of hw failure in this particular one)
<newam[m]> same chip, but same hardware on this working module?
<mameluc[m]> well same setup with a crystal, I don't know more than that as I have not opened it up
neceve has joined #rust-embedded
<mameluc[m]> different RF stuff but that should not be the problem
<dirbaio[m]> I refactored the stm32wl rcc recently, I hope I didn't break anything 😊
<mameluc[m]> Minew module doesn't work
<mameluc[m]> wio-e5 module works
<dirbaio[m]> maybe double-check whether flash latency setting is right, i've seen that cause similar flakiness
<dirbaio[m]> are you doing flash write/erase operations?
<newam[m]> mameluc[m]: never say never :D
<newam[m]> I once accidentally wired up a STM32WL such that it shorted in some RF switch configurations. Not my brightest moment.
<mameluc[m]> dirbaio[m]: yes but later in the program. it should not have gotten that far
<mameluc[m]> newam[m]: > <@newam:matrix.org> never say never :D
<mameluc[m]> true :D
<mameluc[m]> > I once accidentally wired up a STM32WL such that it shorted in some RF switch configurations. Not my brightest moment.
<mameluc[m]> I checked the power buses in case there was shorts but I couldn't see anything with my scope
<mameluc[m]> also no exessive current spikes
<mameluc[m]> thanks for all the help. I just confirmed that it works with MSI, except it gets stuck on RNG stuff but at least the program runs and probe-rs doesn't complain
<dsvsdveg[m]> Is it possible to have code review? :)
<mameluc[m]> I can review any code. I give points for crative emoji use
azzentys117[m] has joined #rust-embedded
<azzentys117[m]> Question: Is there a common Rust based community on matrix or related?
<mameluc[m]> rust:matrix.org
<dirbaio[m]> #rust:matrix.org
<mameluc[m]> ah ,thats how you do it :D
<mameluc[m]> it was too high traffic for me
<azzentys117[m]> I was trying to use use match to do some bitmasked matches, a friend said that I can ask over there.
<azzentys117[m]> If anyone has any ideas here, they are appreciated.
<azzentys117[m]> I'm working on a Chip-8 emulator. So, I'm doing fancy thing like this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/CfThNIORJOQyOfhwvrDoQAuU>)
<azzentys117[m]> * I'm working on a Chip-8 emulator. So, I'm doing fancy thing like this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/ITzuTwxtQzgFBPJxMTWdLmZV>)
neceve has quit [Ping timeout: 255 seconds]
<newam[m]> > Thought maybe there is a good way to do this.... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/lsvxlfCqZAoEmswzwJgZGgRB>)
<azzentys117[m]> Oh it does work.
<azzentys117[m]> It is readable as well. Since, I'm doing this for learning Rust, I I was curious about how others would approach it.
<GrantM11235[m]> You could do a nested match like this... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/OaHQaZalilOplXvgRyolEHYa>)
<mameluc[m]> where do you get self.val_u12 from?
<azzentys117[m]> GrantM11235[m]: > <@grantm11235:matrix.org> You could do a nested match like this... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/AXBRvrkUqihHfQsbVlGpjGrK>)
<azzentys117[m]> mameluc: This is the struct I'm using... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/YNQHDNreAzItAaCJnJWfVftX>)
<azzentys117[m]> I just separate and carry around masked values.
<mameluc[m]> are the u4 and u8 the same bits as u12?
<azzentys117[m]> Yes, they are.
<mameluc[m]> I was just thinking that your match is doing two things. Matching the right command and figuring out what values to pass
<mameluc[m]> if you always passed all the bits to all commands they could figure out what they want to do with the data themselves
<GrantM11235[m]> I don't think you need the CommandConstruct type, you can just convert a u16 (or two u8s) directly into a Command
<azzentys117[m]> > they could figure out what they want to do with the data themselves
<azzentys117[m]> mameluc: I kinda don't want to do that. I could make another function to "pass" proper value. Each command ends up with what particular data it picks from the command.
<azzentys117[m]> * > they could figure out what they want to do with the data themselves
<azzentys117[m]> mameluc: I kinda don't want to do that. I could make another function to "pass" proper value. Each command ends up with what particular data it picks from the command.
<azzentys117[m]> * > they could figure out what they want to do with the data themselves
<azzentys117[m]> mameluc: I kinda don't want to do that. I could make another function to "pass" proper value. Each command ends up with what particular data it picks from the command.
<azzentys117[m]> Thanks for the advice!
<mameluc[m]> yeah thats cool whatever makes sense and is readable
<mameluc[m]> how many commands do you have?
<azzentys117[m]> 37
<azzentys117[m]> <GrantM11235[m]> "I don't think you need the..." <- You're right. I did it to try this out:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/kqIBtyQygtTsWWyDKRbVZtah>)
<mameluc[m]> sounds like a match like that with grants twaks is pretty nice for that amount of commands 👍️
<azzentys117[m]> > <@grantm11235:matrix.org> I don't think you need the CommandConstruct type, you can just convert a u16 (or two u8s) directly into a Command... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/YoFXuaUfNDqWjhdIlVEkxViY>)
<firefrommoonligh> Update your probe-rses. Check this new hotness:
<andresovela[m]> I want to test a no_std lib using std, but I'm running into issues. I added `#![cfg_attr(not(test), no_std)]` to my lib, and now I'm getting this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/rvjPbayAvkfuylavkPYntQES>)
<andresovela[m]> Does anybody have any tips?
<andresovela[m]> How do I switch targets for testing?
<GrantM11235[m]> If you replace CommandConstruct with this, you can lazily calculate the values when needed, so you don't need to do redundant work... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/DkvdEkaFTaYXXvJAgtCHRqEM>)
<GrantM11235[m]> It should work basically the same, just replace self.reg_x with self.reg_x()
<azzentys117[m]> GrantM11235[m]: > <@grantm11235:matrix.org> If you replace CommandConstruct with this, you can lazily calculate the values when needed, so you don't need to do redundant work... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/PnqwCGRCsMBmbRUNJackMctE>)
<mameluc[m]> andresovela[m]: > <@andresovela:matrix.org> I want to test a no_std lib using std, but I'm running into issues. I added `#![cfg_attr(not(test), no_std)]` to my lib, and now I'm getting this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/FnrUWXaBCCqwULjvkXKkQuQW>)
<andresovela[m]> I could probably make do without std, but I don't see why I should make my life miserable when I can just test using std
<mameluc[m]> I was just asking bc I was thinking the same thing and in the end I did not need std stuff for testing my particular firmware. I just tested the logic without std and the code was ofc no_std
<GrantM11235[m]> <andresovela[m]> "I want to test a no_std lib..." <- > <@andresovela:matrix.org> I want to test a no_std lib using std, but I'm running into issues. I added `#![cfg_attr(not(test), no_std)]` to my lib, and now I'm getting this:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/KkBRdUwOVruplKxihdIMHXgl>)
<andresovela[m]> Yes, that's not the problem
<andresovela[m]> I do want to use std
<GrantM11235[m]> Is that what you have?
<andresovela[m]> Yes
<andresovela[m]> I don't think the problem is with critical-section, but rather with my toolchain or something
<andresovela[m]> But I'm not familiar at all with how all that's supposed to work
aflanagan has quit [Quit: Textual IRC Client: www.textualapp.com]
<GrantM11235[m]> The error says that critical-section requires std, but you are building for thumbv6m-none-eabi
<GrantM11235[m]> Are you using edition = "2021"?
<andresovela[m]> Yes
<andresovela[m]> I think the problem is that I'm building for thumbv6m-none-eabi
<andresovela[m]> I want to run the tests on my machine
<GrantM11235[m]> Do you get that error when you run cargo test ?
<andresovela[m]> Yeah
<GrantM11235[m]> hmm, yeah that is a problem
<andresovela[m]> Ok I figured it out
<andresovela[m]> I have to add --target x86_64-apple-darwin to the cargo test command
<andresovela[m]> Is there a setting somewhere that I can set to use this target for tests?
<dirbaio[m]> nope
<dirbaio[m]> you can make aliases tho
<GrantM11235[m]> I think this is why people usually recommend separating you binary crate from your library code
<andresovela[m]> Separating as in?
<GrantM11235[m]> Make two crates. One is a library that has all your code that doesn't depend directly on the hardware. The second crate is a binary that uses that library and also has hardware-specific stuff
<andresovela[m]> That I have already
<andresovela[m]> But they're in the same workspace
<andresovela[m]> They all see the same .cargo/config.toml I guess
<GrantM11235[m]> Also, don't use workspaces, it causes these problems. The library crate shouldn't specify the target in config.toml
<andresovela[m]> Meh, it'd be really annoying to not have all the crates I use in my project in one repo
<GrantM11235[m]> You can keep the crates in one git repo without using a workspace
<andresovela[m]> Ah I think I know what you mean
<andresovela[m]> I'm not using a cargo workspace
<mameluc[m]> path = "../othercrate" is your friend
<andresovela[m]> But when I run cargo test it still compiles using the thumbv6m-none-eabi target that I set in my cargo/config.tom
<andresovela[m]> s//`/, s//`/, s/tom/toml/
<andresovela[m]> mameluc[m]: Yeah that's what I do
<mameluc[m]> put cargo/config in the subcrate?
<andresovela[m]> But I do want to normally build using the target for my MCU
<andresovela[m]> It's just for cargo test that I want to use my laptop's target
<mameluc[m]> basically this
<mameluc[m]> specifically this
<GrantM11235[m]> That example is overly complicated because it also includes running some tests on the mcu
<andresovela[m]> If I understand correctly, they're suggesting to create another crate just for tests?
<mameluc[m]> yes
<mameluc[m]> also another crate for logic that is not bound to embedded stuff if you have a lot of that
<andresovela[m]> That I have
<andresovela[m]> Several crates actually
<andresovela[m]> But it seems overkill to have to create a new crate for every crate I want to test
<mameluc[m]> then one embedded crate that is the actual firmware. To test that stuff you need to run stuff on hardware
<GrantM11235[m]> <andresovela[m]> "It's just for cargo test that..." <- You need to kinda invert your thinking. You "normally" want to build for your laptop (for tests), the exception is when you are building the binary for your mcu
<andresovela[m]> Surely there must be an easier way
<mameluc[m]> andresovela[m]: why not all the tests in the same crate?
<andresovela[m]> GrantM11235[m]: Not really, I "normally" want to build for my MCU, I'd run tests only every now and then
<andresovela[m]> mameluc[m]: I guess you can do that, but feels yucky
<andresovela[m]> Ideally you'd be able to have the test for crate foo in crate foo
<andresovela[m]> s/test/tests/
<mameluc[m]> put on some plastic gloves 👍️
<GrantM11235[m]> andresovela[m]: What I mean is that you should only set the target in the cargo config for your MCU binary crate
<andresovela[m]> Hmm
<andresovela[m]> Let me see what happens if I move it
<GrantM11235[m]> So when you build your mcu binary, it is compiled for thumbv6, but your other library crates will be compiled for your laptop when you run their tests
<andresovela[m]> Hmm I actually don't know where to move it to
<GrantM11235[m]> Put it in whichever crate has the main.rs that runs on your mcu
<GrantM11235[m]> You can't have your libraries nested inside the directory of your main crate like that
<dsvsdveg[m]> <mameluc[m]> "rust:matrix.org" <- are they any ethereum rust or ethereum matrix?
<dsvsdveg[m]> or blockchain matrix
<andresovela[m]> Sure you can, I see it all the time
<GrantM11235[m]> You need the libraries to be next to the main crate. Your top level directory should contain foo, bar, drivers, and my-main-mcu-binary
<mameluc[m]> dsvsdveg[m]: there is a search function in element
<andresovela[m]> But ok, I'll try it
<GrantM11235[m]> cargo looks for config files in parent directories also, so when you do cargo test from one of your libraries, it sees the config that is meant to be for your mcu binary
<andresovela[m]> Okay yeah it looks like that did the trick :)
<andresovela[m]> Thanks a lot!
<andresovela[m]> Good tips
sparky[m] has joined #rust-embedded
<sparky[m]> bit of a hard question but... anyone able to tell me what I did wrong with this compensation algo? not too familiar with C and clearly, the output data im getting is wrong. https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/aeWnGUgpEcXkLgmdrFHPuUrl>)
<sparky[m]> * bit of a hard question but... anyone able to tell me what I did wrong with this compensation algo? not too familiar with C and clearly, the output data im getting is wrong. https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp390-ds002.pdf
<sparky[m]> page 28 has the compensation data mix, https://github.com/sparky8251/bmp390/blob/0ca6013a71531f255fd9a4be5100a90981333465/src/lib.rs#L158-L177 is how i bunch it into a struct
<sparky[m]> temp comes out mostly as 0.0, while pressure seems to be absurdly small... like 1.9198516e23. it also only works in release mode cause of wrapping. unsure if its expected to wrap or not though
<sparky[m]> page 55 at the bottom mentions the temp compensation algo, then 56 is the pressure one. t_lin is the compensated pressure as mentioned at the top of 55 https://github.com/sparky8251/bmp390/blob/0ca6013a71531f255fd9a4be5100a90981333465/src/i2c.rs#L129-L182 are the two functions where I tried to replicate it.
<GrantM11235[m]> The first byte should be the low byte of T1, but you are using it as the high byte
Foxyloxy has joined #rust-embedded
<GrantM11235[m]> (same for all the other u16 and i16 values)
<mameluc[m]> maybe use u16::from_be_bytes(bytes)
<mameluc[m]> or le, too tired to figure out which one :D
cyrozap_ has joined #rust-embedded
thomas25- has joined #rust-embedded
crabbedhaloablut has quit []
lulf[m]1 has joined #rust-embedded
<GrantM11235[m]> Its LE
<sparky[m]> GrantM11235[m]: thats def a huge problem. ofc i didnt pay attention to that when writing it up... thanks for pointing that out. ill have to work through that
<GrantM11235[m]> For some reason the datasheet lists it in reverse order 🙃
HumanG33k has joined #rust-embedded
lulf[m] has quit [Ping timeout: 264 seconds]
Foxyloxy_ has quit [Ping timeout: 264 seconds]
cyrozap has quit [Ping timeout: 264 seconds]
HumanGeek has quit [Ping timeout: 264 seconds]
<sparky[m]> sadly, doesnt seem swapping the order for the u16s/i16s made any difference in the algo outputting total nonsense. still 0.0 for temp, and similar results for pressure to before
thomas25 has quit [Ping timeout: 264 seconds]
<GrantM11235[m]> The shifts and casts are also a bit sketchy when it comes to signed values, i16::from_le_bytes would definitely be clearer
<sparky[m]> GrantM11235[m]: which would be lsb,msb when supplying it?
<GrantM11235[m]> t1: u16::from_le_bytes([value[0], value[1]]),
<sparky[m]> zero change in output when swapping to from_le_bytes. def cleaner, so ill keep it but still busted output lol
<sparky[m]> thanks for the suggestion to make it way more readable
<GrantM11235[m]> Page 55 says you need to convert the integer values to floats, with some division
<sparky[m]> <GrantM11235[m]> "Page 55 says you need to convert..." <- ugh... right. i saw that, but totally ignored it. so, `u16 / f32 -> f32` is what i should use to convert them with the float being the 2^-8 number for par_t1?
<sparky[m]> > <@grantm11235:matrix.org> Page 55 says you need to convert the integer values to floats, with some division
<sparky[m]> * ugh... right. i saw that, but totally ignored it. so, `f32::from(u16/i16/u8/i8) / f32 -> f32` is what i should use to convert them with the float being the 2^-8 number for par\_t1?
<GrantM11235[m]> yeah
<sparky[m]> thatll learn me not to read well
<sparky[m]> thanks. ill get on that now
<GrantM11235[m]> I would do something like this... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/iLdEohTYDCeIpXjVFeRLVyJO>)
<sparky[m]> i just swapped the struct to be all f32, and am doing this t1: f32::from(u16::from_le_bytes([value[0], value[1]])) / 2.0.powf(-8.0),
<sparky[m]> this is where is constructed after all, and theres no use for data without the coefficient applied
<GrantM11235[m]> You can save ram by storing the values as 8 and 16 bit, and it should be super fast to convert on the fly and divide by powers of 2
<sparky[m]> ill keep that in mind if i happen to need it then. personal use driver on a picow with no_std, so RAM isnt the most pressing concern i have
<sparky[m]> for now... i want to see it work and im on like, hour 8 of non-stop focus on the issue lol
IlPalazzo-ojiisa has quit [Quit: Leaving.]
<GrantM11235[m]> yeah, it's only 21 bytes vs 56 bytes, so it doesn't really make much difference
<sparky[m]> hmm... powf isnt a function on floats?
<sparky[m]> same for pow... and powi
<GrantM11235[m]> there are a lot of float operations missing in core
<sparky[m]> any math libs for no_std that impl pow for f32 then?
<GrantM11235[m]> Oops, you want this one https://docs.rs/libm/latest/libm/fn.exp2f.html
<sparky[m]> seems a bit off that theres so many missing float ops for core? guess its just that no ones bothered to try and get it drafted and in or is there some really deep reason as to why?
<GrantM11235[m]> I think they are usually provided by a libc
<sparky[m]> but rust doesnt tend to rely on a libc in core contexts, right? lol
<sparky[m]> ah, i see..
<sparky[m]> shockingly, still zero changes to the output data. temp is always 0.0 and pressure is some absurd exponent in the 20s on average
<sparky[m]> i mustve done something really wrong to get it this screwed up 😄