Настройка размера кеша у микросхемы flash-памяти по размеру прошивки
Co-authored-by: KLASSENTS <klassen@elron.tech> Co-committed-by: KLASSENTS <klassen@elron.tech>
This commit is contained in:
parent
2cb29ab673
commit
5acf627e2c
@ -3,6 +3,41 @@
|
|||||||
#include "mik32_hal_irq.h"
|
#include "mik32_hal_irq.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
// --------------------- flash cache limit --------------------- //
|
||||||
|
#include "mcu32_memory_map.h"
|
||||||
|
#include "mik32_hal_spifi_w25.h"
|
||||||
|
|
||||||
|
// 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 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 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 --------------------- //
|
// --------------------- init --------------------- //
|
||||||
// called from crt0.S before constructors initialization
|
// called from crt0.S before constructors initialization
|
||||||
extern "C" void SystemInit(void)
|
extern "C" void SystemInit(void)
|
||||||
@ -20,6 +55,8 @@ extern "C" void SystemInit(void)
|
|||||||
|
|
||||||
// for delays
|
// for delays
|
||||||
SysTick_Init();
|
SysTick_Init();
|
||||||
|
// update flash cache limit by app size
|
||||||
|
updateCacheLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// called after setup()
|
// called after setup()
|
||||||
|
|||||||
@ -19,5 +19,3 @@ int main()
|
|||||||
loop();
|
loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user