Text menu driven ANSI/VT100 console test utility for LoRa transceivers

radio chip selection

Radio chip driver is not included, allowing choice of radio device.
If you're using SX1272 or SX1276, then import sx127x driver into your program.
if you're using SX1261 or SX1262, then import sx126x driver into your program.
if you're using SX1280, then import sx1280 driver into your program.
if you're using LR1110, then import LR1110 driver into your program.
If you're using NAmote72 or Murata discovery, then you must import only sx127x driver.
If you're using Type1SJ select target DISCO_L072CZ_LRWAN1 and import sx126x driver into your program.

This is VT100 text-based menu driven test program for SX12xx transceiver devices.
Serial console is divided into horizontally into top half and bottom half.
The bottom half serves as scrolling area to log activity.
The top half serves as menu, to configure the radio.
For all devices, the serial console operates at 115200 8N1, and requires terminal with ANSI-VT100 capability, such as putty/teraterm/minicom etc.
Use program only with keyboard up/down/left/right keys. Enter to change an item, or number for value item. Some items are single bit, requiring only enter key to toggle. Others with fixed choices give a drop-down menu.

Committer:
Wayne Roberts
Date:
Mon May 04 17:54:55 2020 -0700
Revision:
9:295e37c38fb3
Parent:
7:ea73b63b9eb1
Child:
14:14b9e1c08bfc
sx126x: add LDO/DCDC control and TCXO control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 1:0817a150122b 1 /* Only for NUCLEO boards: prevent compiling for MOTE_L152RC and typeABZ discovery */
Wayne Roberts 9:295e37c38fb3 2 #if defined(TARGET_FF_ARDUINO) && !defined(TARGET_DISCO_L072CZ_LRWAN1)
Wayne Roberts 1:0817a150122b 3 #include "radio.h"
Wayne Roberts 1:0817a150122b 4 #ifdef SX127x_H
Wayne Roberts 1:0817a150122b 5
Wayne Roberts 1:0817a150122b 6 SPI spi(D11, D12, D13); // mosi, miso, sclk
Wayne Roberts 1:0817a150122b 7 // dio0, dio1, nss, spi, rst
Wayne Roberts 1:0817a150122b 8 SX127x Radio::radio( D2, D3, D10, spi, A0); // sx127[62] arduino shield
Wayne Roberts 1:0817a150122b 9 SX127x_lora Radio::lora(radio);
Wayne Roberts 1:0817a150122b 10 SX127x_fsk Radio::fsk(radio);
Wayne Roberts 1:0817a150122b 11
Wayne Roberts 1:0817a150122b 12 InterruptIn Radio::dio0(D2);
Wayne Roberts 1:0817a150122b 13 InterruptIn Radio::dio1(D3);
Wayne Roberts 1:0817a150122b 14
Wayne Roberts 1:0817a150122b 15 typedef enum {
Wayne Roberts 1:0817a150122b 16 SHIELD_TYPE_NONE = 0,
Wayne Roberts 1:0817a150122b 17 SHIELD_TYPE_LAS,
Wayne Roberts 1:0817a150122b 18 SHIELD_TYPE_MAS,
Wayne Roberts 1:0817a150122b 19 } shield_type_e;
Wayne Roberts 1:0817a150122b 20 shield_type_e shield_type;
Wayne Roberts 1:0817a150122b 21
Wayne Roberts 1:0817a150122b 22 #ifdef TARGET_FF_MORPHO
Wayne Roberts 1:0817a150122b 23 DigitalOut pc3(PC_3); // debug RX indication, for nucleo boards
Wayne Roberts 1:0817a150122b 24 #endif /* TARGET_FF_MORPHO */
Wayne Roberts 1:0817a150122b 25 DigitalInOut rfsw(A4);
Wayne Roberts 1:0817a150122b 26 void Radio::rfsw_callback()
Wayne Roberts 1:0817a150122b 27 {
Wayne Roberts 1:0817a150122b 28 if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER)
Wayne Roberts 1:0817a150122b 29 rfsw = 1;
Wayne Roberts 1:0817a150122b 30 else
Wayne Roberts 1:0817a150122b 31 rfsw = 0;
Wayne Roberts 1:0817a150122b 32
Wayne Roberts 9:295e37c38fb3 33 #ifdef TARGET_FF_MORPHO
Wayne Roberts 1:0817a150122b 34 if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE)
Wayne Roberts 1:0817a150122b 35 pc3 = 1;
Wayne Roberts 1:0817a150122b 36 else
Wayne Roberts 1:0817a150122b 37 pc3 = 0;
Wayne Roberts 9:295e37c38fb3 38 #endif /* TARGET_FF_MORPHO */
Wayne Roberts 1:0817a150122b 39 }
Wayne Roberts 1:0817a150122b 40
Wayne Roberts 1:0817a150122b 41 void Radio::targetInit()
Wayne Roberts 1:0817a150122b 42 {
Wayne Roberts 1:0817a150122b 43 radio.rf_switch = rfsw_callback;
Wayne Roberts 1:0817a150122b 44
Wayne Roberts 1:0817a150122b 45 rfsw.input();
Wayne Roberts 1:0817a150122b 46
Wayne Roberts 1:0817a150122b 47 radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
Wayne Roberts 1:0817a150122b 48
Wayne Roberts 1:0817a150122b 49 if (rfsw.read()) {
Wayne Roberts 1:0817a150122b 50 shield_type = SHIELD_TYPE_LAS;
Wayne Roberts 1:0817a150122b 51 radio.RegPaConfig.bits.PaSelect = 1;
Wayne Roberts 1:0817a150122b 52 } else {
Wayne Roberts 1:0817a150122b 53 shield_type = SHIELD_TYPE_MAS;
Wayne Roberts 1:0817a150122b 54 radio.RegPaConfig.bits.PaSelect = 0;
Wayne Roberts 1:0817a150122b 55 }
Wayne Roberts 1:0817a150122b 56
Wayne Roberts 1:0817a150122b 57 radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
Wayne Roberts 5:1e5cb7139acb 58
Wayne Roberts 1:0817a150122b 59 rfsw.output();
Wayne Roberts 1:0817a150122b 60 }
Wayne Roberts 1:0817a150122b 61
Wayne Roberts 1:0817a150122b 62 void Radio::tx_dbm_print()
Wayne Roberts 1:0817a150122b 63 {
Wayne Roberts 1:0817a150122b 64 int dbm;
Wayne Roberts 1:0817a150122b 65 RegPdsTrim1_t pds_trim;
Wayne Roberts 4:fa31fdf4ec8d 66 uint8_t adr, pa_test_adr;
Wayne Roberts 1:0817a150122b 67
Wayne Roberts 4:fa31fdf4ec8d 68 if (radio.type == SX1276) {
Wayne Roberts 1:0817a150122b 69 adr = REG_PDSTRIM1_SX1276;
Wayne Roberts 4:fa31fdf4ec8d 70 pa_test_adr = REG_PATEST_SX1276;
Wayne Roberts 4:fa31fdf4ec8d 71 } else {
Wayne Roberts 1:0817a150122b 72 adr = REG_PDSTRIM1_SX1272;
Wayne Roberts 4:fa31fdf4ec8d 73 pa_test_adr = REG_PATEST_SX1272;
Wayne Roberts 4:fa31fdf4ec8d 74 }
Wayne Roberts 1:0817a150122b 75
Wayne Roberts 5:1e5cb7139acb 76 if (radio.read_reg(pa_test_adr) & 0x20) {
Wayne Roberts 5:1e5cb7139acb 77 pds_trim.octet = radio.read_reg(adr);
Wayne Roberts 1:0817a150122b 78
Wayne Roberts 4:fa31fdf4ec8d 79 radio.RegPaConfig.octet = radio.read_reg(REG_PACONFIG);
Wayne Roberts 4:fa31fdf4ec8d 80 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 4:fa31fdf4ec8d 81 dbm = radio.RegPaConfig.bits.OutputPower + pds_trim.bits.prog_txdac - 2;
Wayne Roberts 4:fa31fdf4ec8d 82 } else {
Wayne Roberts 4:fa31fdf4ec8d 83 dbm = radio.RegPaConfig.bits.OutputPower - 1;
Wayne Roberts 4:fa31fdf4ec8d 84 }
Wayne Roberts 1:0817a150122b 85 } else {
Wayne Roberts 4:fa31fdf4ec8d 86 dbm = PA_OFF_DBM;
Wayne Roberts 1:0817a150122b 87 }
Wayne Roberts 5:1e5cb7139acb 88 pc.printf("%d", dbm);
Wayne Roberts 1:0817a150122b 89 }
Wayne Roberts 1:0817a150122b 90
Wayne Roberts 1:0817a150122b 91 bool Radio::tx_dbm_write(const char* str)
Wayne Roberts 1:0817a150122b 92 {
Wayne Roberts 1:0817a150122b 93 int i;
Wayne Roberts 4:fa31fdf4ec8d 94 uint8_t v, adr, pa_test_adr;
Wayne Roberts 1:0817a150122b 95 RegPdsTrim1_t pds_trim;
Wayne Roberts 1:0817a150122b 96
Wayne Roberts 1:0817a150122b 97 sscanf(str, "%d", &i);
Wayne Roberts 1:0817a150122b 98
Wayne Roberts 4:fa31fdf4ec8d 99 if (radio.type == SX1276) {
Wayne Roberts 1:0817a150122b 100 adr = REG_PDSTRIM1_SX1276;
Wayne Roberts 4:fa31fdf4ec8d 101 pa_test_adr = REG_PATEST_SX1276;
Wayne Roberts 4:fa31fdf4ec8d 102 } else {
Wayne Roberts 1:0817a150122b 103 adr = REG_PDSTRIM1_SX1272;
Wayne Roberts 4:fa31fdf4ec8d 104 pa_test_adr = REG_PATEST_SX1272;
Wayne Roberts 4:fa31fdf4ec8d 105 }
Wayne Roberts 4:fa31fdf4ec8d 106
Wayne Roberts 4:fa31fdf4ec8d 107 v = radio.read_reg(pa_test_adr);
Wayne Roberts 4:fa31fdf4ec8d 108
Wayne Roberts 4:fa31fdf4ec8d 109 if (i == PA_OFF_DBM) {
Wayne Roberts 4:fa31fdf4ec8d 110 /* for bench testing: prevent overloading receiving station (very low TX power) */
Wayne Roberts 4:fa31fdf4ec8d 111 v &= ~0x20; // turn off pu_regpa_n: disable PA
Wayne Roberts 4:fa31fdf4ec8d 112 radio.write_reg(pa_test_adr, v);
Wayne Roberts 4:fa31fdf4ec8d 113 return false;
Wayne Roberts 4:fa31fdf4ec8d 114 } else if ((v & 0x20) == 0) {
Wayne Roberts 4:fa31fdf4ec8d 115 v |= 0x20; // turn on pu_regpa_n: enable PA
Wayne Roberts 4:fa31fdf4ec8d 116 radio.write_reg(pa_test_adr, v);
Wayne Roberts 4:fa31fdf4ec8d 117 }
Wayne Roberts 5:1e5cb7139acb 118
Wayne Roberts 5:1e5cb7139acb 119 pds_trim.octet = radio.read_reg(adr);
Wayne Roberts 1:0817a150122b 120
Wayne Roberts 1:0817a150122b 121 if (radio.RegPaConfig.bits.PaSelect) {
Wayne Roberts 1:0817a150122b 122 /* PABOOST used: +2dbm to +17, or +20 */
Wayne Roberts 1:0817a150122b 123 if (i == 20) {
Wayne Roberts 1:0817a150122b 124 log_printf("+20dBm PADAC bias\r\n");
Wayne Roberts 1:0817a150122b 125 i -= 3;
Wayne Roberts 1:0817a150122b 126 pds_trim.bits.prog_txdac = 7;
Wayne Roberts 1:0817a150122b 127 radio.write_reg(adr, pds_trim.octet);
Wayne Roberts 1:0817a150122b 128 }
Wayne Roberts 1:0817a150122b 129 if (i > 1)
Wayne Roberts 1:0817a150122b 130 radio.RegPaConfig.bits.OutputPower = i - 2;
Wayne Roberts 1:0817a150122b 131 } else {
Wayne Roberts 1:0817a150122b 132 /* RFO used: -1 to +14dbm */
Wayne Roberts 1:0817a150122b 133 if (i < 15)
Wayne Roberts 1:0817a150122b 134 radio.RegPaConfig.bits.OutputPower = i + 1;
Wayne Roberts 1:0817a150122b 135 }
Wayne Roberts 1:0817a150122b 136 radio.write_reg(REG_PACONFIG, radio.RegPaConfig.octet);
Wayne Roberts 1:0817a150122b 137
Wayne Roberts 1:0817a150122b 138 return false;
Wayne Roberts 1:0817a150122b 139 }
Wayne Roberts 1:0817a150122b 140
Wayne Roberts 1:0817a150122b 141
Wayne Roberts 1:0817a150122b 142 #endif /* ..SX127x_H */
Wayne Roberts 1:0817a150122b 143 #endif /* ...sx127x shield */
Wayne Roberts 1:0817a150122b 144