diff options
Diffstat (limited to 'src/DuetNG')
-rw-r--r-- | src/DuetNG/DuetWiFi/Network.cpp | 16 | ||||
-rw-r--r-- | src/DuetNG/DuetWiFi/Network.h | 3 | ||||
-rw-r--r-- | src/DuetNG/HttpResponder.cpp | 29 | ||||
-rw-r--r-- | src/DuetNG/Pins_DuetNG.h | 4 | ||||
-rw-r--r-- | src/DuetNG/TMC2660.cpp | 79 | ||||
-rw-r--r-- | src/DuetNG/TMC2660.h | 7 |
6 files changed, 122 insertions, 16 deletions
diff --git a/src/DuetNG/DuetWiFi/Network.cpp b/src/DuetNG/DuetWiFi/Network.cpp index 3bb96387..b72e992d 100644 --- a/src/DuetNG/DuetWiFi/Network.cpp +++ b/src/DuetNG/DuetWiFi/Network.cpp @@ -376,6 +376,7 @@ void Network::Start() // The ESP takes about 300ms before it starts talking to us, so don't wait for it here, do that in Spin() spiTxUnderruns = spiRxOverruns = 0; reconnectCount = 0; + transferAlreadyPendingCount = readyTimeoutCount = responseTimeoutCount = 0; lastTickMillis = millis(); state = NetworkState::starting1; @@ -475,6 +476,7 @@ void Network::Spin(bool full) { if (espStatusChanged && digitalRead(EspTransferRequestPin)) { + Platform::softwareResetDebugInfo = 1; if (reprap.Debug(moduleNetwork)) { debugPrintf("ESP reported status change\n"); @@ -487,6 +489,7 @@ void Network::Spin(bool full) && currentMode != WiFiState::autoReconnecting ) { + Platform::softwareResetDebugInfo = 2; // Tell the wifi module to change mode int32_t rslt = ResponseUnknownError; if (currentMode != WiFiState::idle) @@ -515,6 +518,7 @@ void Network::Spin(bool full) } else if (currentMode == WiFiState::connected || currentMode == WiFiState::runningAsAccessPoint) { + Platform::softwareResetDebugInfo = 3; // Find the next socket to poll const size_t startingSocket = currentSocket; do @@ -549,6 +553,7 @@ void Network::Spin(bool full) { nr = responders; // 'responders' can't be null at this point } + Platform::softwareResetDebugInfo = 4; doneSomething = nr->Spin(); nr = nr->GetNext(); } while (!doneSomething && nr != nextResponderToPoll); @@ -558,6 +563,7 @@ void Network::Spin(bool full) } else if (currentMode == requestedMode && (currentMode == WiFiState::connected || currentMode == WiFiState::runningAsAccessPoint)) { + Platform::softwareResetDebugInfo = 5; sockets[currentSocket].Poll(full); ++currentSocket; if (currentSocket == NumTcpSockets) @@ -608,6 +614,7 @@ void Network::Spin(bool full) break; } + Platform::softwareResetDebugInfo = 0; if (full) { platform.ClassReport(longWait); @@ -651,10 +658,13 @@ void Network::Diagnostics(MessageType mtype) { platform.MessageF(mtype, "Network state is %s\n", TranslateNetworkState()); platform.MessageF(mtype, "WiFi module is %s\n", TranslateWiFiState(currentMode)); + platform.MessageF(mtype, "Failed messages: pending %u, notready %u, noresp %u\n", transferAlreadyPendingCount, readyTimeoutCount, responseTimeoutCount); + #if 0 // The underrun/overrun counters don't work at present platform.MessageF(mtype, "SPI underruns %u, overruns %u\n", spiTxUnderruns, spiRxOverruns); #endif + if (state != NetworkState::disabled && state != NetworkState::starting1 && state != NetworkState::starting2) { Receiver<NetworkStatusResponse> status; @@ -675,7 +685,8 @@ void Network::Diagnostics(MessageType mtype) if (currentMode == WiFiState::connected) { - platform.MessageF(mtype, "WiFi signal strength %ddBm\nReconnections %u\n", (int)r.rssi, reconnectCount); + const char* const sleepMode = (r.sleepMode == 1) ? "none" : (r.sleepMode == 2) ? "light" : (r.sleepMode == 3) ? "modem" : "unknown"; + platform.MessageF(mtype, "WiFi signal strength %ddBm, reconnections %u, sleep mode %s\n", (int)r.rssi, reconnectCount, sleepMode); } else if (currentMode == WiFiState::runningAsAccessPoint) { @@ -1192,6 +1203,7 @@ int32_t Network::SendCommand(NetworkCommand cmd, SocketNumber socketNum, uint8_t { debugPrintf("ResponseBusy\n"); } + ++transferAlreadyPendingCount; return ResponseBusy; } @@ -1206,6 +1218,7 @@ int32_t Network::SendCommand(NetworkCommand cmd, SocketNumber socketNum, uint8_t { debugPrintf("ResponseBusy\n"); } + ++readyTimeoutCount; return ResponseBusy; } } @@ -1255,6 +1268,7 @@ int32_t Network::SendCommand(NetworkCommand cmd, SocketNumber socketNum, uint8_t } transferPending = false; spi_dma_disable(); + ++responseTimeoutCount; return ResponseTimeout; } } diff --git a/src/DuetNG/DuetWiFi/Network.h b/src/DuetNG/DuetWiFi/Network.h index 4c97f7e8..fa89cb0b 100644 --- a/src/DuetNG/DuetWiFi/Network.h +++ b/src/DuetNG/DuetWiFi/Network.h @@ -158,6 +158,9 @@ private: unsigned int spiTxUnderruns; unsigned int spiRxOverruns; unsigned int reconnectCount; + unsigned int transferAlreadyPendingCount; + unsigned int readyTimeoutCount; + unsigned int responseTimeoutCount; char wiFiServerVersion[16]; }; diff --git a/src/DuetNG/HttpResponder.cpp b/src/DuetNG/HttpResponder.cpp index 484b0d50..cb25d9d8 100644 --- a/src/DuetNG/HttpResponder.cpp +++ b/src/DuetNG/HttpResponder.cpp @@ -463,11 +463,12 @@ bool HttpResponder::GetJsonResponse(const char* request, OutputBuffer *&response } // See if we can update the current RTC date and time - if (numQualKeys > 1 && StringEquals(qualifiers[1].key, "time") && !GetPlatform().IsDateTimeSet()) + const char* const timeString = GetKeyValue("time"); + if (timeString != nullptr && !GetPlatform().IsDateTimeSet()) { struct tm timeInfo; memset(&timeInfo, 0, sizeof(timeInfo)); - if (strptime(qualifiers[1].value, "%Y-%m-%dT%H:%M:%S", &timeInfo) != nullptr) + if (strptime(timeString, "%Y-%m-%dT%H:%M:%S", &timeInfo) != nullptr) { time_t newTime = mktime(&timeInfo); GetPlatform().SetDateTime(newTime); @@ -876,10 +877,14 @@ void HttpResponder::SendJsonResponse(const char* command) return; } - if (StringEquals(command, "download") && StringEquals(qualifiers[0].key, "name")) + if (StringEquals(command, "download")) { - SendFile(qualifiers[0].value, false); - return; + const char* const filename = GetKeyValue("name"); + if (filename != nullptr) + { + SendFile(filename, false); + return; + } } } @@ -996,7 +1001,8 @@ void HttpResponder::ProcessMessage() || (commandWords[1][0] == '/' && StringEquals(commandWords[1] + 1, KO_START "upload")); if (isUploadRequest) { - if (numQualKeys > 0 && StringEquals(qualifiers[0].key, "name")) + const char* const filename = GetKeyValue("name"); + if (filename != nullptr) { // See how many bytes we expect to read bool contentLengthFound = false; @@ -1018,21 +1024,22 @@ void HttpResponder::ProcessMessage() } // Start a new file upload - FileStore *file = GetPlatform().GetFileStore(FS_PREFIX, qualifiers[0].value, OpenMode::write); + FileStore *file = GetPlatform().GetFileStore(FS_PREFIX, filename, OpenMode::write); if (file == nullptr) { RejectMessage("could not create file"); return; } - StartUpload(file, qualifiers[0].value); + StartUpload(file, filename); // Try to get the last modified file date and time - if (numQualKeys > 1 && StringEquals(qualifiers[1].key, "time")) + const char* const lastModifiedString = GetKeyValue("time"); + if (lastModifiedString != nullptr) { struct tm timeInfo; memset(&timeInfo, 0, sizeof(timeInfo)); - if (strptime(qualifiers[1].value, "%Y-%m-%dT%H:%M:%S", &timeInfo) != nullptr) + if (strptime(lastModifiedString, "%Y-%m-%dT%H:%M:%S", &timeInfo) != nullptr) { fileLastModified = mktime(&timeInfo); } @@ -1048,7 +1055,7 @@ void HttpResponder::ProcessMessage() if (reprap.Debug(moduleWebserver)) { - GetPlatform().MessageF(UsbMessage, "Start uploading file %s length %lu\n", qualifiers[0].value, postFileLength); + GetPlatform().MessageF(UsbMessage, "Start uploading file %s length %lu\n", filename, postFileLength); } uploadedBytes = 0; diff --git a/src/DuetNG/Pins_DuetNG.h b/src/DuetNG/Pins_DuetNG.h index 85b02396..047dfc18 100644 --- a/src/DuetNG/Pins_DuetNG.h +++ b/src/DuetNG/Pins_DuetNG.h @@ -25,6 +25,9 @@ const size_t NumFirmwareUpdateModules = 1; // 1 module #define HAS_LWIP_NETWORKING 0 #define HAS_CPU_TEMP_SENSOR 1 #define HAS_HIGH_SPEED_SD 1 +#define HAS_SMART_DRIVERS 1 +#define HAS_VOLTAGE_MONITOR 1 +#define ACTIVE_LOW_HEAT_ON 1 #define IAP_UPDATE_FILE "iap4e.bin" // using the same IAP file for both Duet WiFi and Duet Ethernet @@ -73,7 +76,6 @@ constexpr Pin DueX_INT = 17; // DueX interrupt pin = PA17 (was E6_STOP) constexpr Pin END_STOP_PINS[DRIVES] = { 46, 02, 93, 74, 48, 200, 203, 202, 201, 213, 39, 8 }; // HEATERS -constexpr bool HEAT_ON = false; // false for inverted heater (e.g. Duet v0.6), true for not (e.g. Duet v0.4) constexpr Pin TEMP_SENSE_PINS[Heaters] = { 45, 47, 44, 61, 62, 63, 59, 18 }; // Thermistor pin numbers constexpr Pin HEAT_ON_PINS[Heaters] = { 19, 20, 16, 35, 37, 40, 43, 15 }; // Heater pin numbers (heater 7 pin TBC) diff --git a/src/DuetNG/TMC2660.cpp b/src/DuetNG/TMC2660.cpp index fb0c9477..12f2f4fb 100644 --- a/src/DuetNG/TMC2660.cpp +++ b/src/DuetNG/TMC2660.cpp @@ -85,6 +85,7 @@ const uint32_t TMC_DRVCTRL_INTPOL = 1 << 9; const uint32_t TMC_SGCSCONF_CS_MASK = 31; #define TMC_SGCSCONF_CS(n) ((((uint32_t)n) & 31) << 0) const uint32_t TMC_SGCSCONF_SGT_MASK = 127 << 8; +const uint32_t TMC_SGCSCONF_SGT_SHIFT = 8; #define TMC_SGCSCONF_SGT(n) ((((uint32_t)n) & 127) << 8) const uint32_t TMC_SGCSCONF_SGT_SFILT = 1 << 16; @@ -126,6 +127,7 @@ const uint32_t defaultSgscConfReg = const uint32_t defaultDrvConfReg = TMC_REG_DRVCONF | TMC_DRVCONF_VSENSE // use high sensitivity range + | TMC_DRVCONF_TS2G_0P8 // fast short-to-ground detection | 0; // Driver control register @@ -137,7 +139,7 @@ const uint32_t defaultDrvCtrlReg = // coolStep control register const uint32_t defaultSmartEnReg = TMC_REG_SMARTEN - | 0; // disable coolStep, we already do this in the main firmware + | 0; // disable coolStep, it needs to be tuned ot the motor to work properly //---------------------------------------------------------------------------------------------------------------------------------- // Private types and methods @@ -161,6 +163,10 @@ struct TmcDriverState void Enable(bool en); void SpiSendWord(uint32_t dataOut); uint32_t ReadStatus(); + void SetStallThreshold(int sgThreshold); + void SetStallFilter(bool sgFilter); + void SetCoolStep(uint16_t coolStepConfig); + void AppendStallConfig(StringRef& reply); }; // Initialise the state of the driver. @@ -270,11 +276,48 @@ uint32_t TmcDriverState::ReadStatus() return lastReadValue & (TMC_RR_SG | TMC_RR_OT | TMC_RR_OTPW | TMC_RR_S2G | TMC_RR_OLA | TMC_RR_OLB | TMC_RR_STST); } +void TmcDriverState::SetStallThreshold(int sgThreshold) +{ + const uint32_t sgVal = ((uint32_t)constrain<int>(sgThreshold, -64, 63)) & 127; + sgcsConfReg = (sgcsConfReg & ~TMC_SGCSCONF_SGT_MASK) | (sgVal << TMC_SGCSCONF_SGT_SHIFT); + SpiSendWord(sgcsConfReg); +} + +void TmcDriverState::SetStallFilter(bool sgFilter) +{ + if (sgFilter) + { + sgcsConfReg |= TMC_SGCSCONF_SGT_SFILT; + } + else + { + sgcsConfReg &= ~TMC_SGCSCONF_SGT_SFILT; + } + SpiSendWord(sgcsConfReg); +} + +void TmcDriverState::SetCoolStep(uint16_t coolStepConfig) +{ + smartEnReg = TMC_REG_SMARTEN | coolStepConfig; + SpiSendWord(smartEnReg); +} + +void TmcDriverState::AppendStallConfig(StringRef& reply) +{ + const bool filtered = ((sgcsConfReg & TMC_SGCSCONF_SGT_SFILT) != 0); + int threshold = (int)((sgcsConfReg & TMC_SGCSCONF_SGT_MASK) >> TMC_SGCSCONF_SGT_SHIFT); + if (threshold >= 64) + { + threshold -= 128; + } + reply.catf("stall threshold %d, filter %s, coolstep %" PRIx32, threshold, ((filtered) ? "on" : "off"), smartEnReg & 0xFFFF); +} + static TmcDriverState driverStates[DRIVES]; //--------------------------- Public interface --------------------------------- -namespace TMC2660 +namespace SmartDrivers { // Initialise the driver interface and the drivers, leaving each drive disabled. // It is assumed that the drivers are not powered, so driversPowered(true) must be called after calling this before the motors can be moved. @@ -434,6 +477,38 @@ namespace TMC2660 } } + void SetStallThreshold(size_t drive, int sgThreshold) + { + if (drive < numTmc2660Drivers) + { + driverStates[drive].SetStallThreshold(sgThreshold); + } + } + + void SetStallFilter(size_t drive, bool sgFilter) + { + if (drive < numTmc2660Drivers) + { + driverStates[drive].SetStallFilter(sgFilter); + } + } + + void SetCoolStep(size_t drive, uint16_t coolStepConfig) + { + if (drive < numTmc2660Drivers) + { + driverStates[drive].SetCoolStep(coolStepConfig); + } + } + + void AppendStallConfig(size_t drive, StringRef& reply) + { + if (drive < numTmc2660Drivers) + { + driverStates[drive].AppendStallConfig(reply); + } + } + }; // end namespace // End diff --git a/src/DuetNG/TMC2660.h b/src/DuetNG/TMC2660.h index 5284789b..91f4b40c 100644 --- a/src/DuetNG/TMC2660.h +++ b/src/DuetNG/TMC2660.h @@ -9,6 +9,7 @@ #define TMC2660_H_ #include "Pins.h" +#include "Libraries/General/StringRef.h" // TMC2660 Read response. The microstep counter can also be read, but we don't include that here. const uint32_t TMC_RR_SG = 1 << 0; // stall detected @@ -19,7 +20,7 @@ const uint32_t TMC_RR_OLA = 1 << 5; // open load A const uint32_t TMC_RR_OLB = 1 << 6; // open load B const uint32_t TMC_RR_STST = 1 << 7; // standstill detected -namespace TMC2660 +namespace SmartDrivers { void Init(const Pin[DRIVES], size_t numTmcDrivers) pre(numTmcDrivers <= DRIVES); @@ -29,6 +30,10 @@ namespace TMC2660 bool SetMicrostepping(size_t drive, int microsteps, int mode); unsigned int GetMicrostepping(size_t drive, int mode, bool& interpolation); void SetDriversPowered(bool powered); + void SetStallThreshold(size_t drive, int sgThreshold); + void SetStallFilter(size_t drive, bool sgFilter); + void SetCoolStep(size_t drive, uint16_t coolStepConfig); + void AppendStallConfig(size_t drive, StringRef& reply); }; #endif /* TMC2660_H_ */ |