Compare commits
26 Commits
therealpro
...
bt_limit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73bae533c4 | ||
|
|
ac344b967f | ||
|
|
c6599f3686 | ||
|
|
3aa5ea9fd3 | ||
|
|
26baac1bf3 | ||
|
|
2d7405fc04 | ||
|
|
e58549b2ec | ||
|
|
9ee8b84217 | ||
|
|
0e2aadf8f2 | ||
|
|
e7138e0e2a | ||
|
|
c142db6e23 | ||
|
|
207bca35f4 | ||
|
|
f9570c7c65 | ||
|
|
f47d1633af | ||
|
|
55e61c3291 | ||
|
|
e64e690512 | ||
|
|
f7a943f480 | ||
|
|
9c6b290e12 | ||
|
|
7e2bec66b7 | ||
|
|
4295bccf0e | ||
|
|
8f292e0f07 | ||
|
|
76d2e947a5 | ||
|
|
76cdd6a95b | ||
|
|
314e48537c | ||
|
|
d5abcf6d2a | ||
|
|
b02a67b5f9 |
@@ -1,13 +1,14 @@
|
||||
[package]
|
||||
authors = ["{{authors}}"]
|
||||
edition = "2018"
|
||||
readme = "README.md"
|
||||
name = "{{project-name}}"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.5.7"
|
||||
cortex-m-rt = "0.6.3"
|
||||
cortex-m-semihosting = "0.3.1"
|
||||
cortex-m = "0.5.8"
|
||||
cortex-m-rt = "0.6.5"
|
||||
cortex-m-semihosting = "0.3.2"
|
||||
panic-halt = "0.2.0"
|
||||
|
||||
# Uncomment for the panic example.
|
||||
|
||||
@@ -8,12 +8,9 @@ This project is developed and maintained by the [Cortex-M team][team].
|
||||
|
||||
To build embedded programs using this template you'll need:
|
||||
|
||||
- Rust 1.30, 1.30-beta, nightly-2018-09-13 or a newer toolchain. e.g. `rustup
|
||||
- Rust 1.31, 1.30-beta, nightly-2018-09-13 or a newer toolchain. e.g. `rustup
|
||||
default beta`
|
||||
|
||||
> **NOTE**: 1.30-beta is not out yet so you'll have to use the nightly channel
|
||||
> in the meantime.
|
||||
|
||||
- The `cargo generate` subcommand. [Installation
|
||||
instructions](https://github.com/ashleygwilliams/cargo-generate#installation).
|
||||
|
||||
@@ -128,5 +125,5 @@ Contribution to this crate is organized under the terms of the [Rust Code of
|
||||
Conduct][CoC], the maintainer of this crate, the [Cortex-M team][team], promises
|
||||
to intervene to uphold that code of conduct.
|
||||
|
||||
[CoC]: CODE_OF_CONDUCT.md
|
||||
[CoC]: https://www.rust-lang.org/policies/code-of-conduct
|
||||
[team]: https://github.com/rust-embedded/wg#the-cortex-m-team
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
extern crate panic_halt;
|
||||
|
||||
use self::alloc::vec;
|
||||
use core::alloc::Layout;
|
||||
use core::fmt::Write;
|
||||
|
||||
use alloc::vec;
|
||||
use alloc_cortex_m::CortexMHeap;
|
||||
use cortex_m::asm;
|
||||
use cortex_m_rt::entry;
|
||||
use cortex_m_semihosting::hio;
|
||||
use cortex_m_semihosting::hprintln;
|
||||
|
||||
// this is the allocator the application will use
|
||||
#[global_allocator]
|
||||
@@ -39,8 +39,11 @@ fn main() -> ! {
|
||||
// Growable array allocated on the heap
|
||||
let xs = vec![0, 1, 2];
|
||||
|
||||
let mut stdout = hio::hstdout().unwrap();
|
||||
writeln!(stdout, "{:?}", xs).unwrap();
|
||||
hprintln!("{:?}", xs).unwrap();
|
||||
|
||||
// exit QEMU
|
||||
// NOTE do not run this on hardware; it can corrupt OpenOCD state
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
//!
|
||||
//! [`svd2rust`]: https://crates.io/crates/svd2rust
|
||||
//!
|
||||
//! Device crates also provide an `interrupt!` macro (behind the "rt" feature) to register interrupt
|
||||
//! handlers.
|
||||
//!
|
||||
//! This example depends on the [`stm32f103xx`] crate so you'll have to add it to your Cargo.toml.
|
||||
//!
|
||||
//! [`stm32f103xx`]: https://crates.io/crates/stm32f103xx
|
||||
@@ -27,11 +24,9 @@
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use cortex_m::peripheral::syst::SystClkSource;
|
||||
use cortex_m_rt::entry;
|
||||
use cortex_m_semihosting::hio::{self, HStdout};
|
||||
use cortex_m_semihosting::hprint;
|
||||
use stm32f30x::{interrupt, Interrupt};
|
||||
|
||||
#[entry]
|
||||
@@ -53,19 +48,11 @@ fn main() -> ! {
|
||||
while !syst.has_wrapped() {}
|
||||
|
||||
// trigger the `EXTI0` interrupt
|
||||
nvic.set_pending(Interrupt::EXTI0);
|
||||
NVIC::pend(Interrupt::EXTI0);
|
||||
}
|
||||
}
|
||||
|
||||
// try commenting out this line: you'll end in `default_handler` instead of in `exti0`
|
||||
interrupt!(EXTI0, exti0, state: Option<HStdout> = None);
|
||||
|
||||
fn exti0(state: &mut Option<HStdout>) {
|
||||
if state.is_none() {
|
||||
*state = Some(hio::hstdout().unwrap());
|
||||
}
|
||||
|
||||
if let Some(hstdout) = state.as_mut() {
|
||||
hstdout.write_str(".").unwrap();
|
||||
}
|
||||
#[interrupt]
|
||||
fn EXTI0() {
|
||||
hprint!(".").unwrap();
|
||||
}
|
||||
|
||||
@@ -12,12 +12,10 @@
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use cortex_m::peripheral::syst::SystClkSource;
|
||||
use cortex_m::Peripherals;
|
||||
use cortex_m_rt::{entry, exception};
|
||||
use cortex_m_semihosting::hio::{self, HStdout};
|
||||
use cortex_m_semihosting::hprint;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@@ -35,13 +33,5 @@ fn main() -> ! {
|
||||
|
||||
#[exception]
|
||||
fn SysTick() {
|
||||
static mut STDOUT: Option<HStdout> = None;
|
||||
|
||||
if STDOUT.is_none() {
|
||||
*STDOUT = Some(hio::hstdout().unwrap());
|
||||
}
|
||||
|
||||
if let Some(hstdout) = STDOUT.as_mut() {
|
||||
hstdout.write_str(".").unwrap();
|
||||
}
|
||||
hprint!(".").unwrap();
|
||||
}
|
||||
|
||||
@@ -5,17 +5,15 @@
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use cortex_m_semihosting::{debug, hio};
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let mut stdout = hio::hstdout().unwrap();
|
||||
writeln!(stdout, "Hello, world!").unwrap();
|
||||
hprintln!("Hello, world!").unwrap();
|
||||
|
||||
// exit QEMU or the debugger section
|
||||
// exit QEMU
|
||||
// NOTE do not run this on hardware; it can corrupt OpenOCD state
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
loop {}
|
||||
|
||||
57
examples/test_on_host.rs
Normal file
57
examples/test_on_host.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
//! Conditionally compiling tests with std and our executable with no_std.
|
||||
//!
|
||||
//! Rust's built in unit testing framework requires the standard library,
|
||||
//! but we need to build our final executable with no_std.
|
||||
//! The testing framework also generates a `main` method, so we need to only use the `#[entry]`
|
||||
//! annotation when building our final image.
|
||||
//! For more information on why this example works, see this excellent blog post.
|
||||
//! https://os.phil-opp.com/unit-testing/
|
||||
//!
|
||||
//! Running this example:
|
||||
//!
|
||||
//! Ensure there are no targets specified under `[build]` in `.cargo/config`
|
||||
//! In order to make this work, we lose the convenience of having a default target that isn't the
|
||||
//! host.
|
||||
//!
|
||||
//! cargo build --example test_on_host --target thumbv7m-none-eabi
|
||||
//! cargo test --example test_on_host
|
||||
|
||||
#![cfg_attr(test, allow(unused_imports))]
|
||||
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
#![cfg_attr(not(test), no_main)]
|
||||
|
||||
// pick a panicking behavior
|
||||
#[cfg(not(test))]
|
||||
extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics
|
||||
// extern crate panic_abort; // requires nightly
|
||||
// extern crate panic_itm; // logs messages over ITM; requires ITM support
|
||||
// extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger
|
||||
|
||||
use cortex_m::asm;
|
||||
use cortex_m_rt::entry;
|
||||
|
||||
#[cfg(not(test))]
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
asm::nop(); // To not have main optimize to abort in release mode, remove when you add code
|
||||
|
||||
loop {
|
||||
// your code goes here
|
||||
}
|
||||
}
|
||||
|
||||
fn add(a: i32, b: i32) -> i32 {
|
||||
a + b
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn foo() {
|
||||
println!("tests work!");
|
||||
assert!(2 == add(1,1));
|
||||
}
|
||||
}
|
||||
13
memory.x
13
memory.x
@@ -19,3 +19,16 @@ MEMORY
|
||||
/* This is required only on microcontrollers that store some configuration right
|
||||
after the vector table */
|
||||
/* _stext = ORIGIN(FLASH) + 0x400; */
|
||||
|
||||
/* Example of putting non-initialized variables into custom RAM locations. */
|
||||
/* This assumes you have defined a region RAM2 above, and in the Rust
|
||||
sources added the attribute `#[link_section = ".ram2bss"]` to the data
|
||||
you want to place there. */
|
||||
/* Note that the section will not be zero-initialized by the runtime! */
|
||||
/* SECTIONS {
|
||||
.ram2bss (NOLOAD) : ALIGN(4) {
|
||||
*(.ram2bss);
|
||||
. = ALIGN(4);
|
||||
} > RAM2
|
||||
} INSERT AFTER .bss;
|
||||
*/
|
||||
|
||||
@@ -3,9 +3,12 @@ target extended-remote :3333
|
||||
# print demangled symbols
|
||||
set print asm-demangle on
|
||||
|
||||
# set backtrace limit to not have infinite backtrace loops
|
||||
set backtrace limit 32
|
||||
|
||||
# detect unhandled exceptions, hard faults and panics
|
||||
break DefaultHandler
|
||||
break UserHardFault
|
||||
break HardFault
|
||||
break rust_begin_unwind
|
||||
|
||||
# *try* to stop at the user entry point (it might be gone due to inlining)
|
||||
|
||||
@@ -7,10 +7,13 @@ extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to c
|
||||
// extern crate panic_itm; // logs messages over ITM; requires ITM support
|
||||
// extern crate panic_semihosting; // logs messages to the host stderr; requires a debugger
|
||||
|
||||
use cortex_m::asm;
|
||||
use cortex_m_rt::entry;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
asm::nop(); // To not have main optimize to abort in release mode, remove when you add code
|
||||
|
||||
loop {
|
||||
// your code goes here
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user