Error: Please specify `upload_port` for environment or use global `--upload-port` option


I am using platformio to develop for an NXP imx rt 1020. Since I use freertos+lwip+pppos I choose to not make use of zephyr, but to copy all the necessary NXP files into my hand crafted “nxp library”. I had some help setting up my project from this forum. It works fine, until I pressed the “upload” button instead of pressing F5 (debug).

So, running the project in debug works like a charm. Still, when I press the upload button I get this error:

Building .pio\build\mimxrt1020_evk\firmware.bin
Configuring upload protocol…
AVAILABLE: blackmagic, jlink, mbed
CURRENT: upload_protocol = mbed
Looking for upload disk…
Error: Please specify upload_port for environment or use global --upload-port option.
For some development platforms it can be a USB flash drive (i.e. /media//)

It seems to default to mbed upload protocol. I use the “segger jlink” when I press F5.

So I thought, lets specify upload_protocol = jlink, but that gives me this error:

Building .pio\build\mimxrt1020_evk\firmware.bin
Configuring upload protocol…
AVAILABLE: blackmagic, jlink, mbed
CURRENT: upload_protocol = jlink
Uploading .pio\build\mimxrt1020_evk\firmware.bin
*** [upload] Error 3221225477
========================================================================== [FAILED] Took 17.11 seconds ==========================================================================
The terminal process “C:\Users\baprins.platformio\penv\Scripts\platformio.exe ‘run’, ‘–target’, ‘upload’, ‘–environment’, ‘mimxrt1020_evk’” terminated with exit code: 1.

Any idea how to get this to work?

Many thx in advance

My platformio.ini:

platform = nxpimxrt
board = mimxrt1020_evk
upload_protocol = jlink
debug_build_flags = -O0 -g -ggdb
build_flags = 
    -I include
    -I include/lwip
lib_extra_dirs =
lib_deps = 
board_build.ldscript = MIMXRT1021.ld

upload_protocol instead.

Ah sorry for the typo, I meant to say that. It’s correct in my pasted platformio.ini though.

That’s not good. Can you do the project task Advanced → Verbose Upload and copy-paste the log here?

-rt-1020\xip\fsl_flexspi_nor_boot.o .pio\build\mimxrt1020_evk\src\hal\uart.o .pio\build\mimxrt1020_evk\src\lwip\sio.o .pio\build\mimxrt1020_evk\src\main.o -L.pio\build\mimxrt1020_evk -Wl,–start-group -lc -lgcc -lm -lstdc++ -lnosys -Wl,–end-group
MethodWrapper([“checkprogsize”], [".pio\build\mimxrt1020_evk\firmware.elf"])
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
RAM: [ ] 0.0% (used 4640 bytes from 33554432 bytes)
Flash: [ ] 0.2% (used 18644 bytes from 8388608 bytes)
.pio\build\mimxrt1020_evk\firmware.elf :

section size addr

.boot_hdr 8192 1610612736

.text 18312 1610620928

.data 332 536870912

.data_RAM2 0 0

.data_RAM3 0 538968064

.bss 4308 536871264

.uninit_RESERVED 0 536870912

.noinit_RAM2 0 0

.noinit_RAM3 0 538968064

.noinit 0 536875572

.heap 4096 536875572

.heap2stackfill 4096 536879668

.stack 0 536932352

.ARM.attributes 46 0

.comment 126 0

.debug_frame 7808 0

.stab 204 0

.stabstr 441 0

Total 47961
arm-none-eabi-objcopy -O binary .pio\build\mimxrt1020_evk\firmware.elf .pio\build\mimxrt1020_evk\firmware.bin
([“upload”], [".pio\build\mimxrt1020_evk\firmware.bin"])
AVAILABLE: blackmagic, jlink, mbed
CURRENT: upload_protocol = jlink
JLink.exe -device MIMXRT1021DAG5A -speed 4000 -if swd -autoconnect 1 -NoGui 1 -CommanderScript “D:\dev\bp\iobox\nxpport.pio\build\mimxrt1020_evk\upload.jlink”
*** [upload] Error 3221225477
========================================================================== [FAILED] Took 12.62 seconds ==========================================================================
Environment Status Duration

mimxrt1020_evk FAILED 00:00:12.621
mimxrt1024_evk IGNORED

The JLink.exe program has just died with error code 0xc0000005, which is a generic “access violation” error (source).


  • JLink.exe is completelly corrupted
  • there is a bug in JLink.exe causing it to crash

Can you remove the tool-jlink package folder so that PIO redownloads a fresh version? It should be C:\Users\<user>\.platformio\packages\tool-jlink. Then retry uploading.

If this is does not help, please manually open a terminal in the project directory and execute the two commands

C:\Users\<user>\.platformio\packages\tool-jlink\JLink.exe -device MIMXRT1021DAG5A -speed 4000 -if swd -autoconnect 1 -NoGui 1 -CommanderScript "D:\dev\bp\iobox\nxpport\.pio\build\mimxrt1020_evk\upload.jlink"

Do you obseve the same error message and code?

Deleted the tool-jlink folder. It gets downloaded again.

Running advanced/verbose upload gives me :

Processing script file…

J-Link connection not established yet but required for command.
Connecting to J-Link via USB…FAILED: Cannot connect to J-Link.

J-Link connection not established yet but required for command.
Connecting to J-Link via USB…FAILED: Failed to open DLL

J-Link connection not established yet but required for command.
Connecting to J-Link via USB…FAILED: Failed to open DLL

Script processing completed.

Trying to upload in debug mode gives me somewhat more information:


It no longer can connect to the nxp board?!

I tried from Xpresso, that still works fine of course. But I guess it uses their proprietary NXP/Xpresso debugger?

My device manager shows the same as before:


I deleted that driver, but Windows keeps reinstalling this version of the DLL. I read :
GoJimmyPi: Fixing J-Link “No emulators connected via USB”: How to have J-Link work for both Segger Utilities and VisualGDB (although probably not concurrently)

But he has a JLink driver. I don’t. My NXP imx RT1020 should have a JLink probe, right? I noticed the SEGGER J-Link popup many times when uploading to my board in debug mode…

When you download and install the latest JLink version from SEGGER - The Embedded Experts - Downloads - J-Link / J-Trace (7.52b), can you connect to the JLink and the chip using the JFlashLite program that is installed with it?

Is that using JLink.exe and related or OpenOCD as debugger?

JFlash lite can see my board.

I don’t know what MCUXpresso uses.

I get to that screen to without having a JLink connected so that is actually a bad test. Can you try and connect to the chip within JFlash, not JFlashLite?

Ah, no, that doesn’t work.

PS: for what it’s worth. MCUXpresso uses this:

I guess there is no easy way to use that instead in platformio?

CMSIS-DAP can be supported, the latest platform code has a case for that

but the board manifest does not list cmsis-dap, so you would need to add it in that array

locally (<user home>/.platformio/platforms/nxpimxrt/boards/mimxrt1020_evk.json), then upload_protocol = cmsis-dap should trigger starting OpenOCD with the interface/cmsis-dap.cfg file.

But is that really a CMSIS-DAP, did you not say there is a JLink connected?

How can I tell ? I have no idea how to see which onboard debug probe sits on an imx rt 1020 EVK board. All I can see is what’s in my screen. When I hit ‘start debug’ in MCUXpresso, it shows that it finds one probe: CMSIS-DAP. In the selection boxes below, I unchecked all except MCUXpresso IDE LinkServer. It finds the CMSIS-DAP probe.

On the other hand… in platformio, I’ve been using JLink. Where I could see the SEGGER J-Link popup appear when I hit ‘start debug’ (which shows erase/program status).

Can this board have both then?

I my attempts to get platformio working again, I also used Zadig to enforce certain DLLs, ultimately removing my COM port (which I think was used by SEGGER J Link). Weirdly enough, without this COM port, Xpresso IDE was still able to upload programs.

After reinstalling SEGGER JLink once more, I revived the COM port, but still the same result. JLink won’t upload anymore since it claims it can’t find a device and opens the emulator dialog.