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