diff --git a/Grbl_Esp32/src/MachineConfig.cpp b/Grbl_Esp32/src/MachineConfig.cpp index 67182c50..723bcb40 100644 --- a/Grbl_Esp32/src/MachineConfig.cpp +++ b/Grbl_Esp32/src/MachineConfig.cpp @@ -373,11 +373,6 @@ void MachineConfig::afterParse() { _coolant = new CoolantControl(); } - if (_spi == nullptr) { - log_info("SPI config missing; building default SPI bus."); - _spi = new SPIBus(); - } - if (_probe == nullptr) { log_info("Probe config missing; building default probe."); _probe = new Probe(); diff --git a/Grbl_Esp32/src/Motors/TrinamicDriver.cpp b/Grbl_Esp32/src/Motors/TrinamicDriver.cpp index 521658dc..108d9556 100644 --- a/Grbl_Esp32/src/Motors/TrinamicDriver.cpp +++ b/Grbl_Esp32/src/Motors/TrinamicDriver.cpp @@ -91,32 +91,36 @@ namespace Motors { config_message(); auto spiConfig = MachineConfig::instance()->_spi; + if (spiConfig != nullptr) { + auto ssPin = spiConfig->_ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); + auto mosiPin = spiConfig->_mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); + auto sckPin = spiConfig->_sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); + auto misoPin = spiConfig->_miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native); - auto ssPin = spiConfig->_ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); - auto mosiPin = spiConfig->_mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); - auto sckPin = spiConfig->_sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); - auto misoPin = spiConfig->_miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native); + SPI.begin(sckPin, misoPin, mosiPin, ssPin); // this will get called for each motor, but does not seem to hurt anything - SPI.begin(sckPin, misoPin, mosiPin, ssPin); // this will get called for each motor, but does not seem to hurt anything + tmcstepper->begin(); - tmcstepper->begin(); + _has_errors = !test(); // Try communicating with motor. Prints an error if there is a problem. - _has_errors = !test(); // Try communicating with motor. Prints an error if there is a problem. + read_settings(); // pull info from settings + set_mode(false); - read_settings(); // pull info from settings - set_mode(false); - - // After initializing all of the TMC drivers, create a task to - // display StallGuard data. List == this for the final instance. - if (List == this) { - xTaskCreatePinnedToCore(readSgTask, // task - "readSgTask", // name for task - 4096, // size of task stack - NULL, // parameters - 1, // priority - NULL, - 0 // core - ); + // After initializing all of the TMC drivers, create a task to + // display StallGuard data. List == this for the final instance. + if (List == this) { + xTaskCreatePinnedToCore(readSgTask, // task + "readSgTask", // name for task + 4096, // size of task stack + NULL, // parameters + 1, // priority + NULL, + 0 // core + ); + } + } else { + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "SPI bus is not available; cannot initialize TMC driver."); + _has_errors = true; } } diff --git a/Grbl_Esp32/src/SDCard.cpp b/Grbl_Esp32/src/SDCard.cpp index 1298b86e..02da8148 100644 --- a/Grbl_Esp32/src/SDCard.cpp +++ b/Grbl_Esp32/src/SDCard.cpp @@ -129,44 +129,48 @@ uint32_t sd_get_current_line_number() { uint8_t sd_state = SDCARD_IDLE; uint8_t get_sd_state(bool refresh) { - // Before we use the SD library, we *must* make sure SPI is properly initialized. Re-initialization + // Before we use the SD library, we *must* make sure SPI is properly initialized. Re-initialization // fortunately doesn't change any of the settings. auto spiConfig = MachineConfig::instance()->_spi; - auto ssPin = spiConfig->_ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); - auto mosiPin = spiConfig->_mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); - auto sckPin = spiConfig->_sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); - auto misoPin = spiConfig->_miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native); + if (spiConfig != nullptr) { + auto ssPin = spiConfig->_ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); + auto mosiPin = spiConfig->_mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); + auto sckPin = spiConfig->_sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native); + auto misoPin = spiConfig->_miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native); - SPI.begin(sckPin, misoPin, mosiPin, ssPin); // this will get called for each motor, but does not seem to hurt anything + SPI.begin(sckPin, misoPin, mosiPin, ssPin); // this will get called for each motor, but does not seem to hurt anything - //no need to go further if SD detect is not correct - if (SDCardDetPin->get() != Pin::UNDEFINED) { - if (!((SDCardDetPin->get().read() == SDCARD_DET_VAL) ? true : false)) { - sd_state = SDCARD_NOT_PRESENT; + //no need to go further if SD detect is not correct + if (SDCardDetPin->get() != Pin::UNDEFINED) { + if (!((SDCardDetPin->get().read() == SDCARD_DET_VAL) ? true : false)) { + sd_state = SDCARD_NOT_PRESENT; + return sd_state; + } + } + + //if busy doing something return state + if (!((sd_state == SDCARD_NOT_PRESENT) || (sd_state == SDCARD_IDLE))) { return sd_state; } - } - - //if busy doing something return state - if (!((sd_state == SDCARD_NOT_PRESENT) || (sd_state == SDCARD_IDLE))) { - return sd_state; - } - if (!refresh) { - return sd_state; //to avoid refresh=true + busy to reset SD and waste time - } - - //SD is idle or not detected, let see if still the case - SD.end(); - sd_state = SDCARD_NOT_PRESENT; - //using default value for speed ? should be parameter - //refresh content if card was removed - if (SD.begin((GRBL_SPI_SS == -1) ? SS : GRBL_SPI_SS, SPI, GRBL_SPI_FREQ, "/sd", 2)) { - if (SD.cardSize() > 0) { - sd_state = SDCARD_IDLE; + if (!refresh) { + return sd_state; //to avoid refresh=true + busy to reset SD and waste time } + + //SD is idle or not detected, let see if still the case + SD.end(); + sd_state = SDCARD_NOT_PRESENT; + //using default value for speed ? should be parameter + //refresh content if card was removed + if (SD.begin((GRBL_SPI_SS == -1) ? SS : GRBL_SPI_SS, SPI, GRBL_SPI_FREQ, "/sd", 2)) { + if (SD.cardSize() > 0) { + sd_state = SDCARD_IDLE; + } + } + return sd_state; + } else { + return SDCARD_NOT_PRESENT; } - return sd_state; } uint8_t set_sd_state(uint8_t flag) {