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