nvm implementation for esp32s2
This commit is contained in:
parent
ddb3590944
commit
35ef6c687f
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2020-11-04 21:18+0530\n"
|
"POT-Creation-Date: 2020-11-11 16:30+0530\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -296,7 +296,8 @@ msgstr ""
|
|||||||
msgid "All I2C peripherals are in use"
|
msgid "All I2C peripherals are in use"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ports/esp32s2/peripherals/pcnt_handler.c
|
#: ports/esp32s2/common-hal/countio/Counter.c
|
||||||
|
#: ports/esp32s2/common-hal/rotaryio/IncrementalEncoder.c
|
||||||
msgid "All PCNT units in use"
|
msgid "All PCNT units in use"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
@ -1248,6 +1249,10 @@ msgstr ""
|
|||||||
msgid "Must use a multiple of 6 rgb pins, not %d"
|
msgid "Must use a multiple of 6 rgb pins, not %d"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: ports/esp32s2/common-hal/nvm/ByteArray.c
|
||||||
|
msgid "NVS Error"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: py/parse.c
|
#: py/parse.c
|
||||||
msgid "Name too long"
|
msgid "Name too long"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -3201,6 +3206,7 @@ msgstr ""
|
|||||||
msgid "pow() with 3 arguments requires integers"
|
msgid "pow() with 3 arguments requires integers"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h
|
||||||
#: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h
|
#: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h
|
||||||
#: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h
|
#: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h
|
||||||
#: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h
|
#: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h
|
||||||
|
@ -104,6 +104,8 @@ INC += -isystem esp-idf/components/soc/soc/include
|
|||||||
INC += -isystem esp-idf/components/soc/soc/esp32s2/include
|
INC += -isystem esp-idf/components/soc/soc/esp32s2/include
|
||||||
INC += -isystem esp-idf/components/heap/include
|
INC += -isystem esp-idf/components/heap/include
|
||||||
INC += -isystem esp-idf/components/esp_system/include
|
INC += -isystem esp-idf/components/esp_system/include
|
||||||
|
INC += -isystem esp-idf/components/spi_flash/include
|
||||||
|
INC += -isystem esp-idf/components/nvs_flash/include
|
||||||
INC += -I$(BUILD)/esp-idf/config
|
INC += -I$(BUILD)/esp-idf/config
|
||||||
|
|
||||||
CFLAGS += -DHAVE_CONFIG_H \
|
CFLAGS += -DHAVE_CONFIG_H \
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
#include "shared-bindings/microcontroller/Pin.h"
|
#include "shared-bindings/microcontroller/Pin.h"
|
||||||
#include "shared-bindings/microcontroller/Processor.h"
|
#include "shared-bindings/microcontroller/Processor.h"
|
||||||
|
#include "shared-bindings/nvm/ByteArray.h"
|
||||||
|
|
||||||
#include "supervisor/filesystem.h"
|
#include "supervisor/filesystem.h"
|
||||||
#include "supervisor/shared/safe_mode.h"
|
#include "supervisor/shared/safe_mode.h"
|
||||||
@ -85,6 +86,17 @@ const mcu_processor_obj_t common_hal_mcu_processor_obj = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if CIRCUITPY_INTERNAL_NVM_SIZE > 0
|
||||||
|
// The singleton nvm.ByteArray object.
|
||||||
|
const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = {
|
||||||
|
.base = {
|
||||||
|
.type = &nvm_bytearray_type,
|
||||||
|
},
|
||||||
|
.start_address = (uint8_t*) CIRCUITPY_INTERNAL_NVM_START_ADDR,
|
||||||
|
.len = CIRCUITPY_INTERNAL_NVM_SIZE,
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
// This maps MCU pin names to pin objects.
|
// This maps MCU pin names to pin objects.
|
||||||
STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = {
|
||||||
{ MP_ROM_QSTR(MP_QSTR_GPIO0), MP_ROM_PTR(&pin_GPIO0) },
|
{ MP_ROM_QSTR(MP_QSTR_GPIO0), MP_ROM_PTR(&pin_GPIO0) },
|
||||||
|
80
ports/esp32s2/common-hal/nvm/ByteArray.c
Normal file
80
ports/esp32s2/common-hal/nvm/ByteArray.c
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 microDev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common-hal/nvm/ByteArray.h"
|
||||||
|
|
||||||
|
#include "py/runtime.h"
|
||||||
|
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
|
||||||
|
uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) {
|
||||||
|
return self->len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static nvs_handle get_nvs_handle(void) {
|
||||||
|
// Initialize NVS
|
||||||
|
esp_err_t err = nvs_flash_init();
|
||||||
|
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||||
|
// NVS partition was truncated and needs to be erased
|
||||||
|
// Retry nvs_flash_init
|
||||||
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||||
|
err = nvs_flash_init();
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(err);
|
||||||
|
|
||||||
|
// Open NVS handle
|
||||||
|
nvs_handle nvs_handle;
|
||||||
|
if (nvs_open("CPY", NVS_READWRITE, &nvs_handle) != ESP_OK) {
|
||||||
|
mp_raise_RuntimeError(translate("NVS Error"));
|
||||||
|
}
|
||||||
|
return nvs_handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self,
|
||||||
|
uint32_t start_index, uint8_t* values, uint32_t len) {
|
||||||
|
char index[9];
|
||||||
|
sprintf(index, "%i", start_index);
|
||||||
|
// start nvs
|
||||||
|
nvs_handle handle = get_nvs_handle();
|
||||||
|
bool status = ((nvs_set_u8(handle, (const char *)index, *values) == ESP_OK) && (nvs_commit(handle) == ESP_OK));
|
||||||
|
// close nvs
|
||||||
|
nvs_close(handle);
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NVM memory is memory mapped so reading it is easy.
|
||||||
|
void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self,
|
||||||
|
uint32_t start_index, uint32_t len, uint8_t* values) {
|
||||||
|
char index[9];
|
||||||
|
sprintf(index, "%i", start_index);
|
||||||
|
// start nvs
|
||||||
|
nvs_handle handle = get_nvs_handle();
|
||||||
|
if (nvs_get_u8(handle, (const char *)index, values) != ESP_OK) {
|
||||||
|
mp_raise_RuntimeError(translate("NVS Error"));
|
||||||
|
}
|
||||||
|
// close nvs
|
||||||
|
nvs_close(handle);
|
||||||
|
}
|
38
ports/esp32s2/common-hal/nvm/ByteArray.h
Normal file
38
ports/esp32s2/common-hal/nvm/ByteArray.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the MicroPython project, http://micropython.org/
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020 microDev
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_NVM_BYTEARRAY_H
|
||||||
|
#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_NVM_BYTEARRAY_H
|
||||||
|
|
||||||
|
#include "py/obj.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
mp_obj_base_t base;
|
||||||
|
uint8_t* start_address;
|
||||||
|
uint32_t len;
|
||||||
|
} nvm_bytearray_obj_t;
|
||||||
|
|
||||||
|
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_NVM_BYTEARRAY_H
|
1
ports/esp32s2/common-hal/nvm/__init__.c
Normal file
1
ports/esp32s2/common-hal/nvm/__init__.c
Normal file
@ -0,0 +1 @@
|
|||||||
|
// No nvm module functions.
|
@ -28,7 +28,6 @@
|
|||||||
#ifndef ESP32S2_MPCONFIGPORT_H__
|
#ifndef ESP32S2_MPCONFIGPORT_H__
|
||||||
#define ESP32S2_MPCONFIGPORT_H__
|
#define ESP32S2_MPCONFIGPORT_H__
|
||||||
|
|
||||||
#define CIRCUITPY_INTERNAL_NVM_SIZE (0)
|
|
||||||
#define MICROPY_NLR_THUMB (0)
|
#define MICROPY_NLR_THUMB (0)
|
||||||
|
|
||||||
#define MICROPY_PY_UJSON (1)
|
#define MICROPY_PY_UJSON (1)
|
||||||
@ -36,11 +35,15 @@
|
|||||||
|
|
||||||
#include "py/circuitpy_mpconfig.h"
|
#include "py/circuitpy_mpconfig.h"
|
||||||
|
|
||||||
|
|
||||||
#define MICROPY_PORT_ROOT_POINTERS \
|
#define MICROPY_PORT_ROOT_POINTERS \
|
||||||
CIRCUITPY_COMMON_ROOT_POINTERS
|
CIRCUITPY_COMMON_ROOT_POINTERS
|
||||||
#define MICROPY_NLR_SETJMP (1)
|
#define MICROPY_NLR_SETJMP (1)
|
||||||
#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000
|
#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000
|
||||||
|
|
||||||
|
#define CIRCUITPY_INTERNAL_NVM_START_ADDR (0x9000)
|
||||||
|
|
||||||
|
#ifndef CIRCUITPY_INTERNAL_NVM_SIZE
|
||||||
|
#define CIRCUITPY_INTERNAL_NVM_SIZE (20000)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // __INCLUDED_ESP32S2_MPCONFIGPORT_H
|
#endif // __INCLUDED_ESP32S2_MPCONFIGPORT_H
|
||||||
|
@ -21,7 +21,7 @@ CIRCUITPY_COUNTIO = 1
|
|||||||
CIRCUITPY_FREQUENCYIO = 0
|
CIRCUITPY_FREQUENCYIO = 0
|
||||||
CIRCUITPY_I2CPERIPHERAL = 0
|
CIRCUITPY_I2CPERIPHERAL = 0
|
||||||
CIRCUITPY_ROTARYIO = 1
|
CIRCUITPY_ROTARYIO = 1
|
||||||
CIRCUITPY_NVM = 0
|
CIRCUITPY_NVM = 1
|
||||||
# We don't have enough endpoints to include MIDI.
|
# We don't have enough endpoints to include MIDI.
|
||||||
CIRCUITPY_USB_MIDI = 0
|
CIRCUITPY_USB_MIDI = 0
|
||||||
CIRCUITPY_WIFI = 1
|
CIRCUITPY_WIFI = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user