From 9e2444197826290f1d774a5c0f6be9802afab2f6 Mon Sep 17 00:00:00 2001 From: sago35 Date: Sun, 25 Sep 2022 02:09:41 +0900 Subject: [PATCH] main: allow setting the baud rate for serial monitors (#3190) * main: allow setting the baud rate for serial monitors with default baudrate of 115200 bps --- compileopts/options.go | 1 + main.go | 2 ++ monitor.go | 7 ++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/compileopts/options.go b/compileopts/options.go index d70c4c05..a7b98e5c 100644 --- a/compileopts/options.go +++ b/compileopts/options.go @@ -51,6 +51,7 @@ type Options struct { Directory string PrintJSON bool Monitor bool + BaudRate int } // Verify performs a validation on the given options, raising an error if options are not valid. diff --git a/main.go b/main.go index 01e20977..67b449dc 100644 --- a/main.go +++ b/main.go @@ -1337,6 +1337,7 @@ func main() { llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable") cpuprofile := flag.String("cpuprofile", "", "cpuprofile output") monitor := flag.Bool("monitor", false, "enable serial monitor") + baudrate := flag.Int("baudrate", 115200, "baudrate of serial monitor") var flagJSON, flagDeps, flagTest bool if command == "help" || command == "list" || command == "info" || command == "build" { @@ -1427,6 +1428,7 @@ func main() { LLVMFeatures: *llvmFeatures, PrintJSON: flagJSON, Monitor: *monitor, + BaudRate: *baudrate, } if *printCommands { options.PrintCommands = printCommand diff --git a/monitor.go b/monitor.go index ec433bb7..74f5c219 100644 --- a/monitor.go +++ b/monitor.go @@ -32,10 +32,15 @@ func Monitor(port string, options *compileopts.Options) error { break } + br := options.BaudRate + if br <= 0 { + br = 115200 + } + wait = 300 var p serial.Port for i := 0; i <= wait; i++ { - p, err = serial.Open(port, &serial.Mode{}) + p, err = serial.Open(port, &serial.Mode{BaudRate: br}) if err != nil { if i < wait { time.Sleep(10 * time.Millisecond)