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
38type ChipHw = stm32f412g::chip::Stm32f4xx<'static, Stm32f412gDefaultPeripherals<'static>>;
39
40static mut PROCESSES: Option<&'static ProcessArray<NUM_PROCS>> = None;
42static mut CHIP: Option<&'static ChipHw> = None;
43static mut PROCESS_PRINTER: Option<&'static capsules_system::process_printer::ProcessPrinterText> =
44 None;
45
46const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
48 capsules_system::process_policies::PanicFaultPolicy {};
49
50kernel::stack_size! {0x2000}
51
52type TemperatureSTMSensor = components::temperature_stm::TemperatureSTMComponentType<
53 capsules_core::virtualizers::virtual_adc::AdcDevice<'static, stm32f412g::adc::Adc<'static>>,
54>;
55type TemperatureDriver = components::temperature::TemperatureComponentType<TemperatureSTMSensor>;
56type RngDriver = components::rng::RngComponentType<stm32f412g::trng::Trng<'static>>;
57type ScreenDriver = components::screen::ScreenComponentType;
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 ScreenDriver,
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::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 <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
487 >(
488 uart_mux,
489 create_capability!(capabilities::SetDebugWriterCapability),
490 )
491 .finalize(components::debug_writer_component_static!());
492
493 let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
498 LedLow<'static, stm32f412g::gpio::Pin>,
499 LedLow::new(
500 base_peripherals
501 .gpio_ports
502 .get_pin(stm32f412g::gpio::PinId::PE00)
503 .unwrap()
504 ),
505 LedLow::new(
506 base_peripherals
507 .gpio_ports
508 .get_pin(stm32f412g::gpio::PinId::PE01)
509 .unwrap()
510 ),
511 LedLow::new(
512 base_peripherals
513 .gpio_ports
514 .get_pin(stm32f412g::gpio::PinId::PE02)
515 .unwrap()
516 ),
517 LedLow::new(
518 base_peripherals
519 .gpio_ports
520 .get_pin(stm32f412g::gpio::PinId::PE03)
521 .unwrap()
522 ),
523 ));
524
525 let button = components::button::ButtonComponent::new(
527 board_kernel,
528 capsules_core::button::DRIVER_NUM,
529 components::button_component_helper!(
530 stm32f412g::gpio::Pin,
531 (
533 base_peripherals
534 .gpio_ports
535 .get_pin(stm32f412g::gpio::PinId::PA00)
536 .unwrap(),
537 kernel::hil::gpio::ActivationMode::ActiveHigh,
538 kernel::hil::gpio::FloatingState::PullNone
539 ),
540 (
542 base_peripherals
543 .gpio_ports
544 .get_pin(stm32f412g::gpio::PinId::PG01)
545 .unwrap(),
546 kernel::hil::gpio::ActivationMode::ActiveHigh,
547 kernel::hil::gpio::FloatingState::PullNone
548 ),
549 (
551 base_peripherals
552 .gpio_ports
553 .get_pin(stm32f412g::gpio::PinId::PF15)
554 .unwrap(),
555 kernel::hil::gpio::ActivationMode::ActiveHigh,
556 kernel::hil::gpio::FloatingState::PullNone
557 ),
558 (
560 base_peripherals
561 .gpio_ports
562 .get_pin(stm32f412g::gpio::PinId::PF14)
563 .unwrap(),
564 kernel::hil::gpio::ActivationMode::ActiveHigh,
565 kernel::hil::gpio::FloatingState::PullNone
566 ),
567 (
569 base_peripherals
570 .gpio_ports
571 .get_pin(stm32f412g::gpio::PinId::PG00)
572 .unwrap(),
573 kernel::hil::gpio::ActivationMode::ActiveHigh,
574 kernel::hil::gpio::FloatingState::PullNone
575 )
576 ),
577 )
578 .finalize(components::button_component_static!(stm32f412g::gpio::Pin));
579
580 let tim2 = &base_peripherals.tim2;
583 let mux_alarm = components::alarm::AlarmMuxComponent::new(tim2).finalize(
584 components::alarm_mux_component_static!(stm32f412g::tim2::Tim2),
585 );
586
587 let alarm = components::alarm::AlarmDriverComponent::new(
588 board_kernel,
589 capsules_core::alarm::DRIVER_NUM,
590 mux_alarm,
591 )
592 .finalize(components::alarm_component_static!(stm32f412g::tim2::Tim2));
593
594 let gpio = GpioComponent::new(
596 board_kernel,
597 capsules_core::gpio::DRIVER_NUM,
598 components::gpio_component_helper!(
599 stm32f412g::gpio::Pin,
600 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() ),
626 )
627 .finalize(components::gpio_component_static!(stm32f412g::gpio::Pin));
628
629 let rng = RngComponent::new(
631 board_kernel,
632 capsules_core::rng::DRIVER_NUM,
633 &peripherals.trng,
634 )
635 .finalize(components::rng_component_static!(stm32f412g::trng::Trng));
636
637 let mux_i2c = components::i2c::I2CMuxComponent::new(&base_peripherals.i2c1, None)
640 .finalize(components::i2c_mux_component_static!(stm32f412g::i2c::I2C));
641
642 let ft6x06 = components::ft6x06::Ft6x06Component::new(
643 mux_i2c,
644 0x38,
645 base_peripherals
646 .gpio_ports
647 .get_pin(stm32f412g::gpio::PinId::PG05)
648 .unwrap(),
649 )
650 .finalize(components::ft6x06_component_static!(stm32f412g::i2c::I2C));
651
652 let bus = components::bus::Bus8080BusComponent::new(&base_peripherals.fsmc).finalize(
653 components::bus8080_bus_component_static!(stm32f412g::fsmc::Fsmc,),
654 );
655
656 let tft = components::st77xx::ST77XXComponent::new(
657 mux_alarm,
658 bus,
659 None,
660 base_peripherals
661 .gpio_ports
662 .get_pin(stm32f412g::gpio::PinId::PD11),
663 &capsules_extra::st77xx::ST7789H2,
664 )
665 .finalize(components::st77xx_component_static!(
666 capsules_extra::bus::Bus8080Bus<'static, stm32f412g::fsmc::Fsmc>,
668 stm32f412g::tim2::Tim2,
670 stm32f412g::gpio::Pin,
672 ));
673
674 let _ = tft.init();
675
676 let screen = components::screen::ScreenComponent::new(
677 board_kernel,
678 capsules_extra::screen::screen::DRIVER_NUM,
679 tft,
680 Some(tft),
681 )
682 .finalize(components::screen_component_static!(1024));
683
684 let touch = components::touch::MultiTouchComponent::new(
685 board_kernel,
686 capsules_extra::touch::DRIVER_NUM,
687 ft6x06,
688 Some(ft6x06),
689 Some(tft),
690 )
691 .finalize(components::touch_component_static!());
692
693 touch.set_screen_rotation_offset(ScreenRotation::Rotated90);
694
695 let adc_mux = components::adc::AdcMuxComponent::new(&base_peripherals.adc1)
702 .finalize(components::adc_mux_component_static!(stm32f412g::adc::Adc));
703
704 let temp_sensor = components::temperature_stm::TemperatureSTMComponent::new(
705 adc_mux,
706 stm32f412g::adc::Channel::Channel18,
707 2.5,
708 0.76,
709 )
710 .finalize(components::temperature_stm_adc_component_static!(
711 stm32f412g::adc::Adc
712 ));
713
714 let temp = components::temperature::TemperatureComponent::new(
715 board_kernel,
716 capsules_extra::temperature::DRIVER_NUM,
717 temp_sensor,
718 )
719 .finalize(components::temperature_component_static!(
720 TemperatureSTMSensor
721 ));
722
723 let adc_channel_0 =
724 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel1)
725 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
726
727 let adc_channel_1 =
728 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel11)
729 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
730
731 let adc_channel_2 =
732 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel13)
733 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
734
735 let adc_channel_3 =
736 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel14)
737 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
738
739 let adc_channel_4 =
740 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel15)
741 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
742
743 let adc_channel_5 =
744 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel8)
745 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
746
747 let adc_syscall =
748 components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
749 .finalize(components::adc_syscall_component_helper!(
750 adc_channel_0,
751 adc_channel_1,
752 adc_channel_2,
753 adc_channel_3,
754 adc_channel_4,
755 adc_channel_5
756 ));
757
758 let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
759 .finalize(components::process_printer_text_component_static!());
760 PROCESS_PRINTER = Some(process_printer);
761
762 let process_console = components::process_console::ProcessConsoleComponent::new(
764 board_kernel,
765 uart_mux,
766 mux_alarm,
767 process_printer,
768 Some(cortexm4::support::reset),
769 )
770 .finalize(components::process_console_component_static!(
771 stm32f412g::tim2::Tim2
772 ));
773 let _ = process_console.start();
774
775 let scheduler = components::sched::round_robin::RoundRobinComponent::new(processes)
776 .finalize(components::round_robin_component_static!(NUM_PROCS));
777
778 let stm32f412g = STM32F412GDiscovery {
779 console,
780 ipc: kernel::ipc::IPC::new(
781 board_kernel,
782 kernel::ipc::DRIVER_NUM,
783 &memory_allocation_capability,
784 ),
785 led,
786 button,
787 alarm,
788 gpio,
789 adc: adc_syscall,
790 touch,
791 screen,
792 temperature: temp,
793 rng,
794
795 scheduler,
796 systick: cortexm4::systick::SysTick::new_with_calibration(
797 (HSI_FREQUENCY_MHZ * 1_000_000) as u32,
798 ),
799 };
800
801 debug!("Initialization complete. Entering main loop");
809
810 extern "C" {
811 static _sapps: u8;
815
816 static _eapps: u8;
820
821 static mut _sappmem: u8;
825
826 static _eappmem: u8;
830 }
831
832 kernel::process::load_processes(
833 board_kernel,
834 chip,
835 core::slice::from_raw_parts(
836 core::ptr::addr_of!(_sapps),
837 core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
838 ),
839 core::slice::from_raw_parts_mut(
840 core::ptr::addr_of_mut!(_sappmem),
841 core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
842 ),
843 &FAULT_RESPONSE,
844 &process_management_capability,
845 )
846 .unwrap_or_else(|err| {
847 debug!("Error loading processes!");
848 debug!("{:?}", err);
849 });
850
851 (board_kernel, stm32f412g, chip)
857}
858
859#[no_mangle]
861pub unsafe fn main() {
862 let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
863
864 let (board_kernel, platform, chip) = start();
865 board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
866}