Teensy 4.1 Uploading with JLink

might be interested in that if you get going, that’s soldering we can do!

A little update for anyone who comes across this. I was getting this error during upload

****** Error: Failed to prepare for programming.
RAM check failed @ addr 0x20001D8C.
RAM check failed while testing 0x7FF0 bytes @ addr 0x20001D8C.
Error while determining flash info (Bank @ 0x60000000)
Unspecified error -1

I found a suggestion to reset and halt before uploading and that seems to have fixed this issue. The new upload.jlink file is as follows:

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

I will also update the solution post to reflect this.

Thanks for that great guide and all the information regarding the debugging.
I was able to set my teensy 4.1 up for the JLink connection.
With the platform.ini above, I was able to upload via JTAG and start the debugger, but the debugger kept jumping through the code in (at least for me) uncomprehensive steps.
As far as I understand, this is probably to some compiler optimization that does not work with the debugger. As this may be relevant to someone else trying this, here’s the platformio.ini that worked for me:

[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
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_tool = jlink
debug_server = 
   ${platformio.packages_dir}\tool-jlink\JLinkGDBServerCL.exe ; edited as suggested by Ivan
   -singlerun
   -if 
   jtag 
   -select 
   USB 
   -device 
   MIMXRT1062xxx6A 
   -port 
   2331
   -speed
   4000
debug_port = localhost:2331

I changed the debug_protocol back to jlink, but overrode some of its parameters, which I guess left the rest of the compiler’s parameters untouched. Adding debug_build_flags = -O0 -ggdb3 -g3 did not work for me, but this did.
I used the upload.jlink file described here.

Thanks again for this thread, really glad I found it, if I had been successful at all, it would have taken a lot longer without it!

Cheers
Philipp

A few hints for you that might help you to solve this issue:

  1. Make your config portable using Interpolation of Values. Replace hardcoded $PROJECT_PACKAGES_DIR and C:\Users\\\rovedo\\.platformio\packages values by ${platformio.packages_dir}/tool-jlink/JLink.exe
  2. Change Buid Configuration to the debug mode.
  3. Build project in verbose mode pio run -v.

So, you will see all flags. I can suppose you will need to remove some default flags using the build_unflags option.

In any case, please share your progress here. Thanks in advance!

Hi Ivan,

thanks a lot for your reply, I edited the script to incorporate your suggestion.

I think I didn’t make myself very clear reading over my text again:

The configuation I posted, which is slightly different to the one sp33 posted a while ago,
works perfectly for me (on multiple machines as well). Compiling, uploading and debugging are all running as expected.

I just wanted to post the ini in case someone else was struggling with debugging using the file originally suggested.

I am keen to give this a try, and have smd flex pcb tooling and experience. If it works I’d be happy to fab extras for the community. Might you be willing to share the schematic and layout or other advice? thanks very much!

I am willing to share what I have, it’s just not organized at the moment. Since posting this I have made multiple versions trying to come up with the best solution possible. Here are some pics of my progress.


Here is a sheet I was making to map out the pins, there’s a tab for links I referenced and pics of progress too.
https://docs.google.com/spreadsheets/d/1IHnKprGMN98fk_qJn_A1hpxdfL1dd9GDggG42iSkLR4/edit?usp=sharing

Main issues I had were pads lifting when trying to accomplish a through hole style soldering method. Once I Switched to using hot air without through holes, lining it up was the hardest part. Let me know which one you are interested in trying out, I have some KiCad files they just are not versioned very well unfortunately.

Hi @sp33 , I’m very interested in what you might be able to share. Really… no matter the condition. I have a huge need to use debug facilities of the chip. I am willing to pay for that capability too. Any help you could provide please let us know.

Note that there’s also a chip that is “close” to the Teensy (NXP iMX.RT1062) and has an evaluation kit for $110: MIMXRT1060-EVKB. Not sure if you can just flash a Teensy + Arduino firmware on it without modifications, but they should be relatively close so that adaptation is minimal and you have can have a debugger on that thing.