Skip to content

Commit

Permalink
S76G TCXO function
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Dec 4, 2020
1 parent b010b66 commit e5ff3a4
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Data|FLARM NMEA|<p align="center">![](https://github.com/lyusupov/SoftRF/raw/mas

# Models
## By Processing Unit
Model|Platform|First appearance|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Comment
Model(s)|Platform|First appearance|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Notes
---|:---:|:---:|:---:|---
1&nbsp;[Prime](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition)<br>2&nbsp;[Standalone](https://github.com/lyusupov/SoftRF/wiki/Standalone-Edition)<br>3&nbsp;[UAV](https://github.com/lyusupov/SoftRF/wiki/UAV-Edition)<br>4&nbsp;[**WebTop**](https://github.com/lyusupov/SoftRF/wiki/WebTop-WiFi-adapter)|[Espressif<br>ESP8266](https://en.wikipedia.org/wiki/ESP8266)|Q4 2015|![](https://placehold.it/140x70/00A000/000000?text=Good)|[Prime](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition) model is no longer supported - use [Prime MkII](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition-MkII) instead.<br><!-- ESP8266 platform will be phased out through year 2020 in favour of ESP32.-->
1&nbsp;[**Prime Mark II**](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition-MkII)<br>2&nbsp;[**Standalone**](https://github.com/lyusupov/SoftRF/wiki/Standalone-Edition) + [adapter](https://github.com/lyusupov/ESP32-NODEMCU-ADAPTER)<br>3&nbsp;[UAV](https://github.com/lyusupov/SoftRF/wiki/UAV-Edition)<br>4&nbsp;[**SkyView EZ**](https://github.com/lyusupov/SoftRF/wiki/SkyView-EZ)<br>5&nbsp;[Flight Recorder](https://github.com/lyusupov/SoftRF/wiki/Flight-Recorder)|[Espressif<br>ESP32](https://en.wikipedia.org/wiki/ESP32)|Q1 2018|![](https://placehold.it/140x70/00A000/000000?text=Good)|Today's best platform
Expand All @@ -39,7 +39,7 @@ Mini|[Cypress<br>PSoC 4100**S**](https://en.wikipedia.org/wiki/Cypress_PSoC)|Q3
Badge|[Nordic Semiconductor<br>nRF52840](https://www.nordicsemi.com/Products/Low-power-short-range-wireless/nRF52840)|Q4 2020|![](https://placehold.it/140x40/c5f015/000000?text=May+need)<br>![](https://placehold.it/140x40/c5f015/000000?text=improvements)|&nbsp;

## By sub-1 GHz radio
Radio|Models|First appearance|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Comment
Radio|Model(s)|First appearance|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Notes
---|:---:|:---:|:---:|---
[Nordic Semiconductor<br>nRF905](https://infocenter.nordicsemi.com/pdf/nRF905_PS_v1.5.pdf)|[Prime](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition),<br>[Standalone](https://github.com/lyusupov/SoftRF/wiki/Standalone-Edition),<br>[UAV](https://github.com/lyusupov/SoftRF/wiki/UAV-Edition)|Q4 2015|![](https://placehold.it/140x70/00A000/000000?text=Good)|&nbsp;
[Semtech<br>SX1276](https://www.semtech.com/products/wireless-rf/lora-transceivers/sx1276)|[LoRa module](https://github.com/lyusupov/SoftRF/wiki/SoftRF-LoRa-module),<br>[**Prime Mark II**](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition-MkII),<br>[**Raspberry Edition**](https://github.com/lyusupov/SoftRF/wiki/Raspberry-Edition),<br>[**Dongle**](https://github.com/lyusupov/SoftRF/wiki/Dongle-Edition)|Q4 2017|![](https://placehold.it/140x70/00A000/000000?text=Good)|&nbsp;
Expand All @@ -49,7 +49,7 @@ Radio|Models|First appearance|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status&n
[Texas Instruments<br>CC1352R](http://www.ti.com/product/CC1352R)|[**Uni Edition**](https://github.com/lyusupov/SoftRF/wiki/Uni-Edition)|Q2 2020|![](https://placehold.it/140x70/00A000/000000?text=Good)|&nbsp;

## By GNSS chip
GNSS|Models|First appearance|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Comment
GNSS|Model(s)|First appearance|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|Notes
---|:---:|:---:|:---:|---
Generic<br>NMEA|[Standalone](https://github.com/lyusupov/SoftRF/wiki/Standalone-Edition)|Q4 2016|![](https://placehold.it/140x70/00A000/000000?text=Good)|&nbsp;
[U-blox](https://en.wikipedia.org/wiki/U-blox)<br>6/7/8|[**Prime Mark II**](https://github.com/lyusupov/SoftRF/wiki/Prime-Edition-MkII),<br>[Retro](https://github.com/lyusupov/SoftRF/wiki/Retro-Edition),<br>[**Uni Edition**](https://github.com/lyusupov/SoftRF/wiki/Uni-Edition)|Q2 2018|![](https://placehold.it/140x70/00A000/000000?text=Good)|&nbsp;
Expand Down
14 changes: 7 additions & 7 deletions software/firmware/source/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# SoftRF firmware build instructions

[NodeMCU](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#nodemcu)<br>
[ESP32](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#esp32)<br>
[Raspberry Pi](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#raspberry-pi)<br>
[CC13XX](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#cc13xx)<br>
[STM32](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#stm32)<br>
[ASR650x](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#asr650x)<br>
[nRF52840](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#nrf52840)<br>
* [NodeMCU](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#nodemcu)<br>
* [ESP32](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#esp32)<br>
* [Raspberry Pi](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#raspberry-pi)<br>
* [CC13XX](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#cc13xx)<br>
* [STM32](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#stm32)<br>
* [ASR650x](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#asr650x)<br>
* [nRF52840](https://github.com/lyusupov/SoftRF/tree/master/software/firmware/source#nrf52840)<br>

<br>

Expand Down
3 changes: 2 additions & 1 deletion software/firmware/source/SoftRF/src/TrafficHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ void ParseData()
return;
}

if (fo.distance < Container[max_dist_ndx].distance) {
if (fo.distance < Container[max_dist_ndx].distance &&
fo.alarm_level >= Container[max_dist_ndx].alarm_level) {
Container[max_dist_ndx] = fo;
return;
}
Expand Down
29 changes: 29 additions & 0 deletions software/firmware/source/SoftRF/src/platform/STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ HardwareSerial Serial1(SOC_GPIO_PIN_CONS_RX, SOC_GPIO_PIN_CONS_TX);
HardwareSerial Serial2(USART2);
HardwareSerial Serial4(SOC_GPIO_PIN_SWSER_RX, SOC_GPIO_PIN_SWSER_TX);

static bool STM32_has_TCXO = false;

#elif defined(ARDUINO_BLUEPILL_F103CB)

HardwareSerial Serial2(SOC_GPIO_PIN_SWSER_RX, SOC_GPIO_PIN_SWSER_TX);
Expand Down Expand Up @@ -151,6 +153,10 @@ static void STM32_setup()
hw_info.model = SOFTRF_MODEL_DONGLE;
stm32_board = STM32_TTGO_TMOTION_1_1;
}

// PC_1 is Low for TCXO or High for Crystal
STM32_has_TCXO = (STM32_probe_pin(SOC_GPIO_PIN_OSC_SEL, INPUT) == 0);

#elif defined(ARDUINO_BLUEPILL_F103CB)
stm32_board = STM32_BLUE_PILL;
#else
Expand Down Expand Up @@ -199,6 +205,23 @@ static void STM32_setup()

Wire.setSCL(SOC_GPIO_PIN_SCL);
Wire.setSDA(SOC_GPIO_PIN_SDA);

#if defined(ARDUINO_NUCLEO_L073RZ)
if (STM32_has_TCXO) {
lmic_pins.tcxo = SOC_GPIO_PIN_TCXO_OE;

digitalWrite(SOC_GPIO_PIN_TCXO_OE, LOW);
pinMode(SOC_GPIO_PIN_TCXO_OE, OUTPUT);
delay(5);
digitalWrite(SOC_GPIO_PIN_TCXO_OE, HIGH);
delay(10);
}

lmic_pins.rxe = SOC_GPIO_PIN_ANT_RXTX;

// Set default value at Rx
digitalWrite(SOC_GPIO_PIN_ANT_RXTX, HIGH);
#endif /* ARDUINO_NUCLEO_L073RZ */
}

static void STM32_post_init()
Expand All @@ -213,6 +236,10 @@ static void STM32_post_init()

Serial.print(F("RADIO : "));
Serial.println(hw_info.rf == RF_IC_SX1276 ? F("PASS") : F("FAIL"));
if (hw_info.rf == RF_IC_SX1276) {
Serial.print(F("CLK SRC : "));
Serial.println(STM32_has_TCXO ? F("TCXO") : F("Crystal"));
}
Serial.print(F("GNSS : "));
Serial.println(hw_info.gnss == GNSS_MODULE_SONY ? F("PASS") : F("FAIL"));

Expand Down Expand Up @@ -283,6 +310,8 @@ static void STM32_fini()
delay(100);
pinMode(SOC_GPIO_PIN_GNSS_LS, INPUT);

digitalWrite(SOC_GPIO_PIN_ANT_RXTX, LOW);
pinMode(SOC_GPIO_PIN_ANT_RXTX, OUTPUT_OPEN_DRAIN);
#endif /* ARDUINO_NUCLEO_L073RZ */

swSer.end();
Expand Down
4 changes: 4 additions & 0 deletions software/firmware/source/SoftRF/src/platform/STM32.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ typedef struct stm32_backup_struct {
/* RF antenna switch */
#define SOC_GPIO_PIN_ANT_RXTX PA1 // 1:Rx, 0:Tx

/* RF clock source */
#define SOC_GPIO_PIN_TCXO_OE PD_7
#define SOC_GPIO_PIN_OSC_SEL PC1

/* I2C */
#define SOC_GPIO_PIN_SDA PB7
#define SOC_GPIO_PIN_SCL PB6
Expand Down
10 changes: 10 additions & 0 deletions software/firmware/source/libraries/arduino-lmic/src/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ static void hal_io_init () {
pinMode(lmic_pins.rxe, OUTPUT);
if (lmic_pins.rst != LMIC_UNUSED_PIN)
pinMode(lmic_pins.rst, OUTPUT);
if (lmic_pins.tcxo != LMIC_UNUSED_PIN)
pinMode(lmic_pins.tcxo, OUTPUT);

hal_interrupt_init();
}
Expand Down Expand Up @@ -182,6 +184,14 @@ static void hal_io_check() {
}
#endif // LMIC_USE_INTERRUPTS

bool hal_pin_tcxo (u1_t val) {
if (lmic_pins.tcxo == LMIC_UNUSED_PIN)
return false;

digitalWrite(lmic_pins.tcxo, val == 1 ? HIGH : LOW);
return true;
}

// -----------------------------------------------------------------------------
// SPI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ void hal_pin_nss (u1_t val);
*/
void hal_pin_rxtx (s1_t val);

/*
* control radio TCXO power (0=off, 1=on)
* (return if TCXO is present and in use)
*/
bool hal_pin_tcxo (u1_t val);

/*
* control radio RST pin (0=low, 1=high, 2=floating)
*/
Expand Down
54 changes: 44 additions & 10 deletions software/firmware/source/libraries/arduino-lmic/src/lmic/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,25 @@
// #define RegAgcThresh3 0x46 // common
// #define RegPllHop 0x4B // common
// #define RegTcxo 0x58 // common
#define RegPaDac 0x5A // common
#define SX1272_RegTcxo 0x58 // common
#define SX1276_RegTcxo 0x4B // common
#define SX1272_RegPaDac 0x5A // common
#define SX1276_RegPaDac 0x4D // common
// #define RegPll 0x5C // common
// #define RegPllLowPn 0x5E // common
// #define RegFormerTemp 0x6C // common
// #define RegBitRateFrac 0x70 // common

#ifdef CFG_sx1276_radio
#define RADIO_VERSION 0x12
#define RegPaDac SX1276_RegPaDac
#define RegTcxo SX1276_RegTcxo
#elif CFG_sx1272_radio
#define RADIO_VERSION 0x22
#define RegPaDac SX1272_RegPaDac
#define RegTcxo SX1272_RegTcxo
#endif

// ----------------------------------------
// spread factors and mode for RegModemConfig2
#define SX1272_MC2_FSK 0x00
Expand Down Expand Up @@ -461,12 +474,23 @@ static void configPower () {
#endif /* CFG_sx1272_radio */
}

static void power_tcxo (void) {
// power-up TCXO and set tcxo as input
if ( hal_pin_tcxo(1) ) {
writeReg(RegTcxo, 0b00011001); // reserved=000, tcxo=1, reserved=1001
}
}

#define RF_FIFOTHRESH_TXSTARTCONDITION_FIFONOTEMPTY 0x80

static void txfsk () {
// select FSK modem (from sleep mode)
writeReg(RegOpMode, 0x0 /* 0x10 */ ); // FSK, BT=0.5
ASSERT(readReg(RegOpMode) == 0x0 /* 0x10 */ );

// power-up tcxo
power_tcxo();

// enter standby mode (required for FIFO loading))
opmode(OPMODE_STANDBY);

Expand Down Expand Up @@ -580,6 +604,9 @@ static void txlora () {
opmodeLora();
ASSERT((readReg(RegOpMode) & OPMODE_LORA) != 0);

// power-up tcxo
power_tcxo();

// enter standby mode (required for FIFO loading))
opmode(OPMODE_STANDBY);
// configure LoRa modem (cfg1, cfg2)
Expand Down Expand Up @@ -653,6 +680,10 @@ static void rxlora (u1_t rxmode) {
// select LoRa modem (from sleep mode)
opmodeLora();
ASSERT((readReg(RegOpMode) & OPMODE_LORA) != 0);

// power-up tcxo
power_tcxo();

// enter standby mode (warm up))
opmode(OPMODE_STANDBY);
// don't use MAC settings at startup
Expand Down Expand Up @@ -730,6 +761,9 @@ static void rxfsk (u1_t rxmode) {
opmodeFSK();
ASSERT((readReg(RegOpMode) & OPMODE_LORA) == 0);

// power-up tcxo
power_tcxo();

// enter standby mode (warm up))
opmode(OPMODE_STANDBY);

Expand Down Expand Up @@ -903,6 +937,9 @@ static void startrx (u1_t rxmode) {
void radio_init () {
hal_disableIRQs();

// power-up tcxo
power_tcxo();

// manually reset radio
#ifdef CFG_sx1276_radio
hal_pin_rst(0); // drive RST pin low
Expand All @@ -913,17 +950,14 @@ void radio_init () {
hal_pin_rst(2); // configure RST pin floating!
hal_waitUntil(os_getTime()+ms2osticks(5)); // wait 5ms

// power-down TCXO
hal_pin_tcxo(0);

opmode(OPMODE_SLEEP);

// some sanity checks, e.g., read version number
u1_t v = readReg(RegVersion);
#ifdef CFG_sx1276_radio
ASSERT(v == 0x12 );
#elif CFG_sx1272_radio
ASSERT(v == 0x22);
#else
#error Missing CFG_sx1272_radio/CFG_sx1276_radio
#endif
// sanity check, read version number
ASSERT( readReg(RegVersion) == RADIO_VERSION );

// seed 15-byte randomness via noise rssi
rxlora(RXMODE_RSSI);
while( (readReg(RegOpMode) & OPMODE_MASK) != OPMODE_RX ); // continuous rx
Expand Down

0 comments on commit e5ff3a4

Please sign in to comment.