Showing posts with label Mkr-WiFi-1010. Show all posts
Showing posts with label Mkr-WiFi-1010. Show all posts

Friday, June 12, 2020

Arduino MKR WiFI 1010 Burning Bootloader from Visual Studio with Atmel Ice

The last time I used my Arduino MKR WIFI 1010 was way back when I wrote a blog about SWD Debugging the Arduino MKR-WiFi-1010 with Atmel ICE. I was at least kind enough to leave myself a note that once the Microchip Atmel Ice was used, the bootloader would need to be burned again to program the board over the serial port. Unfortunately the link was not very helpful. Perhaps the contents changed. In any case, I was not able to use the Ardunio IDE to burn the bootloader.

Wow, I tried searching the Arduino forums, and some of the folks there are pretty harsh with people asking simple questions. Either the answer to them was "don't burn the bootloader" or "read the fine manual". I didn't even bother asking. Instead I'm posting this solution, as yes, sometimes you really do need to burn the bootloader, and yes, I did RTFM (and still didn't find what I was looking for).

My prior blog includes all the pics on connections and such. The only thing needed is this information on how to burn the bootloader from within Visual Studio using the Visual Micro Arduino Extension. Once the Atmel ICE is connected, a fresh bootloader is just a couple of clicks away:


Menu selection for burning a fresh bootloader on the Arduino MKR Wi-Fi 1010 Board
A successful load should have an output like this:

Burning a new bootloader
Burning bootloader to board 'Arduino MKR WiFi 1010' using 'Atmel-ICE'
Erase Pattern: 
Bootloader Pattern: "{path}/{cmd}" {bootloader.verbose} -s "{path}/share/openocd/scripts/" -f "{runtime.platform.path}/variants/{build.variant}/{build.openocdscript}" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{{runtime.platform.path}/bootloaders/{bootloader.file}}} verify reset; shutdown"
C:\Users\gojimmypi\AppData\Local\arduino15\packages\arduino\tools\openocd\0.9.0-arduino6-static\bin\openocd.exe -d2 -s "C:\Users\gojimmypi\AppData\Local\arduino15\packages\arduino\tools\openocd\0.9.0-arduino6-static/share/openocd/scripts/" -f "C:\Users\gojimmypi\AppData\Local\arduino15\packages\arduino\hardware\samd\1.6.20/variants/mkrwifi1010/openocd_scripts/arduino_zero.cfg" -c "telnet_port disabled; init; halt; at91samd bootloader 0; program {{C:\Users\gojimmypi\AppData\Local\arduino15\packages\arduino\hardware\samd\1.6.20/bootloaders/mkrwifi1010/samd21_sam_ba_arduino_mkrwifi1010.bin}} verify reset; shutdown"
Open On-Chip Debugger 0.9.0-g932ec70 (2017-02-15-12:34)
Licensed under GNU GPL v2
For bug reports, read
 http://openocd.org/doc/doxygen/bugs.html
debug_level: 2
Info : only one transport option; autoselect 'swd'
adapter speed: 500 kHz
adapter_nsrst_delay: 100
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 01.27.0082
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : SWD IDCODE 0x0bc11477
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x81000000 pc: 0x00004aac msp: 0x20007fa8
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x81000000 pc: 0x00000b80 msp: 0x20007ffc
** Programming Started **
auto erase enabled
Info : SAMD: partitioning the first flash page into 8 subpages
Info : SAMD MCU: SAMD21G18A (256KB Flash, 32KB RAM)
wrote 8192 bytes from file C:\Users\gojimmypi\AppData\Local\arduino15\packages\arduino\hardware\samd\1.6.20/bootloaders/mkrwifi1010/samd21_sam_ba_arduino_mkrwifi1010.bin in 0.869252s (9.203 KiB/s)
** Programming Finished **
** Verify Started **
verified 7992 bytes in 0.676364s (11.539 KiB/s)
** Verified OK **
** Resetting Target **
Done burning bootloader.
Burn complete
shutdown command invoked


That's it! Once the bootloader has been installed, the MKR WiFI 1010 can once again be programmed over the serial port.

If problems are encountered while programming, try pressing the reset button on the board. Keep in mind that this causes the USB device to go away and come back. So if there's a VM Workstation running, there may be a prompt to connect the "new" device to host or virtual machine. The delay in answering that can also cause programming to fail.

Edit: If any problems are encountered seeing the device as a serial port after developing with the Atmel ICE, try loading up a blank program in release mode with the Atmel Studio and then burning the bootloader fresh:


/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>

/*End of auto generated code by Atmel studio */

//Beginning of Auto generated function prototypes by Atmel Studio
//End of Auto generated function prototypes by Atmel Studio

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(1000);
}





Sunday, December 30, 2018

Favorite Gizmos of 2018

As the end of 2018 approaches, I thought it might be nice to share a list of some of my favorite electronic gizmos. In no particular order:

It's difficult to have any gizmo list without the Raspberry Pi being listed. So voila, let's move on.

One of my favorite gizmos is the DPS5015. In and of itself, perhaps not super interesting: your basic Programmable Supply Power Module. However it was the first commercial product that I "re-purposed" and learned a lot of hardware hacking as noted in my blog from 2017.



I think some of the most amazing devices are the SDR gizmos, such as the NooElec NESDR Smart Bundle on Amazon. (On my wish list is the Lime Micro SDR). Last year I wrote a blog on streaming SDR information directly to an OpenWRT router. I also used my SDR during development of my LoRa button-pushing project (see below).

Also cool, although also not new for 2018 - is the M5Stack series of ESP32 modules, complete with enclosure and display.

I wrote a blog about the M5Stack LoRa range, as well as a blog about my LoRa-GPIO project (pushing a button from afar). A prototype M5Stack that had both an AVR and ESP32 device turned out to be quite the educational experience as noted in my Serial Port Debugging blog, featuring the Rigol Oscilloscope Protocol Decoder. (see also Dave's EEVBlog Review of the DS1054z)

Early in the year, I bought an inexpensive Altera Cyclone IV EP4CE6 FPGA Development Kit and wrote a blog about it. This was my first experience with FPGA and proprietary tools (Quartus).

Cyclone IV FPGA Dev Board
I think one of the most significant new gizmos of the year was Luke's tinyFGPA BX. Be sure to follow @tinyFPGA on twitter. Learning to program an FPGA is something that I've been wanting to do for a long time. Luke - along with a bunch of other FOSS advocates, such as FPGAwars - have finally made it easy and inexpensive for the newbie. There's some really great BX getting started information. One of the coolest FPGA programmers has got to be Icestudio.

Late in the year, [@esden] introduced another cool FPGA device on Crowd Supply called iCEBreaker. Some folks lucky enough to attend conferences have been able to obtain theirs... others (including me) will not have them until delivered until next summer.

Finally - at the very end of the year, there's also the Fomu Crowd Supply project - An FPGA board that fits inside your USB port! (also due next year)

There's an excellent web-based Verilog editor and simulator online from the folks at 8-bit workshop. Be sure to check out their new book Designing Video Game Hardware in Verilog, as well.

Once I get a handle on FPGA programming, I plan to do something with this AD/DA board I found on ebay. (using AD9280 & AD9708)

At the very end of the year, I found the XGecu TL866II Plus USB Programmer from the XG Autoelectric folks (see also xgecu.com), thanks to @tinycompblabla.  At only about 50 bucks, it is considerably less expensive than something like the elnec or dataman. I'm looking forward to receiving it in January.

On the topic of component testers, is the AVR-based M328 Transistor Tester project. (source code here). This is really a quite clever device that automatically detects what component is connected, then indicates whether it is good or not. For things such as transistors, basic key characteristics such as gain and Vbe are displayed.


M328 Transistor / Component Tester

See also the ISP pins in case you want to get creative with your transistor tester.

One of the cool gizmos that I recently purchased is the Arduino MKR WiFi 1010 (also available from Amazon). Atmel SAMD21, ESP32 WiFi, ECC508 Crypto-Authentication, all in one place! This gizmo is so cool, I wrote an entire blog about SWD programming the Arduino MKR WiFi 1010 with the Atmel ICE.
Atmel ICE and MKR WiFi 1010
In the Fall of 2018, I found this cool SPIdriver dev board on Crowd Supply. This too, was so cool that I wrote an SPIdriver blog about it. Note that the same guy has an upcoming and similar I2C driver project, as well - that looks just as cool.

Although perhaps not a gizmo in the pure electronic sense... I did buy myself an inexpensive 3018 Pro CNC machine - as CNC programming is also something I've always wanted to learn. I need to get my thoughts together and put all that information in a blog entry soon. Stay tuned.

This blog is still a work in progress... if you think of any gizmos that I should look at and perhaps add to this list, let me know via twitter or @ gmail.

Wishing everyone health and prosperity in the coming new year.

Cheers.




Sunday, December 9, 2018

SWD Debugging the Arduino MKR-WiFi-1010 with Atmel ICE

Over the weekend I received my new Arduino MKR-WiFi-1010 (the ABX00023) that I purchased from Amazon, as seen here along with my Atmel ICE:


Warning: after writing this blog I realized that using the Atmel ICE can end up causing problems with the bootloader when later attempting to upload a sketch via the serial port! This was easily resolved (everything is easy, when you know how), but beware.

Update: I wrote this blog on Burning Bootloader from Visual Studio with Atmel Ice for the Arduino MKR WiFI 1010.

Ironically, I found this board shortly after commenting to Peter Scargil that I really didn't think anything could replace the Espressif ESP8266 (other than the ESP32) since it has been around for so long and has such a strong community and momentum. I found the 1010 shortly after seeing a tweet from MicroChip regarding the ATMega4809. (an 8-bit Arduino, 16MHz ceramic resonator, WiFi board using the ECC608 Crypto-Authentication chip for $44.90). The MKR1010 (32 bit!) was listed as "related product".  Now, I knew the MKR-1010 board had been released some time ago - but at the time I seem to think it was rather expensive and didn't think much more about it. However at $29.90 - that's just too appealing to pass up. Amazon prime to the rescue for me gizmo addiction: delivered the next day at no extra change! Thank you Prime!

It has been some time since my last blog post. I have a draft blog of some things that I learned with my new CNC, but it is rather messy at the moment, so instead this weekend I am back to debuggers and this MKR-1010 board.

One of the main points of interest with this board - is that in addition to the SAMD21 (specifically the ATSAMD21G18A) it also has an on-board ESP32 ... and the MicroChip ECC508 Crypto-Authentication chip! Although I really like the ESP8266 boards, I will say that JTAG debugging was not exactly the easiest and most robust, as noted here and here. One thing about the Atmel ICE is that in Atmel Studio, it is a fairly robust and reliable hardware debugger.

So fresh out of the gate, I was disappointed that I did not have a cable for (what I thought) was the Single Wire Debug (aka SWD) connector:

Comparing a 50 mil connector to what I thought was the SWD connector.

Note that black connector not a 0.1 pin spacing, it is already the small 50 mil connector that is on the Atmel ICE. The white connector below is even smaller than that!

I spent an embarrassingly long time scouring the internet for anything I could find on "Arduino MKR 1010 SWD Debugging Connector". I could not even determine what that tiny white connector is called so that I could order one. I even posted a plea for help on the Arduino MKRWiFi1010 forum,

Eventually, I found this post where someone was asking about connecting the Atmel ICE SWD to the MKR-ZERO. Although I had no indication the 6 pads on the underside of my MKR-1010 were actually the J2 SWD pins, I was hopeful that the folks at Arduino would have standards and consistency.

Schematic diagram for MKR-1010 SWD Connector (pads on reverse)

The Maker Zero SWD pins are as shown here, in this diagram provided by Federico_Vanzati:

MKR-Zero SWD Pins for Atmel ICE
Keep in mind I had no experience, no knowledge of the MKR-Zero, however the MKR WiFi 101 is just a bit similar, once you see them both, eh?
MKR-1010 board from the Arduino site
So although I was confident and hopeful that I could finally get the Atmel ICE to connect, I was still stuck with 6 pads and no holes. I really wish the Arduino folks would have made a more debug-friendly connector.

Fortunately, I had some of those snap-apart headers on hand. I bent two sets of 3 pins...


Header with some pins bent for the surface-mount SWD pads.

...and stuck them both into a 6-pin cable connector to hold them in the proper position for soldering:

Preparing the home-made surface mount headers in a 6 pin connector.

Be sure that the longer header pin is not pulled through when bending them: Not only do you want to have a good length for electrical contact, but you also don't want them too long on the PCB. Yes, there's a solder mask layer that should act as an insulator, but I would not count on it.  Make sure that pins are only as long as the solder pads. I needed to trim mine.

Note that using sets of three will increase overall mechanical strength - but as they are surface mounted, care should be taken when inserting & removing connections.

So the reality of annoying future breadboard use becomes quite apparent once the header is soldered in place. Clearly the designer prioritized the Arduino logo over the practicality of pad header placement:

My MKR-WiFi-1010 SWD Header Connection, freshly soldered on

I'm thinking if I plug it into a breadboard, I'll just use some of those stackable headers. Still, this will leave many more mechanical connections and many more places for connection problems.

From the MicroChip / Atmel ICE docs - these are the pins used for SWD on the SAMD21 chips:

SAMD Pins for SWD Debugging with Atmel ICE (from the User Guide)
Upon reading the pinouts and looking at the cables and adapters that I have for the Atmel ICE, I realized that my only option was to use that handy-but-annoying Squid Cable.

Arduino MKR WiFi 1010 with SWD Atmel ICE Pin Numbers shown.

Here's what the board looks like connected to the Atmel ICE:

Arduino MKR-WiFi 1010 connected to Atmel ICE with the Squid Cable.

I sure wish a simple 10-pin header would have been installed on the MKR boards - that would connect directly to the Atmel ICE debugger. Well, no worries.. good to go!

There's a MKR-Wifi-1010 tutorial on actually using the WiFi here on GitHub. I actually used the WiFi tutorial page to get started. I took the ino file and pasted it into the Arduino IDE and compiled to ensure everything was working properly. Then I created a new Atmel Studio project from the ino.
Atmel Studio setup step 1.

And on the next screen, select the location of the ino project from the Arduino IDE:

Atmel Studio setup step 2.

Edit Feb 2019: If you don't see the board listed, then launch the Arduino IDE and ensure it is installed via Tools - Board - Board Manager:


Type "MKR" to shorten the list:


/Edit... back  to Atmel Studio:

Connection in Atmel Studio is pretty straightforward, just select the Atmel ICE and ensure "SWD" is used:

Atmel Studio SWD Debugger Settings for Atmel ICE
After that... voila! Click the Debug menu and step in, set breakpoints, and more!


One thing that is not super obvious when debugging with the Atmel ICE, is most sample code is "wait forever until serial port available" during setup. Well, the Atmel ICE is not the serial port!


  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


So be sure to connect something to the serial port! The serial monitor in Atmel Studio is a bit wonky. I simply use putty.

See the Disassembly tab to view the assembly language generated from the source code:


The Processor button show interesting information:


Also cool to browse and inspect I/O registers:


This is SO much better than a zillion serial.println statements!

Well, I hope this saves you the hassle I encountered when trying to use the Atmel ICE hardware debugger with the Arduino MKR-WiFi 1010.

I've added a MKR-WiFi-1010 GitHub Repository with the source code and relevant pictures and documentation.

So ya, perhaps this Arduino will take over the Espressif chips ... but as there's an Espressif on-board this guy, perhaps that's not a fair comparison. Still - it is a quite interesting board at a somewhat reasonable price.

Resources, Inspiration, Credits, and Other Links:


Please leave comments, ideas, suggestions below (moderated, sometimes delayed) or send me a message at gmail, or find me on twitter.

Find gojimmypi at gojimmypi.github.io

I'm currently working on my new blog home at  gojimmypi.github.io After implementing a variety of features such as dark mode , syntax hi...