diff --git a/compileopts/config.go b/compileopts/config.go index 1920d2b9cb..673de40f95 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -539,7 +539,7 @@ func (c *Config) Programmer() (method, openocdInterface string) { case "openocd", "msd", "command", "adb": // The -programmer flag only specifies the flash method. return c.Options.Programmer, c.Target.OpenOCDInterface - case "bmp": + case "bmp", "probe-rs": // The -programmer flag only specifies the flash method. return c.Options.Programmer, "" default: diff --git a/compileopts/target.go b/compileopts/target.go index 4e0269e6b0..0900a7ba2b 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -67,6 +67,7 @@ type TargetSpec struct { ADBPreCommands []string `json:"adb-pre-commands,omitempty"` ADBPushRemote string `json:"adb-push-remote,omitempty"` ADBPostCommands []string `json:"adb-post-commands,omitempty"` + ProbeRSChip string `json:"probe-rs-chip,omitempty"` CodeModel string `json:"code-model,omitempty"` RelocationModel string `json:"relocation-model,omitempty"` WITPackage string `json:"wit-package,omitempty"` diff --git a/main.go b/main.go index de7b060f23..29626fc6e1 100644 --- a/main.go +++ b/main.go @@ -394,7 +394,7 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error { fileExt = filepath.Ext(config.Target.FlashFilename) case "openocd": fileExt = ".hex" - case "bmp": + case "bmp", "probe-rs": fileExt = ".elf" case "adb": fileExt = ".hex" @@ -534,6 +534,16 @@ func Flash(pkgName, port, outpath string, options *compileopts.Options) error { if err != nil { 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": // Run pre-flash adb shell commands. for _, preCmd := range config.Target.ADBPreCommands { @@ -696,6 +706,21 @@ func Debug(debugger, pkgName string, ocdOutput bool, options *compileopts.Option daemon.Stdout = 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": port = ":2331" gdbCommands = append(gdbCommands, "load", "monitor reset halt") diff --git a/targets/stm32l0x1.json b/targets/stm32l0x1.json index 7f66d65895..4c150252f4 100644 --- a/targets/stm32l0x1.json +++ b/targets/stm32l0x1.json @@ -13,6 +13,7 @@ "src/device/stm32/stm32l0x1.s" ], "flash-method": "openocd", + "probe-rs-chip": "STM32L031G6Ux", "openocd-interface": "cmsis-dap", "openocd-target": "stm32l0" }