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