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