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);
}





Saturday, June 6, 2020

Programming FPGA Devices from WSL

Today I received a DM on Twitter asking for help to program an FPGA (specifically the 1bitsquared iCEBreaker) from WSL. I realized that most of the useful information is buried in my long (and admittedly sometimes rambling) prior blogs. So this is a summary for just that topic.

The first thing to do, is plug in your device. In the case of the iCEBreaker, make sure the drivers are set to libusbk using Zadig as noted here:


Note that native USB drivers are not supported in WSL (well, WSL1, anyhow; I've not been able to install WSL2 just yet)

If after changing the drivers the board is *still* not recognized by iceprog, try unplugging, waiting a few seconds and plugging the iCEBreaker back into the USB port. I've also seen mixed results with hubs, so perhaps try connecting directly if it still does not work.

Next, make sure you have the DOS version of the programmer on the Windows filesystem. I have mine in my C:\workspace\ulx3s-toolchain\bin\ directory:



The really crazy thing about WSL, is that not only is the Windows file system available in the /mnt/ directory such as /mnt/c for c:\ ... but Windows executables can be launched from the WSL prompt as well! And of course there's plenty of native USB driver support in Windows.

Here's an example in /mnt/c/users/gojimmypi/source/repos/Verilog12/Verilog12 - a WSL directory which is C:\users\gojimmypi\source\repos\Verilog12\Verilog12 (created by Visual Studio)

Calling the DOS executable to program the iCEBreaker:


That's it!

Links:



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...