From 36249d16ff0460d7d9d6792d76413faebc614633 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Thu, 29 May 2025 15:29:16 +0700 Subject: [PATCH 1/4] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F,=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=8F=D1=8E=D1=89=D0=B0=D1=8F=20=D0=BB=D0=B8?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=20=D0=BA=D1=8D=D1=88=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/arduino/main.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 6dd1d46..1ed6768 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -7,9 +7,28 @@ void initVariant() __attribute__((weak)); void initVariant() { } +#include "mcu32_memory_map.h" +#include "mik32_hal_spifi_w25.h" +#define CLIMIT_NEW (2 * 256 * 1024) // Новый предел кэширования + +// Объявляем, что эта функция исполняется из RAM +__attribute__((section(".ram_text"))) void updateCacheLimit(void) +{ + uint32_t MCMDbackup = SPIFI_CONFIG->MCMD; // Прочитать текущие настройки из регистра MCMD + SPIFI_CONFIG->STAT |= SPIFI_CONFIG_STAT_RESET_M; // Сброс режима MCMD: установить бит RESET + SPIFI_CONFIG->CLIMIT = CLIMIT_NEW; // Установить новое значение CLIMIT + SPIFI_CONFIG->MCMD = MCMDbackup; // Вернуть обратно значение в регистр MCMD +} + + extern "C" int main(void) __attribute__((weak)); int main() { + Serial.begin(9600); + xprintf("old_climit = 0x%08lX\n", SPIFI_CONFIG->CLIMIT); + updateCacheLimit(); + xprintf("new_climit = 0x%08lX\n", SPIFI_CONFIG->CLIMIT); + initVariant(); // for freeRTOS setup(); post_init(); @@ -18,6 +37,4 @@ int main() { loop(); } -} - - +} \ No newline at end of file -- 2.43.0 From dba235e83995cbaa07fac59ec3ed5c52e93f2621 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Thu, 29 May 2025 16:13:04 +0700 Subject: [PATCH 2/4] =?UTF-8?q?=D1=83=D0=BD=D0=B5=D1=81=D0=BB=D0=B0=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8E=20=D0=B2=20=D0=B4?= =?UTF-8?q?=D1=80=D1=83=D0=B3=D0=BE=D0=B9=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB?= =?UTF-8?q?=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/arduino/board.cpp | 19 +++++++++++++++++++ cores/arduino/board.h | 5 +++++ cores/arduino/main.cpp | 18 +++--------------- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/cores/arduino/board.cpp b/cores/arduino/board.cpp index 591676c..bd7fb97 100644 --- a/cores/arduino/board.cpp +++ b/cores/arduino/board.cpp @@ -3,6 +3,25 @@ #include "mik32_hal_irq.h" #include "Arduino.h" +// --------------------- change flash cache limit --------------------- // +#include "mcu32_memory_map.h" +#include "mik32_hal_spifi_w25.h" +#define CLIMIT_NEW (2 * 256 * 1024) // Новый предел кэширования + +// Объявляем, что эта функция исполняется из RAM +__attribute__((section(".ram_text"))) void updateCacheLimit(void) +{ + uint32_t MCMDbackup = SPIFI_CONFIG->MCMD; // Прочитать текущие настройки из регистра MCMD + SPIFI_CONFIG->STAT |= SPIFI_CONFIG_STAT_RESET_M; // Сброс режима MCMD: установить бит RESET + SPIFI_CONFIG->CLIMIT = CLIMIT_NEW; // Установить новое значение CLIMIT + SPIFI_CONFIG->MCMD = MCMDbackup; // Вернуть обратно значение в регистр MCMD +} + +uint32_t getCLimit(void) +{ + return SPIFI_CONFIG->CLIMIT; +} + // --------------------- init --------------------- // // called from crt0.S before constructors initialization extern "C" void SystemInit(void) diff --git a/cores/arduino/board.h b/cores/arduino/board.h index ac36c47..d62102f 100644 --- a/cores/arduino/board.h +++ b/cores/arduino/board.h @@ -8,4 +8,9 @@ extern volatile bool use_error_messages; // function for init called after setup() void post_init(void); +void updateCacheLimit(void); +#include "stdint.h" +uint32_t getCLimit(void); + + #endif /* _BOARD_H_ */ diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index 1ed6768..f4fb6a9 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -7,27 +7,15 @@ void initVariant() __attribute__((weak)); void initVariant() { } -#include "mcu32_memory_map.h" -#include "mik32_hal_spifi_w25.h" -#define CLIMIT_NEW (2 * 256 * 1024) // Новый предел кэширования - -// Объявляем, что эта функция исполняется из RAM -__attribute__((section(".ram_text"))) void updateCacheLimit(void) -{ - uint32_t MCMDbackup = SPIFI_CONFIG->MCMD; // Прочитать текущие настройки из регистра MCMD - SPIFI_CONFIG->STAT |= SPIFI_CONFIG_STAT_RESET_M; // Сброс режима MCMD: установить бит RESET - SPIFI_CONFIG->CLIMIT = CLIMIT_NEW; // Установить новое значение CLIMIT - SPIFI_CONFIG->MCMD = MCMDbackup; // Вернуть обратно значение в регистр MCMD -} - +#include "xprintf.h" extern "C" int main(void) __attribute__((weak)); int main() { Serial.begin(9600); - xprintf("old_climit = 0x%08lX\n", SPIFI_CONFIG->CLIMIT); + xprintf("old_climit = 0x%08lX\n", getCLimit()); updateCacheLimit(); - xprintf("new_climit = 0x%08lX\n", SPIFI_CONFIG->CLIMIT); + xprintf("new_climit = 0x%08lX\n", getCLimit()); initVariant(); // for freeRTOS setup(); -- 2.43.0 From 8d9cca1503d3a6c35631274579051b2b29124d67 Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Fri, 30 May 2025 11:44:46 +0700 Subject: [PATCH 3/4] =?UTF-8?q?=D0=B2=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B1?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=82=D1=81=D1=8F=20=D1=80=D0=B5=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D1=88=D0=B8=D0=B2=D0=BA=D0=B8=20=D1=81=20?= =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B8=D0=BC=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D0=B0=D1=81=D0=BE=D0=BC,=20=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=87=D0=B8=D0=B2=D0=B0=D0=B5=D1=82=D1=81?= =?UTF-8?q?=D1=8F=20=D1=81=D0=B2=D0=B5=D1=80=D1=85=D1=83=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=D1=83=20=D1=84=D0=BB=D0=B5?= =?UTF-8?q?=D1=88=D0=BA=D0=B8=20=D0=B8=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=B2=20=D0=BB?= =?UTF-8?q?=D0=B8=D0=BC=D0=B8=D1=82=20=D0=BA=D0=B5=D1=88=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/arduino/board.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/cores/arduino/board.cpp b/cores/arduino/board.cpp index bd7fb97..ed7cb89 100644 --- a/cores/arduino/board.cpp +++ b/cores/arduino/board.cpp @@ -3,23 +3,39 @@ #include "mik32_hal_irq.h" #include "Arduino.h" -// --------------------- change flash cache limit --------------------- // +// --------------------- flash cache limit --------------------- // #include "mcu32_memory_map.h" #include "mik32_hal_spifi_w25.h" -#define CLIMIT_NEW (2 * 256 * 1024) // Новый предел кэширования -// Объявляем, что эта функция исполняется из RAM +// define board flash size +#if defined(ARDUINO_START_MIK32_V1) + #define FLASH_SIZE 0x00400000 // 4 Mb +#elif defined(ARDUINO_ACE_UNO_16MB) + #define FLASH_SIZE 0x01000000 // 16 Mb +#elif defined(ARDUINO_ACE_UNO_32MB) + #define FLASH_SIZE 0x02000000 // 32 Mb +#else + #define FLASH_SIZE 0x00800000 // 8 Mb +#endif +// define margin from flash end +#define FLASH_END_OFFSET 0x1000 + +// values from ld script +extern uint8_t __TEXT_START__[]; +extern uint8_t __TEXT_END__[]; + +// RAM-function for updating flash cache limit by app size to improve performance __attribute__((section(".ram_text"))) void updateCacheLimit(void) { - uint32_t MCMDbackup = SPIFI_CONFIG->MCMD; // Прочитать текущие настройки из регистра MCMD - SPIFI_CONFIG->STAT |= SPIFI_CONFIG_STAT_RESET_M; // Сброс режима MCMD: установить бит RESET - SPIFI_CONFIG->CLIMIT = CLIMIT_NEW; // Установить новое значение CLIMIT - SPIFI_CONFIG->MCMD = MCMDbackup; // Вернуть обратно значение в регистр MCMD -} + uint32_t new_limit = (uintptr_t)__TEXT_END__ - (uintptr_t)__TEXT_START__ + 128; // 128 byte for margin + // limit cache size by flash size with margin + if (new_limit > (FLASH_SIZE - FLASH_END_OFFSET)) + new_limit = FLASH_SIZE - FLASH_END_OFFSET; -uint32_t getCLimit(void) -{ - return SPIFI_CONFIG->CLIMIT; + uint32_t MCMDbackup = SPIFI_CONFIG->MCMD; // save current value from MCMD + SPIFI_CONFIG->STAT |= SPIFI_CONFIG_STAT_RESET_M; // reset MCMD mode for writing new CLIMIT + SPIFI_CONFIG->CLIMIT = new_limit; // set new CLIMIT + SPIFI_CONFIG->MCMD = MCMDbackup; // restore MCMD value } // --------------------- init --------------------- // @@ -39,6 +55,8 @@ extern "C" void SystemInit(void) // for delays SysTick_Init(); + // update flash cache limit by app size + updateCacheLimit(); } // called after setup() -- 2.43.0 From 44faa66797df75fe4daca1d37ff005b1a9487e9f Mon Sep 17 00:00:00 2001 From: KLASSENTS Date: Fri, 30 May 2025 11:45:05 +0700 Subject: [PATCH 4/4] =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BD=D1=83=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=B8=D1=81=D1=85=D0=BE=D0=B4=D0=BD=D1=83?= =?UTF-8?q?=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cores/arduino/board.h | 5 ----- cores/arduino/main.cpp | 7 ------- 2 files changed, 12 deletions(-) diff --git a/cores/arduino/board.h b/cores/arduino/board.h index d62102f..ac36c47 100644 --- a/cores/arduino/board.h +++ b/cores/arduino/board.h @@ -8,9 +8,4 @@ extern volatile bool use_error_messages; // function for init called after setup() void post_init(void); -void updateCacheLimit(void); -#include "stdint.h" -uint32_t getCLimit(void); - - #endif /* _BOARD_H_ */ diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index f4fb6a9..0fcf31d 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -7,16 +7,9 @@ void initVariant() __attribute__((weak)); void initVariant() { } -#include "xprintf.h" - extern "C" int main(void) __attribute__((weak)); int main() { - Serial.begin(9600); - xprintf("old_climit = 0x%08lX\n", getCLimit()); - updateCacheLimit(); - xprintf("new_climit = 0x%08lX\n", getCLimit()); - initVariant(); // for freeRTOS setup(); post_init(); -- 2.43.0