Skip to content

Commit ba40f59

Browse files
committed
MCU8MASS-1721 Fix a bug where the hardware config would prevent PSM
1 parent 8b09e9c commit ba40f59

File tree

4 files changed

+57
-23
lines changed

4 files changed

+57
-23
lines changed

src/low_power.cpp

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,27 @@
1010
#include <avr/io.h>
1111
#include <avr/sleep.h>
1212

13-
#define AT_COMMAND_DISABLE_EDRX "AT+SQNEDRX=0"
14-
#define AT_COMMAND_ENABLE_PSM "AT+CPSMS=1,,,\"%s\",\"%s\""
15-
#define AT_COMMAND_DISABLE_PSM "AT+CPSMS=0"
16-
#define AT_COMMAND_SET_RING_BEHAVIOUR "AT+SQNRICFG=1,2,1000"
17-
#define AT_COMMAND_CONNECTION_STATUS "AT+CEREG?"
18-
19-
// For use of the rest of library, for example low power
20-
#define RESPONSE_CONNECTION_STATUS_SIZE 70
13+
#define AT_COMMAND_DISABLE_EDRX "AT+SQNEDRX=0"
14+
#define AT_COMMAND_ENABLE_PSM "AT+CPSMS=1,,,\"%s\",\"%s\""
15+
#define AT_COMMAND_DISABLE_PSM "AT+CPSMS=0"
16+
#define AT_COMMAND_SET_RING_BEHAVIOUR "AT+SQNRICFG=1,2,1000"
17+
#define AT_COMMAND_CONNECTION_STATUS "AT+CEREG?"
18+
#define AT_COMMAND_SET_RTS0_HIGH_TRIGGERS_SLEEP "AT+SQNIPSCFG=1,1000"
19+
20+
#define AT_COMMAND_ENTER_MANUFACTURING_MODE "AT+CFUN=5"
21+
#define AT_COMMAND_DISABLE_WAKE_ON_RTS1 "AT+SQNHWCFG=\"wakeRTS1\",\"disable\""
22+
#define AT_COMMAND_DISABLE_WAKE_ON_SIM0 "AT+SQNHWCFG=\"wakeSim0\",\"disable\""
23+
#define AT_COMMAND_DISABLE_WAKE_ON_WAKE0 "AT+SQNHWCFG=\"wake0\",\"disable\""
24+
#define AT_COMMAND_DISABLE_WAKE_ON_WAKE1 "AT+SQNHWCFG=\"wake1\",\"disable\""
25+
#define AT_COMMAND_DISABLE_WAKE_ON_WAKE2 "AT+SQNHWCFG=\"wake2\",\"disable\""
26+
#define AT_COMMAND_DISABLE_WAKE_ON_WAKE3 "AT+SQNHWCFG=\"wake3\",\"disable\""
27+
#define AT_COMMAND_DISABLE_WAKE_ON_WAKE4 "AT+SQNHWCFG=\"wake4\",\"disable\""
28+
#define AT_COMMAND_DISABLE_UART1 "AT+SQNHWCFG=\"uart1\",\"disable\""
29+
#define AT_COMMAND_DISABLE_UART2 "AT+SQNHWCFG=\"uart2\",\"disable\""
30+
31+
#define AT_RESET "AT^RESET"
32+
33+
#define RESPONSE_CONNECTION_STATUS_SIZE 96
2134

2235
// Command without arguments: 18 bytes
2336
// Both arguments within the quotes are strings of 8 numbers: 8 * 2 = 16 bytes
@@ -55,7 +68,7 @@
5568

5669
#ifdef __AVR_AVR128DB48__ // MINI
5770

58-
#define RING_PORT VPORTC
71+
#define RING_PORT PORTC
5972
#define RING_PIN_bm PIN6_bm
6073

6174
#define LOWQ_PIN PIN_PB4
@@ -66,7 +79,7 @@
6679

6780
#ifdef __AVR_AVR128DB64__ // Non-Mini
6881

69-
#define RING_PORT VPORTC
82+
#define RING_PORT PORTC
7083
#define RING_PIN_bm PIN4_bm
7184

7285
#define LOWQ_PIN PIN_PB4
@@ -242,11 +255,10 @@ static uint32_t retrieveOperatorSleepTime(void) {
242255

243256
// First we call CEREG in order to get the byte where the sleep time is
244257
// encoded
245-
SequansController.clearReceiveBuffer();
246-
SequansController.writeCommand(AT_COMMAND_CONNECTION_STATUS);
247-
248258
char response[RESPONSE_CONNECTION_STATUS_SIZE] = "";
249-
const ResponseResult response_result = SequansController.readResponse(
259+
SequansController.clearReceiveBuffer();
260+
const ResponseResult response_result = SequansController.writeCommand(
261+
AT_COMMAND_CONNECTION_STATUS,
250262
response,
251263
RESPONSE_CONNECTION_STATUS_SIZE);
252264

@@ -658,6 +670,33 @@ void LowPowerClass::configurePeriodicPowerSave(
658670
SequansController.begin();
659671
}
660672

673+
// First we need to enter manufactoring mode to disable wake up sources
674+
SequansController.writeCommand(AT_COMMAND_ENTER_MANUFACTURING_MODE);
675+
676+
// Disable all the wake sources except RTS0 (which is on by default)
677+
SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_RTS1);
678+
SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_SIM0);
679+
SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE0);
680+
SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE1);
681+
SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE2);
682+
SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE3);
683+
SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE4);
684+
685+
// Disable the other UARTs on the modem in case the message buffers
686+
// within these UARTs prevent the modem to sleep
687+
SequansController.writeCommand(AT_COMMAND_DISABLE_UART1);
688+
SequansController.writeCommand(AT_COMMAND_DISABLE_UART2);
689+
690+
// Now we need to issue a reset to get back into regular mode
691+
SequansController.writeCommand(AT_RESET);
692+
693+
// Wait for the modem to boot again
694+
SequansController.waitForURC("SYSSTART");
695+
696+
// Set device to sleep when RTS0 is pulled high. By default the modem will
697+
// sleep if RTS0, RTS1 and RTS2 are pulled high, so we want to change that
698+
SequansController.writeCommand(AT_COMMAND_SET_RTS0_HIGH_TRIGGERS_SLEEP);
699+
661700
// Disable EDRX as we use PSM
662701
SequansController.writeCommand(AT_COMMAND_DISABLE_EDRX);
663702

@@ -722,7 +761,7 @@ void LowPowerClass::powerSave(void) {
722761
}
723762
}
724763

725-
if (!attemptToEnterPowerSaveModeForModem(30000)) {
764+
if (!attemptToEnterPowerSaveModeForModem(45000)) {
726765
Log.error(
727766
"Failed to put cellular modem in sleep. Power save functionality "
728767
"might not be available for your operator.");

src/lte.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ bool LteClass::begin(const uint32_t timeout_ms, const bool print_messages) {
126126

127127
// Wait for CEREG URC before checking SIM
128128
SequansController.waitForURC(CEREG_CALLBACK);
129+
SequansController.registerCallback(CEREG_CALLBACK, connectionStatus, false);
129130

130131
// We check that the SIM card is inserted and ready. Note that we can only
131132
// do this and get a meaningful response in CFUN=1 or CFUN=4.
@@ -157,8 +158,6 @@ bool LteClass::begin(const uint32_t timeout_ms, const bool print_messages) {
157158
return false;
158159
}
159160

160-
SequansController.registerCallback(CEREG_CALLBACK, connectionStatus, false);
161-
162161
if (print_messages) {
163162
Log.infof("Connecting to operator");
164163
}

src/mqtt_client.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ bool MqttClientClass::begin(const char* client_id,
425425
MQTT_TLS_ECC_SECURITY_PROFILE_ID)) {
426426
Log.error("Security profile not set up for MQTT TLS with ECC. "
427427
"Run the 'provision' example Arduino sketch to set "
428-
"this up.");
428+
"this up for a custom broker or use the iotprovision "
429+
"tool to set this up for AWS.");
429430
return false;
430431
}
431432

test/test_examples.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import pytest
2-
import argparse
3-
import textwrap
4-
import glob
52
import os
6-
import json
73
import serial
8-
import time
94
import subprocess
105
import re
116

0 commit comments

Comments
 (0)