Unbrick Nano 33 IoT

Note: alternative methods are described at the end of the post.

Using an Arduino board as the programmer

You'll need

  • An extra Arduino board that runs at 3.3 V to use as the programmer.
    • Note: certain Arduino boards can't be used with the sketch that converts it to a programmer.
      • Working: SAMD architecture boards (e.g., MKR boards, Nano 33 IoT, Zero).
      • Untested: AVR architecture boards (e.g., Mega), but the sketch does compile for them.
      • Not working: Nano 33 BLE
    • It is possible to use an Arduino board that runs at 5 V as the programmer, but you'll need to use level shifting circuitry on the programming lines to avoid exposing the target board to 5 V logic levels, which would damage it.
  • An SD slot. This could be built into your Arduino board (e.g., MKR Zero), a shield (e.g., MKR SD Proto Shield), or one of the common SD modules.
  • An SD card that fits your SD slot.
  • A way to connect the SD card to your computer.
  • A way to make the connections to the SWD pins on your target Arduino board. For the Nano 33 IoT and the MKR Boards other than MKR1000, I like to use a 0.1" pitch 2x3 POGO adapter. You could also solder wires to the test points if you prefer. On the MKR boards other than the MKR1000, the SWD header is on the bottom of the board and is the footprint for a 0.1" pitch 2x3 SMD header (e.g., https://www.digikey.com/short/z3dvdv). On the MKR1000, it is a 0.05" pitch 2x5 male header on the top of the board, which you will need an adapter and cable for.

Instructions

  1. Connect an SD card to your computer.

  2. Open this link in your browser: https://github.com/arduino/ArduinoCore-samd/tree/master/bootloaders

  3. Click the folder that matches the name of your target board.

  4. Click the file that ends in .bin

  5. Click the Download button.

  6. Rename the downloaded file to fw.bin

  7. Move fw.bin to the SD card.

  8. Eject the SD card from your computer.

  9. Plug the USB cable of the Arduino board you will be using as a programmer into your computer.

  10. Select Sketch > Include Library > Manage Libraries... from the Arduino IDE's menus.

  11. Wait for the download to finish.

  12. In the "Filter your search..." field, type "Adafruit DAP library".

  13. Press Enter.

  14. Click on "Adafruit DAP library by Adafruit".

  15. Click the "Install" button.

  16. Wait for the installation to finish.

  17. Click the Close button.

  18. Select File > Examples > Adafruit DAP library > samd21 > flash_from_SD from the Arduino IDE's menus.

  19. Change this line:

    #define SD_CS 4
    

    according to the Arduino pin connected to the SD CS pin. If your board has a built-in SD slot (e.g., MKR Zero), then you can change this line:

    if (!SD.begin(SD_CS)) {
    

    to:

    if (!SD.begin()) {
    
  20. Select the correct board from the Tools > Board from the Arduino IDE's menus.

  21. Select the correct port from the Tools > Port from the Arduino IDE's menus.

  22. Select Sketch > Upload from the Arduino IDE's menus.

  23. Wait for the upload to finish successfully.

  24. Unplug the programmer Arduino board from your computer.

  25. Plug the SD card into the SD slot connected to your Arduino board.

  26. Connect the programmer Arduino board to the target Arduino board as follows:

    Programmer Target
    VCC +3V3
    10 SWDIO
    9 SWCLK
    GND GND
    11 RESETN

    SWD pads on MKR boards other than MKR 1000):


    MKR1000 SWD header pinout:

    Nano 33 IoT SWD pads:

  27. Plug the USB cable of the programmer Arduino board into your computer.

  28. Select Tools > Serial Monitor from the Arduino IDE's menus. You should now see the Serial Monitor output showing the target board detected, and the bootloader file flashed to it successfully.

  29. Unplug the programmer Arduino board from your computer.

  30. Disconnect the programmer Arduino board from the target Arduino board.


Alternatives

These are some alternatives to the "Adafruit DAP" method I described above.

Using a CMSIS-DAP debug probe as the programmer

If you have a CMSIS-DAP compliant debug probe, you can just do this instead:

  1. Connect the debug probe to your Arduino board.
  2. Select Tools > Programmer > Atmel EDBG from the Arduino IDE's menus.
  3. Select Tools > Burn Bootloader from the Arduino IDE's menus. - The "Burn Bootloader" process should now finish successfully.

I use this little open source debugger.


Using a J-Link as the programmer

Segger J-Link debug probes (e.g., J-Link EDU Mini) can be used with the Adalink software:
https://github.com/adafruit/Adafruit_Adalink

This is a fairly complex procedure, so I recommend against this option unless you already own a J-Link and don't have the supplies on hand for one of the other options.