Arduino RP2040 must forced bootloader after the upload

After i upload the code into the arduino, i get the notification that the device has disconnected improperly. Eventhought the code get uploaded into the arduino, the arduino will not be identified anymore. The only way to make it identifiable again is to factory-reset the board, following this guide https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-01-technical-reference#forcing-bootloader. Moreover this problem dosen’t seem to happen with the arduino IDE.

  • Executing task: platformio run --target upload --upload-port /dev/cu.usbmodem1201
    Processing nanorp2040connect (platform: raspberrypi; board: nanorp2040connect; framework: arduino)
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Verbose mode can be enabled via -v, --verbose option
    CONFIGURATION: Redirecting...
    PLATFORM: Raspberry Pi RP2040 (1.8.0) > Arduino Nano RP2040 Connect
    HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
    DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, raspberrypi-swd)
    PACKAGES:
    - framework-arduino-mbed @ 3.5.4
    - tool-openocd-raspberrypi @ 2.1100.0 (11.0)
    - tool-rp2040tools @ 1.0.2
    - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 41 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |-- Adafruit NeoPixel @ 1.11.0
    |-- neopixel_led
    | |-- Adafruit NeoPixel @ 1.11.0
    Building in release mode
    Checking size .pio/build/nanorp2040connect/firmware.elf
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [== ] 15.3% (used 41452 bytes from 270336 bytes)
    Flash: [ ] 0.2% (used 4158 bytes from 2097152 bytes)
    Configuring upload protocol…
    AVAILABLE: cmsis-dap, jlink, picotool, raspberrypi-swd
    CURRENT: upload_protocol = picotool
    Looking for upload port…
    Using manually specified: /dev/cu.usbmodem1201
    Forcing reset using 1200bps open/close on port /dev/cu.usbmodem1201
    Uploading .pio/build/nanorp2040connect/firmware.elf
    rp2040load 1.0.1 - compiled with go1.15.8
    …Loading into Flash: [ ] 0%
    Loading into Flash: [= ] 5%
    Loading into Flash: [=== ] 10%
    Loading into Flash: [==== ] 15%
    Loading into Flash: [====== ] 20%
    Loading into Flash: [======= ] 25%
    Loading into Flash: [========= ] 30%
    Loading into Flash: [========== ] 35%
    Loading into Flash: [============ ] 40%
    Loading into Flash: [============= ] 46%
    Loading into Flash: [=============== ] 51%
    Loading into Flash: [================ ] 56%
    Loading into Flash: [================== ] 61%
    Loading into Flash: [=================== ] 66%
    Loading into Flash: [===================== ] 71%
    Loading into Flash: [====================== ] 76%
    Loading into Flash: [======================== ] 81%
    Loading into Flash: [========================= ] 86%
    Loading into Flash: [=========================== ] 92%
    Loading into Flash: [============================= ] 97%
    Loading into Flash: [==============================] 100%
=============================================================================================================================================== [SUCCESS] Took 3.30 seconds ===============================================================================================================================================
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: platformio run --target upload --upload-port /dev/cu.usbmodem1201 

Processing nanorp2040connect (platform: raspberrypi; board: nanorp2040connect; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/raspberrypi/nanorp2040connect.html
PLATFORM: Raspberry Pi RP2040 (1.8.0) > Arduino Nano RP2040 Connect
HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink, raspberrypi-swd)
PACKAGES: 
 - framework-arduino-mbed @ 3.5.4 
 - tool-openocd-raspberrypi @ 2.1100.0 (11.0) 
 - tool-rp2040tools @ 1.0.2 
 - toolchain-gccarmnoneeabi @ 1.90201.191206 (9.2.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 41 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit NeoPixel @ 1.11.0
|-- neopixel_led
|   |-- Adafruit NeoPixel @ 1.11.0
Building in release mode
Checking size .pio/build/nanorp2040connect/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  15.3% (used 41452 bytes from 270336 bytes)
Flash: [          ]   0.2% (used 4158 bytes from 2097152 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, jlink, picotool, raspberrypi-swd
CURRENT: upload_protocol = picotool
Looking for upload port...
Using manually specified: /dev/cu.usbmodem1201
Forcing reset using 1200bps open/close on port /dev/cu.usbmodem1201
Uploading .pio/build/nanorp2040connect/firmware.elf
rp2040load 1.0.1 - compiled with go1.15.8
.....................
*** [upload] Error 1
=============================================================================================================================================== [FAILED] Took 11.64 seconds ===============================================================================================================================================

 *  The terminal process "platformio 'run', '--target', 'upload', '--upload-port', '/dev/cu.usbmodem1201'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

As you can see after the first upload the bord is not seen anymore. It must be something related to platformIO because i don’t have this problem with the arduino ide.
Thank you in advance, any help is appreciated.

The problem was that iwas using int main and not void loop and void setup.