Skip to content

Commit

Permalink
Add ISR stuff to new build system
Browse files Browse the repository at this point in the history
  • Loading branch information
mcoffin committed May 15, 2015
1 parent b0bb488 commit 7065020
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
Cargo.lock
target
.cargo
*.o
*.bin
*.lst
7 changes: 0 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ authors = ["Zinc Developers <[email protected]>"]
name = "zinc"
crate-type = ["lib"]

[features]
mcu_lpc17xx = []
mcu_stm32f4 = []
mcu_stm32l1 = []
mcu_k20 = []
mcu_tiva_c = []

[dependencies.ioreg]
path = "./ioreg"

Expand Down
17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
TARGET=thumbv7m-none-eabi
STRIP=arm-none-eabi-strip
OBJCOPY=arm-none-eabi-objcopy
OBJDUMP=arm-none-eabi-objdump

PLATFORM_DIR=src/hal/$(PLATFORM)
LINK_SCRIPT=$(PLATFORM_DIR)/layout.ld

LDFLAGS=-mthumb -mcpu=cortex-m3 -T$(LINK_SCRIPT) -lm -lgcc -v
OUT_DIR=target/$(TARGET)/release
EXAMPLE_FILE=$(OUT_DIR)/examples/$(EXAMPLE_NAME)

EXAMPLE_FILE=target/$(TARGET)/release/examples/$(EXAMPLE_NAME)
ISR_SRC=src/hal/isr.rs
ISR_CRATE=$(shell rustc --print crate-name $(ISR_SRC))
ISR_FILE=$(ISR_CRATE).o

LDFLAGS=-mthumb -mcpu=cortex-m3 -T$(LINK_SCRIPT) -lm -lgcc $(ISR_FILE)

.PHONY: build clean listing
build: $(EXAMPLE_NAME).bin

clean:
-rm *.bin
-rm *.lst
-rm $(ISR_FILE)
cargo clean

listing: $(EXAMPLE_NAME).lst

$(EXAMPLE_FILE):
$(EXAMPLE_FILE): $(ISR_FILE)
cargo rustc --example $(EXAMPLE_NAME) --release --target=$(TARGET) --verbose -- -C link-args="$(LDFLAGS)"

$(EXAMPLE_NAME).bin: $(EXAMPLE_FILE)
$(OBJCOPY) -O binary $< $@

$(EXAMPLE_NAME).lst: $(EXAMPLE_FILE)
$(OBJDUMP) -D $< > $@

$(ISR_FILE): $(ISR_SRC)
rustc --target=$(TARGET) --emit=obj --cfg mcu_$(PLATFORM) -C opt-level=2 $<
$(STRIP) -N rust_begin_unwind -N rust_stack_exhausted -N rust_eh_personality $@
5 changes: 1 addition & 4 deletions src/hal/cortex_m3/isr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ extern {
fn isr_reserved_1();
}

// TODO(mcoffin) I removed "extern" here because it made no sense
// and created assertion problems in rustc. It may have been necessary; i don't
// really know what I'm doing with this.
#[cfg(not(test))]
#[no_mangle]
pub unsafe fn isr_handler_wrapper() {
pub unsafe extern fn isr_handler_wrapper() {
asm!(".weak isr_nmi, isr_hardfault, isr_mmfault, isr_busfault
.weak isr_usagefault, isr_svcall, isr_pendsv, isr_systick
.weak isr_debugmon
Expand Down
20 changes: 14 additions & 6 deletions src/hal/isr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@
//! This file is not part of zinc crate, it is linked separately, alongside the
//! ISRs for the platform.
#![feature(core, asm, lang_items, no_std)]
#![crate_name = "isr"]
#![crate_type = "staticlib"]
#![no_std]

#![allow(missing_docs)]

//#[path="cortex_m3/isr.rs"] pub mod isr_cortex_m3;
/*
#[cfg(feature = "mcu_lpc17xx")]
extern crate core;

#[path="cortex_m3/isr.rs"] pub mod isr_cortex_m3;

#[cfg(mcu_lpc17xx)]
#[path="lpc17xx/isr.rs"] pub mod isr_lpc17xx;

#[cfg(feature = "mcu_k20")]
#[cfg(mcu_k20)]
#[path="k20/isr.rs"] pub mod isr_k20;

#[cfg(feature = "mcu_tiva_c")]
#[cfg(mcu_tiva_c)]
#[path="tiva_c/isr.rs"] pub mod isr_tiva_c;
*/

#[path="../util/lang_items.rs"] mod lang_items;
2 changes: 0 additions & 2 deletions src/hal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@ pub mod spi;
pub mod stack;
pub mod timer;
pub mod uart;

pub mod isr;

0 comments on commit 7065020

Please sign in to comment.