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