raspberrypi / pico-examples

BSD 3-Clause "New" or "Revised" License
2.61k stars 778 forks source link

Add extern "C" to isr_usbctrl in dev_lowlevel #465

Closed supsm closed 2 months ago

supsm commented 5 months ago

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.

kilograham commented 5 months ago

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

supsm commented 5 months ago

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 commented 4 months ago

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

peterharperuk commented 4 months ago

Seems fine to me