int main() { uint32_t i, u32Data; /* Unlock protected registers */ SYS_UnlockReg(); SYS_Init(); UART_Init(); /* This sample code is used to show how to use StdDriver API to implement ISP functions. */ printf("\n\n"); printf("+----------------------------------------+\n"); printf("| NUC029xDE FMC Sample Code |\n"); printf("+----------------------------------------+\n"); //SYS_UnlockReg(); /* Enable FMC ISP function */ FMC_Open(); if(SetDataFlashBase(DATA_FLASH_TEST_BASE) < 0) { printf("Failed to set Data Flash base address!\n"); goto lexit; } /* Read BS */ printf(" Boot Mode ............................. "); if(FMC_GetBootSource() == 0) printf("[APROM]\n"); else { printf("[LDROM]\n"); printf(" WARNING: The driver sample code must execute in AP mode!\n"); goto lexit; } u32Data = FMC_ReadCID(); printf(" Company ID ............................ [0x%08x]\n", u32Data); u32Data = FMC_ReadDID(); printf(" Device ID ............................. [0x%08x]\n", u32Data); u32Data = FMC_ReadPID(); printf(" Product ID ............................ [0x%08x]\n", u32Data); for(i = 0; i < 3; i++) { u32Data = FMC_ReadUID(i); printf(" Unique ID %d ........................... [0x%08x]\n", i, u32Data); } for(i = 0; i < 4; i++) { u32Data = FMC_ReadUCID(i); printf(" Unique Customer ID %d .................. [0x%08x]\n", i, u32Data); } /* Read User Configuration */ printf(" User Config 0 ......................... [0x%08x]\n", FMC_Read(FMC_CONFIG_BASE)); printf(" User Config 1 ......................... [0x%08x]\n", FMC_Read(FMC_CONFIG_BASE + 4)); /* Read Data Flash base address */ u32Data = FMC_ReadDataFlashBaseAddr(); printf(" Data Flash Base Address ............... [0x%08x]\n", u32Data); printf("\n\nLDROM test =>\n"); FMC_EnableLDUpdate(); if(FlashTest(FMC_LDROM_BASE, FMC_LDROM_BASE + FMC_LDROM_SIZE, TEST_PATTERN) < 0) { printf("\n\nLDROM test failed!\n"); goto lexit; } FMC_DisableLDUpdate(); printf("\n\nAPROM test =>\n"); FMC_EnableAPUpdate(); if(FlashTest(APROM_TEST_BASE, APROM_TEST_END, TEST_PATTERN) < 0) { printf("\n\nAPROM test failed!\n"); goto lexit; } FMC_DisableAPUpdate(); printf("\n\nData Flash test =>\n"); if(FlashTest(DATA_FLASH_TEST_BASE, DATA_FLASH_TEST_END, TEST_PATTERN) < 0) { printf("\n\nUHB test failed!\n"); goto lexit; } lexit: /* Disable FMC ISP function */ FMC_Close(); /* Lock protected registers */ SYS_LockReg(); printf("\nFMC Sample Code Completed.\n"); while(1); }
int main() { uint32_t i, u32Data; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); /*---------------------------------------------------------------------------------------------------------*/ /* SAMPLE CODE */ /*---------------------------------------------------------------------------------------------------------*/ printf("\n\nCPU @ %dHz\n", SystemCoreClock); SYS_UnlockReg(); /* Enable FMC ISP function */ FMC_Open(); if (set_data_flash_base(DATA_FLASH_TEST_BASE) < 0) { printf("Failed to set Data Flash base address!\n"); goto lexit; } /* Read BS */ printf(" Boot Mode ............................. "); if (FMC_GetBootSource() == 0) printf("[APROM]\n"); else { printf("[LDROM]\n"); printf(" WARNING: The driver sample code must execute in AP mode!\n"); goto lexit; } u32Data = FMC_ReadCID(); printf(" Company ID ............................ [0x%08x]\n", u32Data); u32Data = FMC_ReadPID(); printf(" Product ID ............................ [0x%08x]\n", u32Data); for (i = 0; i < 3; i++) { u32Data = FMC_ReadUID(i); printf(" Unique ID %d ........................... [0x%08x]\n", i, u32Data); } for (i = 0; i < 4; i++) { u32Data = FMC_ReadUCID(i); printf(" Unique Customer ID %d .................. [0x%08x]\n", i, u32Data); } /* Read User Configuration */ printf(" User Config 0 ......................... [0x%08x]\n", FMC_Read(FMC_CONFIG_BASE)); printf(" User Config 1 ......................... [0x%08x]\n", FMC_Read(FMC_CONFIG_BASE+4)); /* Read Data Flash base address */ u32Data = FMC_ReadDataFlashBaseAddr(); printf(" Data Flash Base Address ............... [0x%08x]\n", u32Data); printf("\n\nLDROM test =>\n"); FMC_ENABLE_LD_UPDATE(); if (flash_test(FMC_LDROM_BASE, FMC_LDROM_END, TEST_PATTERN) < 0) { printf("\n\nLDROM test failed!\n"); goto lexit; } FMC_DISABLE_LD_UPDATE(); printf("\n\nAPROM test =>\n"); FMC_ENABLE_AP_UPDATE(); if (flash_test(APROM_TEST_BASE, DATA_FLASH_TEST_BASE, TEST_PATTERN) < 0) { printf("\n\nAPROM test failed!\n"); goto lexit; } FMC_DISABLE_AP_UPDATE(); printf("\n\nData Flash test =>\n"); if (flash_test(DATA_FLASH_TEST_BASE, DATA_FLASH_TEST_END, TEST_PATTERN) < 0) { printf("\n\nUHB test failed!\n"); goto lexit; } lexit: /* Disable FMC ISP function */ FMC_Close(); /* Lock protected registers */ SYS_LockReg(); printf("\nFMC Sample Code Completed.\n"); while (1); }
/*---------------------------------------------------------------------------------------------------------*/ int32_t main (void) { uint8_t ch; uint32_t u32Data; /* Init System, IP clock and multi-function I/O */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); /* Unlock protected registers for ISP function */ SYS_UnlockReg(); /* Enable ISP function */ FMC->ISPCON |= FMC_ISPCON_ISPEN_Msk; /* Check the signature to check if Simple LD code is finished or not */ if (inp32(KEY_ADDR) == SIGNATURE) { /* Just clear SIGNATURE and finish the sample code if Simple LD code has been executed. */ outp32(KEY_ADDR, 0); /* Read BS */ printf(" Boot Mode .................................. "); if ((FMC->ISPCON & FMC_ISPCON_BS_Msk) == FMC_ISPCON_BS_APROM) printf("[APROM]\n"); else { printf("[LDROM]\n"); printf(" WARNING: The driver sample code must execute in AP mode!\n"); } goto lexit; } /* This sample code will demo some function about FMC: 1. Check if CPU boots from APROM 2. Read 96-bit UID 3. Erase LDROM, program LD sample code to LDROM, and verify LD sample code 4. Select next booting from LDROM and run LD sample code */ printf("\n\n"); printf("+--------------------------------------------------------+\n"); printf("| M05xx Flash Memory Controller Driver Sample Code |\n"); printf("+--------------------------------------------------------+\n"); printf("\nCPU @ %dHz\n\n", SystemCoreClock); /* Read BS */ printf(" Boot Mode .................................. "); if ((FMC->ISPCON & FMC_ISPCON_BS_Msk) == FMC_ISPCON_BS_APROM) printf("[APROM]\n"); else { printf("[LDROM]\n"); printf(" WARNING: The driver sample code must execute in AP mode!\n"); goto lexit; } /* Read UID */ printf(" UID[ 0:31] ................................. [0x%x]\n", FMC_ReadUID(0)); printf(" UID[32:63] ................................. [0x%x]\n", FMC_ReadUID(1)); printf(" UID[64:95] ................................. [0x%x]\n", FMC_ReadUID(2)); /* Read Data Flash base address */ printf(" Data Flash Base Address .................... [0x%x]\n", FMC->DFBADR); /* Check the data in LD ROM to avoid overwrite them */ u32Data = FMC_Read(FMC_LDROM_BASE); if (u32Data != 0xFFFFFFFF) { printf("\n WARNING: There is code in LD ROM.\n If you proceed, the code in LD ROM will be corrupted.\n"); printf(" Continue? [y/n]:"); ch = getchar(); putchar(ch); if (ch != 'y') goto lexit; printf("\n\n"); } /* Check LD image size */ g_u32ImageSize = (uint32_t)&loaderImageLimit - (uint32_t)&loaderImageBase; if (g_u32ImageSize == 0) { printf(" ERROR: Loader Image is 0 bytes!\n"); goto lexit; } if (g_u32ImageSize > FMC_LDROM_SIZE) { printf(" ERROR: Loader Image is larger than 4KBytes!\n"); goto lexit; } /* Erase LDROM, program LD sample code to LDROM, and verify LD sample code */ /* The chip will boot from LDROM and run LD sample code if LD sample code is downloaded successfully */ FMC_LDROM_Test(); lexit: /* Disable ISP function */ FMC->ISPCON &= ~FMC_ISPCON_ISPEN_Msk; /* Lock protected registers */ SYS_LockReg(); printf("\nFMC Sample Code Completed.\n"); }