mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 08:23:41 +00:00
cli: add basic probe-rs support
OpenOCD can be somewhat outdated. `probe-rs` is a more modern tool written in Rust with many interesting features, like built-in RTT logging support. This commit just adds basic support, to be able to flash devices with probe-rs and debug them.
This commit is contained in:
committed by
Ron Evans
parent
906a20d3bf
commit
c698eeacba
@@ -539,7 +539,7 @@ func (c *Config) Programmer() (method, openocdInterface string) {
|
|||||||
case "openocd", "msd", "command", "adb":
|
case "openocd", "msd", "command", "adb":
|
||||||
// The -programmer flag only specifies the flash method.
|
// The -programmer flag only specifies the flash method.
|
||||||
return c.Options.Programmer, c.Target.OpenOCDInterface
|
return c.Options.Programmer, c.Target.OpenOCDInterface
|
||||||
case "bmp":
|
case "bmp", "probe-rs":
|
||||||
// The -programmer flag only specifies the flash method.
|
// The -programmer flag only specifies the flash method.
|
||||||
return c.Options.Programmer, ""
|
return c.Options.Programmer, ""
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ type TargetSpec struct {
|
|||||||
ADBPreCommands []string `json:"adb-pre-commands,omitempty"`
|
ADBPreCommands []string `json:"adb-pre-commands,omitempty"`
|
||||||
ADBPushRemote string `json:"adb-push-remote,omitempty"`
|
ADBPushRemote string `json:"adb-push-remote,omitempty"`
|
||||||
ADBPostCommands []string `json:"adb-post-commands,omitempty"`
|
ADBPostCommands []string `json:"adb-post-commands,omitempty"`
|
||||||
|
ProbeRSChip string `json:"probe-rs-chip,omitempty"`
|
||||||
CodeModel string `json:"code-model,omitempty"`
|
CodeModel string `json:"code-model,omitempty"`
|
||||||
RelocationModel string `json:"relocation-model,omitempty"`
|
RelocationModel string `json:"relocation-model,omitempty"`
|
||||||
WITPackage string `json:"wit-package,omitempty"`
|
WITPackage string `json:"wit-package,omitempty"`
|
||||||
|
|||||||
@@ -395,7 +395,7 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
|
|||||||
fileExt = filepath.Ext(config.Target.FlashFilename)
|
fileExt = filepath.Ext(config.Target.FlashFilename)
|
||||||
case "openocd":
|
case "openocd":
|
||||||
fileExt = ".hex"
|
fileExt = ".hex"
|
||||||
case "bmp":
|
case "bmp", "probe-rs":
|
||||||
fileExt = ".elf"
|
fileExt = ".elf"
|
||||||
case "adb":
|
case "adb":
|
||||||
fileExt = ".hex"
|
fileExt = ".hex"
|
||||||
@@ -535,6 +535,16 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return &commandError{"failed to flash", result.Binary, err}
|
return &commandError{"failed to flash", result.Binary, err}
|
||||||
}
|
}
|
||||||
|
case "probe-rs":
|
||||||
|
// TODO: this halts the target after flashing.
|
||||||
|
// See: https://github.com/probe-rs/probe-rs/discussions/4005
|
||||||
|
cmd := executeCommand(config.Options, "probe-rs", "download", "--chip="+config.Target.ProbeRSChip, "--verify", result.Binary)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
err = cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return &commandError{"failed to flash", result.Binary, err}
|
||||||
|
}
|
||||||
case "adb":
|
case "adb":
|
||||||
// Run pre-flash adb shell commands.
|
// Run pre-flash adb shell commands.
|
||||||
for _, preCmd := range config.Target.ADBPreCommands {
|
for _, preCmd := range config.Target.ADBPreCommands {
|
||||||
@@ -697,6 +707,21 @@ func Debug(debugger, pkgName string, ocdOutput bool, options *compileopts.Option
|
|||||||
daemon.Stdout = w
|
daemon.Stdout = w
|
||||||
daemon.Stderr = w
|
daemon.Stderr = w
|
||||||
}
|
}
|
||||||
|
case "probe-rs":
|
||||||
|
port = ":1337"
|
||||||
|
gdbCommands = append(gdbCommands, "monitor halt", "load", "monitor reset halt")
|
||||||
|
|
||||||
|
daemon = executeCommand(config.Options, "probe-rs", "gdb", "--chip="+config.Target.ProbeRSChip)
|
||||||
|
if ocdOutput {
|
||||||
|
// Make it clear which output is from the daemon.
|
||||||
|
w := &ColorWriter{
|
||||||
|
Out: colorable.NewColorableStderr(),
|
||||||
|
Prefix: "probe-rs: ",
|
||||||
|
Color: TermColorYellow,
|
||||||
|
}
|
||||||
|
daemon.Stdout = w
|
||||||
|
daemon.Stderr = w
|
||||||
|
}
|
||||||
case "jlink":
|
case "jlink":
|
||||||
port = ":2331"
|
port = ":2331"
|
||||||
gdbCommands = append(gdbCommands, "load", "monitor reset halt")
|
gdbCommands = append(gdbCommands, "load", "monitor reset halt")
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"src/device/stm32/stm32l0x1.s"
|
"src/device/stm32/stm32l0x1.s"
|
||||||
],
|
],
|
||||||
"flash-method": "openocd",
|
"flash-method": "openocd",
|
||||||
|
"probe-rs-chip": "STM32L031G6Ux",
|
||||||
"openocd-interface": "cmsis-dap",
|
"openocd-interface": "cmsis-dap",
|
||||||
"openocd-target": "stm32l0"
|
"openocd-target": "stm32l0"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user