-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Jim-Hodapp-Coaching/initial_interface
Initial interface
- Loading branch information
Showing
13 changed files
with
940 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
runner = "probe-run --chip RP2040" | ||
|
||
rustflags = [ | ||
"-C", "linker=flip-link", | ||
"-C", "link-arg=--nmagic", | ||
"-C", "link-arg=-Tlink.x", | ||
"-C", "link-arg=-Tdefmt.x", | ||
|
||
# Code-size optimizations. | ||
# trap unreachable can save a lot of space, but requires nightly compiler. | ||
# uncomment the next line if you wish to enable it | ||
# "-Z", "trap-unreachable=no", | ||
"-C", "inline-threshold=5", | ||
"-C", "no-vectorize-loops", | ||
] | ||
|
||
[build] | ||
target = "thumbv6m-none-eabi" | ||
|
||
[env] | ||
# Set the level of debug output to display from the target application | ||
DEFMT_LOG = "debug" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"rust.target": "thumbv6m-none-eabi", | ||
"rust.all_targets": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
fn main() {} | ||
//! 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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
//! # ESP32-WROOM-RP Pico Wireless Example | ||
//! | ||
//! This application demonstrates how to use the ESP32-WROOM-RP crate to communicate | ||
//! with a remote ESP32 wifi and retrieve its firmware version. | ||
//! | ||
//! See the `Cargo.toml` file for Copyright and license details. | ||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate esp32_wroom_rp; | ||
|
||
// The macro for our start-up function | ||
use cortex_m_rt::entry; | ||
|
||
// Needed for debug output symbols to be linked in binary image | ||
use defmt_rtt as _; | ||
|
||
use panic_probe as _; | ||
|
||
// Alias for our HAL crate | ||
use rp2040_hal as hal; | ||
|
||
use eh_02::spi::MODE_0; | ||
use embedded_time::fixed_point::FixedPoint; | ||
use embedded_time::rate::Extensions; | ||
use hal::clocks::Clock; | ||
use hal::pac; | ||
|
||
/// The linker will place this boot block at the start of our program image. We | ||
/// need this to help the ROM bootloader get our code up and running. | ||
#[link_section = ".boot2"] | ||
#[used] | ||
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; | ||
|
||
/// External high-speed crystal on the Raspberry Pi Pico board is 12 MHz. Adjust | ||
/// if your board has a different frequency | ||
const XTAL_FREQ_HZ: u32 = 12_000_000u32; | ||
|
||
// Until cortex_m implements the DelayUs trait needed for embedded-hal-1.0.0, | ||
// provide a wrapper around it | ||
pub struct DelayWrap(cortex_m::delay::Delay); | ||
|
||
impl embedded_hal::delay::blocking::DelayUs for DelayWrap { | ||
type Error = core::convert::Infallible; | ||
|
||
fn delay_us(&mut self, us: u32) -> Result<(), Self::Error> { | ||
self.0.delay_us(us); | ||
Ok(()) | ||
} | ||
|
||
fn delay_ms(&mut self, ms: u32) -> Result<(), Self::Error> { | ||
self.0.delay_ms(ms); | ||
Ok(()) | ||
} | ||
} | ||
|
||
/// Entry point to our bare-metal application. | ||
/// | ||
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function | ||
/// as soon as all global variables are initialized. | ||
#[entry] | ||
fn main() -> ! { | ||
// Grab our singleton objects | ||
let mut pac = pac::Peripherals::take().unwrap(); | ||
let core = pac::CorePeripherals::take().unwrap(); | ||
|
||
// Set up the watchdog driver - needed by the clock setup code | ||
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG); | ||
|
||
// Configure the clocks | ||
let clocks = hal::clocks::init_clocks_and_plls( | ||
XTAL_FREQ_HZ, | ||
pac.XOSC, | ||
pac.CLOCKS, | ||
pac.PLL_SYS, | ||
pac.PLL_USB, | ||
&mut pac.RESETS, | ||
&mut watchdog, | ||
) | ||
.ok() | ||
.unwrap(); | ||
|
||
let mut delay = DelayWrap(cortex_m::delay::Delay::new( | ||
core.SYST, | ||
clocks.system_clock.freq().integer(), | ||
)); | ||
|
||
// The single-cycle I/O block controls our GPIO pins | ||
let sio = hal::Sio::new(pac.SIO); | ||
|
||
// Set the pins to their default state | ||
let pins = hal::gpio::Pins::new( | ||
pac.IO_BANK0, | ||
pac.PADS_BANK0, | ||
sio.gpio_bank0, | ||
&mut pac.RESETS, | ||
); | ||
|
||
defmt::info!("ESP32-WROOM-RP get NINA firmware version example"); | ||
|
||
// These are implicitly used by the spi driver if they are in the correct mode | ||
let spi_miso = pins.gpio16.into_mode::<hal::gpio::FunctionSpi>(); | ||
let spi_sclk = pins.gpio18.into_mode::<hal::gpio::FunctionSpi>(); | ||
let spi_mosi = pins.gpio19.into_mode::<hal::gpio::FunctionSpi>(); | ||
|
||
let spi = hal::Spi::<_, _, 8>::new(pac.SPI0); | ||
|
||
// Exchange the uninitialized SPI driver for an initialized one | ||
let spi = spi.init( | ||
&mut pac.RESETS, | ||
clocks.peripheral_clock.freq(), | ||
8_000_000u32.Hz(), | ||
&MODE_0, | ||
); | ||
|
||
let esp_pins = esp32_wroom_rp::gpio::EspControlPins { | ||
// CS on pin x (GPIO7) | ||
cs: pins.gpio7.into_mode::<hal::gpio::PushPullOutput>(), | ||
// GPIO0 on pin x (GPIO2) | ||
gpio0: pins.gpio2.into_mode::<hal::gpio::PushPullOutput>(), | ||
// RESETn on pin x (GPIO11) | ||
resetn: pins.gpio11.into_mode::<hal::gpio::PushPullOutput>(), | ||
// ACK on pin x (GPIO10) | ||
ack: pins.gpio10.into_mode::<hal::gpio::FloatingInput>(), | ||
}; | ||
let mut wifi = esp32_wroom_rp::wifi::Wifi::init(spi, esp_pins, &mut delay).unwrap(); | ||
let firmware_version = wifi.firmware_version(); | ||
defmt::info!("NINA firmware version: {:?}", firmware_version); | ||
|
||
defmt::info!("Entering main loop"); | ||
loop {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
MEMORY { | ||
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 | ||
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 | ||
RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
} | ||
|
||
SECTIONS { | ||
/* ### Boot loader */ | ||
.boot2 ORIGIN(BOOT2) : | ||
{ | ||
KEEP(*(.boot2)); | ||
} > BOOT2 | ||
} INSERT BEFORE .text; |
Oops, something went wrong.