Skip to content

Commit c698eea

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent 906a20d commit c698eea

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

compileopts/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ func (c *Config) Programmer() (method, openocdInterface string) {
539539
case "openocd", "msd", "command", "adb":
540540
// The -programmer flag only specifies the flash method.
541541
return c.Options.Programmer, c.Target.OpenOCDInterface
542-
case "bmp":
542+
case "bmp", "probe-rs":
543543
// The -programmer flag only specifies the flash method.
544544
return c.Options.Programmer, ""
545545
default:

compileopts/target.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type TargetSpec struct {
6767
ADBPreCommands []string `json:"adb-pre-commands,omitempty"`
6868
ADBPushRemote string `json:"adb-push-remote,omitempty"`
6969
ADBPostCommands []string `json:"adb-post-commands,omitempty"`
70+
ProbeRSChip string `json:"probe-rs-chip,omitempty"`
7071
CodeModel string `json:"code-model,omitempty"`
7172
RelocationModel string `json:"relocation-model,omitempty"`
7273
WITPackage string `json:"wit-package,omitempty"`

main.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
395395
fileExt = filepath.Ext(config.Target.FlashFilename)
396396
case "openocd":
397397
fileExt = ".hex"
398-
case "bmp":
398+
case "bmp", "probe-rs":
399399
fileExt = ".elf"
400400
case "adb":
401401
fileExt = ".hex"
@@ -535,6 +535,16 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error {
535535
if err != nil {
536536
return &commandError{"failed to flash", result.Binary, err}
537537
}
538+
case "probe-rs":
539+
// TODO: this halts the target after flashing.
540+
// See: https://github.com/probe-rs/probe-rs/discussions/4005
541+
cmd := executeCommand(config.Options, "probe-rs", "download", "--chip="+config.Target.ProbeRSChip, "--verify", result.Binary)
542+
cmd.Stdout = os.Stdout
543+
cmd.Stderr = os.Stderr
544+
err = cmd.Run()
545+
if err != nil {
546+
return &commandError{"failed to flash", result.Binary, err}
547+
}
538548
case "adb":
539549
// Run pre-flash adb shell commands.
540550
for _, preCmd := range config.Target.ADBPreCommands {
@@ -697,6 +707,21 @@ func Debug(debugger, pkgName string, ocdOutput bool, options *compileopts.Option
697707
daemon.Stdout = w
698708
daemon.Stderr = w
699709
}
710+
case "probe-rs":
711+
port = ":1337"
712+
gdbCommands = append(gdbCommands, "monitor halt", "load", "monitor reset halt")
713+
714+
daemon = executeCommand(config.Options, "probe-rs", "gdb", "--chip="+config.Target.ProbeRSChip)
715+
if ocdOutput {
716+
// Make it clear which output is from the daemon.
717+
w := &ColorWriter{
718+
Out: colorable.NewColorableStderr(),
719+
Prefix: "probe-rs: ",
720+
Color: TermColorYellow,
721+
}
722+
daemon.Stdout = w
723+
daemon.Stderr = w
724+
}
700725
case "jlink":
701726
port = ":2331"
702727
gdbCommands = append(gdbCommands, "load", "monitor reset halt")

targets/stm32l0x1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"src/device/stm32/stm32l0x1.s"
1414
],
1515
"flash-method": "openocd",
16+
"probe-rs-chip": "STM32L031G6Ux",
1617
"openocd-interface": "cmsis-dap",
1718
"openocd-target": "stm32l0"
1819
}

0 commit comments

Comments
 (0)