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 components::gpio::GpioComponent;
18use kernel::capabilities;
19use kernel::component::Component;
20use kernel::debug::PanicResources;
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::scheduler::round_robin::RoundRobinSched;
27use kernel::utilities::single_thread_value::SingleThreadValue;
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
42type ChipHw = stm32f303xc::chip::Stm32f3xx<'static, Stm32f3xxDefaultPeripherals<'static>>;
43type ProcessPrinterInUse = capsules_system::process_printer::ProcessPrinterText;
44
45static PANIC_RESOURCES: SingleThreadValue<PanicResources<ChipHw, ProcessPrinterInUse>> =
47 SingleThreadValue::new(PanicResources::new());
48
49const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
51 capsules_system::process_policies::PanicFaultPolicy {};
52
53kernel::stack_size! {0x1700}
54
55type L3GD20Sensor = components::l3gd20::L3gd20ComponentType<
56 capsules_core::virtualizers::virtual_spi::VirtualSpiMasterDevice<
57 'static,
58 stm32f303xc::spi::Spi<'static>,
59 >,
60>;
61type TemperatureDriver = components::temperature::TemperatureComponentType<L3GD20Sensor>;
62
63struct STM32F3Discovery {
66 console: &'static capsules_core::console::Console<'static>,
67 ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
68 gpio: &'static capsules_core::gpio::GPIO<'static, stm32f303xc::gpio::Pin<'static>>,
69 led: &'static capsules_core::led::LedDriver<
70 'static,
71 LedHigh<'static, stm32f303xc::gpio::Pin<'static>>,
72 8,
73 >,
74 button: &'static capsules_core::button::Button<'static, stm32f303xc::gpio::Pin<'static>>,
75 ninedof: &'static capsules_extra::ninedof::NineDof<'static>,
76 l3gd20: &'static L3GD20Sensor,
77 lsm303dlhc: &'static capsules_extra::lsm303dlhc::Lsm303dlhcI2C<
78 'static,
79 capsules_core::virtualizers::virtual_i2c::I2CDevice<
80 'static,
81 stm32f303xc::i2c::I2C<'static>,
82 >,
83 >,
84 temp: &'static TemperatureDriver,
85 alarm: &'static capsules_core::alarm::AlarmDriver<
86 'static,
87 VirtualMuxAlarm<'static, stm32f303xc::tim2::Tim2<'static>>,
88 >,
89 adc: &'static capsules_core::adc::AdcVirtualized<'static>,
90 nonvolatile_storage:
91 &'static capsules_extra::nonvolatile_storage_driver::NonvolatileStorage<'static>,
92
93 scheduler: &'static RoundRobinSched<'static>,
94 systick: cortexm4::systick::SysTick,
95 watchdog: &'static wdt::WindoWdg<'static>,
96}
97
98impl SyscallDriverLookup for STM32F3Discovery {
100 fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
101 where
102 F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
103 {
104 match driver_num {
105 capsules_core::console::DRIVER_NUM => f(Some(self.console)),
106 capsules_core::led::DRIVER_NUM => f(Some(self.led)),
107 capsules_core::button::DRIVER_NUM => f(Some(self.button)),
108 capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
109 capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
110 capsules_extra::l3gd20::DRIVER_NUM => f(Some(self.l3gd20)),
111 capsules_extra::lsm303dlhc::DRIVER_NUM => f(Some(self.lsm303dlhc)),
112 capsules_extra::ninedof::DRIVER_NUM => f(Some(self.ninedof)),
113 capsules_extra::temperature::DRIVER_NUM => f(Some(self.temp)),
114 kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
115 capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
116 capsules_extra::nonvolatile_storage_driver::DRIVER_NUM => {
117 f(Some(self.nonvolatile_storage))
118 }
119 _ => f(None),
120 }
121 }
122}
123
124impl
125 KernelResources<
126 stm32f303xc::chip::Stm32f3xx<
127 'static,
128 stm32f303xc::chip::Stm32f3xxDefaultPeripherals<'static>,
129 >,
130 > for STM32F3Discovery
131{
132 type SyscallDriverLookup = Self;
133 type SyscallFilter = ();
134 type ProcessFault = ();
135 type Scheduler = RoundRobinSched<'static>;
136 type SchedulerTimer = cortexm4::systick::SysTick;
137 type WatchDog = wdt::WindoWdg<'static>;
138 type ContextSwitchCallback = ();
139
140 fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
141 self
142 }
143 fn syscall_filter(&self) -> &Self::SyscallFilter {
144 &()
145 }
146 fn process_fault(&self) -> &Self::ProcessFault {
147 &()
148 }
149 fn scheduler(&self) -> &Self::Scheduler {
150 self.scheduler
151 }
152 fn scheduler_timer(&self) -> &Self::SchedulerTimer {
153 &self.systick
154 }
155 fn watchdog(&self) -> &Self::WatchDog {
156 self.watchdog
157 }
158 fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
159 &()
160 }
161}
162
163unsafe fn set_pin_primary_functions(
165 syscfg: &stm32f303xc::syscfg::Syscfg,
166 spi1: &stm32f303xc::spi::Spi,
167 i2c1: &stm32f303xc::i2c::I2C,
168 gpio_ports: &'static stm32f303xc::gpio::GpioPorts<'static>,
169) {
170 use stm32f303xc::gpio::{AlternateFunction, Mode, PinId, PortId};
171
172 syscfg.enable_clock();
173
174 gpio_ports.get_port_from_port_id(PortId::A).enable_clock();
175 gpio_ports.get_port_from_port_id(PortId::B).enable_clock();
176 gpio_ports.get_port_from_port_id(PortId::C).enable_clock();
177 gpio_ports.get_port_from_port_id(PortId::D).enable_clock();
178 gpio_ports.get_port_from_port_id(PortId::E).enable_clock();
179 gpio_ports.get_port_from_port_id(PortId::F).enable_clock();
180
181 gpio_ports.get_pin(PinId::PE14).map(|pin| {
182 pin.make_output();
183 pin.set();
184 });
185
186 gpio_ports.get_pin(PinId::PE09).map(|pin| {
188 pin.make_output();
189
190 let debug_gpios = static_init!([&'static dyn kernel::hil::gpio::Pin; 1], [pin]);
192 kernel::debug::initialize_debug_gpio::<
193 <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
194 >();
195 kernel::debug::assign_gpios(debug_gpios);
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 kernel::deferred_call::initialize_deferred_call_state::<
378 <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
379 >();
380
381 PANIC_RESOURCES.bind_to_thread::<<ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider>();
383
384 let rcc = static_init!(stm32f303xc::rcc::Rcc, stm32f303xc::rcc::Rcc::new());
386 let syscfg = static_init!(
387 stm32f303xc::syscfg::Syscfg,
388 stm32f303xc::syscfg::Syscfg::new(rcc)
389 );
390 let exti = static_init!(
391 stm32f303xc::exti::Exti,
392 stm32f303xc::exti::Exti::new(syscfg)
393 );
394
395 let peripherals = static_init!(
396 Stm32f3xxDefaultPeripherals,
397 Stm32f3xxDefaultPeripherals::new(rcc, exti)
398 );
399
400 peripherals.setup_circular_deps();
401
402 set_pin_primary_functions(
403 syscfg,
404 &peripherals.spi1,
405 &peripherals.i2c1,
406 &peripherals.gpio_ports,
407 );
408
409 setup_peripherals(&peripherals.tim2);
410
411 let processes = components::process_array::ProcessArrayComponent::new()
413 .finalize(components::process_array_component_static!(NUM_PROCS));
414 PANIC_RESOURCES.get().map(|resources| {
415 resources.processes.put(processes.as_slice());
416 });
417
418 let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(processes.as_slice()));
420
421 let chip = static_init!(
422 stm32f303xc::chip::Stm32f3xx<Stm32f3xxDefaultPeripherals>,
423 stm32f303xc::chip::Stm32f3xx::new(peripherals)
424 );
425 PANIC_RESOURCES.get().map(|resources| {
426 resources.chip.put(chip);
427 });
428
429 peripherals.usart1.enable_clock();
433 peripherals.usart2.enable_clock();
434
435 let uart_mux = components::console::UartMuxComponent::new(&peripherals.usart1, 115200)
436 .finalize(components::uart_mux_component_static!());
437
438 (*addr_of_mut!(io::WRITER)).set_initialized();
441
442 let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
445 let process_management_capability =
446 create_capability!(capabilities::ProcessManagementCapability);
447
448 let console = components::console::ConsoleComponent::new(
450 board_kernel,
451 capsules_core::console::DRIVER_NUM,
452 uart_mux,
453 )
454 .finalize(components::console_component_static!());
455 components::debug_writer::DebugWriterComponent::new::<
457 <ChipHw as kernel::platform::chip::Chip>::ThreadIdProvider,
458 >(
459 uart_mux,
460 create_capability!(capabilities::SetDebugWriterCapability),
461 )
462 .finalize(components::debug_writer_component_static!());
463
464 let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
469 LedHigh<'static, stm32f303xc::gpio::Pin<'static>>,
470 LedHigh::new(
471 peripherals
472 .gpio_ports
473 .get_pin(stm32f303xc::gpio::PinId::PE09)
474 .unwrap()
475 ),
476 LedHigh::new(
477 peripherals
478 .gpio_ports
479 .get_pin(stm32f303xc::gpio::PinId::PE08)
480 .unwrap()
481 ),
482 LedHigh::new(
483 peripherals
484 .gpio_ports
485 .get_pin(stm32f303xc::gpio::PinId::PE10)
486 .unwrap()
487 ),
488 LedHigh::new(
489 peripherals
490 .gpio_ports
491 .get_pin(stm32f303xc::gpio::PinId::PE15)
492 .unwrap()
493 ),
494 LedHigh::new(
495 peripherals
496 .gpio_ports
497 .get_pin(stm32f303xc::gpio::PinId::PE11)
498 .unwrap()
499 ),
500 LedHigh::new(
501 peripherals
502 .gpio_ports
503 .get_pin(stm32f303xc::gpio::PinId::PE14)
504 .unwrap()
505 ),
506 LedHigh::new(
507 peripherals
508 .gpio_ports
509 .get_pin(stm32f303xc::gpio::PinId::PE12)
510 .unwrap()
511 ),
512 LedHigh::new(
513 peripherals
514 .gpio_ports
515 .get_pin(stm32f303xc::gpio::PinId::PE13)
516 .unwrap()
517 ),
518 ));
519
520 let button = components::button::ButtonComponent::new(
522 board_kernel,
523 capsules_core::button::DRIVER_NUM,
524 components::button_component_helper!(
525 stm32f303xc::gpio::Pin<'static>,
526 (
527 peripherals
528 .gpio_ports
529 .get_pin(stm32f303xc::gpio::PinId::PA00)
530 .unwrap(),
531 kernel::hil::gpio::ActivationMode::ActiveHigh,
532 kernel::hil::gpio::FloatingState::PullNone
533 )
534 ),
535 )
536 .finalize(components::button_component_static!(
537 stm32f303xc::gpio::Pin<'static>
538 ));
539
540 let tim2 = &peripherals.tim2;
543 let mux_alarm = components::alarm::AlarmMuxComponent::new(tim2).finalize(
544 components::alarm_mux_component_static!(stm32f303xc::tim2::Tim2),
545 );
546
547 let alarm = components::alarm::AlarmDriverComponent::new(
548 board_kernel,
549 capsules_core::alarm::DRIVER_NUM,
550 mux_alarm,
551 )
552 .finalize(components::alarm_component_static!(stm32f303xc::tim2::Tim2));
553
554 let gpio_ports = &peripherals.gpio_ports;
555 let gpio = GpioComponent::new(
557 board_kernel,
558 capsules_core::gpio::DRIVER_NUM,
559 components::gpio_component_helper!(
560 stm32f303xc::gpio::Pin<'static>,
561 0 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC01).unwrap(),
563 1 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC03).unwrap(),
564 9 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE07).unwrap(),
572 11 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE11).unwrap(),
574 14 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB11).unwrap(),
577 17 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD09).unwrap(),
580 18 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD11).unwrap(),
581 19 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD13).unwrap(),
582 20 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD15).unwrap(),
583 21 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC06).unwrap(),
584 22 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC00).unwrap(),
586 23 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC02).unwrap(),
587 24 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF02).unwrap(),
588 30 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB00).unwrap(),
594 31 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB02).unwrap(),
595 32 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE08).unwrap(),
596 33 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE10).unwrap(),
597 34 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE12).unwrap(),
598 36 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB10).unwrap(),
600 39 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD08).unwrap(),
603 40 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD10).unwrap(),
604 41 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD12).unwrap(),
605 42 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD14).unwrap(),
606 43 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC07).unwrap(),
607 44 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF09).unwrap(),
609 45 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF00).unwrap(),
610 46 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC14).unwrap(),
611 47 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE06).unwrap(),
612 48 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE04).unwrap(),
613 49 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE02).unwrap(),
614 50 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE00).unwrap(),
615 51 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB08).unwrap(),
616 53 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB04).unwrap(),
618 54 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD07).unwrap(),
619 55 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD05).unwrap(),
620 56 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD03).unwrap(),
621 57 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD01).unwrap(),
622 58 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC12).unwrap(),
623 59 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC10).unwrap(),
624 60 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA14).unwrap(),
625 61 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF06).unwrap(),
626 62 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA12).unwrap(),
627 63 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA10).unwrap(),
628 64 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA08).unwrap(),
629 65 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC08).unwrap(),
630 66 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF10).unwrap(),
632 67 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF01).unwrap(),
633 68 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC15).unwrap(),
634 69 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC13).unwrap(),
635 70 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE05).unwrap(),
636 71 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE03).unwrap(),
637 72 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE01).unwrap(),
638 73 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB09).unwrap(),
639 75 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB05).unwrap(),
641 76 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB03).unwrap(),
642 77 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD06).unwrap(),
643 78 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD04).unwrap(),
644 79 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD02).unwrap(),
645 80 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD00).unwrap(),
646 81 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC11).unwrap(),
647 82 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA15).unwrap(),
648 83 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA13).unwrap(),
649 84 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA11).unwrap(),
650 85 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA09).unwrap(),
651 86 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC09).unwrap()
652 ),
653 )
654 .finalize(components::gpio_component_static!(
655 stm32f303xc::gpio::Pin<'static>
656 ));
657
658 let spi_mux = components::spi::SpiMuxComponent::new(&peripherals.spi1)
660 .finalize(components::spi_mux_component_static!(stm32f303xc::spi::Spi));
661
662 let l3gd20 = components::l3gd20::L3gd20Component::new(
663 spi_mux,
664 gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE03).unwrap(),
665 board_kernel,
666 capsules_extra::l3gd20::DRIVER_NUM,
667 )
668 .finalize(components::l3gd20_component_static!(
669 stm32f303xc::spi::Spi
671 ));
672
673 l3gd20.power_on();
674
675 let temp = components::temperature::TemperatureComponent::new(
677 board_kernel,
678 capsules_extra::temperature::DRIVER_NUM,
679 l3gd20,
680 )
681 .finalize(components::temperature_component_static!(L3GD20Sensor));
682
683 let mux_i2c = components::i2c::I2CMuxComponent::new(&peripherals.i2c1, None)
686 .finalize(components::i2c_mux_component_static!(stm32f303xc::i2c::I2C));
687
688 let lsm303dlhc = components::lsm303dlhc::Lsm303dlhcI2CComponent::new(
689 mux_i2c,
690 None,
691 None,
692 board_kernel,
693 capsules_extra::lsm303dlhc::DRIVER_NUM,
694 )
695 .finalize(components::lsm303dlhc_component_static!(
696 stm32f303xc::i2c::I2C
697 ));
698
699 if let Err(error) = lsm303dlhc.configure(
700 lsm303xx::Lsm303AccelDataRate::DataRate25Hz,
701 false,
702 lsm303xx::Lsm303Scale::Scale2G,
703 false,
704 true,
705 lsm303xx::Lsm303MagnetoDataRate::DataRate3_0Hz,
706 lsm303xx::Lsm303Range::Range1_9G,
707 ) {
708 debug!("Failed to configure LSM303DLHC sensor ({:?})", error);
709 }
710
711 let ninedof = components::ninedof::NineDofComponent::new(
712 board_kernel,
713 capsules_extra::ninedof::DRIVER_NUM,
714 )
715 .finalize(components::ninedof_component_static!(l3gd20, lsm303dlhc));
716
717 let adc_mux = components::adc::AdcMuxComponent::new(&peripherals.adc1)
718 .finalize(components::adc_mux_component_static!(stm32f303xc::adc::Adc));
719
720 let adc_channel_2 =
745 components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel2)
746 .finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
747
748 let adc_channel_3 =
749 components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel3)
750 .finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
751
752 let adc_channel_4 =
753 components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel4)
754 .finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
755
756 let adc_channel_5 =
757 components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel5)
758 .finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
759
760 let adc_syscall =
761 components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
762 .finalize(components::adc_syscall_component_helper!(
763 adc_channel_2,
764 adc_channel_3,
765 adc_channel_4,
766 adc_channel_5,
767 ));
768
769 extern "C" {
772 static _sstorage: u8;
774 static _estorage: u8;
775 }
776
777 let nonvolatile_storage = components::nonvolatile_storage::NonvolatileStorageComponent::new(
778 board_kernel,
779 capsules_extra::nonvolatile_storage_driver::DRIVER_NUM,
780 &peripherals.flash,
781 0x08038000, 0x8000, core::ptr::addr_of!(_sstorage) as usize,
784 core::ptr::addr_of!(_estorage) as usize - core::ptr::addr_of!(_sstorage) as usize,
785 )
786 .finalize(components::nonvolatile_storage_component_static!(
787 stm32f303xc::flash::Flash
788 ));
789
790 let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
791 .finalize(components::process_printer_text_component_static!());
792 PANIC_RESOURCES.get().map(|resources| {
793 resources.printer.put(process_printer);
794 });
795
796 let process_console = components::process_console::ProcessConsoleComponent::new(
798 board_kernel,
799 uart_mux,
800 mux_alarm,
801 process_printer,
802 Some(cortexm4::support::reset),
803 )
804 .finalize(components::process_console_component_static!(
805 stm32f303xc::tim2::Tim2
806 ));
807 let _ = process_console.start();
808
809 let scheduler = components::sched::round_robin::RoundRobinComponent::new(processes)
810 .finalize(components::round_robin_component_static!(NUM_PROCS));
811
812 let stm32f3discovery = STM32F3Discovery {
813 console,
814 ipc: kernel::ipc::IPC::new(
815 board_kernel,
816 kernel::ipc::DRIVER_NUM,
817 &memory_allocation_capability,
818 ),
819 gpio,
820 led,
821 button,
822 alarm,
823 l3gd20,
824 lsm303dlhc,
825 ninedof,
826 temp,
827 adc: adc_syscall,
828 nonvolatile_storage,
829
830 scheduler,
831 systick: cortexm4::systick::SysTick::new_with_calibration(8_000_000),
833 watchdog: &peripherals.watchdog,
834 };
835
836 debug!("Initialization complete. Entering main loop");
842
843 extern "C" {
845 static _sapps: u8;
847 static _eapps: u8;
849 static mut _sappmem: u8;
851 static _eappmem: u8;
853 }
854
855 kernel::process::load_processes(
856 board_kernel,
857 chip,
858 core::slice::from_raw_parts(
859 core::ptr::addr_of!(_sapps),
860 core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
861 ),
862 core::slice::from_raw_parts_mut(
863 core::ptr::addr_of_mut!(_sappmem),
864 core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
865 ),
866 &FAULT_RESPONSE,
867 &process_management_capability,
868 )
869 .unwrap_or_else(|err| {
870 debug!("Error loading processes!");
871 debug!("{:?}", err);
872 });
873
874 peripherals.watchdog.enable();
876
877 (board_kernel, stm32f3discovery, chip)
883}
884
885#[no_mangle]
887pub unsafe fn main() {
888 let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
889
890 let (board_kernel, platform, chip) = start();
891 board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
892}