Skip to content

Instantly share code, notes, and snippets.

@lenaschoenburg
Created January 16, 2016 19:49
Show Gist options
  • Save lenaschoenburg/65ffc031eabea8a9b246 to your computer and use it in GitHub Desktop.
Save lenaschoenburg/65ffc031eabea8a9b246 to your computer and use it in GitHub Desktop.
#![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
Copy link

i bought a new Raspberry pi could you help me program it...please note that i have no programming experience or software except cmd

Copy link

ghost commented Jan 21, 2016

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