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