#include "board.h" #include "mik32_hal_pcc.h" #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) { // set irq vector to ram region write_csr(mtvec, 0x02000000); HAL_Init(); // gpio clock __HAL_PCC_GPIO_0_CLK_ENABLE(); __HAL_PCC_GPIO_1_CLK_ENABLE(); __HAL_PCC_GPIO_2_CLK_ENABLE(); __HAL_PCC_GPIO_IRQ_CLK_ENABLE(); // for delays SysTick_Init(); } // called after setup() void post_init(void) { if(isInterruptsEnabled()) // if user has called noInterrupts() in setup(), this value is false interrupts(); // enable global interrupts } // --------------------- other --------------------- // volatile bool use_error_messages = true; // print error message to Serial extern "C" void ErrorMsgHandler(const char * msg) { // function works if Serial is used in sketch and user doesn't turn it off #ifdef HardwareSerial_h if(use_error_messages&&Serial) Serial.println(msg); #endif }