feat: embassy-lpc55 hal with gpio and pint driver

This commit is contained in:
George Cosma
2024-06-05 13:54:00 +03:00
parent a23f56b3dd
commit e7e245eeb7
12 changed files with 1389 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-rs run --chip LPC55S69JBD100"
[build]
target = "thumbv8m.main-none-eabihf"
[env]
DEFMT_LOG = "debug"

View File

@@ -0,0 +1,22 @@
[package]
edition = "2021"
name = "embassy-nxp-lpc55s69-examples"
version = "0.1.0"
license = "MIT OR Apache-2.0"
[dependencies]
embassy-nxp = { version = "0.1.0", path = "../../embassy-nxp", features = ["rt"] }
embassy-executor = { version = "0.6.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt"] }
embassy-sync = { version = "0.6.0", path = "../../embassy-sync", features = ["defmt"] }
embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt"] }
panic-halt = "0.2.0"
cortex-m = { version = "0.7.6", features = ["inline-asm", "critical-section-single-core"] }
cortex-m-rt = {version = "0.7.0"}
defmt = "0.3"
defmt-rtt = "0.4"
panic-probe = { version = "0.3.2", features = ["print-defmt"] }
panic-semihosting = "0.6.0"
[profile.release]
debug = 2

View File

@@ -0,0 +1,35 @@
//! This build script copies the `memory.x` file from the crate root into
//! a directory where the linker can always find it at build time.
//! For many projects this is optional, as the linker always searches the
//! project root directory -- wherever `Cargo.toml` is. However, if you
//! are using a workspace or have a more complicated build setup, this
//! build script becomes required. Additionally, by requesting that
//! Cargo re-run the build script whenever `memory.x` is changed,
//! updating `memory.x` ensures a rebuild of the application with the
//! new memory settings.
use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
fn main() {
// Put `memory.x` in our output directory and ensure it's
// on the linker search path.
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
File::create(out.join("memory.x"))
.unwrap()
.write_all(include_bytes!("memory.x"))
.unwrap();
println!("cargo:rustc-link-search={}", out.display());
// By default, Cargo will re-run a build script whenever
// any file in the project changes. By specifying `memory.x`
// here, we ensure the build script is only re-run when
// `memory.x` is changed.
println!("cargo:rerun-if-changed=memory.x");
println!("cargo:rustc-link-arg-bins=--nmagic");
println!("cargo:rustc-link-arg-bins=-Tlink.x");
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
}

View File

@@ -0,0 +1,28 @@
/* File originally from lpc55-hal repo: https://github.com/lpc55/lpc55-hal/blob/main/memory.x */
MEMORY
{
FLASH : ORIGIN = 0x00000000, LENGTH = 512K
/* for use with standard link.x */
RAM : ORIGIN = 0x20000000, LENGTH = 256K
/* would be used with proper link.x */
/* needs changes to r0 (initialization code) */
/* SRAM0 : ORIGIN = 0x20000000, LENGTH = 64K */
/* SRAM1 : ORIGIN = 0x20010000, LENGTH = 64K */
/* SRAM2 : ORIGIN = 0x20020000, LENGTH = 64K */
/* SRAM3 : ORIGIN = 0x20030000, LENGTH = 64K */
/* CASPER SRAM regions */
/* SRAMX0: ORIGIN = 0x1400_0000, LENGTH = 4K /1* to 0x1400_0FFF *1/ */
/* SRAMX1: ORIGIN = 0x1400_4000, LENGTH = 4K /1* to 0x1400_4FFF *1/ */
/* USB1 SRAM regin */
/* USB1_SRAM : ORIGIN = 0x40100000, LENGTH = 16K */
/* To define our own USB RAM section in one regular */
/* RAM, probably easiest to shorten length of RAM */
/* above, and use this freed RAM section */
}

View File

@@ -0,0 +1,33 @@
//! This example has been made with the LPCXpresso55S69 board in mind, which has a built-in LED on PIO1_6.
#![no_std]
#![no_main]
use cortex_m::asm::nop;
use defmt::*;
use embassy_executor::Spawner;
use embassy_nxp::gpio::{Level, Output};
use {defmt_rtt as _, panic_halt as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_nxp::init(Default::default());
let mut led = Output::new(p.PIO1_6, Level::Low);
loop {
info!("led off!");
led.set_high();
for _ in 0..200_000 {
nop();
}
info!("led on!");
led.set_low();
for _ in 0..200_000 {
nop();
}
}
}

View File

@@ -0,0 +1,25 @@
//! This example has been made with the LPCXpresso55S69 board in mind, which has a built-in LED on
//! PIO1_6 and a button (labeled "user") on PIO1_9.
#![no_std]
#![no_main]
use defmt::*;
use embassy_executor::Spawner;
use embassy_nxp::gpio::{Input, Level, Output, Pull};
use {defmt_rtt as _, panic_halt as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) -> ! {
let p = embassy_nxp::init(Default::default());
let mut led = Output::new(p.PIO1_6, Level::Low);
let mut button = Input::new(p.PIO1_9, Pull::Up);
info!("Entered main loop");
loop {
button.wait_for_rising_edge().await;
info!("Button pressed");
led.toggle();
}
}