mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-31 10:01:48 +02:00
Fixed SPI and SD initialization.
This commit is contained in:
@@ -61,6 +61,16 @@ void grbl_init() {
|
||||
// The I2S out must be initialized before it can access the expanded GPIO port. Must be initialized _after_ settings!
|
||||
i2s_out_init();
|
||||
}
|
||||
if (config->_spi) {
|
||||
info_serial("Initializing SPI...");
|
||||
// The SPI must be initialized before we can use it.
|
||||
config->_spi->init();
|
||||
|
||||
// Initialize SD card after SPI:
|
||||
if (config->_sdCard != nullptr) {
|
||||
config->_sdCard->init();
|
||||
}
|
||||
}
|
||||
|
||||
info_serial("Initializing steppers...");
|
||||
stepper_init(); // Configure stepper pins and interrupt timers
|
||||
@@ -74,7 +84,8 @@ void grbl_init() {
|
||||
memset(sys_position, 0, sizeof(sys_position)); // Clear machine position.
|
||||
|
||||
machine_init(); // user supplied function for special initialization
|
||||
// Initialize system state.
|
||||
|
||||
// Initialize system state.
|
||||
if (sys.state != State::ConfigAlarm) {
|
||||
#ifdef FORCE_INITIALIZATION_ALARM
|
||||
// Force Grbl into an ALARM state upon a power-cycle or hard reset.
|
||||
|
@@ -3,18 +3,9 @@
|
||||
// Grbl setting that are common to all machines
|
||||
// It should not be necessary to change anything herein
|
||||
|
||||
#ifndef GRBL_SPI_FREQ
|
||||
// You can override these by defining them in a board file.
|
||||
// To override, you must set all of them
|
||||
//-1 means use the default board pin
|
||||
# define GRBL_SPI_SS -1
|
||||
# define GRBL_SPI_MOSI -1
|
||||
# define GRBL_SPI_MISO -1
|
||||
# define GRBL_SPI_SCK -1
|
||||
# define GRBL_SPI_FREQ 4000000
|
||||
#endif
|
||||
const int32_t GRBL_SPI_FREQ = 4000000;
|
||||
|
||||
// ESP32 CPU Settings
|
||||
// ESP32 CPU Settings
|
||||
const uint32_t fTimers = 80000000; // a reference to the speed of ESP32 timers
|
||||
|
||||
// =============== Don't change or comment these out ======================
|
||||
|
@@ -362,6 +362,17 @@ void SPIBus::validate() const {
|
||||
}
|
||||
}
|
||||
|
||||
void SPIBus::init() {
|
||||
if (_ss.defined()) { // validation ensures the rest is also defined.
|
||||
auto ssPin = _ss.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
|
||||
auto mosiPin = _mosi.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
|
||||
auto sckPin = _sck.getNative(Pin::Capabilities::Output | Pin::Capabilities::Native);
|
||||
auto misoPin = _miso.getNative(Pin::Capabilities::Input | Pin::Capabilities::Native);
|
||||
|
||||
SPI.begin(sckPin, misoPin, mosiPin, ssPin);
|
||||
}
|
||||
}
|
||||
|
||||
void SPIBus::group(Configuration::HandlerBase& handler) {
|
||||
handler.item("ss", _ss);
|
||||
handler.item("miso", _miso);
|
||||
|
@@ -203,6 +203,8 @@ public:
|
||||
void group(Configuration::HandlerBase& handler) override;
|
||||
void afterParse() override;
|
||||
|
||||
void init();
|
||||
|
||||
~SPIBus() = default;
|
||||
};
|
||||
|
||||
@@ -370,7 +372,7 @@ public:
|
||||
// before initialization. If it detects a problem and the hard limits setting is enabled, Grbl will
|
||||
// simply message the user to check the limits and enter an alarm state, rather than idle. Grbl will
|
||||
// not throw an alarm message.
|
||||
bool _checkLimitsAtInit = true;
|
||||
bool _checkLimitsAtInit = true;
|
||||
|
||||
// If your machine has two limits switches wired in parallel to one axis, you will need to enable
|
||||
// this feature. Since the two switches are sharing a single pin, there is no way for Grbl to tell
|
||||
|
@@ -142,12 +142,7 @@ SDCard::State SDCard::get_state(bool refresh) {
|
||||
|
||||
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
|
||||
|
||||
|
||||
//no need to go further if SD detect is not correct
|
||||
if (config->_sdCard->_cardDetect.defined() && !config->_sdCard->_cardDetect.read()) {
|
||||
_state = SDCard::State::NotPresent;
|
||||
@@ -164,10 +159,12 @@ SDCard::State SDCard::get_state(bool refresh) {
|
||||
|
||||
//SD is idle or not detected, let see if still the case
|
||||
SD.end();
|
||||
|
||||
_state = SDCard::State::NotPresent;
|
||||
|
||||
//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.begin(ssPin, SPI, GRBL_SPI_FREQ, "/sd", 2)) {
|
||||
if (SD.cardSize() > 0) {
|
||||
_state = SDCard::State::Idle;
|
||||
}
|
||||
|
@@ -69,11 +69,6 @@ void system_reset() {
|
||||
}
|
||||
|
||||
void init_output_pins() {
|
||||
//customize pin definition if needed
|
||||
#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MISO != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1)
|
||||
SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MISO, GRBL_SPI_MOSI, GRBL_SPI_SS);
|
||||
#endif
|
||||
|
||||
auto userOutputs = config->_userOutputs;
|
||||
|
||||
// Setup M62,M63,M64,M65 pins
|
||||
|
Reference in New Issue
Block a user