Arduino Nano BLE 33 Sense can not upload program

I started a very small project testing a sensor that by mistake I uploaded wrong:

void setup() {

  // put your setup code here, to run once:
  pinMode(A0, OUTPUT);

void loop() {
  int read = analogRead(A0);

Now when I connect the Arduino board to the USB sometimes the PC does not detect the board and does not show it in the ports in the Arduino IDE. Even when the board shows up, and I try to reaupload the corrected program (without the second analogRead) the IDE is stuck on uploading. It outputs:

Sketch uses 78180 bytes (7%) of program storage space. Maximum is 983040 bytes.
Global variables use 42256 bytes (16%) of dynamic memory, leaving 219888 bytes for local variables. Maximum is 262144 bytes.

And it does not continue with the red upload progress output.

Any idea if I can get it out of this state?

Hacky, I connected A0 to ground it now works a bit longer, enough to connect and reupload a fixed program. I am not sure if this helped, or it was plain luck but it ok now.

Why would you make A0 and output if you want to read it?