Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pico usb serial interrupt #37

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ithinuel
Copy link
Member

@ithinuel ithinuel changed the base branch from main to hal-0.9 August 15, 2023 17:58
@ithinuel ithinuel marked this pull request as ready for review September 19, 2023 19:23
@ithinuel ithinuel force-pushed the update-pico-usb-serial-interrupt branch from fb5b54a to 9b68598 Compare October 5, 2023 21:30
@ithinuel ithinuel changed the base branch from hal-0.9 to main October 5, 2023 21:30
@jannic
Copy link
Member

jannic commented Oct 15, 2023

The changes look good, but I wonder why the CI actions did not run for this branch?

@ithinuel
Copy link
Member Author

It migth have been because it PR was initially targetting another branch (hal-0.9).
Let me try to force a push.

@ithinuel ithinuel force-pushed the update-pico-usb-serial-interrupt branch from 9b68598 to f46db13 Compare October 21, 2023 20:10
Comment on lines 86 to 87
// The USB Bus Driver (shared with the interrupt).
static mut USB_BUS: Option<UsbBusAllocator<hal::usb::UsbBus>> = None;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the last part of the comment "(shared with the interrupt)" not incorrect? The interrupt function (fn USBCTRL_IRQ()) shouldn't be able to reference the USB_BUS, because USB_BUS is out of scope.

Comment on lines 123 to 126
// Grab a reference to the USB Bus allocator. We are promising to the
// compiler not to take mutable access to this global variable whilst this
// reference exists!
let bus_ref = unsafe { USB_BUS.as_ref().unwrap() };
let bus_ref = USB_BUS.as_mut().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part of the comment "We are promising to the compiler not to take mutable access to this global variable whilst this reference exists!" not incorrect too? The compiler will stop you from taking a second mutable reference and the USB_BUS is local to the #[entry] function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this comment is no longer relevant thanks to the #[entry] trick, the compiler is able to check we're not doing anything silly there.

// Trait required to use `writeln!(…)`
use core::fmt::Write;

// A system wide mutex synchrinising IRQ & cores
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo (synchrinising -> synchronising or synchronizing).

Comment on lines 228 to 231
#[allow(non_snake_case)]
#[exception]
fn SysTick() {
do_with_usb(|usb| usb.usb_device.poll(&mut [&mut usb.usb_serial]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment like "Keeps the usb_device updated in case the usb interrupt is not called often." or a better explanation why this is advisable might be useful here for people like me who only have a superficial understanding of embedded software development.

Comment on lines 83 to 85
/// infinite loop.
#[entry]
fn main() -> ! {
Copy link
Contributor

@Agent59 Agent59 Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't a comment like "never ending function, except when the pico is reset to usb boot." not be more appropriate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot, this text is actually inconsistent with the example.

@ithinuel
Copy link
Member Author

@Agent59 thank you for your reviews! This last push should address your comments. Let me know if you see anything else :)

@ithinuel ithinuel force-pushed the update-pico-usb-serial-interrupt branch from 2bf2c0c to 37a124c Compare November 14, 2023 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants