PlatformIO Community

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:

loadfile .pio\build\teensy41\firmware.hex

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:

platform = teensy
board = teensy41
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
upload_protocol = custom
upload_flags =
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
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!


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.