Skip to content

Commit 52e982e

Browse files
bxparksdeadprogram
authored andcommitted
reference/usage/subcommands: monitor subcommand (#330)
reference/usage/subcommands: Document the `tinygo monitor` subcommand. And the `-monitor` flag on the `tinygo flash` command.
1 parent 1139661 commit 52e982e

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

content/docs/reference/usage/subcommands.md

+52-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,58 @@ Compile and link the program into a regular executable. For microcontrollers, it
3636
Run the program, either directly on the host or in an emulated environment (depending on `-target`).
3737

3838
### flash
39-
Flash the program to a microcontroller.
39+
Flash the program to a microcontroller. Some common flags are described below.
40+
41+
`-target={name}`: Specifies the type of microcontroller that is used. The `name`
42+
of the microcontroller is given on the individual pages for each board type
43+
listed under [Microcontrollers]({{<ref "../microcontrollers/">}}). For example,
44+
`arduino-nano`, `d1mini`, `xiao`.
45+
46+
`-monitor`: Start the serial monitor (see below) immediately after flashing.
47+
However, some microcontrollers need a split second or two to configure the
48+
serial port after flashing, and using the `-monitor` flag can fail because the
49+
serial monitor starts too quickly. In that case, use the `tinygo monitor`
50+
command explicitly.
51+
52+
### monitor
53+
Start the serial monitor on the serial port that is connected to the
54+
microcontroller. If there is only a single board attached to the host computer,
55+
the default values for various options should be sufficient. In other
56+
situations, particularly if you have multiple microcontrollers attached, some
57+
parameters may need to be overridden using the following flags:
58+
59+
`-port={port}`: If there are multiple microcontroller attached, an error message
60+
will display a list of potential serial ports. The appropriate port can be
61+
specified by this flag. On Linux, the port will be something like `/dev/ttyUSB0`
62+
or `/dev/ttyACM1`. On MacOS, the port will look like `/dev/cu.usbserial-1420`.
63+
On Windows, the port will be something like `COM1` or `COM31`.
64+
65+
`-baudrate={rate}`: The default baud rate is 115200. Boards using the AVR
66+
processor (e.g. [Arduino Nano]({{<ref "../microcontrollers/arduino-nano.md">}}),
67+
[Arduino Mega 2560]({{<ref "../microcontrollers/arduino-mega2560">}})) use 9600
68+
instead.
69+
70+
`-target={name}`: If you have more than one microcontrollers attached, you can
71+
sometimes just specify the target name and let `tinygo monitor` figure out the
72+
port. Sometimes, this does not work and you have to explicitly use the `-port`
73+
flag.
74+
75+
The serial monitor intercepts several control characters for its own use instead
76+
of sending them to the microcontroller:
77+
78+
* Control-C: terminates the `tinygo monitor`
79+
* Control-Z: suspends the `tinygo monitor` and drops back into shell
80+
* Control-\\: terminates the `tinygo monitor` with a stack trace
81+
* Control-S: flow control, suspends output to the console
82+
* Control-Q: flow control, resumes output to the console
83+
* Control-@: thrown away by `tinygo monitor`
84+
85+
**Note**: If you are using `os.Stdin` on the microcontroller, you may find that
86+
a CR character on the host computer (also known as Enter, `^M`, or `\r`) is
87+
transmitted to the microcontroller without conversion, so `os.Stdin` returns a
88+
`\r` character instead of the expected `\n` (also known as `^J`, NL, or LF) to
89+
indicate end-of-line. You may be able to get around this problem by hitting
90+
`Control-J` in `tinygo monitor` to transmit the `\n` end-of-line character.
4091

4192
### gdb
4293
Compile the program, optionally flash it to a microcontroller if it is a remote target, and drop into a GDB shell. From there you can set breakpoints, start the program with `run` or `continue` (`run` for a local program, `continue` for on-chip debugging), single-step, show a backtrace, break and resume the program with Ctrl-C/`continue`, etc. You may need to install extra tools (like `openocd` and `arm-none-eabi-gdb`) to be able to do this. Also, you may need a dedicated debugger to be able to debug certain boards if no debugger is integrated. Some boards (like the BBC micro:bit and most professional evaluation boards) have an integrated debugger.

0 commit comments

Comments
 (0)