Skip to content
Snippets Groups Projects
Commit 17d4b71c authored by Vlăduț-Andrei CHINȚOIU's avatar Vlăduț-Andrei CHINȚOIU Committed by Alexandru RADOVICI
Browse files

Code corrections

parent 87b38ae3
No related branches found
No related tags found
No related merge requests found
...@@ -84,11 +84,12 @@ This is how a Rust application would look like ...@@ -84,11 +84,12 @@ This is how a Rust application would look like
<div grid="~ cols-2 gap-4"> <div grid="~ cols-2 gap-4">
```rust{all|1|2|4|6|7,11|10|13-16} ```rust{all|1|2|4,5|7|8,12|11|14-17}
#![no_std] #![no_std]
#![no_main] #![no_main]
use cortex_m_rt::entry; use cortex_m_rt::entry;
use core::panic::PanicInfo;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
...@@ -126,6 +127,7 @@ This is how a Rust application would look like ...@@ -126,6 +127,7 @@ This is how a Rust application would look like
use core::ptr::{read_volatile, write_volatile}; use core::ptr::{read_volatile, write_volatile};
use cortex_m_rt::entry; use cortex_m_rt::entry;
use core::panic::PanicInfo;
const GPIOX_CTRL: u32 = 0x4001_4004; const GPIOX_CTRL: u32 = 0x4001_4004;
const GPIO_OE_SET: *mut u32= 0xd000_0024 as *mut u32; const GPIO_OE_SET: *mut u32= 0xd000_0024 as *mut u32;
...@@ -134,25 +136,25 @@ const GPIO_OUT_CLR:*mut u32= 0xd000_0018 as *mut u32; ...@@ -134,25 +136,25 @@ const GPIO_OUT_CLR:*mut u32= 0xd000_0018 as *mut u32;
#[panic_handler] #[panic_handler]
pub fn panic(_info: &PanicInfo) -> ! { pub fn panic(_info: &PanicInfo) -> ! {
loop { } loop { }
} }
``` ```
```rust {all}{startLine:18} ```rust {all}{startLine:18}
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let gpio_ctrl = GPIOX_CTRL + 8 * pin as *mut u32; let gpio_ctrl = (GPIOX_CTRL + 8 * pin) as *mut u32;
unsafe { unsafe {
write_volatile(gpio_ctrl, 5); write_volatile(gpio_ctrl, 5);
write_volatile(GPIO_OE_SET, 1 << pin); write_volatile(GPIO_OE_SET, 1 << pin);
let reg = match value { let reg = match value {
0 => GPIO_OUT_CLR, 0 => GPIO_OUT_CLR,
_ => GPIO_OUT_SET _ => GPIO_OUT_SET
}; };
write_volatile(reg, 1 << pin); write_volatile(reg, 1 << pin);
}; };
loop { } loop { }
} }
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment