<re_irc>
<@willeml:matrix.org> Does there need to be delays between sending mouse reports or something? Do I need to use interrupts?
emerent has quit [Ping timeout: 245 seconds]
emerent has joined #rust-embedded
<re_irc>
<@burrbull:matrix.org> newam: passing `optional = true` you create feature with name same as dependency. So with this code you've create 2 features with same name
<re_irc>
<@newam:matrix.org> burrbull: Yeah is there any way to avoid that so that I can use the 'defmt' name?
<re_irc>
<@newam:matrix.org> I tried renaming defmt, but that didn't work:
<re_irc>
<@newam:matrix.org> > That is, names of features take after the name of the dependency, not the package name, when renamed.
<re_irc>
<@henrik_alser:matrix.org> willeml: Looks like you’re using an old rtic version < 0.6? Then your type will be different depending on task priority, the lower prio task will have it wrapper in a Mutex
<re_irc>
<@willeml:matrix.org> Ahh, ok, thanks
<re_irc>
<@henrik_alser:matrix.org> So needs lock(|…..
<re_irc>
<@willeml:matrix.org> I am using 0.5
<re_irc>
<@willeml:matrix.org> I guess i will try to upgrade
<re_irc>
<@henrik_alser:matrix.org> Can recommend! 0.6 syntax is so much nicer!
<re_irc>
<@willeml:matrix.org> Ah yes, much nicer
<re_irc>
<@willeml:matrix.org> Oh awesome, thanks, I am just trying to get basic HID working, (using mouse to test) then I want to eventually create firmware for custom joystick/throttle or something for hotas
<re_irc>
<@henrik_alser:matrix.org> Last time i did a HID device there was an issue getting it to enumerate on windows (mac and linux works fine) turned out there was a missing field in the generated descriptors so had to code it by hand, i know perlindgren filed an issue but don’t know if it’s been fixed yet
<re_irc>
<@willeml:matrix.org> macOS here, so probably fine
<re_irc>
<@willeml:matrix.org> I keep getting Err(WouldBlock) whenever I try to send the HID report
cr1901 has quit [Read error: Connection reset by peer]
<re_irc>
<@henrik_alser:matrix.org> Do you allow it some time to empty the buffer or do you just spam it continously? What’s your poll rate?
<re_irc>
<@willeml:matrix.org> every 60ms I think
<re_irc>
<@willeml:matrix.org> And I don't have any buffer (that I know of)
<re_irc>
<@willeml:matrix.org> I know the example you sent uses on, but I cannot use one in the same way...
<re_irc>
<@willeml:matrix.org> (usbbus struct new function does not take a buffer as an argument like in the example you linked)
<re_irc>
<@henrik_alser:matrix.org> If you just spam it in the idle loop it won't allow it time to empty the usb endpoint memory in between your push_input calls
<re_irc>
<@henrik_alser:matrix.org> So you could either do your push_input in the USB interrupt handler task instead or you need to put some delay in your idle loop
<re_irc>
<@willeml:matrix.org> I have a `cortex_m::asm::delay(5_000_000)` in the idle loop
<re_irc>
<@henrik_alser:matrix.org> (Maybe not a good idea to do your print inside the lock there btw, you want as short as possible critical section)
<re_irc>
<@henrik_alser:matrix.org> Where do you poll?
<re_irc>
<@henrik_alser:matrix.org> do the interrupts fire?
<re_irc>
<@willeml:matrix.org> rx does
<re_irc>
<@willeml:matrix.org> I don't see tx firing though
<re_irc>
<@henrik_alser:matrix.org> what happens if you poll in the idle loop? like
<re_irc>
<@henrik_alser:matrix.org> if !usb_dev.poll(&mut [usb_hid]) {
<re_irc>
<@henrik_alser:matrix.org> continue;
<re_irc>
<@henrik_alser:matrix.org> }
<re_irc>
<@henrik_alser:matrix.org> What device are you using?
<re_irc>
<@willeml:matrix.org> stm32f303disco
<re_irc>
<@henrik_alser:matrix.org> I don't have one at hand right here so can't reproduce unfortunately
<re_irc>
<@willeml:matrix.org> Hmm, so I started polling in the idle loop, now rx seems to stop firing after a second or two, and also, it no longer tries to push then input
<re_irc>
<@willeml:matrix.org> Then, if I disable the tx and rx interupts I get that
<re_irc>
<@willeml:matrix.org> And if I reduce the delay, it says success once and then says error once and then stops
<re_irc>
<@willeml:matrix.org> (Note that throught this the mouse does not move and clicking the button does not seem to work)
<re_irc>
<@dirbaio:matrix.org> newam: Yes, with namespaced-features. Nightly only. Not possible in stable.
<re_irc>
<@henrik_alser:matrix.org> willeml: btw usb doesn't have rx & tx interrupts, i think those names refer to the can interrupt, but HP/LP refers to the usb as "high/low priority"
<re_irc>
<@henrik_alser:matrix.org> i think HP usually fires only for isochronous transfers
<re_irc>
<@henrik_alser:matrix.org> and bulk complete iirc
<re_irc>
<@henrik_alser:matrix.org> So i'd expect only LP to be used for interrupt transfers
<re_irc>
<@henrik_alser:matrix.org> Hmm just checked the f303 interrupt enum and saw there's a USB_LP interrupt too? What happens if you use that one instead? And do the poll / push in that one?
<re_irc>
<@willeml:matrix.org> both pull and push?
<re_irc>
<@henrik_alser:matrix.org> Yes you can do this on top
<re_irc>
<@henrik_alser:matrix.org> if !usb_dev.poll(&mut [usb_hid]) {
<re_irc>
<@henrik_alser:matrix.org> and then push input below
<re_irc>
<@henrik_alser:matrix.org> }
<re_irc>
<@henrik_alser:matrix.org> return;
<re_irc>
<@willeml:matrix.org> My probe is no longer workin...
<re_irc>
<@stu_:matrix.org> Will the next meeting be on Thursday next week? We weren’t able to write up an issue with the new `cortex-a` crate design because I’m on vacation, but next week we’ll have something ready.
ni has quit [Quit: WeeChat 2.8]
ni has joined #rust-embedded
<re_irc>
<@9names:matrix.org> Thursday? The meetings usually happen on Tuesdays, 20:00 CEST
<re_irc>
<@stu_:matrix.org> Ohh. Whoops. Thank you 😅
<re_irc>
<@jamesmunns:matrix.org> (USB tends to not work reliably/at all in unoptimized builds, I've found)
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #rust-embedded
jackneill has joined #rust-embedded
jackneill has quit [Remote host closed the connection]
jackneill has joined #rust-embedded
jackneill has quit [Remote host closed the connection]
<re_irc>
<@lachlansneff:matrix.org> jamesmunns: Would be neat to be able to optimize just part of the build, like USB, while compiling the rest in debug. Is that possible?
<re_irc>
<@jamesmunns:matrix.org> Yup! look up "profile overrides"
<re_irc>
<@jamesmunns:matrix.org> you can change opt settings on a per-crate basis.
<re_irc>
<@jamesmunns:matrix.org> (exactly what you described is something I often do for debugging - keep all the deps optimized (or at least opt-level=1, which is still a big step), but leave the top level crate unoptimized, if I'm only debugging top level logic)
<re_irc>
<@jamesmunns:matrix.org> very handy for GDB work
<re_irc>
<@jamesmunns:matrix.org> But yeah, if you are doing certain things at the top level, like iterator loops, or deeply nested function calls that rely heavily on optimization to be zero cost, you can still end up with the final code being "too slow to work" though
<re_irc>
<@dirbaio:matrix.org> would this be UB?
<re_irc>
<@dirbaio:matrix.org> goal is to have the value "persist" across warm reboots (where power to RAM isn't cut)
<re_irc>
<@jamesmunns:matrix.org> hm
<re_irc>
<@jamesmunns:matrix.org> I have no idea
<re_irc>
<@dirbaio:matrix.org> so if device reboots while unlocked, it can lock itself again
<re_irc>
<@jamesmunns:matrix.org> I feel like `MaybeUninit` would be the right answer here
<re_irc>
<@jamesmunns:matrix.org> but... it seems silly.
<re_irc>
<@dirbaio:matrix.org> hmm... even with MaybeUninit it'd be doing an "assume_init" right after boot though
<re_irc>
<@jamesmunns:matrix.org> yeah
<re_irc>
<@chrysn:privacytools.io> Not sure either (agreeing with both "would be the right answer" and "seems silly")
<re_irc>
<@chrysn:privacytools.io> From a UB perspective, mightn't it be best to define the area in the linker script as used only, and access it through an extern atomic pointer?
<re_irc>
<@chrysn:privacytools.io> That way, at no point in time can there be expectations in the Rust memory model about its contents.
<re_irc>
<@dirbaio:matrix.org> maybe yeah
<re_irc>
<@jamesmunns:matrix.org> yeah, that'll pretty much always work here, probably because of pointer escaping
<re_irc>
<@dirbaio:matrix.org> I don't relaly need atomics
<re_irc>
<@dirbaio:matrix.org> unsafe impl Sync for SendIt {}
<re_irc>
<@dirbaio:matrix.org> yolo
<re_irc>
<@dirbaio:matrix.org> should be fine I guess? the volatile read/writes are reading the value inside the UnsafeCell so I'm not "mutating readonly statics"
<re_irc>
<@dirbaio:matrix.org> and volatile should prevent the compiler from optimizing like "hey you're reading from this var without having written before, so its value must be 0!!!"
<re_irc>
<@dirbaio:matrix.org> no idea whether the compiler can do that optimization? 🤷
<re_irc>
<@jamesmunns:matrix.org> (you might want to be more defensive about the value being potentially garbage, but the approach LGTM)
<re_irc>
<@thalesfragoso:matrix.org> dirbaio: It's still UB :/
<re_irc>
<@jamesmunns:matrix.org> I mean, just as UB as any MMIO interaction
<re_irc>
<@dirbaio:matrix.org> yeah I only want to lock if I know for sure it was unlocked
<re_irc>
<@dirbaio:matrix.org> if it was locked, or I don't know (like, batteries removed) then do nothing
<re_irc>
<@thalesfragoso:matrix.org> jamesmunns: Not really, MMIO is in fact inited
<re_irc>
<@dirbaio:matrix.org> because locking while already locked stresses the motor a bit :S
<re_irc>
<@jamesmunns:matrix.org> I mean, yeah, but not at the discretion of the software
<re_irc>
<@thalesfragoso:matrix.org> jamesmunns: But the software can't prove it's uninit, so if it assume it's then that is a compiler bug
<re_irc>
<@jamesmunns:matrix.org> yeah
<re_irc>
<@thalesfragoso:matrix.org> On this case the compiler can prove it
<re_irc>
<@jamesmunns:matrix.org> that's the pointer escaping sort of but
<re_irc>
<@jamesmunns:matrix.org> *bit
<re_irc>
<@thalesfragoso:matrix.org> I'm not saying it won't do the volatile read correct
<re_irc>
<@dirbaio:matrix.org> the only difference between this and MMIO is that here the compiler can see the pointer comes from a static
<re_irc>
<@jamesmunns:matrix.org> Ah, because it's a static, rather than an arbitrary pointer?
<re_irc>
<@jamesmunns:matrix.org> so it WOULDN'T be pointer-escaped?
<re_irc>
<@jamesmunns:matrix.org> yeah, something like putting a linker u32 variable, and using the pointer to that linker variable instead of the static itself would probably be properly escaped
<re_irc>
<@thalesfragoso:matrix.org> My easy way to go that is: the thing is uninit ? If it's then the compiler can find a way to prove it
<re_irc>
<@dirbaio:matrix.org> jamesmunns: these linker variables are also statics though!
<re_irc>
<@jamesmunns:matrix.org> yeah
<re_irc>
<@jamesmunns:matrix.org> but they are SOMEBODY ELSE'S statics
<re_irc>
<@jamesmunns:matrix.org> not rustc's.
<re_irc>
<@dirbaio:matrix.org> oh because extern, hmm wtf
<re_irc>
<@chrysn:privacytools.io> jamesmunns: Yes, that's what I meant by defining it in the linker script
<re_irc>
<@chrysn:privacytools.io> Then they'd come from somewhere where the Rust compiler can't see. (It *can* see in the example that it's 0-init'ed).
<re_irc>
<@dirbaio:matrix.org> it'd be Great Shame that this can't be done without linker script hax :S
<re_irc>
<@thalesfragoso:matrix.org> dirbaio: Arent they just pointers for rustc ?
<re_irc>
<@9names:matrix.org> or jump through asm/C?
<re_irc>
<@jamesmunns:matrix.org> But if you are crossing the environmental boundary, you may get the compiler to throw up it's hands
<re_irc>
<@jamesmunns:matrix.org> (in this case, using C/ASM/Linker script hacks all have the same effect: Crossing out of a "pure rust" environment)
<re_irc>
<@9names:matrix.org> okay, let me put this a different way. is there anyway to get the address of the variable, as an integer, without it being UB?
<re_irc>
<@dirbaio:matrix.org> why is it UB with volatile though?
<re_irc>
<@dirbaio:matrix.org> volatile is specified to "do a read to the given address no matter what"
<re_irc>
<@jamesmunns:matrix.org> you have a variable, "owned" by Rust, that is not fulfilling the contract
<re_irc>
<@jamesmunns:matrix.org> YOU SAID it was a static
<re_irc>
<@jamesmunns:matrix.org> which is initialized as part of the environmental contract
<re_irc>
<@jamesmunns:matrix.org> BUT, you put it in a linker script section that DOES NOT FULFILL that contract.
<re_irc>
<@dirbaio:matrix.org> so the read will produce *some* u32 value, and all bit patterns are valid u32's
<re_irc>
<@jamesmunns:matrix.org> therefore, you lied to the compiler, and it is allowed to do whatever the hell it feels like now
<re_irc>
<@jamesmunns:matrix.org> yeah
<re_irc>
<@dirbaio:matrix.org> 🤔
<re_irc>
<@jamesmunns:matrix.org> This is the barrier between "what the hardware does", and "the theoretical model the compiler holds"
<re_irc>
<@thalesfragoso:matrix.org> But tbh, I doubt it would do something different with volatile
<re_irc>
<@jamesmunns:matrix.org> JUST BECAUSE you think you know what a given line of Rust (or C, or C++) will do at a hardware level, the compiler is under no restriction to do exactly that.
<re_irc>
<@jamesmunns:matrix.org> but yeah
<re_irc>
<@thalesfragoso:matrix.org> But, you know, UB
<re_irc>
<@jamesmunns:matrix.org> this is "theoretical, not practical, UB"
<re_irc>
<@jamesmunns:matrix.org> your original code will probably work just fine :D
<re_irc>
<@jamesmunns:matrix.org> it's just not guaranteed.
<re_irc>
<@thalesfragoso:matrix.org> Tbh, now that you putted that on a specific part of the link script with label and stuff
<re_irc>
<@thalesfragoso:matrix.org> Maybe is not UB ? The compiler isn't sure something isn't initting them, right ?
<re_irc>
<@chrysn:privacytools.io> ... and any smart-ass compiler upgrade may break it, because there's some other case in which the theoretically allowed optimization makes sense.
<re_irc>
<@jamesmunns:matrix.org> (link script labels don't change the requirements)
<re_irc>
<@thalesfragoso:matrix.org> Or maybe the compiler just do that with normal statics
<re_irc>
<@thalesfragoso:matrix.org> I.e. consider them inited
<re_irc>
<@9names:matrix.org> the LLVM thing is about the pointer, not the access. it knows you got your pointer from another pointer.
<re_irc>
<@9names:matrix.org> you escape that by getting a pointer from an integer, which is why I asked if it's UB to get an integer address from a pointer (AFIAK it is not)
<re_irc>
<@jamesmunns:matrix.org> (this segfaults at runtime, but I've been reassured this is NOT UB, this is the user breaking the environmental contract)
<re_irc>
<@9names:matrix.org> the construction will always be unsafe, like all of our FFI
<re_irc>
<@thalesfragoso:matrix.org> I meant because the compiler assumes all statics (normal?) are initialized, even though it didn't initialized it itself
jackneill has joined #rust-embedded
<re_irc>
<@thalesfragoso:matrix.org> I.e. .bss .data
<re_irc>
<@thalesfragoso:matrix.org> 9names: Today you need to go through a reference, so the thing would need to be MaybeUninit
<re_irc>
<@thalesfragoso:matrix.org> Now Im on the fence if it's UB dirbaio haha
<re_irc>
<@thalesfragoso:matrix.org> Just because how .data and .bss statics work
<re_irc>
<@nihal.pasham:matrix.org> just thought I'd check to see if this exists in the community. I'm working on a bootloader with update capabilities (which relies on A/B partitions) for ARM. I have the following questions
<re_irc>
<@nihal.pasham:matrix.org> - do we have a way to stitch multiple binaries together? - like say `bootloader + boot firmware + update firmware` laid out in contiguous memory with predefined offsets.
<re_irc>
<@nihal.pasham:matrix.org> - also, does `cargo flash` (i.e. probe-rs) support flashing such a blob?
<re_irc>
<@nihal.pasham:matrix.org> my current plan is to manually work out of the offsets and flash with something like `pyocd.` I'd love to hear about a better way to do this.
<re_irc>
<@adamgreig:matrix.org> usually you'd make all three firmwares separate projects and flash them individually
<re_irc>
<@adamgreig:matrix.org> memory.x indicates the flash start address and can differ for each firmware, and probe-rs will just flash that one firmware
<re_irc>
<@dirbaio:matrix.org> you can do that with some post-build step: convert the elfs to hex and then mergehex
<re_irc>
<@adamgreig:matrix.org> each firmware needs to occupy separate flash memory banks to allow them to be reprogrammed separately
<re_irc>
<@adamgreig:matrix.org> but yea, in the situation where you do want to do a single probe-rs programming step to flash all three together (factory production?), you can merge three elfs to a single elf, or convert to binary and pad and 'cat', or mergehex, or whatever
<re_irc>
<@adamgreig:matrix.org> but honestly i'd just have three elfs and run cargo-flash three times
<re_irc>
<@adamgreig:matrix.org> shouldn't be any appreciable difference in flash time, and makes updating any one binary much easier too
<re_irc>
<@dirbaio:matrix.org> doing a single flash is faster because you can do chip-erase
<re_irc>
<@adamgreig:matrix.org> hmm
<re_irc>
<@adamgreig:matrix.org> whether that's faster depends on how many sectors you need, right?
<re_irc>
<@adamgreig:matrix.org> if you're using most of the flash I guess it probably would be though
<re_irc>
<@dirbaio:matrix.org> depends on the chip ofc
<re_irc>
<@dirbaio:matrix.org> on nrf's it's maaaasssively faster
<re_irc>
<@adamgreig:matrix.org> faster than e.g. only erasing one sector?
<re_irc>
<@adamgreig:matrix.org> or, say, three sectors
<re_irc>
<@adamgreig:matrix.org> anyway yea it's a good point, maybe for that production programming you do want a script that takes the three elfs and combines them then runs cargo-flash once with chip-erase
<re_irc>
<@dirbaio:matrix.org> on nrf52840:
<re_irc>
<@dirbaio:matrix.org> erase page: 85ms
<re_irc>
<@dirbaio:matrix.org> erase all: 169ms
<re_irc>
<@chrysn:privacytools.io> Separate flashes can still be fast if there is a full-chip erase before -- provided the flasher checks for whether a page-wise erase is actually necessary
<re_irc>
<@nihal.pasham:matrix.org> I'm more worried about someone forgetting to flash one of them (and raising tickets without checking). Yep, binary padding and merging is what we have then.
<re_irc>
<@dirbaio:matrix.org> you don't need to merge files to get fast chip-erase flashes though
<re_irc>
<@dirbaio:matrix.org> both probe-rs and pyocd allow you to create a "loader", load multiple elfs, then flash all in one go with a single chip-erase
<re_irc>
<@adamgreig:matrix.org> another option is to flash only the bootloader and then use it to program the rest of the chip
<re_irc>
<@adamgreig:matrix.org> can be quicker since e.g. ethernet or HS USB can do way higher data rates than you're likely getting with SWD
<re_irc>
<@adamgreig:matrix.org> (and verifies bootloader functionality while you're at it)
<re_irc>
<@dirbaio:matrix.org> yeah but the flash writing itself will probably be slower...?
<re_irc>
<@dirbaio:matrix.org> because the bootloader will have to do sector-erases, it can't do a chip-erase
<re_irc>
<@adamgreig:matrix.org> I guess it depends on chip and setup, no reason the bootloader couldn't be told that a chip erase had already taken place or perhaps check itself
<re_irc>
<@adamgreig:matrix.org> on some chips the flash is two banks and you can do bank-erase on each, too
<re_irc>
<@dirbaio:matrix.org> right :P
<re_irc>
<@nihal.pasham:matrix.org> adamgreig: this one's a secure bootloader with a focus on the smallest possible TCB. So, no networking stacks of any kind. we'll rely on the firmware for that
<re_irc>
<@adamgreig:matrix.org> for sure getting into the weeds here though :P
<re_irc>
<@nihal.pasham:matrix.org> but great, thanks for the confirmation
<re_irc>
<@adamgreig:matrix.org> right fair enough, then yea I guess either merge your three ELFs to a single ELF/hex/bin, or use probe-rs's API to load the three ELFs separately (in a production environment)
<re_irc>
<@adamgreig:matrix.org> I wonder if cargo-flash couldn't just support being given multiple --elf arguments
<re_irc>
<@adamgreig:matrix.org> seems like an easy feature addition
<re_irc>
<@dirbaio:matrix.org> yup!
<re_irc>
<@dirbaio:matrix.org> though if you're doing factory programming you'll want extra custom logic anyway
<re_irc>
<@nihal.pasham:matrix.org> +1 to that
<re_irc>
<@dirbaio:matrix.org> like provisioning keys or unique serial numbers or running tests
<re_irc>
<@dirbaio:matrix.org> at that point you might as well use probe-rs as a lib, instead of execing cargo-flash
<re_irc>
<@adamgreig:matrix.org> yea
<re_irc>
<@adamgreig:matrix.org> I'm inferring this is more for people who are programming their own device if you're worried about them missing one or two of the images
<re_irc>
<@dirbaio:matrix.org> I have my main app purposefully suicide if the bootloader is not there :D
<re_irc>
<@9names:matrix.org> how does your main app execute if the bootloader is missing?
<re_irc>
<@dirbaio:matrix.org> due to the weird-ass flash layout of the softdevice
<re_irc>
<@9names:matrix.org> oh right nrf stuff forget i asked :D
<re_irc>
<@dirbaio:matrix.org> bootloader goes at the *end* of flash
<re_irc>
<@dirbaio:matrix.org> the softdevice will boot the main app if no bootloader is flashed
<re_irc>
<@dirbaio:matrix.org> so it's super easy to miss :S
<re_irc>
<@dirbaio:matrix.org> true that in a more conventional layout where the BL goes at the start of flash this can't happen
<re_irc>
<@dirbaio:matrix.org> damn you nordic
<re_irc>
<@yatekii:matrix.org> dirbaio: see, I need to create my service already :D
jackneill has quit [Remote host closed the connection]
cr1901 has joined #rust-embedded
<re_irc>
<@willeml:matrix.org> jamesmunns: Actually, I am not, I will try it
troth has joined #rust-embedded
<re_irc>
<@jamesmunns:matrix.org> willeml: How'd it go?
<re_irc>
<@jamesmunns:matrix.org> (I have been reinvigorated by espressif's recent hires :D )
<re_irc>
<@adamgreig:matrix.org> hires plural?
<re_irc>
<@adamgreig:matrix.org> probably #rp-rs:matrix.org is the place to discuss, and I think at least one or two relevant people are there too
<re_irc>
<@jamesmunns:matrix.org> That's fair!
<re_irc>
<@jamesmunns:matrix.org> adamgreig: I think there were two, Scott and someone else, unless I have wires crossed with Tweedegolf hiring Dion (which also happened recently)
<re_irc>
<@adamgreig:matrix.org> (though I think they hang out there in an unofficial capacity :P)
<re_irc>
<@adamgreig:matrix.org> cool! i was just aware of scott
xnor has quit [Ping timeout: 268 seconds]
xnor has joined #rust-embedded
GenTooMan has quit [Ping timeout: 245 seconds]
GenTooMan has joined #rust-embedded
xnor has quit [Changing host]
xnor has joined #rust-embedded
<re_irc>
<@willeml:matrix.org> jamesmunns: It didn’t work sadly, still says err would block