Skip to content

Conversation

@supsm
Copy link
Contributor

@supsm supsm commented Jan 20, 2024

The USB dev_lowlevel example silently fails in C++ because isr_usbctrl is name-mangled and therefore not registered as an interrupt handler. This PR adds extern "C" to use C linkage for this function and allow compiling as C++.

It is certainly not the prettiest, but it is necessary for correct behavior (with C++ linkage, none of the host's packets are responded to and the device is useless). The alternative to this is to manually specify irq_set_exclusive_handler, probably within usb_device_init. The pico-sdk advertises itself as C/C++, so C++ compatibility should be taken into consideration in its examples.

@supsm supsm changed the base branch from master to develop January 21, 2024 06:06
@peterharperuk peterharperuk added this to the 1.5.2 milestone Jan 22, 2024
Copy link
Contributor

@peterharperuk peterharperuk left a comment

Choose a reason for hiding this comment

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

See comment from @lurch

@kilograham
Copy link
Contributor

I'm not sure I understand why/how are you trying to compile this example as C++.(or what you mean by it).

@supsm
Copy link
Contributor Author

supsm commented Jan 22, 2024

I'm not sure I understand why/how are you trying to compile this example as C++

I initially saved the file as .cpp to modify it in a more familiar language (not realizing isr_usbctrl is a special function). I suspect other developers may also attempt to unsuccessfully incorporate isr_usbctrl into C++ code.

@supsm
Copy link
Contributor Author

supsm commented Feb 7, 2024

Is there any update on this pr? I have already made the requested changes.

@peterharperuk
Copy link
Contributor

Seems fine to me

@peterharperuk peterharperuk merged commit 28f4b95 into raspberrypi:develop May 2, 2024
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