particle_boron/
main.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2022.
4
5//! Tock kernel for the Particle Boron.
6//!
7//! It is based on nRF52840 SoC (Cortex M4 core with a BLE transceiver) with
8//! many exported I/O and peripherals.
9
10#![no_std]
11#![no_main]
12#![deny(missing_docs)]
13
14use core::ptr::addr_of;
15use core::ptr::addr_of_mut;
16
17use capsules_core::i2c_master_slave_driver::I2CMasterSlaveDriver;
18use capsules_core::virtualizers::virtual_aes_ccm::MuxAES128CCM;
19use capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm;
20use kernel::component::Component;
21use kernel::deferred_call::DeferredCallClient;
22use kernel::hil::gpio::Configure;
23use kernel::hil::gpio::FloatingState;
24use kernel::hil::i2c::{I2CMaster, I2CSlave};
25use kernel::hil::led::LedLow;
26use kernel::hil::symmetric_encryption::AES128;
27use kernel::hil::time::Counter;
28use kernel::platform::{KernelResources, SyscallDriverLookup};
29use kernel::scheduler::round_robin::RoundRobinSched;
30#[allow(unused_imports)]
31use kernel::{capabilities, create_capability, debug, debug_gpio, debug_verbose, static_init};
32use nrf52840::gpio::Pin;
33use nrf52840::interrupt_service::Nrf52840DefaultPeripherals;
34#[allow(unused_imports)]
35use nrf52_components::{self, UartChannel, UartPins};
36
37// The Particle Boron LEDs
38const LED_USR_PIN: Pin = Pin::P1_12;
39const LED2_R_PIN: Pin = Pin::P0_13;
40const LED2_G_PIN: Pin = Pin::P0_14;
41const LED2_B_PIN: Pin = Pin::P0_15;
42
43// The Particle Boron buttons
44const BUTTON_PIN: Pin = Pin::P0_11;
45const BUTTON_RST_PIN: Pin = Pin::P0_18;
46
47// UART Pins (CTS/RTS Unused)
48const _UART_RTS: Option<Pin> = Some(Pin::P0_30);
49const _UART_CTS: Option<Pin> = Some(Pin::P0_31);
50const UART_TXD: Pin = Pin::P0_06;
51const UART_RXD: Pin = Pin::P0_08;
52
53// SPI pins not currently in use, but left here for convenience
54const _SPI_MOSI: Pin = Pin::P1_13;
55const _SPI_MISO: Pin = Pin::P1_14;
56const _SPI_CLK: Pin = Pin::P1_15;
57
58// I2C Pins
59const I2C_SDA_PIN: Pin = Pin::P0_26;
60const I2C_SCL_PIN: Pin = Pin::P0_27;
61
62// Constants related to the configuration of the 15.4 network stack; DEFAULT_EXT_SRC_MAC
63// should be replaced by an extended src address generated from device serial number
64const SRC_MAC: u16 = 0xf00f;
65const PAN_ID: u16 = 0xABCD;
66const DEFAULT_EXT_SRC_MAC: [u8; 8] = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77];
67
68/// UART Writer
69pub mod io;
70
71// State for loading and holding applications.
72// How should the kernel respond when a process faults.
73const FAULT_RESPONSE: capsules_system::process_policies::PanicFaultPolicy =
74    capsules_system::process_policies::PanicFaultPolicy {};
75
76// Number of concurrent processes this platform supports.
77const NUM_PROCS: usize = 8;
78
79static mut PROCESSES: [Option<&'static dyn kernel::process::Process>; NUM_PROCS] =
80    [None; NUM_PROCS];
81
82// Static reference to chip for panic dumps
83static mut CHIP: Option<&'static nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>> = None;
84// Static reference to process printer for panic dumps
85static mut PROCESS_PRINTER: Option<&'static capsules_system::process_printer::ProcessPrinterText> =
86    None;
87static mut NRF52_POWER: Option<&'static nrf52840::power::Power> = None;
88
89/// Dummy buffer that causes the linker to reserve enough space for the stack.
90#[no_mangle]
91#[link_section = ".stack_buffer"]
92pub static mut STACK_MEMORY: [u8; 0x1000] = [0; 0x1000];
93
94type TemperatureDriver =
95    components::temperature::TemperatureComponentType<nrf52840::temperature::Temp<'static>>;
96type RngDriver = components::rng::RngComponentType<nrf52840::trng::Trng<'static>>;
97
98type Ieee802154Driver = components::ieee802154::Ieee802154ComponentType<
99    nrf52840::ieee802154_radio::Radio<'static>,
100    nrf52840::aes::AesECB<'static>,
101>;
102
103/// Supported drivers by the platform
104pub struct Platform {
105    ble_radio: &'static capsules_extra::ble_advertising_driver::BLE<
106        'static,
107        nrf52840::ble_radio::Radio<'static>,
108        VirtualMuxAlarm<'static, nrf52840::rtc::Rtc<'static>>,
109    >,
110    ieee802154_radio: &'static Ieee802154Driver,
111    button: &'static capsules_core::button::Button<'static, nrf52840::gpio::GPIOPin<'static>>,
112    console: &'static capsules_core::console::Console<'static>,
113    gpio: &'static capsules_core::gpio::GPIO<'static, nrf52840::gpio::GPIOPin<'static>>,
114    led: &'static capsules_core::led::LedDriver<
115        'static,
116        LedLow<'static, nrf52840::gpio::GPIOPin<'static>>,
117        4,
118    >,
119    adc: &'static capsules_core::adc::AdcVirtualized<'static>,
120    rng: &'static RngDriver,
121    temp: &'static TemperatureDriver,
122    ipc: kernel::ipc::IPC<{ NUM_PROCS as u8 }>,
123    i2c_master_slave: &'static capsules_core::i2c_master_slave_driver::I2CMasterSlaveDriver<
124        'static,
125        nrf52840::i2c::TWI<'static>,
126    >,
127    alarm: &'static capsules_core::alarm::AlarmDriver<
128        'static,
129        capsules_core::virtualizers::virtual_alarm::VirtualMuxAlarm<
130            'static,
131            nrf52840::rtc::Rtc<'static>,
132        >,
133    >,
134    scheduler: &'static RoundRobinSched<'static>,
135    systick: cortexm4::systick::SysTick,
136}
137
138impl SyscallDriverLookup for Platform {
139    fn with_driver<F, R>(&self, driver_num: usize, f: F) -> R
140    where
141        F: FnOnce(Option<&dyn kernel::syscall::SyscallDriver>) -> R,
142    {
143        match driver_num {
144            capsules_core::console::DRIVER_NUM => f(Some(self.console)),
145            capsules_core::gpio::DRIVER_NUM => f(Some(self.gpio)),
146            capsules_core::alarm::DRIVER_NUM => f(Some(self.alarm)),
147            capsules_core::led::DRIVER_NUM => f(Some(self.led)),
148            capsules_core::button::DRIVER_NUM => f(Some(self.button)),
149            capsules_core::adc::DRIVER_NUM => f(Some(self.adc)),
150            capsules_core::rng::DRIVER_NUM => f(Some(self.rng)),
151            capsules_extra::ble_advertising_driver::DRIVER_NUM => f(Some(self.ble_radio)),
152            capsules_extra::ieee802154::DRIVER_NUM => f(Some(self.ieee802154_radio)),
153            capsules_extra::temperature::DRIVER_NUM => f(Some(self.temp)),
154            kernel::ipc::DRIVER_NUM => f(Some(&self.ipc)),
155            capsules_core::i2c_master_slave_driver::DRIVER_NUM => f(Some(self.i2c_master_slave)),
156            _ => f(None),
157        }
158    }
159}
160
161impl KernelResources<nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'static>>>
162    for Platform
163{
164    type SyscallDriverLookup = Self;
165    type SyscallFilter = ();
166    type ProcessFault = ();
167    type Scheduler = RoundRobinSched<'static>;
168    type SchedulerTimer = cortexm4::systick::SysTick;
169    type WatchDog = ();
170    type ContextSwitchCallback = ();
171
172    fn syscall_driver_lookup(&self) -> &Self::SyscallDriverLookup {
173        self
174    }
175    fn syscall_filter(&self) -> &Self::SyscallFilter {
176        &()
177    }
178    fn process_fault(&self) -> &Self::ProcessFault {
179        &()
180    }
181    fn scheduler(&self) -> &Self::Scheduler {
182        self.scheduler
183    }
184    fn scheduler_timer(&self) -> &Self::SchedulerTimer {
185        &self.systick
186    }
187    fn watchdog(&self) -> &Self::WatchDog {
188        &()
189    }
190    fn context_switch_callback(&self) -> &Self::ContextSwitchCallback {
191        &()
192    }
193}
194
195/// This is in a separate, inline(never) function so that its stack frame is
196/// removed when this function returns. Otherwise, the stack space used for
197/// these static_inits is wasted.
198#[inline(never)]
199unsafe fn create_peripherals() -> &'static mut Nrf52840DefaultPeripherals<'static> {
200    let ieee802154_ack_buf = static_init!(
201        [u8; nrf52840::ieee802154_radio::ACK_BUF_SIZE],
202        [0; nrf52840::ieee802154_radio::ACK_BUF_SIZE]
203    );
204    // Initialize chip peripheral drivers
205    let nrf52840_peripherals = static_init!(
206        Nrf52840DefaultPeripherals,
207        Nrf52840DefaultPeripherals::new(ieee802154_ack_buf)
208    );
209
210    nrf52840_peripherals
211}
212
213/// This is in a separate, inline(never) function so that its stack frame is
214/// removed when this function returns. Otherwise, the stack space used for
215/// these static_inits is wasted.
216#[inline(never)]
217pub unsafe fn start_particle_boron() -> (
218    &'static kernel::Kernel,
219    Platform,
220    &'static nrf52840::chip::NRF52<'static, Nrf52840DefaultPeripherals<'static>>,
221) {
222    nrf52840::init();
223
224    let nrf52840_peripherals = create_peripherals();
225
226    // set up circular peripheral dependencies
227    nrf52840_peripherals.init();
228    let base_peripherals = &nrf52840_peripherals.nrf52;
229
230    // Save a reference to the power module for resetting the board into the
231    // bootloader.
232    NRF52_POWER = Some(&base_peripherals.pwr_clk);
233
234    let board_kernel = static_init!(kernel::Kernel, kernel::Kernel::new(&*addr_of!(PROCESSES)));
235
236    //--------------------------------------------------------------------------
237    // CAPABILITIES
238    //--------------------------------------------------------------------------
239
240    // Create capabilities that the board needs to call certain protected kernel
241    // functions.
242    let process_management_capability =
243        create_capability!(capabilities::ProcessManagementCapability);
244    let memory_allocation_capability = create_capability!(capabilities::MemoryAllocationCapability);
245
246    //--------------------------------------------------------------------------
247    // DEBUG GPIO
248    //--------------------------------------------------------------------------
249
250    let gpio_port = &nrf52840_peripherals.gpio_port;
251    // Configure kernel debug GPIOs as early as possible. These are used by the
252    // `debug_gpio!(0, toggle)` macro. We configure these early so that the
253    // macro is available during most of the setup code and kernel execution.
254    kernel::debug::assign_gpios(Some(&gpio_port[LED2_R_PIN]), None, None);
255
256    let uart_channel = UartChannel::Pins(UartPins::new(None, UART_TXD, None, UART_RXD));
257
258    //--------------------------------------------------------------------------
259    // GPIO
260    //--------------------------------------------------------------------------
261
262    let gpio = components::gpio::GpioComponent::new(
263        board_kernel,
264        capsules_core::gpio::DRIVER_NUM,
265        components::gpio_component_helper!(
266            nrf52840::gpio::GPIOPin,
267            // Left Side pins on mesh feather
268            // A0 - ADC
269            // 0 => &nrf52840_peripherals.gpio_port[Pin::P0_03],
270            // A1 - ADC
271            // 1 => &nrf52840_peripherals.gpio_port[Pin::P0_04],
272            // A2 - ADC
273            // 2 => &nrf52840_peripherals.gpio_port[Pin::P0_28],
274            // A3 - ADC
275            // 3 => &nrf52840_peripherals.gpio_port[Pin::P0_29],
276            // A4 - ADC
277            // 4 => &nrf52840_peripherals.gpio_port[Pin::P0_30],
278            // A5 - ADC
279            // 5 => &nrf52840_peripherals.gpio_port[Pin::P0_31],
280            //D13
281            6 => &nrf52840_peripherals.gpio_port[Pin::P1_15],
282            //D12
283            7 => &nrf52840_peripherals.gpio_port[Pin::P1_13],
284            //D11
285            8 => &nrf52840_peripherals.gpio_port[Pin::P1_14],
286            //D10
287            9 => &nrf52840_peripherals.gpio_port[Pin::P0_08],
288            //D9
289            10 => &nrf52840_peripherals.gpio_port[Pin::P0_06],
290            // Right Side pins on mesh feather
291            //D8
292            11 => &nrf52840_peripherals.gpio_port[Pin::P1_03],
293            //D7: Bound to LED_USR_PIN (Active Low)
294            12 => &nrf52840_peripherals.gpio_port[Pin::P1_12],
295            //D6
296            13 => &nrf52840_peripherals.gpio_port[Pin::P1_11],
297            //D5
298            14 => &nrf52840_peripherals.gpio_port[Pin::P1_10],
299            //D4
300            15 => &nrf52840_peripherals.gpio_port[Pin::P1_08],
301            //D3
302            16 => &nrf52840_peripherals.gpio_port[Pin::P1_02],
303            //D2
304            17 => &nrf52840_peripherals.gpio_port[Pin::P0_01],
305            //D1
306            18 => &nrf52840_peripherals.gpio_port[Pin::P0_27],
307            //D0
308            19 => &nrf52840_peripherals.gpio_port[Pin::P0_26],
309        ),
310    )
311    .finalize(components::gpio_component_static!(nrf52840::gpio::GPIOPin));
312
313    //--------------------------------------------------------------------------
314    // Buttons
315    //--------------------------------------------------------------------------
316
317    let button = components::button::ButtonComponent::new(
318        board_kernel,
319        capsules_core::button::DRIVER_NUM,
320        components::button_component_helper!(
321            nrf52840::gpio::GPIOPin,
322            (
323                &nrf52840_peripherals.gpio_port[BUTTON_PIN],
324                kernel::hil::gpio::ActivationMode::ActiveLow,
325                kernel::hil::gpio::FloatingState::PullUp
326            )
327        ),
328    )
329    .finalize(components::button_component_static!(
330        nrf52840::gpio::GPIOPin
331    ));
332
333    //--------------------------------------------------------------------------
334    // LEDs
335    //--------------------------------------------------------------------------
336
337    let led = components::led::LedsComponent::new().finalize(components::led_component_static!(
338        LedLow<'static, nrf52840::gpio::GPIOPin>,
339        LedLow::new(&nrf52840_peripherals.gpio_port[LED_USR_PIN]),
340        LedLow::new(&nrf52840_peripherals.gpio_port[LED2_R_PIN]),
341        LedLow::new(&nrf52840_peripherals.gpio_port[LED2_G_PIN]),
342        LedLow::new(&nrf52840_peripherals.gpio_port[LED2_B_PIN]),
343    ));
344
345    nrf52_components::startup::NrfStartupComponent::new(
346        false,
347        BUTTON_RST_PIN,
348        nrf52840::uicr::Regulator0Output::V3_0,
349        &base_peripherals.nvmc,
350    )
351    .finalize(());
352
353    //--------------------------------------------------------------------------
354    // ALARM & TIMER
355    //--------------------------------------------------------------------------
356
357    let rtc = &base_peripherals.rtc;
358    let _ = rtc.start();
359    let mux_alarm = components::alarm::AlarmMuxComponent::new(rtc)
360        .finalize(components::alarm_mux_component_static!(nrf52840::rtc::Rtc));
361    let alarm = components::alarm::AlarmDriverComponent::new(
362        board_kernel,
363        capsules_core::alarm::DRIVER_NUM,
364        mux_alarm,
365    )
366    .finalize(components::alarm_component_static!(nrf52840::rtc::Rtc));
367
368    //--------------------------------------------------------------------------
369    // UART & CONSOLE & DEBUG
370    //--------------------------------------------------------------------------
371
372    let uart_channel = nrf52_components::UartChannelComponent::new(
373        uart_channel,
374        mux_alarm,
375        &base_peripherals.uarte0,
376    )
377    .finalize(nrf52_components::uart_channel_component_static!(
378        nrf52840::rtc::Rtc
379    ));
380
381    // Process Printer for displaying process information.
382    let process_printer = components::process_printer::ProcessPrinterTextComponent::new()
383        .finalize(components::process_printer_text_component_static!());
384    PROCESS_PRINTER = Some(process_printer);
385
386    // Create a shared UART channel for the console and for kernel debug.
387    let uart_mux = components::console::UartMuxComponent::new(uart_channel, 115200)
388        .finalize(components::uart_mux_component_static!(132));
389
390    // Setup the console.
391    let console = components::console::ConsoleComponent::new(
392        board_kernel,
393        capsules_core::console::DRIVER_NUM,
394        uart_mux,
395    )
396    .finalize(components::console_component_static!(132, 132));
397    // Create the debugger object that handles calls to `debug!()`.
398    components::debug_writer::DebugWriterComponent::new(
399        uart_mux,
400        create_capability!(capabilities::SetDebugWriterCapability),
401    )
402    .finalize(components::debug_writer_component_static!());
403
404    //--------------------------------------------------------------------------
405    // WIRELESS
406    //--------------------------------------------------------------------------
407
408    let ble_radio = components::ble::BLEComponent::new(
409        board_kernel,
410        capsules_extra::ble_advertising_driver::DRIVER_NUM,
411        &base_peripherals.ble_radio,
412        mux_alarm,
413    )
414    .finalize(components::ble_component_static!(
415        nrf52840::rtc::Rtc,
416        nrf52840::ble_radio::Radio
417    ));
418
419    let aes_mux = static_init!(
420        MuxAES128CCM<'static, nrf52840::aes::AesECB>,
421        MuxAES128CCM::new(&base_peripherals.ecb,)
422    );
423    base_peripherals.ecb.set_client(aes_mux);
424    aes_mux.register();
425
426    let (ieee802154_radio, _mux_mac) = components::ieee802154::Ieee802154Component::new(
427        board_kernel,
428        capsules_extra::ieee802154::DRIVER_NUM,
429        &nrf52840_peripherals.ieee802154_radio,
430        aes_mux,
431        PAN_ID,
432        SRC_MAC,
433        DEFAULT_EXT_SRC_MAC,
434    )
435    .finalize(components::ieee802154_component_static!(
436        nrf52840::ieee802154_radio::Radio,
437        nrf52840::aes::AesECB<'static>
438    ));
439
440    //--------------------------------------------------------------------------
441    // Sensor
442    //--------------------------------------------------------------------------
443
444    let temp = components::temperature::TemperatureComponent::new(
445        board_kernel,
446        capsules_extra::temperature::DRIVER_NUM,
447        &base_peripherals.temp,
448    )
449    .finalize(components::temperature_component_static!(
450        nrf52840::temperature::Temp
451    ));
452
453    //--------------------------------------------------------------------------
454    // RANDOM NUMBERS
455    //--------------------------------------------------------------------------
456
457    let rng = components::rng::RngComponent::new(
458        board_kernel,
459        capsules_core::rng::DRIVER_NUM,
460        &base_peripherals.trng,
461    )
462    .finalize(components::rng_component_static!(nrf52840::trng::Trng));
463
464    //--------------------------------------------------------------------------
465    // ADC
466    //--------------------------------------------------------------------------
467
468    base_peripherals.adc.calibrate();
469
470    let adc_mux = components::adc::AdcMuxComponent::new(&base_peripherals.adc)
471        .finalize(components::adc_mux_component_static!(nrf52840::adc::Adc));
472
473    let adc_syscall =
474        components::adc::AdcVirtualComponent::new(board_kernel, capsules_core::adc::DRIVER_NUM)
475            .finalize(components::adc_syscall_component_helper!(
476                // BRD_A0
477                components::adc::AdcComponent::new(
478                    adc_mux,
479                    nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput1)
480                )
481                .finalize(components::adc_component_static!(nrf52840::adc::Adc)),
482                // BRD_A1
483                components::adc::AdcComponent::new(
484                    adc_mux,
485                    nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput2)
486                )
487                .finalize(components::adc_component_static!(nrf52840::adc::Adc)),
488                // BRD_A2
489                components::adc::AdcComponent::new(
490                    adc_mux,
491                    nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput4)
492                )
493                .finalize(components::adc_component_static!(nrf52840::adc::Adc)),
494                // BRD_A3
495                components::adc::AdcComponent::new(
496                    adc_mux,
497                    nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput5)
498                )
499                .finalize(components::adc_component_static!(nrf52840::adc::Adc)),
500                // BRD_A4
501                components::adc::AdcComponent::new(
502                    adc_mux,
503                    nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput6)
504                )
505                .finalize(components::adc_component_static!(nrf52840::adc::Adc)),
506                // BRD_A5
507                components::adc::AdcComponent::new(
508                    adc_mux,
509                    nrf52840::adc::AdcChannelSetup::new(nrf52840::adc::AdcChannel::AnalogInput7)
510                )
511                .finalize(components::adc_component_static!(nrf52840::adc::Adc)),
512            ));
513
514    //--------------------------------------------------------------------------
515    // I2C Master/Slave
516    //--------------------------------------------------------------------------
517
518    let i2c_master_buffer = static_init!([u8; 128], [0; 128]);
519    let i2c_slave_buffer1 = static_init!([u8; 128], [0; 128]);
520    let i2c_slave_buffer2 = static_init!([u8; 128], [0; 128]);
521
522    let i2c_master_slave = static_init!(
523        I2CMasterSlaveDriver<nrf52840::i2c::TWI<'static>>,
524        I2CMasterSlaveDriver::new(
525            &base_peripherals.twi1,
526            i2c_master_buffer,
527            i2c_slave_buffer1,
528            i2c_slave_buffer2,
529            board_kernel.create_grant(
530                capsules_core::i2c_master_slave_driver::DRIVER_NUM,
531                &memory_allocation_capability
532            ),
533        )
534    );
535    base_peripherals.twi1.configure(
536        nrf52840::pinmux::Pinmux::new(I2C_SCL_PIN as u32),
537        nrf52840::pinmux::Pinmux::new(I2C_SDA_PIN as u32),
538    );
539    base_peripherals.twi1.set_master_client(i2c_master_slave);
540    base_peripherals.twi1.set_slave_client(i2c_master_slave);
541    // Note: strongly suggested to use external pull-ups for higher speeds
542    //       to maintain signal integrity.
543    base_peripherals.twi1.set_speed(nrf52840::i2c::Speed::K400);
544
545    // I2C pin cfg for target
546    nrf52840_peripherals.gpio_port[I2C_SDA_PIN].set_i2c_pin_cfg();
547    nrf52840_peripherals.gpio_port[I2C_SCL_PIN].set_i2c_pin_cfg();
548    // Enable internal pull-ups
549    nrf52840_peripherals.gpio_port[I2C_SDA_PIN].set_floating_state(FloatingState::PullUp);
550    nrf52840_peripherals.gpio_port[I2C_SCL_PIN].set_floating_state(FloatingState::PullUp);
551
552    //--------------------------------------------------------------------------
553    // FINAL SETUP AND BOARD BOOT
554    //--------------------------------------------------------------------------
555
556    nrf52_components::NrfClockComponent::new(&base_peripherals.clock).finalize(());
557
558    let scheduler = components::sched::round_robin::RoundRobinComponent::new(&*addr_of!(PROCESSES))
559        .finalize(components::round_robin_component_static!(NUM_PROCS));
560
561    let platform = Platform {
562        button,
563        ble_radio,
564        ieee802154_radio,
565        console,
566        led,
567        gpio,
568        adc: adc_syscall,
569        rng,
570        temp,
571        alarm,
572        ipc: kernel::ipc::IPC::new(
573            board_kernel,
574            kernel::ipc::DRIVER_NUM,
575            &memory_allocation_capability,
576        ),
577        i2c_master_slave,
578        scheduler,
579        systick: cortexm4::systick::SysTick::new_with_calibration(64000000),
580    };
581
582    let chip = static_init!(
583        nrf52840::chip::NRF52<Nrf52840DefaultPeripherals>,
584        nrf52840::chip::NRF52::new(nrf52840_peripherals)
585    );
586    CHIP = Some(chip);
587
588    debug!("Particle Boron: Initialization complete. Entering main loop\r");
589
590    //--------------------------------------------------------------------------
591    // PROCESSES AND MAIN LOOP
592    //--------------------------------------------------------------------------
593
594    // These symbols are defined in the linker script.
595    extern "C" {
596        /// Beginning of the ROM region containing app images.
597        static _sapps: u8;
598        /// End of the ROM region containing app images.
599        static _eapps: u8;
600        /// Beginning of the RAM region for app memory.
601        static mut _sappmem: u8;
602        /// End of the RAM region for app memory.
603        static _eappmem: u8;
604    }
605
606    kernel::process::load_processes(
607        board_kernel,
608        chip,
609        core::slice::from_raw_parts(
610            core::ptr::addr_of!(_sapps),
611            core::ptr::addr_of!(_eapps) as usize - core::ptr::addr_of!(_sapps) as usize,
612        ),
613        core::slice::from_raw_parts_mut(
614            core::ptr::addr_of_mut!(_sappmem),
615            core::ptr::addr_of!(_eappmem) as usize - core::ptr::addr_of!(_sappmem) as usize,
616        ),
617        &mut *addr_of_mut!(PROCESSES),
618        &FAULT_RESPONSE,
619        &process_management_capability,
620    )
621    .unwrap_or_else(|err| {
622        debug!("Error loading processes!");
623        debug!("{:?}", err);
624    });
625
626    (board_kernel, platform, chip)
627}
628
629/// Main function called after RAM initialized.
630#[no_mangle]
631pub unsafe fn main() {
632    let main_loop_capability = create_capability!(capabilities::MainLoopCapability);
633
634    let (board_kernel, platform, chip) = start_particle_boron();
635    board_kernel.kernel_loop(&platform, chip, Some(&platform.ipc), &main_loop_capability);
636}