#![no_std]
#![cfg_attr(not(doc), no_main)]
#![deny(missing_docs)]
use core::ptr::addr_of;
use core::ptr::addr_of_mut;
use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
use capsules_extra::lsm303xx;
use capsules_system::process_printer::ProcessPrinterText;
use components::gpio::GpioComponent;
use kernel::capabilities;
use kernel::component::Component;
use kernel::hil::gpio::Configure;
use kernel::hil::gpio::Output;
use kernel::hil::led::LedHigh;
use kernel::hil::time::Counter;
use kernel::platform::{KernelResources, SyscallDriverLookup};
use kernel::scheduler::round_robin::RoundRobinSched;
use kernel::{create_capability, debug, static_init};
use stm32f303xc::chip::Stm32f3xxDefaultPeripherals;
use stm32f303xc::wdt;
pub mod io;
#[allow(dead_code)]
mod virtual_uart_rx_test;
const NUM_PROCS: usize = 4;
static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] =
[None, None, None, None];
static mut CHIP: Option<&'static stm32f303xc::chip::Stm32f3xx<Stm32f3xxDefaultPeripherals>> = None;
static mut PROCESS_PRINTER: Option<&'static ProcessPrinterText> = None;
const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
capsules_system::process_policies::PanicFaultPolicy {};
#[no_mangle]
#[link_section = ".stack_buffer"]
pub static mut STACK_MEMORY: [u8; 0x1700] = [0; 0x1700];
type L3GD20Sensor = components::l3gd20::L3gd20ComponentType<
capsules_core::virtualizers::virtual_spi::VirtualSpiMasterDevice<
'static,
stm32f303xc::spi::Spi<'static>,
>,
>;
type TemperatureDriver = components::temperature::TemperatureComponentType<L3GD20Sensor>;
struct STM32F3Discovery {
console: &'static capsules_core::console::Console<'static>,
ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
gpio: &'static capsules_core::gpio::GPIO<'static, stm32f303xc::gpio::Pin<'static>>,
led: &'static capsules_core::led::LedDriver<
'static,
LedHigh<'static, stm32f303xc::gpio::Pin<'static>>,
8,
>,
button: &'static capsules_core::button::Button<'static, stm32f303xc::gpio::Pin<'static>>,
ninedof: &'static capsules_extra::ninedof::NineDof<'static>,
l3gd20: &'static L3GD20Sensor,
lsm303dlhc: &'static capsules_extra::lsm303dlhc::Lsm303dlhcI2C<
'static,
capsules_core::virtualizers::virtual_i2c::I2CDevice<
'static,
stm32f303xc::i2c::I2C<'static>,
>,
>,
temp: &'static TemperatureDriver,
alarm: &'static capsules_core::alarm::AlarmDriver<
'static,
VirtualMuxAlarm<'static, stm32f303xc::tim2::Tim2<'static>>,
>,
adc: &'static capsules_core::adc::AdcVirtualized<'static>,
nonvolatile_storage:
&'static capsules_extra::nonvolatile_storage_driver::NonvolatileStorage<'static>,
scheduler: &'static RoundRobinSched<'static>,
systick: cortexm4::systick::SysTick,
watchdog: &'static wdt::WindoWdg<'static>,
}
impl SyscallDriverLookup for STM32F3Discovery {
fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
where
F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
{
match driver_num {
capsules_core::console::DRIVER_NUM => f(Some(self.console)),
capsules_core::led::DRIVER_NUM => f(Some(self.led)),
capsules_core::button::DRIVER_NUM => f(Some(self.button)),
capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
capsules_extra::l3gd20::DRIVER_NUM => f(Some(self.l3gd20)),
capsules_extra::lsm303dlhc::DRIVER_NUM => f(Some(self.lsm303dlhc)),
capsules_extra::ninedof::DRIVER_NUM => f(Some(self.ninedof)),
capsules_extra::temperature::DRIVER_NUM => f(Some(self.temp)),
kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
capsules_extra::nonvolatile_storage_driver::DRIVER_NUM => {
f(Some(self.nonvolatile_storage))
}
_ => f(None),
}
}
}
impl
KernelResources<
stm32f303xc::chip::Stm32f3xx<
'static,
stm32f303xc::chip::Stm32f3xxDefaultPeripherals<'static>,
>,
> for STM32F3Discovery
{
type SyscallDriverLookup = Self;
type SyscallFilter = ();
type ProcessFault = ();
type Scheduler = RoundRobinSched<'static>;
type SchedulerTimer = cortexm4::systick::SysTick;
type WatchDog = wdt::WindoWdg<'static>;
type ContextSwitchCallback = ();
fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
self
}
fn syscall_filter(&self) -> &Self::SyscallFilter {
&()
}
fn process_fault(&self) -> &Self::ProcessFault {
&()
}
fn scheduler(&self) -> &Self::Scheduler {
self.scheduler
}
fn scheduler_timer(&self) -> &Self::SchedulerTimer {
&self.systick
}
fn watchdog(&self) -> &Self::WatchDog {
self.watchdog
}
fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
&()
}
}
unsafe fn set_pin_primary_functions(
syscfg: &stm32f303xc::syscfg::Syscfg,
spi1: &stm32f303xc::spi::Spi,
i2c1: &stm32f303xc::i2c::I2C,
gpio_ports: &'static stm32f303xc::gpio::GpioPorts<'static>,
) {
use stm32f303xc::gpio::{AlternateFunction, Mode, PinId, PortId};
syscfg.enable_clock();
gpio_ports.get_port_from_port_id(PortId::A).enable_clock();
gpio_ports.get_port_from_port_id(PortId::B).enable_clock();
gpio_ports.get_port_from_port_id(PortId::C).enable_clock();
gpio_ports.get_port_from_port_id(PortId::D).enable_clock();
gpio_ports.get_port_from_port_id(PortId::E).enable_clock();
gpio_ports.get_port_from_port_id(PortId::F).enable_clock();
gpio_ports.get_pin(PinId::PE14).map(|pin| {
pin.make_output();
pin.set();
});
gpio_ports.get_pin(PinId::PE09).map(|pin| {
pin.make_output();
kernel::debug::assign_gpios(Some(pin), None, None);
});
gpio_ports.get_pin(PinId::PC04).map(|pin| {
pin.set_mode(Mode::AlternateFunctionMode);
pin.set_alternate_function(AlternateFunction::AF7);
});
gpio_ports.get_pin(PinId::PC05).map(|pin| {
pin.set_mode(Mode::AlternateFunctionMode);
pin.set_alternate_function(AlternateFunction::AF7);
});
gpio_ports.get_pin(PinId::PA00).map(|pin| {
pin.enable_interrupt();
});
gpio_ports.get_pin(PinId::PC01).map(|pin| {
pin.enable_interrupt();
});
gpio_ports.get_pin(PinId::PA06).map(|pin| {
pin.set_mode(Mode::AlternateFunctionMode);
pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
pin.set_alternate_function(AlternateFunction::AF5);
});
gpio_ports.get_pin(PinId::PA07).map(|pin| {
pin.make_output();
pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
pin.set_mode(Mode::AlternateFunctionMode);
pin.set_alternate_function(AlternateFunction::AF5);
});
gpio_ports.get_pin(PinId::PA05).map(|pin| {
pin.make_output();
pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
pin.set_mode(Mode::AlternateFunctionMode);
pin.set_alternate_function(AlternateFunction::AF5);
});
gpio_ports.get_pin(PinId::PE03).map(|pin| {
pin.make_output();
pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
pin.set();
});
spi1.enable_clock();
gpio_ports.get_pin(PinId::PB06).map(|pin| {
pin.set_mode(Mode::AlternateFunctionMode);
pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
pin.set_alternate_function(AlternateFunction::AF4);
});
gpio_ports.get_pin(PinId::PB07).map(|pin| {
pin.make_output();
pin.set_floating_state(kernel::hil::gpio::FloatingState::PullNone);
pin.set_mode(Mode::AlternateFunctionMode);
pin.set_alternate_function(AlternateFunction::AF4);
});
gpio_ports.get_pin(PinId::PA01).map(|pin| {
pin.set_mode(stm32f303xc::gpio::Mode::AnalogMode);
});
gpio_ports.get_pin(PinId::PA02).map(|pin| {
pin.set_mode(stm32f303xc::gpio::Mode::AnalogMode);
});
gpio_ports.get_pin(PinId::PA03).map(|pin| {
pin.set_mode(stm32f303xc::gpio::Mode::AnalogMode);
});
gpio_ports.get_pin(PinId::PF04).map(|pin| {
pin.set_mode(stm32f303xc::gpio::Mode::AnalogMode);
});
i2c1.enable_clock();
i2c1.set_speed(stm32f303xc::i2c::I2CSpeed::Speed400k, 8);
}
unsafe fn setup_peripherals(tim2: &stm32f303xc::tim2::Tim2) {
cortexm4::nvic::Nvic::new(stm32f303xc::nvic::USART1).enable();
cortexm4::nvic::Nvic::new(stm32f303xc::nvic::USART2).enable();
tim2.enable_clock();
let _ = tim2.start();
cortexm4::nvic::Nvic::new(stm32f303xc::nvic::TIM2).enable();
}
#[inline(never)]
unsafe fn start() -> (
&'static kernel::Kernel,
STM32F3Discovery,
&'static stm32f303xc::chip::Stm32f3xx<'static, Stm32f3xxDefaultPeripherals<'static>>,
) {
stm32f303xc::init();
let rcc = static_init!(stm32f303xc::rcc::Rcc, stm32f303xc::rcc::Rcc::new());
let syscfg = static_init!(
stm32f303xc::syscfg::Syscfg,
stm32f303xc::syscfg::Syscfg::new(rcc)
);
let exti = static_init!(
stm32f303xc::exti::Exti,
stm32f303xc::exti::Exti::new(syscfg)
);
let peripherals = static_init!(
Stm32f3xxDefaultPeripherals,
Stm32f3xxDefaultPeripherals::new(rcc, exti)
);
peripherals.setup_circular_deps();
set_pin_primary_functions(
syscfg,
&peripherals.spi1,
&peripherals.i2c1,
&peripherals.gpio_ports,
);
setup_peripherals(&peripherals.tim2);
let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));
let chip = static_init!(
stm32f303xc::chip::Stm32f3xx<Stm32f3xxDefaultPeripherals>,
stm32f303xc::chip::Stm32f3xx::new(peripherals)
);
CHIP = Some(chip);
peripherals.usart1.enable_clock();
peripherals.usart2.enable_clock();
let uart_mux = components::console::UartMuxComponent::new(&peripherals.usart1, 115200)
.finalize(components::uart_mux_component_static!());
(*addr_of_mut!(io::WRITER)).set_initialized();
let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
let process_management_capability =
create_capability!(capabilities::ProcessManagementCapability);
let console = components::console::ConsoleComponent::new(
board_kernel,
capsules_core::console::DRIVER_NUM,
uart_mux,
)
.finalize(components::console_component_static!());
components::debug_writer::DebugWriterComponent::new(uart_mux)
.finalize(components::debug_writer_component_static!());
let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
LedHigh<'static, stm32f303xc::gpio::Pin<'static>>,
LedHigh::new(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PE09)
.unwrap()
),
LedHigh::new(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PE08)
.unwrap()
),
LedHigh::new(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PE10)
.unwrap()
),
LedHigh::new(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PE15)
.unwrap()
),
LedHigh::new(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PE11)
.unwrap()
),
LedHigh::new(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PE14)
.unwrap()
),
LedHigh::new(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PE12)
.unwrap()
),
LedHigh::new(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PE13)
.unwrap()
),
));
let button = components::button::ButtonComponent::new(
board_kernel,
capsules_core::button::DRIVER_NUM,
components::button_component_helper!(
stm32f303xc::gpio::Pin<'static>,
(
peripherals
.gpio_ports
.get_pin(stm32f303xc::gpio::PinId::PA00)
.unwrap(),
kernel::hil::gpio::ActivationMode::ActiveHigh,
kernel::hil::gpio::FloatingState::PullNone
)
),
)
.finalize(components::button_component_static!(
stm32f303xc::gpio::Pin<'static>
));
let tim2 = &peripherals.tim2;
let mux_alarm = components::alarm::AlarmMuxComponent::new(tim2).finalize(
components::alarm_mux_component_static!(stm32f303xc::tim2::Tim2),
);
let alarm = components::alarm::AlarmDriverComponent::new(
board_kernel,
capsules_core::alarm::DRIVER_NUM,
mux_alarm,
)
.finalize(components::alarm_component_static!(stm32f303xc::tim2::Tim2));
let gpio_ports = &peripherals.gpio_ports;
let gpio = GpioComponent::new(
board_kernel,
capsules_core::gpio::DRIVER_NUM,
components::gpio_component_helper!(
stm32f303xc::gpio::Pin<'static>,
0 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC01).unwrap(),
1 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC03).unwrap(),
9 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE07).unwrap(),
11 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE11).unwrap(),
14 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB11).unwrap(),
17 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD09).unwrap(),
18 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD11).unwrap(),
19 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD13).unwrap(),
20 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD15).unwrap(),
21 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC06).unwrap(),
22 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC00).unwrap(),
23 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC02).unwrap(),
24 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF02).unwrap(),
30 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB00).unwrap(),
31 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB02).unwrap(),
32 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE08).unwrap(),
33 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE10).unwrap(),
34 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE12).unwrap(),
36 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB10).unwrap(),
39 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD08).unwrap(),
40 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD10).unwrap(),
41 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD12).unwrap(),
42 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD14).unwrap(),
43 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC07).unwrap(),
44 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF09).unwrap(),
45 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF00).unwrap(),
46 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC14).unwrap(),
47 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE06).unwrap(),
48 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE04).unwrap(),
49 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE02).unwrap(),
50 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE00).unwrap(),
51 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB08).unwrap(),
53 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB04).unwrap(),
54 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD07).unwrap(),
55 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD05).unwrap(),
56 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD03).unwrap(),
57 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD01).unwrap(),
58 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC12).unwrap(),
59 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC10).unwrap(),
60 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA14).unwrap(),
61 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF06).unwrap(),
62 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA12).unwrap(),
63 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA10).unwrap(),
64 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA08).unwrap(),
65 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC08).unwrap(),
66 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF10).unwrap(),
67 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PF01).unwrap(),
68 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC15).unwrap(),
69 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC13).unwrap(),
70 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE05).unwrap(),
71 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE03).unwrap(),
72 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE01).unwrap(),
73 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB09).unwrap(),
75 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB05).unwrap(),
76 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PB03).unwrap(),
77 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD06).unwrap(),
78 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD04).unwrap(),
79 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD02).unwrap(),
80 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PD00).unwrap(),
81 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC11).unwrap(),
82 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA15).unwrap(),
83 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA13).unwrap(),
84 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA11).unwrap(),
85 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PA09).unwrap(),
86 => gpio_ports.get_pin(stm32f303xc::gpio::PinId::PC09).unwrap()
),
)
.finalize(components::gpio_component_static!(
stm32f303xc::gpio::Pin<'static>
));
let spi_mux = components::spi::SpiMuxComponent::new(&peripherals.spi1)
.finalize(components::spi_mux_component_static!(stm32f303xc::spi::Spi));
let l3gd20 = components::l3gd20::L3gd20Component::new(
spi_mux,
gpio_ports.get_pin(stm32f303xc::gpio::PinId::PE03).unwrap(),
board_kernel,
capsules_extra::l3gd20::DRIVER_NUM,
)
.finalize(components::l3gd20_component_static!(
stm32f303xc::spi::Spi
));
l3gd20.power_on();
let temp = components::temperature::TemperatureComponent::new(
board_kernel,
capsules_extra::temperature::DRIVER_NUM,
l3gd20,
)
.finalize(components::temperature_component_static!(L3GD20Sensor));
let mux_i2c = components::i2c::I2CMuxComponent::new(&peripherals.i2c1, None)
.finalize(components::i2c_mux_component_static!(stm32f303xc::i2c::I2C));
let lsm303dlhc = components::lsm303dlhc::Lsm303dlhcI2CComponent::new(
mux_i2c,
None,
None,
board_kernel,
capsules_extra::lsm303dlhc::DRIVER_NUM,
)
.finalize(components::lsm303dlhc_component_static!(
stm32f303xc::i2c::I2C
));
if let Err(error) = lsm303dlhc.configure(
lsm303xx::Lsm303AccelDataRate::DataRate25Hz,
false,
lsm303xx::Lsm303Scale::Scale2G,
false,
true,
lsm303xx::Lsm303MagnetoDataRate::DataRate3_0Hz,
lsm303xx::Lsm303Range::Range1_9G,
) {
debug!("Failed to configure LSM303DLHC sensor ({:?})", error);
}
let ninedof = components::ninedof::NineDofComponent::new(
board_kernel,
capsules_extra::ninedof::DRIVER_NUM,
)
.finalize(components::ninedof_component_static!(l3gd20, lsm303dlhc));
let adc_mux = components::adc::AdcMuxComponent::new(&peripherals.adc1)
.finalize(components::adc_mux_component_static!(stm32f303xc::adc::Adc));
let adc_channel_2 =
components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel2)
.finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
let adc_channel_3 =
components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel3)
.finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
let adc_channel_4 =
components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel4)
.finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
let adc_channel_5 =
components::adc::AdcComponent::new(adc_mux, stm32f303xc::adc::Channel::Channel5)
.finalize(components::adc_component_static!(stm32f303xc::adc::Adc));
let adc_syscall =
components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
.finalize(components::adc_syscall_component_helper!(
adc_channel_2,
adc_channel_3,
adc_channel_4,
adc_channel_5,
));
extern "C" {
static _sstorage: u8;
static _estorage: u8;
}
let nonvolatile_storage = components::nonvolatile_storage::NonvolatileStorageComponent::new(
board_kernel,
capsules_extra::nonvolatile_storage_driver::DRIVER_NUM,
&peripherals.flash,
0x08038000, 0x8000, core::ptr::addr_of!(_sstorage) as usize,
core::ptr::addr_of!(_estorage) as usize - core::ptr::addr_of!(_sstorage) as usize,
)
.finalize(components::nonvolatile_storage_component_static!(
stm32f303xc::flash::Flash
));
let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
.finalize(components::process_printer_text_component_static!());
PROCESS_PRINTER = Some(process_printer);
let process_console = components::process_console::ProcessConsoleComponent::new(
board_kernel,
uart_mux,
mux_alarm,
process_printer,
Some(cortexm4::support::reset),
)
.finalize(components::process_console_component_static!(
stm32f303xc::tim2::Tim2
));
let _ = process_console.start();
let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
.finalize(components::round_robin_component_static!(NUM_PROCS));
let stm32f3discovery = STM32F3Discovery {
console,
ipc: kernel::ipc::IPC::new(
board_kernel,
kernel::ipc::DRIVER_NUM,
&memory_allocation_capability,
),
gpio,
led,
button,
alarm,
l3gd20,
lsm303dlhc,
ninedof,
temp,
adc: adc_syscall,
nonvolatile_storage,
scheduler,
systick: cortexm4::systick::SysTick::new_with_calibration(8_000_000),
watchdog: &peripherals.watchdog,
};
debug!("Initialization complete. Entering main loop");
extern "C" {
static _sapps: u8;
static _eapps: u8;
static mut _sappmem: u8;
static _eappmem: u8;
}
kernel::process::load_processes(
board_kernel,
chip,
core::slice::from_raw_parts(
core::ptr::addr_of!(_sapps),
core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
),
core::slice::from_raw_parts_mut(
core::ptr::addr_of_mut!(_sappmem),
core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
),
&mut *addr_of_mut!(PROCESSES),
&FAULT_RESPONSE,
&process_management_capability,
)
.unwrap_or_else(|err| {
debug!("Error loading processes!");
debug!("{:?}", err);
});
peripherals.watchdog.enable();
(board_kernel, stm32f3discovery, chip)
}
#[no_mangle]
pub unsafe fn main() {
let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
let (board_kernel, platform, chip) = start();
board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
}