liveBook · Manning

Flashing

As explained in Learn Go with Pocket-Sized Projects

Flashing is the process of deploying a compiled executable to a programmable hardware device's persistent memory.

Flashing deploys a TinyGo program to a microcontroller so it becomes the program the device runs. It is the step that takes a compiled hardware application from the computer to the board. You can try the same workflow first with a virtual board in the TinyGo playground. section 12.3.3 section 12.3

Try a blinking LED before using hardware

Select an Arduino Nano 33 IoT at https://play.tinygo.org, paste a program that configures machine.LED as machine.PinOutput and repeatedly calls High(), sleeps, calls Low(), and sleeps again. Click Flash and watch the virtual orange LED blink. Changing to a Phytec reel board provides a useful check: this program will not blink there because machine.LED is not defined for that platform. section 12.3.1

To flash a physical Arduino Nano 33 IoT:

  • Connect the board to the computer by USB. section 12.3.3
  • Find its port: try `ls /dev/ttyUSB* /dev/ttyACM*` on Linux or `ls /dev/tty.*` on macOS; on Windows, inspect Ports (COM & LPT) in Device Manager. section 12.3.3
  • Run `tinygo flash -target=arduino-nano33 -port=/dev/ttyUSB0`, replacing the example port with the one you found. The target option handles the required build tags. section 12.3.3
Listing 12.23 targets/arduino-nano33.json: Target specifications
{
    "inherits": ["atsamd21g18a"], #1
    "build-tags": ["arduino_nano33"], #2
    "flash-command": "bossac -i -e -w -v -R -U --port={port} #3
        --offset=0x2000 {bin}",  #3
    "serial-port": ["acm:2341:8057", "acm:2341:0057"],  #3
    "flash-1200-bps-reset": "true"  #3
}

The Arduino Nano 33 IoT target specification shows why selecting a target matters: it supplies build tags, serial-port identifiers, a reset setting, and a flash command. section 12.3.1

After flashing, the board runs the newly deployed program. Unplugging it and supplying power elsewhere makes it run that program again. For an LED application, an internal LED may blink during flashing; check the program’s behavior afterward rather than treating that blink as its output. section 12.3.3

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Provides playground and USB-board procedures, port-discovery commands, and a target-specific flash command; leaves low-level flashing mechanics to the target specification.
Examples
Uses a virtual blinking Arduino Nano 33 IoT LED and a `tinygo flash` command for a USB-connected board.
What it assumes
Assumes a TinyGo program; offers a virtual playground when no microcontroller is available and gives port-finding instructions for physical deployment.
What you can do after
Operate/configure it by finding a board’s port, selecting its TinyGo target, and flashing a program that runs after reconnection to power.
How it connects
Connects TinyGo targets, build tags, serial ports, microcontrollers, and GPIO-controlled LEDs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.