VS Arduino
Visual Micro >> Hardware Debugging (GDB, GDB WiFi, GDB Stub) >> MSVS 2019 + Adafruit Feather M0 + J-Link
https://www.visualmicro.com/forums/YaBB.pl?num=1624161137

Message started by J Moore on Jun 20th, 2021 at 3:52am

Title: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 20th, 2021 at 3:52am
Hi my first post to the forum. Trying to move to Visual Studio/Visual Micro with JTAG/SWD debugging support for Cortex M0 and ESP32 family. I previously just used Visual studio and the arduino IDE for a Pololu A-Star 32U4 project.

I posted this over at the Adafruit forum but have had no response. I have effectively bricked two of the Feather M0's because Win 7 will not load a driver for some reason described in the last post to the thread.

Two Feather M0's not being recognized by Win7
https://forums.adafruit.com/viewtopic.php?f=24&t=180404

So while I want to do JTAG debugging (as I'm used to Rowley Crossconenct for ARM), I'm also trying to salvage something from these two Feather to figure out what happened. My hope is the issues are related to Win7 virtual com port USB drives and the J-Link will avoid that all together.

I'm using a Win7 environment using Dell Precision 490 Xenon desktop platform (I also have a very similar Dell Precision M6500 laptop). The feathers have been wired according to the instruction at Adafruit for SDW. I have uploaded the latest from all as described below:

Arduino 1.8.15

Visual Micro - Release 21.06.06.0 - 6th June 2021 - VS

J-Link V7.22b Windows Installer

2017-2019, AS7 Microsoft Visual Studio Community 2019
Version 16.0.1

Arduino IDE for Visual Studio by Visual Micro   19.0
Visual Micro is an Arduino Compatible IDE for Visual Studio 2017-2019.

I confirmed operation of the Segger using Crossworks on an old application. Then I used Zadig to ovewrite the Segger USB drive to WinUSB v6.1.7600.16385.

The verbose  VS output is captured in the attached text file.
The first error is an NV lock error which waterfalls into what amount to a failure to program the device.

Error: SAMD: NVM lock error
Error: Failed to erase row containing 00000000
Error: SAMD: failed to erase sector 0 at 0x00000000
Error: failed erasing sectors 0 to 81
embedded:startup.tcl:510: Error: ** Programming Failed **

Is overwriting the SAMD boot loader going to help this?

https://learn.adafruit.com/how-to-program-samd-bootloaders?view=all#flashing-a-s

P.S I do not seem to be able to attach the compiler output text file. Will email it.

I cross-posted these results to the Adafruit forum thread.

https://forums.adafruit.com/viewtopic.php?f=24&t=180404&p=878130#p878130
https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=MSVS2019_FeatherM0_JLINK_DownLoadFail.txt ( 2 KB | 6 Downloads )

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by Tim@Visual Micro on Jun 20th, 2021 at 3:57am
Hi

Please follow the guide in the yellow box near the top of this page.

Thanks

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 20th, 2021 at 4:16am

Tim@Visual Micro wrote on Jun 20th, 2021 at 3:57am:
Hi

Please follow the guide in the yellow box near the top of this page.

Thanks


I thought I did.  :( What did I miss?  :'(

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by Tim@Visual Micro on Jun 20th, 2021 at 3:41pm
:) It's only got the upload output. If you have switched on the two properties mentioned above and click build or start we will see the build properties, the compiler settings and the verbose upload.

We have the verbose upload so just a build with the settings will do.

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 20th, 2021 at 6:00pm
Full "Build & Upload" output attached.
The program file in the standard Arduino Blink example.

https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=MSV2019_FeatherM0_JLINK_DownloadFail_FULLBUILDDOWNLOAD.txt ( 77 KB | 4 Downloads )

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by Tim@Visual Micro on Jun 20th, 2021 at 10:12pm
Thanks, what is the date, time, name of the usb driver the jlink shows up as in device manager?

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 20th, 2021 at 10:46pm

Tim@Visual Micro wrote on Jun 20th, 2021 at 10:12pm:
Thanks, what is the date, time, name of the usb driver the jlink shows up as in device manager?


Find attached.


J Moore wrote on Jun 20th, 2021 at 3:52am:


I confirmed operation of the Segger using Crossworks on an old application. Then I used Zadig to ovewrite the Segger USB drive to WinUSB v6.1.7600.16385.



J_Link_Driver.png ( 36 KB | 3 Downloads )

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by Simon@Visual Micro on Jun 22nd, 2021 at 9:53am
Just to check the error is the same using the JLink configuration from the core, just listed as "J-Link over OpenOCD"?


Quote:
Is overwriting the SAMD boot loader going to help this?
https://forums.adafruit.com/viewtopic.php?f=24&t=180404&p=878130#p878130


I think it will be worth working through this process, at least up to the point where the fuses and other settings are read from the board, in Microchip Studio. 
Note - You will need to re-install the J-Link Driver from the Segger software to use the JLink in Microchip Studio.  Re-flashing the bootloader may help as well but I cannot be sure.

Microchip Studio will also allow the sketch to be uploaded via the JLink, using only their software and the Segger software, which would prove the board can be uploaded to successfully still.

Also to my knowledge this chip shouldn't need any specific NVM lock changes as part of the sketch upload normally (like on Arduino Due Native USB).




Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 22nd, 2021 at 5:49pm

Simon@Visual Micro wrote on Jun 22nd, 2021 at 9:53am:


I think it will be worth working through this process, at least up to the point where the fuses and other settings are read from the board, in Microchip Studio. 



Thank you for the response. My biggest concern is the possibility I did something to electrically damage the Feather M0. If it is a serial/USB/virtual comm loader screwup I will just as happily move on without any worries.

Given this error, I suspect it is a startup code issue where the startup code somehow branched/bombed to lockout the NVM/reprogramming. This seems to be below the Arduino loader at this point.

I have moved on to the ESP32 platform with the newer ST7789 color LCD (135x240) displays. I'm at the point of moving to VS with the ESP32 so I can single step/debug but have been waiting before upsetting my current Feather M0 configuration for the present J-Link trial. I will download and configure the latest Microchip studio and try as recommended.

Based on your comments, I assume that you can not see anything wrong with what I'm doing, so I will try and do the same SWD download over J-Link on the ESP while I have it running. The HiLetgo TTGO OLED seems more stable using the Silicon Labs CP2014. It is still virtual comports but windows don't seem to keep incrementing the installed virtual comm number and it seems to reliably load.

So thanks again and I will report back after I do some further setup/evaluation.


Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 23rd, 2021 at 9:44am
So I tried to install MicroChip Studio and it seemed to hang up. After reading all the complaints about the Micro Chip transition, I repaired the 2017 Atmel Studio 7 install I already have. This seemed to work (back then) as I recall (it has been a while).

I also reinstalled the latest Segger J-LInk but I'm not sure that changed anything. It still lists the  "J-Link over OCD" and the driver is the same one as posted befoire.

.I uninstalled the J-Link driver from the windows Device Driver dialog but windows just reinstalled the same drive back.


https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=AtmelStudio7FeatherM0_J-Link_001.txt ( 29 KB | 3 Downloads )
AtmelStudio7_001.png ( 77 KB | 1 Download )

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by Simon@Visual Micro on Jun 23rd, 2021 at 10:35am
Thanks for the detail, and windows does cache all the drivers, so sadly it often re-installs the previous driver on detection.

To force the Segger driver back in:
1) Run the \SEGGER\JLink\USBDriver\x64\dpinst_x64.exe to ensure the drivers are available in windows
2) Device Manager > Right click the JLink Device > Update Driver > Browse My Computer for Drivers > Let Me Pick from a list of available drivers on my computer
3) Select the "JLink driver", and next, this should now show the Segger driver in device manager.


Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 23rd, 2021 at 9:02pm

Simon@Visual Micro wrote on Jun 23rd, 2021 at 10:35am:
Thanks for the detail, and windows does cache all the drivers, so sadly it often re-installs the previous driver on detection.

To force the Segger driver back in:
1) Run the \SEGGER\JLink\USBDriver\x64\dpinst_x64.exe to ensure the drivers are available in windows
2) Device Manager > Right click the JLink Device > Update Driver > Browse My Computer for Drivers > Let Me Pick from a list of available drivers on my computer
3) Select the "JLink driver", and next, this should now show the Segger driver in device manager.



Thank you very much, after several false starts I finally got a J-Link SWD download of blink  :D :D

After getting the correct Segger driver, I used the Armel Studion 7: tools> device programmer. screen shots attached in the following posts.


AtmelStudio7_DeviceProgrammingPG1.png ( 41 KB | 10 Downloads )
AtmelStudio7_DeviceProgrammingPG2.png ( 52 KB | 2 Downloads )

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 23rd, 2021 at 9:03pm
Pages 3,4


AtmelStudio7_DeviceProgrammingPG3.png ( 66 KB | 2 Downloads )
AtmelStudio7_DeviceProgrammingPG4.png ( 55 KB | 3 Downloads )

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 23rd, 2021 at 9:03pm
pages 5,6
AtmelStudio7_DeviceProgrammingPG5.png ( 72 KB | 5 Downloads )
AtmelStudio7_DeviceProgrammingPG6.png ( 50 KB | 1 Download )

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 23rd, 2021 at 9:06pm
Finally, I used removed the "Erase Flash before programming" flag and hit "Program".

In the status window, you can see it worked.

Now what? Should this not work in Visual Studio with Visual Micro over the other driver?

Preliminary conclusion.

1.) There is apparently nothing physically wrong with the device.

2.) The Adafruit boot loader is hosedead because it will not respond to the USB I/F chip when Win7 is trying to load its drivers.

3.) At this point, I should probably reburn the boot loader but will wait for advice as I only have the two of them in this state.

I'm moving to ESP32 now and will be dropping the adafuit stuff so this is more for getting the J-Link to work within Visual studio to enhance bebugging.
AtmelStudio7_DeviceProgrammingProgramBinkerSucessful.png ( 56 KB | 1 Download )

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 23rd, 2021 at 10:17pm
I am cross-posting between the Adafruit forum and this one. The directions for using Atmel Studio are shown below (at the adafruit website) along with my post.


I had some success today with the help of the Visual Micro forum tech support. I was able to resurrect my 2017 copy of Atmel Studio 7 running under Win7 and enable the Segger J-Link download under Atmel Studio 7: tools>device programmer. .

I did follow the direction here for setting up JTAG SWD support on the feather M0.
https://learn.adafruit.com/how-to-progr ... -m4-wiring

It turns out the directions for doing setting up Atmel Studio are located here (now I find them).
https://learn.adafruit.com/how-to-progr ... mel-studio

As I look at these detailed instructions I can only imagine I'm not the first person to Brick their Feather M0's .

Title: Re: MSVS 2019 + Adafruit Feather M0 + J-Link
Post by J Moore on Jun 23rd, 2021 at 11:45pm
I have gone back and reprogrammed the BootLoader in Flash according to the instructions at AdaFruit using J-Link. These directions seem old but generally work.

I have also reprogrammed the Blink program using J-Link as well.

However, there seems to be something (buggy) fragile in the integration. This is a brief summary of one set of observations. This is generally what is happening because there seem to be so many paths through this maze I may not have it quite right.

For example, after burning the boot loader, the feather M0 was detected by windows and a virtual comm port (59) was loaded. Then I used the arduino IDE to download through that comm port 59 and and during the startup process another driver 62 got installed.

Arduino show both 59 and 62 but with the feather on the port 62. But then you try to run the Serial monitor and even through I have selected 62 it tries on 59 and says nothing is there.

What is crazy is now that port 59 has been installed once (after the boot loader burn), it now is persistent across restarts of the Arduino IDE even though it does not exist in windows.

This is the kind of crazy stuff that drives you away from the Arduin com port loaders.

At this point, I have tried multiple boot loader downloads and I either get a failure to load the device drives in windows and now I'm having check sum errors in the download.

I think this device is sufficiently screwed up to give up on it. I'm still interested in why the J-Link over OpenOCB (VisualMicro) is unable to talk at all to the Feather M0.

When this reaches a road block or point of diminishing, I'll configure the ESP32 for Jtag SWD and drop the Feathers.
AtmelStudioChecksumFail.png ( 22 KB | 2 Downloads )
ArduinoIDEChecksumFail.png ( 9 KB | 2 Downloads )

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.