/*---------------------------------------------------------------------------------------------------------*/ uint8_t ProgramContinueDataTest(void) { uint8_t u8DataIn, u8DataOut; uint32_t u32NORAddr; printf(" >> Start to program flash ... \n"); /* Write */ for(u32NORAddr = 0; u32NORAddr < EBI_MAX_SIZE; u32NORAddr++) { u8DataIn = (u32NORAddr % 256) + u32NORAddr; if(NOR_WriteData(u32NORAddr, u8DataIn) == FALSE) { printf("Program [0x%05X]:[0x%02X] FAIL !!! \n\n", u32NORAddr, u8DataIn); return FALSE; } } /* Read */ for(u32NORAddr = 0; u32NORAddr < EBI_MAX_SIZE; u32NORAddr++) { u8DataIn = (u32NORAddr % 256) + u32NORAddr; u8DataOut = NOR_ReadData(u32NORAddr); if(u8DataOut != u8DataIn) { printf("Read [0x%05X]:[0x%02X] FAIL !!! (Got [0x%02X]) \n\n", u32NORAddr, u8DataIn, u8DataOut); printf("Program flash FAIL !!! \n\n"); return FALSE; } } printf(" >> Continue Data Program OK !!! \n\n"); return TRUE; }
/** * @brief Check Command Complete * * @param[in] u32Addr The address to read out data to check if command complete * @param[in] u8Data The data to be compared with the read out data * * @retval FALSE Command fail * @retval TRUE Command complete * * @details Check if the specified command is complete or not. */ uint8_t NOR_CheckCMDComplete(uint32_t u32Addr, uint8_t u8Data) { /* Using Data Polling Algorithm to check if command is complete or not */ uint8_t u8CurData; volatile uint32_t u32TimeOutCnts = 0; /* Command timeout period is 200 ms */ u8Data = u8Data & (1 << 7); // read D7 while(u32TimeOutCnts < 200000) { u8CurData = NOR_ReadData(u32Addr); u8CurData = u8CurData & (1 << 7); // read DQ7 if(u8Data == u8CurData) { return TRUE; } CLK_SysTickDelay(1); u32TimeOutCnts++; } return FALSE; }
/*---------------------------------------------------------------------------------------------------------*/ int main (void) { uint8_t u8Item = 0x0; uint32_t u32NORIDInfo; uint32_t u32i; uint8_t u8ReadOutData; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("+------------------------------------+\n"); printf("| M05xx EBI Driver Sample Code |\n"); printf("+------------------------------------+\n"); printf("\n"); do { printf("*****************************************************************\n"); printf("* Please connect BS616LV4017 or W39L010 to M051 Series EBI bus *\n"); printf("* before EBI testing!! *\n"); printf("* *\n"); printf("* The testing result will be FAILED, if there is no BS616LV4017 *\n"); printf("* or W39L010 connecting to M051 sereis EBI bus! *\n"); printf("*****************************************************************\n"); printf("\n"); printf("| >>> Selese item to test <<< |\n"); printf("| [0] SRAM --- BS616LV4017, 16bit |\n"); printf("| [1] NOR --- W39L010, 8bit |\n"); printf("| [ESC] Exit |\n"); u8Item = getchar(); printf("\n"); switch (u8Item) { case '0': /* Enable EBI function and data width 16-bit, MCLK is HCLK/4 */ EBI->EBICON = EBI_EBICON_ExtEN_Msk | EBI_EBICON_ExtBW16_Msk | EBI_EBICON_MCLKDIV_4; /* Start SRAM test */ SRAM_BS616LV4017(); /* Disable EBI function */ EBI->EBICON = 0; break; case '1': /* Enable EBI function and data width 8-bit, MCLK is HCLK/4 */ EBI->EBICON = EBI_EBICON_ExtEN_Msk | EBI_EBICON_MCLKDIV_4; /* Initial NOR flash and check ID */ NOR_Init(); u32NORIDInfo = NOR_GetID(); if (u32NORIDInfo == 0xDA31) { printf("NOR W39L010 initial OK ! ManufactureID:0x%X, DeviceID:0x%X. \n", (u32NORIDInfo>>8), (u32NORIDInfo&0xFF)); }else { printf("NOR W39L010 initial fail ! (ID:0x%X) \n\n", u32NORIDInfo); break; } /* Erase flash */ NOR_Erase(); for (u32i=0; u32i<EBI_MAX_SIZE; u32i++) { u8ReadOutData = NOR_ReadData(u32i); if (u8ReadOutData != 0xFF) { printf(" >> Chip Erase Fail !! Addr:0x%X, Data:0x%X. \n\n", u32i, u8ReadOutData); break; } } printf(" >> Chip Erase OK !!! \n"); /* Start to program NOR flash test */ ProgramContinueDataTest(); /* Disable EBI function */ EBI->EBICON = 0; break; }