From aaf2c3752e6b3b221a2e2d7ebee03a182b95df56 Mon Sep 17 00:00:00 2001 From: Max Holliday Date: Fri, 10 Sep 2021 13:43:04 -0600 Subject: [PATCH] boot counter using existing nvm object --- main.c | 14 +++----------- shared-bindings/nvm/ByteArray.h | 6 +++--- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/main.c b/main.c index 8f2d9e806e..240fd1b1e0 100755 --- a/main.c +++ b/main.c @@ -109,6 +109,7 @@ #ifdef CIRCUITPY_BOOT_COUNTER #include "shared-bindings/nvm/ByteArray.h" +uint8_t value_out = 0; #endif #if MICROPY_ENABLE_PYSTACK @@ -308,15 +309,6 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) { } } -#ifdef CIRCUITPY_BOOT_COUNTER -nvm_bytearray_obj_t bootcnt = { - .base = {.type = &nvm_bytearray_type}, - .len = ( uint32_t) 1, - .start_address = (uint8_t*) (0x00080000 - CIRCUITPY_INTERNAL_NVM_SIZE) - }; -uint8_t value_out = 0; -#endif - STATIC bool run_code_py(safe_mode_t safe_mode) { bool serial_connected_at_start = serial_connected(); bool printed_safe_mode_message = false; @@ -330,9 +322,9 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { #endif #ifdef CIRCUITPY_BOOT_COUNTER - common_hal_nvm_bytearray_get_bytes(&bootcnt,0,1,&value_out); + common_hal_nvm_bytearray_get_bytes(&common_hal_mcu_nvm_obj,0,1,&value_out); ++value_out; - common_hal_nvm_bytearray_set_bytes(&bootcnt,0,&value_out,1); + common_hal_nvm_bytearray_set_bytes(&common_hal_mcu_nvm_obj,0,&value_out,1); #endif pyexec_result_t result; diff --git a/shared-bindings/nvm/ByteArray.h b/shared-bindings/nvm/ByteArray.h index 9b74a4a3f3..c0446b52a3 100644 --- a/shared-bindings/nvm/ByteArray.h +++ b/shared-bindings/nvm/ByteArray.h @@ -31,13 +31,13 @@ extern const mp_obj_type_t nvm_bytearray_type; -uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self); +uint32_t common_hal_nvm_bytearray_get_length(const nvm_bytearray_obj_t *self); -bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self, +bool common_hal_nvm_bytearray_set_bytes(const nvm_bytearray_obj_t *self, uint32_t start_index, uint8_t *values, uint32_t len); // len and values are intentionally swapped to signify values is an output and // also leverage the compiler to validate uses are expected. -void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self, +void common_hal_nvm_bytearray_get_bytes(const nvm_bytearray_obj_t *self, uint32_t start_index, uint32_t len, uint8_t *values); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_NVM_BYTEARRAY_H