Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: [1] 2  Send TopicPrint
Very Hot Topic (More than 25 Replies) Unable to program/debug: Atmel-ICE + Adafruit Metro M4 (Read 6674 times)
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Jan 18th, 2023 at 11:57am
Print Post  
Hi,
I am using Atmel-ICE to program/debug Adafruit Metro M4 board.

With Microchip studio and VS2022, I tried all three uploader options, "Atmel-ICE", "Atmel-ICE over openOCD", "Atmel-ICE over openOCD(vMicro)". The same error happens.

Open On-Chip Debugger 0.10.0+dev-gf0767a31 (2018-06-11-13:36)
Licensed under GNU GPL v2
For bug reports, read
     http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
embedded:startup.tcl:60: Error: Can't find tro_m4/openocd_scripts/metro_m4.cfg
in procedure 'script' 
at file "embedded:startup.tcl", line 60
The uploader process failed
The uploader returned an error

please, help.
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #1 - Jan 18th, 2023 at 12:53pm
Print Post  
Thanks for the report.

Is there a specific reason to use the Atmel-ICE as a programmer instead of the standard tools for upload for this board?

The error is due to Adafruit not packaging an OpenOCD Script for the board in the board package, which needs logging as an issue against their repo, which will help Arduino IDE and Visual Micro users alike.

If you add a Local Board.txt to your project (vMicro > Add Code > Add Local Board.txt) and paste in the below:
Code
Select All
# Atmel ICE Upload for Adafruit Metro M4 (SAMD51), with Programmer "AtmelICE Over OpenOCD (vMicro)"
# as Adafruit have not packaged an OpenOCD Script in the board package.

target\atsame5x.cfg
tools.openocd.path=C:\ProgramData\VMicro\tools\openocd-0.10.0.20200213
tools.atmelICE.program.targetCmd=-c "transport select swd" -f "{build.openocdscript}"
 



Then ensure you have the "AtmelICE Over OpenOCD (vMicro)" Programmer selected and try again.

NOTE: You will also need to have the vMicro OpenOCD tools installed in C:\ProgramData\vMicro\tools\openocd-0.10.0.20200213, which can be downloaded from this location, and unzipped to "C:\ProgramData\vMicro\tools\" (Create this folder if not present).


« Last Edit: Jan 18th, 2023 at 4:01pm by Simon@Visual Micro »  
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #2 - Jan 18th, 2023 at 1:20pm
Print Post  
Thanks for the quick reply!
I tried your approach, and the error persists.

Uploading 'Statechart_middleware_SAMD_ino' to 'Adafruit Metro M4 (SAMD51) (adafruit_adafruit_metro_m4)' using 'Atmel ICE over OpenOCD (vMicro)'
Error during upload using programmer
The uploader process failed

The uploader process failed
Open On-Chip Debugger 0.10.0+dev-01058-g853a05287 (2020-02-13-16:41)
The uploader returned an error
Licensed under GNU GPL v2
For bug reports, read
     http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
swd
embedded:startup.tcl:26: Error: Can't find openocd_scripts/metro_m4.cfg
in procedure 'script' 
at file "embedded:startup.tcl", line 26

Does it mean the board.txt is not recognized by vMicro?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #3 - Jan 18th, 2023 at 3:34pm
Print Post  
Thanks for the update, and apologies the board.txt entries should have looked like the attached (the code section seems to be malforming the display which we will investigate).
« Last Edit: Jan 18th, 2023 at 3:37pm by Simon@Visual Micro »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #4 - Jan 19th, 2023 at 8:09am
Print Post  
Just tried the new script. We are making progress, and the error message changes as follows.

Uploading 'Statechart_middleware_SAMD_ino' to 'Adafruit Metro M4 (SAMD51) (adafruit_adafruit_metro_m4)' using 'Atmel ICE over OpenOCD (vMicro)'
Open On-Chip Debugger 0.10.0+dev-01058-g853a05287 (2020-02-13-16:41)
Licensed under GNU GPL v2
For bug reports, read
     http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
swd
****[vMicro]**** Uploading ELF :target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0000058c msp: 0x2000d6a0
Error during upload using programmer
The uploader process failed

The uploader process failed
The uploader returned an error
** Programming Started **
Error: SAM: NVM lock error
Error: SAM: NVM programming error
Error: Failed to erase block containing 00000000
Error: SAM: failed to erase sector 0 at 0x00000000
Error: failed erasing sectors 0 to 9
embedded:startup.tcl:510: Error: ** Programming Failed **
in procedure 'program' 
in procedure 'program_error' called at file "embedded:startup.tcl", line 575
at file "embedded:startup.tcl", line 510
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #5 - Jan 19th, 2023 at 10:48am
Print Post  
Thanks for the update, this is due to the locked bootloader to my knowledge which needs unlocking before upload, then locking again afterwards (similar to SAM Chips).
https://openocd.org/doc-release/html/Flash-Commands.html#atsame5

Can you try the attached board.txt which will show the size of boot protected area on your chip.  We can then use this to change the pattern to disable the protection and restore it as required (in theory!).
« Last Edit: Jan 19th, 2023 at 10:49am by Simon@Visual Micro »  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #6 - Jan 19th, 2023 at 11:19am
Print Post  
Here is the log

Uploading 'Statechart_middleware_SAMD_ino' to 'Adafruit Metro M4 (SAMD51) (adafruit_adafruit_metro_m4)' using 'Atmel ICE over OpenOCD (vMicro)'
Open On-Chip Debugger 0.10.0+dev-01058-g853a05287 (2020-02-13-16:41)
Licensed under GNU GPL v2
For bug reports, read
     http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
swd
adapter speed: 100 kHz
****[vMicro]**** Uploading ELF :target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x000009ac msp: 0x2000d608
****[vMicro]**** Listing BOOTPROT Size
Bootloader protected in the first 16384 bytes
****************************************************************
shutdown command invoked
     The upload process has finished.
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #7 - Jan 19th, 2023 at 12:02pm
Print Post  
Thanks for the output.

The attached file **should** work, however we do not have a board with this chip to test this on, so please be aware of the risk of using this.

The file will show the BOOTPROT setting, disable it, upload the program, then set the BOOTPROT size back to 16384 and reset.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #8 - Jan 20th, 2023 at 10:56am
Print Post  
I think we are getting closer, but not yet successes Cheesy
What if I erase the whole chip manually and just use the hardware programmer?

Uploading 'Statechart_middleware_SAMD_ino' to 'Adafruit Metro M4 (SAMD51) (adafruit_adafruit_metro_m4)' using 'Atmel ICE over OpenOCD (vMicro)'
Open On-Chip Debugger 0.10.0+dev-01058-g853a05287 (2020-02-13-16:41)
Licensed under GNU GPL v2
For bug reports, read
     http://openocd.org/doc/doxygen/bugs.html
debug_level: 0
swd
adapter speed: 100 kHz
****[vMicro]**** Uploading ELF :target halted due to debug-request, current mode: Handler PendSV
xPSR: 0x6100000e pc: 0x00008b46 msp: 0x2002ffc0
****[vMicro]**** Listing BOOTPROT Size
Bootloader protected in the first 16384 bytes
****[vMicro]**** Disabling BOOTPROT
Bootloader protected in the first 0 bytes
Error during upload using programmer
The uploader process failed

****************************************************************
****[vMicro]**** Uploading ELF :
The uploader process failed
The uploader returned an error
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #9 - Jan 20th, 2023 at 11:37am
Print Post  
Thanks for the update.

That may work though there may be some other timeout or handling getting in the way within vMicro.

Would you be comfortable running the upload manually via OpenOCD and issuing the commands that way?
  
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #10 - Jan 20th, 2023 at 11:47am
Print Post  
Is there a way to use Microchip studio's native Atmel-ICE interfaces/APIs instead of OpenOCD?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #11 - Jan 20th, 2023 at 11:54am
Print Post  
I expect that will work yes, and vMicro has an option to use Atmel Studio Device programming so it just hands over to the Microchip Studio settings there.

The benefit of OpenOCD would be that Adafruit can integrate it into their board package in the future to benefit the whole Arduino community.

Is there a reason not to use the standard upload tools (bossac) in your setup? (custom board etc...)
  
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #12 - Jan 20th, 2023 at 1:14pm
Print Post  
I wish to use Atmel-ice as a hardware debugger. I am not sure, but the way I understand vMicro is I have to first setup Atmel-ice as uploader, then use it as debugger.

Furthermore, using Atmel-ice as debugger also requires the support of openOCD, I guess?
  
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #13 - Jan 20th, 2023 at 1:37pm
Print Post  
BTW, just went to adafruit forum and found this info.

https://forums.adafruit.com/viewtopic.php?p=794091&hilit=metro_m4.cfg#p794091
https://github.com/adafruit/ArduinoCore-samd/issues/208

It seems the openOCD configuration settings of metro M4 has been missing for many years.
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #14 - Jan 20th, 2023 at 2:15pm
Print Post  
Thanks, yes we had seen the GitHub report about it missing when we found it was not included in the board package.

The options to get it working are either:
1) Continue with our assistance to see if we can get it running with OpenOCD and send Adafruit the PR (as well as integrate it with vMicro).
2) Use Microchip Studio's tools to configure the Atmel ICE, then select it as the Uploader and Debugger in vMicro allowing Microchip Studio to handle both of these aspects.

NOTE: The debugging can be configured without the need to handle the uploader, as the standard uploader can be used via USB.  The debugger also wouldn't run into the locked bootloader element, as this is only involved in the upload process.

If debugging is the priority then we can assist with that, assuming you are happy to use the standard upload tools?
  
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #15 - Jan 24th, 2023 at 12:00pm
Print Post  
Yes, the main purpose is to use Atmel-ICE as a debugger because I am working on transplanting a multithreaded OS using Arduino libraries. It is not so easy to check the memory content and registers using the serial debugger.

Of course, it would be nice to make the OpenOCD uploader works. It could be the contribution to the Arduino community.
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #16 - Jan 31st, 2023 at 10:48am
Print Post  
Thanks for confirming debugging is the main aim, and using the standard upload tools instead of the ICE avoids the memory locks for now.

If you try the attached contents in your local board.txt this should allow the debugging to start succesfully.

Once we have that working, we can revisit the upload via the Atmel-ICE if you are happy to try that out, as we do not have this board to test with.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #17 - Feb 14th, 2023 at 12:29pm
Print Post  
Sorry for the delayed response.
I copied the board configuration from your latest reply.
And configure the debugger using Hardware, Atmel ICE, and default optimization.

Then click the run button (build and upload) of VS interface. The files are uploaded to the device using serial port. However the debugger session is not started.
« Last Edit: Feb 14th, 2023 at 12:31pm by Xinyu Tan »  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2370
Joined: Feb 13th, 2019
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #18 - Feb 14th, 2023 at 12:51pm
Print Post  
Thanks for the update.

Do you get any additional information in the Output > Debug or Output > Micro Build windows? (please attach both as text files for us to review)

Does Debug > Attach to Process start the debugging session now the code is uploaded?
  
Back to top
 
IP Logged
 
Xinyu Tan
Junior Member
**
Offline


Posts: 16
Joined: Jan 18th, 2023
Re: Unable to program/debug: Atmel-ICE + Adafruit Metro M4
Reply #19 - Feb 14th, 2023 at 1:05pm
Print Post  
Debug-> Attach to Process starts the debugging session using serial port. Also, use the "start" button of VS2022 native interface uploads the file and starts serial debugging.

btw, here attached the output of VM
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint