stm32f429idiscovery/
main.rs

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