crabbedhaloablut has quit [Ping timeout: 265 seconds]
hmw has joined #rust-embedded
loki_val has quit []
crabbedhaloablut has joined #rust-embedded
crabbedhaloablut has quit [Ping timeout: 268 seconds]
loki_val has joined #rust-embedded
IlPalazzo-ojiisa has joined #rust-embedded
<re_irc>
<@thejpster:matrix.org> I'm finally looking at adding SD card support to the Neotron, and I think I've got a problem.
<re_irc>
This PR - https://github.com/rust-embedded-community/embedded-sdmmc-rs/pull/39 - which I approved back in 2021, seems to split out being in the "initialised" state (that is, you've done the SD card init sequence and the card is online and ready) into a new type. This new type, "BlockSpi", carries an "&mut" back to the parent "SpiSdMmc" device, which is what owns the SPI bus and chip select.
<re_irc>
My problem on the Neotron is, I expose a function based API from the BIOS to the OS. The OS can call a function at any point to "read a sector" or "write a sector". I don't want to repeat card initialisation on every sector read, so I need to cache the fact the card is online and ready. Unfortunately because "BlockSpi" carries a &mut reference, I can't put it in the same structure as the parent "SpiSdMmc" object.
<re_irc>
Maybe I can do something with pinning, but maybe I need to add back in the old way, which was the parent object just had an "is_initialised" flag inside. Easier to get wrong, but easier to store in a context object for later retrieval.
<re_irc>
<@thejpster:matrix.org> * thoughts?
<re_irc>
<@thejpster:matrix.org> Any thoughts>?
<re_irc>
<@jamesmunns:beeper.com> I'm not familiar with the code, but would destructuring help here? Something like:
<re_irc>
struct Ex {
<re_irc>
thingy: SomeType,
<re_irc>
flag: bool,
<re_irc>
impl SomeType {
<re_irc>
}
<re_irc>
fn do_thing(&mut self, flag: &mut bool);
<re_irc>
}
<re_irc>
fn example(ex: &mut Ex) {
<re_irc>
let Ex { flag, thingy } = ex;
<re_irc>
thingy.do_thing(flag);
<re_irc>
}
<re_irc>
<@thejpster:matrix.org> I'm not sure it does.
<re_irc>
<@jamesmunns:beeper.com> Yeah, I don't totally grok the shape of the problem you have, sorry :p
<re_irc>
<@jamesmunns:beeper.com> Unrelated, is there a library for using a slice "as a vec"? like if I want to push a variable chunk of things into a byte slice, or use it as something that impls Write?
<re_irc>
like I want to be able to do something like:
<re_irc>
<@thejpster:matrix.org> In std-lib land, isn't that a Cursor?
<re_irc>
<@jamesmunns:beeper.com> I know I can use heapless::Vec, but there are some cases where the buffer is passed in or whatever, and I don't want to make a new buffer then copy to the destination
<re_irc>
<@thejpster:matrix.org> Or a heapless Vec, but backed with a &mut slice instead having interior storage
<Shell>
there's arrayvec/tinyvec/smallvec
<re_irc>
<@jamesmunns:beeper.com> : Maybe! Heard of it but never used it
<re_irc>
<@jamesmunns:beeper.com> yeah, I don't want anything with owned storage
<re_irc>
<@jamesmunns:beeper.com> I basically want heapless vec, but with borrowed storage instead of owned storage
<re_irc>
<@diondokter:matrix.org> I don't know of any such library off the top of my head
<re_irc>
<@jamesmunns:beeper.com> Shell: Do any of these offer borrowed storage options instead of like their own "[u8; N]"?
<Shell>
tinyvec has SliceVec, seems to fit the bill maybe?
<re_irc>
<@diondokter:matrix.org> Shell: Oh cool!
<re_irc>
<@jamesmunns:beeper.com> Oh neat!
<re_irc>
<@jamesmunns:beeper.com> Yeah, that looks perfect, thanks Shell!
<re_irc>
<@jamesmunns:beeper.com> It's simple enough to write that I end up writing it up whenever I need it, but it seems silly to keep doing. Maybe I'll start using tinyvec's version :)
<re_irc>
<@diondokter:matrix.org> Ok, I have a question too. I've been doing some maintaining on Stackdump and spotted something that could be improved.
<re_irc>
So in DWARF you have these variables that have a memory location, but a memory location is not always valid in every context. Ok so far.
<re_irc>
But a location can be valid according to DWARF/rustc while the variable is not initialized yet or after it has dropped.
<re_irc>
Is there a way to detect from the PC or something else if we're before or after the lifetime of a variable?
<re_irc>
Because if there is, then I'd like to not print any invalid variables
<re_irc>
<@jamesmunns:beeper.com> : Ah yeah, I don't think there is any safe way to have self referential types like that. Like you said, you could do some unsafe stuff and use pin (and maybe projection?) to have the compiler try to help
<re_irc>
<@thejpster:matrix.org> : Based on the fact that lifetime analysis is done, and thrown away, before compilation, I would assume not
<re_irc>
<@jamesmunns:beeper.com> Unsafe "SdMmcSpi::new_skip_init()" function maybe? :p
<re_irc>
<@jamesmunns:beeper.com> : +1 to this, plus with NLL and friends, I'm not sure if you could reliably do things like base it on scope
<re_irc>
<@diondokter:matrix.org> : Yeah I'm afraid of that as well. It's just that I'm seeing a lot of things like 'this enum has a really weird discriminant' and then when I look, that enum simply hasn't been initialized yet, but the enum has been given a memory address
<re_irc>
<@diondokter:matrix.org> This info would help debuggers as well
<re_irc>
<@thejpster:matrix.org> How would it work? Some kind of property that says which variable is valid between which two program addresses? Now imagine an if statement where both branches initialise the object, but differently.
<re_irc>
<@thejpster:matrix.org> You need something like valgrind where memory isn't real, but instead is a big hashmap of <Key=Address, Value=(is_valid: bool, contents: u8)>
<re_irc>
<@diondokter:matrix.org> Well that already kind of exists. The memory location can be described in multiple places depending on the PC
<re_irc>
<@thejpster:matrix.org> Or simply write code that is correct, and then you don't need a debugger.
<re_irc>
<@diondokter:matrix.org> There could also be a list somewhere where it gives you all PC ranges where the variable is 'active'
<re_irc>
<@jamesmunns:beeper.com> : ah yes, the "git gud" approach to program correctness :D
<re_irc>
<@thejpster:matrix.org> : but there can be multiple ranges (the two branches of an if) and you don't know which one applies until run-time
<re_irc>
<@diondokter:matrix.org> There's lots of information that the compiler 'knows' but that isn't exported to DWARF. One other one is whether a type is transparent or not
<re_irc>
<@thejpster:matrix.org> let var = if condition() { do_stuff_a(); 0 } else { do_stuff_b(); 1 };
<re_irc>
<@thejpster:matrix.org> You'd have to write the rule as "address X is not valid until PC A has been visited, or PC B has been visited"
<re_irc>
<@diondokter:matrix.org> Yeah, I don't see what you're getting at... In this case it would say that "var" is active when PC > end of if statement
<re_irc>
let x = foo(); // a
<re_irc>
if y {
<re_irc>
let y: bool = ...;
<re_irc>
<@jamesmunns:beeper.com> I think a more problematic case is:
<re_irc>
drop(x); // b
<re_irc>
else {
<re_irc>
// ...
<re_irc>
}
<re_irc>
// ...
<re_irc>
return; // c
<re_irc>
<@thejpster:matrix.org> the compiler's free to re-order stuff. "var" could be intialised in the middle of "do_stuff_a()"
<re_irc>
<@diondokter:matrix.org> : Is it though? You can't use "x" anymore after the if statement
<re_irc>
<@jamesmunns:beeper.com> like, describing the regions that x is valid is challenging, but I think the core issue is that rust doesn't export it, and there's not really a reliable way to rebuild it after the fact
<re_irc>
<@thejpster:matrix.org> and the 'end of the if statement' doesn't make a lot of sense in assembly land. there's code, and there are jumps to addresses.
<re_irc>
<@jamesmunns:beeper.com> : yeah, but you don't know if the value is still valid, or when it is cleaned up
<re_irc>
<@diondokter:matrix.org> : Yeah, but the compiler knows from which PC that is. You could have multiple ranges. So "var" is active between 0x1000..0x1002 and 0x1010..0x1100
<re_irc>
<@jamesmunns:beeper.com> I agree with dion, "it would be neat if Rust exported liveness ranges for data"
<re_irc>
<@jamesmunns:beeper.com> I do think it would be possible, the question would be keeping that analysis correct through the whole compilation and optimization pipeline, so that it matches the pc and whatever of the final object code
<re_irc>
<@diondokter:matrix.org> : The compiler knows :)
<re_irc>
It has to insert the drop somewhere and it knows what the end of the scope is
<re_irc>
<@jamesmunns:beeper.com> (and I don't think that analysis is stable in any sense of the word)
<re_irc>
<@diondokter:matrix.org> Oh yeah, it'll be tricky to get right for the compiler for sure
<re_irc>
<@jamesmunns:beeper.com> Especially for cases where this isn't an actual drop (like for Copy types)
<re_irc>
<@jamesmunns:beeper.com> and the stack location might just be reused unceremoniously
<re_irc>
<@diondokter:matrix.org> But my feeling is that this info is already sort of known in the compiler. They need to keep track of the memory locations anyways. You can't reuse a stack location while it's still occupied by another alive variable
<re_irc>
<@jamesmunns:beeper.com> (and if there is a drop and it's a no-op, is it "valid" after that point? but that's probably splitting hairs)
<re_irc>
<@jamesmunns:beeper.com> I don't think rustc thinks in memory location
<re_irc>
<@jamesmunns:beeper.com> it thinks in all the different IRs it has, but memory allocation is done by llvm
<re_irc>
<@diondokter:matrix.org> : For the view of the programmer (which is the one I care about), no
<re_irc>
<@diondokter:matrix.org> Yeah, this is more in LLVM land than Rust land
<re_irc>
<@diondokter:matrix.org> Oh sorry, Rust™
<re_irc>
<@diondokter:matrix.org> Anybody getting impacted by the trademark shenanigans?
ni has quit [Remote host closed the connection]
<re_irc>
<@thejpster:matrix.org> Our current go-to for Ferrocene customers is to say "written in Rust, compiled with Ferrocene". We got that from OxidOS.
<re_irc>
<@diondokter:matrix.org> Right, well the organization with which we've been organizing meetups and now a small conference in amsterdam is called RustNL. Don't think we can keep that name with the new proposed rules. Neither can Rust Nation UK
<re_irc>
<@diondokter:matrix.org> Or EuroRust
<re_irc>
<@roy.buitenhuis-tnl:matrix.org> What new rules?
<re_irc>
<@thejpster:matrix.org> god damed bird site
<re_irc>
<@thejpster:matrix.org> put it on the blog (which I subscribe to with RSS) or it didn't happen
<re_irc>
<@thejpster:matrix.org> post a link to the blog on that turd soup if you insist
<re_irc>
<@thejpster:matrix.org> I would be grateful if someone could rant about this for me - not having a twitter account limits my ability to complain when they do policy-by-twitter
<re_irc>
<@thejpster:matrix.org> (and for the avoidance of doubt, my Strong Opinions on twitter don't preclude you having different opinions and/or enjoying twitter)
emerent has quit [Ping timeout: 246 seconds]
emerent has joined #rust-embedded
<re_irc>
<@thejpster:matrix.org> feedback mechanism aside, I don't personally have an issue with that draft policy. They need to protect their assets, and I've found the trademark people to be very prompt when I've queried things with them (e.g. the logo I used in the Embedded World demo I did).
<re_irc>
<@diondokter:matrix.org> I think it's too restrictive for an open source project/foundation
ni has joined #rust-embedded
<re_irc>
<@thejpster:matrix.org> which parts?
<re_irc>
<@diondokter:matrix.org> Say you write a blog post and use the rust logo somewhere you must explicitly distance it from any official association with the project
<re_irc>
<@diondokter:matrix.org> > You may use the following language or a close variation of it:
<re_irc>
> Disclosure: The material in this {book/paper/blog/article} has not been reviewed, endorsed, or approved of by the Rust Foundation. For more information on the Rust Foundation Trademark Policy, click here.
<re_irc>
<@diondokter:matrix.org> > I am producing educational materials (tutorial blogs, videos, etc.). Can I use Rust Marks in these? If so, what are the stipulations?
<re_irc>
> You can use the Rust name in book and article titles, and the Logo in illustrations within the work, as long as the use does not suggest that the Rust Foundation has published, endorsed, or agrees with your work. We require this to be stated up front (i.e. before the first paragraph or page of your work) in a clear and dedicated space. You may use the following language or a close variation of it:
<re_irc>
> Disclosure: The material in this {book/paper/blog/article} has not been reviewed, endorsed, or approved of by the Rust Foundation. For more information on the Rust Foundation Trademark Policy, click here.
<Shell>
(or of course you can simply not do this and cause a shitload of drama if the Rust Foundation sues you over a blog post about Rust.)
<re_irc>
<@jamesmunns:beeper.com> Tbh I don't the rules are particularly new
<re_irc>
<@jamesmunns:beeper.com> They just have never particularly been enforced
<re_irc>
<@jamesmunns:beeper.com> Like, there are more examples and a coat of paint on the docs, but those rules have existed pre foundation. Just nobody had the bandwidth to enforce them
<Shell>
they're not new, it's just that every time anyone brings attention to them much of the community goes "what the fuck" until the Rust Foundation clarifies they don't actually enforce anything.
<re_irc>
<@jamesmunns:beeper.com> Which means anyone who asked got silence or a "no", and anyone who just yolod had no repercussions
<re_irc>
<@diondokter:matrix.org> If you're not gonna enforce them, then just don't have these rules
<re_irc>
<@thejpster:matrix.org> I mean, yeah, what if the blog post is about killing kittens or other Awful Things? It's not your logo, and use of the logo implies endorsement. And you don't have to use the logo to talk about the language.
<re_irc>
<@diondokter:matrix.org> : Sure! But then make that your rule
<re_irc>
<@thejpster:matrix.org> The rule is "you have to ask permission"
<re_irc>
<@thejpster:matrix.org> Which I have found is not unreasonably withheld.
<re_irc>
<@jamesmunns:beeper.com> These rules are part of why I got (or pushed for us? I don't remember) explicit approval to use the rust logo as part of the embedded log
<re_irc>
<@jamesmunns:beeper.com> * logo
<re_irc>
<@thejpster:matrix.org> And Rust Embedded Community also did this, but failed
<re_irc>
<@jamesmunns:beeper.com> So even if we are questionably a project team, I have that approval in writing somewhere
<re_irc>
<@thejpster:matrix.org> These rules do mean I can't sell the Rust Embedded stickers we made. And possibly can't give them away at trade shows, which is a commercial endeavour. I'll make a note to ping someone about that.
<re_irc>
<@codec_abc:matrix.org> Hi guys, I am trying to get a serial port communication working between my discovery F3 and my PC but cannot succeed so far. Anyone available to help me troubleshoot it?
<re_irc>
<@jamesmunns:beeper.com> Hey codec_abc , can you share what code you are using, how things are wired up, and what you've tried?
<re_irc>
<@codec_abc:matrix.org> Program compiled just fine (using cargo run --release since with debug I had problem last time)
<re_irc>
<@codec_abc:matrix.org> For debugging reason I put a button that light a led when pressed and it work fine but the serial communication does seem to work
<re_irc>
<@codec_abc:matrix.org> Truth is I am not even sure on what connector I should plug the usb
<re_irc>
<@jamesmunns:beeper.com> You'll need two USB cables on the discover I think, one for the debugger and one for the "device" connection
<re_irc>
<@codec_abc:matrix.org> But once flashed, Can i plug to the other, reset the device instead of having 2 cables ?
<re_irc>
<@jamesmunns:beeper.com> I think so! As long as you aren't using semihosting
<re_irc>
<@codec_abc:matrix.org> When I do I have a device that is seen in Windows, but it tell me that the descriptor is not correct
<re_irc>
<@codec_abc:matrix.org> : What does it means?
<re_irc>
<@jamesmunns:beeper.com> Ah, I know windows is _weird_ about serial port things
<re_irc>
<@codec_abc:matrix.org> :(]
<re_irc>
<@jamesmunns:beeper.com> codec_abc: "cortex_m_semihosting" is a library some people use for printing things over the debugger connection. I _think_ it will block until the debugger is connected. If it's not in your Cargo toml, you should be fine
<re_irc>
<@codec_abc:matrix.org> Thanks, it does not seem to be here, so I should be fine
<re_irc>
<@jamesmunns:beeper.com> Lemme look if I can find docs on the windows specific stuff
<re_irc>
<@codec_abc:matrix.org> Thanks, there also might be bug in my code since I fought quite a lot to get something close to a sample compiling
<re_irc>
<@jamesmunns:beeper.com> Not 100% sure, it looks fairly okay from a first glance, though you might send "hello world" 1000x a second :D
<re_irc>
<@jamesmunns:beeper.com> What version of Windows are you using?
<re_irc>
<@codec_abc:matrix.org> Seems like progress to me :)
<re_irc>
<@jamesmunns:beeper.com> Does your button example still work?
<re_irc>
<@codec_abc:matrix.org> yes, and led 0 still on (which means poll return falsej0
<re_irc>
<@codec_abc:matrix.org> * false)
<re_irc>
<@jamesmunns:beeper.com> (you might try setting the led off at the start, and set it on if poll succeeds, but don't turn it back off ever)
<re_irc>
<@jamesmunns:beeper.com> it might blink faster than you can see.
<re_irc>
<@codec_abc:matrix.org> Once again you are right
<re_irc>
<@jamesmunns:beeper.com> Setting address is like the second step in the usb sequence, so it will have had some progress in polling
<re_irc>
<@codec_abc:matrix.org> It works !
<re_irc>
<@jamesmunns:beeper.com> 🎉
<re_irc>
<@codec_abc:matrix.org> I just removed my delay at the end of the loop
<re_irc>
<@codec_abc:matrix.org> I guess usb timing is too tight to have a 1ms pause
<re_irc>
<@jamesmunns:beeper.com> Interesting! Usually in more "production"-y examples, you'd use interrupts to be more specific about servicing the connection, but I think usb-device is written in a way where OVER polling is fine, as long as you aren't on battery power :)
<re_irc>
<@codec_abc:matrix.org> Yeah my goal is too make a custom controller to play rocket league (cannot be more geek than this I guess) In the end I think I will try to implement it in more industrial way using a appropriate device kind (namely trying to impersonate the xbox 360 controller)
<re_irc>
<@jamesmunns:beeper.com> (delay 1ms at the end also means that you always are a little LESS often than every 1ms, because the loop body takes some time)
<re_irc>
<@codec_abc:matrix.org> But I am not good at Rust and even worst at anything electronic related so I think sending the controller button state through serial port over USB is fine for now
<re_irc>
<@codec_abc:matrix.org> Anyway a big thanks, because now I just have to configure a bunch of PIN to digital and analog input and sending the whole thing over serial port, which should be a lot easier than this
<re_irc>
<@jamesmunns:beeper.com> (though it looks like that crate only supports mouse and keyboard)
<re_irc>
<@jamesmunns:beeper.com> but, congrats on the progress :)
<re_irc>
<@codec_abc:matrix.org> Last time I looked I couldn't find anything related to controller too. I am pretty sure it is not that difficult to implement for someone that know what he/she is doing but I am not :D
<re_irc>
<@codec_abc:matrix.org> : Well I just copied/pasted the code you gave me, but I am sure it count a little
<re_irc>
<@jamesmunns:beeper.com> gotta start somewhere, and you have something that works! I still copy and paste from examples VERY often, that's why they exist :D
<re_irc>
<@codec_abc:matrix.org> Very true, that's why Arduino is really great to hobbyist. It might not be clean or performant but it is really to start for people with no experience in it. Yet I am pretty impressed on the current state for Rust here. The tutorials as well as the crate features and the awesome community are really cool considering how young the Rust embedded story is.
<re_irc>
<@codec_abc:matrix.org> Is there a way to know the time elapsed since startup. I guess the clock can be used for this
<re_irc>
<@jamesmunns:beeper.com> Yeah, depends on the libraries/hardware you use. Not sure on the f3
<re_irc>
<@datdenkikniet:matrix.org> Rust, in space!
<re_irc>
<@diondokter:matrix.org> I just got interviewed by an intern from a space company in Antwerp. They're rewriting some stuff in Rust too :P
<re_irc>
<@datdenkikniet:matrix.org> * space!(?)
<re_irc>
<@jamesmunns:beeper.com> Yeah, I've seen a couple companies using it
<re_irc>
<@frroossst:matrix.org> Hi everyone,
<re_irc>
I'm part of the University of Saskatchewan's Space Design Team and we're currently working on building a rocket. We've been exploring the possibility of switching to Rust for our project, but we're facing some challenges due to the large number of CPP library dependencies we have. FFI could be an option, but it's not ideal due to the restrictions and difficulties of working with FFI and the memory un-safety of C/CPP.
<re_irc>
We're wondering if anyone has experience with writing their own embedded HAL for a micro-controller or re-implementing CPP libraries in Rust. We'd love to hear about any resources or advice you might have on how to get started with writing our own HAL so we can interact with the hardware directly and avoid having to drop down to C/CPP. We really don't know where to get started, there don't seem to be very well documented rust-embedded resources.
<re_irc>
PS: I'm a second year student, so go a little easy everyone haha.
<re_irc>
Thanks in advance for your help!
<re_irc>
<@jamesmunns:beeper.com> Hey! Do you know which processor you plan to use?
<re_irc>
has basic HID joystick support now. It's not hard to add more buttons and standard axes to this impl, will be a bit more to add sliders and POV hats but definitely achievable
IlPalazzo-ojiisa has quit [Quit: Leaving.]
<re_irc>
<@frroossst:matrix.org> : Right now we're using a Teensy 4.1 (ARM Cortex M7) but we are transitioning to a STM32 based micro-controller very likely the stm32f103c8t6
<re_irc>
<@frroossst:matrix.org> : I think a HAL for the stm32 we are planning on using exists, but I'm just not sure how to use it, but that I can figure out, my larger concern is all the CPP libraries, don't feel like RIIR on everything haha.
<re_irc>
<@jamesmunns:beeper.com> What kind of libraries are you wanting/needing from C++?
<re_irc>
<@frroossst:matrix.org> Like those Adafruit libraries for interfacing with the sensors over I2C or SPI