I am trying to set through code running on the Adafruit Grand Central M4 Express, which is based on a SAMD ARM Cortex M-4 chip. Based on other discussions here: Segger J-link, Adafruit Metro M4 -> USB dies when debug starts - #2 by ryanplusplus I have configured my ini file to bypass the bootloader, but still I get the error
Failed to launch GDB: .pioinit:16 Error in sourced command file::2331: Connection timed out. (from interpreter-exec console "source.pioinit")
It seems like it is timing out for some reason. Uploading via jlink works fine, so I know that the device is connected. The console output provides the following:
JLinkARM.dll V7.50a (DLL compiled Jul 8 2021 18:20:53)
Command line: -singlerun -if SWD -select USB -device ATSAMD51P20 -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: yes
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: ATSAMD51P20
Target interface: SWD
Target interface speed: 4000kHz
Target endian: little
Connecting to J-Link...
J-Link is connected.
Firmware: J-Link EDU Mini V1 compiled Nov 2 2021 11:12:01
Hardware: V1.00
S/N: 801039228
Feature(s): FlashBP, GDB
Checking target voltage...
Connecting to target failed. Connected correctly?
GDB Server will be closed...
Shutting down...
undefinedCould not connect to target.
Please check power, connection and settings.
Reading symbols from /home/rich/Documents/PlatformIO/Projects/VCProject/.pio/build/demo:tx/firmware.elf...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target...
.pioinit:16: Error in sourced command file:
:2331: Connection timed out.
My INI file is below, currently I’m uploading the demo:tx target
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env]
platform = atmelsam
board = adafruit_grandcentral_m4
framework = arduino
monitor_filters = log2file, time, default
board_build.upload.offset_address = 0x00000000
board_build.arduino.ldscript = flash_without_bootloader.ld
upload_protocol = jlink
debug_tool = jlink
[env:vc:tx]
src_filter = +<vc/tx/**/*.cpp> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/>
lib_deps =
TimerOne
[env:vc:rx]
src_filter = +<vc/rx/**/*.cpp> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/>
[env:demo:rx]
src_filter = +<demo/rx/**/*.cpp> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/>
[env:demo:tx]
src_filter = +<demo/tx/**/*.cpp> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/>
[env:scratch]
src_filter = +<scratch/**/*.cpp> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/>
The JLink utility is telling you it can’t connect to the chip. Are you sure VTREF, GND, SWDIO and SWDCLK are properly connected between the JLink and target board?
The SWD header is broken out on the board but there’s not lock/key housing, so with the ribbon cable there are 2 ways to connect it (Pinouts | Introducing the Adafruit Grand Central M4 Express | Adafruit Learning System) I can try flipping it around, but if it was on backwards, wouldn’t I get an error trying to upload to the device?
Yes you would. Funny, that is working?
I need to make a correction, the board does have a lock/key housing, the jlink device does not. I switched the ribbon to connect the other way but still no luck. Let me check the pins on the board and see if I’m getting appropriate voltages and report back.
It reports that it is, though I haven’t actually checked the hardware for signs that it is yet
Please open a commandline and execute
/home/rich/.platformio/packages/tool-jlink/JLinkGDBServer -singlerun -if SWD -select USB -device ATSAMD51P20 -port 2331
what does it output?
SEGGER J-Link GDB Server V7.50a Command Line Version
JLinkARM.dll V7.50a (DLL compiled Jul 8 2021 18:20:53)
Command line: -singlerun -if SWD -select USB -device ATSAMD51P20 -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: yes
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: ATSAMD51P20
Target interface: SWD
Target interface speed: 4000kHz
Target endian: little
Connecting to J-Link...
J-Link is connected.
Firmware: J-Link EDU Mini V1 compiled Dec 7 2021 08:38:51
Hardware: V1.00
S/N: 801039228
Feature(s): FlashBP, GDB
Checking target voltage...
Target voltage: 3.30 V
Listening on TCP/IP port 2331
Connecting to target...
ERROR: Could not connect to target.
Target connection failed. GDBServer will be closed...Restoring target state and closing J-Link connection...
Shutting down...
Could not connect to target.
Please check power, connection and settings
Between here and there I switch the ribbon cable and double checked all my power connections. I’m noticing that it is now seeing the target voltage = 3.3v, but still not able to connect to target.
Please post the output of the project task “Advanced → Verbose Upload”, I want to see whether regular uploading works or not.
> Executing task: platformio run --verbose --target upload --environment demo:tx <
Processing demo:tx (src_filter: +<demo/tx/**/*.cpp> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/>; platform: atmelsam; board: adafruit_grandcentral_m4; framework: arduino; monitor_filters: log2file, time, default; board_build.upload.offset_address: 0x00000000; board_build.arduino.ldscript: flash_without_bootloader.ld; upload_protocol: jlink; debug_tool: jlink)
--------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/atmelsam/adafruit_grandcentral_m4.html
PLATFORM: Atmel SAM (7.1.0) > Adafruit Grand Central M4
HARDWARE: SAMD51P20A 120MHz, 256KB RAM, 1MB Flash
DEBUG: Current (jlink) External (atmel-ice, jlink)
PACKAGES:
- framework-arduino-samd-adafruit 1.7.5
- framework-cmsis 2.50400.181126 (5.4.0)
- framework-cmsis-atmel 1.2.2
- tool-jlink 1.75001.0 (7.50.1)
- toolchain-gccarmnoneeabi 1.90301.200702 (9.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 18 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <RadioHead> (/home/rich/Documents/PlatformIO/Projects/VCProject/lib/RadioHead)
| |-- <SPI> 1.0 (/home/rich/.platformio/packages/framework-arduino-samd-adafruit/libraries/SPI)
| | |-- <Adafruit Zero DMA Library> 1.1.0 (/home/rich/.platformio/packages/framework-arduino-samd-adafruit/libraries/Adafruit_ZeroDMA)
| | | |-- <Adafruit TinyUSB Library> 1.4.3 (/home/rich/.platformio/packages/framework-arduino-samd-adafruit/libraries/Adafruit_TinyUSB_Arduino)
| | |-- <Adafruit TinyUSB Library> 1.4.3 (/home/rich/.platformio/packages/framework-arduino-samd-adafruit/libraries/Adafruit_TinyUSB_Arduino)
|-- <SPI> 1.0 (/home/rich/.platformio/packages/framework-arduino-samd-adafruit/libraries/SPI)
| |-- <Adafruit Zero DMA Library> 1.1.0 (/home/rich/.platformio/packages/framework-arduino-samd-adafruit/libraries/Adafruit_ZeroDMA)
| | |-- <Adafruit TinyUSB Library> 1.4.3 (/home/rich/.platformio/packages/framework-arduino-samd-adafruit/libraries/Adafruit_TinyUSB_Arduino)
| |-- <Adafruit TinyUSB Library> 1.4.3 (/home/rich/.platformio/packages/framework-arduino-samd-adafruit/libraries/Adafruit_TinyUSB_Arduino)
Building in release mode
MethodWrapper(["checkprogsize"], [".pio/build/demo:tx/firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 1.3% (used 3424 bytes from 262144 bytes)
Flash: [ ] 2.6% (used 26792 bytes from 1048576 bytes)
.pio/build/demo:tx/firmware.elf :
section size addr
.text 26520 0
.data 272 536870912
.hsram 1024 536871184
.bss 3152 536872208
.ARM.attributes 48 0
.comment 67 0
.debug_frame 3224 0
.stab 204 0
.stabstr 441 0
Total 34952
<lambda>(["upload"], [".pio/build/demo:tx/firmware.bin"])
AVAILABLE: atmel-ice, jlink, sam-ba
CURRENT: upload_protocol = jlink
JLinkExe -device ATSAMD51P20 -speed 4000 -if swd -autoconnect 1 -NoGui 1 -CommanderScript "/home/rich/Documents/PlatformIO/Projects/VCProject/.pio/build/demo:tx/upload.jlink"
SEGGER J-Link Commander V7.50a (Compiled Jul 8 2021 18:21:10)
DLL version V7.60h, compiled Feb 9 2022 14:14:53
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 EDU Mini V1 compiled Dec 7 2021 08:38:51
Hardware version: V1.00
S/N: 801039228
License(s): FlashBP, GDB
VTref=3.299V
Target connection not established yet but required for command.
Device "ATSAMD51P20A" selected.
Connecting to target via SWD
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
Cannot connect to target.
Target connection not established yet but required for command.
Device "ATSAMD51P20A" selected.
Connecting to target via SWD
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
Cannot connect to target.
Target connection not established yet but required for command.
Device "ATSAMD51P20A" selected.
Connecting to target via SWD
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
InitTarget() start
InitTarget()
Secured Atmel SAMD device detected.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash.
Executing default behavior previously saved in the registry.
Skipping unsecure.
User selected to not unsecure the secured device. Debugging is not possible.
InitTarget() end
Cannot connect to target.
Script processing completed.
============================ [SUCCESS] Took 4.34 seconds ============================
Environment Status Duration
------------- -------- ------------
vc:tx IGNORED
vc:rx IGNORED
demo:rx IGNORED
demo:tx SUCCESS 00:00:04.340
scratch IGNORED
============================ 1 succeeded in 00:00:04.340 ============================
Terminal will be reused by tasks, press any key to close it.
The chip is locked. Also PlatformIO is buggy in telling you “success”, when it could not upload.
Looks like this might be the issue
User selected to not unsecure the secured device. Debugging is not possible.
This was a prompt that came up from the jlink tool suite. As PIO uses their own gdb server I opted to ignore this prompt. Should I not have done?
If the JLink thinks the device is locked, let it unlock it. It will trigger a mass-erase of the flash, but we’re precisely trying to write something new in the flash…
It apparently doesn’t want to let me do that. I try to perform the mass erase using the jlink tools and it gets stuck in a loop.
InitTarget() start
InitTarget()
Do you want to unsecure the device? // select yes
Mass erase done!
Mass erase done!
Mass erase done!
// ... about a dozen more times
InitTarget() end
InitTarget() start()
InitTarget()
Do you want to unsecure the device?
// repeat
I’ve been doing some research, and I tried tying the reset pin to high through a PU resistor, but still no luck. Any ideas, or is now outside of PIO?
Assuming nothing was every truely written to the device or erased, is the board still flashable via the normal USB port?
Well, technically yes. If you can’t even connect to the board via the JLink commandline tools, there’s something wrong there.