1#![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 components::rng::RngComponent;
18use kernel::capabilities;
19use kernel::component::Component;
20use kernel::hil::gpio;
21use kernel::hil::led::LedLow;
22use kernel::hil::screen::ScreenRotation;
23use kernel::platform::{KernelResources, SyscallDriverLookup};
24use kernel::process::ProcessArray;
25use kernel::scheduler::round_robin::RoundRobinSched;
26use kernel::{create_capability, debug, static_init};
27use stm32f412g::chip_specs::Stm32f412Specs;
28use stm32f412g::clocks::hsi::HSI_FREQUENCY_MHZ;
29use stm32f412g::interrupt_service::Stm32f412gDefaultPeripherals;
30use stm32f412g::rcc::PllSource;
31
32pub mod io;
34
35const NUM_PROCS: usize = 4;
37
38static mut PROCESSES: Option<&'static ProcessArray<NUM_PROCS>> = None;
40static mut CHIP: Option<&'static stm32f412g::chip::Stm32f4xx<Stm32f412gDefaultPeripherals>> = None;
41static mut PROCESS_PRINTER: Option<&'static capsules_system::process_printer::ProcessPrinterText> =
42 None;
43
44const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
46 capsules_system::process_policies::PanicFaultPolicy {};
47
48#[no_mangle]
50#[link_section = ".stack_buffer"]
51static mut STACK_MEMORY: [u8; 0x2000] = [0; 0x2000];
52
53type TemperatureSTMSensor = components::temperature_stm::TemperatureSTMComponentType<
54 capsules_core::virtualizers::virtual_adc::AdcDevice<'static, stm32f412g::adc::Adc<'static>>,
55>;
56type TemperatureDriver = components::temperature::TemperatureComponentType<TemperatureSTMSensor>;
57type RngDriver = components::rng::RngComponentType<stm32f412g::trng::Trng<'static>>;
58
59struct STM32F412GDiscovery {
62 console: &'static capsules_core::console::Console<'static>,
63 ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
64 led: &'static capsules_core::led::LedDriver<
65 'static,
66 LedLow<'static, stm32f412g::gpio::Pin<'static>>,
67 4,
68 >,
69 button: &'static capsules_core::button::Button<'static, stm32f412g::gpio::Pin<'static>>,
70 alarm: &'static capsules_core::alarm::AlarmDriver<
71 'static,
72 VirtualMuxAlarm<'static, stm32f412g::tim2::Tim2<'static>>,
73 >,
74 gpio: &'static capsules_core::gpio::GPIO<'static, stm32f412g::gpio::Pin<'static>>,
75 adc: &'static capsules_core::adc::AdcVirtualized<'static>,
76 touch: &'static capsules_extra::touch::Touch<'static>,
77 screen: &'static capsules_extra::screen::Screen<'static>,
78 temperature: &'static TemperatureDriver,
79 rng: &'static RngDriver,
80
81 scheduler: &'static RoundRobinSched<'static>,
82 systick: cortexm4::systick::SysTick,
83}
84
85impl SyscallDriverLookup for STM32F412GDiscovery {
87 fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
88 where
89 F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
90 {
91 match driver_num {
92 capsules_core::console::DRIVER_NUM => f(Some(self.console)),
93 capsules_core::led::DRIVER_NUM => f(Some(self.led)),
94 capsules_core::button::DRIVER_NUM => f(Some(self.button)),
95 capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
96 kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
97 capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
98 capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
99 capsules_extra::touch::DRIVER_NUM => f(Some(self.touch)),
100 capsules_extra::screen::DRIVER_NUM => f(Some(self.screen)),
101 capsules_extra::temperature::DRIVER_NUM => f(Some(self.temperature)),
102 capsules_core::rng::DRIVER_NUM => f(Some(self.rng)),
103 _ => f(None),
104 }
105 }
106}
107
108impl
109 KernelResources<
110 stm32f412g::chip::Stm32f4xx<
111 'static,
112 stm32f412g::interrupt_service::Stm32f412gDefaultPeripherals<'static>,
113 >,
114 > for STM32F412GDiscovery
115{
116 type SyscallDriverLookup = Self;
117 type SyscallFilter = ();
118 type ProcessFault = ();
119 type Scheduler = RoundRobinSched<'static>;
120 type SchedulerTimer = cortexm4::systick::SysTick;
121 type WatchDog = ();
122 type ContextSwitchCallback = ();
123
124 fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
125 self
126 }
127 fn syscall_filter(&self) -> &Self::SyscallFilter {
128 &()
129 }
130 fn process_fault(&self) -> &Self::ProcessFault {
131 &()
132 }
133 fn scheduler(&self) -> &Self::Scheduler {
134 self.scheduler
135 }
136 fn scheduler_timer(&self) -> &Self::SchedulerTimer {
137 &self.systick
138 }
139 fn watchdog(&self) -> &Self::WatchDog {
140 &()
141 }
142 fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
143 &()
144 }
145}
146
147unsafe fn setup_dma(
149 dma: &stm32f412g::dma::Dma1,
150 dma_streams: &'static [stm32f412g::dma::Stream<stm32f412g::dma::Dma1>; 8],
151 usart2: &'static stm32f412g::usart::Usart<stm32f412g::dma::Dma1>,
152) {
153 use stm32f412g::dma::Dma1Peripheral;
154 use stm32f412g::usart;
155
156 dma.enable_clock();
157
158 let usart2_tx_stream = &dma_streams[Dma1Peripheral::USART2_TX.get_stream_idx()];
159 let usart2_rx_stream = &dma_streams[Dma1Peripheral::USART2_RX.get_stream_idx()];
160
161 usart2.set_dma(
162 usart::TxDMA(usart2_tx_stream),
163 usart::RxDMA(usart2_rx_stream),
164 );
165
166 usart2_tx_stream.set_client(usart2);
167 usart2_rx_stream.set_client(usart2);
168
169 usart2_tx_stream.setup(Dma1Peripheral::USART2_TX);
170 usart2_rx_stream.setup(Dma1Peripheral::USART2_RX);
171
172 cortexm4::nvic::Nvic::new(Dma1Peripheral::USART2_TX.get_stream_irqn()).enable();
173 cortexm4::nvic::Nvic::new(Dma1Peripheral::USART2_RX.get_stream_irqn()).enable();
174}
175
176unsafe fn set_pin_primary_functions(
178 syscfg: &stm32f412g::syscfg::Syscfg,
179 i2c1: &stm32f412g::i2c::I2C,
180 gpio_ports: &'static stm32f412g::gpio::GpioPorts<'static>,
181 peripheral_clock_frequency: usize,
182) {
183 use kernel::hil::gpio::Configure;
184 use stm32f412g::gpio::{AlternateFunction, Mode, PinId, PortId};
185
186 syscfg.enable_clock();
187
188 gpio_ports.get_port_from_port_id(PortId::E).enable_clock();
189
190 gpio_ports.get_pin(PinId::PE02).map(|pin| {
192 pin.make_output();
193
194 kernel::debug::assign_gpios(Some(pin), None, None);
196 });
197
198 gpio_ports.get_port_from_port_id(PortId::A).enable_clock();
199
200 gpio_ports.get_pin(PinId::PA02).map(|pin| {
202 pin.set_mode(Mode::AlternateFunctionMode);
203 pin.set_alternate_function(AlternateFunction::AF7);
205 });
206 gpio_ports.get_pin(PinId::PA03).map(|pin| {
207 pin.set_mode(Mode::AlternateFunctionMode);
208 pin.set_alternate_function(AlternateFunction::AF7);
210 });
211
212 gpio_ports.get_pin(PinId::PG01).map(|pin| {
220 pin.enable_interrupt();
221 });
222
223 gpio_ports.get_pin(PinId::PF15).map(|pin| {
225 pin.enable_interrupt();
226 });
227
228 gpio_ports.get_pin(PinId::PF14).map(|pin| {
230 pin.enable_interrupt();
231 });
232
233 gpio_ports.get_pin(PinId::PG00).map(|pin| {
235 pin.enable_interrupt();
236 });
237
238 gpio_ports.get_pin(PinId::PG09).map(|pin| {
240 pin.enable_interrupt();
241 });
242
243 gpio_ports.get_port_from_port_id(PortId::B).enable_clock();
246 gpio_ports.get_port_from_port_id(PortId::C).enable_clock();
248 gpio_ports.get_port_from_port_id(PortId::D).enable_clock();
249 gpio_ports.get_port_from_port_id(PortId::F).enable_clock();
250 gpio_ports.get_port_from_port_id(PortId::G).enable_clock();
251 gpio_ports.get_port_from_port_id(PortId::H).enable_clock();
252
253 gpio_ports.get_pin(PinId::PB06).map(|pin| {
255 pin.set_mode_output_opendrain();
257 pin.set_mode(Mode::AlternateFunctionMode);
258 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
259 pin.set_alternate_function(AlternateFunction::AF4);
261 });
262 gpio_ports.get_pin(PinId::PB07).map(|pin| {
263 pin.set_mode_output_opendrain();
265 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
266 pin.set_mode(Mode::AlternateFunctionMode);
267 pin.set_alternate_function(AlternateFunction::AF4);
269 });
270
271 i2c1.enable_clock();
272 i2c1.set_speed(
273 stm32f412g::i2c::I2CSpeed::Speed400k,
274 peripheral_clock_frequency,
275 );
276
277 gpio_ports.get_pin(PinId::PG05).map(|pin| {
279 pin.enable_interrupt();
280 });
281
282 gpio_ports.get_pin(PinId::PA01).map(|pin| {
286 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
287 });
288
289 gpio_ports.get_pin(PinId::PC01).map(|pin| {
291 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
292 });
293
294 gpio_ports.get_pin(PinId::PC03).map(|pin| {
296 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
297 });
298
299 gpio_ports.get_pin(PinId::PC04).map(|pin| {
301 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
302 });
303
304 gpio_ports.get_pin(PinId::PC05).map(|pin| {
306 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
307 });
308
309 gpio_ports.get_pin(PinId::PB00).map(|pin| {
311 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
312 });
313
314 cortexm4::nvic::Nvic::new(stm32f412g::nvic::EXTI9_5).enable();
316
317 let pins = [
320 PinId::PD00,
321 PinId::PD01,
322 PinId::PD04,
323 PinId::PD05,
324 PinId::PD08,
325 PinId::PD09,
326 PinId::PD10,
327 PinId::PD14,
328 PinId::PD15,
329 PinId::PD07,
330 PinId::PE07,
331 PinId::PE08,
332 PinId::PE09,
333 PinId::PE10,
334 PinId::PE11,
335 PinId::PE12,
336 PinId::PE13,
337 PinId::PE14,
338 PinId::PE15,
339 PinId::PF00,
340 ];
341
342 for pin in pins.iter() {
343 gpio_ports.get_pin(*pin).map(|pin| {
344 pin.set_mode(stm32f412g::gpio::Mode::AlternateFunctionMode);
345 pin.set_floating_state(gpio::FloatingState::PullUp);
346 pin.set_speed();
347 pin.set_alternate_function(stm32f412g::gpio::AlternateFunction::AF12);
348 });
349 }
350
351 use kernel::hil::gpio::Output;
352
353 gpio_ports.get_pin(PinId::PF05).map(|pin| {
354 pin.make_output();
355 pin.set_floating_state(gpio::FloatingState::PullNone);
356 pin.set();
357 });
358
359 gpio_ports.get_pin(PinId::PG04).map(|pin| {
360 pin.make_input();
361 });
362}
363
364unsafe fn setup_peripherals(
366 tim2: &stm32f412g::tim2::Tim2,
367 fsmc: &stm32f412g::fsmc::Fsmc,
368 trng: &stm32f412g::trng::Trng,
369) {
370 cortexm4::nvic::Nvic::new(stm32f412g::nvic::USART2).enable();
372
373 tim2.enable_clock();
375 tim2.start();
376 cortexm4::nvic::Nvic::new(stm32f412g::nvic::TIM2).enable();
377
378 fsmc.enable();
380
381 trng.enable_clock();
383}
384
385#[inline(never)]
391unsafe fn start() -> (
392 &'static kernel::Kernel,
393 STM32F412GDiscovery,
394 &'static stm32f412g::chip::Stm32f4xx<'static, Stm32f412gDefaultPeripherals<'static>>,
395) {
396 stm32f412g::init();
397
398 let rcc = static_init!(stm32f412g::rcc::Rcc, stm32f412g::rcc::Rcc::new());
399 let clocks = static_init!(
400 stm32f412g::clocks::Clocks<Stm32f412Specs>,
401 stm32f412g::clocks::Clocks::new(rcc)
402 );
403
404 let syscfg = static_init!(
405 stm32f412g::syscfg::Syscfg,
406 stm32f412g::syscfg::Syscfg::new(clocks)
407 );
408
409 let exti = static_init!(stm32f412g::exti::Exti, stm32f412g::exti::Exti::new(syscfg));
410
411 let dma1 = static_init!(stm32f412g::dma::Dma1, stm32f412g::dma::Dma1::new(clocks));
412 let dma2 = static_init!(stm32f412g::dma::Dma2, stm32f412g::dma::Dma2::new(clocks));
413
414 let peripherals = static_init!(
415 Stm32f412gDefaultPeripherals,
416 Stm32f412gDefaultPeripherals::new(clocks, exti, dma1, dma2)
417 );
418
419 peripherals.init();
420
421 let _ = clocks.set_ahb_prescaler(stm32f412g::rcc::AHBPrescaler::DivideBy1);
422 let _ = clocks.set_apb1_prescaler(stm32f412g::rcc::APBPrescaler::DivideBy4);
423 let _ = clocks.set_apb2_prescaler(stm32f412g::rcc::APBPrescaler::DivideBy2);
424 let _ = clocks.set_pll_frequency_mhz(PllSource::HSI, 100);
425 let _ = clocks.pll.enable();
426 let _ = clocks.set_sys_clock_source(stm32f412g::rcc::SysClockSource::PLL);
427
428 let base_peripherals = &peripherals.stm32f4;
429 setup_peripherals(
430 &base_peripherals.tim2,
431 &base_peripherals.fsmc,
432 &peripherals.trng,
433 );
434
435 set_pin_primary_functions(
436 syscfg,
437 &base_peripherals.i2c1,
438 &base_peripherals.gpio_ports,
439 clocks.get_apb1_frequency_mhz(),
440 );
441
442 setup_dma(
443 dma1,
444 &base_peripherals.dma1_streams,
445 &base_peripherals.usart2,
446 );
447
448 let processes = components::process_array::ProcessArrayComponent::new()
450 .finalize(components::process_array_component_static!(NUM_PROCS));
451 PROCESSES = Some(processes);
452
453 let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(processes.as_slice()));
455
456 let chip = static_init!(
457 stm32f412g::chip::Stm32f4xx<Stm32f412gDefaultPeripherals>,
458 stm32f412g::chip::Stm32f4xx::new(peripherals)
459 );
460 CHIP = Some(chip);
461
462 base_peripherals.usart2.enable_clock();
466 let uart_mux = components::console::UartMuxComponent::new(&base_peripherals.usart2, 115200)
467 .finalize(components::uart_mux_component_static!());
468
469 (*addr_of_mut!(io::WRITER)).set_initialized();
470
471 let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
474 let process_management_capability =
475 create_capability!(capabilities::ProcessManagementCapability);
476
477 let console = components::console::ConsoleComponent::new(
479 board_kernel,
480 capsules_core::console::DRIVER_NUM,
481 uart_mux,
482 )
483 .finalize(components::console_component_static!());
484 components::debug_writer::DebugWriterComponent::new(
486 uart_mux,
487 create_capability!(capabilities::SetDebugWriterCapability),
488 )
489 .finalize(components::debug_writer_component_static!());
490
491 let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
496 LedLow<'static, stm32f412g::gpio::Pin>,
497 LedLow::new(
498 base_peripherals
499 .gpio_ports
500 .get_pin(stm32f412g::gpio::PinId::PE00)
501 .unwrap()
502 ),
503 LedLow::new(
504 base_peripherals
505 .gpio_ports
506 .get_pin(stm32f412g::gpio::PinId::PE01)
507 .unwrap()
508 ),
509 LedLow::new(
510 base_peripherals
511 .gpio_ports
512 .get_pin(stm32f412g::gpio::PinId::PE02)
513 .unwrap()
514 ),
515 LedLow::new(
516 base_peripherals
517 .gpio_ports
518 .get_pin(stm32f412g::gpio::PinId::PE03)
519 .unwrap()
520 ),
521 ));
522
523 let button = components::button::ButtonComponent::new(
525 board_kernel,
526 capsules_core::button::DRIVER_NUM,
527 components::button_component_helper!(
528 stm32f412g::gpio::Pin,
529 (
531 base_peripherals
532 .gpio_ports
533 .get_pin(stm32f412g::gpio::PinId::PA00)
534 .unwrap(),
535 kernel::hil::gpio::ActivationMode::ActiveHigh,
536 kernel::hil::gpio::FloatingState::PullNone
537 ),
538 (
540 base_peripherals
541 .gpio_ports
542 .get_pin(stm32f412g::gpio::PinId::PG01)
543 .unwrap(),
544 kernel::hil::gpio::ActivationMode::ActiveHigh,
545 kernel::hil::gpio::FloatingState::PullNone
546 ),
547 (
549 base_peripherals
550 .gpio_ports
551 .get_pin(stm32f412g::gpio::PinId::PF15)
552 .unwrap(),
553 kernel::hil::gpio::ActivationMode::ActiveHigh,
554 kernel::hil::gpio::FloatingState::PullNone
555 ),
556 (
558 base_peripherals
559 .gpio_ports
560 .get_pin(stm32f412g::gpio::PinId::PF14)
561 .unwrap(),
562 kernel::hil::gpio::ActivationMode::ActiveHigh,
563 kernel::hil::gpio::FloatingState::PullNone
564 ),
565 (
567 base_peripherals
568 .gpio_ports
569 .get_pin(stm32f412g::gpio::PinId::PG00)
570 .unwrap(),
571 kernel::hil::gpio::ActivationMode::ActiveHigh,
572 kernel::hil::gpio::FloatingState::PullNone
573 )
574 ),
575 )
576 .finalize(components::button_component_static!(stm32f412g::gpio::Pin));
577
578 let tim2 = &base_peripherals.tim2;
581 let mux_alarm = components::alarm::AlarmMuxComponent::new(tim2).finalize(
582 components::alarm_mux_component_static!(stm32f412g::tim2::Tim2),
583 );
584
585 let alarm = components::alarm::AlarmDriverComponent::new(
586 board_kernel,
587 capsules_core::alarm::DRIVER_NUM,
588 mux_alarm,
589 )
590 .finalize(components::alarm_component_static!(stm32f412g::tim2::Tim2));
591
592 let gpio = GpioComponent::new(
594 board_kernel,
595 capsules_core::gpio::DRIVER_NUM,
596 components::gpio_component_helper!(
597 stm32f412g::gpio::Pin,
598 0 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PG09).unwrap(), 1 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PG14).unwrap(), 2 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PG13).unwrap(), 3 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PF04).unwrap(), 4 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PG12).unwrap(), 5 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PF10).unwrap(), 6 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PF03).unwrap(), 7 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PG11).unwrap(), 8 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PG10).unwrap(), 9 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PB08).unwrap(), 10 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PA15).unwrap(), 11 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PA07).unwrap(), 12 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PA06).unwrap(), 13 => base_peripherals.gpio_ports.get_pin(stm32f412g::gpio::PinId::PA15).unwrap() ),
624 )
625 .finalize(components::gpio_component_static!(stm32f412g::gpio::Pin));
626
627 let rng = RngComponent::new(
629 board_kernel,
630 capsules_core::rng::DRIVER_NUM,
631 &peripherals.trng,
632 )
633 .finalize(components::rng_component_static!(stm32f412g::trng::Trng));
634
635 let mux_i2c = components::i2c::I2CMuxComponent::new(&base_peripherals.i2c1, None)
638 .finalize(components::i2c_mux_component_static!(stm32f412g::i2c::I2C));
639
640 let ft6x06 = components::ft6x06::Ft6x06Component::new(
641 mux_i2c,
642 0x38,
643 base_peripherals
644 .gpio_ports
645 .get_pin(stm32f412g::gpio::PinId::PG05)
646 .unwrap(),
647 )
648 .finalize(components::ft6x06_component_static!(stm32f412g::i2c::I2C));
649
650 let bus = components::bus::Bus8080BusComponent::new(&base_peripherals.fsmc).finalize(
651 components::bus8080_bus_component_static!(stm32f412g::fsmc::Fsmc,),
652 );
653
654 let tft = components::st77xx::ST77XXComponent::new(
655 mux_alarm,
656 bus,
657 None,
658 base_peripherals
659 .gpio_ports
660 .get_pin(stm32f412g::gpio::PinId::PD11),
661 &capsules_extra::st77xx::ST7789H2,
662 )
663 .finalize(components::st77xx_component_static!(
664 capsules_extra::bus::Bus8080Bus<'static, stm32f412g::fsmc::Fsmc>,
666 stm32f412g::tim2::Tim2,
668 stm32f412g::gpio::Pin,
670 ));
671
672 let _ = tft.init();
673
674 let screen = components::screen::ScreenComponent::new(
675 board_kernel,
676 capsules_extra::screen::DRIVER_NUM,
677 tft,
678 Some(tft),
679 )
680 .finalize(components::screen_component_static!(1024));
681
682 let touch = components::touch::MultiTouchComponent::new(
683 board_kernel,
684 capsules_extra::touch::DRIVER_NUM,
685 ft6x06,
686 Some(ft6x06),
687 Some(tft),
688 )
689 .finalize(components::touch_component_static!());
690
691 touch.set_screen_rotation_offset(ScreenRotation::Rotated90);
692
693 let adc_mux = components::adc::AdcMuxComponent::new(&base_peripherals.adc1)
700 .finalize(components::adc_mux_component_static!(stm32f412g::adc::Adc));
701
702 let temp_sensor = components::temperature_stm::TemperatureSTMComponent::new(
703 adc_mux,
704 stm32f412g::adc::Channel::Channel18,
705 2.5,
706 0.76,
707 )
708 .finalize(components::temperature_stm_adc_component_static!(
709 stm32f412g::adc::Adc
710 ));
711
712 let temp = components::temperature::TemperatureComponent::new(
713 board_kernel,
714 capsules_extra::temperature::DRIVER_NUM,
715 temp_sensor,
716 )
717 .finalize(components::temperature_component_static!(
718 TemperatureSTMSensor
719 ));
720
721 let adc_channel_0 =
722 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel1)
723 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
724
725 let adc_channel_1 =
726 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel11)
727 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
728
729 let adc_channel_2 =
730 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel13)
731 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
732
733 let adc_channel_3 =
734 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel14)
735 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
736
737 let adc_channel_4 =
738 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel15)
739 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
740
741 let adc_channel_5 =
742 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel8)
743 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
744
745 let adc_syscall =
746 components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
747 .finalize(components::adc_syscall_component_helper!(
748 adc_channel_0,
749 adc_channel_1,
750 adc_channel_2,
751 adc_channel_3,
752 adc_channel_4,
753 adc_channel_5
754 ));
755
756 let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
757 .finalize(components::process_printer_text_component_static!());
758 PROCESS_PRINTER = Some(process_printer);
759
760 let process_console = components::process_console::ProcessConsoleComponent::new(
762 board_kernel,
763 uart_mux,
764 mux_alarm,
765 process_printer,
766 Some(cortexm4::support::reset),
767 )
768 .finalize(components::process_console_component_static!(
769 stm32f412g::tim2::Tim2
770 ));
771 let _ = process_console.start();
772
773 let scheduler = components::sched::round_robin::RoundRobinComponent::new(processes)
774 .finalize(components::round_robin_component_static!(NUM_PROCS));
775
776 let stm32f412g = STM32F412GDiscovery {
777 console,
778 ipc: kernel::ipc::IPC::new(
779 board_kernel,
780 kernel::ipc::DRIVER_NUM,
781 &memory_allocation_capability,
782 ),
783 led,
784 button,
785 alarm,
786 gpio,
787 adc: adc_syscall,
788 touch,
789 screen,
790 temperature: temp,
791 rng,
792
793 scheduler,
794 systick: cortexm4::systick::SysTick::new_with_calibration(
795 (HSI_FREQUENCY_MHZ * 1_000_000) as u32,
796 ),
797 };
798
799 debug!("Initialization complete. Entering main loop");
807
808 extern "C" {
809 static _sapps: u8;
813
814 static _eapps: u8;
818
819 static mut _sappmem: u8;
823
824 static _eappmem: u8;
828 }
829
830 kernel::process::load_processes(
831 board_kernel,
832 chip,
833 core::slice::from_raw_parts(
834 core::ptr::addr_of!(_sapps),
835 core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
836 ),
837 core::slice::from_raw_parts_mut(
838 core::ptr::addr_of_mut!(_sappmem),
839 core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
840 ),
841 &FAULT_RESPONSE,
842 &process_management_capability,
843 )
844 .unwrap_or_else(|err| {
845 debug!("Error loading processes!");
846 debug!("{:?}", err);
847 });
848
849 (board_kernel, stm32f412g, chip)
855}
856
857#[no_mangle]
859pub unsafe fn main() {
860 let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
861
862 let (board_kernel, platform, chip) = start();
863 board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
864}