Pico 2W can't enter BOOTSEL or run code for hours after attempting to upload new code
I recently bought a pico 2W, after running a few simple programs such as blink I wired up an ST7735 TFT LCD screen and wrote a program to write some things on the screen. (I'm using platformIO with arduino framework to code). Code is shown below:
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#define TFT_SCK 10 //or SCL
#define TFT_MOSI 11 //or SDA
#define TFT_MISO 12
#define TFT_CS 13
#define TFT_DC 17
#define TFT_RST 18
#define LED LED_BUILTIN
Adafruit_ST7735 display = Adafruit_ST7735(&SPI1, TFT_CS, TFT_DC, TFT_RST);
void setup() {
// Initialize SPI bus
pinMode(LED, OUTPUT);
SPI1.setSCK(10);
SPI1.setMOSI(11);
SPI1.setMISO(12);
SPI1.setCS(13);
SPI1.begin();
display.initR(INITR_BLACKTAB);
display.setRotation(1);
display.fillScreen(ST77XX_BLACK);
display.setTextWrap(true);
display.setTextSize(2);
display.setTextColor(ST77XX_WHITE);
display.setCursor(10, 10);
display.println("Test");
}
void loop() {
digitalWrite(LED,HIGH);
display.setCursor(10, 30);
display.setTextColor(ST77XX_YELLOW);
display.print(String(millis()/1000));
delay(1000);
display.fillScreen(ST77XX_BLACK);
}#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <SPI.h>
#define TFT_SCK 10 //or SCL
#define TFT_MOSI 11 //or SDA
#define TFT_MISO 12
#define TFT_CS 13
#define TFT_DC 17
#define TFT_RST 18
#define LED LED_BUILTIN
Adafruit_ST7735 display = Adafruit_ST7735(&SPI1, TFT_CS, TFT_DC, TFT_RST);
void setup() {
// Initialize SPI bus
pinMode(LED, OUTPUT);
SPI1.setSCK(10);
SPI1.setMOSI(11);
SPI1.setMISO(12);
SPI1.setCS(13);
SPI1.begin();
display.initR(INITR_BLACKTAB);
display.setRotation(1);
display.fillScreen(ST77XX_BLACK);
display.setTextWrap(true);
display.setTextSize(2);
display.setTextColor(ST77XX_WHITE);
display.setCursor(10, 10);
display.println("Test");
}
void loop() {
digitalWrite(LED,HIGH);
display.setCursor(10, 30);
display.setTextColor(ST77XX_YELLOW);
display.print(String(millis()/1000));
delay(1000);
display.fillScreen(ST77XX_BLACK);
}
This did work, but the next time I tried to upload something, (uploaded via automatic reset rather than manually entering BOOTSEL mode) the program stopped working and the pico's LED also turned off. Only the internal regulator was still outputting 3.3V. After this it was also impossible to manually enter BOOTSEL and the pico wouldn't show up as a device on Windows so I thought it was gone for good.
After about 2 hours though I tried to put it into BOOTSEL again and it randomly worked. This only lasted about 10 seconds however and it returned to being seemingly dead after that.
Next morning I was able to put it into BOOTSEL again and this time I uploaded the flash nuke.uf2 file before it went unresponsive again which fixed the issue. At the time I hadn't realized yet that uploading the code caused this however so I uploaded the above code again and after trying to upload a different code I ended up bricking it again.
So anyways my question is, what causes this? Is there something wrong with the code that corrupts the flash when the pico is reset? And why is it only stuck for a few hours? That seems to imply that I have to wait for some internal capacitors to discharge or something before BOOTSEL mode is accesible. FYI trying to put the pico in BOOTSEL with different cables, on different computers and USB ports didn't work so it seems to be a hardware issue on the pico itself.