Skip to content

Instantly share code, notes, and snippets.

@thiagopnts
Created January 11, 2016 03:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagopnts/d7b6aca1a0446b5e2bfe to your computer and use it in GitHub Desktop.
Save thiagopnts/d7b6aca1a0446b5e2bfe to your computer and use it in GitHub Desktop.
turn ACT led on
#define GPIO_BASE 0x20200000UL
#define LED_GPFSEL 4
#define LED_GPFBIT 21
#define LED_GPSET 8
#define LED_GPCLR 11
#define LED_GPIO_BIT 15
volatile unsigned int* gpio;
int main(void)
{
gpio = (unsigned int*)GPIO_BASE;
while(1)
{
*(gpio+LED_GPSET) = (1 << LED_GPIO_BIT);
}
}
#![feature(no_std, lang_items, start)]
#![crate_type = "staticlib"]
#![no_std]
static GPIO_BASE: usize = 0x20200000;
static LED_GPFSEL: usize = 4;
static LED_GPFBIT: usize = 21;
static LED_GPSET: usize = 8;
static LED_GPCLR: usize = 11;
static LED_GPIO_BIT: usize = 15;
#[allow(dead_code)]
#[no_mangle]
pub fn main() -> ! {
loop {
unsafe {
*((GPIO_BASE + LED_GPSET) as *mut u16) = 1 << LED_GPIO_BIT;
};
}
}
#[lang = "rust_begin_unwind"] extern fn rust_begin_unwind() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() -> ! { loop {} }
#[no_mangle]
pub unsafe fn __aeabi_unwind_cpp_pr0() -> () {
loop {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment