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 let debug_gpios = static_init!([&'static dyn kernel::hil::gpio::Pin; 1], [pin]);
196 kernel::debug::initialize_debug_gpio::<
197 <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
198 >();
199 kernel::debug::assign_gpios(debug_gpios);
200 });
201
202 gpio_ports.get_port_from_port_id(PortId::A).enable_clock();
203
204 gpio_ports.get_pin(PinId::PA02).map(|pin| {
206 pin.set_mode(Mode::AlternateFunctionMode);
207 pin.set_alternate_function(AlternateFunction::AF7);
209 });
210 gpio_ports.get_pin(PinId::PA03).map(|pin| {
211 pin.set_mode(Mode::AlternateFunctionMode);
212 pin.set_alternate_function(AlternateFunction::AF7);
214 });
215
216 gpio_ports.get_pin(PinId::PG01).map(|pin| {
224 pin.enable_interrupt();
225 });
226
227 gpio_ports.get_pin(PinId::PF15).map(|pin| {
229 pin.enable_interrupt();
230 });
231
232 gpio_ports.get_pin(PinId::PF14).map(|pin| {
234 pin.enable_interrupt();
235 });
236
237 gpio_ports.get_pin(PinId::PG00).map(|pin| {
239 pin.enable_interrupt();
240 });
241
242 gpio_ports.get_pin(PinId::PG09).map(|pin| {
244 pin.enable_interrupt();
245 });
246
247 gpio_ports.get_port_from_port_id(PortId::B).enable_clock();
250 gpio_ports.get_port_from_port_id(PortId::C).enable_clock();
252 gpio_ports.get_port_from_port_id(PortId::D).enable_clock();
253 gpio_ports.get_port_from_port_id(PortId::F).enable_clock();
254 gpio_ports.get_port_from_port_id(PortId::G).enable_clock();
255 gpio_ports.get_port_from_port_id(PortId::H).enable_clock();
256
257 gpio_ports.get_pin(PinId::PB06).map(|pin| {
259 pin.set_mode_output_opendrain();
261 pin.set_mode(Mode::AlternateFunctionMode);
262 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
263 pin.set_alternate_function(AlternateFunction::AF4);
265 });
266 gpio_ports.get_pin(PinId::PB07).map(|pin| {
267 pin.set_mode_output_opendrain();
269 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
270 pin.set_mode(Mode::AlternateFunctionMode);
271 pin.set_alternate_function(AlternateFunction::AF4);
273 });
274
275 i2c1.enable_clock();
276 i2c1.set_speed(
277 stm32f412g::i2c::I2CSpeed::Speed400k,
278 peripheral_clock_frequency,
279 );
280
281 gpio_ports.get_pin(PinId::PG05).map(|pin| {
283 pin.enable_interrupt();
284 });
285
286 gpio_ports.get_pin(PinId::PA01).map(|pin| {
290 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
291 });
292
293 gpio_ports.get_pin(PinId::PC01).map(|pin| {
295 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
296 });
297
298 gpio_ports.get_pin(PinId::PC03).map(|pin| {
300 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
301 });
302
303 gpio_ports.get_pin(PinId::PC04).map(|pin| {
305 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
306 });
307
308 gpio_ports.get_pin(PinId::PC05).map(|pin| {
310 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
311 });
312
313 gpio_ports.get_pin(PinId::PB00).map(|pin| {
315 pin.set_mode(stm32f412g::gpio::Mode::AnalogMode);
316 });
317
318 cortexm4::nvic::Nvic::new(stm32f412g::nvic::EXTI9_5).enable();
320
321 let pins = [
324 PinId::PD00,
325 PinId::PD01,
326 PinId::PD04,
327 PinId::PD05,
328 PinId::PD08,
329 PinId::PD09,
330 PinId::PD10,
331 PinId::PD14,
332 PinId::PD15,
333 PinId::PD07,
334 PinId::PE07,
335 PinId::PE08,
336 PinId::PE09,
337 PinId::PE10,
338 PinId::PE11,
339 PinId::PE12,
340 PinId::PE13,
341 PinId::PE14,
342 PinId::PE15,
343 PinId::PF00,
344 ];
345
346 for pin in pins.iter() {
347 gpio_ports.get_pin(*pin).map(|pin| {
348 pin.set_mode(stm32f412g::gpio::Mode::AlternateFunctionMode);
349 pin.set_floating_state(gpio::FloatingState::PullUp);
350 pin.set_speed();
351 pin.set_alternate_function(stm32f412g::gpio::AlternateFunction::AF12);
352 });
353 }
354
355 use kernel::hil::gpio::Output;
356
357 gpio_ports.get_pin(PinId::PF05).map(|pin| {
358 pin.make_output();
359 pin.set_floating_state(gpio::FloatingState::PullNone);
360 pin.set();
361 });
362
363 gpio_ports.get_pin(PinId::PG04).map(|pin| {
364 pin.make_input();
365 });
366}
367
368unsafe fn setup_peripherals(
370 tim2: &stm32f412g::tim2::Tim2,
371 fsmc: &stm32f412g::fsmc::Fsmc,
372 trng: &stm32f412g::trng::Trng,
373) {
374 cortexm4::nvic::Nvic::new(stm32f412g::nvic::USART2).enable();
376
377 tim2.enable_clock();
379 tim2.start();
380 cortexm4::nvic::Nvic::new(stm32f412g::nvic::TIM2).enable();
381
382 fsmc.enable();
384
385 trng.enable_clock();
387}
388
389#[inline(never)]
395unsafe fn start() -> (
396 &'static kernel::Kernel,
397 STM32F412GDiscovery,
398 &'static stm32f412g::chip::Stm32f4xx<'static, Stm32f412gDefaultPeripherals<'static>>,
399) {
400 stm32f412g::init();
401
402 kernel::deferred_call::initialize_deferred_call_state::<
404 <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
405 >();
406
407 let rcc = static_init!(stm32f412g::rcc::Rcc, stm32f412g::rcc::Rcc::new());
408 let clocks = static_init!(
409 stm32f412g::clocks::Clocks<Stm32f412Specs>,
410 stm32f412g::clocks::Clocks::new(rcc)
411 );
412
413 let syscfg = static_init!(
414 stm32f412g::syscfg::Syscfg,
415 stm32f412g::syscfg::Syscfg::new(clocks)
416 );
417
418 let exti = static_init!(stm32f412g::exti::Exti, stm32f412g::exti::Exti::new(syscfg));
419
420 let dma1 = static_init!(stm32f412g::dma::Dma1, stm32f412g::dma::Dma1::new(clocks));
421 let dma2 = static_init!(stm32f412g::dma::Dma2, stm32f412g::dma::Dma2::new(clocks));
422
423 let peripherals = static_init!(
424 Stm32f412gDefaultPeripherals,
425 Stm32f412gDefaultPeripherals::new(clocks, exti, dma1, dma2)
426 );
427
428 peripherals.init();
429
430 let _ = clocks.set_ahb_prescaler(stm32f412g::rcc::AHBPrescaler::DivideBy1);
431 let _ = clocks.set_apb1_prescaler(stm32f412g::rcc::APBPrescaler::DivideBy4);
432 let _ = clocks.set_apb2_prescaler(stm32f412g::rcc::APBPrescaler::DivideBy2);
433 let _ = clocks.set_pll_frequency_mhz(PllSource::HSI, 100);
434 let _ = clocks.pll.enable();
435 let _ = clocks.set_sys_clock_source(stm32f412g::rcc::SysClockSource::PLL);
436
437 let base_peripherals = &peripherals.stm32f4;
438 setup_peripherals(
439 &base_peripherals.tim2,
440 &base_peripherals.fsmc,
441 &peripherals.trng,
442 );
443
444 set_pin_primary_functions(
445 syscfg,
446 &base_peripherals.i2c1,
447 &base_peripherals.gpio_ports,
448 clocks.get_apb1_frequency_mhz(),
449 );
450
451 setup_dma(
452 dma1,
453 &base_peripherals.dma1_streams,
454 &base_peripherals.usart2,
455 );
456
457 let processes = components::process_array::ProcessArrayComponent::new()
459 .finalize(components::process_array_component_static!(NUM_PROCS));
460 PROCESSES = Some(processes);
461
462 let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(processes.as_slice()));
464
465 let chip = static_init!(
466 stm32f412g::chip::Stm32f4xx<Stm32f412gDefaultPeripherals>,
467 stm32f412g::chip::Stm32f4xx::new(peripherals)
468 );
469 CHIP = Some(chip);
470
471 base_peripherals.usart2.enable_clock();
475 let uart_mux = components::console::UartMuxComponent::new(&base_peripherals.usart2, 115200)
476 .finalize(components::uart_mux_component_static!());
477
478 (*addr_of_mut!(io::WRITER)).set_initialized();
479
480 let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
483 let process_management_capability =
484 create_capability!(capabilities::ProcessManagementCapability);
485
486 let console = components::console::ConsoleComponent::new(
488 board_kernel,
489 capsules_core::console::DRIVER_NUM,
490 uart_mux,
491 )
492 .finalize(components::console_component_static!());
493 components::debug_writer::DebugWriterComponent::new::<
495 <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
496 >(
497 uart_mux,
498 create_capability!(capabilities::SetDebugWriterCapability),
499 )
500 .finalize(components::debug_writer_component_static!());
501
502 let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
507 LedLow<'static, stm32f412g::gpio::Pin>,
508 LedLow::new(
509 base_peripherals
510 .gpio_ports
511 .get_pin(stm32f412g::gpio::PinId::PE00)
512 .unwrap()
513 ),
514 LedLow::new(
515 base_peripherals
516 .gpio_ports
517 .get_pin(stm32f412g::gpio::PinId::PE01)
518 .unwrap()
519 ),
520 LedLow::new(
521 base_peripherals
522 .gpio_ports
523 .get_pin(stm32f412g::gpio::PinId::PE02)
524 .unwrap()
525 ),
526 LedLow::new(
527 base_peripherals
528 .gpio_ports
529 .get_pin(stm32f412g::gpio::PinId::PE03)
530 .unwrap()
531 ),
532 ));
533
534 let button = components::button::ButtonComponent::new(
536 board_kernel,
537 capsules_core::button::DRIVER_NUM,
538 components::button_component_helper!(
539 stm32f412g::gpio::Pin,
540 (
542 base_peripherals
543 .gpio_ports
544 .get_pin(stm32f412g::gpio::PinId::PA00)
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::PG01)
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::PF15)
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::PF14)
572 .unwrap(),
573 kernel::hil::gpio::ActivationMode::ActiveHigh,
574 kernel::hil::gpio::FloatingState::PullNone
575 ),
576 (
578 base_peripherals
579 .gpio_ports
580 .get_pin(stm32f412g::gpio::PinId::PG00)
581 .unwrap(),
582 kernel::hil::gpio::ActivationMode::ActiveHigh,
583 kernel::hil::gpio::FloatingState::PullNone
584 )
585 ),
586 )
587 .finalize(components::button_component_static!(stm32f412g::gpio::Pin));
588
589 let tim2 = &base_peripherals.tim2;
592 let mux_alarm = components::alarm::AlarmMuxComponent::new(tim2).finalize(
593 components::alarm_mux_component_static!(stm32f412g::tim2::Tim2),
594 );
595
596 let alarm = components::alarm::AlarmDriverComponent::new(
597 board_kernel,
598 capsules_core::alarm::DRIVER_NUM,
599 mux_alarm,
600 )
601 .finalize(components::alarm_component_static!(stm32f412g::tim2::Tim2));
602
603 let gpio = GpioComponent::new(
605 board_kernel,
606 capsules_core::gpio::DRIVER_NUM,
607 components::gpio_component_helper!(
608 stm32f412g::gpio::Pin,
609 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() ),
635 )
636 .finalize(components::gpio_component_static!(stm32f412g::gpio::Pin));
637
638 let rng = RngComponent::new(
640 board_kernel,
641 capsules_core::rng::DRIVER_NUM,
642 &peripherals.trng,
643 )
644 .finalize(components::rng_component_static!(stm32f412g::trng::Trng));
645
646 let mux_i2c = components::i2c::I2CMuxComponent::new(&base_peripherals.i2c1, None)
649 .finalize(components::i2c_mux_component_static!(stm32f412g::i2c::I2C));
650
651 let ft6x06 = components::ft6x06::Ft6x06Component::new(
652 mux_i2c,
653 0x38,
654 base_peripherals
655 .gpio_ports
656 .get_pin(stm32f412g::gpio::PinId::PG05)
657 .unwrap(),
658 )
659 .finalize(components::ft6x06_component_static!(stm32f412g::i2c::I2C));
660
661 let bus = components::bus::Bus8080BusComponent::new(&base_peripherals.fsmc).finalize(
662 components::bus8080_bus_component_static!(stm32f412g::fsmc::Fsmc,),
663 );
664
665 let tft = components::st77xx::ST77XXComponent::new(
666 mux_alarm,
667 bus,
668 None,
669 base_peripherals
670 .gpio_ports
671 .get_pin(stm32f412g::gpio::PinId::PD11),
672 &capsules_extra::st77xx::ST7789H2,
673 )
674 .finalize(components::st77xx_component_static!(
675 capsules_extra::bus::Bus8080Bus<'static, stm32f412g::fsmc::Fsmc>,
677 stm32f412g::tim2::Tim2,
679 stm32f412g::gpio::Pin,
681 ));
682
683 let _ = tft.init();
684
685 let screen = components::screen::ScreenComponent::new(
686 board_kernel,
687 capsules_extra::screen::screen::DRIVER_NUM,
688 tft,
689 Some(tft),
690 )
691 .finalize(components::screen_component_static!(1024));
692
693 let touch = components::touch::MultiTouchComponent::new(
694 board_kernel,
695 capsules_extra::touch::DRIVER_NUM,
696 ft6x06,
697 Some(ft6x06),
698 Some(tft),
699 )
700 .finalize(components::touch_component_static!());
701
702 touch.set_screen_rotation_offset(ScreenRotation::Rotated90);
703
704 let adc_mux = components::adc::AdcMuxComponent::new(&base_peripherals.adc1)
711 .finalize(components::adc_mux_component_static!(stm32f412g::adc::Adc));
712
713 let temp_sensor = components::temperature_stm::TemperatureSTMComponent::new(
714 adc_mux,
715 stm32f412g::adc::Channel::Channel18,
716 2.5,
717 0.76,
718 )
719 .finalize(components::temperature_stm_adc_component_static!(
720 stm32f412g::adc::Adc
721 ));
722
723 let temp = components::temperature::TemperatureComponent::new(
724 board_kernel,
725 capsules_extra::temperature::DRIVER_NUM,
726 temp_sensor,
727 )
728 .finalize(components::temperature_component_static!(
729 TemperatureSTMSensor
730 ));
731
732 let adc_channel_0 =
733 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel1)
734 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
735
736 let adc_channel_1 =
737 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel11)
738 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
739
740 let adc_channel_2 =
741 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel13)
742 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
743
744 let adc_channel_3 =
745 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel14)
746 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
747
748 let adc_channel_4 =
749 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel15)
750 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
751
752 let adc_channel_5 =
753 components::adc::AdcComponent::new(adc_mux, stm32f412g::adc::Channel::Channel8)
754 .finalize(components::adc_component_static!(stm32f412g::adc::Adc));
755
756 let adc_syscall =
757 components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
758 .finalize(components::adc_syscall_component_helper!(
759 adc_channel_0,
760 adc_channel_1,
761 adc_channel_2,
762 adc_channel_3,
763 adc_channel_4,
764 adc_channel_5
765 ));
766
767 let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
768 .finalize(components::process_printer_text_component_static!());
769 PROCESS_PRINTER = Some(process_printer);
770
771 let process_console = components::process_console::ProcessConsoleComponent::new(
773 board_kernel,
774 uart_mux,
775 mux_alarm,
776 process_printer,
777 Some(cortexm4::support::reset),
778 )
779 .finalize(components::process_console_component_static!(
780 stm32f412g::tim2::Tim2
781 ));
782 let _ = process_console.start();
783
784 let scheduler = components::sched::round_robin::RoundRobinComponent::new(processes)
785 .finalize(components::round_robin_component_static!(NUM_PROCS));
786
787 let stm32f412g = STM32F412GDiscovery {
788 console,
789 ipc: kernel::ipc::IPC::new(
790 board_kernel,
791 kernel::ipc::DRIVER_NUM,
792 &memory_allocation_capability,
793 ),
794 led,
795 button,
796 alarm,
797 gpio,
798 adc: adc_syscall,
799 touch,
800 screen,
801 temperature: temp,
802 rng,
803
804 scheduler,
805 systick: cortexm4::systick::SysTick::new_with_calibration(
806 (HSI_FREQUENCY_MHZ * 1_000_000) as u32,
807 ),
808 };
809
810 debug!("Initialization complete. Entering main loop");
818
819 extern "C" {
820 static _sapps: u8;
824
825 static _eapps: u8;
829
830 static mut _sappmem: u8;
834
835 static _eappmem: u8;
839 }
840
841 kernel::process::load_processes(
842 board_kernel,
843 chip,
844 core::slice::from_raw_parts(
845 core::ptr::addr_of!(_sapps),
846 core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
847 ),
848 core::slice::from_raw_parts_mut(
849 core::ptr::addr_of_mut!(_sappmem),
850 core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
851 ),
852 &FAULT_RESPONSE,
853 &process_management_capability,
854 )
855 .unwrap_or_else(|err| {
856 debug!("Error loading processes!");
857 debug!("{:?}", err);
858 });
859
860 (board_kernel, stm32f412g, chip)
866}
867
868#[no_mangle]
870pub unsafe fn main() {
871 let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
872
873 let (board_kernel, platform, chip) = start();
874 board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
875}