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