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
alex[m]1 has quit [Quit: Idle timeout reached: 172800s]
tschundler has quit [Ping timeout: 276 seconds]
tschundler has joined #rust-embedded
igiona[m] has quit [Quit: Idle timeout reached: 172800s]
emerent has quit [Ping timeout: 248 seconds]
emerent has joined #rust-embedded
nickez[m] has joined #rust-embedded
<nickez[m]> Hi everyone! I read that static muts are being removed from the language. What is the best way to store global mutable state? static UnsafeCell? I'm developing an SDK and getting callbacks for various events. I need to keep some state between the callbacks.
<nickez[m]> * Hi everyone! I read that static muts are being removed from the language. What is the best way to store global mutable state? static UnsafeCell? I'm developing against an SDK and getting callbacks for various events. I need to keep some state between the callbacks.
<nickez[m]> * Hi everyone! I read that static muts are being removed from the language. What is the best way to store global mutable state? static UnsafeCell? I'm developing against a c-based SDK and getting callbacks for various events. I need to keep some state between the callbacks.
<diondokter[m]> nickez[m]: My goto for these kinds of things now: https://docs.rs/grounded/latest/grounded/
<diondokter[m]> Pay good attention to the docs!
<diondokter[m]> Mostly the GroundedCell
<nickez[m]> diondokter[m]: > <@diondokter:matrix.org> My goto for these kinds of things now: https://docs.rs/grounded/latest/grounded/
<nickez[m]> > Pay good attention to the docs!
<nickez[m]> Thanks! I'll take a look, haven't seen that crate before
<nickez[m]> <diondokter[m]> "Mostly the GroundedCell" <- Do you usually build some sort of abstraction on top of that, or just use raw pointers everywhere?
<diondokter[m]> Build something on top. You don't want to deal with raw pointers everywhere
<nickez[m]> the cpu is cortex-m0, so single threaded, and my callbacks are only called from the main thread (I assume)
<diondokter[m]> But if that's your goal, you might want to look at static-cell which does this for you and doesn't require you to write unsafe
<nickez[m]> I'm not sure what my "goal" is yet. I want to use rust, and I want to be able to write somewhat safe and idiomatic code. static-cell seems much better documented than grounded.
<JamesMunns[m]> (author of grounded): If static-cell works for your needs you should definitely use that!
<nickez[m]> static-cell doesn't seem to solve my use case, since I need to "put the state back" somehow when I'm done with it in the callback
<nickez[m]> Hmm, do you mean that I cannot execute `&mut *STATE.get()` in every invocation of the callback?
<diondokter[m]> nickez[m]: Only if it's absolutely guaranteed that only one thing at a time can do this.
<diondokter[m]> So usually behind a mutex
<nickez[m]> there is only one thread and interrupts will not call this handler. So do I need a mutex?
<diondokter[m]> This also includes interrupts!
<diondokter[m]> Interrupts are the same threads in the regard
<diondokter[m]> nickez[m]: No
<nickez[m]> goody, then I'll use grounded for now
<diondokter[m]> * the same as threads in
<diondokter[m]> * This also includes interrupts!
<diondokter[m]> Interrupts are the same as threads in this regard
<nickez[m]> James Munns: Sorry for complaining. But the front page of the `grounded` docs didn't include any examples. So for a newbie like me it wasn't clear how it would solve my problems.
<JamesMunns[m]> yep, happy to answer any questions, it definitely needs more docs!
<JamesMunns[m]> It's basically a "building block" for people building unsafe data structures, it would be good to know what kind of behavior you are trying to build
<nickez[m]> I think step one could be to just mention GroundedCell on the front page.
<nickez[m]> I'm using static mut to keep global state between invocations of the same callback handler. And static muts are going away from the language. That is my "problem".
<nickez[m]> * I'm using static mut to keep global state between invocations of the same callback handler. And static muts are going away from the language. That is my "problem" that I'm trying to abstract around.
<nickez[m]> I feels like that should be a common use case in the "use a little rust with your C" section in the embedded book.
<nickez[m]> s/feels/feel/
<diondokter[m]> nickez[m]: You could also consider using the embassy thread-mode mutex.
<diondokter[m]> It makes sure you're only locking it from thread mode giving guarantees about the behavior making all use of it safe
<diondokter[m]> It's not even really a mutex
<nickez[m]> perhaps there is some way to compose the SDK with something like Embassy so that I can keep the state in async functions. But that seems like a far to big project for now
<nickez[m]> So that all the callbacks form the SDK just awake some waker in some async runtime
Artea has joined #rust-embedded
<nickez[m]> s/form/from/
flippette[m] has joined #rust-embedded
<flippette[m]> hi, i have this repo
<flippette[m]> and for some reason, uart-tx.rs and uart-rx.rs will not build in debug mode, only in release mode. what's happening?
<JamesMunns[m]> What error do you get?
<JamesMunns[m]> This looks like it is for the arduino, it's possible that you have just run out of code/flash memory? debug creates very large code.
<flippette[m]> something along the lines of `extern function not found`
<flippette[m]> JamesMunns[m]: the release binaries are <1kB each, surely debug builds aren't blowing the flash right?
<JamesMunns[m]> debug binaries can be significantly larger
<JamesMunns[m]> It would not surprise me if debug was 10x larger than release
<flippette[m]> flippette[m]: that and `address <something> of .elf section '.data' is not within region 'data'`
<JamesMunns[m]> can you paste the full error onto a github gist or pastebin?
<JamesMunns[m]> it's hard to debug without any information :)
<flippette[m]> JamesMunns[m]: but i've already put `opt-level = "z"` into `[profile.dev]` though?
<flippette[m]> JamesMunns[m]: give me a moment
<JamesMunns[m]> This needs to go in `Cargo.toml` not `.cargo/config.toml`
<JamesMunns[m]> build-std uses your Cargo.toml profile
<flippette[m]> huh
<flippette[m]> i always thought it had to be in `.cargo/config.toml`
<JamesMunns[m]> not as far as I know! I'm pretty sure about it.
<flippette[m]> JamesMunns[m]: here's the cargo output
<JamesMunns[m]> > The functionality implemented today is behind a flag called -Z build-std. This flag indicates that Cargo should compile the standard library from source code using the same profile as the main build itself.
<JamesMunns[m]> flippette[m]: I don't see anything, did you forget to paste the link?
<flippette[m]> JamesMunns[m]: the network where i am is kind of terrible
<JamesMunns[m]> > section `.data' is not within region `data'
<JamesMunns[m]> These errors are typical when you have overflowed the available RAM (too many statics or constant values) or FLASH (too much code)
<JamesMunns[m]> The other error is weird (missing memcmp), but at that point it could be just that linking has totally failed and run out of space so symbols were dropped? not sure.
chrysn[m] has joined #rust-embedded
<chrysn[m]> I haven't managed to spot almost anyone I know from here at EuroRust -- did I miss the secret cabal room?
<diondokter[m]> chrysn[m]: Ha, well my colleague tamme is around somewhere!
<chrysn[m]> yes, he's the "almost" :-)
<diondokter[m]> Ah haha
<JamesMunns[m]> JP and Amos (fasterthanlime) are there AFAIK
<thejpster[m]> I haven’t seen Amos.
AlexandrosLiarok has quit [Quit: Idle timeout reached: 172800s]
okhsunrog[m] has joined #rust-embedded
<okhsunrog[m]> can I use cargo embed for RTT with C projects, without Rust?
<okhsunrog[m]> * can I use cargo-embed (from probe-rs) for RTT with C projects, without Rust?
<JamesMunns[m]> <okhsunrog[m]> "can I use cargo embed for RTT..." <- As far as I know, yes (plain RTT, not defmt-over-RTT)
cbjamo[m] has quit [Quit: Idle timeout reached: 172800s]
Koen[m] has quit [Quit: Idle timeout reached: 172800s]
wassasin[m] has quit [Quit: Idle timeout reached: 172800s]
FreeKill[m] has joined #rust-embedded
<FreeKill[m]> Ello - Out of curiosity is there a standard/known way to parameterise a function or struct with values that may or may not be known at compile time?... (full message at <https://catircservices.org/_irc/v1/media/download/AZxU2L4VFnRiEoSEQ18y4cUFMMKyRI3uN683m2EB6EePlsapmv-b0lD5nYnn_YumyYreBkMdDC2-AVdkE5V00tRCeSdz0qbAAGNhdGlyY3NlcnZpY2VzLm9yZy9pSVJ1UU51eGVYaUxVZ0lwR2xpR1RqVEY>)
<FreeKill[m]> * Ello - Out of curiosity is there a standard/known way to parameterise a function or struct with values that may or may not be known at compile time?... (full message at <https://catircservices.org/_irc/v1/media/download/AQi9DxPByHzMLgT_lxiC-fsufhJVI4dsn5-DJfeVSGI5a-4A5LSHAkv5niRImL_6XoMVhOHp9tl9x8_-e8LOSsdCeSdz3BngAGNhdGlyY3NlcnZpY2VzLm9yZy94Z0V3VVlMUm5helhSY3NCS1pSbEljenc>)
<FreeKill[m]> (it admittedly makes more sense on structs)
<dirbaio[m]> the compiler is pretty good at propagating constants
<dirbaio[m]> if you compile with --release and lto=fat etc, if you just make the function take a regular `usize`, and only ever call it with one value, the compielr can propagate that knowledge into the function usually (or even better, inline it)
<dirbaio[m]> it's not guaranteed, while with your trait Constable it would be guaranteed
<dirbaio[m]> but still, it works well enough that tricks like these are generally not worth the xomplecity
<dirbaio[m]> s/xomplecity/complecity/
<dirbaio[m]> s/xomplecity/complexity/
<FreeKill[m]> Ok cool!
<FreeKill[m]> It presumably can't do that with structs, right? It can't decide that some field always has a known value and so choose not to allocate it?
<FreeKill[m]> Or maybe it can, I guess there's no such thing as a struct at the end of the day as far as the optimiser is concerned
<dirbaio[m]> it probably can yea
sourcebox[m] has quit [Quit: Idle timeout reached: 172800s]
bartmassey[m] has quit [Quit: Idle timeout reached: 172800s]
d3zd3z[m] has quit [Quit: Idle timeout reached: 172800s]
romancardenas[m] has quit [Quit: Idle timeout reached: 172800s]
jannic[m] has quit [Quit: Idle timeout reached: 172800s]
rmsyn[m] has quit [Quit: Idle timeout reached: 172800s]
therealprof[m] has quit [Quit: Idle timeout reached: 172800s]
adamgreig[m] has quit [Quit: Idle timeout reached: 172800s]
rrme[m] has joined #rust-embedded
<dirbaio[m]> it's a bug that needs fixing in stm32l4xx-hal
<rrme[m]> Alright it's not me then, thank you
<dirbaio[m]> I wonder when rustc introduced that error
<dirbaio[m]> stm32l4xx-hal hasn't seen commits in 2 years
<dirbaio[m]> if you want a more maintained hal for stm32l4 check out embassy-stm32
<rrme[m]> Great thank you!
<flippette[m]> <JamesMunns[m]> "not as far as I know! I'm pretty..." <- and i just tested, it does make a difference: putting the section into `.cargo/config.toml` reduces the size by a little bit
<JamesMunns[m]> You need to use the size binutil, not the size of the elf file on disk
<JamesMunns[m]> The latter could just have more metadata in the elf.
<JamesMunns[m]> Huh!
<JamesMunns[m]> Til then, thanks for checking!
<JamesMunns[m]> The latter could just have more metadata in the elf.
<JamesMunns[m]> Edit: nope
d3zd3z[m] has joined #rust-embedded
<d3zd3z[m]> Is anyone here interested/available to do code reviews for my work on adding support for running no-std apps on the Zephyr RTOS? The Zephyr project likes to see two code reviews on each change, and although I didn't have much problem with the initial support, as my code is getting meatier, I'm not finding a lot of people in the project.
JomerDev[m] has quit [Quit: Idle timeout reached: 172800s]
sajattack[m]1 has joined #rust-embedded
<sajattack[m]1> adamgreig I'm trying to use spi-flash-rs on AVR and running into some issues because you specify capacity as usize which is 16bit on AVR and I'm trying to work with a 128K spi flash. Any recs?
<flippette[m]> <flippette[m]> "> <@flippette:matrix.org> hi..." <- > <@flippette:matrix.org> i'm still messing around with cargo, and adding `build-std-features = ["panic_immediate_abort"]` gives off this linker error... (full message at <https://catircservices.org/_irc/v1/media/download/ASrNNTdRXwNTHkKTLpdvaQ2IXQHFquDAaIEOM6W1epL3vmik-v_1Xscg2cfo6NzlEKzXTDjZhCi5DpuXIHQauWJCeSeL4BaQAGNhdGlyY3NlcnZpY2VzLm9yZy9hRXpFeWdDY1RNQ2V3QXJMRW1NZkZCRXI>)
<sajattack[m]1> add --release
<flippette[m]> how do i enable it for rust-analyzer?
<sajattack[m]1> hm idk
<sajattack[m]1> I just know my avr code runs out of registers if I don't build with release
<sajattack[m]1> did you use this? https://github.com/Rahix/avr-hal-template
<flippette[m]> i didn't
<sajattack[m]1> that might help
<flippette[m]> there's nothing about rust-analyzer in there though
<flippette[m]> and i really miss in editor diagnostics
<sajattack[m]1> well if rust analyzer is failing because your binary is too big or whatever using the template might fix that
adamgreig[m] has joined #rust-embedded
<adamgreig[m]> <sajattack[m]1> "adamgreig I'm trying to use spi..." <- Oh lol, I guess it probably shouldn't be usize then
<sajattack[m]1> also I'm specifically trying to work with ice40up5k's flash programming mode. And the SFDP thing panics somehow
Darius has quit [Ping timeout: 260 seconds]
<sajattack[m]1> the data[6] has 3 bytes
<sajattack[m]1> at line 316
<sajattack[m]1> but maybe I misunderstand how this is all supposed to work and I'm just misusing it
<sajattack[m]1> I tend to glaze over datasheets 😅
<sajattack[m]1> IIRC flashrom detects it as "Unknown SFDP-capable device"
<sajattack[m]1> I am setting CRESET low
<sajattack[m]1> oh right
<sajattack[m]1> I just remembered I set my exchange read buffer super small
<sajattack[m]1> that's probably the issue
Darius has joined #rust-embedded
omniscient_[m] has joined #rust-embedded
<omniscient_[m]> SiHo: Hey I only *just* got to this Im sorry. Yeah im exploring their offerings mroe for a new product actually
<omniscient_[m]> omniscient_[m]: Im keen to look at what you've done, if thats okay?
<omniscient_[m]> omniscient_[m]: I'm researching the EFR option further for a new product
<flippette[m]> <flippette[m]> "the release binaries are <1kB..." <- i've written a bit more code, and building in release mode _still_ gives this error... (full message at <https://catircservices.org/_irc/v1/media/download/AcXwxJpe_GYXge9RsCgSQBVQFMACdu0FvmHTtd-s5j762qTzw7l8BMpDoCl8MKAXgvLbabY9eOgl9aYDeU-rJCNCeSeQyUUwAGNhdGlyY3NlcnZpY2VzLm9yZy9SV0dhRmVKcWtIVEFvam1ScnZ3ZGdmeVg>)
<flippette[m]> here's uart-tx.rs right now: https://gist.github.com/flippette/a7698b022783192f36f8da89f0294726