Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit 80ad3d0

Browse files
authored
Merge pull request #6 from fpistm/fw_update
Update library
2 parents 75ee411 + 191d7a3 commit 80ad3d0

23 files changed

+5424
-5724
lines changed

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,38 @@ as a simple LoRa® radio module.
2626

2727
* The module supports only class A.
2828
* Sleep mode is not supported in OTAA mode with the version 2.6 of the firmware.
29-
* The same USART is shared between I-NUCLEO-LRWAN1 LoRa® expansion board and
30-
Nucleo-64 boards. See UM1724, §6.8 section to solve the issue.
29+
* Important note for Nucleo64:
30+
31+
By default, D0/D1 of CN9 board connector are respectively not connected to
32+
PA3 and PA2 (SB62 and SB63 opened).
33+
Those pins are connected to STLink USART thanks to SB13, SB14.
34+
35+
To use the shield:
36+
- Connect shield D0(Tx) to PC11(Rx)
37+
- Connect shield D1(Rx) to PC10(Tx)
38+
39+
or
40+
41+
- Close SB62 and SB63 to connect D0/D1 of CN9 connector to PA3 and PA2
42+
- Open SB13 and SB14 to disconnect PA3 and PA2 from STLink UART
43+
44+
but in this case, you will have to wire STLink Rx/Tx of CN3 connector to
45+
another pins and update Serial instance before call `Serial.begin(115200);`
46+
using:
47+
```
48+
Serial.setRx(Rx pin);
49+
Serial.setTx(Tx pin);
50+
```
51+
52+
See [UM1724](https://www.st.com/resource/en/user_manual/dm00105823.pdf), §6.8 section for more information.
3153

3254
## Examples
3355

34-
* **getDevEUI**: display the unique device EUI.
56+
* **getInfo**: display several info about LoRa shield (Firmware version, device EUI,...)
3557
* **LoRaWANABP**: send/receive data in ABP mode.
3658
* **LoRaWANOTAA**: send/receive data in OTAA mode.
37-
* **LoRaPingPong**: P2P exchange in LoRa®
59+
* **LoRaPingPong**: P2P exchange in LoRa®.
60+
* **BridgeSerial**: Send/Receive AT command from/to PC terminal to/from shield (console mode).
3861

3962
## Advice
4063

@@ -51,7 +74,7 @@ to increase the delay time of the RX1 window.
5174
## Version
5275

5376
This library is based on the STM32CubeExpansion_LRWAN_V1.1.2 driver.
54-
This library has been validated with the version 2.6 of the firmware.
77+
This library has been validated with the version 2.6 and 3.6 of the firmware.
5578

5679
## Documentation
5780

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
Allows to relay UART data from/to a PC terminal to/from LORA shield.
3+
4+
Shield uses a LPUART interface as the AT command console, the D0 and D1 pin
5+
is the LPUART TX and LPUART RX, and the default configuration is 115200,N,8,1
6+
7+
Important note for Nucleo64:
8+
by default, D0/D1 of CN9 board connector are respectively not connected to
9+
PA3 and PA2 (SB62 and SB63 opened).
10+
Those pins are connected to STLink USART thanks to SB13, SB14.
11+
12+
To use the shield:
13+
- Connect shield D0(Tx) to PC11(Rx)
14+
- Connect shield D1(Rx) to PC10(Tx)
15+
or
16+
- Close SB62 and SB63 to connect D0/D1 of CN9 connector to PA3 and PA2
17+
- Open SB13 and SB14 to disconnect PA3 and PA2 from STLink UART
18+
but in this case, you will have to wire STLink Rx/Tx of CN3 connector to
19+
another pins and update Serial instance before call `Serial.begin(115200);`
20+
using:
21+
Serial.setRx(Rx pin);
22+
Serial.setTx(Tx pin);
23+
*/
24+
HardwareSerial SerialLora(D0, D1);
25+
26+
void setup()
27+
{
28+
Serial.begin(115200);
29+
SerialLora.begin(115200);
30+
}
31+
32+
// The loop function runs over and over again forever
33+
void loop()
34+
{
35+
char c;
36+
37+
if (SerialLora.available() > 0)
38+
{
39+
c = SerialLora.read();
40+
Serial.print(c);
41+
}
42+
if (Serial.available() > 0)
43+
{
44+
c = Serial.read();
45+
SerialLora.print(c);
46+
}
47+
}

examples/LoRaPingPong/LoRaPingPong.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
#define SEND_PERIOD_MS 1000 //send period every second.
1313

14-
// Serial port use to communicate with the USI shield. Specific to the board Discovery L475 IoT.
15-
HardwareSerial SerialLora(PA_1, PA_0);
14+
// Serial port use to communicate with the USI shield.
15+
// By default, use D0 (Rx) and D1(Tx).
16+
// For Nucleo64, see "Known limitations" chapter in the README.md
17+
HardwareSerial SerialLora(D0, D1);
1618

1719
// Messages to exchange
1820
uint8_t PingMsg[] = "PING";

examples/LoRaWANABP/LoRaWANABP.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
#define FRAME_DELAY 300000 // in ms. Every 5 minutes by default.
2222

23-
HardwareSerial SerialLora(PA_1, PA_0);
23+
// Serial port use to communicate with the USI shield.
24+
// By default, use D0 (Rx) and D1(Tx).
25+
// For Nucleo64, see "Known limitations" chapter in the README.md
26+
HardwareSerial SerialLora(D0, D1);
2427

2528
// Device address, network & application keys
2629
const char devAddr[] = "ef00cb01";

examples/LoRaWANOTAA/LoRaWANOTAA.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323

2424
#define FRAME_DELAY 300000 // in ms. Every 5 minutes by default.
2525

26-
// Serial port use to communicate with the USI shield. Specific to the board Discovery L475 IoT.
27-
HardwareSerial SerialLora(PA_1, PA_0);
26+
// Serial port use to communicate with the USI shield.
27+
// By default, use D0 (Rx) and D1(Tx).
28+
// For Nucleo64, see "Known limitations" chapter in the README.md
29+
HardwareSerial SerialLora(D0, D1);
2830

2931
// AppKey and AppEUI.
3032
const char appKey[] = "0123456789abcdef0123456789abcdef";
31-
const char appEUI[] = "abcdef0123456789abcdef0123456789";
33+
const char appEUI[] = "0101010101010101";
3234

3335
// Data send
3436
char frameTx[] = "Hello world!";

examples/getDevEUI/getDevEUI.ino

Lines changed: 0 additions & 36 deletions
This file was deleted.

examples/getInfo/getInfo.ino

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
getInfo.ino
3+
4+
Display several information about the module. The devEUI of the USI module
5+
can't be modified. It is useful to read it to configure the module in a
6+
LoRaWAN network when asked by the network server.
7+
*/
8+
9+
#include "LoRaWANNode.h"
10+
11+
// Serial port use to communicate with the USI shield.
12+
// By default, use D0 (Rx) and D1(Tx).
13+
HardwareSerial SerialLora(D0, D1);
14+
15+
void setup()
16+
{
17+
Serial.begin(115200);
18+
Serial.println("-- Get Info sketch --");
19+
20+
// Enable the USI module and set the radio band.
21+
while (!loraNode.begin(&SerialLora, LORA_BAND_EU_868)) {
22+
Serial.println("Lora module not ready");
23+
delay(1000);
24+
}
25+
26+
// Get the DevEUI
27+
String str = "Firmware version: ";
28+
loraNode.getFWVersion(&str);
29+
Serial.println(str);
30+
31+
str = "LoRa stack version: ";
32+
loraNode.getVersion(&str);
33+
Serial.println(str);
34+
35+
str = "Unique DevEUI: 0x";
36+
loraNode.getDevEUI(&str);
37+
Serial.println(str);
38+
39+
str = "Application EUI: 0x";
40+
loraNode.getAppEUI(&str);
41+
Serial.println(str);
42+
43+
str = "Application key: 0x";
44+
loraNode.getAppKey(&str);
45+
Serial.println(str);
46+
47+
str = "Network session Key: 0x";
48+
loraNode.getNwkSKey(&str);
49+
Serial.println(str);
50+
51+
str = "Application session key: 0x";
52+
loraNode.getAppSKey(&str);
53+
Serial.println(str);
54+
55+
str = "Device address: 0x";
56+
loraNode.getDevAddr(&str);
57+
Serial.println(str);
58+
}
59+
60+
void loop()
61+
{
62+
//empty loop
63+
}

src/LoRaRadio.cpp

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ LoraRadio::LoraRadio()
7171
bool LoraRadio::begin(HardwareSerial *serialx)
7272
{
7373
uint8_t nbTry = 0;
74+
uint8_t enable = 0;
7475

7576
if(serialx == NULL) {
7677
return false;
@@ -83,8 +84,14 @@ bool LoraRadio::begin(HardwareSerial *serialx)
8384

8485
LoRa_DumyRequest();
8586

86-
//Echo mode must be disabled
87-
Modem_AT_Cmd(AT_EXCEPT, AT_ATE, 0);
87+
// Local echo mode must be disabled
88+
Modem_AT_Cmd(AT_EXCEPT, AT_ATE, &enable);
89+
90+
// Verbose response must be enabled for the AT parser
91+
enable = 1;
92+
if (Modem_AT_Cmd(AT_EXCEPT, AT_VERB, &enable) != AT_OK) {
93+
AT_VERB_cmd = false;
94+
}
8895

8996
// Enable Lora module
9097
/*
@@ -410,55 +417,55 @@ uint8_t LoraRadio::parseRcvData(void *pdata)
410417
return AT_END_ERROR;
411418
}
412419

413-
/*cleanup the response buffer*/
420+
// Cleanup the response buffer
414421
memset(response, 0x00, DATA_RX_MAX_BUFF_SIZE);
415422

416-
while (!ResponseComplete)
417-
{
423+
while (!ResponseComplete) {
418424
msStart = millis();
419-
while (HW_UART_Modem_IsNewCharReceived() == RESET) {
425+
while (!HW_UART_Modem_IsNewCharReceived()) {
420426
if((millis() - msStart) > RESPONSE_TIMEOUT) {
421427
return AT_UART_LINK_ERROR;
422428
}
423429
}
424430

425-
/*process the response*/
431+
// Process the response
426432
response[i] = HW_UART_Modem_GetNewChar();
427433

428-
/*wait up to carriage return OR the line feed marker*/
429-
if (/*(response[i] =='\r') || */(response[i] == '\n'))
430-
{
434+
// Wait up to carriage return OR the line feed marker
435+
if (/*(response[i] =='\r') || */(response[i] == '\n')) {
431436
DBG_PRINTF("LoRa radio rcv: %s\r\n", response);
432437

433-
if (i!= 0) /*trap the asynchronous event*/
434-
{
435-
/*first statement to get back the return value*/
438+
if (i!= 0) { // Trap the asynchronous event
439+
// First statement to get back the return value
436440
response[i] = '\0';
437-
ptrChr = strchr(&response[0],'+'); /*to skip the '\0''\r'*/
438-
if (strncmp(ptrChr, "+RCV:", sizeof("+RCV:")-1) == 0) {
441+
ptrChr = strchr(&response[0],'+'); // Skip the '\0''\r'
442+
if (strncmp(ptrChr, "+RCV", sizeof("+RCV")-1) == 0) {
439443
RetCode = AT_OK;
440-
ptrChr = strchr(&response[1],':'); /*to skip the '\0''\r'*/
441-
strcpy((char *)pdata,ptrChr+2);
444+
if(AT_VERB_cmd) {
445+
ptrChr = strrchr(&response[1], ',');
446+
strcpy((char *)pdata, ptrChr+1);
447+
} else {
448+
ptrChr = strchr(&response[1],':');
449+
strcpy((char *)pdata, ptrChr+2);
450+
}
442451
ResponseComplete = 1;
443452
} else {
444453
RetCode = AT_END_ERROR;
445454
}
446455
memset(response, 0x00, 16);
447-
i= -1; /*to compensate the next index iteration and restart in [0]*/
456+
i= -1; // Compensate the next index iteration and restart in [0]
448457
}
449-
}
450-
else
451-
{
452-
if (i == (DATA_RX_MAX_BUFF_SIZE-1)) /* frame overflow */
453-
{
458+
} else {
459+
if (i == (DATA_RX_MAX_BUFF_SIZE-1)) {
460+
// Frame overflow
454461
i = 0;
455462
return (AT_TEST_PARAM_OVERFLOW);
456463
}
457464
}
458465
i++;
459466
}
460467

461-
return ( RetCode); /*version of HAL .. there was not Rx field state*/
468+
return RetCode;
462469
}
463470

464471
LoraRadio loraRadio;

src/LoRaRadio.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ class LoraRadio {
9090

9191
LoraRadio();
9292

93-
bool begin(HardwareSerial *serialx); //begin initialization function
93+
// Begin initialization function
94+
bool begin(HardwareSerial *serialx);
9495
void end(void);
9596

9697
bool setFrequency(uint32_t freq);

0 commit comments

Comments
 (0)