Pico - Unable to reboot in C++ demo code

Hi folks, first time poster to these forums.

I recently purchased a Pimoroni Display Pack and a Pico RP2040 from the store and successfully compiled the demo code that Pimoroni have supplied. Thank you to whomever packaged that all up, the instructions were nice and clear.

I’ve been editing the Pico Display demo code just to learn the ecosystem and wanted to add a way to press the BOOTSEL button to trigger a reboot back into programming (USB Mass Storage) mode, so I can avoid repeated USB cable inserts and risk damaging the Micro-USB connector.

From the official Pico-SDK, there are two examples of how to separately read the BOOTSEL button and how to restart back into USB Mass Storage mode;

The BOOTSEL button reading code works fine, however when I try and #include "hardware/flash.h" to access the reset_usb_boot(..., ...); function I get an error saying this header file could not be found… yet I can see it sitting inside the Pico-SDK include folder (which the cmake process appears to be trying to pull in).

Any ideas how I can fix this please? Or is there a better known way to restart the Pico from within software?

Thanks in advance :)

Edit 1:

I managed to get past that error by reading a little more closely into the source, in the same folder as demo.cpp above there’s also CMakeLists.txt, I spotted these lines…

# Pull in pico libraries that we need
target_link_libraries(display pico_stdlib hardware_spi hardware_pwm hardware_dma pico_display)

I added hardware_flash to that list, now I get the following error…

demo.cpp:(.text.startup.main+0x76e): undefined reference to `rom_func_lookup(unsigned long)'

Hi, so this might be hacky and there might be a better solution to this, so you might want to wait for an official answer, but I ran into the same problem and I think it is because of linkage between C and C++.
What fixed it for me was including the file that contains reset_usb_boot with C linkage.

extern "C"
  #include "pico/bootrom.h"

I also used pico_bootrom in target_link_libraries in Cmake

Thank you @Max1412 - this was indeed the case, there are a number of libs that are C only in pico-sdk and some need encapsulating like this.

For others reference, here are at least 3 others I’ve found so far that need encapsulation…

#include "hardware/watchdog.h"
#include "hardware/rtc.h"
#include "pico/util/datetime.h"