Commit 3f950132 authored by Astro's avatar Astro
Browse files

l0dable: works!

parent c413addb
Pipeline #2511 failed with stage
in 11 minutes and 22 seconds
This diff is collapsed.
......@@ -2,7 +2,7 @@
runner = "gdb -q -x openocd.gdb"
rustflags = [
"-C", "linker=arm-none-eabihf-gcc",
"-C", "link-args=-Tl0dable.ld -pie -fPIC",
"-C", "link-args=-Tl0dable.ld -n -pie -fPIC",
"-C", "relocation-model=pic",
]
......
#![no_std]
#![no_main]
use core::fmt::Write;
use panic_abort as _;
use l0dable::entry;
use l0dable::*;
entry!(main);
fn main() -> ! {
loop {}
main!(main);
fn main() {
writeln!(UART, "Hello from Rust\r").unwrap();
let display = Display::open();
for x in 0..160 {
display.print(160 - x, 10, "Hello Rust\0", 0xffff, 0);
display.update();
}
}
......@@ -9,3 +9,4 @@ r0 = "0.2"
[build-dependencies]
cc = "1.0"
bindgen = "0.51"
\ No newline at end of file
......@@ -6,6 +6,7 @@ use std::path::PathBuf;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
// Linker script
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("l0dable.ld"))
.unwrap()
......@@ -14,6 +15,7 @@ fn main() {
println!("cargo:rustc-link-search={}", out.display());
println!("cargo:rerun-if-changed=l0dable.ld");
// Link against C code
cc::Build::new()
.target("thumbv7em-none-eabihf")
.compiler("arm-none-eabihf-gcc")
......@@ -29,6 +31,30 @@ fn main() {
.include("../c/lib/sdk/Libraries/CMSIS/Device/Maxim/MAX32665/Include")
.include("../c/lib/sdk/Libraries/CMSIS/Include")
.include("../c/lib/sdk/Libraries/MAX32665PeriphDriver/Include")
.file("../c/lib/sdk/Libraries/MAX32665PeriphDriver/Source/sema.c")
.file("../c/lib/sdk/Libraries/MAX32665PeriphDriver/Source/mxc_assert.c")
.file("../c/l0dables/lib/hardware.c")
.file("../c/epicardium/api/caller.c")
.file("src/client.c")
.compile("card10");
// Generate bindings to C code
let bindings = bindgen::Builder::default()
.clang_args(&[
"-Isrc",
"-I../c/epicardium",
"-I../c/lib/sdk/Libraries/CMSIS/Device/Maxim/MAX32665/Include",
"-I../c/lib/sdk/Libraries/CMSIS/Include",
"-I../c/lib/sdk/Libraries/MAX32665PeriphDriver/Include",
])
.header("src/bindings.h")
.use_core()
.ctypes_prefix("super::ctypes")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
......@@ -38,9 +38,6 @@ SECTIONS {
KEEP(*(.text.isr_vector))
*(.text*)
*(.rodata*)
KEEP(*(.init))
KEEP(*(.fini))
} :text
.data :
......@@ -75,5 +72,8 @@ SECTIONS {
*(.interp)
/* Dynamic linking section - nuke, we're not a .so and nothing is going to link against us. */
*(.dynamic)
*(.debug*)
*(.init .fini .ARM.exidx.text.*)
}
}
#include <epicardium.h>
This diff is collapsed.
use super::bindings::*;
pub struct Display;
impl Display {
pub fn open() -> Self {
unsafe { epic_disp_open(); }
Display
}
pub fn print(&self, x: u16, y: u16, s: &str, fg: u16, bg: u16) {
unsafe {
epic_disp_print(x, y, s.as_ptr(), fg, bg);
}
}
pub fn update(&self) {
unsafe {
epic_disp_update();
}
}
}
......@@ -5,12 +5,12 @@ global_asm!(include_str!("crt.s"));
/// Type check the user-supplied entry function.
#[macro_export]
macro_rules! entry {
macro_rules! main {
($path:path) => {
#[export_name = "main"]
pub unsafe fn __main() -> ! {
pub unsafe fn __main() {
// type check the given path
let f: fn() -> ! = $path;
let f: fn() = $path;
f()
}
......@@ -32,8 +32,44 @@ pub unsafe extern "C" fn Reset_Handler() -> ! {
SystemInit();
extern "Rust" {
fn main() -> !;
fn main();
}
main();
exit(0);
}
pub mod ctypes {
#![allow(non_camel_case_types)]
pub type c_int = i32;
pub type c_uint = u32;
pub type c_long = i32;
pub type c_ulong = u32;
pub type c_longlong = i64;
pub type c_ulonglong = u64;
pub type c_char = u8;
pub use core::ffi::c_void;
}
pub mod bindings {
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}
use bindings::*;
mod display;
pub use display::Display;
pub mod uart;
pub const UART: uart::Uart = uart::Uart;
pub fn exit(ret: i32) -> ! {
unsafe {
epic_exit(ret);
}
unreachable!()
}
use core::fmt::Write;
use super::bindings::*;
pub struct Uart;
impl Write for Uart {
fn write_str(&mut self, s: &str) -> core::fmt::Result {
unsafe {
epic_uart_write_str(s.as_ptr(), s.len() as isize);
}
Ok(())
}
}
......@@ -16,6 +16,8 @@ stdenv.mkDerivation {
RUST_BACKTRACE = 1;
shellHook = ''
export LIBCLANG_PATH=${llvmPackages.libclang}/lib
echo "Starting openocd…"
${openocd}/bin/openocd-card10 &
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment