rust-exercises icon indicating copy to clipboard operation
rust-exercises copied to clipboard

HAL migration to embassy-nrf for radio, hal-app and USB exercise

Open robamu opened this issue 2 months ago • 12 comments

This might simplify adding async trainings in the future. The radio module is still custom written to remain synchronous and builds on the nrf-pac. I tested the radio binaries as well.

robamu avatar Sep 23 '25 10:09 robamu

Deploying ferrous-systems-rust-exercises with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2ff7bf6
Status: ✅  Deploy successful!
Preview URL: https://32b24f7c.ferrous-systems-rust-exercises.pages.dev
Branch Preview URL: https://try-hal-migration.ferrous-systems-rust-exercises.pages.dev

View logs

The only missing feature which requires a fork: https://github.com/embassy-rs/embassy/pull/4700

robamu avatar Sep 23 '25 10:09 robamu

I'll take a look at this on Friday, hopefully

jonathanpallant avatar Sep 29 '25 15:09 jonathanpallant

The only missing feature which requires a fork: embassy-rs/embassy#4700

Is this now in embassy-nrf-v0.8.0?

jonathanpallant avatar Nov 03 '25 13:11 jonathanpallant

Can you re-do this PR so that instead of a new crate called dk-migration, we replace the existing dk crate with an embassy based one? That would make it easier to see the diff (and if we did merge the PR and make the change, we probably wouldn't want two copies of the DK crate).

It would also be useful to see how easily the dongle firmware can be ported over?

It might be that the radio driver needs to go into a separate radio crate that dk and dongle can both import/re-export - to save writing it twice.

jonathanpallant avatar Nov 03 '25 13:11 jonathanpallant

I think I also did this because there are other components like the USB training which rely on dk as well. Adding a second dk crate allows a partial migration. So I either would have to look into porting everything at once (might actually not be that difficult), or accept breakage of those modules when doing a full replace.

robamu avatar Nov 04 '25 08:11 robamu

Is this now in embassy-nrf-v0.8.0?

Yes, and that release contains a few other goodies as well (e.g. generic removal on the timer structure)

robamu avatar Nov 04 '25 08:11 robamu

I had a look at the USB modules. It is not too much. should be possible to migrate that with reasonable effort as well.

robamu avatar Nov 04 '25 08:11 robamu

I ported the USB code as well, and I updated the HAL exercise with the buttons.

Should we keep the dongle FW port as a separate PR?

robamu avatar Nov 04 '25 10:11 robamu

Should we keep the dongle FW port as a separate PR?

yes, the dongle uses a different BSP and so it can move to embassy-nrf on its own schedule.

jonathanpallant avatar Nov 04 '25 17:11 jonathanpallant

I resolved some smaller stuff. Ready for review now :)

robamu avatar Nov 06 '25 14:11 robamu

I added a notice and the relevant license sections from the nrf52840 HAL.

  1. When I run radio-puzzle-solution I no longer see the radio packets on the defmt log. Can we add those back in?

For which log level? I just tried running both main and this branch with debug log level, and I see exchanged packets for both versions.

00:00:00.946258 [DEBUG] TX: [e9, 2e, 1b, 27, 20, d0, 7f] (dk dk/src/lib.rs:255)
00:00:00.948516 [DEBUG] RX: [e9, 2e, 1b, 27, 20, d0, 00] (dk dk/src/lib.rs:259)
00:00:00.948608 [DEBUG] OK: [00] (dk dk/src/lib.rs:263)
00:00:00.953674 [DEBUG] TX: [e9, 2e, 1b, 27, 20, d0] (dk dk/src/lib.rs:255)
00:00:00.956634 [DEBUG] RX: [e9, 2e, 1b, 27, 20, d0, 77, 4f, 25, 22, 3f, 25, 22, 3f, 49, 7b, 3f, 39, 28, 49, 41, 7d, 74, 39, 3f, 41, 39, 22, 22, 49, 32, 39] (dk dk/src/lib.rs:259)
00:00:00.956817 [DEBUG] OK: [77, 4f, 25, 22, 3f, 25, 22, 3f, 49, 7b, 3f, 39, 28, 49, 41, 7d, 74, 39, 3f, 41, 39, 22, 22, 49, 32, 39] (dk dk/src/lib.rs:263)
ciphertext: wO%"?%"?I{?9(IA}t9?A9""I29
plaintext: This is an example message
00:00:00.962677 [DEBUG] TX: [e9, 2e, 1b, 27, 20, d0, 54, 68, 69, 73, 20, 69, 73, 20, 61, 6e, 20, 65, 78, 61, 6d, 70, 6c, 65, 20, 6d, 65, 73, 73, 61, 67, 65] (dk dk/src/lib.rs:255)
00:00:00.966125 [DEBUG] RX: [e9, 2e, 1b, 27, 20, d0, 63, 6f, 72, 72, 65, 63, 74] (dk dk/src/lib.rs:259)
00:00:00.966217 [DEBUG] OK: [63, 6f, 72, 72, 65, 63, 74] (dk dk/src/lib.rs:263)
Dongle response: correct
`dk::exit()` called; exiting ...
Firmware exited successfully

rust-exercises/nrf52-code/radio-app on  try-hal-migration [$] is 📦 v0.0.0 via 🦀 v1.91.0 took 5s
  1. Is there any text in the exercise workbook that is now wrong because of these changes? I'd like to update that text at the same time as the examples change, so we don't get them out of sync.

This migration basically doesn't change anything for the radio exercise materials because only the underlying PAC was changed. I went through the book again but did not find anything so far.

robamu avatar Nov 13 '25 22:11 robamu

I tested all the solutions on hardware and they look good.

I have some patches to clean up the USB exercise, which I will do separately.

jonathanpallant avatar Nov 28 '25 12:11 jonathanpallant