#include "board.h" #include <cr_section_macros.h> #include "iap_18xx_43xx.h" //IAP: Settings .. ->.. stack offset=32 // Initialize IAP before using it // Erase sector 0 from RAM #define IAP_INIT_CMD 49 void Chip_IAP_Initialise(void) { uint32_t command[5], result[4]; command[0] = IAP_INIT_CMD; iap_entry(command, result); } __RAMFUNC(RAM) void ram_fw_upgrade(void){ int i; uint32_t n_sector=0;//we start writing data in this sector uint32_t command[5], result[4]; __disable_irq(); // prepare sector 0 command[0] = IAP_PREWRRITE_CMD; command[1] = n_sector; command[2] = n_sector; command[3] = 0;//flashBank A iap_entry(command, result); //erase sector 0 command[0] = IAP_ERSSECTOR_CMD; command[1] = n_sector; command[2] = n_sector; command[3] = SystemCoreClock / 1000; command[4] = 0;//flashBank A iap_entry(command, result); //---->crash!! for(i=0;i<1000000;i++);//wait..do something in RAM __enable_irq(); return; } int main(void) { int i=0; void (*longfunc)(void) = &ram_fw_upgrade; SystemCoreClockUpdate(); // Board_Init(); // Board_LED_Set(0, true); Board_UART_Init(0);//doing nothing, but it's needed, or it will not compile Chip_IAP_Initialise(); if(i!=0){ //just for safety..we enter here only manually, during debug.. (*longfunc)();// running from RAM } while(1) { i++; } return 0 ; } |