Week 4-BN: free the probe (pkill/taskkill) in the Step 21 and 29 console flash snippets

Step 29's snippet had no pkill, so with the debug-server OpenOCD still attached the
flash failed with 'CMSIS-DAP command CMD_INFO failed / OpenOCD init failed'. Add the
pkill to Step 29 and both Step 21 blocks.
This commit is contained in:
Kevin Thomas committed 2026-10-03 18:19:11 -04:00
1 parent e25104a1b0
commit 0594cde63b
2 files changed
+5

No files matched your search

+5
View File
@@ -995,11 +995,14 @@ age: 70
> root = open(os.path.expanduser("~/.embedded-hacking-repo")).read().strip() > root = open(os.path.expanduser("~/.embedded-hacking-repo")).read().strip()
> bin_path = os.path.join(os.path.join(root, "0x0005_intro-to-variables", "build"), "0x0005_intro-to-variables-h.bin") > bin_path = os.path.join(os.path.join(root, "0x0005_intro-to-variables", "build"), "0x0005_intro-to-variables-h.bin")
> log = os.path.join(os.path.join(root, "0x0005_intro-to-variables", "build"), "flash.log") > log = os.path.join(os.path.join(root, "0x0005_intro-to-variables", "build"), "flash.log")
> subprocess.run(["pkill", "-TERM", "-f", "openocd"]) # free the probe first
> p = subprocess.Popen([os.path.join(root, "flash.sh"), bin_path], > p = subprocess.Popen([os.path.join(root, "flash.sh"), bin_path],
> stdout=open(log, "w"), stderr=subprocess.STDOUT, start_new_session=True) > stdout=open(log, "w"), stderr=subprocess.STDOUT, start_new_session=True)
> print("flashing in the background; log:", log) > print("flashing in the background; log:", log)
> ``` > ```
> >
> The `pkill` frees the probe first; on Windows use `subprocess.run(["taskkill", "/F", "/IM", "openocd.exe"])`.
>
> The console is free the moment this returns. Check it with `print(p.poll())` (`None` = still running, `0` = done) or read `flash.log` — success ends with `** Verified OK **`. (Verified: `Popen` returns in ~1 ms; the flash itself takes ~2 s.) > The console is free the moment this returns. Check it with `print(p.poll())` (`None` = still running, `0` = done) or read `flash.log` — success ends with `** Verified OK **`. (Verified: `Popen` returns in ~1 ms; the flash itself takes ~2 s.)
> >
> The same non-blocking form without the script: > The same non-blocking form without the script:
@@ -1009,6 +1012,7 @@ age: 70
> ocd = os.path.expanduser("~/.pico-sdk/openocd/0.12.0+dev") > ocd = os.path.expanduser("~/.pico-sdk/openocd/0.12.0+dev")
> bin_path = os.path.join(os.path.join(root, "0x0005_intro-to-variables", "build"), "0x0005_intro-to-variables-h.bin") > bin_path = os.path.join(os.path.join(root, "0x0005_intro-to-variables", "build"), "0x0005_intro-to-variables-h.bin")
> log = os.path.join(os.path.join(root, "0x0005_intro-to-variables", "build"), "flash.log") > log = os.path.join(os.path.join(root, "0x0005_intro-to-variables", "build"), "flash.log")
> subprocess.run(["pkill", "-TERM", "-f", "openocd"]) # free the probe first
> p = subprocess.Popen([f"{ocd}/openocd", "-s", f"{ocd}/scripts", > p = subprocess.Popen([f"{ocd}/openocd", "-s", f"{ocd}/scripts",
> "-f", "interface/cmsis-dap.cfg", "-f", "target/rp2350.cfg", > "-f", "interface/cmsis-dap.cfg", "-f", "target/rp2350.cfg",
> "-c", "adapter speed 5000", > "-c", "adapter speed 5000",
@@ -1478,6 +1482,7 @@ import os, subprocess
root = open(os.path.expanduser("~/.embedded-hacking-repo")).read().strip() root = open(os.path.expanduser("~/.embedded-hacking-repo")).read().strip()
bin_path = os.path.join(os.path.join(root, "0x0008_uninitialized-variables", "build"), "0x0008_uninitialized-variables-h.bin") bin_path = os.path.join(os.path.join(root, "0x0008_uninitialized-variables", "build"), "0x0008_uninitialized-variables-h.bin")
log = os.path.join(os.path.join(root, "0x0008_uninitialized-variables", "build"), "flash.log") log = os.path.join(os.path.join(root, "0x0008_uninitialized-variables", "build"), "flash.log")
subprocess.run(["pkill", "-TERM", "-f", "openocd"]) # free the probe first
p = subprocess.Popen([os.path.join(root, "flash.sh"), bin_path], p = subprocess.Popen([os.path.join(root, "flash.sh"), bin_path],
stdout=open(log, "w"), stderr=subprocess.STDOUT, start_new_session=True) stdout=open(log, "w"), stderr=subprocess.STDOUT, start_new_session=True)
print("flashing in the background; log:", log) print("flashing in the background; log:", log)
Binary file not shown.