Apologies in advance for asking any stupid questions
I want to burn a boot loader on to a custom SAMD21-based board that I've made via JLCPCB, and I don't know how to do it - I'm OS X-based, can run Windows on a Macbook Pro if necessary.
I did some prep work for this project with Arduino Pro Micro and Adafruit Trinket M0 boards, and for my hopefully-final hardware have combined the Trinket M0 design with the handful of other necessary components. But I can't yet program the custom boards as my work with the Pro Micros and Trinkets has used the USB port (yup, there is a USB port on the custom boards) and I understand I need to burn a bootloader first (as per Overview | How to Program SAMD Bootloaders | Adafruit Learning System). The custom boards have SWC and SWD pads, as I knew about the bootloader thing going in.
Question 1. Will my substitute programmer do the job of making a laptop talk to my custom board, or do I need that J-Link EDU Mini?
Question 2. Is there a good reference for doing this kind of thing for OS X users?
Question 3. If that programmer will work, can I use Atmel Studio 7 as per Adafruit notes for the Segger, or do I need something else? (And if so, what?)
I don't have any experience with this programmer, but I do with a different CMSIS-DAP compliant programmer. So if it really is CMSIS-DAP compliant (and I believe it is), your programmer should work perfectly well just as mine does.
I'm sure you can, but if you don't need the bloated Atmel Studio for any other purposes, I would start by seeing if you can use the Arduino IDE (or Arduino CLI if you don't like the IDE) instead.
The question is: which bootloader do you want to use on your board? The tutorial you linked to is focused on the UF2 bootloader that is used by the CircuitPython crowd. This is likely why they don't mention the Arduino IDE, since CircuitPython people are not using the Arduino IDE. But if you are wanting to use your board with Arduino/C++ sketches, then the Arduino IDE will provide the bootloader you want.
To answer your question, I don't honestly know what bootloader I want/need, but from what you write I assume that whatever bootloader the Arduino IDE would provide would work perfectly well. I want whatever bootloader will allow me to simply plug a USB cable into my new boards and upload a sketch as I did with the Trinket M0.
One observation: it's definitely helpful from my perspective to be able to work with OS X only. While I can run and use Windows when necessary, and have always been able to use any Windows- only software, as soon as external devices, USB, USB drivers etc come into the picture things seem to get trickier
You would presumably end up using OpenOCD, which is a multi-platform tool that is available for Mac.
I've found OpenOCD to be ... pretty opaque. It looks like instead of having commands like "upload this file to this address on this chip" you have to explicitly mention specific CMSIS-DAP commands, and the command structure makes avrdude look simple
The command that the Arduino IDE issues for "burn bootloader" on an Adafruit SAMD21 "Metro" board (which does claim to support OpenOCD as a programmer, unlike the Arduino boards) ends up looking like:
(I don't know for sure that that works, BTW, since I don't have an OpenOCD programmer and wouldn't want to actually risk a board to try it out!)
You might also want to look at Mattairtech's SAMD Core, which supports a broader range of chips (but I don't see any detailed instructions on using openOCD.)
@in0: Are you aware of of any "intermediate" OpenOCD tutorials, more detailed than an single-cpu how-to, but more coherent that a detailed description of every possible command?
No, I remain blissfully unaware of OpenOCD in general. My idea was that @zogster can just do a "Burn Bootloader" operation via the Arduino IDE, which will generate the OpenOCD command and provide the appropriate bootloader. The standard Arduino IDE procedure like described here:
The programmer definitions provided by the "Arduino SAMD (32-bits ARM Cortex-M0+) Boards" platform work just fine with the debug probe/programmer I use.
Even though they have specific names, if you check the definitions all except the J-Link are the same so it doesn't matter which of the three you pick to use with your CMSIS-DAP compliant programmer:
The situation is the same with the programmers of the "MattairTech SAM D|L|C core for Arduino" boards platform (though that platform's definitions are different from Arduino's). I don't have a lot of experience using the MattairTech platform (previously I have only used its ATSAMD11 support indirectly for the "MuxTO" firmware of the Nano Every and for the MKR/Nano Motor Carrier), I just tried a Burn Bootloader one one of my ATSAMD21G18, using the "Arduino/Genuino Zero (Autodetect Port)" board selection. It seems to work perfectly. Of course, this is a board that already had a bootloader, so perhaps not the best test.
Board connected to programmer OK… I first simply left the board selection as "Adafruit Trinket M0 (SAMD21)", under "Adafruit SAMD (32-bits ARM Cortex-M0+ and Cortex-M4) boards", noted that the two options under the Programmer menu option were "J-Link over OpenOCD" and "Atmel-ICE over OpenOCD", and just tried "Burn bootloader". Result below.
BN: Unknown board
VID: C251
PID: F001
SN: Upload any sketch to obtain it
Which I take to mean that there is indeed communication between Arduino IDE and the custom board, and that it's only software and me that are the problem.
After a more careful read of the above, I tried selecting "Arduino M0 Pro (Programming Port)" under "Adafruit SAMD (32-bits ARM Cortex-M0+) boards".
Which I take to mean that that bootloader uploaded OK. However when I unplug the programmer and plug in a USB cable, I cannot see the USB port as an option in the Arduino IDE.
Atmel-ICE is CMSIS-DAP compliant. When using the the "Arduino SAMD (32-bits ARM Cortex-M0+) Boards " platform, I had no problems using that programmer selection with my CMSIS-DAP compliant programmer.
I had the same error when I tried it with "Adafruit Trinket M0 (SAMD21)", under "Adafruit SAMD (32-bits ARM Cortex-M0+ and Cortex-M4) boards". I had my programmer connected to my computer, but nothing connected to the programmer because I only wanted to do a quick check out of curiousity without possibly doing something to my ATSAMD21G18 board.
It's just occurred to me that I could maybe upload my sketch this way if I can't get the USB port working… but will stick with Plan A for now.
I selected Atmel SAM-ICE as the option when I tried "Arduino M0 Pro (Programming Port)". (I couldn't see in my menu list the "Arduino/Genuino Zero (Autodetect Port) " you mentioned)
You can try putting the board into bootloader mode by pressing and releasing the reset button twice quickly. Then check whether you have a serial port.
The AVR boards stay constantly in bootloader mode after burning the bootloader, but I'm not sure how the SAMD behaves.
Probably because you don't have the "MattairTech SAM D|L|C core for Arduino " boards platform installed:
I actually experimented with burning an Adafruit itsybitsy m0 bootloader (for the very at91amd21g18 that you appear to be using) on openocd and got a similar result; the bootloader was programmed correctly and the verify passed, but the device wouldn't show up as a port. The problem seemed to have something to do with the clearing lockup after double fault error for me, and I ended up finding that reseting directly after the program / verify - something you can see in the image that you sent - seems to produce the problem. I had to enable bootloader protection prior to the reset for stuff to actually work with the port showing up. So if you end up using openocd, maybe try that.
All cents welcome Sean, thanks, I have c. zero cents here!
Not using OpenOCD, other than via whatever Arduino IDE is doing under the hood.
Not sure whether I'm making progress or not - still haven't been able to see the board on the USB port, but I'm assuming that I can upload a sketch the same way as the bootloader, so will try that and see where it gets me