Skip to content

Commit 2484282

Browse files
committed
Convert std project into a no_std project
1 parent fed4a09 commit 2484282

File tree

8 files changed

+308
-9
lines changed

8 files changed

+308
-9
lines changed

.cargo/config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[target.thumbv7em-none-eabihf]
2+
runner = 'arm-none-eabi-gdb'
3+
rustflags = [
4+
"-C", "link-arg=-Wl,-Tlink.x",
5+
"-C", "link-arg=-nostartfiles",
6+
7+
# uncomment to use rustc LLD to link programs (a)
8+
# "-C", "link-arg=-Tlink.x",
9+
# "-C", "linker=lld",
10+
# "-Z", "linker-flavor=ld.lld",
11+
]
12+
13+
[build]
14+
target = "thumbv7em-none-eabihf"

.gdbinit

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
target remote :3333
2+
3+
# print demangled symbols by default
4+
set print asm-demangle on
5+
6+
monitor arm semihosting enable
7+
8+
# # send captured ITM to the file itm.fifo
9+
# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
10+
# # 8000000 must match the core clock frequency
11+
# monitor tpiu config internal itm.fifo uart off 8000000
12+
13+
# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
14+
# # 2000000 is the frequency of the SWO pin
15+
# monitor tpiu config external uart off 8000000 2000000
16+
17+
# # enable ITM port 0
18+
# monitor itm port 0 on
19+
20+
load
21+
step

Cargo.lock

Lines changed: 153 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,20 @@ version = "0.0.1"
44
authors = ["jonlamb-gh <lamb.jon.io@gmail.com>"]
55

66
[dependencies]
7+
cortex-m = "0.5.2"
8+
cortex-m-semihosting = "0.3.0"
9+
panic-semihosting = "0.3.0"
10+
11+
[dependencies.cortex-m-rt]
12+
version = "0.5.1"
13+
features = ["device"]
14+
15+
[dependencies.nucleo-f767zi]
16+
version = "0.0.1"
17+
git = "https://github.com/jonlamb-gh/nucleo-f767zi.git"
18+
branch = "devel"
19+
features = ["rt"]
20+
21+
[profile.release]
22+
codegen-units = 1 # better optimizations
23+
lto = true # better optimizations

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,30 @@
1-
# oxcc
1+
# oxcc
2+
3+
## Building
4+
5+
```bash
6+
# rustc 1.29.0-nightly (54628c8ea 2018-07-30)
7+
cargo build
8+
```
9+
10+
## Debugging
11+
12+
```bash
13+
./scripts/run-openocd
14+
15+
# or manually
16+
# openocd -f board/stm32f7discovery.cfg
17+
```
18+
19+
```bash
20+
cargo run
21+
22+
# or manually
23+
# arm-none-eabi-gdb target/thumbv7em-none-eabihf/debug/oxcc
24+
```
25+
26+
## Links
27+
28+
- [BSP crate](https://github.com/jonlamb-gh/nucleo-f767zi)
29+
- [HAL crate](https://github.com/jonlamb-gh/stm32f767-hal)
30+
- [device crate](https://github.com/adamgreig/stm32-rs/tree/master/stm32f7)

memory.x

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
MEMORY
2+
{
3+
/* NOTE K = KiBi = 1024 bytes */
4+
5+
/* STM32F767ZI 2 MByte FLASH, 512 KByte RAM */
6+
FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 2048K
7+
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 512K
8+
}
9+
10+
/* This is where the call stack will be allocated. */
11+
/* The stack is of the full descending type. */
12+
/* You may want to use this variable to locate the call stack and static
13+
variables in different memory regions. Below is shown the default value */
14+
/* _stack_start = ORIGIN(RAM) + LENGTH(RAM); */
15+
16+
/* You can use this symbol to customize the location of the .text section */
17+
/* If omitted the .text section will be placed right after the .vector_table
18+
section */
19+
/* This is required only on microcontrollers that store some configuration right
20+
after the vector table */
21+
/* _stext = ORIGIN(FLASH) + 0x400; */
22+
23+
/* Size of the heap (in bytes) */
24+
/* _heap_size = 1024; */

scripts/run-openocd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
openocd -f board/stm32f7discovery.cfg
6+
7+
exit 0

src/main.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,51 @@
1-
// https://github.com/PolySync/oscc/wiki/Hardware-Main
2-
// https://github.com/jonlamb-gh/oscc/
1+
#![no_main]
2+
#![no_std]
3+
4+
extern crate cortex_m;
5+
#[macro_use]
6+
extern crate cortex_m_rt as rt;
7+
extern crate cortex_m_semihosting as sh;
8+
extern crate nucleo_f767zi;
9+
extern crate panic_semihosting;
310

411
mod fault_condition;
512
mod pid;
613
mod throttle_module;
714

8-
use throttle_module::ThrottleModule;
15+
use core::fmt::Write;
16+
use cortex_m::peripheral::syst::SystClkSource;
17+
use nucleo_f767zi::hal::stm32f7x7;
18+
use rt::ExceptionFrame;
19+
use sh::hio;
20+
21+
entry!(main);
22+
23+
fn main() -> ! {
24+
let mut stdout = hio::hstdout().unwrap();
25+
let peripherals = cortex_m::Peripherals::take().unwrap();
26+
//let peripherals = stm32f7x7::Peripherals::take().unwrap();
27+
28+
let mut syst = peripherals.SYST;
29+
30+
// need to fix/add HAL RCC to get full clock speed
31+
syst.set_clock_source(SystClkSource::Core);
32+
syst.set_reload(8_000_000); // 1s
33+
syst.enable_counter();
934

10-
fn main() {
11-
println!("Hello, world!");
35+
loop {
36+
while !syst.has_wrapped() {}
37+
writeln!(stdout, "Hello, world!").unwrap();
38+
}
39+
}
40+
41+
exception!(HardFault, hard_fault);
42+
43+
fn hard_fault(ef: &ExceptionFrame) -> ! {
44+
panic!("HardFault at {:#?}", ef);
45+
}
1246

13-
let _throttle_module = ThrottleModule::new();
47+
exception!(*, default_handler);
1448

15-
println!("All done");
49+
fn default_handler(irqn: i16) {
50+
panic!("Unhandled exception (IRQn = {})", irqn);
1651
}

0 commit comments

Comments
 (0)