stm32_rust_template/
main.rs

1//! # STM32 Rust Template
2//!
3//! A bare-metal Rust template for STM32 microcontrollers, providing a structured
4//! framework for embedded applications with modular drivers, BSP support, and
5//! application management.
6//!
7//! This crate serves as the main entry point, initializing the system and
8//! orchestrating application execution on Cortex-M4 based STM32 devices.
9#![no_std]
10#![no_main]
11
12extern crate alloc;
13use alloc::boxed::Box;
14use alloc_cortex_m::CortexMHeap;
15use cortex_m_rt::entry;
16use panic_halt as _;
17
18#[global_allocator]
19static ALLOCATOR: CortexMHeap = CortexMHeap::empty();
20
21const HEAP_SIZE: usize = 1024; // 1 KB
22
23mod apps;
24mod arch;
25mod bsp;
26mod components;
27mod driver;
28mod mcu;
29mod utils;
30
31use crate::apps::{init_all_apps, init_app_registry, register_app, run_all_loop_steps};
32
33#[entry]
34fn main() -> ! {
35    // Initialize the allocator
36    unsafe { ALLOCATOR.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE) };
37
38    // Initialize SysTick for 1ms interrupts (assuming 16 MHz system clock)
39    let _ = arch::cortex_m4::systick::systick_init_1ms(16_000_000);
40
41    // Initialize app registry
42    init_app_registry();
43
44    // Register apps
45    // register_app(Box::new(apps::empty::create_empty_app()));
46    register_app(Box::new(apps::blink::create_simple_blink_app()));
47
48    // Initialize all apps
49    if let Err(_) = init_all_apps() {
50        // Handle initialization error
51        loop {
52            cortex_m::asm::nop();
53        }
54    }
55
56    // Run the main loop
57    loop {
58        run_all_loop_steps();
59    }
60}