mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 19:44:00 +00:00
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
This commit is contained in:
@@ -51,6 +51,7 @@ type Options struct {
|
|||||||
Directory string
|
Directory string
|
||||||
PrintJSON bool
|
PrintJSON bool
|
||||||
Monitor bool
|
Monitor bool
|
||||||
|
BaudRate int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify performs a validation on the given options, raising an error if options are not valid.
|
// Verify performs a validation on the given options, raising an error if options are not valid.
|
||||||
|
|||||||
@@ -1337,6 +1337,7 @@ func main() {
|
|||||||
llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable")
|
llvmFeatures := flag.String("llvm-features", "", "comma separated LLVM features to enable")
|
||||||
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
|
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
|
||||||
monitor := flag.Bool("monitor", false, "enable serial monitor")
|
monitor := flag.Bool("monitor", false, "enable serial monitor")
|
||||||
|
baudrate := flag.Int("baudrate", 115200, "baudrate of serial monitor")
|
||||||
|
|
||||||
var flagJSON, flagDeps, flagTest bool
|
var flagJSON, flagDeps, flagTest bool
|
||||||
if command == "help" || command == "list" || command == "info" || command == "build" {
|
if command == "help" || command == "list" || command == "info" || command == "build" {
|
||||||
@@ -1427,6 +1428,7 @@ func main() {
|
|||||||
LLVMFeatures: *llvmFeatures,
|
LLVMFeatures: *llvmFeatures,
|
||||||
PrintJSON: flagJSON,
|
PrintJSON: flagJSON,
|
||||||
Monitor: *monitor,
|
Monitor: *monitor,
|
||||||
|
BaudRate: *baudrate,
|
||||||
}
|
}
|
||||||
if *printCommands {
|
if *printCommands {
|
||||||
options.PrintCommands = printCommand
|
options.PrintCommands = printCommand
|
||||||
|
|||||||
+6
-1
@@ -32,10 +32,15 @@ func Monitor(port string, options *compileopts.Options) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
br := options.BaudRate
|
||||||
|
if br <= 0 {
|
||||||
|
br = 115200
|
||||||
|
}
|
||||||
|
|
||||||
wait = 300
|
wait = 300
|
||||||
var p serial.Port
|
var p serial.Port
|
||||||
for i := 0; i <= wait; i++ {
|
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 err != nil {
|
||||||
if i < wait {
|
if i < wait {
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|||||||
Reference in New Issue
Block a user