Skip to content

Commit

Permalink
ongoing LoRa work.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdgilbert committed Jul 31, 2024
1 parent 0d48b16 commit 49bc656
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 63 deletions.
33 changes: 3 additions & 30 deletions dev-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,29 +147,18 @@ fugit = { version = "0.3.3", optional = true }
# include *also* thumbv6 support. It seems shared-bus-rtic is no longer needed.
# shared-bus-rtic = { git = "https://github.com/ryan-summers/shared-bus-rtic", features = ["thumbv6"], optional = true }

## only certain versions of radio, radio-sx127x, embedded-hal_1.0.0-alpha and embedded-hal-compat work together
##radio = { version = "0.9.0" }
##radio-sx127x = { version = "0.11.0", default-features = false }
#radio = { version = "0.9.1" }
##radio = { version = "0.10.0" }
#radio-sx127x = { git = "https://github.com/rust-iot/rust-radio-sx127x", default-features = false }
#radio-sx127x = { version = "0.14.0", default-features = false }
#radio = { version = "0.11.0" }

# NB seems important to use the same version of radio that is used by radio-sx127x
# It would be nice if radio-sx127x re-exported traits Transmit and Receive so radio is not needed.

#radio = { git = "https://github.com/rust-iot/radio-hal" } # eh-1
#radio-sx127x = { git = "https://github.com/rust-iot/rust-radio-sx127x", default-features = false }
# That is being done in pdgilbert/rust-radio-sx127x.

# these two work together
#radio = { version = "0.11.1", git = "https://github.com/rust-iot/radio-hal", rev = "7aade85b61c08161bf3422f7d148417bd38ecdc2" }
#radio-sx127x = { git = "https://github.com/matheo-lucak/rust-radio-sx127x", default-features = false }


# This radio-sx127 re-exports {Receive, Transmit} so looks after getting correct radio version.
# This radio-sx127 re-exports {Receive, Transmit} so insures correct radio version.
radio-sx127x = { git = "https://github.com/pdgilbert/rust-radio-sx127x", default-features = false, branch = "ehal-1" }
#radio-sx127x = { path = "...rust-radio-sx127x", default-features = false }
#radio-sx127x = { path = "/home/paul/githubClones/rust-radio-sx127x", default-features = false }

# not used yet
#radio-sx1231 = { git = "https://github.com/rust-io/rust-radio-sx1231", default-features = false }
Expand Down Expand Up @@ -216,22 +205,6 @@ cortex-m-rt = ">=0.7.0"
panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] }
rtt-target = { version = ">=0.3.1", features = ["cortex-m"] }


# for radio-sx127x https://github.com/rust-iot/rust-radio-sx127x

#LEAVE THESE COMMENTED LINES FOR REFERENCE BUT REMOVE WHEN SOMETHING WORKS
#embedded-hal 1.0.0-alpha
#e-h-1a = { version = "1.0.0-alpha.5,<1.0.0-alpha.6", package = "embedded-hal" }
# alpha.6 requires changes to delay and radio-sx127x support. See branch eh-1-alpha
#e-h-1a = { version = "1.0.0-alpha.6,<1.0.0-alpha.7", package = "embedded-hal" }
#e-h-1a = { version = "1.0.0-alpha.7,<1.0.0-alpha.8", package = "embedded-hal" }

#stm32f4xx IS NOW NEEDS 1.0.0-alpha.7 AND radio, radio-sx127x, embedded-hal-compat, NEED alpha.5
# src/lib.rs also has lora_spi_gps_usart; commented out

#embedded-hal-compat = "0.4.0"
#embedded-hal-compat = { git = "https://github.com/ryankurte/embedded-hal-compat.git", branch = "main", optional = true}

cortex-m-semihosting = { version = "0.3.7" } #test carefully when updating. Version change can break many examples
panic-semihosting = { version = ">=0.5.2" }
panic-reset = { version = ">=0.1.0" }
Expand Down
2 changes: 1 addition & 1 deletion examples/projects/iaq_ens160aht21_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ use heapless;

///////////////////// lora

use radio::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit.
use radio_sx127x::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit.

use radio_sx127x::{
//Error as sx127xError, // Error name conflict with hals
Expand Down
40 changes: 26 additions & 14 deletions examples/radio-sx127x/lora_spi_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ use panic_halt as _;
use cortex_m_rt::entry;
use cortex_m_semihosting::*;

//use cortex_m_semihosting::{debug, hprintln};
//use cortex_m_semihosting::{hprintln};

use embedded_hal::delay::DelayNs;

//use radio::Transmit; // trait needs to be in scope to find methods start_transmit and check_transmit.
Expand All @@ -66,13 +69,21 @@ use radio_sx127x::{
prelude::*, // prelude has Sx127x,
};

// for config examination on debugging
use radio_sx127x::{
device::regs::Register,
// read_register, get_mode, get_signal_bandwidth, get_coding_rate_4, get_spreading_factor,

};


// //////////////////////////////////////////////////////////////////////

use rust_integration_testing_of_examples::setup;
use rust_integration_testing_of_examples::setup::{Peripherals, LED};

//use rust_integration_testing_of_examples::lora::{CONFIG_PA, CONFIG_RADIO, CONFIG_LORA, CONFIG_CH, FREQUENCY, MODE};
use rust_integration_testing_of_examples::lora::{CONFIG_RADIO};
use rust_integration_testing_of_examples::lora::{CONFIG_PA, CONFIG_RADIO, CONFIG_LORA, CONFIG_CH, FREQUENCY, MODE};
//use rust_integration_testing_of_examples::lora::{CONFIG_RADIO};

// //////////////////////////////////////////////////////////////////////

Expand All @@ -99,21 +110,22 @@ fn main() -> ! {


// print out configuration (for debugging)
// hprintln!("frequency {:?}", lora.get_frequency());

// use radio_sx127x::device::regs::Register;
//
// let v = lora.lora_get_config();
// hprintln!("configuration {}", v).unwrap();
//
// hprintln!("channel {}", lora.get_channel()).unwrap();
//
// hprintln!("mode {}", lora.get_mode()).unwrap();
// hprintln!("mode {}", lora.read_register(Register::RegOpMode.addr())).unwrap();
// hprintln!("bandwidth {:?}", lora.get_signal_bandwidth()).unwrap();
// hprintln!("coding_rate {:?}", lora.get_coding_rate_4()).unwrap();
// hprintln!("spreading_factor {:?}", lora.get_spreading_factor()).unwrap();
// hprintln!("invert_iq {:?}", lora.get_invert_iq()).unwrap();
// hprintln!("tx_power {:?}", lora.get_tx_power()).unwrap();
// let v = lora.lora_get_config();
// hprintln!("configuration {:?}", v).unwrap();
//
// hprintln!("channel {}", lora.get_channel()).unwrap();
//
// hprintln!("mode {}", lora.get_mode()).unwrap();
// hprintln!("mode {}", lora.read_register(Register::RegOpMode.addr())).unwrap();
// hprintln!("bandwidth {:?}", lora.get_signal_bandwidth()).unwrap();
// hprintln!("coding_rate {:?}", lora.get_coding_rate_4()).unwrap();
// hprintln!("spreading_factor {:?}", lora.get_spreading_factor()).unwrap();
// hprintln!("invert_iq {:?}", lora.get_invert_iq()).unwrap();
// hprintln!("tx_power {:?}", lora.get_tx_power()).unwrap();

// transmit something

Expand Down
12 changes: 6 additions & 6 deletions src/PinMap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ PA3 rx2 gpioa.pa3.into_alternate(),
Config::default().baudrate(9600.bps()),

PA11 tx3 on USART6 gpioa.pa11.into_alternate(), TRY TO RESOLVE CONFILICT WITH CsPin below
PA12 tx3 gpioa.pa12.into_alternate(),
PA12 rx3 gpioa.pa12.into_alternate(),

PA5 sck dp.SPI1 gpioa.pa5.into_alternate(), // sck
PA6 miso gpioa.pa6.into_alternate(), // miso
PA7 mosi gpioa.pa7.into_alternate(), // mosi
MODE, 8.MHz(),

PA11 CsPin Sx127x::spi( gpioa.pa11.into_push_pull_output(), //CsPin
PB4 BusyPin gpiob.pb8.into_floating_input(), //BusyPin DI00 triggers RxDone/TxDone status. CHANGED
PB5 ReadyPin gpiob.pb9.into_floating_input(), //ReadyPin DI01 triggers RxTimeout and other errors status. CHANGED
PA11 CsPin Sx127x::spi( gpioa.pa11.into_push_pull_output(), //CsPin (still unresolved conflict with tx3 above)
PB4 BusyPin gpiob.pb8.into_floating_input(), //BusyPin DI00 triggers RxDone/TxDone status.
PB5 ReadyPin gpiob.pb9.into_floating_input(), //ReadyPin DI01 triggers RxTimeout and other errors status.
PA0 ResetPin gpioa.pa0.into_push_pull_output(), //ResetPin
delay, &CONFIG_RADIO, ).unwrap(); // should handle error

Expand Down Expand Up @@ -183,8 +183,8 @@ PA7 mosi gpioa.pa7.into_alternate(), // mosi
MODE, 8.MHz(),

PA1 CsPin Sx127x::spi( gpioa.pa1.into_push_pull_output(), //CsPin
PB4 BusyPin gpiob.pb8.into_floating_input(), //BusyPin DI00 triggers RxDone/TxDone status. CHANGED
PB5 ReadyPin gpiob.pb9.into_floating_input(), //ReadyPin DI01 triggers RxTimeout and other errors status. CHANGED
PB4 BusyPin gpiob.pb8.into_floating_input(), //BusyPin DI00 triggers RxDone/TxDone status.
PB5 ReadyPin gpiob.pb9.into_floating_input(), //ReadyPin DI01 triggers RxTimeout and other errors status.
PA0 ResetPin gpioa.pa0.into_push_pull_output(), //ResetPin
delay, &CONFIG_RADIO, ).unwrap(); // should handle error

Expand Down
15 changes: 3 additions & 12 deletions src/lora.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
// //////////////////////////////////////////
// see src/PinMap.txt for pin usage

// might be something like
//pub type LoraSpiType = Sx127x<Base<SpiType,
// Pin<'A', 1, Output>, Pin<'B', 4>, Pin<'B', 5>, Pin<'A', 0, Output>,
// Delay<TIM5, 1000000>>>;

// LoraSpiType might be something like
// impl DelayNs
// + Transmit<Error = sx127xError<Error>>
// + Receive<Info = PacketInfo, Error = sx127xError<Error>>,
// see src/PinMap.txt for summary pin assignment.
// see src/setup_all_* for pin usage and details.

// //////////////////////////////////////////

Expand Down Expand Up @@ -49,7 +40,7 @@ pub const MODE: Mode = Mode {
polarity: Polarity::IdleHigh,
};

pub const FREQUENCY: u32 = 907_400_000; // frequency in hertz ch_12: 915_000_000, ch_2: 907_400_000
pub const FREQUENCY: u32 = 915_000_000; // 907_400_000; // frequency in hertz ch_12: 915_000_000, ch_2: 907_400_000

pub const CONFIG_CH: LoRaChannel = LoRaChannel {
freq: FREQUENCY as u32, // frequency in hertz
Expand Down

0 comments on commit 49bc656

Please sign in to comment.