Skip to content

Commit 127053a

Browse files
authored
Merge branch 'release_candidate' into rtk-reset
2 parents 7daa04e + 0b29f7a commit 127053a

21 files changed

+2151
-1787
lines changed

.github/workflows/compile-rtk-firmware.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
env:
77
FILENAME_PREFIX: RTK_Surveyor_Firmware
88
FIRMWARE_VERSION_MAJOR: 3
9-
FIRMWARE_VERSION_MINOR: 4
9+
FIRMWARE_VERSION_MINOR: 5
1010
POINTPERFECT_TOKEN: ${{ secrets.POINTPERFECT_TOKEN }}
1111

1212
jobs:
@@ -126,7 +126,7 @@ jobs:
126126
github_token: ${{ secrets.GITHUB_TOKEN }}
127127
directory: ./Firmware/RTK_Surveyor
128128
branch: ${{ env.BRANCH }}
129-
message: 'Update form.h via Python ${date}'
129+
message: 'Update form.h via Python'
130130

131131
- name: Copy custom app3M_fat9M_16MB.csv
132132
run:

Firmware/RTK_Surveyor/Begin.ino

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,15 @@ void beginUART2()
557557
2000, // Stack Size
558558
nullptr, // Task input parameter
559559
0, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest
560-
&pinUART2TaskHandle, // Task handle
561-
0); // Core where task should run, 0=core, 1=Arduino
560+
&pinUART2TaskHandle, // Task handle
561+
settings.gnssUartInterruptsCore); // Core where task should run, 0=core, 1=Arduino
562562

563563
while (uart2pinned == false) // Wait for task to run once
564564
delay(1);
565565
}
566566

567-
// Assign UART2 interrupts to the core 0. See: https://github.com/espressif/arduino-esp32/issues/3386
567+
// Assign UART2 interrupts to the core that started the task. See:
568+
// https://github.com/espressif/arduino-esp32/issues/3386
568569
void pinUART2Task(void *pvParameters)
569570
{
570571
// Note: ESP32 2.0.6 does some strange auto-bauding thing here which takes 20s to complete if there is no data for
@@ -586,7 +587,7 @@ void pinUART2Task(void *pvParameters)
586587
// Reduce threshold value above which RX FIFO full interrupt is generated
587588
// Allows more time between when the UART interrupt occurs and when the FIFO buffer overruns
588589
// serialGNSS.setRxFIFOFull(50); //Available in >v2.0.5
589-
uart_set_rx_full_threshold(2, 50); // uart_num, threshold
590+
uart_set_rx_full_threshold(2, settings.serialGNSSRxFullThreshold); // uart_num, threshold
590591
}
591592

592593
uart2pinned = true;
@@ -1150,7 +1151,24 @@ void beginIdleTasks()
11501151

11511152
void beginI2C()
11521153
{
1153-
Wire.begin(); // Start I2C on core 1
1154+
if (pinI2CTaskHandle == nullptr)
1155+
xTaskCreatePinnedToCore(
1156+
pinI2CTask,
1157+
"I2CStart", // Just for humans
1158+
2000, // Stack Size
1159+
nullptr, // Task input parameter
1160+
0, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the lowest
1161+
&pinI2CTaskHandle, // Task handle
1162+
settings.i2cInterruptsCore); // Core where task should run, 0=core, 1=Arduino
1163+
1164+
while (i2cPinned == false) // Wait for task to run once
1165+
delay(1);
1166+
}
1167+
1168+
// Assign I2C interrupts to the core that started the task. See: https://github.com/espressif/arduino-esp32/issues/3386
1169+
void pinI2CTask(void *pvParameters)
1170+
{
1171+
Wire.begin(); // Start I2C on core the core that was chosen when the task was started
11541172
// Wire.setClock(400000);
11551173

11561174
// begin/end wire transmission to see if bus is responding correctly
@@ -1166,6 +1184,10 @@ void beginI2C()
11661184
online.i2c = true;
11671185
else
11681186
systemPrintln("Error: I2C Bus Not Responding");
1187+
1188+
i2cPinned = true;
1189+
1190+
vTaskDelete(nullptr); // Delete task once it has run once
11691191
}
11701192

11711193
// Depending on radio selection, begin hardware

Firmware/RTK_Surveyor/Bluetooth.ino

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ void bluetoothStart()
166166
else if (settings.bluetoothRadioType == BLUETOOTH_RADIO_BLE)
167167
bluetoothSerial = new BTLESerial();
168168

169+
// Not yet implemented
170+
// if (pinBluetoothTaskHandle == nullptr)
171+
// xTaskCreatePinnedToCore(
172+
// pinBluetoothTask,
173+
// "BluetoothStart", // Just for humans
174+
// 2000, // Stack Size
175+
// nullptr, // Task input parameter
176+
// 0, // Priority, with 3 (configMAX_PRIORITIES - 1) being the highest, and 0 being the
177+
// lowest &pinBluetoothTaskHandle, // Task handle settings.bluetoothInterruptsCore); //
178+
// Core where task should run, 0=core, 1=Arduino
179+
180+
// while (bluetoothPinned == false) // Wait for task to run once
181+
// delay(1);
182+
169183
if (bluetoothSerial->begin(deviceName) == false)
170184
{
171185
systemPrintln("An error occurred initializing Bluetooth");
@@ -216,6 +230,25 @@ void bluetoothStart()
216230
#endif // COMPILE_BT
217231
}
218232

233+
// Assign Bluetooth interrupts to the core that started the task. See:
234+
// https://github.com/espressif/arduino-esp32/issues/3386
235+
void pinBluetoothTask(void *pvParameters)
236+
{
237+
#ifdef COMPILE_BT
238+
if (bluetoothSerial->begin(deviceName) == false)
239+
{
240+
systemPrintln("An error occurred initializing Bluetooth");
241+
242+
if (productVariant == RTK_SURVEYOR)
243+
digitalWrite(pin_bluetoothStatusLED, LOW);
244+
}
245+
246+
bluetoothPinned = true;
247+
248+
vTaskDelete(nullptr); // Delete task once it has run once
249+
#endif // COMPILE_BT
250+
}
251+
219252
// This function stops BT so that it can be restarted later
220253
// It also releases as much system resources as possible so that WiFi/caster is more stable
221254
void bluetoothStop()
@@ -227,7 +260,7 @@ void bluetoothStop()
227260
bluetoothSerial->flush(); // Complete any transfers
228261
bluetoothSerial->disconnect(); // Drop any clients
229262
bluetoothSerial->end(); // bluetoothSerial->end() will release significant RAM (~100k!) but a
230-
// bluetoothSerial->start will crash.
263+
// bluetoothSerial->start will crash.
231264

232265
log_d("Bluetooth turned off");
233266

Firmware/RTK_Surveyor/NVM.ino

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,16 @@ void recordSystemSettingsToFile(File *settingsFile)
413413
}
414414

415415
settingsFile->printf("%s=%d\r\n", "mdnsEnable", settings.mdnsEnable);
416+
settingsFile->printf("%s=%d\r\n", "serialGNSSRxFullThreshold", settings.serialGNSSRxFullThreshold);
417+
settingsFile->printf("%s=%d\r\n", "btReadTaskPriority", settings.btReadTaskPriority);
418+
settingsFile->printf("%s=%d\r\n", "gnssReadTaskPriority", settings.gnssReadTaskPriority);
419+
settingsFile->printf("%s=%d\r\n", "handleGnssDataTaskPriority", settings.handleGnssDataTaskPriority);
420+
settingsFile->printf("%s=%d\r\n", "btReadTaskCore", settings.btReadTaskCore);
421+
settingsFile->printf("%s=%d\r\n", "gnssReadTaskCore", settings.gnssReadTaskCore);
422+
settingsFile->printf("%s=%d\r\n", "handleGnssDataTaskCore", settings.handleGnssDataTaskCore);
423+
settingsFile->printf("%s=%d\r\n", "gnssUartInterruptsCore", settings.gnssUartInterruptsCore);
424+
settingsFile->printf("%s=%d\r\n", "bluetoothInterruptsCore", settings.bluetoothInterruptsCore);
425+
settingsFile->printf("%s=%d\r\n", "i2cInterruptsCore", settings.i2cInterruptsCore);
416426
}
417427

418428
// Given a fileName, parse the file and load the given settings struct
@@ -733,8 +743,7 @@ bool parseLine(char *str, Settings *settings)
733743

734744
// Check to see if this setting file is compatible with this version of RTK Surveyor
735745
if (d != sizeof(Settings))
736-
systemPrintf("Warning: Settings size is %d but current firmware expects %d. Attempting to use settings "
737-
"from file.\r\n",
746+
log_d("Settings size is %d but current firmware expects %d. Attempting to use settings from file.",
738747
(int)d, sizeof(Settings));
739748
}
740749

@@ -1275,6 +1284,26 @@ bool parseLine(char *str, Settings *settings)
12751284
}
12761285
else if (strcmp(settingName, "mdnsEnable") == 0)
12771286
settings->mdnsEnable = d;
1287+
else if (strcmp(settingName, "serialGNSSRxFullThreshold") == 0)
1288+
settings->serialGNSSRxFullThreshold = d;
1289+
else if (strcmp(settingName, "btReadTaskPriority") == 0)
1290+
settings->btReadTaskPriority = d;
1291+
else if (strcmp(settingName, "gnssReadTaskPriority") == 0)
1292+
settings->gnssReadTaskPriority = d;
1293+
else if (strcmp(settingName, "handleGnssDataTaskPriority") == 0)
1294+
settings->handleGnssDataTaskPriority = d;
1295+
else if (strcmp(settingName, "btReadTaskCore") == 0)
1296+
settings->btReadTaskCore = d;
1297+
else if (strcmp(settingName, "gnssReadTaskCore") == 0)
1298+
settings->gnssReadTaskCore = d;
1299+
else if (strcmp(settingName, "handleGnssDataTaskCore") == 0)
1300+
settings->handleGnssDataTaskCore = d;
1301+
else if (strcmp(settingName, "gnssUartInterruptsCore") == 0)
1302+
settings->gnssUartInterruptsCore = d;
1303+
else if (strcmp(settingName, "bluetoothInterruptsCore") == 0)
1304+
settings->bluetoothInterruptsCore = d;
1305+
else if (strcmp(settingName, "i2cInterruptsCore") == 0)
1306+
settings->i2cInterruptsCore = d;
12781307

12791308
// Check for bulk settings (WiFi credentials, constellations, message rates, ESPNOW Peers)
12801309
// Must be last on else list
@@ -1456,7 +1485,7 @@ void loadProfileNumber()
14561485
File fileProfileNumber = LittleFS.open("/profileNumber.txt", FILE_READ);
14571486
if (!fileProfileNumber)
14581487
{
1459-
systemPrintln("profileNumber.txt not found");
1488+
log_d("profileNumber.txt not found");
14601489
settings.updateZEDSettings = true; // Force module update
14611490
recordProfileNumber(0); // Record profile
14621491
}
@@ -1469,7 +1498,7 @@ void loadProfileNumber()
14691498
// We have arbitrary limit of user profiles
14701499
if (profileNumber >= MAX_PROFILE_COUNT)
14711500
{
1472-
systemPrintln("ProfileNumber invalid. Going to zero.");
1501+
log_d("ProfileNumber invalid. Going to zero.");
14731502
settings.updateZEDSettings = true; // Force module update
14741503
recordProfileNumber(0); // Record profile
14751504
}

Firmware/RTK_Surveyor/NtripClient.ino

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,9 @@ bool ntripClientConnectLimitReached()
169169
ntripClientStop(false); // Allocate new wifiClient
170170

171171
// Retry the connection a few times
172-
bool limitReached = false;
173-
if (ntripClientConnectionAttempts++ >= MAX_NTRIP_CLIENT_CONNECTION_ATTEMPTS)
174-
limitReached = true;
172+
bool limitReached = (ntripClientConnectionAttempts >= MAX_NTRIP_CLIENT_CONNECTION_ATTEMPTS);
175173

174+
ntripClientConnectionAttempts++;
176175
ntripClientConnectionAttemptsTotal++;
177176

178177
if (limitReached == false)
@@ -434,6 +433,12 @@ void ntripClientUpdate()
434433
else
435434
{
436435
// Wait for ethernet to connect
436+
static unsigned long lastDebug = millis();
437+
if (millis() > (lastDebug + 5000))
438+
{
439+
lastDebug = millis();
440+
log_d("NTRIP Client: Ethernet not connected. Waiting to retry.");
441+
}
437442
}
438443
}
439444
else

Firmware/RTK_Surveyor/NtripServer.ino

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,24 @@ bool ntripServerConnectLimitReached()
130130
ntripServerStop(false); // Allocate new wifiClient
131131

132132
// Retry the connection a few times
133-
bool limitReached = false;
134-
if (ntripServerConnectionAttempts++ >= MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS)
135-
limitReached = true;
133+
bool limitReached = (ntripServerConnectionAttempts >= MAX_NTRIP_SERVER_CONNECTION_ATTEMPTS);
136134

135+
ntripServerConnectionAttempts++;
137136
ntripServerConnectionAttemptsTotal++;
138137

139138
if (limitReached == false)
140139
{
141-
ntripServerConnectionAttemptTimeout =
142-
ntripServerConnectionAttempts * 5 * 60 * 1000L; // Wait 5, 10, 15, etc minutes between attempts
140+
if (ntripServerConnectionAttempts == 1)
141+
ntripServerConnectionAttemptTimeout = 15 * 1000L; // Wait 15s
142+
else if (ntripServerConnectionAttempts == 2)
143+
ntripServerConnectionAttemptTimeout = 30 * 1000L; // Wait 30s
144+
else if (ntripServerConnectionAttempts == 3)
145+
ntripServerConnectionAttemptTimeout = 1 * 60 * 1000L; // Wait 1 minute
146+
else if (ntripServerConnectionAttempts == 4)
147+
ntripServerConnectionAttemptTimeout = 2 * 60 * 1000L; // Wait 2 minutes
148+
else
149+
ntripServerConnectionAttemptTimeout =
150+
(ntripServerConnectionAttempts - 4) * 5 * 60 * 1000L; // Wait 5, 10, 15, etc minutes between attempts
143151

144152
reportHeapNow();
145153
}
@@ -419,8 +427,18 @@ void ntripServerUpdate()
419427
{
420428
if (online.ethernetStatus == ETH_CONNECTED)
421429
ntripServerSetState(NTRIP_SERVER_WIFI_ETHERNET_CONNECTED);
422-
else
430+
else if (online.ethernetStatus == ETH_CAN_NOT_BEGIN) // Ethernet hardware failure or not available
423431
ntripServerSetState(NTRIP_SERVER_OFF);
432+
else
433+
{
434+
// Wait for ethernet to connect
435+
static unsigned long lastDebug = millis();
436+
if (millis() > (lastDebug + 5000))
437+
{
438+
lastDebug = millis();
439+
log_d("NTRIP Server: Ethernet not connected. Waiting to retry.");
440+
}
441+
}
424442
}
425443
else
426444
{
@@ -456,18 +474,20 @@ void ntripServerUpdate()
456474
// Attempt a connection to the NTRIP caster
457475
if (!ntripServerConnectCaster())
458476
{
459-
if (ntripServerConnectionAttemptTimeout / 1000 < 120)
460-
systemPrintf("NTRIP Server failed to connect to caster. Trying again in %d seconds.\r\n",
461-
ntripServerConnectionAttemptTimeout / 1000);
462-
else
463-
systemPrintf("NTRIP Server failed to connect to caster. Trying again in %d minutes.\r\n",
464-
ntripServerConnectionAttemptTimeout / 1000 / 60);
465-
466477
// Assume service not available
467-
if (ntripServerConnectLimitReached())
478+
if (ntripServerConnectLimitReached()) // Update ntripServerConnectionAttemptTimeout
468479
{
469480
systemPrintln("NTRIP Server failed to connect! Do you have your caster address and port correct?");
470481
}
482+
else
483+
{
484+
if (ntripServerConnectionAttemptTimeout / 1000 < 120)
485+
systemPrintf("NTRIP Server failed to connect to caster. Trying again in %d seconds.\r\n",
486+
ntripServerConnectionAttemptTimeout / 1000);
487+
else
488+
systemPrintf("NTRIP Server failed to connect to caster. Trying again in %d minutes.\r\n",
489+
ntripServerConnectionAttemptTimeout / 1000 / 60);
490+
}
471491
}
472492
else
473493
{

Firmware/RTK_Surveyor/RTK_Surveyor.ino

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
The RTK Surveyor implements classic Bluetooth SPP to transfer data from the
1616
ZED-F9P to the phone and receive any RTCM from the phone and feed it back
17-
to the ZED-F9P to achieve RTK: F9PSerialWriteTask(), F9PSerialReadTask().
17+
to the ZED-F9P to achieve RTK: btReadTask(), gnssReadTask().
1818
1919
Settings are loaded from microSD if available otherwise settings are pulled from ESP32's file system LittleFS.
2020
*/
@@ -123,8 +123,8 @@ char profileNames[MAX_PROFILE_COUNT][50]; // Populated based on names found in
123123
char settingsFileName[60]; // Contains the %s_Settings_%d.txt with current profile number set
124124

125125
char stationCoordinateECEFFileName[60]; // Contains the /StationCoordinates-ECEF_%d.csv with current profile number set
126-
char stationCoordinateGeodeticFileName[60]; // Contains the /StationCoordinates-Geodetic_%d.csv with current profile
127-
// number set
126+
char stationCoordinateGeodeticFileName[60]; // Contains the /StationCoordinates-Geodetic_%d.csv with current profile
127+
// number set
128128
const int COMMON_COORDINATES_MAX_STATIONS = 50; // Record upto 50 ECEF and Geodetic commonly used stations
129129
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
130130

@@ -252,7 +252,8 @@ char neoFirmwareVersion[20]; // Output to system status menu.
252252
uint8_t zedFirmwareVersionInt = 0; // Controls which features (constellations) can be configured (v1.12 doesn't support
253253
// SBAS). Note: will fail above 2.55!
254254
uint8_t zedModuleType = PLATFORM_F9P; // Controls which messages are supported and configured
255-
char zedUniqueId[11] = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 0 }; // Output to system status menu and log file.
255+
char zedUniqueId[11] = {'0', '0', '0', '0', '0', '0',
256+
'0', '0', '0', '0', 0}; // Output to system status menu and log file.
256257

257258
// Use Michael's lock/unlock methods to prevent the UART2 task from calling checkUblox during a sendCommand and
258259
// waitForResponse. Also prevents pushRawData from being called too.
@@ -263,7 +264,7 @@ class SFE_UBLOX_GNSS_SUPER_DERIVED : public SFE_UBLOX_GNSS_SUPER
263264

264265
// Revert to a simple bool lock. The Mutex was causing occasional panics caused by
265266
// vTaskPriorityDisinheritAfterTimeout in lock() (I think possibly / probably caused by the GNSS not being pinned to
266-
//one core?
267+
// one core?
267268
bool iAmLocked = false;
268269

269270
bool createLock(void)
@@ -391,25 +392,28 @@ HardwareSerial serialGNSS(2); // TX on 17, RX on 16
391392

392393
#define SERIAL_SIZE_TX 512
393394
uint8_t wBuffer[SERIAL_SIZE_TX]; // Buffer for writing from incoming SPP to F9P
394-
TaskHandle_t F9PSerialWriteTaskHandle =
395+
TaskHandle_t btReadTaskHandle =
395396
nullptr; // Store handles so that we can kill them if user goes into WiFi NTRIP Server mode
396-
const uint8_t F9PSerialWriteTaskPriority = 1; // 3 being the highest, and 0 being the lowest
397-
const int writeTaskStackSize = 2000;
397+
const int btReadTaskStackSize = 2000;
398398

399399
uint8_t *ringBuffer; // Buffer for reading from F9P. At 230400bps, 23040 bytes/s. If SD blocks for 250ms, we need 23040
400400
// * 0.25 = 5760 bytes worst case.
401-
TaskHandle_t F9PSerialReadTaskHandle =
401+
TaskHandle_t gnssReadTaskHandle =
402402
nullptr; // Store handles so that we can kill them if user goes into WiFi NTRIP Server mode
403-
const uint8_t F9PSerialReadTaskPriority = 1; // 3 being the highest, and 0 being the lowest
404-
const int readTaskStackSize = 2000;
403+
const int gnssReadTaskStackSize = 2500;
405404

406-
TaskHandle_t handleGNSSDataTaskHandle = nullptr;
407-
const uint8_t handleGNSSDataTaskPriority = 1; // 3 being the highest, and 0 being the lowest
408-
const int handleGNSSDataTaskStackSize = 3000;
405+
TaskHandle_t handleGnssDataTaskHandle = nullptr;
406+
const int handleGnssDataTaskStackSize = 3000;
409407

410-
TaskHandle_t pinUART2TaskHandle = nullptr; // Dummy task to start UART2 on core 0.
408+
TaskHandle_t pinUART2TaskHandle = nullptr; // Dummy task to start hardware on an assigned core
411409
volatile bool uart2pinned = false; // This variable is touched by core 0 but checked by core 1. Must be volatile.
412410

411+
TaskHandle_t pinI2CTaskHandle = nullptr; // Dummy task to start hardware on an assigned core
412+
volatile bool i2cPinned = false; // This variable is touched by core 0 but checked by core 1. Must be volatile.
413+
414+
TaskHandle_t pinBluetoothTaskHandle = nullptr; // Dummy task to start hardware on an assigned core
415+
volatile bool bluetoothPinned = false; // This variable is touched by core 0 but checked by core 1. Must be volatile.
416+
413417
volatile static int combinedSpaceRemaining = 0; // Overrun indicator
414418
volatile static long fileSize = 0; // Updated with each write
415419
int bufferOverruns = 0; // Running count of possible data losses since power-on

0 commit comments

Comments
 (0)