]> git.proxmox.com Git - rustc.git/blob - src/doc/embedded-book/src/intro/tooling.md
New upstream version 1.34.2+dfsg1
[rustc.git] / src / doc / embedded-book / src / intro / tooling.md
1 # Tooling
2
3 Dealing with microcontrollers involves using several different tools as we'll be
4 dealing with an architecture different than your laptop's and we'll have to run
5 and debug programs on a *remote* device.
6
7 We'll use all the tools listed below. Any recent version should work when a
8 minimum version is not specified, but we have listed the versions we have
9 tested.
10
11 - Rust 1.31, 1.31-beta, or a newer toolchain PLUS ARM Cortex-M compilation
12 support.
13 - [`cargo-binutils`](https://github.com/rust-embedded/cargo-binutils) ~0.1.4
14 - [`qemu-system-arm`](https://www.qemu.org/). Tested versions: 3.0.0
15 - OpenOCD >=0.8. Tested versions: v0.9.0 and v0.10.0
16 - GDB with ARM support. Version 7.12 or newer highly recommended. Tested
17 versions: 7.10, 7.11, 7.12 and 8.1
18 - [OPTIONAL] `git` OR
19 [`cargo-generate`](https://github.com/ashleygwilliams/cargo-generate). If you
20 have neither installed then don't worry about installing either.
21
22 The text below explains why we are using these tools. Installation instructions
23 can be found on the next page.
24
25 ## `cargo-generate` OR `git`
26
27 Bare metal programs are non-standard (`no_std`) Rust programs that require some
28 fiddling with the linking process to get the memory layout of the program
29 right. All this requires unusual files (like linker scripts) and unusual
30 settings (like linker flags). We have packaged all that for you in a template
31 so that you only need to fill in the blanks such as the project name and the
32 characteristics of your target hardware.
33
34 Our template is compatible with `cargo-generate`: a Cargo subcommand for
35 creating new Cargo projects from templates. You can also download the
36 template using `git`, `curl`, `wget`, or your web browser.
37
38 ## `cargo-binutils`
39
40 `cargo-binutils` is a collection of Cargo subcommands that make it easy to use
41 the LLVM tools that are shipped with the Rust toolchain. These tools include the
42 LLVM versions of `objdump`, `nm` and `size` and are used for inspecting
43 binaries.
44
45 The advantage of using these tools over GNU binutils is that (a) installing the
46 LLVM tools is the same one-command installation (`rustup component add
47 llvm-tools-preview`) regardless of your OS and (b) tools like `objdump` support
48 all the architectures that `rustc` supports -- from ARM to x86_64 -- because
49 they both share the same LLVM backend.
50
51 ## `qemu-system-arm`
52
53 QEMU is an emulator. In this case we use the variant that can fully emulate ARM
54 systems. We use QEMU to run embedded programs on the host. Thanks to this you
55 can follow some parts of this book even if you don't have any hardware with you!
56
57 ## GDB
58
59 A debugger is a very important component of embedded development as you may not
60 always have the luxury to log stuff to the host console. In some cases, you may
61 not have LEDs to blink on your hardware!
62
63 In general, LLDB works as well as GDB when it comes to debugging but we haven't
64 found an LLDB counterpart to GDB's `load` command, which uploads the program to
65 the target hardware, so currently we recommend that you use GDB.
66
67 ## OpenOCD
68
69 GDB isn't able to communicate directly with the ST-Link debugging hardware on
70 your STM32F3DISCOVERY development board. It needs a translator and the Open
71 On-Chip Debugger, OpenOCD, is that translator. OpenOCD is a program that runs
72 on your laptop/PC and translates between GDB's TCP/IP based remote debug
73 protocol and ST-Link's USB based protocol.
74
75 OpenOCD also performs other important work as part of its translation for the
76 debugging of the ARM Cortex-M based microcontroller on your STM32F3DISCOVERY
77 development board:
78 * It knows how to interact with the memory mapped registers used by the ARM
79 CoreSight debug peripheral. It is these CoreSight registers that allow for:
80 * Breakpoint/Watchpoint manipulation
81 * Reading and writing of the CPU registers
82 * Detecting when the CPU has been halted for a debug event
83 * Continuing CPU execution after a debug event has been encountered
84 * etc.
85 * It also knows how to erase and write to the microcontroller's FLASH