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
bjc has quit [Remote host closed the connection]
bjc has joined #rust-embedded
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
starblue has quit [Ping timeout: 252 seconds]
starblue has joined #rust-embedded
IlPalazzo-ojiisa has joined #rust-embedded
dne has quit [Remote host closed the connection]
dne has joined #rust-embedded
<re_irc> < (@anand21:matrix.org)> Hi, I am working on TrustZone-M on NRF9160 board.
<re_irc> I have defmt setup for my Bootloader as well as Firmware.
<re_irc> Isn't it possible to get the defmt working after we jump to the Firmware.
<re_irc> I am not able to get the defmt (deferred formatting) work for my Firmware.
crabbedhaloablut has quit [Ping timeout: 255 seconds]
crabbedhaloablut has joined #rust-embedded
starblue has quit [Ping timeout: 260 seconds]
starblue has joined #rust-embedded
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #rust-embedded
<re_irc> < (@chemicstry:matrix.org)> : I'm not sure if trustzone causes you additional issues, but it could be that you are reinitializing RTT block from firmware, which throws off the debugger. You have to initialize RTT manually in that case, because defmt/rtt_target libs do not support reusing already initialized block. Here is what I did: https://gist.github.com/chemicstry/939293905c7766330c73f39efaee2ebd You then wire up...
<re_irc> ... "TERMINAL_CHANNEL" as defmt sink
<re_irc> < (@chemicstry:matrix.org)> I'm not sure if trustzone causes you additional issues, but it could be that you are reinitializing RTT block from firmware, which throws off the debugger. You have to initialize RTT manually in that case, because defmt/rtt_target libs do not support reusing already initialized block. Here is what I did: https://gist.github.com/chemicstry/939293905c7766330c73f39efaee2ebd You then wire up returned...
<re_irc> ... "UpChannel" as defmt sink
<re_irc> < (@chemicstry:matrix.org)> oh and you also need to define rtt block section in linker so that it is always in the same RAM location
<re_irc> < (@chemicstry:matrix.org)> for both bootloader and firmware
fooker has quit [Ping timeout: 268 seconds]
fooker has joined #rust-embedded
<re_irc> <riskable> Anyone have any ideas why this single bit of code would cause my firmware to hang?
<re_irc> .product("Riskeyboard 70")
<re_irc> .manufacturer("Riskable")
<re_irc> let usb_key_dev = UsbDeviceBuilder::new(usb_bus, UsbVidPid(VID, PID))
<re_irc> <riskable> It's an old stm32f4xx_hal (stm32f411) project that I resurrected recently to make a very minor change. It compiles fine after making the change but when I flash and run it it just hangs. I put in a zillion debug statements to figure out that's where it hangs 🤷
<re_irc> <riskable> The thing that baffles me: This isn't part of the code that changed! haha
<re_irc> <FĂ©lix | Totem> riskable: There is a precise order in which you are supposed to create the various USB stuff. You can try to tweak that. In my project, I need to create first the bus, then the class, then the device.
<re_irc> <FĂ©lix | Totem> Before I used that order, I was in the same situation as you
<re_irc> <riskable> FĂ©lix | Totem: Yeah I tried moving it all around... Didn't make any difference. It still hangs on that line
<re_irc> <riskable> I even tried getting rid of basically everything else the code does. It's an RTIC (0.5) project and I basically reduced it to a bare bones thing to narrow this down
<re_irc> < (@dirbaio:matrix.org)> maybe it's panicking. Maybe add a "panic!("foo");" to check that your panic message printing is working
<re_irc> <riskable> : Good idea! I'll try that
<re_irc> <FĂ©lix | Totem> riskable: Isn't that an old version of RTIC?
<re_irc> <FĂ©lix | Totem> Are you talking about "cortex-m-rtic"
<re_irc> <riskable> FĂ©lix | Totem: Oh yes. very!
<re_irc> <riskable> Like, I _can_ spend a ton of time porting this to the latest & greatest everything but _I don't wanna!_ hahaha
<re_irc> <riskable> That's a lot of work for what should be a trivial change
<re_irc> <FĂ©lix | Totem> Yeah, right, it depends of the amount of lines to update
<re_irc> <FĂ©lix | Totem> * on
<re_irc> <riskable> : I put "panic!("Testing panics");" in the code just above that USB initialization line and it panicked like it should...
<re_irc> stack backtrace:
<re_irc> <exception entry>
<re_irc> 0: HardFaultTrampoline
<re_irc> <riskable> Though the panic _message_ is nowhere to be found which is... Interesting
<re_irc> < (@dirbaio:matrix.org)> if you're using "panic-probe" enable feature "print-defmt"
<re_irc> < (@dirbaio:matrix.org)> but yea if this one hardfaults and the other doesn't it's maybe not a panic...
<re_irc> < (@dirbaio:matrix.org)> stack overflow maybe?
<re_irc> <riskable> To enable the debugging (the old "rtt-target" stuff wasn't working) I switched it over to:
<re_irc> panic-probe = { version = "0.3", features = ["print-defmt"] }
<re_irc> defmt = "0.3"
<re_irc> defmt-rtt = "0.4.0"
<re_irc> < (@dirbaio:matrix.org)> that looksok, it should print the panic message...
<re_irc> <riskable> For reference, I suspect this _could_ be a bug that was introduced in some version of "stm32f4xx-hal" version 0.9.X but since that package went through a pretty rapid and regular evolution no one noticed (it's now on 0.14.X). Right now I'm thinking I'll try various older versions of the 0.9 series to see if that fixes it and if not probably start porting this to the latest & greatest RTIC stuff
<re_irc> < (@anand21:matrix.org)> : Thank you for the response. so what i understood is We need to add this code in the firmware, and avoid re initialisation of rtt.
<re_irc> is this correct?
<re_irc> < (@chemicstry:matrix.org)> : well it's a snippet from a "startup" code so it has a lot of hacks and might need massaging to get working. But the general idea is that you have to do same initialization as those libs do (defmt/rtt), but omit overwriting RTT block if it's already there
<re_irc> < (@chemicstry:matrix.org)> I guess you could also modify the libs and submit a PR for such use case
<re_irc> < (@anand21:matrix.org)> : Ok thank you for the clarification. Will try to raise a PR.
<re_irc> <riskable> OK nothing I've tried works so *I guess I'm porting this code to RTIC 1.1! This is going to take _hours_... Sigh
<re_irc> < (@datdenkikniet:matrix.org)> can you see any useful information when you break the program at the point where it hangs?
<re_irc> < (@datdenkikniet:matrix.org)> (defmt-rtt has support for backtraces, I believe)
<re_irc> < (@datdenkikniet:matrix.org)> * believe, but not sure if/what kind of changes it would require to activate it if you haven't, yet)
<re_irc> < (@datdenkikniet:matrix.org)> maybe can you find some useful information in the backtrace when you break the program at the point where it hangs?
<re_irc> < (@datdenkikniet:matrix.org)> maybe can you find some useful information in the backtrace if you interrupt the program at the point where it hangs?
<re_irc> < (@datdenkikniet:matrix.org)> as in: is it "just" that line with the UsbDeviceBuilder, or does the point at which "build" hangs give some useful feedback?
<re_irc> < (@datdenkikniet:matrix.org)> +(assuming that it's "build")
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
cr1901_ has joined #rust-embedded
cr1901_ has quit [Remote host closed the connection]
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
<re_irc> <riskable> OK so I just updated everything to the latest & greatest RTIC, stmf4xx_hal, and others and... Wow, I wish the borrow checker could've told me this _before_ haha:
<re_irc> ERROR panicked at 'already borrowed: BorrowMutError', /home/riskable/.cargo/registry/src/github.com-1ecc6299db9ec823/usb-device-0.2.9/src/bus.rs:194:36
<re_irc> └─ panic_probe::print_defmt::print @ /home/riskable/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-probe-0.3.0/src/lib.rs:91
<re_irc> So apparently I'm just borrowing the USB_BUS in more than one place or some way that's not appropriate.
<re_irc> < (@ryan-summers:matrix.org)> That's usually the case when someone is using some internal "RefCell"
<re_irc> < (@ryan-summers:matrix.org)> * "RefCell", which implies run-time borrow-checking rules
<re_irc> < (@ryan-summers:matrix.org)> And yeah, it seems like you may be using the USB bus peripheral in multiple contexts?
<re_irc> <riskable> : I'm not using anything fancy like "RefCell"
<re_irc> < (@ryan-summers:matrix.org)> usb-device uses it internally
<re_irc> < (@ryan-summers:matrix.org)> * internally, see https://docs.rs/usb-device/0.2.9/src/usb_device/bus.rs.html#150
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
DepthDeluxe_ has joined #rust-embedded
<re_irc> <riskable> For reference, if you're getting a similar 'already borrowed' error when trying to use "UsbDeviceBuilder" it's because you need to create your other USB devices _before_ that in the code. For example, I'm creating a USB mouse and a keyboard. I had the mouse code after I was calling "UsbDeviceBuilder" which was causing that error.
<re_irc> <FĂ©lix | Totem> There sometimes are really weird side effects. If I set a led to on inside a loop, everything works, if I remove that line, the initialization crashes (I think it crashes there).
<re_irc> That looks like what would happen when there is an UB 🤔
<re_irc> <FĂ©lix | Totem> The code looks like that:
<re_irc> #[task(local = [matrix, leds], shared = [usb_class])]
<re_irc> fn matrix_scan(mut cx: matrix_scan::Context) {
<re_irc> let keys = cx.local.matrix.scan();
cr1901 has quit [Read error: Connection reset by peer]
cr1901 has joined #rust-embedded
<re_irc> <FĂ©lix | Totem> I think it's due to the fact I use a local data inside a lock block
<re_irc> < (@korken89:matrix.org)> FĂ©lix | Totem: That does not matter in RTIC, locals are simply "&mut" references to static memory
<re_irc> < (@korken89:matrix.org)> They do not interact with locks
<re_irc> < (@korken89:matrix.org)> That does not matter in RTIC, locals are simply "&mut" references to static memory with appropriate imposed lifetime
<re_irc> < (@korken89:matrix.org)> The side effect must be from optimization happening in a different way
<re_irc> <henrik_alser> Félix | Totem: Are you running in —release?
<re_irc> <FĂ©lix | Totem> henrik_alser: Yes. I think the bin wouldn't fit in the board otherwise
<re_irc> <FĂ©lix | Totem> : This shouldn't happen, right?
<re_irc> < (@korken89:matrix.org)> Sounds weird to me
<re_irc> <henrik_alser> FĂ©lix | Totem: how do you do the poll?
<re_irc> <FĂ©lix | Totem> henrik_alser: #[task(binds = USB_LP, shared = [usb_device, usb_class])]
<re_irc> fn usb_poll(cx: usb_poll::Context) {
<re_irc> usb_device.poll(&mut [usb_class]); // Dispatches to the class
<re_irc> (cx.shared.usb_device, cx.shared.usb_class).lock(|usb_device, usb_class| {
<re_irc> <FĂ©lix | Totem> LP means low priority. There also is a USB_HP
DepthDeluxe_ has quit [Ping timeout: 252 seconds]
DepthDeluxe has joined #rust-embedded
emerent_ has joined #rust-embedded
emerent has quit [Killed (platinum.libera.chat (Nickname regained by services))]
emerent_ is now known as emerent
DepthDeluxe has quit [Ping timeout: 260 seconds]
DepthDeluxe has joined #rust-embedded