Created
January 16, 2016 19:49
-
-
Save lenaschoenburg/65ffc031eabea8a9b246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(lang_items, asm)] | |
#![crate_type = "staticlib"] | |
#![no_std] | |
const GPIO_BASE: u32 = 0x3F000000; | |
const GPIO_SET: u32 = 0x3F200020; | |
const GPIO_CLR: u32 = 0x3F20002C; | |
const GPIO47: u32 = 0x8000; | |
fn sleep(value: u32){ | |
for _ in 1..value { | |
unsafe { asm!("");} | |
} | |
} | |
fn gpio_set(port: u32, enabled: bool) { | |
let gpio = GPIO_BASE as *const u32; | |
let fun = match enabled { | |
true => GPIO_SET as *mut u32, | |
false => GPIO_CLR as *mut u32, | |
}; | |
unsafe { | |
*(fun) = port; | |
} | |
} | |
#[no_mangle] | |
pub extern fn main() { | |
loop { | |
gpio_set(GPIO47, true); | |
sleep(500000); | |
gpio_set(GPIO47, false); | |
sleep(500000); | |
} | |
} | |
#[lang = "eh_personality"] | |
extern fn eh_personality() {} | |
#[lang = "panic_fmt"] | |
extern fn panic_fmt() {} | |
;;; Compile with $ rustc --target arm-unknown-linux-gnueabihf -O --emit=obj kernel.rs | |
;;; The link with $ arm-none-eabi-gcc -O0 -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard -nostartfiles kernel.o -o kernel.elf | |
;;; Then build the image with $ arm-none-eabi-objcopy kernel.elf -O binary kernel.img |
Gershuan, you should see the RaspberryPi Resources section.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i bought a new Raspberry pi could you help me program it...please note that i have no programming experience or software except cmd