Skip to content

Commit

Permalink
Changed NVS storage for settings in flash from 2 to 4KB.
Browse files Browse the repository at this point in the history
Added note to _platformio.ino_ files.
  • Loading branch information
terjeio committed Oct 27, 2024
1 parent f96e219 commit 5863c20
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
15 changes: 13 additions & 2 deletions main/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
#include "grbl/motor_pins.h"
#include "grbl/machine_limits.h"
#include "grbl/pin_bits_masks.h"
#if NVSDATA_BUFFER_ENABLE
#include "grbl/nvs_buffer.h"
#endif

#if CONFIG_IDF_TARGET_ESP32S3
#include "esp32s3/clk.h"
Expand Down Expand Up @@ -2925,7 +2928,7 @@ bool driver_init (void)
#else
hal.info = "ESP32";
#endif
hal.driver_version = "241003";
hal.driver_version = "241025";
hal.driver_url = GRBL_URL "/ESP32";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
Expand Down Expand Up @@ -3026,14 +3029,22 @@ bool driver_init (void)
#if EEPROM_ENABLE
i2c_eeprom_init();
#else
if(nvsInit()) {
static const esp_partition_t *partition;

if((partition = nvsInit())) {
hal.nvs.type = NVS_Flash;
hal.nvs.memcpy_from_flash = nvsRead;
hal.nvs.memcpy_to_flash = nvsWrite;
hal.nvs.size_max = partition->size;
} else
hal.nvs.type = NVS_None;
#endif

#if NVSDATA_BUFFER_ENABLE
if(hal.nvs.type != NVS_None)
nvs_buffer_alloc(); // Reallocate memory block for NVS buffer
#endif

#if DRIVER_SPINDLE_ENABLE

#if DRIVER_SPINDLE_PWM_ENABLE
Expand Down
15 changes: 7 additions & 8 deletions main/nvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
Part of grblHAL
Copyright (c) 2018-2023 Terje Io
Copyright (c) 2018-2024 Terje Io
Grbl is free software: you can redistribute it and/or modify
grblHAL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
grblHAL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
*/

#include "esp_partition.h"
#include "esp_log.h"

#include "nvs.h"
Expand Down Expand Up @@ -73,9 +72,9 @@ bool nvsWrite (uint8_t *source)
return ok;
}

bool nvsInit (void)
const esp_partition_t *nvsInit (void)
{
grblNVS = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "grbl");

return grblNVS != NULL;
return grblNVS;
}
16 changes: 9 additions & 7 deletions main/nvs.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/*
nvs.c - An embedded CNC Controller with rs274/ngc (g-code) support
nvs.h - An embedded CNC Controller with rs274/ngc (g-code) support
Peristent storage of settings in flash
Part of grblHAL
Copyright (c) 2018 Terje Io
Copyright (c) 2018-2024 Terje Io
Grbl is free software: you can redistribute it and/or modify
grblHAL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
grblHAL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
*/

bool nvsInit(void);
#include "esp_partition.h"

const esp_partition_t *nvsInit(void);
bool nvsRead (uint8_t *dest);
bool nvsWrite (uint8_t *source);
6 changes: 6 additions & 0 deletions platformio.cnc3040.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

#
# NOTE: PlatformIO support is provided by the community and platformio.ini is
# not maintained or tested by the repo owner.
# Please submit a PR with bug fixes and enhancments.
#

[platformio]
src_dir = main
include_dir = main
Expand Down
6 changes: 6 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
# Building for BDring new 6x board
#

#
# NOTE: PlatformIO support is provided by the community and platformio.ini is
# not maintained or tested by the repo owner.
# Please submit a PR with bug fixes and enhancments.
#

[platformio]
src_dir = main
include_dir = main
Expand Down

0 comments on commit 5863c20

Please sign in to comment.