/** * @brief Read config1 * * @param None * * @return Config1 value * * @details Read config1 */ uint32_t CONFIG1_Read(void) { uint32_t ulTmp; int32_t ret; ret = DrvFMC_Read(CONFIG_START_ADDRESS + 0x04, &ulTmp); if(ret < 0) { ulTmp = 0; printf("Config1 Read Error\n"); while(1); } return ulTmp; }
//============================================================================ // u32addr : 0-1024 //============================================================================ uint32_t DATA_FLASH_Read(uint32_t u32add) { uint32_t u32data; #ifdef M451 u32data = FMC_Read(u32add*4+DATA_Flash_Start_ADD); #else __set_PRIMASK(1); UNLOCKREG(); DrvFMC_EnableISP(); DrvFMC_Read(u32add*4+DATA_Flash_Start_ADD, &u32data); DrvFMC_DisableISP(); LOCKREG(); __set_PRIMASK(0); #endif return u32data; }
/** * @brief Verify APROM erase succeed or not * * @param None * * @return None * * @details Verify APROM erase succeed or not */ void APROM_Erase_Verify(void) { uint32_t ulCount, u32Data; int32_t ret; for(ulCount=0;ulCount<((APROM_SIZE-APROM_START_ADDRESS)/4);ulCount++) { ret =DrvFMC_Read(APROM_START_ADDRESS + ulCount*4, &u32Data); //中:写地址//en:Write address if(ret < 0) { printf("APROM Erase Verify Read error\n"); while(1); } if(u32Data != 0xFFFFFFFF) //中:验证擦除操作是否成功//en:Verify the ERASE operation success or not { printf("APROM Erase Verify Error\n"); while(1); } } }
//============================================================================ // DATA FLASH OPERATION // u32addr : 0-1024 (For 4KBytes Data Flash) // u32data : 0-0xFFFFFFFF (4Bytes) //============================================================================ void DATA_FLASH_Write(uint32_t u32addr,uint32_t u32data) { uint32_t i=0; #ifdef M451 SYS_UnlockReg(); FMC_Open(); for(i=0; i<PAGE_SIZE; i++) data_buff[i] = FMC_Read(DATA_Flash_Start_ADD+i*4+ u32addr/PAGE_SIZE*2048); FMC_Erase(DATA_Flash_Start_ADD+u32addr/PAGE_SIZE*2048); data_buff[u32addr%PAGE_SIZE]=u32data; for(i=0; i<PAGE_SIZE; i++) FMC_Write(DATA_Flash_Start_ADD+i*4+ u32addr/PAGE_SIZE*2048, data_buff[i]); FMC_Close(); SYS_LockReg(); #else uint32_t data_buff[PAGE_SIZE]; __set_PRIMASK(1);//Avoid interrupt UNLOCKREG(); DrvFMC_EnableISP(); for(i=0; i<PAGE_SIZE; i++) DrvFMC_Read(DATA_Flash_Start_ADD+i*4+ u32addr/128*512, &data_buff[i]); DrvFMC_Erase(DATA_Flash_Start_ADD+u32addr/128*512); data_buff[u32addr%128]=u32data; for(i=0; i<PAGE_SIZE; i++) DrvFMC_Write(DATA_Flash_Start_ADD+i*4+ u32addr/128*512, data_buff[i]); DrvFMC_DisableISP(); LOCKREG(); __set_PRIMASK(0); #endif }
/** * @brief Verify APROM Program succeed or not * * @param ulDATA: Data to be compared with programmed APROM data. * * @return None * * @details Verify APROM Program succeed or not */ void APROM_Program_Verify(uint32_t ulDATA) { uint32_t ulCount, u32Data; int32_t ret; for(ulCount=0;ulCount<((APROM_SIZE-APROM_START_ADDRESS)/4);ulCount++) { ret =DrvFMC_Read(APROM_START_ADDRESS + ulCount*4, &u32Data); //中:写地址//en:Write address if(ret < 0) { printf("APROM Program Verify Read error\n"); while(1); } if(u32Data != ulDATA) //中:验证编程操作是否成功//en:Verify the PROGRAM operation success or not { printf("APROM Program Verify Error\n"); while(1); } ulDATA = ~ulDATA; } }
/******************************************************************************//** *@brief A simple FMC example. It Erase the LDROM and Verify ,then Program LDROM * and read out data to compare. *@param None *@return None **********************************************************************************/ void FMC_LDROM(void) { uint32_t u32Data, i; int32_t i32Err; // STR_UART_T sParam; /* Unlock the protected registers */ UNLOCKREG(); /* Enable the 12MHz oscillator oscillation */ SYSCLK->PWRCON.XTL12M_EN = 1; /* Waiting for 12M Xtal stable */ while (DrvSYS_GetChipClockSourceStatus(E_SYS_XTL12M) != 1); /* Set UART Pin */ DrvGPIO_InitFunction(E_FUNC_UART0); /* UART Setting */ /* sParam.u32BaudRate = 115200; sParam.u8cDataBits = DRVUART_DATABITS_8; sParam.u8cStopBits = DRVUART_STOPBITS_1; sParam.u8cParity = DRVUART_PARITY_NONE; sParam.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES; */ /* Select UART Clock Source From 12MHz */ DrvSYS_SelectIPClockSource(E_SYS_UART_CLKSRC, 0); /* Set UART Configuration */ // DrvUART_Open(UART_PORT0, &sParam); /* Enable ISP function */ DrvFMC_EnableISP(); /* Enable LDROM update */ DrvFMC_EnableLDUpdate(); /* Page Erase LDROM */ printf("Erase LDROM test..............................."); for(i=0; i<4096; i+=PAGE_SIZE) DrvFMC_Erase(LDROM_BASE + i); /* Erase Verify */ i32Err = 0; for(i = LDROM_BASE; i < (LDROM_BASE+4096); i += 4) { DrvFMC_Read(i, &u32Data); if(u32Data != 0xFFFFFFFF) { i32Err = 1; } } if (i32Err) printf("[FAIL]\n\r"); else printf("[OK]\n\r"); /* Program LD ROM and read out data to compare */ printf("Program LDROM test............................."); for(i = LDROM_BASE; i < (LDROM_BASE+4096); i += 4) { DrvFMC_Write(i, i); } i32Err = 0; for(i = LDROM_BASE; i < (LDROM_BASE+4096); i += 4) { DrvFMC_Read(i, &u32Data); if(u32Data != i) { i32Err = 1; } } if (i32Err) printf("[FAIL]\n\r"); else printf("[OK]\n\r"); /* Disable ISP function */ DrvFMC_DisableISP(); /* Lock protected registers */ LOCKREG(); printf("FMC Sample Code Completed!\n\r"); }