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 capsules_extra::lsm303xx;
17use capsules_system::process_printer::ProcessPrinterText;
18use components::gpio::GpioComponent;
19use kernel::capabilities;
20use kernel::component::Component;
21use kernel::hil::gpio::Configure;
22use kernel::hil::gpio::Output;
23use kernel::hil::led::LedHigh;
24use kernel::hil::time::Counter;
25use kernel::platform::{KernelResources, SyscallDriverLookup};
26use kernel::process::ProcessArray;
27use kernel::scheduler::round_robin::RoundRobinSched;
28use kernel::{create_capability, debug, static_init};
29use stm32f303xc::chip::Stm32f3xxDefaultPeripherals;
30use stm32f303xc::wdt;
31
32pub mod io;
34
35#[allow(dead_code)]
37mod virtual_uart_rx_test;
38
39const NUM_PROCS: usize = 4;
41
42static mut PROCESSES: Option<&'static ProcessArray<NUM_PROCS>> = None;
44
45static mut CHIP: Option<&'static stm32f303xc::chip::Stm32f3xx<Stm32f3xxDefaultPeripherals>> = None;
47static mut PROCESS_PRINTER: Option<&'static ProcessPrinterText> = None;
49
50const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
52 capsules_system::process_policies::PanicFaultPolicy {};
53
54kernel::stack_size! {0x1700}
55
56type L3GD20Sensor = components::l3gd20::L3gd20ComponentType<
57 capsules_core::virtualizers::virtual_spi::VirtualSpiMasterDevice<
58 'static,
59 stm32f303xc::spi::Spi<'static>,
60 >,
61>;
62type TemperatureDriver = components::temperature::TemperatureComponentType<L3GD20Sensor>;
63
64struct STM32F3Discovery {
67 console: &'static capsules_core::console::Console<'static>,
68 ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
69 gpio: &'static capsules_core::gpio::GPIO<'static, stm32f303xc::gpio::Pin<'static>>,
70 led: &'static capsules_core::led::LedDriver<
71 'static,
72 LedHigh<'static, stm32f303xc::gpio::Pin<'static>>,
73 8,
74 >,
75 button: &'static capsules_core::button::Button<'static, stm32f303xc::gpio::Pin<'static>>,
76 ninedof: &'static capsules_extra::ninedof::NineDof<'static>,
77 l3gd20: &'static L3GD20Sensor,
78 lsm303dlhc: &'static capsules_extra::lsm303dlhc::Lsm303dlhcI2C<
79 'static,
80 capsules_core::virtualizers::virtual_i2c::I2CDevice<
81 'static,
82 stm32f303xc::i2c::I2C<'static>,
83 >,
84 >,
85 temp: &'static TemperatureDriver,
86 alarm: &'static capsules_core::alarm::AlarmDriver<
87 'static,
88 VirtualMuxAlarm<'static, stm32f303xc::tim2::Tim2<'static>>,
89 >,
90 adc: &'static capsules_core::adc::AdcVirtualized<'static>,
91 nonvolatile_storage:
92 &'static capsules_extra::nonvolatile_storage_driver::NonvolatileStorage<'static>,
93
94 scheduler: &'static RoundRobinSched<'static>,
95 systick: cortexm4::systick::SysTick,
96 watchdog: &'static wdt::WindoWdg<'static>,
97}
98
99impl SyscallDriverLookup for STM32F3Discovery {
101 fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
102 where
103 F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
104 {
105 match driver_num {
106 capsules_core::console::DRIVER_NUM => f(Some(self.console)),
107 capsules_core::led::DRIVER_NUM => f(Some(self.led)),
108 capsules_core::button::DRIVER_NUM => f(Some(self.button)),
109 capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
110 capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
111 capsules_extra::l3gd20::DRIVER_NUM => f(Some(self.l3gd20)),
112 capsules_extra::lsm303dlhc::DRIVER_NUM => f(Some(self.lsm303dlhc)),
113 capsules_extra::ninedof::DRIVER_NUM => f(Some(self.ninedof)),
114 capsules_extra::temperature::DRIVER_NUM => f(Some(self.temp)),
115 kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
116 capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
117 capsules_extra::nonvolatile_storage_driver::DRIVER_NUM => {
118 f(Some(self.nonvolatile_storage))
119 }
120 _ => f(None),
121 }
122 }
123}
124
125impl
126 KernelResources<
127 stm32f303xc::chip::Stm32f3xx<
128 'static,
129 stm32f303xc::chip::Stm32f3xxDefaultPeripherals<'static>,
130 >,
131 > for STM32F3Discovery
132{
133 type SyscallDriverLookup = Self;
134 type SyscallFilter = ();
135 type ProcessFault = ();
136 type Scheduler = RoundRobinSched<'static>;
137 type SchedulerTimer = cortexm4::systick::SysTick;
138 type WatchDog = wdt::WindoWdg<'static>;
139 type ContextSwitchCallback = ();
140
141 fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
142 self
143 }
144 fn syscall_filter(&self) -> &Self::SyscallFilter {
145 &()
146 }
147 fn process_fault(&self) -> &Self::ProcessFault {
148 &()
149 }
150 fn scheduler(&self) -> &Self::Scheduler {
151 self.scheduler
152 }
153 fn scheduler_timer(&self) -> &Self::SchedulerTimer {
154 &self.systick
155 }
156 fn watchdog(&self) -> &Self::WatchDog {
157 self.watchdog
158 }
159 fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
160 &()
161 }
162}
163
164unsafe fn set_pin_primary_functions(
166 syscfg: &stm32f303xc::syscfg::Syscfg,
167 spi1: &stm32f303xc::spi::Spi,
168 i2c1: &stm32f303xc::i2c::I2C,
169 gpio_ports: &'static stm32f303xc::gpio::GpioPorts<'static>,
170) {
171 use stm32f303xc::gpio::{AlternateFunction, Mode, PinId, PortId};
172
173 syscfg.enable_clock();
174
175 gpio_ports.get_port_from_port_id(PortId::A).enable_clock();
176 gpio_ports.get_port_from_port_id(PortId::B).enable_clock();
177 gpio_ports.get_port_from_port_id(PortId::C).enable_clock();
178 gpio_ports.get_port_from_port_id(PortId::D).enable_clock();
179 gpio_ports.get_port_from_port_id(PortId::E).enable_clock();
180 gpio_ports.get_port_from_port_id(PortId::F).enable_clock();
181
182 gpio_ports.get_pin(PinId::PE14).map(|pin| {
183 pin.make_output();
184 pin.set();
185 });
186
187 gpio_ports.get_pin(PinId::PE09).map(|pin| {
189 pin.make_output();
190
191 kernel::debug::assign_gpios(Some(pin), None, None);
193 });
194
195 gpio_ports.get_pin(PinId::PC04).map(|pin| {
197 pin.set_mode(Mode::AlternateFunctionMode);
198 pin.set_alternate_function(AlternateFunction::AF7);
200 });
201 gpio_ports.get_pin(PinId::PC05).map(|pin| {
202 pin.set_mode(Mode::AlternateFunctionMode);
203 pin.set_alternate_function(AlternateFunction::AF7);
205 });
206
207 gpio_ports.get_pin(PinId::PA00).map(|pin| {
209 pin.enable_interrupt();
210 });
211
212 gpio_ports.get_pin(PinId::PC01).map(|pin| {
214 pin.enable_interrupt();
215 });
216
217 gpio_ports.get_pin(PinId::PA06).map(|pin| {
219 pin.set_mode(Mode::AlternateFunctionMode);
220 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
221 pin.set_alternate_function(AlternateFunction::AF5);
223 });
224 gpio_ports.get_pin(PinId::PA07).map(|pin| {
225 pin.make_output();
226 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
227 pin.set_mode(Mode::AlternateFunctionMode);
228 pin.set_alternate_function(AlternateFunction::AF5);
230 });
231 gpio_ports.get_pin(PinId::PA05).map(|pin| {
232 pin.make_output();
233 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
234 pin.set_mode(Mode::AlternateFunctionMode);
235 pin.set_alternate_function(AlternateFunction::AF5);
237 });
238 gpio_ports.get_pin(PinId::PE03).map(|pin| {
240 pin.make_output();
241 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
242 pin.set();
243 });
244
245 spi1.enable_clock();
246
247 gpio_ports.get_pin(PinId::PB06).map(|pin| {
249 pin.set_mode(Mode::AlternateFunctionMode);
250 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
251 pin.set_alternate_function(AlternateFunction::AF4);
253 });
254 gpio_ports.get_pin(PinId::PB07).map(|pin| {
255 pin.make_output();
256 pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
257 pin.set_mode(Mode::AlternateFunctionMode);
258 pin.set_alternate_function(AlternateFunction::AF4);
260 });
261
262 gpio_ports.get_pin(PinId::PA01).map(|pin| {
270 pin.set_mode(stm32f303xc::gpio::Mode::AnalogMode);
271 });
272
273 gpio_ports.get_pin(PinId::PA02).map(|pin| {
275 pin.set_mode(stm32f303xc::gpio::Mode::AnalogMode);
276 });
277
278 gpio_ports.get_pin(PinId::PA03).map(|pin| {
280 pin.set_mode(stm32f303xc::gpio::Mode::AnalogMode);
281 });
282
283 gpio_ports.get_pin(PinId::PF04).map(|pin| {
285 pin.set_mode(stm32f303xc::gpio::Mode::AnalogMode);
286 });
287
288 i2c1.enable_clock();
344 i2c1.set_speed(stm32f303xc::i2c::I2CSpeed::Speed400k, 8);
345}
346
347unsafe fn setup_peripherals(tim2: &stm32f303xc::tim2::Tim2) {
349 cortexm4::nvic::Nvic::new(stm32f303xc::nvic::USART1).enable();
351 cortexm4::nvic::Nvic::new(stm32f303xc::nvic::USART2).enable();
353
354 tim2.enable_clock();
356 let _ = tim2.start();
357 cortexm4::nvic::Nvic::new(stm32f303xc::nvic::TIM2).enable();
358}
359
360#[inline(never)]
366unsafe fn start() -> (
367 &'static kernel::Kernel,
368 STM32F3Discovery,
369 &'static stm32f303xc::chip::Stm32f3xx<'static, Stm32f3xxDefaultPeripherals<'static>>,
370) {
371 stm32f303xc::init();
372
373 let rcc = static_init!(stm32f303xc::rcc::Rcc, stm32f303xc::rcc::Rcc::new());
375 let syscfg = static_init!(
376 stm32f303xc::syscfg::Syscfg,
377 stm32f303xc::syscfg::Syscfg::new(rcc)
378 );
379 let exti = static_init!(
380 stm32f303xc::exti::Exti,
381 stm32f303xc::exti::Exti::new(syscfg)
382 );
383
384 let peripherals = static_init!(
385 Stm32f3xxDefaultPeripherals,
386 Stm32f3xxDefaultPeripherals::new(rcc, exti)
387 );
388
389 peripherals.setup_circular_deps();
390
391 set_pin_primary_functions(
392 syscfg,
393 &peripherals.spi1,
394 &peripherals.i2c1,
395 &peripherals.gpio_ports,
396 );
397
398 setup_peripherals(&peripherals.tim2);
399
400 let processes = components::process_array::ProcessArrayComponent::new()
402 .finalize(components::process_array_component_static!(NUM_PROCS));
403 PROCESSES = Some(processes);
404
405 let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(processes.as_slice()));
407
408 let chip = static_init!(
409 stm32f303xc::chip::Stm32f3xx<Stm32f3xxDefaultPeripherals>,
410 stm32f303xc::chip::Stm32f3xx::new(peripherals)
411 );
412 CHIP = Some(chip);
413
414 peripherals.usart1.enable_clock();
418 peripherals.usart2.enable_clock();
419
420 let uart_mux = components::console::UartMuxComponent::new(&peripherals.usart1, 115200)
421 .finalize(components::uart_mux_component_static!());
422
423 (*addr_of_mut!(io::WRITER)).set_initialized();
426
427 let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
430 let process_management_capability =
431 create_capability!(capabilities::ProcessManagementCapability);
432
433 let console = components::console::ConsoleComponent::new(
435 board_kernel,
436 capsules_core::console::DRIVER_NUM,
437 uart_mux,
438 )
439 .finalize(components::console_component_static!());
440 components::debug_writer::DebugWriterComponent::new(
442 uart_mux,
443 create_capability!(capabilities::SetDebugWriterCapability),
444 )
445 .finalize(components::debug_writer_component_static!());
446
447 let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
452 LedHigh<'static, stm32f303xc::gpio::Pin<'static>>,
453 LedHigh::new(
454 peripherals
455 .gpio_ports
456 .get_pin(stm32f303xc::gpio::PinId::PE09)
457 .unwrap()
458 ),
459 LedHigh::new(
460 peripherals
461 .gpio_ports
462 .get_pin(stm32f303xc::gpio::PinId::PE08)
463 .unwrap()
464 ),
465 LedHigh::new(
466 peripherals
467 .gpio_ports
468 .get_pin(stm32f303xc::gpio::PinId::PE10)
469 .unwrap()
470 ),
471 LedHigh::new(
472 peripherals
473 .gpio_ports
474 .get_pin(stm32f303xc::gpio::PinId::PE15)
475 .unwrap()
476 ),
477 LedHigh::new(
478 peripherals
479 .gpio_ports
480 .get_pin(stm32f303xc::gpio::PinId::PE11)
481 .unwrap()
482 ),
483 LedHigh::new(
484 peripherals
485 .gpio_ports
486 .get_pin(stm32f303xc::gpio::PinId::PE14)
487 .unwrap()
488 ),
489 LedHigh::new(
490 peripherals
491 .gpio_ports
492 .get_pin(stm32f303xc::gpio::PinId::PE12)
493 .unwrap()
494 ),
495 LedHigh::new(
496 peripherals
497 .gpio_ports
498 .get_pin(stm32f303xc::gpio::PinId::PE13)
499 .unwrap()
500 ),
501 ));
502
503 let button = components::button::ButtonComponent::new(
505 board_kernel,
506 capsules_core::button::DRIVER_NUM,
507 components::button_component_helper!(
508 stm32f303xc::gpio::Pin<'static>,
509 (
510 peripherals
511 .gpio_ports
512 .get_pin(stm32f303xc::gpio::PinId::PA00)
513 .unwrap(),
514 kernel::hil::gpio::ActivationMode::ActiveHigh,
515 kernel::hil::gpio::FloatingState::PullNone
516 )
517 ),
518 )
519 .finalize(components::button_component_static!(
520 stm32f303xc::gpio::Pin<'static>
521 ));
522
523 let tim2 = &peripherals.tim2;
526 let mux_alarm = components::alarm::AlarmMuxComponent::new(tim2).finalize(
527 components::alarm_mux_component_static!(stm32f303xc::tim2::Tim2),
528 );
529
530 let alarm = components::alarm::AlarmDriverComponent::new(
531 board_kernel,
532 capsules_core::alarm::DRIVER_NUM,
533 mux_alarm,
534 )
535 .finalize(components::alarm_component_static!(stm32f303xc::tim2::Tim2));
536
537 let gpio_ports = &peripherals.gpio_ports;
538 let gpio = GpioComponent::new(
540 board_kernel,
541 capsules_core::gpio::DRIVER_NUM,
542 components::gpio_component_helper!(
543 stm32f303xc::gpio::Pin<'static>,
544 0 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC01).unwrap(),
546 1 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC03).unwrap(),
547 9 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE07).unwrap(),
555 11 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE11).unwrap(),
557 14 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB11).unwrap(),
560 17 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD09).unwrap(),
563 18 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD11).unwrap(),
564 19 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD13).unwrap(),
565 20 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD15).unwrap(),
566 21 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC06).unwrap(),
567 22 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC00).unwrap(),
569 23 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC02).unwrap(),
570 24 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF02).unwrap(),
571 30 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB00).unwrap(),
577 31 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB02).unwrap(),
578 32 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE08).unwrap(),
579 33 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE10).unwrap(),
580 34 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE12).unwrap(),
581 36 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB10).unwrap(),
583 39 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD08).unwrap(),
586 40 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD10).unwrap(),
587 41 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD12).unwrap(),
588 42 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD14).unwrap(),
589 43 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC07).unwrap(),
590 44 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF09).unwrap(),
592 45 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF00).unwrap(),
593 46 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC14).unwrap(),
594 47 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE06).unwrap(),
595 48 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE04).unwrap(),
596 49 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE02).unwrap(),
597 50 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE00).unwrap(),
598 51 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB08).unwrap(),
599 53 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB04).unwrap(),
601 54 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD07).unwrap(),
602 55 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD05).unwrap(),
603 56 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD03).unwrap(),
604 57 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD01).unwrap(),
605 58 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC12).unwrap(),
606 59 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC10).unwrap(),
607 60 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA14).unwrap(),
608 61 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF06).unwrap(),
609 62 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA12).unwrap(),
610 63 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA10).unwrap(),
611 64 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA08).unwrap(),
612 65 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC08).unwrap(),
613 66 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF10).unwrap(),
615 67 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF01).unwrap(),
616 68 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC15).unwrap(),
617 69 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC13).unwrap(),
618 70 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE05).unwrap(),
619 71 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE03).unwrap(),
620 72 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE01).unwrap(),
621 73 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB09).unwrap(),
622 75 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB05).unwrap(),
624 76 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB03).unwrap(),
625 77 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD06).unwrap(),
626 78 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD04).unwrap(),
627 79 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD02).unwrap(),
628 80 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD00).unwrap(),
629 81 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC11).unwrap(),
630 82 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA15).unwrap(),
631 83 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA13).unwrap(),
632 84 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA11).unwrap(),
633 85 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA09).unwrap(),
634 86 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC09).unwrap()
635 ),
636 )
637 .finalize(components::gpio_component_static!(
638 stm32f303xc::gpio::Pin<'static>
639 ));
640
641 let spi_mux = components::spi::SpiMuxComponent::new(&peripherals.spi1)
643 .finalize(components::spi_mux_component_static!(stm32f303xc::spi::Spi));
644
645 let l3gd20 = components::l3gd20::L3gd20Component::new(
646 spi_mux,
647 gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE03).unwrap(),
648 board_kernel,
649 capsules_extra::l3gd20::DRIVER_NUM,
650 )
651 .finalize(components::l3gd20_component_static!(
652 stm32f303xc::spi::Spi
654 ));
655
656 l3gd20.power_on();
657
658 let temp = components::temperature::TemperatureComponent::new(
660 board_kernel,
661 capsules_extra::temperature::DRIVER_NUM,
662 l3gd20,
663 )
664 .finalize(components::temperature_component_static!(L3GD20Sensor));
665
666 let mux_i2c = components::i2c::I2CMuxComponent::new(&peripherals.i2c1, None)
669 .finalize(components::i2c_mux_component_static!(stm32f303xc::i2c::I2C));
670
671 let lsm303dlhc = components::lsm303dlhc::Lsm303dlhcI2CComponent::new(
672 mux_i2c,
673 None,
674 None,
675 board_kernel,
676 capsules_extra::lsm303dlhc::DRIVER_NUM,
677 )
678 .finalize(components::lsm303dlhc_component_static!(
679 stm32f303xc::i2c::I2C
680 ));
681
682 if let Err(error) = lsm303dlhc.configure(
683 lsm303xx::Lsm303AccelDataRate::DataRate25Hz,
684 false,
685 lsm303xx::Lsm303Scale::Scale2G,
686 false,
687 true,
688 lsm303xx::Lsm303MagnetoDataRate::DataRate3_0Hz,
689 lsm303xx::Lsm303Range::Range1_9G,
690 ) {
691 debug!("Failed to configure LSM303DLHC sensor ({:?})", error);
692 }
693
694 let ninedof = components::ninedof::NineDofComponent::new(
695 board_kernel,
696 capsules_extra::ninedof::DRIVER_NUM,
697 )
698 .finalize(components::ninedof_component_static!(l3gd20, lsm303dlhc));
699
700 let adc_mux = components::adc::AdcMuxComponent::new(&peripherals.adc1)
701 .finalize(components::adc_mux_component_static!(stm32f303xc::adc::Adc));
702
703 let adc_channel_2 =
728 components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel2)
729 .finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
730
731 let adc_channel_3 =
732 components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel3)
733 .finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
734
735 let adc_channel_4 =
736 components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel4)
737 .finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
738
739 let adc_channel_5 =
740 components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel5)
741 .finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
742
743 let adc_syscall =
744 components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
745 .finalize(components::adc_syscall_component_helper!(
746 adc_channel_2,
747 adc_channel_3,
748 adc_channel_4,
749 adc_channel_5,
750 ));
751
752 extern "C" {
755 static _sstorage: u8;
757 static _estorage: u8;
758 }
759
760 let nonvolatile_storage = components::nonvolatile_storage::NonvolatileStorageComponent::new(
761 board_kernel,
762 capsules_extra::nonvolatile_storage_driver::DRIVER_NUM,
763 &peripherals.flash,
764 0x08038000, 0x8000, core::ptr::addr_of!(_sstorage) as usize,
767 core::ptr::addr_of!(_estorage) as usize - core::ptr::addr_of!(_sstorage) as usize,
768 )
769 .finalize(components::nonvolatile_storage_component_static!(
770 stm32f303xc::flash::Flash
771 ));
772
773 let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
774 .finalize(components::process_printer_text_component_static!());
775 PROCESS_PRINTER = Some(process_printer);
776
777 let process_console = components::process_console::ProcessConsoleComponent::new(
779 board_kernel,
780 uart_mux,
781 mux_alarm,
782 process_printer,
783 Some(cortexm4::support::reset),
784 )
785 .finalize(components::process_console_component_static!(
786 stm32f303xc::tim2::Tim2
787 ));
788 let _ = process_console.start();
789
790 let scheduler = components::sched::round_robin::RoundRobinComponent::new(processes)
791 .finalize(components::round_robin_component_static!(NUM_PROCS));
792
793 let stm32f3discovery = STM32F3Discovery {
794 console,
795 ipc: kernel::ipc::IPC::new(
796 board_kernel,
797 kernel::ipc::DRIVER_NUM,
798 &memory_allocation_capability,
799 ),
800 gpio,
801 led,
802 button,
803 alarm,
804 l3gd20,
805 lsm303dlhc,
806 ninedof,
807 temp,
808 adc: adc_syscall,
809 nonvolatile_storage,
810
811 scheduler,
812 systick: cortexm4::systick::SysTick::new_with_calibration(8_000_000),
814 watchdog: &peripherals.watchdog,
815 };
816
817 debug!("Initialization complete. Entering main loop");
823
824 extern "C" {
826 static _sapps: u8;
828 static _eapps: u8;
830 static mut _sappmem: u8;
832 static _eappmem: u8;
834 }
835
836 kernel::process::load_processes(
837 board_kernel,
838 chip,
839 core::slice::from_raw_parts(
840 core::ptr::addr_of!(_sapps),
841 core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
842 ),
843 core::slice::from_raw_parts_mut(
844 core::ptr::addr_of_mut!(_sappmem),
845 core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
846 ),
847 &FAULT_RESPONSE,
848 &process_management_capability,
849 )
850 .unwrap_or_else(|err| {
851 debug!("Error loading processes!");
852 debug!("{:?}", err);
853 });
854
855 peripherals.watchdog.enable();
857
858 (board_kernel, stm32f3discovery, chip)
864}
865
866#[no_mangle]
868pub unsafe fn main() {
869 let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
870
871 let (board_kernel, platform, chip) = start();
872 board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
873}