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