Teensy 4.1 Uploading with JLink

I have modified a Teensy 4.1 to give me access to the JTAG pins on the IMXRT1062, it is connected to a Segger J-Link EDU with the following pins: VTref, GND, TDI,TMS,TCK,TDO.

I am having trouble uploading and debugging using platformio in VSCode. When I try and upload my code it shows the following and just hangs forever.

Configuring upload protocol...
AVAILABLE: jlink, jlink-jtag, teensy-gui
CURRENT: upload_protocol = jlink-jtag
Uploading .pio\build\teensy41\firmware.hex

My platformio.ini looks like this:

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
debug_tool = jlink
upload_protocol = jlink-jtag

I am able to upload the hex file to the teensy using Seggers tools with no issues so I’m not quite sure what is wrong. I have tried various config settings with no luck. What is the best way to troubleshoot this?

1 Like

Please execute the project task “Advanced → Verbose Upload” and post output.

Processing teensy41 (platform: teensy; board: teensy41; framework: arduino; debug_tool: jlink; upload_protocol: jlink-jtag)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: Redirecting...
PLATFORM: Teensy (4.12.0) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:

  • framework-arduinoteensy 1.153.0 (1.53)
  • tool-jlink 1.68801.0 (6.88.1)
  • tool-teensy 1.152.200516 (1.52)
  • toolchain-gccarmnoneeabi 1.50401.190816 (5.4.1)
    LDF: Library Dependency Finder → Library Dependency Finder (LDF) — PlatformIO latest documentation
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 89 compatible libraries
    Scanning dependencies…
    No dependencies
    Building in release mode
    arm-none-eabi-g++ -o .pio\build\teensy41\firmware.elf -T imxrt1062_t41.ld -Wl,–gc-sections,–relax -mthumb -mcpu=cortex-m7 -Wl,–defsym=__rtc_localtime=1610195861 -fsingle-precision-constant -mfloat-abi=hard -mfpu=fpv5-d16 -O2 .pio\build\teensy41\src\main.cpp.o -LC:\Users<user>.platformio\packages\framework-arduinoteensy\cores\teensy4 -L.pio\build\teensy41 -Wl,–start-group .pio\build\teensy41\libFrameworkArduino.a -larm_cortexM7lfsp_math -lm -lstdc++ -Wl,–end-group
    MethodWrapper([“checkprogsize”], [“.pio\build\teensy41\firmware.elf”])
    arm-none-eabi-objcopy -O ihex -R .eeprom .pio\build\teensy41\firmware.elf .pio\build\teensy41\firmware.hex
    Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
    RAM: [= ] 7.9% (used 41660 bytes from 524288 bytes)
    Flash: [ ] 0.2% (used 14304 bytes from 8126464 bytes)
    .pio\build\teensy41\firmware.elf :

section size addr

.text.progmem 6928 1610612736

.text.itcm 6320 0

.fini 4 6320

.text.itcm.padding 26444 6324

.data 1056 536870912

.bss 7840 536871968

.bss.dma 12384 538968064

.debug_frame 96 0

.ARM.attributes 46 0

.comment 110 0

Total 61228
([“upload”], [“.pio\build\teensy41\firmware.hex”])
AVAILABLE: jlink, jlink-jtag, teensy-gui
CURRENT: upload_protocol = jlink-jtag
JLink.exe -device MIMXRT1062xxxxA -speed 4000 -if jtag -autoconnect 1 -NoGui 1 -CommanderScript “C:\Users<user>\Documents\PlatformIO\Projects\Test Debugger.pio\build\teensy41\upload.jlink”

Weird, this looks okay.

Can you please open a PIO CLI and execute

C:\Users\<user>\.platformio\packages\tool-jlink\JLink.exe -device MIMXRT1062xxxxA -speed 4000 -if jtag -autoconnect 1 -NoGui 1 -CommanderScript "C:\Users\<user>\Documents\PlatformIO\Projects\Test Debugger\.pio\build\teensy41\upload.jlink"

yourself (while adapting the <user> path information) to check what the output is?

Also what’s the output of just

C:\Users\<user>\.platformio\packages\tool-jlink\JLink.exe -device MIMXRT1062xxxxA -speed 4000 -if jtag -autoconnect 1 -NoGui 1

When I use that platformio.ini, while having no debugger connected at all, JLink will at least complain.

Uploading .pio\build\teensy412\firmware.hex
SEGGER J-Link Commander V6.88b (Compiled Nov 27 2020 15:45:43)
DLL version V6.88b, compiled Nov 27 2020 15:44:11


J-Link Command File read successfully.
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.

Do you have an antivirus active that might interfere? Does temporarily disabling it change something?

First Command

SEGGER J-Link Commander V6.88b (Compiled Nov 27 2020 15:45:43)
DLL version V6.88b, compiled Nov 27 2020 15:44:11

J-Link Command File read successfully.
Processing script file…

J-Link connection not established yet but required for command.
Connecting to J-Link via USB…O.K.
Firmware: J-Link V11 compiled Nov 12 2020 10:07:08
Hardware version: V11.00
S/N: 261008241
License(s): FlashBP, GDB
OEM: SEGGER-EDU
VTref=3.309V
Target connection not established yet but required for command.
Device position in JTAG chain (IRPre,DRPre) : -1,-1 => Auto-detect

Second Command

SEGGER J-Link Commander V6.88b (Compiled Nov 27 2020 15:45:43)
DLL version V6.88b, compiled Nov 27 2020 15:44:11

Connecting to J-Link via USB…O.K.
Firmware: J-Link V11 compiled Nov 12 2020 10:07:08
Hardware version: V11.00
S/N: 261008241
License(s): FlashBP, GDB
OEM: SEGGER-EDU
VTref=3.309V
Device position in JTAG chain (IRPre,DRPre) : -1,-1 => Auto-detect

I disabled antivirus and still the same result

Hmm this looks all good, question is why does PlatformIO not give any output after that.

Can you please start the program C:\Users\<user>\.platformio\packages\tool-jlink\JFlash.exe, create a new project with the settings

and then try and connect

Is that successfull?

It seems perfectly fine. Also a note, when I try and upload with platformio it hangs indefinitely unless I click on upload again and tell it to “Terminate Task”

Okay I’ve also noticed that my teensy platform is one version behind the current one, but after updating I still get the update and no hangup, so that should be okay.

This all seems pretty good, the JLink tools can connect to the target. No idea why PlatformIO isn’t even able to call into them though.

As a last test, can you execute

C:\Users\<user>\.platformio\packages\tool-jlink\JLinkGDBServerCL.exe -singlerun -if jtag -select USB -device MIMXRT1062xxxxA -port 2331

and post the output? That should be the command with which the GDB server for debugging is opened.

If no output appears and the VSCode task appears to hang, my only recommendations are

  • restart VSCode
  • restart PC
  • Upgrade PlatformIO to latest core version. In PIO CLI pio upgrade --dev, then restart VSCode
  • uninstall instead of disable Antivirus. (I’ve had cases with Avast Antivirus where it still interfered although it was being “inactive”)
  • temporarily disable Windows Defender (Turn off Defender antivirus protection in Windows Security - Microsoft Support)
  • re-test in a project that does not contain spaces. There’s been old issues regarding that in the past. (“Test Debugger” contains a spcae)

SEGGER J-Link GDB Server V6.88b Command Line Version

JLinkARM.dll V6.88b (DLL compiled Nov 27 2020 15:44:11)

Command line: -singlerun -if jtag -select USB -device MIMXRT1062xxxxA -port 2331
-----GDB Server start settings-----
GDBInit file: none
GDB Server Listening port: 2331
SWO raw output listening port: 2332
Terminal I/O port: 2333
Accept remote connection: localhost only
Generate logfile: off
Verify download: off
Init regs on start: off
Silent mode: off
Single run mode: on
Target connection timeout: 0 ms
------J-Link related settings------
J-Link Host interface: USB
J-Link script: none
J-Link settings file: none
------Target related settings------
Target device: MIMXRT1062xxxxA
Target interface: JTAG
Target interface speed: 4000kHz
Target endian: little

Connecting to J-Link…
J-Link is connected.
Firmware: J-Link V11 compiled Nov 12 2020 10:07:08
Hardware: V11.00
S/N: 261008241
OEM: SEGGER-EDU
Feature(s): FlashBP, GDB
Checking target voltage…
Target voltage: 3.31 V
Listening on TCP/IP port 2331
Connecting to target…

J-Link found 1 JTAG device, Total IRLen = 4
JTAG ID: 0x0BA02477 (Cortex-M4)
Connected to target
Waiting for GDB connection…

Do the things listed above make a difference?

Also, if you add

debug_tool = custom
debug_server = 
   C:\Users\<user>\.platformio\packages\tool-jlink\JLinkGDBServerCL.exe 
   -singlerun 
   -if 
   jtag 
   -select 
   USB 
   -device 
   MIMXRT1062xxxxA 
   -port 
   2331
debug_port = localhost:2331
debug_init_cmds =
   target extended-remote $DEBUG_PORT
   monitor clrbp
   monitor speed auto
   monitor reset
   monitor halt
   $LOAD_CMDS
   $INIT_BREAK

(with adapted path info) to the platformio.ini, does debugging work in VSCode?

I have restarted VS code, updated platformio, reinstalled platformio, created a new project which is spaces free. None of these made a difference yet, but I have yet to uninstall virus protection/disable defender.

The custom debug tools almost work. It was able to flash the teensy once but then VS Code jumped to a random arduino lib and the arduino became unstable to where I couldn’t do anything and had to reflash it with JFlash. Not sure if that is a different issue or what.

I appreciate all the help… I’m still trying everything I can.

Well the base error is that PlatformIO doesn’t seem to be able to execute any commands from inside VSCode to the Jlink tools.

When I do “Start Debugging” in VSCode with the above platformio.ini, I do get the JLink output, telling me it failed to start (since no JLink is connected of course)

And I do get the “Verbose Upload” JLink output as indicated above.

I’m not excluding antivirus to be a culprit if you get no output at all.

It seems to help in your setup though to specify explicit commands.

For uploading you can also try the platformio.ini

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
upload_protocol = custom
upload_command =
   $PROJECT_PACKAGES_DIR/tool-jlink/JLink.exe 
   -device 
   MIMXRT1062xxxxA
   -if 
   jtag
   -autoconnect 
   1
   -NoGui 
   1
   -CommanderScript 
   upload.jlink

And a upload.jlink file at the same level as the platformio.ini with content

h
loadfile .pio\build\teensy41\firmware.hex
r
q

Then check “Verbose Upload” if the tool is invoked correctly and flashes correctly (docs).

I went ahead and uninstalled my antivirus and disabled defender temporarily but unfortunately it is still hanging up on upload.

I also tried the above, here is the end of the output… still looks to be the same issue

arm-none-eabi-objcopy -O ihex -R .eeprom .pio\build\teensy41\firmware.elf .pio\build\teensy41\firmware.hex
MethodWrapper([“checkprogsize”], [“.pio\build\teensy41\firmware.elf”])
Advanced Memory Usage is available via “PlatformIO Home > Project Inspect”
RAM: [= ] 7.9% (used 41660 bytes from 524288 bytes)
Flash: [ ] 0.2% (used 14304 bytes from 8126464 bytes)
.pio\build\teensy41\firmware.elf :

section size addr

.text.progmem 6928 1610612736

.text.itcm 6320 0

.fini 4 6320

.text.itcm.padding 26444 6324

.data 1056 536870912

.bss 7840 536871968

.bss.dma 12384 538968064

.debug_frame 96 0

.ARM.attributes 46 0

.comment 110 0

Total 61228
([“upload”], [“.pio\build\teensy41\firmware.hex”])
AVAILABLE: custom, jlink, teensy-gui
CURRENT: upload_protocol = custom
C:\Users<user>.platformio\packages\tool-jlink\JLink.exe

Please file a bug in Issues · platformio/platform-teensy · GitHub with reference to this thread, I have no idea why this hangs up. The standard platformio.ini from the first post should work.

As an extravangza test one could install VirtualBox + Ubuntu 20 + Guest extensions and test whether it works in that virtual machine, when the USB device is forwarded. But as said, the invocations work for me on my Windows 10 x64 system without problems.

Correction to previous platformio.ini: It should have been

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
upload_protocol = custom
upload_flags =
   -device 
   MIMXRT1062xxxxA
   -if 
   jtag
   -autoconnect 
   1
   -NoGui 
   1
   -CommanderScript 
   upload.jlink
upload_command = $PROJECT_PACKAGES_DIR/tool-jlink/JLink.exe $UPLOAD_FLAGS

But that doesn’t change a lot regarding the initial problem.

1 Like

I have managed to get it working. I added/removed a few things to my ini after @maxgerhardt 's suggestions.
Here is my platformio.ini:

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
upload_protocol = custom
upload_flags =
   -device
   MIMXRT1062xxx6A
   -speed
   4000
   -if
   jtag
   -jtagconf
   -1,-1
   -autoconnect
   1
   -NoGui
   1
   -CommanderScript
   "upload.jlink"
upload_command = $PROJECT_PACKAGES_DIR\tool-jlink\JLink.exe $UPLOAD_FLAGS
debug_tool = custom
debug_server = 
   C:\Users\\\<user>\\.platformio\packages\tool-jlink\JLinkGDBServerCL.exe 
   -singlerun 
   -if 
   jtag 
   -select 
   USB 
   -device 
   MIMXRT1062xxx6A 
   -port 
   2331
   -speed
   4000
debug_port = localhost:2331
debug_init_cmds =
   target extended-remote $DEBUG_PORT

with an upload.jlink file at the root of the project:

r
loadfile .pio\build\teensy41\firmware.hex
r
q

Thanks for helping @maxgerhardt
I’m still not sure what the underlying issue is, I doubt I will look into it much further but if a dev is interested I can work with them to figure it out.

2 Likes

How hard was the mod need to get this working, do you have pictures? I’ve put this off as I did not find any great guides as to the how to do it! hint hint :slight_smile:

I have not seen anyone else do it with a Teensy 4/4.1 yet. The Teensy 3s are a bit easier to mod since they had debug pads on the board, but you still needed to remove the same chip. It requires good soldering skills, hot air station, microscope, magnet wire, etc. I am still in the early stages of the modification so it is a mess. I am waiting on a pcb to be made which should make this presentable.
Here are some pics.



The mod requires removing the MKL02Z32VFG4 to access the JTAG pads, connecting those to a J-Link, and reconnecting the chip to the other (non JTAG) pads to keep everything happy… And yes… that is the MKL02Z32VFG4 floating off to the right.

@datkins47 Let me know if you need guidance, if you decide to take it on.

1 Like

credit due there, just wow! might wait before tackling that, love the teensy 4.1 with ethernet but not sure that’s ready for my solder blobbing skills, you thinking pcb to replace chip?

1 Like

I designed a flex pcb that will be soldered in place of the chip and extrude out the right side of the board and breakout the pins so they can be jumpered over to the J-Link. It will involve de soldering the M0 chip, soldering the m0 to the flex pcb, and soldering the flex pcb back in place of the M0 on the Teensy. Then you have normal 2.54mm headers to jumper from.

I left the chip in the equation because it is handling a few things besides just programming, without it I believe the processor never starts up a DCDC converter. Also this way you can jumper the pins back to the chip and use it as normal.