Posts: 64
Joined: Fri Jan 22, 2021 6:53 pm

Is reading the BOOTSEL button possible in Micropython?

Sat Jan 23, 2021 2:43 pm

Clearly there is currently no support for reading the state of the onboard BOOTSEL button in Micropython at the moment, but I'm not even sure if such support is feasible.

The C SDK example that shows how to read the button ( ... n/button.c) explains that the trick to doing this is as follows:
//Picoboard has a button attached to the flash CS pin, which the bootrom
// checks, and jumps straight to the USB bootcode if the button is pressed
// (pulling flash CS low). We can check this pin in by jumping to some code in
// SRAM (so that the XIP interface is not required), floating the flash CS
// pin, and observing whether it is pulled low.
// This doesn't work if others are trying to access flash at the same time,
// e.g. XIP streamer, or the other core.
Are those restrictions going to make it impossible to add this to Micropython?

Posts: 9144
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Is reading the BOOTSEL button possible in Micropython?

Sun Jan 24, 2021 12:31 pm

It seems to me it would be possible but with the same caveats and limitations. A fail-safe implementation could be tricky but a brute force float the pin and read, restore as was when done, could work if you knew the Flash was not being accessed.

Return to “MicroPython”