From d76b76cb1db59b85ef1300f6afb1aee97e5e0c72 Mon Sep 17 00:00:00 2001 From: jgillick Date: Sun, 22 Mar 2020 02:22:59 -0700 Subject: Add non-volatile memory support to STM --- ports/stm/common-hal/microcontroller/__init__.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ports/stm/common-hal/microcontroller') diff --git a/ports/stm/common-hal/microcontroller/__init__.c b/ports/stm/common-hal/microcontroller/__init__.c index 0c680eb05..85e66fb00 100644 --- a/ports/stm/common-hal/microcontroller/__init__.c +++ b/ports/stm/common-hal/microcontroller/__init__.c @@ -32,6 +32,7 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/microcontroller/Processor.h" +#include "shared-bindings/nvm/ByteArray.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/microcontroller/Processor.h" @@ -109,6 +110,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, + }, + .len = NVM_BYTEARRAY_BUFFER, + .start_address = (uint8_t*) (CIRCUITPY_INTERNAL_NVM_START_ADDR) +}; +#endif + STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { #if MCU_PACKAGE >= 100 { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) }, -- cgit v1.2.3 From 68195a8dfe0bec239a38cc01ad2b74160bbdacd6 Mon Sep 17 00:00:00 2001 From: jgillick Date: Sun, 22 Mar 2020 15:19:53 -0700 Subject: Update NVM_BYTEARRAY_BUFFER_LEN --- ports/stm/boards/thunderpack/mpconfigboard.h | 11 +++++++++-- ports/stm/common-hal/microcontroller/__init__.c | 2 +- ports/stm/common-hal/nvm/ByteArray.h | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) (limited to 'ports/stm/common-hal/microcontroller') diff --git a/ports/stm/boards/thunderpack/mpconfigboard.h b/ports/stm/boards/thunderpack/mpconfigboard.h index 62bf7609d..270600b3c 100644 --- a/ports/stm/boards/thunderpack/mpconfigboard.h +++ b/ports/stm/boards/thunderpack/mpconfigboard.h @@ -26,11 +26,18 @@ #define MICROPY_HW_BOARD_NAME "THUNDERPACK" #define MICROPY_HW_MCU_NAME "STM32F411CE" -#define FLASH_SIZE (0x80000) -#define FLASH_PAGE_SIZE (0x4000) +// Non-volatile memory config #define CIRCUITPY_INTERNAL_NVM_SIZE (0x4000) #define CIRCUITPY_INTERNAL_NVM_START_ADDR (0x0800C000) #define CIRCUITPY_INTERNAL_NVM_SECTOR FLASH_SECTOR_3 + +// Putting the entire flash sector in the NVM byte array buffer +// would take up too much RAM. This limits how much of the sector we use. +#define NVM_BYTEARRAY_BUFFER_LEN 512 + +// Flash config +#define FLASH_SIZE (0x80000) +#define FLASH_PAGE_SIZE (0x4000) #define BOARD_FLASH_SIZE (FLASH_SIZE - CIRCUITPY_INTERNAL_NVM_SIZE- 0x2000 - 0xC000) #define BOARD_OSC_DIV (24) diff --git a/ports/stm/common-hal/microcontroller/__init__.c b/ports/stm/common-hal/microcontroller/__init__.c index 85e66fb00..b69407eff 100644 --- a/ports/stm/common-hal/microcontroller/__init__.c +++ b/ports/stm/common-hal/microcontroller/__init__.c @@ -116,7 +116,7 @@ const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { .base = { .type = &nvm_bytearray_type, }, - .len = NVM_BYTEARRAY_BUFFER, + .len = NVM_BYTEARRAY_BUFFER_LEN, .start_address = (uint8_t*) (CIRCUITPY_INTERNAL_NVM_START_ADDR) }; #endif diff --git a/ports/stm/common-hal/nvm/ByteArray.h b/ports/stm/common-hal/nvm/ByteArray.h index 8ad64cb81..0d7ecf6ab 100644 --- a/ports/stm/common-hal/nvm/ByteArray.h +++ b/ports/stm/common-hal/nvm/ByteArray.h @@ -32,7 +32,9 @@ // STM flash is saved in sectors (not pages), at a minimum size of 16k. // To limit the RAM usage during writing, we want to set a smaller // maximum value. -#define NVM_BYTEARRAY_BUFFER 512 +#ifndef NVM_BYTEARRAY_BUFFER_LEN +#define NVM_BYTEARRAY_BUFFER_LEN 512 +#endif typedef struct { mp_obj_base_t base; -- cgit v1.2.3 From a79ac35173d29b473f64492b089f74e88a13d8bd Mon Sep 17 00:00:00 2001 From: jgillick Date: Sun, 22 Mar 2020 15:20:58 -0700 Subject: Rename NVM_BYTEARRAY_BUFFER_SIZE --- ports/stm/boards/thunderpack/mpconfigboard.h | 2 +- ports/stm/common-hal/microcontroller/__init__.c | 2 +- ports/stm/common-hal/nvm/ByteArray.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'ports/stm/common-hal/microcontroller') diff --git a/ports/stm/boards/thunderpack/mpconfigboard.h b/ports/stm/boards/thunderpack/mpconfigboard.h index 270600b3c..0b3c55819 100644 --- a/ports/stm/boards/thunderpack/mpconfigboard.h +++ b/ports/stm/boards/thunderpack/mpconfigboard.h @@ -33,7 +33,7 @@ // Putting the entire flash sector in the NVM byte array buffer // would take up too much RAM. This limits how much of the sector we use. -#define NVM_BYTEARRAY_BUFFER_LEN 512 +#define NVM_BYTEARRAY_BUFFER_SIZE 512 // Flash config #define FLASH_SIZE (0x80000) diff --git a/ports/stm/common-hal/microcontroller/__init__.c b/ports/stm/common-hal/microcontroller/__init__.c index b69407eff..d407ecfe5 100644 --- a/ports/stm/common-hal/microcontroller/__init__.c +++ b/ports/stm/common-hal/microcontroller/__init__.c @@ -116,7 +116,7 @@ const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { .base = { .type = &nvm_bytearray_type, }, - .len = NVM_BYTEARRAY_BUFFER_LEN, + .len = NVM_BYTEARRAY_BUFFER_SIZE, .start_address = (uint8_t*) (CIRCUITPY_INTERNAL_NVM_START_ADDR) }; #endif diff --git a/ports/stm/common-hal/nvm/ByteArray.h b/ports/stm/common-hal/nvm/ByteArray.h index 0d7ecf6ab..b6ea36de3 100644 --- a/ports/stm/common-hal/nvm/ByteArray.h +++ b/ports/stm/common-hal/nvm/ByteArray.h @@ -32,8 +32,8 @@ // STM flash is saved in sectors (not pages), at a minimum size of 16k. // To limit the RAM usage during writing, we want to set a smaller // maximum value. -#ifndef NVM_BYTEARRAY_BUFFER_LEN -#define NVM_BYTEARRAY_BUFFER_LEN 512 +#ifndef NVM_BYTEARRAY_BUFFER_SIZE +#define NVM_BYTEARRAY_BUFFER_SIZE 512 #endif typedef struct { -- cgit v1.2.3