mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-04-20 23:16:56 +02:00
Add minimal microcontroller example.
This commit is contained in:
parent
6490657dcf
commit
e751c30061
@ -1,5 +1,17 @@
|
|||||||
# Microcontrollers
|
# Microcontrollers
|
||||||
|
|
||||||
* Peripheral Access Crates
|
The `cortex_m_rt` crate provides (among other things) a reset handler for Cortex M microcontrollers.
|
||||||
* HAL crates
|
|
||||||
* Other projects
|
```rust,editable,compile_fail
|
||||||
|
{{#include microcontrollers/examples/src/bin/minimal.rs:Example}}
|
||||||
|
```
|
||||||
|
|
||||||
|
Next we'll look at how to access peripherals, with increasing levels of abstraction.
|
||||||
|
|
||||||
|
<details>
|
||||||
|
|
||||||
|
* The `cortex_m_rt::entry` macro requires that the function have type `fn() -> !`, because returning
|
||||||
|
to the reset handler doesn't make sense.
|
||||||
|
* Run the example with `cargo embed --bin minimal`
|
||||||
|
|
||||||
|
</details>
|
||||||
|
@ -19,6 +19,9 @@ name = "board_support"
|
|||||||
[[bin]]
|
[[bin]]
|
||||||
name = "hal"
|
name = "hal"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "minimal"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "mmio"
|
name = "mmio"
|
||||||
|
|
||||||
|
28
src/bare-metal/microcontrollers/examples/src/bin/minimal.rs
Normal file
28
src/bare-metal/microcontrollers/examples/src/bin/minimal.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2023 Google LLC
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
// ANCHOR: Example
|
||||||
|
#![no_main]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
extern crate panic_halt as _;
|
||||||
|
|
||||||
|
mod interrupts;
|
||||||
|
|
||||||
|
use cortex_m_rt::entry;
|
||||||
|
|
||||||
|
#[entry]
|
||||||
|
fn main() -> ! {
|
||||||
|
loop {}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user