1#![no_std]
10#![no_main]
11#![deny(missing_docs)]
12use core::ptr::{addr_of, addr_of_mut};
13
14use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
15use components::gpio::GpioComponent;
16use components::rng::RngComponent;
17use kernel::capabilities;
18use kernel::component::Component;
19use kernel::hil::gpio;
20use kernel::hil::led::LedLow;
21use kernel::hil::screen::ScreenRotation;
22use kernel::platform::{KernelResources, SyscallDriverLookup};
23use kernel::scheduler::round_robin::RoundRobinSched;
24use kernel::{create_capability, debug, static_init};
25use stm32f412g::chip_specs::Stm32f412Specs;
26use stm32f412g::clocks::hsi::HSI_FREQUENCY_MHZ;
27use stm32f412g::interrupt_service::Stm32f412gDefaultPeripherals;
28use stm32f412g::rcc::PllSource;
29
30pub mod io;
32
33const NUM_PROCS: usize = 4;
35
36static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] =
38 [None, None, None, None];
39
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"]
51pub static 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 board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));
449
450 let chip = static_init!(
451 stm32f412g::chip::Stm32f4xx<Stm32f412gDefaultPeripherals>,
452 stm32f412g::chip::Stm32f4xx::new(peripherals)
453 );
454 CHIP = Some(chip);
455
456 base_peripherals.usart2.enable_clock();
460 let uart_mux = components::console::UartMuxComponent::new(&base_peripherals.usart2, 115200)
461 .finalize(components::uart_mux_component_static!());
462
463 (*addr_of_mut!(io::WRITER)).set_initialized();
464
465 let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
468 let process_management_capability =
469 create_capability!(capabilities::ProcessManagementCapability);
470
471 let console = components::console::ConsoleComponent::new(
473 board_kernel,
474 capsules_core::console::DRIVER_NUM,
475 uart_mux,
476 )
477 .finalize(components::console_component_static!());
478 components::debug_writer::DebugWriterComponent::new(
480 uart_mux,
481 create_capability!(capabilities::SetDebugWriterCapability),
482 )
483 .finalize(components::debug_writer_component_static!());
484
485 let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
490 LedLow<'static, stm32f412g::gpio::Pin>,
491 LedLow::new(
492 base_peripherals
493 .gpio_ports
494 .get_pin(stm32f412g::gpio::PinId::PE00)
495 .unwrap()
496 ),
497 LedLow::new(
498 base_peripherals
499 .gpio_ports
500 .get_pin(stm32f412g::gpio::PinId::PE01)
501 .unwrap()
502 ),
503 LedLow::new(
504 base_peripherals
505 .gpio_ports
506 .get_pin(stm32f412g::gpio::PinId::PE02)
507 .unwrap()
508 ),
509 LedLow::new(
510 base_peripherals
511 .gpio_ports
512 .get_pin(stm32f412g::gpio::PinId::PE03)
513 .unwrap()
514 ),
515 ));
516
517 let button = components::button::ButtonComponent::new(
519 board_kernel,
520 capsules_core::button::DRIVER_NUM,
521 components::button_component_helper!(
522 stm32f412g::gpio::Pin,
523 (
525 base_peripherals
526 .gpio_ports
527 .get_pin(stm32f412g::gpio::PinId::PA00)
528 .unwrap(),
529 kernel::hil::gpio::ActivationMode::ActiveHigh,
530 kernel::hil::gpio::FloatingState::PullNone
531 ),
532 (
534 base_peripherals
535 .gpio_ports
536 .get_pin(stm32f412g::gpio::PinId::PG01)
537 .unwrap(),
538 kernel::hil::gpio::ActivationMode::ActiveHigh,
539 kernel::hil::gpio::FloatingState::PullNone
540 ),
541 (
543 base_peripherals
544 .gpio_ports
545 .get_pin(stm32f412g::gpio::PinId::PF15)
546 .unwrap(),
547 kernel::hil::gpio::ActivationMode::ActiveHigh,
548 kernel::hil::gpio::FloatingState::PullNone
549 ),
550 (
552 base_peripherals
553 .gpio_ports
554 .get_pin(stm32f412g::gpio::PinId::PF14)
555 .unwrap(),
556 kernel::hil::gpio::ActivationMode::ActiveHigh,
557 kernel::hil::gpio::FloatingState::PullNone
558 ),
559 (
561 base_peripherals
562 .gpio_ports
563 .get_pin(stm32f412g::gpio::PinId::PG00)
564 .unwrap(),
565 kernel::hil::gpio::ActivationMode::ActiveHigh,
566 kernel::hil::gpio::FloatingState::PullNone
567 )
568 ),
569 )
570 .finalize(components::button_component_static!(stm32f412g::gpio::Pin));
571
572 let tim2 = &base_peripherals.tim2;
575 let mux_alarm = components::alarm::AlarmMuxComponent::new(tim2).finalize(
576 components::alarm_mux_component_static!(stm32f412g::tim2::Tim2),
577 );
578
579 let alarm = components::alarm::AlarmDriverComponent::new(
580 board_kernel,
581 capsules_core::alarm::DRIVER_NUM,
582 mux_alarm,
583 )
584 .finalize(components::alarm_component_static!(stm32f412g::tim2::Tim2));
585
586 let gpio = GpioComponent::new(
588 board_kernel,
589 capsules_core::gpio::DRIVER_NUM,
590 components::gpio_component_helper!(
591 stm32f412g::gpio::Pin,
592 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() ),
618 )
619 .finalize(components::gpio_component_static!(stm32f412g::gpio::Pin));
620
621 let rng = RngComponent::new(
623 board_kernel,
624 capsules_core::rng::DRIVER_NUM,
625 &peripherals.trng,
626 )
627 .finalize(components::rng_component_static!(stm32f412g::trng::Trng));
628
629 let mux_i2c = components::i2c::I2CMuxComponent::new(&base_peripherals.i2c1, None)
632 .finalize(components::i2c_mux_component_static!(stm32f412g::i2c::I2C));
633
634 let ft6x06 = components::ft6x06::Ft6x06Component::new(
635 mux_i2c,
636 0x38,
637 base_peripherals
638 .gpio_ports
639 .get_pin(stm32f412g::gpio::PinId::PG05)
640 .unwrap(),
641 )
642 .finalize(components::ft6x06_component_static!(stm32f412g::i2c::I2C));
643
644 let bus = components::bus::Bus8080BusComponent::new(&base_peripherals.fsmc).finalize(
645 components::bus8080_bus_component_static!(stm32f412g::fsmc::Fsmc,),
646 );
647
648 let tft = components::st77xx::ST77XXComponent::new(
649 mux_alarm,
650 bus,
651 None,
652 base_peripherals
653 .gpio_ports
654 .get_pin(stm32f412g::gpio::PinId::PD11),
655 &capsules_extra::st77xx::ST7789H2,
656 )
657 .finalize(components::st77xx_component_static!(
658 capsules_extra::bus::Bus8080Bus<'static, stm32f412g::fsmc::Fsmc>,
660 stm32f412g::tim2::Tim2,
662 stm32f412g::gpio::Pin,
664 ));
665
666 let _ = tft.init();
667
668 let screen = components::screen::ScreenComponent::new(
669 board_kernel,
670 capsules_extra::screen::DRIVER_NUM,
671 tft,
672 Some(tft),
673 )
674 .finalize(components::screen_component_static!(1024));
675
676 let touch = components::touch::MultiTouchComponent::new(
677 board_kernel,
678 capsules_extra::touch::DRIVER_NUM,
679 ft6x06,
680 Some(ft6x06),
681 Some(tft),
682 )
683 .finalize(components::touch_component_static!());
684
685 touch.set_screen_rotation_offset(ScreenRotation::Rotated90);
686
687 let adc_mux = components::adc::AdcMuxComponent::new(&base_peripherals.adc1)
694 .finalize(components::adc_mux_component_static!(stm32f412g::adc::Adc));
695
696 let temp_sensor = components::temperature_stm::TemperatureSTMComponent::new(
697 adc_mux,
698 stm32f412g::adc::Channel::Channel18,
699 2.5,
700 0.76,
701 )
702 .finalize(components::temperature_stm_adc_component_static!(
703 stm32f412g::adc::Adc
704 ));
705
706 let temp = components::temperature::TemperatureComponent::new(
707 board_kernel,
708 capsules_extra::temperature::DRIVER_NUM,
709 temp_sensor,
710 )
711 .finalize(components::temperature_component_static!(
712 TemperatureSTMSensor
713 ));
714
715 let adc_channel_0 =
716 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel1)
717 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
718
719 let adc_channel_1 =
720 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel11)
721 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
722
723 let adc_channel_2 =
724 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel13)
725 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
726
727 let adc_channel_3 =
728 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel14)
729 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
730
731 let adc_channel_4 =
732 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel15)
733 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
734
735 let adc_channel_5 =
736 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel8)
737 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
738
739 let adc_syscall =
740 components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
741 .finalize(components::adc_syscall_component_helper!(
742 adc_channel_0,
743 adc_channel_1,
744 adc_channel_2,
745 adc_channel_3,
746 adc_channel_4,
747 adc_channel_5
748 ));
749
750 let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
751 .finalize(components::process_printer_text_component_static!());
752 PROCESS_PRINTER = Some(process_printer);
753
754 let process_console = components::process_console::ProcessConsoleComponent::new(
756 board_kernel,
757 uart_mux,
758 mux_alarm,
759 process_printer,
760 Some(cortexm4::support::reset),
761 )
762 .finalize(components::process_console_component_static!(
763 stm32f412g::tim2::Tim2
764 ));
765 let _ = process_console.start();
766
767 let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
768 .finalize(components::round_robin_component_static!(NUM_PROCS));
769
770 let stm32f412g = STM32F412GDiscovery {
771 console,
772 ipc: kernel::ipc::IPC::new(
773 board_kernel,
774 kernel::ipc::DRIVER_NUM,
775 &memory_allocation_capability,
776 ),
777 led,
778 button,
779 alarm,
780 gpio,
781 adc: adc_syscall,
782 touch,
783 screen,
784 temperature: temp,
785 rng,
786
787 scheduler,
788 systick: cortexm4::systick::SysTick::new_with_calibration(
789 (HSI_FREQUENCY_MHZ * 1_000_000) as u32,
790 ),
791 };
792
793 debug!("Initialization complete. Entering main loop");
801
802 extern "C" {
803 static _sapps: u8;
807
808 static _eapps: u8;
812
813 static mut _sappmem: u8;
817
818 static _eappmem: u8;
822 }
823
824 kernel::process::load_processes(
825 board_kernel,
826 chip,
827 core::slice::from_raw_parts(
828 core::ptr::addr_of!(_sapps),
829 core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
830 ),
831 core::slice::from_raw_parts_mut(
832 core::ptr::addr_of_mut!(_sappmem),
833 core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
834 ),
835 &mut *addr_of_mut!(PROCESSES),
836 &FAULT_RESPONSE,
837 &process_management_capability,
838 )
839 .unwrap_or_else(|err| {
840 debug!("Error loading processes!");
841 debug!("{:?}", err);
842 });
843
844 (board_kernel, stm32f412g, chip)
850}
851
852#[no_mangle]
854pub unsafe fn main() {
855 let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
856
857 let (board_kernel, platform, chip) = start();
858 board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
859}