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