feat: llgo run -target target -port port auto start monitor
This commit is contained in:
@@ -7,7 +7,8 @@
|
|||||||
- `-file-format <format>` - Convert to specified format (**requires `-target`**)
|
- `-file-format <format>` - Convert to specified format (**requires `-target`**)
|
||||||
- Supported: `elf` (default), `bin`, `hex`, `uf2`, `zip`, `img`
|
- Supported: `elf` (default), `bin`, `hex`, `uf2`, `zip`, `img`
|
||||||
- `-emulator` - Run using emulator (auto-detects required format)
|
- `-emulator` - Run using emulator (auto-detects required format)
|
||||||
- `-port <port>` - Target port for flashing or testing
|
- `-port <port>` - Target port for flashing, testing, or monitoring
|
||||||
|
- `-baudrate <rate>` - Baudrate for serial communication (default: 115200)
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
@@ -32,6 +33,20 @@ Install program or flash to device.
|
|||||||
- No `-target`: Install to `$GOPATH/bin`
|
- No `-target`: Install to `$GOPATH/bin`
|
||||||
- With `-target`: Flash to device (use `-port` to specify port)
|
- With `-target`: Flash to device (use `-port` to specify port)
|
||||||
|
|
||||||
|
### llgo monitor
|
||||||
|
Monitor serial output from embedded device.
|
||||||
|
- `-port <device>`: Serial port device (e.g., `/dev/ttyUSB0`, `COM3`)
|
||||||
|
- `-target <platform>`: Auto-detect port from target configuration
|
||||||
|
- `-baudrate <rate>`: Communication speed (default: 115200)
|
||||||
|
- `[executable]`: Optional ELF file for debug info (panic address resolution)
|
||||||
|
|
||||||
|
Features:
|
||||||
|
- Real-time bidirectional serial communication
|
||||||
|
- Automatic port detection from target configuration
|
||||||
|
- Debug info integration for panic address resolution
|
||||||
|
- Cross-platform support (Linux, macOS, Windows)
|
||||||
|
- Graceful exit with Ctrl-C
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -43,10 +58,16 @@ llgo install hello.go # install to bin
|
|||||||
|
|
||||||
# Cross-compilation
|
# Cross-compilation
|
||||||
llgo build -target esp32 . # -> hello (ELF)
|
llgo build -target esp32 . # -> hello (ELF)
|
||||||
llgo build -target esp32 -file-format bin , # -> hello.bin
|
llgo build -target esp32 -file-format bin . # -> hello.bin
|
||||||
llgo run -target esp32 . # run on ESP32 (guess a port)
|
llgo run -target esp32 . # run on ESP32 (guess a port)
|
||||||
llgo run -target esp32 -emulator . # run in emulator
|
llgo run -target esp32 -emulator . # run in emulator
|
||||||
llgo test -target esp32 -port /dev/ttyUSB0 . # run tests on device
|
llgo test -target esp32 -port /dev/ttyUSB0 . # run tests on device
|
||||||
llgo test -target esp32 -emulator . # run tests in emulator
|
llgo test -target esp32 -emulator . # run tests in emulator
|
||||||
llgo install -target esp32 -port /dev/ttyUSB0 . # flash to specific port
|
llgo install -target esp32 -port /dev/ttyUSB0 . # flash to specific port
|
||||||
|
|
||||||
|
# Monitor device output
|
||||||
|
llgo monitor -port /dev/ttyUSB0 # monitor with specific port
|
||||||
|
llgo monitor -target esp32 # monitor with auto-detected port
|
||||||
|
llgo monitor -target esp32 -baudrate 9600 # custom baudrate
|
||||||
|
llgo monitor -port /dev/ttyUSB0 ./firmware.elf # with debug info for panic resolution
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import (
|
|||||||
"github.com/goplus/llgo/internal/firmware"
|
"github.com/goplus/llgo/internal/firmware"
|
||||||
"github.com/goplus/llgo/internal/flash"
|
"github.com/goplus/llgo/internal/flash"
|
||||||
"github.com/goplus/llgo/internal/mockable"
|
"github.com/goplus/llgo/internal/mockable"
|
||||||
|
"github.com/goplus/llgo/internal/monitor"
|
||||||
"github.com/goplus/llgo/internal/packages"
|
"github.com/goplus/llgo/internal/packages"
|
||||||
"github.com/goplus/llgo/internal/typepatch"
|
"github.com/goplus/llgo/internal/typepatch"
|
||||||
"github.com/goplus/llgo/ssa/abi"
|
"github.com/goplus/llgo/ssa/abi"
|
||||||
@@ -76,12 +77,13 @@ type Config struct {
|
|||||||
Goarch string
|
Goarch string
|
||||||
Target string // target name (e.g., "rp2040", "wasi") - takes precedence over Goos/Goarch
|
Target string // target name (e.g., "rp2040", "wasi") - takes precedence over Goos/Goarch
|
||||||
BinPath string
|
BinPath string
|
||||||
AppExt string // ".exe" on Windows, empty on Unix
|
AppExt string // ".exe" on Windows, empty on Unix
|
||||||
OutFile string // only valid for ModeBuild when len(pkgs) == 1
|
OutFile string // only valid for ModeBuild when len(pkgs) == 1
|
||||||
FileFormat string // File format override (e.g., "bin", "hex", "elf", "uf2", "zip") - takes precedence over target's default
|
FileFormat string // File format override (e.g., "bin", "hex", "elf", "uf2", "zip") - takes precedence over target's default
|
||||||
Emulator bool // only valid for ModeRun/ModeTest - run in emulator mode
|
Emulator bool // run in emulator mode
|
||||||
Port string // only valid for ModeRun/ModeTest/ModeInstall/ModeCmpTest - target port for flashing
|
Port string // target port for flashing
|
||||||
RunArgs []string // only valid for ModeRun
|
BaudRate int // baudrate for serial communication
|
||||||
|
RunArgs []string
|
||||||
Mode Mode
|
Mode Mode
|
||||||
AbiMode AbiMode
|
AbiMode AbiMode
|
||||||
GenExpect bool // only valid for ModeCmpTest
|
GenExpect bool // only valid for ModeCmpTest
|
||||||
@@ -355,6 +357,15 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
|||||||
err = runInEmulator(ctx.crossCompile.Emulator, finalApp, pkg.Dir, pkg.PkgPath, conf, mode, verbose)
|
err = runInEmulator(ctx.crossCompile.Emulator, finalApp, pkg.Dir, pkg.PkgPath, conf, mode, verbose)
|
||||||
} else {
|
} else {
|
||||||
err = flash.Flash(ctx.crossCompile, finalApp, ctx.buildConf.Port, verbose)
|
err = flash.Flash(ctx.crossCompile, finalApp, ctx.buildConf.Port, verbose)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
err = monitor.Monitor(monitor.MonitorConfig{
|
||||||
|
Port: ctx.buildConf.Port,
|
||||||
|
Target: conf.Target,
|
||||||
|
Executable: finalApp,
|
||||||
|
BaudRate: conf.BaudRate,
|
||||||
|
}, verbose)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user