Skip to content

Commit f13bf4b

Browse files
committed
Implement LED blink module
- Added main loop to toggle LED using peripherals module - Introduced simple busy-wait delay for visible blinking - Uses cortex_m::asm::nop() for safe CPU wait - Fully no_std and no_main compatible for embedded targets - Prepares code for future timer-based non-blocking blink
1 parent b9a7fcb commit f13bf4b

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

examples/blinky.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
//! M2 Bootloader RUST
2-
//! ------------------
1+
//! M2 Bootloader RUST Blink Module
2+
//! -------------------------------
33
//! License : Dual License
44
//! - Apache 2.0 for open-source / personal use
55
//! - Commercial license required for closed-source use
66
//! Author : Md Mahbubur Rahman
77
//! URL : <https://m-a-h-b-u-b.github.io>
8-
//! GitHub : <https://github.com/m-a-h-b-u-b/M2-Bootloader-RUST>
8+
//! GitHub : <https://github.com/m-a-h-b-u-b/M2-Bootloader-Rust>
99
1010
#![no_std]
1111
#![no_main]
12+
13+
use cortex_m::asm;
1214
use cortex_m_rt::entry;
1315

16+
mod peripherals;
17+
1418
#[entry]
1519
fn main() -> ! {
20+
// Initialize LED
21+
peripherals::init_led();
22+
1623
loop {
17-
// Blink LED
24+
// Toggle LED state
25+
peripherals::toggle_led();
26+
27+
// Simple busy-wait delay for visible blink
28+
delay();
29+
}
30+
}
31+
32+
/// Busy-wait delay function
33+
#[inline(always)]
34+
fn delay() {
35+
// Adjust this value according to your MCU clock speed
36+
for _ in 0..5_000_000 {
37+
asm::nop();
1838
}
19-
}
39+
}

0 commit comments

Comments
 (0)