/******************************************************************************* * Function Name : main. * Description : main routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ int main(void) { GPIO_InitTypeDef GPIO_InitStructure; NAND_IDTypeDef NAND_Id; NAND_ADDRESS NAND_Address; int i=0; #ifdef DEBUG debug(); #endif Set_System(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); Serial_Init(); NAND_Init(); NAND_Reset(); NAND_ReadID(&NAND_Id); Get_Medium_Characteristics(); Set_USBClock(); USB_Interrupts_Config(); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_Init(GPIOC, &GPIO_InitStructure); USB_Init(); while (1) { } }
/******************************************************************************* * Function Name : MAL_Init * Description : Initializes the Media on the STM32 * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t MAL_Init(uint8_t lun) { uint16_t status = MAL_OK; switch (lun) { case 0: #ifdef USE_STM3210E_EVAL Status = SD_Init(); Status = SD_GetCardInfo(&SDCardInfo); Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); Status = SD_SetDeviceMode(SD_DMA_MODE); #else MSD_Init(); #endif break; #ifdef USE_FSMC_NAND case 1: status = NAND_Init(); break; #endif default: return MAL_FAIL; } return status; }
/******************************************************************************* * Function Name : MAL_Init * Description : Initializes the Media on the STM32 * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t MAL_Init(uint8_t lun) { uint16_t status = MAL_OK; switch (lun) { case 0: #ifdef USE_STM3210E_EVAL Status = SD_Init(); Status = SD_GetCardInfo(&SDCardInfo); Status = SD_SelectDeselect((uint32_t) (SDCardInfo.RCA << 16)); Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); Status = SD_SetDeviceMode(SD_DMA_MODE); if (Status == SD_OK) { //Status = SD_ReadMultiBlocks(0x00, Buffer_MultiBlock_Rx, BlockSize, NumberOfBlocks1); // printf("\r\nSD SDIO-4bit模式 测试TF卡读写成功! \n "); } if (Status == SD_OK) { // Read block of 512 bytes from address 0 Status = SD_ReadBlock(0x00, Buffer_Block_Rx, BlockSize); } if (Status == SD_OK) { // Check the corectness of written dada printf("\r\nSD SDIO-4bit模式 测试TF卡读写成功! \n "); } #else MSD_Init(); #endif break; #ifdef USE_STM3210E_EVAL case 1: status = NAND_Init(); break; #endif default: return MAL_FAIL; } return status; }
DSTATUS disk_initialize ( BYTE drv /* Physical drive nmuber (0..) */ ) { if(NAND_Init()== NAND_OK) return RES_OK; else return RES_ERROR; }
void I2S_PCMOutDMA(AUDIO_PORT rhs_ePort) { UART_Printf("\nPlay Wave File.\n"); // Data From NAND #ifdef I2SFROMNAND NAND_Inform[0].uNandType = NAND_Normal8bit; NAND_Inform[0].uAddrCycle = 4; NAND_Inform[0].uBlockNum = 4096; NAND_Inform[0].uPageNum = 32; NAND_Inform[0].uPageSize = NAND_PAGE_512; NAND_Inform[0].uSpareSize = NAND_SPARE_16; NAND_Inform[0].uECCtest = 0; NAND_Inform[0].uTacls =30; NAND_Inform[0].uTwrph0 = 35+30; //Pad delay : about 10ns NAND_Inform[0].uTwrph1 = 15+35; //tWH : 15ns NAND_Inform[0].uSpareECC =0; NAND_Inform[0].uSpareECCtest =0; NAND_Init(0); NAND_ReadMultiPage(0, 1000, 0, (u8 *)0x51000000, 21690392); #endif if ((g_oI2SInfor[rhs_ePort].m_CLKSRC != I2S_EXTERNALCDCLK) && (g_oI2SInfor[rhs_ePort].m_eOpMode == Master)) { I2S_CDCLKOut(rhs_ePort); } else if ((g_oI2SInfor[rhs_ePort].m_CLKSRC == I2S_FIN) && (g_oI2SInfor[rhs_ePort].m_eOpMode == Slave)) { I2S_CDCLKOut(rhs_ePort); //12MHz Out } else if ((g_oI2SInfor[rhs_ePort].m_CLKSRC != I2S_EXTERNALCDCLK) && (g_oI2SInfor[rhs_ePort].m_CLKSRC != I2S_FIN) && (g_oI2SInfor[rhs_ePort].m_eOpMode == Slave)) { if ( g_oI2SInfor[rhs_ePort].m_dSamplingFreq % 11025) I2S_SetEpllCDCLKOut(rhs_ePort, I2S_USERCLKOUT2); // 11.2896MHz Out else I2S_SetEpllCDCLKOut(rhs_ePort, I2S_USERCLKOUT1); // 12.288MHz Out } #if (I2S_CODEC == WM8753) WM8753_CodecInitPCMOut(g_oI2SInfor[rhs_ePort].m_eDataFormat, (u32) g_oI2SInfor[rhs_ePort].m_dSamplingFreq, g_oI2SInfor[rhs_ePort].m_eOpMode, g_oI2SInfor[rhs_ePort].m_eWordLength, SMDK_I2S); #elif (I2S_CODEC == WM8990) WM8990_CodecInitPCMOut(g_oI2SInfor[rhs_ePort].m_eDataFormat, (u32) g_oI2SInfor[rhs_ePort].m_dSamplingFreq, g_oI2SInfor[rhs_ePort].m_eOpMode, g_oI2SInfor[rhs_ePort].m_eWordLength, SMDK_I2S); #elif (I2S_CODEC == WM8580) WM8580_CodecInitPCMOut(g_oI2SInfor[rhs_ePort].m_eDataFormat, (u32) g_oI2SInfor[rhs_ePort].m_dSamplingFreq, g_oI2SInfor[rhs_ePort].m_eOpMode, g_oI2SInfor[rhs_ePort].m_eWordLength, SMDK_I2S); #endif I2SMOD_SetTXR(rhs_ePort, TXOnly); I2S_DataOutDMAStart(rhs_ePort); I2S_DataOutDMAStop(rhs_ePort); }
/******************************************************************************* * Function Name : MAL_Init * Description : Initializes the Media on the STM32 * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t MAL_Init(uint8_t lun) { uint16_t status = MAL_OK; switch (lun) { case 0: break; case 1: NAND_Init(); break; default: return MAL_FAIL; } return status; }
uint16_t MAL_Init(uint8_t lun) { uint16_t status = MAL_OK; switch (lun) { case 0: Status = SD_Init(); break; #ifdef USE_STM3210E_EVAL case 1: NAND_Init(); break; #endif default: return MAL_FAIL; } return status; }
/******************************************************************************* * Function Name : MAL_Init * Description : Initializes the Media on the STM32 * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t MAL_Init(uint8_t lun) { uint16_t status = MAL_OK; switch (lun) { case 0: Status = SD_Init(); Status = SD_GetCardInfo(&SDCardInfo); Status = SD_SelectDeselect((u32) (SDCardInfo.RCA << 16)); Status = SD_EnableWideBusOperation(SDIO_BusWide_4b); Status = SD_SetDeviceMode(SD_DMA_MODE); break; case 1: status = NAND_Init(); break; default: return MAL_FAIL; } return status; }
/******************************************************************************* * Function Name : MAL_Init * Description : Initializes the Media on the STM32 * Input : None * Output : None * Return : None *******************************************************************************/ uint16_t MAL_Init(uint8_t lun) { uint16_t status = MAL_OK; switch (lun) { case 0: Status = disk_initialize(0);/* Physical drive number (0) */ if(Status) Status = disk_initialize(0);/*Try again on error*/ if(!Status && !Data_Buffer) Data_Buffer=(volatile uint32_t*)malloc(MAX_DMA_BUFF_SIZE);/*Allocate the data buffer*/ break; #ifdef USE_STM3210E_EVAL case 1: NAND_Init(); break; #endif default: return MAL_FAIL; } return status; }
VOID BSPPowerOn() { OALMSG(OAL_FUNC, (TEXT("++BSPPowerOn()\n"))); // The OEM can add BSP specific procedure here when system power up //---------------------------- // Wake Up Source Determine //---------------------------- S3C6410_WakeUpSource_Detect(); #ifdef _IROM_SDMMC_ if (!BootDeviceInit()) { OALMSG(OAL_ERROR, (TEXT("[OAL:ERR] BootDeviceInit() returned FALSE\r\n"))); } #endif // NAND Controller Initialize NAND_Init(); PWRCTL_Awake(); OALMSG(OAL_FUNC, (TEXT("--BSPPowerOn()\n"))); }
void main(void) { register nPage; unsigned char *pBuf; unsigned char ucDID, ucHID; unsigned char nCnt; unsigned char uNumOfLoadPage = LOAD_PAGE_SIZE; BOOL b4KPage = FALSE; // Set up copy section (initialized globals). // // NOTE: after this call, globals become valid. // // SetupCopySection(pTOC); // Enable the ICache. // MMU_EnableICache(); // Set up all GPIO ports. Port_Init(); #ifdef DEBUGUART // UART initialize Uart_Init(); //Uart_SendString("\r\n\r\nWince 5.0 1st NAND Bootloader (NBL1) for SMDK2443\r\n"); // Initialize the NAND flash interface. Uart_SendString("NAND Initialize\r\n"); #endif NAND_Init(); Read_DeviceID(0, &ucDID, &ucHID); #ifdef DEBUGUART Uart_SendString("Device ID : 0x"); Uart_SendBYTE(ucDID, 1); Uart_SendString("Hidden ID : 0x"); Uart_SendBYTE(ucHID, 1); #endif if ( (ucDID == 0xd5 && ucHID == 0x14) || (ucDID == 0xd5 && ucHID == 0x94) || (ucDID == 0xd7 && ucHID == 0x55) || (ucDID == 0xd7 && ucHID == 0xD5) // for MLC || (ucDID == 0xd3 && ucHID == 0x10)) // for SLC { b4KPage = TRUE; uNumOfLoadPage = LOAD_PAGE_SIZE/2; } // Turn the LEDs off. Led_Display(0x0); pBuf = (unsigned char *)LOAD_ADDRESS_PHYSICAL; // MLC // Page 0, 1 : Steploader // Page 2 ~ 5 : empty page // Page 6 ~ PAGES_PER_BLOCK-3 : effective page // read pages with 0, 1 and 6 to PAGES_PER_BLOCK-3 nPage = 10; for (nCnt = 0; nCnt < uNumOfLoadPage; nCnt++) { #ifdef OMNIBOOK_VER Led_Display(0x1); #else //!OMNIBOOK_VER Led_Display(0x2); #endif OMNIBOOK_VER if (nPage >= (NAND_PAGE_PER_BLOCK-2) || (NAND_Read(0, nPage, pBuf, b4KPage) == FALSE)) { #ifdef DEBUGUART // Uncorrectable ECC Error Uart_SendString("ECC Error @ Page 0x"); Uart_SendBYTE(nPage, 1); #endif #ifdef OMNIBOOK_VER Led_Display(0x0); #else //!OMNIBOOK_VER Led_Display(0x9); #endif OMNIBOOK_VER while(1); } nPage++; if (b4KPage == TRUE) pBuf += NAND_BYTE_PER_PAGE*2; else pBuf += NAND_BYTE_PER_PAGE; #ifdef OMNIBOOK_VER Led_Display(0x2); #else //!OMNIBOOK_VER Led_Display(0x4); #endif OMNIBOOK_VER } //Uart_SendString("Jump to 2nd Bootloader...\r\n"); // Uart_SendDWORD(LOAD_ADDRESS_PHYSICAL, 1); // Turn the LEDs on. // #ifdef OMNIBOOK_VER Led_Display(0x3); #else //!OMNIBOOK_VER Led_Display(0x5); #endif OMNIBOOK_VER #ifdef DEBUGUART Uart_SendString("Jump to 2nd Bootloader...\r\n"); #endif ((PFN_IMAGE_LAUNCH)(LOAD_ADDRESS_PHYSICAL))(); }
void main(void) { register nBlock; register nPage; register nBadBlocks; volatile unsigned char *pBuf; // Set up copy section (initialized globals). // // NOTE: after this call, globals become valid. // SetupCopySection(pTOC); // Enable the ICache. //System_EnableICache(); // I-Cache was already enabled in startup.s // Set up all GPIO ports for LED. //Port_Init(); //Led_Display(0xf); // UART Initialize #if UART_DEBUG Uart_Init(); Uart_SendString("\r\nWinCE 6.0 Steploader for SMDK6410\r\n"); // Initialize the NAND flash interface. Uart_SendString("NAND Initialize\n\r"); #endif g_bLargeBlock = NAND_Init(); // Copy image from NAND flash to RAM. pBuf = (unsigned char *)LOAD_ADDRESS_PHYSICAL; nBadBlocks = 0; //Led_Display(0x4); for (nPage = LOAD_IMAGE_PAGE_OFFSET; nPage < (LOAD_IMAGE_PAGE_OFFSET + LOAD_IMAGE_PAGE_COUNT) ; nPage++) { //Led_Display(0x1); nBlock = ((nPage / NAND_PAGES_PER_BLOCK) + nBadBlocks); if (!NAND_ReadPage(nBlock, (nPage % NAND_PAGES_PER_BLOCK), pBuf)) { if ((nPage % NAND_PAGES_PER_BLOCK) != 0) { //Led_Display(0x9); // real ECC Error. #if UART_DEBUG Uart_SendString("ECC Error.\r\n"); #endif while(1) { // Spin forever... } } // ECC error on a block boundary is (likely) a bad block - retry the page 0 read on the next block. nBadBlocks++; nPage--; continue; } pBuf += NAND_BYTES_PER_PAGE; } //Led_Display(0x6); #if UART_DEBUG Uart_SendString("Launch Eboot...\n\r"); #endif ((PFN_IMAGE_LAUNCH)(LOAD_ADDRESS_PHYSICAL))(); }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ /* Initialize Leds mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); /* Enable the FSMC Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* FSMC Initialization */ NAND_Init(); /* NAND read ID command */ NAND_ReadID(&NAND_ID); /* Verify the NAND ID */ if((NAND_ID.Maker_ID == NAND_ST_MakerID) && (NAND_ID.Device_ID == NAND_ST_DeviceID)) { /* NAND memory address to write to */ WriteReadAddr.Zone = 0x00; WriteReadAddr.Block = 0x00; WriteReadAddr.Page = 0x00; /* Erase the NAND first Block */ status = NAND_EraseBlock(WriteReadAddr); /* Write data to FSMC NAND memory */ /* Fill the buffer to send */ Fill_Buffer(TxBuffer, BUFFER_SIZE , 0x66); status = NAND_WriteSmallPage(TxBuffer, WriteReadAddr, PageNumber); /* Read back the written data */ status = NAND_ReadSmallPage (RxBuffer, WriteReadAddr, PageNumber); /* Verify the written data */ for(j = 0; j < BUFFER_SIZE; j++) { if(TxBuffer[j] != RxBuffer[j]) { WriteReadStatus++; } } if (WriteReadStatus == 0) { /* OK */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* KO */ /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } } else { /* Turn on LED3 */ STM_EVAL_LEDOn(LED3); } while(1) { } }
void Redbull_Init() { char buff[128] = { 0 }; USART_STDIO_Init(); Delay_Init(); Button_GPIO_Config(); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); STM3210E_LCD_Init(); LCD_SetFont(&Font8x12); LCD_SetColors(LCD_COLOR_WHITE, LCD_COLOR_BLACK); LCD_WriteRAM_Prepare(); for (int i = 0; i < (320 * 240); i++) { LCD_WriteRAM(LCD_COLOR_WHITE); } for (int i = 0; i < (320 * 240); i++) { LCD_WriteRAM(LCD_COLOR_BLACK); } LCD_DisplayStringLine(LINE(0), (uint8_t*) " initializing REDBULL"); LCD_DisplayStringLine(LINE(1), (uint8_t*) " CPU ..............................."); sprintf(buff, "ARM Cortex-M3 @ %dMHz", (int) SystemCoreClock / 1000000); printRight(1, buff); LCD_DisplayStringLine(LINE(2), (uint8_t*) " LCD ............................320x240"); LCD_DisplayStringLine(LINE(3), (uint8_t*) " LED .................................."); LED_Init(); toggleLED(LED1_PIN, 0); toggleLED(LED2_PIN, LED1_PIN); toggleLED(LED3_PIN, LED2_PIN); toggleLED(LED4_PIN, LED3_PIN); toggleLED(LED5_PIN, LED4_PIN); toggleLED(LED4_PIN, LED5_PIN); toggleLED(LED3_PIN, LED4_PIN); toggleLED(LED2_PIN, LED3_PIN); toggleLED(LED1_PIN, LED2_PIN); toggleLED(0, LED1_PIN); printRight(3, "5"); LCD_DisplayStringLine(LINE(4), (uint8_t*) " RTC ................"); RTC_Init(); RTC_t rtc = { .year = 2011, .month = 12, .mday = 19, .hour = 21, .min = 00 }; //RTC_SetTime(&rtc); RTC_GetTime(&rtc); sprintf(buff, "%04d/%02d/%02d %02d:%02d:%02d", rtc.year, rtc.month, rtc.mday, rtc.hour, rtc.min, rtc.sec); printRight(4, buff); LCD_DisplayStringLine(LINE(5), (uint8_t*) " USB ................................."); Set_USBClock(); Set_System(); USB_Interrupts_Config(); USB_Init(); printRight(5, "ok"); //IS61LV25616 (512KB) LCD_DisplayStringLine(LINE(6), (uint8_t*) " SRAM ................................"); SRAM_Init(); uint32_t* RAM = (uint32_t*) Bank1_SRAM3_ADDR; uint8_t TESTOK = 1; for (uint32_t i = 0; i < (512 * 1024) / 4; i++) { RAM[i] = i; } for (uint32_t i = 0; i < (512 * 1024) / 4; i++) { if (RAM[i] != i) { TESTOK = 0; } RAM[i] = 0; } if (TESTOK) { printRight(6, "IS61LV25616 512KB"); } else { printRight(6, "fail"); } //M29W128F (2MB) LCD_DisplayStringLine(LINE(7), (uint8_t*) " NOR ................................."); NOR_Init(); NOR_IDTypeDef norid; NOR_ReadID(&norid); printRight(7, "MX29LV160D 2MB"); //HY27UF081G2A (128MB) LCD_DisplayStringLine(LINE(8), (uint8_t*) " NAND ................................"); NAND_Init(); NAND_IDTypeDef nandid; NAND_ReadID(&nandid); printRight(8, "HY27UF081G2A 128MB"); LCD_DisplayStringLine(LINE(9), (uint8_t*) " SDIO ................................"); SD_Init(); SD_CardInfo cardinfo; SD_GetCardInfo(&cardinfo); printRight(9, "ok"); }