I am designing a new board using ATSAMD21E17D processor. Originally the processor was ATSAMD21E17A, but since it was out of stock I switched it for "D" variant.
I have a J-link debugger and I was able to program a simple blink example to it using "Microchip Studio for AVR and SAM Devices", to see that the processor works fine. But I want to write my programs using Arduino IDE, because of the vast and diverse software libraries that are available. In order to do so, I feel that I have the following options:
Write my codes in Arduino IDE, export the binary file, and use the exported .bin to program the processor using Microchip Studio.
I was unable to use this approach. When I export the binary (Sketch >> Export compiled Binary) , it will compile the code for selected board (Tools >> Board). None of the board that I know of use ATSAMD21E17D. There is Tau from Rabid Prototypes that use ATSAMD21E17A. I tried to upload the code for the simple blink example using a few boards such as Tau, MKRZERO, Zero, etc with no success. Microchip Studio can upload the code to the processor but nothing happens.
Write the program in Arduino IDE, then use Microchip Studio's feature: Create project from Arduino sketch
I was unable to even import the simple Blink example to Microchip Studio. I saved the original Blink example on my computer, then in Microchip Studio I selected File>>New Project>>Create project from Arduino Sketch, I selected MKRZERO (and a few other boards), and I compiled the code (I did not even change the processor). I got 54 errors (see attached file).
Well, there were a couple of more approaches that I tried without success, but my question is already getting unusually long. So I will just mention them:
I was unable to upload the SAM-BA bootloader to my board.
I was unable to create a custom board matching my processor in Arduino IDE.
Any help is much appreciated, however buying another programmer is not an option for me.
Thanks and I am terribly sorry for the long post.
I recently had a discussion about this on the forum.
For the the SMAD21E17D you'll need to burn a modified bootloader to account for the microcontroller's smaller memory compared with the SAMD21G18A used on SAMD21 Arduino boards. For this you'll require your J-Link programmer connected to the microcontroller's SWD port.
After burning the bootloader you can remove the programmer.
You'll also need to change the Arduino IDE's BOSSSA executable, in order to upload sketches over the microcontroller's native USB port. To do this you'll need to swap Arduino's "bossac.exe", for one that's compatible with the SAMD21E17D. Here's a zip file containing "bossac.exe" and instructions for that: Lower memory SAMD21 variant - #37 by MartinL.
Hi @MartinL, I uploaded the bootloader in your zip file. After the bootloader was loaded to my device, I got the error "USB device not recognized" from windows, and the port submenu in Arduino IDE is grayed out.
Just to be sure, here is my procedure in Microchip Studio: Tools>>Device Programming>>Memories>>Flash (132KB). I load your bootloader and click on Program.
Since there are only 4 pins (Vcc, GND, D+, and D-), and I already ohm-checked them, I seriously doubt that it is a connection error.
Is there a fuse-bit that I need to change in the processor?
Maybe this is caused by my previous attempts to load "bad" bootloaders into my chip and now windows cannot recognize this. I will try to find another computer and connect it to that PC to see if it is recognized.
@MartinL , thanks to you I have advanced a step, on a fresh computer, the board is recognized as a Arduino Zero after uploading your bootloader. After replacing the bossac.exe with your file, I was also able to program the board (I selected Arduino Zero - Native USB Port) and I got the following message:
Atmel SMART device 0x10010094 found
Device : ATSAMD21E17D
Chip ID : 10010094
Version : v2.0 [Arduino:XYZP] Oct 2 2021 13:30:30
Address : 8192
Pages : 1920
Page Size : 64 bytes
Total Size : 120KB
Planes : 1
Lock Regions : 16
Locked : none
Security : false
Boot Flash : true
BOD : true
BOR : true
Arduino : FAST_CHIP_ERASE
Arduino : FAST_MULTI_PAGE_WRITE
Arduino : CAN_CHECKSUM_MEMORY_BUFFER
done in 0.444 seconds
Write 11440 bytes to flash (179 pages)
[==============================] 100% (179/179 pages)
done in 0.072 seconds
Verify 11440 bytes of flash with checksum.
done in 0.011 seconds
However, the board disappears after that and the port sub-menu in Arduino is grayed out. The board is recognized again after double tapping the reset button, but my code does not seem to run. It is the simple Blink code that should turn A4 (which is pin PA05, i.e. pin number 6 of ATSAMD21E17D chip) on and off. But the pin seems to be floating and does not oscillate. Any suggestions?
@meghdadi Does your custom board have an external 32.768kHz crystal?
I configured the bootloader to operate crystalless using the microcontroller's own internal 32.768kHz oscillator. However, if the board selected in the Arduino IDE uses an external crystal (like the Arduino Zero), but your custom board doesn't have one, the sketch will stall immediately after upload.