/* ********************************************************************************************************* * 函 数 名: bsp_InitNorFlash * 功能说明: 配置连接外部NOR Flash的GPIO和FSMC * 形 参: 无 * 返 回 值: 无 ********************************************************************************************************* */ void bsp_InitNorFlash(void) { FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef p; GPIO_InitTypeDef GPIO_InitStructure; uint32_t ChipID; Mem_Set(&GPIO_InitStructure, 0x00, sizeof(GPIO_InitTypeDef)); Mem_Set(&FSMC_NORSRAMInitStructure, 0x00, sizeof(FSMC_NORSRAMInitTypeDef)); Mem_Set(&p, 0x00, sizeof(FSMC_NORSRAMTimingInitTypeDef)); /* 使能GPIO时钟 */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE | RCC_AHB1Periph_GPIOF | RCC_AHB1Periph_GPIOG, ENABLE); /* 使能 FSMC 时钟 */ RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); /* NOR Flash 的 GPIO : PD0/FSMC_D2 PD1/FSMC_D3 PD4/FSMC_NOE PD5/FSMC_NWE PD6/FSMC_NWAIT - 忙信号,配置为GPIO,输入模式,通过软件查询方式判忙 PD8/FSMC_D13 PD9/FSMC_D14 PD10/FSMC_D15 PD11/FSMC_CLE/FSMC_A16 PD12/FSMC_ALE/FSMC_A17 PD13/FSMC_A18 PD14/FSMC_D0 PD15/FSMC_D1 PE3/FSMC_A19 PE4/FSMC_A20 PE5/FSMC_A21 PE6/FSMC_A22 PE7/FSMC_D4 PE8/FSMC_D5 PE9/FSMC_D6 PE10/FSMC_D7 PE11/FSMC_D8 PE12/FSMC_D9 PE13/FSMC_D10 PE14/FSMC_D11 PE15/FSMC_D12 PF0/FSMC_A0 PF1/FSMC_A1 PF2/FSMC_A2 PF3/FSMC_A3 PF4/FSMC_A4 PF5/FSMC_A5 PF12/FSMC_A6 PF13/FSMC_A7 PF14/FSMC_A8 PF15/FSMC_A9 PG0/FSMC_A10 PG1/FSMC_A11 PG2/FSMC_A12 PG3/FSMC_A13 PG4/FSMC_A14 PG5/FSMC_A15 PG9/FSMC_NE2 - 片选信号 */ /* GPIOD configuration */ GPIO_PinAFConfig(GPIOD, GPIO_PinSource0, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource1, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource4, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource8, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource9, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource10, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource11, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); /* GPIOE configuration */ GPIO_PinAFConfig(GPIOE, GPIO_PinSource3 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource4 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource5 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource7 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource8 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource9 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource10 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource11 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource12 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource13 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource14 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOE, GPIO_PinSource15 , GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11| GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOE, &GPIO_InitStructure); /* GPIOF configuration */ GPIO_PinAFConfig(GPIOF, GPIO_PinSource0 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource1 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource2 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource3 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource4 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource5 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource12 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource13 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource14 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOF, GPIO_PinSource15 , GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_Init(GPIOF, &GPIO_InitStructure); /* GPIOG configuration */ GPIO_PinAFConfig(GPIOG, GPIO_PinSource0 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource1 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource2 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource3 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource4 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource5 , GPIO_AF_FSMC); GPIO_PinAFConfig(GPIOG, GPIO_PinSource9 , GPIO_AF_FSMC); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_9; GPIO_Init(GPIOG, &GPIO_InitStructure); /* PD6 作为忙信号, 配置为GPIO输入模式,软件查询 */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; /* 输入模式 */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); /*-- FSMC Configuration ------------------------------------------------------*/ p.FSMC_AddressSetupTime = 0x06; /* 0x05正常, 0x04 出错 */ p.FSMC_AddressHoldTime = 0x01; p.FSMC_DataSetupTime = 0x0C; /* 0x0B正常, 0x0A 出错 */ p.FSMC_BusTurnAroundDuration = 0x00; p.FSMC_CLKDivision = 0x00; p.FSMC_DataLatency = 0x00; p.FSMC_AccessMode = FSMC_AccessMode_B; FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_NOR; FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); /*!< Enable FSMC Bank1_SRAM2 Bank */ FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); #if debug_enable ChipID = NOR_ReadID(); if(ChipID == 0x017E0A00) { printf("NorFlash ID = %x, Model = S29JL032H \r\n", ChipID); } #endif }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /* Periph clock enable */ RCC_Configuration(); /* Config the LED GPIO */ LED_Configuration(); /* Config the USART1 */ USART1_Configuration(); printf("NOR Flash Init!\n\r"); /* EXMC nor flash init */ EXMC_NorFlash_Init(); /* Read Nor Flash ID and printf */ NOR_ReadID(&NOR_ID); printf("\n\rNor Flash ID:0x%X 0x%X 0x%X 0x%X\n\r",NOR_ID.Manufacturer_Code,NOR_ID.Device_Code, NOR_ID.Block_Protection_Indicator,NOR_ID.Block_Protection_Status); NOR_ReturnToReadMode(); /* Erase the nor flash block to be written data */ Status = NOR_EraseBlock(WRITE_READ_ADDR); if(NOR_SUCCESS == Status) { printf("\n\rErase nor flash block successfully!\n\r"); } else { printf("\n\rErase nor flash block failure!\n\r"); } /* Whether address cross-border */ if((WRITE_READ_ADDR + BUFFER_SIZE ) > NOR_MAX_ADDRESS) { printf("\n\rAddress cross-border\n\r"); GPIO_SetBits(LED_GPIO, LED4_PIN | LED5_PIN); while(1) { } } /* Fill WriteBuffer with the specified value */ Fill_Buffer(WriteBuffer, BUFFER_SIZE, 0x1234); /* Write data to nor flash, WRITE_READ_ADDR: the starting address of the write data */ Status = NOR_WriteBuffer(WriteBuffer, WRITE_READ_ADDR, BUFFER_SIZE); if(NOR_SUCCESS == Status) { printf("\n\rWrite data to nor flash block successfully!\n\r"); } else { printf("\n\rWrite data to nor flash block failure!\n\r"); } /* Read data from nor flash, WRITE_READ_ADDR: the starting address of the read data*/ NOR_ReadBuffer(ReadBuffer, WRITE_READ_ADDR, BUFFER_SIZE); /* Read and write data comparison for equality */ WriteReadStatus = 0; for (Index = 0x00; Index < BUFFER_SIZE; Index++) { if (ReadBuffer[Index] != WriteBuffer[Index]) { WriteReadStatus++; break; } } printf("\n\rThe result to access the nor flash:\n\r"); if (WriteReadStatus == 0) { printf("\n\rAccess nor flash successfully!\n\r"); GPIO_SetBits(LED_GPIO, LED2_PIN | LED3_PIN | LED4_PIN | LED5_PIN); } else { printf("\n\rAccess nor flash failure!\n\r"); GPIO_SetBits(LED_GPIO, LED2_PIN | LED3_PIN); } printf("\n\rPrintf data to be read: \n\r"); printf("\n\r"); for(Index = 0; Index < BUFFER_SIZE; Index++) { printf("%X ",ReadBuffer[Index]); } while(1) { } }
/** * @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_stm32l1xx_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32l1xx.c file */ /* Initialize Leds mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); /* Write/read to/from FSMC SRAM memory *************************************/ /* Enable the FSMC Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* Configure FSMC Bank1 NOR/SRAM2 */ NOR_Init(); /* Read NOR memory ID */ NOR_ReadID(&NOR_ID); NOR_ReturnToReadMode(); /* Erase the NOR memory block to write on */ NOR_EraseBlock(WRITE_READ_ADDR); /* Write data to FSMC NOR memory */ /* Fill the buffer to send */ Fill_Buffer(TxBuffer, BUFFER_SIZE, 0x3210); NOR_WriteBuffer(TxBuffer, WRITE_READ_ADDR, BUFFER_SIZE); /* Read data from FSMC NOR memory */ NOR_ReadBuffer(RxBuffer, WRITE_READ_ADDR, BUFFER_SIZE); /* Read back NOR memory and check content correctness */ for (Index = 0x00; (Index < BUFFER_SIZE) && (WriteReadStatus == 0); Index++) { if (RxBuffer[Index] != TxBuffer[Index]) { WriteReadStatus = Index + 1; } } if (WriteReadStatus == 0) { /* OK */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* KO */ /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } 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"); }