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