diff --git a/Firmware/RTK_Surveyor/Tasks.ino b/Firmware/RTK_Surveyor/Tasks.ino index 870a4dbf1..3bbe79a20 100644 --- a/Firmware/RTK_Surveyor/Tasks.ino +++ b/Firmware/RTK_Surveyor/Tasks.ino @@ -1285,7 +1285,7 @@ void sdSizeCheckTask(void *e) sdCardSize = SD_MMC.cardSize(); sdFreeSpace = SD_MMC.totalBytes() - SD_MMC.usedBytes(); } -#endif // COMPILE_SD_MMC +#endif // COMPILE_SD_MMC xSemaphoreGive(sdCardSemaphore); diff --git a/Firmware/Tools/RTK_Reset.c b/Firmware/Tools/RTK_Reset.c new file mode 100644 index 000000000..324e0ae89 --- /dev/null +++ b/Firmware/Tools/RTK_Reset.c @@ -0,0 +1,154 @@ +//------------------------------------------------------------------------------ +// Lee Leahy +// 12 June 2023 +// +// Program to reset the ESP32 +//------------------------------------------------------------------------------ +// +// Starting from the SparkFun RTK Surveyor +// +// https://www.sparkfun.com/products/18443 +// +// Schematic +// +// https://cdn.sparkfun.com/assets/c/1/b/d/8/SparkFun_RTK_Surveyor-v13.pdf +// +// ___ ___ GPIO-0 PU +// DTR RTS BOOT EN +// 0 0 1 1 Run flash code +// 0 1 0 1 Download code, write to flash +// 1 0 1 0 Power off +// 1 1 0 0 Power off +// +// To the ESP-WROOM-32 datasheet +// +// https://www.espressif.com/sites/default/files/documentation/esp32-wroom-32_datasheet_en.pdf +// +// To the ESP-32 Series datasheet +// +// https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf +// +// PU - 0: Power off, 1: Power on/up +// +// GPIO-O: Saved at power up, 0 = download image, 1 = boot from flash +// +//------------------------------------------------------------------------------ + +#define MICROSECONDS 1 +#define MILLISECONDS (1000 * MICROSECONDS) +#define POWER_OFF_DELAY (250 * MILLISECONDS) + +#include +#include +#include +#include +#include +#include + +const int dtrPin = TIOCM_DTR; +const int rtsPin = TIOCM_RTS; + +// GPIO-0 PU +// DTR RTS BOOT EN +// 1 1 1 1 Run flash code +// 1 0 0 1 Download code, write to flash +// 0 1 1 0 Power off +// 0 0 0 0 Power off + +int bootFromFlash(int serialPort) +{ + int status; + + status = ioctl(serialPort, TIOCMBIS, &rtsPin); + if (status) + fprintf(stderr, "ERROR: Failed to select the boot from flash\n"); + return status; +} + +int downloadImage(int serialPort) +{ + int status; + + status = ioctl(serialPort, TIOCMBIC, &rtsPin); + if (status) + fprintf(stderr, "ERROR: Failed to select download image\n"); + return status; +} + +int powerOff(int serialPort) +{ + int status; + + status = ioctl(serialPort, TIOCMBIC, &dtrPin); + if (status) + fprintf(stderr, "ERROR: Failed to power off the ESP-32\n"); + return status; +} + +int powerOn(int serialPort) +{ + int status; + + status = ioctl(serialPort, TIOCMBIS, &dtrPin); + if (status) + fprintf(stderr, "ERROR: Failed to power on the ESP-32\n"); + return status; +} + +int main (int argc, const char ** argv) +{ + struct termios params; + int serialPort; + const char * serialPortName; + int status; + + serialPort = -1; + status = 0; + do + { + // Display the help if necessary + if (argc != 2) + { + status = -1; + printf("%s serial_port\n", argv[0]); + break; + } + + // Open the serial port + serialPortName = argv[1]; + serialPort = open (serialPortName, O_RDWR); + if (serialPort < 0) + { + status = errno; + perror ("ERROR: Failed to open the terminal"); + break; + } + + // Get the terminal attributes + if (tcgetattr(serialPort, ¶ms) != 0) + { + status = errno; + perror("ERROR: tcgetattr failed!"); + break; + } + + // Power off the RTK's ESP-32 + status = powerOff(serialPort); + if (status) + break; + usleep(POWER_OFF_DELAY); + + // Select the boot device + status = bootFromFlash(serialPort); + if (status) + break; + + // Power on the RTK's ESP-32 + status = powerOn(serialPort); + } while (0); + + // Close the terminal + if (serialPort >= 0) + close(serialPort); + return status; +} diff --git a/Firmware/Tools/makefile b/Firmware/Tools/makefile index 0f457571e..abc0e0ae7 100644 --- a/Firmware/Tools/makefile +++ b/Firmware/Tools/makefile @@ -10,6 +10,7 @@ EXECUTABLES = Compare EXECUTABLES += NMEA_Client +EXECUTABLES += RTK_Reset EXECUTABLES += Split_Messages INCLUDES = crc24q.h