minimal working project with instruct step debugging infrastructure in place

This commit is contained in:
2025-07-13 19:57:20 +02:00
parent a794dac7d4
commit 9ab135672b
10 changed files with 99 additions and 236 deletions
+20 -27
View File
@@ -7,33 +7,26 @@
(add-to-list (add-to-list
'dape-configs 'dape-configs
`(gdb-dap-openocd `(gdb-dap-openocd
,@(alist-get 'gdb-dap dape-configs) ensure (lambda (config)
fn (lambda (config) (dape-ensure-command config)
(let* ((default-directory (dape--guess-root config)) (let* ((default-directory
(openocd (or (dape-config-get config 'command-cwd)
;; Run openocd with config files from `openocd-files' property default-directory))
(start-process-shell-command (command (dape-config-get config 'command))
"openocd" "*openocd*" (output (shell-command-to-string (format "%s --version" command)))
(concat "openocd" (version (save-match-data
(mapconcat (lambda (file) (when (string-match "GNU gdb \\(?:(.*) \\)?\\([0-9.]+\\)" output)
(concat " -f " (shell-quote-argument file))) (string-to-number (match-string 1 output))))))
(append (dape-config-get config 'openocd-files) nil))))) (unless (>= version 14.1)
probe) (user-error "Requires gdb version >= 14.1"))))
;; Wait until port is open modes ()
(while (and (process-live-p openocd) command-cwd dape-command-cwd
(not (setq probe (ignore-errors command "gdb"
(make-network-process :name "openocd port probe" command-args ("--interpreter=dap")
:service 3333))))) :request nil
(sleep-for 0.1)) :program nil
;; Close probe connection :args []
(when probe :stopAtBeginningOfMainSubprogram nil))
(delete-process probe)))
config)
openocd-files ["openocd.cfg"]
:initCommands ["target remote 10.128.5.10:3333"
"monitor reset halt"]
:exitCommands ["monitor shutdown"]
:terminateCommands ["monitor shutdown"]))
) )
;;; .doomrc ends here ;;; .doomrc ends here
+7
View File
@@ -0,0 +1,7 @@
target extended-remote :3333
set remotetimeout 2000
#symbol-file target/riscv32imc-unknown-none-elf/release/ch32v203-examples
file target/riscv32imc-unknown-none-elf/release/bms
monitor reset halt
Generated
+29 -138
View File
@@ -20,12 +20,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "az"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
[[package]] [[package]]
name = "bit_field" name = "bit_field"
version = "0.10.2" version = "0.10.2"
@@ -39,16 +33,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac" checksum = "2d7e60934ceec538daadb9d8432424ed043a904d8e0243f3c6446bce549a46ac"
[[package]] [[package]]
name = "byte-slice-cast" name = "bms"
version = "0.3.5" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [
checksum = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" "ch32-hal",
"embassy-executor",
[[package]] "embassy-futures",
name = "byte-slice-cast" "embassy-time",
version = "1.2.3" "embassy-usb",
source = "registry+https://github.com/rust-lang/crates.io-index" "embedded-hal 1.0.0",
checksum = "7575182f7272186991736b70173b0ea045398f984bf5ebbb3804736ce1330c9d" "heapless",
"micromath",
"panic-halt",
"qingke",
"qingke-rt",
]
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@@ -65,6 +64,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "ch32-hal" name = "ch32-hal"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/ch32-rs/ch32-hal#2b8e1c864ba5545ee65b1c77dcb17c86a471b70c"
dependencies = [ dependencies = [
"ch32-metapac", "ch32-metapac",
"critical-section", "critical-section",
@@ -73,6 +73,7 @@ dependencies = [
"embassy-sync", "embassy-sync",
"embassy-time", "embassy-time",
"embassy-time-driver", "embassy-time-driver",
"embassy-time-queue-utils",
"embassy-usb-driver", "embassy-usb-driver",
"embedded-hal 0.2.7", "embedded-hal 0.2.7",
"embedded-hal 1.0.0", "embedded-hal 1.0.0",
@@ -97,26 +98,6 @@ dependencies = [
"vcell", "vcell",
] ]
[[package]]
name = "ch32v203-examples"
version = "0.1.0"
dependencies = [
"ch32-hal",
"display-interface-spi 0.5.0",
"embassy-executor",
"embassy-futures",
"embassy-time",
"embassy-usb",
"embedded-graphics",
"embedded-hal 1.0.0",
"heapless",
"micromath",
"panic-halt",
"qingke",
"qingke-rt",
"ssd1306",
]
[[package]] [[package]]
name = "critical-section" name = "critical-section"
version = "1.2.0" version = "1.2.0"
@@ -158,51 +139,6 @@ dependencies = [
"syn 2.0.101", "syn 2.0.101",
] ]
[[package]]
name = "display-interface"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7517c040926d7b02b111884aa089177db80878533127f7c1b480d852c5fb4112"
[[package]]
name = "display-interface"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ba2aab1ef3793e6f7804162debb5ac5edb93b3d650fbcc5aeb72fcd0e6c03a0"
[[package]]
name = "display-interface-i2c"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4895cd4e54e5536ef370d7f1eec787aad8275dd8ad15815aebfa71dd847b4ebf"
dependencies = [
"display-interface 0.4.1",
"embedded-hal 0.2.7",
]
[[package]]
name = "display-interface-spi"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "489378ad054862146fbd1f09f51d585ccbe4bd1e2feadcda2a13ac33f840e1a5"
dependencies = [
"byte-slice-cast 0.3.5",
"display-interface 0.4.1",
"embedded-hal 0.2.7",
]
[[package]]
name = "display-interface-spi"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f86b9ec30048b1955da2038fcc3c017f419ab21bb0001879d16c0a3749dc6b7a"
dependencies = [
"byte-slice-cast 1.2.3",
"display-interface 0.5.0",
"embedded-hal 1.0.0",
"embedded-hal-async",
]
[[package]] [[package]]
name = "document-features" name = "document-features"
version = "0.2.11" version = "0.2.11"
@@ -214,15 +150,13 @@ dependencies = [
[[package]] [[package]]
name = "embassy-executor" name = "embassy-executor"
version = "0.6.3" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f64f84599b0f4296b92a4b6ac2109bc02340094bda47b9766c5f9ec6a318ebf8" checksum = "90327bcc66333a507f89ecc4e2d911b265c45f5c9bc241f98eee076752d35ac6"
dependencies = [ dependencies = [
"critical-section", "critical-section",
"document-features", "document-features",
"embassy-executor-macros", "embassy-executor-macros",
"embassy-time-driver",
"embassy-time-queue-driver",
] ]
[[package]] [[package]]
@@ -285,36 +219,38 @@ dependencies = [
[[package]] [[package]]
name = "embassy-time" name = "embassy-time"
version = "0.3.2" version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "158080d48f824fad101d7b2fae2d83ac39e3f7a6fa01811034f7ab8ffc6e7309" checksum = "f820157f198ada183ad62e0a66f554c610cdcd1a9f27d4b316358103ced7a1f8"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"critical-section", "critical-section",
"document-features", "document-features",
"embassy-time-driver", "embassy-time-driver",
"embassy-time-queue-driver",
"embedded-hal 0.2.7", "embedded-hal 0.2.7",
"embedded-hal 1.0.0", "embedded-hal 1.0.0",
"embedded-hal-async", "embedded-hal-async",
"futures-util", "futures-util",
"heapless",
] ]
[[package]] [[package]]
name = "embassy-time-driver" name = "embassy-time-driver"
version = "0.1.0" version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e0c214077aaa9206958b16411c157961fb7990d4ea628120a78d1a5a28aed24" checksum = "8d45f5d833b6d98bd2aab0c2de70b18bfaa10faf661a1578fd8e5dfb15eb7eba"
dependencies = [ dependencies = [
"document-features", "document-features",
] ]
[[package]] [[package]]
name = "embassy-time-queue-driver" name = "embassy-time-queue-utils"
version = "0.1.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1177859559ebf42cd24ae7ba8fe6ee707489b01d0bf471f8827b7b12dcb0bc0" checksum = "dc55c748d16908a65b166d09ce976575fb8852cf60ccd06174092b41064d8f83"
dependencies = [
"embassy-executor",
"heapless",
]
[[package]] [[package]]
name = "embassy-usb" name = "embassy-usb"
@@ -337,29 +273,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fc247028eae04174b6635104a35b1ed336aabef4654f5e87a8f32327d231970" checksum = "4fc247028eae04174b6635104a35b1ed336aabef4654f5e87a8f32327d231970"
[[package]]
name = "embedded-graphics"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0649998afacf6d575d126d83e68b78c0ab0e00ca2ac7e9b3db11b4cbe8274ef0"
dependencies = [
"az",
"byteorder",
"embedded-graphics-core",
"float-cmp",
"micromath",
]
[[package]]
name = "embedded-graphics-core"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba9ecd261f991856250d2207f6d8376946cd9f412a2165d3b75bc87a0bc7a044"
dependencies = [
"az",
"byteorder",
]
[[package]] [[package]]
name = "embedded-hal" name = "embedded-hal"
version = "0.2.7" version = "0.2.7"
@@ -416,15 +329,6 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "float-cmp"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@@ -766,19 +670,6 @@ dependencies = [
"syn 2.0.101", "syn 2.0.101",
] ]
[[package]]
name = "ssd1306"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b37918f6137f2b58427181c3e10a731bef1061a9756b13ffbade64f21892acc6"
dependencies = [
"display-interface 0.4.1",
"display-interface-i2c",
"display-interface-spi 0.4.1",
"embedded-graphics-core",
"embedded-hal 0.2.7",
]
[[package]] [[package]]
name = "ssmarshal" name = "ssmarshal"
version = "1.0.0" version = "1.0.0"
+9 -13
View File
@@ -1,10 +1,10 @@
[package] [package]
name = "ch32v203-examples" name = "bms"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
ch32-hal = { path = "../ch32-hal", features = [ ch32-hal = { git = "https://github.com/ch32-rs/ch32-hal", features = [
"ch32v203c8t6", "ch32v203c8t6",
"memory-x", "memory-x",
"embassy", "embassy",
@@ -12,16 +12,14 @@ ch32-hal = { path = "../ch32-hal", features = [
"time-driver-tim2", "time-driver-tim2",
], default-features = false } ], default-features = false }
embassy-executor = { version = "0.6.0", features = [ embassy-executor = { version = "0.7.0", features = [
"integrated-timers",
"arch-riscv32", "arch-riscv32",
"executor-thread", "executor-thread",
] } ] }
embassy-time = { version = "0.3.2" } embassy-time = { version = "0.4.0" }
embassy-usb = { version = "0.3.0" } embassy-usb = { version = "0.3.0" }
embassy-futures = { version = "0.1.0" } embassy-futures = { version = "0.1.0" }
#embassy-rp = "0.2.0"
# This is okay because we should automatically use whatever ch32-hal uses # This is okay because we should automatically use whatever ch32-hal uses
qingke-rt = "*" qingke-rt = "*"
@@ -29,18 +27,16 @@ qingke = "*"
panic-halt = "1.0" panic-halt = "1.0"
display-interface-spi = "0.5.0"
embedded-hal = "1.0.0" embedded-hal = "1.0.0"
embedded-graphics = "0.8.1"
ssd1306 = "0.8.4"
heapless = "0.8.0" heapless = "0.8.0"
micromath = { version = "2.1.0", features = ["num-traits"] } micromath = { version = "2.1.0", features = ["num-traits"] }
# mipidsi = "0.7.1" [profile.dev]
# embedded-hal-bus = "0.1.0" #lto = true
opt-level = 1
[profile.release] [profile.release]
strip = false # symbols are not flashed to the microcontroller, so don't strip them. strip = false # symbols are not flashed to the microcontroller, so don't strip them.
lto = true #lto = true
debug = true
opt-level = "z" # Optimize for size. opt-level = "z" # Optimize for size.
+24 -11
View File
@@ -1,18 +1,31 @@
# ch32v203-examples # ch32v203-bms
- SWDIO: PA13 A simple battery management controller software.
- SWCLK: PA14
## Boards ## Building
### FlappyBoard - CH32V203G6 ``` sh
cargo build --release
```
Link: <https://github.com/metro94/FlappyBoard> ## Flash
### nanoCH32V203 - CH32V203C8T6 ``` sh
wchip wchisp flash target/riscv32imc-unknown-none-elf/release/bms
```
Link: <https://github.com/wuxx/nanoCH32V203> ## Debugging
- HSE: 8MHz For debugging purposes a container file is provided together with wrapper scripts to start the containerized `openocd` and `riscv-gdb` transparently. The wrapper scripts assume that `podman` is setup.
- LSE: 32.768kHz
- LED: PA15 Starting Debug server
```
./bin/openocd
```
Connecting with gdb for interactive debugging
```
./bin/gdb -f target/riscv32imc-unknown-none-elf/release/bms
```
+1
View File
@@ -13,6 +13,7 @@ function _fatal {
declare -a PODMAN_ARGS=( declare -a PODMAN_ARGS=(
"--rm" "-i" "--log-driver=none" "--rm" "-i" "--log-driver=none"
"--network=host" "--network=host"
"--pid=host"
"-v" "$PWD:$PWD:rw" "-v" "$PWD:$PWD:rw"
"-w" "$PWD" "-w" "$PWD"
) )
+1 -2
View File
@@ -12,8 +12,7 @@ function _fatal {
declare -a PODMAN_ARGS=( declare -a PODMAN_ARGS=(
"--rm" "-i" "--log-driver=none" "--rm" "-i" "--log-driver=none"
"-p" "3333:3333" "--network=host"
"-p" "4444:4444"
"-v" "$PWD:$PWD:rw" "-v" "$PWD:$PWD:rw"
"-w" "$PWD" "-w" "$PWD"
) )
+1 -1
View File
@@ -1,7 +1,7 @@
set _CHIPNAME ch32v203 set _CHIPNAME ch32v203
set _TARGETNAME $_CHIPNAME.cpu set _TARGETNAME $_CHIPNAME.cpu
bindto 0.0.0.0 #bindto 0.0.0.0
adapter driver wlinke adapter driver wlinke
adapter speed 6000 adapter speed 6000
+5 -44
View File
@@ -28,50 +28,11 @@ async fn main(spawner: Spawner) -> ! {
let mut led = Output::new(p.PB2, Level::Low, Default::default()); let mut led = Output::new(p.PB2, Level::Low, Default::default());
let mut cfg = usart::Config::default(); loop {
let mut uart = UartTx::new_blocking(p.USART1, p.PA9, cfg).unwrap(); Timer::after_millis(1000).await;
let usb_driver = Driver::new(p.USBD, Irqs, p.PA12, p.PA11); //class.write_packet(b"hello world from embassy main\r\n").await;
// Create embassy-usb Config
let mut config = Config::new(0xc0de, 0xcafe);
config.manufacturer = Some("Embassy");
config.product = Some("USB-serial example");
config.serial_number = Some("12345678");
config.max_power = 100;
config.max_packet_size_0 = 64;
// Create embassy-usb DeviceBuilder using the driver and config. led.toggle();
// It needs some buffers for building the descriptors. }
let mut config_descriptor = [0; 256];
let mut bos_descriptor = [0; 256];
let mut control_buf = [0; 64];
let mut state = State::new();
let mut builder = Builder::new(
usb_driver,
config,
&mut config_descriptor,
&mut bos_descriptor,
&mut [], // no msos descriptors
&mut control_buf,
);
// Create classes on the builder.
let mut class = CdcAcmClass::new(&mut builder, &mut state, 64);
let mut usb = builder.build();
let usb_task = usb.run();
let worker_task = async {
loop {
Timer::after_millis(1000).await;
//class.write_packet(b"hello world from embassy main\r\n").await;
led.toggle();
}
};
join(usb_task, worker_task).await.1
} }
+2
View File
@@ -22,4 +22,6 @@ RUN cd /root && \
mv xpack-toolchain/riscv-none-elf /usr/local && \ mv xpack-toolchain/riscv-none-elf /usr/local && \
rm -rf xpack-toolchain xpack-riscv-toolchain.tar.gz rm -rf xpack-toolchain xpack-riscv-toolchain.tar.gz
RUN mkdir -p /root/.config/gdb && echo "set auto-load safe-path /" >> /root/.config/gdb/gdbinit
ENTRYPOINT [ "/usr/bin/bash" ] ENTRYPOINT [ "/usr/bin/bash" ]