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