aboutsummaryrefslogtreecommitdiff
path: root/crates/rp-pico-2040/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rp-pico-2040/src/lib.rs')
-rw-r--r--crates/rp-pico-2040/src/lib.rs94
1 files changed, 94 insertions, 0 deletions
diff --git a/crates/rp-pico-2040/src/lib.rs b/crates/rp-pico-2040/src/lib.rs
new file mode 100644
index 0000000..8f877aa
--- /dev/null
+++ b/crates/rp-pico-2040/src/lib.rs
@@ -0,0 +1,94 @@
+//! Standard library support crate for an Raspberry Pi Pico with an RP2040.
+//!
+//! The blinky support example comes from the rp-hal-boards example, available
+//! <https://github.com/rp-rs/rp-hal-boards/blob/5135e3dafe3e69b112e6d2d72cfb1856a7679b82/boards/rp-pico/examples/pico_blinky.rs#L1>
+//! and licensed MIT or APACHE-2.0.
+
+#![no_std]
+#![feature(rustc_private)]
+extern crate fusible;
+
+use core::pin::Pin;
+
+use rust_threadx_cortex_m as _;
+use rust_threadx_stdio_semihosting as _;
+use rust_threadx_sync_single_core as _;
+
+use embedded_hal::digital::OutputPin;
+use rp_pico::hal;
+use rp_pico::hal::pac;
+
+#[doc(hidden)]
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn _tx_initialize_low_level() {
+ use cortex_m::{
+ Peripherals,
+ peripheral::{scb::SystemHandler, syst::SystClkSource},
+ };
+
+ cortex_m::interrupt::disable();
+
+ unsafe {
+ let Peripherals {
+ mut SYST, mut SCB, ..
+ } = Peripherals::steal();
+
+ SCB.set_priority(SystemHandler::SysTick, 0x40);
+ SCB.set_priority(SystemHandler::PendSV, 0xff);
+ SCB.set_priority(SystemHandler::SVCall, 0xff);
+
+ SYST.set_clock_source(SystClkSource::Core);
+ SYST.set_reload(125_000_000 / 100 - 1);
+ SYST.clear_current();
+ SYST.enable_interrupt();
+ SYST.enable_counter();
+ }
+}
+
+use fusible::thread::{StaticStack, Thread, ThreadContext};
+static STACK: StaticStack<512> = StaticStack::new();
+static THREAD: ThreadContext = Thread::context();
+
+#[unsafe(no_mangle)]
+#[doc(hidden)]
+pub extern "C" fn __rust_threadx_app_define() {
+ let mut pac = pac::Peripherals::take().unwrap();
+
+ let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);
+
+ hal::clocks::init_clocks_and_plls(
+ rp_pico::XOSC_CRYSTAL_FREQ,
+ pac.XOSC,
+ pac.CLOCKS,
+ pac.PLL_SYS,
+ pac.PLL_USB,
+ &mut pac.RESETS,
+ &mut watchdog,
+ )
+ .ok()
+ .unwrap();
+
+ let sio = hal::Sio::new(pac.SIO);
+
+ let pins = rp_pico::Pins::new(
+ pac.IO_BANK0,
+ pac.PADS_BANK0,
+ sio.gpio_bank0,
+ &mut pac.RESETS,
+ );
+
+ let mut led_pin = pins.led.into_push_pull_output();
+
+ Thread::create(
+ Pin::static_ref(&THREAD),
+ STACK.take().unwrap(),
+ &Default::default(),
+ move || loop {
+ led_pin.set_high().unwrap();
+ fusible::thread::sleep(50);
+ led_pin.set_low().unwrap();
+ fusible::thread::sleep(50);
+ },
+ )
+ .unwrap();
+}