88 <h3 align =" center " >rp-hal</h3 >
99
1010 <p align =" center " >
11- Rust support for the " Raspberry Silicon" family of microcontrollers
11+ Rust support for the Raspberry Pi family of microcontrollers
1212 <br />
13- <a href="https://docs.rs/rp2040-hal"><strong>Explore the API docs »</strong> </a>
13+ <strong>Explore the API docs for < a href="https://docs.rs/rp2040-hal">RP2040</a> or <a href="https:// docs.rs/rp2350-hal">RP2350 </a></strong >
1414 <br />
1515 <br />
1616 <a href="https://github.com/rp-rs/rp-hal-boards/tree/main/boards/rp-pico/examples">View Demos</a>
4040
4141## Getting Started
4242
43- So, you want to program your new Raspberry Silicon microcontroller, using the
43+ So, you want to program your new Raspberry Pi microcontroller, using the
4444Rust programming language. You've come to the right place!
4545
4646This repository is ` rp-hal ` - a collection of high-level drivers for the
47- Raspberry Silicon RP2040 microcontroller and various associated boards, like
48- the Raspberry Pi Pico and the Adafruit Feather RP2040.
47+ Raspberry Pi RP2040 and RP2350 microcontrollers.
4948
50- If you want to write an application for Raspberry Silicon, check out our
51- [ RP2040 Project Template] ( https://github.com/rp-rs/rp2040-project-template ) .
49+ If you want to write an application for the RP2040, check out our [ RP2040
50+ Project Template] ( https://github.com/rp-rs/rp2040-project-template ) . If you
51+ want to use the RP2350 family, check out the [ RP2350 Project
52+ Template] ( https://github.com/rp-rs/rp235x-project-template ) instead.
5253
5354If you want to write code that uses the Raspberry Silicon PIO State Machines,
5455check out [ pio-rs] ( https://github.com/rp-rs/pio-rs ) . You can even compile PIO
55- programs at run-time, on the RP2040 itself!
56+ programs at run-time, on the MCU itself!
5657
57- If you want to try out some examples on one of our supported boards, check out
58- the list of [ * Board Support Packages* ] [ BSPs ] , and click through to see the various
59- examples for each board.
58+ This repository only includes examples suitable for the Raspberry Pi Pico and
59+ Raspberry Pi Pico 2 boards. We do also have some [ * Board Support
60+ Packages* ] [ BSPs ] which you can refer to, although note, you can also just
61+ start with the bare HAL if you prefer (or if there is no BSP for your board
62+ yet).
6063
6164Before trying any of the examples, please ensure you have the latest stable
6265version of Rust installed, along with the right target support:
@@ -65,6 +68,8 @@ version of Rust installed, along with the right target support:
6568rustup self update
6669rustup update stable
6770rustup target add thumbv6m-none-eabi
71+ rustup target add thumbv8m.main-none-eabihf
72+ rustup target add riscv32imac-unknown-none-elf
6873```
6974
7075You may also want to install probe-rs, to flash your device over the SWD pins
@@ -83,27 +88,13 @@ binary][picotool-releases] for your system.
8388
8489## Packages
8590
86- There is a _ Hardware Abstraction Layer_ (or HAL) crate for the RP2040 chip,
87- and _ Board Support Package_ crates for a number of RP2040 based PCBs. If you
88- are writing code that should run on any microcontroller, consider using the
89- generic Rust Embedded Working Group's [ Embedded HAL] .
91+ There is one _ Hardware Abstraction Layer_ (or HAL) crate for the RP2040, and
92+ another for the RP2350. We also have a common HAL, and various examples.
9093
91- If you are writing code that should work on any RP2040 device, use the _ HAL_
92- crate. If you are running code on a specific board, use the appropriate _ BSP_
93- crate (which will include the _ HAL_ crate for you). Please note, you cannot
94- depend on multiple _ BSP_ crates; you have to pick one, or use [ Cargo Features]
95- to select one at build time.
96-
97- Each BSP includes some examples to show off the features of that particular board.
98-
99- [ Cargo Workspace ] : https://doc.rust-lang.org/cargo/reference/workspaces.html
100- [ Embedded HAL ] : https://github.com/rust-embedded/embedded-hal
101- [ Cargo Features ] : https://doc.rust-lang.org/cargo/reference/features.html
102-
103- ### [ rp2040-hal] - The HAL for the [ Raspberry Silicon RP2040]
94+ ### [ rp2040-hal] - The HAL for the [ Raspberry Pi RP2040]
10495
10596You should include this crate in your project if you want to write a driver or
106- library that runs on the [ Raspberry Silicon RP2040] , or if you are writing a Board
97+ library that runs on the [ Raspberry Pi RP2040] , or if you are writing a Board
10798Support Package (see later on).
10899
109100The crate provides high-level drivers for the RP2040's internal peripherals,
@@ -115,13 +106,82 @@ There are examples in this crate to show how to use various peripherals
115106(GPIO, I²C, SPI, UART, etc) but note that the pin-outs may not match any
116107particular board.
117108
109+ ### [ rp2040-hal-examples] - Examples for using [ rp2040-hal]
110+
111+ This folder contains various examples for how to use the Rust HAL for the
112+ RP2040. We have examples for the following (plus many more):
113+
114+ * GPIO
115+ * I²C
116+ * SPI
117+ * UART
118+ * Spawning tasks on Core 1
119+ * Blinking an LED with PWM
120+ * Using PIO
121+ * Sleeping and waiting on the RTC
122+
123+ ### [ rp235x-hal] - The HAL for the [ Raspberry Pi RP2350]
124+
125+ You should include this crate in your project if you want to write a driver or
126+ library that runs on the [ Raspberry Pi RP2350] , or if you are writing a Board
127+ Support Package (see later on). We call it the 'rp235x-hal' because it
128+ supports the RP2350A, the RP2350B and variants which include on-board Flash
129+ such as the RP2354A and RP2354B.
130+
131+ The crate provides high-level drivers for the RP2350's internal peripherals,
132+ such as the SPI Controller and the I²C Controller. It doesn't know anything
133+ about how your particular board is wired up (such as what each IO pin of the
134+ RP2350 is connected to).
135+
136+ There are examples in this crate to show how to use various peripherals
137+ (GPIO, I²C, SPI, UART, etc) but note that the pin-outs may not match any
138+ particular board.
139+
140+ This HAL fully supports the RP2350A, and has partial support for the extra
141+ pins on the RP2350B.
142+
143+ ### [ rp235x-hal-examples] - Examples for using [ rp235x-hal]
144+
145+ This folder contains various examples for how to use the Rust HAL for the
146+ RP2040. We have examples for the following (plus many more):
147+
148+ * GPIO
149+ * I²C
150+ * SPI
151+ * UART
152+ * Spawning tasks on Core 1
153+ * Blinking an LED with PWM
154+ * Using PIO
155+ * Sleeping and waiting on the RTC
156+ * Running in RISC-V mode
157+
158+ ### [ rp-hal-common] - Shared code for the two HALs
159+
160+ We're in the process of rationalising the two HALs into one (or, mostly into
161+ one) and any common components will get moved here. You will likely never need
162+ to use this library yourself.
163+
164+ ### [ rp-binary-info] - Library for generating ` picotool ` compatible metadata
165+
166+ Raspberry Pi's ` picotool ` program supports marking binaries with certain
167+ metadata - the name of the program, the version number, and so on. We have
168+ implemented support for this on the firmware side, so your Rust binaries can
169+ also have this metadata appear in ` picotool ` .
170+
118171### [ BSPs] - Board support packages
119172
120- There are BSPs for various boards based on the RP2040 available in
121- a [ separate repository] [ BSPs ] .
173+ There are BSPs for various boards based on the RP2040 available in a [ separate
174+ repository] [ BSPs ] . They used to be in this repository, but were moved out
175+ because there were so many of them.
122176
123177[ rp2040-hal ] : https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal
124- [ Raspberry Silicon RP2040 ] : https://www.raspberrypi.org/products/rp2040/
178+ [ rp2040-hal-examples ] : https://github.com/rp-rs/rp-hal/tree/main/rp2040-hal-examples
179+ [ rp235x-hal ] : https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal
180+ [ rp235x-hal-examples ] : https://github.com/rp-rs/rp-hal/tree/main/rp235x-hal-examples
181+ [ rp-binary-info ] : https://github.com/rp-rs/rp-hal/tree/main/rp-binary-info
182+ [ rp-hal-common ] : https://github.com/rp-rs/rp-hal/tree/main/rp-hal-common
183+ [ Raspberry Pi RP2040 ] : https://www.raspberrypi.org/products/rp2040/
184+ [ Raspberry Pi RP2350 ] : https://www.raspberrypi.org/products/rp2350/
125185[ BSPs ] : https://github.com/rp-rs/rp-hal-boards/
126186
127187<!-- PROGRAMMING -->
@@ -134,29 +194,44 @@ that accepts UF2 format images. You can use picotool to flash your device over
134194USB, or convert the Arm ELF file to a UF2 format image.
135195
136196The RP2040 contains two Cortex-M0+ processors, which execute Thumb-2 encoded
137- ARMv6 -M instructions. There are no operating-specific features in the binaries
197+ Armv6 -M instructions. There are no operating-specific features in the binaries
138198produced - they are for 'bare-metal' systems. For compatibility with other Arm
139199code (e.g. as produced by GCC), Rust uses the * Arm Embedded-Application Binary
140200Interface* standard or EABI. Therefore, any Rust code for the RP2040 should be
141201compiled with the target * ` thumbv6m-none-eabi ` * .
142202
143- More details can be found in the [ Project Template] .
203+ The RP2350 contains two Cortex-M33 processors (each with a single-precision
204+ FPU), which execute Thumb-2 encoded Armv8-M Mainline instructions. There are
205+ no operating-specific features in the binaries produced - they are for
206+ 'bare-metal' systems. For compatibility with other Arm code (e.g. as produced
207+ by GCC), Rust uses the * Arm Embedded-Application Binary Interface* standard or
208+ EABI. Therefore, any Rust code for the RP2350 should be compiled with the
209+ target * ` thumbv8m.main-none-eabihf ` * .
210+
211+ Each core in the RP2350 can optionally be swapped out at run-time for a RISC-V
212+ Hazard3 processor core. Any Rust code for the RP2350 in RISC-V mode should be
213+ compiled with the target * ` riscv32imac-unknown-none-elf ` * .
214+
215+ More details can be found in the [ RP2040 Project Template] and the [ RP2350
216+ Project Template] .
144217
145218### Linker flags
146219
147- Besides the correct target, which mainly defines the instruction set,
148- it's also necessary to use a certain memory layout compatible with
149- the rp2040. To achieve that, rustc must be called with appropriate
150- linker flags. In the [ Project Template] , those flags are defined in
220+ Besides the correct target, which mainly defines the instruction set, it's
221+ also necessary to use a certain memory layout compatible with your MCU. To
222+ achieve that, rustc must be called with appropriate linker flags. In the
223+ [ RP2040 Project Template] , those flags are defined in
151224[ ` .cargo/config.toml ` ] ( https://github.com/rp-rs/rp2040-project-template/blob/main/.cargo/config.toml ) .
152- Another necessary file is
153- [ ` memory.x ` ] ( https://github.com/rp-rs/rp2040-project-template/blob/main/memory.x ) .
225+ You must also provide a file called
226+ [ ` memory.x ` ] ( https://github.com/rp-rs/rp2040-project-template/blob/main/memory.x ) ,
227+ which is required by the [ ` cortex-m-rt ` ] ( https://crates.io/crates/cortex-m-rt )
228+ start-up library we use.
154229
155230More detailed information on how the linker flags work can be found in
156- [ the cortex_m_rt docs] ( https://docs.rs/cortex-m-rt/latest/cortex_m_rt/ ) .
231+ [ the ` cortex-m-rt ` docs] ( https://docs.rs/cortex-m-rt/latest/cortex_m_rt/ ) .
157232
158233In most cases, it should be sufficient to use the example files from the
159- [ Project Template] .
234+ [ RP2040 Project Template ] or [ RP2350 Project Template] .
160235
161236### Loading over USB with picotool
162237
@@ -177,12 +252,12 @@ The `thumbv6m-none-eabi` target may be replaced by the all-Arm wildcard
177252whilst holding some kind of "Boot Select" button. On Linux, you will also need
178253to 'mount' the device, like you would a USB Thumb Drive.
179254
180- * Step 4* - Use ` cargo run ` , which will compile the code and started the
255+ * Step 4* - Use ` cargo run ` , which will compile the code and start the
181256specified 'runner'. As the 'runner' is picotool, it will flash your compiled
182257binary over USB.
183258
184- ``` console
185- $ cargo run --release --features " critical-section-impl,rt,defmt" --example pwm_blink
259+ ``` sh
260+ cargo run --release --features " critical-section-impl,rt,defmt" --example pwm_blink
186261```
187262
188263(The ` pwm_blink ` example doesn't need all these feature flags. They are listed here
@@ -192,28 +267,27 @@ If you want to create a UF2 file, which is loaded by copying it over to the
192267RPI-RP2 mass storage device, use the ` picotool uf2 convert ` command on your
193268compiled program with the ` -t elf ` argument.
194269
195- ``` console
196- $ picotool uf2 convert -t elf target/thumbv6m-none-eabi/release/pwm_blink
197- pwm_blink.uf2
270+ ``` sh
271+ picotool uf2 convert -t elf target/thumbv6m-none-eabi/release/pwm_blink pwm_blink.uf2
198272```
199273
200274Picotool can also read "Binary Info" from a device with ` picotool info ` . To
201275enable this in your firmware, see the [ rp-binary-info] crate and the
202276corresponding [ binary info example] .
203277
204- [ rp-binary-info ] : https://github.com/rp-rs/rp-hal/tree/main/rp-binary-info
205278[ binary info example ] : https://github.com/rp-rs/rp-hal/blob/main/rp2040-hal-examples/src/bin/binary_info_demo.rs
206279
207280### Loading with probe-rs
281+
208282[ probe-rs] ( https://github.com/probe-rs/probe-rs ) is a library and a
209283command-line tool which can flash a wide variety of microcontrollers
210284using a wide variety of debug/JTAG probes. Unlike using, say, OpenOCD,
211285probe-rs can autodetect your debug probe, which can make it easier to use.
212286
213287* Step 1* - Install ` probe-rs ` :
214288
215- ``` console
216- $ cargo install --locked probe-rs-tools
289+ ``` sh
290+ cargo install --locked probe-rs-tools
217291```
218292
219293Alternatively, follow the installation instructions on https://probe.rs/ .
@@ -244,11 +318,11 @@ will reflect the probe you have connected.
244318RP2040 via the first probe it finds, and install your firmware into the Flash
245319connected to the RP2040.
246320
247- ``` console
248- $ cargo run --release --example pwm_blink
321+ ``` sh
322+ cargo run --release --example pwm_blink
249323```
250-
251- [ Project Template ] : https://github.com/rp-rs/rp2040 -project-template
324+ [ RP2040 Project Template ] : https://github.com/rp-rs/rp2040-project-template
325+ [ RP2350 Project Template] : https://github.com/rp-rs/rp235x -project-template
252326
253327<!-- ROADMAP -->
254328## Roadmap
0 commit comments