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.]
starblue has quit [Ping timeout: 240 seconds]
starblue has joined #rust-embedded
crabbedhaloablut has joined #rust-embedded
lehmrob has joined #rust-embedded
lehmrob has quit [Ping timeout: 260 seconds]
emerent is now known as Guest13
emerent has joined #rust-embedded
Guest13 has quit [Ping timeout: 258 seconds]
lehmrob has joined #rust-embedded
jsolano has joined #rust-embedded
jsolano has quit [Client Quit]
jsolano has joined #rust-embedded
jsolano has quit [Quit: leaving]
jsolano has joined #rust-embedded
lehmrob has quit [Remote host closed the connection]
jsolano has quit [Quit: leaving]
jsolano has joined #rust-embedded
jsolano has quit [Client Quit]
jsolano has joined #rust-embedded
jsolano has quit [Client Quit]
jsolano has joined #rust-embedded
jsolano has quit [Client Quit]
jsolano has joined #rust-embedded
jsolano has quit [Quit: leaving]
jsolano has joined #rust-embedded
jsolano has quit [Client Quit]
jsolano has joined #rust-embedded
<lulf[m]> <dirbaio[m]> "I wanted to do something like..." <- I was thinking maybe a way would be to create a FuzzFlash which could be created with write, read, erase and corruption rates. Upon performing the operation, it draws a random number and returns error or (in the case of writes) corrupts the data silently. Then one can just run this with different parameters many iterations. Logging all operations to reproduce a test error would be nice
<lulf[m]> too. Could be useful for anything working with embedded-storage traits
<lulf[m]> * a FuzzFlash implementing embedded-storage, which could
andresovela[m] has joined #rust-embedded
<andresovela[m]> How can I generate documentation for a binary crate? I tried the --document-private-items option but it still doesn't generate anything other than exit for my main crate
<andresovela[m]> My project is based off the knurling template, so it has a main.rs and a lib.rs
<andresovela[m]> It seems only lib.rs is being documented
<andresovela[m]> * How can I generate documentation for a binary crate? I tried the --document-private-items option but it still doesn't generate anything other than exit and panic for my main crate
starblue has quit [Ping timeout: 258 seconds]
starblue has joined #rust-embedded
<JamesMunns[m]> It's the difference between the lib and bin crate andresovela
<JamesMunns[m]> You might be able to pass cargo doc --bin or something like that?
<JamesMunns[m]> The knurling template actually gives you a structure that has two "crates" (sort of), the lib crate in lib-rs, and the bin crate of your application (main-rs or bin/whatever-rs)
<lulf[m]> * I was thinking maybe a way would be to create a FailFlash implementing embedded-storage, which could be created with write, read, erase and corruption rates. Upon performing the operation, it draws a random number and returns error or (in the case of writes) corrupts the data silently. Then one can just run this with different parameters many iterations. Logging all operations to reproduce a test error would be nice too. Could be
<lulf[m]> useful for anything working with embedded-storage traits
IlPalazzo-ojiisa has joined #rust-embedded
lkostka[m] has joined #rust-embedded
<lkostka[m]> What's your experience ?
<lkostka[m]> Hi. I am beginner in rust embedded. I am familiar with C, C++ embedded. I know how to optimise code, read assembly etc in C, C++. I wonder however how rust (with borrow checker) will emit fairly optimised code. My most concern is about interrupt handlers and global (static in rust case) variables like buffers.
<diondokter[m]> lkostka[m]: > <@lkostka:matrix.org> Hi. I am beginner in rust embedded. I am familiar with C, C++ embedded. I know how to optimise code, read assembly etc in C, C++. I wonder however how rust (with borrow checker) will emit fairly optimised code. My most concern is about interrupt handlers and global (static in rust case) variables like buffers.
<diondokter[m]> > What's your experience ?
<diondokter[m]> The borrow checker only exists at compile time. Your code can/will be just as close to the metal as C
<lkostka[m]> I think that I will use https://crates.io/crates/stm32f1 crate since it provides all registers and I will build higher abstractions myself. Only problem is that all of them are singletons. I do solve this problems in C++ with using/typedefs and a function that accepts it.
<d3zd3z[m]> <Mathias[m]> "d3zd3z: There is a way to read..." <- You're right, this does look like it verifies that the ECC is correct. It's kind of unfortunate that the ROM driver doesn't seem to support this, but at least the hardware does, and this looks easier to deal with than trying to recover from the fault.
<lkostka[m]> BTW how do you do conditional compilation. For example when you have multiple boards, one has 2 stepper drivers, second has 4, and for a twist they differ in MCU vendor ?
K900 has joined #rust-embedded
<K900> #[cfg] attributes
<diondokter[m]> lkostka[m]: For straightforward conditional compilation we have `cfg` and crate features: https://doc.rust-lang.org/reference/conditional-compilation.html
<diondokter[m]> With the change in PAC. we typically do that through the typesystem using traits
<diondokter[m]> s/we/We/
<diondokter[m]> Or macros I guess
mameluc[m] has joined #rust-embedded
<mameluc[m]> you can do a lot with features and hals but it also depends also on how much code is the same between the boards, sometimes it is just easier to have two projects and put the common code in another crate
<mameluc[m]> this is probably the fifth time I paste this and there is probably newer resources but this project helped me think about my project
waveguide[m] has joined #rust-embedded
<waveguide[m]> <lkostka[m]> "Hi. I am beginner in rust..." <- > <@lkostka:matrix.org> Hi. I am beginner in rust embedded. I am familiar with C, C++ embedded. I know how to optimise code, read assembly etc in C, C++. I wonder however how rust (with borrow checker) will emit fairly optimised code. My most concern is about interrupt handlers and global (static in rust case) variables like buffers.
<waveguide[m]> You can have global mutable statics, but access will need to be wrapped in unsafe and that’s just fine
<waveguide[m]> > What's your experience ?
Lumpio[m] has joined #rust-embedded
<Lumpio[m]> <lkostka[m]> "Hi. I am beginner in rust..." <- > <@lkostka:matrix.org> Hi. I am beginner in rust embedded. I am familiar with C, C++ embedded. I know how to optimise code, read assembly etc in C, C++. I wonder however how rust (with borrow checker) will emit fairly optimised code. My most concern is about interrupt handlers and global (static in rust case) variables like buffers.
<Lumpio[m]> > What's your experience ?
<Lumpio[m]> The borrow checker is entirely a compile time thing. I don't think it would be a cause of emitting less optimal code in and of itself. Rust's reference rules even allow optimizations that are not commonly done in C (like assuming there is no pointer aliasing - although I still don't remember whether that works yet or was it reverted again because it broke things.
<Lumpio[m]> However it is possible that you might need to use runtime stuff (like RefCell for example) to implement things the borrow checker cannot support in safe rust.
<JamesMunns[m]> Lumpio[m]: I think it's back now! It did go back and forth a few times over a few years.
<Lumpio[m]> s//`/, s//`/, s/./, while in C you wouldn't need that if you're sure you know what you're doing™./
FlixtheNewbie[m] has joined #rust-embedded
<FlixtheNewbie[m]> Yeah, it was a bit like reading a novel with a lot of episodes
Guest7221 has left #rust-embedded [Error from remote client]
StephenD[m] has joined #rust-embedded
<StephenD[m]> Question, but how are firmware updates normally implemented? At a high level I understand how they work but I'm curious if there are any crates or anything that makes it easier. I'm using rtic on an stm32
<StephenD[m]> Ideally I'd like to update the firmware using the normal usb_fs thing
<JamesMunns[m]> So, there's usually two ways (specific to usb+stm32):
<JamesMunns[m]> most stm32 devices have a "hardware bootloader" that can do DFU updates, meaning you don't have to write a bootloader
<JamesMunns[m]> Usually these are triggered by holding a GPIO low on reset, and then the hw bootloader takes over, and you can use standard tools to update the firmware
<JamesMunns[m]> the other way would be to write your own, which is usually only needed when you want some custom behavior like checking that the update is signed, or some kind of fail-safe mode, or work over some other interface like a radio or something
<firefrommoonligh> I let teh user download a standalone exectuable that does it
<firefrommoonligh> Per release
<firefrommoonligh> Run executable. It directs user to press the boot button while applying power and press a key when ready. Flashing happens
<StephenD[m]> firefrommoonligh: What we're talking about is what that executable would do - ie, how would it communicate with the stm32 - as well as how the stm32 would take in that data and apply it to flash
<firefrommoonligh> Probably will integrate it into the PC GUI software used to configure and check status as well
<firefrommoonligh> Oh
<firefrommoonligh> Wraps DFU-util
<firefrommoonligh> How the stm32 does it is magic (Something lower level than I work with)
<StephenD[m]> JamesMunns[m]: This is good to know. Does that communicate over the usb pins then?
<firefrommoonligh> Yes
<StephenD[m]> Awesome
<firefrommoonligh> I'm also trying to get a CAN bootloader set up for updates over CAN, but no luck there yet
<StephenD[m]> I'll look into DFU then, thanks
<firefrommoonligh> Btw, this is using the first process James already described
<JamesMunns[m]> StephenD[m]: Yup! I think it's also possible to "jump to bootloader" from the app as well, so you don't need to hold a GPIO. I've done it on some chips, but it wasn't super reliable always, but I could have been holding it wrong
<firefrommoonligh> And the CAN loader is the second wday James described
<firefrommoonligh> JamesMunns[m]: I think you need a custom bootloader for this; 99% sure it's possible, but I haven't done it
<JamesMunns[m]> there's an STM32 app note that has the hardware bootloader address in ROM and RAM for all the different families, which should be enough to allow you to "jump to bootloader" if you get the command in the app
<JamesMunns[m]> firefrommoonligh: Disagree! I've done this on stm32f0 and f4, iirc.
<firefrommoonligh> Really!
<JamesMunns[m]> well, "disagree you need a custom bootloader"
<JamesMunns[m]> yeah, for a while I had my panic impl just jump to the bootloader lol
<firefrommoonligh> Hmm. I should probalby try; would be useful and wouldn't need to expose the boot button on enclosures...
<JamesMunns[m]> "oh we panicked? time for a new firmware!"
<firefrommoonligh> V cool
<StephenD[m]> JamesMunns[m]: Oh nice. Just with a jmp instruction then?
<firefrommoonligh> James - is there an easy way to implement this?
<firefrommoonligh> Would you still wrap dfu-util, or some other way?
<JamesMunns[m]> today I'd probably use the cortex_m::asm::bootload function which does the msp + pc setting in one shot
<JamesMunns[m]> I think the issue I was having before is you probably also need to set the vtor through scb to do it. Note that those SP and PC constants vary by chip! You gotta find that app note.
<firefrommoonligh> I should prob switch to something like that
<JamesMunns[m]> firefrommoonligh: I was just using dfu-util with cargo-make at the time, iirc. cargo build to make the elf, objcopy to make a bin, pass to dfu-util to do the update
<StephenD[m]> I think actually I'll go the hardware route, so if the firmware update fails it doesn't brick the device. I'm working on hardware that I want to sell to ham radio operators so it's consumer-ish
<JamesMunns[m]> the f0 worked reliably, the f4 would sometimes get a little glitchy after a couple bootloads - like I said I THINK that was just not setting the VTOR, but I could be wrong.
<firefrommoonligh> So, I generally ship the devices with a UI program that interacts over USB/serial. It lets you do various config and checking everything's good etc. I've been doing the firmware updates as separate executables. Maybe when I integrate, I can skip the Boot0/DFU process like James does. Seems like saves a step and mildly simplifies enclosure design
<firefrommoonligh> I don't know what the risks are for the approach James uses, but the boot0 is, as far as I can tell, not possible to brick
<firefrommoonligh> (The only way I've managed to brick stm32s is by overvolting)
<JamesMunns[m]> yeah, you can't really brick the hw bootloader
<JamesMunns[m]> which is a nice benefit. even if an upload fails, if you do have the access to the boot0 pin (even if inconvenient), you're pretty much good to go.
<JamesMunns[m]> yeah, unless I had some kind of security or other reason (like requiring signed updates or something), I'd probably just use DFU + the hw bootloader on stm32 10/10 times
<StephenD[m]> JamesMunns[m]: Ah, so that's what the boot0 pin does. I assumed I could load two different programs onto flash and the boot0 would just set the initial pc
<JamesMunns[m]> StephenD[m]: uh, I think on some chips there is something vaguely like this? or it changes the flash mapping? depends on the chip
<StephenD[m]> I'm using an stm32f411 dev board with a boot0 pin
<JamesMunns[m]> I think on most newer chips there's only "force bootloader boot" on those pins, older ones had boot0 and boot1 which I don't remember all the permutations of
<firefrommoonligh> Btw, a lazy option is to offer the .bin file as a download, and direct the user to use Boot0 with STM32-cube-programmer, but IMO it's not user friendly and the download for that alone is bloaty
<JamesMunns[m]> (f411 is relatively "older" tho, so boot0/1 stuff may apply, read your reference manual to find out more 😅)
<firefrommoonligh> It's sometimes surprising which parts of STM32 hardwares are conserved among the various generations and which aren't
<firefrommoonligh> Yea god bless dirbaio
<firefrommoonligh> I have that bookmarked and check it from time to time
<FlixtheNewbie[m]> <JamesMunns[m]> "yeah, for a while I had my panic..." <- That's a good idea actually. I'm gonna do that
<JamesMunns[m]> FlixtheNewbie[m]: Yeah, I only did that during development, but it was pretty conceptually funny to me
<firefrommoonligh> I hate how I'm so reliant on one line of MCUs, but the series as a whole is so flexible, and so much code and PCB design considerations are conserved
<StephenD[m]> `Bus 001 Device 007: ID 0483:df11 STMicroelectronics STM Device in DFU Mode`
<StephenD[m]> sick, it worked
<firefrommoonligh> Is that DFU-util?
<FlixtheNewbie[m]> JamesMunns[m]: It's not my job, it's for something I use daily, so its' the right context for me to do that
<JamesMunns[m]> that looks like lsusb
dreamcat4 has joined #rust-embedded
<d3zd3z[m]> It seems that with the lpc55-hal, if I chain-load to another app, and it tries to set the clocks, the pll programming just locks up.
<d3zd3z[m]> I guess I do need to look more into the crate.
<d3zd3z[m]> I'm guessing that the code isn't correctly moving the CPU clock away from the pll before trying to program it.
<JamesMunns[m]> Some HALs may just assume that clocks and such are in a default state when configuring, which may not be true for chain loading. I recently solved this by having the bootloader:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/ikPZKonGYjsZIWAqfzKsyvRb>)
<jessebraham[m]> "contains no tokens or contains more than one token" ???
burrbull[m] has joined #rust-embedded
<burrbull[m]> how patch looks like? and which registers do you try to collect?
<burrbull[m]> `T?CONFIG:`
<jessebraham[m]> I had tired T*CONFIG and T%sCONFIG, both of which work for the other devices' SVDs
<jessebraham[m]> It's just this one that for some reason won't collect
<jessebraham[m]> And I don't see any differences that would cause this in the SVD, and the error messages gives me zero clues 😅
<jessebraham[m]> I will take a break and take another look though, I guess
<burrbull[m]> `"T%sCONFIG": {}` -> `"T?CONFIG: {}"`. This is glob-like pattern to find registers you want to collect.
<burrbull[m]> * `"T%sCONFIG": {}` -> `"T?CONFIG": {}`. This is glob-like pattern to find registers you want to collect.
<burrbull[m]> If you want to specify array name manually:... (full message at <https://catircservices.org/_matrix/media/v3/download/catircservices.org/pFAckJPVDjWvlRYuSvUDVTGK>)
<burrbull[m]> * `"T%sCONFIG": {}` -> `"T?CONFIG": {}`. This is glob-like pattern to find registers you want to collect. It automatically replaces common part with "%s"
xfbs[m] has quit [Quit: Idle timeout reached: 172800s]
<burrbull[m]> * `"T%sCONFIG": {}` -> `"T?CONFIG": {}` or `"T*CONFIG": {}`. This is glob-like pattern to find registers you want to collect. It automatically replaces common part with "%s"
<jessebraham[m]> T%sCONFIG, T*CONFIG, and T?CONFIG all have the same behaviour. I've just hacked around this using _modify/_delete instead of _array for these registers, for now.
<burrbull[m]> what error with *. It should be different
<jessebraham[m]> It's the same lol
<jessebraham[m]> It's fine I've moved on for now, couldn't figure out why it worked for 2 chips but not the others 🤷
Guest7221 has joined #rust-embedded
<burrbull[m]> possibly it is due to https://github.com/rust-embedded/svdtools/pull/166. Could you try svdtools 0.3.3, please?
thejpster[m] has quit [Quit: Idle timeout reached: 172800s]
elpiel[m] has quit [Quit: Idle timeout reached: 172800s]
pacarito[m] has quit [Quit: Idle timeout reached: 172800s]
<jessebraham[m]> Will probably have to wait until tomorrow but I can give it a shot
thalesfragoso[m] has quit [Quit: Idle timeout reached: 172800s]
hayley_gayley[m] has quit [Quit: Idle timeout reached: 172800s]
bartmassey[m] has quit [Quit: Idle timeout reached: 172800s]
ChaeyoungLee[m] has joined #rust-embedded
<ChaeyoungLee[m]> Hi! I'm new to this channel. Has anyone worked with Rust on STM32U5 series before?
<dirbaio[m]> yes, embassy-stm32 has quite complete support for it
<ChaeyoungLee[m]> yeah it seems like there's no stm32-rs support :/
<M9names[m]> embassy-stm32 is pretty good, why not give it a try?
<ChaeyoungLee[m]> i got it set up! i'm just familiar with stm32-rs
<ChaeyoungLee[m]> 'm playing with the examples script rn, [blinky.rs](https://github.com/embassy-rs/embassy/blob/main/examples/stm32u5/src/bin/blinky.rs) specifically. I changed the LED pin from `p.PH7` to `p.PH6` and the code won't get loaded. Any idea why it's not working? Both PH6 and 7 should be LEDs on the stm32u5 eval board.
<ChaeyoungLee[m]> * I'm playing
<dirbaio[m]> did you change the chip in both Cargo.toml and .cargo/config.toml ?
<ChaeyoungLee[m]> Cargo.toml yes, .cargo/config not really since I'm using GDB instead of probe-rs
<dirbaio[m]> and it works with PH7 and not PH6?
<ChaeyoungLee[m]> Actually just fixed it, the problem was with the memory.x
<ChaeyoungLee[m]> Both LEDs are getting lit up, sorry about that
<dirbaio[m]> ahh nice
<ChaeyoungLee[m]> embassy-stm generates a memory.x for the board right
<dirbaio[m]> yes
<dirbaio[m]> but you can provide your own too
<ChaeyoungLee[m]> yeah I was using mine and didn't specify the region for OTP
<ChaeyoungLee[m]> Perfect, thanks for the help!
fu5ha[m] has quit [Quit: Idle timeout reached: 172800s]
jannic[m] has quit [Quit: Idle timeout reached: 172800s]
duderonomy has joined #rust-embedded
Guest7221 has left #rust-embedded [Error from remote client]
Guest7221 has joined #rust-embedded
dngrsspookyvisio has quit [Quit: Idle timeout reached: 172800s]
<dirbaio[m]> it's in worse shape than what I remembered, it uses curve25519-dalek for quite a bit of stuff that's not the core
<dirbaio[m]> in particular, standard ed25519 requires sha512, which means it uses Scalar::from_bytes_mod_order_wide() which is a bit nontrivial and could be optimized using the fe25519 asm
Guest7221 has left #rust-embedded [Error from remote client]
IlPalazzo-ojiisa has quit [Quit: Leaving.]
IlPalazzo-ojiisa has joined #rust-embedded