1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-11-29 18:29:40 +02:00

Add minimal microcontroller example.

This commit is contained in:
Andrew Walbran 2023-03-03 19:03:52 +00:00
parent 6490657dcf
commit e751c30061
3 changed files with 46 additions and 3 deletions

View File

@ -1,5 +1,17 @@
# Microcontrollers
* Peripheral Access Crates
* HAL crates
* Other projects
The `cortex_m_rt` crate provides (among other things) a reset handler for Cortex M microcontrollers.
```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>

View File

@ -19,6 +19,9 @@ name = "board_support"
[[bin]]
name = "hal"
[[bin]]
name = "minimal"
[[bin]]
name = "mmio"

View 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 {}
}