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