stm32f429idiscovery/
main.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Board file for STM32F429I Discovery development board
6//!
7//! - <https://www.st.com/en/evaluation-tools/32f429idiscovery.html>
8
9#![no_std]
10#![no_main]
11#![deny(missing_docs)]
12
13use core::ptr::{addr_of, addr_of_mut};
14
15use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
16use components::gpio::GpioComponent;
17use kernel::capabilities;
18use kernel::component::Component;
19use kernel::hil::led::LedHigh;
20use kernel::platform::{KernelResources, SyscallDriverLookup};
21use kernel::scheduler::round_robin::RoundRobinSched;
22use kernel::{create_capability, debug, static_init};
23
24use stm32f429zi::chip_specs::Stm32f429Specs;
25use stm32f429zi::clocks::hsi::HSI_FREQUENCY_MHZ;
26use stm32f429zi::gpio::{AlternateFunction, Mode, PinId, PortId};
27use stm32f429zi::interrupt_service::Stm32f429ziDefaultPeripherals;
28
29/// Support routines for debugging I/O.
30pub mod io;
31
32// Number of concurrent processes this platform supports.
33const NUM_PROCS: usize = 4;
34
35// Actual memory for holding the active process structures.
36static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] =
37    [None, None, None, None];
38
39static mut CHIP: Option<&'static stm32f429zi::chip::Stm32f4xx<Stm32f429ziDefaultPeripherals>> =
40    None;
41static mut PROCESS_PRINTER: Option<&'static capsules_system::process_printer::ProcessPrinterText> =
42    None;
43
44// How should the kernel respond when a process faults.
45const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
46    capsules_system::process_policies::PanicFaultPolicy {};
47
48/// Dummy buffer that causes the linker to reserve enough space for the stack.
49#[no_mangle]
50#[link_section = ".stack_buffer"]
51pub static mut STACK_MEMORY: [u8; 0x2000] = [0; 0x2000];
52
53type TemperatureSTMSensor = components::temperature_stm::TemperatureSTMComponentType<
54    capsules_core::virtualizers::virtual_adc::AdcDevice<'static, stm32f429zi::adc::Adc<'static>>,
55>;
56type TemperatureDriver = components::temperature::TemperatureComponentType<TemperatureSTMSensor>;
57
58/// A structure representing this platform that holds references to all
59/// capsules for this platform.
60struct STM32F429IDiscovery {
61    console: &'static capsules_core::console::Console<'static>,
62    ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
63    led: &'static capsules_core::led::LedDriver<
64        'static,
65        LedHigh<'static, stm32f429zi::gpio::Pin<'static>>,
66        4,
67    >,
68    button: &'static capsules_core::button::Button<'static, stm32f429zi::gpio::Pin<'static>>,
69    adc: &'static capsules_core::adc::AdcVirtualized<'static>,
70    alarm: &'static capsules_core::alarm::AlarmDriver<
71        'static,
72        VirtualMuxAlarm<'static, stm32f429zi::tim2::Tim2<'static>>,
73    >,
74    temperature: &'static TemperatureDriver,
75    gpio: &'static capsules_core::gpio::GPIO<'static, stm32f429zi::gpio::Pin<'static>>,
76
77    scheduler: &'static RoundRobinSched<'static>,
78    systick: cortexm4::systick::SysTick,
79}
80
81/// Mapping of integer syscalls to objects that implement syscalls.
82impl SyscallDriverLookup for STM32F429IDiscovery {
83    fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
84    where
85        F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
86    {
87        match driver_num {
88            capsules_core::console::DRIVER_NUM => f(Some(self.console)),
89            capsules_core::led::DRIVER_NUM => f(Some(self.led)),
90            capsules_core::button::DRIVER_NUM => f(Some(self.button)),
91            capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
92            capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
93            capsules_extra::temperature::DRIVER_NUM => f(Some(self.temperature)),
94            kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
95            capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
96            _ => f(None),
97        }
98    }
99}
100
101impl
102    KernelResources<
103        stm32f429zi::chip::Stm32f4xx<
104            'static,
105            stm32f429zi::interrupt_service::Stm32f429ziDefaultPeripherals<'static>,
106        >,
107    > for STM32F429IDiscovery
108{
109    type SyscallDriverLookup = Self;
110    type SyscallFilter = ();
111    type ProcessFault = ();
112    type Scheduler = RoundRobinSched<'static>;
113    type SchedulerTimer = cortexm4::systick::SysTick;
114    type WatchDog = ();
115    type ContextSwitchCallback = ();
116
117    fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
118        self
119    }
120    fn syscall_filter(&self) -> &Self::SyscallFilter {
121        &()
122    }
123    fn process_fault(&self) -> &Self::ProcessFault {
124        &()
125    }
126    fn scheduler(&self) -> &Self::Scheduler {
127        self.scheduler
128    }
129    fn scheduler_timer(&self) -> &Self::SchedulerTimer {
130        &self.systick
131    }
132    fn watchdog(&self) -> &Self::WatchDog {
133        &()
134    }
135    fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
136        &()
137    }
138}
139
140/// Helper function called during bring-up that configures DMA.
141unsafe fn setup_dma(
142    dma: &stm32f429zi::dma::Dma2,
143    dma_streams: &'static [stm32f429zi::dma::Stream<'static, stm32f429zi::dma::Dma2>; 8],
144    usart1: &'static stm32f429zi::usart::Usart<stm32f429zi::dma::Dma2>,
145) {
146    use stm32f429zi::dma::Dma2Peripheral;
147    use stm32f429zi::usart;
148
149    dma.enable_clock();
150
151    let usart1_tx_stream = &dma_streams[Dma2Peripheral::USART1_TX.get_stream_idx()];
152    let usart1_rx_stream = &dma_streams[Dma2Peripheral::USART1_RX.get_stream_idx()];
153
154    usart1.set_dma(
155        usart::TxDMA(usart1_tx_stream),
156        usart::RxDMA(usart1_rx_stream),
157    );
158
159    usart1_tx_stream.set_client(usart1);
160    usart1_rx_stream.set_client(usart1);
161
162    usart1_tx_stream.setup(Dma2Peripheral::USART1_TX);
163    usart1_rx_stream.setup(Dma2Peripheral::USART1_RX);
164
165    cortexm4::nvic::Nvic::new(Dma2Peripheral::USART1_TX.get_stream_irqn()).enable();
166    cortexm4::nvic::Nvic::new(Dma2Peripheral::USART1_RX.get_stream_irqn()).enable();
167}
168
169/// Helper function called during bring-up that configures multiplexed I/O.
170unsafe fn set_pin_primary_functions(
171    syscfg: &stm32f429zi::syscfg::Syscfg,
172    gpio_ports: &'static stm32f429zi::gpio::GpioPorts<'static>,
173) {
174    use kernel::hil::gpio::Configure;
175
176    syscfg.enable_clock();
177
178    gpio_ports.get_port_from_port_id(PortId::G).enable_clock();
179
180    // User LD4 (red) is connected to PG14. Configure PG14 as `debug_gpio!(0, ...)`
181    gpio_ports.get_pin(PinId::PG14).map(|pin| {
182        pin.make_output();
183
184        // Configure kernel debug gpios as early as possible
185        kernel::debug::assign_gpios(Some(pin), None, None);
186    });
187
188    gpio_ports.get_port_from_port_id(PortId::A).enable_clock();
189
190    // Configure USART1 on Pins PA09 and PA10.
191    // USART1 is connected to ST-LINK virtual COM port on Rev.1 of the Stm32f429i Discovery board
192    gpio_ports.get_pin(PinId::PA09).map(|pin| {
193        pin.set_mode(Mode::AlternateFunctionMode);
194        // AF7 is USART1_TX
195        pin.set_alternate_function(AlternateFunction::AF7);
196    });
197    gpio_ports.get_pin(PinId::PA10).map(|pin| {
198        pin.set_mode(Mode::AlternateFunctionMode);
199        // AF7 is USART1_RX
200        pin.set_alternate_function(AlternateFunction::AF7);
201    });
202
203    // User button B1 is connected on pa00
204    gpio_ports.get_pin(PinId::PA00).map(|pin| {
205        // By default, upon reset, the pin is in input mode, with no internal
206        // pull-up, no internal pull-down (i.e., floating).
207        //
208        // Only set the mapping between EXTI line and the Pin and let capsule do
209        // the rest.
210        pin.enable_interrupt();
211    });
212    // EXTI0 interrupts is delivered at IRQn 6 (EXTI0)
213    cortexm4::nvic::Nvic::new(stm32f429zi::nvic::EXTI0).enable(); // TODO check if this is still necessary!
214
215    // Enable clocks for GPIO Ports
216    // Disable some of them if you don't need some of the GPIOs
217    // Ports A, and B are already enabled
218    //           A: already enabled
219    gpio_ports.get_port_from_port_id(PortId::B).enable_clock();
220    gpio_ports.get_port_from_port_id(PortId::C).enable_clock();
221    gpio_ports.get_port_from_port_id(PortId::D).enable_clock();
222    gpio_ports.get_port_from_port_id(PortId::E).enable_clock();
223    gpio_ports.get_port_from_port_id(PortId::F).enable_clock();
224    //           G: already enabled
225    gpio_ports.get_port_from_port_id(PortId::H).enable_clock();
226
227    // Arduino A0
228    gpio_ports.get_pin(PinId::PA03).map(|pin| {
229        pin.set_mode(stm32f429zi::gpio::Mode::AnalogMode);
230    });
231
232    // Arduino A1
233    gpio_ports.get_pin(PinId::PC00).map(|pin| {
234        pin.set_mode(stm32f429zi::gpio::Mode::AnalogMode);
235    });
236
237    // Arduino A2
238    gpio_ports.get_pin(PinId::PC03).map(|pin| {
239        pin.set_mode(stm32f429zi::gpio::Mode::AnalogMode);
240    });
241
242    // Arduino A3
243    gpio_ports.get_pin(PinId::PF03).map(|pin| {
244        pin.set_mode(stm32f429zi::gpio::Mode::AnalogMode);
245    });
246
247    // Arduino A4
248    gpio_ports.get_pin(PinId::PF05).map(|pin| {
249        pin.set_mode(stm32f429zi::gpio::Mode::AnalogMode);
250    });
251
252    // Arduino A5
253    gpio_ports.get_pin(PinId::PF10).map(|pin| {
254        pin.set_mode(stm32f429zi::gpio::Mode::AnalogMode);
255    });
256}
257
258/// Helper function for miscellaneous peripheral functions
259unsafe fn setup_peripherals(tim2: &stm32f429zi::tim2::Tim2) {
260    // USART1 IRQn is 37
261    cortexm4::nvic::Nvic::new(stm32f429zi::nvic::USART1).enable();
262
263    // TIM2 IRQn is 28
264    tim2.enable_clock();
265    tim2.start();
266    cortexm4::nvic::Nvic::new(stm32f429zi::nvic::TIM2).enable();
267}
268
269/// Main function
270///
271/// This is in a separate, inline(never) function so that its stack frame is
272/// removed when this function returns. Otherwise, the stack space used for
273/// these static_inits is wasted.
274#[inline(never)]
275unsafe fn start() -> (
276    &'static kernel::Kernel,
277    STM32F429IDiscovery,
278    &'static stm32f429zi::chip::Stm32f4xx<'static, Stm32f429ziDefaultPeripherals<'static>>,
279) {
280    stm32f429zi::init();
281
282    // We use the default HSI 16Mhz clock
283    let rcc = static_init!(stm32f429zi::rcc::Rcc, stm32f429zi::rcc::Rcc::new());
284    let clocks = static_init!(
285        stm32f429zi::clocks::Clocks<Stm32f429Specs>,
286        stm32f429zi::clocks::Clocks::new(rcc)
287    );
288    let syscfg = static_init!(
289        stm32f429zi::syscfg::Syscfg,
290        stm32f429zi::syscfg::Syscfg::new(clocks)
291    );
292    let exti = static_init!(
293        stm32f429zi::exti::Exti,
294        stm32f429zi::exti::Exti::new(syscfg)
295    );
296    let dma1 = static_init!(stm32f429zi::dma::Dma1, stm32f429zi::dma::Dma1::new(clocks));
297    let dma2 = static_init!(stm32f429zi::dma::Dma2, stm32f429zi::dma::Dma2::new(clocks));
298    let peripherals = static_init!(
299        Stm32f429ziDefaultPeripherals,
300        Stm32f429ziDefaultPeripherals::new(clocks, exti, dma1, dma2)
301    );
302
303    peripherals.init();
304    let base_peripherals = &peripherals.stm32f4;
305
306    setup_peripherals(&base_peripherals.tim2);
307
308    set_pin_primary_functions(syscfg, &base_peripherals.gpio_ports);
309
310    setup_dma(
311        dma2,
312        &base_peripherals.dma2_streams,
313        &base_peripherals.usart1,
314    );
315
316    let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));
317
318    let chip = static_init!(
319        stm32f429zi::chip::Stm32f4xx<Stm32f429ziDefaultPeripherals>,
320        stm32f429zi::chip::Stm32f4xx::new(peripherals)
321    );
322    CHIP = Some(chip);
323
324    // UART
325
326    // Create a shared UART channel for kernel debug.
327    // USART1 is only connected to the ST-LINK port in the DISC1 revision of
328    // the STM32F429I boards, DISC0 does not have this connection and will
329    // not have USART output available!
330    base_peripherals.usart1.enable_clock();
331    let uart_mux = components::console::UartMuxComponent::new(&base_peripherals.usart1, 115200)
332        .finalize(components::uart_mux_component_static!());
333
334    (*addr_of_mut!(io::WRITER)).set_initialized();
335
336    // Create capabilities that the board needs to call certain protected kernel
337    // functions.
338    let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
339    let process_management_capability =
340        create_capability!(capabilities::ProcessManagementCapability);
341
342    // Setup the console.
343    let console = components::console::ConsoleComponent::new(
344        board_kernel,
345        capsules_core::console::DRIVER_NUM,
346        uart_mux,
347    )
348    .finalize(components::console_component_static!());
349    // Create the debugger object that handles calls to `debug!()`.
350    components::debug_writer::DebugWriterComponent::new(
351        uart_mux,
352        create_capability!(capabilities::SetDebugWriterCapability),
353    )
354    .finalize(components::debug_writer_component_static!());
355
356    // LEDs
357
358    // Clock to all GPIO Ports is enabled in `set_pin_primary_functions()`
359    let gpio_ports = &base_peripherals.gpio_ports;
360
361    let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
362        LedHigh<'static, stm32f429zi::gpio::Pin>,
363        LedHigh::new(gpio_ports.get_pin(stm32f429zi::gpio::PinId::PG13).unwrap()),
364        LedHigh::new(gpio_ports.get_pin(stm32f429zi::gpio::PinId::PG14).unwrap()),
365        LedHigh::new(gpio_ports.get_pin(stm32f429zi::gpio::PinId::PB13).unwrap()),
366        LedHigh::new(gpio_ports.get_pin(stm32f429zi::gpio::PinId::PC05).unwrap()),
367    ));
368
369    // BUTTONs
370    let button = components::button::ButtonComponent::new(
371        board_kernel,
372        capsules_core::button::DRIVER_NUM,
373        components::button_component_helper!(
374            stm32f429zi::gpio::Pin,
375            (
376                gpio_ports.get_pin(stm32f429zi::gpio::PinId::PA00).unwrap(),
377                kernel::hil::gpio::ActivationMode::ActiveHigh,
378                kernel::hil::gpio::FloatingState::PullNone
379            )
380        ),
381    )
382    .finalize(components::button_component_static!(stm32f429zi::gpio::Pin));
383
384    // ALARM
385
386    let tim2 = &base_peripherals.tim2;
387    let mux_alarm = components::alarm::AlarmMuxComponent::new(tim2).finalize(
388        components::alarm_mux_component_static!(stm32f429zi::tim2::Tim2),
389    );
390
391    let alarm = components::alarm::AlarmDriverComponent::new(
392        board_kernel,
393        capsules_core::alarm::DRIVER_NUM,
394        mux_alarm,
395    )
396    .finalize(components::alarm_component_static!(stm32f429zi::tim2::Tim2));
397
398    // GPIO
399    let gpio = GpioComponent::new(
400        board_kernel,
401        capsules_core::gpio::DRIVER_NUM,
402        components::gpio_component_helper!(
403            stm32f429zi::gpio::Pin,
404            // Arduino like RX/TX
405            0 => gpio_ports.get_pin(PinId::PG09).unwrap(), //D0
406            1 => gpio_ports.pins[6][14].as_ref().unwrap(), //D1
407            2 => gpio_ports.pins[5][15].as_ref().unwrap(), //D2
408            3 => gpio_ports.pins[4][13].as_ref().unwrap(), //D3
409            4 => gpio_ports.pins[5][14].as_ref().unwrap(), //D4
410            5 => gpio_ports.pins[4][11].as_ref().unwrap(), //D5
411            6 => gpio_ports.pins[4][9].as_ref().unwrap(), //D6
412            7 => gpio_ports.pins[5][13].as_ref().unwrap(), //D7
413            8 => gpio_ports.pins[5][12].as_ref().unwrap(), //D8
414            9 => gpio_ports.pins[3][15].as_ref().unwrap(), //D9
415            // SPI Pins
416            10 => gpio_ports.pins[3][14].as_ref().unwrap(), //D10
417            11 => gpio_ports.pins[0][7].as_ref().unwrap(),  //D11
418            12 => gpio_ports.pins[0][6].as_ref().unwrap(),  //D12
419            13 => gpio_ports.pins[0][5].as_ref().unwrap(),  //D13
420            // I2C Pins
421            14 => gpio_ports.pins[1][9].as_ref().unwrap(), //D14
422            15 => gpio_ports.pins[1][8].as_ref().unwrap(), //D15
423            16 => gpio_ports.pins[2][6].as_ref().unwrap(), //D16
424            17 => gpio_ports.pins[1][15].as_ref().unwrap(), //D17
425            18 => gpio_ports.pins[1][13].as_ref().unwrap(), //D18
426            19 => gpio_ports.pins[1][12].as_ref().unwrap(), //D19
427            20 => gpio_ports.pins[0][15].as_ref().unwrap(), //D20
428            21 => gpio_ports.pins[2][7].as_ref().unwrap(), //D21
429            // SPI B Pins
430            // 22 => gpio_ports.pins[1][5].as_ref().unwrap(), //D22
431            // 23 => gpio_ports.pins[1][3].as_ref().unwrap(), //D23
432            // 24 => gpio_ports.pins[0][4].as_ref().unwrap(), //D24
433            // 24 => gpio_ports.pins[1][4].as_ref().unwrap(), //D25
434            // QSPI
435            26 => gpio_ports.pins[1][6].as_ref().unwrap(), //D26
436            27 => gpio_ports.pins[1][2].as_ref().unwrap(), //D27
437            28 => gpio_ports.pins[3][13].as_ref().unwrap(), //D28
438            29 => gpio_ports.pins[3][12].as_ref().unwrap(), //D29
439            30 => gpio_ports.pins[3][11].as_ref().unwrap(), //D30
440            31 => gpio_ports.pins[4][2].as_ref().unwrap(), //D31
441            // Timer Pins
442            // PA00 (or PIN[0][0]) is used for the button component so cannot
443            // be used for this component as well, otherwise interrupts will
444            // not reach the button component.
445            // 32 => stm32f429zi::gpio::PIN[0][0].as_ref().unwrap(), //D32
446            33 => gpio_ports.pins[1][0].as_ref().unwrap(), //D33
447            34 => gpio_ports.pins[4][0].as_ref().unwrap(), //D34
448            35 => gpio_ports.pins[1][11].as_ref().unwrap(), //D35
449            36 => gpio_ports.pins[1][10].as_ref().unwrap(), //D36
450            37 => gpio_ports.pins[4][15].as_ref().unwrap(), //D37
451            38 => gpio_ports.pins[4][14].as_ref().unwrap(), //D38
452            39 => gpio_ports.pins[4][12].as_ref().unwrap(), //D39
453            40 => gpio_ports.pins[4][10].as_ref().unwrap(), //D40
454            41 => gpio_ports.pins[4][7].as_ref().unwrap(), //D41
455            42 => gpio_ports.pins[4][8].as_ref().unwrap(), //D42
456            // SDMMC
457            43 => gpio_ports.pins[2][8].as_ref().unwrap(), //D43
458            44 => gpio_ports.pins[2][9].as_ref().unwrap(), //D44
459            45 => gpio_ports.pins[2][10].as_ref().unwrap(), //D45
460            46 => gpio_ports.pins[2][11].as_ref().unwrap(), //D46
461            47 => gpio_ports.pins[2][12].as_ref().unwrap(), //D47
462            48 => gpio_ports.pins[3][2].as_ref().unwrap(), //D48
463            49 => gpio_ports.pins[6][2].as_ref().unwrap(), //D49
464            50 => gpio_ports.pins[6][3].as_ref().unwrap(), //D50
465            // USART
466            51 => gpio_ports.pins[3][7].as_ref().unwrap(), //D51
467            52 => gpio_ports.pins[3][6].as_ref().unwrap(), //D52
468            53 => gpio_ports.pins[3][5].as_ref().unwrap(), //D53
469            54 => gpio_ports.pins[3][4].as_ref().unwrap(), //D54
470            55 => gpio_ports.pins[3][3].as_ref().unwrap(), //D55
471            56 => gpio_ports.pins[4][2].as_ref().unwrap(), //D56
472            57 => gpio_ports.pins[4][4].as_ref().unwrap(), //D57
473            58 => gpio_ports.pins[4][5].as_ref().unwrap(), //D58
474            59 => gpio_ports.pins[4][6].as_ref().unwrap(), //D59
475            60 => gpio_ports.pins[4][3].as_ref().unwrap(), //D60
476            61 => gpio_ports.pins[5][8].as_ref().unwrap(), //D61
477            62 => gpio_ports.pins[5][7].as_ref().unwrap(), //D62
478            63 => gpio_ports.pins[5][9].as_ref().unwrap(), //D63
479            64 => gpio_ports.pins[6][1].as_ref().unwrap(), //D64
480            65 => gpio_ports.pins[6][0].as_ref().unwrap(), //D65
481            66 => gpio_ports.pins[3][1].as_ref().unwrap(), //D66
482            67 => gpio_ports.pins[3][0].as_ref().unwrap(), //D67
483            68 => gpio_ports.pins[5][0].as_ref().unwrap(), //D68
484            69 => gpio_ports.pins[5][1].as_ref().unwrap(), //D69
485            70 => gpio_ports.pins[5][2].as_ref().unwrap(), //D70
486            71 => gpio_ports.pins[0][7].as_ref().unwrap()  //D71
487
488            // ADC Pins
489            // Enable the to use the ADC pins as GPIO
490            // 72 => gpio_ports.pins[0][3].as_ref().unwrap(), //A0
491            // 73 => gpio_ports.pins[2][0].as_ref().unwrap(), //A1
492            // 74 gpio_ports.pins::PIN[2][3].as_ref().unwrap(), //A2
493            // 75 gpio_ports.pins::PIN[5][3].as_ref().unwrap(), //A3
494            // 76 gpio_ports.pins::PIN[5][5].as_ref().unwrap(), //A4
495            // 77 gpio_ports.pins::PIN[5][10].as_ref().unwrap(), //A5
496            // 78 gpio_ports.pins::PIN[1][1].as_ref().unwrap(), //A6
497            // 79 gpio_ports.pins::PIN[2][2].as_ref().unwrap(), //A7
498            // 80 gpio_ports.pins::PIN[5][4].as_ref().unwrap()  //A8
499        ),
500    )
501    .finalize(components::gpio_component_static!(stm32f429zi::gpio::Pin));
502
503    // ADC
504    let adc_mux = components::adc::AdcMuxComponent::new(&base_peripherals.adc1)
505        .finalize(components::adc_mux_component_static!(stm32f429zi::adc::Adc));
506
507    let temp_sensor = components::temperature_stm::TemperatureSTMComponent::new(
508        adc_mux,
509        stm32f429zi::adc::Channel::Channel18,
510        2.5,
511        0.76,
512    )
513    .finalize(components::temperature_stm_adc_component_static!(
514        stm32f429zi::adc::Adc
515    ));
516
517    let temp = components::temperature::TemperatureComponent::new(
518        board_kernel,
519        capsules_extra::temperature::DRIVER_NUM,
520        temp_sensor,
521    )
522    .finalize(components::temperature_component_static!(
523        TemperatureSTMSensor
524    ));
525
526    let adc_channel_0 =
527        components::adc::AdcComponent::new(adc_mux, stm32f429zi::adc::Channel::Channel3)
528            .finalize(components::adc_component_static!(stm32f429zi::adc::Adc));
529
530    let adc_channel_1 =
531        components::adc::AdcComponent::new(adc_mux, stm32f429zi::adc::Channel::Channel10)
532            .finalize(components::adc_component_static!(stm32f429zi::adc::Adc));
533
534    let adc_channel_2 =
535        components::adc::AdcComponent::new(adc_mux, stm32f429zi::adc::Channel::Channel13)
536            .finalize(components::adc_component_static!(stm32f429zi::adc::Adc));
537
538    let adc_channel_3 =
539        components::adc::AdcComponent::new(adc_mux, stm32f429zi::adc::Channel::Channel9)
540            .finalize(components::adc_component_static!(stm32f429zi::adc::Adc));
541
542    let adc_channel_4 =
543        components::adc::AdcComponent::new(adc_mux, stm32f429zi::adc::Channel::Channel15)
544            .finalize(components::adc_component_static!(stm32f429zi::adc::Adc));
545
546    let adc_channel_5 =
547        components::adc::AdcComponent::new(adc_mux, stm32f429zi::adc::Channel::Channel8)
548            .finalize(components::adc_component_static!(stm32f429zi::adc::Adc));
549
550    let adc_syscall =
551        components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
552            .finalize(components::adc_syscall_component_helper!(
553                adc_channel_0,
554                adc_channel_1,
555                adc_channel_2,
556                adc_channel_3,
557                adc_channel_4,
558                adc_channel_5
559            ));
560
561    let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
562        .finalize(components::process_printer_text_component_static!());
563    PROCESS_PRINTER = Some(process_printer);
564
565    // PROCESS CONSOLE
566    let process_console = components::process_console::ProcessConsoleComponent::new(
567        board_kernel,
568        uart_mux,
569        mux_alarm,
570        process_printer,
571        Some(cortexm4::support::reset),
572    )
573    .finalize(components::process_console_component_static!(
574        stm32f429zi::tim2::Tim2
575    ));
576    let _ = process_console.start();
577
578    let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
579        .finalize(components::round_robin_component_static!(NUM_PROCS));
580
581    let stm32f429i_discovery = STM32F429IDiscovery {
582        console,
583        ipc: kernel::ipc::IPC::new(
584            board_kernel,
585            kernel::ipc::DRIVER_NUM,
586            &memory_allocation_capability,
587        ),
588        adc: adc_syscall,
589        led,
590        temperature: temp,
591        button,
592        alarm,
593        gpio,
594
595        scheduler,
596        systick: cortexm4::systick::SysTick::new_with_calibration(
597            (HSI_FREQUENCY_MHZ * 1_000_000) as u32,
598        ),
599    };
600
601    // // Optional kernel tests
602    // //
603    // // See comment in `boards/imix/src/main.rs`
604    // virtual_uart_rx_test::run_virtual_uart_receive(mux_uart);
605
606    debug!("Initialization complete. Entering main loop");
607
608    // These symbols are defined in the linker script.
609    extern "C" {
610        /// Beginning of the ROM region containing app images.
611        static _sapps: u8;
612        /// End of the ROM region containing app images.
613        static _eapps: u8;
614        /// Beginning of the RAM region for app memory.
615        static mut _sappmem: u8;
616        /// End of the RAM region for app memory.
617        static _eappmem: u8;
618    }
619
620    kernel::process::load_processes(
621        board_kernel,
622        chip,
623        core::slice::from_raw_parts(
624            core::ptr::addr_of!(_sapps),
625            core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
626        ),
627        core::slice::from_raw_parts_mut(
628            core::ptr::addr_of_mut!(_sappmem),
629            core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
630        ),
631        &mut *addr_of_mut!(PROCESSES),
632        &FAULT_RESPONSE,
633        &process_management_capability,
634    )
635    .unwrap_or_else(|err| {
636        debug!("Error loading processes!");
637        debug!("{:?}", err);
638    });
639
640    //Uncomment to run multi alarm test
641    /*components::test::multi_alarm_test::MultiAlarmTestComponent::new(mux_alarm)
642    .finalize(components::multi_alarm_test_component_buf!(stm32f429zi::tim2::Tim2))
643    .run();*/
644
645    (board_kernel, stm32f429i_discovery, chip)
646}
647
648/// Main function called after RAM initialized.
649#[no_mangle]
650pub unsafe fn main() {
651    let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
652
653    let (board_kernel, platform, chip) = start();
654    board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
655}