Skip to content

Commit 9e24441

Browse files
authored
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
1 parent 1e6c14b commit 9e24441

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

compileopts/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type Options struct {
5151
Directory string
5252
PrintJSON bool
5353
Monitor bool
54+
BaudRate int
5455
}
5556

5657
// Verify performs a validation on the given options, raising an error if options are not valid.

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ func main() {
13371337
llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable")
13381338
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
13391339
monitor := flag.Bool("monitor", false, "enable serial monitor")
1340+
baudrate := flag.Int("baudrate", 115200, "baudrate of serial monitor")
13401341

13411342
var flagJSON, flagDeps, flagTest bool
13421343
if command == "help" || command == "list" || command == "info" || command == "build" {
@@ -1427,6 +1428,7 @@ func main() {
14271428
LLVMFeatures: *llvmFeatures,
14281429
PrintJSON: flagJSON,
14291430
Monitor: *monitor,
1431+
BaudRate: *baudrate,
14301432
}
14311433
if *printCommands {
14321434
options.PrintCommands = printCommand

monitor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ func Monitor(port string, options *compileopts.Options) error {
3232
break
3333
}
3434

35+
br := options.BaudRate
36+
if br <= 0 {
37+
br = 115200
38+
}
39+
3540
wait = 300
3641
var p serial.Port
3742
for i := 0; i <= wait; i++ {
38-
p, err = serial.Open(port, &serial.Mode{})
43+
p, err = serial.Open(port, &serial.Mode{BaudRate: br})
3944
if err != nil {
4045
if i < wait {
4146
time.Sleep(10 * time.Millisecond)

0 commit comments

Comments
 (0)