Skip to content

Commit fc573fd

Browse files
Add FskRadio / LoRaRadio libraries
1 parent e2212a4 commit fc573fd

File tree

45 files changed

+6877
-1552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6877
-1552
lines changed

boards.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,55 @@ B-L072Z-LRWAN1.menu.opt.o3.build.flags.optimize=-O3
267267
B-L072Z-LRWAN1.menu.opt.o3.build.flags.ldspecs=
268268

269269

270+
# ST I-NUCLEO-LRWAN1
271+
# ---------------------------------------
272+
I-NUCLEO-LRWAN1.name=I-NUCLEO-LRWAN1
273+
I-NUCLEO-LRWAN1.vid.0=0x0483
274+
I-NUCLEO-LRWAN1.pid.0=0x374b
275+
276+
I-NUCLEO-LRWAN1.upload.tool=stm32l0_openocd
277+
I-NUCLEO-LRWAN1.upload.protocol=stlink
278+
I-NUCLEO-LRWAN1.upload.maximum_size=65536
279+
I-NUCLEO-LRWAN1.upload.maximum_data_size=8192
280+
I-NUCLEO-LRWAN1.upload.use_1200bps_touch=true
281+
I-NUCLEO-LRWAN1.upload.wait_for_upload_port=false
282+
I-NUCLEO-LRWAN1.upload.native_usb=false
283+
284+
I-NUCLEO-LRWAN1.build.mcu=cortex-m0plus
285+
I-NUCLEO-LRWAN1.build.f_cpu=32000000L
286+
I-NUCLEO-LRWAN1.build.board=STM32L0_NUCLEO
287+
I-NUCLEO-LRWAN1.build.arch=stm32l0
288+
I-NUCLEO-LRWAN1.build.core=arduino
289+
I-NUCLEO-LRWAN1.build.vid=0x0483
290+
I-NUCLEO-LRWAN1.build.pid=0x374b
291+
I-NUCLEO-LRWAN1.build.did=0xffff
292+
I-NUCLEO-LRWAN1.build.extra_flags=-DSTM32L052xx -march=armv6-m -mthumb -mabi=aapcs -mfloat-abi=soft -fsingle-precision-constant
293+
I-NUCLEO-LRWAN1.build.ldscript=linker_scripts/STM32L052T8_FLASH.ld
294+
I-NUCLEO-LRWAN1.build.openocdscript=openocd_scripts/i-nucleo-lrwan1.cfg
295+
I-NUCLEO-LRWAN1.build.variant=I-NUCLEO-LRWAN1
296+
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
297+
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"
298+
299+
I-NUCLEO-LRWAN1.menu.speed.32=32 MHz
300+
I-NUCLEO-LRWAN1.menu.speed.32.build.f_cpu=32000000L
301+
I-NUCLEO-LRWAN1.menu.speed.16=16 MHz
302+
I-NUCLEO-LRWAN1.menu.speed.16.build.f_cpu=16000000L
303+
I-NUCLEO-LRWAN1.menu.speed.4=4.2 MHz
304+
I-NUCLEO-LRWAN1.menu.speed.4.build.f_cpu=4200000L
305+
306+
I-NUCLEO-LRWAN1.menu.opt.os=Smallest Code
307+
I-NUCLEO-LRWAN1.menu.opt.os.build.flags.optimize=-Os
308+
I-NUCLEO-LRWAN1.menu.opt.os.build.flags.ldspecs=--specs=nano.specs
309+
I-NUCLEO-LRWAN1.menu.opt.o1=Fast
310+
I-NUCLEO-LRWAN1.menu.opt.o1.build.flags.optimize=-O1
311+
I-NUCLEO-LRWAN1.menu.opt.o1.build.flags.ldspecs=
312+
I-NUCLEO-LRWAN1.menu.opt.o2=Faster
313+
I-NUCLEO-LRWAN1.menu.opt.o2.build.flags.optimize=-O2
314+
I-NUCLEO-LRWAN1.menu.opt.o2.build.flags.ldspecs=
315+
I-NUCLEO-LRWAN1.menu.opt.o3=Fastest
316+
I-NUCLEO-LRWAN1.menu.opt.o3.build.flags.optimize=-O3
317+
I-NUCLEO-LRWAN1.menu.opt.o3.build.flags.ldspecs=
318+
270319

271320
# ST P-NUCLEO-LRWAN1
272321
# ---------------------------------------

cores/arduino/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ INCLUDES = \
2020
-I../../libraries/CayenneLPP/src \
2121
-I../../libraries/DOSFS/src \
2222
-I../../libraries/EEPROM/src \
23+
-I../../libraries/FskRadio/src \
2324
-I../../libraries/GNSS/src \
2425
-I../../libraries/GNSS/src/utility \
26+
-I../../libraries/LoRaRadio/src \
2527
-I../../libraries/LoRaWAN/src \
2628
-I../../libraries/RTC/src \
2729
-I../../libraries/SPI/src \
@@ -32,8 +34,10 @@ INCLUDES = \
3234
SRCS = \
3335
../../libraries/CayenneLPP/src/CayenneLPP.cpp \
3436
../../libraries/DOSFS/src/DOSFS.cpp \
37+
../../libraries/FskRadio/src/FskRadio.cpp \
3538
../../libraries/GNSS/src/GNSS.cpp \
3639
../../libraries/GNSS/src/utility/gnss_core.c \
40+
../../libraries/LoRaRadio/src/LoRaRadio.cpp \
3741
../../libraries/LoRaWAN/src/LoRaWAN.cpp \
3842
../../libraries/RTC/src/RTC.cpp \
3943
../../libraries/SPI/src/SPI.cpp \
@@ -78,8 +82,10 @@ SRCS = \
7882
OBJS = \
7983
../../libraries/CayenneLPP/src/CayenneLPP.o \
8084
../../libraries/DOSFS/src/DOSFS.o \
85+
../../libraries/FskRadio/src/FskRadio.o \
8186
../../libraries/GNSS/src/GNSS.o \
8287
../../libraries/GNSS/src/utility/gnss_core.o \
88+
../../libraries/LoRaRadio/src/LoRaRadio.o \
8389
../../libraries/LoRaWAN/src/LoRaWAN.o \
8490
../../libraries/RTC/src/RTC.o \
8591
../../libraries/SPI/src/SPI.o \

cores/arduino/wiring_analog.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,16 @@
3333
extern "C" {
3434
#endif
3535

36+
#if defined(PWM_INSTANCE_COUNT)
37+
3638
extern const unsigned int g_PWMInstances[PWM_INSTANCE_COUNT];
3739

3840
static stm32l0_timer_t stm32l0_pwm[PWM_INSTANCE_COUNT];
3941

4042
static uint8_t _channels[PWM_INSTANCE_COUNT];
43+
44+
#endif /* PWM_INSTANCE_COUNT */
45+
4146
static int _readResolution = 10;
4247
static int _readPeriod = 2000;
4348
static int _writeResolution = 8;
@@ -124,10 +129,7 @@ uint32_t analogRead(uint32_t ulPin)
124129
return 0;
125130
}
126131

127-
if (g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2))
128-
{
129-
stm32l0_dac_disable(g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2));
130-
}
132+
__analogWriteDisable(ulPin);
131133

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

@@ -151,6 +153,7 @@ void analogWrite(uint32_t ulPin, uint32_t value)
151153
return;
152154
}
153155

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

162165
return;
163166
}
167+
#endif /* DAC_RESOLUTION */
164168

169+
#if defined(PWM_INSTANCE_COUNT)
165170
if (g_APinDescription[ulPin].pwm_instance != PWM_INSTANCE_NONE)
166171
{
167172
instance = g_APinDescription[ulPin].pwm_instance;
@@ -202,6 +207,7 @@ void analogWrite(uint32_t ulPin, uint32_t value)
202207

203208
return;
204209
}
210+
#endif /* PWM_INSTANCE_COUNT */
205211

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

218224
void __analogWriteDisable(uint32_t ulPin)
219225
{
226+
#if defined(PWM_INSTANCE_COUNT)
220227
uint32_t instance;
228+
#endif /* PWM_INSTANCE_COUNT */
221229

230+
#if defined(DAC_RESOLUTION)
222231
if (g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2))
223232
{
224233
stm32l0_dac_disable(g_APinDescription[ulPin].attr & (PIN_ATTR_DAC1 | PIN_ATTR_DAC2));
225234

226235
return;
227236
}
237+
#endif /* DAC_RESOLUTION */
228238

239+
#if defined(PWM_INSTANCE_COUNT)
229240
if (g_APinDescription[ulPin].pwm_instance != PWM_INSTANCE_NONE)
230241
{
231242
instance = g_APinDescription[ulPin].pwm_instance;
@@ -243,6 +254,7 @@ void __analogWriteDisable(uint32_t ulPin)
243254
}
244255
}
245256
}
257+
#endif /* PWM_INSTANCE_COUNT */
246258
}
247259

248260
#ifdef __cplusplus

cores/arduino/wiring_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ extern bool USBD_Suspended(void);
7171

7272
extern void CMWX1ZZABZ_Initialize(uint16_t pin_tcxo, uint16_t pin_stsafe);
7373
extern void SX1272MB2DAS_Initialize(void);
74+
extern void WMSGSM42_Initialize(void);
7475

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

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/* Simple Ping-Pong using address filtering for a FSK Radio/Modem
2+
*
3+
* In setup() below please adjust your country specific frequency ranges,
4+
* as well as the Bandwidth/SpreadingFactor/CodingRate settings.
5+
*
6+
* They way this example works is that the device first listens for 5000ms.
7+
* If it received a "PING" message, it considers itself a SLAVE. If not
8+
* it considers itself a MASTER. A SLAVE waits for an incoming "PING" message,
9+
* which it answers with a "PONG" message. A MASTER simply sends periodically
10+
* every 1000ms) a "PING" message, and collects "PONG" replies while waiting.
11+
*
12+
* This variant makes use of address filter to comminicate between nodes.
13+
*
14+
*
15+
* This example code is in the public domain.
16+
*/
17+
18+
#include "FskRadio.h"
19+
20+
#define STATE_NONE 0
21+
#define STATE_SCANNING 1
22+
#define STATE_TX_MASTER 2
23+
#define STATE_RX_MASTER 3
24+
#define STATE_TX_SLAVE 4
25+
#define STATE_RX_SLAVE 5
26+
27+
int state = STATE_NONE;
28+
int address = 0x00;
29+
30+
void setup( void )
31+
{
32+
Serial.begin(9600);
33+
34+
while (!Serial) { }
35+
36+
FskRadio.begin(915000000);
37+
38+
FskRadio.setFrequency(915000000);
39+
FskRadio.setTxPower(14);
40+
FskRadio.setDeviation(25000);
41+
FskRadio.setBandwidth(100000);
42+
FskRadio.setBandwidthAfc(100000);
43+
FskRadio.setBitRate(50000);
44+
FskRadio.setModulation(FskRadio.FSK);
45+
FskRadio.setAddressFiltering(FskRadio.FILTERING_NODE_AND_BROADCAST);
46+
FskRadio.setNodeAddress(0x00);
47+
FskRadio.setBroadcastAddress(0xff);
48+
FskRadio.setLnaBoost(true);
49+
50+
state = STATE_SCANNING;
51+
52+
FskRadio.receive(5000);
53+
}
54+
55+
void loop( void )
56+
{
57+
switch (state) {
58+
case STATE_NONE:
59+
break;
60+
61+
case STATE_SCANNING:
62+
if ((FskRadio.parsePacket() == 4) &&
63+
(FskRadio.read() == 'P') &&
64+
(FskRadio.read() == 'I') &&
65+
(FskRadio.read() == 'N') &&
66+
(FskRadio.read() == 'G'))
67+
{
68+
// Got a PING from a master, so we are slave ...
69+
70+
Serial.println("= SLAVE");
71+
Serial.print("< PING (RSSI: ");
72+
Serial.print(FskRadio.packetRssi());
73+
Serial.println(")");
74+
Serial.println("> PONG");
75+
76+
state = STATE_TX_SLAVE;
77+
78+
FskRadio.beginPacket(0xff);
79+
FskRadio.write('P');
80+
FskRadio.write('O');
81+
FskRadio.write('N');
82+
FskRadio.write('G');
83+
FskRadio.endPacket();
84+
}
85+
else
86+
{
87+
if (!FskRadio.busy())
88+
{
89+
// Didn't hear anything, so we are master ...
90+
91+
Serial.println("= MASTER");
92+
Serial.print("> PING ");
93+
Serial.println(address, HEX);
94+
95+
state = STATE_TX_MASTER;
96+
97+
FskRadio.beginPacket(address);
98+
FskRadio.write('P');
99+
FskRadio.write('I');
100+
FskRadio.write('N');
101+
FskRadio.write('G');
102+
FskRadio.endPacket();
103+
104+
address ^= 1;
105+
}
106+
}
107+
break;
108+
109+
case STATE_TX_MASTER:
110+
if (!FskRadio.busy())
111+
{
112+
state = STATE_RX_MASTER;
113+
114+
FskRadio.receive(1000);
115+
}
116+
break;
117+
118+
case STATE_RX_MASTER:
119+
if ((FskRadio.parsePacket() == 4) &&
120+
(FskRadio.read() == 'P') &&
121+
(FskRadio.read() == 'O') &&
122+
(FskRadio.read() == 'N') &&
123+
(FskRadio.read() == 'G'))
124+
{
125+
// Got a PING from a slave
126+
127+
Serial.print("< PONG (RSSI: ");
128+
Serial.print(FskRadio.packetRssi());
129+
Serial.println(")");
130+
}
131+
132+
if (!FskRadio.busy())
133+
{
134+
// Receive timed out, so send a PING
135+
136+
Serial.print("> PING ");
137+
Serial.println(address, HEX);
138+
139+
state = STATE_TX_MASTER;
140+
141+
FskRadio.beginPacket(address);
142+
FskRadio.write('P');
143+
FskRadio.write('I');
144+
FskRadio.write('N');
145+
FskRadio.write('G');
146+
FskRadio.endPacket();
147+
148+
address ^= 1;
149+
}
150+
break;
151+
152+
case STATE_TX_SLAVE:
153+
if (!FskRadio.busy())
154+
{
155+
state = STATE_RX_SLAVE;
156+
157+
FskRadio.receive();
158+
}
159+
break;
160+
161+
case STATE_RX_SLAVE:
162+
if ((FskRadio.parsePacket() == 4) &&
163+
(FskRadio.read() == 'P') &&
164+
(FskRadio.read() == 'I') &&
165+
(FskRadio.read() == 'N') &&
166+
(FskRadio.read() == 'G'))
167+
{
168+
// Got a PING from a master, so send a PONG as reply
169+
170+
Serial.print("< PING (RSSI: ");
171+
Serial.print(FskRadio.packetRssi());
172+
Serial.println(")");
173+
Serial.println("> PONG");
174+
175+
state = STATE_TX_SLAVE;
176+
177+
FskRadio.beginPacket(0xff);
178+
FskRadio.write('P');
179+
FskRadio.write('O');
180+
FskRadio.write('N');
181+
FskRadio.write('G');
182+
FskRadio.endPacket();
183+
}
184+
break;
185+
}
186+
}

0 commit comments

Comments
 (0)