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