From c102e380e4fc869e8d0264bc72d76be87e4c5d4c Mon Sep 17 00:00:00 2001 From: Davide Mor <davide.mor@skywarder.eu> Date: Mon, 3 Apr 2023 17:04:04 +0200 Subject: [PATCH] [sx1278] Fixed Fsk RX problem, and slightly improved test entrypoint --- src/shared/radio/SX1278/SX1278Defs.h | 2 +- src/shared/radio/SX1278/SX1278Fsk.cpp | 8 +++++--- src/tests/radio/sx1278/gui/GUI.h | 16 +++++++++++++--- src/tests/radio/sx1278/sx1278-init.h | 12 ++++++------ src/tests/radio/sx1278/test-sx1278-bench.cpp | 17 +++++++++++++++-- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/shared/radio/SX1278/SX1278Defs.h b/src/shared/radio/SX1278/SX1278Defs.h index b674d59d2..ee5e4ea17 100644 --- a/src/shared/radio/SX1278/SX1278Defs.h +++ b/src/shared/radio/SX1278/SX1278Defs.h @@ -230,7 +230,7 @@ inline constexpr uint8_t make(bool rx_trigger_rssi_interrupt, bool restart_rx_on_collision) { return (rx_trigger_rssi_interrupt ? 0b001 : 0) | - (rx_trigger_preable_detect ? 0b110 << 1 : 0) | + (rx_trigger_preable_detect ? 0b110 : 0) | (agc_auto_on ? 1 << 3 : 0) | (afc_auto_on ? 1 << 4 : 0) | (restart_rx_with_pll_lock ? 1 << 5 : 0) | (restart_rx_without_pll_lock ? 1 << 6 : 0) | diff --git a/src/shared/radio/SX1278/SX1278Fsk.cpp b/src/shared/radio/SX1278/SX1278Fsk.cpp index 9179b9aac..0677a3ede 100644 --- a/src/shared/radio/SX1278/SX1278Fsk.cpp +++ b/src/shared/radio/SX1278/SX1278Fsk.cpp @@ -74,8 +74,8 @@ SX1278Fsk::Error SX1278Fsk::configure(const Config &config) setDefaultMode(RegOpMode::MODE_SLEEP, DEFAULT_MAPPING, false, false); miosix::Thread::sleep(1); - // Make sure the device remains in standby and not in sleep - setDefaultMode(RegOpMode::MODE_STDBY, DEFAULT_MAPPING, false, false); + // Make sure the device remains in RX and not in sleep + setDefaultMode(RegOpMode::MODE_RX, DEFAULT_MAPPING, false, false); miosix::Thread::sleep(1); // Lock the bus @@ -142,6 +142,9 @@ SX1278Fsk::Error SX1278Fsk::configure(const Config &config) spi.writeRegister(REG_SYNC_VALUE_1, 0x12); spi.writeRegister(REG_SYNC_VALUE_2, 0xad); + // Set preamble length + spi.writeRegister16(REG_PREAMBLE_MSB, 2); + // Setup shaping spi.writeRegister(REG_PA_RAMP, RegPaRamp::make(RegPaRamp::PA_RAMP_US_40, shaping)); @@ -176,7 +179,6 @@ SX1278Fsk::Error SX1278Fsk::configure(const Config &config) } // Setup other registers - spi.writeRegister16(REG_PREAMBLE_MSB, 2); spi.writeRegister( REG_RX_CONFIG, diff --git a/src/tests/radio/sx1278/gui/GUI.h b/src/tests/radio/sx1278/gui/GUI.h index d42aa0125..9f317e8df 100644 --- a/src/tests/radio/sx1278/gui/GUI.h +++ b/src/tests/radio/sx1278/gui/GUI.h @@ -39,6 +39,16 @@ std::string format_link_speed(size_t value) return fmt::format("{} b/s", value); } +std::string format_frequency(size_t value) +{ + if (value > 1000000) + return fmt::format("{:.2f} MHz", static_cast<float>(value) / 1000000); + else if (value > 1000) + return fmt::format("{:.2f} kHz", static_cast<float>(value) / 1000); + else + return fmt::format("{} Hz", value); +} + class StatsScreen { public: @@ -91,9 +101,9 @@ public: root.addView(&lbl_tx_data, 0.1); root.addView(&tx_data, 0.4); root.addView(&lbl_rx_data, 0.1); - root.addView(&rx_data, 0.8); + root.addView(&rx_data, 0.6); root.addView(&lbl_misc_data, 0.1); - root.addView(&misc_data, 0.2); + root.addView(&misc_data, 0.6); } void updateReady() @@ -112,7 +122,7 @@ public: corrupted_count.setText(fmt::format("{}", stats.corrupted_count)); rssi.setText(fmt::format("{} dBm", stats.rssi)); - fei.setText(fmt::format("{} Hz", stats.fei)); + fei.setText(format_frequency(stats.fei)); snr.setText(fmt::format("{}", stats.snr)); } diff --git a/src/tests/radio/sx1278/sx1278-init.h b/src/tests/radio/sx1278/sx1278-init.h index 75672862a..2ed08f3af 100644 --- a/src/tests/radio/sx1278/sx1278-init.h +++ b/src/tests/radio/sx1278/sx1278-init.h @@ -39,7 +39,7 @@ // Uncomment the following line to enable Ebyte module // #define SX1278_IS_EBYTE // Uncomment the following line to ebable Skyward433 module -#define SX1278_IS_SKYWARD433 +// #define SX1278_IS_SKYWARD433 using cs = miosix::peripherals::ra01::pc13::cs; using dio0 = miosix::peripherals::ra01::pc13::dio0; @@ -75,8 +75,8 @@ using sck = miosix::radio::sck; using miso = miosix::radio::miso; using mosi = miosix::radio::mosi; -using txen = miosix::radio::txEn; -using rxen = miosix::radio::rxEn; +using txen = miosix::radio::txEn; +using rxen = miosix::radio::rxEn; #define SX1278_SPI SPI4 @@ -191,8 +191,8 @@ bool initRadio() Boardcore::SX1278Fsk::Error err; sx1278 = new Boardcore::SX1278Fsk(sx1278_bus, cs::getPin(), - Boardcore::SPI::ClockDivider::DIV_64, - std::move(frontend)); + Boardcore::SPI::ClockDivider::DIV_64, + std::move(frontend)); printf("\n[sx1278] Configuring sx1278 fsk...\n"); if ((err = sx1278->init(config)) != Boardcore::SX1278Fsk::Error::NONE) @@ -206,4 +206,4 @@ bool initRadio() #endif return true; -} \ No newline at end of file +} diff --git a/src/tests/radio/sx1278/test-sx1278-bench.cpp b/src/tests/radio/sx1278/test-sx1278-bench.cpp index ca8a8454e..a68dcbff5 100644 --- a/src/tests/radio/sx1278/test-sx1278-bench.cpp +++ b/src/tests/radio/sx1278/test-sx1278-bench.cpp @@ -20,14 +20,14 @@ * THE SOFTWARE. */ -#include "sx1278-init.h" - #include <drivers/timer/TimestampTimer.h> #include <miosix.h> #include <utils/MovingAverage.h> #include <thread> +#include "sx1278-init.h" + using namespace Boardcore; using namespace miosix; @@ -166,4 +166,17 @@ void spawnThreads() std::thread send([]() { sendLoop(); }); send.detach(); #endif + + /* For now, I'll keep it here, just in case ... + std::thread watchdog([]() { + while(1) { + { + FastInterruptDisableLock dlock; + sx1278->handleDioIRQ(); + } + Thread::sleep(200); + } + }); + watchdog.detach(); + //*/ } -- GitLab