embedded-trainings-2020/embedded-workshop-book/src/running-from-vsc.md

27 lines
1.8 KiB
Markdown
Raw Normal View History

2020-07-12 14:36:39 +00:00
# Running the Program from VS Code
2020-07-08 13:06:49 +00:00
2020-08-17 08:58:10 +00:00
Both `cargo-embed` and `cargo-flash` are tools based on the `probe-rs` library. This library exposes an API to communicate with the J-Link and perform all the operations exposed by the JTAG protocol. We have developed a small Cargo runner called [probe-run](https://github.com/knurling-rs/probe-run) that uses the `probe-rs` library to streamline the process of running a program and printing logs, like `cargo-embed`, while also having better integration into VS code. We'll be using it in this workshop, and you can utilize it in your future projects too.
2020-07-08 13:06:49 +00:00
✅ Open the `src/bin/hello.rs` file and click the "Run" button that's hovering over the `main` function.
2020-07-14 11:51:11 +00:00
> Note: you will get the "Run" button if the Rust analyzer's workspace is set to the `beginner/apps` folder. This will be the case if the current folder in VS code (left side panel) is set to `beginner/apps`.
If you are not using VS code, you can run the program out of your console.
2020-07-14 11:51:11 +00:00
Enter the command `cargo run --bin hello` from within the `beginer/apps` folder. Rust Analyzer's "Run" button is a short-cut for that command.
2020-07-08 13:06:49 +00:00
2020-07-14 11:51:11 +00:00
Expected output:
2020-07-08 13:06:49 +00:00
``` console
$ cargo run --bin hello
INFO:hello -- Hello, world!
stack backtrace:
0: 0x0000229c - __bkpt
1: 0x0000030e - hello::__cortex_m_rt_main
2: 0x0000011a - main
3: 0x00001ba2 - Reset
```
2020-08-17 08:58:10 +00:00
`cargo run` will compile the application and then invoke `probe-run` with its argument set to the path of the output ELF file.
2020-07-08 13:06:49 +00:00
2020-08-17 08:58:10 +00:00
Unlike `cargo-embed`, `probe-run` will terminate when the program reaches a breakpoint (`asm::bkpt`) that halts the device. Before exiting, `probe-run` will print a stack backtrace of the program starting from the breakpoint. This can be used to write small test programs that are meant to perform some work and then terminate.