Skip to content

Commit

Permalink
Add FskRadio / LoRaRadio libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
GrumpyOldPizza committed Aug 30, 2018
1 parent e2212a4 commit fc573fd
Show file tree
Hide file tree
Showing 45 changed files with 6,877 additions and 1,552 deletions.
49 changes: 49 additions & 0 deletions boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,55 @@ B-L072Z-LRWAN1.menu.opt.o3.build.flags.optimize=-O3
B-L072Z-LRWAN1.menu.opt.o3.build.flags.ldspecs=


# ST I-NUCLEO-LRWAN1
# ---------------------------------------
I-NUCLEO-LRWAN1.name=I-NUCLEO-LRWAN1
I-NUCLEO-LRWAN1.vid.0=0x0483
I-NUCLEO-LRWAN1.pid.0=0x374b

I-NUCLEO-LRWAN1.upload.tool=stm32l0_openocd
I-NUCLEO-LRWAN1.upload.protocol=stlink
I-NUCLEO-LRWAN1.upload.maximum_size=65536
I-NUCLEO-LRWAN1.upload.maximum_data_size=8192
I-NUCLEO-LRWAN1.upload.use_1200bps_touch=true
I-NUCLEO-LRWAN1.upload.wait_for_upload_port=false
I-NUCLEO-LRWAN1.upload.native_usb=false

I-NUCLEO-LRWAN1.build.mcu=cortex-m0plus
I-NUCLEO-LRWAN1.build.f_cpu=32000000L
I-NUCLEO-LRWAN1.build.board=STM32L0_NUCLEO
I-NUCLEO-LRWAN1.build.arch=stm32l0
I-NUCLEO-LRWAN1.build.core=arduino
I-NUCLEO-LRWAN1.build.vid=0x0483
I-NUCLEO-LRWAN1.build.pid=0x374b
I-NUCLEO-LRWAN1.build.did=0xffff
I-NUCLEO-LRWAN1.build.extra_flags=-DSTM32L052xx -march=armv6-m -mthumb -mabi=aapcs -mfloat-abi=soft -fsingle-precision-constant
I-NUCLEO-LRWAN1.build.ldscript=linker_scripts/STM32L052T8_FLASH.ld
I-NUCLEO-LRWAN1.build.openocdscript=openocd_scripts/i-nucleo-lrwan1.cfg
I-NUCLEO-LRWAN1.build.variant=I-NUCLEO-LRWAN1
I-NUCLEO-LRWAN1.build.variant_system_libs="-L{runtime.platform.path}/system/STM32L0xx/Lib" "-L{runtime.platform.path}/system/CMSIS/Lib" -lstm32l052xx -larm_cortexM0l_math
I-NUCLEO-LRWAN1.build.variant_system_include="-I{runtime.platform.path}/system/CMSIS/Include" "-I{runtime.platform.path}/system/CMSIS/Device/ST/STM32L0xx/Include" "-I{runtime.platform.path}/system/STM32L0xx/Include"

I-NUCLEO-LRWAN1.menu.speed.32=32 MHz
I-NUCLEO-LRWAN1.menu.speed.32.build.f_cpu=32000000L
I-NUCLEO-LRWAN1.menu.speed.16=16 MHz
I-NUCLEO-LRWAN1.menu.speed.16.build.f_cpu=16000000L
I-NUCLEO-LRWAN1.menu.speed.4=4.2 MHz
I-NUCLEO-LRWAN1.menu.speed.4.build.f_cpu=4200000L

I-NUCLEO-LRWAN1.menu.opt.os=Smallest Code
I-NUCLEO-LRWAN1.menu.opt.os.build.flags.optimize=-Os
I-NUCLEO-LRWAN1.menu.opt.os.build.flags.ldspecs=--specs=nano.specs
I-NUCLEO-LRWAN1.menu.opt.o1=Fast
I-NUCLEO-LRWAN1.menu.opt.o1.build.flags.optimize=-O1
I-NUCLEO-LRWAN1.menu.opt.o1.build.flags.ldspecs=
I-NUCLEO-LRWAN1.menu.opt.o2=Faster
I-NUCLEO-LRWAN1.menu.opt.o2.build.flags.optimize=-O2
I-NUCLEO-LRWAN1.menu.opt.o2.build.flags.ldspecs=
I-NUCLEO-LRWAN1.menu.opt.o3=Fastest
I-NUCLEO-LRWAN1.menu.opt.o3.build.flags.optimize=-O3
I-NUCLEO-LRWAN1.menu.opt.o3.build.flags.ldspecs=


# ST P-NUCLEO-LRWAN1
# ---------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions cores/arduino/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ INCLUDES = \
-I../../libraries/CayenneLPP/src \
-I../../libraries/DOSFS/src \
-I../../libraries/EEPROM/src \
-I../../libraries/FskRadio/src \
-I../../libraries/GNSS/src \
-I../../libraries/GNSS/src/utility \
-I../../libraries/LoRaRadio/src \
-I../../libraries/LoRaWAN/src \
-I../../libraries/RTC/src \
-I../../libraries/SPI/src \
Expand All @@ -32,8 +34,10 @@ INCLUDES = \
SRCS = \
../../libraries/CayenneLPP/src/CayenneLPP.cpp \
../../libraries/DOSFS/src/DOSFS.cpp \
../../libraries/FskRadio/src/FskRadio.cpp \
../../libraries/GNSS/src/GNSS.cpp \
../../libraries/GNSS/src/utility/gnss_core.c \
../../libraries/LoRaRadio/src/LoRaRadio.cpp \
../../libraries/LoRaWAN/src/LoRaWAN.cpp \
../../libraries/RTC/src/RTC.cpp \
../../libraries/SPI/src/SPI.cpp \
Expand Down Expand Up @@ -78,8 +82,10 @@ SRCS = \
OBJS = \
../../libraries/CayenneLPP/src/CayenneLPP.o \
../../libraries/DOSFS/src/DOSFS.o \
../../libraries/FskRadio/src/FskRadio.o \
../../libraries/GNSS/src/GNSS.o \
../../libraries/GNSS/src/utility/gnss_core.o \
../../libraries/LoRaRadio/src/LoRaRadio.o \
../../libraries/LoRaWAN/src/LoRaWAN.o \
../../libraries/RTC/src/RTC.o \
../../libraries/SPI/src/SPI.o \
Expand Down
20 changes: 16 additions & 4 deletions cores/arduino/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@
extern "C" {
#endif

#if defined(PWM_INSTANCE_COUNT)

extern const unsigned int g_PWMInstances[PWM_INSTANCE_COUNT];

static stm32l0_timer_t stm32l0_pwm[PWM_INSTANCE_COUNT];

static uint8_t _channels[PWM_INSTANCE_COUNT];

#endif /* PWM_INSTANCE_COUNT */

static int _readResolution = 10;
static int _readPeriod = 2000;
static int _writeResolution = 8;
Expand Down Expand Up @@ -124,10 +129,7 @@ uint32_t analogRead(uint32_t ulPin)
return 0;
}

if (g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2))
{
stm32l0_dac_disable(g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2));
}
__analogWriteDisable(ulPin);

stm32l0_gpio_pin_configure(g_APinDescription[ulPin].pin, (STM32L0_GPIO_PUPD_NONE | STM32L0_GPIO_MODE_ANALOG));

Expand All @@ -151,6 +153,7 @@ void analogWrite(uint32_t ulPin, uint32_t value)
return;
}

#if defined(DAC_RESOLUTION)
if (g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2))
{
stm32l0_gpio_pin_configure(g_APinDescription[ulPin].pin, (STM32L0_GPIO_PUPD_NONE | STM32L0_GPIO_MODE_ANALOG));
Expand All @@ -161,7 +164,9 @@ void analogWrite(uint32_t ulPin, uint32_t value)

return;
}
#endif /* DAC_RESOLUTION */

#if defined(PWM_INSTANCE_COUNT)
if (g_APinDescription[ulPin].pwm_instance != PWM_INSTANCE_NONE)
{
instance = g_APinDescription[ulPin].pwm_instance;
Expand Down Expand Up @@ -202,6 +207,7 @@ void analogWrite(uint32_t ulPin, uint32_t value)

return;
}
#endif /* PWM_INSTANCE_COUNT */

// -- Defaults to digital write
pinMode(ulPin, OUTPUT) ;
Expand All @@ -217,15 +223,20 @@ void analogWrite(uint32_t ulPin, uint32_t value)

void __analogWriteDisable(uint32_t ulPin)
{
#if defined(PWM_INSTANCE_COUNT)
uint32_t instance;
#endif /* PWM_INSTANCE_COUNT */

#if defined(DAC_RESOLUTION)
if (g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2))
{
stm32l0_dac_disable(g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2));

return;
}
#endif /* DAC_RESOLUTION */

#if defined(PWM_INSTANCE_COUNT)
if (g_APinDescription[ulPin].pwm_instance != PWM_INSTANCE_NONE)
{
instance = g_APinDescription[ulPin].pwm_instance;
Expand All @@ -243,6 +254,7 @@ void __analogWriteDisable(uint32_t ulPin)
}
}
}
#endif /* PWM_INSTANCE_COUNT */
}

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions cores/arduino/wiring_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extern bool USBD_Suspended(void);

extern void CMWX1ZZABZ_Initialize(uint16_t pin_tcxo, uint16_t pin_stsafe);
extern void SX1272MB2DAS_Initialize(void);
extern void WMSGSM42_Initialize(void);

extern int g_swdStatus; /* 0, default, 1 = enable, 2 = disable, 3 = forced disable */

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/* Simple Ping-Pong using address filtering for a FSK Radio/Modem
*
* In setup() below please adjust your country specific frequency ranges,
* as well as the Bandwidth/SpreadingFactor/CodingRate settings.
*
* They way this example works is that the device first listens for 5000ms.
* If it received a "PING" message, it considers itself a SLAVE. If not
* it considers itself a MASTER. A SLAVE waits for an incoming "PING" message,
* which it answers with a "PONG" message. A MASTER simply sends periodically
* every 1000ms) a "PING" message, and collects "PONG" replies while waiting.
*
* This variant makes use of address filter to comminicate between nodes.
*
*
* This example code is in the public domain.
*/

#include "FskRadio.h"

#define STATE_NONE 0
#define STATE_SCANNING 1
#define STATE_TX_MASTER 2
#define STATE_RX_MASTER 3
#define STATE_TX_SLAVE 4
#define STATE_RX_SLAVE 5

int state = STATE_NONE;
int address = 0x00;

void setup( void )
{
Serial.begin(9600);

while (!Serial) { }

FskRadio.begin(915000000);

FskRadio.setFrequency(915000000);
FskRadio.setTxPower(14);
FskRadio.setDeviation(25000);
FskRadio.setBandwidth(100000);
FskRadio.setBandwidthAfc(100000);
FskRadio.setBitRate(50000);
FskRadio.setModulation(FskRadio.FSK);
FskRadio.setAddressFiltering(FskRadio.FILTERING_NODE_AND_BROADCAST);
FskRadio.setNodeAddress(0x00);
FskRadio.setBroadcastAddress(0xff);
FskRadio.setLnaBoost(true);

state = STATE_SCANNING;

FskRadio.receive(5000);
}

void loop( void )
{
switch (state) {
case STATE_NONE:
break;

case STATE_SCANNING:
if ((FskRadio.parsePacket() == 4) &&
(FskRadio.read() == 'P') &&
(FskRadio.read() == 'I') &&
(FskRadio.read() == 'N') &&
(FskRadio.read() == 'G'))
{
// Got a PING from a master, so we are slave ...

Serial.println("= SLAVE");
Serial.print("< PING (RSSI: ");
Serial.print(FskRadio.packetRssi());
Serial.println(")");
Serial.println("> PONG");

state = STATE_TX_SLAVE;

FskRadio.beginPacket(0xff);
FskRadio.write('P');
FskRadio.write('O');
FskRadio.write('N');
FskRadio.write('G');
FskRadio.endPacket();
}
else
{
if (!FskRadio.busy())
{
// Didn't hear anything, so we are master ...

Serial.println("= MASTER");
Serial.print("> PING ");
Serial.println(address, HEX);

state = STATE_TX_MASTER;

FskRadio.beginPacket(address);
FskRadio.write('P');
FskRadio.write('I');
FskRadio.write('N');
FskRadio.write('G');
FskRadio.endPacket();

address ^= 1;
}
}
break;

case STATE_TX_MASTER:
if (!FskRadio.busy())
{
state = STATE_RX_MASTER;

FskRadio.receive(1000);
}
break;

case STATE_RX_MASTER:
if ((FskRadio.parsePacket() == 4) &&
(FskRadio.read() == 'P') &&
(FskRadio.read() == 'O') &&
(FskRadio.read() == 'N') &&
(FskRadio.read() == 'G'))
{
// Got a PING from a slave

Serial.print("< PONG (RSSI: ");
Serial.print(FskRadio.packetRssi());
Serial.println(")");
}

if (!FskRadio.busy())
{
// Receive timed out, so send a PING

Serial.print("> PING ");
Serial.println(address, HEX);

state = STATE_TX_MASTER;

FskRadio.beginPacket(address);
FskRadio.write('P');
FskRadio.write('I');
FskRadio.write('N');
FskRadio.write('G');
FskRadio.endPacket();

address ^= 1;
}
break;

case STATE_TX_SLAVE:
if (!FskRadio.busy())
{
state = STATE_RX_SLAVE;

FskRadio.receive();
}
break;

case STATE_RX_SLAVE:
if ((FskRadio.parsePacket() == 4) &&
(FskRadio.read() == 'P') &&
(FskRadio.read() == 'I') &&
(FskRadio.read() == 'N') &&
(FskRadio.read() == 'G'))
{
// Got a PING from a master, so send a PONG as reply

Serial.print("< PING (RSSI: ");
Serial.print(FskRadio.packetRssi());
Serial.println(")");
Serial.println("> PONG");

state = STATE_TX_SLAVE;

FskRadio.beginPacket(0xff);
FskRadio.write('P');
FskRadio.write('O');
FskRadio.write('N');
FskRadio.write('G');
FskRadio.endPacket();
}
break;
}
}
Loading

0 comments on commit fc573fd

Please sign in to comment.